Index: cc/input/scrollbar_animation_controller.cc |
diff --git a/cc/input/scrollbar_animation_controller.cc b/cc/input/scrollbar_animation_controller.cc |
index 49d24920a2e4134bdbf9c6c553211c997d5b33c5..6927d0415738fc93435406bdeb0fcd3f8f30db1d 100644 |
--- a/cc/input/scrollbar_animation_controller.cc |
+++ b/cc/input/scrollbar_animation_controller.cc |
@@ -15,42 +15,43 @@ std::unique_ptr<ScrollbarAnimationController> |
ScrollbarAnimationController::CreateScrollbarAnimationControllerAndroid( |
int scroll_layer_id, |
ScrollbarAnimationControllerClient* client, |
- base::TimeDelta delay_before_starting, |
- base::TimeDelta resize_delay_before_starting, |
- base::TimeDelta fade_duration) { |
+ base::TimeDelta fade_out_delay, |
+ base::TimeDelta fade_out_resize_delay, |
+ base::TimeDelta fade_out_duration) { |
return base::WrapUnique(new ScrollbarAnimationController( |
- scroll_layer_id, client, delay_before_starting, |
- resize_delay_before_starting, fade_duration)); |
+ scroll_layer_id, client, fade_out_delay, fade_out_resize_delay, |
+ fade_out_duration)); |
} |
std::unique_ptr<ScrollbarAnimationController> |
ScrollbarAnimationController::CreateScrollbarAnimationControllerAuraOverlay( |
int scroll_layer_id, |
ScrollbarAnimationControllerClient* client, |
- base::TimeDelta delay_before_starting, |
- base::TimeDelta resize_delay_before_starting, |
- base::TimeDelta fade_duration, |
+ base::TimeDelta fade_in_delay, |
+ base::TimeDelta fade_out_delay, |
+ base::TimeDelta fade_out_resize_delay, |
+ base::TimeDelta fade_out_duration, |
base::TimeDelta thinning_duration) { |
return base::WrapUnique(new ScrollbarAnimationController( |
- scroll_layer_id, client, delay_before_starting, |
- resize_delay_before_starting, fade_duration, thinning_duration)); |
+ scroll_layer_id, client, fade_in_delay, fade_out_delay, |
+ fade_out_resize_delay, fade_out_duration, thinning_duration)); |
} |
ScrollbarAnimationController::ScrollbarAnimationController( |
int scroll_layer_id, |
ScrollbarAnimationControllerClient* client, |
- base::TimeDelta delay_before_starting, |
- base::TimeDelta resize_delay_before_starting, |
- base::TimeDelta fade_duration) |
+ base::TimeDelta fade_out_delay, |
+ base::TimeDelta fade_out_resize_delay, |
+ base::TimeDelta fade_out_duration) |
: client_(client), |
- delay_before_starting_(delay_before_starting), |
- resize_delay_before_starting_(resize_delay_before_starting), |
+ fade_out_delay_(fade_out_delay), |
+ fade_out_resize_delay_(fade_out_resize_delay), |
is_animating_(false), |
scroll_layer_id_(scroll_layer_id), |
currently_scrolling_(false), |
scroll_gesture_has_scrolled_(false), |
opacity_(0.0f), |
- fade_duration_(fade_duration), |
+ fade_out_duration_(fade_out_duration), |
need_thinning_animation_(false), |
weak_factory_(this) { |
ApplyOpacityToScrollbars(0.0f); |
@@ -59,19 +60,21 @@ ScrollbarAnimationController::ScrollbarAnimationController( |
ScrollbarAnimationController::ScrollbarAnimationController( |
int scroll_layer_id, |
ScrollbarAnimationControllerClient* client, |
- base::TimeDelta delay_before_starting, |
- base::TimeDelta resize_delay_before_starting, |
- base::TimeDelta fade_duration, |
+ base::TimeDelta fade_in_delay, |
+ base::TimeDelta fade_out_delay, |
+ base::TimeDelta fade_out_resize_delay, |
+ base::TimeDelta fade_out_duration, |
base::TimeDelta thinning_duration) |
: client_(client), |
- delay_before_starting_(delay_before_starting), |
- resize_delay_before_starting_(resize_delay_before_starting), |
+ fade_in_delay_(fade_in_delay), |
+ fade_out_delay_(fade_out_delay), |
+ fade_out_resize_delay_(fade_out_resize_delay), |
is_animating_(false), |
scroll_layer_id_(scroll_layer_id), |
currently_scrolling_(false), |
scroll_gesture_has_scrolled_(false), |
opacity_(0.0f), |
- fade_duration_(fade_duration), |
+ fade_out_duration_(fade_out_duration), |
need_thinning_animation_(true), |
weak_factory_(this) { |
vertical_controller_ = SingleScrollbarAnimationControllerThinning::Create( |
@@ -100,25 +103,33 @@ ScrollbarAnimationController::GetScrollbarAnimationController( |
} |
void ScrollbarAnimationController::StartAnimation() { |
- delayed_scrollbar_fade_.Cancel(); |
+ delayed_scrollbar_fade_in_.Cancel(); |
+ delayed_scrollbar_fade_out_.Cancel(); |
is_animating_ = true; |
last_awaken_time_ = base::TimeTicks(); |
client_->SetNeedsAnimateForScrollbarAnimation(); |
} |
void ScrollbarAnimationController::StopAnimation() { |
- delayed_scrollbar_fade_.Cancel(); |
+ delayed_scrollbar_fade_in_.Cancel(); |
+ delayed_scrollbar_fade_out_.Cancel(); |
is_animating_ = false; |
} |
-void ScrollbarAnimationController::PostDelayedAnimationTask(bool on_resize) { |
- base::TimeDelta delay = |
- on_resize ? resize_delay_before_starting_ : delay_before_starting_; |
- delayed_scrollbar_fade_.Reset( |
+void ScrollbarAnimationController::PostDelayedFadeIn() { |
+ delayed_scrollbar_fade_in_.Reset(base::Bind( |
+ &ScrollbarAnimationController::FadeIn, weak_factory_.GetWeakPtr())); |
+ client_->PostDelayedScrollbarAnimationTask( |
+ delayed_scrollbar_fade_in_.callback(), fade_in_delay_); |
bokan
2017/02/27 23:13:56
Can we say anything about the fade out animation?
|
+} |
+ |
+void ScrollbarAnimationController::PostDelayedFadeOut(bool on_resize) { |
+ base::TimeDelta delay = on_resize ? fade_out_resize_delay_ : fade_out_delay_; |
bokan
2017/02/27 23:13:56
Ditto here for fade in
chaopeng
2017/02/28 01:38:27
But we immediately fade in for resize and update s
bokan
2017/02/28 14:04:49
Right, but that should happen immediately rather t
|
+ delayed_scrollbar_fade_out_.Reset( |
base::Bind(&ScrollbarAnimationController::StartAnimation, |
weak_factory_.GetWeakPtr())); |
- client_->PostDelayedScrollbarAnimationTask(delayed_scrollbar_fade_.callback(), |
- delay); |
+ client_->PostDelayedScrollbarAnimationTask( |
+ delayed_scrollbar_fade_out_.callback(), delay); |
} |
bool ScrollbarAnimationController::Animate(base::TimeTicks now) { |
@@ -147,7 +158,7 @@ bool ScrollbarAnimationController::Animate(base::TimeTicks now) { |
float ScrollbarAnimationController::AnimationProgressAtTime( |
base::TimeTicks now) { |
base::TimeDelta delta = now - last_awaken_time_; |
- float progress = delta.InSecondsF() / fade_duration_.InSecondsF(); |
+ float progress = delta.InSecondsF() / fade_out_duration_.InSecondsF(); |
return std::max(std::min(progress, 1.f), 0.f); |
} |
@@ -174,12 +185,12 @@ void ScrollbarAnimationController::DidScrollUpdate(bool on_resize) { |
// We don't fade out scrollbar if they need thinning animation and mouse is |
// near. |
if (!need_thinning_animation_ || !mouse_is_near_any_scrollbar()) |
- PostDelayedAnimationTask(on_resize); |
+ PostDelayedFadeOut(on_resize); |
} else { |
scroll_gesture_has_scrolled_ = true; |
} |
- ApplyOpacityToScrollbars(1); |
+ FadeIn(); |
if (need_thinning_animation_) { |
vertical_controller_->UpdateThumbThicknessScale(); |
@@ -199,7 +210,7 @@ void ScrollbarAnimationController::DidScrollEnd() { |
return; |
if (has_scrolled) |
- PostDelayedAnimationTask(false); |
+ PostDelayedFadeOut(false); |
} |
void ScrollbarAnimationController::DidMouseDown() { |
@@ -218,7 +229,7 @@ void ScrollbarAnimationController::DidMouseUp() { |
horizontal_controller_->DidMouseUp(); |
if (!mouse_is_near_any_scrollbar()) |
- PostDelayedAnimationTask(false); |
+ PostDelayedFadeOut(false); |
} |
void ScrollbarAnimationController::DidMouseLeave() { |
@@ -231,7 +242,7 @@ void ScrollbarAnimationController::DidMouseLeave() { |
if (ScrollbarsHidden() || Captured()) |
return; |
- PostDelayedAnimationTask(false); |
+ PostDelayedFadeOut(false); |
} |
void ScrollbarAnimationController::DidMouseMoveNear( |
@@ -240,16 +251,29 @@ void ScrollbarAnimationController::DidMouseMoveNear( |
if (!need_thinning_animation_) |
return; |
+ bool is_over_scrollbar_before = mouse_is_over_any_scrollbar(); |
+ |
GetScrollbarAnimationController(orientation).DidMouseMoveNear(distance); |
- if (ScrollbarsHidden() || Captured()) |
+ if (Captured()) |
return; |
- if (mouse_is_near_any_scrollbar()) { |
- ApplyOpacityToScrollbars(1); |
- StopAnimation(); |
- } else if (!is_animating_) { |
- PostDelayedAnimationTask(false); |
+ if (ScrollbarsHidden()) { |
+ bool is_over_scrollbar_now = mouse_is_over_any_scrollbar(); |
bokan
2017/02/27 23:17:48
Also - We shouldn't be doing any of this mouse rel
chaopeng
2017/02/28 01:38:27
We have a early return in this method |!need_thin
bokan
2017/02/28 14:04:49
Ah, sorry, I missed that.
|
+ if (is_over_scrollbar_before != is_over_scrollbar_now) { |
+ if (is_over_scrollbar_now) { |
+ PostDelayedFadeIn(); |
+ } else { |
+ delayed_scrollbar_fade_in_.Cancel(); |
+ } |
+ } |
+ } else { |
+ if (mouse_is_near_any_scrollbar()) { |
+ FadeIn(); |
+ StopAnimation(); |
+ } else if (!is_animating_) { |
+ PostDelayedFadeOut(false); |
+ } |
} |
} |
@@ -259,6 +283,12 @@ bool ScrollbarAnimationController::mouse_is_over_scrollbar( |
return GetScrollbarAnimationController(orientation).mouse_is_over_scrollbar(); |
} |
+bool ScrollbarAnimationController::mouse_is_over_any_scrollbar() const { |
+ DCHECK(need_thinning_animation_); |
+ return vertical_controller_->mouse_is_over_scrollbar() || |
+ horizontal_controller_->mouse_is_over_scrollbar(); |
+} |
+ |
bool ScrollbarAnimationController::mouse_is_near_scrollbar( |
ScrollbarOrientation orientation) const { |
DCHECK(need_thinning_animation_); |
@@ -280,6 +310,10 @@ bool ScrollbarAnimationController::Captured() const { |
return vertical_controller_->captured() || horizontal_controller_->captured(); |
} |
+void ScrollbarAnimationController::FadeIn() { |
+ ApplyOpacityToScrollbars(1.0f); |
+} |
+ |
void ScrollbarAnimationController::ApplyOpacityToScrollbars(float opacity) { |
for (ScrollbarLayerImplBase* scrollbar : Scrollbars()) { |
if (!scrollbar->is_overlay_scrollbar()) |