Chromium Code Reviews| Index: ui/views/animation/ink_drop_impl.cc |
| diff --git a/ui/views/animation/ink_drop_impl.cc b/ui/views/animation/ink_drop_impl.cc |
| index fdc6b773cdfccae8b67a7bd01f15e0d8e20fa61f..36df29db7800f6bf50da06c9e0e431af006c6ada 100644 |
| --- a/ui/views/animation/ink_drop_impl.cc |
| +++ b/ui/views/animation/ink_drop_impl.cc |
| @@ -78,19 +78,21 @@ void InkDropImpl::AnimateToState(InkDropState ink_drop_state) { |
| if (!ink_drop_ripple_) |
| CreateInkDropRipple(); |
| - // When deactivating and the host is focused, snap back to the highlight |
| - // state. (In the case of highlighting due to hover, we'll animate the |
| - // highlight back in after a delay.) |
| - if (ink_drop_state == views::InkDropState::DEACTIVATED && is_focused_) { |
| - ink_drop_ripple_->HideImmediately(); |
| - SetHighlight(true, base::TimeDelta(), false); |
| - return; |
| - } |
| - |
| - if (ink_drop_state != views::InkDropState::HIDDEN) { |
| - SetHighlight(false, base::TimeDelta::FromMilliseconds( |
| - kHighlightFadeOutBeforeRippleDurationMs), |
| - true); |
| + if (ink_drop_ripple_->OverridesHighlight()) { |
| + // When deactivating and the host is focused, snap back to the highlight |
| + // state. (In the case of highlighting due to hover, we'll animate the |
| + // highlight back in after a delay.) |
| + if (ink_drop_state == views::InkDropState::DEACTIVATED && is_focused_) { |
| + ink_drop_ripple_->HideImmediately(); |
| + SetHighlight(true, base::TimeDelta(), false); |
| + return; |
| + } |
| + |
| + if (ink_drop_state != views::InkDropState::HIDDEN) { |
| + SetHighlight(false, base::TimeDelta::FromMilliseconds( |
| + kHighlightFadeOutBeforeRippleDurationMs), |
| + true); |
| + } |
| } |
| ink_drop_ripple_->AnimateToState(ink_drop_state); |
| @@ -101,7 +103,8 @@ void InkDropImpl::SnapToActivated() { |
| if (!ink_drop_ripple_) |
| CreateInkDropRipple(); |
| - SetHighlight(false, base::TimeDelta(), false); |
| + if (ink_drop_ripple_->OverridesHighlight()) |
| + SetHighlight(false, base::TimeDelta(), false); |
| ink_drop_ripple_->SnapToActivated(); |
| } |
| @@ -133,15 +136,18 @@ void InkDropImpl::DestroyHiddenTargetedAnimations() { |
| void InkDropImpl::CreateInkDropRipple() { |
| DestroyInkDropRipple(); |
| ink_drop_ripple_ = ink_drop_host_->CreateInkDropRipple(); |
| - ink_drop_ripple_->set_observer(this); |
| - root_layer_->Add(ink_drop_ripple_->GetRootLayer()); |
| - AddRootLayerToHostIfNeeded(); |
| + if (ink_drop_ripple_->GetRootLayer()) { |
| + ink_drop_ripple_->set_observer(this); |
| + root_layer_->Add(ink_drop_ripple_->GetRootLayer()); |
| + AddRootLayerToHostIfNeeded(); |
| + } |
| } |
| void InkDropImpl::DestroyInkDropRipple() { |
| if (!ink_drop_ripple_) |
| return; |
| - root_layer_->Remove(ink_drop_ripple_->GetRootLayer()); |
| + if (ink_drop_ripple_->GetRootLayer()) |
| + root_layer_->Remove(ink_drop_ripple_->GetRootLayer()); |
| ink_drop_ripple_.reset(); |
| RemoveRootLayerFromHostIfNeeded(); |
| } |
| @@ -168,6 +174,7 @@ void InkDropImpl::DestroyInkDropHighlight() { |
| void InkDropImpl::AddRootLayerToHostIfNeeded() { |
| DCHECK(highlight_ || ink_drop_ripple_); |
| + DCHECK(!root_layer_->children().empty()); |
| if (!root_layer_added_to_host_) { |
| root_layer_added_to_host_ = true; |
| ink_drop_host_->AddInkDropLayer(root_layer_.get()); |
| @@ -175,7 +182,7 @@ void InkDropImpl::AddRootLayerToHostIfNeeded() { |
| } |
| void InkDropImpl::RemoveRootLayerFromHostIfNeeded() { |
| - if (root_layer_added_to_host_ && !highlight_ && !ink_drop_ripple_) { |
| + if (root_layer_added_to_host_ && root_layer_->children().empty()) { |
| root_layer_added_to_host_ = false; |
| ink_drop_host_->RemoveInkDropLayer(root_layer_.get()); |
| } |
| @@ -199,10 +206,12 @@ void InkDropImpl::AnimationEnded(InkDropState ink_drop_state, |
| } else if (ink_drop_state == views::InkDropState::HIDDEN) { |
| // Re-highlight, as necessary. For hover, there's a delay; for focus, jump |
| // straight into the animation. |
| - if (is_focused_) |
| - HighlightAfterRippleTimerFired(); |
| - else if (is_hovered_) |
| - StartHighlightAfterRippleTimer(); |
| + if (!IsHighlightFadingInOrVisible()) { |
| + if (is_focused_) |
| + HighlightAfterRippleTimerFired(); |
| + else if (is_hovered_) |
| + StartHighlightAfterRippleTimer(); |
| + } |
| // TODO(bruthig): Investigate whether creating and destroying |
| // InkDropRipples is expensive and consider creating an |
| @@ -235,8 +244,11 @@ void InkDropImpl::SetHighlight(bool should_highlight, |
| if (should_highlight) { |
| CreateInkDropHighlight(); |
| - if (highlight_ && !(ink_drop_ripple_ && ink_drop_ripple_->IsVisible())) |
| + if (highlight_ && |
| + !(ink_drop_ripple_ && ink_drop_ripple_->IsVisible() && |
| + ink_drop_ripple_->OverridesHighlight())) { |
|
bruthig
2016/09/08 15:56:04
Can this have a test?
Evan Stade
2016/09/08 19:17:32
added to HighlightCanCoexistWithRipple
|
| highlight_->FadeIn(animation_duration); |
| + } |
| } else { |
| highlight_->FadeOut(animation_duration, explode); |
| } |