| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 #include "core/frame/LocalFrame.h" | 47 #include "core/frame/LocalFrame.h" |
| 48 #include "core/frame/RemoteFrame.h" | 48 #include "core/frame/RemoteFrame.h" |
| 49 #include "core/frame/Settings.h" | 49 #include "core/frame/Settings.h" |
| 50 #include "core/html/HTMLAreaElement.h" | 50 #include "core/html/HTMLAreaElement.h" |
| 51 #include "core/html/HTMLImageElement.h" | 51 #include "core/html/HTMLImageElement.h" |
| 52 #include "core/html/HTMLPlugInElement.h" | 52 #include "core/html/HTMLPlugInElement.h" |
| 53 #include "core/html/HTMLShadowElement.h" | 53 #include "core/html/HTMLShadowElement.h" |
| 54 #include "core/html/HTMLSlotElement.h" | 54 #include "core/html/HTMLSlotElement.h" |
| 55 #include "core/html/TextControlElement.h" | 55 #include "core/html/TextControlElement.h" |
| 56 #include "core/input/EventHandler.h" | 56 #include "core/input/EventHandler.h" |
| 57 #include "core/layout/HitTestResult.h" |
| 57 #include "core/page/ChromeClient.h" | 58 #include "core/page/ChromeClient.h" |
| 59 #include "core/page/FocusChangedObserver.h" |
| 58 #include "core/page/FrameTree.h" | 60 #include "core/page/FrameTree.h" |
| 59 #include "core/page/Page.h" | 61 #include "core/page/Page.h" |
| 60 #include "core/layout/HitTestResult.h" | |
| 61 #include "core/page/SpatialNavigation.h" | 62 #include "core/page/SpatialNavigation.h" |
| 63 |
| 62 #include <limits> | 64 #include <limits> |
| 63 | 65 |
| 64 namespace blink { | 66 namespace blink { |
| 65 | 67 |
| 66 using namespace HTMLNames; | 68 using namespace HTMLNames; |
| 67 | 69 |
| 68 namespace { | 70 namespace { |
| 69 | 71 |
| 70 inline bool isShadowInsertionPointFocusScopeOwner(Element& element) { | 72 inline bool isShadowInsertionPointFocusScopeOwner(Element& element) { |
| 71 return isActiveShadowInsertionPoint(element) && | 73 return isActiveShadowInsertionPoint(element) && |
| (...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 newFrame->selection().setFocused(true); | 761 newFrame->selection().setFocused(true); |
| 760 newFrame->domWindow()->dispatchEvent(Event::create(EventTypeNames::focus)); | 762 newFrame->domWindow()->dispatchEvent(Event::create(EventTypeNames::focus)); |
| 761 } | 763 } |
| 762 | 764 |
| 763 m_isChangingFocusedFrame = false; | 765 m_isChangingFocusedFrame = false; |
| 764 | 766 |
| 765 // Checking client() is necessary, as the frame might have been detached as | 767 // Checking client() is necessary, as the frame might have been detached as |
| 766 // part of dispatching the focus event above. See https://crbug.com/570874. | 768 // part of dispatching the focus event above. See https://crbug.com/570874. |
| 767 if (m_focusedFrame && m_focusedFrame->client() && notifyEmbedder) | 769 if (m_focusedFrame && m_focusedFrame->client() && notifyEmbedder) |
| 768 m_focusedFrame->client()->frameFocused(); | 770 m_focusedFrame->client()->frameFocused(); |
| 771 |
| 772 notifyFocusChangedObservers(); |
| 769 } | 773 } |
| 770 | 774 |
| 771 void FocusController::focusDocumentView(Frame* frame, bool notifyEmbedder) { | 775 void FocusController::focusDocumentView(Frame* frame, bool notifyEmbedder) { |
| 772 DCHECK(!frame || frame->page() == m_page); | 776 DCHECK(!frame || frame->page() == m_page); |
| 773 if (m_focusedFrame == frame) | 777 if (m_focusedFrame == frame) |
| 774 return; | 778 return; |
| 775 | 779 |
| 776 LocalFrame* focusedFrame = (m_focusedFrame && m_focusedFrame->isLocalFrame()) | 780 LocalFrame* focusedFrame = (m_focusedFrame && m_focusedFrame->isLocalFrame()) |
| 777 ? toLocalFrame(m_focusedFrame.get()) | 781 ? toLocalFrame(m_focusedFrame.get()) |
| 778 : nullptr; | 782 : nullptr; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 861 setFocusedFrame(m_page->mainFrame()); | 865 setFocusedFrame(m_page->mainFrame()); |
| 862 | 866 |
| 863 // setFocusedFrame above might reject to update m_focusedFrame, or | 867 // setFocusedFrame above might reject to update m_focusedFrame, or |
| 864 // m_focusedFrame might be changed by blur/focus event handlers. | 868 // m_focusedFrame might be changed by blur/focus event handlers. |
| 865 if (m_focusedFrame && m_focusedFrame->isLocalFrame() && | 869 if (m_focusedFrame && m_focusedFrame->isLocalFrame() && |
| 866 toLocalFrame(m_focusedFrame.get())->view()) { | 870 toLocalFrame(m_focusedFrame.get())->view()) { |
| 867 toLocalFrame(m_focusedFrame.get())->selection().setFocused(focused); | 871 toLocalFrame(m_focusedFrame.get())->selection().setFocused(focused); |
| 868 dispatchEventsOnWindowAndFocusedElement( | 872 dispatchEventsOnWindowAndFocusedElement( |
| 869 toLocalFrame(m_focusedFrame.get())->document(), focused); | 873 toLocalFrame(m_focusedFrame.get())->document(), focused); |
| 870 } | 874 } |
| 875 |
| 876 notifyFocusChangedObservers(); |
| 871 } | 877 } |
| 872 | 878 |
| 873 bool FocusController::setInitialFocus(WebFocusType type) { | 879 bool FocusController::setInitialFocus(WebFocusType type) { |
| 874 bool didAdvanceFocus = advanceFocus(type, true); | 880 bool didAdvanceFocus = advanceFocus(type, true); |
| 875 | 881 |
| 876 // If focus is being set initially, accessibility needs to be informed that | 882 // If focus is being set initially, accessibility needs to be informed that |
| 877 // system focus has moved into the web area again, even if focus did not | 883 // system focus has moved into the web area again, even if focus did not |
| 878 // change within WebCore. PostNotification is called instead of | 884 // change within WebCore. PostNotification is called instead of |
| 879 // handleFocusedUIElementChanged, because this will send the notification even | 885 // handleFocusedUIElementChanged, because this will send the notification even |
| 880 // if the element is the same. | 886 // if the element is the same. |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1389 nodeRectInAbsoluteCoordinates(container, true /* ignore border */); | 1395 nodeRectInAbsoluteCoordinates(container, true /* ignore border */); |
| 1390 container = | 1396 container = |
| 1391 scrollableEnclosingBoxOrParentFrameForNodeInDirection(type, container); | 1397 scrollableEnclosingBoxOrParentFrameForNodeInDirection(type, container); |
| 1392 if (container && container->isDocumentNode()) | 1398 if (container && container->isDocumentNode()) |
| 1393 toDocument(container)->updateStyleAndLayoutIgnorePendingStylesheets(); | 1399 toDocument(container)->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 1394 } while (!consumed && container); | 1400 } while (!consumed && container); |
| 1395 | 1401 |
| 1396 return consumed; | 1402 return consumed; |
| 1397 } | 1403 } |
| 1398 | 1404 |
| 1405 void FocusController::registerFocusChangedObserver( |
| 1406 FocusChangedObserver* observer) { |
| 1407 DCHECK(observer); |
| 1408 DCHECK(!m_focusChangedObservers.contains(observer)); |
| 1409 m_focusChangedObservers.insert(observer); |
| 1410 } |
| 1411 |
| 1412 void FocusController::notifyFocusChangedObservers() const { |
| 1413 for (const auto& it : m_focusChangedObservers) |
| 1414 it->focusedFrameChanged(); |
| 1415 } |
| 1416 |
| 1399 DEFINE_TRACE(FocusController) { | 1417 DEFINE_TRACE(FocusController) { |
| 1400 visitor->trace(m_page); | 1418 visitor->trace(m_page); |
| 1401 visitor->trace(m_focusedFrame); | 1419 visitor->trace(m_focusedFrame); |
| 1420 visitor->trace(m_focusChangedObservers); |
| 1402 } | 1421 } |
| 1403 | 1422 |
| 1404 } // namespace blink | 1423 } // namespace blink |
| OLD | NEW |