Update mojo surfaces bindings and mojo/cc/ glue
[chromium-blink-merge.git] / ash / desktop_background / desktop_background_widget_controller.cc
blob4a195386eabfcc2df3aa1a1575ce575bdd799d3d
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/window_event_dispatcher.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 {
20 class ShowWallpaperAnimationObserver : public ui::ImplicitAnimationObserver,
21 public views::WidgetObserver {
22 public:
23 ShowWallpaperAnimationObserver(RootWindowController* root_window_controller,
24 views::Widget* desktop_widget,
25 bool is_initial_animation)
26 : root_window_controller_(root_window_controller),
27 desktop_widget_(desktop_widget),
28 is_initial_animation_(is_initial_animation) {
29 DCHECK(desktop_widget_);
30 desktop_widget_->AddObserver(this);
33 virtual ~ShowWallpaperAnimationObserver() {
34 StopObservingImplicitAnimations();
35 if (desktop_widget_)
36 desktop_widget_->RemoveObserver(this);
39 private:
40 // Overridden from ui::ImplicitAnimationObserver:
41 virtual void OnImplicitAnimationsScheduled() OVERRIDE {
42 if (is_initial_animation_) {
43 root_window_controller_->
44 HandleInitialDesktopBackgroundAnimationStarted();
48 virtual void OnImplicitAnimationsCompleted() OVERRIDE {
49 root_window_controller_->OnWallpaperAnimationFinished(desktop_widget_);
50 delete this;
53 // Overridden from views::WidgetObserver.
54 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE {
55 delete this;
58 RootWindowController* root_window_controller_;
59 views::Widget* desktop_widget_;
61 // Is this object observing the initial brightness/grayscale animation?
62 const bool is_initial_animation_;
64 DISALLOW_COPY_AND_ASSIGN(ShowWallpaperAnimationObserver);
67 } // namespace
69 DesktopBackgroundWidgetController::DesktopBackgroundWidgetController(
70 views::Widget* widget) : widget_(widget) {
71 DCHECK(widget_);
72 widget_->AddObserver(this);
75 DesktopBackgroundWidgetController::~DesktopBackgroundWidgetController() {
76 if (widget_) {
77 widget_->RemoveObserver(this);
78 widget_->CloseNow();
79 widget_ = NULL;
83 void DesktopBackgroundWidgetController::OnWidgetDestroying(
84 views::Widget* widget) {
85 widget_->RemoveObserver(this);
86 widget_ = NULL;
89 void DesktopBackgroundWidgetController::SetBounds(gfx::Rect bounds) {
90 if (widget_)
91 widget_->SetBounds(bounds);
94 bool DesktopBackgroundWidgetController::Reparent(aura::Window* root_window,
95 int src_container,
96 int dest_container) {
97 if (widget_) {
98 views::Widget::ReparentNativeView(widget_->GetNativeView(),
99 root_window->GetChildById(dest_container));
100 return true;
102 // Nothing to reparent.
103 return false;
106 void DesktopBackgroundWidgetController::StartAnimating(
107 RootWindowController* root_window_controller) {
108 if (widget_) {
109 ui::ScopedLayerAnimationSettings settings(
110 widget_->GetNativeView()->layer()->GetAnimator());
111 settings.AddObserver(new ShowWallpaperAnimationObserver(
112 root_window_controller, widget_,
113 Shell::GetInstance()->user_wallpaper_delegate()->
114 ShouldShowInitialAnimation()));
115 // When |widget_| shows, AnimateShowWindowCommon() is called to do the
116 // animation. Sets transition duration to 0 to avoid animating to the
117 // show animation's initial values.
118 settings.SetTransitionDuration(base::TimeDelta());
119 widget_->Show();
120 widget_->GetNativeView()->SetName("DesktopBackgroundView");
124 AnimatingDesktopController::AnimatingDesktopController(
125 DesktopBackgroundWidgetController* component) {
126 controller_.reset(component);
129 AnimatingDesktopController::~AnimatingDesktopController() {
132 void AnimatingDesktopController::StopAnimating() {
133 if (controller_) {
134 ui::Layer* layer = controller_->widget()->GetNativeView()->layer();
135 layer->GetAnimator()->StopAnimating();
139 DesktopBackgroundWidgetController* AnimatingDesktopController::GetController(
140 bool pass_ownership) {
141 if (pass_ownership)
142 return controller_.release();
143 return controller_.get();
146 } // namespace ash