| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/desktop_background/desktop_background_widget_controller.h" | 5 #include "ash/wallpaper/wallpaper_widget_controller.h" |
| 6 | 6 |
| 7 #include "ash/ash_export.h" | 7 #include "ash/ash_export.h" |
| 8 #include "ash/common/wallpaper/wallpaper_delegate.h" | 8 #include "ash/common/wallpaper/wallpaper_delegate.h" |
| 9 #include "ash/common/wm_lookup.h" | 9 #include "ash/common/wm_lookup.h" |
| 10 #include "ash/common/wm_shell.h" | 10 #include "ash/common/wm_shell.h" |
| 11 #include "ash/common/wm_window.h" | 11 #include "ash/common/wm_window.h" |
| 12 #include "ash/root_window_controller.h" | 12 #include "ash/root_window_controller.h" |
| 13 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
| 14 #include "ui/compositor/layer_animation_observer.h" | 14 #include "ui/compositor/layer_animation_observer.h" |
| 15 #include "ui/compositor/scoped_layer_animation_settings.h" | 15 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 16 #include "ui/views/widget/widget.h" | 16 #include "ui/views/widget/widget.h" |
| 17 | 17 |
| 18 namespace ash { | 18 namespace ash { |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 class ShowWallpaperAnimationObserver : public ui::ImplicitAnimationObserver, | 21 class ShowWallpaperAnimationObserver : public ui::ImplicitAnimationObserver, |
| 22 public views::WidgetObserver { | 22 public views::WidgetObserver { |
| 23 public: | 23 public: |
| 24 ShowWallpaperAnimationObserver(RootWindowController* root_window_controller, | 24 ShowWallpaperAnimationObserver(RootWindowController* root_window_controller, |
| 25 views::Widget* desktop_widget, | 25 views::Widget* wallpaper_widget, |
| 26 bool is_initial_animation) | 26 bool is_initial_animation) |
| 27 : root_window_controller_(root_window_controller), | 27 : root_window_controller_(root_window_controller), |
| 28 desktop_widget_(desktop_widget), | 28 wallpaper_widget_(wallpaper_widget), |
| 29 is_initial_animation_(is_initial_animation) { | 29 is_initial_animation_(is_initial_animation) { |
| 30 DCHECK(desktop_widget_); | 30 DCHECK(wallpaper_widget_); |
| 31 desktop_widget_->AddObserver(this); | 31 wallpaper_widget_->AddObserver(this); |
| 32 } | 32 } |
| 33 | 33 |
| 34 ~ShowWallpaperAnimationObserver() override { | 34 ~ShowWallpaperAnimationObserver() override { |
| 35 StopObservingImplicitAnimations(); | 35 StopObservingImplicitAnimations(); |
| 36 if (desktop_widget_) | 36 if (wallpaper_widget_) |
| 37 desktop_widget_->RemoveObserver(this); | 37 wallpaper_widget_->RemoveObserver(this); |
| 38 } | 38 } |
| 39 | 39 |
| 40 private: | 40 private: |
| 41 // Overridden from ui::ImplicitAnimationObserver: | 41 // Overridden from ui::ImplicitAnimationObserver: |
| 42 void OnImplicitAnimationsScheduled() override { | 42 void OnImplicitAnimationsScheduled() override { |
| 43 if (is_initial_animation_) { | 43 if (is_initial_animation_) { |
| 44 root_window_controller_->HandleInitialDesktopBackgroundAnimationStarted(); | 44 root_window_controller_->HandleInitialWallpaperAnimationStarted(); |
| 45 } | 45 } |
| 46 } | 46 } |
| 47 | 47 |
| 48 void OnImplicitAnimationsCompleted() override { | 48 void OnImplicitAnimationsCompleted() override { |
| 49 root_window_controller_->OnWallpaperAnimationFinished(desktop_widget_); | 49 root_window_controller_->OnWallpaperAnimationFinished(wallpaper_widget_); |
| 50 delete this; | 50 delete this; |
| 51 } | 51 } |
| 52 | 52 |
| 53 // Overridden from views::WidgetObserver. | 53 // Overridden from views::WidgetObserver. |
| 54 void OnWidgetDestroying(views::Widget* widget) override { delete this; } | 54 void OnWidgetDestroying(views::Widget* widget) override { delete this; } |
| 55 | 55 |
| 56 RootWindowController* root_window_controller_; | 56 RootWindowController* root_window_controller_; |
| 57 views::Widget* desktop_widget_; | 57 views::Widget* wallpaper_widget_; |
| 58 | 58 |
| 59 // Is this object observing the initial brightness/grayscale animation? | 59 // Is this object observing the initial brightness/grayscale animation? |
| 60 const bool is_initial_animation_; | 60 const bool is_initial_animation_; |
| 61 | 61 |
| 62 DISALLOW_COPY_AND_ASSIGN(ShowWallpaperAnimationObserver); | 62 DISALLOW_COPY_AND_ASSIGN(ShowWallpaperAnimationObserver); |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 } // namespace | 65 } // namespace |
| 66 | 66 |
| 67 DesktopBackgroundWidgetController::DesktopBackgroundWidgetController( | 67 WallpaperWidgetController::WallpaperWidgetController(views::Widget* widget) |
| 68 views::Widget* widget) | |
| 69 : widget_(widget), | 68 : widget_(widget), |
| 70 widget_parent_(WmLookup::Get()->GetWindowForWidget(widget)->GetParent()) { | 69 widget_parent_(WmLookup::Get()->GetWindowForWidget(widget)->GetParent()) { |
| 71 DCHECK(widget_); | 70 DCHECK(widget_); |
| 72 widget_->AddObserver(this); | 71 widget_->AddObserver(this); |
| 73 widget_parent_->AddObserver(this); | 72 widget_parent_->AddObserver(this); |
| 74 } | 73 } |
| 75 | 74 |
| 76 DesktopBackgroundWidgetController::~DesktopBackgroundWidgetController() { | 75 WallpaperWidgetController::~WallpaperWidgetController() { |
| 77 if (widget_) { | 76 if (widget_) { |
| 78 views::Widget* widget = widget_; | 77 views::Widget* widget = widget_; |
| 79 RemoveObservers(); | 78 RemoveObservers(); |
| 80 widget->CloseNow(); | 79 widget->CloseNow(); |
| 81 } | 80 } |
| 82 } | 81 } |
| 83 | 82 |
| 84 void DesktopBackgroundWidgetController::OnWidgetDestroying( | 83 void WallpaperWidgetController::OnWidgetDestroying(views::Widget* widget) { |
| 85 views::Widget* widget) { | |
| 86 RemoveObservers(); | 84 RemoveObservers(); |
| 87 } | 85 } |
| 88 | 86 |
| 89 void DesktopBackgroundWidgetController::SetBounds(const gfx::Rect& bounds) { | 87 void WallpaperWidgetController::SetBounds(const gfx::Rect& bounds) { |
| 90 if (widget_) | 88 if (widget_) |
| 91 widget_->SetBounds(bounds); | 89 widget_->SetBounds(bounds); |
| 92 } | 90 } |
| 93 | 91 |
| 94 bool DesktopBackgroundWidgetController::Reparent(aura::Window* root_window, | 92 bool WallpaperWidgetController::Reparent(aura::Window* root_window, |
| 95 int src_container, | 93 int container) { |
| 96 int dest_container) { | |
| 97 if (widget_) { | 94 if (widget_) { |
| 98 widget_parent_->RemoveObserver(this); | 95 widget_parent_->RemoveObserver(this); |
| 99 views::Widget::ReparentNativeView( | 96 views::Widget::ReparentNativeView(widget_->GetNativeView(), |
| 100 widget_->GetNativeView(), root_window->GetChildById(dest_container)); | 97 root_window->GetChildById(container)); |
| 101 widget_parent_ = WmLookup::Get()->GetWindowForWidget(widget_)->GetParent(); | 98 widget_parent_ = WmLookup::Get()->GetWindowForWidget(widget_)->GetParent(); |
| 102 widget_parent_->AddObserver(this); | 99 widget_parent_->AddObserver(this); |
| 103 return true; | 100 return true; |
| 104 } | 101 } |
| 105 // Nothing to reparent. | 102 // Nothing to reparent. |
| 106 return false; | 103 return false; |
| 107 } | 104 } |
| 108 | 105 |
| 109 void DesktopBackgroundWidgetController::RemoveObservers() { | 106 void WallpaperWidgetController::RemoveObservers() { |
| 110 widget_parent_->RemoveObserver(this); | 107 widget_parent_->RemoveObserver(this); |
| 111 widget_->RemoveObserver(this); | 108 widget_->RemoveObserver(this); |
| 112 widget_ = nullptr; | 109 widget_ = nullptr; |
| 113 } | 110 } |
| 114 | 111 |
| 115 void DesktopBackgroundWidgetController::OnWindowBoundsChanged( | 112 void WallpaperWidgetController::OnWindowBoundsChanged( |
| 116 WmWindow* window, | 113 WmWindow* window, |
| 117 const gfx::Rect& old_bounds, | 114 const gfx::Rect& old_bounds, |
| 118 const gfx::Rect& new_bounds) { | 115 const gfx::Rect& new_bounds) { |
| 119 SetBounds(new_bounds); | 116 SetBounds(new_bounds); |
| 120 } | 117 } |
| 121 | 118 |
| 122 void DesktopBackgroundWidgetController::StartAnimating( | 119 void WallpaperWidgetController::StartAnimating( |
| 123 RootWindowController* root_window_controller) { | 120 RootWindowController* root_window_controller) { |
| 124 if (widget_) { | 121 if (widget_) { |
| 125 ui::ScopedLayerAnimationSettings settings( | 122 ui::ScopedLayerAnimationSettings settings( |
| 126 widget_->GetNativeView()->layer()->GetAnimator()); | 123 widget_->GetNativeView()->layer()->GetAnimator()); |
| 127 settings.AddObserver(new ShowWallpaperAnimationObserver( | 124 settings.AddObserver(new ShowWallpaperAnimationObserver( |
| 128 root_window_controller, widget_, | 125 root_window_controller, widget_, |
| 129 WmShell::Get()->wallpaper_delegate()->ShouldShowInitialAnimation())); | 126 WmShell::Get()->wallpaper_delegate()->ShouldShowInitialAnimation())); |
| 130 // When |widget_| shows, AnimateShowWindowCommon() is called to do the | 127 // When |widget_| shows, AnimateShowWindowCommon() is called to do the |
| 131 // animation. Sets transition duration to 0 to avoid animating to the | 128 // animation. Sets transition duration to 0 to avoid animating to the |
| 132 // show animation's initial values. | 129 // show animation's initial values. |
| 133 settings.SetTransitionDuration(base::TimeDelta()); | 130 settings.SetTransitionDuration(base::TimeDelta()); |
| 134 widget_->Show(); | 131 widget_->Show(); |
| 135 } | 132 } |
| 136 } | 133 } |
| 137 | 134 |
| 138 AnimatingDesktopController::AnimatingDesktopController( | 135 AnimatingDesktopController::AnimatingDesktopController( |
| 139 DesktopBackgroundWidgetController* component) { | 136 WallpaperWidgetController* component) { |
| 140 controller_.reset(component); | 137 controller_.reset(component); |
| 141 } | 138 } |
| 142 | 139 |
| 143 AnimatingDesktopController::~AnimatingDesktopController() {} | 140 AnimatingDesktopController::~AnimatingDesktopController() {} |
| 144 | 141 |
| 145 void AnimatingDesktopController::StopAnimating() { | 142 void AnimatingDesktopController::StopAnimating() { |
| 146 if (controller_) { | 143 if (controller_) { |
| 147 ui::Layer* layer = controller_->widget()->GetNativeView()->layer(); | 144 ui::Layer* layer = controller_->widget()->GetNativeView()->layer(); |
| 148 layer->GetAnimator()->StopAnimating(); | 145 layer->GetAnimator()->StopAnimating(); |
| 149 } | 146 } |
| 150 } | 147 } |
| 151 | 148 |
| 152 DesktopBackgroundWidgetController* AnimatingDesktopController::GetController( | 149 WallpaperWidgetController* AnimatingDesktopController::GetController( |
| 153 bool pass_ownership) { | 150 bool pass_ownership) { |
| 154 if (pass_ownership) | 151 if (pass_ownership) |
| 155 return controller_.release(); | 152 return controller_.release(); |
| 156 return controller_.get(); | 153 return controller_.get(); |
| 157 } | 154 } |
| 158 | 155 |
| 159 } // namespace ash | 156 } // namespace ash |
| OLD | NEW |