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 74d681d8d637422bd900240fac416aa68d3a33d2..6fe08545ddf3060ed7954ca503681ec381f5ae28 100644 |
| --- a/ui/views/animation/ink_drop_animation_controller_impl.cc |
| +++ b/ui/views/animation/ink_drop_animation_controller_impl.cc |
| @@ -4,14 +4,31 @@ |
| #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), |
| + ink_drop_large_corner_radius_(0), |
| + ink_drop_small_corner_radius_(0), |
| + root_layer_(new ui::Layer(ui::LAYER_NOT_DRAWN)) { |
| + ink_drop_host_->AddInkDropLayer(root_layer_.get()); |
|
sadrul
2015/11/04 19:58:10
The layer is never removed from host?
bruthig
2015/11/11 21:48:44
Whoops, done.
|
| +} |
| InkDropAnimationControllerImpl::~InkDropAnimationControllerImpl() { |
| // Explicitly destroy the InkDropAnimation so that this still exists if |
| @@ -32,6 +49,31 @@ void InkDropAnimationControllerImpl::AnimateToState( |
| ink_drop_animation_->AnimateToState(ink_drop_state); |
| } |
| +void InkDropAnimationControllerImpl::SetHovered(bool is_hovered) { |
| + if (IsHovered() == is_hovered) |
| + return; |
| + |
| + 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 { |
| + if (!hover_) |
| + return false; |
| + return hover_->IsVisible(); |
|
sadrul
2015/11/04 19:58:10
return hover_ && hover_->IsVisible()
bruthig
2015/11/11 21:48:44
Done.
|
| +} |
| + |
| gfx::Size InkDropAnimationControllerImpl::GetInkDropLargeSize() const { |
| return ink_drop_large_size_; |
| } |
| @@ -49,7 +91,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 +101,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 +114,47 @@ 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: |
| + 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: |
| + SetHovered(false); |
| + break; |
| + } |
|
sadrul
2015/11/04 19:58:10
What's the reason for the switch statement here?
bruthig
2015/11/11 21:48:44
Removed.
|
| +} |
| void InkDropAnimationControllerImpl::InkDropAnimationEnded( |
| InkDropState ink_drop_state, |