Mailbox support for texture layers.
[chromium-blink-merge.git] / ui / base / events / event_dispatcher.h
blob8463349e401b47484984531bbebb115fbfa18022
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef UI_BASE_EVENTS_EVENT_DISPATCHER_H_
6 #define UI_BASE_EVENTS_EVENT_DISPATCHER_H_
8 #include "base/auto_reset.h"
9 #include "ui/base/events/event.h"
10 #include "ui/base/events/event_constants.h"
11 #include "ui/base/events/event_target.h"
12 #include "ui/base/ui_export.h"
14 namespace ui {
16 class EventDispatcher;
18 class UI_EXPORT EventDispatcherDelegate {
19 public:
20 EventDispatcherDelegate();
21 virtual ~EventDispatcherDelegate();
23 // Returns whether an event can still be dispatched to a target. (e.g. during
24 // event dispatch, one of the handlers may have destroyed the target, in which
25 // case the event can no longer be dispatched to the target).
26 virtual bool CanDispatchToTarget(EventTarget* target) = 0;
28 // Returns the event being dispatched (or NULL if no event is being
29 // dispatched).
30 Event* current_event();
32 protected:
33 // Dispatches the event to the target. Returns true if the delegate is still
34 // alive after dispatching event, and false if the delegate was destroyed
35 // during the event dispatch.
36 bool DispatchEvent(EventTarget* target, Event* event);
38 private:
39 EventDispatcher* dispatcher_;
41 DISALLOW_COPY_AND_ASSIGN(EventDispatcherDelegate);
44 // Dispatches events to appropriate targets.
45 class UI_EXPORT EventDispatcher {
46 public:
47 explicit EventDispatcher(EventDispatcherDelegate* delegate);
48 virtual ~EventDispatcher();
50 void ProcessEvent(EventTarget* target, Event* event);
52 const Event* current_event() const { return current_event_; }
53 Event* current_event() { return current_event_; }
55 bool delegate_destroyed() const { return !delegate_; }
57 void OnHandlerDestroyed(EventHandler* handler);
58 void OnDispatcherDelegateDestroyed();
60 private:
61 void DispatchEventToEventHandlers(EventHandlerList& list,
62 Event* event);
64 // Dispatches an event, and makes sure it sets ER_CONSUMED on the
65 // event-handling result if the dispatcher itself has been destroyed during
66 // dispatching the event to the event handler.
67 void DispatchEvent(EventHandler* handler, Event* event);
69 void DispatchEventToSingleHandler(EventHandler* handler, Event* event);
71 EventDispatcherDelegate* delegate_;
73 Event* current_event_;
75 EventHandlerList handler_list_;
77 DISALLOW_COPY_AND_ASSIGN(EventDispatcher);
80 } // namespace ui
82 #endif // UI_BASE_EVENTS_EVENT_DISPATCHER_H_