OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_WIDGET_CONTROLLER_H_ | |
6 #define ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_WIDGET_CONTROLLER_H_ | |
7 | |
8 #include <memory> | |
9 | |
10 #include "ash/ash_export.h" | |
11 #include "ash/common/wm_window_observer.h" | |
12 #include "base/macros.h" | |
13 #include "ui/views/widget/widget_observer.h" | |
14 | |
15 namespace aura { | |
16 class Window; | |
17 } | |
18 | |
19 namespace ash { | |
20 class RootWindowController; | |
21 | |
22 // This class implements a widget-based wallpaper. | |
23 // DesktopBackgroundWidgetController is owned by RootWindowController. | |
24 // When the animation completes the old DesktopBackgroundWidgetController is | |
25 // destroyed. Exported for tests. | |
26 class ASH_EXPORT DesktopBackgroundWidgetController | |
27 : public views::WidgetObserver, | |
28 public WmWindowObserver { | |
29 public: | |
30 // Create | |
31 explicit DesktopBackgroundWidgetController(views::Widget* widget); | |
32 | |
33 ~DesktopBackgroundWidgetController() override; | |
34 | |
35 // Overridden from views::WidgetObserver. | |
36 void OnWidgetDestroying(views::Widget* widget) override; | |
37 | |
38 // Set bounds of component that draws background. | |
39 void SetBounds(const gfx::Rect& bounds); | |
40 | |
41 // Move component from |src_container| in |root_window| to |dest_container|. | |
42 // It is required for lock screen, when we need to move background so that | |
43 // it hides user's windows. Returns true if there was something to reparent. | |
44 bool Reparent(aura::Window* root_window, | |
45 int src_container, | |
46 int dest_container); | |
47 | |
48 // Starts wallpaper fade in animation. |root_window_controller| is | |
49 // the root window where the animation will happen. (This is | |
50 // necessary this as |layer_| doesn't have access to the root window). | |
51 void StartAnimating(RootWindowController* root_window_controller); | |
52 | |
53 views::Widget* widget() { return widget_; } | |
54 | |
55 private: | |
56 void RemoveObservers(); | |
57 | |
58 // WmWindowObserver: | |
59 void OnWindowBoundsChanged(WmWindow* window, | |
60 const gfx::Rect& old_bounds, | |
61 const gfx::Rect& new_bounds) override; | |
62 | |
63 views::Widget* widget_; | |
64 | |
65 // Parent of |widget_|. | |
66 WmWindow* widget_parent_; | |
67 | |
68 DISALLOW_COPY_AND_ASSIGN(DesktopBackgroundWidgetController); | |
69 }; | |
70 | |
71 // This class wraps a DesktopBackgroundWidgetController pointer. It is owned | |
72 // by RootWindowController. The instance of DesktopBackgroundWidgetController is | |
73 // moved to this RootWindowController when the animation completes. | |
74 // Exported for tests. | |
75 class ASH_EXPORT AnimatingDesktopController { | |
76 public: | |
77 explicit AnimatingDesktopController( | |
78 DesktopBackgroundWidgetController* component); | |
79 ~AnimatingDesktopController(); | |
80 | |
81 // Stops animation and makes sure OnImplicitAnimationsCompleted() is called if | |
82 // current animation is not finished yet. | |
83 // 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 | |
85 // 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 | |
87 // 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 | |
89 // 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 | |
91 // 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 | |
93 // for more details. | |
94 void StopAnimating(); | |
95 | |
96 // Gets the wrapped DesktopBackgroundWidgetController pointer. Caller should | |
97 // take ownership of the pointer if |pass_ownership| is true. | |
98 DesktopBackgroundWidgetController* GetController(bool pass_ownership); | |
99 | |
100 private: | |
101 std::unique_ptr<DesktopBackgroundWidgetController> controller_; | |
102 | |
103 DISALLOW_COPY_AND_ASSIGN(AnimatingDesktopController); | |
104 }; | |
105 | |
106 } // namespace ash | |
107 | |
108 #endif // ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_WIDGET_CONTROLLER_H_ | |
OLD | NEW |