Changeset 143145 in webkit


Ignore:
Timestamp:
Feb 17, 2013 9:51:49 PM (11 years ago)
Author:
hayato@chromium.org
Message:

Make EventDispatcher take an Event object in its constructor.
https://bugs.webkit.org/show_bug.cgi?id=109898

Reviewed by Dimitri Glazkov.

That makes EventDispatcher more RAII-like so that we can calculate
an EventPath in its constructor. I'll remove
EventDispatcher::ensureEventPath() in a following patch.

No tests. No change in behavior.

  • dom/EventDispatchMediator.cpp:

(WebCore::EventDispatchMediator::dispatchEvent):

  • dom/EventDispatcher.cpp:

(WebCore::EventDispatcher::dispatchEvent):
(WebCore::EventDispatcher::EventDispatcher):
(WebCore::EventDispatcher::ensureEventPath):
(WebCore::EventDispatcher::dispatchSimulatedClick):
(WebCore::EventDispatcher::dispatch):
(WebCore::EventDispatcher::dispatchEventPreProcess):
(WebCore::EventDispatcher::dispatchEventAtCapturing):
(WebCore::EventDispatcher::dispatchEventAtTarget):
(WebCore::EventDispatcher::dispatchEventAtBubbling):
(WebCore::EventDispatcher::dispatchEventPostProcess):

  • dom/EventDispatcher.h:

(EventDispatcher):
(WebCore::EventDispatcher::node):
(WebCore::EventDispatcher::event):

  • dom/FocusEvent.cpp:

(WebCore::FocusEventDispatchMediator::dispatchEvent):
(WebCore::BlurEventDispatchMediator::dispatchEvent):
(WebCore::FocusInEventDispatchMediator::dispatchEvent):
(WebCore::FocusOutEventDispatchMediator::dispatchEvent):

  • dom/GestureEvent.cpp:

(WebCore::GestureEventDispatchMediator::dispatchEvent):

  • dom/MouseEvent.cpp:

(WebCore::MouseEventDispatchMediator::dispatchEvent):

Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r143144 r143145  
     12013-02-17  Hayato Ito  <hayato@chromium.org>
     2
     3        Make EventDispatcher take an Event object in its constructor.
     4        https://bugs.webkit.org/show_bug.cgi?id=109898
     5
     6        Reviewed by Dimitri Glazkov.
     7
     8        That makes EventDispatcher more RAII-like so that we can calculate
     9        an EventPath in its constructor.  I'll remove
     10        EventDispatcher::ensureEventPath() in a following patch.
     11
     12        No tests. No change in behavior.
     13
     14        * dom/EventDispatchMediator.cpp:
     15        (WebCore::EventDispatchMediator::dispatchEvent):
     16        * dom/EventDispatcher.cpp:
     17        (WebCore::EventDispatcher::dispatchEvent):
     18        (WebCore::EventDispatcher::EventDispatcher):
     19        (WebCore::EventDispatcher::ensureEventPath):
     20        (WebCore::EventDispatcher::dispatchSimulatedClick):
     21        (WebCore::EventDispatcher::dispatch):
     22        (WebCore::EventDispatcher::dispatchEventPreProcess):
     23        (WebCore::EventDispatcher::dispatchEventAtCapturing):
     24        (WebCore::EventDispatcher::dispatchEventAtTarget):
     25        (WebCore::EventDispatcher::dispatchEventAtBubbling):
     26        (WebCore::EventDispatcher::dispatchEventPostProcess):
     27        * dom/EventDispatcher.h:
     28        (EventDispatcher):
     29        (WebCore::EventDispatcher::node):
     30        (WebCore::EventDispatcher::event):
     31        * dom/FocusEvent.cpp:
     32        (WebCore::FocusEventDispatchMediator::dispatchEvent):
     33        (WebCore::BlurEventDispatchMediator::dispatchEvent):
     34        (WebCore::FocusInEventDispatchMediator::dispatchEvent):
     35        (WebCore::FocusOutEventDispatchMediator::dispatchEvent):
     36        * dom/GestureEvent.cpp:
     37        (WebCore::GestureEventDispatchMediator::dispatchEvent):
     38        * dom/MouseEvent.cpp:
     39        (WebCore::MouseEventDispatchMediator::dispatchEvent):
     40
    1412013-02-17  Philip Rogers  <pdr@google.com>
    242
  • trunk/Source/WebCore/dom/EventDispatchMediator.cpp

    r142957 r143145  
    5151bool EventDispatchMediator::dispatchEvent(EventDispatcher* dispatcher) const
    5252{
    53     return dispatcher->dispatchEvent(m_event.get());
     53    ASSERT(m_event.get() == dispatcher->event());
     54    return dispatcher->dispatch();
    5455}
    5556
  • trunk/Source/WebCore/dom/EventDispatcher.cpp

    r142957 r143145  
    5252    ASSERT(!NoEventDispatchAssertion::isEventDispatchForbidden());
    5353
    54     EventDispatcher dispatcher(node);
     54    EventDispatcher dispatcher(node, mediator->event());
    5555    return mediator->dispatchEvent(&dispatcher);
    5656}
    5757
    58 EventDispatcher::EventDispatcher(Node* node)
     58EventDispatcher::EventDispatcher(Node* node, PassRefPtr<Event> event)
    5959    : m_node(node)
     60    , m_event(event)
    6061    , m_eventPathInitialized(false)
    6162#ifndef NDEBUG
     
    6465{
    6566    ASSERT(node);
     67    ASSERT(m_event.get());
     68    ASSERT(!m_event->type().isNull()); // JavaScript code can create an event with an empty name, but not null.
    6669    m_view = node->document()->view();
    6770}
    6871
    69 EventPath& EventDispatcher::ensureEventPath(Event* event)
     72EventPath& EventDispatcher::ensureEventPath()
    7073{
    7174    if (m_eventPathInitialized)
    7275        return m_eventPath;
    7376    m_eventPathInitialized = true;
    74     EventRetargeter::calculateEventPath(m_node.get(), event, m_eventPath);
     77    EventRetargeter::calculateEventPath(m_node.get(), m_event.get(), m_eventPath);
    7578    return m_eventPath;
    7679}
     
    9699
    97100    if (mouseEventOptions == SendMouseOverUpDownEvents)
    98         EventDispatcher(node).dispatchEvent(SimulatedMouseEvent::create(eventNames().mouseoverEvent, node->document()->defaultView(), underlyingEvent));
     101        EventDispatcher(node, SimulatedMouseEvent::create(eventNames().mouseoverEvent, node->document()->defaultView(), underlyingEvent)).dispatch();
    99102
    100103    if (mouseEventOptions != SendNoEvents)
    101         EventDispatcher(node).dispatchEvent(SimulatedMouseEvent::create(eventNames().mousedownEvent, node->document()->defaultView(), underlyingEvent));
     104        EventDispatcher(node, SimulatedMouseEvent::create(eventNames().mousedownEvent, node->document()->defaultView(), underlyingEvent)).dispatch();
    102105    node->setActive(true, visualOptions == ShowPressedLook);
    103106    if (mouseEventOptions != SendNoEvents)
    104         EventDispatcher(node).dispatchEvent(SimulatedMouseEvent::create(eventNames().mouseupEvent, node->document()->defaultView(), underlyingEvent));
     107        EventDispatcher(node, SimulatedMouseEvent::create(eventNames().mouseupEvent, node->document()->defaultView(), underlyingEvent)).dispatch();
    105108    node->setActive(false);
    106109
    107110    // always send click
    108     EventDispatcher(node).dispatchEvent(SimulatedMouseEvent::create(eventNames().clickEvent, node->document()->defaultView(), underlyingEvent));
     111    EventDispatcher(node, SimulatedMouseEvent::create(eventNames().clickEvent, node->document()->defaultView(), underlyingEvent)).dispatch();
    109112
    110113    gNodesDispatchingSimulatedClicks->remove(node);
    111114}
    112115
    113 bool EventDispatcher::dispatchEvent(PassRefPtr<Event> prpEvent)
     116bool EventDispatcher::dispatch()
    114117{
    115118#ifndef NDEBUG
     
    117120    m_eventDispatched = true;
    118121#endif
    119     RefPtr<Event> event = prpEvent;
    120122    ChildNodesLazySnapshot::takeChildNodesLazySnapshot();
    121123
    122     event->setTarget(EventRetargeter::eventTargetRespectingTargetRules(m_node.get()));
     124    m_event->setTarget(EventRetargeter::eventTargetRespectingTargetRules(m_node.get()));
    123125    ASSERT(!NoEventDispatchAssertion::isEventDispatchForbidden());
    124     ASSERT(event->target());
    125     ASSERT(!event->type().isNull()); // JavaScript code can create an event with an empty name, but not null.
    126     ensureEventPath(event.get());
    127     WindowEventContext windowEventContext(event.get(), m_node.get(), topEventContext());
    128     InspectorInstrumentationCookie cookie = InspectorInstrumentation::willDispatchEvent(m_node->document(), *event, windowEventContext.window(), m_node.get(), m_eventPath);
     126    ASSERT(m_event->target());
     127    ensureEventPath();
     128    WindowEventContext windowEventContext(m_event.get(), m_node.get(), topEventContext());
     129    InspectorInstrumentationCookie cookie = InspectorInstrumentation::willDispatchEvent(m_node->document(), *m_event, windowEventContext.window(), m_node.get(), m_eventPath);
    129130
    130131    void* preDispatchEventHandlerResult;
    131     if (dispatchEventPreProcess(event, preDispatchEventHandlerResult) == ContinueDispatching)
    132         if (dispatchEventAtCapturing(event, windowEventContext) == ContinueDispatching)
    133             if (dispatchEventAtTarget(event) == ContinueDispatching)
    134                 dispatchEventAtBubbling(event, windowEventContext);
    135     dispatchEventPostProcess(event, preDispatchEventHandlerResult);
     132    if (dispatchEventPreProcess(preDispatchEventHandlerResult) == ContinueDispatching)
     133        if (dispatchEventAtCapturing(windowEventContext) == ContinueDispatching)
     134            if (dispatchEventAtTarget() == ContinueDispatching)
     135                dispatchEventAtBubbling(windowEventContext);
     136    dispatchEventPostProcess(preDispatchEventHandlerResult);
    136137
    137138    // Ensure that after event dispatch, the event's target object is the
    138139    // outermost shadow DOM boundary.
    139     event->setTarget(windowEventContext.target());
    140     event->setCurrentTarget(0);
     140    m_event->setTarget(windowEventContext.target());
     141    m_event->setCurrentTarget(0);
    141142    InspectorInstrumentation::didDispatchEvent(cookie);
    142143
    143     return !event->defaultPrevented();
    144 }
    145 
    146 inline EventDispatchContinuation EventDispatcher::dispatchEventPreProcess(PassRefPtr<Event> event, void*& preDispatchEventHandlerResult)
     144    return !m_event->defaultPrevented();
     145}
     146
     147inline EventDispatchContinuation EventDispatcher::dispatchEventPreProcess(void*& preDispatchEventHandlerResult)
    147148{
    148149    // Give the target node a chance to do some work before DOM event handlers get a crack.
    149     preDispatchEventHandlerResult = m_node->preDispatchEventHandler(event.get());
    150     return (m_eventPath.isEmpty() || event->propagationStopped()) ? DoneDispatching : ContinueDispatching;
    151 }
    152 
    153 inline EventDispatchContinuation EventDispatcher::dispatchEventAtCapturing(PassRefPtr<Event> event, WindowEventContext& windowEventContext)
     150    preDispatchEventHandlerResult = m_node->preDispatchEventHandler(m_event.get());
     151    return (m_eventPath.isEmpty() || m_event->propagationStopped()) ? DoneDispatching : ContinueDispatching;
     152}
     153
     154inline EventDispatchContinuation EventDispatcher::dispatchEventAtCapturing(WindowEventContext& windowEventContext)
    154155{
    155156    // Trigger capturing event handlers, starting at the top and working our way down.
    156     event->setEventPhase(Event::CAPTURING_PHASE);
    157 
    158     if (windowEventContext.handleLocalEvents(event.get()) && event->propagationStopped())
     157    m_event->setEventPhase(Event::CAPTURING_PHASE);
     158
     159    if (windowEventContext.handleLocalEvents(m_event.get()) && m_event->propagationStopped())
    159160        return DoneDispatching;
    160161
     
    162163        const EventContext& eventContext = *m_eventPath[i];
    163164        if (eventContext.currentTargetSameAsTarget()) {
    164             if (event->bubbles())
     165            if (m_event->bubbles())
    165166                continue;
    166             event->setEventPhase(Event::AT_TARGET);
     167            m_event->setEventPhase(Event::AT_TARGET);
    167168        } else
    168             event->setEventPhase(Event::CAPTURING_PHASE);
    169         eventContext.handleLocalEvents(event.get());
    170         if (event->propagationStopped())
     169            m_event->setEventPhase(Event::CAPTURING_PHASE);
     170        eventContext.handleLocalEvents(m_event.get());
     171        if (m_event->propagationStopped())
    171172            return DoneDispatching;
    172173    }
     
    175176}
    176177
    177 inline EventDispatchContinuation EventDispatcher::dispatchEventAtTarget(PassRefPtr<Event> event)
    178 {
    179     event->setEventPhase(Event::AT_TARGET);
    180     m_eventPath[0]->handleLocalEvents(event.get());
    181     return event->propagationStopped() ? DoneDispatching : ContinueDispatching;
    182 }
    183 
    184 inline EventDispatchContinuation EventDispatcher::dispatchEventAtBubbling(PassRefPtr<Event> event, WindowEventContext& windowContext)
    185 {
    186     if (event->bubbles() && !event->cancelBubble()) {
     178inline EventDispatchContinuation EventDispatcher::dispatchEventAtTarget()
     179{
     180    m_event->setEventPhase(Event::AT_TARGET);
     181    m_eventPath[0]->handleLocalEvents(m_event.get());
     182    return m_event->propagationStopped() ? DoneDispatching : ContinueDispatching;
     183}
     184
     185inline EventDispatchContinuation EventDispatcher::dispatchEventAtBubbling(WindowEventContext& windowContext)
     186{
     187    if (m_event->bubbles() && !m_event->cancelBubble()) {
    187188        // Trigger bubbling event handlers, starting at the bottom and working our way up.
    188         event->setEventPhase(Event::BUBBLING_PHASE);
     189        m_event->setEventPhase(Event::BUBBLING_PHASE);
    189190
    190191        size_t size = m_eventPath.size();
     
    192193            const EventContext& eventContext = *m_eventPath[i];
    193194            if (eventContext.currentTargetSameAsTarget())
    194                 event->setEventPhase(Event::AT_TARGET);
     195                m_event->setEventPhase(Event::AT_TARGET);
    195196            else
    196                 event->setEventPhase(Event::BUBBLING_PHASE);
    197             eventContext.handleLocalEvents(event.get());
    198             if (event->propagationStopped() || event->cancelBubble())
     197                m_event->setEventPhase(Event::BUBBLING_PHASE);
     198            eventContext.handleLocalEvents(m_event.get());
     199            if (m_event->propagationStopped() || m_event->cancelBubble())
    199200                return DoneDispatching;
    200201        }
    201         windowContext.handleLocalEvents(event.get());
     202        windowContext.handleLocalEvents(m_event.get());
    202203    }
    203204    return ContinueDispatching;
    204205}
    205206
    206 inline void EventDispatcher::dispatchEventPostProcess(PassRefPtr<Event> event, void* preDispatchEventHandlerResult)
    207 {
    208     event->setTarget(EventRetargeter::eventTargetRespectingTargetRules(m_node.get()));
    209     event->setCurrentTarget(0);
    210     event->setEventPhase(0);
     207inline void EventDispatcher::dispatchEventPostProcess(void* preDispatchEventHandlerResult)
     208{
     209    m_event->setTarget(EventRetargeter::eventTargetRespectingTargetRules(m_node.get()));
     210    m_event->setCurrentTarget(0);
     211    m_event->setEventPhase(0);
    211212
    212213    // Pass the data from the preDispatchEventHandler to the postDispatchEventHandler.
    213     m_node->postDispatchEventHandler(event.get(), preDispatchEventHandlerResult);
     214    m_node->postDispatchEventHandler(m_event.get(), preDispatchEventHandlerResult);
    214215
    215216    // Call default event handlers. While the DOM does have a concept of preventing
    216217    // default handling, the detail of which handlers are called is an internal
    217218    // implementation detail and not part of the DOM.
    218     if (!event->defaultPrevented() && !event->defaultHandled()) {
     219    if (!m_event->defaultPrevented() && !m_event->defaultHandled()) {
    219220        // Non-bubbling events call only one default event handler, the one for the target.
    220         m_node->defaultEventHandler(event.get());
    221         ASSERT(!event->defaultPrevented());
    222         if (event->defaultHandled())
     221        m_node->defaultEventHandler(m_event.get());
     222        ASSERT(!m_event->defaultPrevented());
     223        if (m_event->defaultHandled())
    223224            return;
    224225        // For bubbling events, call default event handlers on the same targets in the
    225226        // same order as the bubbling phase.
    226         if (event->bubbles()) {
     227        if (m_event->bubbles()) {
    227228            size_t size = m_eventPath.size();
    228229            for (size_t i = 1; i < size; ++i) {
    229                 m_eventPath[i]->node()->defaultEventHandler(event.get());
    230                 ASSERT(!event->defaultPrevented());
    231                 if (event->defaultHandled())
     230                m_eventPath[i]->node()->defaultEventHandler(m_event.get());
     231                ASSERT(!m_event->defaultPrevented());
     232                if (m_event->defaultHandled())
    232233                    return;
    233234            }
  • trunk/Source/WebCore/dom/EventDispatcher.h

    r142957 r143145  
    3131#include <wtf/Forward.h>
    3232#include <wtf/HashMap.h>
     33#include <wtf/PassRefPtr.h>
    3334#include <wtf/Vector.h>
    3435
     
    5859    static void dispatchSimulatedClick(Node*, Event* underlyingEvent, SimulatedClickMouseEventOptions, SimulatedClickVisualOptions);
    5960
    60     bool dispatchEvent(PassRefPtr<Event>);
    61     Node* node() const;
    62     EventPath& ensureEventPath(Event*);
     61    bool dispatch();
     62    Node* node() const { return m_node.get(); }
     63    Event* event() const { return m_event.get(); }
     64    EventPath& ensureEventPath();
    6365
    6466private:
    65     EventDispatcher(Node*);
     67    EventDispatcher(Node*, PassRefPtr<Event>);
    6668    const EventContext* topEventContext();
    6769
    68     EventDispatchContinuation dispatchEventPreProcess(PassRefPtr<Event>, void*& preDispatchEventHandlerResult);
    69     EventDispatchContinuation dispatchEventAtCapturing(PassRefPtr<Event>, WindowEventContext&);
    70     EventDispatchContinuation dispatchEventAtTarget(PassRefPtr<Event>);
    71     EventDispatchContinuation dispatchEventAtBubbling(PassRefPtr<Event>, WindowEventContext&);
    72     void dispatchEventPostProcess(PassRefPtr<Event>, void* preDispatchEventHandlerResult);
     70    EventDispatchContinuation dispatchEventPreProcess(void*& preDispatchEventHandlerResult);
     71    EventDispatchContinuation dispatchEventAtCapturing(WindowEventContext&);
     72    EventDispatchContinuation dispatchEventAtTarget();
     73    EventDispatchContinuation dispatchEventAtBubbling(WindowEventContext&);
     74    void dispatchEventPostProcess(void* preDispatchEventHandlerResult);
    7375
    7476    EventPath m_eventPath;
    7577    RefPtr<Node> m_node;
     78    RefPtr<Event> m_event;
    7679    RefPtr<FrameView> m_view;
    7780    bool m_eventPathInitialized;
     
    8184};
    8285
    83 inline Node* EventDispatcher::node() const
    84 {
    85     return m_node.get();
    86 }
    87 
    8886}
    8987
  • trunk/Source/WebCore/dom/FocusEvent.cpp

    r142957 r143145  
    7878bool FocusEventDispatchMediator::dispatchEvent(EventDispatcher* dispatcher) const
    7979{
    80     EventRetargeter::adjustForFocusEvent(dispatcher->node(), *event(), dispatcher->ensureEventPath(event()));
     80    EventRetargeter::adjustForFocusEvent(dispatcher->node(), *event(), dispatcher->ensureEventPath());
    8181    return EventDispatchMediator::dispatchEvent(dispatcher);
    8282}
     
    9494bool BlurEventDispatchMediator::dispatchEvent(EventDispatcher* dispatcher) const
    9595{
    96     EventRetargeter::adjustForFocusEvent(dispatcher->node(), *event(), dispatcher->ensureEventPath(event()));
     96    EventRetargeter::adjustForFocusEvent(dispatcher->node(), *event(), dispatcher->ensureEventPath());
    9797    return EventDispatchMediator::dispatchEvent(dispatcher);
    9898}
     
    110110bool FocusInEventDispatchMediator::dispatchEvent(EventDispatcher* dispatcher) const
    111111{
    112     EventRetargeter::adjustForFocusEvent(dispatcher->node(), *event(), dispatcher->ensureEventPath(event()));
     112    EventRetargeter::adjustForFocusEvent(dispatcher->node(), *event(), dispatcher->ensureEventPath());
    113113    return EventDispatchMediator::dispatchEvent(dispatcher);
    114114}
     
    126126bool FocusOutEventDispatchMediator::dispatchEvent(EventDispatcher* dispatcher) const
    127127{
    128     EventRetargeter::adjustForFocusEvent(dispatcher->node(), *event(), dispatcher->ensureEventPath(event()));
     128    EventRetargeter::adjustForFocusEvent(dispatcher->node(), *event(), dispatcher->ensureEventPath());
    129129    return EventDispatchMediator::dispatchEvent(dispatcher);
    130130}
  • trunk/Source/WebCore/dom/GestureEvent.cpp

    r142057 r143145  
    123123        return true;
    124124
    125     dispatcher->dispatchEvent(event());
     125    dispatcher->dispatch();
    126126    ASSERT(!event()->defaultPrevented());
    127127    return event()->defaultHandled() || event()->defaultPrevented();
  • trunk/Source/WebCore/dom/MouseEvent.cpp

    r142957 r143145  
    263263{
    264264    if (isSyntheticMouseEvent()) {
    265         EventRetargeter::adjustForMouseEvent(dispatcher->node(), *event(),  dispatcher->ensureEventPath(event()));
    266         return dispatcher->dispatchEvent(event());
     265        EventRetargeter::adjustForMouseEvent(dispatcher->node(), *event(),  dispatcher->ensureEventPath());
     266        return dispatcher->dispatch();
    267267    }
    268268
     
    276276
    277277    EventTarget* relatedTarget = event()->relatedTarget();
    278     EventRetargeter::adjustForMouseEvent(dispatcher->node(), *event(),  dispatcher->ensureEventPath(event()));
    279 
    280     dispatcher->dispatchEvent(event());
     278    EventRetargeter::adjustForMouseEvent(dispatcher->node(), *event(),  dispatcher->ensureEventPath());
     279
     280    dispatcher->dispatch();
    281281    bool swallowEvent = event()->defaultHandled() || event()->defaultPrevented();
    282282
Note: See TracChangeset for help on using the changeset viewer.