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

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

Issue 2318223003: mash: Migrate wallpaper controllers to ash/common. (Closed)
Patch Set: Cleanup. 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_controller.h" 5 #include "ash/common/wallpaper/wallpaper_controller.h"
6 6
7 #include "ash/aura/wm_window_aura.h"
8 #include "ash/common/shell_window_ids.h" 7 #include "ash/common/shell_window_ids.h"
8 #include "ash/common/wallpaper/wallpaper_controller_observer.h"
9 #include "ash/common/wallpaper/wallpaper_delegate.h" 9 #include "ash/common/wallpaper/wallpaper_delegate.h"
10 #include "ash/common/wallpaper/wallpaper_view.h"
11 #include "ash/common/wallpaper/wallpaper_widget_controller.h"
12 #include "ash/common/wm_root_window_controller.h"
10 #include "ash/common/wm_shell.h" 13 #include "ash/common/wm_shell.h"
11 #include "ash/root_window_controller.h" 14 #include "ash/common/wm_window.h"
12 #include "ash/shell.h"
13 #include "ash/wallpaper/wallpaper_controller_observer.h"
14 #include "ash/wallpaper/wallpaper_view.h"
15 #include "ash/wallpaper/wallpaper_widget_controller.h"
16 #include "base/bind.h" 15 #include "base/bind.h"
17 #include "base/logging.h" 16 #include "base/logging.h"
18 #include "base/threading/sequenced_worker_pool.h" 17 #include "base/task_runner.h"
19 #include "components/wallpaper/wallpaper_resizer.h" 18 #include "components/wallpaper/wallpaper_resizer.h"
20 #include "ui/aura/window.h"
21 #include "ui/display/manager/managed_display_info.h" 19 #include "ui/display/manager/managed_display_info.h"
22 #include "ui/display/screen.h" 20 #include "ui/display/screen.h"
23 #include "ui/views/widget/widget.h" 21 #include "ui/views/widget/widget.h"
24 22
25 namespace ash { 23 namespace ash {
26 namespace { 24 namespace {
27 25
28 // How long to wait reloading the wallpaper after the display size has changed. 26 // How long to wait reloading the wallpaper after the display size has changed.
29 const int kWallpaperReloadDelayMs = 100; 27 const int kWallpaperReloadDelayMs = 100;
30 28
31 } // namespace 29 } // namespace
32 30
33 WallpaperController::WallpaperController( 31 WallpaperController::WallpaperController(base::TaskRunner* task_runner)
34 base::SequencedWorkerPool* blocking_pool)
35 : locked_(false), 32 : locked_(false),
36 wallpaper_mode_(WALLPAPER_NONE), 33 wallpaper_mode_(WALLPAPER_NONE),
37 wallpaper_reload_delay_(kWallpaperReloadDelayMs), 34 wallpaper_reload_delay_(kWallpaperReloadDelayMs),
38 blocking_pool_(blocking_pool) { 35 task_runner_(task_runner) {
39 WmShell::Get()->AddDisplayObserver(this); 36 WmShell::Get()->AddDisplayObserver(this);
40 WmShell::Get()->AddShellObserver(this); 37 WmShell::Get()->AddShellObserver(this);
41 } 38 }
42 39
43 WallpaperController::~WallpaperController() { 40 WallpaperController::~WallpaperController() {
44 WmShell::Get()->RemoveDisplayObserver(this); 41 WmShell::Get()->RemoveDisplayObserver(this);
45 WmShell::Get()->RemoveShellObserver(this); 42 WmShell::Get()->RemoveShellObserver(this);
46 } 43 }
47 44
48 gfx::ImageSkia WallpaperController::GetWallpaper() const { 45 gfx::ImageSkia WallpaperController::GetWallpaper() const {
(...skipping 22 matching lines...) Expand all
71 VLOG(1) << "SetWallpaper: image_id=" 68 VLOG(1) << "SetWallpaper: image_id="
72 << wallpaper::WallpaperResizer::GetImageId(image) 69 << wallpaper::WallpaperResizer::GetImageId(image)
73 << " layout=" << layout; 70 << " layout=" << layout;
74 71
75 if (WallpaperIsAlreadyLoaded(image, true /* compare_layouts */, layout)) { 72 if (WallpaperIsAlreadyLoaded(image, true /* compare_layouts */, layout)) {
76 VLOG(1) << "Wallpaper is already loaded"; 73 VLOG(1) << "Wallpaper is already loaded";
77 return false; 74 return false;
78 } 75 }
79 76
80 current_wallpaper_.reset(new wallpaper::WallpaperResizer( 77 current_wallpaper_.reset(new wallpaper::WallpaperResizer(
81 image, GetMaxDisplaySizeInNative(), layout, blocking_pool_)); 78 image, GetMaxDisplaySizeInNative(), layout, task_runner_));
82 current_wallpaper_->StartResize(); 79 current_wallpaper_->StartResize();
83 80
84 FOR_EACH_OBSERVER(WallpaperControllerObserver, observers_, 81 FOR_EACH_OBSERVER(WallpaperControllerObserver, observers_,
85 OnWallpaperDataChanged()); 82 OnWallpaperDataChanged());
86 wallpaper_mode_ = WALLPAPER_IMAGE; 83 wallpaper_mode_ = WALLPAPER_IMAGE;
87 InstallDesktopControllerForAllWindows(); 84 InstallDesktopControllerForAllWindows();
88 return true; 85 return true;
89 } 86 }
90 87
91 void WallpaperController::CreateEmptyWallpaper() { 88 void WallpaperController::CreateEmptyWallpaper() {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 case WALLPAPER_IMAGE: { 185 case WALLPAPER_IMAGE: {
189 component = new WallpaperWidgetController( 186 component = new WallpaperWidgetController(
190 CreateWallpaper(root_window, container_id)); 187 CreateWallpaper(root_window, container_id));
191 break; 188 break;
192 } 189 }
193 case WALLPAPER_NONE: 190 case WALLPAPER_NONE:
194 NOTREACHED(); 191 NOTREACHED();
195 return; 192 return;
196 } 193 }
197 194
198 aura::Window* aura_root_window = WmWindowAura::GetAuraWindow(root_window); 195 WmRootWindowController* controller = root_window->GetRootWindowController();
199 RootWindowController* controller = GetRootWindowController(aura_root_window);
200 controller->SetAnimatingWallpaperWidgetController( 196 controller->SetAnimatingWallpaperWidgetController(
201 new AnimatingWallpaperWidgetController(component)); 197 new AnimatingWallpaperWidgetController(component));
202 component->StartAnimating(controller); 198 component->StartAnimating(controller);
203 } 199 }
204 200
205 void WallpaperController::InstallDesktopControllerForAllWindows() { 201 void WallpaperController::InstallDesktopControllerForAllWindows() {
206 for (WmWindow* root : WmShell::Get()->GetAllRootWindows()) 202 for (WmWindow* root : WmShell::Get()->GetAllRootWindows())
207 InstallDesktopController(root); 203 InstallDesktopController(root);
208 current_max_display_size_ = GetMaxDisplaySizeInNative(); 204 current_max_display_size_ = GetMaxDisplaySizeInNative();
209 } 205 }
210 206
211 bool WallpaperController::ReparentWallpaper(int container) { 207 bool WallpaperController::ReparentWallpaper(int container) {
212 bool moved = false; 208 bool moved = false;
213 for (auto* root_window_controller : Shell::GetAllRootWindowControllers()) { 209 for (WmWindow* root_window : WmShell::Get()->GetAllRootWindows()) {
210 WmRootWindowController* root_window_controller =
211 root_window->GetRootWindowController();
214 // In the steady state (no animation playing) the wallpaper widget 212 // In the steady state (no animation playing) the wallpaper widget
215 // controller exists in the RootWindowController. 213 // controller exists in the RootWindowController.
216 WallpaperWidgetController* wallpaper_widget_controller = 214 WallpaperWidgetController* wallpaper_widget_controller =
217 root_window_controller->wallpaper_widget_controller(); 215 root_window_controller->wallpaper_widget_controller();
218 if (wallpaper_widget_controller) { 216 if (wallpaper_widget_controller) {
219 moved |= wallpaper_widget_controller->Reparent( 217 moved |= wallpaper_widget_controller->Reparent(
220 root_window_controller->GetRootWindow(), container); 218 root_window_controller->GetWindow(), container);
221 } 219 }
222 // During wallpaper show animations the controller lives in 220 // During wallpaper show animations the controller lives in
223 // AnimatingWallpaperWidgetController owned by RootWindowController. 221 // AnimatingWallpaperWidgetController owned by RootWindowController.
224 // NOTE: If an image load happens during a wallpaper show animation there 222 // NOTE: If an image load happens during a wallpaper show animation there
225 // can temporarily be two wallpaper widgets. We must reparent both of them, 223 // can temporarily be two wallpaper widgets. We must reparent both of them,
226 // one above and one here. 224 // one above and one here.
227 WallpaperWidgetController* animating_controller = 225 WallpaperWidgetController* animating_controller =
228 root_window_controller->animating_wallpaper_widget_controller() 226 root_window_controller->animating_wallpaper_widget_controller()
229 ? root_window_controller->animating_wallpaper_widget_controller() 227 ? root_window_controller->animating_wallpaper_widget_controller()
230 ->GetController(false) 228 ->GetController(false)
231 : nullptr; 229 : nullptr;
232 if (animating_controller) { 230 if (animating_controller) {
233 moved |= animating_controller->Reparent( 231 moved |= animating_controller->Reparent(
234 root_window_controller->GetRootWindow(), container); 232 root_window_controller->GetWindow(), container);
235 } 233 }
236 } 234 }
237 return moved; 235 return moved;
238 } 236 }
239 237
240 int WallpaperController::GetWallpaperContainerId(bool locked) { 238 int WallpaperController::GetWallpaperContainerId(bool locked) {
241 return locked ? kShellWindowId_LockScreenWallpaperContainer 239 return locked ? kShellWindowId_LockScreenWallpaperContainer
242 : kShellWindowId_WallpaperContainer; 240 : kShellWindowId_WallpaperContainer;
243 } 241 }
244 242
245 void WallpaperController::UpdateWallpaper(bool clear_cache) { 243 void WallpaperController::UpdateWallpaper(bool clear_cache) {
246 current_wallpaper_.reset(); 244 current_wallpaper_.reset();
247 WmShell::Get()->wallpaper_delegate()->UpdateWallpaper(clear_cache); 245 WmShell::Get()->wallpaper_delegate()->UpdateWallpaper(clear_cache);
248 } 246 }
249 247
250 } // namespace ash 248 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698