Changeset 197055 in webkit


Ignore:
Timestamp:
Feb 24, 2016 3:37:51 PM (8 years ago)
Author:
rniwa@webkit.org
Message:

Use more references in FocusNavigationScope
https://bugs.webkit.org/show_bug.cgi?id=154637

Reviewed by Chris Dumez.

Use references in various functions of FocusNavigationScope as well as m_treeScope.

  • page/FocusController.cpp:

(WebCore::FocusNavigationScope::FocusNavigationScope): Takes TreeScope& instead of TreeScope*.
(WebCore::FocusNavigationScope::rootNode): Returns ContainerNode& instead of ContainerNode*.
(WebCore::FocusNavigationScope::owner):
(WebCore::FocusNavigationScope::scopeOf): Takes Node& instead of Node*. Renamed from focusNavigationScopeOf.
(WebCore::FocusNavigationScope::scopeOwnedByShadowHost): Ditto. Renamed from focusNavigationScopeOwnedByShadowHost.
(WebCore::FocusNavigationScope::scopeOwnedByIFrame): Ditto. Renamed from focusNavigationScopeOwnedByIFrame.
(WebCore::FocusController::findFocusableElementDescendingDownIntoFrameDocument):
(WebCore::FocusController::advanceFocusInDocumentOrder):
(WebCore::FocusController::findFocusableElementAcrossFocusScope): Define currentScope inside the loop now that
the copy constructor of FocusNavigationScope no longer exists (since m_treeScope is a reference).
(WebCore::FocusController::findFocusableElementRecursively):
(WebCore::nextElementWithGreaterTabIndex):
(WebCore::FocusController::nextFocusableElement):
(WebCore::FocusController::previousFocusableElement):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r197053 r197055  
     12016-02-24  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Use more references in FocusNavigationScope
     4        https://bugs.webkit.org/show_bug.cgi?id=154637
     5
     6        Reviewed by Chris Dumez.
     7
     8        Use references in various functions of FocusNavigationScope as well as m_treeScope.
     9
     10        * page/FocusController.cpp:
     11        (WebCore::FocusNavigationScope::FocusNavigationScope): Takes TreeScope& instead of TreeScope*.
     12        (WebCore::FocusNavigationScope::rootNode): Returns ContainerNode& instead of ContainerNode*.
     13        (WebCore::FocusNavigationScope::owner):
     14        (WebCore::FocusNavigationScope::scopeOf): Takes Node& instead of Node*. Renamed from focusNavigationScopeOf.
     15        (WebCore::FocusNavigationScope::scopeOwnedByShadowHost): Ditto. Renamed from focusNavigationScopeOwnedByShadowHost.
     16        (WebCore::FocusNavigationScope::scopeOwnedByIFrame): Ditto. Renamed from focusNavigationScopeOwnedByIFrame.
     17        (WebCore::FocusController::findFocusableElementDescendingDownIntoFrameDocument):
     18        (WebCore::FocusController::advanceFocusInDocumentOrder):
     19        (WebCore::FocusController::findFocusableElementAcrossFocusScope): Define currentScope inside the loop now that
     20        the copy constructor of FocusNavigationScope no longer exists (since m_treeScope is a reference).
     21        (WebCore::FocusController::findFocusableElementRecursively):
     22        (WebCore::nextElementWithGreaterTabIndex):
     23        (WebCore::FocusController::nextFocusableElement):
     24        (WebCore::FocusController::previousFocusableElement):
     25
    1262016-02-24  Adam Bergkvist  <adam.bergkvist@ericsson.com>
    227
  • trunk/Source/WebCore/page/FocusController.cpp

    r197021 r197055  
    7070class FocusNavigationScope {
    7171public:
    72     ContainerNode* rootNode() const;
     72    ContainerNode& rootNode() const;
    7373    Element* owner() const;
    74     WEBCORE_EXPORT static FocusNavigationScope focusNavigationScopeOf(Node*);
    75     static FocusNavigationScope focusNavigationScopeOwnedByShadowHost(Node*);
    76     static FocusNavigationScope focusNavigationScopeOwnedByIFrame(HTMLFrameOwnerElement*);
     74    WEBCORE_EXPORT static FocusNavigationScope scopeOf(Node&);
     75    static FocusNavigationScope scopeOwnedByShadowHost(Element&);
     76    static FocusNavigationScope scopeOwnedByIFrame(HTMLFrameOwnerElement&);
    7777
    7878    Node* nextInScope(const Node*) const;
     
    8383    Node* firstChildInScope(const Node*) const;
    8484
    85     explicit FocusNavigationScope(TreeScope*);
    86     TreeScope* m_rootTreeScope;
     85    explicit FocusNavigationScope(TreeScope&);
     86    TreeScope& m_rootTreeScope;
    8787};
    8888
     
    138138}
    139139
    140 FocusNavigationScope::FocusNavigationScope(TreeScope* treeScope)
     140FocusNavigationScope::FocusNavigationScope(TreeScope& treeScope)
    141141    : m_rootTreeScope(treeScope)
    142142{
    143     ASSERT(treeScope);
    144 }
    145 
    146 ContainerNode* FocusNavigationScope::rootNode() const
    147 {
    148     return &m_rootTreeScope->rootNode();
     143}
     144
     145ContainerNode& FocusNavigationScope::rootNode() const
     146{
     147    return m_rootTreeScope.rootNode();
    149148}
    150149
    151150Element* FocusNavigationScope::owner() const
    152151{
    153     ContainerNode* root = rootNode();
    154     if (is<ShadowRoot>(*root))
    155         return downcast<ShadowRoot>(*root).host();
    156     if (Frame* frame = root->document().frame())
     152    ContainerNode& root = rootNode();
     153    if (is<ShadowRoot>(root))
     154        return downcast<ShadowRoot>(root).host();
     155    if (Frame* frame = root.document().frame())
    157156        return frame->ownerElement();
    158157    return nullptr;
    159158}
    160159
    161 FocusNavigationScope FocusNavigationScope::focusNavigationScopeOf(Node* node)
    162 {
    163     ASSERT(node);
    164     Node* root = node;
    165     for (Node* n = node; n; n = parentInScope(n))
    166         root = n;
     160FocusNavigationScope FocusNavigationScope::scopeOf(Node& startingNode)
     161{
     162    Node* root = nullptr;
     163    for (Node* currentNode = &startingNode; currentNode; currentNode = parentInScope(currentNode))
     164        root = currentNode;
    167165    // The result is not always a ShadowRoot nor a DocumentNode since
    168166    // a starting node is in an orphaned tree in composed shadow tree.
    169     return FocusNavigationScope(&root->treeScope());
    170 }
    171 
    172 FocusNavigationScope FocusNavigationScope::focusNavigationScopeOwnedByShadowHost(Node* node)
    173 {
    174     ASSERT(node);
    175     ASSERT(downcast<Element>(*node).shadowRoot());
    176     return FocusNavigationScope(downcast<Element>(*node).shadowRoot());
    177 }
    178 
    179 FocusNavigationScope FocusNavigationScope::focusNavigationScopeOwnedByIFrame(HTMLFrameOwnerElement* frame)
    180 {
    181     ASSERT(frame);
    182     ASSERT(frame->contentFrame());
    183     return FocusNavigationScope(frame->contentFrame()->document());
     167    return FocusNavigationScope(root->treeScope());
     168}
     169
     170FocusNavigationScope FocusNavigationScope::scopeOwnedByShadowHost(Element& element)
     171{
     172    ASSERT(element.shadowRoot());
     173    return FocusNavigationScope(*element.shadowRoot());
     174}
     175
     176FocusNavigationScope FocusNavigationScope::scopeOwnedByIFrame(HTMLFrameOwnerElement& frame)
     177{
     178    ASSERT(frame.contentFrame());
     179    ASSERT(frame.contentFrame()->document());
     180    return FocusNavigationScope(*frame.contentFrame()->document());
    184181}
    185182
     
    302299        if (!owner.contentFrame())
    303300            break;
    304         Element* foundElement = findFocusableElement(direction, FocusNavigationScope::focusNavigationScopeOwnedByIFrame(&owner), 0, event);
     301        Element* foundElement = findFocusableElement(direction, FocusNavigationScope::scopeOwnedByIFrame(owner), 0, event);
    305302        if (!foundElement)
    306303            break;
     
    356353    document->updateLayoutIgnorePendingStylesheets();
    357354
    358     RefPtr<Element> element = findFocusableElementAcrossFocusScope(direction, FocusNavigationScope::focusNavigationScopeOf(currentNode ? currentNode : document), currentNode, event);
     355    RefPtr<Element> element = findFocusableElementAcrossFocusScope(direction, FocusNavigationScope::scopeOf(currentNode ? *currentNode : *document), currentNode, event);
    359356
    360357    if (!element) {
     
    368365
    369366        // Chrome doesn't want focus, so we should wrap focus.
    370         element = findFocusableElementRecursively(direction, FocusNavigationScope::focusNavigationScopeOf(m_page.mainFrame().document()), 0, event);
     367        element = findFocusableElementRecursively(direction, FocusNavigationScope::scopeOf(*m_page.mainFrame().document()), 0, event);
    371368        element = findFocusableElementDescendingDownIntoFrameDocument(direction, element.get(), event);
    372369
     
    425422    Element* found;
    426423    if (currentNode && direction == FocusDirectionForward && isFocusableShadowHost(*currentNode, *event)) {
    427         Element* foundInInnerFocusScope = findFocusableElementRecursively(direction, FocusNavigationScope::focusNavigationScopeOwnedByShadowHost(currentNode), 0, event);
     424        Element* foundInInnerFocusScope = findFocusableElementRecursively(direction, FocusNavigationScope::scopeOwnedByShadowHost(downcast<Element>(*currentNode)), 0, event);
    428425        found = foundInInnerFocusScope ? foundInInnerFocusScope : findFocusableElementRecursively(direction, scope, currentNode, event);
    429426    } else
     
    431428
    432429    // If there's no focusable node to advance to, move up the focus scopes until we find one.
    433     FocusNavigationScope currentScope = scope;
    434     while (!found) {
    435         Element* owner = currentScope.owner();
    436         if (!owner)
    437             break;
    438         currentScope = FocusNavigationScope::focusNavigationScopeOf(owner);
     430    Element* owner = scope.owner();
     431    while (!found && owner) {
     432        FocusNavigationScope currentScope = FocusNavigationScope::scopeOf(*owner);
    439433        if (direction == FocusDirectionBackward && isFocusableShadowHost(*owner, *event)) {
    440434            found = owner;
     
    442436        }
    443437        found = findFocusableElementRecursively(direction, currentScope, owner, event);
     438        owner = currentScope.owner();
    444439    }
    445440    found = findFocusableElementDescendingDownIntoFrameDocument(direction, found, event);
     
    456451        if (!isNonFocusableShadowHost(*found, *event))
    457452            return found;
    458         Element* foundInInnerFocusScope = findFocusableElementRecursively(direction, FocusNavigationScope::focusNavigationScopeOwnedByShadowHost(found), 0, event);
     453        Element* foundInInnerFocusScope = findFocusableElementRecursively(direction, FocusNavigationScope::scopeOwnedByShadowHost(*found), 0, event);
    459454        return foundInInnerFocusScope ? foundInInnerFocusScope : findFocusableElementRecursively(direction, scope, found, event);
    460455    }
    461456    ASSERT(direction == FocusDirectionBackward);
    462457    if (isFocusableShadowHost(*found, *event)) {
    463         Element* foundInInnerFocusScope = findFocusableElementRecursively(direction, FocusNavigationScope::focusNavigationScopeOwnedByShadowHost(found), 0, event);
     458        Element* foundInInnerFocusScope = findFocusableElementRecursively(direction, FocusNavigationScope::scopeOwnedByShadowHost(*found), 0, event);
    464459        return foundInInnerFocusScope ? foundInInnerFocusScope : found;
    465460    }
    466461    if (isNonFocusableShadowHost(*found, *event)) {
    467         Element* foundInInnerFocusScope = findFocusableElementRecursively(direction, FocusNavigationScope::focusNavigationScopeOwnedByShadowHost(found), 0, event);
     462        Element* foundInInnerFocusScope = findFocusableElementRecursively(direction, FocusNavigationScope::scopeOwnedByShadowHost(*found), 0, event);
    468463        return foundInInnerFocusScope ? foundInInnerFocusScope :findFocusableElementRecursively(direction, scope, found, event);
    469464    }
     
    496491    int winningTabIndex = std::numeric_limits<short>::max() + 1;
    497492    Element* winner = nullptr;
    498     for (Node* node = scope.rootNode(); node; node = scope.nextInScope(node)) {
     493    for (Node* node = &scope.rootNode(); node; node = scope.nextInScope(node)) {
    499494        if (!is<Element>(*node))
    500495            continue;
     
    530525{
    531526    Ref<KeyboardEvent> keyEvent = KeyboardEvent::createForDummy();
    532     return nextFocusableElement(FocusNavigationScope::focusNavigationScopeOf(&start), &start, keyEvent.ptr());
     527    return nextFocusableElement(FocusNavigationScope::scopeOf(start), &start, keyEvent.ptr());
    533528}
    534529
     
    536531{
    537532    Ref<KeyboardEvent> keyEvent = KeyboardEvent::createForDummy();
    538     return previousFocusableElement(FocusNavigationScope::focusNavigationScopeOf(&start), &start, keyEvent.ptr());
     533    return previousFocusableElement(FocusNavigationScope::scopeOf(start), &start, keyEvent.ptr());
    539534}
    540535
     
    571566    // There are no nodes with a tabindex greater than start's tabindex,
    572567    // so find the first node with a tabindex of 0.
    573     return findElementWithExactTabIndex(scope, scope.rootNode(), 0, event, FocusDirectionForward);
     568    return findElementWithExactTabIndex(scope, &scope.rootNode(), 0, event, FocusDirectionForward);
    574569}
    575570
     
    577572{
    578573    Node* last = nullptr;
    579     for (Node* node = scope.rootNode(); node; node = scope.lastChildInScope(node))
     574    for (Node* node = &scope.rootNode(); node; node = scope.lastChildInScope(node))
    580575        last = node;
    581576    ASSERT(last);
Note: See TracChangeset for help on using the changeset viewer.