Chromium Code Reviews| 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_impl.h" | 5 #include "ui/views/animation/ink_drop_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_highlight.h" | 10 #include "ui/views/animation/ink_drop_highlight.h" |
| 11 #include "ui/views/animation/ink_drop_host.h" | 11 #include "ui/views/animation/ink_drop_host.h" |
| 12 #include "ui/views/animation/square_ink_drop_ripple.h" | 12 #include "ui/views/animation/square_ink_drop_ripple.h" |
| 13 | 13 |
| 14 namespace views { | 14 namespace views { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 // The duration, in milliseconds, of the highlight state fade in animation when | 18 // The duration, in milliseconds, of the highlight state fade in animation when |
| 19 // it is triggered by user input. | 19 // it is triggered by user input. |
| 20 const int kHighlightFadeInFromUserInputDurationInMs = 250; | 20 const int kHighlightFadeInFromUserInputDurationMs = 250; |
| 21 | 21 |
| 22 // The duration, in milliseconds, of the highlight state fade out animation when | 22 // The duration, in milliseconds, of the highlight state fade out animation when |
| 23 // it is triggered by user input. | 23 // it is triggered by user input. |
| 24 const int kHighlightFadeOutFromUserInputDurationInMs = 250; | 24 const int kHighlightFadeOutFromUserInputDurationMs = 250; |
| 25 | 25 |
| 26 // The duration, in milliseconds, of the highlight state fade in animation when | 26 // The duration, in milliseconds, of the highlight state fade in animation when |
| 27 // it is triggered by an ink drop ripple animation ending. | 27 // it is triggered by an ink drop ripple animation ending. |
| 28 const int kHighlightFadeInAfterRippleDurationInMs = 250; | 28 const int kHighlightFadeInAfterRippleDurationMs = 250; |
| 29 | 29 |
| 30 // The duration, in milliseconds, of the highlight state fade out animation when | 30 // The duration, in milliseconds, of the highlight state fade out animation when |
| 31 // it is triggered by an ink drop ripple animation starting. | 31 // it is triggered by an ink drop ripple animation starting. |
| 32 const int kHighlightFadeOutBeforeRippleDurationInMs = 120; | 32 const int kHighlightFadeOutBeforeRippleDurationMs = 120; |
| 33 | 33 |
| 34 // The amount of time in milliseconds that |highlight_| should delay after a | 34 // The amount of time in milliseconds that |highlight_| should delay after a |
| 35 // ripple animation before fading in. | 35 // ripple animation before fading in, for highlight due to mouse hover. |
| 36 const int kHighlightFadeInAfterRippleDelayInMs = 1000; | 36 const int kHoverFadeInAfterRippleDelayMs = 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: |
| 43 case views::InkDropState::ALTERNATE_ACTION_TRIGGERED: | 43 case views::InkDropState::ALTERNATE_ACTION_TRIGGERED: |
| 44 case views::InkDropState::DEACTIVATED: | 44 case views::InkDropState::DEACTIVATED: |
| 45 return true; | 45 return true; |
| 46 default: | 46 default: |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 71 if (!ink_drop_ripple_) | 71 if (!ink_drop_ripple_) |
| 72 return InkDropState::HIDDEN; | 72 return InkDropState::HIDDEN; |
| 73 return ink_drop_ripple_->target_ink_drop_state(); | 73 return ink_drop_ripple_->target_ink_drop_state(); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void InkDropImpl::AnimateToState(InkDropState ink_drop_state) { | 76 void InkDropImpl::AnimateToState(InkDropState ink_drop_state) { |
| 77 DestroyHiddenTargetedAnimations(); | 77 DestroyHiddenTargetedAnimations(); |
| 78 if (!ink_drop_ripple_) | 78 if (!ink_drop_ripple_) |
| 79 CreateInkDropRipple(); | 79 CreateInkDropRipple(); |
| 80 | 80 |
| 81 // When deactivating and the host is focused, snap back to the highlight | |
| 82 // state. (In the case of highlighting due to hover, we'll animate the | |
| 83 // highlight back in after a delay.) | |
| 84 if (ink_drop_state == views::InkDropState::DEACTIVATED && is_focused_) { | |
|
bruthig
2016/07/09 16:25:47
Should the focus highlight snap back in after an A
Evan Stade
2016/07/12 17:32:42
good point, I guess you can see this if you focus
| |
| 85 ink_drop_ripple_->HideImmediately(); | |
| 86 SetHighlight(true, base::TimeDelta(), false); | |
| 87 return; | |
| 88 } | |
| 89 | |
| 81 if (ink_drop_state != views::InkDropState::HIDDEN) { | 90 if (ink_drop_state != views::InkDropState::HIDDEN) { |
| 82 SetHighlight(false, base::TimeDelta::FromMilliseconds( | 91 SetHighlight(false, base::TimeDelta::FromMilliseconds( |
| 83 kHighlightFadeOutBeforeRippleDurationInMs), | 92 kHighlightFadeOutBeforeRippleDurationMs), |
| 84 true); | 93 true); |
| 85 } | 94 } |
| 86 | 95 |
| 87 ink_drop_ripple_->AnimateToState(ink_drop_state); | 96 ink_drop_ripple_->AnimateToState(ink_drop_state); |
| 88 } | 97 } |
| 89 | 98 |
| 90 void InkDropImpl::SnapToActivated() { | 99 void InkDropImpl::SnapToActivated() { |
| 91 DestroyHiddenTargetedAnimations(); | 100 DestroyHiddenTargetedAnimations(); |
| 92 if (!ink_drop_ripple_) | 101 if (!ink_drop_ripple_) |
| 93 CreateInkDropRipple(); | 102 CreateInkDropRipple(); |
| 94 | 103 |
| 95 SetHighlight(false, base::TimeDelta(), false); | 104 SetHighlight(false, base::TimeDelta(), false); |
| 96 | 105 |
| 97 ink_drop_ripple_->SnapToActivated(); | 106 ink_drop_ripple_->SnapToActivated(); |
| 98 } | 107 } |
| 99 | 108 |
| 100 void InkDropImpl::SetHovered(bool is_hovered) { | 109 void InkDropImpl::SetHovered(bool is_hovered) { |
| 101 is_hovered_ = is_hovered; | 110 is_hovered_ = is_hovered; |
| 102 SetHighlight(ShouldHighlight(), | 111 SetHighlight(ShouldHighlight(), |
| 103 ShouldHighlight() | 112 ShouldHighlight() |
| 104 ? base::TimeDelta::FromMilliseconds( | 113 ? base::TimeDelta::FromMilliseconds( |
| 105 kHighlightFadeInFromUserInputDurationInMs) | 114 kHighlightFadeInFromUserInputDurationMs) |
| 106 : base::TimeDelta::FromMilliseconds( | 115 : base::TimeDelta::FromMilliseconds( |
| 107 kHighlightFadeOutFromUserInputDurationInMs), | 116 kHighlightFadeOutFromUserInputDurationMs), |
| 108 false); | 117 false); |
| 109 } | 118 } |
| 110 | 119 |
| 111 void InkDropImpl::SetFocused(bool is_focused) { | 120 void InkDropImpl::SetFocused(bool is_focused) { |
| 112 is_focused_ = is_focused; | 121 is_focused_ = is_focused; |
| 113 SetHighlight(ShouldHighlight(), base::TimeDelta(), false); | 122 SetHighlight(ShouldHighlight(), base::TimeDelta(), false); |
| 114 } | 123 } |
| 115 | 124 |
| 116 void InkDropImpl::DestroyHiddenTargetedAnimations() { | 125 void InkDropImpl::DestroyHiddenTargetedAnimations() { |
| 117 if (ink_drop_ripple_ && | 126 if (ink_drop_ripple_ && |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 InkDropAnimationEndedReason reason) { | 216 InkDropAnimationEndedReason reason) { |
| 208 if (animation_type == InkDropHighlight::FADE_OUT && | 217 if (animation_type == InkDropHighlight::FADE_OUT && |
| 209 reason == InkDropAnimationEndedReason::SUCCESS) { | 218 reason == InkDropAnimationEndedReason::SUCCESS) { |
| 210 DestroyInkDropHighlight(); | 219 DestroyInkDropHighlight(); |
| 211 } | 220 } |
| 212 } | 221 } |
| 213 | 222 |
| 214 void InkDropImpl::SetHighlight(bool should_highlight, | 223 void InkDropImpl::SetHighlight(bool should_highlight, |
| 215 base::TimeDelta animation_duration, | 224 base::TimeDelta animation_duration, |
| 216 bool explode) { | 225 bool explode) { |
| 217 StopHighlightAfterRippleTimer(); | 226 highlight_after_ripple_timer_.reset(); |
| 218 | 227 |
| 219 if (IsHighlightFadingInOrVisible() == should_highlight) | 228 if (IsHighlightFadingInOrVisible() == should_highlight) |
| 220 return; | 229 return; |
| 221 | 230 |
| 222 if (should_highlight) { | 231 if (should_highlight) { |
| 223 CreateInkDropHighlight(); | 232 CreateInkDropHighlight(); |
| 224 if (highlight_ && !(ink_drop_ripple_ && ink_drop_ripple_->IsVisible())) | 233 if (highlight_ && !(ink_drop_ripple_ && ink_drop_ripple_->IsVisible())) |
| 225 highlight_->FadeIn(animation_duration); | 234 highlight_->FadeIn(animation_duration); |
| 226 } else { | 235 } else { |
| 227 highlight_->FadeOut(animation_duration, explode); | 236 highlight_->FadeOut(animation_duration, explode); |
| 228 } | 237 } |
| 229 } | 238 } |
| 230 | 239 |
| 231 bool InkDropImpl::ShouldHighlight() const { | 240 bool InkDropImpl::ShouldHighlight() const { |
| 232 return is_focused_ || is_hovered_; | 241 return is_focused_ || is_hovered_; |
| 233 } | 242 } |
| 234 | 243 |
| 235 void InkDropImpl::StartHighlightAfterRippleTimer() { | 244 void InkDropImpl::StartHighlightAfterRippleTimer() { |
| 236 StopHighlightAfterRippleTimer(); | 245 highlight_after_ripple_timer_.reset(new base::OneShotTimer); |
| 237 | |
| 238 if (!highlight_after_ripple_timer_) | |
| 239 highlight_after_ripple_timer_.reset(new base::OneShotTimer); | |
| 240 | |
| 241 highlight_after_ripple_timer_->Start( | 246 highlight_after_ripple_timer_->Start( |
| 242 FROM_HERE, | 247 FROM_HERE, |
| 243 base::TimeDelta::FromMilliseconds(kHighlightFadeInAfterRippleDelayInMs), | 248 base::TimeDelta::FromMilliseconds(kHoverFadeInAfterRippleDelayMs), |
| 244 base::Bind(&InkDropImpl::HighlightAfterRippleTimerFired, | 249 base::Bind(&InkDropImpl::HighlightAfterRippleTimerFired, |
| 245 base::Unretained(this))); | 250 base::Unretained(this))); |
| 246 } | 251 } |
| 247 | 252 |
| 248 void InkDropImpl::StopHighlightAfterRippleTimer() { | |
| 249 if (highlight_after_ripple_timer_) | |
| 250 highlight_after_ripple_timer_.reset(); | |
| 251 } | |
| 252 | |
| 253 void InkDropImpl::HighlightAfterRippleTimerFired() { | 253 void InkDropImpl::HighlightAfterRippleTimerFired() { |
| 254 SetHighlight(true, base::TimeDelta::FromMilliseconds( | 254 SetHighlight(true, base::TimeDelta::FromMilliseconds( |
| 255 kHighlightFadeInAfterRippleDurationInMs), | 255 kHighlightFadeInAfterRippleDurationMs), |
| 256 true); | 256 true); |
| 257 highlight_after_ripple_timer_.reset(); | 257 highlight_after_ripple_timer_.reset(); |
| 258 } | 258 } |
| 259 | 259 |
| 260 } // namespace views | 260 } // namespace views |
| OLD | NEW |