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

Unified Diff: Source/core/html/HTMLElement.cpp

Issue 16959002: Spatial navigation enhancements (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Applied changes suggested by code reviewer. Created 7 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
« Source/core/dom/KeyboardEvent.h ('K') | « Source/core/html/HTMLElement.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/HTMLElement.cpp
diff --git a/Source/core/html/HTMLElement.cpp b/Source/core/html/HTMLElement.cpp
index 485e9b0cd5da1170b084a27a69bc73ce13b3a899..05c2cd1fcc745016e9f2ae4b6235d23921a41a5a 100644
--- a/Source/core/html/HTMLElement.cpp
+++ b/Source/core/html/HTMLElement.cpp
@@ -38,6 +38,7 @@
#include "core/dom/EventListener.h"
#include "core/dom/EventNames.h"
#include "core/dom/ExceptionCode.h"
+#include "core/dom/KeyboardEvent.h"
#include "core/dom/NodeTraversal.h"
#include "core/dom/Text.h"
#include "core/editing/markup.h"
@@ -48,6 +49,7 @@
#include "core/html/parser/HTMLParserIdioms.h"
#include "core/loader/FrameLoader.h"
#include "core/page/Frame.h"
+#include "core/page/Settings.h"
#include "core/rendering/RenderWordBreak.h"
#include <wtf/StdLibExtras.h>
#include <wtf/text/CString.h>
@@ -598,9 +600,19 @@ bool HTMLElement::hasCustomFocusLogic() const
return false;
}
+bool HTMLElement::supportsSpatialNavigationFocus() const
+{
+ EventTarget* target = const_cast<HTMLElement*>(this);
+ return target->hasEventListeners(eventNames().clickEvent)
tkent 2013/06/16 22:50:24 This looks an incompatible change. An element with
+ || target->hasEventListeners(eventNames().keydownEvent)
+ || target->hasEventListeners(eventNames().keypressEvent)
+ || target->hasEventListeners(eventNames().keyupEvent);
+}
+
bool HTMLElement::supportsFocus() const
{
- return Element::supportsFocus() || (rendererIsEditable() && parentNode() && !parentNode()->rendererIsEditable());
+ return Element::supportsFocus() || (rendererIsEditable() && parentNode() && !parentNode()->rendererIsEditable())
+ || supportsSpatialNavigationFocus();
}
String HTMLElement::contentEditable() const
@@ -1024,6 +1036,28 @@ void HTMLElement::addHTMLColorToStyle(MutableStylePropertySet* style, CSSPropert
style->setProperty(propertyID, cssValuePool().createColorValue(parsedColor.rgb()));
}
+void HTMLElement::defaultEventHandler(Event* event)
+{
+ if (event->type() == eventNames().keypressEvent && event->isKeyboardEvent()) {
+ handleKeypressEvent(toKeyboardEvent(event));
+ if (event->defaultHandled())
+ return;
+ }
+
+ StyledElement::defaultEventHandler(event);
+}
+
+void HTMLElement::handleKeypressEvent(KeyboardEvent* event)
+{
+ if (!document()->settings()->spatialNavigationEnabled() || !supportsFocus())
+ return;
+ int charCode = event->charCode();
+ if (charCode == '\r' || charCode == ' ') {
+ dispatchSimulatedClick(event);
+ event->setDefaultHandled();
+ }
+}
+
} // namespace WebCore
#ifndef NDEBUG
« Source/core/dom/KeyboardEvent.h ('K') | « Source/core/html/HTMLElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698