Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Unified Diff: ash/desktop_background/desktop_background_view.cc

Issue 9557001: Change Aura desktop background behavior. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: 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 bd535a8a23811006d8ed01759a4749986972e26b..45a4c60500aaeaaf93271820354a50c744b647b1 100644
--- a/ash/desktop_background/desktop_background_view.cc
+++ b/ash/desktop_background/desktop_background_view.cc
@@ -33,10 +33,50 @@ DesktopBackgroundView::~DesktopBackgroundView() {
// DesktopBackgroundView, views::View overrides:
void DesktopBackgroundView::OnPaint(gfx::Canvas* canvas) {
- canvas->DrawBitmapInt(wallpaper_,
- 0, 0, wallpaper_.width(), wallpaper_.height(),
- 0, 0, width(), height(),
- true);
+ // 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).
+ gfx::Rect wallpaper_rect(0, 0, wallpaper_.width(), wallpaper_.height());
+ if (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<double>(width()) /
+ static_cast<double>(wallpaper_.width());
+ double vertical_ratio = static_cast<double>(height()) /
+ static_cast<double>(wallpaper_.height());
+
+ gfx::Size cropped_size;
+ if (vertical_ratio > horizontal_ratio) {
+ cropped_size = gfx::Size(
+ static_cast<int>(static_cast<double>(width()) / vertical_ratio),
Daniel Erat 2012/02/29 21:41:40 nit: round this?
Emmanuel Saint-loubert-Bié 2012/02/29 22:04:16 Do you mean using floor() or similar function and
Daniel Erat 2012/02/29 22:10:40 i meant doing static_cast<int>(round(...)) on the
+ wallpaper_.height());
+ } else {
+ cropped_size = gfx::Size(wallpaper_.width(),
+ static_cast<int>(static_cast<double>(height()) / horizontal_ratio));
Daniel Erat 2012/02/29 21:41:40 nit: round?
+ }
+
+ 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 {
+ // Center the wallpaper and crop to the destination rectangle.
Daniel Erat 2012/02/29 21:41:40 have you tested whether it's okay for the destinat
Emmanuel Saint-loubert-Bié 2012/02/29 22:04:16 Ha yes that works too, much clearer. I applied you
+ gfx::Rect wallpaper_centered_rect = wallpaper_rect.Center(gfx::Size(
+ std::min(wallpaper_.width(), width()),
+ std::min(wallpaper_.height(), height())));
+ canvas->DrawBitmapInt(wallpaper_,
+ wallpaper_centered_rect.x(), wallpaper_centered_rect.y(),
+ wallpaper_centered_rect.width(), wallpaper_centered_rect.height(),
+ std::max(0, (width() - wallpaper_centered_rect.width()) / 2),
+ std::max(0, (height() - wallpaper_centered_rect.height()) / 2),
+ wallpaper_centered_rect.width(), wallpaper_centered_rect.height(),
+ true);
+ }
}
bool DesktopBackgroundView::OnMousePressed(const views::MouseEvent& event) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698