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

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
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->set_target(target);
37
36 EventHandlerList list; 38 EventHandlerList list;
37 target->GetPreTargetHandlers(&list); 39 target->GetPreTargetHandlers(&list);
38 ProcessPreTargetList(&list); 40 ProcessPreTargetList(&list);
39 int result = DispatchEventToEventHandlers(list, target, event); 41 int result = DispatchEventToEventHandlers(list, event);
40 if (result & ER_CONSUMED) 42 if (result & ER_CONSUMED)
41 return result; 43 return result;
42 44
43 // If the event hasn't been consumed, trigger the default handler. Note that 45 // 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 46 // 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 47 // 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 48 // this layer, however it should not be processed in the next layer of
47 // abstraction. 49 // abstraction.
48 if (CanDispatchToTarget(target)) { 50 if (CanDispatchToTarget(target)) {
49 result |= DispatchEventToSingleHandler(target, target, event); 51 result |= DispatchEventToSingleHandler(target, event);
50 if (result & ER_CONSUMED) 52 if (result & ER_CONSUMED)
51 return result; 53 return result;
52 } 54 }
53 55
54 if (!CanDispatchToTarget(target)) 56 if (!CanDispatchToTarget(target))
55 return result; 57 return result;
56 58
57 list.clear(); 59 list.clear();
58 target->GetPostTargetHandlers(&list); 60 target->GetPostTargetHandlers(&list);
59 ProcessPostTargetList(&list); 61 ProcessPostTargetList(&list);
60 result |= DispatchEventToEventHandlers(list, target, event); 62 result |= DispatchEventToEventHandlers(list, event);
61 return result; 63 return result;
62 } 64 }
63 65
64 private: 66 private:
65 template<class T> 67 template<class T>
66 int DispatchEventToEventHandlers(EventHandlerList& list, 68 int DispatchEventToEventHandlers(EventHandlerList& list, T* event) {
67 EventTarget* target,
68 T* event) {
69 int result = ER_UNHANDLED; 69 int result = ER_UNHANDLED;
70 for (EventHandlerList::const_iterator it = list.begin(), 70 for (EventHandlerList::const_iterator it = list.begin(),
71 end = list.end(); it != end; ++it) { 71 end = list.end(); it != end; ++it) {
72 result |= DispatchEventToSingleHandler((*it), target, event); 72 result |= DispatchEventToSingleHandler((*it), event);
73 if (result & ER_CONSUMED) 73 if (result & ER_CONSUMED)
74 return result; 74 return result;
75 } 75 }
76 return result; 76 return result;
77 } 77 }
78 78
79 EventResult DispatchEventToSingleHandler(EventHandler* handler, 79 EventResult DispatchEventToSingleHandler(EventHandler* handler,
80 EventTarget* target,
81 ui::KeyEvent* event) { 80 ui::KeyEvent* event) {
82 return handler->OnKeyEvent(target, event); 81 return handler->OnKeyEvent(event);
83 } 82 }
84 83
85 EventResult DispatchEventToSingleHandler(EventHandler* handler, 84 EventResult DispatchEventToSingleHandler(EventHandler* handler,
86 EventTarget* target,
87 ui::MouseEvent* event) { 85 ui::MouseEvent* event) {
88 return handler->OnMouseEvent(target, event); 86 return handler->OnMouseEvent(event);
89 } 87 }
90 88
91 EventResult DispatchEventToSingleHandler(EventHandler* handler, 89 EventResult DispatchEventToSingleHandler(EventHandler* handler,
92 EventTarget* target,
93 ui::ScrollEvent* event) { 90 ui::ScrollEvent* event) {
94 return handler->OnScrollEvent(target, event); 91 return handler->OnScrollEvent(event);
95 } 92 }
96 93
97 EventResult DispatchEventToSingleHandler(EventHandler* handler, 94 EventResult DispatchEventToSingleHandler(EventHandler* handler,
98 EventTarget* target,
99 ui::TouchEvent* event) { 95 ui::TouchEvent* event) {
100 // TODO(sad): This needs fixing (especially for the QUEUED_ status). 96 // TODO(sad): This needs fixing (especially for the QUEUED_ status).
101 TouchStatus status = handler->OnTouchEvent(target, event); 97 TouchStatus status = handler->OnTouchEvent(event);
102 return status == ui::TOUCH_STATUS_UNKNOWN ? ER_UNHANDLED : 98 return status == ui::TOUCH_STATUS_UNKNOWN ? ER_UNHANDLED :
103 status == ui::TOUCH_STATUS_QUEUED_END ? ER_CONSUMED : 99 status == ui::TOUCH_STATUS_QUEUED_END ? ER_CONSUMED :
104 ER_HANDLED; 100 ER_HANDLED;
105 } 101 }
106 102
107 EventResult DispatchEventToSingleHandler(EventHandler* handler, 103 EventResult DispatchEventToSingleHandler(EventHandler* handler,
108 EventTarget* target,
109 ui::GestureEvent* event) { 104 ui::GestureEvent* event) {
110 return handler->OnGestureEvent(target, event); 105 return handler->OnGestureEvent(event);
111 } 106 }
112 107
113 DISALLOW_COPY_AND_ASSIGN(EventDispatcher); 108 DISALLOW_COPY_AND_ASSIGN(EventDispatcher);
114 }; 109 };
115 110
116 } // namespace ui 111 } // namespace ui
117 112
118 #endif // UI_BASE_EVENTS_EVENT_CONSTANTS_EVENTS_EVENT_DISPATCHER_H_ 113 #endif // UI_BASE_EVENTS_EVENT_CONSTANTS_EVENTS_EVENT_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698