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

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

Issue 1804943002: Remove a wrong assert and use Document directly, instead of documentElement() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 STACK_ALLOCATED(); 75 STACK_ALLOCATED();
76 public: 76 public:
77 Element* currentElement() const; 77 Element* currentElement() const;
78 void setCurrentElement(Element*); 78 void setCurrentElement(Element*);
79 void moveToNext(); 79 void moveToNext();
80 void moveToPrevious(); 80 void moveToPrevious();
81 void moveToFirst(); 81 void moveToFirst();
82 void moveToLast(); 82 void moveToLast();
83 Element* owner() const; 83 Element* owner() const;
84 static ScopedFocusNavigation createScopedFocusNavigation(const Element& root , const Element* current); 84 static ScopedFocusNavigation createScopedFocusNavigation(const Element& root , const Element* current);
85 static ScopedFocusNavigation createScopedFocusNavigationForDocument(Document &);
85 static ScopedFocusNavigation ownedByNonFocusableFocusScopeOwner(Element&); 86 static ScopedFocusNavigation ownedByNonFocusableFocusScopeOwner(Element&);
86 static ScopedFocusNavigation ownedByShadowHost(const Element&); 87 static ScopedFocusNavigation ownedByShadowHost(const Element&);
87 static ScopedFocusNavigation ownedByShadowInsertionPoint(HTMLShadowElement&) ; 88 static ScopedFocusNavigation ownedByShadowInsertionPoint(HTMLShadowElement&) ;
88 static ScopedFocusNavigation ownedByHTMLSlotElement(const HTMLSlotElement&); 89 static ScopedFocusNavigation ownedByHTMLSlotElement(const HTMLSlotElement&);
89 static ScopedFocusNavigation ownedByIFrame(const HTMLFrameOwnerElement&); 90 static ScopedFocusNavigation ownedByIFrame(const HTMLFrameOwnerElement&);
90 91
91 private: 92 private:
92 ScopedFocusNavigation(TreeScope&, const Element*); 93 ScopedFocusNavigation(TreeScope&, const Element*);
93 ScopedFocusNavigation(HTMLSlotElement&, const Element*); 94 ScopedFocusNavigation(HTMLSlotElement&, const Element*);
94 RawPtrWillBeMember<ContainerNode> m_rootNode; 95 RawPtrWillBeMember<ContainerNode> m_rootNode;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 // FIXME: Figure out the right thing for OOPI here. 200 // FIXME: Figure out the right thing for OOPI here.
200 if (Frame* frame = m_rootNode->document().frame()) 201 if (Frame* frame = m_rootNode->document().frame())
201 return frame->deprecatedLocalOwner(); 202 return frame->deprecatedLocalOwner();
202 return nullptr; 203 return nullptr;
203 } 204 }
204 205
205 ScopedFocusNavigation ScopedFocusNavigation::createScopedFocusNavigation(const E lement& root, const Element* current) 206 ScopedFocusNavigation ScopedFocusNavigation::createScopedFocusNavigation(const E lement& root, const Element* current)
206 { 207 {
207 if (SlotScopedTraversal::isSlotScoped(root)) 208 if (SlotScopedTraversal::isSlotScoped(root))
208 return ScopedFocusNavigation(*SlotScopedTraversal::findScopeOwnerSlot(ro ot), current); 209 return ScopedFocusNavigation(*SlotScopedTraversal::findScopeOwnerSlot(ro ot), current);
209 return ScopedFocusNavigation(*&root.treeScope(), current); 210 return ScopedFocusNavigation(root.treeScope(), current);
211 }
212
213 ScopedFocusNavigation ScopedFocusNavigation::createScopedFocusNavigationForDocum ent(Document& document)
214 {
215 return ScopedFocusNavigation(document, nullptr);
210 } 216 }
211 217
212 ScopedFocusNavigation ScopedFocusNavigation::ownedByNonFocusableFocusScopeOwner( Element& element) 218 ScopedFocusNavigation ScopedFocusNavigation::ownedByNonFocusableFocusScopeOwner( Element& element)
213 { 219 {
214 if (isShadowHost(element)) 220 if (isShadowHost(element))
215 return ScopedFocusNavigation::ownedByShadowHost(element); 221 return ScopedFocusNavigation::ownedByShadowHost(element);
216 if (isShadowInsertionPointFocusScopeOwner(element)) 222 if (isShadowInsertionPointFocusScopeOwner(element))
217 return ScopedFocusNavigation::ownedByShadowInsertionPoint(toHTMLShadowEl ement(element)); 223 return ScopedFocusNavigation::ownedByShadowInsertionPoint(toHTMLShadowEl ement(element));
218 ASSERT(isHTMLSlotElement(element)); 224 ASSERT(isHTMLSlotElement(element));
219 return ScopedFocusNavigation::ownedByHTMLSlotElement(toHTMLSlotElement(eleme nt)); 225 return ScopedFocusNavigation::ownedByHTMLSlotElement(toHTMLSlotElement(eleme nt));
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 start = toHTMLFrameOwnerElement(from->owner()); 849 start = toHTMLFrameOwnerElement(from->owner());
844 } 850 }
845 851
846 return advanceFocusInDocumentOrder(to, start, type, false, sourceCapabilitie s); 852 return advanceFocusInDocumentOrder(to, start, type, false, sourceCapabilitie s);
847 } 853 }
848 854
849 bool FocusController::advanceFocusInDocumentOrder(LocalFrame* frame, Element* st art, WebFocusType type, bool initialFocus, InputDeviceCapabilities* sourceCapabi lities) 855 bool FocusController::advanceFocusInDocumentOrder(LocalFrame* frame, Element* st art, WebFocusType type, bool initialFocus, InputDeviceCapabilities* sourceCapabi lities)
850 { 856 {
851 ASSERT(frame); 857 ASSERT(frame);
852 Document* document = frame->document(); 858 Document* document = frame->document();
853 ASSERT(document->documentElement());
854 document->updateDistribution(); 859 document->updateDistribution();
855 860
856 Element* current = start; 861 Element* current = start;
857 if (!current && !initialFocus) 862 if (!current && !initialFocus)
858 current = document->sequentialFocusNavigationStartingPoint(type); 863 current = document->sequentialFocusNavigationStartingPoint(type);
859 864
860 // FIXME: Not quite correct when it comes to focus transitions leaving/enter ing the WebView itself 865 // FIXME: Not quite correct when it comes to focus transitions leaving/enter ing the WebView itself
861 bool caretBrowsing = frame->settings() && frame->settings()->caretBrowsingEn abled(); 866 bool caretBrowsing = frame->settings() && frame->settings()->caretBrowsingEn abled();
862 867
863 if (caretBrowsing && !current) 868 if (caretBrowsing && !current)
864 current = adjustToElement(frame->selection().start().anchorNode(), type) ; 869 current = adjustToElement(frame->selection().start().anchorNode(), type) ;
865 870
866 document->updateLayoutIgnorePendingStylesheets(); 871 document->updateLayoutIgnorePendingStylesheets();
867 ScopedFocusNavigation scope = ScopedFocusNavigation::createScopedFocusNaviga tion(current ? *current : *document->documentElement(), current); 872 ScopedFocusNavigation scope = current ? ScopedFocusNavigation::createScopedF ocusNavigation(*current, current) : ScopedFocusNavigation::createScopedFocusNavi gationForDocument(*document);
868 RefPtrWillBeRawPtr<Element> element = findFocusableElementAcrossFocusScopes( type, scope); 873 RefPtrWillBeRawPtr<Element> element = findFocusableElementAcrossFocusScopes( type, scope);
869 874
870 if (!element) { 875 if (!element) {
871 // If there's a RemoteFrame on the ancestor chain, we need to continue 876 // If there's a RemoteFrame on the ancestor chain, we need to continue
872 // searching for focusable elements there. 877 // searching for focusable elements there.
873 if (frame->localFrameRoot() != frame->tree().top()) { 878 if (frame->localFrameRoot() != frame->tree().top()) {
874 document->clearFocusedElement(); 879 document->clearFocusedElement();
875 document->setSequentialFocusNavigationStartingPoint(nullptr); 880 document->setSequentialFocusNavigationStartingPoint(nullptr);
876 toRemoteFrame(frame->localFrameRoot()->tree().parent())->advanceFocu s(type, frame->localFrameRoot()); 881 toRemoteFrame(frame->localFrameRoot()->tree().parent())->advanceFocu s(type, frame->localFrameRoot());
877 return true; 882 return true;
878 } 883 }
879 884
880 // We didn't find an element to focus, so we should try to pass focus to Chrome. 885 // We didn't find an element to focus, so we should try to pass focus to Chrome.
881 if (!initialFocus && m_page->chromeClient().canTakeFocus(type)) { 886 if (!initialFocus && m_page->chromeClient().canTakeFocus(type)) {
882 document->clearFocusedElement(); 887 document->clearFocusedElement();
883 document->setSequentialFocusNavigationStartingPoint(nullptr); 888 document->setSequentialFocusNavigationStartingPoint(nullptr);
884 setFocusedFrame(nullptr); 889 setFocusedFrame(nullptr);
885 m_page->chromeClient().takeFocus(type); 890 m_page->chromeClient().takeFocus(type);
886 return true; 891 return true;
887 } 892 }
888 893
889 // Chrome doesn't want focus, so we should wrap focus. 894 // Chrome doesn't want focus, so we should wrap focus.
890 ScopedFocusNavigation scope = ScopedFocusNavigation::createScopedFocusNa vigation(*toLocalFrame(m_page->mainFrame())->document()->documentElement(), null ptr); 895 ScopedFocusNavigation scope = ScopedFocusNavigation::createScopedFocusNa vigationForDocument(*toLocalFrame(m_page->mainFrame())->document());
891 element = findFocusableElementRecursively(type, scope); 896 element = findFocusableElementRecursively(type, scope);
892 element = findFocusableElementDescendingDownIntoFrameDocument(type, elem ent.get()); 897 element = findFocusableElementDescendingDownIntoFrameDocument(type, elem ent.get());
893 898
894 if (!element) 899 if (!element)
895 return false; 900 return false;
896 } 901 }
897 902
898 ASSERT(element); 903 ASSERT(element);
899 904
900 if (element == document->focusedElement()) { 905 if (element == document->focusedElement()) {
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
1252 return consumed; 1257 return consumed;
1253 } 1258 }
1254 1259
1255 DEFINE_TRACE(FocusController) 1260 DEFINE_TRACE(FocusController)
1256 { 1261 {
1257 visitor->trace(m_page); 1262 visitor->trace(m_page);
1258 visitor->trace(m_focusedFrame); 1263 visitor->trace(m_focusedFrame);
1259 } 1264 }
1260 1265
1261 } // namespace blink 1266 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698