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/wm/workspace/desktop_background_fade_controller.h"
7 #include "ash/wm/window_animations.h"
8 #include "ash/wm/workspace/colored_window_controller.h"
10 #include "ui/aura/window.h"
11 #include "ui/compositor/scoped_layer_animation_settings.h"
12 #include "ui/views/widget/widget.h"
17 DesktopBackgroundFadeController::DesktopBackgroundFadeController(
19 aura::Window
* position_above
,
20 base::TimeDelta duration
,
21 Direction direction
) {
22 SkColor start_color
, target_color
;
23 ui::Tween::Type tween_type
;
24 if (direction
== FADE_OUT
) {
25 start_color
= SkColorSetARGB(0, 0, 0, 0);
26 target_color
= SK_ColorBLACK
;
27 tween_type
= ui::Tween::EASE_IN_OUT
;
29 start_color
= SK_ColorBLACK
;
30 target_color
= SkColorSetARGB(0, 0, 0, 0);
31 tween_type
= ui::Tween::EASE_IN_OUT
;
34 window_controller_
.reset(
35 new ColoredWindowController(parent
, "DesktopFade"));
37 // Force the window to be directly on top of the desktop.
38 aura::Window
* fade_window
= window_controller_
->GetWidget()->GetNativeView();
39 parent
->StackChildBelow(fade_window
, position_above
);
40 parent
->StackChildAbove(fade_window
, position_above
);
41 window_controller_
->SetColor(start_color
);
42 views::corewm::SetWindowVisibilityAnimationTransition(
43 window_controller_
->GetWidget()->GetNativeView(),
44 views::corewm::ANIMATE_NONE
);
45 window_controller_
->GetWidget()->Show();
47 ui::ScopedLayerAnimationSettings
scoped_setter(
48 fade_window
->layer()->GetAnimator());
49 scoped_setter
.AddObserver(this);
50 scoped_setter
.SetTweenType(tween_type
);
51 scoped_setter
.SetTransitionDuration(duration
);
52 window_controller_
->SetColor(target_color
);
56 DesktopBackgroundFadeController::~DesktopBackgroundFadeController() {
57 StopObservingImplicitAnimations();
60 void DesktopBackgroundFadeController::OnImplicitAnimationsCompleted() {
61 window_controller_
.reset();
64 } // namespace internal