Roll leveldb from r73 to r75.
[chromium-blink-merge.git] / ash / desktop_background / desktop_background_widget_controller.h
blobbf94619631050a6de04c145c010d8a625b17d30c
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.
5 #ifndef ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_WIDGET_CONTROLLER_H_
6 #define ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_WIDGET_CONTROLLER_H_
8 #include "ash/ash_export.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "ui/aura/window.h"
11 #include "ui/compositor/layer.h"
12 #include "ui/views/widget/widget.h"
13 #include "ui/views/widget/widget_observer.h"
15 namespace ash {
16 namespace internal {
18 // This class hides difference between two possible background implementations:
19 // effective Layer-based for solid color, and Widget-based for images.
20 // DesktopBackgroundWidgetController is installed as an owned property on the
21 // RootWindow. To avoid a white flash during wallpaper changes the old
22 // DesktopBackgroundWidgetController is moved to a secondary property
23 // (kComponentWrapper). When the animation completes the old
24 // DesktopBackgroundWidgetController is destroyed. Exported for tests.
25 class ASH_EXPORT DesktopBackgroundWidgetController
26 : public views::WidgetObserver {
27 public:
28 // Create
29 explicit DesktopBackgroundWidgetController(views::Widget* widget);
30 explicit DesktopBackgroundWidgetController(ui::Layer* layer);
32 virtual ~DesktopBackgroundWidgetController();
34 // Overridden from views::WidgetObserver.
35 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE;
37 // Set bounds of component that draws background.
38 void SetBounds(gfx::Rect bounds);
40 // Move component from |src_container| in |root_window| to |dest_container|.
41 // It is required for lock screen, when we need to move background so that
42 // it hides user's windows. Returns true if there was something to reparent.
43 bool Reparent(aura::RootWindow* root_window,
44 int src_container,
45 int dest_container);
47 views::Widget* widget() { return widget_; }
48 ui::Layer* layer() { return layer_.get(); }
50 private:
51 views::Widget* widget_;
52 scoped_ptr<ui::Layer> layer_;
54 DISALLOW_COPY_AND_ASSIGN(DesktopBackgroundWidgetController);
57 // This class wraps a DesktopBackgroundWidgetController pointer. It is installed
58 // as an owned property on the RootWindow. DesktopBackgroundWidgetController is
59 // moved to this property before animation completes. After animation completes,
60 // the kDesktopController property on RootWindow is set to the
61 // DesktopBackgroundWidgetController in this class. Exported for tests.
62 class ASH_EXPORT AnimatingDesktopController {
63 public:
64 explicit AnimatingDesktopController(
65 DesktopBackgroundWidgetController* component);
66 ~AnimatingDesktopController();
68 // Stops animation and makes sure OnImplicitAnimationsCompleted() is called if
69 // current animation is not finished yet.
70 // Note we have to make sure this function is called before we set
71 // kAnimatingDesktopController to a new controller. If it is not called, the
72 // animating widget/layer is closed immediately and the new one is animating
73 // from the widget/layer before animation. For instance, if a user quickly
74 // switches between red, green and blue wallpapers. The green wallpaper will
75 // first fade in from red wallpaper. And in the middle of the animation, blue
76 // wallpaper also wants to fade in. If the green wallpaper animation does not
77 // finish immediately, the green wallpaper widget will be removed and the red
78 // widget will show again. As a result, the blue wallpaper fades in from red
79 // wallpaper. This is a bad user experience. See bug http://crbug.com/156542
80 // for more details.
81 void StopAnimating();
83 // Gets the wrapped DesktopBackgroundWidgetController pointer. Caller should
84 // take ownership of the pointer if |pass_ownership| is true.
85 DesktopBackgroundWidgetController* GetController(bool pass_ownership);
87 private:
88 scoped_ptr<DesktopBackgroundWidgetController> controller_;
90 DISALLOW_COPY_AND_ASSIGN(AnimatingDesktopController);
93 // Window property key, that binds instance of DesktopBackgroundWidgetController
94 // to root windows. Owned property.
95 ASH_EXPORT extern
96 const aura::WindowProperty<DesktopBackgroundWidgetController*>* const
97 kDesktopController;
99 // Wrapper for the DesktopBackgroundWidgetController for a desktop background
100 // that is animating in. Owned property.
101 ASH_EXPORT extern const aura::WindowProperty<AnimatingDesktopController*>* const
102 kAnimatingDesktopController;
104 } // namespace internal
105 } // namespace ash
107 #endif // ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_WIDGET_CONTROLLER_H_