summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
authorbshe@chromium.org <bshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-15 21:41:37 +0000
committerbshe@chromium.org <bshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-15 21:41:37 +0000
commit2f5b48321398324f5a17e1a735099dca3d95024e (patch)
tree066c9e3f53a0038dc00f5c0d6ad1463467c176e5 /ash
parent977b06c4da2de240e262ff4e1ea3c56873bd9ee4 (diff)
downloadchromium_src-2f5b48321398324f5a17e1a735099dca3d95024e.zip
chromium_src-2f5b48321398324f5a17e1a735099dca3d95024e.tar.gz
chromium_src-2f5b48321398324f5a17e1a735099dca3d95024e.tar.bz2
Implement user selected wallpaper feature.
BUG=123612, 122791 TEST=Verify if custom wallpaper is supported Review URL: https://chromiumcodereview.appspot.com/10375010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137258 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r--ash/desktop_background/desktop_background_controller.cc19
-rw-r--r--ash/desktop_background/desktop_background_controller.h31
-rw-r--r--ash/desktop_background/desktop_background_resources.h4
-rw-r--r--ash/desktop_background/desktop_background_view.cc16
-rw-r--r--ash/desktop_background/desktop_background_view.h5
-rw-r--r--ash/shell_factory.h3
6 files changed, 47 insertions, 31 deletions
diff --git a/ash/desktop_background/desktop_background_controller.cc b/ash/desktop_background/desktop_background_controller.cc
index f95c32e..5b2562e 100644
--- a/ash/desktop_background/desktop_background_controller.cc
+++ b/ash/desktop_background/desktop_background_controller.cc
@@ -41,10 +41,8 @@ class DesktopBackgroundController::WallpaperOperation
void LoadingWallpaper() {
if (cancel_flag_.IsSet())
return;
-
wallpaper_ = ui::ResourceBundle::GetSharedInstance().GetImageNamed(
GetWallpaperInfo(index_).id).ToSkBitmap();
-
if (cancel_flag_.IsSet())
return;
layout_ = GetWallpaperInfo(index_).layout;
@@ -58,7 +56,7 @@ class DesktopBackgroundController::WallpaperOperation
return wallpaper_;
}
- ImageLayout image_layout() {
+ WallpaperLayout wallpaper_layout() {
return layout_;
}
@@ -69,12 +67,11 @@ class DesktopBackgroundController::WallpaperOperation
private:
friend class base::RefCountedThreadSafe<
DesktopBackgroundController::WallpaperOperation>;
- ~WallpaperOperation(){};
base::CancellationFlag cancel_flag_;
const SkBitmap* wallpaper_;
- ImageLayout layout_;
+ WallpaperLayout layout_;
int index_;
DISALLOW_COPY_AND_ASSIGN(WallpaperOperation);
@@ -93,6 +90,7 @@ DesktopBackgroundController::~DesktopBackgroundController() {
void DesktopBackgroundController::SetDefaultWallpaper(int index) {
if (previous_index_ == index)
return;
+
CancelPendingWallpaperOperation();
wallpaper_op_ = new WallpaperOperation(index);
@@ -105,6 +103,15 @@ void DesktopBackgroundController::SetDefaultWallpaper(int index) {
true /* task_is_slow */);
}
+void DesktopBackgroundController::SetCustomWallpaper(const SkBitmap& wallpaper,
+ WallpaperLayout layout) {
+ internal::RootWindowLayoutManager* root_window_layout =
+ Shell::GetInstance()->root_window_layout();
+ root_window_layout->SetBackgroundLayer(NULL);
+ internal::CreateDesktopBackground(wallpaper, layout);
+ desktop_background_mode_ = BACKGROUND_IMAGE;
+}
+
void DesktopBackgroundController::CancelPendingWallpaperOperation() {
// Set canceled flag of previous request to skip unneeded loading.
if (wallpaper_op_.get())
@@ -148,7 +155,7 @@ void DesktopBackgroundController::SetDesktopBackgroundImageMode(
Shell::GetInstance()->root_window_layout();
root_window_layout->SetBackgroundLayer(NULL);
if(wo->wallpaper()) {
- internal::CreateDesktopBackground(*wo->wallpaper(), wo->image_layout());
+ internal::CreateDesktopBackground(*wo->wallpaper(), wo->wallpaper_layout());
desktop_background_mode_ = BACKGROUND_IMAGE;
}
}
diff --git a/ash/desktop_background/desktop_background_controller.h b/ash/desktop_background/desktop_background_controller.h
index b31a214..a531001 100644
--- a/ash/desktop_background/desktop_background_controller.h
+++ b/ash/desktop_background/desktop_background_controller.h
@@ -22,7 +22,7 @@ class UserWallpaperDelegate {
// Gets the index of user selected wallpaper.
virtual const int GetUserWallpaperIndex() = 0;
- // Open the set wallpaper page in the browser.
+ // Opens the set wallpaper page in the browser.
virtual void OpenSetWallpaperPage() = 0;
// Returns true if user can open set wallpaper page. Only guest user returns
@@ -30,8 +30,8 @@ class UserWallpaperDelegate {
virtual bool CanOpenSetWallpaperPage() = 0;
};
-// A class to listen for login and desktop background change events and set the
-// corresponding default wallpaper in Aura shell.
+// Loads selected desktop wallpaper from file system asynchronously and updates
+// background layer if loaded successfully.
class ASH_EXPORT DesktopBackgroundController {
public:
enum BackgroundMode {
@@ -42,39 +42,44 @@ class ASH_EXPORT DesktopBackgroundController {
DesktopBackgroundController();
virtual ~DesktopBackgroundController();
- // Get the desktop background mode.
+ // Gets the desktop background mode.
BackgroundMode desktop_background_mode() const {
return desktop_background_mode_;
}
- // Load default wallpaper at |index| asynchronously and set to current
+ // Loads default wallpaper at |index| asynchronously and sets to current
// wallpaper after loaded.
void SetDefaultWallpaper(int index);
- // Cancel the current wallpaper loading operation.
+ // Sets the user selected custom wallpaper. Called when user selected a file
+ // from file system or changed the layout of wallpaper.
+ void SetCustomWallpaper(const SkBitmap& wallpaper, WallpaperLayout layout);
+
+ // Cancels the current wallpaper loading operation.
void CancelPendingWallpaperOperation();
- // Load logged in user wallpaper asynchronously and set to current wallpaper
+ // Loads logged in user wallpaper asynchronously and sets to current wallpaper
// after loaded.
void SetLoggedInUserWallpaper();
- // Sets the desktop background to solid color mode and create a solid color
+ // Sets the desktop background to solid color mode and creates a solid color
// layout.
void SetDesktopBackgroundSolidColorMode();
private:
- // An operation to asynchronously load wallpaper.
+ // An operation to asynchronously loads wallpaper.
class WallpaperOperation;
- // Sets the desktop background to image mode and create a new background
- // widget with user selected wallpaper or default wallpaper. Delete the old
+ // Sets the desktop background to image mode and creates a new background
+ // widget with user selected wallpaper or default wallpaper. Deletes the old
// widget if any.
void SetDesktopBackgroundImageMode(scoped_refptr<WallpaperOperation> wo);
- // Default wallpapper loaded, set the background mode to image mode.
+ // Creates a new background widget and sets the background mode to image mode.
+ // Called after wallpaper loaded successfully.
void OnWallpaperLoadCompleted(scoped_refptr<WallpaperOperation> wo);
- // Create an empty wallpaper. Some tests require a wallpaper widget is ready
+ // Creates an empty wallpaper. Some tests require a wallpaper widget is ready
// when running. However, the wallpaper widgets are now created asynchronously
// . If loading a real wallpaper, there are cases that these tests crash
// because the required widget is not ready. This function synchronously
diff --git a/ash/desktop_background/desktop_background_resources.h b/ash/desktop_background/desktop_background_resources.h
index 19f23d0..4b48e9d 100644
--- a/ash/desktop_background/desktop_background_resources.h
+++ b/ash/desktop_background/desktop_background_resources.h
@@ -11,7 +11,7 @@ class SkBitmap;
namespace ash {
-enum ImageLayout {
+enum WallpaperLayout {
CENTER,
CENTER_CROPPED,
STRETCH,
@@ -21,7 +21,7 @@ enum ImageLayout {
struct ASH_EXPORT WallpaperInfo {
int id;
int thumb_id;
- ImageLayout layout;
+ WallpaperLayout layout;
// TODO(bshe): author member should be encoded to UTF16. We need to use i18n
// string for this member after M19.
const char* author;
diff --git a/ash/desktop_background/desktop_background_view.cc b/ash/desktop_background/desktop_background_view.cc
index 80e3ce0..c1c08d8 100644
--- a/ash/desktop_background/desktop_background_view.cc
+++ b/ash/desktop_background/desktop_background_view.cc
@@ -61,9 +61,9 @@ static int RoundPositive(double x) {
// DesktopBackgroundView, public:
DesktopBackgroundView::DesktopBackgroundView(const SkBitmap& wallpaper,
- ImageLayout layout) {
+ WallpaperLayout wallpaper_layout) {
wallpaper_ = wallpaper;
- image_layout_ = layout;
+ wallpaper_layout_ = wallpaper_layout;
wallpaper_.buildMipMap(false);
}
@@ -80,7 +80,7 @@ void DesktopBackgroundView::OnPaint(gfx::Canvas* canvas) {
// streching to avoid upsampling artifacts (Note that we could tile too, but
// decided not to do this at the moment).
gfx::Rect wallpaper_rect(0, 0, wallpaper_.width(), wallpaper_.height());
- if (image_layout_ == ash::CENTER_CROPPED && wallpaper_.width() > width()
+ if (wallpaper_layout_ == ash::CENTER_CROPPED && wallpaper_.width() > width()
&& wallpaper_.height() > height()) {
// The dimension with the smallest ratio must be cropped, the other one
// is preserved. Both are set in gfx::Size cropped_size.
@@ -105,9 +105,9 @@ void DesktopBackgroundView::OnPaint(gfx::Canvas* canvas) {
wallpaper_cropped_rect.width(), wallpaper_cropped_rect.height(),
0, 0, width(), height(),
true);
- } else if (image_layout_ == ash::TILE) {
+ } else if (wallpaper_layout_ == ash::TILE) {
canvas->TileImageInt(wallpaper_, 0, 0, width(), height());
- } else if (image_layout_ == ash::STRETCH) {
+ } else if (wallpaper_layout_ == ash::STRETCH) {
// This is generally not recommended as it may show artifacts.
canvas->DrawBitmapInt(wallpaper_, 0, 0, wallpaper_.width(),
wallpaper_.height(), 0, 0, width(), height(), true);
@@ -127,11 +127,13 @@ void DesktopBackgroundView::OnMouseReleased(const views::MouseEvent& event) {
Shell::GetInstance()->ShowBackgroundMenu(GetWidget(), event.location());
}
-void CreateDesktopBackground(const SkBitmap& wallpaper, ImageLayout layout) {
+void CreateDesktopBackground(const SkBitmap& wallpaper,
+ WallpaperLayout wallpaper_layout) {
views::Widget* desktop_widget = new views::Widget;
views::Widget::InitParams params(
views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
- DesktopBackgroundView* view = new DesktopBackgroundView(wallpaper, layout);
+ DesktopBackgroundView* view = new DesktopBackgroundView(wallpaper,
+ wallpaper_layout);
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 3effb1f..4a5b676 100644
--- a/ash/desktop_background/desktop_background_view.h
+++ b/ash/desktop_background/desktop_background_view.h
@@ -16,7 +16,8 @@ namespace internal {
class DesktopBackgroundView : public views::WidgetDelegateView {
public:
- DesktopBackgroundView(const SkBitmap& wallpaper, ImageLayout layout);
+ DesktopBackgroundView(const SkBitmap& wallpaper,
+ WallpaperLayout wallpaper_layout);
virtual ~DesktopBackgroundView();
private:
@@ -26,7 +27,7 @@ class DesktopBackgroundView : public views::WidgetDelegateView {
virtual void OnMouseReleased(const views::MouseEvent& event) OVERRIDE;
SkBitmap wallpaper_;
- ImageLayout image_layout_;
+ WallpaperLayout wallpaper_layout_;
DISALLOW_COPY_AND_ASSIGN(DesktopBackgroundView);
};
diff --git a/ash/shell_factory.h b/ash/shell_factory.h
index 03b8170..c1ebf51e 100644
--- a/ash/shell_factory.h
+++ b/ash/shell_factory.h
@@ -21,7 +21,8 @@ class Widget;
namespace ash {
namespace internal {
-void CreateDesktopBackground(const SkBitmap& wallpaper, ImageLayout layout);
+void CreateDesktopBackground(const SkBitmap& wallpaper,
+ WallpaperLayout wallpaper_layout);
ASH_EXPORT views::Widget* CreateStatusArea(views::View* contents);
} // namespace internal