Commit 6ae5319d authored by David Black's avatar David Black Committed by Chromium LUCI CQ

Restore elevation to holding space tray icon previews.

Per UX request, restoring slight elevation to holding space tray icon
previews to add depth and dilineation.

This CL also makes a slight tweak to shrinking of white backgrounds
that was done to prevent paint artifacts from showing behind images.
Previously we shrunk backgrounds by twice as much as was necessary.

Bug: 1163304
Change-Id: I1b65bb65de3e331f2e58c2993fe1634d5dabcb98
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2618560Reviewed-by: default avatarToni Baržić <tbarzic@chromium.org>
Commit-Queue: David Black <dmblack@google.com>
Cr-Commit-Position: refs/heads/master@{#841669}
parent d54d2584
...@@ -159,8 +159,8 @@ class DragImageItemView : public views::View { ...@@ -159,8 +159,8 @@ class DragImageItemView : public views::View {
// painting the background outside content bounds as might otherwise occur // painting the background outside content bounds as might otherwise occur
// due to pixel rounding. Failure to do so could result in white paint // due to pixel rounding. Failure to do so could result in white paint
// artifacts. // artifacts.
gfx::Rect bounds(GetContentsBounds()); gfx::RectF bounds(GetContentsBounds());
bounds.Inset(gfx::Insets(1)); bounds.Inset(gfx::InsetsF(0.5f));
cc::PaintFlags flags; cc::PaintFlags flags;
flags.setAntiAlias(true); flags.setAntiAlias(true);
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "ash/system/holding_space/holding_space_item_chip_view.h" #include "ash/system/holding_space/holding_space_item_chip_view.h"
#include <algorithm>
#include "ash/public/cpp/holding_space/holding_space_constants.h" #include "ash/public/cpp/holding_space/holding_space_constants.h"
#include "ash/public/cpp/holding_space/holding_space_item.h" #include "ash/public/cpp/holding_space/holding_space_item.h"
#include "ash/public/cpp/rounded_image_view.h" #include "ash/public/cpp/rounded_image_view.h"
...@@ -17,9 +19,41 @@ ...@@ -17,9 +19,41 @@
#include "ui/views/layout/box_layout.h" #include "ui/views/layout/box_layout.h"
#include "ui/views/layout/fill_layout.h" #include "ui/views/layout/fill_layout.h"
#include "ui/views/metadata/metadata_impl_macros.h" #include "ui/views/metadata/metadata_impl_macros.h"
#include "ui/views/painter.h"
namespace ash { namespace ash {
// CirclePainter ---------------------------------------------------------------
class CirclePainter : public views::Painter {
public:
CirclePainter(SkColor color, const gfx::InsetsF& insets)
: color_(color), insets_(insets) {}
CirclePainter(const CirclePainter&) = delete;
CirclePainter& operator=(const CirclePainter&) = delete;
~CirclePainter() override = default;
private:
// views::Painter:
gfx::Size GetMinimumSize() const override { return gfx::Size(); }
void Paint(gfx::Canvas* canvas, const gfx::Size& size) override {
gfx::RectF bounds{gfx::SizeF(size)};
bounds.Inset(insets_);
cc::PaintFlags flags;
flags.setAntiAlias(true);
flags.setColor(color_);
canvas->DrawCircle(
bounds.CenterPoint(),
std::min(bounds.size().width(), bounds.size().height()) / 2.f, flags);
}
const SkColor color_;
const gfx::InsetsF insets_;
};
// HoldingSpaceItemChipView::LabelMaskOwner ------------------------------------ // HoldingSpaceItemChipView::LabelMaskOwner ------------------------------------
class HoldingSpaceItemChipView::LabelMaskLayerOwner : public ui::LayerDelegate { class HoldingSpaceItemChipView::LabelMaskLayerOwner : public ui::LayerDelegate {
...@@ -88,8 +122,12 @@ HoldingSpaceItemChipView::HoldingSpaceItemChipView( ...@@ -88,8 +122,12 @@ HoldingSpaceItemChipView::HoldingSpaceItemChipView(
image_ = AddChildView(std::make_unique<RoundedImageView>( image_ = AddChildView(std::make_unique<RoundedImageView>(
kHoldingSpaceChipIconSize / 2, RoundedImageView::Alignment::kLeading)); kHoldingSpaceChipIconSize / 2, RoundedImageView::Alignment::kLeading));
image_->SetBackground(views::CreateRoundedRectBackground(
SK_ColorWHITE, kHoldingSpaceChipIconSize / 2)); // Shrink circular background by a single pixel to prevent painting outside of
// the image which may otherwise occur due to pixel rounding. Failure to do so
// could result in white paint artifacts.
image_->SetBackground(views::CreateBackgroundFromPainter(
std::make_unique<CirclePainter>(SK_ColorWHITE, gfx::InsetsF(0.5f))));
// Subscribe to be notified of changes to `item_`'s image. // Subscribe to be notified of changes to `item_`'s image.
image_subscription_ = image_subscription_ =
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "ash/system/holding_space/holding_space_tray_icon_preview.h" #include "ash/system/holding_space/holding_space_tray_icon_preview.h"
#include <algorithm>
#include "ash/public/cpp/holding_space/holding_space_constants.h" #include "ash/public/cpp/holding_space/holding_space_constants.h"
#include "ash/public/cpp/holding_space/holding_space_image.h" #include "ash/public/cpp/holding_space/holding_space_image.h"
#include "ash/public/cpp/holding_space/holding_space_item.h" #include "ash/public/cpp/holding_space/holding_space_item.h"
...@@ -20,12 +22,16 @@ ...@@ -20,12 +22,16 @@
#include "ui/gfx/image/image_skia.h" #include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_skia_operations.h" #include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/image/image_skia_source.h" #include "ui/gfx/image/image_skia_source.h"
#include "ui/gfx/shadow_util.h"
#include "ui/gfx/skia_paint_util.h" #include "ui/gfx/skia_paint_util.h"
namespace ash { namespace ash {
namespace { namespace {
// Appearance.
constexpr int kElevation = 1;
// The duration of each of the preview icon bounce animation. // The duration of each of the preview icon bounce animation.
constexpr base::TimeDelta kBounceAnimationSegmentDuration = constexpr base::TimeDelta kBounceAnimationSegmentDuration =
base::TimeDelta::FromMilliseconds(250); base::TimeDelta::FromMilliseconds(250);
...@@ -47,6 +53,13 @@ gfx::Size GetPreviewSize() { ...@@ -47,6 +53,13 @@ gfx::Size GetPreviewSize() {
kHoldingSpaceTrayIconPreviewSize); kHoldingSpaceTrayIconPreviewSize);
} }
// Returns the shadow details for painting elevation.
const gfx::ShadowDetails& GetShadowDetails() {
const gfx::Size size(GetPreviewSize());
const int radius = std::min(size.height(), size.width()) / 2;
return gfx::ShadowDetails::Get(kElevation, radius);
}
// Returns whether the specified `shelf_alignment` is horizontal. // Returns whether the specified `shelf_alignment` is horizontal.
bool IsHorizontal(ShelfAlignment shelf_alignment) { bool IsHorizontal(ShelfAlignment shelf_alignment) {
switch (shelf_alignment) { switch (shelf_alignment) {
...@@ -307,13 +320,16 @@ void HoldingSpaceTrayIconPreview::OnPaintLayer( ...@@ -307,13 +320,16 @@ void HoldingSpaceTrayIconPreview::OnPaintLayer(
cc::PaintFlags flags; cc::PaintFlags flags;
flags.setAntiAlias(true); flags.setAntiAlias(true);
flags.setColor(SK_ColorWHITE); flags.setColor(SK_ColorWHITE);
flags.setLooper(gfx::CreateShadowDrawLooper(GetShadowDetails().values));
canvas->DrawCircle( canvas->DrawCircle(
contents_bounds.CenterPoint(), gfx::PointF(contents_bounds.CenterPoint()),
std::min(contents_bounds.width(), contents_bounds.height()) / 2 - 1, std::min(contents_bounds.width(), contents_bounds.height()) / 2 - 0.5,
flags); flags);
// Contents. // Contents.
// NOTE: The `contents_image_` should already be resized.
if (!contents_image_.isNull()) { if (!contents_image_.isNull()) {
DCHECK_EQ(contents_image_.size(), contents_bounds.size());
canvas->DrawImageInt(contents_image_, contents_bounds.x(), canvas->DrawImageInt(contents_image_, contents_bounds.x(),
contents_bounds.y()); contents_bounds.y());
} }
......
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