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