| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_AURA_WINDOW_EVENT_DISPATCHER_H_ | 5 #ifndef UI_AURA_WINDOW_EVENT_DISPATCHER_H_ |
| 6 #define UI_AURA_WINDOW_EVENT_DISPATCHER_H_ | 6 #define UI_AURA_WINDOW_EVENT_DISPATCHER_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "ui/aura/aura_export.h" | 16 #include "ui/aura/aura_export.h" |
| 17 #include "ui/aura/client/capture_delegate.h" | 17 #include "ui/aura/client/capture_delegate.h" |
| 18 #include "ui/aura/window_tree_host.h" | 18 #include "ui/aura/window_tree_host.h" |
| 19 #include "ui/aura/window_tree_host_delegate.h" |
| 19 #include "ui/base/cursor/cursor.h" | 20 #include "ui/base/cursor/cursor.h" |
| 21 #include "ui/compositor/compositor.h" |
| 22 #include "ui/compositor/layer_animation_observer.h" |
| 20 #include "ui/events/event_constants.h" | 23 #include "ui/events/event_constants.h" |
| 21 #include "ui/events/event_processor.h" | 24 #include "ui/events/event_processor.h" |
| 22 #include "ui/events/event_targeter.h" | 25 #include "ui/events/event_targeter.h" |
| 23 #include "ui/events/gestures/gesture_recognizer.h" | 26 #include "ui/events/gestures/gesture_recognizer.h" |
| 24 #include "ui/events/gestures/gesture_types.h" | 27 #include "ui/events/gestures/gesture_types.h" |
| 25 #include "ui/gfx/native_widget_types.h" | 28 #include "ui/gfx/native_widget_types.h" |
| 26 #include "ui/gfx/point.h" | 29 #include "ui/gfx/point.h" |
| 27 | 30 |
| 28 namespace gfx { | 31 namespace gfx { |
| 29 class Size; | 32 class Size; |
| 30 class Transform; | 33 class Transform; |
| 31 } | 34 } |
| 32 | 35 |
| 33 namespace ui { | 36 namespace ui { |
| 34 class GestureEvent; | 37 class GestureEvent; |
| 35 class GestureRecognizer; | 38 class GestureRecognizer; |
| 36 class KeyEvent; | 39 class KeyEvent; |
| 40 class LayerAnimationSequence; |
| 37 class MouseEvent; | 41 class MouseEvent; |
| 38 class ScrollEvent; | 42 class ScrollEvent; |
| 39 class TouchEvent; | 43 class TouchEvent; |
| 40 } | 44 } |
| 41 | 45 |
| 42 namespace aura { | 46 namespace aura { |
| 43 class RootWindowObserver; | 47 class RootWindowObserver; |
| 44 class TestScreen; | 48 class TestScreen; |
| 45 class WindowTargeter; | 49 class WindowTargeter; |
| 46 | 50 |
| 47 // WindowEventDispatcher orchestrates event dispatch within a window tree | 51 // WindowEventDispatcher orchestrates event dispatch within a window tree |
| 48 // owned by WindowTreeHost. WTH also owns the WED. | 52 // owned by WindowTreeHost. WTH also owns the WED. |
| 49 // TODO(beng): In progress, remove functionality not directly related to | 53 // TODO(beng): In progress, remove functionality not directly related to |
| 50 // event dispatch. | 54 // event dispatch. |
| 51 class AURA_EXPORT WindowEventDispatcher : public ui::EventProcessor, | 55 class AURA_EXPORT WindowEventDispatcher : public ui::EventProcessor, |
| 52 public ui::GestureEventHelper, | 56 public ui::GestureEventHelper, |
| 53 public client::CaptureDelegate { | 57 public ui::LayerAnimationObserver, |
| 58 public client::CaptureDelegate, |
| 59 public WindowTreeHostDelegate { |
| 54 public: | 60 public: |
| 55 explicit WindowEventDispatcher(WindowTreeHost* host); | 61 explicit WindowEventDispatcher(WindowTreeHost* host); |
| 56 virtual ~WindowEventDispatcher(); | 62 virtual ~WindowEventDispatcher(); |
| 57 | 63 |
| 58 Window* window() { return host()->window(); } | 64 Window* window() { return host()->window(); } |
| 59 const Window* window() const { return host()->window(); } | 65 const Window* window() const { return host()->window(); } |
| 60 WindowTreeHost* host() { | 66 WindowTreeHost* host() { |
| 61 return const_cast<WindowTreeHost*>( | 67 return const_cast<WindowTreeHost*>( |
| 62 const_cast<const WindowEventDispatcher*>(this)->host()); | 68 const_cast<const WindowEventDispatcher*>(this)->host()); |
| 63 } | 69 } |
| 64 const WindowTreeHost* host() const { return host_; } | 70 const WindowTreeHost* host() const { return host_; } |
| 65 Window* mouse_pressed_handler() { return mouse_pressed_handler_; } | 71 Window* mouse_pressed_handler() { return mouse_pressed_handler_; } |
| 66 Window* mouse_moved_handler() { return mouse_moved_handler_; } | 72 Window* mouse_moved_handler() { return mouse_moved_handler_; } |
| 67 | 73 |
| 68 // Stop listening events in preparation for shutdown. | 74 // Stop listening events in preparation for shutdown. |
| 69 void PrepareForShutdown(); | 75 void PrepareForShutdown(); |
| 70 | 76 |
| 71 // Repost event for re-processing. Used when exiting context menus. | 77 // Repost event for re-processing. Used when exiting context menus. |
| 72 // We only support the ET_MOUSE_PRESSED and ET_GESTURE_TAP_DOWN event | 78 // We only support the ET_MOUSE_PRESSED and ET_GESTURE_TAP_DOWN event |
| 73 // types (although the latter is currently a no-op). | 79 // types (although the latter is currently a no-op). |
| 74 void RepostEvent(const ui::LocatedEvent& event); | 80 void RepostEvent(const ui::LocatedEvent& event); |
| 75 | 81 |
| 82 WindowTreeHostDelegate* AsWindowTreeHostDelegate(); |
| 83 |
| 76 // Invoked when the mouse events get enabled or disabled. | 84 // Invoked when the mouse events get enabled or disabled. |
| 77 void OnMouseEventsEnableStateChanged(bool enabled); | 85 void OnMouseEventsEnableStateChanged(bool enabled); |
| 78 | 86 |
| 79 void DispatchCancelModeEvent(); | |
| 80 | |
| 81 // Returns a target window for the given gesture event. | 87 // Returns a target window for the given gesture event. |
| 82 Window* GetGestureTarget(ui::GestureEvent* event); | 88 Window* GetGestureTarget(ui::GestureEvent* event); |
| 83 | 89 |
| 84 // Handles a gesture event. Returns true if handled. Unlike the other | 90 // Handles a gesture event. Returns true if handled. Unlike the other |
| 85 // event-dispatching function (e.g. for touch/mouse/keyboard events), gesture | 91 // event-dispatching function (e.g. for touch/mouse/keyboard events), gesture |
| 86 // events are dispatched from GestureRecognizer instead of WindowTreeHost. | 92 // events are dispatched from GestureRecognizer instead of WindowTreeHost. |
| 87 void DispatchGestureEvent(ui::GestureEvent* event); | 93 void DispatchGestureEvent(ui::GestureEvent* event); |
| 88 | 94 |
| 89 // Invoked when |window| is being destroyed. | 95 // Invoked when |window| is being destroyed. |
| 90 void OnWindowDestroying(Window* window); | 96 void OnWindowDestroying(Window* window); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 // | 132 // |
| 127 // More than one hold can be invoked and each hold must be cancelled by a | 133 // More than one hold can be invoked and each hold must be cancelled by a |
| 128 // release before we resume normal operation. | 134 // release before we resume normal operation. |
| 129 void HoldPointerMoves(); | 135 void HoldPointerMoves(); |
| 130 void ReleasePointerMoves(); | 136 void ReleasePointerMoves(); |
| 131 | 137 |
| 132 // Gets the last location seen in a mouse event in this root window's | 138 // Gets the last location seen in a mouse event in this root window's |
| 133 // coordinates. This may return a point outside the root window's bounds. | 139 // coordinates. This may return a point outside the root window's bounds. |
| 134 gfx::Point GetLastMouseLocationInRoot() const; | 140 gfx::Point GetLastMouseLocationInRoot() const; |
| 135 | 141 |
| 136 void OnHostLostMouseGrab(); | |
| 137 // TODO(beng): replace with a window observer. | |
| 138 void OnHostResized(const gfx::Size& size); | |
| 139 void OnCursorMovedToRootLocation(const gfx::Point& root_location); | |
| 140 | |
| 141 private: | 142 private: |
| 142 FRIEND_TEST_ALL_PREFIXES(WindowEventDispatcherTest, | 143 FRIEND_TEST_ALL_PREFIXES(WindowEventDispatcherTest, |
| 143 KeepTranslatedEventInRoot); | 144 KeepTranslatedEventInRoot); |
| 144 | 145 |
| 145 friend class Window; | 146 friend class Window; |
| 146 friend class TestScreen; | 147 friend class TestScreen; |
| 147 | 148 |
| 148 // The parameter for OnWindowHidden() to specify why window is hidden. | 149 // The parameter for OnWindowHidden() to specify why window is hidden. |
| 149 enum WindowHiddenReason { | 150 enum WindowHiddenReason { |
| 150 WINDOW_DESTROYED, // Window is destroyed. | 151 WINDOW_DESTROYED, // Window is destroyed. |
| 151 WINDOW_HIDDEN, // Window is hidden. | 152 WINDOW_HIDDEN, // Window is hidden. |
| 152 WINDOW_MOVING, // Window is temporarily marked as hidden due to move | 153 WINDOW_MOVING, // Window is temporarily marked as hidden due to move |
| 153 // across root windows. | 154 // across root windows. |
| 154 }; | 155 }; |
| 155 | 156 |
| 156 // Updates the event with the appropriate transform for the device scale | 157 // Updates the event with the appropriate transform for the device scale |
| 157 // factor. The WindowEventDispatcher dispatches events in the physical pixel | 158 // factor. The WindowTreeHostDelegate dispatches events in the physical pixel |
| 158 // coordinate. But the event processing from WindowEventDispatcher onwards | 159 // coordinate. But the event processing from WindowEventDispatcher onwards |
| 159 // happen in device-independent pixel coordinate. So it is necessary to update | 160 // happen in device-independent pixel coordinate. So it is necessary to update |
| 160 // the event received from the host. | 161 // the event received from the host. |
| 161 void TransformEventForDeviceScaleFactor(ui::LocatedEvent* event); | 162 void TransformEventForDeviceScaleFactor(ui::LocatedEvent* event); |
| 162 | 163 |
| 163 // Dispatches the specified event type (intended for enter/exit) to the | 164 // Dispatches the specified event type (intended for enter/exit) to the |
| 164 // |mouse_moved_handler_|. | 165 // |mouse_moved_handler_|. |
| 165 ui::EventDispatchDetails DispatchMouseEnterOrExit( | 166 ui::EventDispatchDetails DispatchMouseEnterOrExit( |
| 166 const ui::MouseEvent& event, | 167 const ui::MouseEvent& event, |
| 167 ui::EventType type) WARN_UNUSED_RESULT; | 168 ui::EventType type) WARN_UNUSED_RESULT; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 virtual ui::EventDispatchDetails PreDispatchEvent(ui::EventTarget* target, | 200 virtual ui::EventDispatchDetails PreDispatchEvent(ui::EventTarget* target, |
| 200 ui::Event* event) OVERRIDE; | 201 ui::Event* event) OVERRIDE; |
| 201 virtual ui::EventDispatchDetails PostDispatchEvent( | 202 virtual ui::EventDispatchDetails PostDispatchEvent( |
| 202 ui::EventTarget* target, const ui::Event& event) OVERRIDE; | 203 ui::EventTarget* target, const ui::Event& event) OVERRIDE; |
| 203 | 204 |
| 204 // Overridden from ui::GestureEventHelper. | 205 // Overridden from ui::GestureEventHelper. |
| 205 virtual bool CanDispatchToConsumer(ui::GestureConsumer* consumer) OVERRIDE; | 206 virtual bool CanDispatchToConsumer(ui::GestureConsumer* consumer) OVERRIDE; |
| 206 virtual void DispatchPostponedGestureEvent(ui::GestureEvent* event) OVERRIDE; | 207 virtual void DispatchPostponedGestureEvent(ui::GestureEvent* event) OVERRIDE; |
| 207 virtual void DispatchCancelTouchEvent(ui::TouchEvent* event) OVERRIDE; | 208 virtual void DispatchCancelTouchEvent(ui::TouchEvent* event) OVERRIDE; |
| 208 | 209 |
| 210 // Overridden from ui::LayerAnimationObserver: |
| 211 virtual void OnLayerAnimationEnded( |
| 212 ui::LayerAnimationSequence* animation) OVERRIDE; |
| 213 virtual void OnLayerAnimationScheduled( |
| 214 ui::LayerAnimationSequence* animation) OVERRIDE; |
| 215 virtual void OnLayerAnimationAborted( |
| 216 ui::LayerAnimationSequence* animation) OVERRIDE; |
| 217 |
| 218 // Overridden from aura::WindowTreeHostDelegate: |
| 219 virtual void OnHostCancelMode() OVERRIDE; |
| 220 virtual void OnHostActivated() OVERRIDE; |
| 221 virtual void OnHostLostWindowCapture() OVERRIDE; |
| 222 virtual void OnHostLostMouseGrab() OVERRIDE; |
| 223 virtual void OnHostResized(const gfx::Size& size) OVERRIDE; |
| 224 virtual void OnCursorMovedToRootLocation( |
| 225 const gfx::Point& root_location) OVERRIDE; |
| 226 virtual WindowEventDispatcher* AsDispatcher() OVERRIDE; |
| 227 virtual const WindowEventDispatcher* AsDispatcher() const OVERRIDE; |
| 228 virtual ui::EventProcessor* GetEventProcessor() OVERRIDE; |
| 229 |
| 209 // We hold and aggregate mouse drags and touch moves as a way of throttling | 230 // We hold and aggregate mouse drags and touch moves as a way of throttling |
| 210 // resizes when HoldMouseMoves() is called. The following methods are used to | 231 // resizes when HoldMouseMoves() is called. The following methods are used to |
| 211 // dispatch held and newly incoming mouse and touch events, typically when an | 232 // dispatch held and newly incoming mouse and touch events, typically when an |
| 212 // event other than one of these needs dispatching or a matching | 233 // event other than one of these needs dispatching or a matching |
| 213 // ReleaseMouseMoves()/ReleaseTouchMoves() is called. NOTE: because these | 234 // ReleaseMouseMoves()/ReleaseTouchMoves() is called. NOTE: because these |
| 214 // methods dispatch events from WindowTreeHost the coordinates are in terms of | 235 // methods dispatch events from WindowTreeHost the coordinates are in terms of |
| 215 // the root. | 236 // the root. |
| 216 | 237 |
| 217 ui::EventDispatchDetails DispatchHeldEvents() WARN_UNUSED_RESULT; | 238 ui::EventDispatchDetails DispatchHeldEvents() WARN_UNUSED_RESULT; |
| 218 // Creates and dispatches synthesized mouse move event using the | 239 // Creates and dispatches synthesized mouse move event using the |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 | 279 |
| 259 // Used to schedule DispatchHeldEvents() when |move_hold_count_| goes to 0. | 280 // Used to schedule DispatchHeldEvents() when |move_hold_count_| goes to 0. |
| 260 base::WeakPtrFactory<WindowEventDispatcher> held_event_factory_; | 281 base::WeakPtrFactory<WindowEventDispatcher> held_event_factory_; |
| 261 | 282 |
| 262 DISALLOW_COPY_AND_ASSIGN(WindowEventDispatcher); | 283 DISALLOW_COPY_AND_ASSIGN(WindowEventDispatcher); |
| 263 }; | 284 }; |
| 264 | 285 |
| 265 } // namespace aura | 286 } // namespace aura |
| 266 | 287 |
| 267 #endif // UI_AURA_WINDOW_EVENT_DISPATCHER_H_ | 288 #endif // UI_AURA_WINDOW_EVENT_DISPATCHER_H_ |
| OLD | NEW |