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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 class ViewProp; | 43 class ViewProp; |
44 } | 44 } |
45 | 45 |
46 namespace aura { | 46 namespace aura { |
47 | 47 |
48 class FocusManager; | 48 class FocusManager; |
49 class RootWindow; | 49 class RootWindow; |
50 class RootWindowHost; | 50 class RootWindowHost; |
51 class RootWindowObserver; | 51 class RootWindowObserver; |
52 | 52 |
53 // This class represents a lock on the compositor, that can be used to prevent a | |
54 // compositing pass from happening while we're waiting for an asynchronous | |
55 // event. The typical use case is when waiting for a renderer to produce a frame | |
56 // at the right size. The caller keeps a reference on this object, and drops the | |
57 // reference once it desires to release the lock. | |
58 // Note however that the lock is canceled after a short timeout to ensure | |
59 // responsiveness of the UI, so the compositor tree should be kept in a | |
60 // "reasonable" state while the lock is held. | |
61 // Don't instantiate this class directly, use RootWindow::GetCompositorLock. | |
62 class AURA_EXPORT CompositorLock | |
63 : public base::RefCounted<CompositorLock>, | |
64 public base::SupportsWeakPtr<CompositorLock> { | |
65 private: | |
66 friend class base::RefCounted<CompositorLock>; | |
67 friend class RootWindow; | |
68 | |
69 explicit CompositorLock(RootWindow* root_window); | |
70 ~CompositorLock(); | |
71 | |
72 void CancelLock(); | |
73 | |
74 RootWindow* root_window_; | |
75 DISALLOW_COPY_AND_ASSIGN(CompositorLock); | |
76 }; | |
77 | |
78 // RootWindow is responsible for hosting a set of windows. | 53 // RootWindow is responsible for hosting a set of windows. |
79 class AURA_EXPORT RootWindow : public ui::CompositorDelegate, | 54 class AURA_EXPORT RootWindow : public ui::CompositorDelegate, |
80 public ui::CompositorObserver, | 55 public ui::CompositorObserver, |
81 public Window, | 56 public Window, |
82 public ui::EventDispatcher, | 57 public ui::EventDispatcher, |
83 public ui::GestureEventHelper, | 58 public ui::GestureEventHelper, |
84 public ui::LayerAnimationObserver, | 59 public ui::LayerAnimationObserver, |
85 public aura::client::CaptureDelegate, | 60 public aura::client::CaptureDelegate, |
86 public aura::RootWindowHostDelegate { | 61 public aura::RootWindowHostDelegate { |
87 public: | 62 public: |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 // These methods are used to defer the processing of mouse events related | 202 // These methods are used to defer the processing of mouse events related |
228 // to resize. A client (typically a RenderWidgetHostViewAura) can call | 203 // to resize. A client (typically a RenderWidgetHostViewAura) can call |
229 // HoldMouseMoves when an resize is initiated and then ReleaseMouseMoves | 204 // HoldMouseMoves when an resize is initiated and then ReleaseMouseMoves |
230 // once the resize is completed. | 205 // once the resize is completed. |
231 // | 206 // |
232 // More than one hold can be invoked and each hold must be cancelled by a | 207 // More than one hold can be invoked and each hold must be cancelled by a |
233 // release before we resume normal operation. | 208 // release before we resume normal operation. |
234 void HoldMouseMoves(); | 209 void HoldMouseMoves(); |
235 void ReleaseMouseMoves(); | 210 void ReleaseMouseMoves(); |
236 | 211 |
237 // Creates a compositor lock. | |
238 scoped_refptr<CompositorLock> GetCompositorLock(); | |
239 | |
240 // Sets if the window should be focused when shown. | 212 // Sets if the window should be focused when shown. |
241 void SetFocusWhenShown(bool focus_when_shown); | 213 void SetFocusWhenShown(bool focus_when_shown); |
242 | 214 |
243 // Grabs the snapshot of the root window by using the platform-dependent APIs. | 215 // Grabs the snapshot of the root window by using the platform-dependent APIs. |
244 bool GrabSnapshot(const gfx::Rect& snapshot_bounds, | 216 bool GrabSnapshot(const gfx::Rect& snapshot_bounds, |
245 std::vector<unsigned char>* png_representation); | 217 std::vector<unsigned char>* png_representation); |
246 | 218 |
247 // Gets the last location seen in a mouse event in this root window's | 219 // Gets the last location seen in a mouse event in this root window's |
248 // coordinates. This may return a point outside the root window's bounds. | 220 // coordinates. This may return a point outside the root window's bounds. |
249 gfx::Point GetLastMouseLocationInRoot() const; | 221 gfx::Point GetLastMouseLocationInRoot() const; |
250 | 222 |
251 // Overridden from Window: | 223 // Overridden from Window: |
252 virtual RootWindow* GetRootWindow() OVERRIDE; | 224 virtual RootWindow* GetRootWindow() OVERRIDE; |
253 virtual const RootWindow* GetRootWindow() const OVERRIDE; | 225 virtual const RootWindow* GetRootWindow() const OVERRIDE; |
254 virtual void SetTransform(const gfx::Transform& transform) OVERRIDE; | 226 virtual void SetTransform(const gfx::Transform& transform) OVERRIDE; |
255 | 227 |
256 // Overridden from ui::EventTarget: | 228 // Overridden from ui::EventTarget: |
257 virtual ui::EventTarget* GetParentTarget() OVERRIDE; | 229 virtual ui::EventTarget* GetParentTarget() OVERRIDE; |
258 | 230 |
259 // Overridden from ui::CompositorDelegate: | 231 // Overridden from ui::CompositorDelegate: |
260 virtual void ScheduleDraw() OVERRIDE; | 232 virtual void ScheduleDraw() OVERRIDE; |
261 | 233 |
262 // Overridden from ui::CompositorObserver: | 234 // Overridden from ui::CompositorObserver: |
263 virtual void OnCompositingDidCommit(ui::Compositor*) OVERRIDE; | 235 virtual void OnCompositingDidCommit(ui::Compositor*) OVERRIDE; |
264 virtual void OnCompositingWillStart(ui::Compositor*) OVERRIDE; | |
265 virtual void OnCompositingStarted(ui::Compositor*) OVERRIDE; | 236 virtual void OnCompositingStarted(ui::Compositor*) OVERRIDE; |
266 virtual void OnCompositingEnded(ui::Compositor*) OVERRIDE; | 237 virtual void OnCompositingEnded(ui::Compositor*) OVERRIDE; |
267 virtual void OnCompositingAborted(ui::Compositor*) OVERRIDE; | 238 virtual void OnCompositingAborted(ui::Compositor*) OVERRIDE; |
| 239 virtual void OnCompositingLockStateChanged(ui::Compositor*) OVERRIDE; |
268 | 240 |
269 // Overridden from ui::LayerDelegate: | 241 // Overridden from ui::LayerDelegate: |
270 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE; | 242 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE; |
271 | 243 |
272 // Overridden from Window: | 244 // Overridden from Window: |
273 virtual bool CanFocus() const OVERRIDE; | 245 virtual bool CanFocus() const OVERRIDE; |
274 virtual bool CanReceiveEvents() const OVERRIDE; | 246 virtual bool CanReceiveEvents() const OVERRIDE; |
275 virtual FocusManager* GetFocusManager() OVERRIDE; | 247 virtual FocusManager* GetFocusManager() OVERRIDE; |
276 | 248 |
277 // Overridden from aura::client::CaptureDelegate: | 249 // Overridden from aura::client::CaptureDelegate: |
278 virtual void UpdateCapture(Window* old_capture, Window* new_capture) OVERRIDE; | 250 virtual void UpdateCapture(Window* old_capture, Window* new_capture) OVERRIDE; |
279 virtual void SetNativeCapture() OVERRIDE; | 251 virtual void SetNativeCapture() OVERRIDE; |
280 virtual void ReleaseNativeCapture() OVERRIDE; | 252 virtual void ReleaseNativeCapture() OVERRIDE; |
281 | 253 |
282 // Exposes RootWindowHost::QueryMouseLocation() for test purposes. | 254 // Exposes RootWindowHost::QueryMouseLocation() for test purposes. |
283 gfx::Point QueryMouseLocationForTest() const; | 255 gfx::Point QueryMouseLocationForTest() const; |
284 | 256 |
285 private: | 257 private: |
286 friend class Window; | 258 friend class Window; |
287 friend class CompositorLock; | |
288 | 259 |
289 // Called whenever the mouse moves, tracks the current |mouse_moved_handler_|, | 260 // Called whenever the mouse moves, tracks the current |mouse_moved_handler_|, |
290 // sending exited and entered events as its value changes. | 261 // sending exited and entered events as its value changes. |
291 void HandleMouseMoved(const ui::MouseEvent& event, Window* target); | 262 void HandleMouseMoved(const ui::MouseEvent& event, Window* target); |
292 | 263 |
293 bool ProcessMouseEvent(Window* target, ui::MouseEvent* event); | 264 bool ProcessMouseEvent(Window* target, ui::MouseEvent* event); |
294 bool ProcessKeyEvent(Window* target, ui::KeyEvent* event); | 265 bool ProcessKeyEvent(Window* target, ui::KeyEvent* event); |
295 ui::EventResult ProcessTouchEvent(Window* target, ui::TouchEvent* event); | 266 ui::EventResult ProcessTouchEvent(Window* target, ui::TouchEvent* event); |
296 ui::EventResult ProcessGestureEvent(Window* target, | 267 ui::EventResult ProcessGestureEvent(Window* target, |
297 ui::GestureEvent* event); | 268 ui::GestureEvent* event); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 gfx::Rect GetInitialHostWindowBounds() const; | 323 gfx::Rect GetInitialHostWindowBounds() const; |
353 | 324 |
354 // Posts a task to send synthesized mouse move event if there | 325 // Posts a task to send synthesized mouse move event if there |
355 // is no a pending task. | 326 // is no a pending task. |
356 void PostMouseMoveEventAfterWindowChange(); | 327 void PostMouseMoveEventAfterWindowChange(); |
357 | 328 |
358 // Creates and dispatches synthesized mouse move event using the | 329 // Creates and dispatches synthesized mouse move event using the |
359 // current mouse location. | 330 // current mouse location. |
360 void SynthesizeMouseMoveEvent(); | 331 void SynthesizeMouseMoveEvent(); |
361 | 332 |
362 // Called by CompositorLock. | |
363 void UnlockCompositor(); | |
364 | |
365 scoped_ptr<ui::Compositor> compositor_; | 333 scoped_ptr<ui::Compositor> compositor_; |
366 | 334 |
367 scoped_ptr<RootWindowHost> host_; | 335 scoped_ptr<RootWindowHost> host_; |
368 | 336 |
369 // Used to schedule painting. | 337 // Used to schedule painting. |
370 base::WeakPtrFactory<RootWindow> schedule_paint_factory_; | 338 base::WeakPtrFactory<RootWindow> schedule_paint_factory_; |
371 | 339 |
372 // Use to post mouse move event. | 340 // Use to post mouse move event. |
373 base::WeakPtrFactory<RootWindow> event_factory_; | 341 base::WeakPtrFactory<RootWindow> event_factory_; |
374 | 342 |
(...skipping 26 matching lines...) Expand all Loading... |
401 // How many holds are outstanding. We try to defer dispatching mouse moves | 369 // How many holds are outstanding. We try to defer dispatching mouse moves |
402 // while the count is > 0. | 370 // while the count is > 0. |
403 int mouse_move_hold_count_; | 371 int mouse_move_hold_count_; |
404 scoped_ptr<ui::MouseEvent> held_mouse_move_; | 372 scoped_ptr<ui::MouseEvent> held_mouse_move_; |
405 // Used to schedule DispatchHeldMouseMove() when |mouse_move_hold_count_| goes | 373 // Used to schedule DispatchHeldMouseMove() when |mouse_move_hold_count_| goes |
406 // to 0. | 374 // to 0. |
407 base::WeakPtrFactory<RootWindow> held_mouse_event_factory_; | 375 base::WeakPtrFactory<RootWindow> held_mouse_event_factory_; |
408 | 376 |
409 scoped_ptr<ui::ViewProp> prop_; | 377 scoped_ptr<ui::ViewProp> prop_; |
410 | 378 |
411 CompositorLock* compositor_lock_; | |
412 bool draw_on_compositor_unlock_; | |
413 | |
414 DISALLOW_COPY_AND_ASSIGN(RootWindow); | 379 DISALLOW_COPY_AND_ASSIGN(RootWindow); |
415 }; | 380 }; |
416 | 381 |
417 } // namespace aura | 382 } // namespace aura |
418 | 383 |
419 #endif // UI_AURA_ROOT_WINDOW_H_ | 384 #endif // UI_AURA_ROOT_WINDOW_H_ |
OLD | NEW |