Chromium Code Reviews| 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 if (desktop_background_mode_ != BACKGROUND_SOLID_COLOR) |
| 217 desktop_background_mode_ = BACKGROUND_SOLID_COLOR; | 216 desktop_background_mode_ = BACKGROUND_SOLID_COLOR; |
| 218 InstallComponentForAllWindows(); | |
| 219 return; | |
| 220 } | |
| 221 | 217 |
| 222 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 218 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 } | 219 } |
| 233 | 220 |
| 234 void DesktopBackgroundController::CreateEmptyWallpaper() { | 221 void DesktopBackgroundController::CreateEmptyWallpaper() { |
| 235 current_wallpaper_.reset(NULL); | 222 current_wallpaper_.reset(NULL); |
| 236 SetDesktopBackgroundImageMode(); | 223 SetDesktopBackgroundImageMode(); |
| 237 } | 224 } |
| 238 | 225 |
| 239 void DesktopBackgroundController::MoveDesktopToLockedContainer() { | 226 void DesktopBackgroundController::MoveDesktopToLockedContainer() { |
| 240 if (locked_) | 227 if (locked_) |
| 241 return; | 228 return; |
| 242 locked_ = true; | 229 locked_ = true; |
| 243 ReparentBackgroundWidgets(GetBackgroundContainerId(false), | 230 ReparentBackgroundWidgets(GetBackgroundContainerId(false), |
| 244 GetBackgroundContainerId(true)); | 231 GetBackgroundContainerId(true)); |
| 245 } | 232 } |
| 246 | 233 |
| 247 void DesktopBackgroundController::MoveDesktopToUnlockedContainer() { | 234 void DesktopBackgroundController::MoveDesktopToUnlockedContainer() { |
| 248 if (!locked_) | 235 if (!locked_) |
| 249 return; | 236 return; |
| 250 locked_ = false; | 237 locked_ = false; |
| 251 ReparentBackgroundWidgets(GetBackgroundContainerId(true), | 238 ReparentBackgroundWidgets(GetBackgroundContainerId(true), |
| 252 GetBackgroundContainerId(false)); | 239 GetBackgroundContainerId(false)); |
| 253 } | 240 } |
| 254 | 241 |
| 255 void DesktopBackgroundController::OnWindowDestroying(aura::Window* window) { | 242 void DesktopBackgroundController::OnWindowDestroying(aura::Window* window) { |
| 256 window->SetProperty(internal::kWindowDesktopComponent, | 243 window->SetProperty(internal::kWindowDesktopComponent, |
| 257 static_cast<internal::DesktopBackgroundWidgetController*>(NULL)); | 244 static_cast<internal::DesktopBackgroundWidgetController*>(NULL)); |
| 245 window->SetProperty(internal::kComponentWrapper, | |
| 246 static_cast<internal::ComponentWrapper*>(NULL)); | |
| 258 } | 247 } |
| 259 | 248 |
| 260 void DesktopBackgroundController::SetDesktopBackgroundImageMode() { | 249 void DesktopBackgroundController::SetDesktopBackgroundImageMode() { |
| 261 if (desktop_background_mode_ != BACKGROUND_IMAGE) { | 250 if (desktop_background_mode_ != BACKGROUND_IMAGE) { |
|
sky
2012/08/13 17:31:05
Do you even need the if now?
bshe
2012/08/13 18:28:22
No need. Removed it.
On 2012/08/13 17:31:05, sky
| |
| 262 desktop_background_mode_ = BACKGROUND_IMAGE; | 251 desktop_background_mode_ = BACKGROUND_IMAGE; |
| 263 InstallComponentForAllWindows(); | |
| 264 return; | |
| 265 } | 252 } |
| 266 | 253 InstallComponentForAllWindows(); |
| 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 } | 254 } |
| 281 | 255 |
| 282 void DesktopBackgroundController::OnWallpaperLoadCompleted( | 256 void DesktopBackgroundController::OnWallpaperLoadCompleted( |
| 283 scoped_refptr<WallpaperOperation> wo) { | 257 scoped_refptr<WallpaperOperation> wo) { |
| 284 current_wallpaper_.reset(wo->ReleaseWallpaperData()); | 258 current_wallpaper_.reset(wo->ReleaseWallpaperData()); |
| 285 | 259 |
| 286 SetDesktopBackgroundImageMode(); | 260 SetDesktopBackgroundImageMode(); |
| 287 | 261 |
| 288 DCHECK(wo.get() == wallpaper_op_.get()); | 262 DCHECK(wo.get() == wallpaper_op_.get()); |
| 289 wallpaper_op_ = NULL; | 263 wallpaper_op_ = NULL; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 321 break; | 295 break; |
| 322 } | 296 } |
| 323 default: { | 297 default: { |
| 324 NOTREACHED(); | 298 NOTREACHED(); |
| 325 } | 299 } |
| 326 } | 300 } |
| 327 if (NULL == root_window->GetProperty(internal::kWindowDesktopComponent)) { | 301 if (NULL == root_window->GetProperty(internal::kWindowDesktopComponent)) { |
| 328 // First time for this root window | 302 // First time for this root window |
| 329 root_window->AddObserver(this); | 303 root_window->AddObserver(this); |
| 330 } | 304 } |
| 331 root_window->SetProperty(internal::kWindowDesktopComponent, component); | 305 root_window->SetProperty(internal::kComponentWrapper, |
| 306 new internal::ComponentWrapper(component)); | |
| 332 } | 307 } |
| 333 | 308 |
| 334 void DesktopBackgroundController::InstallComponentForAllWindows() { | 309 void DesktopBackgroundController::InstallComponentForAllWindows() { |
| 335 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 310 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 336 for (Shell::RootWindowList::iterator iter = root_windows.begin(); | 311 for (Shell::RootWindowList::iterator iter = root_windows.begin(); |
| 337 iter != root_windows.end(); ++iter) { | 312 iter != root_windows.end(); ++iter) { |
| 338 InstallComponent(*iter); | 313 InstallComponent(*iter); |
| 339 } | 314 } |
| 340 } | 315 } |
| 341 | 316 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 366 iter != root_windows.end(); ++iter) { | 341 iter != root_windows.end(); ++iter) { |
| 367 gfx::Size root_window_size = (*iter)->GetHostSize(); | 342 gfx::Size root_window_size = (*iter)->GetHostSize(); |
| 368 if (root_window_size.width() > kSmallWallpaperMaximalWidth || | 343 if (root_window_size.width() > kSmallWallpaperMaximalWidth || |
| 369 root_window_size.height() > kSmallWallpaperMaximalHeight) | 344 root_window_size.height() > kSmallWallpaperMaximalHeight) |
| 370 resolution = LARGE; | 345 resolution = LARGE; |
| 371 } | 346 } |
| 372 return resolution; | 347 return resolution; |
| 373 } | 348 } |
| 374 | 349 |
| 375 } // namespace ash | 350 } // namespace ash |
| OLD | NEW |