Chromium Code Reviews| Index: Source/core/html/HTMLElement.cpp |
| diff --git a/Source/core/html/HTMLElement.cpp b/Source/core/html/HTMLElement.cpp |
| index 5953c68a61aaab77335aa6b2db57edbf83173f32..6c160e96762152d93ca405c9ece2ea4410f01ccd 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()->spatialNavigationEnabled()) |
|
tkent
2013/06/21 02:36:53
document()->settings() can be NULL.
Krzysztof Olczyk
2013/06/21 07:22:51
Done.
|
| + 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()->spatialNavigationEnabled() || !supportsFocus()) |
| + return; |
| + int charCode = event->charCode(); |
| + if (charCode == '\r' || charCode == ' ') { |
| + dispatchSimulatedClick(event); |
| + event->setDefaultHandled(); |
| + } |
| +} |
| + |
| } // namespace WebCore |
| #ifndef NDEBUG |