Chromium Code Reviews| 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 |