Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: ash/common/wallpaper/wallpaper_widget_controller.cc

Issue 2318223003: mash: Migrate wallpaper controllers to ash/common. (Closed)
Patch Set: Fix nit. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/wallpaper/wallpaper_widget_controller.h" 5 #include "ash/common/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_root_window_controller.h"
10 #include "ash/common/wm_shell.h" 11 #include "ash/common/wm_shell.h"
11 #include "ash/common/wm_window.h" 12 #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" 13 #include "ui/compositor/layer_animation_observer.h"
15 #include "ui/compositor/scoped_layer_animation_settings.h" 14 #include "ui/compositor/scoped_layer_animation_settings.h"
16 #include "ui/views/widget/widget.h" 15 #include "ui/views/widget/widget.h"
17 16
18 namespace ash { 17 namespace ash {
19 namespace { 18 namespace {
20 19
21 class ShowWallpaperAnimationObserver : public ui::ImplicitAnimationObserver, 20 class ShowWallpaperAnimationObserver : public ui::ImplicitAnimationObserver,
22 public views::WidgetObserver { 21 public views::WidgetObserver {
23 public: 22 public:
24 ShowWallpaperAnimationObserver(RootWindowController* root_window_controller, 23 ShowWallpaperAnimationObserver(WmRootWindowController* root_window_controller,
25 views::Widget* wallpaper_widget, 24 views::Widget* wallpaper_widget,
26 bool is_initial_animation) 25 bool is_initial_animation)
27 : root_window_controller_(root_window_controller), 26 : root_window_controller_(root_window_controller),
28 wallpaper_widget_(wallpaper_widget), 27 wallpaper_widget_(wallpaper_widget),
29 is_initial_animation_(is_initial_animation) { 28 is_initial_animation_(is_initial_animation) {
30 DCHECK(wallpaper_widget_); 29 DCHECK(wallpaper_widget_);
31 wallpaper_widget_->AddObserver(this); 30 wallpaper_widget_->AddObserver(this);
32 } 31 }
33 32
34 ~ShowWallpaperAnimationObserver() override { 33 ~ShowWallpaperAnimationObserver() override {
35 StopObservingImplicitAnimations(); 34 StopObservingImplicitAnimations();
36 if (wallpaper_widget_) 35 if (wallpaper_widget_)
37 wallpaper_widget_->RemoveObserver(this); 36 wallpaper_widget_->RemoveObserver(this);
38 } 37 }
39 38
40 private: 39 private:
41 // Overridden from ui::ImplicitAnimationObserver: 40 // Overridden from ui::ImplicitAnimationObserver:
42 void OnImplicitAnimationsScheduled() override { 41 void OnImplicitAnimationsScheduled() override {
43 if (is_initial_animation_) { 42 if (is_initial_animation_)
44 root_window_controller_->HandleInitialWallpaperAnimationStarted(); 43 root_window_controller_->OnInitialWallpaperAnimationStarted();
45 }
46 } 44 }
47 45
48 void OnImplicitAnimationsCompleted() override { 46 void OnImplicitAnimationsCompleted() override {
49 root_window_controller_->OnWallpaperAnimationFinished(wallpaper_widget_); 47 root_window_controller_->OnWallpaperAnimationFinished(wallpaper_widget_);
50 delete this; 48 delete this;
51 } 49 }
52 50
53 // Overridden from views::WidgetObserver. 51 // Overridden from views::WidgetObserver.
54 void OnWidgetDestroying(views::Widget* widget) override { delete this; } 52 void OnWidgetDestroying(views::Widget* widget) override { delete this; }
55 53
56 RootWindowController* root_window_controller_; 54 WmRootWindowController* root_window_controller_;
57 views::Widget* wallpaper_widget_; 55 views::Widget* wallpaper_widget_;
58 56
59 // Is this object observing the initial brightness/grayscale animation? 57 // Is this object observing the initial brightness/grayscale animation?
60 const bool is_initial_animation_; 58 const bool is_initial_animation_;
61 59
62 DISALLOW_COPY_AND_ASSIGN(ShowWallpaperAnimationObserver); 60 DISALLOW_COPY_AND_ASSIGN(ShowWallpaperAnimationObserver);
63 }; 61 };
64 62
65 } // namespace 63 } // namespace
66 64
(...skipping 15 matching lines...) Expand all
82 80
83 void WallpaperWidgetController::OnWidgetDestroying(views::Widget* widget) { 81 void WallpaperWidgetController::OnWidgetDestroying(views::Widget* widget) {
84 RemoveObservers(); 82 RemoveObservers();
85 } 83 }
86 84
87 void WallpaperWidgetController::SetBounds(const gfx::Rect& bounds) { 85 void WallpaperWidgetController::SetBounds(const gfx::Rect& bounds) {
88 if (widget_) 86 if (widget_)
89 widget_->SetBounds(bounds); 87 widget_->SetBounds(bounds);
90 } 88 }
91 89
92 bool WallpaperWidgetController::Reparent(aura::Window* root_window, 90 bool WallpaperWidgetController::Reparent(WmWindow* root_window, int container) {
93 int container) {
94 if (widget_) { 91 if (widget_) {
95 widget_parent_->RemoveObserver(this); 92 widget_parent_->RemoveObserver(this);
96 views::Widget::ReparentNativeView(widget_->GetNativeView(), 93 WmWindow* window = WmLookup::Get()->GetWindowForWidget(widget_);
97 root_window->GetChildById(container)); 94 root_window->GetChildByShellWindowId(container)->AddChild(window);
98 widget_parent_ = WmLookup::Get()->GetWindowForWidget(widget_)->GetParent(); 95 widget_parent_ = WmLookup::Get()->GetWindowForWidget(widget_)->GetParent();
99 widget_parent_->AddObserver(this); 96 widget_parent_->AddObserver(this);
100 return true; 97 return true;
101 } 98 }
102 // Nothing to reparent. 99 // Nothing to reparent.
103 return false; 100 return false;
104 } 101 }
105 102
106 void WallpaperWidgetController::RemoveObservers() { 103 void WallpaperWidgetController::RemoveObservers() {
107 widget_parent_->RemoveObserver(this); 104 widget_parent_->RemoveObserver(this);
108 widget_->RemoveObserver(this); 105 widget_->RemoveObserver(this);
109 widget_ = nullptr; 106 widget_ = nullptr;
110 } 107 }
111 108
112 void WallpaperWidgetController::OnWindowBoundsChanged( 109 void WallpaperWidgetController::OnWindowBoundsChanged(
113 WmWindow* window, 110 WmWindow* window,
114 const gfx::Rect& old_bounds, 111 const gfx::Rect& old_bounds,
115 const gfx::Rect& new_bounds) { 112 const gfx::Rect& new_bounds) {
116 SetBounds(new_bounds); 113 SetBounds(new_bounds);
117 } 114 }
118 115
119 void WallpaperWidgetController::StartAnimating( 116 void WallpaperWidgetController::StartAnimating(
120 RootWindowController* root_window_controller) { 117 WmRootWindowController* root_window_controller) {
121 if (widget_) { 118 if (widget_) {
122 ui::ScopedLayerAnimationSettings settings( 119 ui::ScopedLayerAnimationSettings settings(
123 widget_->GetNativeView()->layer()->GetAnimator()); 120 widget_->GetLayer()->GetAnimator());
124 settings.AddObserver(new ShowWallpaperAnimationObserver( 121 settings.AddObserver(new ShowWallpaperAnimationObserver(
125 root_window_controller, widget_, 122 root_window_controller, widget_,
126 WmShell::Get()->wallpaper_delegate()->ShouldShowInitialAnimation())); 123 WmShell::Get()->wallpaper_delegate()->ShouldShowInitialAnimation()));
127 // When |widget_| shows, AnimateShowWindowCommon() is called to do the 124 // When |widget_| shows, AnimateShowWindowCommon() is called to do the
128 // animation. Sets transition duration to 0 to avoid animating to the 125 // animation. Sets transition duration to 0 to avoid animating to the
129 // show animation's initial values. 126 // show animation's initial values.
130 settings.SetTransitionDuration(base::TimeDelta()); 127 settings.SetTransitionDuration(base::TimeDelta());
131 widget_->Show(); 128 widget_->Show();
132 } 129 }
133 } 130 }
134 131
135 AnimatingWallpaperWidgetController::AnimatingWallpaperWidgetController( 132 AnimatingWallpaperWidgetController::AnimatingWallpaperWidgetController(
136 WallpaperWidgetController* controller) 133 WallpaperWidgetController* controller)
137 : controller_(controller) {} 134 : controller_(controller) {}
138 135
139 AnimatingWallpaperWidgetController::~AnimatingWallpaperWidgetController() {} 136 AnimatingWallpaperWidgetController::~AnimatingWallpaperWidgetController() {}
140 137
141 void AnimatingWallpaperWidgetController::StopAnimating() { 138 void AnimatingWallpaperWidgetController::StopAnimating() {
142 if (controller_) { 139 if (controller_)
143 ui::Layer* layer = controller_->widget()->GetNativeView()->layer(); 140 controller_->widget()->GetLayer()->GetAnimator()->StopAnimating();
144 layer->GetAnimator()->StopAnimating();
145 }
146 } 141 }
147 142
148 WallpaperWidgetController* AnimatingWallpaperWidgetController::GetController( 143 WallpaperWidgetController* AnimatingWallpaperWidgetController::GetController(
149 bool pass_ownership) { 144 bool pass_ownership) {
150 if (pass_ownership) 145 if (pass_ownership)
151 return controller_.release(); 146 return controller_.release();
152 return controller_.get(); 147 return controller_.get();
153 } 148 }
154 149
155 } // namespace ash 150 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/wallpaper/wallpaper_widget_controller.h ('k') | ash/common/wm_root_window_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698