Beispiel #1
0
        public override bool OnClick(UIEvent clickEvent)
        {
            if (!clickEvent.heldDown && Element.MouseWasDown())
            {
                Element.Focus();

                // Move the cursor to the click point:
                int localClickX = clickEvent.clientX - Element.Style.Computed.OffsetLeft + Element.Style.Computed.ScrollLeft;
                int localClickY = clickEvent.clientY - Element.Style.Computed.OffsetTop + Element.Style.Computed.ScrollTop;

                int index = 0;

                if (Element.childNodes.Count > 1)
                {
                    // Note: If it's equal to 1, ele[0] is the cursor.
                    TextElement text = (TextElement)(Element.childNodes[0]);
                    if (text != null)
                    {
                        index = text.LetterIndex(localClickX, localClickY);
                    }
                }

                MoveCursor(index, true);
            }

            base.OnClick(clickEvent);
            clickEvent.stopPropagation();

            return(true);
        }
        public override bool OnClick(UIEvent clickEvent)
        {
            // Did the mouse go up, and was the element clicked down on too?
            if (!clickEvent.heldDown && Element.MouseWasDown())
            {
                // Focus it:
                Element.Focus();

                if (Type == InputType.Submit)
                {
                    // Find the form and then attempt to submit it.
                    FormTag form = Element.form;
                    if (form != null)
                    {
                        form.submit();
                    }
                }
                else if (IsScrollInput())
                {
                    // Clicked somewhere on a scrollbar:
                    // Figure out where the click was, and scroll there.
                }
                else if (Type == InputType.Radio)
                {
                    Select();
                }
                else if (Type == InputType.Checkbox)
                {
                    if (Checked)
                    {
                        Unselect();
                    }
                    else
                    {
                        Select();
                    }
                }
                else if (IsTextInput())
                {
                    // Move the cursor to the click point:
                    int localClick = clickEvent.clientX - Element.Style.Computed.OffsetLeft + Element.Style.Computed.ScrollLeft;
                    int index      = 0;

                    if (Element.childNodes.Count > 1)
                    {
                        // Note: If it's equal to 1, ele[0] is the cursor.
                        TextElement text = (TextElement)(Element.childNodes[0]);
                        if (text != null)
                        {
                            index = text.LetterIndex(localClick);
                        }
                    }

                    MoveCursor(index, true);
                }
            }

            base.OnClick(clickEvent);
            clickEvent.stopPropagation();

            return(true);
        }