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

Unified Diff: cc/input/single_scrollbar_animation_controller_thinning.cc

Issue 2841943002: Overlay scrollbars expand only when mouse is near thumb (Closed)
Patch Set: bokan comments#8 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
Index: cc/input/single_scrollbar_animation_controller_thinning.cc
diff --git a/cc/input/single_scrollbar_animation_controller_thinning.cc b/cc/input/single_scrollbar_animation_controller_thinning.cc
index f09756ee5e636571e659691d1c146f6424b18bc3..81a2a176fb696ff023c4ed2943e46e3cb715fc6b 100644
--- a/cc/input/single_scrollbar_animation_controller_thinning.cc
+++ b/cc/input/single_scrollbar_animation_controller_thinning.cc
@@ -15,6 +15,34 @@
namespace cc {
+namespace {
+
+float DistanceToScrollbarTrack(const gfx::PointF& device_viewport_point,
weiliangc 2017/05/01 19:48:02 nit: move common code to another function and shar
+ const ScrollbarLayerImplBase& scrollbar) {
+ gfx::Rect scrollbar_bounds(scrollbar.bounds());
+
+ gfx::RectF device_viewport_scrollbar_bounds = MathUtil::MapClippedRect(
+ scrollbar.ScreenSpaceTransform(), gfx::RectF(scrollbar_bounds));
+
+ return device_viewport_scrollbar_bounds.ManhattanDistanceToPoint(
+ device_viewport_point) /
+ scrollbar.layer_tree_impl()->device_scale_factor();
+}
+
+float DistanceToScrollbarThumb(const gfx::PointF& device_viewport_point,
+ const ScrollbarLayerImplBase& scrollbar) {
+ gfx::Rect thumb_bounds(scrollbar.ComputeExpandedThumbQuadRect());
+
+ gfx::RectF device_viewport_scrollbar_thumb_bounds = MathUtil::MapClippedRect(
+ scrollbar.ScreenSpaceTransform(), gfx::RectF(thumb_bounds));
+
+ return device_viewport_scrollbar_thumb_bounds.ManhattanDistanceToPoint(
+ device_viewport_point) /
+ scrollbar.layer_tree_impl()->device_scale_factor();
+}
+
+} // namespace
+
std::unique_ptr<SingleScrollbarAnimationControllerThinning>
SingleScrollbarAnimationControllerThinning::Create(
ElementId scroll_element_id,
@@ -36,13 +64,27 @@ SingleScrollbarAnimationControllerThinning::
scroll_element_id_(scroll_element_id),
orientation_(orientation),
captured_(false),
- mouse_is_over_scrollbar_(false),
- mouse_is_near_scrollbar_(false),
+ mouse_is_over_scrollbar_thumb_(false),
+ mouse_is_near_scrollbar_thumb_(false),
+ mouse_is_near_scrollbar_track_(false),
thickness_change_(NONE),
thinning_duration_(thinning_duration) {
ApplyThumbThicknessScale(kIdleThicknessScale);
}
+ScrollbarLayerImplBase*
+SingleScrollbarAnimationControllerThinning::GetScrollbar() const {
+ for (ScrollbarLayerImplBase* scrollbar :
+ client_->ScrollbarsFor(scroll_element_id_)) {
+ DCHECK(scrollbar->is_overlay_scrollbar());
+
+ if (scrollbar->orientation() == orientation_)
+ return scrollbar;
+ }
+
+ return nullptr;
+}
+
bool SingleScrollbarAnimationControllerThinning::Animate(base::TimeTicks now) {
if (!is_animating_)
return false;
@@ -92,7 +134,7 @@ void SingleScrollbarAnimationControllerThinning::StopAnimation() {
}
void SingleScrollbarAnimationControllerThinning::DidMouseDown() {
- if (!mouse_is_over_scrollbar_)
+ if (!mouse_is_over_scrollbar_thumb_)
return;
StopAnimation();
@@ -107,7 +149,7 @@ void SingleScrollbarAnimationControllerThinning::DidMouseUp() {
captured_ = false;
StopAnimation();
- if (!mouse_is_near_scrollbar_) {
+ if (!mouse_is_near_scrollbar_thumb_) {
thickness_change_ = DECREASE;
StartAnimation();
} else {
@@ -116,11 +158,12 @@ void SingleScrollbarAnimationControllerThinning::DidMouseUp() {
}
void SingleScrollbarAnimationControllerThinning::DidMouseLeave() {
- if (!mouse_is_over_scrollbar_ && !mouse_is_near_scrollbar_)
+ if (!mouse_is_over_scrollbar_thumb_ && !mouse_is_near_scrollbar_thumb_)
return;
- mouse_is_over_scrollbar_ = false;
- mouse_is_near_scrollbar_ = false;
+ mouse_is_over_scrollbar_thumb_ = false;
+ mouse_is_near_scrollbar_thumb_ = false;
+ mouse_is_near_scrollbar_track_ = false;
if (captured_)
return;
@@ -129,24 +172,39 @@ void SingleScrollbarAnimationControllerThinning::DidMouseLeave() {
StartAnimation();
}
-void SingleScrollbarAnimationControllerThinning::DidMouseMoveNear(
- float distance) {
- bool mouse_is_over_scrollbar = distance == 0.0f;
- bool mouse_is_near_scrollbar =
- distance < kDefaultMouseMoveDistanceToTriggerAnimation;
+void SingleScrollbarAnimationControllerThinning::DidMouseMove(
+ const gfx::PointF& device_viewport_point) {
+ ScrollbarLayerImplBase* scrollbar = GetScrollbar();
+
+ if (!scrollbar)
+ return;
+
+ float distance_to_scrollbar_track =
+ DistanceToScrollbarTrack(device_viewport_point, *scrollbar);
+ float distance_to_scrollbar_thumb =
+ DistanceToScrollbarThumb(device_viewport_point, *scrollbar);
+
+ mouse_is_near_scrollbar_track_ =
+ distance_to_scrollbar_track <
+ ScrollbarAnimationController::kMouseMoveDistanceToTriggerFadeIn;
- if (!captured_ && mouse_is_near_scrollbar != mouse_is_near_scrollbar_) {
- thickness_change_ = mouse_is_near_scrollbar ? INCREASE : DECREASE;
+ bool mouse_is_over_scrollbar_thumb = distance_to_scrollbar_thumb == 0.0f;
+ bool mouse_is_near_scrollbar_thumb =
+ distance_to_scrollbar_thumb < kMouseMoveDistanceToTriggerExpand;
+
+ if (!captured_ &&
+ mouse_is_near_scrollbar_thumb != mouse_is_near_scrollbar_thumb_) {
+ thickness_change_ = mouse_is_near_scrollbar_thumb ? INCREASE : DECREASE;
StartAnimation();
}
- mouse_is_near_scrollbar_ = mouse_is_near_scrollbar;
- mouse_is_over_scrollbar_ = mouse_is_over_scrollbar;
+ mouse_is_near_scrollbar_thumb_ = mouse_is_near_scrollbar_thumb;
+ mouse_is_over_scrollbar_thumb_ = mouse_is_over_scrollbar_thumb;
}
float SingleScrollbarAnimationControllerThinning::ThumbThicknessScaleAt(
float progress) {
if (thickness_change_ == NONE)
- return mouse_is_near_scrollbar_ ? 1.f : kIdleThicknessScale;
+ return mouse_is_near_scrollbar_thumb_ ? 1.f : kIdleThicknessScale;
float factor = thickness_change_ == INCREASE ? progress : (1.f - progress);
return ((1.f - kIdleThicknessScale) * factor) + kIdleThicknessScale;
}
@@ -173,8 +231,8 @@ float SingleScrollbarAnimationControllerThinning::AdjustScale(
void SingleScrollbarAnimationControllerThinning::UpdateThumbThicknessScale() {
StopAnimation();
- ApplyThumbThicknessScale(mouse_is_near_scrollbar_ ? 1.f
- : kIdleThicknessScale);
+ ApplyThumbThicknessScale(
+ mouse_is_near_scrollbar_thumb_ ? 1.f : kIdleThicknessScale);
}
void SingleScrollbarAnimationControllerThinning::ApplyThumbThicknessScale(
@@ -182,8 +240,7 @@ void SingleScrollbarAnimationControllerThinning::ApplyThumbThicknessScale(
for (auto* scrollbar : client_->ScrollbarsFor(scroll_element_id_)) {
if (scrollbar->orientation() != orientation_)
continue;
- if (!scrollbar->is_overlay_scrollbar())
- continue;
+ DCHECK(scrollbar->is_overlay_scrollbar());
float scale = AdjustScale(thumb_thickness_scale,
scrollbar->thumb_thickness_scale_factor(),

Powered by Google App Engine
This is Rietveld 408576698