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 #include "ash/desktop_background/desktop_background_widget_controller.h"
7 #include "ash/ash_export.h"
8 #include "ash/desktop_background/user_wallpaper_delegate.h"
9 #include "ash/root_window_controller.h"
10 #include "ash/shell.h"
11 #include "ui/aura/root_window.h"
12 #include "ui/compositor/layer_animation_observer.h"
13 #include "ui/compositor/scoped_layer_animation_settings.h"
14 #include "ui/views/widget/widget.h"
15 #include "ui/views/widget/widget_observer.h"
21 class ShowWallpaperAnimationObserver
: public ui::ImplicitAnimationObserver
,
22 public views::WidgetObserver
{
24 ShowWallpaperAnimationObserver(RootWindowController
* root_window_controller
,
25 views::Widget
* desktop_widget
,
26 bool is_initial_animation
)
27 : root_window_controller_(root_window_controller
),
28 desktop_widget_(desktop_widget
),
29 is_initial_animation_(is_initial_animation
) {
30 DCHECK(desktop_widget_
);
31 desktop_widget_
->AddObserver(this);
34 virtual ~ShowWallpaperAnimationObserver() {
35 StopObservingImplicitAnimations();
37 desktop_widget_
->RemoveObserver(this);
41 // Overridden from ui::ImplicitAnimationObserver:
42 virtual void OnImplicitAnimationsScheduled() OVERRIDE
{
43 if (is_initial_animation_
) {
44 root_window_controller_
->
45 HandleInitialDesktopBackgroundAnimationStarted();
49 virtual void OnImplicitAnimationsCompleted() OVERRIDE
{
50 root_window_controller_
->OnWallpaperAnimationFinished(desktop_widget_
);
54 // Overridden from views::WidgetObserver.
55 virtual void OnWidgetDestroying(views::Widget
* widget
) OVERRIDE
{
59 RootWindowController
* root_window_controller_
;
60 views::Widget
* desktop_widget_
;
62 // Is this object observing the initial brightness/grayscale animation?
63 const bool is_initial_animation_
;
65 DISALLOW_COPY_AND_ASSIGN(ShowWallpaperAnimationObserver
);
70 DesktopBackgroundWidgetController::DesktopBackgroundWidgetController(
71 views::Widget
* widget
) : widget_(widget
) {
73 widget_
->AddObserver(this);
76 DesktopBackgroundWidgetController::~DesktopBackgroundWidgetController() {
78 widget_
->RemoveObserver(this);
84 void DesktopBackgroundWidgetController::OnWidgetDestroying(
85 views::Widget
* widget
) {
86 widget_
->RemoveObserver(this);
90 void DesktopBackgroundWidgetController::SetBounds(gfx::Rect bounds
) {
92 widget_
->SetBounds(bounds
);
95 bool DesktopBackgroundWidgetController::Reparent(aura::RootWindow
* root_window
,
99 views::Widget::ReparentNativeView(widget_
->GetNativeView(),
100 root_window
->GetChildById(dest_container
));
103 // Nothing to reparent.
107 void DesktopBackgroundWidgetController::StartAnimating(
108 RootWindowController
* root_window_controller
) {
110 ui::ScopedLayerAnimationSettings
settings(
111 widget_
->GetNativeView()->layer()->GetAnimator());
112 settings
.AddObserver(new ShowWallpaperAnimationObserver(
113 root_window_controller
, widget_
,
114 Shell::GetInstance()->user_wallpaper_delegate()->
115 ShouldShowInitialAnimation()));
116 // When |widget_| shows, AnimateShowWindowCommon() is called to do the
117 // animation. Sets transition duration to 0 to avoid animating to the
118 // show animation's initial values.
119 settings
.SetTransitionDuration(base::TimeDelta());
121 widget_
->GetNativeView()->SetName("DesktopBackgroundView");
125 AnimatingDesktopController::AnimatingDesktopController(
126 DesktopBackgroundWidgetController
* component
) {
127 controller_
.reset(component
);
130 AnimatingDesktopController::~AnimatingDesktopController() {
133 void AnimatingDesktopController::StopAnimating() {
135 ui::Layer
* layer
= controller_
->widget()->GetNativeView()->layer();
136 layer
->GetAnimator()->StopAnimating();
140 DesktopBackgroundWidgetController
* AnimatingDesktopController::GetController(
141 bool pass_ownership
) {
143 return controller_
.release();
144 return controller_
.get();
147 } // namespace internal