| 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 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1051 ScopedFocusNavigation scope = | 1051 ScopedFocusNavigation scope = |
| 1052 ScopedFocusNavigation::ownedByShadowHost(shadowHost); | 1052 ScopedFocusNavigation::ownedByShadowHost(shadowHost); |
| 1053 return findFocusableElementAcrossFocusScopes(WebFocusTypeForward, scope); | 1053 return findFocusableElementAcrossFocusScopes(WebFocusTypeForward, scope); |
| 1054 } | 1054 } |
| 1055 | 1055 |
| 1056 static bool relinquishesEditingFocus(const Element& element) { | 1056 static bool relinquishesEditingFocus(const Element& element) { |
| 1057 DCHECK(hasEditableStyle(element)); | 1057 DCHECK(hasEditableStyle(element)); |
| 1058 return element.document().frame() && rootEditableElement(element); | 1058 return element.document().frame() && rootEditableElement(element); |
| 1059 } | 1059 } |
| 1060 | 1060 |
| 1061 static void clearSelectionIfNeeded(LocalFrame* oldFocusedFrame, | |
| 1062 LocalFrame* newFocusedFrame, | |
| 1063 Element* newFocusedElement) { | |
| 1064 if (!oldFocusedFrame || !newFocusedFrame) | |
| 1065 return; | |
| 1066 | |
| 1067 if (oldFocusedFrame->document() != newFocusedFrame->document()) | |
| 1068 return; | |
| 1069 | |
| 1070 FrameSelection& selection = oldFocusedFrame->selection(); | |
| 1071 if (selection.isNone()) | |
| 1072 return; | |
| 1073 | |
| 1074 Node* selectionStartNode = selection.selection().start().anchorNode(); | |
| 1075 if (selectionStartNode == newFocusedElement || | |
| 1076 selectionStartNode->isDescendantOf(newFocusedElement)) | |
| 1077 return; | |
| 1078 | |
| 1079 if (!enclosingTextControl(selectionStartNode)) | |
| 1080 return; | |
| 1081 | |
| 1082 if (selectionStartNode->isInShadowTree() && | |
| 1083 selectionStartNode->ownerShadowHost() == newFocusedElement) | |
| 1084 return; | |
| 1085 | |
| 1086 selection.clear(); | |
| 1087 } | |
| 1088 | |
| 1089 bool FocusController::setFocusedElement(Element* element, | 1061 bool FocusController::setFocusedElement(Element* element, |
| 1090 Frame* newFocusedFrame) { | 1062 Frame* newFocusedFrame) { |
| 1091 return setFocusedElement( | 1063 return setFocusedElement( |
| 1092 element, newFocusedFrame, | 1064 element, newFocusedFrame, |
| 1093 FocusParams(SelectionBehaviorOnFocus::None, WebFocusTypeNone, nullptr)); | 1065 FocusParams(SelectionBehaviorOnFocus::None, WebFocusTypeNone, nullptr)); |
| 1094 } | 1066 } |
| 1095 | 1067 |
| 1096 bool FocusController::setFocusedElement(Element* element, | 1068 bool FocusController::setFocusedElement(Element* element, |
| 1097 Frame* newFocusedFrame, | 1069 Frame* newFocusedFrame, |
| 1098 const FocusParams& params) { | 1070 const FocusParams& params) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1115 Document* newDocument = nullptr; | 1087 Document* newDocument = nullptr; |
| 1116 if (element) | 1088 if (element) |
| 1117 newDocument = &element->document(); | 1089 newDocument = &element->document(); |
| 1118 else if (newFocusedFrame && newFocusedFrame->isLocalFrame()) | 1090 else if (newFocusedFrame && newFocusedFrame->isLocalFrame()) |
| 1119 newDocument = toLocalFrame(newFocusedFrame)->document(); | 1091 newDocument = toLocalFrame(newFocusedFrame)->document(); |
| 1120 | 1092 |
| 1121 if (newDocument && oldDocument == newDocument && | 1093 if (newDocument && oldDocument == newDocument && |
| 1122 newDocument->focusedElement() == element) | 1094 newDocument->focusedElement() == element) |
| 1123 return true; | 1095 return true; |
| 1124 | 1096 |
| 1125 if (newFocusedFrame && newFocusedFrame->isLocalFrame()) | |
| 1126 clearSelectionIfNeeded(oldFocusedFrame, toLocalFrame(newFocusedFrame), | |
| 1127 element); | |
| 1128 | |
| 1129 if (oldDocument && oldDocument != newDocument) | 1097 if (oldDocument && oldDocument != newDocument) |
| 1130 oldDocument->clearFocusedElement(); | 1098 oldDocument->clearFocusedElement(); |
| 1131 | 1099 |
| 1132 if (newFocusedFrame && !newFocusedFrame->page()) { | 1100 if (newFocusedFrame && !newFocusedFrame->page()) { |
| 1133 setFocusedFrame(nullptr); | 1101 setFocusedFrame(nullptr); |
| 1134 return false; | 1102 return false; |
| 1135 } | 1103 } |
| 1136 setFocusedFrame(newFocusedFrame); | 1104 setFocusedFrame(newFocusedFrame); |
| 1137 | 1105 |
| 1138 if (newDocument) { | 1106 if (newDocument) { |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1393 | 1361 |
| 1394 return consumed; | 1362 return consumed; |
| 1395 } | 1363 } |
| 1396 | 1364 |
| 1397 DEFINE_TRACE(FocusController) { | 1365 DEFINE_TRACE(FocusController) { |
| 1398 visitor->trace(m_page); | 1366 visitor->trace(m_page); |
| 1399 visitor->trace(m_focusedFrame); | 1367 visitor->trace(m_focusedFrame); |
| 1400 } | 1368 } |
| 1401 | 1369 |
| 1402 } // namespace blink | 1370 } // namespace blink |
| OLD | NEW |