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

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

Issue 10916210: events: Inlcude the event-phase and event-result in 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_constants.h ('k') | ui/base/events/event_dispatcher.cc » ('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_DISPATCHER_H_ 5 #ifndef UI_BASE_EVENTS_EVENT_DISPATCHER_H_
6 #define UI_BASE_EVENTS_EVENT_DISPATCHER_H_ 6 #define UI_BASE_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); 36 ScopedDispatchHelper dispatch_helper(event);
37 dispatcher.set_target(target); 37 dispatch_helper.set_target(target);
38 38
39 EventHandlerList list; 39 EventHandlerList list;
40 target->GetPreTargetHandlers(&list); 40 target->GetPreTargetHandlers(&list);
41 ProcessPreTargetList(&list); 41 ProcessPreTargetList(&list);
42 dispatch_helper.set_phase(EP_PRETARGET);
42 int result = DispatchEventToEventHandlers(list, event); 43 int result = DispatchEventToEventHandlers(list, event);
43 if (result & ER_CONSUMED) 44 if (result & ER_CONSUMED)
44 return result; 45 return result;
45 46
46 // If the event hasn't been consumed, trigger the default handler. Note that 47 // If the event hasn't been consumed, trigger the default handler. Note that
47 // even if the event has already been handled (i.e. return result has 48 // even if the event has already been handled (i.e. return result has
48 // ER_HANDLED set), that means that the event should still be processed at 49 // ER_HANDLED set), that means that the event should still be processed at
49 // this layer, however it should not be processed in the next layer of 50 // this layer, however it should not be processed in the next layer of
50 // abstraction. 51 // abstraction.
51 if (CanDispatchToTarget(target)) { 52 if (CanDispatchToTarget(target)) {
53 dispatch_helper.set_phase(EP_TARGET);
52 result |= DispatchEventToSingleHandler(target, event); 54 result |= DispatchEventToSingleHandler(target, event);
55 dispatch_helper.set_result(event->result() | result);
53 if (result & ER_CONSUMED) 56 if (result & ER_CONSUMED)
54 return result; 57 return result;
55 } 58 }
56 59
57 if (!CanDispatchToTarget(target)) 60 if (!CanDispatchToTarget(target))
58 return result; 61 return result;
59 62
60 list.clear(); 63 list.clear();
61 target->GetPostTargetHandlers(&list); 64 target->GetPostTargetHandlers(&list);
62 ProcessPostTargetList(&list); 65 ProcessPostTargetList(&list);
66 dispatch_helper.set_phase(EP_POSTTARGET);
63 result |= DispatchEventToEventHandlers(list, event); 67 result |= DispatchEventToEventHandlers(list, event);
64 return result; 68 return result;
65 } 69 }
66 70
67 private: 71 private:
72 class UI_EXPORT ScopedDispatchHelper : public NON_EXPORTED_BASE(
73 Event::DispatcherApi) {
74 public:
75 explicit ScopedDispatchHelper(Event* event);
76 virtual ~ScopedDispatchHelper();
77 private:
78 DISALLOW_COPY_AND_ASSIGN(ScopedDispatchHelper);
79 };
80
68 template<class T> 81 template<class T>
69 int DispatchEventToEventHandlers(EventHandlerList& list, T* event) { 82 int DispatchEventToEventHandlers(EventHandlerList& list, T* event) {
70 int result = ER_UNHANDLED; 83 int result = ER_UNHANDLED;
84 Event::DispatcherApi dispatch_helper(event);
71 for (EventHandlerList::const_iterator it = list.begin(), 85 for (EventHandlerList::const_iterator it = list.begin(),
72 end = list.end(); it != end; ++it) { 86 end = list.end(); it != end; ++it) {
73 result |= DispatchEventToSingleHandler((*it), event); 87 result |= DispatchEventToSingleHandler((*it), event);
88 dispatch_helper.set_result(event->result() | result);
74 if (result & ER_CONSUMED) 89 if (result & ER_CONSUMED)
75 return result; 90 return result;
76 } 91 }
77 return result; 92 return result;
78 } 93 }
79 94
80 EventResult DispatchEventToSingleHandler(EventHandler* handler, 95 EventResult DispatchEventToSingleHandler(EventHandler* handler,
81 KeyEvent* event); 96 KeyEvent* event);
82 EventResult DispatchEventToSingleHandler(EventHandler* handler, 97 EventResult DispatchEventToSingleHandler(EventHandler* handler,
83 MouseEvent* event); 98 MouseEvent* event);
84 EventResult DispatchEventToSingleHandler(EventHandler* handler, 99 EventResult DispatchEventToSingleHandler(EventHandler* handler,
85 ScrollEvent* event); 100 ScrollEvent* event);
86 EventResult DispatchEventToSingleHandler(EventHandler* handler, 101 EventResult DispatchEventToSingleHandler(EventHandler* handler,
87 TouchEvent* event); 102 TouchEvent* event);
88 EventResult DispatchEventToSingleHandler(EventHandler* handler, 103 EventResult DispatchEventToSingleHandler(EventHandler* handler,
89 GestureEvent* event); 104 GestureEvent* event);
90 105
91 DISALLOW_COPY_AND_ASSIGN(EventDispatcher); 106 DISALLOW_COPY_AND_ASSIGN(EventDispatcher);
92 }; 107 };
93 108
94 } // namespace ui 109 } // namespace ui
95 110
96 #endif // UI_BASE_EVENTS_EVENT_DISPATCHER_H_ 111 #endif // UI_BASE_EVENTS_EVENT_DISPATCHER_H_
OLDNEW
« no previous file with comments | « ui/base/events/event_constants.h ('k') | ui/base/events/event_dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698