Changeset 150709 in webkit


Ignore:
Timestamp:
May 25, 2013 10:05:37 PM (11 years ago)
Author:
akling@apple.com
Message:

Move Node::isFocusable() to Element.
<http://webkit.org/b/116777>

Reviewed by Anders Carlsson.

Nodes cannot be focusable, so move isFocusable() from Node to Element.

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

(WebCore::Element::isFocusable):

Moved here from Node.

  • dom/Document.cpp:

(WebCore::Document::setFocusedNode):

  • accessibility/AccessibilityNodeObject.cpp:

(WebCore::AccessibilityNodeObject::determineAccessibilityRole):

Check that the underlying node is an Element before asking if it's focusable.

  • page/FrameView.cpp:

(WebCore::FrameView::scrollToAnchor):

Renamed the 'anchorNode' variable to 'anchorElement' because reasons.

  • html/HTMLAreaElement.h:
  • html/HTMLFormControlElement.h:
  • html/HTMLLabelElement.h:
  • html/HTMLOptionElement.h:
  • svg/SVGAElement.h:

Sprinkle OVERRIDE.

  • html/ValidationMessage.cpp:

(WebCore::ValidationMessage::setMessage):

Update a comment to refer to Element::isFocusable() instead of Node.

Location:
trunk/Source/WebCore
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r150707 r150709  
     12013-05-25  Andreas Kling  <akling@apple.com>
     2
     3        Move Node::isFocusable() to Element.
     4        <http://webkit.org/b/116777>
     5
     6        Reviewed by Anders Carlsson.
     7
     8        Nodes cannot be focusable, so move isFocusable() from Node to Element.
     9
     10        * dom/Node.cpp:
     11        * dom/Node.h:
     12        * dom/Element.h:
     13        * dom/Element.cpp:
     14        (WebCore::Element::isFocusable):
     15
     16            Moved here from Node.
     17
     18        * dom/Document.cpp:
     19        (WebCore::Document::setFocusedNode):
     20        * accessibility/AccessibilityNodeObject.cpp:
     21        (WebCore::AccessibilityNodeObject::determineAccessibilityRole):
     22
     23            Check that the underlying node is an Element before asking if it's focusable.
     24
     25        * page/FrameView.cpp:
     26        (WebCore::FrameView::scrollToAnchor):
     27
     28            Renamed the 'anchorNode' variable to 'anchorElement' because reasons.
     29
     30        * html/HTMLAreaElement.h:
     31        * html/HTMLFormControlElement.h:
     32        * html/HTMLLabelElement.h:
     33        * html/HTMLOptionElement.h:
     34        * svg/SVGAElement.h:
     35
     36            Sprinkle OVERRIDE.
     37
     38        * html/ValidationMessage.cpp:
     39        (WebCore::ValidationMessage::setMessage):
     40
     41            Update a comment to refer to Element::isFocusable() instead of Node.
     42
    1432013-05-25  Andreas Kling  <akling@apple.com>
    244
  • trunk/Source/WebCore/accessibility/AccessibilityNodeObject.cpp

    r150684 r150709  
    316316    if (node()->hasTagName(labelTag))
    317317        return LabelRole;
    318     if (node()->isFocusable())
     318    if (node()->isElementNode() && toElement(node())->isFocusable())
    319319        return GroupRole;
    320320   
  • trunk/Source/WebCore/dom/Document.cpp

    r150700 r150709  
    33873387    }
    33883388
    3389     if (newFocusedNode && newFocusedNode->isFocusable()) {
     3389    if (newFocusedNode && newFocusedNode->isElementNode() && toElement(newFocusedNode.get())->isFocusable()) {
    33903390        if (newFocusedNode->isRootEditableElement() && !acceptsEditingFocus(newFocusedNode.get())) {
    33913391            // delegate blocks focus change
  • trunk/Source/WebCore/dom/Element.cpp

    r150697 r150709  
    418418}
    419419
     420bool Element::isFocusable() const
     421{
     422    if (!inDocument() || !supportsFocus())
     423        return false;
     424
     425    // Elements in canvas fallback content are not rendered, but they are allowed to be
     426    // focusable as long as their canvas is displayed and visible.
     427    if (isInCanvasSubtree()) {
     428        const Element* e = this;
     429        while (e && !e->hasLocalName(canvasTag))
     430            e = e->parentElement();
     431        ASSERT(e);
     432        return e->renderer() && e->renderer()->style()->visibility() == VISIBLE;
     433    }
     434
     435    if (renderer())
     436        ASSERT(!renderer()->needsLayout());
     437    else {
     438        // If the node is in a display:none tree it might say it needs style recalc but
     439        // the whole document is actually up to date.
     440        ASSERT(!document()->childNeedsStyleRecalc());
     441    }
     442
     443    // FIXME: Even if we are not visible, we might have a child that is visible.
     444    // Hyatt wants to fix that some day with a "has visible content" flag or the like.
     445    if (!renderer() || renderer()->style()->visibility() != VISIBLE)
     446        return false;
     447
     448    return true;
     449}
     450
    420451bool Element::isUserActionElementFocused() const
    421452{
  • trunk/Source/WebCore/dom/Element.h

    r150707 r150709  
    433433    virtual void setFocus(bool flag);
    434434
     435    virtual bool isFocusable() const;
    435436    virtual bool isKeyboardFocusable(KeyboardEvent*) const;
    436437    virtual bool isMouseFocusable() const;
  • trunk/Source/WebCore/dom/Node.cpp

    r150707 r150709  
    851851}
    852852   
    853 bool Node::isFocusable() const
    854 {
    855     if (!inDocument() || !supportsFocus())
    856         return false;
    857    
    858     // Elements in canvas fallback content are not rendered, but they are allowed to be
    859     // focusable as long as their canvas is displayed and visible.
    860     if (isElementNode() && toElement(this)->isInCanvasSubtree()) {
    861         const Element* e = toElement(this);
    862         while (e && !e->hasLocalName(canvasTag))
    863             e = e->parentElement();
    864         ASSERT(e);
    865         return e->renderer() && e->renderer()->style()->visibility() == VISIBLE;
    866     }
    867 
    868     if (renderer())
    869         ASSERT(!renderer()->needsLayout());
    870     else
    871         // If the node is in a display:none tree it might say it needs style recalc but
    872         // the whole document is actually up to date.
    873         ASSERT(!document()->childNeedsStyleRecalc());
    874 
    875     // FIXME: Even if we are not visible, we might have a child that is visible.
    876     // Hyatt wants to fix that some day with a "has visible content" flag or the like.
    877     if (!renderer() || renderer()->style()->visibility() != VISIBLE)
    878         return false;
    879 
    880     return true;
    881 }
    882 
    883853unsigned Node::nodeIndex() const
    884854{
  • trunk/Source/WebCore/dom/Node.h

    r150707 r150709  
    403403    // not focusable but some elements, such as form controls and links, are.
    404404    virtual bool supportsFocus() const;
    405     // Whether the node can actually be focused.
    406     virtual bool isFocusable() const;
    407405
    408406    enum UserSelectAllTreatment {
  • trunk/Source/WebCore/html/HTMLAreaElement.h

    r150692 r150709  
    5656    virtual bool isKeyboardFocusable(KeyboardEvent*) const OVERRIDE;
    5757    virtual bool isMouseFocusable() const OVERRIDE;
    58     virtual bool isFocusable() const;
     58    virtual bool isFocusable() const OVERRIDE;
    5959    virtual void updateFocusAppearance(bool /*restorePreviousSelection*/);
    6060    virtual void setFocus(bool) OVERRIDE;
  • trunk/Source/WebCore/html/HTMLFormControlElement.h

    r150707 r150709  
    6767    virtual bool isDisabledFormControl() const OVERRIDE;
    6868
    69     virtual bool isFocusable() const;
     69    virtual bool isFocusable() const OVERRIDE;
    7070    virtual bool isEnumeratable() const { return false; }
    7171
  • trunk/Source/WebCore/html/HTMLLabelElement.h

    r150684 r150709  
    4242    HTMLLabelElement(const QualifiedName&, Document*);
    4343
    44     virtual bool isFocusable() const;
     44    virtual bool isFocusable() const OVERRIDE;
    4545
    4646    virtual void accessKeyAction(bool sendMouseEvents);
  • trunk/Source/WebCore/html/HTMLOptionElement.h

    r149960 r150709  
    7171
    7272    virtual bool supportsFocus() const;
    73     virtual bool isFocusable() const;
     73    virtual bool isFocusable() const OVERRIDE;
    7474    virtual bool rendererIsNeeded(const NodeRenderingContext&) { return false; }
    7575    virtual void attach();
  • trunk/Source/WebCore/html/ValidationMessage.cpp

    r142247 r150709  
    111111
    112112    // Don't modify the DOM tree in this context.
    113     // If so, an assertion in Node::isFocusable() fails.
     113    // If so, an assertion in Element::isFocusable() fails.
    114114    ASSERT(!message.isEmpty());
    115115    m_message = message;
  • trunk/Source/WebCore/page/FrameView.cpp

    r150666 r150709  
    18431843    m_frame->document()->setGotoAnchorNeededAfterStylesheetsLoad(false);
    18441844
    1845     Element* anchorNode = m_frame->document()->findAnchor(name);
     1845    Element* anchorElement = m_frame->document()->findAnchor(name);
    18461846
    18471847    // Setting to null will clear the current target.
    1848     m_frame->document()->setCSSTarget(anchorNode);
     1848    m_frame->document()->setCSSTarget(anchorElement);
    18491849
    18501850#if ENABLE(SVG)
    18511851    if (m_frame->document()->isSVGDocument()) {
    18521852        if (SVGSVGElement* svg = toSVGDocument(m_frame->document())->rootElement()) {
    1853             svg->setupInitialView(name, anchorNode);
    1854             if (!anchorNode)
     1853            svg->setupInitialView(name, anchorElement);
     1854            if (!anchorElement)
    18551855                return true;
    18561856        }
     
    18591859 
    18601860    // Implement the rule that "" and "top" both mean top of page as in other browsers.
    1861     if (!anchorNode && !(name.isEmpty() || equalIgnoringCase(name, "top")))
     1861    if (!anchorElement && !(name.isEmpty() || equalIgnoringCase(name, "top")))
    18621862        return false;
    18631863
    1864     maintainScrollPositionAtAnchor(anchorNode ? static_cast<Node*>(anchorNode) : m_frame->document());
     1864    maintainScrollPositionAtAnchor(anchorElement ? static_cast<Node*>(anchorElement) : m_frame->document());
    18651865   
    18661866    // If the anchor accepts keyboard focus, move focus there to aid users relying on keyboard navigation.
    1867     if (anchorNode && anchorNode->isFocusable())
    1868         m_frame->document()->setFocusedNode(anchorNode);
     1867    if (anchorElement && anchorElement->isFocusable())
     1868        m_frame->document()->setFocusedNode(anchorElement);
    18691869   
    18701870    return true;
  • trunk/Source/WebCore/svg/SVGAElement.h

    r150692 r150709  
    6060    virtual bool isMouseFocusable() const OVERRIDE;
    6161    virtual bool isKeyboardFocusable(KeyboardEvent*) const OVERRIDE;
    62     virtual bool isFocusable() const;
     62    virtual bool isFocusable() const OVERRIDE;
    6363    virtual bool isURLAttribute(const Attribute&) const;
    6464
Note: See TracChangeset for help on using the changeset viewer.