Commit ce1bbbfd authored by David Black's avatar David Black Committed by Commit Bot

Paint background for holding space tray icon items.

The background is composed of an opaque white circle with a drop shadow.
The next CL will implement painting of the actual contents representing
the associated holding space item.

Screenshot: https://screenshot.googleplex.com/KDyRTn7ALwdy8U2

Bug: 1142572
Change-Id: I9bd8ea71e9977487bd59df69ce78d79015192146
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2503321
Commit-Queue: David Black <dmblack@google.com>
Reviewed-by: default avatarToni Baržić <tbarzic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821829}
parent f99198c0
...@@ -9,12 +9,27 @@ ...@@ -9,12 +9,27 @@
#include "ash/system/holding_space/holding_space_tray_icon.h" #include "ash/system/holding_space/holding_space_tray_icon.h"
#include "ash/system/tray/tray_constants.h" #include "ash/system/tray/tray_constants.h"
#include "ui/compositor/layer.h" #include "ui/compositor/layer.h"
#include "ui/compositor/paint_recorder.h"
#include "ui/compositor/scoped_layer_animation_settings.h" #include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/shadow_util.h"
#include "ui/gfx/skia_paint_util.h"
namespace ash { namespace ash {
namespace { namespace {
// Appearance.
constexpr int kElevation = 2;
// Returns the shadow details to use when painting elevation for `layer`.
const gfx::ShadowDetails GetShadowDetails(const ui::Layer* layer) {
DCHECK(layer);
const gfx::Size size = layer->size();
return gfx::ShadowDetails::Get(
kElevation, /*radius=*/std::min(size.width(), size.height()) / 2);
}
// Performs set up of the specified `animation_settings`. // Performs set up of the specified `animation_settings`.
void SetUpAnimation(ui::ScopedLayerAnimationSettings* animation_settings) { void SetUpAnimation(ui::ScopedLayerAnimationSettings* animation_settings) {
animation_settings->SetPreemptionStrategy( animation_settings->SetPreemptionStrategy(
...@@ -116,6 +131,29 @@ void HoldingSpaceTrayIconItem::AnimateUnshift() { ...@@ -116,6 +131,29 @@ void HoldingSpaceTrayIconItem::AnimateUnshift() {
layer_->SetOpacity(1.f); layer_->SetOpacity(1.f);
} }
void HoldingSpaceTrayIconItem::OnPaintLayer(const ui::PaintContext& context) {
DCHECK(layer_);
const gfx::ShadowDetails& shadow = GetShadowDetails(layer_.get());
const gfx::Insets shadow_margins(gfx::ShadowValue::GetMargin(shadow.values));
gfx::Size contents_size = layer_->size();
contents_size.Enlarge(shadow_margins.width(), shadow_margins.height());
gfx::Rect contents_bounds = layer_->bounds();
contents_bounds.ClampToCenteredSize(contents_size);
ui::PaintRecorder recorder(context, layer_->size());
PaintBackground(recorder.canvas(), contents_bounds);
PaintContents(recorder.canvas(), contents_bounds);
}
void HoldingSpaceTrayIconItem::OnDeviceScaleFactorChanged(
float old_device_scale_factor,
float new_device_scale_factor) {
DCHECK(layer_);
layer_->SchedulePaint(layer_->bounds());
}
void HoldingSpaceTrayIconItem::OnImplicitAnimationsCompleted() { void HoldingSpaceTrayIconItem::OnImplicitAnimationsCompleted() {
if (layer_->visible()) if (layer_->visible())
return; return;
...@@ -129,15 +167,12 @@ void HoldingSpaceTrayIconItem::OnImplicitAnimationsCompleted() { ...@@ -129,15 +167,12 @@ void HoldingSpaceTrayIconItem::OnImplicitAnimationsCompleted() {
} }
} }
// TODO(crbug.com/1142572): Layer should visually represent `item_`.
void HoldingSpaceTrayIconItem::CreateLayer() { void HoldingSpaceTrayIconItem::CreateLayer() {
DCHECK(!layer_); DCHECK(!layer_);
layer_ = std::make_unique<ui::Layer>(ui::LAYER_SOLID_COLOR); layer_ = std::make_unique<ui::Layer>(ui::LAYER_TEXTURED);
layer_->SetBounds(gfx::Rect(0, 0, kTrayItemSize, kTrayItemSize)); layer_->SetBounds(gfx::Rect(0, 0, kTrayItemSize, kTrayItemSize));
layer_->SetColor(SkColorSetA(SK_ColorWHITE, 0.26 * 0xFF));
layer_->SetIsFastRoundedCorner(true);
layer_->SetRoundedCornerRadius(gfx::RoundedCornersF(kTrayItemSize / 2));
layer_->SetTransform(transform_); layer_->SetTransform(transform_);
layer_->set_delegate(this);
} }
// TODO(crbug.com/1142572): Handle side shelf. // TODO(crbug.com/1142572): Handle side shelf.
...@@ -146,4 +181,24 @@ bool HoldingSpaceTrayIconItem::NeedsLayer() const { ...@@ -146,4 +181,24 @@ bool HoldingSpaceTrayIconItem::NeedsLayer() const {
return x < kHoldingSpaceTrayIconMaxVisibleItems * kTrayItemSize / 2; return x < kHoldingSpaceTrayIconMaxVisibleItems * kTrayItemSize / 2;
} }
// TODO(crbug.com/1142572): Support theming.
void HoldingSpaceTrayIconItem::PaintBackground(
gfx::Canvas* canvas,
const gfx::Rect& contents_bounds) {
cc::PaintFlags flags;
flags.setAntiAlias(true);
flags.setColor(SK_ColorWHITE);
flags.setLooper(
gfx::CreateShadowDrawLooper(GetShadowDetails(layer_.get()).values));
canvas->DrawCircle(
contents_bounds.CenterPoint(),
std::min(contents_bounds.width(), contents_bounds.height()) / 2, flags);
}
// TODO(crbug.com/1142572): Implement.
void HoldingSpaceTrayIconItem::PaintContents(gfx::Canvas* canvas,
const gfx::Rect& contents_bounds) {
NOTIMPLEMENTED();
}
} // namespace ash } // namespace ash
...@@ -11,6 +11,11 @@ ...@@ -11,6 +11,11 @@
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "base/callback.h" #include "base/callback.h"
#include "ui/compositor/layer_animation_observer.h" #include "ui/compositor/layer_animation_observer.h"
#include "ui/compositor/layer_delegate.h"
namespace gfx {
class Canvas;
} // namespace gfx
namespace ui { namespace ui {
class Layer; class Layer;
...@@ -25,7 +30,8 @@ class HoldingSpaceTrayIcon; ...@@ -25,7 +30,8 @@ class HoldingSpaceTrayIcon;
// space tray icon in the shelf. While determined to be within the icon's // space tray icon in the shelf. While determined to be within the icon's
// viewport, each instance will manage a layer for the holding space tray icon. // viewport, each instance will manage a layer for the holding space tray icon.
class ASH_EXPORT HoldingSpaceTrayIconItem class ASH_EXPORT HoldingSpaceTrayIconItem
: public ui::ImplicitAnimationObserver { : public ui::LayerDelegate,
public ui::ImplicitAnimationObserver {
public: public:
HoldingSpaceTrayIconItem(HoldingSpaceTrayIcon*, const HoldingSpaceItem*); HoldingSpaceTrayIconItem(HoldingSpaceTrayIcon*, const HoldingSpaceItem*);
HoldingSpaceTrayIconItem(const HoldingSpaceTrayIconItem&) = delete; HoldingSpaceTrayIconItem(const HoldingSpaceTrayIconItem&) = delete;
...@@ -48,6 +54,11 @@ class ASH_EXPORT HoldingSpaceTrayIconItem ...@@ -48,6 +54,11 @@ class ASH_EXPORT HoldingSpaceTrayIconItem
const HoldingSpaceItem* item() const { return item_; } const HoldingSpaceItem* item() const { return item_; }
private: private:
// ui::LayerDelegate:
void OnPaintLayer(const ui::PaintContext& context) override;
void OnDeviceScaleFactorChanged(float old_device_scale_factor,
float new_device_scale_factor) override;
// ui::ImplicitAnimationObserver: // ui::ImplicitAnimationObserver:
void OnImplicitAnimationsCompleted() override; void OnImplicitAnimationsCompleted() override;
...@@ -61,6 +72,10 @@ class ASH_EXPORT HoldingSpaceTrayIconItem ...@@ -61,6 +72,10 @@ class ASH_EXPORT HoldingSpaceTrayIconItem
// space tray `icon_`, this is used to gate creation/deletion of `layer_`. // space tray `icon_`, this is used to gate creation/deletion of `layer_`.
bool NeedsLayer() const; bool NeedsLayer() const;
// Invoked to paint the background/contents to the given `canvas`.
void PaintBackground(gfx::Canvas* canvas, const gfx::Rect& contents_bounds);
void PaintContents(gfx::Canvas* canvas, const gfx::Rect& contents_bounds);
HoldingSpaceTrayIcon* const icon_; HoldingSpaceTrayIcon* const icon_;
const HoldingSpaceItem* item_; const HoldingSpaceItem* item_;
......
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