| 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 1047 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1058 ScopedFocusNavigation scope = | 1058 ScopedFocusNavigation scope = |
| 1059 ScopedFocusNavigation::OwnedByShadowHost(shadow_host); | 1059 ScopedFocusNavigation::OwnedByShadowHost(shadow_host); |
| 1060 return FindFocusableElementAcrossFocusScopes(kWebFocusTypeForward, scope); | 1060 return FindFocusableElementAcrossFocusScopes(kWebFocusTypeForward, scope); |
| 1061 } | 1061 } |
| 1062 | 1062 |
| 1063 static bool RelinquishesEditingFocus(const Element& element) { | 1063 static bool RelinquishesEditingFocus(const Element& element) { |
| 1064 DCHECK(HasEditableStyle(element)); | 1064 DCHECK(HasEditableStyle(element)); |
| 1065 return element.GetDocument().GetFrame() && RootEditableElement(element); | 1065 return element.GetDocument().GetFrame() && RootEditableElement(element); |
| 1066 } | 1066 } |
| 1067 | 1067 |
| 1068 static void ClearSelectionIfNeeded(LocalFrame* old_focused_frame, | |
| 1069 LocalFrame* new_focused_frame, | |
| 1070 Element* new_focused_element) { | |
| 1071 if (!old_focused_frame || !new_focused_frame) | |
| 1072 return; | |
| 1073 | |
| 1074 if (old_focused_frame->GetDocument() != new_focused_frame->GetDocument()) | |
| 1075 return; | |
| 1076 | |
| 1077 FrameSelection& selection = old_focused_frame->Selection(); | |
| 1078 const SelectionInDOMTree& selection_in_dom_tree = | |
| 1079 selection.GetSelectionInDOMTree(); | |
| 1080 if (selection_in_dom_tree.IsNone()) | |
| 1081 return; | |
| 1082 | |
| 1083 Node* selection_start_node = selection_in_dom_tree.Base().AnchorNode(); | |
| 1084 if (selection_start_node == new_focused_element || | |
| 1085 selection_start_node->IsDescendantOf(new_focused_element)) | |
| 1086 return; | |
| 1087 | |
| 1088 if (!EnclosingTextControl(selection_start_node)) | |
| 1089 return; | |
| 1090 | |
| 1091 if (selection_start_node->IsInShadowTree() && | |
| 1092 selection_start_node->OwnerShadowHost() == new_focused_element) | |
| 1093 return; | |
| 1094 | |
| 1095 selection.Clear(); | |
| 1096 } | |
| 1097 | |
| 1098 bool FocusController::SetFocusedElement(Element* element, | 1068 bool FocusController::SetFocusedElement(Element* element, |
| 1099 Frame* new_focused_frame) { | 1069 Frame* new_focused_frame) { |
| 1100 return SetFocusedElement( | 1070 return SetFocusedElement( |
| 1101 element, new_focused_frame, | 1071 element, new_focused_frame, |
| 1102 FocusParams(SelectionBehaviorOnFocus::kNone, kWebFocusTypeNone, nullptr)); | 1072 FocusParams(SelectionBehaviorOnFocus::kNone, kWebFocusTypeNone, nullptr)); |
| 1103 } | 1073 } |
| 1104 | 1074 |
| 1105 bool FocusController::SetFocusedElement(Element* element, | 1075 bool FocusController::SetFocusedElement(Element* element, |
| 1106 Frame* new_focused_frame, | 1076 Frame* new_focused_frame, |
| 1107 const FocusParams& params) { | 1077 const FocusParams& params) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1124 Document* new_document = nullptr; | 1094 Document* new_document = nullptr; |
| 1125 if (element) | 1095 if (element) |
| 1126 new_document = &element->GetDocument(); | 1096 new_document = &element->GetDocument(); |
| 1127 else if (new_focused_frame && new_focused_frame->IsLocalFrame()) | 1097 else if (new_focused_frame && new_focused_frame->IsLocalFrame()) |
| 1128 new_document = ToLocalFrame(new_focused_frame)->GetDocument(); | 1098 new_document = ToLocalFrame(new_focused_frame)->GetDocument(); |
| 1129 | 1099 |
| 1130 if (new_document && old_document == new_document && | 1100 if (new_document && old_document == new_document && |
| 1131 new_document->FocusedElement() == element) | 1101 new_document->FocusedElement() == element) |
| 1132 return true; | 1102 return true; |
| 1133 | 1103 |
| 1134 if (new_focused_frame && new_focused_frame->IsLocalFrame()) | |
| 1135 ClearSelectionIfNeeded(old_focused_frame, ToLocalFrame(new_focused_frame), | |
| 1136 element); | |
| 1137 | 1104 |
| 1138 if (old_document && old_document != new_document) | 1105 if (old_document && old_document != new_document) |
| 1139 old_document->ClearFocusedElement(); | 1106 old_document->ClearFocusedElement(); |
| 1140 | 1107 |
| 1141 if (new_focused_frame && !new_focused_frame->GetPage()) { | 1108 if (new_focused_frame && !new_focused_frame->GetPage()) { |
| 1142 SetFocusedFrame(nullptr); | 1109 SetFocusedFrame(nullptr); |
| 1143 return false; | 1110 return false; |
| 1144 } | 1111 } |
| 1145 SetFocusedFrame(new_focused_frame); | 1112 SetFocusedFrame(new_focused_frame); |
| 1146 | 1113 |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1353 if (focus_candidate.is_offscreen_after_scrolling) { | 1320 if (focus_candidate.is_offscreen_after_scrolling) { |
| 1354 Node* container = focus_candidate.enclosing_scrollable_box; | 1321 Node* container = focus_candidate.enclosing_scrollable_box; |
| 1355 ScrollInDirection(container, type); | 1322 ScrollInDirection(container, type); |
| 1356 return true; | 1323 return true; |
| 1357 } | 1324 } |
| 1358 | 1325 |
| 1359 // We found a new focus node, navigate to it. | 1326 // We found a new focus node, navigate to it. |
| 1360 Element* element = ToElement(focus_candidate.focusable_node); | 1327 Element* element = ToElement(focus_candidate.focusable_node); |
| 1361 DCHECK(element); | 1328 DCHECK(element); |
| 1362 | 1329 |
| 1330 if (!element->IsTextControl() && !HasEditableStyle(*element->ToNode())) { |
| 1331 // To fulfill the expectation of spatial-navigation/snav-input.html |
| 1332 // we clear selection when spatnav moves focus away from a text-field. |
| 1333 FocusedFrame()->Selection().Clear(); |
| 1334 } |
| 1363 element->focus(FocusParams(SelectionBehaviorOnFocus::kReset, type, nullptr)); | 1335 element->focus(FocusParams(SelectionBehaviorOnFocus::kReset, type, nullptr)); |
| 1364 return true; | 1336 return true; |
| 1365 } | 1337 } |
| 1366 | 1338 |
| 1367 bool FocusController::AdvanceFocusDirectionally(WebFocusType type) { | 1339 bool FocusController::AdvanceFocusDirectionally(WebFocusType type) { |
| 1368 // FIXME: Directional focus changes don't yet work with RemoteFrames. | 1340 // FIXME: Directional focus changes don't yet work with RemoteFrames. |
| 1369 if (!FocusedOrMainFrame()->IsLocalFrame()) | 1341 if (!FocusedOrMainFrame()->IsLocalFrame()) |
| 1370 return false; | 1342 return false; |
| 1371 LocalFrame* cur_frame = ToLocalFrame(FocusedOrMainFrame()); | 1343 LocalFrame* cur_frame = ToLocalFrame(FocusedOrMainFrame()); |
| 1372 DCHECK(cur_frame); | 1344 DCHECK(cur_frame); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1424 it->FocusedFrameChanged(); | 1396 it->FocusedFrameChanged(); |
| 1425 } | 1397 } |
| 1426 | 1398 |
| 1427 DEFINE_TRACE(FocusController) { | 1399 DEFINE_TRACE(FocusController) { |
| 1428 visitor->Trace(page_); | 1400 visitor->Trace(page_); |
| 1429 visitor->Trace(focused_frame_); | 1401 visitor->Trace(focused_frame_); |
| 1430 visitor->Trace(focus_changed_observers_); | 1402 visitor->Trace(focus_changed_observers_); |
| 1431 } | 1403 } |
| 1432 | 1404 |
| 1433 } // namespace blink | 1405 } // namespace blink |
| OLD | NEW |