| 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_CONSTANTS_EVENTS_EVENT_DISPATCHER_H_ | 5 #ifndef UI_BASE_EVENTS_EVENT_DISPATCHER_H_ |
| 6 #define UI_BASE_EVENTS_EVENT_CONSTANTS_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" |
| 11 #include "ui/base/ui_export.h" | 11 #include "ui/base/ui_export.h" |
| 12 | 12 |
| 13 namespace ui { | 13 namespace ui { |
| 14 | 14 |
| 15 // Dispatches events to appropriate targets. | 15 // Dispatches events to appropriate targets. |
| 16 class UI_EXPORT EventDispatcher { | 16 class UI_EXPORT EventDispatcher { |
| 17 public: | 17 public: |
| 18 EventDispatcher() {} | 18 EventDispatcher(); |
| 19 virtual ~EventDispatcher() {} | 19 virtual ~EventDispatcher(); |
| 20 | 20 |
| 21 // Returns whether an event can still be dispatched to a target. (e.g. during | 21 // Returns whether an event can still be dispatched to a target. (e.g. during |
| 22 // event dispatch, one of the handlers may have destroyed the target, in which | 22 // event dispatch, one of the handlers may have destroyed the target, in which |
| 23 // case the event can no longer be dispatched to the target). | 23 // case the event can no longer be dispatched to the target). |
| 24 virtual bool CanDispatchToTarget(EventTarget* target) = 0; | 24 virtual bool CanDispatchToTarget(EventTarget* target) = 0; |
| 25 | 25 |
| 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; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 for (EventHandlerList::const_iterator it = list.begin(), | 71 for (EventHandlerList::const_iterator it = list.begin(), |
| 72 end = list.end(); it != end; ++it) { | 72 end = list.end(); it != end; ++it) { |
| 73 result |= DispatchEventToSingleHandler((*it), event); | 73 result |= DispatchEventToSingleHandler((*it), event); |
| 74 if (result & ER_CONSUMED) | 74 if (result & ER_CONSUMED) |
| 75 return result; | 75 return result; |
| 76 } | 76 } |
| 77 return result; | 77 return result; |
| 78 } | 78 } |
| 79 | 79 |
| 80 EventResult DispatchEventToSingleHandler(EventHandler* handler, | 80 EventResult DispatchEventToSingleHandler(EventHandler* handler, |
| 81 ui::KeyEvent* event) { | 81 KeyEvent* event); |
| 82 return handler->OnKeyEvent(event); | |
| 83 } | |
| 84 | |
| 85 EventResult DispatchEventToSingleHandler(EventHandler* handler, | 82 EventResult DispatchEventToSingleHandler(EventHandler* handler, |
| 86 ui::MouseEvent* event) { | 83 MouseEvent* event); |
| 87 return handler->OnMouseEvent(event); | |
| 88 } | |
| 89 | |
| 90 EventResult DispatchEventToSingleHandler(EventHandler* handler, | 84 EventResult DispatchEventToSingleHandler(EventHandler* handler, |
| 91 ui::ScrollEvent* event) { | 85 ScrollEvent* event); |
| 92 return handler->OnScrollEvent(event); | |
| 93 } | |
| 94 | |
| 95 EventResult DispatchEventToSingleHandler(EventHandler* handler, | 86 EventResult DispatchEventToSingleHandler(EventHandler* handler, |
| 96 ui::TouchEvent* event) { | 87 TouchEvent* event); |
| 97 // TODO(sad): This needs fixing (especially for the QUEUED_ status). | |
| 98 TouchStatus status = handler->OnTouchEvent(event); | |
| 99 return status == ui::TOUCH_STATUS_UNKNOWN ? ER_UNHANDLED : | |
| 100 status == ui::TOUCH_STATUS_QUEUED_END ? ER_CONSUMED : | |
| 101 ER_HANDLED; | |
| 102 } | |
| 103 | |
| 104 EventResult DispatchEventToSingleHandler(EventHandler* handler, | 88 EventResult DispatchEventToSingleHandler(EventHandler* handler, |
| 105 ui::GestureEvent* event) { | 89 GestureEvent* event); |
| 106 return handler->OnGestureEvent(event); | |
| 107 } | |
| 108 | 90 |
| 109 DISALLOW_COPY_AND_ASSIGN(EventDispatcher); | 91 DISALLOW_COPY_AND_ASSIGN(EventDispatcher); |
| 110 }; | 92 }; |
| 111 | 93 |
| 112 } // namespace ui | 94 } // namespace ui |
| 113 | 95 |
| 114 #endif // UI_BASE_EVENTS_EVENT_CONSTANTS_EVENTS_EVENT_DISPATCHER_H_ | 96 #endif // UI_BASE_EVENTS_EVENT_DISPATCHER_H_ |
| OLD | NEW |