summaryrefslogtreecommitdiffstats
path: root/ash/desktop_background
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-03 18:39:26 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-03 18:39:26 +0000
commit8fd386fa4ea955ec1a0c6b3e42fd30baf17fde80 (patch)
treef8ccafb02305bcecc9d18d7ac943029d442ed135 /ash/desktop_background
parent66edcb54dd11f62cb6b255992a3bd63744953cc4 (diff)
downloadchromium_src-8fd386fa4ea955ec1a0c6b3e42fd30baf17fde80.zip
chromium_src-8fd386fa4ea955ec1a0c6b3e42fd30baf17fde80.tar.gz
chromium_src-8fd386fa4ea955ec1a0c6b3e42fd30baf17fde80.tar.bz2
Revert 149869 because it broke ash_unittests on win_aura and linux_chromeos.
""" 2nd display should show the same background as login/lock screen: Added special container for background on lock screen. Background view can now be created in specific container. Disabled lock screen wallpaper implementation based on serving PNG image via data source. BUG=136853,137581 TEST=Lock screen on multimonitor configuration. Check that windows on secondary display are hidden with background. Review URL: https://chromiumcodereview.appspot.com/10810039 TBR=antrim@chromium.org Review URL: https://chromiumcodereview.appspot.com/10829173 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149878 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/desktop_background')
-rw-r--r--ash/desktop_background/desktop_background_controller.cc165
-rw-r--r--ash/desktop_background/desktop_background_controller.h39
-rw-r--r--ash/desktop_background/desktop_background_view.cc17
-rw-r--r--ash/desktop_background/desktop_background_widget_controller.cc57
-rw-r--r--ash/desktop_background/desktop_background_widget_controller.h54
5 files changed, 64 insertions, 268 deletions
diff --git a/ash/desktop_background/desktop_background_controller.cc b/ash/desktop_background/desktop_background_controller.cc
index a28faa9..022ca0b 100644
--- a/ash/desktop_background/desktop_background_controller.cc
+++ b/ash/desktop_background/desktop_background_controller.cc
@@ -5,7 +5,6 @@
#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"
@@ -19,7 +18,6 @@
#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"
@@ -93,11 +91,9 @@ class DesktopBackgroundController::WallpaperOperation
};
DesktopBackgroundController::DesktopBackgroundController()
- : locked_(false),
- desktop_background_mode_(BACKGROUND_SOLID_COLOR),
+ : desktop_background_mode_(BACKGROUND_IMAGE),
background_color_(SK_ColorGRAY),
weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
- InstallComponentForAllWindows();
}
DesktopBackgroundController::~DesktopBackgroundController() {
@@ -124,16 +120,27 @@ SkBitmap DesktopBackgroundController::GetCurrentWallpaperImage() {
void DesktopBackgroundController::OnRootWindowAdded(
aura::RootWindow* root_window) {
- InstallComponent(root_window);
+ switch (desktop_background_mode_) {
+ case BACKGROUND_IMAGE:
+ if (current_wallpaper_.get()) {
+ SetDesktopBackgroundImage(root_window);
+ } else {
+ internal::CreateDesktopBackground(root_window);
+ }
+ break;
+ case BACKGROUND_SOLID_COLOR:
+ SetDesktopBackgroundSolidColorMode(background_color_);
+ break;
+ }
}
void DesktopBackgroundController::SetDefaultWallpaper(int index) {
// We should not change background when index is invalid. For instance, at
// login screen or stub_user login.
- if (index == GetInvalidWallpaperIndex()) {
+ if (index == ash::GetInvalidWallpaperIndex()) {
CreateEmptyWallpaper();
return;
- } else if (index == GetSolidColorIndex()) {
+ } else if (index == ash::GetSolidColorIndex()) {
SetDesktopBackgroundSolidColorMode(kLoginWallpaperColor);
return;
}
@@ -158,7 +165,8 @@ void DesktopBackgroundController::SetCustomWallpaper(
WallpaperLayout layout) {
CancelPendingWallpaperOperation();
current_wallpaper_.reset(new WallpaperData(layout, wallpaper));
- SetDesktopBackgroundImageMode();
+ desktop_background_mode_ = BACKGROUND_IMAGE;
+ UpdateDesktopBackgroundImageMode();
}
void DesktopBackgroundController::CancelPendingWallpaperOperation() {
@@ -172,142 +180,65 @@ 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;
- if (desktop_background_mode_ != BACKGROUND_SOLID_COLOR) {
- desktop_background_mode_ = BACKGROUND_SOLID_COLOR;
- InstallComponentForAllWindows();
- return;
- }
-
+ desktop_background_mode_ = BACKGROUND_SOLID_COLOR;
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;
- internal::DesktopBackgroundWidgetController* component = root_window->
- GetProperty(internal::kWindowDesktopComponent);
- DCHECK(component);
- DCHECK(component->layer());
- component->layer()->SetColor(background_color_ );
+ Shell::GetContainer(
+ root_window,
+ internal::kShellWindowId_DesktopBackgroundContainer)->
+ layer()->Add(background_layer);
+ GetRootWindowLayoutManager(root_window)->SetBackgroundLayer(
+ background_layer);
+ GetRootWindowLayoutManager(root_window)->SetBackgroundWidget(NULL);
}
}
-void DesktopBackgroundController::CreateEmptyWallpaper() {
- current_wallpaper_.reset(NULL);
- SetDesktopBackgroundImageMode();
-}
-
-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::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::SetDesktopBackgroundImageMode() {
- if (desktop_background_mode_ != BACKGROUND_IMAGE) {
- desktop_background_mode_ = BACKGROUND_IMAGE;
- InstallComponentForAllWindows();
- return;
- }
-
+void DesktopBackgroundController::UpdateDesktopBackgroundImageMode() {
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);
- DCHECK(component->widget());
- aura::Window* window = component->widget()->GetNativeView();
- gfx::Rect bounds = window->bounds();
- window->SchedulePaintInRect(gfx::Rect(0, 0,
- bounds.width(), bounds.height()));
+ iter != root_windows.end(); ++iter) {
+ SetDesktopBackgroundImage(*iter);
}
+ desktop_background_mode_ = BACKGROUND_IMAGE;
}
void DesktopBackgroundController::OnWallpaperLoadCompleted(
scoped_refptr<WallpaperOperation> wo) {
current_wallpaper_.reset(wo->ReleaseWallpaperData());
- SetDesktopBackgroundImageMode();
+ UpdateDesktopBackgroundImageMode();
DCHECK(wo.get() == wallpaper_op_.get());
wallpaper_op_ = NULL;
}
-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();
- }
- }
- root_window->SetProperty(internal::kWindowDesktopComponent, component);
-}
-
-void DesktopBackgroundController::InstallComponentForAllWindows() {
+void DesktopBackgroundController::CreateEmptyWallpaper() {
+ current_wallpaper_.reset(NULL);
+ desktop_background_mode_ = BACKGROUND_IMAGE;
Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
for (Shell::RootWindowList::iterator iter = root_windows.begin();
iter != root_windows.end(); ++iter) {
- InstallComponent(*iter);
+ internal::CreateDesktopBackground(*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
diff --git a/ash/desktop_background/desktop_background_controller.h b/ash/desktop_background/desktop_background_controller.h
index 4ce2a67..b575654 100644
--- a/ash/desktop_background/desktop_background_controller.h
+++ b/ash/desktop_background/desktop_background_controller.h
@@ -13,7 +13,6 @@
#include "base/memory/weak_ptr.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkColor.h"
-#include "ui/compositor/layer.h"
#include "ui/gfx/image/image_skia.h"
namespace aura {
@@ -95,49 +94,25 @@ class ASH_EXPORT DesktopBackgroundController {
// is SystemGestureEventFilterTest.ThreeFingerSwipe.
void CreateEmptyWallpaper();
- // Move all desktop widgets to locked container.
- void MoveDesktopToLockedContainer();
-
- // Move all desktop widgets to unlocked container.
- void MoveDesktopToUnlockedContainer();
-
private:
// An operation to asynchronously loads wallpaper.
class WallpaperOperation;
struct WallpaperData;
- // Creates view for all root windows, or notifies them to repaint if they
- // already exist.
- void SetDesktopBackgroundImageMode();
+ // Creates a new background widget using the current wallpapaer image and
+ // use it as a background of the |root_window|. Deletes the old widget if any.
+ void SetDesktopBackgroundImage(aura::RootWindow* root_window);
+
+ // Update the background of all root windows using the current wallpaper image
+ // in |current_wallpaper_|.
+ void UpdateDesktopBackgroundImageMode();
// Creates a new background widget and sets the background mode to image mode.
// Called after wallpaper loaded successfully.
void OnWallpaperLoadCompleted(scoped_refptr<WallpaperOperation> wo);
- // Adds layer with solid |color| to container |container_id| in |root_window|.
- ui::Layer* SetColorLayerForContainer(SkColor color,
- aura::RootWindow* root_window,
- int container_id);
-
- // Creates and adds component for current mode (either Widget or Layer) to
- // |root_window|.
- void InstallComponent(aura::RootWindow* root_window);
-
- // Creates and adds component for current mode (either Widget or Layer) to
- // all root windows.
- void InstallComponentForAllWindows();
-
- // Moves all descktop components from one container to other across all root
- // windows.
- void ReparentBackgroundWidgets(int src_container, int dst_container);
-
- // Returns id for background container for unlocked and locked states.
- int GetBackgroundContainerId(bool locked);
-
// Can change at runtime.
- bool locked_;
-
BackgroundMode desktop_background_mode_;
SkColor background_color_;
diff --git a/ash/desktop_background/desktop_background_view.cc b/ash/desktop_background/desktop_background_view.cc
index 28a7a0c..e5f9665 100644
--- a/ash/desktop_background/desktop_background_view.cc
+++ b/ash/desktop_background/desktop_background_view.cc
@@ -10,6 +10,7 @@
#include "ash/desktop_background/desktop_background_controller.h"
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
+#include "ash/wm/root_window_layout_manager.h"
#include "ash/wm/window_animations.h"
#include "base/message_loop.h"
#include "base/utf_string_conversions.h"
@@ -30,10 +31,8 @@ namespace {
class ShowWallpaperAnimationObserver : public ui::ImplicitAnimationObserver {
public:
ShowWallpaperAnimationObserver(aura::RootWindow* root_window,
- int container_id,
views::Widget* desktop_widget)
: root_window_(root_window),
- container_id_(container_id),
desktop_widget_(desktop_widget) {
}
@@ -43,6 +42,11 @@ class ShowWallpaperAnimationObserver : public ui::ImplicitAnimationObserver {
private:
// Overridden from ui::ImplicitAnimationObserver:
virtual void OnImplicitAnimationsCompleted() OVERRIDE {
+ internal::RootWindowLayoutManager* root_window_layout =
+ static_cast<internal::RootWindowLayoutManager*>(
+ root_window_->layout_manager());
+ root_window_layout->SetBackgroundWidget(desktop_widget_);
+
ash::Shell::GetInstance()->
user_wallpaper_delegate()->OnWallpaperAnimationFinished();
@@ -50,7 +54,6 @@ class ShowWallpaperAnimationObserver : public ui::ImplicitAnimationObserver {
}
aura::RootWindow* root_window_;
- int container_id_;
views::Widget* desktop_widget_;
DISALLOW_COPY_AND_ASSIGN(ShowWallpaperAnimationObserver);
@@ -135,8 +138,7 @@ void DesktopBackgroundView::ShowContextMenuForView(views::View* source,
Shell::GetInstance()->ShowBackgroundMenu(GetWidget(), point);
}
-views::Widget* CreateDesktopBackground(aura::RootWindow* root_window,
- int container_id) {
+void CreateDesktopBackground(aura::RootWindow* root_window) {
DesktopBackgroundController* controller = ash::Shell::GetInstance()->
desktop_background_controller();
views::Widget* desktop_widget = new views::Widget;
@@ -146,7 +148,8 @@ views::Widget* CreateDesktopBackground(aura::RootWindow* root_window,
params.delegate = view;
if (controller->GetWallpaper().empty())
params.transparent = true;
- params.parent = root_window->GetChildById(container_id);
+ params.parent = root_window->GetChildById(
+ ash::internal::kShellWindowId_DesktopBackgroundContainer);
desktop_widget->Init(params);
desktop_widget->SetContentsView(view);
ash::WindowVisibilityAnimationType animation_type =
@@ -160,11 +163,9 @@ views::Widget* CreateDesktopBackground(aura::RootWindow* root_window,
desktop_widget->GetNativeView()->layer()->GetAnimator());
settings.SetPreemptionStrategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION);
settings.AddObserver(new ShowWallpaperAnimationObserver(root_window,
- container_id,
desktop_widget));
desktop_widget->Show();
desktop_widget->GetNativeView()->SetName("DesktopBackgroundView");
- return desktop_widget;
}
} // namespace internal
diff --git a/ash/desktop_background/desktop_background_widget_controller.cc b/ash/desktop_background/desktop_background_widget_controller.cc
deleted file mode 100644
index 6e6d799..0000000
--- a/ash/desktop_background/desktop_background_widget_controller.cc
+++ /dev/null
@@ -1,57 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "ash/desktop_background/desktop_background_widget_controller.h"
-
-#include "ui/aura/root_window.h"
-#include "ui/views/widget/widget.h"
-
-DECLARE_WINDOW_PROPERTY_TYPE(ash::internal::DesktopBackgroundWidgetController*);
-
-namespace ash {
-namespace internal {
-
-DEFINE_OWNED_WINDOW_PROPERTY_KEY(DesktopBackgroundWidgetController,
- kWindowDesktopComponent, NULL);
-
-DesktopBackgroundWidgetController::DesktopBackgroundWidgetController(
- views::Widget* widget) : widget_(widget) {
-}
-
-DesktopBackgroundWidgetController::DesktopBackgroundWidgetController(
- ui::Layer* layer) : widget_(NULL) {
- layer_.reset(layer);
-}
-
-DesktopBackgroundWidgetController::~DesktopBackgroundWidgetController() {
- if (widget_) {
- widget_->CloseNow();
- widget_ = NULL;
- } else if (layer_.get())
- layer_.reset(NULL);
-}
-
-void DesktopBackgroundWidgetController::SetBounds(gfx::Rect bounds) {
- if (widget_)
- widget_->SetBounds(bounds);
- else if (layer_.get())
- layer_->SetBounds(bounds);
-}
-
-
-void DesktopBackgroundWidgetController::Reparent(aura::RootWindow* root_window,
- int src_container,
- int dest_container) {
- if (widget_) {
- views::Widget::ReparentNativeView(widget_->GetNativeView(),
- root_window->GetChildById(dest_container));
- } else if (layer_.get()) {
- ui::Layer* layer = layer_.get();
- root_window->GetChildById(src_container)->layer()->Remove(layer);
- root_window->GetChildById(dest_container)->layer()->Add(layer);
- }
-}
-
-} // namespace internal
-} // namespace ash
diff --git a/ash/desktop_background/desktop_background_widget_controller.h b/ash/desktop_background/desktop_background_widget_controller.h
deleted file mode 100644
index fe07ef3..0000000
--- a/ash/desktop_background/desktop_background_widget_controller.h
+++ /dev/null
@@ -1,54 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_WIDGET_CONTROLLER_H_
-#define ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_WIDGET_CONTROLLER_H_
-
-#include "base/memory/scoped_ptr.h"
-#include "ui/aura/window_property.h"
-#include "ui/compositor/layer.h"
-#include "ui/views/widget/widget.h"
-
-namespace ash {
-namespace internal {
-
-// This class hides difference between two possible background implementations:
-// effective Layer-based for solid color, and Widget-based for images.
-class DesktopBackgroundWidgetController {
- public:
- // Create
- explicit DesktopBackgroundWidgetController(views::Widget* widget);
- explicit DesktopBackgroundWidgetController(ui::Layer* layer);
-
- ~DesktopBackgroundWidgetController();
-
- // Set bounds of component that draws background.
- void SetBounds(gfx::Rect bounds);
-
- // Move component from |src_container| in |root_window| to |dest_container|.
- // It is required for lock screen, when we need to move background so that
- // it hides user's windows.
- void Reparent(aura::RootWindow* root_window,
- int src_container,
- int dest_container);
-
- views::Widget* widget() { return widget_; }
- ui::Layer* layer() { return layer_.get(); }
-
- private:
- views::Widget* widget_;
- scoped_ptr<ui::Layer> layer_;
-
- DISALLOW_COPY_AND_ASSIGN(DesktopBackgroundWidgetController);
-};
-
-// Window property key, that binds instance of DesktopBackgroundWidgetController
-// to root windows.
-extern const aura::WindowProperty<DesktopBackgroundWidgetController*>* const
- kWindowDesktopComponent;
-
-} // namespace internal
-} // namespace ash
-
-#endif // ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_WIDGET_CONTROLLER_H_