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 15 matching lines...) Expand all Loading... |
26 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
27 #include "grit/ash_resources.h" | 27 #include "grit/ash_resources.h" |
28 #include "ui/aura/window.h" | 28 #include "ui/aura/window.h" |
29 #include "ui/aura/window_event_dispatcher.h" | 29 #include "ui/aura/window_event_dispatcher.h" |
30 #include "ui/compositor/layer.h" | 30 #include "ui/compositor/layer.h" |
31 #include "ui/gfx/codec/jpeg_codec.h" | 31 #include "ui/gfx/codec/jpeg_codec.h" |
32 #include "ui/gfx/image/image_skia.h" | 32 #include "ui/gfx/image/image_skia.h" |
33 #include "ui/gfx/rect.h" | 33 #include "ui/gfx/rect.h" |
34 #include "ui/views/widget/widget.h" | 34 #include "ui/views/widget/widget.h" |
35 | 35 |
36 using ash::internal::DesktopBackgroundWidgetController; | |
37 using content::BrowserThread; | 36 using content::BrowserThread; |
38 | 37 |
39 namespace ash { | 38 namespace ash { |
40 namespace { | 39 namespace { |
41 | 40 |
42 // How long to wait reloading the wallpaper after the max display has | 41 // How long to wait reloading the wallpaper after the max display has |
43 // changed? | 42 // changed? |
44 const int kWallpaperReloadDelayMs = 2000; | 43 const int kWallpaperReloadDelayMs = 2000; |
45 | 44 |
46 } // namespace | 45 } // namespace |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 OnWallpaperDataChanged()); | 362 OnWallpaperDataChanged()); |
364 | 363 |
365 SetDesktopBackgroundImageMode(); | 364 SetDesktopBackgroundImageMode(); |
366 | 365 |
367 DCHECK(loader.get() == default_wallpaper_loader_.get()); | 366 DCHECK(loader.get() == default_wallpaper_loader_.get()); |
368 default_wallpaper_loader_ = NULL; | 367 default_wallpaper_loader_ = NULL; |
369 } | 368 } |
370 | 369 |
371 void DesktopBackgroundController::InstallDesktopController( | 370 void DesktopBackgroundController::InstallDesktopController( |
372 aura::Window* root_window) { | 371 aura::Window* root_window) { |
373 internal::DesktopBackgroundWidgetController* component = NULL; | 372 DesktopBackgroundWidgetController* component = NULL; |
374 int container_id = GetBackgroundContainerId(locked_); | 373 int container_id = GetBackgroundContainerId(locked_); |
375 | 374 |
376 switch (desktop_background_mode_) { | 375 switch (desktop_background_mode_) { |
377 case BACKGROUND_IMAGE: { | 376 case BACKGROUND_IMAGE: { |
378 views::Widget* widget = internal::CreateDesktopBackground(root_window, | 377 views::Widget* widget = |
379 container_id); | 378 CreateDesktopBackground(root_window, container_id); |
380 component = new internal::DesktopBackgroundWidgetController(widget); | 379 component = new DesktopBackgroundWidgetController(widget); |
381 break; | 380 break; |
382 } | 381 } |
383 case BACKGROUND_NONE: | 382 case BACKGROUND_NONE: |
384 NOTREACHED(); | 383 NOTREACHED(); |
385 return; | 384 return; |
386 } | 385 } |
387 internal::GetRootWindowController(root_window)-> | 386 GetRootWindowController(root_window)->SetAnimatingWallpaperController( |
388 SetAnimatingWallpaperController( | 387 new AnimatingDesktopController(component)); |
389 new internal::AnimatingDesktopController(component)); | |
390 | 388 |
391 component->StartAnimating(internal::GetRootWindowController(root_window)); | 389 component->StartAnimating(GetRootWindowController(root_window)); |
392 } | 390 } |
393 | 391 |
394 void DesktopBackgroundController::InstallDesktopControllerForAllWindows() { | 392 void DesktopBackgroundController::InstallDesktopControllerForAllWindows() { |
395 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 393 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
396 for (aura::Window::Windows::iterator iter = root_windows.begin(); | 394 for (aura::Window::Windows::iterator iter = root_windows.begin(); |
397 iter != root_windows.end(); ++iter) { | 395 iter != root_windows.end(); ++iter) { |
398 InstallDesktopController(*iter); | 396 InstallDesktopController(*iter); |
399 } | 397 } |
400 current_max_display_size_ = GetMaxDisplaySizeInNative(); | 398 current_max_display_size_ = GetMaxDisplaySizeInNative(); |
401 } | 399 } |
402 | 400 |
403 bool DesktopBackgroundController::ReparentBackgroundWidgets(int src_container, | 401 bool DesktopBackgroundController::ReparentBackgroundWidgets(int src_container, |
404 int dst_container) { | 402 int dst_container) { |
405 bool moved = false; | 403 bool moved = false; |
406 Shell::RootWindowControllerList controllers = | 404 Shell::RootWindowControllerList controllers = |
407 Shell::GetAllRootWindowControllers(); | 405 Shell::GetAllRootWindowControllers(); |
408 for (Shell::RootWindowControllerList::iterator iter = controllers.begin(); | 406 for (Shell::RootWindowControllerList::iterator iter = controllers.begin(); |
409 iter != controllers.end(); ++iter) { | 407 iter != controllers.end(); ++iter) { |
410 internal::RootWindowController* root_window_controller = *iter; | 408 RootWindowController* root_window_controller = *iter; |
411 // In the steady state (no animation playing) the background widget | 409 // In the steady state (no animation playing) the background widget |
412 // controller exists in the RootWindowController. | 410 // controller exists in the RootWindowController. |
413 DesktopBackgroundWidgetController* desktop_controller = | 411 DesktopBackgroundWidgetController* desktop_controller = |
414 root_window_controller->wallpaper_controller(); | 412 root_window_controller->wallpaper_controller(); |
415 if (desktop_controller) { | 413 if (desktop_controller) { |
416 moved |= desktop_controller->Reparent( | 414 moved |= desktop_controller->Reparent( |
417 root_window_controller->root_window(), | 415 root_window_controller->root_window(), |
418 src_container, | 416 src_container, |
419 dst_container); | 417 dst_container); |
420 } | 418 } |
(...skipping 11 matching lines...) Expand all Loading... |
432 moved |= animating_controller->Reparent( | 430 moved |= animating_controller->Reparent( |
433 root_window_controller->root_window(), | 431 root_window_controller->root_window(), |
434 src_container, | 432 src_container, |
435 dst_container); | 433 dst_container); |
436 } | 434 } |
437 } | 435 } |
438 return moved; | 436 return moved; |
439 } | 437 } |
440 | 438 |
441 int DesktopBackgroundController::GetBackgroundContainerId(bool locked) { | 439 int DesktopBackgroundController::GetBackgroundContainerId(bool locked) { |
442 return locked ? internal::kShellWindowId_LockScreenBackgroundContainer : | 440 return locked ? kShellWindowId_LockScreenBackgroundContainer |
443 internal::kShellWindowId_DesktopBackgroundContainer; | 441 : kShellWindowId_DesktopBackgroundContainer; |
444 } | 442 } |
445 | 443 |
446 void DesktopBackgroundController::UpdateWallpaper() { | 444 void DesktopBackgroundController::UpdateWallpaper() { |
447 current_wallpaper_.reset(NULL); | 445 current_wallpaper_.reset(NULL); |
448 current_default_wallpaper_path_ = base::FilePath(); | 446 current_default_wallpaper_path_ = base::FilePath(); |
449 current_default_wallpaper_resource_id_ = -1; | 447 current_default_wallpaper_resource_id_ = -1; |
450 ash::Shell::GetInstance()->user_wallpaper_delegate()-> | 448 ash::Shell::GetInstance()->user_wallpaper_delegate()-> |
451 UpdateWallpaper(true /* clear cache */); | 449 UpdateWallpaper(true /* clear cache */); |
452 } | 450 } |
453 | 451 |
454 // static | 452 // static |
455 gfx::Size DesktopBackgroundController::GetMaxDisplaySizeInNative() { | 453 gfx::Size DesktopBackgroundController::GetMaxDisplaySizeInNative() { |
456 int width = 0; | 454 int width = 0; |
457 int height = 0; | 455 int height = 0; |
458 std::vector<gfx::Display> displays = Shell::GetScreen()->GetAllDisplays(); | 456 std::vector<gfx::Display> displays = Shell::GetScreen()->GetAllDisplays(); |
459 internal::DisplayManager* display_manager = | 457 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
460 Shell::GetInstance()->display_manager(); | |
461 | 458 |
462 for (std::vector<gfx::Display>::iterator iter = displays.begin(); | 459 for (std::vector<gfx::Display>::iterator iter = displays.begin(); |
463 iter != displays.end(); ++iter) { | 460 iter != displays.end(); ++iter) { |
464 // Don't use size_in_pixel because we want to use the native pixel size. | 461 // Don't use size_in_pixel because we want to use the native pixel size. |
465 gfx::Size size_in_pixel = | 462 gfx::Size size_in_pixel = |
466 display_manager->GetDisplayInfo(iter->id()).bounds_in_native().size(); | 463 display_manager->GetDisplayInfo(iter->id()).bounds_in_native().size(); |
467 if (iter->rotation() == gfx::Display::ROTATE_90 || | 464 if (iter->rotation() == gfx::Display::ROTATE_90 || |
468 iter->rotation() == gfx::Display::ROTATE_270) { | 465 iter->rotation() == gfx::Display::ROTATE_270) { |
469 size_in_pixel = gfx::Size(size_in_pixel.height(), size_in_pixel.width()); | 466 size_in_pixel = gfx::Size(size_in_pixel.height(), size_in_pixel.width()); |
470 } | 467 } |
471 width = std::max(size_in_pixel.width(), width); | 468 width = std::max(size_in_pixel.width(), width); |
472 height = std::max(size_in_pixel.height(), height); | 469 height = std::max(size_in_pixel.height(), height); |
473 } | 470 } |
474 return gfx::Size(width, height); | 471 return gfx::Size(width, height); |
475 } | 472 } |
476 | 473 |
477 } // namespace ash | 474 } // namespace ash |
OLD | NEW |