Commit e39ae2ba authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Remove dead code.

Create(Default,Square)InkDropHighlight() are never called.  Removing
these removed the only caller of set_explode_size(), which meant the
explode size was always the same as the nomal size.  This in turn
allowed removing the scaling transform machinery.

Bug: none
Change-Id: I63e6dca81db75ec16d2d1c079de4bdc0e6589625
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2067550Reviewed-by: default avatarPeter Boström <pbos@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#744066}
parent e2902619
......@@ -28,9 +28,6 @@ namespace {
// The opacity of the highlight when it is not visible.
constexpr float kHiddenOpacity = 0.0f;
// Default opacity of the highlight.
constexpr float kDefaultOpacity = 0.128f;
} // namespace
std::string ToString(InkDropHighlight::AnimationType animation_type) {
......@@ -40,24 +37,16 @@ std::string ToString(InkDropHighlight::AnimationType animation_type) {
case InkDropHighlight::AnimationType::kFadeOut:
return std::string("FADE_OUT");
}
NOTREACHED()
<< "Should never be reached but is necessary for some compilers.";
return std::string("UNKNOWN");
}
InkDropHighlight::InkDropHighlight(
const gfx::PointF& center_point,
std::unique_ptr<BasePaintedLayerDelegate> layer_delegate)
: center_point_(center_point),
// TODO(sammiequon) : Make the default opacity consistent between all
// constructors.
visible_opacity_(1.f),
last_animation_initiated_was_fade_in_(false),
layer_delegate_(std::move(layer_delegate)),
layer_(new ui::Layer()),
observer_(nullptr) {
layer_(std::make_unique<ui::Layer>()) {
const gfx::RectF painted_bounds = layer_delegate_->GetPaintedBounds();
size_ = explode_size_ = painted_bounds.size();
size_ = painted_bounds.size();
layer_->SetBounds(gfx::ToEnclosingRect(painted_bounds));
layer_->SetFillsBoundsOpaquely(false);
......@@ -73,9 +62,9 @@ InkDropHighlight::InkDropHighlight(const gfx::SizeF& size,
SkColor color)
: InkDropHighlight(
center_point,
std::unique_ptr<BasePaintedLayerDelegate>(
new RoundedRectangleLayerDelegate(color, size, corner_radius))) {
visible_opacity_ = kDefaultOpacity;
std::make_unique<RoundedRectangleLayerDelegate>(color,
size,
corner_radius)) {
layer_->SetOpacity(visible_opacity_);
}
......@@ -86,11 +75,7 @@ InkDropHighlight::InkDropHighlight(const gfx::Size& size,
: InkDropHighlight(gfx::SizeF(size), corner_radius, center_point, color) {}
InkDropHighlight::InkDropHighlight(const gfx::SizeF& size, SkColor base_color)
: last_animation_initiated_was_fade_in_(false), observer_(nullptr) {
size_ = explode_size_ = size;
visible_opacity_ = kDefaultOpacity;
layer_ = std::make_unique<ui::Layer>(ui::LAYER_SOLID_COLOR);
: size_(size), layer_(std::make_unique<ui::Layer>(ui::LAYER_SOLID_COLOR)) {
layer_->SetColor(base_color);
layer_->SetBounds(gfx::Rect(gfx::ToRoundedSize(size)));
layer_->SetVisible(false);
......@@ -112,12 +97,11 @@ bool InkDropHighlight::IsFadingInOrVisible() const {
void InkDropHighlight::FadeIn(const base::TimeDelta& duration) {
layer_->SetOpacity(kHiddenOpacity);
layer_->SetVisible(true);
AnimateFade(AnimationType::kFadeIn, duration, size_, size_);
AnimateFade(AnimationType::kFadeIn, duration);
}
void InkDropHighlight::FadeOut(const base::TimeDelta& duration, bool explode) {
AnimateFade(AnimationType::kFadeOut, duration, size_,
explode ? explode_size_ : size_);
void InkDropHighlight::FadeOut(const base::TimeDelta& duration) {
AnimateFade(AnimationType::kFadeOut, duration);
}
test::InkDropHighlightTestApi* InkDropHighlight::GetTestApi() {
......@@ -125,16 +109,14 @@ test::InkDropHighlightTestApi* InkDropHighlight::GetTestApi() {
}
void InkDropHighlight::AnimateFade(AnimationType animation_type,
const base::TimeDelta& duration,
const gfx::SizeF& initial_size,
const gfx::SizeF& target_size) {
const base::TimeDelta& duration) {
const base::TimeDelta effective_duration =
gfx::Animation::ShouldRenderRichAnimation() ? duration
: base::TimeDelta();
last_animation_initiated_was_fade_in_ =
animation_type == AnimationType::kFadeIn;
layer_->SetTransform(CalculateTransform(initial_size));
layer_->SetTransform(CalculateTransform());
// The |animation_observer| will be destroyed when the
// AnimationStartedCallback() returns true.
......@@ -161,33 +143,16 @@ void InkDropHighlight::AnimateFade(AnimationType animation_type,
opacity_sequence->AddObserver(animation_observer);
animator->StartAnimation(opacity_sequence);
if (initial_size != target_size) {
std::unique_ptr<ui::LayerAnimationElement> transform_element =
ui::LayerAnimationElement::CreateTransformElement(
CalculateTransform(target_size), effective_duration);
ui::LayerAnimationSequence* transform_sequence =
new ui::LayerAnimationSequence(std::move(transform_element));
transform_sequence->AddObserver(animation_observer);
animator->StartAnimation(transform_sequence);
}
animation_observer->SetActive();
}
gfx::Transform InkDropHighlight::CalculateTransform(
const gfx::SizeF& size) const {
gfx::Transform InkDropHighlight::CalculateTransform() const {
gfx::Transform transform;
// No transform needed for a solid color layer.
if (!layer_delegate_)
return transform;
transform.Translate(center_point_.x(), center_point_.y());
// TODO(bruthig): Fix the InkDropHighlight to work well when initialized with
// a (0x0) size. See https://crbug.com/661618.
transform.Scale(size_.width() == 0 ? 0 : size.width() / size_.width(),
size_.height() == 0 ? 0 : size.height() / size_.height());
gfx::Vector2dF layer_offset = layer_delegate_->GetCenteringOffset();
transform.Translate(-layer_offset.x(), -layer_offset.y());
......
......@@ -68,8 +68,6 @@ class VIEWS_EXPORT InkDropHighlight {
observer_ = observer;
}
void set_explode_size(const gfx::SizeF& size) { explode_size_ = size; }
void set_visible_opacity(float visible_opacity) {
visible_opacity_ = visible_opacity;
}
......@@ -81,10 +79,8 @@ class VIEWS_EXPORT InkDropHighlight {
// Fades in the highlight visual over the given |duration|.
void FadeIn(const base::TimeDelta& duration);
// Fades out the highlight visual over the given |duration|. If |explode| is
// true then the highlight will animate a size increase in addition to the
// fade out.
void FadeOut(const base::TimeDelta& duration, bool explode);
// Fades out the highlight visual over the given |duration|.
void FadeOut(const base::TimeDelta& duration);
// The root Layer that can be added in to a Layer tree.
ui::Layer* layer() { return layer_.get(); }
......@@ -97,16 +93,13 @@ class VIEWS_EXPORT InkDropHighlight {
private:
friend class test::InkDropHighlightTestApi;
// Animates a fade in/out as specified by |animation_type| combined with a
// transformation from the |initial_size| to the |target_size| over the given
// Animates a fade in/out as specified by |animation_type| over the given
// |duration|.
void AnimateFade(AnimationType animation_type,
const base::TimeDelta& duration,
const gfx::SizeF& initial_size,
const gfx::SizeF& target_size);
const base::TimeDelta& duration);
// Calculates the Transform to apply to |layer_| for the given |size|.
gfx::Transform CalculateTransform(const gfx::SizeF& size) const;
// Calculates the Transform to apply to |layer_|.
gfx::Transform CalculateTransform() const;
// The callback that will be invoked when a fade in/out animation is started.
void AnimationStartedCallback(
......@@ -121,20 +114,16 @@ class VIEWS_EXPORT InkDropHighlight {
// The size of the highlight shape when fully faded in.
gfx::SizeF size_;
// The target size of the highlight shape when it expands during a fade out
// animation.
gfx::SizeF explode_size_;
// The center point of the highlight shape in the parent Layer's coordinate
// space.
gfx::PointF center_point_;
// The opacity for the fully visible state of the highlight.
float visible_opacity_;
float visible_opacity_ = 0.128f;
// True if the last animation to be initiated was a kFadeIn, and false
// otherwise.
bool last_animation_initiated_was_fade_in_;
bool last_animation_initiated_was_fade_in_ = false;
// The LayerDelegate that paints the highlight |layer_|. Null if |layer_| is a
// solid color layer.
......@@ -143,7 +132,7 @@ class VIEWS_EXPORT InkDropHighlight {
// The visual highlight layer.
std::unique_ptr<ui::Layer> layer_;
InkDropHighlightObserver* observer_;
InkDropHighlightObserver* observer_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(InkDropHighlight);
};
......
......@@ -94,8 +94,7 @@ TEST_F(InkDropHighlightTest, IsHighlightedStateTransitions) {
test_api()->CompleteAnimations();
EXPECT_TRUE(ink_drop_highlight()->IsFadingInOrVisible());
ink_drop_highlight()->FadeOut(base::TimeDelta::FromSeconds(1),
false /* explode */);
ink_drop_highlight()->FadeOut(base::TimeDelta::FromSeconds(1));
EXPECT_FALSE(ink_drop_highlight()->IsFadingInOrVisible());
test_api()->CompleteAnimations();
......@@ -132,8 +131,7 @@ TEST_F(InkDropHighlightTest,
EXPECT_EQ(InkDropHighlight::AnimationType::kFadeIn,
observer()->last_animation_started_context());
ink_drop_highlight()->FadeOut(base::TimeDelta::FromSeconds(1),
false /* explode */);
ink_drop_highlight()->FadeOut(base::TimeDelta::FromSeconds(1));
EXPECT_EQ(InkDropHighlight::AnimationType::kFadeOut,
observer()->last_animation_started_context());
......@@ -158,8 +156,7 @@ TEST_F(InkDropHighlightTest, VerifyObserversAreNotifiedOfPreemptedAnimations) {
return;
ink_drop_highlight()->FadeIn(base::TimeDelta::FromSeconds(1));
ink_drop_highlight()->FadeOut(base::TimeDelta::FromSeconds(1),
false /* explode */);
ink_drop_highlight()->FadeOut(base::TimeDelta::FromSeconds(1));
EXPECT_EQ(2, observer()->last_animation_ended_ordinal());
EXPECT_EQ(InkDropHighlight::AnimationType::kFadeIn,
......@@ -175,8 +172,7 @@ TEST_F(InkDropHighlightTest, NullObserverIsSafe) {
ink_drop_highlight()->FadeIn(base::TimeDelta::FromSeconds(1));
test_api()->CompleteAnimations();
ink_drop_highlight()->FadeOut(base::TimeDelta::FromMilliseconds(0),
false /* explode */);
ink_drop_highlight()->FadeOut(base::TimeDelta::FromMilliseconds(0));
test_api()->CompleteAnimations();
EXPECT_FALSE(ink_drop_highlight()->IsFadingInOrVisible());
}
......@@ -203,15 +199,14 @@ TEST_F(InkDropHighlightTest, AnimationsAbortedDuringDeletion) {
TEST_F(InkDropHighlightTest, AnimatingAZeroSizeHighlight) {
InitHighlight(std::make_unique<InkDropHighlight>(
gfx::Size(0, 0), 3, gfx::PointF(), SK_ColorBLACK));
ink_drop_highlight()->FadeOut(base::TimeDelta::FromMilliseconds(0),
false /* explode */);
ink_drop_highlight()->FadeOut(base::TimeDelta::FromMilliseconds(0));
}
TEST_F(InkDropHighlightTest, TransformIsPixelAligned) {
const float kEpsilon = 0.001f;
gfx::Size highlight_size(10, 10);
constexpr float kEpsilon = 0.001f;
constexpr gfx::Size kHighlightSize(10, 10);
InitHighlight(std::make_unique<InkDropHighlight>(
highlight_size, 3, gfx::PointF(3.5f, 3.5f), SK_ColorYELLOW));
kHighlightSize, 3, gfx::PointF(3.5f, 3.5f), SK_ColorYELLOW));
const gfx::PointF layer_origin(
ink_drop_highlight()->layer()->bounds().origin());
for (auto dsf : {1.25, 1.33, 1.5, 1.6, 1.75, 1.8, 2.25}) {
......@@ -220,8 +215,7 @@ TEST_F(InkDropHighlightTest, TransformIsPixelAligned) {
<< "Device Scale Factor: " << dsf << std::endl);
ink_drop_highlight()->layer()->OnDeviceScaleFactorChanged(dsf);
const gfx::SizeF size(highlight_size);
gfx::Transform transform = test_api()->CalculateTransform(size);
gfx::Transform transform = test_api()->CalculateTransform();
gfx::Point3F transformed_layer_origin(layer_origin.x(), layer_origin.y(),
0);
transform.TransformPoint(&transformed_layer_origin);
......
......@@ -161,21 +161,6 @@ std::unique_ptr<InkDropRipple> InkDropHostView::CreateSquareInkDropRipple(
return ripple;
}
std::unique_ptr<InkDropHighlight>
InkDropHostView::CreateDefaultInkDropHighlight(const gfx::PointF& center_point,
const gfx::Size& size) const {
return CreateSquareInkDropHighlight(center_point, size);
}
std::unique_ptr<InkDropHighlight> InkDropHostView::CreateSquareInkDropHighlight(
const gfx::PointF& center_point,
const gfx::Size& size) const {
auto highlight = std::make_unique<InkDropHighlight>(
size, ink_drop_small_corner_radius_, center_point, GetInkDropBaseColor());
highlight->set_explode_size(gfx::SizeF(CalculateLargeInkDropSize(size)));
return highlight;
}
bool InkDropHostView::HasInkDrop() const {
return !!ink_drop_;
}
......
......@@ -13,10 +13,6 @@
#include "ui/views/animation/ink_drop_event_handler.h"
#include "ui/views/view.h"
namespace gfx {
class PointF;
} // namespace gfx
namespace ui {
class Layer;
class LocatedEvent;
......@@ -168,17 +164,6 @@ class VIEWS_EXPORT InkDropHostView : public View {
const gfx::Point& center_point,
const gfx::Size& size) const;
// TODO(pbos): Migrate uses to CreateSquareInkDropHighlight which this calls
// directly.
std::unique_ptr<InkDropHighlight> CreateDefaultInkDropHighlight(
const gfx::PointF& center_point,
const gfx::Size& size = kDefaultInkDropSize) const;
// Creates a InkDropHighlight centered on |center_point|.
std::unique_ptr<InkDropHighlight> CreateSquareInkDropHighlight(
const gfx::PointF& center_point,
const gfx::Size& size) const;
// Returns true if an ink drop instance has been created.
bool HasInkDrop() const;
......
This diff is collapsed.
......@@ -171,12 +171,10 @@ class VIEWS_EXPORT InkDropImpl : public InkDrop,
std::unique_ptr<HighlightState> CreateStartState();
std::unique_ptr<HighlightState> CreateHiddenState(
base::TimeDelta animation_duration,
bool explode);
base::TimeDelta animation_duration);
std::unique_ptr<HighlightState> CreateVisibleState(
base::TimeDelta animation_duration,
bool explode);
base::TimeDelta animation_duration);
InkDropImpl* ink_drop() { return ink_drop_; }
......@@ -244,11 +242,8 @@ class VIEWS_EXPORT InkDropImpl : public InkDrop,
// Enables or disables the highlight state based on |should_highlight| and if
// an animation is triggered it will be scheduled to have the given
// |animation_duration|. If |explode| is true the highlight will expand as it
// fades out. |explode| is ignored when |should_higlight| is true.
void SetHighlight(bool should_highlight,
base::TimeDelta animation_duration,
bool explode);
// |animation_duration|.
void SetHighlight(bool should_highlight, base::TimeDelta animation_duration);
// Returns true if |this| the highlight should be visible based on the
// hover/focus status.
......
......@@ -26,9 +26,8 @@ std::vector<ui::LayerAnimator*> InkDropHighlightTestApi::GetLayerAnimators() {
return animators;
}
gfx::Transform InkDropHighlightTestApi::CalculateTransform(
const gfx::SizeF& size) {
return ink_drop_highlight()->CalculateTransform(size);
gfx::Transform InkDropHighlightTestApi::CalculateTransform() {
return ink_drop_highlight()->CalculateTransform();
}
} // namespace test
......
......@@ -10,7 +10,6 @@
#include "base/macros.h"
#include "ui/compositor/test/multi_layer_animator_test_controller.h"
#include "ui/compositor/test/multi_layer_animator_test_controller_delegate.h"
#include "ui/gfx/geometry/size_f.h"
#include "ui/gfx/transform.h"
namespace ui {
......@@ -35,7 +34,7 @@ class InkDropHighlightTestApi
// MultiLayerAnimatorTestControllerDelegate:
std::vector<ui::LayerAnimator*> GetLayerAnimators() override;
gfx::Transform CalculateTransform(const gfx::SizeF& size);
gfx::Transform CalculateTransform();
protected:
InkDropHighlight* ink_drop_highlight() {
......
......@@ -142,11 +142,13 @@ std::unique_ptr<views::InkDropHighlight> MdTextButton::CreateInkDropHighlight()
// the mask bounds.
shadows.emplace_back(gfx::Vector2d(0, kYOffset), 2 * kSkiaBlurRadius,
theme->GetSystemColor(shadow_color_id));
return std::make_unique<InkDropHighlight>(
auto highlight = std::make_unique<InkDropHighlight>(
gfx::RectF(GetLocalBounds()).CenterPoint(),
base::WrapUnique(new BorderShadowLayerDelegate(
std::make_unique<BorderShadowLayerDelegate>(
shadows, GetLocalBounds(), theme->GetSystemColor(fill_color_id),
corner_radius_)));
corner_radius_));
highlight->set_visible_opacity(1.0f);
return highlight;
}
void MdTextButton::SetEnabledTextColors(base::Optional<SkColor> color) {
......
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