| 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 30 matching lines...) Expand all Loading... |
| 41 // changed? | 41 // changed? |
| 42 const int kWallpaperReloadDelayMs = 2000; | 42 const int kWallpaperReloadDelayMs = 2000; |
| 43 | 43 |
| 44 } // namespace | 44 } // namespace |
| 45 | 45 |
| 46 DesktopBackgroundController::DesktopBackgroundController() | 46 DesktopBackgroundController::DesktopBackgroundController() |
| 47 : locked_(false), | 47 : locked_(false), |
| 48 desktop_background_mode_(BACKGROUND_NONE), | 48 desktop_background_mode_(BACKGROUND_NONE), |
| 49 wallpaper_reload_delay_(kWallpaperReloadDelayMs) { | 49 wallpaper_reload_delay_(kWallpaperReloadDelayMs) { |
| 50 Shell::GetInstance()->display_controller()->AddObserver(this); | 50 Shell::GetInstance()->display_controller()->AddObserver(this); |
| 51 Shell::GetInstance()->AddShellObserver(this); |
| 51 } | 52 } |
| 52 | 53 |
| 53 DesktopBackgroundController::~DesktopBackgroundController() { | 54 DesktopBackgroundController::~DesktopBackgroundController() { |
| 54 Shell::GetInstance()->display_controller()->RemoveObserver(this); | 55 Shell::GetInstance()->display_controller()->RemoveObserver(this); |
| 56 Shell::GetInstance()->RemoveShellObserver(this); |
| 55 } | 57 } |
| 56 | 58 |
| 57 gfx::ImageSkia DesktopBackgroundController::GetWallpaper() const { | 59 gfx::ImageSkia DesktopBackgroundController::GetWallpaper() const { |
| 58 if (current_wallpaper_) | 60 if (current_wallpaper_) |
| 59 return current_wallpaper_->image(); | 61 return current_wallpaper_->image(); |
| 60 return gfx::ImageSkia(); | 62 return gfx::ImageSkia(); |
| 61 } | 63 } |
| 62 | 64 |
| 63 void DesktopBackgroundController::AddObserver( | 65 void DesktopBackgroundController::AddObserver( |
| 64 DesktopBackgroundControllerObserver* observer) { | 66 DesktopBackgroundControllerObserver* observer) { |
| 65 observers_.AddObserver(observer); | 67 observers_.AddObserver(observer); |
| 66 } | 68 } |
| 67 | 69 |
| 68 void DesktopBackgroundController::RemoveObserver( | 70 void DesktopBackgroundController::RemoveObserver( |
| 69 DesktopBackgroundControllerObserver* observer) { | 71 DesktopBackgroundControllerObserver* observer) { |
| 70 observers_.RemoveObserver(observer); | 72 observers_.RemoveObserver(observer); |
| 71 } | 73 } |
| 72 | 74 |
| 73 WallpaperLayout DesktopBackgroundController::GetWallpaperLayout() const { | 75 WallpaperLayout DesktopBackgroundController::GetWallpaperLayout() const { |
| 74 if (current_wallpaper_) | 76 if (current_wallpaper_) |
| 75 return current_wallpaper_->layout(); | 77 return current_wallpaper_->layout(); |
| 76 return WALLPAPER_LAYOUT_CENTER_CROPPED; | 78 return WALLPAPER_LAYOUT_CENTER_CROPPED; |
| 77 } | 79 } |
| 78 | 80 |
| 79 void DesktopBackgroundController::OnRootWindowAdded(aura::Window* root_window) { | |
| 80 // The background hasn't been set yet. | |
| 81 if (desktop_background_mode_ == BACKGROUND_NONE) | |
| 82 return; | |
| 83 | |
| 84 // Handle resolution change for "built-in" images. | |
| 85 gfx::Size max_display_size = GetMaxDisplaySizeInNative(); | |
| 86 if (current_max_display_size_ != max_display_size) { | |
| 87 current_max_display_size_ = max_display_size; | |
| 88 if (desktop_background_mode_ == BACKGROUND_IMAGE && | |
| 89 current_wallpaper_.get()) | |
| 90 UpdateWallpaper(); | |
| 91 } | |
| 92 | |
| 93 InstallDesktopController(root_window); | |
| 94 } | |
| 95 | |
| 96 bool DesktopBackgroundController::SetWallpaperImage(const gfx::ImageSkia& image, | 81 bool DesktopBackgroundController::SetWallpaperImage(const gfx::ImageSkia& image, |
| 97 WallpaperLayout layout) { | 82 WallpaperLayout layout) { |
| 98 VLOG(1) << "SetWallpaper: image_id=" << WallpaperResizer::GetImageId(image) | 83 VLOG(1) << "SetWallpaper: image_id=" << WallpaperResizer::GetImageId(image) |
| 99 << " layout=" << layout; | 84 << " layout=" << layout; |
| 100 | 85 |
| 101 if (WallpaperIsAlreadyLoaded(&image, kInvalidResourceID, layout)) { | 86 if (WallpaperIsAlreadyLoaded(&image, kInvalidResourceID, layout)) { |
| 102 VLOG(1) << "Wallpaper is already loaded"; | 87 VLOG(1) << "Wallpaper is already loaded"; |
| 103 return false; | 88 return false; |
| 104 } | 89 } |
| 105 | 90 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 current_wallpaper_.get()) { | 147 current_wallpaper_.get()) { |
| 163 timer_.Stop(); | 148 timer_.Stop(); |
| 164 timer_.Start(FROM_HERE, | 149 timer_.Start(FROM_HERE, |
| 165 base::TimeDelta::FromMilliseconds(wallpaper_reload_delay_), | 150 base::TimeDelta::FromMilliseconds(wallpaper_reload_delay_), |
| 166 this, | 151 this, |
| 167 &DesktopBackgroundController::UpdateWallpaper); | 152 &DesktopBackgroundController::UpdateWallpaper); |
| 168 } | 153 } |
| 169 } | 154 } |
| 170 } | 155 } |
| 171 | 156 |
| 157 void DesktopBackgroundController::OnRootWindowAdded(aura::Window* root_window) { |
| 158 // The background hasn't been set yet. |
| 159 if (desktop_background_mode_ == BACKGROUND_NONE) |
| 160 return; |
| 161 |
| 162 // Handle resolution change for "built-in" images. |
| 163 gfx::Size max_display_size = GetMaxDisplaySizeInNative(); |
| 164 if (current_max_display_size_ != max_display_size) { |
| 165 current_max_display_size_ = max_display_size; |
| 166 if (desktop_background_mode_ == BACKGROUND_IMAGE && |
| 167 current_wallpaper_.get()) |
| 168 UpdateWallpaper(); |
| 169 } |
| 170 |
| 171 InstallDesktopController(root_window); |
| 172 } |
| 173 |
| 172 // static | 174 // static |
| 173 gfx::Size DesktopBackgroundController::GetMaxDisplaySizeInNative() { | 175 gfx::Size DesktopBackgroundController::GetMaxDisplaySizeInNative() { |
| 174 int width = 0; | 176 int width = 0; |
| 175 int height = 0; | 177 int height = 0; |
| 176 std::vector<gfx::Display> displays = Shell::GetScreen()->GetAllDisplays(); | 178 std::vector<gfx::Display> displays = Shell::GetScreen()->GetAllDisplays(); |
| 177 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 179 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 178 | 180 |
| 179 for (std::vector<gfx::Display>::iterator iter = displays.begin(); | 181 for (std::vector<gfx::Display>::iterator iter = displays.begin(); |
| 180 iter != displays.end(); ++iter) { | 182 iter != displays.end(); ++iter) { |
| 181 // Don't use size_in_pixel because we want to use the native pixel size. | 183 // Don't use size_in_pixel because we want to use the native pixel size. |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 : kShellWindowId_DesktopBackgroundContainer; | 290 : kShellWindowId_DesktopBackgroundContainer; |
| 289 } | 291 } |
| 290 | 292 |
| 291 void DesktopBackgroundController::UpdateWallpaper() { | 293 void DesktopBackgroundController::UpdateWallpaper() { |
| 292 current_wallpaper_.reset(NULL); | 294 current_wallpaper_.reset(NULL); |
| 293 ash::Shell::GetInstance()->user_wallpaper_delegate()-> | 295 ash::Shell::GetInstance()->user_wallpaper_delegate()-> |
| 294 UpdateWallpaper(true /* clear cache */); | 296 UpdateWallpaper(true /* clear cache */); |
| 295 } | 297 } |
| 296 | 298 |
| 297 } // namespace ash | 299 } // namespace ash |
| OLD | NEW |