Changeset 150692 in webkit


Ignore:
Timestamp:
May 25, 2013 4:09:29 PM (11 years ago)
Author:
akling@apple.com
Message:

Move Node::isMouseFocusable() to Element.
<http://webkit.org/b/116762>

Reviewed by Anders Carlsson.

Source/WebCore:

Node::isMouseFocusable() would just return isFocusable(), which is never true for a non-Element
since Node::supportsFocus() always returns false. So move it to Element!

  • dom/Node.h:
  • dom/Node.cpp:
  • dom/Element.h:
  • dom/Element.cpp:

(WebCore::Element::isMouseFocusable):

Moved here from Node.

  • editing/FrameSelection.cpp:

(WebCore::FrameSelection::setFocusedNodeIfNeeded):

  • page/EventHandler.cpp:

(WebCore::EventHandler::dispatchMouseEvent):

Walk up the parent chain with parentOrShadowHostElement() instead of parentOrShadowHostNode().
Removed a misleading no-op hunk about mouse-focusable ShadowRoots, since ShadowRoots are not
Elements and thus cannot be mouse-focusable.

  • page/TouchAdjustment.cpp:

(WebCore::TouchAdjustment::nodeRespondsToTapGesture):

Check that the Node is an Element before asking if it's mouse-focusable.

  • html/HTMLAnchorElement.h:
  • html/HTMLAreaElement.h:
  • html/HTMLFormControlElement.h:
  • html/HTMLInputElement.h:
  • html/HTMLMediaElement.h:
  • html/HTMLSelectElement.h:
  • html/HTMLTextAreaElement.h:
  • html/shadow/ClearButtonElement.h:
  • html/shadow/TextControlInnerElements.h:
  • svg/SVGAElement.h:
  • svg/SVGStyledElement.h:

Sprinkle OVERRIDE.

Source/WebKit2:

  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::highlightPotentialActivation):

Check that the potentially activated Node is an Element before asking if it's mouse-focusable.

Location:
trunk/Source
Files:
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r150687 r150692  
     12013-05-25  Andreas Kling  <akling@apple.com>
     2
     3        Move Node::isMouseFocusable() to Element.
     4        <http://webkit.org/b/116762>
     5
     6        Reviewed by Anders Carlsson.
     7
     8        Node::isMouseFocusable() would just return isFocusable(), which is never true for a non-Element
     9        since Node::supportsFocus() always returns false. So move it to Element!
     10
     11        * dom/Node.h:
     12        * dom/Node.cpp:
     13        * dom/Element.h:
     14        * dom/Element.cpp:
     15        (WebCore::Element::isMouseFocusable):
     16
     17            Moved here from Node.
     18
     19        * editing/FrameSelection.cpp:
     20        (WebCore::FrameSelection::setFocusedNodeIfNeeded):
     21        * page/EventHandler.cpp:
     22        (WebCore::EventHandler::dispatchMouseEvent):
     23
     24            Walk up the parent chain with parentOrShadowHostElement() instead of parentOrShadowHostNode().
     25            Removed a misleading no-op hunk about mouse-focusable ShadowRoots, since ShadowRoots are not
     26            Elements and thus cannot be mouse-focusable.
     27
     28        * page/TouchAdjustment.cpp:
     29        (WebCore::TouchAdjustment::nodeRespondsToTapGesture):
     30
     31            Check that the Node is an Element before asking if it's mouse-focusable.
     32
     33        * html/HTMLAnchorElement.h:
     34        * html/HTMLAreaElement.h:
     35        * html/HTMLFormControlElement.h:
     36        * html/HTMLInputElement.h:
     37        * html/HTMLMediaElement.h:
     38        * html/HTMLSelectElement.h:
     39        * html/HTMLTextAreaElement.h:
     40        * html/shadow/ClearButtonElement.h:
     41        * html/shadow/TextControlInnerElements.h:
     42        * svg/SVGAElement.h:
     43        * svg/SVGStyledElement.h:
     44
     45            Sprinkle OVERRIDE.
     46
    1472013-05-25  Andreas Kling  <akling@apple.com>
    248
  • trunk/Source/WebCore/dom/Element.cpp

    r150687 r150692  
    255255}
    256256
     257bool Element::isMouseFocusable() const
     258{
     259    return isFocusable();
     260}
     261
    257262DEFINE_VIRTUAL_ATTRIBUTE_EVENT_LISTENER(Element, blur);
    258263DEFINE_VIRTUAL_ATTRIBUTE_EVENT_LISTENER(Element, error);
  • trunk/Source/WebCore/dom/Element.h

    r150687 r150692  
    434434
    435435    virtual bool isKeyboardFocusable(KeyboardEvent*) const;
     436    virtual bool isMouseFocusable() const;
    436437
    437438    RenderStyle* computedStyle(PseudoId = NOPSEUDO);
  • trunk/Source/WebCore/dom/Node.cpp

    r150687 r150692  
    886886}
    887887
    888 bool Node::isMouseFocusable() const
    889 {
    890     return isFocusable();
    891 }
    892 
    893888Node* Node::focusDelegate()
    894889{
  • trunk/Source/WebCore/dom/Node.h

    r150687 r150692  
    407407    // Whether the node can actually be focused.
    408408    virtual bool isFocusable() const;
    409     virtual bool isMouseFocusable() const;
    410409    virtual Node* focusDelegate();
    411410
  • trunk/Source/WebCore/editing/FrameSelection.cpp

    r150482 r150692  
    18901890    }
    18911891
    1892     if (Node* target = rootEditableElement()) {
    1893         // Walk up the DOM tree to search for a node to focus.
     1892    if (Element* target = rootEditableElement()) {
     1893        // Walk up the DOM tree to search for an element to focus.
    18941894        while (target) {
    18951895            // We don't want to set focus on a subframe when selecting in a parent frame,
     
    19001900                return;
    19011901            }
    1902             target = target->parentOrShadowHostNode();
     1902            target = target->parentOrShadowHostElement();
    19031903        }
    19041904        m_frame->document()->setFocusedNode(0);
  • trunk/Source/WebCore/html/HTMLAnchorElement.h

    r150687 r150692  
    110110private:
    111111    virtual bool supportsFocus() const;
    112     virtual bool isMouseFocusable() const;
     112    virtual bool isMouseFocusable() const OVERRIDE;
    113113    virtual bool isKeyboardFocusable(KeyboardEvent*) const OVERRIDE;
    114114    virtual void defaultEventHandler(Event*);
  • trunk/Source/WebCore/html/HTMLAreaElement.h

    r150687 r150692  
    5555    virtual String target() const;
    5656    virtual bool isKeyboardFocusable(KeyboardEvent*) const OVERRIDE;
    57     virtual bool isMouseFocusable() const;
     57    virtual bool isMouseFocusable() const OVERRIDE;
    5858    virtual bool isFocusable() const;
    5959    virtual void updateFocusAppearance(bool /*restorePreviousSelection*/);
  • trunk/Source/WebCore/html/HTMLFormControlElement.h

    r150687 r150692  
    118118    virtual bool supportsFocus() const;
    119119    virtual bool isKeyboardFocusable(KeyboardEvent*) const OVERRIDE;
    120     virtual bool isMouseFocusable() const;
     120    virtual bool isMouseFocusable() const OVERRIDE;
    121121
    122122    virtual void didRecalcStyle(StyleChange) OVERRIDE;
  • trunk/Source/WebCore/html/HTMLInputElement.h

    r150687 r150692  
    325325    virtual bool hasCustomFocusLogic() const OVERRIDE;
    326326    virtual bool isKeyboardFocusable(KeyboardEvent*) const OVERRIDE;
    327     virtual bool isMouseFocusable() const;
     327    virtual bool isMouseFocusable() const OVERRIDE;
    328328    virtual bool isEnumeratable() const;
    329329    virtual bool supportLabels() const OVERRIDE;
  • trunk/Source/WebCore/html/HTMLMediaElement.h

    r150651 r150692  
    432432    virtual bool hasCustomFocusLogic() const OVERRIDE;
    433433    virtual bool supportsFocus() const;
    434     virtual bool isMouseFocusable() const;
     434    virtual bool isMouseFocusable() const OVERRIDE;
    435435    virtual bool rendererIsNeeded(const NodeRenderingContext&);
    436436    virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
  • trunk/Source/WebCore/html/HTMLSelectElement.h

    r150687 r150692  
    113113   
    114114    virtual bool isKeyboardFocusable(KeyboardEvent*) const OVERRIDE;
    115     virtual bool isMouseFocusable() const;
     115    virtual bool isMouseFocusable() const OVERRIDE;
    116116
    117117    virtual void dispatchFocusEvent(PassRefPtr<Node> oldFocusedNode, FocusDirection) OVERRIDE;
  • trunk/Source/WebCore/html/HTMLTextAreaElement.h

    r150687 r150692  
    105105    virtual void reset();
    106106    virtual bool hasCustomFocusLogic() const OVERRIDE;
    107     virtual bool isMouseFocusable() const;
     107    virtual bool isMouseFocusable() const OVERRIDE;
    108108    virtual bool isKeyboardFocusable(KeyboardEvent*) const OVERRIDE;
    109109    virtual void updateFocusAppearance(bool restorePreviousSelection);
  • trunk/Source/WebCore/html/shadow/ClearButtonElement.h

    r149960 r150692  
    4949    ClearButtonElement(Document*, ClearButtonOwner&);
    5050    virtual void detach();
    51     virtual bool isMouseFocusable() const { return false; }
     51    virtual bool isMouseFocusable() const OVERRIDE { return false; }
    5252    virtual void defaultEventHandler(Event*);
    5353
  • trunk/Source/WebCore/html/shadow/TextControlInnerElements.h

    r149960 r150692  
    5353
    5454private:
    55     virtual bool isMouseFocusable() const { return false; }
     55    virtual bool isMouseFocusable() const OVERRIDE { return false; }
    5656};
    5757
     
    6666    virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
    6767    virtual PassRefPtr<RenderStyle> customStyleForRenderer() OVERRIDE;
    68     virtual bool isMouseFocusable() const { return false; }
     68    virtual bool isMouseFocusable() const OVERRIDE { return false; }
    6969};
    7070
     
    7979    SearchFieldResultsButtonElement(Document*);
    8080    virtual const AtomicString& shadowPseudoId() const;
    81     virtual bool isMouseFocusable() const { return false; }
     81    virtual bool isMouseFocusable() const OVERRIDE { return false; }
    8282};
    8383
     
    9393    virtual const AtomicString& shadowPseudoId() const;
    9494    virtual void detach();
    95     virtual bool isMouseFocusable() const { return false; }
     95    virtual bool isMouseFocusable() const OVERRIDE { return false; }
    9696
    9797    bool m_capturing;
     
    131131    void setState(SpeechInputState state);
    132132    virtual const AtomicString& shadowPseudoId() const;
    133     virtual bool isMouseFocusable() const { return false; }
     133    virtual bool isMouseFocusable() const OVERRIDE { return false; }
    134134    virtual void attach();
    135135
  • trunk/Source/WebCore/page/EventHandler.cpp

    r150686 r150692  
    23312331        // is expected by some sites that rely on onChange handlers running
    23322332        // from form fields before the button click is processed.
    2333         Node* node = m_nodeUnderMouse.get();
    2334 
    2335         // Walk up the DOM tree to search for a node to focus.
    2336         while (node) {
    2337             if (node->isMouseFocusable()) {
     2333
     2334        Element* element;
     2335        if (m_nodeUnderMouse)
     2336            element = m_nodeUnderMouse->isElementNode() ? toElement(m_nodeUnderMouse.get()) : m_nodeUnderMouse->parentOrShadowHostElement();
     2337        else
     2338            element = 0;
     2339
     2340        // Walk up the DOM tree to search for an element to focus.
     2341        while (element) {
     2342            if (element->isMouseFocusable()) {
    23382343                // To fix <rdar://problem/4895428> Can't drag selected ToDo, we don't focus a
    23392344                // node on mouse down if it's selected and inside a focused node. It will be
    23402345                // focused if the user does a mouseup over it, however, because the mouseup
    23412346                // will set a selection inside it, which will call setFocuseNodeIfNeeded.
    2342                 Node* n = node->isShadowRoot() ? toShadowRoot(node)->host() : node;
    23432347                if (m_frame->selection()->isRange()
    2344                     && m_frame->selection()->toNormalizedRange()->compareNode(n, IGNORE_EXCEPTION) == Range::NODE_INSIDE
    2345                     && n->isDescendantOf(m_frame->document()->focusedNode()))
     2348                    && m_frame->selection()->toNormalizedRange()->compareNode(element, IGNORE_EXCEPTION) == Range::NODE_INSIDE
     2349                    && element->isDescendantOf(m_frame->document()->focusedNode()))
    23462350                    return true;
    23472351                   
    23482352                break;
    23492353            }
    2350             node = node->parentOrShadowHostNode();
     2354            element = element->parentOrShadowHostElement();
    23512355        }
    23522356
    23532357        // Only change the focus when clicking scrollbars if it can transfered to a mouse focusable node.
    2354         if ((!node || !node->isMouseFocusable()) && isInsideScrollbar(mouseEvent.position()))
     2358        if ((!element || !element->isMouseFocusable()) && isInsideScrollbar(mouseEvent.position()))
    23552359            return false;
    23562360
     
    23582362        // if the page already set it (e.g., by canceling default behavior).
    23592363        if (Page* page = m_frame->page()) {
    2360             if (node && node->isMouseFocusable()) {
    2361                 if (!page->focusController()->setFocusedNode(node, m_frame))
     2364            if (element && element->isMouseFocusable()) {
     2365                if (!page->focusController()->setFocusedNode(element, m_frame))
    23622366                    swallowEvent = true;
    2363             } else if (!node || !node->isElementNode() || !toElement(node)->focused()) {
     2367            } else if (!element || !element->focused()) {
    23642368                if (!page->focusController()->setFocusedNode(0, m_frame))
    23652369                    swallowEvent = true;
  • trunk/Source/WebCore/page/TouchAdjustment.cpp

    r150140 r150692  
    7474bool nodeRespondsToTapGesture(Node* node)
    7575{
    76     if (node->isMouseFocusable())
    77         return true;
    7876    if (node->willRespondToMouseClickEvents() || node->willRespondToMouseMoveEvents())
    7977        return true;
     
    8179    if (node->isElementNode()) {
    8280        Element* element = toElement(node);
     81        if (element->isMouseFocusable())
     82            return true;
    8383        if (element->childrenAffectedByActive() || element->childrenAffectedByHover())
    8484            return true;
  • trunk/Source/WebCore/svg/SVGAElement.h

    r150687 r150692  
    5858   
    5959    virtual bool supportsFocus() const;
    60     virtual bool isMouseFocusable() const;
     60    virtual bool isMouseFocusable() const OVERRIDE;
    6161    virtual bool isKeyboardFocusable(KeyboardEvent*) const OVERRIDE;
    6262    virtual bool isFocusable() const;
  • trunk/Source/WebCore/svg/SVGStyledElement.h

    r150687 r150692  
    8282
    8383    virtual bool isKeyboardFocusable(KeyboardEvent*) const OVERRIDE;
    84     virtual bool isMouseFocusable() const;
     84    virtual bool isMouseFocusable() const OVERRIDE;
    8585
    8686    void buildPendingResourcesIfNeeded();
  • trunk/Source/WebKit2/ChangeLog

    r150691 r150692  
     12013-05-25  Andreas Kling  <akling@apple.com>
     2
     3        Move Node::isMouseFocusable() to Element.
     4        <http://webkit.org/b/116762>
     5
     6        Reviewed by Anders Carlsson.
     7
     8        * WebProcess/WebPage/WebPage.cpp:
     9        (WebKit::WebPage::highlightPotentialActivation):
     10
     11            Check that the potentially activated Node is an Element before asking if it's mouse-focusable.
     12
    1132013-05-25  Andreas Kling  <akling@apple.com>
    214
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp

    r150669 r150692  
    18841884
    18851885            // We always highlight focusable (form-elements), image links or content-editable elements.
    1886             if (node->isMouseFocusable() || node->isLink() || node->isContentEditable())
     1886            if ((node->isElementNode() && toElement(node)->isMouseFocusable()) || node->isLink() || node->isContentEditable())
    18871887                activationNode = node;
    18881888            else if (node->willRespondToMouseClickEvents()) {
Note: See TracChangeset for help on using the changeset viewer.