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

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

Issue 2413503002: Cleanup mojo Wallpaper interfaces for mash. (Closed)
Patch Set: Cleanup. Created 4 years, 2 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/common/wallpaper/wallpaper_controller.h" 5 #include "ash/common/wallpaper/wallpaper_controller.h"
6 6
7 #include "ash/common/shell_delegate.h"
7 #include "ash/common/shell_window_ids.h" 8 #include "ash/common/shell_window_ids.h"
8 #include "ash/common/wallpaper/wallpaper_controller_observer.h" 9 #include "ash/common/wallpaper/wallpaper_controller_observer.h"
9 #include "ash/common/wallpaper/wallpaper_delegate.h" 10 #include "ash/common/wallpaper/wallpaper_delegate.h"
10 #include "ash/common/wallpaper/wallpaper_view.h" 11 #include "ash/common/wallpaper/wallpaper_view.h"
11 #include "ash/common/wallpaper/wallpaper_widget_controller.h" 12 #include "ash/common/wallpaper/wallpaper_widget_controller.h"
12 #include "ash/common/wm_root_window_controller.h" 13 #include "ash/common/wm_root_window_controller.h"
13 #include "ash/common/wm_shell.h" 14 #include "ash/common/wm_shell.h"
14 #include "ash/common/wm_window.h" 15 #include "ash/common/wm_window.h"
15 #include "base/bind.h" 16 #include "base/bind.h"
16 #include "base/logging.h" 17 #include "base/logging.h"
17 #include "base/task_runner.h" 18 #include "base/task_runner.h"
18 #include "components/wallpaper/wallpaper_resizer.h" 19 #include "components/wallpaper/wallpaper_resizer.h"
20 #include "services/shell/public/cpp/connector.h"
19 #include "ui/display/manager/managed_display_info.h" 21 #include "ui/display/manager/managed_display_info.h"
20 #include "ui/display/screen.h" 22 #include "ui/display/screen.h"
21 #include "ui/views/widget/widget.h" 23 #include "ui/views/widget/widget.h"
22 24
23 namespace ash { 25 namespace ash {
24 namespace { 26 namespace {
25 27
26 // How long to wait reloading the wallpaper after the display size has changed. 28 // How long to wait reloading the wallpaper after the display size has changed.
27 const int kWallpaperReloadDelayMs = 100; 29 const int kWallpaperReloadDelayMs = 100;
28 30
31 // TODO(msw): Use enum traits instead.
32 wallpaper::WallpaperLayout WallpaperLayoutFromMojo(
33 ash::mojom::WallpaperLayout layout) {
34 switch (layout) {
35 case ash::mojom::WallpaperLayout::CENTER:
James Cook 2016/10/11 23:21:49 nit: ash:: not needed?
msw 2016/10/14 21:07:43 Done.
36 return wallpaper::WALLPAPER_LAYOUT_CENTER;
37 case ash::mojom::WallpaperLayout::CENTER_CROPPED:
38 return wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED;
39 case ash::mojom::WallpaperLayout::STRETCH:
40 return wallpaper::WALLPAPER_LAYOUT_STRETCH;
41 case ash::mojom::WallpaperLayout::TILE:
42 return wallpaper::WALLPAPER_LAYOUT_TILE;
43 }
44 NOTREACHED();
45 return wallpaper::WALLPAPER_LAYOUT_CENTER;
46 }
47
29 } // namespace 48 } // namespace
30 49
31 WallpaperController::WallpaperController( 50 WallpaperController::WallpaperController(
32 const scoped_refptr<base::TaskRunner>& task_runner) 51 const scoped_refptr<base::TaskRunner>& task_runner)
33 : locked_(false), 52 : locked_(false),
34 wallpaper_mode_(WALLPAPER_NONE), 53 wallpaper_mode_(WALLPAPER_NONE),
35 wallpaper_reload_delay_(kWallpaperReloadDelayMs), 54 wallpaper_reload_delay_(kWallpaperReloadDelayMs),
36 task_runner_(task_runner) { 55 task_runner_(task_runner) {
37 WmShell::Get()->AddDisplayObserver(this); 56 WmShell::Get()->AddDisplayObserver(this);
38 WmShell::Get()->AddShellObserver(this); 57 WmShell::Get()->AddShellObserver(this);
39 } 58 }
40 59
41 WallpaperController::~WallpaperController() { 60 WallpaperController::~WallpaperController() {
42 WmShell::Get()->RemoveDisplayObserver(this); 61 WmShell::Get()->RemoveDisplayObserver(this);
43 WmShell::Get()->RemoveShellObserver(this); 62 WmShell::Get()->RemoveShellObserver(this);
44 } 63 }
45 64
65 void WallpaperController::BindRequest(
66 mojom::WallpaperControllerRequest request) {
67 bindings_.AddBinding(this, std::move(request));
68 }
69
46 gfx::ImageSkia WallpaperController::GetWallpaper() const { 70 gfx::ImageSkia WallpaperController::GetWallpaper() const {
47 if (current_wallpaper_) 71 if (current_wallpaper_)
48 return current_wallpaper_->image(); 72 return current_wallpaper_->image();
49 return gfx::ImageSkia(); 73 return gfx::ImageSkia();
50 } 74 }
51 75
52 void WallpaperController::AddObserver(WallpaperControllerObserver* observer) { 76 void WallpaperController::AddObserver(WallpaperControllerObserver* observer) {
53 observers_.AddObserver(observer); 77 observers_.AddObserver(observer);
54 } 78 }
55 79
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 return false; 199 return false;
176 200
177 // Compare layouts only if necessary. 201 // Compare layouts only if necessary.
178 if (compare_layouts && layout != current_wallpaper_->layout()) 202 if (compare_layouts && layout != current_wallpaper_->layout())
179 return false; 203 return false;
180 204
181 return wallpaper::WallpaperResizer::GetImageId(image) == 205 return wallpaper::WallpaperResizer::GetImageId(image) ==
182 current_wallpaper_->original_image_id(); 206 current_wallpaper_->original_image_id();
183 } 207 }
184 208
209 void WallpaperController::OpenSetWallpaperPage() {
210 auto shell = WmShell::Get();
James Cook 2016/10/11 23:21:49 nit: I think WmShell* is better than auto here. Th
msw 2016/10/14 21:07:43 Done.
211 auto connector = shell->delegate()->GetShellConnector();
James Cook 2016/10/11 23:21:49 This one might be worth it for wrapping, but also
msw 2016/10/14 21:07:43 Done.
212 if (!connector || !shell->wallpaper_delegate()->CanOpenSetWallpaperPage())
213 return;
214
215 mojom::WallpaperManagerPtr wallpaper_manager;
216 connector->ConnectToInterface("service:content_browser", &wallpaper_manager);
217 wallpaper_manager->Open();
218 }
219
220 void WallpaperController::SetWallpaper(const SkBitmap& wallpaper,
221 mojom::WallpaperLayout layout) {
222 if (wallpaper.isNull())
223 return;
224
225 gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(wallpaper);
226 SetWallpaperImage(image, WallpaperLayoutFromMojo(layout));
227 }
228
185 void WallpaperController::InstallDesktopController(WmWindow* root_window) { 229 void WallpaperController::InstallDesktopController(WmWindow* root_window) {
186 WallpaperWidgetController* component = nullptr; 230 WallpaperWidgetController* component = nullptr;
187 int container_id = GetWallpaperContainerId(locked_); 231 int container_id = GetWallpaperContainerId(locked_);
188 232
189 switch (wallpaper_mode_) { 233 switch (wallpaper_mode_) {
190 case WALLPAPER_IMAGE: { 234 case WALLPAPER_IMAGE: {
191 component = new WallpaperWidgetController( 235 component = new WallpaperWidgetController(
192 CreateWallpaper(root_window, container_id)); 236 CreateWallpaper(root_window, container_id));
193 break; 237 break;
194 } 238 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 return locked ? kShellWindowId_LockScreenWallpaperContainer 288 return locked ? kShellWindowId_LockScreenWallpaperContainer
245 : kShellWindowId_WallpaperContainer; 289 : kShellWindowId_WallpaperContainer;
246 } 290 }
247 291
248 void WallpaperController::UpdateWallpaper(bool clear_cache) { 292 void WallpaperController::UpdateWallpaper(bool clear_cache) {
249 current_wallpaper_.reset(); 293 current_wallpaper_.reset();
250 WmShell::Get()->wallpaper_delegate()->UpdateWallpaper(clear_cache); 294 WmShell::Get()->wallpaper_delegate()->UpdateWallpaper(clear_cache);
251 } 295 }
252 296
253 } // namespace ash 297 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698