OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_BASE_EVENTS_EVENT_TARGET_H_ | 5 #ifndef UI_BASE_EVENTS_EVENT_TARGET_H_ |
6 #define UI_BASE_EVENTS_EVENT_TARGET_H_ | 6 #define UI_BASE_EVENTS_EVENT_TARGET_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "ui/base/events/event_handler.h" | 9 #include "ui/base/events/event_handler.h" |
10 #include "ui/base/ui_export.h" | 10 #include "ui/base/ui_export.h" |
11 | 11 |
12 namespace ui { | 12 namespace ui { |
13 | 13 |
14 class EventDispatcher; | 14 class EventDispatcher; |
15 | 15 |
16 class UI_EXPORT EventTarget : public EventHandler { | 16 class UI_EXPORT EventTarget : public EventHandler { |
17 public: | 17 public: |
18 typedef std::vector<EventTarget*> EventTargets; | 18 typedef std::vector<EventTarget*> EventTargets; |
19 | 19 |
| 20 class TestApi { |
| 21 public: |
| 22 explicit TestApi(EventTarget* target) : target_(target) {} |
| 23 |
| 24 const EventHandlerList& pre_target_handlers() { |
| 25 return target_->pre_target_list_; |
| 26 } |
| 27 |
| 28 private: |
| 29 TestApi(); |
| 30 EventTarget* target_; |
| 31 |
| 32 DISALLOW_COPY_AND_ASSIGN(TestApi); |
| 33 }; |
| 34 |
20 EventTarget(); | 35 EventTarget(); |
21 virtual ~EventTarget(); | 36 virtual ~EventTarget(); |
22 | 37 |
23 virtual bool CanAcceptEvents() = 0; | 38 virtual bool CanAcceptEvents() = 0; |
24 virtual EventTarget* GetParentTarget() = 0; | 39 virtual EventTarget* GetParentTarget() = 0; |
25 | 40 |
26 // Adds a handler to receive events before the target. The handler must be | 41 // Adds a handler to receive events before the target. The handler must be |
27 // explicitly removed from the target before the handler is destroyed. The | 42 // explicitly removed from the target before the handler is destroyed. The |
28 // EventTarget does not take ownership of the handler. | 43 // EventTarget does not take ownership of the handler. |
29 void AddPreTargetHandler(EventHandler* handler); | 44 void AddPreTargetHandler(EventHandler* handler); |
30 void RemovePreTargetHandler(EventHandler* handler); | 45 void RemovePreTargetHandler(EventHandler* handler); |
31 | 46 |
32 // Adds a handler to receive events after the target. The hanler must be | 47 // Adds a handler to receive events after the target. The handler must be |
33 // explicitly removed from the target before the handler is destroyed. The | 48 // explicitly removed from the target before the handler is destroyed. The |
34 // EventTarget does not take ownership of the handler. | 49 // EventTarget does not take ownership of the handler. |
35 void AddPostTargetHandler(EventHandler* handler); | 50 void AddPostTargetHandler(EventHandler* handler); |
36 void RemovePostTargetHandler(EventHandler* handler); | 51 void RemovePostTargetHandler(EventHandler* handler); |
37 | 52 |
38 protected: | 53 protected: |
39 void set_target_handler(EventHandler* handler) { | 54 void set_target_handler(EventHandler* handler) { |
40 target_handler_ = handler; | 55 target_handler_ = handler; |
41 } | 56 } |
42 | 57 |
43 EventHandlerList& pre_target_list() { return pre_target_list_; } | |
44 EventHandlerList& post_target_list() { return post_target_list_; } | |
45 | |
46 private: | 58 private: |
47 friend class EventDispatcher; | 59 friend class EventDispatcher; |
48 | 60 |
49 // Returns the list of handlers that should receive the event before the | 61 // Returns the list of handlers that should receive the event before the |
50 // target. The handlers from the outermost target are first in the list, and | 62 // target. The handlers from the outermost target are first in the list, and |
51 // the handlers on |this| are the last in the list. | 63 // the handlers on |this| are the last in the list. |
52 void GetPreTargetHandlers(EventHandlerList* list); | 64 void GetPreTargetHandlers(EventHandlerList* list); |
53 | 65 |
54 // Returns the list of handlers that should receive the event after the | 66 // Returns the list of handlers that should receive the event after the |
55 // target. The handlers from the outermost target are last in the list, and | 67 // target. The handlers from the outermost target are last in the list, and |
(...skipping 10 matching lines...) Expand all Loading... |
66 EventHandlerList pre_target_list_; | 78 EventHandlerList pre_target_list_; |
67 EventHandlerList post_target_list_; | 79 EventHandlerList post_target_list_; |
68 EventHandler* target_handler_; | 80 EventHandler* target_handler_; |
69 | 81 |
70 DISALLOW_COPY_AND_ASSIGN(EventTarget); | 82 DISALLOW_COPY_AND_ASSIGN(EventTarget); |
71 }; | 83 }; |
72 | 84 |
73 } // namespace ui | 85 } // namespace ui |
74 | 86 |
75 #endif // UI_BASE_EVENTS_EVENT_TARGET_H_ | 87 #endif // UI_BASE_EVENTS_EVENT_TARGET_H_ |
OLD | NEW |