| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 12 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 13 #include "ui/aura/aura_export.h" | 14 #include "ui/aura/aura_export.h" |
| 14 #include "ui/aura/cursor.h" | 15 #include "ui/aura/cursor.h" |
| 15 #include "ui/aura/focus_manager.h" | 16 #include "ui/aura/focus_manager.h" |
| 16 #include "ui/aura/gestures/gesture_recognizer.h" | 17 #include "ui/aura/gestures/gesture_recognizer.h" |
| 17 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
| 18 #include "ui/base/events.h" | 19 #include "ui/base/events.h" |
| 19 #include "ui/gfx/compositor/compositor.h" | 20 #include "ui/gfx/compositor/compositor.h" |
| 20 #include "ui/gfx/compositor/compositor_observer.h" | 21 #include "ui/gfx/compositor/compositor_observer.h" |
| 21 #include "ui/gfx/compositor/layer_animation_observer.h" | 22 #include "ui/gfx/compositor/layer_animation_observer.h" |
| 22 #include "ui/gfx/native_widget_types.h" | 23 #include "ui/gfx/native_widget_types.h" |
| 23 #include "ui/gfx/point.h" | 24 #include "ui/gfx/point.h" |
| 24 | 25 |
| 25 namespace gfx { | 26 namespace gfx { |
| 26 class Size; | 27 class Size; |
| 27 } | 28 } |
| 28 | 29 |
| 29 namespace ui { | 30 namespace ui { |
| 30 class LayerAnimationSequence; | 31 class LayerAnimationSequence; |
| 31 class Transform; | 32 class Transform; |
| 32 } | 33 } |
| 33 | 34 |
| 34 namespace aura { | 35 namespace aura { |
| 35 | 36 |
| 37 class RootWindow; |
| 36 class RootWindowHost; | 38 class RootWindowHost; |
| 37 class RootWindowObserver; | 39 class RootWindowObserver; |
| 38 class KeyEvent; | 40 class KeyEvent; |
| 39 class MouseEvent; | 41 class MouseEvent; |
| 40 class StackingClient; | 42 class StackingClient; |
| 41 class ScrollEvent; | 43 class ScrollEvent; |
| 42 class TouchEvent; | 44 class TouchEvent; |
| 43 class GestureEvent; | 45 class GestureEvent; |
| 44 | 46 |
| 47 // This class represents a lock on the compositor, that can be used to prevent a |
| 48 // compositing pass from happening while we're waiting for an asynchronous |
| 49 // event. The typical use case is when waiting for a renderer to produce a frame |
| 50 // at the right size. The caller keeps a reference on this object, and drops the |
| 51 // reference once it desires to release the lock. |
| 52 // Note however that the lock is canceled after a short timeout to ensure |
| 53 // responsiveness of the UI, so the compositor tree should be kept in a |
| 54 // "reasonable" state while the lock is held. |
| 55 // Don't instantiate this class directly, use RootWindow::GetCompositorLock. |
| 56 class AURA_EXPORT CompositorLock : |
| 57 public base::RefCounted<CompositorLock>, |
| 58 public base::SupportsWeakPtr<CompositorLock> { |
| 59 public: |
| 60 ~CompositorLock(); |
| 61 |
| 62 private: |
| 63 friend class RootWindow; |
| 64 |
| 65 CompositorLock(RootWindow* root_window); |
| 66 void CancelLock(); |
| 67 |
| 68 RootWindow* root_window_; |
| 69 DISALLOW_COPY_AND_ASSIGN(CompositorLock); |
| 70 }; |
| 71 |
| 45 // RootWindow is responsible for hosting a set of windows. | 72 // RootWindow is responsible for hosting a set of windows. |
| 46 class AURA_EXPORT RootWindow : public ui::CompositorDelegate, | 73 class AURA_EXPORT RootWindow : public ui::CompositorDelegate, |
| 47 public ui::CompositorObserver, | 74 public ui::CompositorObserver, |
| 48 public Window, | 75 public Window, |
| 49 public internal::FocusManager, | 76 public internal::FocusManager, |
| 50 public ui::LayerAnimationObserver { | 77 public ui::LayerAnimationObserver { |
| 51 public: | 78 public: |
| 52 explicit RootWindow(const gfx::Rect& initial_bounds); | 79 explicit RootWindow(const gfx::Rect& initial_bounds); |
| 53 virtual ~RootWindow(); | 80 virtual ~RootWindow(); |
| 54 | 81 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 // These methods are used to defer the processing of mouse events related | 209 // These methods are used to defer the processing of mouse events related |
| 183 // to resize. A client (typically a RenderWidgetHostViewAura) can call | 210 // to resize. A client (typically a RenderWidgetHostViewAura) can call |
| 184 // HoldMouseMoves when an resize is initiated and then ReleaseMouseMoves | 211 // HoldMouseMoves when an resize is initiated and then ReleaseMouseMoves |
| 185 // once the resize is completed. | 212 // once the resize is completed. |
| 186 // | 213 // |
| 187 // More than one hold can be invoked and each hold must be cancelled by a | 214 // More than one hold can be invoked and each hold must be cancelled by a |
| 188 // release before we resume normal operation. | 215 // release before we resume normal operation. |
| 189 void HoldMouseMoves(); | 216 void HoldMouseMoves(); |
| 190 void ReleaseMouseMoves(); | 217 void ReleaseMouseMoves(); |
| 191 | 218 |
| 219 // Creates a compositor lock. |
| 220 scoped_refptr<CompositorLock> GetCompositorLock(); |
| 221 |
| 192 // Sets if the window should be focused when shown. | 222 // Sets if the window should be focused when shown. |
| 193 void SetFocusWhenShown(bool focus_when_shown); | 223 void SetFocusWhenShown(bool focus_when_shown); |
| 194 | 224 |
| 195 // Overridden from Window: | 225 // Overridden from Window: |
| 196 virtual RootWindow* GetRootWindow() OVERRIDE; | 226 virtual RootWindow* GetRootWindow() OVERRIDE; |
| 197 virtual const RootWindow* GetRootWindow() const OVERRIDE; | 227 virtual const RootWindow* GetRootWindow() const OVERRIDE; |
| 198 virtual void SetTransform(const ui::Transform& transform) OVERRIDE; | 228 virtual void SetTransform(const ui::Transform& transform) OVERRIDE; |
| 199 | 229 |
| 200 // Overridden from ui::CompositorDelegate: | 230 // Overridden from ui::CompositorDelegate: |
| 201 virtual void ScheduleDraw() OVERRIDE; | 231 virtual void ScheduleDraw() OVERRIDE; |
| 202 | 232 |
| 203 // Overridden from ui::CompositorObserver: | 233 // Overridden from ui::CompositorObserver: |
| 204 virtual void OnCompositingStarted(ui::Compositor*) OVERRIDE; | 234 virtual void OnCompositingStarted(ui::Compositor*) OVERRIDE; |
| 205 virtual void OnCompositingEnded(ui::Compositor*) OVERRIDE; | 235 virtual void OnCompositingEnded(ui::Compositor*) OVERRIDE; |
| 206 | 236 |
| 207 private: | 237 private: |
| 208 friend class Window; | 238 friend class Window; |
| 239 friend class CompositorLock; |
| 209 | 240 |
| 210 // Called whenever the mouse moves, tracks the current |mouse_moved_handler_|, | 241 // Called whenever the mouse moves, tracks the current |mouse_moved_handler_|, |
| 211 // sending exited and entered events as its value changes. | 242 // sending exited and entered events as its value changes. |
| 212 void HandleMouseMoved(const MouseEvent& event, Window* target); | 243 void HandleMouseMoved(const MouseEvent& event, Window* target); |
| 213 | 244 |
| 214 // Called whenever the |capture_window_| changes. | 245 // Called whenever the |capture_window_| changes. |
| 215 // Sends capture changed events to event filters for old capture window. | 246 // Sends capture changed events to event filters for old capture window. |
| 216 void HandleMouseCaptureChanged(Window* old_capture_window); | 247 void HandleMouseCaptureChanged(Window* old_capture_window); |
| 217 | 248 |
| 218 bool ProcessMouseEvent(Window* target, MouseEvent* event); | 249 bool ProcessMouseEvent(Window* target, MouseEvent* event); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 gfx::Rect GetInitialHostWindowBounds() const; | 295 gfx::Rect GetInitialHostWindowBounds() const; |
| 265 | 296 |
| 266 // Posts a task to send synthesized mouse move event if there | 297 // Posts a task to send synthesized mouse move event if there |
| 267 // is no a pending task. | 298 // is no a pending task. |
| 268 void PostMouseMoveEventAfterWindowChange(); | 299 void PostMouseMoveEventAfterWindowChange(); |
| 269 | 300 |
| 270 // Creates and dispatches synthesized mouse move event using the | 301 // Creates and dispatches synthesized mouse move event using the |
| 271 // current mouse location. | 302 // current mouse location. |
| 272 void SynthesizeMouseMoveEvent(); | 303 void SynthesizeMouseMoveEvent(); |
| 273 | 304 |
| 305 // Called by CompositorLock. |
| 306 void UnlockCompositor(); |
| 307 |
| 274 scoped_ptr<ui::Compositor> compositor_; | 308 scoped_ptr<ui::Compositor> compositor_; |
| 275 | 309 |
| 276 scoped_ptr<RootWindowHost> host_; | 310 scoped_ptr<RootWindowHost> host_; |
| 277 | 311 |
| 278 // If set before the RootWindow is created, the cursor will be drawn within | 312 // If set before the RootWindow is created, the cursor will be drawn within |
| 279 // the Aura root window but hidden outside of it, and it'll remain hidden | 313 // the Aura root window but hidden outside of it, and it'll remain hidden |
| 280 // after the Aura window is closed. | 314 // after the Aura window is closed. |
| 281 static bool hide_host_cursor_; | 315 static bool hide_host_cursor_; |
| 282 | 316 |
| 283 // Used to schedule painting. | 317 // Used to schedule painting. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 bool draw_on_compositing_end_; | 350 bool draw_on_compositing_end_; |
| 317 | 351 |
| 318 bool defer_draw_scheduling_; | 352 bool defer_draw_scheduling_; |
| 319 | 353 |
| 320 // How many holds are outstanding. We try to defer dispatching mouse moves | 354 // How many holds are outstanding. We try to defer dispatching mouse moves |
| 321 // while the count is > 0. | 355 // while the count is > 0. |
| 322 int mouse_move_hold_count_; | 356 int mouse_move_hold_count_; |
| 323 bool should_hold_mouse_moves_; | 357 bool should_hold_mouse_moves_; |
| 324 scoped_ptr<MouseEvent> held_mouse_move_; | 358 scoped_ptr<MouseEvent> held_mouse_move_; |
| 325 | 359 |
| 360 CompositorLock* compositor_lock_; |
| 361 bool draw_on_compositor_unlock_; |
| 362 |
| 326 DISALLOW_COPY_AND_ASSIGN(RootWindow); | 363 DISALLOW_COPY_AND_ASSIGN(RootWindow); |
| 327 }; | 364 }; |
| 328 | 365 |
| 329 } // namespace aura | 366 } // namespace aura |
| 330 | 367 |
| 331 #endif // UI_AURA_ROOT_WINDOW_H_ | 368 #endif // UI_AURA_ROOT_WINDOW_H_ |
| OLD | NEW |