Chromium Code Reviews| 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 0b014bd8b5caf3cd853f0a190cde8323dc713873..913a836946cc55c2727d389f901c94c46af629b7 100644 |
| --- a/ui/views/animation/ink_drop_animation_controller_impl.cc |
| +++ b/ui/views/animation/ink_drop_animation_controller_impl.cc |
| @@ -14,11 +14,9 @@ InkDropAnimationControllerImpl::InkDropAnimationControllerImpl( |
| : ink_drop_host_(ink_drop_host) {} |
| InkDropAnimationControllerImpl::~InkDropAnimationControllerImpl() { |
| - if (ink_drop_animation_) { |
| - // TODO(bruthig): Change this to be called when the ink drop becomes hidden. |
| - // See www.crbug.com/522175. |
| - ink_drop_host_->RemoveInkDropLayer(ink_drop_animation_->root_layer()); |
| - } |
| + // Explicitly destroy the InkDropAnimation so that this still exists if |
| + // views::InkDropAnimationObserver methods are called on this. |
| + DestroyInkDropAnimation(); |
| } |
| InkDropState InkDropAnimationControllerImpl::GetInkDropState() const { |
| @@ -27,10 +25,11 @@ InkDropState InkDropAnimationControllerImpl::GetInkDropState() const { |
| return ink_drop_animation_->ink_drop_state(); |
| } |
| -void InkDropAnimationControllerImpl::AnimateToState(InkDropState state) { |
| +void InkDropAnimationControllerImpl::AnimateToState( |
| + InkDropState ink_drop_state) { |
| if (!ink_drop_animation_) |
| CreateInkDropAnimation(); |
| - ink_drop_animation_->AnimateToState(state); |
| + ink_drop_animation_->AnimateToState(ink_drop_state); |
| } |
| gfx::Size InkDropAnimationControllerImpl::GetInkDropLargeSize() const { |
| @@ -61,19 +60,48 @@ void InkDropAnimationControllerImpl::SetInkDropCenter( |
| } |
| void InkDropAnimationControllerImpl::CreateInkDropAnimation() { |
| - if (ink_drop_animation_) |
| - ink_drop_host_->RemoveInkDropLayer(ink_drop_animation_->root_layer()); |
| + DestroyInkDropAnimation(); |
| - // TODO(bruthig): It will be expensive to maintain InkDropAnimation instances |
| - // when they are not actually being used. Consider creating InkDropAnimations |
| - // on an as-needed basis and if construction is also expensive then consider |
| - // creating an InkDropAnimationPool. See www.crbug.com/522175. |
| ink_drop_animation_.reset(new InkDropAnimation( |
| ink_drop_large_size_, ink_drop_large_corner_radius_, ink_drop_small_size_, |
| ink_drop_small_corner_radius_)); |
| + ink_drop_animation_->AddObserver(this); |
| ink_drop_animation_->SetCenterPoint(ink_drop_center_); |
| ink_drop_host_->AddInkDropLayer(ink_drop_animation_->root_layer()); |
| } |
| +void InkDropAnimationControllerImpl::DestroyInkDropAnimation() { |
| + if (!ink_drop_animation_) |
| + return; |
| + ink_drop_host_->RemoveInkDropLayer(ink_drop_animation_->root_layer()); |
| + ink_drop_animation_->RemoveObserver(this); |
| + ink_drop_animation_.reset(); |
| +} |
| + |
| +void InkDropAnimationControllerImpl::InkDropAnimationStarted( |
| + InkDropState ink_drop_state) {} |
| + |
| +void InkDropAnimationControllerImpl::InkDropAnimationEnded( |
| + InkDropState ink_drop_state, |
| + InkDropAnimationEndedReason reason) { |
| + if (reason == SUCCESS) { |
|
sadrul
2015/10/08 01:06:01
early return instead
bruthig
2015/10/08 21:42:55
Done.
|
| + 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: |
| + // TODO(bruthig): Investigate whether creating and destroying |
| + // InkDropAnimations is expensive and consider creating an |
| + // InkDropAnimationPool. See www.crbug.com/522175. |
| + DestroyInkDropAnimation(); |
| + break; |
| + default: |
| + break; |
| + } |
| + } |
| +} |
| + |
| } // namespace views |