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..896ab02abe8a45619ad6bbe0c2bf99e9165027f4 100644 |
| --- a/cc/input/scrollbar_animation_controller.cc |
| +++ b/cc/input/scrollbar_animation_controller.cc |
| @@ -30,11 +30,13 @@ ScrollbarAnimationController::CreateScrollbarAnimationControllerAuraOverlay( |
| base::TimeDelta show_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)); |
| + 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) { |
| @@ -65,19 +68,22 @@ ScrollbarAnimationController::ScrollbarAnimationController( |
| base::TimeDelta show_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_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) { |
| @@ -118,19 +124,23 @@ void ScrollbarAnimationController::StopAnimation() { |
| delayed_scrollbar_show_.Cancel(); |
| delayed_scrollbar_fade_out_.Cancel(); |
| is_animating_ = false; |
| + animation_change_ = NONE; |
| } |
| -void ScrollbarAnimationController::PostDelayedShow() { |
| +void ScrollbarAnimationController::PostDelayedFadeIn() { |
| DCHECK(delayed_scrollbar_fade_out_.IsCancelled()); |
| + animation_change_ = FADE_IN; |
| delayed_scrollbar_show_.Cancel(); |
| - delayed_scrollbar_show_.Reset(base::Bind(&ScrollbarAnimationController::Show, |
| - weak_factory_.GetWeakPtr())); |
| + delayed_scrollbar_show_.Reset( |
|
bokan
2017/04/13 14:38:14
Rename delayed_scrollbar_show too.
chaopeng
2017/04/13 15:15:37
Done.
|
| + base::Bind(&ScrollbarAnimationController::StartAnimation, |
| + weak_factory_.GetWeakPtr())); |
| client_->PostDelayedScrollbarAnimationTask(delayed_scrollbar_show_.callback(), |
| show_delay_); |
| } |
| void ScrollbarAnimationController::PostDelayedFadeOut(bool on_resize) { |
| DCHECK(delayed_scrollbar_show_.IsCancelled()); |
| + animation_change_ = FADE_OUT; |
| base::TimeDelta delay = on_resize ? fade_out_resize_delay_ : fade_out_delay_; |
| delayed_scrollbar_fade_out_.Cancel(); |
| delayed_scrollbar_fade_out_.Reset( |
| @@ -143,7 +153,7 @@ void ScrollbarAnimationController::PostDelayedFadeOut(bool on_resize) { |
| bool ScrollbarAnimationController::Animate(base::TimeTicks now) { |
| bool animated = false; |
| - if (is_animating_) { |
| + if (is_animating_ && animation_change_ != NONE) { |
| if (last_awaken_time_.is_null()) |
| last_awaken_time_ = now; |
| @@ -166,12 +176,22 @@ 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; |
| + |
| + if (animation_change_ == FADE_IN) { |
| + opacity = std::max(progress, opacity_); |
| + } else { |
|
bokan
2017/04/13 14:38:14
DCHECK above that animation_change_ isn't NONE
chaopeng
2017/04/13 15:15:37
Done.
|
| + opacity = std::min(1.f - progress, opacity_); |
| + } |
| + |
| + ApplyOpacityToScrollbars(opacity); |
| if (progress == 1.f) |
| StopAnimation(); |
| } |
| @@ -296,7 +316,7 @@ void ScrollbarAnimationController::DidMouseMoveNear( |
| if (ScrollbarsHidden()) { |
| if (need_trigger_scrollbar_show_before != need_trigger_scrollbar_show_) { |
| if (need_trigger_scrollbar_show_) { |
| - PostDelayedShow(); |
| + PostDelayedFadeIn(); |
| } else { |
| delayed_scrollbar_show_.Cancel(); |
| } |
| @@ -324,7 +344,7 @@ bool ScrollbarAnimationController::CalcNeedTriggerScrollbarShow( |
| if (scrollbar->orientation() != orientation) |
| continue; |
| - if (distance < kMouseMoveDistanceToTriggerShow) |
| + if (distance < kMouseMoveDistanceToTriggerFadeIn) |
| return true; |
| } |
| @@ -359,7 +379,6 @@ bool ScrollbarAnimationController::Captured() const { |
| } |
| void ScrollbarAnimationController::Show() { |
| - delayed_scrollbar_show_.Cancel(); |
|
bokan
2017/04/13 14:38:14
Why don't we want to cancel this now? If we scroll
chaopeng
2017/04/13 15:15:37
Yes, we should keep this.
|
| ApplyOpacityToScrollbars(1.0f); |
| } |