Changeset 197055 in webkit
- Timestamp:
- Feb 24, 2016 3:37:51 PM (8 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r197053 r197055 1 2016-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 1 26 2016-02-24 Adam Bergkvist <adam.bergkvist@ericsson.com> 2 27 -
trunk/Source/WebCore/page/FocusController.cpp
r197021 r197055 70 70 class FocusNavigationScope { 71 71 public: 72 ContainerNode *rootNode() const;72 ContainerNode& rootNode() const; 73 73 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&); 77 77 78 78 Node* nextInScope(const Node*) const; … … 83 83 Node* firstChildInScope(const Node*) const; 84 84 85 explicit FocusNavigationScope(TreeScope *);86 TreeScope *m_rootTreeScope;85 explicit FocusNavigationScope(TreeScope&); 86 TreeScope& m_rootTreeScope; 87 87 }; 88 88 … … 138 138 } 139 139 140 FocusNavigationScope::FocusNavigationScope(TreeScope *treeScope)140 FocusNavigationScope::FocusNavigationScope(TreeScope& treeScope) 141 141 : m_rootTreeScope(treeScope) 142 142 { 143 ASSERT(treeScope); 144 } 145 146 ContainerNode* FocusNavigationScope::rootNode() const 147 { 148 return &m_rootTreeScope->rootNode(); 143 } 144 145 ContainerNode& FocusNavigationScope::rootNode() const 146 { 147 return m_rootTreeScope.rootNode(); 149 148 } 150 149 151 150 Element* FocusNavigationScope::owner() const 152 151 { 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()) 157 156 return frame->ownerElement(); 158 157 return nullptr; 159 158 } 160 159 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; 160 FocusNavigationScope FocusNavigationScope::scopeOf(Node& startingNode) 161 { 162 Node* root = nullptr; 163 for (Node* currentNode = &startingNode; currentNode; currentNode = parentInScope(currentNode)) 164 root = currentNode; 167 165 // The result is not always a ShadowRoot nor a DocumentNode since 168 166 // 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 170 FocusNavigationScope FocusNavigationScope::scopeOwnedByShadowHost(Element& element) 171 { 172 ASSERT(element.shadowRoot()); 173 return FocusNavigationScope(*element.shadowRoot()); 174 } 175 176 FocusNavigationScope FocusNavigationScope::scopeOwnedByIFrame(HTMLFrameOwnerElement& frame) 177 { 178 ASSERT(frame.contentFrame()); 179 ASSERT(frame.contentFrame()->document()); 180 return FocusNavigationScope(*frame.contentFrame()->document()); 184 181 } 185 182 … … 302 299 if (!owner.contentFrame()) 303 300 break; 304 Element* foundElement = findFocusableElement(direction, FocusNavigationScope:: focusNavigationScopeOwnedByIFrame(&owner), 0, event);301 Element* foundElement = findFocusableElement(direction, FocusNavigationScope::scopeOwnedByIFrame(owner), 0, event); 305 302 if (!foundElement) 306 303 break; … … 356 353 document->updateLayoutIgnorePendingStylesheets(); 357 354 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); 359 356 360 357 if (!element) { … … 368 365 369 366 // 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); 371 368 element = findFocusableElementDescendingDownIntoFrameDocument(direction, element.get(), event); 372 369 … … 425 422 Element* found; 426 423 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); 428 425 found = foundInInnerFocusScope ? foundInInnerFocusScope : findFocusableElementRecursively(direction, scope, currentNode, event); 429 426 } else … … 431 428 432 429 // 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); 439 433 if (direction == FocusDirectionBackward && isFocusableShadowHost(*owner, *event)) { 440 434 found = owner; … … 442 436 } 443 437 found = findFocusableElementRecursively(direction, currentScope, owner, event); 438 owner = currentScope.owner(); 444 439 } 445 440 found = findFocusableElementDescendingDownIntoFrameDocument(direction, found, event); … … 456 451 if (!isNonFocusableShadowHost(*found, *event)) 457 452 return found; 458 Element* foundInInnerFocusScope = findFocusableElementRecursively(direction, FocusNavigationScope:: focusNavigationScopeOwnedByShadowHost(found), 0, event);453 Element* foundInInnerFocusScope = findFocusableElementRecursively(direction, FocusNavigationScope::scopeOwnedByShadowHost(*found), 0, event); 459 454 return foundInInnerFocusScope ? foundInInnerFocusScope : findFocusableElementRecursively(direction, scope, found, event); 460 455 } 461 456 ASSERT(direction == FocusDirectionBackward); 462 457 if (isFocusableShadowHost(*found, *event)) { 463 Element* foundInInnerFocusScope = findFocusableElementRecursively(direction, FocusNavigationScope:: focusNavigationScopeOwnedByShadowHost(found), 0, event);458 Element* foundInInnerFocusScope = findFocusableElementRecursively(direction, FocusNavigationScope::scopeOwnedByShadowHost(*found), 0, event); 464 459 return foundInInnerFocusScope ? foundInInnerFocusScope : found; 465 460 } 466 461 if (isNonFocusableShadowHost(*found, *event)) { 467 Element* foundInInnerFocusScope = findFocusableElementRecursively(direction, FocusNavigationScope:: focusNavigationScopeOwnedByShadowHost(found), 0, event);462 Element* foundInInnerFocusScope = findFocusableElementRecursively(direction, FocusNavigationScope::scopeOwnedByShadowHost(*found), 0, event); 468 463 return foundInInnerFocusScope ? foundInInnerFocusScope :findFocusableElementRecursively(direction, scope, found, event); 469 464 } … … 496 491 int winningTabIndex = std::numeric_limits<short>::max() + 1; 497 492 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)) { 499 494 if (!is<Element>(*node)) 500 495 continue; … … 530 525 { 531 526 Ref<KeyboardEvent> keyEvent = KeyboardEvent::createForDummy(); 532 return nextFocusableElement(FocusNavigationScope:: focusNavigationScopeOf(&start), &start, keyEvent.ptr());527 return nextFocusableElement(FocusNavigationScope::scopeOf(start), &start, keyEvent.ptr()); 533 528 } 534 529 … … 536 531 { 537 532 Ref<KeyboardEvent> keyEvent = KeyboardEvent::createForDummy(); 538 return previousFocusableElement(FocusNavigationScope:: focusNavigationScopeOf(&start), &start, keyEvent.ptr());533 return previousFocusableElement(FocusNavigationScope::scopeOf(start), &start, keyEvent.ptr()); 539 534 } 540 535 … … 571 566 // There are no nodes with a tabindex greater than start's tabindex, 572 567 // 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); 574 569 } 575 570 … … 577 572 { 578 573 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)) 580 575 last = node; 581 576 ASSERT(last);
Note: See TracChangeset
for help on using the changeset viewer.