Commit 9e21c73c authored by David Bokan's avatar David Bokan Committed by Commit Bot

Fix overlay scrollbar at huge scroll offsets

The overlay scrollbar ThumbPosition method was losing precision at very
high scroll offsets. This would cause it to drift away from where we
actually show the thumb from the compositor so the hit testing would be
unreliable.

Looking at this method, there's no reason it should need to be any
different from the base class ScrollbarTheme::ThumbPosition which is
robust under high scroll offsets so the solution here is to simply
remove the override. Less code, less bugs.

Bug: 739668
Change-Id: Ib90152d989931cd0bcc0bddfb226d97d577ce575
Reviewed-on: https://chromium-review.googlesource.com/598734Reviewed-by: default avatarDave Tapuska <dtapuska@chromium.org>
Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Commit-Queue: David Bokan <bokan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491766}
parent 66506bb8
......@@ -203,6 +203,38 @@ TEST_P(ScrollbarAppearanceTest, ThemeEngineDefinesMinimumThumbLength) {
EXPECT_EQ(StubWebThemeEngine::kMinimumVerticalLength,
theme.ThumbLength(*scrollable_area->VerticalScrollbar()));
}
// Ensure thumb position is correctly calculated even at ridiculously large
// scales.
TEST_P(ScrollbarAppearanceTest, HugeScrollingThumbPosition) {
ScopedTestingPlatformSupport<ScrollbarTestingPlatformSupport> platform;
v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
WebView().Resize(WebSize(1000, 1000));
SimRequest request("https://example.com/test.html", "text/html");
LoadURL("https://example.com/test.html");
request.Complete(
"<style> body { margin: 0px; height: 10000000px; } </style>");
ScrollableArea* scrollable_area =
GetDocument().View()->LayoutViewportScrollableArea();
Compositor().BeginFrame();
scrollable_area->SetScrollOffset(ScrollOffset(0, 10000000),
kProgrammaticScroll);
int scroll_y = scrollable_area->GetScrollOffset().Height();
ASSERT_EQ(9999000, scroll_y);
Scrollbar* scrollbar = scrollable_area->VerticalScrollbar();
ASSERT_TRUE(scrollbar);
int maximumThumbPosition =
WebView().Size().height - StubWebThemeEngine::kMinimumVerticalLength;
EXPECT_EQ(maximumThumbPosition,
scrollbar->GetTheme().ThumbPosition(*scrollbar));
}
#endif
} // namespace
......
......@@ -103,17 +103,6 @@ double ScrollbarThemeOverlay::OverlayScrollbarFadeOutDurationSeconds() const {
return style.fade_out_duration_seconds;
}
int ScrollbarThemeOverlay::ThumbPosition(const ScrollbarThemeClient& scrollbar,
float scroll_position) {
if (!scrollbar.TotalSize())
return 0;
int track_len = TrackLength(scrollbar);
float proportion =
static_cast<float>(scroll_position) / scrollbar.TotalSize();
return round(proportion * track_len);
}
int ScrollbarThemeOverlay::ThumbLength(const ScrollbarThemeClient& scrollbar) {
int track_len = TrackLength(scrollbar);
......
......@@ -59,8 +59,6 @@ class PLATFORM_EXPORT ScrollbarThemeOverlay : public ScrollbarTheme {
double OverlayScrollbarFadeOutDelaySeconds() const override;
double OverlayScrollbarFadeOutDurationSeconds() const override;
int ThumbPosition(const ScrollbarThemeClient&,
float scroll_position) override;
int ThumbLength(const ScrollbarThemeClient&) override;
bool HasButtons(const ScrollbarThemeClient&) override { return false; }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment