| Index: ash/desktop_background/desktop_background_controller.cc
|
| diff --git a/ash/desktop_background/desktop_background_controller.cc b/ash/desktop_background/desktop_background_controller.cc
|
| index 3f9dcba9dd7bf35c5cfc94fb0ac0ffdce322d608..de3a1211b8871c2f4fdcb0b1e7ad644799172445 100644
|
| --- a/ash/desktop_background/desktop_background_controller.cc
|
| +++ b/ash/desktop_background/desktop_background_controller.cc
|
| @@ -5,6 +5,7 @@
|
| #include "ash/desktop_background/desktop_background_controller.h"
|
|
|
| #include "ash/desktop_background/desktop_background_view.h"
|
| +#include "ash/desktop_background/desktop_background_widget_controller.h"
|
| #include "ash/shell.h"
|
| #include "ash/shell_factory.h"
|
| #include "ash/shell_window_ids.h"
|
| @@ -18,6 +19,7 @@
|
| #include "ui/aura/window.h"
|
| #include "ui/base/resource/resource_bundle.h"
|
| #include "ui/compositor/layer.h"
|
| +#include "ui/gfx/rect.h"
|
| #include "ui/gfx/image/image.h"
|
| #include "ui/views/widget/widget.h"
|
|
|
| @@ -99,9 +101,11 @@ class DesktopBackgroundController::WallpaperOperation
|
| };
|
|
|
| DesktopBackgroundController::DesktopBackgroundController()
|
| - : desktop_background_mode_(BACKGROUND_IMAGE),
|
| + : locked_(false),
|
| + desktop_background_mode_(BACKGROUND_SOLID_COLOR),
|
| background_color_(SK_ColorGRAY),
|
| weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
|
| + InstallComponentForAllWindows();
|
| }
|
|
|
| DesktopBackgroundController::~DesktopBackgroundController() {
|
| @@ -128,38 +132,32 @@ SkBitmap DesktopBackgroundController::GetCurrentWallpaperImage() {
|
|
|
| void DesktopBackgroundController::OnRootWindowAdded(
|
| aura::RootWindow* root_window) {
|
| - switch (desktop_background_mode_) {
|
| - case BACKGROUND_IMAGE:
|
| - if (current_wallpaper_.get()) {
|
| - gfx::Size root_window_size = root_window->GetHostSize();
|
| - int wallpaper_width = current_wallpaper_->wallpaper_image.width();
|
| - int wallpaper_height = current_wallpaper_->wallpaper_image.height();
|
| - // Loads a higher resolution wallpaper if needed.
|
| - if ((wallpaper_width < root_window_size.width() ||
|
| - wallpaper_height < root_window_size.height()) &&
|
| - current_wallpaper_->wallpaper_index != -1 &&
|
| - current_wallpaper_->wallpaper_layout != TILE)
|
| - SetDefaultWallpaper(current_wallpaper_->wallpaper_index, true);
|
| - else
|
| - SetDesktopBackgroundImage(root_window);
|
| - } else {
|
| - internal::CreateDesktopBackground(root_window);
|
| - }
|
| - break;
|
| - case BACKGROUND_SOLID_COLOR:
|
| - SetDesktopBackgroundSolidColorMode(background_color_);
|
| - break;
|
| + // Handle resolution change for "built-in" images."
|
| + if (BACKGROUND_IMAGE == desktop_background_mode_) {
|
| + if (current_wallpaper_.get()) {
|
| + gfx::Size root_window_size = root_window->GetHostSize();
|
| + int wallpaper_width = current_wallpaper_->wallpaper_image.width();
|
| + int wallpaper_height = current_wallpaper_->wallpaper_image.height();
|
| + // Loads a higher resolution wallpaper if needed.
|
| + if ((wallpaper_width < root_window_size.width() ||
|
| + wallpaper_height < root_window_size.height()) &&
|
| + current_wallpaper_->wallpaper_index != -1 &&
|
| + current_wallpaper_->wallpaper_layout != TILE)
|
| + SetDefaultWallpaper(current_wallpaper_->wallpaper_index, true);
|
| + }
|
| }
|
| +
|
| + InstallComponent(root_window);
|
| }
|
|
|
| void DesktopBackgroundController::SetDefaultWallpaper(int index,
|
| bool force_reload) {
|
| // We should not change background when index is invalid. For instance, at
|
| // login screen or stub_user login.
|
| - if (index == ash::GetInvalidWallpaperIndex()) {
|
| + if (index == GetInvalidWallpaperIndex()) {
|
| CreateEmptyWallpaper();
|
| return;
|
| - } else if (index == ash::GetSolidColorIndex()) {
|
| + } else if (index == GetSolidColorIndex()) {
|
| SetDesktopBackgroundSolidColorMode(kLoginWallpaperColor);
|
| return;
|
| }
|
| @@ -195,8 +193,7 @@ void DesktopBackgroundController::SetCustomWallpaper(
|
| WallpaperLayout layout) {
|
| CancelPendingWallpaperOperation();
|
| current_wallpaper_.reset(new WallpaperData(layout, wallpaper));
|
| - desktop_background_mode_ = BACKGROUND_IMAGE;
|
| - UpdateDesktopBackgroundImageMode();
|
| + SetDesktopBackgroundImageMode();
|
| }
|
|
|
| void DesktopBackgroundController::CancelPendingWallpaperOperation() {
|
| @@ -210,65 +207,151 @@ void DesktopBackgroundController::CancelPendingWallpaperOperation() {
|
|
|
| void DesktopBackgroundController::SetDesktopBackgroundSolidColorMode(
|
| SkColor color) {
|
| - // Set a solid black background.
|
| - // TODO(derat): Remove this in favor of having the compositor only clear the
|
| - // viewport when there are regions not covered by a layer:
|
| - // http://crbug.com/113445
|
| - current_wallpaper_.reset(NULL);
|
| background_color_ = color;
|
| - desktop_background_mode_ = BACKGROUND_SOLID_COLOR;
|
| + if (desktop_background_mode_ != BACKGROUND_SOLID_COLOR) {
|
| + desktop_background_mode_ = BACKGROUND_SOLID_COLOR;
|
| + InstallComponentForAllWindows();
|
| + return;
|
| + }
|
| +
|
| Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
|
| for (Shell::RootWindowList::iterator iter = root_windows.begin();
|
| iter != root_windows.end(); ++iter) {
|
| - ui::Layer* background_layer = new ui::Layer(ui::LAYER_SOLID_COLOR);
|
| - background_layer->SetColor(color);
|
| aura::RootWindow* root_window = *iter;
|
| - Shell::GetContainer(
|
| - root_window,
|
| - internal::kShellWindowId_DesktopBackgroundContainer)->
|
| - layer()->Add(background_layer);
|
| - GetRootWindowLayoutManager(root_window)->SetBackgroundLayer(
|
| - background_layer);
|
| - GetRootWindowLayoutManager(root_window)->SetBackgroundWidget(NULL);
|
| + internal::DesktopBackgroundWidgetController* component = root_window->
|
| + GetProperty(internal::kWindowDesktopComponent);
|
| + DCHECK(component);
|
| + DCHECK(component->layer());
|
| + component->layer()->SetColor(background_color_ );
|
| }
|
| }
|
|
|
| -void DesktopBackgroundController::SetDesktopBackgroundImage(
|
| - aura::RootWindow* root_window) {
|
| - GetRootWindowLayoutManager(root_window)->SetBackgroundLayer(NULL);
|
| - if (current_wallpaper_.get() &&
|
| - !current_wallpaper_->wallpaper_image.empty())
|
| - internal::CreateDesktopBackground(root_window);
|
| +void DesktopBackgroundController::CreateEmptyWallpaper() {
|
| + current_wallpaper_.reset(NULL);
|
| + SetDesktopBackgroundImageMode();
|
| }
|
|
|
| -void DesktopBackgroundController::UpdateDesktopBackgroundImageMode() {
|
| - Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
|
| +void DesktopBackgroundController::MoveDesktopToLockedContainer() {
|
| + if (locked_)
|
| + return;
|
| + locked_ = true;
|
| + ReparentBackgroundWidgets(GetBackgroundContainerId(false),
|
| + GetBackgroundContainerId(true));
|
| +}
|
| +
|
| +void DesktopBackgroundController::MoveDesktopToUnlockedContainer() {
|
| + if (!locked_)
|
| + return;
|
| + locked_ = false;
|
| + ReparentBackgroundWidgets(GetBackgroundContainerId(true),
|
| + GetBackgroundContainerId(false));
|
| +}
|
| +
|
| +void DesktopBackgroundController::OnWindowDestroying(aura::Window* window) {
|
| + window->SetProperty(internal::kWindowDesktopComponent,
|
| + static_cast<internal::DesktopBackgroundWidgetController*>(NULL));
|
| +}
|
| +
|
| +void DesktopBackgroundController::SetDesktopBackgroundImageMode() {
|
| + if (desktop_background_mode_ != BACKGROUND_IMAGE) {
|
| + desktop_background_mode_ = BACKGROUND_IMAGE;
|
| + InstallComponentForAllWindows();
|
| + return;
|
| + }
|
|
|
| + Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
|
| for (Shell::RootWindowList::iterator iter = root_windows.begin();
|
| - iter != root_windows.end(); ++iter) {
|
| - SetDesktopBackgroundImage(*iter);
|
| + iter != root_windows.end(); ++iter) {
|
| + aura::RootWindow* root_window = *iter;
|
| + internal::DesktopBackgroundWidgetController* component = root_window->
|
| + GetProperty(internal::kWindowDesktopComponent);
|
| + DCHECK(component);
|
| + DCHECK(component->widget());
|
| + aura::Window* window = component->widget()->GetNativeView();
|
| + gfx::Rect bounds = window->bounds();
|
| + window->SchedulePaintInRect(gfx::Rect(0, 0,
|
| + bounds.width(), bounds.height()));
|
| }
|
| - desktop_background_mode_ = BACKGROUND_IMAGE;
|
| }
|
|
|
| void DesktopBackgroundController::OnWallpaperLoadCompleted(
|
| scoped_refptr<WallpaperOperation> wo) {
|
| current_wallpaper_.reset(wo->ReleaseWallpaperData());
|
|
|
| - UpdateDesktopBackgroundImageMode();
|
| + SetDesktopBackgroundImageMode();
|
|
|
| DCHECK(wo.get() == wallpaper_op_.get());
|
| wallpaper_op_ = NULL;
|
| }
|
|
|
| -void DesktopBackgroundController::CreateEmptyWallpaper() {
|
| - current_wallpaper_.reset(NULL);
|
| - desktop_background_mode_ = BACKGROUND_IMAGE;
|
| +ui::Layer* DesktopBackgroundController::SetColorLayerForContainer(
|
| + SkColor color,
|
| + aura::RootWindow* root_window,
|
| + int container_id) {
|
| + ui::Layer* background_layer = new ui::Layer(ui::LAYER_SOLID_COLOR);
|
| + background_layer->SetColor(color);
|
| +
|
| + Shell::GetContainer(root_window,container_id)->
|
| + layer()->Add(background_layer);
|
| + return background_layer;
|
| +}
|
| +
|
| +void DesktopBackgroundController::InstallComponent(
|
| + aura::RootWindow* root_window) {
|
| + internal::DesktopBackgroundWidgetController* component = NULL;
|
| + int container_id = GetBackgroundContainerId(locked_);
|
| +
|
| + switch (desktop_background_mode_) {
|
| + case BACKGROUND_IMAGE: {
|
| + views::Widget* widget = internal::CreateDesktopBackground(root_window,
|
| + container_id);
|
| + component = new internal::DesktopBackgroundWidgetController(widget);
|
| + break;
|
| + }
|
| + case BACKGROUND_SOLID_COLOR: {
|
| + ui::Layer* layer = SetColorLayerForContainer(background_color_,
|
| + root_window,
|
| + container_id);
|
| + component = new internal::DesktopBackgroundWidgetController(layer);
|
| + break;
|
| + }
|
| + default: {
|
| + NOTREACHED();
|
| + }
|
| + }
|
| + if (NULL == root_window->GetProperty(internal::kWindowDesktopComponent)) {
|
| + // First time for this root window
|
| + root_window->AddObserver(this);
|
| + }
|
| + root_window->SetProperty(internal::kWindowDesktopComponent, component);
|
| +}
|
| +
|
| +void DesktopBackgroundController::InstallComponentForAllWindows() {
|
| Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
|
| for (Shell::RootWindowList::iterator iter = root_windows.begin();
|
| iter != root_windows.end(); ++iter) {
|
| - internal::CreateDesktopBackground(*iter);
|
| + InstallComponent(*iter);
|
| }
|
| }
|
|
|
| +void DesktopBackgroundController::ReparentBackgroundWidgets(int src_container,
|
| + int dst_container) {
|
| + Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
|
| + for (Shell::RootWindowList::iterator iter = root_windows.begin();
|
| + iter != root_windows.end(); ++iter) {
|
| + aura::RootWindow* root_window = *iter;
|
| + internal::DesktopBackgroundWidgetController* component = root_window->
|
| + GetProperty(internal::kWindowDesktopComponent);
|
| + DCHECK(component);
|
| + component->Reparent(root_window,
|
| + src_container,
|
| + dst_container);
|
| + }
|
| +}
|
| +
|
| +int DesktopBackgroundController::GetBackgroundContainerId(bool locked) {
|
| + return locked ? internal::kShellWindowId_LockScreenBackgroundContainer :
|
| + internal::kShellWindowId_DesktopBackgroundContainer;
|
| +}
|
| +
|
| } // namespace ash
|
|
|