| Index: ui/views/animation/ink_drop_animation_controller_impl.cc
|
| diff --git a/ui/views/animation/ink_drop_animation_controller_impl.cc b/ui/views/animation/ink_drop_animation_controller_impl.cc
|
| index af1451c71ceb338d8219e94a4adba260921ed01f..fcb2197809b2f8d4302f578be815278a30953e67 100644
|
| --- a/ui/views/animation/ink_drop_animation_controller_impl.cc
|
| +++ b/ui/views/animation/ink_drop_animation_controller_impl.cc
|
| @@ -4,6 +4,7 @@
|
|
|
| #include "ui/views/animation/ink_drop_animation_controller_impl.h"
|
|
|
| +#include "base/auto_reset.h"
|
| #include "base/timer/timer.h"
|
| #include "ui/compositor/layer.h"
|
| #include "ui/views/animation/ink_drop_animation.h"
|
| @@ -45,6 +46,7 @@ InkDropAnimationControllerImpl::InkDropAnimationControllerImpl(
|
| ink_drop_large_corner_radius_(0),
|
| ink_drop_small_corner_radius_(0),
|
| root_layer_(new ui::Layer(ui::LAYER_NOT_DRAWN)),
|
| + can_destroy_after_hidden_animation_(true),
|
| hover_after_animation_timer_(new base::OneShotTimer()) {
|
| ink_drop_host_->AddInkDropLayer(root_layer_.get());
|
| }
|
| @@ -66,9 +68,34 @@ void InkDropAnimationControllerImpl::AnimateToState(
|
| InkDropState ink_drop_state) {
|
| if (!ink_drop_animation_)
|
| CreateInkDropAnimation();
|
| +
|
| + // The InkDropAnimationObserver::InkDropAnimationEnded() callback needs to
|
| + // know if it is safe to destroy the |ink_drop_animation_| and it is not safe
|
| + // when the notification is raised within a call to
|
| + // InkDropAnimation::AnimateToState().
|
| + base::AutoReset<bool> auto_reset_can_destroy_after_hidden_animation(
|
| + &can_destroy_after_hidden_animation_, false);
|
| +
|
| + // Make sure the ink drop completes its full state transitions if it was going
|
| + // to auto transition to the HIDDEN state.
|
| + if (WillAutoAnimateToHidden())
|
| + ink_drop_animation_->AnimateToState(views::InkDropState::HIDDEN);
|
| ink_drop_animation_->AnimateToState(ink_drop_state);
|
| }
|
|
|
| +bool InkDropAnimationControllerImpl::WillAutoAnimateToHidden() const {
|
| + if (!ink_drop_animation_)
|
| + return false;
|
| + switch (ink_drop_animation_->ink_drop_state()) {
|
| + case views::InkDropState::QUICK_ACTION:
|
| + case views::InkDropState::SLOW_ACTION:
|
| + case views::InkDropState::DEACTIVATED:
|
| + return true;
|
| + default:
|
| + return false;
|
| + }
|
| +}
|
| +
|
| void InkDropAnimationControllerImpl::SetHovered(bool is_hovered) {
|
| SetHoveredInternal(is_hovered,
|
| is_hovered ? base::TimeDelta::FromMilliseconds(
|
| @@ -165,21 +192,16 @@ void InkDropAnimationControllerImpl::InkDropAnimationEnded(
|
| InkDropAnimationEndedReason reason) {
|
| if (reason != SUCCESS)
|
| return;
|
| - switch (ink_drop_state) {
|
| - case views::InkDropState::QUICK_ACTION:
|
| - case views::InkDropState::SLOW_ACTION:
|
| - case views::InkDropState::DEACTIVATED:
|
| - ink_drop_animation_->AnimateToState(views::InkDropState::HIDDEN);
|
| - break;
|
| - case views::InkDropState::HIDDEN:
|
| - StartHoverAfterAnimationTimer();
|
| + if (WillAutoAnimateToHidden())
|
| + ink_drop_animation_->AnimateToState(views::InkDropState::HIDDEN);
|
| + else if (ink_drop_state == views::InkDropState::HIDDEN) {
|
| + StartHoverAfterAnimationTimer();
|
| + if (can_destroy_after_hidden_animation_) {
|
| // TODO(bruthig): Investigate whether creating and destroying
|
| // InkDropAnimations is expensive and consider creating an
|
| // InkDropAnimationPool. See www.crbug.com/522175.
|
| DestroyInkDropAnimation();
|
| - break;
|
| - default:
|
| - break;
|
| + }
|
| }
|
| }
|
|
|
|
|