Commit 26d79700 authored by akling@apple.com's avatar akling@apple.com

Move keyboard event dispatch from Node to Element.

<https://webkit.org/b/121873>

Reviewed by Antti Koivisto.

We only dispatch keyboard events on Elements so that logic shouldn't be in Node.

* dom/Document.cpp:
(WebCore::eventTargetElementForDocument):

    Reworked to return Element instead of Node.

* dom/Document.h:
* dom/Element.h:
* dom/Element.cpp:
(WebCore::Element::dispatchKeyEvent):

    Moved from Node to Element.

* editing/AlternativeTextController.cpp:
(WebCore::AlternativeTextController::insertDictatedText):
* page/EventHandler.cpp:
(WebCore::EventHandler::keyEvent):
(WebCore::EventHandler::handleTextInputEvent):

    Adjusted for above changes.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@156372 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent a63eb124
2013-09-24 Andreas Kling <akling@apple.com>
Move keyboard event dispatch from Node to Element.
<https://webkit.org/b/121873>
Reviewed by Antti Koivisto.
We only dispatch keyboard events on Elements so that logic shouldn't be in Node.
* dom/Document.cpp:
(WebCore::eventTargetElementForDocument):
Reworked to return Element instead of Node.
* dom/Document.h:
* dom/Element.h:
* dom/Element.cpp:
(WebCore::Element::dispatchKeyEvent):
Moved from Node to Element.
* editing/AlternativeTextController.cpp:
(WebCore::AlternativeTextController::insertDictatedText):
* page/EventHandler.cpp:
(WebCore::EventHandler::keyEvent):
(WebCore::EventHandler::handleTextInputEvent):
Adjusted for above changes.
2013-09-24 Zoltan Horvath <zoltan@webkit.org>
[CSS Shapes] Modify updateSegmentsForShapes function to use logical coordinates
......@@ -5734,20 +5734,20 @@ IntSize Document::initialViewportSize() const
}
#endif
Node* eventTargetNodeForDocument(Document* doc)
Element* eventTargetElementForDocument(Document* doc)
{
if (!doc)
return 0;
Node* node = doc->focusedElement();
if (!node && doc->isPluginDocument()) {
Element* element = doc->focusedElement();
if (!element && doc->isPluginDocument()) {
PluginDocument* pluginDocument = toPluginDocument(doc);
node = pluginDocument->pluginElement();
element = pluginDocument->pluginElement();
}
if (!node && doc->isHTMLDocument())
node = doc->body();
if (!node)
node = doc->documentElement();
return node;
if (!element && doc->isHTMLDocument())
element = doc->body();
if (!element)
element = doc->documentElement();
return element;
}
void Document::adjustFloatQuadsForScrollAndAbsoluteZoomAndFrameScale(Vector<FloatQuad>& quads, RenderObject* renderer)
......
......@@ -1642,7 +1642,7 @@ inline ScriptExecutionContext* Node::scriptExecutionContext() const
return &document();
}
Node* eventTargetNodeForDocument(Document*);
Element* eventTargetElementForDocument(Document*);
} // namespace WebCore
......
......@@ -65,6 +65,7 @@
#include "HTMLTableRowsCollection.h"
#include "InsertionPoint.h"
#include "InspectorInstrumentation.h"
#include "KeyboardEvent.h"
#include "MutationObserverInterestGroup.h"
#include "MutationRecord.h"
#include "NamedNodeMap.h"
......@@ -238,6 +239,11 @@ bool Element::shouldUseInputMethod()
return isContentEditable(UserSelectAllIsAlwaysNonEditable);
}
bool Element::dispatchKeyEvent(const PlatformKeyboardEvent& event)
{
return EventDispatcher::dispatchEvent(this, KeyboardEventDispatchMediator::create(KeyboardEvent::create(event, document().defaultView())));
}
void Element::dispatchSimulatedClick(Event* underlyingEvent, SimulatedClickMouseEventOptions eventOptions, SimulatedClickVisualOptions visualOptions)
{
EventDispatcher::dispatchSimulatedClick(this, underlyingEvent, eventOptions, visualOptions);
......
......@@ -534,6 +534,7 @@ public:
IntSize savedLayerScrollOffset() const;
void setSavedLayerScrollOffset(const IntSize&);
bool dispatchKeyEvent(const PlatformKeyboardEvent&);
void dispatchSimulatedClick(Event* underlyingEvent, SimulatedClickMouseEventOptions = SendNoEvents, SimulatedClickVisualOptions = ShowPressedLook);
void dispatchFocusInEvent(const AtomicString& eventType, PassRefPtr<Element> oldFocusedElement);
void dispatchFocusOutEvent(const AtomicString& eventType, PassRefPtr<Element> newFocusedElement);
......
......@@ -2110,11 +2110,6 @@ bool Node::dispatchDOMActivateEvent(int detail, PassRefPtr<Event> underlyingEven
return event->defaultHandled();
}
bool Node::dispatchKeyEvent(const PlatformKeyboardEvent& event)
{
return EventDispatcher::dispatchEvent(this, KeyboardEventDispatchMediator::create(KeyboardEvent::create(event, document().defaultView())));
}
bool Node::dispatchMouseEvent(const PlatformMouseEvent& event, const AtomicString& eventType,
int detail, Node* relatedTarget)
{
......
......@@ -549,7 +549,6 @@ public:
void dispatchSubtreeModifiedEvent();
bool dispatchDOMActivateEvent(int detail, PassRefPtr<Event> underlyingEvent);
bool dispatchKeyEvent(const PlatformKeyboardEvent&);
bool dispatchWheelEvent(const PlatformWheelEvent&);
bool dispatchMouseEvent(const PlatformMouseEvent&, const AtomicString& eventType, int clickCount = 0, Node* relatedTarget = 0);
#if ENABLE(GESTURE_EVENTS)
......
......@@ -33,6 +33,7 @@
#include "EditCommand.h"
#include "Editor.h"
#include "EditorClient.h"
#include "Element.h"
#include "Event.h"
#include "ExceptionCodePlaceholder.h"
#include "FloatQuad.h"
......@@ -691,7 +692,7 @@ bool AlternativeTextController::insertDictatedText(const String& text, const Vec
if (triggeringEvent)
target = triggeringEvent->target();
else
target = eventTargetNodeForDocument(m_frame.document());
target = eventTargetElementForDocument(m_frame.document());
if (!target)
return false;
......
......@@ -3279,8 +3279,8 @@ bool EventHandler::keyEvent(const PlatformKeyboardEvent& initialKeyEvent)
// Check for cases where we are too early for events -- possible unmatched key up
// from pressing return in the location bar.
RefPtr<Node> node = eventTargetNodeForDocument(m_frame.document());
if (!node)
RefPtr<Element> element = eventTargetElementForDocument(m_frame.document());
if (!element)
return false;
UserGestureIndicator gestureIndicator(DefinitelyProcessingUserGesture);
......@@ -3303,7 +3303,7 @@ bool EventHandler::keyEvent(const PlatformKeyboardEvent& initialKeyEvent)
// FIXME: it would be fair to let an input method handle KeyUp events before DOM dispatch.
if (initialKeyEvent.type() == PlatformEvent::KeyUp || initialKeyEvent.type() == PlatformEvent::Char)
return !node->dispatchKeyEvent(initialKeyEvent);
return !element->dispatchKeyEvent(initialKeyEvent);
bool backwardCompatibilityMode = needsKeyboardEventDisambiguationQuirks();
......@@ -3313,10 +3313,10 @@ bool EventHandler::keyEvent(const PlatformKeyboardEvent& initialKeyEvent)
RefPtr<KeyboardEvent> keydown = KeyboardEvent::create(keyDownEvent, m_frame.document()->defaultView());
if (matchedAnAccessKey)
keydown->setDefaultPrevented(true);
keydown->setTarget(node);
keydown->setTarget(element);
if (initialKeyEvent.type() == PlatformEvent::RawKeyDown) {
node->dispatchEvent(keydown, IGNORE_EXCEPTION);
element->dispatchEvent(keydown, IGNORE_EXCEPTION);
// If frame changed as a result of keydown dispatch, then return true to avoid sending a subsequent keypress message to the new frame.
bool changedFocusedFrame = m_frame.page() && &m_frame != &m_frame.page()->focusController().focusedOrMainFrame();
return keydown->defaultHandled() || keydown->defaultPrevented() || changedFocusedFrame;
......@@ -3334,22 +3334,22 @@ bool EventHandler::keyEvent(const PlatformKeyboardEvent& initialKeyEvent)
if (handledByInputMethod) {
keyDownEvent.setWindowsVirtualKeyCode(CompositionEventKeyCode);
keydown = KeyboardEvent::create(keyDownEvent, m_frame.document()->defaultView());
keydown->setTarget(node);
keydown->setTarget(element);
keydown->setDefaultHandled();
}
node->dispatchEvent(keydown, IGNORE_EXCEPTION);
element->dispatchEvent(keydown, IGNORE_EXCEPTION);
// If frame changed as a result of keydown dispatch, then return early to avoid sending a subsequent keypress message to the new frame.
bool changedFocusedFrame = m_frame.page() && &m_frame != &m_frame.page()->focusController().focusedOrMainFrame();
bool keydownResult = keydown->defaultHandled() || keydown->defaultPrevented() || changedFocusedFrame;
if (handledByInputMethod || (keydownResult && !backwardCompatibilityMode))
return keydownResult;
// Focus may have changed during keydown handling, so refetch node.
// But if we are dispatching a fake backward compatibility keypress, then we pretend that the keypress happened on the original node.
// Focus may have changed during keydown handling, so refetch element.
// But if we are dispatching a fake backward compatibility keypress, then we pretend that the keypress happened on the original element.
if (!keydownResult) {
node = eventTargetNodeForDocument(m_frame.document());
if (!node)
element = eventTargetElementForDocument(m_frame.document());
if (!element)
return false;
}
......@@ -3358,13 +3358,13 @@ bool EventHandler::keyEvent(const PlatformKeyboardEvent& initialKeyEvent)
if (keyPressEvent.text().isEmpty())
return keydownResult;
RefPtr<KeyboardEvent> keypress = KeyboardEvent::create(keyPressEvent, m_frame.document()->defaultView());
keypress->setTarget(node);
keypress->setTarget(element);
if (keydownResult)
keypress->setDefaultPrevented(true);
#if PLATFORM(MAC)
keypress->keypressCommands() = keydown->keypressCommands();
#endif
node->dispatchEvent(keypress, IGNORE_EXCEPTION);
element->dispatchEvent(keypress, IGNORE_EXCEPTION);
return keydownResult || keypress->defaultPrevented() || keypress->defaultHandled();
}
......@@ -3704,7 +3704,7 @@ bool EventHandler::handleTextInputEvent(const String& text, Event* underlyingEve
if (underlyingEvent)
target = underlyingEvent->target();
else
target = eventTargetNodeForDocument(m_frame.document());
target = eventTargetElementForDocument(m_frame.document());
if (!target)
return false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment