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

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

Issue 174803002: Move root_window.* to window_event_dispatcher.* (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 10 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/root_window.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef UI_AURA_ROOT_WINDOW_H_
6 #define UI_AURA_ROOT_WINDOW_H_
7
8 #include <vector>
9
10 #include "base/basictypes.h"
11 #include "base/gtest_prod_util.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/message_loop/message_loop.h"
16 #include "ui/aura/aura_export.h"
17 #include "ui/aura/client/capture_delegate.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"
21 #include "ui/compositor/compositor.h"
22 #include "ui/compositor/layer_animation_observer.h"
23 #include "ui/events/event_constants.h"
24 #include "ui/events/event_processor.h"
25 #include "ui/events/event_targeter.h"
26 #include "ui/events/gestures/gesture_recognizer.h"
27 #include "ui/events/gestures/gesture_types.h"
28 #include "ui/gfx/native_widget_types.h"
29 #include "ui/gfx/point.h"
30
31 namespace gfx {
32 class Size;
33 class Transform;
34 }
35
36 namespace ui {
37 class GestureEvent;
38 class GestureRecognizer;
39 class KeyEvent;
40 class LayerAnimationSequence;
41 class MouseEvent;
42 class ScrollEvent;
43 class TouchEvent;
44 class ViewProp;
45 }
46
47 namespace aura {
48 class WindowTreeHost;
49 class RootWindowObserver;
50 class TestScreen;
51 class WindowTargeter;
52
53 // RootWindow is responsible for hosting a set of windows.
54 class AURA_EXPORT WindowEventDispatcher : public ui::EventProcessor,
55 public ui::GestureEventHelper,
56 public ui::LayerAnimationObserver,
57 public client::CaptureDelegate,
58 public WindowTreeHostDelegate {
59 public:
60 struct AURA_EXPORT CreateParams {
61 // CreateParams with initial_bounds and default host in pixel.
62 explicit CreateParams(const gfx::Rect& initial_bounds);
63 ~CreateParams() {}
64
65 gfx::Rect initial_bounds;
66
67 // A host to use in place of the default one that RootWindow will create.
68 // NULL by default.
69 WindowTreeHost* host;
70 };
71
72 explicit WindowEventDispatcher(const CreateParams& params);
73 virtual ~WindowEventDispatcher();
74
75 // Returns the WindowTreeHost for the specified accelerated widget, or NULL
76 // if there is none associated.
77 static WindowEventDispatcher* GetForAcceleratedWidget(
78 gfx::AcceleratedWidget widget);
79
80 Window* window() {
81 return const_cast<Window*>(
82 const_cast<const WindowEventDispatcher*>(this)->window());
83 }
84 const Window* window() const { return window_.get(); }
85 WindowTreeHost* host() {
86 return const_cast<WindowTreeHost*>(
87 const_cast<const WindowEventDispatcher*>(this)->host());
88 }
89 const WindowTreeHost* host() const { return host_.get(); }
90 Window* mouse_pressed_handler() { return mouse_pressed_handler_; }
91 Window* mouse_moved_handler() { return mouse_moved_handler_; }
92
93 // Stop listening events in preparation for shutdown.
94 void PrepareForShutdown();
95
96 // Repost event for re-processing. Used when exiting context menus.
97 // We only support the ET_MOUSE_PRESSED and ET_GESTURE_TAP_DOWN event
98 // types (although the latter is currently a no-op).
99 void RepostEvent(const ui::LocatedEvent& event);
100
101 WindowTreeHostDelegate* AsWindowTreeHostDelegate();
102
103 // Invoked when the mouse events get enabled or disabled.
104 void OnMouseEventsEnableStateChanged(bool enabled);
105
106 // Returns a target window for the given gesture event.
107 Window* GetGestureTarget(ui::GestureEvent* event);
108
109 // Handles a gesture event. Returns true if handled. Unlike the other
110 // event-dispatching function (e.g. for touch/mouse/keyboard events), gesture
111 // events are dispatched from GestureRecognizer instead of WindowTreeHost.
112 void DispatchGestureEvent(ui::GestureEvent* event);
113
114 // Invoked when |window| is being destroyed.
115 void OnWindowDestroying(Window* window);
116
117 // Invoked when |window|'s bounds have changed. |contained_mouse| indicates if
118 // the bounds before change contained the |last_moust_location()|.
119 void OnWindowBoundsChanged(Window* window, bool contained_mouse);
120
121 // Dispatches OnMouseExited to the |window| which is hiding if nessessary.
122 void DispatchMouseExitToHidingWindow(Window* window);
123
124 // Dispatches a ui::ET_MOUSE_EXITED event at |point|.
125 void DispatchMouseExitAtPoint(const gfx::Point& point);
126
127 // Invoked when |window|'s visibility has changed.
128 void OnWindowVisibilityChanged(Window* window, bool is_visible);
129
130 // Invoked when |window|'s tranfrom has changed. |contained_mouse|
131 // indicates if the bounds before change contained the
132 // |last_moust_location()|.
133 void OnWindowTransformed(Window* window, bool contained_mouse);
134
135 // Invoked when the keyboard mapping (in X11 terms: the mapping between
136 // keycodes and keysyms) has changed.
137 void OnKeyboardMappingChanged();
138
139 // The system windowing system has sent a request that we close our window.
140 void OnWindowTreeHostCloseRequested();
141
142 // Add/remove observer. There is no need to remove the observer if
143 // the root window is being deleted. In particular, you SHOULD NOT remove
144 // in |WindowObserver::OnWindowDestroying| of the observer observing
145 // the root window because it is too late to remove it.
146 void AddRootWindowObserver(RootWindowObserver* observer);
147 void RemoveRootWindowObserver(RootWindowObserver* observer);
148
149 // Gesture Recognition -------------------------------------------------------
150
151 // When a touch event is dispatched to a Window, it may want to process the
152 // touch event asynchronously. In such cases, the window should consume the
153 // event during the event dispatch. Once the event is properly processed, the
154 // window should let the WindowEventDispatcher know about the result of the
155 // event processing, so that gesture events can be properly created and
156 // dispatched.
157 void ProcessedTouchEvent(ui::TouchEvent* event,
158 Window* window,
159 ui::EventResult result);
160
161 // These methods are used to defer the processing of mouse/touch events
162 // related to resize. A client (typically a RenderWidgetHostViewAura) can call
163 // HoldPointerMoves when an resize is initiated and then ReleasePointerMoves
164 // once the resize is completed.
165 //
166 // More than one hold can be invoked and each hold must be cancelled by a
167 // release before we resume normal operation.
168 void HoldPointerMoves();
169 void ReleasePointerMoves();
170
171 // Gets the last location seen in a mouse event in this root window's
172 // coordinates. This may return a point outside the root window's bounds.
173 gfx::Point GetLastMouseLocationInRoot() const;
174
175 private:
176 FRIEND_TEST_ALL_PREFIXES(WindowEventDispatcherTest,
177 KeepTranslatedEventInRoot);
178
179 friend class Window;
180 friend class TestScreen;
181
182 // The parameter for OnWindowHidden() to specify why window is hidden.
183 enum WindowHiddenReason {
184 WINDOW_DESTROYED, // Window is destroyed.
185 WINDOW_HIDDEN, // Window is hidden.
186 WINDOW_MOVING, // Window is temporarily marked as hidden due to move
187 // across root windows.
188 };
189
190 // Updates the event with the appropriate transform for the device scale
191 // factor. The WindowTreeHostDelegate dispatches events in the physical pixel
192 // coordinate. But the event processing from WindowEventDispatcher onwards
193 // happen in device-independent pixel coordinate. So it is necessary to update
194 // the event received from the host.
195 void TransformEventForDeviceScaleFactor(ui::LocatedEvent* event);
196
197 // Dispatches the specified event type (intended for enter/exit) to the
198 // |mouse_moved_handler_|.
199 ui::EventDispatchDetails DispatchMouseEnterOrExit(
200 const ui::MouseEvent& event,
201 ui::EventType type) WARN_UNUSED_RESULT;
202 ui::EventDispatchDetails ProcessGestures(
203 ui::GestureRecognizer::Gestures* gestures) WARN_UNUSED_RESULT;
204
205 // Called when a Window is attached or detached from the
206 // WindowEventDispatcher.
207 void OnWindowAddedToRootWindow(Window* window);
208 void OnWindowRemovedFromRootWindow(Window* window, Window* new_root);
209
210 // Called when a window becomes invisible, either by being removed
211 // from root window hierarchy, via SetVisible(false) or being destroyed.
212 // |reason| specifies what triggered the hiding. Note that becoming invisible
213 // will cause a window to lose capture and some windows may destroy themselves
214 // on capture (like DragDropTracker).
215 void OnWindowHidden(Window* invisible, WindowHiddenReason reason);
216
217 // Cleans up the state of gestures for all windows in |window| (including
218 // |window| itself). This includes cancelling active touch points.
219 void CleanupGestureState(Window* window);
220
221 // Overridden from aura::client::CaptureDelegate:
222 virtual void UpdateCapture(Window* old_capture, Window* new_capture) OVERRIDE;
223 virtual void OnOtherRootGotCapture() OVERRIDE;
224 virtual void SetNativeCapture() OVERRIDE;
225 virtual void ReleaseNativeCapture() OVERRIDE;
226
227 // Overridden from ui::EventProcessor:
228 virtual ui::EventTarget* GetRootTarget() OVERRIDE;
229 virtual void PrepareEventForDispatch(ui::Event* event) OVERRIDE;
230
231 // Overridden from ui::EventDispatcherDelegate.
232 virtual bool CanDispatchToTarget(ui::EventTarget* target) OVERRIDE;
233 virtual ui::EventDispatchDetails PreDispatchEvent(ui::EventTarget* target,
234 ui::Event* event) OVERRIDE;
235 virtual ui::EventDispatchDetails PostDispatchEvent(
236 ui::EventTarget* target, const ui::Event& event) OVERRIDE;
237
238 // Overridden from ui::GestureEventHelper.
239 virtual bool CanDispatchToConsumer(ui::GestureConsumer* consumer) OVERRIDE;
240 virtual void DispatchPostponedGestureEvent(ui::GestureEvent* event) OVERRIDE;
241 virtual void DispatchCancelTouchEvent(ui::TouchEvent* event) OVERRIDE;
242
243 // Overridden from ui::LayerAnimationObserver:
244 virtual void OnLayerAnimationEnded(
245 ui::LayerAnimationSequence* animation) OVERRIDE;
246 virtual void OnLayerAnimationScheduled(
247 ui::LayerAnimationSequence* animation) OVERRIDE;
248 virtual void OnLayerAnimationAborted(
249 ui::LayerAnimationSequence* animation) OVERRIDE;
250
251 // Overridden from aura::WindowTreeHostDelegate:
252 virtual void OnHostCancelMode() OVERRIDE;
253 virtual void OnHostActivated() OVERRIDE;
254 virtual void OnHostLostWindowCapture() OVERRIDE;
255 virtual void OnHostLostMouseGrab() OVERRIDE;
256 virtual void OnHostMoved(const gfx::Point& origin) OVERRIDE;
257 virtual void OnHostResized(const gfx::Size& size) OVERRIDE;
258 virtual void OnCursorMovedToRootLocation(
259 const gfx::Point& root_location) OVERRIDE;
260 virtual WindowEventDispatcher* AsDispatcher() OVERRIDE;
261 virtual const WindowEventDispatcher* AsDispatcher() const OVERRIDE;
262 virtual ui::EventProcessor* GetEventProcessor() OVERRIDE;
263
264 // We hold and aggregate mouse drags and touch moves as a way of throttling
265 // resizes when HoldMouseMoves() is called. The following methods are used to
266 // dispatch held and newly incoming mouse and touch events, typically when an
267 // event other than one of these needs dispatching or a matching
268 // ReleaseMouseMoves()/ReleaseTouchMoves() is called. NOTE: because these
269 // methods dispatch events from WindowTreeHost the coordinates are in terms of
270 // the root.
271
272 ui::EventDispatchDetails DispatchHeldEvents() WARN_UNUSED_RESULT;
273 // Creates and dispatches synthesized mouse move event using the
274 // current mouse location.
275 ui::EventDispatchDetails SynthesizeMouseMoveEvent() WARN_UNUSED_RESULT;
276
277 void SynthesizeMouseMoveEventAsync();
278
279 // Posts a task to send synthesized mouse move event if there
280 // is no a pending task.
281 void PostMouseMoveEventAfterWindowChange();
282
283 void PreDispatchLocatedEvent(Window* target, ui::LocatedEvent* event);
284 void PreDispatchMouseEvent(Window* target, ui::MouseEvent* event);
285 void PreDispatchTouchEvent(Window* target, ui::TouchEvent* event);
286
287 // TODO(beng): evaluate the ideal ownership model.
288 scoped_ptr<Window> window_;
289
290 scoped_ptr<WindowTreeHost> host_;
291
292 // Touch ids that are currently down.
293 uint32 touch_ids_down_;
294
295 ObserverList<RootWindowObserver> observers_;
296
297 Window* mouse_pressed_handler_;
298 Window* mouse_moved_handler_;
299 Window* event_dispatch_target_;
300 Window* old_dispatch_target_;
301
302 bool synthesize_mouse_move_;
303
304 // How many move holds are outstanding. We try to defer dispatching
305 // touch/mouse moves while the count is > 0.
306 int move_hold_count_;
307 // The location of |held_move_event_| is in |window_|'s coordinate.
308 scoped_ptr<ui::LocatedEvent> held_move_event_;
309
310 // Allowing for reposting of events. Used when exiting context menus.
311 scoped_ptr<ui::LocatedEvent> held_repostable_event_;
312
313 // Set when dispatching a held event.
314 bool dispatching_held_event_;
315
316 scoped_ptr<ui::ViewProp> prop_;
317
318 // Used to schedule reposting an event.
319 base::WeakPtrFactory<WindowEventDispatcher> repost_event_factory_;
320
321 // Used to schedule DispatchHeldEvents() when |move_hold_count_| goes to 0.
322 base::WeakPtrFactory<WindowEventDispatcher> held_event_factory_;
323
324 DISALLOW_COPY_AND_ASSIGN(WindowEventDispatcher);
325 };
326
327 } // namespace aura
328
329 #endif // UI_AURA_ROOT_WINDOW_H_
OLDNEW
« no previous file with comments | « ui/aura/remote_window_tree_host_win.cc ('k') | ui/aura/root_window.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698