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 74d681d8d637422bd900240fac416aa68d3a33d2..1c598453f4a806a9e0c4c760314cc098f637440e 100644 |
--- a/ui/views/animation/ink_drop_animation_controller_impl.cc |
+++ b/ui/views/animation/ink_drop_animation_controller_impl.cc |
@@ -4,14 +4,30 @@ |
#include "ui/views/animation/ink_drop_animation_controller_impl.h" |
+#include "ui/compositor/layer.h" |
#include "ui/views/animation/ink_drop_animation.h" |
#include "ui/views/animation/ink_drop_host.h" |
+#include "ui/views/animation/ink_drop_hover.h" |
namespace views { |
+namespace { |
+ |
+// The duration of the hover state fade in animation. |
+const int kFadeInDurationInMs = 250; |
+ |
+// The duration of the hover state fade out animation. |
+const int kFadeOutDurationInMs = 250; |
+ |
+} // namespace |
+ |
InkDropAnimationControllerImpl::InkDropAnimationControllerImpl( |
InkDropHost* ink_drop_host) |
- : ink_drop_host_(ink_drop_host) {} |
+ : ink_drop_host_(ink_drop_host), |
+ root_layer_(new ui::Layer(ui::LAYER_NOT_DRAWN)), |
+ is_hovered_(false) { |
+ ink_drop_host_->AddInkDropLayer(root_layer_.get()); |
+} |
InkDropAnimationControllerImpl::~InkDropAnimationControllerImpl() { |
// Explicitly destroy the InkDropAnimation so that this still exists if |
@@ -32,6 +48,30 @@ void InkDropAnimationControllerImpl::AnimateToState( |
ink_drop_animation_->AnimateToState(ink_drop_state); |
} |
+void InkDropAnimationControllerImpl::SetHovered(bool is_hovered) { |
+ if (is_hovered_ == is_hovered) |
+ return; |
+ |
+ is_hovered_ = is_hovered; |
+ if (is_hovered_) { |
+ if (!hover_) |
+ CreateInkDropHover(); |
+ if (GetInkDropState() == views::InkDropState::HIDDEN) { |
+ base::TimeDelta duration = |
+ base::TimeDelta::FromMilliseconds(kFadeInDurationInMs); |
+ hover_->FadeIn(duration); |
+ } |
+ } else { |
+ base::TimeDelta duration = |
+ base::TimeDelta::FromMilliseconds(kFadeOutDurationInMs); |
+ hover_->FadeOut(duration); |
+ } |
+} |
+ |
+bool InkDropAnimationControllerImpl::IsHovered() const { |
+ return is_hovered_; |
+} |
+ |
gfx::Size InkDropAnimationControllerImpl::GetInkDropLargeSize() const { |
return ink_drop_large_size_; |
} |
@@ -49,7 +89,9 @@ void InkDropAnimationControllerImpl::SetInkDropSize(const gfx::Size& large_size, |
ink_drop_large_corner_radius_ = large_corner_radius; |
ink_drop_small_size_ = small_size; |
ink_drop_small_corner_radius_ = small_corner_radius; |
- ink_drop_animation_.reset(); |
+ |
+ DestroyInkDropAnimation(); |
+ DestroyInkDropHover(); |
} |
void InkDropAnimationControllerImpl::SetInkDropCenter( |
@@ -57,6 +99,8 @@ void InkDropAnimationControllerImpl::SetInkDropCenter( |
ink_drop_center_ = center_point; |
if (ink_drop_animation_) |
ink_drop_animation_->SetCenterPoint(ink_drop_center_); |
+ if (hover_) |
+ hover_->SetCenterPoint(ink_drop_center_); |
} |
void InkDropAnimationControllerImpl::CreateInkDropAnimation() { |
@@ -68,19 +112,51 @@ void InkDropAnimationControllerImpl::CreateInkDropAnimation() { |
ink_drop_animation_->AddObserver(this); |
ink_drop_animation_->SetCenterPoint(ink_drop_center_); |
- ink_drop_host_->AddInkDropLayer(ink_drop_animation_->root_layer()); |
+ root_layer_->Add(ink_drop_animation_->root_layer()); |
} |
void InkDropAnimationControllerImpl::DestroyInkDropAnimation() { |
if (!ink_drop_animation_) |
return; |
- ink_drop_host_->RemoveInkDropLayer(ink_drop_animation_->root_layer()); |
+ root_layer_->Remove(ink_drop_animation_->root_layer()); |
ink_drop_animation_->RemoveObserver(this); |
ink_drop_animation_.reset(); |
} |
+void InkDropAnimationControllerImpl::CreateInkDropHover() { |
+ DestroyInkDropHover(); |
+ |
+ hover_.reset( |
+ new InkDropHover(ink_drop_small_size_, ink_drop_small_corner_radius_)); |
+ hover_->SetCenterPoint(ink_drop_center_); |
+ root_layer_->Add(hover_->root_layer()); |
+} |
+ |
+void InkDropAnimationControllerImpl::DestroyInkDropHover() { |
+ if (!hover_) |
+ return; |
+ root_layer_->Remove(hover_->root_layer()); |
+ hover_.reset(); |
+} |
+ |
void InkDropAnimationControllerImpl::InkDropAnimationStarted( |
- InkDropState ink_drop_state) {} |
+ InkDropState ink_drop_state) { |
+ switch (ink_drop_state) { |
+ case views::InkDropState::HIDDEN: |
+ break; |
+ case views::InkDropState::ACTION_PENDING: |
+ case views::InkDropState::QUICK_ACTION: |
+ case views::InkDropState::SLOW_ACTION_PENDING: |
+ case views::InkDropState::SLOW_ACTION: |
+ case views::InkDropState::ACTIVATED: |
+ case views::InkDropState::DEACTIVATED: |
+ if (is_hovered_ && hover_) { |
+ hover_->FadeOut( |
+ base::TimeDelta::FromMilliseconds(kFadeOutDurationInMs)); |
+ } |
+ break; |
+ } |
+} |
void InkDropAnimationControllerImpl::InkDropAnimationEnded( |
InkDropState ink_drop_state, |
@@ -98,6 +174,10 @@ void InkDropAnimationControllerImpl::InkDropAnimationEnded( |
// InkDropAnimations is expensive and consider creating an |
// InkDropAnimationPool. See www.crbug.com/522175. |
DestroyInkDropAnimation(); |
+ |
+ if (is_hovered_ && hover_) { |
+ hover_->FadeIn(base::TimeDelta::FromMilliseconds(kFadeInDurationInMs)); |
+ } |
break; |
default: |
break; |