OLD | NEW |
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/wallpaper/wallpaper_controller_observer.h" | 8 #include "ash/common/wallpaper/wallpaper_controller_observer.h" |
8 #include "ash/common/wallpaper/wallpaper_delegate.h" | 9 #include "ash/common/wallpaper/wallpaper_delegate.h" |
9 #include "ash/common/wallpaper/wallpaper_view.h" | 10 #include "ash/common/wallpaper/wallpaper_view.h" |
10 #include "ash/common/wallpaper/wallpaper_widget_controller.h" | 11 #include "ash/common/wallpaper/wallpaper_widget_controller.h" |
11 #include "ash/common/wm_root_window_controller.h" | 12 #include "ash/common/wm_root_window_controller.h" |
12 #include "ash/common/wm_shell.h" | 13 #include "ash/common/wm_shell.h" |
13 #include "ash/common/wm_window.h" | 14 #include "ash/common/wm_window.h" |
14 #include "ash/public/cpp/shell_window_ids.h" | 15 #include "ash/public/cpp/shell_window_ids.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/service_manager/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 |
29 } // namespace | 31 } // namespace |
30 | 32 |
31 WallpaperController::WallpaperController( | 33 WallpaperController::WallpaperController( |
32 const scoped_refptr<base::TaskRunner>& task_runner) | 34 const scoped_refptr<base::TaskRunner>& task_runner) |
33 : locked_(false), | 35 : locked_(false), |
34 wallpaper_mode_(WALLPAPER_NONE), | 36 wallpaper_mode_(WALLPAPER_NONE), |
35 wallpaper_reload_delay_(kWallpaperReloadDelayMs), | 37 wallpaper_reload_delay_(kWallpaperReloadDelayMs), |
36 task_runner_(task_runner) { | 38 task_runner_(task_runner) { |
37 WmShell::Get()->AddDisplayObserver(this); | 39 WmShell::Get()->AddDisplayObserver(this); |
38 WmShell::Get()->AddShellObserver(this); | 40 WmShell::Get()->AddShellObserver(this); |
39 } | 41 } |
40 | 42 |
41 WallpaperController::~WallpaperController() { | 43 WallpaperController::~WallpaperController() { |
42 WmShell::Get()->RemoveDisplayObserver(this); | 44 WmShell::Get()->RemoveDisplayObserver(this); |
43 WmShell::Get()->RemoveShellObserver(this); | 45 WmShell::Get()->RemoveShellObserver(this); |
44 } | 46 } |
45 | 47 |
| 48 void WallpaperController::BindRequest( |
| 49 mojom::WallpaperControllerRequest request) { |
| 50 bindings_.AddBinding(this, std::move(request)); |
| 51 } |
| 52 |
46 gfx::ImageSkia WallpaperController::GetWallpaper() const { | 53 gfx::ImageSkia WallpaperController::GetWallpaper() const { |
47 if (current_wallpaper_) | 54 if (current_wallpaper_) |
48 return current_wallpaper_->image(); | 55 return current_wallpaper_->image(); |
49 return gfx::ImageSkia(); | 56 return gfx::ImageSkia(); |
50 } | 57 } |
51 | 58 |
52 void WallpaperController::AddObserver(WallpaperControllerObserver* observer) { | 59 void WallpaperController::AddObserver(WallpaperControllerObserver* observer) { |
53 observers_.AddObserver(observer); | 60 observers_.AddObserver(observer); |
54 } | 61 } |
55 | 62 |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 return false; | 182 return false; |
176 | 183 |
177 // Compare layouts only if necessary. | 184 // Compare layouts only if necessary. |
178 if (compare_layouts && layout != current_wallpaper_->layout()) | 185 if (compare_layouts && layout != current_wallpaper_->layout()) |
179 return false; | 186 return false; |
180 | 187 |
181 return wallpaper::WallpaperResizer::GetImageId(image) == | 188 return wallpaper::WallpaperResizer::GetImageId(image) == |
182 current_wallpaper_->original_image_id(); | 189 current_wallpaper_->original_image_id(); |
183 } | 190 } |
184 | 191 |
| 192 void WallpaperController::OpenSetWallpaperPage() { |
| 193 WmShell* shell = WmShell::Get(); |
| 194 service_manager::Connector* connector = |
| 195 shell->delegate()->GetShellConnector(); |
| 196 if (!connector || !shell->wallpaper_delegate()->CanOpenSetWallpaperPage()) |
| 197 return; |
| 198 |
| 199 mojom::WallpaperManagerPtr wallpaper_manager; |
| 200 connector->ConnectToInterface("service:content_browser", &wallpaper_manager); |
| 201 wallpaper_manager->Open(); |
| 202 } |
| 203 |
| 204 void WallpaperController::SetWallpaper(const SkBitmap& wallpaper, |
| 205 wallpaper::WallpaperLayout layout) { |
| 206 if (wallpaper.isNull()) |
| 207 return; |
| 208 |
| 209 SetWallpaperImage(gfx::ImageSkia::CreateFrom1xBitmap(wallpaper), layout); |
| 210 } |
| 211 |
185 void WallpaperController::InstallDesktopController(WmWindow* root_window) { | 212 void WallpaperController::InstallDesktopController(WmWindow* root_window) { |
186 WallpaperWidgetController* component = nullptr; | 213 WallpaperWidgetController* component = nullptr; |
187 int container_id = GetWallpaperContainerId(locked_); | 214 int container_id = GetWallpaperContainerId(locked_); |
188 | 215 |
189 switch (wallpaper_mode_) { | 216 switch (wallpaper_mode_) { |
190 case WALLPAPER_IMAGE: { | 217 case WALLPAPER_IMAGE: { |
191 component = new WallpaperWidgetController( | 218 component = new WallpaperWidgetController( |
192 CreateWallpaper(root_window, container_id)); | 219 CreateWallpaper(root_window, container_id)); |
193 break; | 220 break; |
194 } | 221 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 return locked ? kShellWindowId_LockScreenWallpaperContainer | 271 return locked ? kShellWindowId_LockScreenWallpaperContainer |
245 : kShellWindowId_WallpaperContainer; | 272 : kShellWindowId_WallpaperContainer; |
246 } | 273 } |
247 | 274 |
248 void WallpaperController::UpdateWallpaper(bool clear_cache) { | 275 void WallpaperController::UpdateWallpaper(bool clear_cache) { |
249 current_wallpaper_.reset(); | 276 current_wallpaper_.reset(); |
250 WmShell::Get()->wallpaper_delegate()->UpdateWallpaper(clear_cache); | 277 WmShell::Get()->wallpaper_delegate()->UpdateWallpaper(clear_cache); |
251 } | 278 } |
252 | 279 |
253 } // namespace ash | 280 } // namespace ash |
OLD | NEW |