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

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

Issue 2833503002: OOPIF: Enable TabAndMouseFocusNavigation. (Closed)
Patch Set: Fix comment by alexmos. Created 3 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
« no previous file with comments | « chrome/browser/site_per_process_interactive_browsertest.cc ('k') | 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 915 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 // If we are shifting focus from a child frame to its parent, the 926 // If we are shifting focus from a child frame to its parent, the
927 // child frame has no more focusable elements, and we should continue 927 // child frame has no more focusable elements, and we should continue
928 // looking for focusable elements in the parent, starting from the <iframe> 928 // looking for focusable elements in the parent, starting from the <iframe>
929 // element of the child frame. 929 // element of the child frame.
930 Element* start = nullptr; 930 Element* start = nullptr;
931 if (from->Tree().Parent() == to) { 931 if (from->Tree().Parent() == to) {
932 DCHECK(from->Owner()->IsLocal()); 932 DCHECK(from->Owner()->IsLocal());
933 start = ToHTMLFrameOwnerElement(from->Owner()); 933 start = ToHTMLFrameOwnerElement(from->Owner());
934 } 934 }
935 935
936 return AdvanceFocusInDocumentOrder(to, start, type, false, 936 // If we're coming from a parent frame, we need to restart from the first or
937 // last focusable element.
938 bool initial_focus = to->Tree().Parent() == from;
939
940 return AdvanceFocusInDocumentOrder(to, start, type, initial_focus,
937 source_capabilities); 941 source_capabilities);
938 } 942 }
939 943
940 #if DCHECK_IS_ON() 944 #if DCHECK_IS_ON()
941 inline bool IsNonFocusableShadowHost(const Element& element) { 945 inline bool IsNonFocusableShadowHost(const Element& element) {
942 return IsShadowHostWithoutCustomFocusLogic(element) && !element.IsFocusable(); 946 return IsShadowHostWithoutCustomFocusLogic(element) && !element.IsFocusable();
943 } 947 }
944 #endif 948 #endif
945 949
946 bool FocusController::AdvanceFocusInDocumentOrder( 950 bool FocusController::AdvanceFocusInDocumentOrder(
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 *ToLocalFrame(page_->MainFrame())->GetDocument()); 995 *ToLocalFrame(page_->MainFrame())->GetDocument());
992 element = FindFocusableElementRecursively(type, scope); 996 element = FindFocusableElementRecursively(type, scope);
993 element = 997 element =
994 FindFocusableElementDescendingDownIntoFrameDocument(type, element); 998 FindFocusableElementDescendingDownIntoFrameDocument(type, element);
995 999
996 if (!element) 1000 if (!element)
997 return false; 1001 return false;
998 } 1002 }
999 1003
1000 if (element == document->FocusedElement()) { 1004 if (element == document->FocusedElement()) {
1001 // Focus wrapped around to the same element. 1005 // Focus is either coming from a remote frame or has wrapped around.
1006 if (FocusedFrame() != document->GetFrame()) {
1007 SetFocusedFrame(document->GetFrame());
1008 DispatchFocusEvent(*document, *element);
1009 }
1002 return true; 1010 return true;
1003 } 1011 }
1004 1012
1005 if (element->IsFrameOwnerElement() && 1013 if (element->IsFrameOwnerElement() &&
1006 (!IsHTMLPlugInElement(*element) || !element->IsKeyboardFocusable())) { 1014 (!IsHTMLPlugInElement(*element) || !element->IsKeyboardFocusable())) {
1007 // We focus frames rather than frame owners. 1015 // We focus frames rather than frame owners.
1008 // FIXME: We should not focus frames that have no scrollbars, as focusing 1016 // FIXME: We should not focus frames that have no scrollbars, as focusing
1009 // them isn't useful to the user. 1017 // them isn't useful to the user.
1010 HTMLFrameOwnerElement* owner = ToHTMLFrameOwnerElement(element); 1018 HTMLFrameOwnerElement* owner = ToHTMLFrameOwnerElement(element);
1011 if (!owner->ContentFrame()) 1019 if (!owner->ContentFrame())
1012 return false; 1020 return false;
1013 1021
1014 document->ClearFocusedElement(); 1022 document->ClearFocusedElement();
1015 SetFocusedFrame(owner->ContentFrame());
1016 1023
1017 // If contentFrame is remote, continue the search for focusable 1024 // If ContentFrame is remote, continue the search for focusable elements in
1018 // elements in that frame's process. 1025 // that frame's process. The target ContentFrame's process will grab focus
1019 // clearFocusedElement() fires events that might detach the 1026 // from inside AdvanceFocusInDocumentOrder().
1020 // contentFrame, hence the need to null-check it again. 1027 //
1028 // ClearFocusedElement() fires events that might detach the contentFrame,
1029 // hence the need to null-check it again.
1021 if (owner->ContentFrame() && owner->ContentFrame()->IsRemoteFrame()) 1030 if (owner->ContentFrame() && owner->ContentFrame()->IsRemoteFrame())
1022 ToRemoteFrame(owner->ContentFrame())->AdvanceFocus(type, frame); 1031 ToRemoteFrame(owner->ContentFrame())->AdvanceFocus(type, frame);
1032 else
1033 SetFocusedFrame(owner->ContentFrame());
1023 1034
1024 return true; 1035 return true;
1025 } 1036 }
1026 1037
1027 DCHECK(element->IsFocusable()); 1038 DCHECK(element->IsFocusable());
1028 1039
1029 // FIXME: It would be nice to just be able to call setFocusedElement(element) 1040 // FIXME: It would be nice to just be able to call setFocusedElement(element)
1030 // here, but we can't do that because some elements (e.g. HTMLInputElement 1041 // here, but we can't do that because some elements (e.g. HTMLInputElement
1031 // and HTMLTextAreaElement) do extra work in their focus() methods. 1042 // and HTMLTextAreaElement) do extra work in their focus() methods.
1032 Document& new_document = element->GetDocument(); 1043 Document& new_document = element->GetDocument();
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
1396 it->FocusedFrameChanged(); 1407 it->FocusedFrameChanged();
1397 } 1408 }
1398 1409
1399 DEFINE_TRACE(FocusController) { 1410 DEFINE_TRACE(FocusController) {
1400 visitor->Trace(page_); 1411 visitor->Trace(page_);
1401 visitor->Trace(focused_frame_); 1412 visitor->Trace(focused_frame_);
1402 visitor->Trace(focus_changed_observers_); 1413 visitor->Trace(focus_changed_observers_);
1403 } 1414 }
1404 1415
1405 } // namespace blink 1416 } // namespace blink
OLDNEW
« no previous file with comments | « chrome/browser/site_per_process_interactive_browsertest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698