| 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 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 toHTMLSlotElement(parent)->assignedNodes().isEmpty()) | 331 toHTMLSlotElement(parent)->assignedNodes().isEmpty()) |
| 332 return !SlotScopedTraversal::isSlotScoped(current) && | 332 return !SlotScopedTraversal::isSlotScoped(current) && |
| 333 toHTMLSlotElement(parent) == slot; | 333 toHTMLSlotElement(parent) == slot; |
| 334 parent = parent->parentElement(); | 334 parent = parent->parentElement(); |
| 335 } | 335 } |
| 336 return false; | 336 return false; |
| 337 } | 337 } |
| 338 | 338 |
| 339 inline void dispatchBlurEvent(const Document& document, | 339 inline void dispatchBlurEvent(const Document& document, |
| 340 Element& focusedElement) { | 340 Element& focusedElement) { |
| 341 focusedElement.dispatchBlurEvent(nullptr, WebFocusTypePage); | 341 focusedElement.dispatchBlurEvent(nullptr, WebFocusTypePage, |
| 342 InputDeviceCapabilities::Null); |
| 342 if (focusedElement == document.focusedElement()) { | 343 if (focusedElement == document.focusedElement()) { |
| 343 focusedElement.dispatchFocusOutEvent(EventTypeNames::focusout, nullptr); | 344 focusedElement.dispatchFocusOutEvent(EventTypeNames::focusout, nullptr, |
| 344 if (focusedElement == document.focusedElement()) | 345 InputDeviceCapabilities::Null); |
| 345 focusedElement.dispatchFocusOutEvent(EventTypeNames::DOMFocusOut, | 346 if (focusedElement == document.focusedElement()) { |
| 346 nullptr); | 347 focusedElement.dispatchFocusOutEvent(EventTypeNames::DOMFocusOut, nullptr, |
| 348 InputDeviceCapabilities::Null); |
| 349 } |
| 347 } | 350 } |
| 348 } | 351 } |
| 349 | 352 |
| 350 inline void dispatchFocusEvent(const Document& document, | 353 inline void dispatchFocusEvent(const Document& document, |
| 351 Element& focusedElement) { | 354 Element& focusedElement) { |
| 352 focusedElement.dispatchFocusEvent(0, WebFocusTypePage); | 355 focusedElement.dispatchFocusEvent(0, WebFocusTypePage, |
| 356 InputDeviceCapabilities::Null); |
| 353 if (focusedElement == document.focusedElement()) { | 357 if (focusedElement == document.focusedElement()) { |
| 354 focusedElement.dispatchFocusInEvent(EventTypeNames::focusin, nullptr, | 358 focusedElement.dispatchFocusInEvent(EventTypeNames::focusin, nullptr, |
| 355 WebFocusTypePage); | 359 WebFocusTypePage, |
| 356 if (focusedElement == document.focusedElement()) | 360 InputDeviceCapabilities::Null); |
| 361 if (focusedElement == document.focusedElement()) { |
| 357 focusedElement.dispatchFocusInEvent(EventTypeNames::DOMFocusIn, nullptr, | 362 focusedElement.dispatchFocusInEvent(EventTypeNames::DOMFocusIn, nullptr, |
| 358 WebFocusTypePage); | 363 WebFocusTypePage, |
| 364 InputDeviceCapabilities::Null); |
| 365 } |
| 359 } | 366 } |
| 360 } | 367 } |
| 361 | 368 |
| 362 inline void dispatchEventsOnWindowAndFocusedElement(Document* document, | 369 inline void dispatchEventsOnWindowAndFocusedElement(Document* document, |
| 363 bool focused) { | 370 bool focused) { |
| 364 DCHECK(document); | 371 DCHECK(document); |
| 365 // If we have a focused element we should dispatch blur on it before we blur | 372 // If we have a focused element we should dispatch blur on it before we blur |
| 366 // the window. If we have a focused element we should dispatch focus on it | 373 // the window. If we have a focused element we should dispatch focus on it |
| 367 // after we focus the window. https://bugs.webkit.org/show_bug.cgi?id=27105 | 374 // after we focus the window. https://bugs.webkit.org/show_bug.cgi?id=27105 |
| 368 | 375 |
| (...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 870 toLocalFrame(m_focusedFrame.get())->view()) { | 877 toLocalFrame(m_focusedFrame.get())->view()) { |
| 871 toLocalFrame(m_focusedFrame.get())->selection().setFocused(focused); | 878 toLocalFrame(m_focusedFrame.get())->selection().setFocused(focused); |
| 872 dispatchEventsOnWindowAndFocusedElement( | 879 dispatchEventsOnWindowAndFocusedElement( |
| 873 toLocalFrame(m_focusedFrame.get())->document(), focused); | 880 toLocalFrame(m_focusedFrame.get())->document(), focused); |
| 874 } | 881 } |
| 875 | 882 |
| 876 notifyFocusChangedObservers(); | 883 notifyFocusChangedObservers(); |
| 877 } | 884 } |
| 878 | 885 |
| 879 bool FocusController::setInitialFocus(WebFocusType type) { | 886 bool FocusController::setInitialFocus(WebFocusType type) { |
| 880 bool didAdvanceFocus = advanceFocus(type, true); | 887 bool didAdvanceFocus = |
| 888 advanceFocus(type, true, InputDeviceCapabilities::Null); |
| 881 | 889 |
| 882 // If focus is being set initially, accessibility needs to be informed that | 890 // If focus is being set initially, accessibility needs to be informed that |
| 883 // system focus has moved into the web area again, even if focus did not | 891 // system focus has moved into the web area again, even if focus did not |
| 884 // change within WebCore. PostNotification is called instead of | 892 // change within WebCore. PostNotification is called instead of |
| 885 // handleFocusedUIElementChanged, because this will send the notification even | 893 // handleFocusedUIElementChanged, because this will send the notification even |
| 886 // if the element is the same. | 894 // if the element is the same. |
| 887 if (focusedOrMainFrame()->isLocalFrame()) { | 895 if (focusedOrMainFrame()->isLocalFrame()) { |
| 888 Document* document = toLocalFrame(focusedOrMainFrame())->document(); | 896 Document* document = toLocalFrame(focusedOrMainFrame())->document(); |
| 889 if (AXObjectCache* cache = document->existingAXObjectCache()) | 897 if (AXObjectCache* cache = document->existingAXObjectCache()) |
| 890 cache->handleInitialFocus(); | 898 cache->handleInitialFocus(); |
| 891 } | 899 } |
| 892 | 900 |
| 893 return didAdvanceFocus; | 901 return didAdvanceFocus; |
| 894 } | 902 } |
| 895 | 903 |
| 896 bool FocusController::advanceFocus( | 904 bool FocusController::advanceFocus( |
| 897 WebFocusType type, | 905 WebFocusType type, |
| 898 bool initialFocus, | 906 bool initialFocus, |
| 899 InputDeviceCapabilities* sourceCapabilities) { | 907 const InputDeviceCapabilitiesValue& sourceCapabilities) { |
| 900 switch (type) { | 908 switch (type) { |
| 901 case WebFocusTypeForward: | 909 case WebFocusTypeForward: |
| 902 case WebFocusTypeBackward: { | 910 case WebFocusTypeBackward: { |
| 903 // We should never hit this when a RemoteFrame is focused, since the key | 911 // We should never hit this when a RemoteFrame is focused, since the key |
| 904 // event that initiated focus advancement should've been routed to that | 912 // event that initiated focus advancement should've been routed to that |
| 905 // frame's process from the beginning. | 913 // frame's process from the beginning. |
| 906 LocalFrame* startingFrame = toLocalFrame(focusedOrMainFrame()); | 914 LocalFrame* startingFrame = toLocalFrame(focusedOrMainFrame()); |
| 907 return advanceFocusInDocumentOrder(startingFrame, nullptr, type, | 915 return advanceFocusInDocumentOrder(startingFrame, nullptr, type, |
| 908 initialFocus, sourceCapabilities); | 916 initialFocus, sourceCapabilities); |
| 909 } | 917 } |
| 910 case WebFocusTypeLeft: | 918 case WebFocusTypeLeft: |
| 911 case WebFocusTypeRight: | 919 case WebFocusTypeRight: |
| 912 case WebFocusTypeUp: | 920 case WebFocusTypeUp: |
| 913 case WebFocusTypeDown: | 921 case WebFocusTypeDown: |
| 914 return advanceFocusDirectionally(type); | 922 return advanceFocusDirectionally(type); |
| 915 default: | 923 default: |
| 916 NOTREACHED(); | 924 NOTREACHED(); |
| 917 } | 925 } |
| 918 | 926 |
| 919 return false; | 927 return false; |
| 920 } | 928 } |
| 921 | 929 |
| 922 bool FocusController::advanceFocusAcrossFrames( | 930 bool FocusController::advanceFocusAcrossFrames( |
| 923 WebFocusType type, | 931 WebFocusType type, |
| 924 RemoteFrame* from, | 932 RemoteFrame* from, |
| 925 LocalFrame* to, | 933 LocalFrame* to, |
| 926 InputDeviceCapabilities* sourceCapabilities) { | 934 const InputDeviceCapabilitiesValue& sourceCapabilities) { |
| 927 // If we are shifting focus from a child frame to its parent, the | 935 // If we are shifting focus from a child frame to its parent, the |
| 928 // child frame has no more focusable elements, and we should continue | 936 // child frame has no more focusable elements, and we should continue |
| 929 // looking for focusable elements in the parent, starting from the <iframe> | 937 // looking for focusable elements in the parent, starting from the <iframe> |
| 930 // element of the child frame. | 938 // element of the child frame. |
| 931 Element* start = nullptr; | 939 Element* start = nullptr; |
| 932 if (from->tree().parent() == to) { | 940 if (from->tree().parent() == to) { |
| 933 DCHECK(from->owner()->isLocal()); | 941 DCHECK(from->owner()->isLocal()); |
| 934 start = toHTMLFrameOwnerElement(from->owner()); | 942 start = toHTMLFrameOwnerElement(from->owner()); |
| 935 } | 943 } |
| 936 | 944 |
| 937 return advanceFocusInDocumentOrder(to, start, type, false, | 945 return advanceFocusInDocumentOrder(to, start, type, false, |
| 938 sourceCapabilities); | 946 sourceCapabilities); |
| 939 } | 947 } |
| 940 | 948 |
| 941 #if DCHECK_IS_ON() | 949 #if DCHECK_IS_ON() |
| 942 inline bool isNonFocusableShadowHost(const Element& element) { | 950 inline bool isNonFocusableShadowHost(const Element& element) { |
| 943 return isShadowHostWithoutCustomFocusLogic(element) && !element.isFocusable(); | 951 return isShadowHostWithoutCustomFocusLogic(element) && !element.isFocusable(); |
| 944 } | 952 } |
| 945 #endif | 953 #endif |
| 946 | 954 |
| 947 bool FocusController::advanceFocusInDocumentOrder( | 955 bool FocusController::advanceFocusInDocumentOrder( |
| 948 LocalFrame* frame, | 956 LocalFrame* frame, |
| 949 Element* start, | 957 Element* start, |
| 950 WebFocusType type, | 958 WebFocusType type, |
| 951 bool initialFocus, | 959 bool initialFocus, |
| 952 InputDeviceCapabilities* sourceCapabilities) { | 960 const InputDeviceCapabilitiesValue& sourceCapabilities) { |
| 953 DCHECK(frame); | 961 DCHECK(frame); |
| 954 Document* document = frame->document(); | 962 Document* document = frame->document(); |
| 955 document->updateDistribution(); | 963 document->updateDistribution(); |
| 956 | 964 |
| 957 Element* current = start; | 965 Element* current = start; |
| 958 #if DCHECK_IS_ON() | 966 #if DCHECK_IS_ON() |
| 959 DCHECK(!current || !isNonFocusableShadowHost(*current)); | 967 DCHECK(!current || !isNonFocusableShadowHost(*current)); |
| 960 #endif | 968 #endif |
| 961 if (!current && !initialFocus) | 969 if (!current && !initialFocus) |
| 962 current = document->sequentialFocusNavigationStartingPoint(type); | 970 current = document->sequentialFocusNavigationStartingPoint(type); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1091 selectionStartNode->ownerShadowHost() == newFocusedElement) | 1099 selectionStartNode->ownerShadowHost() == newFocusedElement) |
| 1092 return; | 1100 return; |
| 1093 | 1101 |
| 1094 selection.clear(); | 1102 selection.clear(); |
| 1095 } | 1103 } |
| 1096 | 1104 |
| 1097 bool FocusController::setFocusedElement(Element* element, | 1105 bool FocusController::setFocusedElement(Element* element, |
| 1098 Frame* newFocusedFrame) { | 1106 Frame* newFocusedFrame) { |
| 1099 return setFocusedElement( | 1107 return setFocusedElement( |
| 1100 element, newFocusedFrame, | 1108 element, newFocusedFrame, |
| 1101 FocusParams(SelectionBehaviorOnFocus::None, WebFocusTypeNone, nullptr)); | 1109 FocusParams(SelectionBehaviorOnFocus::None, WebFocusTypeNone, |
| 1110 InputDeviceCapabilities::Null)); |
| 1102 } | 1111 } |
| 1103 | 1112 |
| 1104 bool FocusController::setFocusedElement(Element* element, | 1113 bool FocusController::setFocusedElement(Element* element, |
| 1105 Frame* newFocusedFrame, | 1114 Frame* newFocusedFrame, |
| 1106 const FocusParams& params) { | 1115 const FocusParams& params) { |
| 1107 LocalFrame* oldFocusedFrame = focusedFrame(); | 1116 LocalFrame* oldFocusedFrame = focusedFrame(); |
| 1108 Document* oldDocument = | 1117 Document* oldDocument = |
| 1109 oldFocusedFrame ? oldFocusedFrame->document() : nullptr; | 1118 oldFocusedFrame ? oldFocusedFrame->document() : nullptr; |
| 1110 | 1119 |
| 1111 Element* oldFocusedElement = | 1120 Element* oldFocusedElement = |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1343 if (focusCandidate.isOffscreenAfterScrolling) { | 1352 if (focusCandidate.isOffscreenAfterScrolling) { |
| 1344 Node* container = focusCandidate.enclosingScrollableBox; | 1353 Node* container = focusCandidate.enclosingScrollableBox; |
| 1345 scrollInDirection(container, type); | 1354 scrollInDirection(container, type); |
| 1346 return true; | 1355 return true; |
| 1347 } | 1356 } |
| 1348 | 1357 |
| 1349 // We found a new focus node, navigate to it. | 1358 // We found a new focus node, navigate to it. |
| 1350 Element* element = toElement(focusCandidate.focusableNode); | 1359 Element* element = toElement(focusCandidate.focusableNode); |
| 1351 DCHECK(element); | 1360 DCHECK(element); |
| 1352 | 1361 |
| 1353 element->focus(FocusParams(SelectionBehaviorOnFocus::Reset, type, nullptr)); | 1362 element->focus(FocusParams(SelectionBehaviorOnFocus::Reset, type, |
| 1363 InputDeviceCapabilities::Null)); |
| 1354 return true; | 1364 return true; |
| 1355 } | 1365 } |
| 1356 | 1366 |
| 1357 bool FocusController::advanceFocusDirectionally(WebFocusType type) { | 1367 bool FocusController::advanceFocusDirectionally(WebFocusType type) { |
| 1358 // FIXME: Directional focus changes don't yet work with RemoteFrames. | 1368 // FIXME: Directional focus changes don't yet work with RemoteFrames. |
| 1359 if (!focusedOrMainFrame()->isLocalFrame()) | 1369 if (!focusedOrMainFrame()->isLocalFrame()) |
| 1360 return false; | 1370 return false; |
| 1361 LocalFrame* curFrame = toLocalFrame(focusedOrMainFrame()); | 1371 LocalFrame* curFrame = toLocalFrame(focusedOrMainFrame()); |
| 1362 DCHECK(curFrame); | 1372 DCHECK(curFrame); |
| 1363 | 1373 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1414 it->focusedFrameChanged(); | 1424 it->focusedFrameChanged(); |
| 1415 } | 1425 } |
| 1416 | 1426 |
| 1417 DEFINE_TRACE(FocusController) { | 1427 DEFINE_TRACE(FocusController) { |
| 1418 visitor->trace(m_page); | 1428 visitor->trace(m_page); |
| 1419 visitor->trace(m_focusedFrame); | 1429 visitor->trace(m_focusedFrame); |
| 1420 visitor->trace(m_focusChangedObservers); | 1430 visitor->trace(m_focusChangedObservers); |
| 1421 } | 1431 } |
| 1422 | 1432 |
| 1423 } // namespace blink | 1433 } // namespace blink |
| OLD | NEW |