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/desktop_background/desktop_background_controller.h" | 5 #include "ash/desktop_background/desktop_background_controller.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/desktop_background/desktop_background_controller_observer.h" | 8 #include "ash/desktop_background/desktop_background_controller_observer.h" |
9 #include "ash/desktop_background/desktop_background_view.h" | 9 #include "ash/desktop_background/desktop_background_view.h" |
10 #include "ash/desktop_background/desktop_background_widget_controller.h" | 10 #include "ash/desktop_background/desktop_background_widget_controller.h" |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
148 // ID of an image resource to use if |file_path_| is empty or unloadable. | 148 // ID of an image resource to use if |file_path_| is empty or unloadable. |
149 int resource_id_; | 149 int resource_id_; |
150 | 150 |
151 // Layout to be used when displaying |resource_id_|. | 151 // Layout to be used when displaying |resource_id_|. |
152 WallpaperLayout resource_layout_; | 152 WallpaperLayout resource_layout_; |
153 | 153 |
154 DISALLOW_COPY_AND_ASSIGN(WallpaperLoader); | 154 DISALLOW_COPY_AND_ASSIGN(WallpaperLoader); |
155 }; | 155 }; |
156 | 156 |
157 DesktopBackgroundController::DesktopBackgroundController() | 157 DesktopBackgroundController::DesktopBackgroundController() |
158 : command_line_for_testing_(NULL), | 158 : locked_(false), |
159 locked_(false), | |
160 desktop_background_mode_(BACKGROUND_NONE), | 159 desktop_background_mode_(BACKGROUND_NONE), |
161 current_default_wallpaper_resource_id_(-1), | 160 current_default_wallpaper_resource_id_(-1), |
162 weak_ptr_factory_(this), | 161 weak_ptr_factory_(this), |
163 wallpaper_reload_delay_(kWallpaperReloadDelayMs) { | 162 wallpaper_reload_delay_( |
163 base::TimeDelta::FromMilliseconds(kWallpaperReloadDelayMs)) { | |
164 Shell::GetInstance()->display_controller()->AddObserver(this); | 164 Shell::GetInstance()->display_controller()->AddObserver(this); |
165 InitWallpaperPathsFromCommandLine(base::CommandLine::ForCurrentProcess()); | |
165 } | 166 } |
166 | 167 |
167 DesktopBackgroundController::~DesktopBackgroundController() { | 168 DesktopBackgroundController::~DesktopBackgroundController() { |
168 CancelDefaultWallpaperLoader(); | 169 CancelDefaultWallpaperLoader(); |
169 Shell::GetInstance()->display_controller()->RemoveObserver(this); | 170 Shell::GetInstance()->display_controller()->RemoveObserver(this); |
170 } | 171 } |
171 | 172 |
172 gfx::ImageSkia DesktopBackgroundController::GetWallpaper() const { | |
173 if (current_wallpaper_) | |
174 return current_wallpaper_->image(); | |
175 return gfx::ImageSkia(); | |
176 } | |
177 | |
178 void DesktopBackgroundController::AddObserver( | 173 void DesktopBackgroundController::AddObserver( |
179 DesktopBackgroundControllerObserver* observer) { | 174 DesktopBackgroundControllerObserver* observer) { |
180 observers_.AddObserver(observer); | 175 observers_.AddObserver(observer); |
181 } | 176 } |
182 | 177 |
183 void DesktopBackgroundController::RemoveObserver( | 178 void DesktopBackgroundController::RemoveObserver( |
184 DesktopBackgroundControllerObserver* observer) { | 179 DesktopBackgroundControllerObserver* observer) { |
185 observers_.RemoveObserver(observer); | 180 observers_.RemoveObserver(observer); |
186 } | 181 } |
187 | 182 |
188 WallpaperLayout DesktopBackgroundController::GetWallpaperLayout() const { | 183 WallpaperLayout DesktopBackgroundController::GetWallpaperLayout() const { |
189 if (current_wallpaper_) | 184 if (current_wallpaper_) |
190 return current_wallpaper_->layout(); | 185 return current_wallpaper_->layout(); |
191 return WALLPAPER_LAYOUT_CENTER_CROPPED; | 186 return WALLPAPER_LAYOUT_CENTER_CROPPED; |
192 } | 187 } |
193 | 188 |
189 gfx::ImageSkia DesktopBackgroundController::GetWallpaper() const { | |
190 if (current_wallpaper_) | |
191 return current_wallpaper_->image(); | |
192 return gfx::ImageSkia(); | |
193 } | |
194 | |
194 void DesktopBackgroundController::OnRootWindowAdded(aura::Window* root_window) { | 195 void DesktopBackgroundController::OnRootWindowAdded(aura::Window* root_window) { |
195 // The background hasn't been set yet. | 196 // The background hasn't been set yet. |
196 if (desktop_background_mode_ == BACKGROUND_NONE) | 197 if (desktop_background_mode_ == BACKGROUND_NONE) |
197 return; | 198 return; |
198 | 199 |
199 // Handle resolution change for "built-in" images. | 200 // Handle resolution change for "built-in" images. |
200 gfx::Size max_display_size = GetMaxDisplaySizeInNative(); | 201 gfx::Size max_display_size = GetMaxDisplaySizeInNative(); |
201 if (current_max_display_size_ != max_display_size) { | 202 if (current_max_display_size_ != max_display_size) { |
202 current_max_display_size_ = max_display_size; | 203 current_max_display_size_ = max_display_size; |
203 if (desktop_background_mode_ == BACKGROUND_IMAGE && | 204 if (desktop_background_mode_ == BACKGROUND_IMAGE && |
204 current_wallpaper_.get()) | 205 current_wallpaper_.get()) |
205 UpdateWallpaper(); | 206 UpdateWallpaper(); |
206 } | 207 } |
207 | 208 |
208 InstallDesktopController(root_window); | 209 InstallDesktopController(root_window); |
209 } | 210 } |
210 | 211 |
212 void DesktopBackgroundController::InitWallpaperPathsFromCommandLine( | |
213 base::CommandLine* cl) { | |
214 small_default_wallpaper_path_ = | |
215 cl->GetSwitchValuePath(switches::kAshDefaultWallpaperSmall); | |
216 large_default_wallpaper_path_ = | |
217 cl->GetSwitchValuePath(switches::kAshDefaultWallpaperLarge); | |
218 small_guest_wallpaper_path_ = | |
219 cl->GetSwitchValuePath(switches::kAshGuestWallpaperSmall); | |
220 large_guest_wallpaper_path_ = | |
221 cl->GetSwitchValuePath(switches::kAshGuestWallpaperLarge); | |
222 } | |
223 | |
224 void DesktopBackgroundController::SetDefaultWallpaperPaths( | |
225 const base::FilePath& small_path, | |
226 const base::FilePath& large_path, | |
227 bool is_guest) { | |
228 base::FilePath old_path; | |
229 WallpaperLayout old_layout; | |
230 GetDefaultWallpaperInfo(is_guest, &old_path, &old_layout, NULL, NULL); | |
Alexander Alekseev
2014/03/24 23:04:12
This call returns "Future wallpaper parameters, th
Daniel Erat
2014/03/24 23:12:05
"first of all" -> is this the only concern?
is yo
| |
231 | |
232 small_default_wallpaper_path_ = small_path; | |
233 large_default_wallpaper_path_ = large_path; | |
Alexander Alekseev
2014/03/24 23:04:12
if (is_guest) {
...
} else {
...
}
?
Daniel Erat
2014/03/24 23:12:05
do you need to override the default guest wallpape
| |
234 | |
235 // If the default was previously in use, update it. | |
236 if (DefaultWallpaperIsAlreadyLoadingOrLoaded(old_path, old_layout)) | |
237 SetDefaultWallpaper(is_guest); | |
238 } | |
239 | |
211 bool DesktopBackgroundController::SetDefaultWallpaper(bool is_guest) { | 240 bool DesktopBackgroundController::SetDefaultWallpaper(bool is_guest) { |
212 VLOG(1) << "SetDefaultWallpaper: is_guest=" << is_guest; | 241 VLOG(1) << "SetDefaultWallpaper: is_guest=" << is_guest; |
213 const bool use_large = | |
214 GetAppropriateResolution() == WALLPAPER_RESOLUTION_LARGE; | |
215 | |
216 base::FilePath file_path; | 242 base::FilePath file_path; |
217 WallpaperLayout file_layout = use_large ? WALLPAPER_LAYOUT_CENTER_CROPPED : | 243 int resource_id; |
218 WALLPAPER_LAYOUT_CENTER; | 244 WallpaperLayout file_layout, resource_layout; |
219 int resource_id = use_large ? IDR_AURA_WALLPAPER_DEFAULT_LARGE : | 245 GetDefaultWallpaperInfo( |
220 IDR_AURA_WALLPAPER_DEFAULT_SMALL; | 246 is_guest, &file_path, &file_layout, &resource_id, &resource_layout); |
221 WallpaperLayout resource_layout = WALLPAPER_LAYOUT_TILE; | |
222 | |
223 CommandLine* command_line = command_line_for_testing_ ? | |
224 command_line_for_testing_ : CommandLine::ForCurrentProcess(); | |
225 const char* switch_name = NULL; | |
226 if (is_guest) { | |
227 switch_name = use_large ? switches::kAshGuestWallpaperLarge : | |
228 switches::kAshGuestWallpaperSmall; | |
229 } else { | |
230 switch_name = use_large ? switches::kAshDefaultWallpaperLarge : | |
231 switches::kAshDefaultWallpaperSmall; | |
232 } | |
233 file_path = command_line->GetSwitchValuePath(switch_name); | |
234 | 247 |
235 if (DefaultWallpaperIsAlreadyLoadingOrLoaded(file_path, resource_id)) { | 248 if (DefaultWallpaperIsAlreadyLoadingOrLoaded(file_path, resource_id)) { |
236 VLOG(1) << "Default wallpaper is already loading or loaded"; | 249 VLOG(1) << "Default wallpaper is already loading or loaded"; |
237 return false; | 250 return false; |
238 } | 251 } |
239 | 252 |
240 CancelDefaultWallpaperLoader(); | 253 CancelDefaultWallpaperLoader(); |
241 default_wallpaper_loader_ = new WallpaperLoader( | 254 default_wallpaper_loader_ = new WallpaperLoader( |
242 file_path, file_layout, resource_id, resource_layout); | 255 file_path, file_layout, resource_id, resource_layout); |
243 base::WorkerPool::PostTaskAndReply( | 256 base::WorkerPool::PostTaskAndReply( |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
313 GetBackgroundContainerId(false)); | 326 GetBackgroundContainerId(false)); |
314 } | 327 } |
315 | 328 |
316 void DesktopBackgroundController::OnDisplayConfigurationChanged() { | 329 void DesktopBackgroundController::OnDisplayConfigurationChanged() { |
317 gfx::Size max_display_size = GetMaxDisplaySizeInNative(); | 330 gfx::Size max_display_size = GetMaxDisplaySizeInNative(); |
318 if (current_max_display_size_ != max_display_size) { | 331 if (current_max_display_size_ != max_display_size) { |
319 current_max_display_size_ = max_display_size; | 332 current_max_display_size_ = max_display_size; |
320 if (desktop_background_mode_ == BACKGROUND_IMAGE && | 333 if (desktop_background_mode_ == BACKGROUND_IMAGE && |
321 current_wallpaper_.get()) { | 334 current_wallpaper_.get()) { |
322 timer_.Stop(); | 335 timer_.Stop(); |
323 timer_.Start(FROM_HERE, | 336 timer_.Start(FROM_HERE, wallpaper_reload_delay_, this, |
324 base::TimeDelta::FromMilliseconds(wallpaper_reload_delay_), | |
325 this, | |
326 &DesktopBackgroundController::UpdateWallpaper); | 337 &DesktopBackgroundController::UpdateWallpaper); |
327 } | 338 } |
328 } | 339 } |
329 } | 340 } |
330 | 341 |
342 void DesktopBackgroundController::GetDefaultWallpaperInfo( | |
343 bool is_guest, | |
344 base::FilePath* file_path, | |
345 WallpaperLayout* file_layout, | |
346 int* resource_id, | |
347 WallpaperLayout* resource_layout) { | |
348 const bool use_large = | |
349 GetAppropriateResolution() == WALLPAPER_RESOLUTION_LARGE; | |
350 | |
351 if (file_path) { | |
352 if (is_guest) { | |
353 *file_path = use_large ? large_guest_wallpaper_path_ : | |
354 small_guest_wallpaper_path_; | |
355 } else { | |
356 *file_path = use_large ? large_default_wallpaper_path_ : | |
357 small_default_wallpaper_path_; | |
358 } | |
359 } | |
360 if (file_layout) { | |
361 *file_layout = use_large ? WALLPAPER_LAYOUT_CENTER_CROPPED : | |
362 WALLPAPER_LAYOUT_CENTER; | |
363 } | |
364 | |
365 if (resource_id) { | |
366 *resource_id = use_large ? IDR_AURA_WALLPAPER_DEFAULT_LARGE : | |
367 IDR_AURA_WALLPAPER_DEFAULT_SMALL; | |
368 } | |
369 if (resource_layout) | |
370 *resource_layout = WALLPAPER_LAYOUT_TILE; | |
371 } | |
372 | |
331 bool DesktopBackgroundController::DefaultWallpaperIsAlreadyLoadingOrLoaded( | 373 bool DesktopBackgroundController::DefaultWallpaperIsAlreadyLoadingOrLoaded( |
332 const base::FilePath& image_file, | 374 const base::FilePath& image_file, |
333 int image_resource_id) const { | 375 int image_resource_id) const { |
334 return (default_wallpaper_loader_.get() && | 376 return (default_wallpaper_loader_.get() && |
335 !default_wallpaper_loader_->IsCanceled() && | 377 !default_wallpaper_loader_->IsCanceled() && |
336 default_wallpaper_loader_->file_path() == image_file && | 378 default_wallpaper_loader_->file_path() == image_file && |
337 default_wallpaper_loader_->resource_id() == image_resource_id) || | 379 default_wallpaper_loader_->resource_id() == image_resource_id) || |
338 (current_wallpaper_.get() && | 380 (current_wallpaper_.get() && |
339 current_default_wallpaper_path_ == image_file && | 381 current_default_wallpaper_path_ == image_file && |
340 current_default_wallpaper_resource_id_ == image_resource_id); | 382 current_default_wallpaper_resource_id_ == image_resource_id); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
468 iter->rotation() == gfx::Display::ROTATE_270) { | 510 iter->rotation() == gfx::Display::ROTATE_270) { |
469 size_in_pixel = gfx::Size(size_in_pixel.height(), size_in_pixel.width()); | 511 size_in_pixel = gfx::Size(size_in_pixel.height(), size_in_pixel.width()); |
470 } | 512 } |
471 width = std::max(size_in_pixel.width(), width); | 513 width = std::max(size_in_pixel.width(), width); |
472 height = std::max(size_in_pixel.height(), height); | 514 height = std::max(size_in_pixel.height(), height); |
473 } | 515 } |
474 return gfx::Size(width, height); | 516 return gfx::Size(width, height); |
475 } | 517 } |
476 | 518 |
477 } // namespace ash | 519 } // namespace ash |
OLD | NEW |