Revert 224458 "Enabling MediaStreamInfoBarTest.DenyingCameraDoes..."
[chromium-blink-merge.git] / ash / desktop_background / desktop_background_widget_controller.cc
blobbd23b09ddb338a0d3a6acbc20cf7e5b2e1e3a519
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"
17 namespace ash {
18 namespace internal {
19 namespace {
21 class ShowWallpaperAnimationObserver : public ui::ImplicitAnimationObserver,
22 public views::WidgetObserver {
23 public:
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();
36 if (desktop_widget_)
37 desktop_widget_->RemoveObserver(this);
40 private:
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_);
51 delete this;
54 // Overridden from views::WidgetObserver.
55 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE {
56 delete this;
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);
68 } // namespace
70 DesktopBackgroundWidgetController::DesktopBackgroundWidgetController(
71 views::Widget* widget) : widget_(widget) {
72 DCHECK(widget_);
73 widget_->AddObserver(this);
76 DesktopBackgroundWidgetController::~DesktopBackgroundWidgetController() {
77 if (widget_) {
78 widget_->RemoveObserver(this);
79 widget_->CloseNow();
80 widget_ = NULL;
84 void DesktopBackgroundWidgetController::OnWidgetDestroying(
85 views::Widget* widget) {
86 widget_->RemoveObserver(this);
87 widget_ = NULL;
90 void DesktopBackgroundWidgetController::SetBounds(gfx::Rect bounds) {
91 if (widget_)
92 widget_->SetBounds(bounds);
95 bool DesktopBackgroundWidgetController::Reparent(aura::RootWindow* root_window,
96 int src_container,
97 int dest_container) {
98 if (widget_) {
99 views::Widget::ReparentNativeView(widget_->GetNativeView(),
100 root_window->GetChildById(dest_container));
101 return true;
103 // Nothing to reparent.
104 return false;
107 void DesktopBackgroundWidgetController::StartAnimating(
108 RootWindowController* root_window_controller) {
109 if (widget_) {
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());
120 widget_->Show();
121 widget_->GetNativeView()->SetName("DesktopBackgroundView");
125 AnimatingDesktopController::AnimatingDesktopController(
126 DesktopBackgroundWidgetController* component) {
127 controller_.reset(component);
130 AnimatingDesktopController::~AnimatingDesktopController() {
133 void AnimatingDesktopController::StopAnimating() {
134 if (controller_) {
135 ui::Layer* layer = controller_->widget()->GetNativeView()->layer();
136 layer->GetAnimator()->StopAnimating();
140 DesktopBackgroundWidgetController* AnimatingDesktopController::GetController(
141 bool pass_ownership) {
142 if (pass_ownership)
143 return controller_.release();
144 return controller_.get();
147 } // namespace internal
148 } // namespace ash