Chromium Code Reviews| Index: cc/input/scrollbar_animation_controller.cc |
| diff --git a/cc/input/scrollbar_animation_controller.cc b/cc/input/scrollbar_animation_controller.cc |
| index c018016c8d7f93be8c052b088abf5e6fef919cfd..5325e358c20c57590522736d3848270e83626781 100644 |
| --- a/cc/input/scrollbar_animation_controller.cc |
| +++ b/cc/input/scrollbar_animation_controller.cc |
| @@ -27,14 +27,16 @@ std::unique_ptr<ScrollbarAnimationController> |
| ScrollbarAnimationController::CreateScrollbarAnimationControllerAuraOverlay( |
| int scroll_layer_id, |
| ScrollbarAnimationControllerClient* client, |
| - base::TimeDelta show_delay, |
| + base::TimeDelta fade_in_delay, |
| base::TimeDelta fade_out_delay, |
| base::TimeDelta fade_out_resize_delay, |
| + base::TimeDelta fade_in_duration, |
| base::TimeDelta fade_out_duration, |
| base::TimeDelta thinning_duration) { |
| return base::WrapUnique(new ScrollbarAnimationController( |
| - scroll_layer_id, client, show_delay, fade_out_delay, |
| - fade_out_resize_delay, fade_out_duration, thinning_duration)); |
| + scroll_layer_id, client, fade_in_delay, fade_out_delay, |
| + fade_out_resize_delay, fade_in_duration, fade_out_duration, |
| + thinning_duration)); |
| } |
| ScrollbarAnimationController::ScrollbarAnimationController( |
| @@ -46,13 +48,14 @@ ScrollbarAnimationController::ScrollbarAnimationController( |
| : client_(client), |
| fade_out_delay_(fade_out_delay), |
| fade_out_resize_delay_(fade_out_resize_delay), |
| + fade_out_duration_(fade_out_duration), |
| need_trigger_scrollbar_show_(false), |
| is_animating_(false), |
| + animation_change_(NONE), |
| scroll_layer_id_(scroll_layer_id), |
| currently_scrolling_(false), |
| show_in_fast_scroll_(false), |
| opacity_(0.0f), |
| - fade_out_duration_(fade_out_duration), |
| show_scrollbars_on_scroll_gesture_(false), |
| need_thinning_animation_(false), |
| weak_factory_(this) { |
| @@ -62,22 +65,25 @@ ScrollbarAnimationController::ScrollbarAnimationController( |
| ScrollbarAnimationController::ScrollbarAnimationController( |
| int scroll_layer_id, |
| ScrollbarAnimationControllerClient* client, |
| - base::TimeDelta show_delay, |
| + base::TimeDelta fade_in_delay, |
| base::TimeDelta fade_out_delay, |
| base::TimeDelta fade_out_resize_delay, |
| + base::TimeDelta fade_in_duration, |
| base::TimeDelta fade_out_duration, |
| base::TimeDelta thinning_duration) |
| : client_(client), |
| - show_delay_(show_delay), |
| + fade_in_delay_(fade_in_delay), |
| fade_out_delay_(fade_out_delay), |
| fade_out_resize_delay_(fade_out_resize_delay), |
| + fade_in_duration_(fade_in_duration), |
| + fade_out_duration_(fade_out_duration), |
| need_trigger_scrollbar_show_(false), |
| is_animating_(false), |
| + animation_change_(NONE), |
| scroll_layer_id_(scroll_layer_id), |
| currently_scrolling_(false), |
| show_in_fast_scroll_(false), |
| opacity_(0.0f), |
| - fade_out_duration_(fade_out_duration), |
| show_scrollbars_on_scroll_gesture_(true), |
| need_thinning_animation_(true), |
| weak_factory_(this) { |
| @@ -107,43 +113,44 @@ ScrollbarAnimationController::GetScrollbarAnimationController( |
| } |
| void ScrollbarAnimationController::StartAnimation() { |
| - delayed_scrollbar_show_.Cancel(); |
| - delayed_scrollbar_fade_out_.Cancel(); |
| + DCHECK(animation_change_ != NONE); |
| + delayed_scrollbar_animation_.Cancel(); |
| is_animating_ = true; |
| last_awaken_time_ = base::TimeTicks(); |
| client_->SetNeedsAnimateForScrollbarAnimation(); |
| } |
| void ScrollbarAnimationController::StopAnimation() { |
| - delayed_scrollbar_show_.Cancel(); |
| - delayed_scrollbar_fade_out_.Cancel(); |
| + delayed_scrollbar_animation_.Cancel(); |
| is_animating_ = false; |
| + animation_change_ = NONE; |
| } |
| -void ScrollbarAnimationController::PostDelayedShow() { |
| - DCHECK(delayed_scrollbar_fade_out_.IsCancelled()); |
| - delayed_scrollbar_show_.Cancel(); |
| - delayed_scrollbar_show_.Reset(base::Bind(&ScrollbarAnimationController::Show, |
| - weak_factory_.GetWeakPtr())); |
| - client_->PostDelayedScrollbarAnimationTask(delayed_scrollbar_show_.callback(), |
| - show_delay_); |
| -} |
| +void ScrollbarAnimationController::PostDelayedAnimation( |
| + AnimationChange animation_change, |
| + bool on_resize) { |
| + animation_change_ = animation_change; |
| + |
| + base::TimeDelta delay; |
| + if (animation_change == FADE_IN) { |
| + delay = fade_in_delay_; |
| + } else { |
| + delay = on_resize ? fade_out_resize_delay_ : fade_out_delay_; |
| + } |
| -void ScrollbarAnimationController::PostDelayedFadeOut(bool on_resize) { |
| - DCHECK(delayed_scrollbar_show_.IsCancelled()); |
| - base::TimeDelta delay = on_resize ? fade_out_resize_delay_ : fade_out_delay_; |
| - delayed_scrollbar_fade_out_.Cancel(); |
| - delayed_scrollbar_fade_out_.Reset( |
| + delayed_scrollbar_animation_.Cancel(); |
| + delayed_scrollbar_animation_.Reset( |
| base::Bind(&ScrollbarAnimationController::StartAnimation, |
| weak_factory_.GetWeakPtr())); |
| client_->PostDelayedScrollbarAnimationTask( |
| - delayed_scrollbar_fade_out_.callback(), delay); |
| + delayed_scrollbar_animation_.callback(), delay); |
| } |
| bool ScrollbarAnimationController::Animate(base::TimeTicks now) { |
| bool animated = false; |
| if (is_animating_) { |
| + DCHECK(animation_change_ != NONE); |
| if (last_awaken_time_.is_null()) |
| last_awaken_time_ = now; |
| @@ -166,12 +173,23 @@ bool ScrollbarAnimationController::Animate(base::TimeTicks now) { |
| float ScrollbarAnimationController::AnimationProgressAtTime( |
| base::TimeTicks now) { |
| base::TimeDelta delta = now - last_awaken_time_; |
| - float progress = delta.InSecondsF() / fade_out_duration_.InSecondsF(); |
| + base::TimeDelta duration = |
| + animation_change_ == FADE_IN ? fade_in_duration_ : fade_out_duration_; |
| + float progress = delta.InSecondsF() / duration.InSecondsF(); |
| return std::max(std::min(progress, 1.f), 0.f); |
| } |
| void ScrollbarAnimationController::RunAnimationFrame(float progress) { |
| - ApplyOpacityToScrollbars(1.f - progress); |
| + float opacity; |
| + |
| + DCHECK(animation_change_ != NONE); |
| + if (animation_change_ == FADE_IN) { |
| + opacity = std::max(progress, opacity_); |
| + } else { |
| + opacity = std::min(1.f - progress, opacity_); |
| + } |
| + |
| + ApplyOpacityToScrollbars(opacity); |
| if (progress == 1.f) |
| StopAnimation(); |
| } |
| @@ -192,7 +210,7 @@ void ScrollbarAnimationController::DidScrollEnd() { |
| return; |
| if (has_scrolled) |
| - PostDelayedFadeOut(false); |
| + PostDelayedAnimation(FADE_OUT, false); |
| } |
| void ScrollbarAnimationController::DidScrollUpdate() { |
| @@ -201,19 +219,19 @@ void ScrollbarAnimationController::DidScrollUpdate() { |
| StopAnimation(); |
| + Show(); |
| + |
| // As an optimization, we avoid spamming fade delay tasks during active fast |
| // scrolls. But if we're not within one, we need to post every scroll update. |
| if (!currently_scrolling_) { |
| // We don't fade out scrollbar if they need thinning animation and mouse is |
| // near. |
| if (!need_thinning_animation_ || !MouseIsNearAnyScrollbar()) |
| - PostDelayedFadeOut(false); |
| + PostDelayedAnimation(FADE_OUT, false); |
| } else { |
| show_in_fast_scroll_ = true; |
| } |
| - Show(); |
| - |
| if (need_thinning_animation_) { |
| vertical_controller_->UpdateThumbThicknessScale(); |
| horizontal_controller_->UpdateThumbThicknessScale(); |
| @@ -236,7 +254,7 @@ void ScrollbarAnimationController::DidResize() { |
| // As an optimization, we avoid spamming fade delay tasks during active fast |
| // scrolls. |
| if (!currently_scrolling_) { |
| - PostDelayedFadeOut(true); |
| + PostDelayedAnimation(FADE_OUT, true); |
| } else { |
| show_in_fast_scroll_ = true; |
| } |
| @@ -258,7 +276,7 @@ void ScrollbarAnimationController::DidMouseUp() { |
| horizontal_controller_->DidMouseUp(); |
| if (!MouseIsNearAnyScrollbar()) |
| - PostDelayedFadeOut(false); |
| + PostDelayedAnimation(FADE_OUT, false); |
| } |
| void ScrollbarAnimationController::DidMouseLeave() { |
| @@ -268,13 +286,13 @@ void ScrollbarAnimationController::DidMouseLeave() { |
| vertical_controller_->DidMouseLeave(); |
| horizontal_controller_->DidMouseLeave(); |
| - delayed_scrollbar_show_.Cancel(); |
| + delayed_scrollbar_animation_.Cancel(); |
| need_trigger_scrollbar_show_ = false; |
| if (ScrollbarsHidden() || Captured()) |
| return; |
| - PostDelayedFadeOut(false); |
| + PostDelayedAnimation(FADE_OUT, false); |
| } |
| void ScrollbarAnimationController::DidMouseMoveNear( |
| @@ -296,9 +314,9 @@ void ScrollbarAnimationController::DidMouseMoveNear( |
| if (ScrollbarsHidden()) { |
| if (need_trigger_scrollbar_show_before != need_trigger_scrollbar_show_) { |
| if (need_trigger_scrollbar_show_) { |
| - PostDelayedShow(); |
| + PostDelayedAnimation(FADE_IN, false); |
| } else { |
| - delayed_scrollbar_show_.Cancel(); |
| + delayed_scrollbar_animation_.Cancel(); |
| } |
| } |
| } else { |
|
chaopeng
2017/04/19 16:12:18
when is_animating FadeOut, mouse move would not po
weiliangc
2017/04/19 20:47:08
Ah I see so there is no animation to fade in when
|
| @@ -306,7 +324,7 @@ void ScrollbarAnimationController::DidMouseMoveNear( |
| Show(); |
| StopAnimation(); |
| } else if (!is_animating_) { |
| - PostDelayedFadeOut(false); |
| + PostDelayedAnimation(FADE_OUT, false); |
| } |
| } |
| } |
| @@ -324,7 +342,7 @@ bool ScrollbarAnimationController::CalcNeedTriggerScrollbarShow( |
| if (scrollbar->orientation() != orientation) |
| continue; |
| - if (distance < kMouseMoveDistanceToTriggerShow) |
| + if (distance < kMouseMoveDistanceToTriggerFadeIn) |
| return true; |
| } |
| @@ -359,7 +377,7 @@ bool ScrollbarAnimationController::Captured() const { |
| } |
| void ScrollbarAnimationController::Show() { |
| - delayed_scrollbar_show_.Cancel(); |
| + delayed_scrollbar_animation_.Cancel(); |
| ApplyOpacityToScrollbars(1.0f); |
| } |