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/desktop_background/desktop_background_view.h" | 7 #include "ash/desktop_background/desktop_background_view.h" |
8 #include "ash/desktop_background/desktop_background_widget_controller.h" | 8 #include "ash/desktop_background/desktop_background_widget_controller.h" |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/shell_factory.h" | 10 #include "ash/shell_factory.h" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 const WallpaperResolution resolution_; | 99 const WallpaperResolution resolution_; |
100 | 100 |
101 DISALLOW_COPY_AND_ASSIGN(WallpaperOperation); | 101 DISALLOW_COPY_AND_ASSIGN(WallpaperOperation); |
102 }; | 102 }; |
103 | 103 |
104 DesktopBackgroundController::DesktopBackgroundController() | 104 DesktopBackgroundController::DesktopBackgroundController() |
105 : locked_(false), | 105 : locked_(false), |
106 desktop_background_mode_(BACKGROUND_SOLID_COLOR), | 106 desktop_background_mode_(BACKGROUND_SOLID_COLOR), |
107 background_color_(kTransparentColor), | 107 background_color_(kTransparentColor), |
108 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 108 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 109 InstallComponentForAllWindows(); |
109 } | 110 } |
110 | 111 |
111 DesktopBackgroundController::~DesktopBackgroundController() { | 112 DesktopBackgroundController::~DesktopBackgroundController() { |
112 CancelPendingWallpaperOperation(); | 113 CancelPendingWallpaperOperation(); |
113 } | 114 } |
114 | 115 |
115 gfx::ImageSkia DesktopBackgroundController::GetWallpaper() const { | 116 gfx::ImageSkia DesktopBackgroundController::GetWallpaper() const { |
116 if (current_wallpaper_.get()) | 117 if (current_wallpaper_.get()) |
117 return current_wallpaper_->wallpaper_image; | 118 return current_wallpaper_->wallpaper_image; |
118 return gfx::ImageSkia(); | 119 return gfx::ImageSkia(); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 if (wallpaper_op_.get()) | 206 if (wallpaper_op_.get()) |
206 wallpaper_op_->Cancel(); | 207 wallpaper_op_->Cancel(); |
207 | 208 |
208 // Cancel reply callback for previous request. | 209 // Cancel reply callback for previous request. |
209 weak_ptr_factory_.InvalidateWeakPtrs(); | 210 weak_ptr_factory_.InvalidateWeakPtrs(); |
210 } | 211 } |
211 | 212 |
212 void DesktopBackgroundController::SetDesktopBackgroundSolidColorMode( | 213 void DesktopBackgroundController::SetDesktopBackgroundSolidColorMode( |
213 SkColor color) { | 214 SkColor color) { |
214 background_color_ = color; | 215 background_color_ = color; |
215 desktop_background_mode_ = BACKGROUND_SOLID_COLOR; | 216 if (desktop_background_mode_ != BACKGROUND_SOLID_COLOR) { |
| 217 desktop_background_mode_ = BACKGROUND_SOLID_COLOR; |
| 218 InstallComponentForAllWindows(); |
| 219 return; |
| 220 } |
216 | 221 |
217 InstallComponentForAllWindows(); | 222 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 223 for (Shell::RootWindowList::iterator iter = root_windows.begin(); |
| 224 iter != root_windows.end(); ++iter) { |
| 225 aura::RootWindow* root_window = *iter; |
| 226 internal::DesktopBackgroundWidgetController* component = root_window-> |
| 227 GetProperty(internal::kWindowDesktopComponent); |
| 228 DCHECK(component); |
| 229 DCHECK(component->layer()); |
| 230 component->layer()->SetColor(background_color_ ); |
| 231 } |
218 } | 232 } |
219 | 233 |
220 void DesktopBackgroundController::CreateEmptyWallpaper() { | 234 void DesktopBackgroundController::CreateEmptyWallpaper() { |
221 current_wallpaper_.reset(NULL); | 235 current_wallpaper_.reset(NULL); |
222 SetDesktopBackgroundImageMode(); | 236 SetDesktopBackgroundImageMode(); |
223 } | 237 } |
224 | 238 |
225 void DesktopBackgroundController::MoveDesktopToLockedContainer() { | 239 void DesktopBackgroundController::MoveDesktopToLockedContainer() { |
226 if (locked_) | 240 if (locked_) |
227 return; | 241 return; |
228 locked_ = true; | 242 locked_ = true; |
229 ReparentBackgroundWidgets(GetBackgroundContainerId(false), | 243 ReparentBackgroundWidgets(GetBackgroundContainerId(false), |
230 GetBackgroundContainerId(true)); | 244 GetBackgroundContainerId(true)); |
231 } | 245 } |
232 | 246 |
233 void DesktopBackgroundController::MoveDesktopToUnlockedContainer() { | 247 void DesktopBackgroundController::MoveDesktopToUnlockedContainer() { |
234 if (!locked_) | 248 if (!locked_) |
235 return; | 249 return; |
236 locked_ = false; | 250 locked_ = false; |
237 ReparentBackgroundWidgets(GetBackgroundContainerId(true), | 251 ReparentBackgroundWidgets(GetBackgroundContainerId(true), |
238 GetBackgroundContainerId(false)); | 252 GetBackgroundContainerId(false)); |
239 } | 253 } |
240 | 254 |
241 void DesktopBackgroundController::OnWindowDestroying(aura::Window* window) { | 255 void DesktopBackgroundController::OnWindowDestroying(aura::Window* window) { |
242 window->SetProperty(internal::kWindowDesktopComponent, | 256 window->SetProperty(internal::kWindowDesktopComponent, |
243 static_cast<internal::DesktopBackgroundWidgetController*>(NULL)); | 257 static_cast<internal::DesktopBackgroundWidgetController*>(NULL)); |
244 window->SetProperty(internal::kComponentWrapper, | |
245 static_cast<internal::ComponentWrapper*>(NULL)); | |
246 } | 258 } |
247 | 259 |
248 void DesktopBackgroundController::SetDesktopBackgroundImageMode() { | 260 void DesktopBackgroundController::SetDesktopBackgroundImageMode() { |
249 desktop_background_mode_ = BACKGROUND_IMAGE; | 261 if (desktop_background_mode_ != BACKGROUND_IMAGE) { |
250 InstallComponentForAllWindows(); | 262 desktop_background_mode_ = BACKGROUND_IMAGE; |
| 263 InstallComponentForAllWindows(); |
| 264 return; |
| 265 } |
| 266 |
| 267 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 268 for (Shell::RootWindowList::iterator iter = root_windows.begin(); |
| 269 iter != root_windows.end(); ++iter) { |
| 270 aura::RootWindow* root_window = *iter; |
| 271 internal::DesktopBackgroundWidgetController* component = root_window-> |
| 272 GetProperty(internal::kWindowDesktopComponent); |
| 273 DCHECK(component); |
| 274 DCHECK(component->widget()); |
| 275 aura::Window* window = component->widget()->GetNativeView(); |
| 276 gfx::Rect bounds = window->bounds(); |
| 277 window->SchedulePaintInRect(gfx::Rect(0, 0, |
| 278 bounds.width(), bounds.height())); |
| 279 } |
251 } | 280 } |
252 | 281 |
253 void DesktopBackgroundController::OnWallpaperLoadCompleted( | 282 void DesktopBackgroundController::OnWallpaperLoadCompleted( |
254 scoped_refptr<WallpaperOperation> wo) { | 283 scoped_refptr<WallpaperOperation> wo) { |
255 current_wallpaper_.reset(wo->ReleaseWallpaperData()); | 284 current_wallpaper_.reset(wo->ReleaseWallpaperData()); |
256 | 285 |
257 SetDesktopBackgroundImageMode(); | 286 SetDesktopBackgroundImageMode(); |
258 | 287 |
259 DCHECK(wo.get() == wallpaper_op_.get()); | 288 DCHECK(wo.get() == wallpaper_op_.get()); |
260 wallpaper_op_ = NULL; | 289 wallpaper_op_ = NULL; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 break; | 321 break; |
293 } | 322 } |
294 default: { | 323 default: { |
295 NOTREACHED(); | 324 NOTREACHED(); |
296 } | 325 } |
297 } | 326 } |
298 if (NULL == root_window->GetProperty(internal::kWindowDesktopComponent)) { | 327 if (NULL == root_window->GetProperty(internal::kWindowDesktopComponent)) { |
299 // First time for this root window | 328 // First time for this root window |
300 root_window->AddObserver(this); | 329 root_window->AddObserver(this); |
301 } | 330 } |
302 root_window->SetProperty(internal::kComponentWrapper, | 331 root_window->SetProperty(internal::kWindowDesktopComponent, component); |
303 new internal::ComponentWrapper(component)); | |
304 } | 332 } |
305 | 333 |
306 void DesktopBackgroundController::InstallComponentForAllWindows() { | 334 void DesktopBackgroundController::InstallComponentForAllWindows() { |
307 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 335 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
308 for (Shell::RootWindowList::iterator iter = root_windows.begin(); | 336 for (Shell::RootWindowList::iterator iter = root_windows.begin(); |
309 iter != root_windows.end(); ++iter) { | 337 iter != root_windows.end(); ++iter) { |
310 InstallComponent(*iter); | 338 InstallComponent(*iter); |
311 } | 339 } |
312 } | 340 } |
313 | 341 |
(...skipping 24 matching lines...) Expand all Loading... |
338 iter != root_windows.end(); ++iter) { | 366 iter != root_windows.end(); ++iter) { |
339 gfx::Size root_window_size = (*iter)->GetHostSize(); | 367 gfx::Size root_window_size = (*iter)->GetHostSize(); |
340 if (root_window_size.width() > kSmallWallpaperMaximalWidth || | 368 if (root_window_size.width() > kSmallWallpaperMaximalWidth || |
341 root_window_size.height() > kSmallWallpaperMaximalHeight) | 369 root_window_size.height() > kSmallWallpaperMaximalHeight) |
342 resolution = LARGE; | 370 resolution = LARGE; |
343 } | 371 } |
344 return resolution; | 372 return resolution; |
345 } | 373 } |
346 | 374 |
347 } // namespace ash | 375 } // namespace ash |
OLD | NEW |