Chromium Code Reviews| 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 ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_WIDGET_CONTROLLER_H_ | 5 #ifndef ASH_WALLPAPER_WALLPAPER_WIDGET_CONTROLLER_H_ |
| 6 #define ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_WIDGET_CONTROLLER_H_ | 6 #define ASH_WALLPAPER_WALLPAPER_WIDGET_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "ash/ash_export.h" | 10 #include "ash/ash_export.h" |
| 11 #include "ash/common/wm_window_observer.h" | 11 #include "ash/common/wm_window_observer.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "ui/views/widget/widget_observer.h" | 13 #include "ui/views/widget/widget_observer.h" |
| 14 | 14 |
| 15 namespace aura { | 15 namespace aura { |
| 16 class Window; | 16 class Window; |
| 17 } | 17 } |
| 18 | 18 |
| 19 namespace ash { | 19 namespace ash { |
| 20 class RootWindowController; | 20 class RootWindowController; |
| 21 | 21 |
| 22 // This class implements a widget-based wallpaper. | 22 // This class implements a widget-based wallpaper. |
| 23 // DesktopBackgroundWidgetController is owned by RootWindowController. | 23 // WallpaperWidgetController is owned by RootWindowController. |
| 24 // When the animation completes the old DesktopBackgroundWidgetController is | 24 // When the animation completes the old WallpaperWidgetController is |
| 25 // destroyed. Exported for tests. | 25 // destroyed. Exported for tests. |
| 26 class ASH_EXPORT DesktopBackgroundWidgetController | 26 class ASH_EXPORT WallpaperWidgetController : public views::WidgetObserver, |
| 27 : public views::WidgetObserver, | 27 public WmWindowObserver { |
| 28 public WmWindowObserver { | |
| 29 public: | 28 public: |
| 30 // Create | 29 // Create |
|
James Cook
2016/08/30 05:18:20
nit: remove this
msw
2016/08/30 16:07:59
Done.
| |
| 31 explicit DesktopBackgroundWidgetController(views::Widget* widget); | 30 explicit WallpaperWidgetController(views::Widget* widget); |
| 32 | 31 |
| 33 ~DesktopBackgroundWidgetController() override; | 32 ~WallpaperWidgetController() override; |
| 34 | 33 |
| 35 // Overridden from views::WidgetObserver. | 34 // Overridden from views::WidgetObserver. |
| 36 void OnWidgetDestroying(views::Widget* widget) override; | 35 void OnWidgetDestroying(views::Widget* widget) override; |
| 37 | 36 |
| 38 // Set bounds of component that draws background. | 37 // Set bounds for the widget that draws the wallpaper. |
| 39 void SetBounds(const gfx::Rect& bounds); | 38 void SetBounds(const gfx::Rect& bounds); |
| 40 | 39 |
| 41 // Move component from |src_container| in |root_window| to |dest_container|. | 40 // Move the wallpaper for |root_window| to the specified |container|. |
| 42 // It is required for lock screen, when we need to move background so that | 41 // The lock screen moves the wallpaper container to hides the user's windows. |
| 43 // it hides user's windows. Returns true if there was something to reparent. | 42 // Returns true if there was something to reparent. |
| 44 bool Reparent(aura::Window* root_window, | 43 bool Reparent(aura::Window* root_window, int container); |
| 45 int src_container, | |
| 46 int dest_container); | |
| 47 | 44 |
| 48 // Starts wallpaper fade in animation. |root_window_controller| is | 45 // Starts wallpaper fade in animation. |root_window_controller| is |
| 49 // the root window where the animation will happen. (This is | 46 // the root window where the animation will happen. (This is |
| 50 // necessary this as |layer_| doesn't have access to the root window). | 47 // necessary this as |layer_| doesn't have access to the root window). |
| 51 void StartAnimating(RootWindowController* root_window_controller); | 48 void StartAnimating(RootWindowController* root_window_controller); |
| 52 | 49 |
| 53 views::Widget* widget() { return widget_; } | 50 views::Widget* widget() { return widget_; } |
| 54 | 51 |
| 55 private: | 52 private: |
| 56 void RemoveObservers(); | 53 void RemoveObservers(); |
| 57 | 54 |
| 58 // WmWindowObserver: | 55 // WmWindowObserver: |
| 59 void OnWindowBoundsChanged(WmWindow* window, | 56 void OnWindowBoundsChanged(WmWindow* window, |
| 60 const gfx::Rect& old_bounds, | 57 const gfx::Rect& old_bounds, |
| 61 const gfx::Rect& new_bounds) override; | 58 const gfx::Rect& new_bounds) override; |
| 62 | 59 |
| 63 views::Widget* widget_; | 60 views::Widget* widget_; |
| 64 | 61 |
| 65 // Parent of |widget_|. | 62 // Parent of |widget_|. |
| 66 WmWindow* widget_parent_; | 63 WmWindow* widget_parent_; |
| 67 | 64 |
| 68 DISALLOW_COPY_AND_ASSIGN(DesktopBackgroundWidgetController); | 65 DISALLOW_COPY_AND_ASSIGN(WallpaperWidgetController); |
| 69 }; | 66 }; |
| 70 | 67 |
| 71 // This class wraps a DesktopBackgroundWidgetController pointer. It is owned | 68 // This class wraps a WallpaperWidgetController pointer. It is owned |
| 72 // by RootWindowController. The instance of DesktopBackgroundWidgetController is | 69 // by RootWindowController. The instance of WallpaperWidgetController is |
| 73 // moved to this RootWindowController when the animation completes. | 70 // moved to this RootWindowController when the animation completes. |
| 74 // Exported for tests. | 71 // Exported for tests. |
| 75 class ASH_EXPORT AnimatingDesktopController { | 72 class ASH_EXPORT AnimatingDesktopController { |
| 76 public: | 73 public: |
| 77 explicit AnimatingDesktopController( | 74 explicit AnimatingDesktopController(WallpaperWidgetController* component); |
| 78 DesktopBackgroundWidgetController* component); | |
| 79 ~AnimatingDesktopController(); | 75 ~AnimatingDesktopController(); |
| 80 | 76 |
| 81 // Stops animation and makes sure OnImplicitAnimationsCompleted() is called if | 77 // Stops animation and makes sure OnImplicitAnimationsCompleted() is called if |
| 82 // current animation is not finished yet. | 78 // current animation is not finished yet. |
| 83 // Note we have to make sure this function is called before we set | 79 // Note we have to make sure this function is called before we set |
| 84 // kAnimatingDesktopController to a new controller. If it is not called, the | 80 // kAnimatingDesktopController to a new controller. If it is not called, the |
| 85 // animating widget/layer is closed immediately and the new one is animating | 81 // animating widget/layer is closed immediately and the new one is animating |
| 86 // from the widget/layer before animation. For instance, if a user quickly | 82 // from the widget/layer before animation. For instance, if a user quickly |
| 87 // switches between red, green and blue wallpapers. The green wallpaper will | 83 // switches between red, green and blue wallpapers. The green wallpaper will |
| 88 // first fade in from red wallpaper. And in the middle of the animation, blue | 84 // first fade in from red wallpaper. And in the middle of the animation, blue |
| 89 // wallpaper also wants to fade in. If the green wallpaper animation does not | 85 // wallpaper also wants to fade in. If the green wallpaper animation does not |
| 90 // finish immediately, the green wallpaper widget will be removed and the red | 86 // finish immediately, the green wallpaper widget will be removed and the red |
| 91 // widget will show again. As a result, the blue wallpaper fades in from red | 87 // widget will show again. As a result, the blue wallpaper fades in from red |
| 92 // wallpaper. This is a bad user experience. See bug http://crbug.com/156542 | 88 // wallpaper. This is a bad user experience. See bug http://crbug.com/156542 |
| 93 // for more details. | 89 // for more details. |
| 94 void StopAnimating(); | 90 void StopAnimating(); |
| 95 | 91 |
| 96 // Gets the wrapped DesktopBackgroundWidgetController pointer. Caller should | 92 // Gets the wrapped WallpaperWidgetController pointer. Caller should |
| 97 // take ownership of the pointer if |pass_ownership| is true. | 93 // take ownership of the pointer if |pass_ownership| is true. |
| 98 DesktopBackgroundWidgetController* GetController(bool pass_ownership); | 94 WallpaperWidgetController* GetController(bool pass_ownership); |
| 99 | 95 |
| 100 private: | 96 private: |
| 101 std::unique_ptr<DesktopBackgroundWidgetController> controller_; | 97 std::unique_ptr<WallpaperWidgetController> controller_; |
| 102 | 98 |
| 103 DISALLOW_COPY_AND_ASSIGN(AnimatingDesktopController); | 99 DISALLOW_COPY_AND_ASSIGN(AnimatingDesktopController); |
| 104 }; | 100 }; |
| 105 | 101 |
| 106 } // namespace ash | 102 } // namespace ash |
| 107 | 103 |
| 108 #endif // ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_WIDGET_CONTROLLER_H_ | 104 #endif // ASH_WALLPAPER_WALLPAPER_WIDGET_CONTROLLER_H_ |
| OLD | NEW |