Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: ui/base/events/event_dispatcher.h

Issue 10908127: events: Move EventTarget into Event. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/base/events/event.cc ('k') | ui/base/events/event_handler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_CONSTANTS_EVENTS_EVENT_DISPATCHER_H_ 5 #ifndef UI_BASE_EVENTS_EVENT_CONSTANTS_EVENTS_EVENT_DISPATCHER_H_
6 #define UI_BASE_EVENTS_EVENT_CONSTANTS_EVENTS_EVENT_DISPATCHER_H_ 6 #define UI_BASE_EVENTS_EVENT_CONSTANTS_EVENTS_EVENT_DISPATCHER_H_
7 7
8 #include "ui/base/events/event.h" 8 #include "ui/base/events/event.h"
9 #include "ui/base/events/event_constants.h" 9 #include "ui/base/events/event_constants.h"
10 #include "ui/base/events/event_target.h" 10 #include "ui/base/events/event_target.h"
(...skipping 15 matching lines...) Expand all
26 // Allows the subclass to add additional event handlers to the dispatch 26 // Allows the subclass to add additional event handlers to the dispatch
27 // sequence. 27 // sequence.
28 virtual void ProcessPreTargetList(EventHandlerList* list) = 0; 28 virtual void ProcessPreTargetList(EventHandlerList* list) = 0;
29 virtual void ProcessPostTargetList(EventHandlerList* list) = 0; 29 virtual void ProcessPostTargetList(EventHandlerList* list) = 0;
30 30
31 template<class T> 31 template<class T>
32 int ProcessEvent(EventTarget* target, T* event) { 32 int ProcessEvent(EventTarget* target, T* event) {
33 if (!target || !target->CanAcceptEvents()) 33 if (!target || !target->CanAcceptEvents())
34 return ER_UNHANDLED; 34 return ER_UNHANDLED;
35 35
36 Event::DispatcherApi dispatcher(event);
37 dispatcher.set_target(target);
38
36 EventHandlerList list; 39 EventHandlerList list;
37 target->GetPreTargetHandlers(&list); 40 target->GetPreTargetHandlers(&list);
38 ProcessPreTargetList(&list); 41 ProcessPreTargetList(&list);
39 int result = DispatchEventToEventHandlers(list, target, event); 42 int result = DispatchEventToEventHandlers(list, event);
40 if (result & ER_CONSUMED) 43 if (result & ER_CONSUMED)
41 return result; 44 return result;
42 45
43 // If the event hasn't been consumed, trigger the default handler. Note that 46 // If the event hasn't been consumed, trigger the default handler. Note that
44 // even if the event has already been handled (i.e. return result has 47 // even if the event has already been handled (i.e. return result has
45 // ER_HANDLED set), that means that the event should still be processed at 48 // ER_HANDLED set), that means that the event should still be processed at
46 // this layer, however it should not be processed in the next layer of 49 // this layer, however it should not be processed in the next layer of
47 // abstraction. 50 // abstraction.
48 if (CanDispatchToTarget(target)) { 51 if (CanDispatchToTarget(target)) {
49 result |= DispatchEventToSingleHandler(target, target, event); 52 result |= DispatchEventToSingleHandler(target, event);
50 if (result & ER_CONSUMED) 53 if (result & ER_CONSUMED)
51 return result; 54 return result;
52 } 55 }
53 56
54 if (!CanDispatchToTarget(target)) 57 if (!CanDispatchToTarget(target))
55 return result; 58 return result;
56 59
57 list.clear(); 60 list.clear();
58 target->GetPostTargetHandlers(&list); 61 target->GetPostTargetHandlers(&list);
59 ProcessPostTargetList(&list); 62 ProcessPostTargetList(&list);
60 result |= DispatchEventToEventHandlers(list, target, event); 63 result |= DispatchEventToEventHandlers(list, event);
61 return result; 64 return result;
62 } 65 }
63 66
64 private: 67 private:
65 template<class T> 68 template<class T>
66 int DispatchEventToEventHandlers(EventHandlerList& list, 69 int DispatchEventToEventHandlers(EventHandlerList& list, T* event) {
67 EventTarget* target,
68 T* event) {
69 int result = ER_UNHANDLED; 70 int result = ER_UNHANDLED;
70 for (EventHandlerList::const_iterator it = list.begin(), 71 for (EventHandlerList::const_iterator it = list.begin(),
71 end = list.end(); it != end; ++it) { 72 end = list.end(); it != end; ++it) {
72 result |= DispatchEventToSingleHandler((*it), target, event); 73 result |= DispatchEventToSingleHandler((*it), event);
73 if (result & ER_CONSUMED) 74 if (result & ER_CONSUMED)
74 return result; 75 return result;
75 } 76 }
76 return result; 77 return result;
77 } 78 }
78 79
79 EventResult DispatchEventToSingleHandler(EventHandler* handler, 80 EventResult DispatchEventToSingleHandler(EventHandler* handler,
80 EventTarget* target,
81 ui::KeyEvent* event) { 81 ui::KeyEvent* event) {
82 return handler->OnKeyEvent(target, event); 82 return handler->OnKeyEvent(event);
83 } 83 }
84 84
85 EventResult DispatchEventToSingleHandler(EventHandler* handler, 85 EventResult DispatchEventToSingleHandler(EventHandler* handler,
86 EventTarget* target,
87 ui::MouseEvent* event) { 86 ui::MouseEvent* event) {
88 return handler->OnMouseEvent(target, event); 87 return handler->OnMouseEvent(event);
89 } 88 }
90 89
91 EventResult DispatchEventToSingleHandler(EventHandler* handler, 90 EventResult DispatchEventToSingleHandler(EventHandler* handler,
92 EventTarget* target,
93 ui::ScrollEvent* event) { 91 ui::ScrollEvent* event) {
94 return handler->OnScrollEvent(target, event); 92 return handler->OnScrollEvent(event);
95 } 93 }
96 94
97 EventResult DispatchEventToSingleHandler(EventHandler* handler, 95 EventResult DispatchEventToSingleHandler(EventHandler* handler,
98 EventTarget* target,
99 ui::TouchEvent* event) { 96 ui::TouchEvent* event) {
100 // TODO(sad): This needs fixing (especially for the QUEUED_ status). 97 // TODO(sad): This needs fixing (especially for the QUEUED_ status).
101 TouchStatus status = handler->OnTouchEvent(target, event); 98 TouchStatus status = handler->OnTouchEvent(event);
102 return status == ui::TOUCH_STATUS_UNKNOWN ? ER_UNHANDLED : 99 return status == ui::TOUCH_STATUS_UNKNOWN ? ER_UNHANDLED :
103 status == ui::TOUCH_STATUS_QUEUED_END ? ER_CONSUMED : 100 status == ui::TOUCH_STATUS_QUEUED_END ? ER_CONSUMED :
104 ER_HANDLED; 101 ER_HANDLED;
105 } 102 }
106 103
107 EventResult DispatchEventToSingleHandler(EventHandler* handler, 104 EventResult DispatchEventToSingleHandler(EventHandler* handler,
108 EventTarget* target,
109 ui::GestureEvent* event) { 105 ui::GestureEvent* event) {
110 return handler->OnGestureEvent(target, event); 106 return handler->OnGestureEvent(event);
111 } 107 }
112 108
113 DISALLOW_COPY_AND_ASSIGN(EventDispatcher); 109 DISALLOW_COPY_AND_ASSIGN(EventDispatcher);
114 }; 110 };
115 111
116 } // namespace ui 112 } // namespace ui
117 113
118 #endif // UI_BASE_EVENTS_EVENT_CONSTANTS_EVENTS_EVENT_DISPATCHER_H_ 114 #endif // UI_BASE_EVENTS_EVENT_CONSTANTS_EVENTS_EVENT_DISPATCHER_H_
OLDNEW
« no previous file with comments | « ui/base/events/event.cc ('k') | ui/base/events/event_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698