Changeset 150707 in webkit


Ignore:
Timestamp:
May 25, 2013 9:33:35 PM (11 years ago)
Author:
akling@apple.com
Message:

Move Node::tabIndex() to Element.
<http://webkit.org/b/116772>

Reviewed by Ryosuke Niwa.

Since only Elements are keyboard-focusable, it doesn't make sense for Node to have a tabIndex().

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

A Node can't have a tab index, so move tabIndex() to Element.

  • page/FocusController.h:
  • page/FocusController.cpp:

(WebCore::adjustedTabIndex):
(WebCore::FocusController::findElementWithExactTabIndex):
(WebCore::nextElementWithGreaterTabIndex):
(WebCore::previousElementWithLowerTabIndex):
(WebCore::FocusController::nextFocusableNode):
(WebCore::FocusController::previousFocusableNode):

Make this code deal in Element* when doing tab index stuff. FocusController needs
more Node->Element cleanup, but let's do that separately.

  • html/HTMLAnchorElement.h:
  • html/HTMLElement.h:
  • html/HTMLFormControlElement.h:

Sprinkle OVERRIDE.

Location:
trunk/Source/WebCore
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r150702 r150707  
     12013-05-25  Andreas Kling  <akling@apple.com>
     2
     3        Move Node::tabIndex() to Element.
     4        <http://webkit.org/b/116772>
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Since only Elements are keyboard-focusable, it doesn't make sense for Node to have a tabIndex().
     9
     10        * dom/Element.h:
     11        * dom/Node.cpp:
     12        * dom/Node.h:
     13
     14            A Node can't have a tab index, so move tabIndex() to Element.
     15
     16        * page/FocusController.h:
     17        * page/FocusController.cpp:
     18        (WebCore::adjustedTabIndex):
     19        (WebCore::FocusController::findElementWithExactTabIndex):
     20        (WebCore::nextElementWithGreaterTabIndex):
     21        (WebCore::previousElementWithLowerTabIndex):
     22        (WebCore::FocusController::nextFocusableNode):
     23        (WebCore::FocusController::previousFocusableNode):
     24
     25            Make this code deal in Element* when doing tab index stuff. FocusController needs
     26            more Node->Element cleanup, but let's do that separately.
     27
     28        * html/HTMLAnchorElement.h:
     29        * html/HTMLElement.h:
     30        * html/HTMLFormControlElement.h:
     31
     32            Sprinkle OVERRIDE.
     33
    1342013-05-25  Andreas Kling  <akling@apple.com>
    235
  • trunk/Source/WebCore/dom/Element.h

    r150697 r150707  
    436436    virtual bool isMouseFocusable() const;
    437437
     438    virtual short tabIndex() const;
    438439    virtual Element* focusDelegate();
    439440
     
    655656    void setTabIndexExplicitly(short);
    656657    virtual bool supportsFocus() const OVERRIDE;
    657     virtual short tabIndex() const OVERRIDE;
    658658
    659659    PassRefPtr<HTMLCollection> ensureCachedHTMLCollection(CollectionType);
  • trunk/Source/WebCore/dom/Node.cpp

    r150697 r150707  
    500500}
    501501
    502 short Node::tabIndex() const
    503 {
    504     return 0;
    505 }
    506 
    507502String Node::nodeValue() const
    508503{
  • trunk/Source/WebCore/dom/Node.h

    r150697 r150707  
    400400    virtual void setActive(bool flag = true, bool pause = false);
    401401
    402     virtual short tabIndex() const;
    403 
    404402    // Whether this kind of node can receive focus by default. Most nodes are
    405403    // not focusable but some elements, such as form controls and links, are.
  • trunk/Source/WebCore/html/HTMLAnchorElement.h

    r150692 r150707  
    118118    virtual bool canStartSelection() const;
    119119    virtual String target() const;
    120     virtual short tabIndex() const;
     120    virtual short tabIndex() const OVERRIDE FINAL;
    121121    virtual bool draggable() const;
    122122
  • trunk/Source/WebCore/html/HTMLElement.h

    r149960 r150707  
    5151    virtual String title() const OVERRIDE FINAL;
    5252
    53     virtual short tabIndex() const;
     53    virtual short tabIndex() const OVERRIDE;
    5454    void setTabIndex(int);
    5555
  • trunk/Source/WebCore/html/HTMLFormControlElement.h

    r150692 r150707  
    137137    virtual bool alwaysCreateUserAgentShadowRoot() const OVERRIDE { return true; }
    138138
    139     virtual short tabIndex() const;
     139    virtual short tabIndex() const OVERRIDE FINAL;
    140140
    141141    virtual HTMLFormElement* virtualForm() const;
  • trunk/Source/WebCore/page/FocusController.cpp

    r150687 r150707  
    150150{
    151151    ASSERT(node);
    152     return isNonFocusableShadowHost(node, event) ? 0 : node->tabIndex();
     152    if (!node->isElementNode())
     153        return 0;
     154    return isNonFocusableShadowHost(node, event) ? 0 : toElement(node)->tabIndex();
    153155}
    154156
     
    416418}
    417419
    418 Node* FocusController::findNodeWithExactTabIndex(Node* start, int tabIndex, KeyboardEvent* event, FocusDirection direction)
     420Element* FocusController::findElementWithExactTabIndex(Node* start, int tabIndex, KeyboardEvent* event, FocusDirection direction)
    419421{
    420422    // Search is inclusive of start
    421423    using namespace NodeRenderingTraversal;
    422424    for (Node* node = start; node; node = direction == FocusDirectionForward ? nextInScope(node) : previousInScope(node)) {
    423         if (shouldVisit(node, event) && adjustedTabIndex(node, event) == tabIndex)
    424             return node;
     425        if (!node->isElementNode())
     426            continue;
     427        Element* element = toElement(node);
     428        if (shouldVisit(element, event) && adjustedTabIndex(element, event) == tabIndex)
     429            return element;
    425430    }
    426431    return 0;
    427432}
    428433
    429 static Node* nextNodeWithGreaterTabIndex(Node* start, int tabIndex, KeyboardEvent* event)
     434static Element* nextElementWithGreaterTabIndex(Node* start, int tabIndex, KeyboardEvent* event)
    430435{
    431436    // Search is inclusive of start
    432437    int winningTabIndex = std::numeric_limits<short>::max() + 1;
    433     Node* winner = 0;
     438    Element* winner = 0;
    434439    for (Node* node = start; node; node = NodeRenderingTraversal::nextInScope(node)) {
    435         if (shouldVisit(node, event) && node->tabIndex() > tabIndex && node->tabIndex() < winningTabIndex) {
    436             winner = node;
    437             winningTabIndex = node->tabIndex();
     440        if (!node->isElementNode())
     441            continue;
     442        Element* element = toElement(node);
     443        if (shouldVisit(element, event) && element->tabIndex() > tabIndex && element->tabIndex() < winningTabIndex) {
     444            winner = element;
     445            winningTabIndex = element->tabIndex();
    438446        }
    439447    }
     
    442450}
    443451
    444 static Node* previousNodeWithLowerTabIndex(Node* start, int tabIndex, KeyboardEvent* event)
     452static Element* previousElementWithLowerTabIndex(Node* start, int tabIndex, KeyboardEvent* event)
    445453{
    446454    // Search is inclusive of start
    447455    int winningTabIndex = 0;
    448     Node* winner = 0;
     456    Element* winner = 0;
    449457    for (Node* node = start; node; node = NodeRenderingTraversal::previousInScope(node)) {
    450         int currentTabIndex = adjustedTabIndex(node, event);
    451         if ((shouldVisit(node, event) || isNonFocusableShadowHost(node, event)) && currentTabIndex < tabIndex && currentTabIndex > winningTabIndex) {
    452             winner = node;
     458        if (!node->isElementNode())
     459            continue;
     460        Element* element = toElement(node);
     461        int currentTabIndex = adjustedTabIndex(element, event);
     462        if ((shouldVisit(element, event) || isNonFocusableShadowHost(element, event)) && currentTabIndex < tabIndex && currentTabIndex > winningTabIndex) {
     463            winner = element;
    453464            winningTabIndex = currentTabIndex;
    454465        }
     
    472483
    473484        // First try to find a node with the same tabindex as start that comes after start in the scope.
    474         if (Node* winner = findNodeWithExactTabIndex(nextInScope(start), tabIndex, event, FocusDirectionForward))
     485        if (Element* winner = findElementWithExactTabIndex(nextInScope(start), tabIndex, event, FocusDirectionForward))
    475486            return winner;
    476487
     
    480491    }
    481492
    482     // Look for the first node in the scope that:
     493    // Look for the first Element in the scope that:
    483494    // 1) has the lowest tabindex that is higher than start's tabindex (or 0, if start is null), and
    484495    // 2) comes first in the scope, if there's a tie.
    485     if (Node* winner = nextNodeWithGreaterTabIndex(scope.rootNode(), start ? adjustedTabIndex(start, event) : 0, event))
     496    if (Element* winner = nextElementWithGreaterTabIndex(scope.rootNode(), start ? adjustedTabIndex(start, event) : 0, event))
    486497        return winner;
    487498
    488499    // There are no nodes with a tabindex greater than start's tabindex,
    489500    // so find the first node with a tabindex of 0.
    490     return findNodeWithExactTabIndex(scope.rootNode(), 0, event, FocusDirectionForward);
     501    return findElementWithExactTabIndex(scope.rootNode(), 0, event, FocusDirectionForward);
    491502}
    492503
     
    520531    }
    521532
    522     if (Node* winner = findNodeWithExactTabIndex(startingNode, startingTabIndex, event, FocusDirectionBackward))
     533    if (Element* winner = findElementWithExactTabIndex(startingNode, startingTabIndex, event, FocusDirectionBackward))
    523534        return winner;
    524535
     
    527538    // 2) comes last in the scope, if there's a tie.
    528539    startingTabIndex = (start && startingTabIndex) ? startingTabIndex : std::numeric_limits<short>::max();
    529     return previousNodeWithLowerTabIndex(last, startingTabIndex, event);
     540    return previousElementWithLowerTabIndex(last, startingTabIndex, event);
    530541}
    531542
  • trunk/Source/WebCore/page/FocusController.h

    r141738 r150707  
    106106    Node* previousFocusableNode(FocusNavigationScope, Node* start, KeyboardEvent*);
    107107
    108     Node* findNodeWithExactTabIndex(Node* start, int tabIndex, KeyboardEvent*, FocusDirection);
     108    Element* findElementWithExactTabIndex(Node* start, int tabIndex, KeyboardEvent*, FocusDirection);
    109109
    110110    bool advanceFocusDirectionallyInContainer(Node* container, const LayoutRect& startingRect, FocusDirection, KeyboardEvent*);
Note: See TracChangeset for help on using the changeset viewer.