Commit 24ec7cd7 authored by Kurt Horimoto's avatar Kurt Horimoto Committed by Commit Bot

[iOS] Ignore pixel alignments when updating the MainContentUIState.

UIScrollView does not send a |-didEndDecelerating| to its delegate after
pixel alignments, so the MainContentUIState should not be considered
decelerating if the target contentOffset is less than a pixel away from
the current value.

This will correctly update the MainContentUIState's |scrolling|
property to NO, allowing the FullscreenScrollEndAnimator to start.

Bug: 800757
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I4407bf34c4a6c5cb485bba01528c34cf9e86c156
Reviewed-on: https://chromium-review.googlesource.com/922888Reviewed-by: default avatarJustin Cohen <justincohen@chromium.org>
Commit-Queue: Kurt Horimoto <kkhorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#537382}
parent 48a3163e
...@@ -56,11 +56,11 @@ ...@@ -56,11 +56,11 @@
// Called when a drag event with |panGesture| begins. // Called when a drag event with |panGesture| begins.
- (void)scrollViewWillBeginDraggingWithGesture: - (void)scrollViewWillBeginDraggingWithGesture:
(nonnull UIPanGestureRecognizer*)panGesture; (nonnull UIPanGestureRecognizer*)panGesture;
// Called when a drag event with |panGesture| ends. |velocity| is the regidual // Called when a drag event with |panGesture| ends. |target| is the final
// velocity from the scroll event. // content offset resulting from the residual velocity of the drag event.
- (void)scrollViewDidEndDraggingWithGesture: - (void)scrollViewDidEndDraggingWithGesture:
(nonnull UIPanGestureRecognizer*)panGesture (nonnull UIPanGestureRecognizer*)panGesture
residualVelocity:(CGPoint)velocity; targetContentOffset:(CGPoint)target;
// Called when the scroll view stops decelerating. // Called when the scroll view stops decelerating.
- (void)scrollViewDidEndDecelerating; - (void)scrollViewDidEndDecelerating;
// Called when the scroll view starts and ends zooming. // Called when the scroll view starts and ends zooming.
......
...@@ -113,15 +113,23 @@ ...@@ -113,15 +113,23 @@
} }
- (void)scrollViewDidEndDraggingWithGesture:(UIPanGestureRecognizer*)panGesture - (void)scrollViewDidEndDraggingWithGesture:(UIPanGestureRecognizer*)panGesture
residualVelocity:(CGPoint)velocity { targetContentOffset:(CGPoint)target {
// It's possible during the side-swipe gesture for a drag to end on the scroll // It's possible during the side-swipe gesture for a drag to end on the scroll
// view without a corresponding begin dragging call. Early return if there // view without a corresponding begin dragging call. Early return if there
// is no pan gesture from the begin call. // is no pan gesture from the begin call.
if (!self.panGesture) if (!self.panGesture)
return; return;
DCHECK_EQ(panGesture, self.panGesture); DCHECK_EQ(panGesture, self.panGesture);
if (!AreCGFloatsEqual(velocity.y, 0.0)) // UIScrollView does not sent a |-scrollViewDidEndDecelerating:| signal after
// pixel alignments, so the state should not be considered decelerating if the
// target content offset is less than a pixel away from the current value.
CGFloat singlePixel = 1.0 / [UIScreen mainScreen].scale;
CGFloat delta = std::abs(self.state.yContentOffset - target.y);
if (delta > singlePixel) {
self.state.decelerating = YES; self.state.decelerating = YES;
} else {
self.state.yContentOffset = target.y;
}
self.state.dragging = NO; self.state.dragging = NO;
self.panGesture = nil; self.panGesture = nil;
} }
......
...@@ -50,10 +50,27 @@ TEST_F(MainContentUIStateUpdaterTest, BroadcastScrollingAndDragging) { ...@@ -50,10 +50,27 @@ TEST_F(MainContentUIStateUpdaterTest, BroadcastScrollingAndDragging) {
EXPECT_TRUE(state().scrolling); EXPECT_TRUE(state().scrolling);
EXPECT_TRUE(state().dragging); EXPECT_TRUE(state().dragging);
[updater() scrollViewDidEndDraggingWithGesture:pan [updater() scrollViewDidEndDraggingWithGesture:pan
residualVelocity:CGPointMake(0, 5)]; targetContentOffset:CGPointMake(0, 5)];
EXPECT_TRUE(state().scrolling); EXPECT_TRUE(state().scrolling);
EXPECT_FALSE(state().dragging); EXPECT_FALSE(state().dragging);
[updater() scrollViewDidEndDecelerating]; [updater() scrollViewDidEndDecelerating];
EXPECT_FALSE(state().scrolling); EXPECT_FALSE(state().scrolling);
EXPECT_FALSE(state().dragging); EXPECT_FALSE(state().dragging);
} }
// Tests that pixel alignment don't count as residual deceleration.
TEST_F(MainContentUIStateUpdaterTest, IgnorePixelAligntment) {
UIPanGestureRecognizer* pan = [[UIPanGestureRecognizer alloc] init];
const CGFloat kSinglePixel = 1.0 / [UIScreen mainScreen].scale;
const CGPoint kUnalignedOffset = CGPointMake(0.0, kSinglePixel / 2.0);
ASSERT_FALSE(state().scrolling);
ASSERT_FALSE(state().dragging);
[updater() scrollViewWillBeginDraggingWithGesture:pan];
EXPECT_TRUE(state().scrolling);
EXPECT_TRUE(state().dragging);
[updater() scrollViewDidScrollToOffset:kUnalignedOffset];
[updater() scrollViewDidEndDraggingWithGesture:pan
targetContentOffset:CGPointZero];
EXPECT_FALSE(state().scrolling);
EXPECT_FALSE(state().dragging);
}
...@@ -149,7 +149,7 @@ void UpdateStateWithProxy(MainContentUIStateUpdater* updater, ...@@ -149,7 +149,7 @@ void UpdateStateWithProxy(MainContentUIStateUpdater* updater,
targetContentOffset:(inout CGPoint*)targetContentOffset { targetContentOffset:(inout CGPoint*)targetContentOffset {
[self.updater [self.updater
scrollViewDidEndDraggingWithGesture:self.proxy.panGestureRecognizer scrollViewDidEndDraggingWithGesture:self.proxy.panGestureRecognizer
residualVelocity:velocity]; targetContentOffset:*targetContentOffset];
} }
- (void)webViewScrollViewDidEndDecelerating: - (void)webViewScrollViewDidEndDecelerating:
......
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