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

Unified Diff: Source/core/dom/Element.cpp

Issue 455223002: Make anchors mouse-focusable (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: from scratch: put focus logic in Element Created 6 years, 4 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
Index: Source/core/dom/Element.cpp
diff --git a/Source/core/dom/Element.cpp b/Source/core/dom/Element.cpp
index 0253525e3481a27a63fbedffb0bd68d3fdddb7af..2b7b2cf8673ca3a2c468c1d3b1f40bde9ac07be9 100644
--- a/Source/core/dom/Element.cpp
+++ b/Source/core/dom/Element.cpp
@@ -139,6 +139,7 @@ PassRefPtrWillBeRawPtr<Element> Element::create(const QualifiedName& tagName, Do
Element::Element(const QualifiedName& tagName, Document* document, ConstructionType type)
: ContainerNode(document, type)
, m_tagName(tagName)
+ , m_wasFocusedByMouse(false)
{
ScriptWrappable::init(this);
}
@@ -2126,6 +2127,12 @@ bool Element::supportsFocus() const
|| supportsSpatialNavigationFocus();
}
+bool Element::shouldHaveFocusAppearance() const
+{
+ ASSERT(focused());
+ return shouldShowFocusRingOnMouseFocus() || !m_wasFocusedByMouse;
+}
+
bool Element::supportsSpatialNavigationFocus() const
{
// This function checks whether the element satisfies the extended criteria
@@ -2164,8 +2171,23 @@ bool Element::isMouseFocusable() const
return isFocusable();
}
-void Element::dispatchFocusEvent(Element* oldFocusedElement, FocusType)
+void Element::willCallDefaultEventHandler(const Event& event)
{
+ if (!m_wasFocusedByMouse)
+ return;
+ if (!event.isKeyboardEvent() || event.type() != EventTypeNames::keydown)
+ return;
+ m_wasFocusedByMouse = false;
+ // Focus changes could affect the focus ring appearance if the focus ring is not shown by default on mouse focus.
+ if (!shouldShowFocusRingOnMouseFocus() && renderer())
+ renderer()->setShouldDoFullPaintInvalidation(true);
+}
+
+void Element::dispatchFocusEvent(Element* oldFocusedElement, FocusType type)
+{
+ if (type != FocusTypePage)
+ m_wasFocusedByMouse = type == FocusTypeMouse;
+
RefPtrWillBeRawPtr<FocusEvent> event = FocusEvent::create(EventTypeNames::focus, false, false, document().domWindow(), 0, oldFocusedElement);
EventDispatcher::dispatchEvent(this, FocusEventDispatchMediator::create(event.release()));
}

Powered by Google App Engine
This is Rietveld 408576698