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/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 |
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 auto* connector = shell->delegate()->GetShellConnector(); | |
195 if (!connector || !shell->wallpaper_delegate()->CanOpenSetWallpaperPage()) | |
196 return; | |
197 | |
198 mojom::WallpaperManagerPtr wallpaper_manager; | |
199 connector->ConnectToInterface("service:content_browser", &wallpaper_manager); | |
200 wallpaper_manager->Open(); | |
201 } | |
202 | |
203 void WallpaperController::SetWallpaper(const SkBitmap& wallpaper, | |
204 wallpaper::WallpaperLayout layout) { | |
205 if (wallpaper.isNull()) | |
206 return; | |
207 | |
208 SetWallpaperImage(gfx::ImageSkia::CreateFrom1xBitmap(wallpaper), layout); | |
209 } | |
210 | |
211 void WallpaperController::GetWallpaper(const GetWallpaperCallback& callback) { | |
212 callback.Run(*GetWallpaper().bitmap(), GetWallpaperLayout()); | |
James Cook
2016/10/14 21:58:02
nit: maybe comment here also that this can be slow
msw
2016/10/17 22:22:47
Moot; removed.
| |
213 } | |
214 | |
185 void WallpaperController::InstallDesktopController(WmWindow* root_window) { | 215 void WallpaperController::InstallDesktopController(WmWindow* root_window) { |
186 WallpaperWidgetController* component = nullptr; | 216 WallpaperWidgetController* component = nullptr; |
187 int container_id = GetWallpaperContainerId(locked_); | 217 int container_id = GetWallpaperContainerId(locked_); |
188 | 218 |
189 switch (wallpaper_mode_) { | 219 switch (wallpaper_mode_) { |
190 case WALLPAPER_IMAGE: { | 220 case WALLPAPER_IMAGE: { |
191 component = new WallpaperWidgetController( | 221 component = new WallpaperWidgetController( |
192 CreateWallpaper(root_window, container_id)); | 222 CreateWallpaper(root_window, container_id)); |
193 break; | 223 break; |
194 } | 224 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
244 return locked ? kShellWindowId_LockScreenWallpaperContainer | 274 return locked ? kShellWindowId_LockScreenWallpaperContainer |
245 : kShellWindowId_WallpaperContainer; | 275 : kShellWindowId_WallpaperContainer; |
246 } | 276 } |
247 | 277 |
248 void WallpaperController::UpdateWallpaper(bool clear_cache) { | 278 void WallpaperController::UpdateWallpaper(bool clear_cache) { |
249 current_wallpaper_.reset(); | 279 current_wallpaper_.reset(); |
250 WmShell::Get()->wallpaper_delegate()->UpdateWallpaper(clear_cache); | 280 WmShell::Get()->wallpaper_delegate()->UpdateWallpaper(clear_cache); |
251 } | 281 } |
252 | 282 |
253 } // namespace ash | 283 } // namespace ash |
OLD | NEW |