| 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 return; | 113 return; |
| 114 | 114 |
| 115 if (!file_path_.empty()) | 115 if (!file_path_.empty()) |
| 116 file_bitmap_ = LoadSkBitmapFromJPEGFile(file_path_); | 116 file_bitmap_ = LoadSkBitmapFromJPEGFile(file_path_); |
| 117 | 117 |
| 118 if (cancel_flag_.IsSet()) | 118 if (cancel_flag_.IsSet()) |
| 119 return; | 119 return; |
| 120 | 120 |
| 121 if (file_bitmap_) { | 121 if (file_bitmap_) { |
| 122 gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(*file_bitmap_); | 122 gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(*file_bitmap_); |
| 123 image.MakeThreadSafe(); |
| 123 wallpaper_resizer_.reset(new WallpaperResizer( | 124 wallpaper_resizer_.reset(new WallpaperResizer( |
| 124 image, GetMaxDisplaySizeInNative(), file_layout_)); | 125 image, GetMaxDisplaySizeInNative(), file_layout_)); |
| 125 } else { | 126 } else { |
| 126 wallpaper_resizer_.reset(new WallpaperResizer( | 127 wallpaper_resizer_.reset(new WallpaperResizer( |
| 127 resource_id_, GetMaxDisplaySizeInNative(), resource_layout_)); | 128 resource_id_, GetMaxDisplaySizeInNative(), resource_layout_)); |
| 128 } | 129 } |
| 129 } | 130 } |
| 130 | 131 |
| 131 ~WallpaperLoader() {} | 132 ~WallpaperLoader() {} |
| 132 | 133 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 162 Shell::GetInstance()->display_controller()->AddObserver(this); | 163 Shell::GetInstance()->display_controller()->AddObserver(this); |
| 163 } | 164 } |
| 164 | 165 |
| 165 DesktopBackgroundController::~DesktopBackgroundController() { | 166 DesktopBackgroundController::~DesktopBackgroundController() { |
| 166 CancelPendingWallpaperOperation(); | 167 CancelPendingWallpaperOperation(); |
| 167 Shell::GetInstance()->display_controller()->RemoveObserver(this); | 168 Shell::GetInstance()->display_controller()->RemoveObserver(this); |
| 168 } | 169 } |
| 169 | 170 |
| 170 gfx::ImageSkia DesktopBackgroundController::GetWallpaper() const { | 171 gfx::ImageSkia DesktopBackgroundController::GetWallpaper() const { |
| 171 if (current_wallpaper_) | 172 if (current_wallpaper_) |
| 172 return current_wallpaper_->wallpaper_image(); | 173 return current_wallpaper_->image(); |
| 173 return gfx::ImageSkia(); | 174 return gfx::ImageSkia(); |
| 174 } | 175 } |
| 175 | 176 |
| 176 void DesktopBackgroundController::AddObserver( | 177 void DesktopBackgroundController::AddObserver( |
| 177 DesktopBackgroundControllerObserver* observer) { | 178 DesktopBackgroundControllerObserver* observer) { |
| 178 observers_.AddObserver(observer); | 179 observers_.AddObserver(observer); |
| 179 } | 180 } |
| 180 | 181 |
| 181 void DesktopBackgroundController::RemoveObserver( | 182 void DesktopBackgroundController::RemoveObserver( |
| 182 DesktopBackgroundControllerObserver* observer) { | 183 DesktopBackgroundControllerObserver* observer) { |
| 183 observers_.RemoveObserver(observer); | 184 observers_.RemoveObserver(observer); |
| 184 } | 185 } |
| 185 | 186 |
| 186 WallpaperLayout DesktopBackgroundController::GetWallpaperLayout() const { | 187 WallpaperLayout DesktopBackgroundController::GetWallpaperLayout() const { |
| 187 if (current_wallpaper_) | 188 if (current_wallpaper_) |
| 188 return current_wallpaper_->layout(); | 189 return current_wallpaper_->layout(); |
| 189 return WALLPAPER_LAYOUT_CENTER_CROPPED; | 190 return WALLPAPER_LAYOUT_CENTER_CROPPED; |
| 190 } | 191 } |
| 191 | 192 |
| 192 void DesktopBackgroundController::OnRootWindowAdded( | 193 void DesktopBackgroundController::OnRootWindowAdded( |
| 193 aura::Window* root_window) { | 194 aura::Window* root_window) { |
| 194 // The background hasn't been set yet. | 195 // The background hasn't been set yet. |
| 195 if (desktop_background_mode_ == BACKGROUND_NONE) | 196 if (desktop_background_mode_ == BACKGROUND_NONE) |
| 196 return; | 197 return; |
| 197 gfx::Size max_display_size = GetMaxDisplaySizeInNative(); | 198 gfx::Size max_display_size = GetMaxDisplaySizeInNative(); |
| 198 // Handle resolution change for "built-in" images. | 199 // Handle resolution change for "built-in" images. |
| 199 if (BACKGROUND_IMAGE == desktop_background_mode_ && | 200 if (desktop_background_mode_ == BACKGROUND_IMAGE && |
| 200 current_wallpaper_.get() && | 201 current_wallpaper_.get() && |
| 201 current_max_display_size_ != max_display_size) { | 202 current_max_display_size_ != max_display_size) { |
| 202 current_max_display_size_ = max_display_size; | 203 current_max_display_size_ = max_display_size; |
| 203 UpdateWallpaper(); | 204 UpdateWallpaper(); |
| 204 } | 205 } |
| 205 | 206 |
| 206 InstallDesktopController(root_window); | 207 InstallDesktopController(root_window); |
| 207 } | 208 } |
| 208 | 209 |
| 209 bool DesktopBackgroundController::SetDefaultWallpaper(bool is_guest) { | 210 bool DesktopBackgroundController::SetDefaultWallpaper(bool is_guest) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 bool DesktopBackgroundController::MoveDesktopToUnlockedContainer() { | 298 bool DesktopBackgroundController::MoveDesktopToUnlockedContainer() { |
| 298 if (!locked_) | 299 if (!locked_) |
| 299 return false; | 300 return false; |
| 300 locked_ = false; | 301 locked_ = false; |
| 301 return ReparentBackgroundWidgets(GetBackgroundContainerId(true), | 302 return ReparentBackgroundWidgets(GetBackgroundContainerId(true), |
| 302 GetBackgroundContainerId(false)); | 303 GetBackgroundContainerId(false)); |
| 303 } | 304 } |
| 304 | 305 |
| 305 void DesktopBackgroundController::OnDisplayConfigurationChanged() { | 306 void DesktopBackgroundController::OnDisplayConfigurationChanged() { |
| 306 gfx::Size max_display_size = GetMaxDisplaySizeInNative(); | 307 gfx::Size max_display_size = GetMaxDisplaySizeInNative(); |
| 307 if (current_max_display_size_ != max_display_size) { | 308 if (desktop_background_mode_ == BACKGROUND_IMAGE && |
| 309 current_wallpaper_.get() && |
| 310 current_max_display_size_ != max_display_size) { |
| 308 current_max_display_size_ = max_display_size; | 311 current_max_display_size_ = max_display_size; |
| 309 timer_.Stop(); | 312 timer_.Stop(); |
| 310 timer_.Start(FROM_HERE, | 313 timer_.Start(FROM_HERE, |
| 311 base::TimeDelta::FromMilliseconds(wallpaper_reload_delay_), | 314 base::TimeDelta::FromMilliseconds(wallpaper_reload_delay_), |
| 312 this, | 315 this, |
| 313 &DesktopBackgroundController::UpdateWallpaper); | 316 &DesktopBackgroundController::UpdateWallpaper); |
| 314 } | 317 } |
| 315 } | 318 } |
| 316 | 319 |
| 317 bool DesktopBackgroundController::DefaultWallpaperIsAlreadyLoadingOrLoaded( | 320 bool DesktopBackgroundController::DefaultWallpaperIsAlreadyLoadingOrLoaded( |
| 318 const base::FilePath& image_file, int image_resource_id) const { | 321 const base::FilePath& image_file, int image_resource_id) const { |
| 319 return (wallpaper_loader_.get() && | 322 return (wallpaper_loader_.get() && |
| 320 wallpaper_loader_->file_path() == image_file && | 323 wallpaper_loader_->file_path() == image_file && |
| 321 wallpaper_loader_->resource_id() == image_resource_id) || | 324 wallpaper_loader_->resource_id() == image_resource_id) || |
| 322 (current_wallpaper_.get() && | 325 (current_wallpaper_.get() && |
| 323 current_default_wallpaper_path_ == image_file && | 326 current_default_wallpaper_path_ == image_file && |
| 324 current_default_wallpaper_resource_id_ == image_resource_id); | 327 current_default_wallpaper_resource_id_ == image_resource_id); |
| 325 } | 328 } |
| 326 | 329 |
| 327 bool DesktopBackgroundController::CustomWallpaperIsAlreadyLoaded( | 330 bool DesktopBackgroundController::CustomWallpaperIsAlreadyLoaded( |
| 328 const gfx::ImageSkia& image) const { | 331 const gfx::ImageSkia& image) const { |
| 329 return current_wallpaper_.get() && | 332 return current_wallpaper_.get() && |
| 330 current_wallpaper_->wallpaper_image().BackedBySameObjectAs(image); | 333 (WallpaperResizer::GetImageId(image) == |
| 334 current_wallpaper_->original_image_id()); |
| 331 } | 335 } |
| 332 | 336 |
| 333 void DesktopBackgroundController::SetDesktopBackgroundImageMode() { | 337 void DesktopBackgroundController::SetDesktopBackgroundImageMode() { |
| 334 desktop_background_mode_ = BACKGROUND_IMAGE; | 338 desktop_background_mode_ = BACKGROUND_IMAGE; |
| 335 InstallDesktopControllerForAllWindows(); | 339 InstallDesktopControllerForAllWindows(); |
| 336 } | 340 } |
| 337 | 341 |
| 338 void DesktopBackgroundController::OnDefaultWallpaperLoadCompleted( | 342 void DesktopBackgroundController::OnDefaultWallpaperLoadCompleted( |
| 339 scoped_refptr<WallpaperLoader> loader) { | 343 scoped_refptr<WallpaperLoader> loader) { |
| 340 current_wallpaper_.reset(loader->ReleaseWallpaperResizer()); | 344 current_wallpaper_.reset(loader->ReleaseWallpaperResizer()); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 iter->rotation() == gfx::Display::ROTATE_270) { | 454 iter->rotation() == gfx::Display::ROTATE_270) { |
| 451 size_in_pixel = gfx::Size(size_in_pixel.height(), size_in_pixel.width()); | 455 size_in_pixel = gfx::Size(size_in_pixel.height(), size_in_pixel.width()); |
| 452 } | 456 } |
| 453 width = std::max(size_in_pixel.width(), width); | 457 width = std::max(size_in_pixel.width(), width); |
| 454 height = std::max(size_in_pixel.height(), height); | 458 height = std::max(size_in_pixel.height(), height); |
| 455 } | 459 } |
| 456 return gfx::Size(width, height); | 460 return gfx::Size(width, height); |
| 457 } | 461 } |
| 458 | 462 |
| 459 } // namespace ash | 463 } // namespace ash |
| OLD | NEW |