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

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

Issue 2849403002: Use const ref for LocalFrame::LocalFrameRoot and FrameTree::Top (Closed)
Patch Set: Created 3 years, 7 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 804 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 return ToLocalFrame(focused_frame_.Get()); 815 return ToLocalFrame(focused_frame_.Get());
816 } 816 }
817 817
818 Frame* FocusController::FocusedOrMainFrame() const { 818 Frame* FocusController::FocusedOrMainFrame() const {
819 if (LocalFrame* frame = FocusedFrame()) 819 if (LocalFrame* frame = FocusedFrame())
820 return frame; 820 return frame;
821 821
822 // FIXME: This is a temporary hack to ensure that we return a LocalFrame, even 822 // FIXME: This is a temporary hack to ensure that we return a LocalFrame, even
823 // when the mainFrame is remote. FocusController needs to be refactored to 823 // when the mainFrame is remote. FocusController needs to be refactored to
824 // deal with RemoteFrames cross-process focus transfers. 824 // deal with RemoteFrames cross-process focus transfers.
825 for (Frame* frame = page_->MainFrame()->Tree().Top(); frame; 825 for (Frame* frame = &page_->MainFrame()->Tree().Top(); frame;
826 frame = frame->Tree().TraverseNext()) { 826 frame = frame->Tree().TraverseNext()) {
827 if (frame->IsLocalRoot()) 827 if (frame->IsLocalRoot())
828 return frame; 828 return frame;
829 } 829 }
830 830
831 return page_->MainFrame(); 831 return page_->MainFrame();
832 } 832 }
833 833
834 HTMLFrameOwnerElement* FocusController::FocusedFrameOwnerElement( 834 HTMLFrameOwnerElement* FocusController::FocusedFrameOwnerElement(
835 LocalFrame& current_frame) const { 835 LocalFrame& current_frame) const {
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
971 current ? ScopedFocusNavigation::CreateFor(*current) 971 current ? ScopedFocusNavigation::CreateFor(*current)
972 : ScopedFocusNavigation::CreateForDocument(*document); 972 : ScopedFocusNavigation::CreateForDocument(*document);
973 Element* element = FindFocusableElementAcrossFocusScopes(type, scope); 973 Element* element = FindFocusableElementAcrossFocusScopes(type, scope);
974 if (!element) { 974 if (!element) {
975 // If there's a RemoteFrame on the ancestor chain, we need to continue 975 // If there's a RemoteFrame on the ancestor chain, we need to continue
976 // searching for focusable elements there. 976 // searching for focusable elements there.
977 if (frame->LocalFrameRoot() != frame->Tree().Top()) { 977 if (frame->LocalFrameRoot() != frame->Tree().Top()) {
978 document->ClearFocusedElement(); 978 document->ClearFocusedElement();
979 document->SetSequentialFocusNavigationStartingPoint(nullptr); 979 document->SetSequentialFocusNavigationStartingPoint(nullptr);
980 SetFocusedFrame(nullptr); 980 SetFocusedFrame(nullptr);
981 ToRemoteFrame(frame->LocalFrameRoot()->Tree().Parent()) 981 ToRemoteFrame(frame->LocalFrameRoot().Tree().Parent())
982 ->AdvanceFocus(type, frame->LocalFrameRoot()); 982 ->AdvanceFocus(type, &frame->LocalFrameRoot());
983 return true; 983 return true;
984 } 984 }
985 985
986 // We didn't find an element to focus, so we should try to pass focus to 986 // We didn't find an element to focus, so we should try to pass focus to
987 // Chrome. 987 // Chrome.
988 if (!initial_focus && page_->GetChromeClient().CanTakeFocus(type)) { 988 if (!initial_focus && page_->GetChromeClient().CanTakeFocus(type)) {
989 document->ClearFocusedElement(); 989 document->ClearFocusedElement();
990 document->SetSequentialFocusNavigationStartingPoint(nullptr); 990 document->SetSequentialFocusNavigationStartingPoint(nullptr);
991 SetFocusedFrame(nullptr); 991 SetFocusedFrame(nullptr);
992 page_->GetChromeClient().TakeFocus(type); 992 page_->GetChromeClient().TakeFocus(type);
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1137 1137
1138 void FocusController::SetActive(bool active) { 1138 void FocusController::SetActive(bool active) {
1139 if (is_active_ == active) 1139 if (is_active_ == active)
1140 return; 1140 return;
1141 1141
1142 is_active_ = active; 1142 is_active_ = active;
1143 1143
1144 Frame* frame = FocusedOrMainFrame(); 1144 Frame* frame = FocusedOrMainFrame();
1145 if (frame->IsLocalFrame()) { 1145 if (frame->IsLocalFrame()) {
1146 Document* const document = 1146 Document* const document =
1147 ToLocalFrame(frame)->LocalFrameRoot()->GetDocument(); 1147 ToLocalFrame(frame)->LocalFrameRoot().GetDocument();
1148 DCHECK(document); 1148 DCHECK(document);
1149 if (!document->IsActive()) 1149 if (!document->IsActive())
1150 return; 1150 return;
1151 // Invalidate all custom scrollbars because they support the CSS 1151 // Invalidate all custom scrollbars because they support the CSS
1152 // window-active attribute. This should be applied to the entire page so 1152 // window-active attribute. This should be applied to the entire page so
1153 // we invalidate from the root FrameView instead of just the focused. 1153 // we invalidate from the root FrameView instead of just the focused.
1154 if (FrameView* view = document->View()) 1154 if (FrameView* view = document->View())
1155 view->InvalidateAllCustomScrollbarsOnActiveChanged(); 1155 view->InvalidateAllCustomScrollbarsOnActiveChanged();
1156 ToLocalFrame(frame)->Selection().PageActivationChanged(); 1156 ToLocalFrame(frame)->Selection().PageActivationChanged();
1157 } 1157 }
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
1410 it->FocusedFrameChanged(); 1410 it->FocusedFrameChanged();
1411 } 1411 }
1412 1412
1413 DEFINE_TRACE(FocusController) { 1413 DEFINE_TRACE(FocusController) {
1414 visitor->Trace(page_); 1414 visitor->Trace(page_);
1415 visitor->Trace(focused_frame_); 1415 visitor->Trace(focused_frame_);
1416 visitor->Trace(focus_changed_observers_); 1416 visitor->Trace(focus_changed_observers_);
1417 } 1417 }
1418 1418
1419 } // namespace blink 1419 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698