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

Unified Diff: cc/input/scrollbar_animation_controller.cc

Issue 2841943002: Overlay scrollbars expand only when mouse is near thumb (Closed)
Patch Set: weiliangc comment addressed Created 3 years, 8 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
« no previous file with comments | « cc/input/scrollbar_animation_controller.h ('k') | cc/input/scrollbar_animation_controller_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/input/scrollbar_animation_controller.cc
diff --git a/cc/input/scrollbar_animation_controller.cc b/cc/input/scrollbar_animation_controller.cc
index 2812a2cb53ef986c3ac85d67cc8beea51b455b9a..14dfe30a5ef5312c4bc693260022cea074e493c5 100644
--- a/cc/input/scrollbar_animation_controller.cc
+++ b/cc/input/scrollbar_animation_controller.cc
@@ -40,7 +40,7 @@ ScrollbarAnimationController::ScrollbarAnimationController(
: client_(client),
fade_delay_(fade_delay),
fade_duration_(fade_duration),
- need_trigger_scrollbar_show_(false),
+ need_trigger_scrollbar_fade_in_(false),
is_animating_(false),
animation_change_(NONE),
scroll_element_id_(scroll_element_id),
@@ -62,7 +62,7 @@ ScrollbarAnimationController::ScrollbarAnimationController(
: client_(client),
fade_delay_(fade_delay),
fade_duration_(fade_duration),
- need_trigger_scrollbar_show_(false),
+ need_trigger_scrollbar_fade_in_(false),
is_animating_(false),
animation_change_(NONE),
scroll_element_id_(scroll_element_id),
@@ -78,6 +78,7 @@ ScrollbarAnimationController::ScrollbarAnimationController(
horizontal_controller_ = SingleScrollbarAnimationControllerThinning::Create(
scroll_element_id, ScrollbarOrientation::HORIZONTAL, client,
thinning_duration);
+
ApplyOpacityToScrollbars(0.0f);
}
@@ -248,7 +249,7 @@ void ScrollbarAnimationController::DidMouseLeave() {
horizontal_controller_->DidMouseLeave();
delayed_scrollbar_animation_.Cancel();
- need_trigger_scrollbar_show_ = false;
+ need_trigger_scrollbar_fade_in_ = false;
if (ScrollbarsHidden() || Captured())
return;
@@ -256,25 +257,25 @@ void ScrollbarAnimationController::DidMouseLeave() {
PostDelayedAnimation(FADE_OUT);
}
-void ScrollbarAnimationController::DidMouseMoveNear(
- ScrollbarOrientation orientation,
- float distance) {
+void ScrollbarAnimationController::DidMouseMove(
+ const gfx::PointF& device_viewport_point) {
if (!need_thinning_animation_)
return;
- bool need_trigger_scrollbar_show_before = need_trigger_scrollbar_show_;
+ bool need_trigger_scrollbar_fade_in_before = need_trigger_scrollbar_fade_in_;
- GetScrollbarAnimationController(orientation).DidMouseMoveNear(distance);
+ vertical_controller_->DidMouseMove(device_viewport_point);
+ horizontal_controller_->DidMouseMove(device_viewport_point);
- need_trigger_scrollbar_show_ =
- CalcNeedTriggerScrollbarShow(orientation, distance);
+ need_trigger_scrollbar_fade_in_ = MouseIsNearAnyScrollbar();
if (Captured())
return;
if (ScrollbarsHidden()) {
- if (need_trigger_scrollbar_show_before != need_trigger_scrollbar_show_) {
- if (need_trigger_scrollbar_show_) {
+ if (need_trigger_scrollbar_fade_in_before !=
+ need_trigger_scrollbar_fade_in_) {
+ if (need_trigger_scrollbar_fade_in_) {
PostDelayedAnimation(FADE_IN);
} else {
delayed_scrollbar_animation_.Cancel();
@@ -290,42 +291,31 @@ void ScrollbarAnimationController::DidMouseMoveNear(
}
}
-bool ScrollbarAnimationController::CalcNeedTriggerScrollbarShow(
- ScrollbarOrientation orientation,
- float distance) const {
+bool ScrollbarAnimationController::MouseIsOverScrollbarThumb(
+ ScrollbarOrientation orientation) 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 (distance < kMouseMoveDistanceToTriggerFadeIn)
- return true;
- }
-
- return false;
+ return GetScrollbarAnimationController(orientation)
+ .mouse_is_over_scrollbar_thumb();
}
-bool ScrollbarAnimationController::MouseIsOverScrollbar(
+bool ScrollbarAnimationController::MouseIsNearScrollbarThumb(
ScrollbarOrientation orientation) const {
DCHECK(need_thinning_animation_);
- return GetScrollbarAnimationController(orientation).mouse_is_over_scrollbar();
+ return GetScrollbarAnimationController(orientation)
+ .mouse_is_near_scrollbar_thumb();
}
bool ScrollbarAnimationController::MouseIsNearScrollbar(
ScrollbarOrientation orientation) const {
DCHECK(need_thinning_animation_);
- return GetScrollbarAnimationController(orientation).mouse_is_near_scrollbar();
+ return GetScrollbarAnimationController(orientation)
+ .mouse_is_near_scrollbar_track();
}
bool ScrollbarAnimationController::MouseIsNearAnyScrollbar() const {
DCHECK(need_thinning_animation_);
- return vertical_controller_->mouse_is_near_scrollbar() ||
- horizontal_controller_->mouse_is_near_scrollbar();
+ return vertical_controller_->mouse_is_near_scrollbar_track() ||
+ horizontal_controller_->mouse_is_near_scrollbar_track();
}
bool ScrollbarAnimationController::ScrollbarsHidden() const {
@@ -334,7 +324,8 @@ bool ScrollbarAnimationController::ScrollbarsHidden() const {
bool ScrollbarAnimationController::Captured() const {
DCHECK(need_thinning_animation_);
- return vertical_controller_->captured() || horizontal_controller_->captured();
+ return GetScrollbarAnimationController(VERTICAL).captured() ||
+ GetScrollbarAnimationController(HORIZONTAL).captured();
}
void ScrollbarAnimationController::Show() {
@@ -344,8 +335,7 @@ void ScrollbarAnimationController::Show() {
void ScrollbarAnimationController::ApplyOpacityToScrollbars(float opacity) {
for (ScrollbarLayerImplBase* scrollbar : Scrollbars()) {
- if (!scrollbar->is_overlay_scrollbar())
- continue;
+ DCHECK(scrollbar->is_overlay_scrollbar());
float effective_opacity = scrollbar->CanScrollOrientation() ? opacity : 0;
scrollbar->SetOverlayScrollbarLayerOpacityAnimated(effective_opacity);
}
« no previous file with comments | « cc/input/scrollbar_animation_controller.h ('k') | cc/input/scrollbar_animation_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698