Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(533)

Side by Side Diff: Source/core/page/FocusController.cpp

Issue 235553006: Move Document pointer from Frame to LocalFrame. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Nuanti Ltd. 3 * Copyright (C) 2008 Nuanti Ltd.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 } 113 }
114 114
115 FocusNavigationScope FocusNavigationScope::ownedByShadowHost(Node* node) 115 FocusNavigationScope FocusNavigationScope::ownedByShadowHost(Node* node)
116 { 116 {
117 ASSERT(isShadowHost(node)); 117 ASSERT(isShadowHost(node));
118 return FocusNavigationScope(toElement(node)->shadow()->youngestShadowRoot()) ; 118 return FocusNavigationScope(toElement(node)->shadow()->youngestShadowRoot()) ;
119 } 119 }
120 120
121 FocusNavigationScope FocusNavigationScope::ownedByIFrame(HTMLFrameOwnerElement* frame) 121 FocusNavigationScope FocusNavigationScope::ownedByIFrame(HTMLFrameOwnerElement* frame)
122 { 122 {
123 ASSERT(frame && frame->contentFrame()); 123 ASSERT(frame && frame->contentFrame() && frame->contentFrame()->isLocalFrame ());
124 return FocusNavigationScope(frame->contentFrame()->document()); 124 return FocusNavigationScope(toLocalFrame(frame->contentFrame())->document()) ;
125 } 125 }
126 126
127 FocusNavigationScope FocusNavigationScope::ownedByShadowInsertionPoint(HTMLShado wElement* shadowInsertionPoint) 127 FocusNavigationScope FocusNavigationScope::ownedByShadowInsertionPoint(HTMLShado wElement* shadowInsertionPoint)
128 { 128 {
129 ASSERT(isShadowInsertionPointFocusScopeOwner(*shadowInsertionPoint)); 129 ASSERT(isShadowInsertionPointFocusScopeOwner(*shadowInsertionPoint));
130 return FocusNavigationScope(shadowInsertionPoint->olderShadowRoot()); 130 return FocusNavigationScope(shadowInsertionPoint->olderShadowRoot());
131 } 131 }
132 132
133 static inline void dispatchEventsOnWindowAndFocusedNode(Document* document, bool focused) 133 static inline void dispatchEventsOnWindowAndFocusedNode(Document* document, bool focused)
134 { 134 {
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 } 290 }
291 } 291 }
292 292
293 Node* FocusController::findFocusableNodeDecendingDownIntoFrameDocument(FocusType type, Node* node) 293 Node* FocusController::findFocusableNodeDecendingDownIntoFrameDocument(FocusType type, Node* node)
294 { 294 {
295 // The node we found might be a HTMLFrameOwnerElement, so descend down the t ree until we find either: 295 // The node we found might be a HTMLFrameOwnerElement, so descend down the t ree until we find either:
296 // 1) a focusable node, or 296 // 1) a focusable node, or
297 // 2) the deepest-nested HTMLFrameOwnerElement. 297 // 2) the deepest-nested HTMLFrameOwnerElement.
298 while (node && node->isFrameOwnerElement()) { 298 while (node && node->isFrameOwnerElement()) {
299 HTMLFrameOwnerElement* owner = toHTMLFrameOwnerElement(node); 299 HTMLFrameOwnerElement* owner = toHTMLFrameOwnerElement(node);
300 if (!owner->contentFrame()) 300 if (!owner->contentFrame() || !owner->contentFrame()->isLocalFrame())
dcheng 2014/04/14 19:25:57 This means we'll stop searching as soon as we hit
kenrb 2014/04/14 20:09:52 Yes we are treating the remote frame as a focused
301 break; 301 break;
302 Node* foundNode = findFocusableNode(type, FocusNavigationScope::ownedByI Frame(owner), 0); 302 Node* foundNode = findFocusableNode(type, FocusNavigationScope::ownedByI Frame(owner), 0);
303 if (!foundNode) 303 if (!foundNode)
304 break; 304 break;
305 ASSERT(node != foundNode); 305 ASSERT(node != foundNode);
306 node = foundNode; 306 node = foundNode;
307 } 307 }
308 return node; 308 return node;
309 } 309 }
310 310
311 bool FocusController::setInitialFocus(FocusType type) 311 bool FocusController::setInitialFocus(FocusType type)
312 { 312 {
313 bool didAdvanceFocus = advanceFocus(type, true); 313 bool didAdvanceFocus = advanceFocus(type, true);
314 314
315 // If focus is being set initially, accessibility needs to be informed that system focus has moved 315 // If focus is being set initially, accessibility needs to be informed that system focus has moved
316 // into the web area again, even if focus did not change within WebCore. Pos tNotification is called instead 316 // into the web area again, even if focus did not change within WebCore. Pos tNotification is called instead
317 // of handleFocusedUIElementChanged, because this will send the notification even if the element is the same. 317 // of handleFocusedUIElementChanged, because this will send the notification even if the element is the same.
318 if (AXObjectCache* cache = focusedOrMainFrame()->document()->existingAXObjec tCache()) 318 if (focusedOrMainFrame()->isLocalFrame()) {
319 cache->postNotification(focusedOrMainFrame()->document(), AXObjectCache: :AXFocusedUIElementChanged, true); 319 Document* document = toLocalFrame(focusedOrMainFrame())->document();
320 if (AXObjectCache* cache = document->existingAXObjectCache())
321 cache->postNotification(document, AXObjectCache::AXFocusedUIElementC hanged, true);
322 }
320 323
321 return didAdvanceFocus; 324 return didAdvanceFocus;
322 } 325 }
323 326
324 bool FocusController::advanceFocus(FocusType type, bool initialFocus) 327 bool FocusController::advanceFocus(FocusType type, bool initialFocus)
325 { 328 {
326 switch (type) { 329 switch (type) {
327 case FocusTypeForward: 330 case FocusTypeForward:
328 case FocusTypeBackward: 331 case FocusTypeBackward:
329 return advanceFocusInDocumentOrder(type, initialFocus); 332 return advanceFocusInDocumentOrder(type, initialFocus);
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 645
643 // FIXME: Might want to disable this check for caretBrowsing 646 // FIXME: Might want to disable this check for caretBrowsing
644 if (oldFocusedElement && oldFocusedElement->isRootEditableElement() && !reli nquishesEditingFocus(oldFocusedElement)) 647 if (oldFocusedElement && oldFocusedElement->isRootEditableElement() && !reli nquishesEditingFocus(oldFocusedElement))
645 return false; 648 return false;
646 649
647 m_page->chrome().client().willSetInputMethodState(); 650 m_page->chrome().client().willSetInputMethodState();
648 651
649 RefPtr<Document> newDocument; 652 RefPtr<Document> newDocument;
650 if (element) 653 if (element)
651 newDocument = &element->document(); 654 newDocument = &element->document();
652 else if (newFocusedFrame) 655 else if (newFocusedFrame && newFocusedFrame->isLocalFrame())
653 newDocument = newFocusedFrame->document(); 656 newDocument = toLocalFrame(newFocusedFrame.get())->document();
dcheng 2014/04/14 19:25:57 Do you happen to know if these codepaths like this
kenrb 2014/04/14 20:09:52 This code only changes behavior for cross-site ifr
654 657
655 if (newDocument && oldDocument == newDocument && newDocument->focusedElement () == element) 658 if (newDocument && oldDocument == newDocument && newDocument->focusedElement () == element)
656 return true; 659 return true;
657 660
658 clearSelectionIfNeeded(oldFocusedFrame.get(), toLocalFrame(newFocusedFrame.g et()), element); 661 clearSelectionIfNeeded(oldFocusedFrame.get(), toLocalFrame(newFocusedFrame.g et()), element);
659 662
660 if (oldDocument && oldDocument != newDocument) 663 if (oldDocument && oldDocument != newDocument)
661 oldDocument->setFocusedElement(nullptr); 664 oldDocument->setFocusedElement(nullptr);
662 665
663 if (newFocusedFrame && !newFocusedFrame->page()) { 666 if (newFocusedFrame && !newFocusedFrame->page()) {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 closest = candidate; 777 closest = candidate;
775 return; 778 return;
776 } 779 }
777 780
778 if (candidate.alignment > closest.alignment) 781 if (candidate.alignment > closest.alignment)
779 closest = candidate; 782 closest = candidate;
780 } 783 }
781 784
782 void FocusController::findFocusCandidateInContainer(Node& container, const Layou tRect& startingRect, FocusType type, FocusCandidate& closest) 785 void FocusController::findFocusCandidateInContainer(Node& container, const Layou tRect& startingRect, FocusType type, FocusCandidate& closest)
783 { 786 {
784 Element* focusedElement = (focusedFrame() && focusedFrame()->document()) ? f ocusedFrame()->document()->focusedElement() : 0; 787 Element* focusedElement = (focusedFrame() && toLocalFrame(focusedFrame())->d ocument()) ? toLocalFrame(focusedFrame())->document()->focusedElement() : 0;
dcheng 2014/04/14 19:25:57 Are we skipping the isLocalFrame() check here beca
kenrb 2014/04/14 20:09:52 I think that assumption is correct, but I put a ba
dcheng 2014/04/14 21:09:29 I don't see any changes, so maybe you didn't uploa
kenrb 2014/04/15 14:20:44 Sorry if I wasn't clear. The check already exists,
785 788
786 Element* element = ElementTraversal::firstWithin(container); 789 Element* element = ElementTraversal::firstWithin(container);
787 FocusCandidate current; 790 FocusCandidate current;
788 current.rect = startingRect; 791 current.rect = startingRect;
789 current.focusableNode = focusedElement; 792 current.focusableNode = focusedElement;
790 current.visibleNode = focusedElement; 793 current.visibleNode = focusedElement;
791 794
792 for (; element; element = (element->isFrameOwnerElement() || canScrollInDire ction(element, type)) 795 for (; element; element = (element->isFrameOwnerElement() || canScrollInDire ction(element, type))
793 ? ElementTraversal::nextSkippingChildren(*element, &container) 796 ? ElementTraversal::nextSkippingChildren(*element, &container)
794 : ElementTraversal::next(*element, &container)) { 797 : ElementTraversal::next(*element, &container)) {
(...skipping 26 matching lines...) Expand all
821 FocusCandidate focusCandidate; 824 FocusCandidate focusCandidate;
822 findFocusCandidateInContainer(*container, newStartingRect, type, focusCandid ate); 825 findFocusCandidateInContainer(*container, newStartingRect, type, focusCandid ate);
823 826
824 if (focusCandidate.isNull()) { 827 if (focusCandidate.isNull()) {
825 // Nothing to focus, scroll if possible. 828 // Nothing to focus, scroll if possible.
826 // NOTE: If no scrolling is performed (i.e. scrollInDirection returns fa lse), the 829 // NOTE: If no scrolling is performed (i.e. scrollInDirection returns fa lse), the
827 // spatial navigation algorithm will skip this container. 830 // spatial navigation algorithm will skip this container.
828 return scrollInDirection(container, type); 831 return scrollInDirection(container, type);
829 } 832 }
830 833
831 if (HTMLFrameOwnerElement* frameElement = frameOwnerElement(focusCandidate)) { 834 HTMLFrameOwnerElement* frameElement = frameOwnerElement(focusCandidate);
dcheng 2014/04/14 19:25:57 Why was this if removed?
kenrb 2014/04/14 20:09:52 It wasn't, it was just moved lower -- line 839 in
832 // If we have an iframe without the src attribute, it will not have a co ntentFrame(). 835 // If we have an iframe without the src attribute, it will not have a conten tFrame().
833 // We ASSERT here to make sure that 836 // We ASSERT here to make sure that
834 // updateFocusCandidateIfNeeded() will never consider such an iframe as a candidate. 837 // updateFocusCandidateIfNeeded() will never consider such an iframe as a ca ndidate.
835 ASSERT(frameElement->contentFrame()); 838 ASSERT(!frameElement || frameElement->contentFrame());
836 839 if (frameElement && frameElement->contentFrame()->isLocalFrame()) {
837 if (focusCandidate.isOffscreenAfterScrolling) { 840 if (focusCandidate.isOffscreenAfterScrolling) {
838 scrollInDirection(&focusCandidate.visibleNode->document(), type); 841 scrollInDirection(&focusCandidate.visibleNode->document(), type);
839 return true; 842 return true;
840 } 843 }
841 // Navigate into a new frame. 844 // Navigate into a new frame.
842 LayoutRect rect; 845 LayoutRect rect;
843 Element* focusedElement = focusedOrMainFrame()->document()->focusedEleme nt(); 846 Element* focusedElement = toLocalFrame(focusedOrMainFrame())->document() ->focusedElement();
844 if (focusedElement && !hasOffscreenRect(focusedElement)) 847 if (focusedElement && !hasOffscreenRect(focusedElement))
845 rect = nodeRectInAbsoluteCoordinates(focusedElement, true /* ignore border */); 848 rect = nodeRectInAbsoluteCoordinates(focusedElement, true /* ignore border */);
846 frameElement->contentFrame()->document()->updateLayoutIgnorePendingStyle sheets(); 849 toLocalFrame(frameElement->contentFrame())->document()->updateLayoutIgno rePendingStylesheets();
847 if (!advanceFocusDirectionallyInContainer(frameElement->contentFrame()-> document(), rect, type)) { 850 if (!advanceFocusDirectionallyInContainer(toLocalFrame(frameElement->con tentFrame())->document(), rect, type)) {
848 // The new frame had nothing interesting, need to find another candi date. 851 // The new frame had nothing interesting, need to find another candi date.
849 return advanceFocusDirectionallyInContainer(container, nodeRectInAbs oluteCoordinates(focusCandidate.visibleNode, true), type); 852 return advanceFocusDirectionallyInContainer(container, nodeRectInAbs oluteCoordinates(focusCandidate.visibleNode, true), type);
850 } 853 }
851 return true; 854 return true;
852 } 855 }
853 856
854 if (canScrollInDirection(focusCandidate.visibleNode, type)) { 857 if (canScrollInDirection(focusCandidate.visibleNode, type)) {
855 if (focusCandidate.isOffscreenAfterScrolling) { 858 if (focusCandidate.isOffscreenAfterScrolling) {
856 scrollInDirection(focusCandidate.visibleNode, type); 859 scrollInDirection(focusCandidate.visibleNode, type);
857 return true; 860 return true;
858 } 861 }
859 // Navigate into a new scrollable container. 862 // Navigate into a new scrollable container.
860 LayoutRect startingRect; 863 LayoutRect startingRect;
861 Element* focusedElement = focusedOrMainFrame()->document()->focusedEleme nt(); 864 Element* focusedElement = toLocalFrame(focusedOrMainFrame())->document() ->focusedElement();
dcheng 2014/04/14 19:25:57 Does this need to be protected by an isLocalFrame(
kenrb 2014/04/14 20:09:52 Same comment as above re: directional focus advanc
862 if (focusedElement && !hasOffscreenRect(focusedElement)) 865 if (focusedElement && !hasOffscreenRect(focusedElement))
863 startingRect = nodeRectInAbsoluteCoordinates(focusedElement, true); 866 startingRect = nodeRectInAbsoluteCoordinates(focusedElement, true);
864 return advanceFocusDirectionallyInContainer(focusCandidate.visibleNode, startingRect, type); 867 return advanceFocusDirectionallyInContainer(focusCandidate.visibleNode, startingRect, type);
865 } 868 }
866 if (focusCandidate.isOffscreenAfterScrolling) { 869 if (focusCandidate.isOffscreenAfterScrolling) {
867 Node* container = focusCandidate.enclosingScrollableBox; 870 Node* container = focusCandidate.enclosingScrollableBox;
868 scrollInDirection(container, type); 871 scrollInDirection(container, type);
869 return true; 872 return true;
870 } 873 }
871 874
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 startingRect = nodeRectInAbsoluteCoordinates(container, true /* ignore b order */); 917 startingRect = nodeRectInAbsoluteCoordinates(container, true /* ignore b order */);
915 container = scrollableEnclosingBoxOrParentFrameForNodeInDirection(type, container); 918 container = scrollableEnclosingBoxOrParentFrameForNodeInDirection(type, container);
916 if (container && container->isDocumentNode()) 919 if (container && container->isDocumentNode())
917 toDocument(container)->updateLayoutIgnorePendingStylesheets(); 920 toDocument(container)->updateLayoutIgnorePendingStylesheets();
918 } while (!consumed && container); 921 } while (!consumed && container);
919 922
920 return consumed; 923 return consumed;
921 } 924 }
922 925
923 } // namespace WebCore 926 } // namespace WebCore
OLDNEW
« Source/core/frame/LocalFrame.cpp ('K') | « Source/core/page/EventHandler.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698