- add sources.
[platform/framework/web/crosswalk.git] / src / ash / wm / workspace / desktop_background_fade_controller.cc
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 #include "ash/wm/workspace/desktop_background_fade_controller.h"
6
7 #include "ash/wm/window_animations.h"
8 #include "ash/wm/workspace/colored_window_controller.h"
9 #include "base/time/time.h"
10 #include "ui/aura/window.h"
11 #include "ui/compositor/scoped_layer_animation_settings.h"
12 #include "ui/views/widget/widget.h"
13
14 namespace ash {
15 namespace internal {
16
17 DesktopBackgroundFadeController::DesktopBackgroundFadeController(
18     aura::Window* parent,
19     aura::Window* position_above,
20     base::TimeDelta duration,
21     Direction direction) {
22   SkColor start_color, target_color;
23   gfx::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 = gfx::Tween::EASE_IN_OUT;
28   } else {
29     start_color = SK_ColorBLACK;
30     target_color = SkColorSetARGB(0, 0, 0, 0);
31     tween_type = gfx::Tween::EASE_IN_OUT;
32   }
33
34   window_controller_.reset(
35       new ColoredWindowController(parent, "DesktopFade"));
36
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();
46   {
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);
53   }
54 }
55
56 DesktopBackgroundFadeController::~DesktopBackgroundFadeController() {
57   StopObservingImplicitAnimations();
58 }
59
60 void DesktopBackgroundFadeController::OnImplicitAnimationsCompleted() {
61   window_controller_.reset();
62 }
63
64 }  // namespace internal
65 }  // namespace ash