Chromium Code Reviews| 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 15 matching lines...) Expand all Loading... | |
| 26 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
| 27 #include "grit/ash_resources.h" | 27 #include "grit/ash_resources.h" |
| 28 #include "ui/aura/window.h" | 28 #include "ui/aura/window.h" |
| 29 #include "ui/aura/window_event_dispatcher.h" | 29 #include "ui/aura/window_event_dispatcher.h" |
| 30 #include "ui/compositor/layer.h" | 30 #include "ui/compositor/layer.h" |
| 31 #include "ui/gfx/codec/jpeg_codec.h" | 31 #include "ui/gfx/codec/jpeg_codec.h" |
| 32 #include "ui/gfx/image/image_skia.h" | 32 #include "ui/gfx/image/image_skia.h" |
| 33 #include "ui/gfx/rect.h" | 33 #include "ui/gfx/rect.h" |
| 34 #include "ui/views/widget/widget.h" | 34 #include "ui/views/widget/widget.h" |
| 35 | 35 |
| 36 #if defined(OS_CHROMEOS) | |
| 37 #include "chrome/browser/chromeos/login/wallpaper_manager.h" | |
|
Daniel Erat
2014/03/24 16:25:48
ash isn't allowed to depend on chrome. you need to
Alexander Alekseev
2014/03/24 17:33:43
Done.
| |
| 38 #endif | |
| 39 | |
| 36 using ash::internal::DesktopBackgroundWidgetController; | 40 using ash::internal::DesktopBackgroundWidgetController; |
| 37 using content::BrowserThread; | 41 using content::BrowserThread; |
| 38 | 42 |
| 39 namespace ash { | 43 namespace ash { |
| 40 namespace { | 44 namespace { |
| 41 | 45 |
| 42 // How long to wait reloading the wallpaper after the max display has | 46 // How long to wait reloading the wallpaper after the max display has |
| 43 // changed? | 47 // changed? |
| 44 const int kWallpaperReloadDelayMs = 2000; | 48 const int kWallpaperReloadDelayMs = 2000; |
| 45 | 49 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 | 157 |
| 154 DISALLOW_COPY_AND_ASSIGN(WallpaperLoader); | 158 DISALLOW_COPY_AND_ASSIGN(WallpaperLoader); |
| 155 }; | 159 }; |
| 156 | 160 |
| 157 DesktopBackgroundController::DesktopBackgroundController() | 161 DesktopBackgroundController::DesktopBackgroundController() |
| 158 : command_line_for_testing_(NULL), | 162 : command_line_for_testing_(NULL), |
| 159 locked_(false), | 163 locked_(false), |
| 160 desktop_background_mode_(BACKGROUND_NONE), | 164 desktop_background_mode_(BACKGROUND_NONE), |
| 161 current_default_wallpaper_resource_id_(-1), | 165 current_default_wallpaper_resource_id_(-1), |
| 162 weak_ptr_factory_(this), | 166 weak_ptr_factory_(this), |
| 163 wallpaper_reload_delay_(kWallpaperReloadDelayMs) { | 167 wallpaper_reload_delay_(kWallpaperReloadDelayMs), |
| 168 customization_applied_(false) { | |
| 164 Shell::GetInstance()->display_controller()->AddObserver(this); | 169 Shell::GetInstance()->display_controller()->AddObserver(this); |
| 165 } | 170 } |
| 166 | 171 |
| 167 DesktopBackgroundController::~DesktopBackgroundController() { | 172 DesktopBackgroundController::~DesktopBackgroundController() { |
| 168 CancelDefaultWallpaperLoader(); | 173 CancelDefaultWallpaperLoader(); |
| 169 Shell::GetInstance()->display_controller()->RemoveObserver(this); | 174 Shell::GetInstance()->display_controller()->RemoveObserver(this); |
| 170 } | 175 } |
| 171 | 176 |
| 172 gfx::ImageSkia DesktopBackgroundController::GetWallpaper() const { | 177 gfx::ImageSkia DesktopBackgroundController::GetWallpaper() const { |
| 173 if (current_wallpaper_) | 178 if (current_wallpaper_) |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 201 if (current_max_display_size_ != max_display_size) { | 206 if (current_max_display_size_ != max_display_size) { |
| 202 current_max_display_size_ = max_display_size; | 207 current_max_display_size_ = max_display_size; |
| 203 if (desktop_background_mode_ == BACKGROUND_IMAGE && | 208 if (desktop_background_mode_ == BACKGROUND_IMAGE && |
| 204 current_wallpaper_.get()) | 209 current_wallpaper_.get()) |
| 205 UpdateWallpaper(); | 210 UpdateWallpaper(); |
| 206 } | 211 } |
| 207 | 212 |
| 208 InstallDesktopController(root_window); | 213 InstallDesktopController(root_window); |
| 209 } | 214 } |
| 210 | 215 |
| 216 void DesktopBackgroundController::CheckForCustomization() { | |
| 217 #if defined(OS_CHROMEOS) | |
| 218 if (customization_applied_) | |
| 219 return; | |
| 220 customization_applied_ = true; | |
| 221 | |
| 222 if (chromeos::WallpaperManager::ShouldUseCustomizedDefaultWallpaper()) { | |
| 223 customized_default_wallpaper_file_small_ = chromeos::WallpaperManager:: | |
| 224 GetCustomizedWallpaperDefaultRescaledSmallFileName(); | |
| 225 customized_default_wallpaper_file_large_ = chromeos::WallpaperManager:: | |
| 226 GetCustomizedWallpaperDefaultRescaledLargeFileName(); | |
| 227 VLOG(1) << "Start with customized wallpapers: small_file_name = '" | |
| 228 << customized_default_wallpaper_file_small_.value() | |
| 229 << "', large_file_name = '" | |
| 230 << customized_default_wallpaper_file_large_.value() << "'"; | |
| 231 } | |
| 232 #endif | |
| 233 } | |
| 234 | |
| 211 bool DesktopBackgroundController::SetDefaultWallpaper(bool is_guest) { | 235 bool DesktopBackgroundController::SetDefaultWallpaper(bool is_guest) { |
| 212 VLOG(1) << "SetDefaultWallpaper: is_guest=" << is_guest; | 236 VLOG(1) << "SetDefaultWallpaper: is_guest=" << is_guest; |
| 213 const bool use_large = | 237 const bool use_large = |
| 214 GetAppropriateResolution() == WALLPAPER_RESOLUTION_LARGE; | 238 GetAppropriateResolution() == WALLPAPER_RESOLUTION_LARGE; |
| 239 CommandLine* command_line = command_line_for_testing_ ? | |
| 240 command_line_for_testing_ : CommandLine::ForCurrentProcess(); | |
| 241 | |
| 242 CheckForCustomization(); | |
| 215 | 243 |
| 216 base::FilePath file_path; | 244 base::FilePath file_path; |
| 217 WallpaperLayout file_layout = use_large ? WALLPAPER_LAYOUT_CENTER_CROPPED : | 245 if (is_guest) { |
| 218 WALLPAPER_LAYOUT_CENTER; | 246 const char* switch_name = use_large ? switches::kAshGuestWallpaperLarge |
| 219 int resource_id = use_large ? IDR_AURA_WALLPAPER_DEFAULT_LARGE : | 247 : switches::kAshGuestWallpaperSmall; |
| 220 IDR_AURA_WALLPAPER_DEFAULT_SMALL; | 248 file_path = command_line->GetSwitchValuePath(switch_name); |
| 249 } else if (use_large && !customized_default_wallpaper_file_large_.empty()) { | |
| 250 file_path = customized_default_wallpaper_file_large_; | |
| 251 } else if (!use_large && !customized_default_wallpaper_file_small_.empty()) { | |
| 252 file_path = customized_default_wallpaper_file_small_; | |
| 253 } else { | |
| 254 const char* switch_name = use_large ? switches::kAshDefaultWallpaperLarge | |
| 255 : switches::kAshDefaultWallpaperSmall; | |
| 256 file_path = command_line->GetSwitchValuePath(switch_name); | |
| 257 } | |
| 258 return DoSetDefaultWallpaper(file_path, use_large); | |
| 259 } | |
| 260 | |
| 261 bool DesktopBackgroundController::DoSetDefaultWallpaper( | |
| 262 const base::FilePath& file_path, | |
| 263 const bool use_large) { | |
| 264 WallpaperLayout file_layout = | |
| 265 use_large ? WALLPAPER_LAYOUT_CENTER_CROPPED : WALLPAPER_LAYOUT_CENTER; | |
| 266 int resource_id = use_large ? IDR_AURA_WALLPAPER_DEFAULT_LARGE | |
| 267 : IDR_AURA_WALLPAPER_DEFAULT_SMALL; | |
| 221 WallpaperLayout resource_layout = WALLPAPER_LAYOUT_TILE; | 268 WallpaperLayout resource_layout = WALLPAPER_LAYOUT_TILE; |
| 222 | 269 |
| 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 | |
| 235 if (DefaultWallpaperIsAlreadyLoadingOrLoaded(file_path, resource_id)) { | 270 if (DefaultWallpaperIsAlreadyLoadingOrLoaded(file_path, resource_id)) { |
| 236 VLOG(1) << "Default wallpaper is already loading or loaded"; | 271 VLOG(1) << "Default wallpaper is already loading or loaded"; |
| 237 return false; | 272 return false; |
| 238 } | 273 } |
| 239 | 274 |
| 240 CancelDefaultWallpaperLoader(); | 275 CancelDefaultWallpaperLoader(); |
| 241 default_wallpaper_loader_ = new WallpaperLoader( | 276 default_wallpaper_loader_ = new WallpaperLoader( |
| 242 file_path, file_layout, resource_id, resource_layout); | 277 file_path, file_layout, resource_id, resource_layout); |
| 243 base::WorkerPool::PostTaskAndReply( | 278 base::WorkerPool::PostTaskAndReply( |
| 244 FROM_HERE, | 279 FROM_HERE, |
| 245 base::Bind(&WallpaperLoader::LoadOnWorkerPoolThread, | 280 base::Bind(&WallpaperLoader::LoadOnWorkerPoolThread, |
| 246 default_wallpaper_loader_), | 281 default_wallpaper_loader_), |
| 247 base::Bind(&DesktopBackgroundController::OnDefaultWallpaperLoadCompleted, | 282 base::Bind(&DesktopBackgroundController::OnDefaultWallpaperLoadCompleted, |
| 248 weak_ptr_factory_.GetWeakPtr(), | 283 weak_ptr_factory_.GetWeakPtr(), |
| 249 default_wallpaper_loader_), | 284 default_wallpaper_loader_), |
| 250 true /* task_is_slow */); | 285 true /* task_is_slow */); |
| 251 return true; | 286 return true; |
| 252 } | 287 } |
| 253 | 288 |
| 289 void DesktopBackgroundController::SetDefaultWallpaperPath( | |
| 290 const base::FilePath& customized_default_wallpaper_file_small, | |
| 291 const base::FilePath& customized_default_wallpaper_file_large) { | |
| 292 customization_applied_ = true; | |
| 293 const bool need_reset = DefaultWallpaperFileIsAlreadyLoadingOrLoaded( | |
| 294 customized_default_wallpaper_file_small_) || | |
| 295 DefaultWallpaperFileIsAlreadyLoadingOrLoaded( | |
| 296 customized_default_wallpaper_file_large_); | |
|
Daniel Erat
2014/03/24 16:25:48
why is all this stuff necessary? does the followin
Alexander Alekseev
2014/03/24 17:33:43
Done.
| |
| 297 customized_default_wallpaper_file_small_ = | |
| 298 customized_default_wallpaper_file_small; | |
| 299 customized_default_wallpaper_file_large_ = | |
| 300 customized_default_wallpaper_file_large; | |
| 301 if (need_reset) { | |
| 302 const bool use_large = | |
| 303 GetAppropriateResolution() == WALLPAPER_RESOLUTION_LARGE; | |
| 304 DoSetDefaultWallpaper( | |
| 305 (use_large ? customized_default_wallpaper_file_large_ | |
| 306 : customized_default_wallpaper_file_small_), | |
| 307 use_large); | |
| 308 } | |
| 309 } | |
| 310 | |
| 254 void DesktopBackgroundController::SetCustomWallpaper( | 311 void DesktopBackgroundController::SetCustomWallpaper( |
| 255 const gfx::ImageSkia& image, | 312 const gfx::ImageSkia& image, |
| 256 WallpaperLayout layout) { | 313 WallpaperLayout layout) { |
| 257 VLOG(1) << "SetCustomWallpaper: image_id=" | 314 VLOG(1) << "SetCustomWallpaper: image_id=" |
| 258 << WallpaperResizer::GetImageId(image) << " layout=" << layout; | 315 << WallpaperResizer::GetImageId(image) << " layout=" << layout; |
| 259 CancelDefaultWallpaperLoader(); | 316 CancelDefaultWallpaperLoader(); |
| 260 | 317 |
| 261 if (CustomWallpaperIsAlreadyLoaded(image)) { | 318 if (CustomWallpaperIsAlreadyLoaded(image)) { |
| 262 VLOG(1) << "Custom wallpaper is already loaded"; | 319 VLOG(1) << "Custom wallpaper is already loaded"; |
| 263 return; | 320 return; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 333 int image_resource_id) const { | 390 int image_resource_id) const { |
| 334 return (default_wallpaper_loader_.get() && | 391 return (default_wallpaper_loader_.get() && |
| 335 !default_wallpaper_loader_->IsCanceled() && | 392 !default_wallpaper_loader_->IsCanceled() && |
| 336 default_wallpaper_loader_->file_path() == image_file && | 393 default_wallpaper_loader_->file_path() == image_file && |
| 337 default_wallpaper_loader_->resource_id() == image_resource_id) || | 394 default_wallpaper_loader_->resource_id() == image_resource_id) || |
| 338 (current_wallpaper_.get() && | 395 (current_wallpaper_.get() && |
| 339 current_default_wallpaper_path_ == image_file && | 396 current_default_wallpaper_path_ == image_file && |
| 340 current_default_wallpaper_resource_id_ == image_resource_id); | 397 current_default_wallpaper_resource_id_ == image_resource_id); |
| 341 } | 398 } |
| 342 | 399 |
| 400 bool DesktopBackgroundController::DefaultWallpaperFileIsAlreadyLoadingOrLoaded( | |
| 401 const base::FilePath& image_file) const { | |
|
Daniel Erat
2014/03/24 16:25:48
why do you need this method? it looks like it's mo
Alexander Alekseev
2014/03/24 17:33:43
I need to detect the usage of default wallpaper re
Daniel Erat
2014/03/24 19:19:43
resource_id is just a fallback that we use if we c
Alexander Alekseev
2014/03/24 19:52:58
bool DesktopBackgroundController::DoSetDefaultWall
| |
| 402 return (default_wallpaper_loader_.get() && | |
| 403 !default_wallpaper_loader_->IsCanceled() && | |
| 404 default_wallpaper_loader_->file_path() == image_file) || | |
| 405 (current_wallpaper_.get() && | |
| 406 current_default_wallpaper_path_ == image_file); | |
| 407 } | |
| 408 | |
| 343 bool DesktopBackgroundController::CustomWallpaperIsAlreadyLoaded( | 409 bool DesktopBackgroundController::CustomWallpaperIsAlreadyLoaded( |
| 344 const gfx::ImageSkia& image) const { | 410 const gfx::ImageSkia& image) const { |
| 345 return current_wallpaper_.get() && | 411 return current_wallpaper_.get() && |
| 346 (WallpaperResizer::GetImageId(image) == | 412 (WallpaperResizer::GetImageId(image) == |
| 347 current_wallpaper_->original_image_id()); | 413 current_wallpaper_->original_image_id()); |
| 348 } | 414 } |
| 349 | 415 |
| 350 void DesktopBackgroundController::SetDesktopBackgroundImageMode() { | 416 void DesktopBackgroundController::SetDesktopBackgroundImageMode() { |
| 351 desktop_background_mode_ = BACKGROUND_IMAGE; | 417 desktop_background_mode_ = BACKGROUND_IMAGE; |
| 352 InstallDesktopControllerForAllWindows(); | 418 InstallDesktopControllerForAllWindows(); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 468 iter->rotation() == gfx::Display::ROTATE_270) { | 534 iter->rotation() == gfx::Display::ROTATE_270) { |
| 469 size_in_pixel = gfx::Size(size_in_pixel.height(), size_in_pixel.width()); | 535 size_in_pixel = gfx::Size(size_in_pixel.height(), size_in_pixel.width()); |
| 470 } | 536 } |
| 471 width = std::max(size_in_pixel.width(), width); | 537 width = std::max(size_in_pixel.width(), width); |
| 472 height = std::max(size_in_pixel.height(), height); | 538 height = std::max(size_in_pixel.height(), height); |
| 473 } | 539 } |
| 474 return gfx::Size(width, height); | 540 return gfx::Size(width, height); |
| 475 } | 541 } |
| 476 | 542 |
| 477 } // namespace ash | 543 } // namespace ash |
| OLD | NEW |