| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/views/animation/ink_drop_animation_controller_impl.h" | 5 #include "ui/views/animation/ink_drop_animation_controller_impl.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/timer/timer.h" | 8 #include "base/timer/timer.h" |
| 9 #include "ui/compositor/layer.h" | 9 #include "ui/compositor/layer.h" |
| 10 #include "ui/views/animation/ink_drop_host.h" | 10 #include "ui/views/animation/ink_drop_host.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 // The duration, in milliseconds, of the hover state fade out animation when it | 22 // The duration, in milliseconds, of the hover state fade out animation when it |
| 23 // is triggered by user input. | 23 // is triggered by user input. |
| 24 const int kHoverFadeOutFromUserInputDurationInMs = 250; | 24 const int kHoverFadeOutFromUserInputDurationInMs = 250; |
| 25 | 25 |
| 26 // The duration, in milliseconds, of the hover state fade in animation when it | 26 // The duration, in milliseconds, of the hover state fade in animation when it |
| 27 // is triggered by an ink drop ripple animation ending. | 27 // is triggered by an ink drop ripple animation ending. |
| 28 const int kHoverFadeInAfterAnimationDurationInMs = 250; | 28 const int kHoverFadeInAfterAnimationDurationInMs = 250; |
| 29 | 29 |
| 30 // The duration, in milliseconds, of the hover state fade out animation when it | 30 // The duration, in milliseconds, of the hover state fade out animation when it |
| 31 // is triggered by an ink drop ripple animation starting. | 31 // is triggered by an ink drop ripple animation starting. |
| 32 const int kHoverFadeOutBeforeAnimationDurationInMs = 300; | 32 const int kHoverFadeOutBeforeAnimationDurationInMs = 120; |
| 33 | 33 |
| 34 // The amount of time in milliseconds that |hover_| should delay after a ripple | 34 // The amount of time in milliseconds that |hover_| should delay after a ripple |
| 35 // animation before fading in. | 35 // animation before fading in. |
| 36 const int kHoverFadeInAfterAnimationDelayInMs = 1000; | 36 const int kHoverFadeInAfterAnimationDelayInMs = 1000; |
| 37 | 37 |
| 38 // Returns true if an ink drop with the given |ink_drop_state| should | 38 // Returns true if an ink drop with the given |ink_drop_state| should |
| 39 // automatically transition to the InkDropState::HIDDEN state. | 39 // automatically transition to the InkDropState::HIDDEN state. |
| 40 bool ShouldAnimateToHidden(InkDropState ink_drop_state) { | 40 bool ShouldAnimateToHidden(InkDropState ink_drop_state) { |
| 41 switch (ink_drop_state) { | 41 switch (ink_drop_state) { |
| 42 case views::InkDropState::ACTION_TRIGGERED: | 42 case views::InkDropState::ACTION_TRIGGERED: |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 } | 78 } |
| 79 | 79 |
| 80 void InkDropAnimationControllerImpl::AnimateToState( | 80 void InkDropAnimationControllerImpl::AnimateToState( |
| 81 InkDropState ink_drop_state) { | 81 InkDropState ink_drop_state) { |
| 82 DestroyHiddenTargetedAnimations(); | 82 DestroyHiddenTargetedAnimations(); |
| 83 if (!ink_drop_animation_) | 83 if (!ink_drop_animation_) |
| 84 CreateInkDropAnimation(); | 84 CreateInkDropAnimation(); |
| 85 | 85 |
| 86 if (ink_drop_state != views::InkDropState::HIDDEN) { | 86 if (ink_drop_state != views::InkDropState::HIDDEN) { |
| 87 SetHoveredInternal(false, base::TimeDelta::FromMilliseconds( | 87 SetHoveredInternal(false, base::TimeDelta::FromMilliseconds( |
| 88 kHoverFadeOutBeforeAnimationDurationInMs)); | 88 kHoverFadeOutBeforeAnimationDurationInMs), |
| 89 true); |
| 89 } | 90 } |
| 90 | 91 |
| 91 ink_drop_animation_->AnimateToState(ink_drop_state); | 92 ink_drop_animation_->AnimateToState(ink_drop_state); |
| 92 } | 93 } |
| 93 | 94 |
| 94 void InkDropAnimationControllerImpl::SnapToActivated() { | 95 void InkDropAnimationControllerImpl::SnapToActivated() { |
| 95 DestroyHiddenTargetedAnimations(); | 96 DestroyHiddenTargetedAnimations(); |
| 96 if (!ink_drop_animation_) | 97 if (!ink_drop_animation_) |
| 97 CreateInkDropAnimation(); | 98 CreateInkDropAnimation(); |
| 98 | 99 |
| 99 SetHoveredInternal(false, base::TimeDelta()); | 100 SetHoveredInternal(false, base::TimeDelta(), false); |
| 100 | 101 |
| 101 ink_drop_animation_->SnapToActivated(); | 102 ink_drop_animation_->SnapToActivated(); |
| 102 } | 103 } |
| 103 | 104 |
| 104 void InkDropAnimationControllerImpl::SetHovered(bool is_hovered) { | 105 void InkDropAnimationControllerImpl::SetHovered(bool is_hovered) { |
| 105 is_hovered_ = is_hovered; | 106 is_hovered_ = is_hovered; |
| 106 SetHoveredInternal(is_hovered, | 107 SetHoveredInternal(is_hovered, |
| 107 is_hovered ? base::TimeDelta::FromMilliseconds( | 108 is_hovered ? base::TimeDelta::FromMilliseconds( |
| 108 kHoverFadeInFromUserInputDurationInMs) | 109 kHoverFadeInFromUserInputDurationInMs) |
| 109 : base::TimeDelta::FromMilliseconds( | 110 : base::TimeDelta::FromMilliseconds( |
| 110 kHoverFadeOutFromUserInputDurationInMs)); | 111 kHoverFadeOutFromUserInputDurationInMs), |
| 112 false); |
| 111 } | 113 } |
| 112 | 114 |
| 113 void InkDropAnimationControllerImpl::DestroyHiddenTargetedAnimations() { | 115 void InkDropAnimationControllerImpl::DestroyHiddenTargetedAnimations() { |
| 114 if (ink_drop_animation_ && | 116 if (ink_drop_animation_ && |
| 115 (ink_drop_animation_->target_ink_drop_state() == InkDropState::HIDDEN || | 117 (ink_drop_animation_->target_ink_drop_state() == InkDropState::HIDDEN || |
| 116 ShouldAnimateToHidden(ink_drop_animation_->target_ink_drop_state()))) { | 118 ShouldAnimateToHidden(ink_drop_animation_->target_ink_drop_state()))) { |
| 117 DestroyInkDropAnimation(); | 119 DestroyInkDropAnimation(); |
| 118 } | 120 } |
| 119 } | 121 } |
| 120 | 122 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 StartHoverAfterAnimationTimer(); | 170 StartHoverAfterAnimationTimer(); |
| 169 // TODO(bruthig): Investigate whether creating and destroying | 171 // TODO(bruthig): Investigate whether creating and destroying |
| 170 // InkDropAnimations is expensive and consider creating an | 172 // InkDropAnimations is expensive and consider creating an |
| 171 // InkDropAnimationPool. See www.crbug.com/522175. | 173 // InkDropAnimationPool. See www.crbug.com/522175. |
| 172 DestroyInkDropAnimation(); | 174 DestroyInkDropAnimation(); |
| 173 } | 175 } |
| 174 } | 176 } |
| 175 | 177 |
| 176 void InkDropAnimationControllerImpl::SetHoveredInternal( | 178 void InkDropAnimationControllerImpl::SetHoveredInternal( |
| 177 bool is_hovered, | 179 bool is_hovered, |
| 178 base::TimeDelta animation_duration) { | 180 base::TimeDelta animation_duration, |
| 181 bool explode) { |
| 179 StopHoverAfterAnimationTimer(); | 182 StopHoverAfterAnimationTimer(); |
| 180 | 183 |
| 181 if (IsHoverFadingInOrVisible() == is_hovered) | 184 if (IsHoverFadingInOrVisible() == is_hovered) |
| 182 return; | 185 return; |
| 183 | 186 |
| 184 if (is_hovered) { | 187 if (is_hovered) { |
| 185 CreateInkDropHover(); | 188 CreateInkDropHover(); |
| 186 if (hover_ && !IsVisible()) | 189 if (hover_ && !IsVisible()) |
| 187 hover_->FadeIn(animation_duration); | 190 hover_->FadeIn(animation_duration); |
| 188 } else { | 191 } else { |
| 189 hover_->FadeOut(animation_duration); | 192 hover_->FadeOut(animation_duration, explode); |
| 190 } | 193 } |
| 191 } | 194 } |
| 192 | 195 |
| 193 void InkDropAnimationControllerImpl::StartHoverAfterAnimationTimer() { | 196 void InkDropAnimationControllerImpl::StartHoverAfterAnimationTimer() { |
| 194 StopHoverAfterAnimationTimer(); | 197 StopHoverAfterAnimationTimer(); |
| 195 | 198 |
| 196 if (!hover_after_animation_timer_) | 199 if (!hover_after_animation_timer_) |
| 197 hover_after_animation_timer_.reset(new base::OneShotTimer); | 200 hover_after_animation_timer_.reset(new base::OneShotTimer); |
| 198 | 201 |
| 199 hover_after_animation_timer_->Start( | 202 hover_after_animation_timer_->Start( |
| 200 FROM_HERE, | 203 FROM_HERE, |
| 201 base::TimeDelta::FromMilliseconds(kHoverFadeInAfterAnimationDelayInMs), | 204 base::TimeDelta::FromMilliseconds(kHoverFadeInAfterAnimationDelayInMs), |
| 202 base::Bind(&InkDropAnimationControllerImpl::HoverAfterAnimationTimerFired, | 205 base::Bind(&InkDropAnimationControllerImpl::HoverAfterAnimationTimerFired, |
| 203 base::Unretained(this))); | 206 base::Unretained(this))); |
| 204 } | 207 } |
| 205 | 208 |
| 206 void InkDropAnimationControllerImpl::StopHoverAfterAnimationTimer() { | 209 void InkDropAnimationControllerImpl::StopHoverAfterAnimationTimer() { |
| 207 if (hover_after_animation_timer_) | 210 if (hover_after_animation_timer_) |
| 208 hover_after_animation_timer_.reset(); | 211 hover_after_animation_timer_.reset(); |
| 209 } | 212 } |
| 210 | 213 |
| 211 void InkDropAnimationControllerImpl::HoverAfterAnimationTimerFired() { | 214 void InkDropAnimationControllerImpl::HoverAfterAnimationTimerFired() { |
| 212 SetHoveredInternal(true, base::TimeDelta::FromMilliseconds( | 215 SetHoveredInternal(true, base::TimeDelta::FromMilliseconds( |
| 213 kHoverFadeInAfterAnimationDurationInMs)); | 216 kHoverFadeInAfterAnimationDurationInMs), |
| 217 true); |
| 214 hover_after_animation_timer_.reset(); | 218 hover_after_animation_timer_.reset(); |
| 215 } | 219 } |
| 216 | 220 |
| 217 } // namespace views | 221 } // namespace views |
| OLD | NEW |