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_TARGET_H_
6 #define UI_BASE_EVENTS_EVENT_TARGET_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "ui/base/events/event_handler.h"
11 #include "ui/base/ui_export.h"
15 class EventDispatcher
;
17 class UI_EXPORT EventTarget
: public EventHandler
{
19 typedef std::vector
<EventTarget
*> EventTargets
;
23 explicit TestApi(EventTarget
* target
) : target_(target
) {}
25 const EventHandlerList
& pre_target_handlers() {
26 return target_
->pre_target_list_
;
33 DISALLOW_COPY_AND_ASSIGN(TestApi
);
38 explicit DispatcherApi(EventTarget
* target
) : target_(target
) {}
40 const EventHandlerList
& pre_target_list() const {
41 return target_
->pre_target_list_
;
48 DISALLOW_COPY_AND_ASSIGN(DispatcherApi
);
52 virtual ~EventTarget();
54 virtual bool CanAcceptEvent(const ui::Event
& event
) = 0;
55 virtual EventTarget
* GetParentTarget() = 0;
57 // Adds a handler to receive events before the target. The handler must be
58 // explicitly removed from the target before the handler is destroyed. The
59 // EventTarget does not take ownership of the handler.
60 void AddPreTargetHandler(EventHandler
* handler
);
61 void RemovePreTargetHandler(EventHandler
* handler
);
63 // Adds a handler to receive events after the target. The handler must be
64 // explicitly removed from the target before the handler is destroyed. The
65 // EventTarget does not take ownership of the handler.
66 void AddPostTargetHandler(EventHandler
* handler
);
67 void RemovePostTargetHandler(EventHandler
* handler
);
70 void set_target_handler(EventHandler
* handler
) {
71 target_handler_
= handler
;
74 // Overridden from EventHandler:
75 virtual void OnEvent(Event
* event
) OVERRIDE
;
76 virtual void OnKeyEvent(KeyEvent
* event
) OVERRIDE
;
77 virtual void OnMouseEvent(MouseEvent
* event
) OVERRIDE
;
78 virtual void OnScrollEvent(ScrollEvent
* event
) OVERRIDE
;
79 virtual void OnTouchEvent(TouchEvent
* event
) OVERRIDE
;
80 virtual void OnGestureEvent(GestureEvent
* event
) OVERRIDE
;
83 friend class EventDispatcher
;
85 // Returns the list of handlers that should receive the event before the
86 // target. The handlers from the outermost target are first in the list, and
87 // the handlers on |this| are the last in the list.
88 void GetPreTargetHandlers(EventHandlerList
* list
);
90 // Returns the list of handlers that should receive the event after the
91 // target. The handlers from the outermost target are last in the list, and
92 // the handlers on |this| are the first in the list.
93 void GetPostTargetHandlers(EventHandlerList
* list
);
95 EventHandlerList pre_target_list_
;
96 EventHandlerList post_target_list_
;
97 EventHandler
* target_handler_
;
99 DISALLOW_COPY_AND_ASSIGN(EventTarget
);
104 #endif // UI_BASE_EVENTS_EVENT_TARGET_H_