| 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_host.h" | 10 #include "ui/views/animation/ink_drop_host.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 | 50 |
| 51 } // namespace | 51 } // namespace |
| 52 | 52 |
| 53 InkDropImpl::InkDropImpl(InkDropHost* ink_drop_host) | 53 InkDropImpl::InkDropImpl(InkDropHost* ink_drop_host) |
| 54 : ink_drop_host_(ink_drop_host), | 54 : ink_drop_host_(ink_drop_host), |
| 55 root_layer_(new ui::Layer(ui::LAYER_NOT_DRAWN)), | 55 root_layer_(new ui::Layer(ui::LAYER_NOT_DRAWN)), |
| 56 root_layer_added_to_host_(false), | 56 root_layer_added_to_host_(false), |
| 57 is_hovered_(false), | 57 is_hovered_(false), |
| 58 is_focused_(false), |
| 58 hover_after_ripple_timer_(nullptr) { | 59 hover_after_ripple_timer_(nullptr) { |
| 59 root_layer_->set_name("InkDropImpl:RootLayer"); | 60 root_layer_->set_name("InkDropImpl:RootLayer"); |
| 60 } | 61 } |
| 61 | 62 |
| 62 InkDropImpl::~InkDropImpl() { | 63 InkDropImpl::~InkDropImpl() { |
| 63 // Explicitly destroy the InkDropRipple so that this still exists if | 64 // Explicitly destroy the InkDropRipple so that this still exists if |
| 64 // views::InkDropRippleObserver methods are called on this. | 65 // views::InkDropRippleObserver methods are called on this. |
| 65 DestroyInkDropRipple(); | 66 DestroyInkDropRipple(); |
| 66 DestroyInkDropHover(); | 67 DestroyInkDropHover(); |
| 67 } | 68 } |
| 68 | 69 |
| 69 InkDropState InkDropImpl::GetTargetInkDropState() const { | 70 InkDropState InkDropImpl::GetTargetInkDropState() const { |
| 70 if (!ink_drop_ripple_) | 71 if (!ink_drop_ripple_) |
| 71 return InkDropState::HIDDEN; | 72 return InkDropState::HIDDEN; |
| 72 return ink_drop_ripple_->target_ink_drop_state(); | 73 return ink_drop_ripple_->target_ink_drop_state(); |
| 73 } | 74 } |
| 74 | 75 |
| 75 bool InkDropImpl::IsVisible() const { | 76 bool InkDropImpl::IsVisible() const { |
| 76 return ink_drop_ripple_ && ink_drop_ripple_->IsVisible(); | 77 return ink_drop_ripple_ && ink_drop_ripple_->IsVisible(); |
| 77 } | 78 } |
| 78 | 79 |
| 79 void InkDropImpl::AnimateToState(InkDropState ink_drop_state) { | 80 void InkDropImpl::AnimateToState(InkDropState ink_drop_state) { |
| 80 DestroyHiddenTargetedAnimations(); | 81 DestroyHiddenTargetedAnimations(); |
| 81 if (!ink_drop_ripple_) | 82 if (!ink_drop_ripple_) |
| 82 CreateInkDropRipple(); | 83 CreateInkDropRipple(); |
| 83 | 84 |
| 84 if (ink_drop_state != views::InkDropState::HIDDEN) { | 85 if (ink_drop_state != views::InkDropState::HIDDEN) { |
| 85 SetHoveredInternal(false, base::TimeDelta::FromMilliseconds( | 86 SetHighlight(false, base::TimeDelta::FromMilliseconds( |
| 86 kHoverFadeOutBeforeRippleDurationInMs), | 87 kHoverFadeOutBeforeRippleDurationInMs), |
| 87 true); | 88 true); |
| 88 } | 89 } |
| 89 | 90 |
| 90 ink_drop_ripple_->AnimateToState(ink_drop_state); | 91 ink_drop_ripple_->AnimateToState(ink_drop_state); |
| 91 } | 92 } |
| 92 | 93 |
| 93 void InkDropImpl::SnapToActivated() { | 94 void InkDropImpl::SnapToActivated() { |
| 94 DestroyHiddenTargetedAnimations(); | 95 DestroyHiddenTargetedAnimations(); |
| 95 if (!ink_drop_ripple_) | 96 if (!ink_drop_ripple_) |
| 96 CreateInkDropRipple(); | 97 CreateInkDropRipple(); |
| 97 | 98 |
| 98 SetHoveredInternal(false, base::TimeDelta(), false); | 99 SetHighlight(false, base::TimeDelta(), false); |
| 99 | 100 |
| 100 ink_drop_ripple_->SnapToActivated(); | 101 ink_drop_ripple_->SnapToActivated(); |
| 101 } | 102 } |
| 102 | 103 |
| 103 void InkDropImpl::SetHovered(bool is_hovered) { | 104 void InkDropImpl::SetHovered(bool is_hovered) { |
| 104 is_hovered_ = is_hovered; | 105 is_hovered_ = is_hovered; |
| 105 SetHoveredInternal(is_hovered, | 106 SetHighlight(ShouldHighlight(), |
| 106 is_hovered ? base::TimeDelta::FromMilliseconds( | 107 ShouldHighlight() ? base::TimeDelta::FromMilliseconds( |
| 107 kHoverFadeInFromUserInputDurationInMs) | 108 kHoverFadeInFromUserInputDurationInMs) |
| 108 : base::TimeDelta::FromMilliseconds( | 109 : base::TimeDelta::FromMilliseconds( |
| 109 kHoverFadeOutFromUserInputDurationInMs), | 110 kHoverFadeOutFromUserInputDurationInMs), |
| 110 false); | 111 false); |
| 112 } |
| 113 |
| 114 void InkDropImpl::SetFocused(bool is_focused) { |
| 115 is_focused_ = is_focused; |
| 116 SetHighlight(ShouldHighlight(), base::TimeDelta(), false); |
| 111 } | 117 } |
| 112 | 118 |
| 113 void InkDropImpl::DestroyHiddenTargetedAnimations() { | 119 void InkDropImpl::DestroyHiddenTargetedAnimations() { |
| 114 if (ink_drop_ripple_ && | 120 if (ink_drop_ripple_ && |
| 115 (ink_drop_ripple_->target_ink_drop_state() == InkDropState::HIDDEN || | 121 (ink_drop_ripple_->target_ink_drop_state() == InkDropState::HIDDEN || |
| 116 ShouldAnimateToHidden(ink_drop_ripple_->target_ink_drop_state()))) { | 122 ShouldAnimateToHidden(ink_drop_ripple_->target_ink_drop_state()))) { |
| 117 DestroyInkDropRipple(); | 123 DestroyInkDropRipple(); |
| 118 } | 124 } |
| 119 } | 125 } |
| 120 | 126 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 } | 207 } |
| 202 | 208 |
| 203 void InkDropImpl::AnimationEnded(InkDropHover::AnimationType animation_type, | 209 void InkDropImpl::AnimationEnded(InkDropHover::AnimationType animation_type, |
| 204 InkDropAnimationEndedReason reason) { | 210 InkDropAnimationEndedReason reason) { |
| 205 if (animation_type == InkDropHover::FADE_OUT && | 211 if (animation_type == InkDropHover::FADE_OUT && |
| 206 reason == InkDropAnimationEndedReason::SUCCESS) { | 212 reason == InkDropAnimationEndedReason::SUCCESS) { |
| 207 DestroyInkDropHover(); | 213 DestroyInkDropHover(); |
| 208 } | 214 } |
| 209 } | 215 } |
| 210 | 216 |
| 211 void InkDropImpl::SetHoveredInternal(bool is_hovered, | 217 void InkDropImpl::SetHighlight(bool should_highlight, |
| 212 base::TimeDelta animation_duration, | 218 base::TimeDelta animation_duration, |
| 213 bool explode) { | 219 bool explode) { |
| 214 StopHoverAfterRippleTimer(); | 220 StopHoverAfterRippleTimer(); |
| 215 | 221 |
| 216 if (IsHoverFadingInOrVisible() == is_hovered) | 222 if (IsHoverFadingInOrVisible() == should_highlight) |
| 217 return; | 223 return; |
| 218 | 224 |
| 219 if (is_hovered) { | 225 if (should_highlight) { |
| 220 CreateInkDropHover(); | 226 CreateInkDropHover(); |
| 221 if (hover_ && !IsVisible()) | 227 if (hover_ && !IsVisible()) |
| 222 hover_->FadeIn(animation_duration); | 228 hover_->FadeIn(animation_duration); |
| 223 } else { | 229 } else { |
| 224 hover_->FadeOut(animation_duration, explode); | 230 hover_->FadeOut(animation_duration, explode); |
| 225 } | 231 } |
| 226 } | 232 } |
| 227 | 233 |
| 234 bool InkDropImpl::ShouldHighlight() const { |
| 235 return is_focused_ || is_hovered_; |
| 236 } |
| 237 |
| 228 void InkDropImpl::StartHoverAfterRippleTimer() { | 238 void InkDropImpl::StartHoverAfterRippleTimer() { |
| 229 StopHoverAfterRippleTimer(); | 239 StopHoverAfterRippleTimer(); |
| 230 | 240 |
| 231 if (!hover_after_ripple_timer_) | 241 if (!hover_after_ripple_timer_) |
| 232 hover_after_ripple_timer_.reset(new base::OneShotTimer); | 242 hover_after_ripple_timer_.reset(new base::OneShotTimer); |
| 233 | 243 |
| 234 hover_after_ripple_timer_->Start( | 244 hover_after_ripple_timer_->Start( |
| 235 FROM_HERE, | 245 FROM_HERE, |
| 236 base::TimeDelta::FromMilliseconds(kHoverFadeInAfterRippleDelayInMs), | 246 base::TimeDelta::FromMilliseconds(kHoverFadeInAfterRippleDelayInMs), |
| 237 base::Bind(&InkDropImpl::HoverAfterRippleTimerFired, | 247 base::Bind(&InkDropImpl::HoverAfterRippleTimerFired, |
| 238 base::Unretained(this))); | 248 base::Unretained(this))); |
| 239 } | 249 } |
| 240 | 250 |
| 241 void InkDropImpl::StopHoverAfterRippleTimer() { | 251 void InkDropImpl::StopHoverAfterRippleTimer() { |
| 242 if (hover_after_ripple_timer_) | 252 if (hover_after_ripple_timer_) |
| 243 hover_after_ripple_timer_.reset(); | 253 hover_after_ripple_timer_.reset(); |
| 244 } | 254 } |
| 245 | 255 |
| 246 void InkDropImpl::HoverAfterRippleTimerFired() { | 256 void InkDropImpl::HoverAfterRippleTimerFired() { |
| 247 SetHoveredInternal(true, base::TimeDelta::FromMilliseconds( | 257 SetHighlight(true, base::TimeDelta::FromMilliseconds( |
| 248 kHoverFadeInAfterRippleDurationInMs), | 258 kHoverFadeInAfterRippleDurationInMs), |
| 249 true); | 259 true); |
| 250 hover_after_ripple_timer_.reset(); | 260 hover_after_ripple_timer_.reset(); |
| 251 } | 261 } |
| 252 | 262 |
| 253 } // namespace views | 263 } // namespace views |
| OLD | NEW |