summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbshe@chromium.org <bshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-28 14:30:18 +0000
committerbshe@chromium.org <bshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-28 14:30:18 +0000
commit3659dcb674859d6451e42bbdb141f38dba202edb (patch)
treedda38449f255eaa95c2cf3935ca8abe63f12e5e0
parent108d7f756b27b7a929a92e6416d982ceea299a1e (diff)
downloadchromium_src-3659dcb674859d6451e42bbdb141f38dba202edb.zip
chromium_src-3659dcb674859d6451e42bbdb141f38dba202edb.tar.gz
chromium_src-3659dcb674859d6451e42bbdb141f38dba202edb.tar.bz2
Merge 256482 "Stretch CENTER_CROPPED wallpaper to fill screen"
> Stretch CENTER_CROPPED wallpaper to fill screen > > If a screen is larger than wallpaper, we used to pain black rectangle on > both side that is not covered by wallpaper. As large monitor becomes more > popular, we decide to scale and crop wallpaper in that case. > > > BUG=chrome-os-parter:26288 > > Review URL: https://codereview.chromium.org/189623005 TBR=bshe@chromium.org Review URL: https://codereview.chromium.org/216153003 git-svn-id: svn://svn.chromium.org/chrome/branches/1847/src@260121 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ash/desktop_background/desktop_background_view.cc32
1 files changed, 16 insertions, 16 deletions
diff --git a/ash/desktop_background/desktop_background_view.cc b/ash/desktop_background/desktop_background_view.cc
index acf4e3b..a9aa9eb 100644
--- a/ash/desktop_background/desktop_background_view.cc
+++ b/ash/desktop_background/desktop_background_view.cc
@@ -89,14 +89,18 @@ DesktopBackgroundView::~DesktopBackgroundView() {
void DesktopBackgroundView::OnPaint(gfx::Canvas* canvas) {
// Scale the image while maintaining the aspect ratio, cropping as
// necessary to fill the background. Ideally the image should be larger
- // than the largest display supported, if not we will center it rather than
- // streching to avoid upsampling artifacts (Note that we could tile too, but
- // decided not to do this at the moment).
+ // than the largest display supported, if not we will scale and center it if
+ // the layout is WALLPAPER_LAYOUT_CENTER_CROPPED.
DesktopBackgroundController* controller =
Shell::GetInstance()->desktop_background_controller();
gfx::ImageSkia wallpaper = controller->GetWallpaper();
WallpaperLayout wallpaper_layout = controller->GetWallpaperLayout();
+ if (wallpaper.isNull()) {
+ canvas->FillRect(GetLocalBounds(), SK_ColorBLACK);
+ return;
+ }
+
gfx::NativeView native_view = GetWidget()->GetNativeView();
gfx::Display display = gfx::Screen::GetScreenFor(native_view)->
GetDisplayNearestWindow(native_view);
@@ -112,9 +116,7 @@ void DesktopBackgroundView::OnPaint(gfx::Canvas* canvas) {
gfx::Rect wallpaper_rect(
0, 0, wallpaper.width() * scaling, wallpaper.height() * scaling);
- if (wallpaper_layout == WALLPAPER_LAYOUT_CENTER_CROPPED &&
- wallpaper_rect.width() >= width() &&
- wallpaper_rect.height() >= height()) {
+ if (wallpaper_layout == WALLPAPER_LAYOUT_CENTER_CROPPED) {
// 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<double>(width()) /
@@ -150,16 +152,14 @@ void DesktopBackgroundView::OnPaint(gfx::Canvas* canvas) {
// Fill with black to make sure that the entire area is opaque.
canvas->FillRect(GetLocalBounds(), SK_ColorBLACK);
// All other are simply centered, and not scaled (but may be clipped).
- if (wallpaper.width() && wallpaper.height()) {
- canvas->DrawImageInt(
- wallpaper,
- 0, 0, wallpaper.width(), wallpaper.height(),
- (width() - wallpaper_rect.width()) / 2,
- (height() - wallpaper_rect.height()) / 2,
- wallpaper_rect.width(),
- wallpaper_rect.height(),
- true);
- }
+ canvas->DrawImageInt(
+ wallpaper,
+ 0, 0, wallpaper.width(), wallpaper.height(),
+ (width() - wallpaper_rect.width()) / 2,
+ (height() - wallpaper_rect.height()) / 2,
+ wallpaper_rect.width(),
+ wallpaper_rect.height(),
+ true);
}
}