| 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 1048 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1059 ScopedFocusNavigation scope = | 1059 ScopedFocusNavigation scope = |
| 1060 ScopedFocusNavigation::ownedByShadowHost(shadowHost); | 1060 ScopedFocusNavigation::ownedByShadowHost(shadowHost); |
| 1061 return findFocusableElementAcrossFocusScopes(WebFocusTypeForward, scope); | 1061 return findFocusableElementAcrossFocusScopes(WebFocusTypeForward, scope); |
| 1062 } | 1062 } |
| 1063 | 1063 |
| 1064 static bool relinquishesEditingFocus(const Element& element) { | 1064 static bool relinquishesEditingFocus(const Element& element) { |
| 1065 DCHECK(hasEditableStyle(element)); | 1065 DCHECK(hasEditableStyle(element)); |
| 1066 return element.document().frame() && rootEditableElement(element); | 1066 return element.document().frame() && rootEditableElement(element); |
| 1067 } | 1067 } |
| 1068 | 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 if (selection.isNone()) | |
| 1080 return; | |
| 1081 | |
| 1082 Node* selectionStartNode = selection.selection().start().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 | |
| 1097 bool FocusController::setFocusedElement(Element* element, | 1069 bool FocusController::setFocusedElement(Element* element, |
| 1098 Frame* newFocusedFrame) { | 1070 Frame* newFocusedFrame) { |
| 1099 return setFocusedElement( | 1071 return setFocusedElement( |
| 1100 element, newFocusedFrame, | 1072 element, newFocusedFrame, |
| 1101 FocusParams(SelectionBehaviorOnFocus::None, WebFocusTypeNone, nullptr)); | 1073 FocusParams(SelectionBehaviorOnFocus::None, WebFocusTypeNone, nullptr)); |
| 1102 } | 1074 } |
| 1103 | 1075 |
| 1104 bool FocusController::setFocusedElement(Element* element, | 1076 bool FocusController::setFocusedElement(Element* element, |
| 1105 Frame* newFocusedFrame, | 1077 Frame* newFocusedFrame, |
| 1106 const FocusParams& params) { | 1078 const FocusParams& params) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1123 Document* newDocument = nullptr; | 1095 Document* newDocument = nullptr; |
| 1124 if (element) | 1096 if (element) |
| 1125 newDocument = &element->document(); | 1097 newDocument = &element->document(); |
| 1126 else if (newFocusedFrame && newFocusedFrame->isLocalFrame()) | 1098 else if (newFocusedFrame && newFocusedFrame->isLocalFrame()) |
| 1127 newDocument = toLocalFrame(newFocusedFrame)->document(); | 1099 newDocument = toLocalFrame(newFocusedFrame)->document(); |
| 1128 | 1100 |
| 1129 if (newDocument && oldDocument == newDocument && | 1101 if (newDocument && oldDocument == newDocument && |
| 1130 newDocument->focusedElement() == element) | 1102 newDocument->focusedElement() == element) |
| 1131 return true; | 1103 return true; |
| 1132 | 1104 |
| 1133 if (newFocusedFrame && newFocusedFrame->isLocalFrame()) | |
| 1134 clearSelectionIfNeeded(oldFocusedFrame, toLocalFrame(newFocusedFrame), | |
| 1135 element); | |
| 1136 | |
| 1137 if (oldDocument && oldDocument != newDocument) | 1105 if (oldDocument && oldDocument != newDocument) |
| 1138 oldDocument->clearFocusedElement(); | 1106 oldDocument->clearFocusedElement(); |
| 1139 | 1107 |
| 1140 if (newFocusedFrame && !newFocusedFrame->page()) { | 1108 if (newFocusedFrame && !newFocusedFrame->page()) { |
| 1141 setFocusedFrame(nullptr); | 1109 setFocusedFrame(nullptr); |
| 1142 return false; | 1110 return false; |
| 1143 } | 1111 } |
| 1144 setFocusedFrame(newFocusedFrame); | 1112 setFocusedFrame(newFocusedFrame); |
| 1145 | 1113 |
| 1146 if (newDocument) { | 1114 if (newDocument) { |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1414 it->focusedFrameChanged(); | 1382 it->focusedFrameChanged(); |
| 1415 } | 1383 } |
| 1416 | 1384 |
| 1417 DEFINE_TRACE(FocusController) { | 1385 DEFINE_TRACE(FocusController) { |
| 1418 visitor->trace(m_page); | 1386 visitor->trace(m_page); |
| 1419 visitor->trace(m_focusedFrame); | 1387 visitor->trace(m_focusedFrame); |
| 1420 visitor->trace(m_focusChangedObservers); | 1388 visitor->trace(m_focusChangedObservers); |
| 1421 } | 1389 } |
| 1422 | 1390 |
| 1423 } // namespace blink | 1391 } // namespace blink |
| OLD | NEW |