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 f3f1a48121f113abcdb926d304e04dee22d948b0..1e491fb6c8a6ed55733b2a5ad51c07f58a507271 100644 |
| --- a/cc/input/scrollbar_animation_controller.cc |
| +++ b/cc/input/scrollbar_animation_controller.cc |
| @@ -9,6 +9,40 @@ |
| #include "base/time/time.h" |
| #include "cc/trees/layer_tree_impl.h" |
| +namespace { |
| + |
| +float DistanceToScrollbar(const gfx::PointF& device_viewport_point, |
|
bokan
2017/04/25 19:36:21
This should be called "DistanceToScrollbarTrack"
|
| + const cc::ScrollbarLayerImplBase* scrollbar) { |
| + if (!scrollbar) |
| + return std::numeric_limits<float>::max(); |
| + |
| + gfx::Rect scrollbar_bounds(scrollbar->bounds()); |
| + |
| + gfx::RectF device_viewport_scrollbar_bounds = cc::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 cc::ScrollbarLayerImplBase* scrollbar) { |
| + if (!scrollbar) |
| + return std::numeric_limits<float>::max(); |
| + |
| + gfx::Rect thumb_bounds(scrollbar->ComputeExpandedThumbQuadRect()); |
| + |
| + gfx::RectF device_viewport_scrollbar_bounds = cc::MathUtil::MapClippedRect( |
| + scrollbar->ScreenSpaceTransform(), gfx::RectF(thumb_bounds)); |
| + |
| + return device_viewport_scrollbar_bounds.ManhattanDistanceToPoint( |
| + device_viewport_point) / |
| + scrollbar->layer_tree_impl()->device_scale_factor(); |
| +} |
| + |
| +} // namespace |
| + |
| namespace cc { |
| std::unique_ptr<ScrollbarAnimationController> |
| @@ -95,6 +129,20 @@ ScrollbarSet ScrollbarAnimationController::Scrollbars() const { |
| return client_->ScrollbarsFor(scroll_element_id_); |
| } |
| +ScrollbarLayerImplBase* ScrollbarAnimationController::GetScrollbar( |
| + ScrollbarOrientation orientation) const { |
| + for (ScrollbarLayerImplBase* scrollbar : Scrollbars()) { |
| + if (!scrollbar->is_overlay_scrollbar()) |
| + continue; |
| + |
| + if (scrollbar->orientation() == orientation) |
| + return scrollbar; |
| + } |
| + |
| + NOTREACHED(); |
| + return nullptr; |
| +} |
| + |
| SingleScrollbarAnimationControllerThinning& |
| ScrollbarAnimationController::GetScrollbarAnimationController( |
| ScrollbarOrientation orientation) const { |
| @@ -283,16 +331,24 @@ void ScrollbarAnimationController::DidMouseLeave() { |
| void ScrollbarAnimationController::DidMouseMoveNear( |
|
bokan
2017/04/25 19:36:21
This no longer cares about distance - lets just ca
|
| ScrollbarOrientation orientation, |
| - float distance) { |
| + const gfx::PointF& device_viewport_point) { |
| if (!need_thinning_animation_) |
| return; |
| bool need_trigger_scrollbar_show_before = need_trigger_scrollbar_show_; |
| - GetScrollbarAnimationController(orientation).DidMouseMoveNear(distance); |
| + ScrollbarLayerImplBase* scrollbar = GetScrollbar(orientation); |
| + |
| + float distance_to_scrollbar = |
| + DistanceToScrollbar(device_viewport_point, scrollbar); |
| + float distance_to_thumb = |
| + DistanceToScrollbarThumb(device_viewport_point, scrollbar); |
| + |
| + GetScrollbarAnimationController(orientation) |
| + .DidMouseMoveNear(distance_to_scrollbar, distance_to_thumb); |
| need_trigger_scrollbar_show_ = |
| - CalcNeedTriggerScrollbarShow(orientation, distance); |
| + CalcNeedTriggerScrollbarShow(orientation, distance_to_scrollbar); |
| if (Captured()) |
| return; |
| @@ -320,8 +376,8 @@ bool ScrollbarAnimationController::CalcNeedTriggerScrollbarShow( |
| float distance) const { |
| DCHECK(need_thinning_animation_); |
| - if (vertical_controller_->mouse_is_over_scrollbar() || |
| - horizontal_controller_->mouse_is_over_scrollbar()) |
| + if (vertical_controller_->mouse_is_over_scrollbar_thumb() || |
|
bokan
2017/04/25 19:36:21
I think the show should still happen for "over the
|
| + horizontal_controller_->mouse_is_over_scrollbar_thumb()) |
| return true; |
| for (ScrollbarLayerImplBase* scrollbar : Scrollbars()) { |
| @@ -335,10 +391,18 @@ bool ScrollbarAnimationController::CalcNeedTriggerScrollbarShow( |
| return false; |
| } |
| -bool ScrollbarAnimationController::MouseIsOverScrollbar( |
| +bool ScrollbarAnimationController::MouseIsOverScrollbarThumb( |
| + ScrollbarOrientation orientation) const { |
| + DCHECK(need_thinning_animation_); |
| + return GetScrollbarAnimationController(orientation) |
| + .mouse_is_over_scrollbar_thumb(); |
| +} |
| + |
| +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( |