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 25 matching lines...) Expand all Loading... |
36 | 36 |
37 namespace ash { | 37 namespace ash { |
38 namespace { | 38 namespace { |
39 | 39 |
40 // How long to wait reloading the wallpaper after the max display has | 40 // How long to wait reloading the wallpaper after the max display has |
41 // changed? | 41 // changed? |
42 const int kWallpaperReloadDelayMs = 2000; | 42 const int kWallpaperReloadDelayMs = 2000; |
43 | 43 |
44 } // namespace | 44 } // namespace |
45 | 45 |
| 46 const int DesktopBackgroundController::kInvalidResourceID = -1; |
| 47 |
46 DesktopBackgroundController::DesktopBackgroundController() | 48 DesktopBackgroundController::DesktopBackgroundController() |
47 : locked_(false), | 49 : locked_(false), |
48 desktop_background_mode_(BACKGROUND_NONE), | 50 desktop_background_mode_(BACKGROUND_NONE), |
49 wallpaper_reload_delay_(kWallpaperReloadDelayMs) { | 51 wallpaper_reload_delay_(kWallpaperReloadDelayMs) { |
50 Shell::GetInstance()->display_controller()->AddObserver(this); | 52 Shell::GetInstance()->display_controller()->AddObserver(this); |
51 } | 53 } |
52 | 54 |
53 DesktopBackgroundController::~DesktopBackgroundController() { | 55 DesktopBackgroundController::~DesktopBackgroundController() { |
54 Shell::GetInstance()->display_controller()->RemoveObserver(this); | 56 Shell::GetInstance()->display_controller()->RemoveObserver(this); |
55 } | 57 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 } | 93 } |
92 | 94 |
93 InstallDesktopController(root_window); | 95 InstallDesktopController(root_window); |
94 } | 96 } |
95 | 97 |
96 bool DesktopBackgroundController::SetWallpaperImage(const gfx::ImageSkia& image, | 98 bool DesktopBackgroundController::SetWallpaperImage(const gfx::ImageSkia& image, |
97 WallpaperLayout layout) { | 99 WallpaperLayout layout) { |
98 VLOG(1) << "SetWallpaper: image_id=" << WallpaperResizer::GetImageId(image) | 100 VLOG(1) << "SetWallpaper: image_id=" << WallpaperResizer::GetImageId(image) |
99 << " layout=" << layout; | 101 << " layout=" << layout; |
100 | 102 |
101 if (WallpaperIsAlreadyLoaded(&image, kInvalidResourceID, layout)) { | 103 if (WallpaperIsAlreadyLoaded( |
| 104 &image, kInvalidResourceID, true /* compare_layouts */, layout)) { |
102 VLOG(1) << "Wallpaper is already loaded"; | 105 VLOG(1) << "Wallpaper is already loaded"; |
103 return false; | 106 return false; |
104 } | 107 } |
105 | 108 |
106 current_wallpaper_.reset( | 109 current_wallpaper_.reset( |
107 new WallpaperResizer(image, GetMaxDisplaySizeInNative(), layout)); | 110 new WallpaperResizer(image, GetMaxDisplaySizeInNative(), layout)); |
108 current_wallpaper_->StartResize(); | 111 current_wallpaper_->StartResize(); |
109 | 112 |
110 FOR_EACH_OBSERVER(DesktopBackgroundControllerObserver, | 113 FOR_EACH_OBSERVER(DesktopBackgroundControllerObserver, |
111 observers_, | 114 observers_, |
112 OnWallpaperDataChanged()); | 115 OnWallpaperDataChanged()); |
113 SetDesktopBackgroundImageMode(); | 116 SetDesktopBackgroundImageMode(); |
114 return true; | 117 return true; |
115 } | 118 } |
116 | 119 |
117 bool DesktopBackgroundController::SetWallpaperResource(int resource_id, | 120 bool DesktopBackgroundController::SetWallpaperResource(int resource_id, |
118 WallpaperLayout layout) { | 121 WallpaperLayout layout) { |
119 VLOG(1) << "SetWallpaper: resource_id=" << resource_id | 122 VLOG(1) << "SetWallpaper: resource_id=" << resource_id |
120 << " layout=" << layout; | 123 << " layout=" << layout; |
121 | 124 |
122 if (WallpaperIsAlreadyLoaded(NULL, resource_id, layout)) { | 125 if (WallpaperIsAlreadyLoaded( |
| 126 NULL, resource_id, true /* compare_layouts */, layout)) { |
123 VLOG(1) << "Wallpaper is already loaded"; | 127 VLOG(1) << "Wallpaper is already loaded"; |
124 return false; | 128 return false; |
125 } | 129 } |
126 current_wallpaper_.reset( | 130 current_wallpaper_.reset( |
127 new WallpaperResizer(resource_id, GetMaxDisplaySizeInNative(), layout)); | 131 new WallpaperResizer(resource_id, GetMaxDisplaySizeInNative(), layout)); |
128 current_wallpaper_->StartResize(); | 132 current_wallpaper_->StartResize(); |
129 | 133 |
130 FOR_EACH_OBSERVER(DesktopBackgroundControllerObserver, observers_, | 134 FOR_EACH_OBSERVER(DesktopBackgroundControllerObserver, observers_, |
131 OnWallpaperDataChanged()); | 135 OnWallpaperDataChanged()); |
132 SetDesktopBackgroundImageMode(); | 136 SetDesktopBackgroundImageMode(); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 } | 191 } |
188 width = std::max(size_in_pixel.width(), width); | 192 width = std::max(size_in_pixel.width(), width); |
189 height = std::max(size_in_pixel.height(), height); | 193 height = std::max(size_in_pixel.height(), height); |
190 } | 194 } |
191 return gfx::Size(width, height); | 195 return gfx::Size(width, height); |
192 } | 196 } |
193 | 197 |
194 bool DesktopBackgroundController::WallpaperIsAlreadyLoaded( | 198 bool DesktopBackgroundController::WallpaperIsAlreadyLoaded( |
195 const gfx::ImageSkia* image, | 199 const gfx::ImageSkia* image, |
196 int resource_id, | 200 int resource_id, |
| 201 bool compare_layouts, |
197 WallpaperLayout layout) const { | 202 WallpaperLayout layout) const { |
198 if (!current_wallpaper_.get()) | 203 if (!current_wallpaper_.get()) |
199 return false; | 204 return false; |
200 | 205 |
201 if (layout != current_wallpaper_->layout()) | 206 // Compare layouts only if necessary. |
| 207 if (compare_layouts && layout != current_wallpaper_->layout()) |
202 return false; | 208 return false; |
203 | 209 |
204 if (image) { | 210 if (image) { |
205 return WallpaperResizer::GetImageId(*image) == | 211 return WallpaperResizer::GetImageId(*image) == |
206 current_wallpaper_->original_image_id(); | 212 current_wallpaper_->original_image_id(); |
207 } | 213 } |
208 | 214 |
209 return current_wallpaper_->resource_id() == resource_id; | 215 return current_wallpaper_->resource_id() == resource_id; |
210 } | 216 } |
211 | 217 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 : kShellWindowId_DesktopBackgroundContainer; | 294 : kShellWindowId_DesktopBackgroundContainer; |
289 } | 295 } |
290 | 296 |
291 void DesktopBackgroundController::UpdateWallpaper() { | 297 void DesktopBackgroundController::UpdateWallpaper() { |
292 current_wallpaper_.reset(NULL); | 298 current_wallpaper_.reset(NULL); |
293 ash::Shell::GetInstance()->user_wallpaper_delegate()-> | 299 ash::Shell::GetInstance()->user_wallpaper_delegate()-> |
294 UpdateWallpaper(true /* clear cache */); | 300 UpdateWallpaper(true /* clear cache */); |
295 } | 301 } |
296 | 302 |
297 } // namespace ash | 303 } // namespace ash |
OLD | NEW |