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