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 6fe08545ddf3060ed7954ca503681ec381f5ae28..880e8ff46ea537f29043ba4339281df4fbdaac9b 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 "ui/compositor/layer.h" |
#include "ui/views/animation/ink_drop_animation.h" |
#include "ui/views/animation/ink_drop_host.h" |
@@ -26,7 +27,8 @@ InkDropAnimationControllerImpl::InkDropAnimationControllerImpl( |
: ink_drop_host_(ink_drop_host), |
ink_drop_large_corner_radius_(0), |
ink_drop_small_corner_radius_(0), |
- root_layer_(new ui::Layer(ui::LAYER_NOT_DRAWN)) { |
+ root_layer_(new ui::Layer(ui::LAYER_NOT_DRAWN)), |
+ can_destroy_after_hidden_animation_(true) { |
ink_drop_host_->AddInkDropLayer(root_layer_.get()); |
} |
@@ -46,9 +48,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 { |
varkha
2015/11/06 00:00:27
nit: Maybe ShouldAutoAnimateToHidden? It is not re
bruthig
2015/11/11 18:11:20
From the perspective of the InkDropAnimationContro
|
+ 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) { |
if (IsHovered() == is_hovered) |
return; |
@@ -161,20 +188,14 @@ 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: |
+ if (WillAutoAnimateToHidden()) |
+ ink_drop_animation_->AnimateToState(views::InkDropState::HIDDEN); |
+ else if (ink_drop_state == views::InkDropState::HIDDEN && |
+ 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; |
} |
} |