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