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

Side by Side Diff: ash/common/wallpaper/wallpaper_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_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(
34 base::SequencedWorkerPool* blocking_pool) 32 const scoped_refptr<base::TaskRunner>& task_runner)
35 : locked_(false), 33 : locked_(false),
36 wallpaper_mode_(WALLPAPER_NONE), 34 wallpaper_mode_(WALLPAPER_NONE),
37 wallpaper_reload_delay_(kWallpaperReloadDelayMs), 35 wallpaper_reload_delay_(kWallpaperReloadDelayMs),
38 blocking_pool_(blocking_pool) { 36 task_runner_(task_runner) {
39 WmShell::Get()->AddDisplayObserver(this); 37 WmShell::Get()->AddDisplayObserver(this);
40 WmShell::Get()->AddShellObserver(this); 38 WmShell::Get()->AddShellObserver(this);
41 } 39 }
42 40
43 WallpaperController::~WallpaperController() { 41 WallpaperController::~WallpaperController() {
44 WmShell::Get()->RemoveDisplayObserver(this); 42 WmShell::Get()->RemoveDisplayObserver(this);
45 WmShell::Get()->RemoveShellObserver(this); 43 WmShell::Get()->RemoveShellObserver(this);
46 } 44 }
47 45
48 gfx::ImageSkia WallpaperController::GetWallpaper() const { 46 gfx::ImageSkia WallpaperController::GetWallpaper() const {
(...skipping 22 matching lines...) Expand all
71 VLOG(1) << "SetWallpaper: image_id=" 69 VLOG(1) << "SetWallpaper: image_id="
72 << wallpaper::WallpaperResizer::GetImageId(image) 70 << wallpaper::WallpaperResizer::GetImageId(image)
73 << " layout=" << layout; 71 << " layout=" << layout;
74 72
75 if (WallpaperIsAlreadyLoaded(image, true /* compare_layouts */, layout)) { 73 if (WallpaperIsAlreadyLoaded(image, true /* compare_layouts */, layout)) {
76 VLOG(1) << "Wallpaper is already loaded"; 74 VLOG(1) << "Wallpaper is already loaded";
77 return false; 75 return false;
78 } 76 }
79 77
80 current_wallpaper_.reset(new wallpaper::WallpaperResizer( 78 current_wallpaper_.reset(new wallpaper::WallpaperResizer(
81 image, GetMaxDisplaySizeInNative(), layout, blocking_pool_)); 79 image, GetMaxDisplaySizeInNative(), layout, task_runner_));
82 current_wallpaper_->StartResize(); 80 current_wallpaper_->StartResize();
83 81
84 FOR_EACH_OBSERVER(WallpaperControllerObserver, observers_, 82 FOR_EACH_OBSERVER(WallpaperControllerObserver, observers_,
85 OnWallpaperDataChanged()); 83 OnWallpaperDataChanged());
86 wallpaper_mode_ = WALLPAPER_IMAGE; 84 wallpaper_mode_ = WALLPAPER_IMAGE;
87 InstallDesktopControllerForAllWindows(); 85 InstallDesktopControllerForAllWindows();
88 return true; 86 return true;
89 } 87 }
90 88
91 void WallpaperController::CreateEmptyWallpaper() { 89 void WallpaperController::CreateEmptyWallpaper() {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 case WALLPAPER_IMAGE: { 186 case WALLPAPER_IMAGE: {
189 component = new WallpaperWidgetController( 187 component = new WallpaperWidgetController(
190 CreateWallpaper(root_window, container_id)); 188 CreateWallpaper(root_window, container_id));
191 break; 189 break;
192 } 190 }
193 case WALLPAPER_NONE: 191 case WALLPAPER_NONE:
194 NOTREACHED(); 192 NOTREACHED();
195 return; 193 return;
196 } 194 }
197 195
198 aura::Window* aura_root_window = WmWindowAura::GetAuraWindow(root_window); 196 WmRootWindowController* controller = root_window->GetRootWindowController();
199 RootWindowController* controller = GetRootWindowController(aura_root_window);
200 controller->SetAnimatingWallpaperWidgetController( 197 controller->SetAnimatingWallpaperWidgetController(
201 new AnimatingWallpaperWidgetController(component)); 198 new AnimatingWallpaperWidgetController(component));
202 component->StartAnimating(controller); 199 component->StartAnimating(controller);
203 } 200 }
204 201
205 void WallpaperController::InstallDesktopControllerForAllWindows() { 202 void WallpaperController::InstallDesktopControllerForAllWindows() {
206 for (WmWindow* root : WmShell::Get()->GetAllRootWindows()) 203 for (WmWindow* root : WmShell::Get()->GetAllRootWindows())
207 InstallDesktopController(root); 204 InstallDesktopController(root);
208 current_max_display_size_ = GetMaxDisplaySizeInNative(); 205 current_max_display_size_ = GetMaxDisplaySizeInNative();
209 } 206 }
210 207
211 bool WallpaperController::ReparentWallpaper(int container) { 208 bool WallpaperController::ReparentWallpaper(int container) {
212 bool moved = false; 209 bool moved = false;
213 for (auto* root_window_controller : Shell::GetAllRootWindowControllers()) { 210 for (WmWindow* root_window : WmShell::Get()->GetAllRootWindows()) {
211 WmRootWindowController* root_window_controller =
212 root_window->GetRootWindowController();
214 // In the steady state (no animation playing) the wallpaper widget 213 // In the steady state (no animation playing) the wallpaper widget
215 // controller exists in the RootWindowController. 214 // controller exists in the RootWindowController.
216 WallpaperWidgetController* wallpaper_widget_controller = 215 WallpaperWidgetController* wallpaper_widget_controller =
217 root_window_controller->wallpaper_widget_controller(); 216 root_window_controller->wallpaper_widget_controller();
218 if (wallpaper_widget_controller) { 217 if (wallpaper_widget_controller) {
219 moved |= wallpaper_widget_controller->Reparent( 218 moved |= wallpaper_widget_controller->Reparent(
220 root_window_controller->GetRootWindow(), container); 219 root_window_controller->GetWindow(), container);
221 } 220 }
222 // During wallpaper show animations the controller lives in 221 // During wallpaper show animations the controller lives in
223 // AnimatingWallpaperWidgetController owned by RootWindowController. 222 // AnimatingWallpaperWidgetController owned by RootWindowController.
224 // NOTE: If an image load happens during a wallpaper show animation there 223 // 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, 224 // can temporarily be two wallpaper widgets. We must reparent both of them,
226 // one above and one here. 225 // one above and one here.
227 WallpaperWidgetController* animating_controller = 226 WallpaperWidgetController* animating_controller =
228 root_window_controller->animating_wallpaper_widget_controller() 227 root_window_controller->animating_wallpaper_widget_controller()
229 ? root_window_controller->animating_wallpaper_widget_controller() 228 ? root_window_controller->animating_wallpaper_widget_controller()
230 ->GetController(false) 229 ->GetController(false)
231 : nullptr; 230 : nullptr;
232 if (animating_controller) { 231 if (animating_controller) {
233 moved |= animating_controller->Reparent( 232 moved |= animating_controller->Reparent(
234 root_window_controller->GetRootWindow(), container); 233 root_window_controller->GetWindow(), container);
235 } 234 }
236 } 235 }
237 return moved; 236 return moved;
238 } 237 }
239 238
240 int WallpaperController::GetWallpaperContainerId(bool locked) { 239 int WallpaperController::GetWallpaperContainerId(bool locked) {
241 return locked ? kShellWindowId_LockScreenWallpaperContainer 240 return locked ? kShellWindowId_LockScreenWallpaperContainer
242 : kShellWindowId_WallpaperContainer; 241 : kShellWindowId_WallpaperContainer;
243 } 242 }
244 243
245 void WallpaperController::UpdateWallpaper(bool clear_cache) { 244 void WallpaperController::UpdateWallpaper(bool clear_cache) {
246 current_wallpaper_.reset(); 245 current_wallpaper_.reset();
247 WmShell::Get()->wallpaper_delegate()->UpdateWallpaper(clear_cache); 246 WmShell::Get()->wallpaper_delegate()->UpdateWallpaper(clear_cache);
248 } 247 }
249 248
250 } // namespace ash 249 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/wallpaper/wallpaper_controller.h ('k') | ash/common/wallpaper/wallpaper_controller_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698