Changeset 82891 in webkit


Ignore:
Timestamp:
Apr 4, 2011 4:23:06 PM (13 years ago)
Author:
Dimitri Glazkov
Message:

2011-04-04 Dimitri Glazkov <Dimitri Glazkov>

Reviewed by Adam Barth.

Introduce EventDispatchMediator abstraction, which encapsulate all
non-trivial logic around firing a specific type of an event.
https://bugs.webkit.org/show_bug.cgi?id=57562

Refactoring, covered by existing tests.

  • dom/Event.cpp: (WebCore::EventDispatchMediator::EventDispatchMediator): Added. (WebCore::EventDispatchMediator::~EventDispatchMediator): Added. (WebCore::EventDispatchMediator::dispatchEvent): Added. (WebCore::EventDispatchMediator::event): Added.
  • dom/Event.h: Added decl.
  • dom/EventDispatcher.cpp: (WebCore::EventDispatcher::dispatchEvent): Changed to use EventDispatchMediator.
  • dom/EventDispatcher.h: Updated decls.
  • dom/KeyboardEvent.cpp: (WebCore::KeyboardEventDispatchMediator::KeyboardEventDispatchMediator): Added. (WebCore::KeyboardEventDispatchMediator::dispatchEvent): Added.
  • dom/KeyboardEvent.h: Updated decls
  • dom/Node.cpp: (WebCore::Node::dispatchEvent): Changed to use EventDispatchMediator. (WebCore::Node::dispatchKeyEvent): Changed to use KeyboardEventDispatchMediator.
Location:
trunk/Source/WebCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r82890 r82891  
     12011-04-04  Dimitri Glazkov  <dglazkov@chromium.org>
     2
     3        Reviewed by Adam Barth.
     4
     5        Introduce EventDispatchMediator abstraction, which encapsulate all
     6        non-trivial logic around firing a specific type of an event.
     7        https://bugs.webkit.org/show_bug.cgi?id=57562
     8
     9        Refactoring, covered by existing tests.
     10
     11        * dom/Event.cpp:
     12        (WebCore::EventDispatchMediator::EventDispatchMediator): Added.
     13        (WebCore::EventDispatchMediator::~EventDispatchMediator): Added.
     14        (WebCore::EventDispatchMediator::dispatchEvent): Added.
     15        (WebCore::EventDispatchMediator::event): Added.
     16        * dom/Event.h: Added decl.
     17        * dom/EventDispatcher.cpp:
     18        (WebCore::EventDispatcher::dispatchEvent): Changed to use EventDispatchMediator.
     19        * dom/EventDispatcher.h: Updated decls.
     20        * dom/KeyboardEvent.cpp:
     21        (WebCore::KeyboardEventDispatchMediator::KeyboardEventDispatchMediator): Added.
     22        (WebCore::KeyboardEventDispatchMediator::dispatchEvent): Added.
     23        * dom/KeyboardEvent.h: Updated decls
     24        * dom/Node.cpp:
     25        (WebCore::Node::dispatchEvent): Changed to use EventDispatchMediator.
     26        (WebCore::Node::dispatchKeyEvent): Changed to use KeyboardEventDispatchMediator.
     27
    1282011-04-04  Martin Robinson  <mrobinson@igalia.com>
    229
  • trunk/Source/WebCore/dom/Event.cpp

    r82264 r82891  
    272272}
    273273
    274 bool Event::dispatch(EventDispatcher* dispatcher)
    275 {
    276     return dispatcher->dispatchEvent(this);
    277 }
    278 
    279274void Event::setTarget(PassRefPtr<EventTarget> target)
    280275{
     
    300295}
    301296
     297EventDispatchMediator::EventDispatchMediator(PassRefPtr<Event> event)
     298    : m_event(event)
     299{
     300}
     301
     302EventDispatchMediator::~EventDispatchMediator()
     303{
     304}
     305
     306bool EventDispatchMediator::dispatchEvent(EventDispatcher* dispatcher) const
     307{
     308    return dispatcher->dispatchEvent(m_event.get());
     309}
     310
     311Event* EventDispatchMediator::event() const
     312{
     313    return m_event.get();
     314}
     315
    302316} // namespace WebCore
  • trunk/Source/WebCore/dom/Event.h

    r82264 r82891  
    167167        virtual Clipboard* clipboard() const { return 0; }
    168168
    169         virtual bool dispatch(EventDispatcher*);
    170169
    171170    protected:
     
    195194    };
    196195
     196class EventDispatchMediator {
     197public:
     198    explicit EventDispatchMediator(PassRefPtr<Event>);
     199    virtual ~EventDispatchMediator();
     200
     201    virtual bool dispatchEvent(EventDispatcher*) const;
     202    Event* event() const;
     203private:
     204    RefPtr<Event> m_event;
     205};
     206
    197207} // namespace WebCore
    198208
  • trunk/Source/WebCore/dom/EventDispatcher.cpp

    r82584 r82891  
    5454static HashSet<Node*>* gNodesDispatchingSimulatedClicks = 0;
    5555
    56 bool EventDispatcher::dispatchEvent(Node* node, PassRefPtr<Event> prpEvent)
    57 {
    58     RefPtr<Event> event = prpEvent;
    59 
     56bool EventDispatcher::dispatchEvent(Node* node, const EventDispatchMediator& mediator)
     57{
    6058    EventDispatcher dispatcher(node);
    61     return event->dispatch(&dispatcher);
     59    return mediator.dispatchEvent(&dispatcher);
    6260}
    6361
  • trunk/Source/WebCore/dom/EventDispatcher.h

    r82376 r82891  
    3434class Event;
    3535class EventContext;
     36class EventDispatchMediator;
    3637class EventTarget;
    3738class FrameView;
     
    4849class EventDispatcher {
    4950public:
    50     static bool dispatchEvent(Node*, PassRefPtr<Event>);
     51    static bool dispatchEvent(Node*, const EventDispatchMediator&);
    5152    static void dispatchScopedEvent(Node*, PassRefPtr<Event>);
    5253
  • trunk/Source/WebCore/dom/KeyboardEvent.cpp

    r82264 r82891  
    162162}
    163163
    164 bool KeyboardEvent::dispatch(EventDispatcher* dispatcher)
     164KeyboardEventDispatchMediator::KeyboardEventDispatchMediator(PassRefPtr<KeyboardEvent> event)
     165    : EventDispatchMediator(event)
     166{
     167}
     168
     169bool KeyboardEventDispatchMediator::dispatchEvent(EventDispatcher* dispatcher) const
    165170{
    166171    // Make sure not to return true if we already took default action while handling the event.
    167     return dispatcher->dispatchEvent(this) && !defaultHandled();
     172    return EventDispatchMediator::dispatchEvent(dispatcher) && !event()->defaultHandled();
    168173}
    169174
  • trunk/Source/WebCore/dom/KeyboardEvent.h

    r82720 r82891  
    102102                      const String& keyIdentifier, unsigned keyLocation,
    103103                      bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, bool altGraphKey);
    104         virtual bool dispatch(EventDispatcher*);
    105104
    106105        OwnPtr<PlatformKeyboardEvent> m_keyEvent;
     
    117116    KeyboardEvent* findKeyboardEvent(Event*);
    118117
     118class KeyboardEventDispatchMediator : public EventDispatchMediator {
     119public:
     120    explicit KeyboardEventDispatchMediator(PassRefPtr<KeyboardEvent>);
     121
     122private:
     123    virtual bool dispatchEvent(EventDispatcher*) const;
     124};
     125
    119126} // namespace WebCore
    120127
  • trunk/Source/WebCore/dom/Node.cpp

    r82886 r82891  
    26142614bool Node::dispatchEvent(PassRefPtr<Event> event)
    26152615{
    2616     return EventDispatcher::dispatchEvent(this, event);
     2616    return EventDispatcher::dispatchEvent(this, EventDispatchMediator(event));
    26172617}
    26182618
     
    26462646bool Node::dispatchKeyEvent(const PlatformKeyboardEvent& event)
    26472647{
    2648     return EventDispatcher::dispatchEvent(this, KeyboardEvent::create(event, document()->defaultView()));
     2648    return EventDispatcher::dispatchEvent(this, KeyboardEventDispatchMediator(KeyboardEvent::create(event, document()->defaultView())));
    26492649}
    26502650
Note: See TracChangeset for help on using the changeset viewer.