Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(367)

Unified Diff: ui/views/animation/ink_drop_hover.cc

Issue 1924663007: Expand the Material Design hover as it fades out when a ripple is triggered. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/animation/ink_drop_hover.h ('k') | ui/views/animation/ink_drop_hover_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/animation/ink_drop_hover.cc
diff --git a/ui/views/animation/ink_drop_hover.cc b/ui/views/animation/ink_drop_hover.cc
index be440c95b9d4b701e1180204a265b6059c4b1b1c..9bb7b02d8958015a3eedd6acc34b943d79d8d1ae 100644
--- a/ui/views/animation/ink_drop_hover.cc
+++ b/ui/views/animation/ink_drop_hover.cc
@@ -27,7 +27,10 @@ InkDropHover::InkDropHover(const gfx::Size& size,
int corner_radius,
const gfx::Point& center_point,
SkColor color)
- : last_animation_initiated_was_fade_in_(false),
+ : size_(size),
+ explode_size_(size),
+ center_point_(center_point),
+ last_animation_initiated_was_fade_in_(false),
layer_delegate_(
new RoundedRectangleLayerDelegate(color, size, corner_radius)),
layer_(new ui::Layer()) {
@@ -38,11 +41,6 @@ InkDropHover::InkDropHover(const gfx::Size& size,
layer_->SetOpacity(kHoverVisibleOpacity);
layer_->SetMasksToBounds(false);
layer_->set_name("InkDropHover:layer");
-
- gfx::Transform transform;
- transform.Translate(center_point.x() - layer_->bounds().CenterPoint().x(),
- center_point.y() - layer_->bounds().CenterPoint().y());
- layer_->SetTransform(transform);
}
InkDropHover::~InkDropHover() {}
@@ -54,17 +52,21 @@ bool InkDropHover::IsFadingInOrVisible() const {
void InkDropHover::FadeIn(const base::TimeDelta& duration) {
layer_->SetOpacity(kHiddenOpacity);
layer_->SetVisible(true);
- AnimateFade(FADE_IN, duration);
+ AnimateFade(FADE_IN, duration, size_, size_);
}
-void InkDropHover::FadeOut(const base::TimeDelta& duration) {
- AnimateFade(FADE_OUT, duration);
+void InkDropHover::FadeOut(const base::TimeDelta& duration, bool explode) {
+ AnimateFade(FADE_OUT, duration, size_, explode ? explode_size_ : size_);
}
void InkDropHover::AnimateFade(HoverAnimationType animation_type,
- const base::TimeDelta& duration) {
+ const base::TimeDelta& duration,
+ const gfx::Size& initial_size,
+ const gfx::Size& target_size) {
last_animation_initiated_was_fade_in_ = animation_type == FADE_IN;
+ layer_->SetTransform(CalculateTransform(initial_size));
+
// The |animation_observer| will be destroyed when the
// AnimationStartedCallback() returns true.
ui::CallbackLayerAnimationObserver* animation_observer =
@@ -77,19 +79,38 @@ void InkDropHover::AnimateFade(HoverAnimationType animation_type,
animation.SetTweenType(gfx::Tween::EASE_IN_OUT);
animation.SetPreemptionStrategy(
ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
- ui::LayerAnimationElement* animation_element =
+
+ ui::LayerAnimationElement* opacity_element =
ui::LayerAnimationElement::CreateOpacityElement(
animation_type == FADE_IN ? kHoverVisibleOpacity : kHiddenOpacity,
duration);
- ui::LayerAnimationSequence* animation_sequence =
- new ui::LayerAnimationSequence(animation_element);
- animation_sequence->AddObserver(animation_observer);
-
- animator->StartAnimation(animation_sequence);
+ ui::LayerAnimationSequence* opacity_sequence =
+ new ui::LayerAnimationSequence(opacity_element);
+ opacity_sequence->AddObserver(animation_observer);
+ animator->StartAnimation(opacity_sequence);
+
+ if (initial_size != target_size) {
+ ui::LayerAnimationElement* transform_element =
+ ui::LayerAnimationElement::CreateTransformElement(
+ CalculateTransform(target_size), duration);
+ ui::LayerAnimationSequence* transform_sequence =
+ new ui::LayerAnimationSequence(transform_element);
+ transform_sequence->AddObserver(animation_observer);
+ animator->StartAnimation(transform_sequence);
+ }
animation_observer->SetActive();
}
+gfx::Transform InkDropHover::CalculateTransform(const gfx::Size& size) const {
+ gfx::Transform transform;
+ transform.Translate(center_point_.x(), center_point_.y());
+ transform.Scale(size.width() / size_.width(), size.height() / size_.height());
+ transform.Translate(-layer_delegate_->GetCenterPoint().x(),
+ -layer_delegate_->GetCenterPoint().y());
+ return transform;
+}
+
bool InkDropHover::AnimationEndedCallback(
HoverAnimationType animation_type,
const ui::CallbackLayerAnimationObserver& observer) {
« no previous file with comments | « ui/views/animation/ink_drop_hover.h ('k') | ui/views/animation/ink_drop_hover_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698