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_AURA_ROOT_WINDOW_H_ | 5 #ifndef UI_AURA_ROOT_WINDOW_H_ |
6 #define UI_AURA_ROOT_WINDOW_H_ | 6 #define UI_AURA_ROOT_WINDOW_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 class KeyEvent; | 38 class KeyEvent; |
39 class LayerAnimationSequence; | 39 class LayerAnimationSequence; |
40 class MouseEvent; | 40 class MouseEvent; |
41 class ScrollEvent; | 41 class ScrollEvent; |
42 class TouchEvent; | 42 class TouchEvent; |
43 class ViewProp; | 43 class ViewProp; |
44 } | 44 } |
45 | 45 |
46 namespace aura { | 46 namespace aura { |
47 class RootWindow; | 47 class RootWindow; |
48 class WindowTreeHost; | 48 class RootWindowHost; |
49 class RootWindowObserver; | 49 class RootWindowObserver; |
50 class TestScreen; | 50 class TestScreen; |
51 | 51 |
52 // RootWindow is responsible for hosting a set of windows. | 52 // RootWindow is responsible for hosting a set of windows. |
53 class AURA_EXPORT RootWindow : public ui::EventDispatcherDelegate, | 53 class AURA_EXPORT RootWindow : public ui::EventDispatcherDelegate, |
54 public ui::GestureEventHelper, | 54 public ui::GestureEventHelper, |
55 public ui::LayerAnimationObserver, | 55 public ui::LayerAnimationObserver, |
56 public aura::client::CaptureDelegate, | 56 public aura::client::CaptureDelegate, |
57 public aura::WindowTreeHostDelegate { | 57 public aura::RootWindowHostDelegate { |
58 public: | 58 public: |
59 struct AURA_EXPORT CreateParams { | 59 struct AURA_EXPORT CreateParams { |
60 // CreateParams with initial_bounds and default host in pixel. | 60 // CreateParams with initial_bounds and default host in pixel. |
61 explicit CreateParams(const gfx::Rect& initial_bounds); | 61 explicit CreateParams(const gfx::Rect& initial_bounds); |
62 ~CreateParams() {} | 62 ~CreateParams() {} |
63 | 63 |
64 gfx::Rect initial_bounds; | 64 gfx::Rect initial_bounds; |
65 | 65 |
66 // A host to use in place of the default one that RootWindow will create. | 66 // A host to use in place of the default one that RootWindow will create. |
67 // NULL by default. | 67 // NULL by default. |
68 WindowTreeHost* host; | 68 RootWindowHost* host; |
69 }; | 69 }; |
70 | 70 |
71 explicit RootWindow(const CreateParams& params); | 71 explicit RootWindow(const CreateParams& params); |
72 virtual ~RootWindow(); | 72 virtual ~RootWindow(); |
73 | 73 |
74 // Returns the WindowTreeHost for the specified accelerated widget, or NULL | 74 // Returns the RootWindowHost for the specified accelerated widget, or NULL |
75 // if there is none associated. | 75 // if there is none associated. |
76 static RootWindow* GetForAcceleratedWidget(gfx::AcceleratedWidget widget); | 76 static RootWindow* GetForAcceleratedWidget(gfx::AcceleratedWidget widget); |
77 | 77 |
78 Window* window() { | 78 Window* window() { |
79 return const_cast<Window*>(const_cast<const RootWindow*>(this)->window()); | 79 return const_cast<Window*>(const_cast<const RootWindow*>(this)->window()); |
80 } | 80 } |
81 const Window* window() const { return window_.get(); } | 81 const Window* window() const { return window_.get(); } |
82 WindowTreeHost* host() { | 82 RootWindowHost* host() { |
83 return const_cast<WindowTreeHost*>( | 83 return const_cast<RootWindowHost*>( |
84 const_cast<const RootWindow*>(this)->host()); | 84 const_cast<const RootWindow*>(this)->host()); |
85 } | 85 } |
86 const WindowTreeHost* host() const { return host_.get(); } | 86 const RootWindowHost* host() const { return host_.get(); } |
87 gfx::NativeCursor last_cursor() const { return last_cursor_; } | 87 gfx::NativeCursor last_cursor() const { return last_cursor_; } |
88 Window* mouse_pressed_handler() { return mouse_pressed_handler_; } | 88 Window* mouse_pressed_handler() { return mouse_pressed_handler_; } |
89 Window* mouse_moved_handler() { return mouse_moved_handler_; } | 89 Window* mouse_moved_handler() { return mouse_moved_handler_; } |
90 | 90 |
91 // Initializes the root window. | 91 // Initializes the root window. |
92 void Init(); | 92 void Init(); |
93 | 93 |
94 // Stop listening events in preparation for shutdown. | 94 // Stop listening events in preparation for shutdown. |
95 void PrepareForShutdown(); | 95 void PrepareForShutdown(); |
96 | 96 |
97 // Repost event for re-processing. Used when exiting context menus. | 97 // Repost event for re-processing. Used when exiting context menus. |
98 // We only support the ET_MOUSE_PRESSED and ET_GESTURE_TAP_DOWN event | 98 // We only support the ET_MOUSE_PRESSED and ET_GESTURE_TAP_DOWN event |
99 // types (although the latter is currently a no-op). | 99 // types (although the latter is currently a no-op). |
100 void RepostEvent(const ui::LocatedEvent& event); | 100 void RepostEvent(const ui::LocatedEvent& event); |
101 | 101 |
102 WindowTreeHostDelegate* AsWindowTreeHostDelegate(); | 102 RootWindowHostDelegate* AsRootWindowHostDelegate(); |
103 | 103 |
104 // Gets/sets the size of the host window. | 104 // Gets/sets the size of the host window. |
105 void SetHostSize(const gfx::Size& size_in_pixel); | 105 void SetHostSize(const gfx::Size& size_in_pixel); |
106 | 106 |
107 // Sets the bounds of the host window. | 107 // Sets the bounds of the host window. |
108 void SetHostBounds(const gfx::Rect& size_in_pizel); | 108 void SetHostBounds(const gfx::Rect& size_in_pizel); |
109 | 109 |
110 // Sets the currently-displayed cursor. If the cursor was previously hidden | 110 // Sets the currently-displayed cursor. If the cursor was previously hidden |
111 // via ShowCursor(false), it will remain hidden until ShowCursor(true) is | 111 // via ShowCursor(false), it will remain hidden until ShowCursor(true) is |
112 // called, at which point the cursor that was last set via SetCursor() will be | 112 // called, at which point the cursor that was last set via SetCursor() will be |
(...skipping 10 matching lines...) Expand all Loading... |
123 void MoveCursorTo(const gfx::Point& location); | 123 void MoveCursorTo(const gfx::Point& location); |
124 | 124 |
125 // Moves the cursor to the |host_location| given in host coordinates. | 125 // Moves the cursor to the |host_location| given in host coordinates. |
126 void MoveCursorToHostLocation(const gfx::Point& host_location); | 126 void MoveCursorToHostLocation(const gfx::Point& host_location); |
127 | 127 |
128 // Returns a target window for the given gesture event. | 128 // Returns a target window for the given gesture event. |
129 Window* GetGestureTarget(ui::GestureEvent* event); | 129 Window* GetGestureTarget(ui::GestureEvent* event); |
130 | 130 |
131 // Handles a gesture event. Returns true if handled. Unlike the other | 131 // Handles a gesture event. Returns true if handled. Unlike the other |
132 // event-dispatching function (e.g. for touch/mouse/keyboard events), gesture | 132 // event-dispatching function (e.g. for touch/mouse/keyboard events), gesture |
133 // events are dispatched from GestureRecognizer instead of WindowTreeHost. | 133 // events are dispatched from GestureRecognizer instead of RootWindowHost. |
134 void DispatchGestureEvent(ui::GestureEvent* event); | 134 void DispatchGestureEvent(ui::GestureEvent* event); |
135 | 135 |
136 // Invoked when |window| is being destroyed. | 136 // Invoked when |window| is being destroyed. |
137 void OnWindowDestroying(Window* window); | 137 void OnWindowDestroying(Window* window); |
138 | 138 |
139 // Invoked when |window|'s bounds have changed. |contained_mouse| indicates if | 139 // Invoked when |window|'s bounds have changed. |contained_mouse| indicates if |
140 // the bounds before change contained the |last_moust_location()|. | 140 // the bounds before change contained the |last_moust_location()|. |
141 void OnWindowBoundsChanged(Window* window, bool contained_mouse); | 141 void OnWindowBoundsChanged(Window* window, bool contained_mouse); |
142 | 142 |
143 // Dispatches OnMouseExited to the |window| which is hiding if nessessary. | 143 // Dispatches OnMouseExited to the |window| which is hiding if nessessary. |
144 void DispatchMouseExitToHidingWindow(Window* window); | 144 void DispatchMouseExitToHidingWindow(Window* window); |
145 | 145 |
146 // Dispatches a ui::ET_MOUSE_EXITED event at |point|. | 146 // Dispatches a ui::ET_MOUSE_EXITED event at |point|. |
147 void DispatchMouseExitAtPoint(const gfx::Point& point); | 147 void DispatchMouseExitAtPoint(const gfx::Point& point); |
148 | 148 |
149 // Invoked when |window|'s visibility has changed. | 149 // Invoked when |window|'s visibility has changed. |
150 void OnWindowVisibilityChanged(Window* window, bool is_visible); | 150 void OnWindowVisibilityChanged(Window* window, bool is_visible); |
151 | 151 |
152 // Invoked when |window|'s tranfrom has changed. |contained_mouse| | 152 // Invoked when |window|'s tranfrom has changed. |contained_mouse| |
153 // indicates if the bounds before change contained the | 153 // indicates if the bounds before change contained the |
154 // |last_moust_location()|. | 154 // |last_moust_location()|. |
155 void OnWindowTransformed(Window* window, bool contained_mouse); | 155 void OnWindowTransformed(Window* window, bool contained_mouse); |
156 | 156 |
157 // Invoked when the keyboard mapping (in X11 terms: the mapping between | 157 // Invoked when the keyboard mapping (in X11 terms: the mapping between |
158 // keycodes and keysyms) has changed. | 158 // keycodes and keysyms) has changed. |
159 void OnKeyboardMappingChanged(); | 159 void OnKeyboardMappingChanged(); |
160 | 160 |
161 // The system windowing system has sent a request that we close our window. | 161 // The system windowing system has sent a request that we close our window. |
162 void OnWindowTreeHostCloseRequested(); | 162 void OnRootWindowHostCloseRequested(); |
163 | 163 |
164 // Add/remove observer. There is no need to remove the observer if | 164 // Add/remove observer. There is no need to remove the observer if |
165 // the root window is being deleted. In particular, you SHOULD NOT remove | 165 // the root window is being deleted. In particular, you SHOULD NOT remove |
166 // in |WindowObserver::OnWindowDestroying| of the observer observing | 166 // in |WindowObserver::OnWindowDestroying| of the observer observing |
167 // the root window because it is too late to remove it. | 167 // the root window because it is too late to remove it. |
168 void AddRootWindowObserver(RootWindowObserver* observer); | 168 void AddRootWindowObserver(RootWindowObserver* observer); |
169 void RemoveRootWindowObserver(RootWindowObserver* observer); | 169 void RemoveRootWindowObserver(RootWindowObserver* observer); |
170 | 170 |
171 // Gesture Recognition ------------------------------------------------------- | 171 // Gesture Recognition ------------------------------------------------------- |
172 | 172 |
(...skipping 28 matching lines...) Expand all Loading... |
201 | 201 |
202 // The parameter for OnWindowHidden() to specify why window is hidden. | 202 // The parameter for OnWindowHidden() to specify why window is hidden. |
203 enum WindowHiddenReason { | 203 enum WindowHiddenReason { |
204 WINDOW_DESTROYED, // Window is destroyed. | 204 WINDOW_DESTROYED, // Window is destroyed. |
205 WINDOW_HIDDEN, // Window is hidden. | 205 WINDOW_HIDDEN, // Window is hidden. |
206 WINDOW_MOVING, // Window is temporarily marked as hidden due to move | 206 WINDOW_MOVING, // Window is temporarily marked as hidden due to move |
207 // across root windows. | 207 // across root windows. |
208 }; | 208 }; |
209 | 209 |
210 // Updates the event with the appropriate transform for the device scale | 210 // Updates the event with the appropriate transform for the device scale |
211 // factor. The WindowTreeHostDelegate dispatches events in the physical pixel | 211 // factor. The RootWindowHostDelegate dispatches events in the physical pixel |
212 // coordinate. But the event processing from RootWindow onwards happen in | 212 // coordinate. But the event processing from RootWindow onwards happen in |
213 // device-independent pixel coordinate. So it is necessary to update the event | 213 // device-independent pixel coordinate. So it is necessary to update the event |
214 // received from the host. | 214 // received from the host. |
215 void TransformEventForDeviceScaleFactor(ui::LocatedEvent* event); | 215 void TransformEventForDeviceScaleFactor(ui::LocatedEvent* event); |
216 | 216 |
217 // Moves the cursor to the specified location. This method is internally used | 217 // Moves the cursor to the specified location. This method is internally used |
218 // by MoveCursorTo() and MoveCursorToHostLocation(). | 218 // by MoveCursorTo() and MoveCursorToHostLocation(). |
219 void MoveCursorToInternal(const gfx::Point& root_location, | 219 void MoveCursorToInternal(const gfx::Point& root_location, |
220 const gfx::Point& host_location); | 220 const gfx::Point& host_location); |
221 | 221 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 virtual void DispatchCancelTouchEvent(ui::TouchEvent* event) OVERRIDE; | 257 virtual void DispatchCancelTouchEvent(ui::TouchEvent* event) OVERRIDE; |
258 | 258 |
259 // Overridden from ui::LayerAnimationObserver: | 259 // Overridden from ui::LayerAnimationObserver: |
260 virtual void OnLayerAnimationEnded( | 260 virtual void OnLayerAnimationEnded( |
261 ui::LayerAnimationSequence* animation) OVERRIDE; | 261 ui::LayerAnimationSequence* animation) OVERRIDE; |
262 virtual void OnLayerAnimationScheduled( | 262 virtual void OnLayerAnimationScheduled( |
263 ui::LayerAnimationSequence* animation) OVERRIDE; | 263 ui::LayerAnimationSequence* animation) OVERRIDE; |
264 virtual void OnLayerAnimationAborted( | 264 virtual void OnLayerAnimationAborted( |
265 ui::LayerAnimationSequence* animation) OVERRIDE; | 265 ui::LayerAnimationSequence* animation) OVERRIDE; |
266 | 266 |
267 // Overridden from aura::WindowTreeHostDelegate: | 267 // Overridden from aura::RootWindowHostDelegate: |
268 virtual bool OnHostKeyEvent(ui::KeyEvent* event) OVERRIDE; | 268 virtual bool OnHostKeyEvent(ui::KeyEvent* event) OVERRIDE; |
269 virtual bool OnHostMouseEvent(ui::MouseEvent* event) OVERRIDE; | 269 virtual bool OnHostMouseEvent(ui::MouseEvent* event) OVERRIDE; |
270 virtual bool OnHostScrollEvent(ui::ScrollEvent* event) OVERRIDE; | 270 virtual bool OnHostScrollEvent(ui::ScrollEvent* event) OVERRIDE; |
271 virtual bool OnHostTouchEvent(ui::TouchEvent* event) OVERRIDE; | 271 virtual bool OnHostTouchEvent(ui::TouchEvent* event) OVERRIDE; |
272 virtual void OnHostCancelMode() OVERRIDE; | 272 virtual void OnHostCancelMode() OVERRIDE; |
273 virtual void OnHostActivated() OVERRIDE; | 273 virtual void OnHostActivated() OVERRIDE; |
274 virtual void OnHostLostWindowCapture() OVERRIDE; | 274 virtual void OnHostLostWindowCapture() OVERRIDE; |
275 virtual void OnHostLostMouseGrab() OVERRIDE; | 275 virtual void OnHostLostMouseGrab() OVERRIDE; |
276 virtual void OnHostMoved(const gfx::Point& origin) OVERRIDE; | 276 virtual void OnHostMoved(const gfx::Point& origin) OVERRIDE; |
277 virtual void OnHostResized(const gfx::Size& size) OVERRIDE; | 277 virtual void OnHostResized(const gfx::Size& size) OVERRIDE; |
278 virtual RootWindow* AsRootWindow() OVERRIDE; | 278 virtual RootWindow* AsRootWindow() OVERRIDE; |
279 virtual const RootWindow* AsRootWindow() const OVERRIDE; | 279 virtual const RootWindow* AsRootWindow() const OVERRIDE; |
280 | 280 |
281 ui::EventDispatchDetails OnHostMouseEventImpl(ui::MouseEvent* event) | 281 ui::EventDispatchDetails OnHostMouseEventImpl(ui::MouseEvent* event) |
282 WARN_UNUSED_RESULT; | 282 WARN_UNUSED_RESULT; |
283 | 283 |
284 // We hold and aggregate mouse drags and touch moves as a way of throttling | 284 // We hold and aggregate mouse drags and touch moves as a way of throttling |
285 // resizes when HoldMouseMoves() is called. The following methods are used to | 285 // resizes when HoldMouseMoves() is called. The following methods are used to |
286 // dispatch held and newly incoming mouse and touch events, typically when an | 286 // dispatch held and newly incoming mouse and touch events, typically when an |
287 // event other than one of these needs dispatching or a matching | 287 // event other than one of these needs dispatching or a matching |
288 // ReleaseMouseMoves()/ReleaseTouchMoves() is called. NOTE: because these | 288 // ReleaseMouseMoves()/ReleaseTouchMoves() is called. NOTE: because these |
289 // methods dispatch events from WindowTreeHost the coordinates are in terms of | 289 // methods dispatch events from RootWindowHost the coordinates are in terms of |
290 // the root. | 290 // the root. |
291 ui::EventDispatchDetails DispatchMouseEventImpl(ui::MouseEvent* event) | 291 ui::EventDispatchDetails DispatchMouseEventImpl(ui::MouseEvent* event) |
292 WARN_UNUSED_RESULT; | 292 WARN_UNUSED_RESULT; |
293 ui::EventDispatchDetails DispatchMouseEventRepost(ui::MouseEvent* event) | 293 ui::EventDispatchDetails DispatchMouseEventRepost(ui::MouseEvent* event) |
294 WARN_UNUSED_RESULT; | 294 WARN_UNUSED_RESULT; |
295 ui::EventDispatchDetails DispatchMouseEventToTarget(ui::MouseEvent* event, | 295 ui::EventDispatchDetails DispatchMouseEventToTarget(ui::MouseEvent* event, |
296 Window* target) | 296 Window* target) |
297 WARN_UNUSED_RESULT; | 297 WARN_UNUSED_RESULT; |
298 ui::EventDispatchDetails DispatchTouchEventImpl(ui::TouchEvent* event) | 298 ui::EventDispatchDetails DispatchTouchEventImpl(ui::TouchEvent* event) |
299 WARN_UNUSED_RESULT; | 299 WARN_UNUSED_RESULT; |
300 ui::EventDispatchDetails DispatchHeldEvents() WARN_UNUSED_RESULT; | 300 ui::EventDispatchDetails DispatchHeldEvents() WARN_UNUSED_RESULT; |
301 // Creates and dispatches synthesized mouse move event using the | 301 // Creates and dispatches synthesized mouse move event using the |
302 // current mouse location. | 302 // current mouse location. |
303 ui::EventDispatchDetails SynthesizeMouseMoveEvent() WARN_UNUSED_RESULT; | 303 ui::EventDispatchDetails SynthesizeMouseMoveEvent() WARN_UNUSED_RESULT; |
304 | 304 |
305 void DispatchHeldEventsAsync(); | 305 void DispatchHeldEventsAsync(); |
306 void SynthesizeMouseMoveEventAsync(); | 306 void SynthesizeMouseMoveEventAsync(); |
307 | 307 |
308 // Posts a task to send synthesized mouse move event if there | 308 // Posts a task to send synthesized mouse move event if there |
309 // is no a pending task. | 309 // is no a pending task. |
310 void PostMouseMoveEventAfterWindowChange(); | 310 void PostMouseMoveEventAfterWindowChange(); |
311 | 311 |
312 // TODO(beng): evaluate the ideal ownership model. | 312 // TODO(beng): evaluate the ideal ownership model. |
313 scoped_ptr<Window> window_; | 313 scoped_ptr<Window> window_; |
314 | 314 |
315 scoped_ptr<WindowTreeHost> host_; | 315 scoped_ptr<RootWindowHost> host_; |
316 | 316 |
317 // Touch ids that are currently down. | 317 // Touch ids that are currently down. |
318 uint32 touch_ids_down_; | 318 uint32 touch_ids_down_; |
319 | 319 |
320 // Last cursor set. Used for testing. | 320 // Last cursor set. Used for testing. |
321 gfx::NativeCursor last_cursor_; | 321 gfx::NativeCursor last_cursor_; |
322 | 322 |
323 ObserverList<RootWindowObserver> observers_; | 323 ObserverList<RootWindowObserver> observers_; |
324 | 324 |
325 Window* mouse_pressed_handler_; | 325 Window* mouse_pressed_handler_; |
(...skipping 17 matching lines...) Expand all Loading... |
343 | 343 |
344 // Used to schedule DispatchHeldEvents() when |move_hold_count_| goes to 0. | 344 // Used to schedule DispatchHeldEvents() when |move_hold_count_| goes to 0. |
345 base::WeakPtrFactory<RootWindow> held_event_factory_; | 345 base::WeakPtrFactory<RootWindow> held_event_factory_; |
346 | 346 |
347 DISALLOW_COPY_AND_ASSIGN(RootWindow); | 347 DISALLOW_COPY_AND_ASSIGN(RootWindow); |
348 }; | 348 }; |
349 | 349 |
350 } // namespace aura | 350 } // namespace aura |
351 | 351 |
352 #endif // UI_AURA_ROOT_WINDOW_H_ | 352 #endif // UI_AURA_ROOT_WINDOW_H_ |
OLD | NEW |