Commit 4040922c authored by Sammie Quon's avatar Sammie Quon Committed by Commit Bot

inkdrop: Add API to create solid color inkdrop highlights.

Inkdrop highlights are normal created by painting a texture using a
layer delegate into a certain shape. In most cases, this shape matches
the shape provided by the ink drop mask/clip, so a solid color layer
would achieve the same results, and is cheaper.

Test: manual
Bug: 1042303
Change-Id: I1919a0a4ab651581fa4001e9b6086f9be13c2ff5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2036112
Commit-Queue: Sammie Quon <sammiequon@chromium.org>
Reviewed-by: default avatarPeter Boström <pbos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738010}
parent 6167a158
...@@ -134,10 +134,8 @@ class OverviewCloseButton : public views::ImageButton { ...@@ -134,10 +134,8 @@ class OverviewCloseButton : public views::ImageButton {
std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight() std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight()
const override { const override {
return std::make_unique<views::InkDropHighlight>( return std::make_unique<views::InkDropHighlight>(
gfx::PointF(GetLocalBounds().CenterPoint()), gfx::SizeF(GetLocalBounds().size()),
std::make_unique<views::CircleLayerDelegate>( kCloseButtonInkDropRippleHighlightColor);
kCloseButtonInkDropRippleHighlightColor,
kCloseButtonInkDropRadiusDp));
} }
}; };
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "ui/compositor/scoped_layer_animation_settings.h" #include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/gfx/animation/animation.h" #include "ui/gfx/animation/animation.h"
#include "ui/gfx/geometry/insets.h" #include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/size_conversions.h"
#include "ui/views/animation/ink_drop_highlight_observer.h" #include "ui/views/animation/ink_drop_highlight_observer.h"
#include "ui/views/animation/ink_drop_painted_layer_delegates.h" #include "ui/views/animation/ink_drop_painted_layer_delegates.h"
#include "ui/views/animation/ink_drop_util.h" #include "ui/views/animation/ink_drop_util.h"
...@@ -79,6 +80,20 @@ InkDropHighlight::InkDropHighlight(const gfx::Size& size, ...@@ -79,6 +80,20 @@ InkDropHighlight::InkDropHighlight(const gfx::Size& size,
SkColor color) SkColor color)
: InkDropHighlight(gfx::SizeF(size), corner_radius, center_point, color) {} : InkDropHighlight(gfx::SizeF(size), corner_radius, center_point, color) {}
InkDropHighlight::InkDropHighlight(const gfx::SizeF& size, SkColor color)
: visible_opacity_(1.f),
last_animation_initiated_was_fade_in_(false),
observer_(nullptr) {
size_ = explode_size_ = size;
layer_ = std::make_unique<ui::Layer>(ui::LAYER_SOLID_COLOR);
layer_->SetColor(color);
layer_->SetBounds(gfx::Rect(gfx::ToRoundedSize(size)));
layer_->SetVisible(false);
layer_->SetMasksToBounds(false);
layer_->SetName("InkDropHighlight:solid_color_layer");
}
InkDropHighlight::~InkDropHighlight() { InkDropHighlight::~InkDropHighlight() {
// Explicitly aborting all the animations ensures all callbacks are invoked // Explicitly aborting all the animations ensures all callbacks are invoked
// while this instance still exists. // while this instance still exists.
...@@ -156,6 +171,10 @@ void InkDropHighlight::AnimateFade(AnimationType animation_type, ...@@ -156,6 +171,10 @@ void InkDropHighlight::AnimateFade(AnimationType animation_type,
gfx::Transform InkDropHighlight::CalculateTransform( gfx::Transform InkDropHighlight::CalculateTransform(
const gfx::SizeF& size) const { const gfx::SizeF& size) const {
gfx::Transform transform; gfx::Transform transform;
// No transform needed for a solid color layer.
if (!layer_delegate_)
return transform;
transform.Translate(center_point_.x(), center_point_.y()); transform.Translate(center_point_.x(), center_point_.y());
// TODO(bruthig): Fix the InkDropHighlight to work well when initialized with // TODO(bruthig): Fix the InkDropHighlight to work well when initialized with
// a (0x0) size. See https://crbug.com/661618. // a (0x0) size. See https://crbug.com/661618.
......
...@@ -31,8 +31,8 @@ class InkDropHighlightTestApi; ...@@ -31,8 +31,8 @@ class InkDropHighlightTestApi;
class BasePaintedLayerDelegate; class BasePaintedLayerDelegate;
class InkDropHighlightObserver; class InkDropHighlightObserver;
// Manages fade in/out animations for a painted Layer that is used to provide // Manages fade in/out animations for a Layer that is used to provide visual
// visual feedback on ui::Views for highlight states (e.g. mouse hover, keyboard // feedback on ui::Views for highlight states (e.g. mouse hover, keyboard
// focus). // focus).
class VIEWS_EXPORT InkDropHighlight { class VIEWS_EXPORT InkDropHighlight {
public: public:
...@@ -56,6 +56,10 @@ class VIEWS_EXPORT InkDropHighlight { ...@@ -56,6 +56,10 @@ class VIEWS_EXPORT InkDropHighlight {
const gfx::PointF& center_point, const gfx::PointF& center_point,
SkColor color); SkColor color);
// Creates a highlight that is drawn with a solid color layer. It's shape will
// be determined by the mask or clip applied to the parent layer.
InkDropHighlight(const gfx::SizeF& size, SkColor color);
virtual ~InkDropHighlight(); virtual ~InkDropHighlight();
void set_observer(InkDropHighlightObserver* observer) { void set_observer(InkDropHighlightObserver* observer) {
...@@ -130,10 +134,11 @@ class VIEWS_EXPORT InkDropHighlight { ...@@ -130,10 +134,11 @@ class VIEWS_EXPORT InkDropHighlight {
// otherwise. // otherwise.
bool last_animation_initiated_was_fade_in_; bool last_animation_initiated_was_fade_in_;
// The LayerDelegate that paints the highlight |layer_|. // The LayerDelegate that paints the highlight |layer_|. Null if |layer_| is a
// solid color layer.
std::unique_ptr<BasePaintedLayerDelegate> layer_delegate_; std::unique_ptr<BasePaintedLayerDelegate> layer_delegate_;
// The visual highlight layer that is painted by |layer_delegate_|. // The visual highlight layer.
std::unique_ptr<ui::Layer> layer_; std::unique_ptr<ui::Layer> layer_;
InkDropHighlightObserver* observer_; InkDropHighlightObserver* observer_;
......
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