Commit b2d99679 authored by Xianzhu Wang's avatar Xianzhu Wang Committed by Commit Bot

Check scroll layer when updating composited scroll offset

ScrollingCoordinator::UpdateCompositedScrollOffset() assumes that the
scroll layer exists. We should not call the function when we haven't
created the scroll layer.

The check was not needed before crrev.com/c/1895081 because we created
the layers earilier (during CompositeUpdate). After the CL we created
the layers during PrePaint, but VisualViewport::DidSetScaleOrLocation()
can be called earlier.

Bug: 1020181
Change-Id: Ie9a341928ed13e02b4edbefdfbc513f1ecb22be0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1899598
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Reviewed-by: default avatarDavid Bokan <bokan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713141}
parent 602dd76b
......@@ -542,8 +542,10 @@ bool VisualViewport::DidSetScaleOrLocation(float scale,
// SVG runs with accelerated compositing disabled so no
// ScrollingCoordinator.
if (auto* coordinator = GetPage().GetScrollingCoordinator())
coordinator->UpdateCompositedScrollOffset(this);
if (auto* coordinator = GetPage().GetScrollingCoordinator()) {
if (scroll_layer_)
coordinator->UpdateCompositedScrollOffset(this);
}
EnqueueScrollEvent();
......@@ -595,6 +597,7 @@ void VisualViewport::CreateLayers() {
LayerForScrollingDidChange(coordinator->GetCompositorAnimationTimeline());
InitializeScrollbars();
coordinator->UpdateCompositedScrollOffset(this);
}
void VisualViewport::InitializeScrollbars() {
......
......@@ -2696,5 +2696,27 @@ TEST_F(VisualViewportSimTest, UsedColorSchemeFromRootElement) {
EXPECT_EQ(WebColorScheme::kDark, visual_viewport.UsedColorScheme());
}
TEST_P(VisualViewportTest, SetLocationBeforePrePaint) {
InitializeWithAndroidSettings();
WebView()->MainFrameWidget()->Resize(WebSize(100, 100));
RegisterMockedHttpURLLoad("content-width-1000.html");
NavigateTo(base_url_ + "content-width-1000.html");
// Simulate that the visual viewport is just created and FrameLoader is
// restoring the previously saved scale and scroll state.
VisualViewport& visual_viewport = GetFrame()->GetPage()->GetVisualViewport();
visual_viewport.DisposeImpl();
ASSERT_FALSE(visual_viewport.LayerForScrolling());
visual_viewport.SetScaleAndLocation(1.75, false, FloatPoint(12, 34));
EXPECT_EQ(FloatPoint(12, 34), visual_viewport.ScrollPosition());
UpdateAllLifecyclePhases();
EXPECT_EQ(FloatPoint(12, 34), visual_viewport.ScrollPosition());
// When we create the scrolling layer, we should update its scroll offset.
ASSERT_TRUE(visual_viewport.LayerForScrolling());
EXPECT_EQ(gfx::ScrollOffset(12, 34),
visual_viewport.LayerForScrolling()->CurrentScrollOffset());
}
} // namespace
} // namespace blink
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