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

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

Issue 1686483002: Oilpan: Remove most WillBe types from the code base (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 Node* rootNode() const; 75 Node* rootNode() const;
76 Element* owner() const; 76 Element* owner() const;
77 static FocusNavigationScope focusNavigationScopeOf(const Node&); 77 static FocusNavigationScope focusNavigationScopeOf(const Node&);
78 static FocusNavigationScope ownedByNonFocusableFocusScopeOwner(Element&); 78 static FocusNavigationScope ownedByNonFocusableFocusScopeOwner(Element&);
79 static FocusNavigationScope ownedByShadowHost(const Element&); 79 static FocusNavigationScope ownedByShadowHost(const Element&);
80 static FocusNavigationScope ownedByShadowInsertionPoint(HTMLShadowElement&); 80 static FocusNavigationScope ownedByShadowInsertionPoint(HTMLShadowElement&);
81 static FocusNavigationScope ownedByIFrame(const HTMLFrameOwnerElement&); 81 static FocusNavigationScope ownedByIFrame(const HTMLFrameOwnerElement&);
82 82
83 private: 83 private:
84 explicit FocusNavigationScope(TreeScope*); 84 explicit FocusNavigationScope(TreeScope*);
85 RawPtrWillBeMember<TreeScope> m_rootTreeScope; 85 Member<TreeScope> m_rootTreeScope;
86 }; 86 };
87 87
88 FocusNavigationScope::FocusNavigationScope(TreeScope* treeScope) 88 FocusNavigationScope::FocusNavigationScope(TreeScope* treeScope)
89 : m_rootTreeScope(treeScope) 89 : m_rootTreeScope(treeScope)
90 { 90 {
91 ASSERT(treeScope); 91 ASSERT(treeScope);
92 } 92 }
93 93
94 Node* FocusNavigationScope::rootNode() const 94 Node* FocusNavigationScope::rootNode() const
95 { 95 {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 if (document->focusedElement() && isHTMLPlugInElement(document->focusedEleme nt())) 176 if (document->focusedElement() && isHTMLPlugInElement(document->focusedEleme nt()))
177 toHTMLPlugInElement(document->focusedElement())->setPluginFocus(focused) ; 177 toHTMLPlugInElement(document->focusedElement())->setPluginFocus(focused) ;
178 178
179 // Do not fire events while modal dialogs are up. See https://bugs.webkit.o rg/show_bug.cgi?id=33962 179 // Do not fire events while modal dialogs are up. See https://bugs.webkit.o rg/show_bug.cgi?id=33962
180 if (Page* page = document->page()) { 180 if (Page* page = document->page()) {
181 if (page->defersLoading()) 181 if (page->defersLoading())
182 return; 182 return;
183 } 183 }
184 184
185 if (!focused && document->focusedElement()) { 185 if (!focused && document->focusedElement()) {
186 RefPtrWillBeRawPtr<Element> focusedElement(document->focusedElement()); 186 RawPtr<Element> focusedElement(document->focusedElement());
187 focusedElement->setFocus(false); 187 focusedElement->setFocus(false);
188 dispatchBlurEvent(*document, *focusedElement); 188 dispatchBlurEvent(*document, *focusedElement);
189 } 189 }
190 190
191 if (LocalDOMWindow* window = document->domWindow()) 191 if (LocalDOMWindow* window = document->domWindow())
192 window->dispatchEvent(Event::create(focused ? EventTypeNames::focus : Ev entTypeNames::blur)); 192 window->dispatchEvent(Event::create(focused ? EventTypeNames::focus : Ev entTypeNames::blur));
193 if (focused && document->focusedElement()) { 193 if (focused && document->focusedElement()) {
194 RefPtrWillBeRawPtr<Element> focusedElement(document->focusedElement()); 194 RawPtr<Element> focusedElement(document->focusedElement());
195 focusedElement->setFocus(true); 195 focusedElement->setFocus(true);
196 dispatchFocusEvent(*document, *focusedElement); 196 dispatchFocusEvent(*document, *focusedElement);
197 } 197 }
198 } 198 }
199 199
200 inline bool hasCustomFocusLogic(const Element& element) 200 inline bool hasCustomFocusLogic(const Element& element)
201 { 201 {
202 return element.isHTMLElement() && toHTMLElement(element).hasCustomFocusLogic (); 202 return element.isHTMLElement() && toHTMLElement(element).hasCustomFocusLogic ();
203 } 203 }
204 204
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 } // anonymous namespace 537 } // anonymous namespace
538 538
539 FocusController::FocusController(Page* page) 539 FocusController::FocusController(Page* page)
540 : m_page(page) 540 : m_page(page)
541 , m_isActive(false) 541 , m_isActive(false)
542 , m_isFocused(false) 542 , m_isFocused(false)
543 , m_isChangingFocusedFrame(false) 543 , m_isChangingFocusedFrame(false)
544 { 544 {
545 } 545 }
546 546
547 PassOwnPtrWillBeRawPtr<FocusController> FocusController::create(Page* page) 547 RawPtr<FocusController> FocusController::create(Page* page)
548 { 548 {
549 return adoptPtrWillBeNoop(new FocusController(page)); 549 return (new FocusController(page));
550 } 550 }
551 551
552 void FocusController::setFocusedFrame(PassRefPtrWillBeRawPtr<Frame> frame, bool notifyEmbedder) 552 void FocusController::setFocusedFrame(RawPtr<Frame> frame, bool notifyEmbedder)
553 { 553 {
554 ASSERT(!frame || frame->page() == m_page); 554 ASSERT(!frame || frame->page() == m_page);
555 if (m_focusedFrame == frame || (m_isChangingFocusedFrame && frame)) 555 if (m_focusedFrame == frame || (m_isChangingFocusedFrame && frame))
556 return; 556 return;
557 557
558 m_isChangingFocusedFrame = true; 558 m_isChangingFocusedFrame = true;
559 559
560 RefPtrWillBeRawPtr<LocalFrame> oldFrame = (m_focusedFrame && m_focusedFrame- >isLocalFrame()) ? toLocalFrame(m_focusedFrame.get()) : nullptr; 560 RawPtr<LocalFrame> oldFrame = (m_focusedFrame && m_focusedFrame->isLocalFram e()) ? toLocalFrame(m_focusedFrame.get()) : nullptr;
561 561
562 RefPtrWillBeRawPtr<LocalFrame> newFrame = (frame && frame->isLocalFrame()) ? toLocalFrame(frame.get()) : nullptr; 562 RawPtr<LocalFrame> newFrame = (frame && frame->isLocalFrame()) ? toLocalFram e(frame.get()) : nullptr;
563 563
564 m_focusedFrame = frame.get(); 564 m_focusedFrame = frame.get();
565 565
566 // Now that the frame is updated, fire events and update the selection focus ed states of both frames. 566 // Now that the frame is updated, fire events and update the selection focus ed states of both frames.
567 if (oldFrame && oldFrame->view()) { 567 if (oldFrame && oldFrame->view()) {
568 oldFrame->selection().setFocused(false); 568 oldFrame->selection().setFocused(false);
569 oldFrame->domWindow()->dispatchEvent(Event::create(EventTypeNames::blur) ); 569 oldFrame->domWindow()->dispatchEvent(Event::create(EventTypeNames::blur) );
570 } 570 }
571 571
572 if (newFrame && newFrame->view() && isFocused()) { 572 if (newFrame && newFrame->view() && isFocused()) {
573 newFrame->selection().setFocused(true); 573 newFrame->selection().setFocused(true);
574 newFrame->domWindow()->dispatchEvent(Event::create(EventTypeNames::focus )); 574 newFrame->domWindow()->dispatchEvent(Event::create(EventTypeNames::focus ));
575 } 575 }
576 576
577 m_isChangingFocusedFrame = false; 577 m_isChangingFocusedFrame = false;
578 578
579 // Checking client() is necessary, as the frame might have been detached as 579 // Checking client() is necessary, as the frame might have been detached as
580 // part of dispatching the focus event above. See https://crbug.com/570874. 580 // part of dispatching the focus event above. See https://crbug.com/570874.
581 if (m_focusedFrame && m_focusedFrame->client() && notifyEmbedder) 581 if (m_focusedFrame && m_focusedFrame->client() && notifyEmbedder)
582 m_focusedFrame->client()->frameFocused(); 582 m_focusedFrame->client()->frameFocused();
583 } 583 }
584 584
585 void FocusController::focusDocumentView(PassRefPtrWillBeRawPtr<Frame> frame, boo l notifyEmbedder) 585 void FocusController::focusDocumentView(RawPtr<Frame> frame, bool notifyEmbedder )
586 { 586 {
587 ASSERT(!frame || frame->page() == m_page); 587 ASSERT(!frame || frame->page() == m_page);
588 if (m_focusedFrame == frame) 588 if (m_focusedFrame == frame)
589 return; 589 return;
590 590
591 RefPtrWillBeRawPtr<LocalFrame> focusedFrame = (m_focusedFrame && m_focusedFr ame->isLocalFrame()) ? toLocalFrame(m_focusedFrame.get()) : nullptr; 591 RawPtr<LocalFrame> focusedFrame = (m_focusedFrame && m_focusedFrame->isLocal Frame()) ? toLocalFrame(m_focusedFrame.get()) : nullptr;
592 if (focusedFrame && focusedFrame->view()) { 592 if (focusedFrame && focusedFrame->view()) {
593 RefPtrWillBeRawPtr<Document> document = focusedFrame->document(); 593 RawPtr<Document> document = focusedFrame->document();
594 Element* focusedElement = document ? document->focusedElement() : nullpt r; 594 Element* focusedElement = document ? document->focusedElement() : nullpt r;
595 if (focusedElement) 595 if (focusedElement)
596 dispatchBlurEvent(*document, *focusedElement); 596 dispatchBlurEvent(*document, *focusedElement);
597 } 597 }
598 598
599 RefPtrWillBeRawPtr<LocalFrame> newFocusedFrame = (frame && frame->isLocalFra me()) ? toLocalFrame(frame.get()) : nullptr; 599 RawPtr<LocalFrame> newFocusedFrame = (frame && frame->isLocalFrame()) ? toLo calFrame(frame.get()) : nullptr;
600 if (newFocusedFrame && newFocusedFrame->view()) { 600 if (newFocusedFrame && newFocusedFrame->view()) {
601 RefPtrWillBeRawPtr<Document> document = newFocusedFrame->document(); 601 RawPtr<Document> document = newFocusedFrame->document();
602 Element* focusedElement = document ? document->focusedElement() : nullpt r; 602 Element* focusedElement = document ? document->focusedElement() : nullpt r;
603 if (focusedElement) 603 if (focusedElement)
604 dispatchFocusEvent(*document, *focusedElement); 604 dispatchFocusEvent(*document, *focusedElement);
605 } 605 }
606 606
607 setFocusedFrame(frame, notifyEmbedder); 607 setFocusedFrame(frame, notifyEmbedder);
608 } 608 }
609 609
610 LocalFrame* FocusController::focusedFrame() const 610 LocalFrame* FocusController::focusedFrame() const
611 { 611 {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 currentNode = document->focusedElement(); 738 currentNode = document->focusedElement();
739 739
740 // FIXME: Not quite correct when it comes to focus transitions leaving/enter ing the WebView itself 740 // FIXME: Not quite correct when it comes to focus transitions leaving/enter ing the WebView itself
741 bool caretBrowsing = frame->settings() && frame->settings()->caretBrowsingEn abled(); 741 bool caretBrowsing = frame->settings() && frame->settings()->caretBrowsingEn abled();
742 742
743 if (caretBrowsing && !currentNode) 743 if (caretBrowsing && !currentNode)
744 currentNode = frame->selection().start().anchorNode(); 744 currentNode = frame->selection().start().anchorNode();
745 745
746 document->updateLayoutIgnorePendingStylesheets(); 746 document->updateLayoutIgnorePendingStylesheets();
747 747
748 RefPtrWillBeRawPtr<Element> element = findFocusableElementAcrossFocusScopes( type, FocusNavigationScope::focusNavigationScopeOf(currentNode ? *currentNode : *document), currentNode); 748 RawPtr<Element> element = findFocusableElementAcrossFocusScopes(type, FocusN avigationScope::focusNavigationScopeOf(currentNode ? *currentNode : *document), currentNode);
749 749
750 if (!element) { 750 if (!element) {
751 // If there's a RemoteFrame on the ancestor chain, we need to continue 751 // If there's a RemoteFrame on the ancestor chain, we need to continue
752 // searching for focusable elements there. 752 // searching for focusable elements there.
753 if (frame->localFrameRoot() != frame->tree().top()) { 753 if (frame->localFrameRoot() != frame->tree().top()) {
754 document->clearFocusedElement(); 754 document->clearFocusedElement();
755 toRemoteFrame(frame->localFrameRoot()->tree().parent())->advanceFocu s(type, frame->localFrameRoot()); 755 toRemoteFrame(frame->localFrameRoot()->tree().parent())->advanceFocu s(type, frame->localFrameRoot());
756 return true; 756 return true;
757 } 757 }
758 758
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 857
858 if (!enclosingTextFormControl(selectionStartNode)) 858 if (!enclosingTextFormControl(selectionStartNode))
859 return; 859 return;
860 860
861 if (selectionStartNode->isInShadowTree() && selectionStartNode->shadowHost() == newFocusedElement) 861 if (selectionStartNode->isInShadowTree() && selectionStartNode->shadowHost() == newFocusedElement)
862 return; 862 return;
863 863
864 selection.clear(); 864 selection.clear();
865 } 865 }
866 866
867 bool FocusController::setFocusedElement(Element* element, PassRefPtrWillBeRawPtr <Frame> newFocusedFrame) 867 bool FocusController::setFocusedElement(Element* element, RawPtr<Frame> newFocus edFrame)
868 { 868 {
869 return setFocusedElement(element, newFocusedFrame, FocusParams(SelectionBeha viorOnFocus::None, WebFocusTypeNone, nullptr)); 869 return setFocusedElement(element, newFocusedFrame, FocusParams(SelectionBeha viorOnFocus::None, WebFocusTypeNone, nullptr));
870 } 870 }
871 871
872 bool FocusController::setFocusedElement(Element* element, PassRefPtrWillBeRawPtr <Frame> newFocusedFrame, const FocusParams& params) 872 bool FocusController::setFocusedElement(Element* element, RawPtr<Frame> newFocus edFrame, const FocusParams& params)
873 { 873 {
874 RefPtrWillBeRawPtr<LocalFrame> oldFocusedFrame = focusedFrame(); 874 RawPtr<LocalFrame> oldFocusedFrame = focusedFrame();
875 RefPtrWillBeRawPtr<Document> oldDocument = oldFocusedFrame ? oldFocusedFrame ->document() : nullptr; 875 RawPtr<Document> oldDocument = oldFocusedFrame ? oldFocusedFrame->document() : nullptr;
876 876
877 Element* oldFocusedElement = oldDocument ? oldDocument->focusedElement() : n ullptr; 877 Element* oldFocusedElement = oldDocument ? oldDocument->focusedElement() : n ullptr;
878 if (element && oldFocusedElement == element) 878 if (element && oldFocusedElement == element)
879 return true; 879 return true;
880 880
881 // FIXME: Might want to disable this check for caretBrowsing 881 // FIXME: Might want to disable this check for caretBrowsing
882 if (oldFocusedElement && oldFocusedElement->isRootEditableElement() && !reli nquishesEditingFocus(*oldFocusedElement)) 882 if (oldFocusedElement && oldFocusedElement->isRootEditableElement() && !reli nquishesEditingFocus(*oldFocusedElement))
883 return false; 883 return false;
884 884
885 m_page->chromeClient().willSetInputMethodState(); 885 m_page->chromeClient().willSetInputMethodState();
886 886
887 RefPtrWillBeRawPtr<Document> newDocument = nullptr; 887 RawPtr<Document> newDocument = nullptr;
888 if (element) 888 if (element)
889 newDocument = &element->document(); 889 newDocument = &element->document();
890 else if (newFocusedFrame && newFocusedFrame->isLocalFrame()) 890 else if (newFocusedFrame && newFocusedFrame->isLocalFrame())
891 newDocument = toLocalFrame(newFocusedFrame.get())->document(); 891 newDocument = toLocalFrame(newFocusedFrame.get())->document();
892 892
893 if (newDocument && oldDocument == newDocument && newDocument->focusedElement () == element) 893 if (newDocument && oldDocument == newDocument && newDocument->focusedElement () == element)
894 return true; 894 return true;
895 895
896 if (newFocusedFrame && newFocusedFrame->isLocalFrame()) 896 if (newFocusedFrame && newFocusedFrame->isLocalFrame())
897 clearSelectionIfNeeded(oldFocusedFrame.get(), toLocalFrame(newFocusedFra me.get()), element); 897 clearSelectionIfNeeded(oldFocusedFrame.get(), toLocalFrame(newFocusedFra me.get()), element);
898 898
899 if (oldDocument && oldDocument != newDocument) 899 if (oldDocument && oldDocument != newDocument)
900 oldDocument->clearFocusedElement(); 900 oldDocument->clearFocusedElement();
901 901
902 if (newFocusedFrame && !newFocusedFrame->page()) { 902 if (newFocusedFrame && !newFocusedFrame->page()) {
903 setFocusedFrame(nullptr); 903 setFocusedFrame(nullptr);
904 return false; 904 return false;
905 } 905 }
906 setFocusedFrame(newFocusedFrame); 906 setFocusedFrame(newFocusedFrame);
907 907
908 // Setting the focused node can result in losing our last reft to node when JS event handlers fire. 908 // Setting the focused node can result in losing our last reft to node when JS event handlers fire.
909 RefPtrWillBeRawPtr<Element> protect = element; 909 RawPtr<Element> protect = element;
910 ALLOW_UNUSED_LOCAL(protect); 910 ALLOW_UNUSED_LOCAL(protect);
911 if (newDocument) { 911 if (newDocument) {
912 bool successfullyFocused = newDocument->setFocusedElement(element, param s); 912 bool successfullyFocused = newDocument->setFocusedElement(element, param s);
913 if (!successfullyFocused) 913 if (!successfullyFocused)
914 return false; 914 return false;
915 } 915 }
916 916
917 return true; 917 return true;
918 } 918 }
919 919
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
1122 return consumed; 1122 return consumed;
1123 } 1123 }
1124 1124
1125 DEFINE_TRACE(FocusController) 1125 DEFINE_TRACE(FocusController)
1126 { 1126 {
1127 visitor->trace(m_page); 1127 visitor->trace(m_page);
1128 visitor->trace(m_focusedFrame); 1128 visitor->trace(m_focusedFrame);
1129 } 1129 }
1130 1130
1131 } // namespace blink 1131 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698