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

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

Issue 2791753002: Revert of Reland: Do not send redundant selectionchange-events (Closed)
Patch Set: Add a NeedsRebaseline to manage conflict with http://crrev.com/460732 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
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 1021 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 Document& newDocument = element->document(); 1032 Document& newDocument = element->document();
1033 1033
1034 if (&newDocument != document) { 1034 if (&newDocument != document) {
1035 // Focus is going away from this document, so clear the focused element. 1035 // Focus is going away from this document, so clear the focused element.
1036 document->clearFocusedElement(); 1036 document->clearFocusedElement();
1037 document->setSequentialFocusNavigationStartingPoint(nullptr); 1037 document->setSequentialFocusNavigationStartingPoint(nullptr);
1038 } 1038 }
1039 1039
1040 setFocusedFrame(newDocument.frame()); 1040 setFocusedFrame(newDocument.frame());
1041 1041
1042 if (!element->isTextControl() && !hasEditableStyle(*element->toNode())) {
1043 // TODO(editing-dev): Remove this clear(), crbug.com/692898.
1044 focusedFrame()->selection().clear();
1045 }
1046 element->focus( 1042 element->focus(
1047 FocusParams(SelectionBehaviorOnFocus::Reset, type, sourceCapabilities)); 1043 FocusParams(SelectionBehaviorOnFocus::Reset, type, sourceCapabilities));
1048 return true; 1044 return true;
1049 } 1045 }
1050 1046
1051 Element* FocusController::findFocusableElement(WebFocusType type, 1047 Element* FocusController::findFocusableElement(WebFocusType type,
1052 Element& element) { 1048 Element& element) {
1053 // FIXME: No spacial navigation code yet. 1049 // FIXME: No spacial navigation code yet.
1054 DCHECK(type == WebFocusTypeForward || type == WebFocusTypeBackward); 1050 DCHECK(type == WebFocusTypeForward || type == WebFocusTypeBackward);
1055 ScopedFocusNavigation scope = ScopedFocusNavigation::createFor(element); 1051 ScopedFocusNavigation scope = ScopedFocusNavigation::createFor(element);
1056 return findFocusableElementAcrossFocusScopes(type, scope); 1052 return findFocusableElementAcrossFocusScopes(type, scope);
1057 } 1053 }
1058 1054
1059 Element* FocusController::findFocusableElementInShadowHost( 1055 Element* FocusController::findFocusableElementInShadowHost(
1060 const Element& shadowHost) { 1056 const Element& shadowHost) {
1061 DCHECK(shadowHost.authorShadowRoot()); 1057 DCHECK(shadowHost.authorShadowRoot());
1062 ScopedFocusNavigation scope = 1058 ScopedFocusNavigation scope =
1063 ScopedFocusNavigation::ownedByShadowHost(shadowHost); 1059 ScopedFocusNavigation::ownedByShadowHost(shadowHost);
1064 return findFocusableElementAcrossFocusScopes(WebFocusTypeForward, scope); 1060 return findFocusableElementAcrossFocusScopes(WebFocusTypeForward, scope);
1065 } 1061 }
1066 1062
1067 static bool relinquishesEditingFocus(const Element& element) { 1063 static bool relinquishesEditingFocus(const Element& element) {
1068 DCHECK(hasEditableStyle(element)); 1064 DCHECK(hasEditableStyle(element));
1069 return element.document().frame() && rootEditableElement(element); 1065 return element.document().frame() && rootEditableElement(element);
1070 } 1066 }
1071 1067
1068 static void clearSelectionIfNeeded(LocalFrame* oldFocusedFrame,
1069 LocalFrame* newFocusedFrame,
1070 Element* newFocusedElement) {
1071 if (!oldFocusedFrame || !newFocusedFrame)
1072 return;
1073
1074 if (oldFocusedFrame->document() != newFocusedFrame->document())
1075 return;
1076
1077 FrameSelection& selection = oldFocusedFrame->selection();
1078 const SelectionInDOMTree& selectionInDOMTree = selection.selectionInDOMTree();
1079 if (selectionInDOMTree.isNone())
1080 return;
1081
1082 Node* selectionStartNode = selectionInDOMTree.base().anchorNode();
1083 if (selectionStartNode == newFocusedElement ||
1084 selectionStartNode->isDescendantOf(newFocusedElement))
1085 return;
1086
1087 if (!enclosingTextControl(selectionStartNode))
1088 return;
1089
1090 if (selectionStartNode->isInShadowTree() &&
1091 selectionStartNode->ownerShadowHost() == newFocusedElement)
1092 return;
1093
1094 selection.clear();
1095 }
1096
1072 bool FocusController::setFocusedElement(Element* element, 1097 bool FocusController::setFocusedElement(Element* element,
1073 Frame* newFocusedFrame) { 1098 Frame* newFocusedFrame) {
1074 return setFocusedElement( 1099 return setFocusedElement(
1075 element, newFocusedFrame, 1100 element, newFocusedFrame,
1076 FocusParams(SelectionBehaviorOnFocus::None, WebFocusTypeNone, nullptr)); 1101 FocusParams(SelectionBehaviorOnFocus::None, WebFocusTypeNone, nullptr));
1077 } 1102 }
1078 1103
1079 bool FocusController::setFocusedElement(Element* element, 1104 bool FocusController::setFocusedElement(Element* element,
1080 Frame* newFocusedFrame, 1105 Frame* newFocusedFrame,
1081 const FocusParams& params) { 1106 const FocusParams& params) {
(...skipping 16 matching lines...) Expand all
1098 Document* newDocument = nullptr; 1123 Document* newDocument = nullptr;
1099 if (element) 1124 if (element)
1100 newDocument = &element->document(); 1125 newDocument = &element->document();
1101 else if (newFocusedFrame && newFocusedFrame->isLocalFrame()) 1126 else if (newFocusedFrame && newFocusedFrame->isLocalFrame())
1102 newDocument = toLocalFrame(newFocusedFrame)->document(); 1127 newDocument = toLocalFrame(newFocusedFrame)->document();
1103 1128
1104 if (newDocument && oldDocument == newDocument && 1129 if (newDocument && oldDocument == newDocument &&
1105 newDocument->focusedElement() == element) 1130 newDocument->focusedElement() == element)
1106 return true; 1131 return true;
1107 1132
1133 if (newFocusedFrame && newFocusedFrame->isLocalFrame())
1134 clearSelectionIfNeeded(oldFocusedFrame, toLocalFrame(newFocusedFrame),
1135 element);
1136
1108 if (oldDocument && oldDocument != newDocument) 1137 if (oldDocument && oldDocument != newDocument)
1109 oldDocument->clearFocusedElement(); 1138 oldDocument->clearFocusedElement();
1110 1139
1111 if (newFocusedFrame && !newFocusedFrame->page()) { 1140 if (newFocusedFrame && !newFocusedFrame->page()) {
1112 setFocusedFrame(nullptr); 1141 setFocusedFrame(nullptr);
1113 return false; 1142 return false;
1114 } 1143 }
1115 setFocusedFrame(newFocusedFrame); 1144 setFocusedFrame(newFocusedFrame);
1116 1145
1117 if (newDocument) { 1146 if (newDocument) {
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
1318 if (focusCandidate.isOffscreenAfterScrolling) { 1347 if (focusCandidate.isOffscreenAfterScrolling) {
1319 Node* container = focusCandidate.enclosingScrollableBox; 1348 Node* container = focusCandidate.enclosingScrollableBox;
1320 scrollInDirection(container, type); 1349 scrollInDirection(container, type);
1321 return true; 1350 return true;
1322 } 1351 }
1323 1352
1324 // We found a new focus node, navigate to it. 1353 // We found a new focus node, navigate to it.
1325 Element* element = toElement(focusCandidate.focusableNode); 1354 Element* element = toElement(focusCandidate.focusableNode);
1326 DCHECK(element); 1355 DCHECK(element);
1327 1356
1328 if (!element->isTextControl() && !hasEditableStyle(*element->toNode())) {
1329 // TODO(editing-dev): Remove this clear(), crbug.com/692898.
1330 focusedFrame()->selection().clear();
1331 }
1332 element->focus(FocusParams(SelectionBehaviorOnFocus::Reset, type, nullptr)); 1357 element->focus(FocusParams(SelectionBehaviorOnFocus::Reset, type, nullptr));
1333 return true; 1358 return true;
1334 } 1359 }
1335 1360
1336 bool FocusController::advanceFocusDirectionally(WebFocusType type) { 1361 bool FocusController::advanceFocusDirectionally(WebFocusType type) {
1337 // FIXME: Directional focus changes don't yet work with RemoteFrames. 1362 // FIXME: Directional focus changes don't yet work with RemoteFrames.
1338 if (!focusedOrMainFrame()->isLocalFrame()) 1363 if (!focusedOrMainFrame()->isLocalFrame())
1339 return false; 1364 return false;
1340 LocalFrame* curFrame = toLocalFrame(focusedOrMainFrame()); 1365 LocalFrame* curFrame = toLocalFrame(focusedOrMainFrame());
1341 DCHECK(curFrame); 1366 DCHECK(curFrame);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1393 it->focusedFrameChanged(); 1418 it->focusedFrameChanged();
1394 } 1419 }
1395 1420
1396 DEFINE_TRACE(FocusController) { 1421 DEFINE_TRACE(FocusController) {
1397 visitor->trace(m_page); 1422 visitor->trace(m_page);
1398 visitor->trace(m_focusedFrame); 1423 visitor->trace(m_focusedFrame);
1399 visitor->trace(m_focusChangedObservers); 1424 visitor->trace(m_focusChangedObservers);
1400 } 1425 }
1401 1426
1402 } // namespace blink 1427 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/PendingSelection.cpp ('k') | third_party/WebKit/Source/web/tests/WebFrameTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698