Commit eb1e0f0a authored by Ahmed Fakhry's avatar Ahmed Fakhry Committed by Commit Bot

Desks: Fix centered-layout wallpapers in the desk mini view.

The wallpaper paint code of the centered layout used to just
draw the image with its original size centered in the display
area. DeskMiniView which uses WallpaperBaseView to draw the
wallpaper in its small bounds needs to apply a scale to that
original size of the wallpaper image, to scale it down by the
same factor it scales down the desk.

Demo: https://bugs.chromium.org/p/chromium/issues/detail?id=992339#c6

BUG=992339
TEST=Manually, Pick a wallpaper image from the local file system,
     and make its layout centered.

Change-Id: I28e253c8ba48b12a25c83576e41037d1ad24783f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1896245Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Commit-Queue: Ahmed Fakhry <afakhry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#712162}
parent 60b63e24
......@@ -118,7 +118,9 @@ void WallpaperBaseView::OnPaint(gfx::Canvas* canvas) {
const float image_scale = canvas->image_scale();
// Simply centered and not scaled (but may be clipped).
gfx::Rect wallpaper_rect = gfx::ScaleToRoundedRect(
gfx::Rect(wallpaper.size()), 1.f / image_scale);
gfx::Rect(wallpaper.size()),
centered_layout_image_scale_.x() / image_scale,
centered_layout_image_scale_.y() / image_scale);
wallpaper_rect.set_x((width() - wallpaper_rect.width()) / 2);
wallpaper_rect.set_y((height() - wallpaper_rect.height()) / 2);
DrawWallpaper(wallpaper, gfx::Rect(wallpaper.size()), wallpaper_rect,
......
......@@ -6,6 +6,7 @@
#define ASH_WALLPAPER_WALLPAPER_BASE_VIEW_H_
#include "base/macros.h"
#include "ui/gfx/geometry/vector2d_f.h"
#include "ui/views/view.h"
namespace ash {
......@@ -20,6 +21,10 @@ class WallpaperBaseView : public views::View {
WallpaperBaseView() = default;
~WallpaperBaseView() override = default;
void set_centered_layout_image_scale(const gfx::Vector2dF& value) {
centered_layout_image_scale_ = value;
}
// views::View:
const char* GetClassName() const override;
void OnPaint(gfx::Canvas* canvas) override;
......@@ -32,6 +37,14 @@ class WallpaperBaseView : public views::View {
gfx::Canvas* canvas);
private:
// Factor by which we scale the size of the wallpaper image when the wallpaper
// layout is WALLPAPER_LAYOUT_CENTER. This is used by DeskPreviewView, which
// acts as a minified view of the desk, in which case a centered image in the
// big bounds of the display, will not look the same way if we don't scale it
// down by the same factor by which we scale down the desk in the its
// mini_view.
gfx::Vector2dF centered_layout_image_scale_ = gfx::Vector2dF(1.0f, 1.0f);
DISALLOW_COPY_AND_ASSIGN(WallpaperBaseView);
};
......
......@@ -20,6 +20,7 @@
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/rounded_corners_f.h"
#include "ui/gfx/geometry/vector2d_f.h"
#include "ui/gfx/skia_paint_util.h"
#include "ui/views/border.h"
......@@ -292,9 +293,12 @@ void DeskPreviewView::Layout() {
// The desk's contents mirrored layer needs to be scaled down so that it fits
// exactly in the center of the view.
const auto root_size = mini_view_->root_window()->layer()->size();
const gfx::Vector2dF scale{
static_cast<float>(bounds.width()) / root_size.width(),
static_cast<float>(bounds.height()) / root_size.height()};
wallpaper_preview_->set_centered_layout_image_scale(scale);
gfx::Transform transform;
transform.Scale(static_cast<float>(bounds.width()) / root_size.width(),
static_cast<float>(bounds.height()) / root_size.height());
transform.Scale(scale.x(), scale.y());
ui::Layer* desk_mirrored_contents_layer =
desk_mirrored_contents_layer_tree_owner_->root();
DCHECK(desk_mirrored_contents_layer);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment