Chromium Code Reviews| 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..fcd5421f0edd7ee4d9dd6e6dc7201707746449c3 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,23 @@ bool InkDropHover::IsFadingInOrVisible() const { |
| void InkDropHover::FadeIn(const base::TimeDelta& duration) { |
| layer_->SetOpacity(kHiddenOpacity); |
| layer_->SetVisible(true); |
| - AnimateFade(FADE_IN, duration); |
| + const gfx::Transform transform = CalculateTransform(size_); |
| + AnimateFade(FADE_IN, duration, transform, transform); |
| } |
| -void InkDropHover::FadeOut(const base::TimeDelta& duration) { |
| - AnimateFade(FADE_OUT, duration); |
| +void InkDropHover::FadeOut(const base::TimeDelta& duration, bool explode) { |
| + AnimateFade(FADE_OUT, duration, CalculateTransform(size_), |
| + CalculateTransform(explode ? explode_size_ : size_)); |
| } |
| void InkDropHover::AnimateFade(HoverAnimationType animation_type, |
| - const base::TimeDelta& duration) { |
| + const base::TimeDelta& duration, |
| + const gfx::Transform& initial_transform, |
| + const gfx::Transform& target_transform) { |
| last_animation_initiated_was_fade_in_ = animation_type == FADE_IN; |
| + layer_->SetTransform(initial_transform); |
| + |
| // The |animation_observer| will be destroyed when the |
| // AnimationStartedCallback() returns true. |
| ui::CallbackLayerAnimationObserver* animation_observer = |
| @@ -77,19 +81,37 @@ 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); |
| + ui::LayerAnimationSequence* opacity_sequence = |
| + new ui::LayerAnimationSequence(opacity_element); |
| + opacity_sequence->AddObserver(animation_observer); |
| - animator->StartAnimation(animation_sequence); |
| + ui::LayerAnimationElement* transform_element = |
| + ui::LayerAnimationElement::CreateTransformElement(target_transform, |
| + duration); |
| + ui::LayerAnimationSequence* transform_sequence = |
| + new ui::LayerAnimationSequence(transform_element); |
| + transform_sequence->AddObserver(animation_observer); |
| + |
| + animator->StartAnimation(opacity_sequence); |
|
varkha
2016/04/21 16:16:49
nit: Maybe move this above to have a full block of
bruthig
2016/04/21 21:14:04
Done.
|
| + animator->StartAnimation(transform_sequence); |
| animation_observer->SetActive(); |
| } |
| +gfx::Transform InkDropHover::CalculateTransform(const gfx::SizeF& size) const { |
| + gfx::Transform transform; |
| + transform.Translate(center_point_.x(), center_point_.y()); |
| + transform.Scale(size.width() / size_.width(), size.height() / size_.height()); |
|
varkha
2016/04/21 16:16:49
This is one place I think could benefit from havin
bruthig
2016/04/21 21:14:04
Discussed offline. We will defer this as per othe
|
| + transform.Translate(-layer_delegate_->GetCenterPoint().x(), |
| + -layer_delegate_->GetCenterPoint().y()); |
| + return transform; |
| +} |
| + |
| bool InkDropHover::AnimationEndedCallback( |
| HoverAnimationType animation_type, |
| const ui::CallbackLayerAnimationObserver& observer) { |