Title: [156372] trunk/Source/WebCore
Revision
156372
Author
[email protected]
Date
2013-09-24 16:39:51 -0700 (Tue, 24 Sep 2013)

Log Message

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.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (156371 => 156372)


--- trunk/Source/WebCore/ChangeLog	2013-09-24 23:27:51 UTC (rev 156371)
+++ trunk/Source/WebCore/ChangeLog	2013-09-24 23:39:51 UTC (rev 156372)
@@ -1,3 +1,32 @@
+2013-09-24  Andreas Kling  <[email protected]>
+
+        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  <[email protected]>
 
         [CSS Shapes] Modify updateSegmentsForShapes function to use logical coordinates

Modified: trunk/Source/WebCore/dom/Document.cpp (156371 => 156372)


--- trunk/Source/WebCore/dom/Document.cpp	2013-09-24 23:27:51 UTC (rev 156371)
+++ trunk/Source/WebCore/dom/Document.cpp	2013-09-24 23:39:51 UTC (rev 156372)
@@ -5734,20 +5734,20 @@
 }
 #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)

Modified: trunk/Source/WebCore/dom/Document.h (156371 => 156372)


--- trunk/Source/WebCore/dom/Document.h	2013-09-24 23:27:51 UTC (rev 156371)
+++ trunk/Source/WebCore/dom/Document.h	2013-09-24 23:39:51 UTC (rev 156372)
@@ -1642,7 +1642,7 @@
     return &document();
 }
 
-Node* eventTargetNodeForDocument(Document*);
+Element* eventTargetElementForDocument(Document*);
 
 } // namespace WebCore
 

Modified: trunk/Source/WebCore/dom/Element.cpp (156371 => 156372)


--- trunk/Source/WebCore/dom/Element.cpp	2013-09-24 23:27:51 UTC (rev 156371)
+++ trunk/Source/WebCore/dom/Element.cpp	2013-09-24 23:39:51 UTC (rev 156372)
@@ -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 @@
     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);

Modified: trunk/Source/WebCore/dom/Element.h (156371 => 156372)


--- trunk/Source/WebCore/dom/Element.h	2013-09-24 23:27:51 UTC (rev 156371)
+++ trunk/Source/WebCore/dom/Element.h	2013-09-24 23:39:51 UTC (rev 156372)
@@ -534,6 +534,7 @@
     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);

Modified: trunk/Source/WebCore/dom/Node.cpp (156371 => 156372)


--- trunk/Source/WebCore/dom/Node.cpp	2013-09-24 23:27:51 UTC (rev 156371)
+++ trunk/Source/WebCore/dom/Node.cpp	2013-09-24 23:39:51 UTC (rev 156372)
@@ -2110,11 +2110,6 @@
     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)
 {

Modified: trunk/Source/WebCore/dom/Node.h (156371 => 156372)


--- trunk/Source/WebCore/dom/Node.h	2013-09-24 23:27:51 UTC (rev 156371)
+++ trunk/Source/WebCore/dom/Node.h	2013-09-24 23:39:51 UTC (rev 156372)
@@ -549,7 +549,6 @@
     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)

Modified: trunk/Source/WebCore/editing/AlternativeTextController.cpp (156371 => 156372)


--- trunk/Source/WebCore/editing/AlternativeTextController.cpp	2013-09-24 23:27:51 UTC (rev 156371)
+++ trunk/Source/WebCore/editing/AlternativeTextController.cpp	2013-09-24 23:39:51 UTC (rev 156372)
@@ -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 @@
     if (triggeringEvent)
         target = triggeringEvent->target();
     else
-        target = eventTargetNodeForDocument(m_frame.document());
+        target = eventTargetElementForDocument(m_frame.document());
     if (!target)
         return false;
 

Modified: trunk/Source/WebCore/page/EventHandler.cpp (156371 => 156372)


--- trunk/Source/WebCore/page/EventHandler.cpp	2013-09-24 23:27:51 UTC (rev 156371)
+++ trunk/Source/WebCore/page/EventHandler.cpp	2013-09-24 23:39:51 UTC (rev 156372)
@@ -3279,8 +3279,8 @@
 
     // 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 @@
 
     // 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 @@
     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 @@
     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 @@
     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 @@
     if (underlyingEvent)
         target = underlyingEvent->target();
     else
-        target = eventTargetNodeForDocument(m_frame.document());
+        target = eventTargetElementForDocument(m_frame.document());
     if (!target)
         return false;
     
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to