diff options
author | bshe@chromium.org <bshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-15 16:24:47 +0000 |
---|---|---|
committer | bshe@chromium.org <bshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-15 16:24:47 +0000 |
commit | e70cf0ed41432b87472fcfb7afda83c86091f0be (patch) | |
tree | dc71dca1f858760d79c5da83e837f244d260236e /ash | |
parent | 51533e1bea52a6a7d16578bca8d676e00801b120 (diff) | |
download | chromium_src-e70cf0ed41432b87472fcfb7afda83c86091f0be.zip chromium_src-e70cf0ed41432b87472fcfb7afda83c86091f0be.tar.gz chromium_src-e70cf0ed41432b87472fcfb7afda83c86091f0be.tar.bz2 |
Retry landing "Enable users change desktop background image from settings page in Chromeos Aura build"
Enable user change background image in settings page in Aura build.
Only support change between default background images currently.
This is a second try to land, last time it fails on win_aura build.
The original CL is here: http://codereview.chromium.org/9580023/
TBR=flackr,ben,jhawkins
BUG=105508
TEST=Go to settings page and click "set wallpaper" button to change background image.
Review URL: https://chromiumcodereview.appspot.com/9703031
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@126923 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r-- | ash/accelerators/accelerator_controller.cc | 11 | ||||
-rw-r--r-- | ash/ash.gyp | 4 | ||||
-rw-r--r-- | ash/desktop_background/desktop_background_controller.cc | 77 | ||||
-rw-r--r-- | ash/desktop_background/desktop_background_controller.h | 66 | ||||
-rw-r--r-- | ash/desktop_background/desktop_background_resources.cc | 67 | ||||
-rw-r--r-- | ash/desktop_background/desktop_background_resources.h | 19 | ||||
-rw-r--r-- | ash/desktop_background/desktop_background_view.cc | 15 | ||||
-rw-r--r-- | ash/desktop_background/desktop_background_view.h | 9 | ||||
-rw-r--r-- | ash/shell.cc | 30 | ||||
-rw-r--r-- | ash/shell.h | 21 | ||||
-rw-r--r-- | ash/shell_factory.h | 4 |
11 files changed, 275 insertions, 48 deletions
diff --git a/ash/accelerators/accelerator_controller.cc b/ash/accelerators/accelerator_controller.cc index 0eb7ce8..b43b5f4 100644 --- a/ash/accelerators/accelerator_controller.cc +++ b/ash/accelerators/accelerator_controller.cc @@ -5,6 +5,7 @@ #include "ash/accelerators/accelerator_controller.h" #include "ash/accelerators/accelerator_table.h" +#include "ash/desktop_background/desktop_background_controller.h" #include "ash/ash_switches.h" #include "ash/caps_lock_delegate.h" #include "ash/ime_control_delegate.h" @@ -90,11 +91,13 @@ bool HandleRotateScreen() { } bool HandleToggleDesktopBackgroundMode() { - ash::Shell* shell = ash::Shell::GetInstance(); - if (shell->desktop_background_mode() == ash::Shell::BACKGROUND_IMAGE) - shell->SetDesktopBackgroundMode(ash::Shell::BACKGROUND_SOLID_COLOR); + ash::DesktopBackgroundController* desktop_background_controller = + ash::Shell::GetInstance()->desktop_background_controller(); + if (desktop_background_controller->desktop_background_mode() == + ash::DesktopBackgroundController::BACKGROUND_IMAGE) + desktop_background_controller->SetDesktopBackgroundSolidColorMode(); else - shell->SetDesktopBackgroundMode(ash::Shell::BACKGROUND_IMAGE); + desktop_background_controller->SetPreviousDesktopBackgroundImage(); return true; } diff --git a/ash/ash.gyp b/ash/ash.gyp index a5ee083..2626712 100644 --- a/ash/ash.gyp +++ b/ash/ash.gyp @@ -67,6 +67,10 @@ 'ash_switches.cc', 'ash_switches.h', 'caps_lock_delegate.h', + 'desktop_background/desktop_background_controller.cc', + 'desktop_background/desktop_background_controller.h', + 'desktop_background/desktop_background_resources.cc', + 'desktop_background/desktop_background_resources.h', 'desktop_background/desktop_background_view.cc', 'desktop_background/desktop_background_view.h', 'drag_drop/drag_drop_controller.cc', diff --git a/ash/desktop_background/desktop_background_controller.cc b/ash/desktop_background/desktop_background_controller.cc new file mode 100644 index 0000000..cc4e017 --- /dev/null +++ b/ash/desktop_background/desktop_background_controller.cc @@ -0,0 +1,77 @@ +// 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_controller.h" + +#include "ash/desktop_background/desktop_background_resources.h" +#include "ash/desktop_background/desktop_background_view.h" +#include "ash/shell.h" +#include "ash/shell_factory.h" +#include "ash/shell_window_ids.h" +#include "ash/wm/root_window_layout_manager.h" +#include "base/logging.h" +#include "grit/ui_resources.h" +#include "ui/aura/window.h" +#include "ui/gfx/compositor/layer.h" +#include "ui/gfx/image/image.h" +#include "ui/base/resource/resource_bundle.h" +#include "ui/views/widget/widget.h" + +namespace ash { + +DesktopBackgroundController::DesktopBackgroundController() : + previous_wallpaper_index_(GetDefaultWallpaperIndex()), + desktop_background_mode_(BACKGROUND_IMAGE) { +} + +DesktopBackgroundController::~DesktopBackgroundController() { +} + +void DesktopBackgroundController::OnDesktopBackgroundChanged(int index) { + internal::RootWindowLayoutManager* root_window_layout = + Shell::GetInstance()->root_window_layout(); + if (desktop_background_mode_ == BACKGROUND_SOLID_COLOR) + return; + + DCHECK(root_window_layout->background_widget()->widget_delegate()); + static_cast<internal::DesktopBackgroundView*>( + root_window_layout->background_widget()->widget_delegate())-> + SetWallpaper(GetWallpaper(index)); + previous_wallpaper_index_ = index; +} + +void DesktopBackgroundController::SetDesktopBackgroundImageMode( + const SkBitmap& wallpaper) { + internal::RootWindowLayoutManager* root_window_layout = + Shell::GetInstance()->root_window_layout(); + root_window_layout->SetBackgroundLayer(NULL); + root_window_layout->SetBackgroundWidget( + internal::CreateDesktopBackground(wallpaper)); + desktop_background_mode_ = BACKGROUND_IMAGE; +} + +void DesktopBackgroundController::SetDefaultDesktopBackgroundImage() { + SetDesktopBackgroundImageMode(GetWallpaper(GetDefaultWallpaperIndex())); +} + +void DesktopBackgroundController::SetPreviousDesktopBackgroundImage() { + SetDesktopBackgroundImageMode(GetWallpaper(previous_wallpaper_index_)); +} + +void DesktopBackgroundController::SetDesktopBackgroundSolidColorMode() { + // 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 + Shell* shell = Shell::GetInstance(); + ui::Layer* background_layer = new ui::Layer(ui::Layer::LAYER_SOLID_COLOR); + background_layer->SetColor(SK_ColorBLACK); + shell->GetContainer(internal::kShellWindowId_DesktopBackgroundContainer)-> + layer()->Add(background_layer); + shell->root_window_layout()->SetBackgroundLayer(background_layer); + shell->root_window_layout()->SetBackgroundWidget(NULL); + desktop_background_mode_ = BACKGROUND_SOLID_COLOR; +} + +} // namespace ash diff --git a/ash/desktop_background/desktop_background_controller.h b/ash/desktop_background/desktop_background_controller.h new file mode 100644 index 0000000..e6ef435 --- /dev/null +++ b/ash/desktop_background/desktop_background_controller.h @@ -0,0 +1,66 @@ +// 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_CONTROLLER_H_ +#define ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_CONTROLLER_H_ +#pragma once + +#include "ash/ash_export.h" +#include "base/basictypes.h" + +class SkBitmap; + +namespace ash { + +// A class to listen for login and desktop background change events and set the +// corresponding default wallpaper in Aura shell. +class ASH_EXPORT DesktopBackgroundController { + public: + enum BackgroundMode { + BACKGROUND_IMAGE, + BACKGROUND_SOLID_COLOR + }; + + DesktopBackgroundController(); + virtual ~DesktopBackgroundController(); + + // Get the desktop background mode. + BackgroundMode desktop_background_mode() const { + return desktop_background_mode_; + } + + // Change the desktop background image to wallpaper with |index|. + void OnDesktopBackgroundChanged(int index); + + // Sets the desktop background to image mode and create a new background + // widget with |wallpaper|. + void SetDesktopBackgroundImageMode(const SkBitmap& wallpaper); + + // Sets the desktop background to image mode and create a new background + // widget with default wallpaper. + void SetDefaultDesktopBackgroundImage(); + + // Sets the desktop background to image mode and create a new background + // widget with previous selected wallpaper at run time. + void SetPreviousDesktopBackgroundImage(); + + // Sets the desktop background to solid color mode and create a solid color + // layout. + void SetDesktopBackgroundSolidColorMode(); + + private: + // We need to cache the previously used wallpaper index. So when users switch + // desktop background color mode at run time, we can directly switch back to + // the user selected wallpaper in image mode. + int previous_wallpaper_index_; + + // Can change at runtime. + BackgroundMode desktop_background_mode_; + + DISALLOW_COPY_AND_ASSIGN(DesktopBackgroundController); +}; + +} // namespace ash + +#endif // ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_CONTROLLER_H_ diff --git a/ash/desktop_background/desktop_background_resources.cc b/ash/desktop_background/desktop_background_resources.cc new file mode 100644 index 0000000..f7dc840 --- /dev/null +++ b/ash/desktop_background/desktop_background_resources.cc @@ -0,0 +1,67 @@ +// 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_resources.h" + +#include "base/logging.h" +#include "grit/ui_resources.h" +#include "ui/base/resource/resource_bundle.h" +#include "ui/gfx/image/image.h" +#include "third_party/skia/include/core/SkBitmap.h" + +namespace { + +const int kDefaultWallpaperResources[] = { + IDR_AURA_WALLPAPER, + IDR_AURA_WALLPAPER_1, + IDR_AURA_WALLPAPER_2, + IDR_AURA_WALLPAPER_3, + IDR_AURA_WALLPAPER_4, + IDR_AURA_WALLPAPER_5, + IDR_AURA_WALLPAPER_6, + IDR_AURA_WALLPAPER_7, + IDR_AURA_WALLPAPER_8, +}; + +const int kDefaultWallpaperResourcesThumb[] = { + IDR_AURA_WALLPAPER_THUMB, + IDR_AURA_WALLPAPER_1_THUMB, + IDR_AURA_WALLPAPER_2_THUMB, + IDR_AURA_WALLPAPER_3_THUMB, + IDR_AURA_WALLPAPER_4_THUMB, + IDR_AURA_WALLPAPER_5_THUMB, + IDR_AURA_WALLPAPER_6_THUMB, + IDR_AURA_WALLPAPER_7_THUMB, + IDR_AURA_WALLPAPER_8_THUMB, +}; + +const int kDefaultWallpaperCount = arraysize(kDefaultWallpaperResources); + +const int kDefaultWallpaperIndex = 0; + +} // namespace + +namespace ash { + +int GetDefaultWallpaperIndex() { + return kDefaultWallpaperIndex; +} + +int GetWallpaperCount() { + return kDefaultWallpaperCount; +} + +const SkBitmap& GetWallpaper(int index) { + DCHECK(index >= 0 && index < kDefaultWallpaperCount); + return *ui::ResourceBundle::GetSharedInstance().GetImageNamed( + kDefaultWallpaperResources[index]).ToSkBitmap(); +} + +const SkBitmap& GetWallpaperThumbnail(int index) { + DCHECK(index >= 0 && index < kDefaultWallpaperCount); + return *ui::ResourceBundle::GetSharedInstance().GetImageNamed( + kDefaultWallpaperResourcesThumb[index]).ToSkBitmap(); +} + +} // namespace ash diff --git a/ash/desktop_background/desktop_background_resources.h b/ash/desktop_background/desktop_background_resources.h new file mode 100644 index 0000000..1bcfdf8 --- /dev/null +++ b/ash/desktop_background/desktop_background_resources.h @@ -0,0 +1,19 @@ +// 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_RESOURCES_H_ +#define ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_RESOURCES_H_ + +class SkBitmap; + +namespace ash { + +int GetDefaultWallpaperIndex(); +int GetWallpaperCount(); +const SkBitmap& GetWallpaper(int index); +const SkBitmap& GetWallpaperThumbnail(int index); + +} // namespace ash + +#endif // ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_RESOURCES_H_ diff --git a/ash/desktop_background/desktop_background_view.cc b/ash/desktop_background/desktop_background_view.cc index dbf256f..96c4a6e 100644 --- a/ash/desktop_background/desktop_background_view.cc +++ b/ash/desktop_background/desktop_background_view.cc @@ -28,15 +28,20 @@ static int RoundPositive(double x) { //////////////////////////////////////////////////////////////////////////////// // DesktopBackgroundView, public: -DesktopBackgroundView::DesktopBackgroundView() { - wallpaper_ = *ui::ResourceBundle::GetSharedInstance().GetImageNamed( - IDR_AURA_WALLPAPER_1).ToSkBitmap(); +DesktopBackgroundView::DesktopBackgroundView(const SkBitmap& wallpaper) { + wallpaper_ = wallpaper; wallpaper_.buildMipMap(false); } DesktopBackgroundView::~DesktopBackgroundView() { } +void DesktopBackgroundView::SetWallpaper(const SkBitmap& wallpaper) { + wallpaper_ = wallpaper; + wallpaper_.buildMipMap(false); + SchedulePaint(); +} + //////////////////////////////////////////////////////////////////////////////// // DesktopBackgroundView, views::View overrides: @@ -88,11 +93,11 @@ void DesktopBackgroundView::OnMouseReleased(const views::MouseEvent& event) { Shell::GetInstance()->ShowBackgroundMenu(GetWidget(), event.location()); } -views::Widget* CreateDesktopBackground() { +views::Widget* CreateDesktopBackground(const SkBitmap& wallpaper) { views::Widget* desktop_widget = new views::Widget; views::Widget::InitParams params( views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); - DesktopBackgroundView* view = new DesktopBackgroundView; + DesktopBackgroundView* view = new DesktopBackgroundView(wallpaper); params.delegate = view; params.parent = Shell::GetInstance()->GetContainer( diff --git a/ash/desktop_background/desktop_background_view.h b/ash/desktop_background/desktop_background_view.h index 6af6583..f1f7652 100644 --- a/ash/desktop_background/desktop_background_view.h +++ b/ash/desktop_background/desktop_background_view.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// 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. @@ -15,9 +15,14 @@ namespace internal { class DesktopBackgroundView : public views::WidgetDelegateView { public: - DesktopBackgroundView(); + DesktopBackgroundView(const SkBitmap& wallpaper); virtual ~DesktopBackgroundView(); + // TODO(bshe): Remove this function once issue 117244 is fixed. It is + // currently used in DesktopBackgroundController:: + // OnDesktopBackgroundChanged. + void SetWallpaper(const SkBitmap& wallpaper); + private: // Overridden from views::View: virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; diff --git a/ash/shell.cc b/ash/shell.cc index d3a794a..4b4c29f 100644 --- a/ash/shell.cc +++ b/ash/shell.cc @@ -8,6 +8,9 @@ #include "ash/app_list/app_list.h" #include "ash/ash_switches.h" +#include "ash/desktop_background/desktop_background_controller.h" +#include "ash/desktop_background/desktop_background_resources.h" +#include "ash/desktop_background/desktop_background_view.h" #include "ash/drag_drop/drag_drop_controller.h" #include "ash/focus_cycler.h" #include "ash/ime/input_method_event_filter.h" @@ -341,7 +344,6 @@ Shell::Shell(ShellDelegate* delegate) root_filter_(NULL), delegate_(delegate), shelf_(NULL), - desktop_background_mode_(BACKGROUND_IMAGE), root_window_layout_(NULL), status_widget_(NULL) { aura::Env::GetInstance()->SetMonitorManager( @@ -517,6 +519,9 @@ void Shell::Init() { GetContainer(internal::kShellWindowId_DefaultContainer); launcher_.reset(new Launcher(default_container)); + // This controller needs to be set before SetupManagedWindowMode. + desktop_background_controller_.reset(new DesktopBackgroundController); + InitLayoutManagers(); if (!command_line->HasSwitch(switches::kAuraNoShadows)) @@ -580,27 +585,6 @@ void Shell::ToggleAppList() { app_list_->SetVisible(!app_list_->IsVisible()); } -void Shell::SetDesktopBackgroundMode(BackgroundMode mode) { - if (mode == BACKGROUND_SOLID_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 - ui::Layer* background_layer = new ui::Layer(ui::Layer::LAYER_SOLID_COLOR); - background_layer->SetColor(SK_ColorBLACK); - GetContainer(internal::kShellWindowId_DesktopBackgroundContainer)-> - layer()->Add(background_layer); - root_window_layout_->SetBackgroundLayer(background_layer); - root_window_layout_->SetBackgroundWidget(NULL); - } else { - // Create the desktop background image. - root_window_layout_->SetBackgroundLayer(NULL); - root_window_layout_->SetBackgroundWidget( - internal::CreateDesktopBackground()); - } - desktop_background_mode_ = mode; -} - bool Shell::IsScreenLocked() const { const aura::Window* lock_screen_container = GetContainer( internal::kShellWindowId_LockScreenContainer); @@ -683,7 +667,7 @@ void Shell::InitLayoutManagers() { launcher_->widget()->Show(); // Create the desktop background image. - SetDesktopBackgroundMode(BACKGROUND_IMAGE); + desktop_background_controller_->SetDefaultDesktopBackgroundImage(); } void Shell::DisableWorkspaceGridLayout() { diff --git a/ash/shell.h b/ash/shell.h index 8a0f615..29e6e2b 100644 --- a/ash/shell.h +++ b/ash/shell.h @@ -19,6 +19,7 @@ #include "ui/gfx/insets.h" class CommandLine; +class SkBitmap; namespace aura { class EventFilter; @@ -40,6 +41,7 @@ class Widget; namespace ash { class AcceleratorController; +class DesktopBackgroundController; class Launcher; class NestedDispatcherController; class PowerButtonController; @@ -77,11 +79,6 @@ class WorkspaceController; // takes ownership of the Shell. class ASH_EXPORT Shell { public: - enum BackgroundMode { - BACKGROUND_IMAGE, - BACKGROUND_SOLID_COLOR - }; - enum Direction { FORWARD, BACKWARD @@ -117,8 +114,8 @@ class ASH_EXPORT Shell { // Get the singleton RootWindow used by the Shell. static aura::RootWindow* GetRootWindow(); - BackgroundMode desktop_background_mode() const { - return desktop_background_mode_; + internal::RootWindowLayoutManager* root_window_layout() const { + return root_window_layout_; } aura::Window* GetContainer(int container_id); @@ -135,9 +132,6 @@ class ASH_EXPORT Shell { // Toggles app list. void ToggleAppList(); - // Sets the desktop background mode. - void SetDesktopBackgroundMode(BackgroundMode mode); - // Returns true if the screen is locked. bool IsScreenLocked() const; @@ -176,6 +170,9 @@ class ASH_EXPORT Shell { internal::PartialScreenshotEventFilter* partial_screenshot_filter() { return partial_screenshot_filter_.get(); } + DesktopBackgroundController* desktop_background_controller() { + return desktop_background_controller_.get(); + } PowerButtonController* power_button_controller() { return power_button_controller_.get(); } @@ -263,6 +260,7 @@ class ASH_EXPORT Shell { scoped_ptr<internal::ShadowController> shadow_controller_; scoped_ptr<internal::TooltipController> tooltip_controller_; scoped_ptr<internal::VisibilityController> visibility_controller_; + scoped_ptr<DesktopBackgroundController> desktop_background_controller_; scoped_ptr<PowerButtonController> power_button_controller_; scoped_ptr<VideoDetector> video_detector_; scoped_ptr<WindowCycleController> window_cycle_controller_; @@ -287,9 +285,6 @@ class ASH_EXPORT Shell { ObserverList<ShellObserver> observers_; - // Can change at runtime. - BackgroundMode desktop_background_mode_; - // Owned by aura::RootWindow, cached here for type safety. internal::RootWindowLayoutManager* root_window_layout_; diff --git a/ash/shell_factory.h b/ash/shell_factory.h index 0faec35..b90889b 100644 --- a/ash/shell_factory.h +++ b/ash/shell_factory.h @@ -8,6 +8,8 @@ #include "ash/ash_export.h" +class SkBitmap; + namespace views { class View; class Widget; @@ -18,7 +20,7 @@ class Widget; namespace ash { namespace internal { -views::Widget* CreateDesktopBackground(); +views::Widget* CreateDesktopBackground(const SkBitmap& wallpaper); ASH_EXPORT views::Widget* CreateStatusArea(views::View* contents); } // namespace internal |