Skip to content

Commit

Permalink
[Compositor threaded scrollbar scrolling] Mac scrollbars hit testing.
Browse files Browse the repository at this point in the history
Mac doesn't |use-zoom-for-dsf|. Hence, the ScreenSpaceTransform needs
to be scaled down by the device_scale_factor for hit testing to work
as intended.

Bug: 1003576
Change-Id: I049e5d06d4ed6859e3e5a88b7fb61b46e8175801
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1588948
Reviewed-by: Jonathan Ross <jonross@chromium.org>
Reviewed-by: David Bokan <bokan@chromium.org>
Commit-Queue: Rahul Arakeri <arakeri@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#702546}
  • Loading branch information
Rahul Arakeri authored and Commit Bot committed Oct 3, 2019
1 parent 90c5b31 commit 64953c3
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 5 deletions.
39 changes: 34 additions & 5 deletions cc/input/scrollbar_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -378,14 +378,21 @@ float ScrollbarController::GetScrollerToScrollbarRatio() {
const LayerImpl* owner_scroll_layer =
layer_tree_host_impl_->active_tree()->ScrollableLayerByElementId(
currently_captured_scrollbar_->scroll_element_id());
float viewport_length =
const float viewport_length =
orientation == ScrollbarOrientation::VERTICAL
? owner_scroll_layer->scroll_container_bounds().height()
: (owner_scroll_layer->scroll_container_bounds().width());

// For platforms which have use_zoom_for_dsf set to false (like Mac), the
// device_scale_factor should not be used while determining the
// scaled_scroller_to_scrollbar_ratio as thumb drag would appear jittery due
// to constant over and under corrections.
// (See ScrollbarController::ScreenSpaceScaleFactor()).
float scaled_scroller_to_scrollbar_ratio =
((scroll_layer_length - viewport_length) /
(scrollbar_track_length - scrollbar_thumb_length)) *
layer_tree_host_impl_->active_tree()->device_scale_factor();
ScreenSpaceScaleFactor();

return scaled_scroller_to_scrollbar_ratio;
}

Expand Down Expand Up @@ -597,16 +604,38 @@ int ScrollbarController::GetScrollDeltaForScrollbarPart(
default:
scroll_delta = 0;
}
return scroll_delta *
layer_tree_host_impl_->active_tree()->device_scale_factor();

return scroll_delta * ScreenSpaceScaleFactor();
}

float ScrollbarController::ScreenSpaceScaleFactor() const {
// TODO(arakeri): When crbug.com/716231 is fixed, this needs to be updated.
// If use_zoom_for_dsf is false, the click deltas and thumb drag ratios
// shouldn't be scaled. For example: On Mac, when the use_zoom_for_dsf is
// false and the device_scale_factor is 2, the scroll delta for pointer clicks
// on arrows would be incorrectly calculated as 80px instead of 40px. This is
// also necessary to ensure that hit testing works as intended.
return layer_tree_host_impl_->settings().use_zoom_for_dsf
? layer_tree_host_impl_->active_tree()->device_scale_factor()
: 1.f;
}

gfx::PointF ScrollbarController::GetScrollbarRelativePosition(
const gfx::PointF position_in_widget,
bool* clipped) {
gfx::Transform inverse_screen_space_transform(
gfx::Transform::kSkipInitialization);
if (!currently_captured_scrollbar_->ScreenSpaceTransform().GetInverse(

// If use_zoom_for_dsf is false, the ScreenSpaceTransform needs to be scaled
// down by the DSF to ensure that position_in_widget is transformed correctly.
const float scale =
!layer_tree_host_impl_->settings().use_zoom_for_dsf
? 1.f / layer_tree_host_impl_->active_tree()->device_scale_factor()
: 1.f;
gfx::Transform scaled_screen_space_transform(
currently_captured_scrollbar_->ScreenSpaceTransform());
scaled_screen_space_transform.PostScale(scale, scale);
if (!scaled_screen_space_transform.GetInverse(
&inverse_screen_space_transform))
return gfx::PointF(0, 0);

Expand Down
3 changes: 3 additions & 0 deletions cc/input/scrollbar_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ class CC_EXPORT ScrollbarController {
float scroll_position_at_start_;
};

// Returns the DSF based on whether use-zoom-for-dsf is enabled.
float ScreenSpaceScaleFactor() const;

// Helper to convert scroll offset to autoscroll velocity.
float InitialDeltaToAutoscrollVelocity(gfx::ScrollOffset scroll_offset) const;

Expand Down
3 changes: 3 additions & 0 deletions cc/trees/layer_tree_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ class CC_EXPORT LayerTreeSettings {
// deadlines.
bool wait_for_all_pipeline_stages_before_draw = false;

// Determines whether the zoom needs to be applied to the device scale factor.
bool use_zoom_for_dsf = false;

// Determines whether mouse interactions on composited scrollbars are handled
// on the compositor thread.
bool compositor_threaded_scrollbar_scrolling = false;
Expand Down
1 change: 1 addition & 0 deletions content/renderer/render_widget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2917,6 +2917,7 @@ cc::LayerTreeSettings RenderWidget::GenerateLayerTreeSettings(
const base::CommandLine& cmd = *base::CommandLine::ForCurrentProcess();
cc::LayerTreeSettings settings;

settings.use_zoom_for_dsf = compositor_deps->IsUseZoomForDSFEnabled();
settings.compositor_threaded_scrollbar_scrolling =
base::FeatureList::IsEnabled(
features::kCompositorThreadedScrollbarScrolling);
Expand Down
2 changes: 2 additions & 0 deletions third_party/blink/web_tests/NeverFixTests
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ fast/harness/results.html [ WontFix ]
[ Mac ] fast/scrolling/scrollbars/scrollbar-thumb-snapping.html [ WontFix ]
[ Linux ] virtual/compositor_threaded_scrollbar_scrolling/fast/scrolling/scrollbars/scrollbar-thumb-snapping.html [ WontFix ]
[ Mac ] virtual/compositor_threaded_scrollbar_scrolling/fast/scrolling/scrollbars/scrollbar-thumb-snapping.html [ WontFix ]
[ Linux ] virtual/compositor_threaded_scrollbar_scrolling_hidpi_nozoomfordsf/fast/scrolling/scrollbars/scrollbar-thumb-snapping.html [ WontFix ]
[ Mac ] virtual/compositor_threaded_scrollbar_scrolling_hidpi_nozoomfordsf/fast/scrolling/scrollbars/scrollbar-thumb-snapping.html [ WontFix ]
[ Linux ] virtual/scroll_customization/fast/scrolling/scrollbars/scrollbar-thumb-snapping.html [ WontFix ]
[ Mac ] virtual/scroll_customization/fast/scrolling/scrollbars/scrollbar-thumb-snapping.html [ WontFix ]
[ Linux ] virtual/threaded/fast/scrolling/scrollbars/scrollbar-thumb-snapping.html [ WontFix ]
Expand Down
5 changes: 5 additions & 0 deletions third_party/blink/web_tests/TestExpectations
Original file line number Diff line number Diff line change
Expand Up @@ -3052,6 +3052,11 @@ crbug.com/953847 [ Mac ] virtual/compositor_threaded_scrollbar_scrolling/fast/sc
crbug.com/953847 [ Mac ] virtual/compositor_threaded_scrollbar_scrolling/fast/scrolling/scrollbars/scroll-chaining-for-gesture-based-scrolling.html [ Failure ]
crbug.com/953847 [ Mac ] virtual/compositor_threaded_scrollbar_scrolling/fast/scrolling/scrollbars/scrollbar-occluded-by-div.html [ Failure ]
crbug.com/953847 [ Mac ] virtual/compositor_threaded_scrollbar_scrolling/fast/scrolling/scrollbars/mouse-autoscrolling-on-scrollbar.html [ Failure Timeout ]
crbug.com/953847 [ Mac ] virtual/compositor_threaded_scrollbar_scrolling_hidpi_nozoomfordsf/fast/scrolling/scrollbars/mouse-scrolling-on-div-scrollbar.html [ Failure ]
crbug.com/953847 [ Mac ] virtual/compositor_threaded_scrollbar_scrolling_hidpi_nozoomfordsf/fast/scrolling/scrollbars/mouse-scrolling-on-root-scrollbar.html [ Failure ]
crbug.com/953847 [ Mac ] virtual/compositor_threaded_scrollbar_scrolling_hidpi_nozoomfordsf/fast/scrolling/scrollbars/scrollbar-button-gesture-target.html [ Failure ]
crbug.com/953847 [ Mac ] virtual/compositor_threaded_scrollbar_scrolling_hidpi_nozoomfordsf/fast/scrolling/scrollbars/scrollbar-occluded-by-div.html [ Failure ]
crbug.com/953847 [ Mac ] virtual/compositor_threaded_scrollbar_scrolling_hidpi_nozoomfordsf/fast/scrolling/scrollbars/mouse-autoscrolling-on-scrollbar.html [ Failure Timeout ]
crbug.com/953847 [ Mac ] virtual/scroll_customization/fast/scrolling/scrollbars/mouse-scrolling-on-div-scrollbar.html [ Failure ]
crbug.com/953847 [ Mac ] virtual/scroll_customization/fast/scrolling/scrollbars/mouse-scrolling-on-root-scrollbar.html [ Failure ]
crbug.com/953847 [ Mac ] virtual/scroll_customization/fast/scrolling/scrollbars/scroll-chaining-for-gesture-based-scrolling.html [ Failure ]
Expand Down
10 changes: 10 additions & 0 deletions third_party/blink/web_tests/VirtualTestSuites
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,16 @@
"--enable-prefer-compositing-to-lcd-text",
"--disable-smooth-scrolling"]
},
{
"prefix": "compositor_threaded_scrollbar_scrolling_hidpi_nozoomfordsf",
"base": "fast/scrolling/scrollbars",
"args": ["--enable-features=CompositorThreadedScrollbarScrolling",
"--enable-threaded-compositing",
"--enable-prefer-compositing-to-lcd-text",
"--disable-smooth-scrolling",
"--force-device-scale-factor=2",
"--enable-use-zoom-for-dsf=false"]
},
{
"prefix": "compositor_threaded_scrollbar_scrolling",
"base": "paint/invalidation/scroll/sticky",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This directory is dedicated for testing the "Compositor threaded
scrollbar scrolling" feature with DSF = 2 and use_zoom_for_dsf set
to false. This is done in order to simulate the current setup on Mac

0 comments on commit 64953c3

Please sign in to comment.