From ff6c38d6dc90b0bafe92b24f5f4657ff535f813e Mon Sep 17 00:00:00 2001 From: "bshe@chromium.org" Date: Fri, 23 Mar 2012 13:46:07 +0000 Subject: Add image layout parameter for wallpaper +emmanuel's patch: add some new resources and paint background with specified layout. BUG=None TEST=None Review URL: https://chromiumcodereview.appspot.com/9808045 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@128474 0039d316-1c4b-4281-b951-d872f2087c98 --- ash/desktop_background/desktop_background_view.cc | 38 ++++++++++++++++------- 1 file changed, 27 insertions(+), 11 deletions(-) (limited to 'ash/desktop_background/desktop_background_view.cc') diff --git a/ash/desktop_background/desktop_background_view.cc b/ash/desktop_background/desktop_background_view.cc index f00ce1a..797d048 100644 --- a/ash/desktop_background/desktop_background_view.cc +++ b/ash/desktop_background/desktop_background_view.cc @@ -28,15 +28,19 @@ static int RoundPositive(double x) { //////////////////////////////////////////////////////////////////////////////// // DesktopBackgroundView, public: -DesktopBackgroundView::DesktopBackgroundView(const SkBitmap& wallpaper) { +DesktopBackgroundView::DesktopBackgroundView(const SkBitmap& wallpaper, + ImageLayout layout) { wallpaper_ = wallpaper; + image_layout_ = layout; wallpaper_.buildMipMap(false); } DesktopBackgroundView::~DesktopBackgroundView() { } -void DesktopBackgroundView::SetWallpaper(const SkBitmap& wallpaper) { +void DesktopBackgroundView::SetWallpaper(const SkBitmap& wallpaper, + ImageLayout layout) { + image_layout_ = layout; wallpaper_ = wallpaper; wallpaper_.buildMipMap(false); SchedulePaint(); @@ -52,7 +56,8 @@ 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 (wallpaper_.width() > width() && wallpaper_.height() > height()) { + if (image_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. double horizontal_ratio = static_cast(width()) / @@ -72,13 +77,23 @@ void DesktopBackgroundView::OnPaint(gfx::Canvas* canvas) { gfx::Rect wallpaper_cropped_rect = wallpaper_rect.Center(cropped_size); canvas->DrawBitmapInt(wallpaper_, - wallpaper_cropped_rect.x(), wallpaper_cropped_rect.y(), - wallpaper_cropped_rect.width(), wallpaper_cropped_rect.height(), - 0, 0, width(), height(), - true); - } else { - // Tiling. + wallpaper_cropped_rect.x(), wallpaper_cropped_rect.y(), + wallpaper_cropped_rect.width(), wallpaper_cropped_rect.height(), + 0, 0, width(), height(), + true); + } else if (image_layout_ == ash::TILE) { canvas->TileImageInt(wallpaper_, 0, 0, width(), height()); + } else if (image_layout_ == ash::STRETCH){ + // This is generally not recommended as it may show artifacts. + gfx::Rect centered_rect = wallpaper_rect.Center( + gfx::Size(width(), height())); + canvas->DrawBitmapInt(wallpaper_, centered_rect.x(), centered_rect.y(), + centered_rect.width(), centered_rect.height(), 0, 0, width(), height(), + true); + } else { + // All other are simply centered, and not scaled (but may be clipped). + canvas->DrawBitmapInt(wallpaper_, (width() - wallpaper_.width()) / 2, + (height() - wallpaper_.height()) / 2); } } @@ -91,11 +106,12 @@ void DesktopBackgroundView::OnMouseReleased(const views::MouseEvent& event) { Shell::GetInstance()->ShowBackgroundMenu(GetWidget(), event.location()); } -views::Widget* CreateDesktopBackground(const SkBitmap& wallpaper) { +views::Widget* CreateDesktopBackground(const SkBitmap& wallpaper, + ImageLayout layout) { views::Widget* desktop_widget = new views::Widget; views::Widget::InitParams params( views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); - DesktopBackgroundView* view = new DesktopBackgroundView(wallpaper); + DesktopBackgroundView* view = new DesktopBackgroundView(wallpaper, layout); params.delegate = view; params.parent = Shell::GetInstance()->GetContainer( -- cgit v1.1