Commit 4439f3a3 authored by Yi Gu's avatar Yi Gu Committed by Commit Bot

[scroll-snap] Clear scroll-snap target when updating cc scroll animation

Clear the animating scroll snap targets in LayerTreeHostImpl whenever
we update the animation target. This ensures that we attempt to snap to
an actual snap position once the animation finishes.

Bug: 1035953
Change-Id: Ieb2b8d04d6a6f795124770a599373a21c9d61989
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1976826
Commit-Queue: Yi Gu <yigu@chromium.org>
Reviewed-by: default avatarMajid Valipour <majidvp@chromium.org>
Cr-Commit-Position: refs/heads/master@{#742663}
parent 4f380d9a
...@@ -5916,6 +5916,11 @@ bool LayerTreeHostImpl::ScrollAnimationUpdateTarget( ...@@ -5916,6 +5916,11 @@ bool LayerTreeHostImpl::ScrollAnimationUpdateTarget(
// event, the LatencyInfo associated with the input event will not be // event, the LatencyInfo associated with the input event will not be
// added as a swap promise and we won't get any swap results. // added as a swap promise and we won't get any swap results.
NotifySwapPromiseMonitorsOfSetNeedsRedraw(); NotifySwapPromiseMonitorsOfSetNeedsRedraw();
// The animation is no longer targeting a snap position. By clearing the
// target, this will ensure that we attempt to resnap at the end of this
// animation.
scroll_animating_snap_target_ids_ = TargetSnapAreaElementIds();
} }
return animation_updated; return animation_updated;
......
...@@ -1916,6 +1916,68 @@ TEST_F(LayerTreeHostImplTest, ScrollSnapAfterAnimatedScroll) { ...@@ -1916,6 +1916,68 @@ TEST_F(LayerTreeHostImplTest, ScrollSnapAfterAnimatedScroll) {
GetSnapContainerData(overflow)->GetTargetSnapAreaElementIds()); GetSnapContainerData(overflow)->GetTargetSnapAreaElementIds());
} }
TEST_F(LayerTreeHostImplTest, SnapAnimationTargetUpdated) {
LayerImpl* overflow = CreateLayerForSnapping();
gfx::Point pointer_position(10, 10);
gfx::Vector2dF y_delta(0, 20);
EXPECT_EQ(
InputHandler::SCROLL_ON_IMPL_THREAD,
host_impl_
->ScrollBegin(
BeginState(pointer_position, y_delta, InputHandler::WHEEL).get(),
InputHandler::WHEEL)
.thread);
EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 0), CurrentScrollOffset(overflow));
host_impl_->ScrollUpdate(
UpdateState(pointer_position, y_delta, InputHandler::WHEEL).get());
EXPECT_FALSE(host_impl_->IsAnimatingForSnap());
viz::BeginFrameArgs begin_frame_args =
viz::CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 0, 1);
host_impl_->ScrollEnd(true);
base::TimeTicks start_time =
base::TimeTicks() + base::TimeDelta::FromMilliseconds(100);
BeginImplFrameAndAnimate(begin_frame_args, start_time);
// Finish smooth wheel scroll animation which starts a snap animation.
BeginImplFrameAndAnimate(begin_frame_args,
start_time + base::TimeDelta::FromMilliseconds(100));
EXPECT_TRUE(host_impl_->IsAnimatingForSnap());
EXPECT_EQ(TargetSnapAreaElementIds(),
GetSnapContainerData(overflow)->GetTargetSnapAreaElementIds());
gfx::ScrollOffset current_offset = CurrentScrollOffset(overflow);
EXPECT_GT(50, current_offset.y());
EXPECT_LT(20, current_offset.y());
// Update wheel scroll animation target. This should no longer be considered
// as animating a snap scroll, which should happen at the end of this
// animation.
host_impl_->ScrollUpdate(
AnimatedUpdateState(gfx::Point(10, 10), gfx::Vector2dF(0, -10)).get());
EXPECT_FALSE(host_impl_->IsAnimatingForSnap());
// Finish the smooth scroll animation for wheel.
BeginImplFrameAndAnimate(begin_frame_args,
start_time + base::TimeDelta::FromMilliseconds(150));
// At the end of the previous scroll animation, a new animation for the
// snapping should have started.
EXPECT_TRUE(host_impl_->IsAnimatingForSnap());
// Finish the snap animation.
BeginImplFrameAndAnimate(
begin_frame_args, start_time + base::TimeDelta::FromMilliseconds(1000));
EXPECT_FALSE(host_impl_->IsAnimatingForSnap());
// At the end of snap animation we should have updated the
// TargetSnapAreaElementIds.
EXPECT_EQ(TargetSnapAreaElementIds(ElementId(), ElementId(10)),
GetSnapContainerData(overflow)->GetTargetSnapAreaElementIds());
EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 50), CurrentScrollOffset(overflow));
}
TEST_F(LayerTreeHostImplTest, SnapAnimationCancelledByScroll) { TEST_F(LayerTreeHostImplTest, SnapAnimationCancelledByScroll) {
LayerImpl* overflow = CreateLayerForSnapping(); LayerImpl* overflow = CreateLayerForSnapping();
......
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