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

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

Issue 1495753002: Make the material design ripple effect more visible on a quick action (single click or single tap) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Renamed kDurationTableInMs to kAnimationDurationInMs. Created 4 years, 11 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
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 2035866ba912ff96f59e8264d2cb48e326bb9bfe..486a174cfba6d218667c62930e05422168df04bb 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"
@@ -28,12 +29,25 @@ const int kHoverFadeInAfterAnimationDurationInMs = 250;
// The duration, in milliseconds, of the hover state fade out animation when it
// is triggered by an ink drop ripple animation starting.
-const int kHoverFadeOutBeforeAnimationDurationInMs = 0;
+const int kHoverFadeOutBeforeAnimationDurationInMs = 300;
// The amount of time in milliseconds that |hover_| should delay after a ripple
// animation before fading in.
const int kHoverFadeInAfterAnimationDelayInMs = 1000;
+// Returns true if an ink drop with the given |ink_drop_state| should
+// automatically transition to the InkDropState::HIDDEN state.
+bool ShouldAnimateToHidden(InkDropState ink_drop_state) {
+ switch (ink_drop_state) {
+ case views::InkDropState::QUICK_ACTION:
+ case views::InkDropState::SLOW_ACTION:
+ case views::InkDropState::DEACTIVATED:
+ return true;
+ default:
+ return false;
+ }
+}
+
} // namespace
InkDropAnimationControllerImpl::InkDropAnimationControllerImpl(
@@ -42,6 +56,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_(nullptr) {
root_layer_->set_name("InkDropAnimationControllerImpl:RootLayer");
ink_drop_host_->AddInkDropLayer(root_layer_.get());
@@ -64,6 +79,25 @@ 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);
+
+ if (ink_drop_state != views::InkDropState::HIDDEN) {
+ SetHoveredInternal(false, base::TimeDelta::FromMilliseconds(
+ kHoverFadeOutBeforeAnimationDurationInMs));
+ }
+
+ // Make sure the ink drop starts from the HIDDEN state it was going to auto
+ // transition to it.
+ if (ink_drop_animation_->ink_drop_state() == InkDropState::HIDDEN ||
+ ShouldAnimateToHidden(ink_drop_animation_->ink_drop_state())) {
+ ink_drop_animation_->HideImmediately();
+ }
ink_drop_animation_->AnimateToState(ink_drop_state);
}
@@ -159,23 +193,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:
- // TODO(bruthig): Consider only starting the timer if the InkDropHost is
- // hovered now, as oppposed to when the timer fires.
- StartHoverAfterAnimationTimer();
+ if (ShouldAnimateToHidden(ink_drop_state)) {
+ 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;
+ }
}
}
« no previous file with comments | « ui/views/animation/ink_drop_animation_controller_impl.h ('k') | ui/views/animation/ink_drop_animation_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698