Changeset 156372 in webkit


Ignore:
Timestamp:
Sep 24, 2013 4:39:51 PM (11 years ago)
Author:
akling@apple.com
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.

Location:
trunk/Source/WebCore
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r156364 r156372  
     12013-09-24  Andreas Kling  <akling@apple.com>
     2
     3        Move keyboard event dispatch from Node to Element.
     4        <https://webkit.org/b/121873>
     5
     6        Reviewed by Antti Koivisto.
     7
     8        We only dispatch keyboard events on Elements so that logic shouldn't be in Node.
     9
     10        * dom/Document.cpp:
     11        (WebCore::eventTargetElementForDocument):
     12
     13            Reworked to return Element instead of Node.
     14
     15        * dom/Document.h:
     16        * dom/Element.h:
     17        * dom/Element.cpp:
     18        (WebCore::Element::dispatchKeyEvent):
     19
     20            Moved from Node to Element.
     21
     22        * editing/AlternativeTextController.cpp:
     23        (WebCore::AlternativeTextController::insertDictatedText):
     24        * page/EventHandler.cpp:
     25        (WebCore::EventHandler::keyEvent):
     26        (WebCore::EventHandler::handleTextInputEvent):
     27
     28            Adjusted for above changes.
     29
    1302013-09-24  Zoltan Horvath  <zoltan@webkit.org>
    231
  • trunk/Source/WebCore/dom/Document.cpp

    r156339 r156372  
    57355735#endif
    57365736
    5737 Node* eventTargetNodeForDocument(Document* doc)
     5737Element* eventTargetElementForDocument(Document* doc)
    57385738{
    57395739    if (!doc)
    57405740        return 0;
    5741     Node* node = doc->focusedElement();
    5742     if (!node && doc->isPluginDocument()) {
     5741    Element* element = doc->focusedElement();
     5742    if (!element && doc->isPluginDocument()) {
    57435743        PluginDocument* pluginDocument = toPluginDocument(doc);
    5744         node = pluginDocument->pluginElement();
    5745     }
    5746     if (!node && doc->isHTMLDocument())
    5747         node = doc->body();
    5748     if (!node)
    5749         node = doc->documentElement();
    5750     return node;
     5744        element = pluginDocument->pluginElement();
     5745    }
     5746    if (!element && doc->isHTMLDocument())
     5747        element = doc->body();
     5748    if (!element)
     5749        element = doc->documentElement();
     5750    return element;
    57515751}
    57525752
  • trunk/Source/WebCore/dom/Document.h

    r156256 r156372  
    16431643}
    16441644
    1645 Node* eventTargetNodeForDocument(Document*);
     1645Element* eventTargetElementForDocument(Document*);
    16461646
    16471647} // namespace WebCore
  • trunk/Source/WebCore/dom/Element.cpp

    r156256 r156372  
    6666#include "InsertionPoint.h"
    6767#include "InspectorInstrumentation.h"
     68#include "KeyboardEvent.h"
    6869#include "MutationObserverInterestGroup.h"
    6970#include "MutationRecord.h"
     
    239240}
    240241
     242bool Element::dispatchKeyEvent(const PlatformKeyboardEvent& event)
     243{
     244    return EventDispatcher::dispatchEvent(this, KeyboardEventDispatchMediator::create(KeyboardEvent::create(event, document().defaultView())));
     245}
     246
    241247void Element::dispatchSimulatedClick(Event* underlyingEvent, SimulatedClickMouseEventOptions eventOptions, SimulatedClickVisualOptions visualOptions)
    242248{
  • trunk/Source/WebCore/dom/Element.h

    r156250 r156372  
    535535    void setSavedLayerScrollOffset(const IntSize&);
    536536
     537    bool dispatchKeyEvent(const PlatformKeyboardEvent&);
    537538    void dispatchSimulatedClick(Event* underlyingEvent, SimulatedClickMouseEventOptions = SendNoEvents, SimulatedClickVisualOptions = ShowPressedLook);
    538539    void dispatchFocusInEvent(const AtomicString& eventType, PassRefPtr<Element> oldFocusedElement);
  • trunk/Source/WebCore/dom/Node.cpp

    r156256 r156372  
    21112111}
    21122112
    2113 bool Node::dispatchKeyEvent(const PlatformKeyboardEvent& event)
    2114 {
    2115     return EventDispatcher::dispatchEvent(this, KeyboardEventDispatchMediator::create(KeyboardEvent::create(event, document().defaultView())));
    2116 }
    2117 
    21182113bool Node::dispatchMouseEvent(const PlatformMouseEvent& event, const AtomicString& eventType,
    21192114    int detail, Node* relatedTarget)
  • trunk/Source/WebCore/dom/Node.h

    r156250 r156372  
    550550    bool dispatchDOMActivateEvent(int detail, PassRefPtr<Event> underlyingEvent);
    551551
    552     bool dispatchKeyEvent(const PlatformKeyboardEvent&);
    553552    bool dispatchWheelEvent(const PlatformWheelEvent&);
    554553    bool dispatchMouseEvent(const PlatformMouseEvent&, const AtomicString& eventType, int clickCount = 0, Node* relatedTarget = 0);
  • trunk/Source/WebCore/editing/AlternativeTextController.cpp

    r155228 r156372  
    3434#include "Editor.h"
    3535#include "EditorClient.h"
     36#include "Element.h"
    3637#include "Event.h"
    3738#include "ExceptionCodePlaceholder.h"
     
    692693        target = triggeringEvent->target();
    693694    else
    694         target = eventTargetNodeForDocument(m_frame.document());
     695        target = eventTargetElementForDocument(m_frame.document());
    695696    if (!target)
    696697        return false;
  • trunk/Source/WebCore/page/EventHandler.cpp

    r155548 r156372  
    32803280    // Check for cases where we are too early for events -- possible unmatched key up
    32813281    // from pressing return in the location bar.
    3282     RefPtr<Node> node = eventTargetNodeForDocument(m_frame.document());
    3283     if (!node)
     3282    RefPtr<Element> element = eventTargetElementForDocument(m_frame.document());
     3283    if (!element)
    32843284        return false;
    32853285
     
    33043304    // FIXME: it would be fair to let an input method handle KeyUp events before DOM dispatch.
    33053305    if (initialKeyEvent.type() == PlatformEvent::KeyUp || initialKeyEvent.type() == PlatformEvent::Char)
    3306         return !node->dispatchKeyEvent(initialKeyEvent);
     3306        return !element->dispatchKeyEvent(initialKeyEvent);
    33073307
    33083308    bool backwardCompatibilityMode = needsKeyboardEventDisambiguationQuirks();
     
    33143314    if (matchedAnAccessKey)
    33153315        keydown->setDefaultPrevented(true);
    3316     keydown->setTarget(node);
     3316    keydown->setTarget(element);
    33173317
    33183318    if (initialKeyEvent.type() == PlatformEvent::RawKeyDown) {
    3319         node->dispatchEvent(keydown, IGNORE_EXCEPTION);
     3319        element->dispatchEvent(keydown, IGNORE_EXCEPTION);
    33203320        // If frame changed as a result of keydown dispatch, then return true to avoid sending a subsequent keypress message to the new frame.
    33213321        bool changedFocusedFrame = m_frame.page() && &m_frame != &m_frame.page()->focusController().focusedOrMainFrame();
     
    33353335        keyDownEvent.setWindowsVirtualKeyCode(CompositionEventKeyCode);
    33363336        keydown = KeyboardEvent::create(keyDownEvent, m_frame.document()->defaultView());
    3337         keydown->setTarget(node);
     3337        keydown->setTarget(element);
    33383338        keydown->setDefaultHandled();
    33393339    }
    33403340
    3341     node->dispatchEvent(keydown, IGNORE_EXCEPTION);
     3341    element->dispatchEvent(keydown, IGNORE_EXCEPTION);
    33423342    // If frame changed as a result of keydown dispatch, then return early to avoid sending a subsequent keypress message to the new frame.
    33433343    bool changedFocusedFrame = m_frame.page() && &m_frame != &m_frame.page()->focusController().focusedOrMainFrame();
     
    33463346        return keydownResult;
    33473347   
    3348     // Focus may have changed during keydown handling, so refetch node.
    3349     // But if we are dispatching a fake backward compatibility keypress, then we pretend that the keypress happened on the original node.
     3348    // Focus may have changed during keydown handling, so refetch element.
     3349    // But if we are dispatching a fake backward compatibility keypress, then we pretend that the keypress happened on the original element.
    33503350    if (!keydownResult) {
    3351         node = eventTargetNodeForDocument(m_frame.document());
    3352         if (!node)
     3351        element = eventTargetElementForDocument(m_frame.document());
     3352        if (!element)
    33533353            return false;
    33543354    }
     
    33593359        return keydownResult;
    33603360    RefPtr<KeyboardEvent> keypress = KeyboardEvent::create(keyPressEvent, m_frame.document()->defaultView());
    3361     keypress->setTarget(node);
     3361    keypress->setTarget(element);
    33623362    if (keydownResult)
    33633363        keypress->setDefaultPrevented(true);
     
    33653365    keypress->keypressCommands() = keydown->keypressCommands();
    33663366#endif
    3367     node->dispatchEvent(keypress, IGNORE_EXCEPTION);
     3367    element->dispatchEvent(keypress, IGNORE_EXCEPTION);
    33683368
    33693369    return keydownResult || keypress->defaultPrevented() || keypress->defaultHandled();
     
    37053705        target = underlyingEvent->target();
    37063706    else
    3707         target = eventTargetNodeForDocument(m_frame.document());
     3707        target = eventTargetElementForDocument(m_frame.document());
    37083708    if (!target)
    37093709        return false;
Note: See TracChangeset for help on using the changeset viewer.