Commit cfdbb756 authored by Chris Harrelson's avatar Chris Harrelson Committed by Commit Bot

Adjust scroll animation on clamping scroll, rather than just setting scroll.

This allows a clamping scroll to correctly fix scroll animations from
a previous scroll anchoring animation.

Bug: 1026985

Change-Id: Ic39dc466c596cc601040454c86d0a310bd241419
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1929439
Commit-Queue: Chris Harrelson <chrishtr@chromium.org>
Reviewed-by: default avatarDavid Bokan <bokan@chromium.org>
Reviewed-by: default avatarRobert Flack <flackr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#718843}
parent 8500b415
......@@ -4,6 +4,7 @@
#include "third_party/blink/renderer/core/layout/scroll_anchor.h"
#include "build/build_config.h"
#include "third_party/blink/renderer/core/dom/static_node_list.h"
#include "third_party/blink/renderer/core/frame/root_frame_viewport.h"
#include "third_party/blink/renderer/core/frame/visual_viewport.h"
......@@ -11,6 +12,7 @@
#include "third_party/blink/renderer/core/layout/layout_box.h"
#include "third_party/blink/renderer/core/page/print_context.h"
#include "third_party/blink/renderer/core/paint/paint_layer_scrollable_area.h"
#include "third_party/blink/renderer/core/scroll/scroll_animator_base.h"
#include "third_party/blink/renderer/core/testing/core_unit_test_helper.h"
#include "third_party/blink/renderer/platform/testing/histogram_tester.h"
#include "third_party/blink/renderer/platform/testing/runtime_enabled_features_test_helpers.h"
......@@ -927,4 +929,43 @@ TEST_P(ScrollAnchorTest, DeleteAnonymousBlockCrash) {
GetDocument().getElementById("deleteMe")->remove();
Update();
}
TEST_P(ScrollAnchorTest, ClampAdjustsAnchorAnimation) {
SetBodyInnerHTML(R"HTML(
<style>
body { margin: 0 }
.content {
height: 45vh;
background: lightblue;
}
#hidden {
height: 200px;
display: none;
}
</style>
<div class="content" id=one></div>
<div id="hidden"></div>
<div class="content" id=two></div>
<div class="content" id=three></div>
<div class="content" id=four></div>
)HTML");
LayoutViewport()->SetScrollOffset(ScrollOffset(0, 2000), kUserScroll);
Update();
GetDocument().getElementById("hidden")->setAttribute(html_names::kStyleAttr,
"display:block");
GetDocument().UpdateStyleAndLayout();
#if !defined(OS_MACOSX)
EXPECT_EQ(IntSize(0, 200), LayoutViewport()
->GetScrollAnimator()
.ImplOnlyAnimationAdjustmentForTesting());
#endif
GetDocument().getElementById("hidden")->setAttribute(html_names::kStyleAttr,
"");
GetDocument().UpdateStyleAndLayout();
// The clamping scroll after resizing layout overflow to be smaller
// should adjust the animation back to 0.
EXPECT_EQ(IntSize(0, 0), LayoutViewport()
->GetScrollAnimator()
.ImplOnlyAnimationAdjustmentForTesting());
}
}
......@@ -170,6 +170,7 @@ class CORE_EXPORT ScrollAnimatorCompositorCoordinator
UserScrollCallBackAtAnimationFinishOnMainThread);
FRIEND_TEST_ALL_PREFIXES(ScrollAnimatorTest,
UserScrollCallBackAtAnimationFinishOnCompositor);
FRIEND_TEST_ALL_PREFIXES(ScrollAnchorTest, ClampAdjustsAnchorAnimation);
std::unique_ptr<CompositorAnimation> compositor_animation_;
// The element id to which the compositor animation is attached when
......
......@@ -238,9 +238,12 @@ void ScrollableArea::SetScrollOffset(const ScrollOffset& offset,
switch (scroll_type) {
case kCompositorScroll:
case kClampingScroll:
ScrollOffsetChanged(clamped_offset, scroll_type);
break;
case kClampingScroll:
GetScrollAnimator().AdjustAnimationAndSetScrollOffset(clamped_offset,
scroll_type);
break;
case kAnchoringScroll:
GetScrollAnimator().AdjustAnimationAndSetScrollOffset(clamped_offset,
scroll_type);
......
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