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

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: Added null checks for document()->settings() 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
« no previous file with comments | « Source/core/html/HTMLElement.h ('k') | public/web/WebSettings.h » ('j') | 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 5953c68a61aaab77335aa6b2db57edbf83173f32..645ebf1a55d9aa7aa33af5a51b14dfd416542f96 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,6 +600,23 @@ bool HTMLElement::hasCustomFocusLogic() const
return false;
}
+bool HTMLElement::supportsSpatialNavigationFocus() const
+{
+ // This function checks whether the element satisfies the extended criteria
+ // for the element to be focusable, introduced by spatial navigation feature,
+ // i.e. checks if click or keyboard event handler is specified.
+ // This is the way to make it possible to navigate to (focus) elements
+ // which web designer meant for being active (made them respond to click events).
+
+ if (!document()->settings() || !document()->settings()->spatialNavigationEnabled())
+ return false;
+ EventTarget* target = const_cast<HTMLElement*>(this);
+ return target->hasEventListeners(eventNames().clickEvent)
+ || target->hasEventListeners(eventNames().keydownEvent)
+ || target->hasEventListeners(eventNames().keypressEvent)
+ || target->hasEventListeners(eventNames().keyupEvent);
+}
+
bool HTMLElement::supportsFocus() const
{
// FIXME: supportsFocus() can be called when layout is not up to date.
@@ -605,7 +624,8 @@ bool HTMLElement::supportsFocus() const
// But supportsFocus must return true when the element is editable, or else
// it won't be focusable. Furthermore, supportsFocus cannot just return true
// always or else tabIndex() will change for all HTML elements.
- return Element::supportsFocus() || (rendererIsEditable() && parentNode() && !parentNode()->rendererIsEditable());
+ return Element::supportsFocus() || (rendererIsEditable() && parentNode() && !parentNode()->rendererIsEditable())
+ || supportsSpatialNavigationFocus();
}
String HTMLElement::contentEditable() const
@@ -1029,6 +1049,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() || !document()->settings()->spatialNavigationEnabled() || !supportsFocus())
+ return;
+ int charCode = event->charCode();
+ if (charCode == '\r' || charCode == ' ') {
+ dispatchSimulatedClick(event);
+ event->setDefaultHandled();
+ }
+}
+
} // namespace WebCore
#ifndef NDEBUG
« no previous file with comments | « Source/core/html/HTMLElement.h ('k') | public/web/WebSettings.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698