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

Side by Side Diff: ui/aura/window_event_dispatcher.h

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

Powered by Google App Engine
This is Rietveld 408576698