Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3500)

Unified Diff: cc/input/scrollbar_animation_controller.cc

Issue 2716453005: Aura Overlay Scrollbars appear when mouse hovers over scroller edge (Closed)
Patch Set: add 50px trigger Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..c32a1e3b278200334a585a4053f0b4c05e0cc3b8 100644
--- a/cc/input/scrollbar_animation_controller.cc
+++ b/cc/input/scrollbar_animation_controller.cc
@@ -9,48 +9,54 @@
#include "base/time/time.h"
#include "cc/trees/layer_tree_impl.h"
+namespace {
+constexpr float kMouseMoveDistanceToTriggerFadeInAnimation = 50.0f;
+}
+
namespace cc {
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),
+ need_trigger_scrollbar_fade_in_(false),
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 +65,22 @@ 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),
+ need_trigger_scrollbar_fade_in_(false),
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 +109,34 @@ 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() {
+ DCHECK(delayed_scrollbar_fade_in_.IsCancelled());
bokan 2017/02/28 14:04:49 It could also be null, right? I don't really care
chaopeng 2017/02/28 15:57:20 CancelableClosure doesnot have is_null(), and its
bokan 2017/02/28 17:12:30 Ok, that's fine, but I was still saying we should
+ delayed_scrollbar_fade_in_.Reset(base::Bind(
+ &ScrollbarAnimationController::FadeIn, weak_factory_.GetWeakPtr()));
+ client_->PostDelayedScrollbarAnimationTask(
+ delayed_scrollbar_fade_in_.callback(), fade_in_delay_);
+}
+
+void ScrollbarAnimationController::PostDelayedFadeOut(bool on_resize) {
+ base::TimeDelta delay = on_resize ? fade_out_resize_delay_ : fade_out_delay_;
+ 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 +165,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 +192,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 +217,7 @@ void ScrollbarAnimationController::DidScrollEnd() {
return;
if (has_scrolled)
- PostDelayedAnimationTask(false);
+ PostDelayedFadeOut(false);
}
void ScrollbarAnimationController::DidMouseDown() {
@@ -218,7 +236,7 @@ void ScrollbarAnimationController::DidMouseUp() {
horizontal_controller_->DidMouseUp();
if (!mouse_is_near_any_scrollbar())
- PostDelayedAnimationTask(false);
+ PostDelayedFadeOut(false);
}
void ScrollbarAnimationController::DidMouseLeave() {
@@ -231,7 +249,7 @@ void ScrollbarAnimationController::DidMouseLeave() {
if (ScrollbarsHidden() || Captured())
return;
- PostDelayedAnimationTask(false);
+ PostDelayedFadeOut(false);
}
void ScrollbarAnimationController::DidMouseMoveNear(
@@ -240,17 +258,54 @@ void ScrollbarAnimationController::DidMouseMoveNear(
if (!need_thinning_animation_)
return;
+ bool need_trigger_scrollbar_fade_in_before = need_trigger_scrollbar_fade_in_;
+
GetScrollbarAnimationController(orientation).DidMouseMoveNear(distance);
- if (ScrollbarsHidden() || Captured())
+ need_trigger_scrollbar_fade_in_ =
+ CalcNeedTriggerScrollbarFadeIn(orientation, distance);
+
+ if (Captured())
return;
- if (mouse_is_near_any_scrollbar()) {
- ApplyOpacityToScrollbars(1);
- StopAnimation();
- } else if (!is_animating_) {
- PostDelayedAnimationTask(false);
+ if (ScrollbarsHidden()) {
+ if (need_trigger_scrollbar_fade_in_before !=
+ need_trigger_scrollbar_fade_in_) {
+ if (need_trigger_scrollbar_fade_in_) {
+ PostDelayedFadeIn();
+ } else {
+ delayed_scrollbar_fade_in_.Cancel();
+ }
+ }
+ } else {
+ if (mouse_is_near_any_scrollbar()) {
+ FadeIn();
+ StopAnimation();
+ } else if (!is_animating_) {
+ PostDelayedFadeOut(false);
+ }
+ }
+}
+
+bool ScrollbarAnimationController::CalcNeedTriggerScrollbarFadeIn(
+ ScrollbarOrientation orientation,
+ float distance) const {
+ DCHECK(need_thinning_animation_);
+
+ if (vertical_controller_->mouse_is_over_scrollbar() ||
+ horizontal_controller_->mouse_is_over_scrollbar())
+ return true;
+
+ for (ScrollbarLayerImplBase* scrollbar : Scrollbars()) {
+ if (scrollbar->orientation() != orientation)
+ continue;
+
+ if (scrollbar->ThumbThickness() + distance <
bokan 2017/02/28 14:04:49 Nit: I think this would be clearer as |distance <
+ kMouseMoveDistanceToTriggerFadeInAnimation)
+ return true;
}
+
+ return false;
}
bool ScrollbarAnimationController::mouse_is_over_scrollbar(
@@ -280,6 +335,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())

Powered by Google App Engine
This is Rietveld 408576698