| 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(); | |
| 110 } | 109 } |
| 111 | 110 |
| 112 DesktopBackgroundController::~DesktopBackgroundController() { | 111 DesktopBackgroundController::~DesktopBackgroundController() { |
| 113 CancelPendingWallpaperOperation(); | 112 CancelPendingWallpaperOperation(); |
| 114 } | 113 } |
| 115 | 114 |
| 116 gfx::ImageSkia DesktopBackgroundController::GetWallpaper() const { | 115 gfx::ImageSkia DesktopBackgroundController::GetWallpaper() const { |
| 117 if (current_wallpaper_.get()) | 116 if (current_wallpaper_.get()) |
| 118 return current_wallpaper_->wallpaper_image; | 117 return current_wallpaper_->wallpaper_image; |
| 119 return gfx::ImageSkia(); | 118 return gfx::ImageSkia(); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 if (wallpaper_op_.get()) | 205 if (wallpaper_op_.get()) |
| 207 wallpaper_op_->Cancel(); | 206 wallpaper_op_->Cancel(); |
| 208 | 207 |
| 209 // Cancel reply callback for previous request. | 208 // Cancel reply callback for previous request. |
| 210 weak_ptr_factory_.InvalidateWeakPtrs(); | 209 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 211 } | 210 } |
| 212 | 211 |
| 213 void DesktopBackgroundController::SetDesktopBackgroundSolidColorMode( | 212 void DesktopBackgroundController::SetDesktopBackgroundSolidColorMode( |
| 214 SkColor color) { | 213 SkColor color) { |
| 215 background_color_ = color; | 214 background_color_ = color; |
| 216 if (desktop_background_mode_ != BACKGROUND_SOLID_COLOR) { | 215 desktop_background_mode_ = BACKGROUND_SOLID_COLOR; |
| 217 desktop_background_mode_ = BACKGROUND_SOLID_COLOR; | |
| 218 InstallComponentForAllWindows(); | |
| 219 return; | |
| 220 } | |
| 221 | 216 |
| 222 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 217 InstallComponentForAllWindows(); |
| 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 } | |
| 232 } | 218 } |
| 233 | 219 |
| 234 void DesktopBackgroundController::CreateEmptyWallpaper() { | 220 void DesktopBackgroundController::CreateEmptyWallpaper() { |
| 235 current_wallpaper_.reset(NULL); | 221 current_wallpaper_.reset(NULL); |
| 236 SetDesktopBackgroundImageMode(); | 222 SetDesktopBackgroundImageMode(); |
| 237 } | 223 } |
| 238 | 224 |
| 239 void DesktopBackgroundController::MoveDesktopToLockedContainer() { | 225 void DesktopBackgroundController::MoveDesktopToLockedContainer() { |
| 240 if (locked_) | 226 if (locked_) |
| 241 return; | 227 return; |
| 242 locked_ = true; | 228 locked_ = true; |
| 243 ReparentBackgroundWidgets(GetBackgroundContainerId(false), | 229 ReparentBackgroundWidgets(GetBackgroundContainerId(false), |
| 244 GetBackgroundContainerId(true)); | 230 GetBackgroundContainerId(true)); |
| 245 } | 231 } |
| 246 | 232 |
| 247 void DesktopBackgroundController::MoveDesktopToUnlockedContainer() { | 233 void DesktopBackgroundController::MoveDesktopToUnlockedContainer() { |
| 248 if (!locked_) | 234 if (!locked_) |
| 249 return; | 235 return; |
| 250 locked_ = false; | 236 locked_ = false; |
| 251 ReparentBackgroundWidgets(GetBackgroundContainerId(true), | 237 ReparentBackgroundWidgets(GetBackgroundContainerId(true), |
| 252 GetBackgroundContainerId(false)); | 238 GetBackgroundContainerId(false)); |
| 253 } | 239 } |
| 254 | 240 |
| 255 void DesktopBackgroundController::OnWindowDestroying(aura::Window* window) { | 241 void DesktopBackgroundController::OnWindowDestroying(aura::Window* window) { |
| 256 window->SetProperty(internal::kWindowDesktopComponent, | 242 window->SetProperty(internal::kWindowDesktopComponent, |
| 257 static_cast<internal::DesktopBackgroundWidgetController*>(NULL)); | 243 static_cast<internal::DesktopBackgroundWidgetController*>(NULL)); |
| 244 window->SetProperty(internal::kComponentWrapper, |
| 245 static_cast<internal::ComponentWrapper*>(NULL)); |
| 258 } | 246 } |
| 259 | 247 |
| 260 void DesktopBackgroundController::SetDesktopBackgroundImageMode() { | 248 void DesktopBackgroundController::SetDesktopBackgroundImageMode() { |
| 261 if (desktop_background_mode_ != BACKGROUND_IMAGE) { | 249 desktop_background_mode_ = BACKGROUND_IMAGE; |
| 262 desktop_background_mode_ = BACKGROUND_IMAGE; | 250 InstallComponentForAllWindows(); |
| 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 } | |
| 280 } | 251 } |
| 281 | 252 |
| 282 void DesktopBackgroundController::OnWallpaperLoadCompleted( | 253 void DesktopBackgroundController::OnWallpaperLoadCompleted( |
| 283 scoped_refptr<WallpaperOperation> wo) { | 254 scoped_refptr<WallpaperOperation> wo) { |
| 284 current_wallpaper_.reset(wo->ReleaseWallpaperData()); | 255 current_wallpaper_.reset(wo->ReleaseWallpaperData()); |
| 285 | 256 |
| 286 SetDesktopBackgroundImageMode(); | 257 SetDesktopBackgroundImageMode(); |
| 287 | 258 |
| 288 DCHECK(wo.get() == wallpaper_op_.get()); | 259 DCHECK(wo.get() == wallpaper_op_.get()); |
| 289 wallpaper_op_ = NULL; | 260 wallpaper_op_ = NULL; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 317 ui::Layer* layer = SetColorLayerForContainer(background_color_, | 288 ui::Layer* layer = SetColorLayerForContainer(background_color_, |
| 318 root_window, | 289 root_window, |
| 319 container_id); | 290 container_id); |
| 320 component = new internal::DesktopBackgroundWidgetController(layer); | 291 component = new internal::DesktopBackgroundWidgetController(layer); |
| 321 break; | 292 break; |
| 322 } | 293 } |
| 323 default: { | 294 default: { |
| 324 NOTREACHED(); | 295 NOTREACHED(); |
| 325 } | 296 } |
| 326 } | 297 } |
| 327 if (NULL == root_window->GetProperty(internal::kWindowDesktopComponent)) { | 298 if (NULL == root_window->GetProperty(internal::kComponentWrapper)) { |
| 328 // First time for this root window | 299 // First time for this root window |
| 329 root_window->AddObserver(this); | 300 root_window->AddObserver(this); |
| 330 } | 301 } |
| 331 root_window->SetProperty(internal::kWindowDesktopComponent, component); | 302 root_window->SetProperty(internal::kComponentWrapper, |
| 303 new internal::ComponentWrapper(component)); |
| 332 } | 304 } |
| 333 | 305 |
| 334 void DesktopBackgroundController::InstallComponentForAllWindows() { | 306 void DesktopBackgroundController::InstallComponentForAllWindows() { |
| 335 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 307 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 336 for (Shell::RootWindowList::iterator iter = root_windows.begin(); | 308 for (Shell::RootWindowList::iterator iter = root_windows.begin(); |
| 337 iter != root_windows.end(); ++iter) { | 309 iter != root_windows.end(); ++iter) { |
| 338 InstallComponent(*iter); | 310 InstallComponent(*iter); |
| 339 } | 311 } |
| 340 } | 312 } |
| 341 | 313 |
| 342 void DesktopBackgroundController::ReparentBackgroundWidgets(int src_container, | 314 void DesktopBackgroundController::ReparentBackgroundWidgets(int src_container, |
| 343 int dst_container) { | 315 int dst_container) { |
| 344 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 316 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 345 for (Shell::RootWindowList::iterator iter = root_windows.begin(); | 317 for (Shell::RootWindowList::iterator iter = root_windows.begin(); |
| 346 iter != root_windows.end(); ++iter) { | 318 iter != root_windows.end(); ++iter) { |
| 347 aura::RootWindow* root_window = *iter; | 319 aura::RootWindow* root_window = *iter; |
| 348 internal::DesktopBackgroundWidgetController* component = root_window-> | 320 if (root_window->GetProperty(internal::kComponentWrapper)) { |
| 349 GetProperty(internal::kWindowDesktopComponent); | 321 internal::DesktopBackgroundWidgetController* component = root_window-> |
| 350 DCHECK(component); | 322 GetProperty(internal::kComponentWrapper)->component(); |
| 351 component->Reparent(root_window, | 323 DCHECK(component); |
| 352 src_container, | 324 component->Reparent(root_window, |
| 353 dst_container); | 325 src_container, |
| 326 dst_container); |
| 327 } |
| 354 } | 328 } |
| 355 } | 329 } |
| 356 | 330 |
| 357 int DesktopBackgroundController::GetBackgroundContainerId(bool locked) { | 331 int DesktopBackgroundController::GetBackgroundContainerId(bool locked) { |
| 358 return locked ? internal::kShellWindowId_LockScreenBackgroundContainer : | 332 return locked ? internal::kShellWindowId_LockScreenBackgroundContainer : |
| 359 internal::kShellWindowId_DesktopBackgroundContainer; | 333 internal::kShellWindowId_DesktopBackgroundContainer; |
| 360 } | 334 } |
| 361 | 335 |
| 362 WallpaperResolution DesktopBackgroundController::GetAppropriateResolution() { | 336 WallpaperResolution DesktopBackgroundController::GetAppropriateResolution() { |
| 363 WallpaperResolution resolution = SMALL; | 337 WallpaperResolution resolution = SMALL; |
| 364 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 338 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 365 for (Shell::RootWindowList::iterator iter = root_windows.begin(); | 339 for (Shell::RootWindowList::iterator iter = root_windows.begin(); |
| 366 iter != root_windows.end(); ++iter) { | 340 iter != root_windows.end(); ++iter) { |
| 367 gfx::Size root_window_size = (*iter)->GetHostSize(); | 341 gfx::Size root_window_size = (*iter)->GetHostSize(); |
| 368 if (root_window_size.width() > kSmallWallpaperMaximalWidth || | 342 if (root_window_size.width() > kSmallWallpaperMaximalWidth || |
| 369 root_window_size.height() > kSmallWallpaperMaximalHeight) | 343 root_window_size.height() > kSmallWallpaperMaximalHeight) |
| 370 resolution = LARGE; | 344 resolution = LARGE; |
| 371 } | 345 } |
| 372 return resolution; | 346 return resolution; |
| 373 } | 347 } |
| 374 | 348 |
| 375 } // namespace ash | 349 } // namespace ash |
| OLD | NEW |