Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1131)

Unified Diff: Source/core/input/EventHandler.cpp

Issue 1174933002: Implement ShadowRoot.delegatesFocus 2/4 (slide focus on mouse click) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebase Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/input/EventHandler.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/input/EventHandler.cpp
diff --git a/Source/core/input/EventHandler.cpp b/Source/core/input/EventHandler.cpp
index 6de87e31af73df1a1f2000de30e5dc1701f63e33..41003478ecf59c73c7289fca2080a26f331f6996 100644
--- a/Source/core/input/EventHandler.cpp
+++ b/Source/core/input/EventHandler.cpp
@@ -2071,6 +2071,8 @@ bool EventHandler::handleMouseFocus(const MouseEventWithHitTestResults& targeted
// clear swallowEvent if the page already set it (e.g., by canceling
// default behavior).
if (element) {
+ if (slideFocusOnShadowHostIfNecessary(*element))
+ return true;
if (!page->focusController().setFocusedElement(element, m_frame, WebFocusTypeMouse))
return true;
} else {
@@ -2086,6 +2088,28 @@ bool EventHandler::handleMouseFocus(const MouseEventWithHitTestResults& targeted
return false;
}
+bool EventHandler::slideFocusOnShadowHostIfNecessary(const Element& element)
+{
+ if (element.shadowRoot() && element.shadowRoot()->delegatesFocus()) {
+ Document* doc = m_frame->document();
+ if (element.containsIncludingShadowDOM(doc->focusedElement())) {
+ // If the inner element is already focused, do nothing.
+ return true;
+ }
+
+ // If the host has a focusable inner element, focus it. Otherwise, the host takes focus.
+ Page* page = m_frame->page();
+ ASSERT(page);
+ Node* next = page->focusController().findFocusableNode(WebFocusTypeForward, *element.shadowRoot());
+ if (next && next->isElementNode() && element.containsIncludingShadowDOM(next)) {
+ // Use WebFocusTypeForward instead of WebFocusTypeMouse here to mean the focus has slided.
+ toElement(next)->focus(false, WebFocusTypeForward);
+ return true;
+ }
+ }
+ return false;
+}
+
bool EventHandler::handleWheelEvent(const PlatformWheelEvent& event)
{
#define RETURN_WHEEL_EVENT_HANDLED() \
« no previous file with comments | « Source/core/input/EventHandler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698