[iOS WK2] position:fixed elements sometimes truncated on scroll view bouncing
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 16 Jun 2015 02:10:58 +0000 (02:10 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 16 Jun 2015 02:10:58 +0000 (02:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=146000
rdar://problem/19448439

Reviewed by Benjamin Poulain.

When in the middle of a rubber-band (UIScrollView bounce), we could send a bad
fixed position rect down to WebCore, causing 100% height elements to get laid out
at the wrong height, possible too short. This occurred when -_updateVisibleContentRects
said we were in a stable state, but the rubber-band offset caused WebPageProxy::computeCustomFixedPositionRect()
to compute a bad rect via constrainedUnobscuredRect.intersect(documentRect).

Fix by not claiming to be in a stable state during rubber-banding. Added _scrollViewIsRubberBanding
to compute that, taking care with floating point comparisons for 3x devices.

* UIProcess/API/Cocoa/WKWebView.mm:
(isGreaterInDevicePixels):
(-[WKWebView _scrollViewIsRubberBanding]):
(-[WKWebView _updateVisibleContentRects]):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@185576 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm

index 35f6993..47abc26 100644 (file)
@@ -1,3 +1,25 @@
+2015-06-15  Simon Fraser  <simon.fraser@apple.com>
+
+        [iOS WK2] position:fixed elements sometimes truncated on scroll view bouncing
+        https://bugs.webkit.org/show_bug.cgi?id=146000
+        rdar://problem/19448439
+
+        Reviewed by Benjamin Poulain.
+        
+        When in the middle of a rubber-band (UIScrollView bounce), we could send a bad 
+        fixed position rect down to WebCore, causing 100% height elements to get laid out
+        at the wrong height, possible too short. This occurred when -_updateVisibleContentRects
+        said we were in a stable state, but the rubber-band offset caused WebPageProxy::computeCustomFixedPositionRect()
+        to compute a bad rect via constrainedUnobscuredRect.intersect(documentRect).
+        
+        Fix by not claiming to be in a stable state during rubber-banding. Added _scrollViewIsRubberBanding
+        to compute that, taking care with floating point comparisons for 3x devices.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (isGreaterInDevicePixels):
+        (-[WKWebView _scrollViewIsRubberBanding]):
+        (-[WKWebView _updateVisibleContentRects]):
+
 2015-06-15  Ryuan Choi  <ryuan.choi@navercorp.com>
 
         Fix build break when ENABLE_SECCOMP_FILTERS is ON
index 2bb6840..af026be 100644 (file)
@@ -689,6 +689,12 @@ static inline CGFloat floorToDevicePixel(CGFloat input, float deviceScaleFactor)
     return CGFloor(input * deviceScaleFactor) / deviceScaleFactor;
 }
 
+static inline bool pointsEqualInDevicePixels(CGPoint a, CGPoint b, float deviceScaleFactor)
+{
+    return fabs(a.x * deviceScaleFactor - b.x * deviceScaleFactor) < std::numeric_limits<float>::epsilon()
+        && fabs(a.y * deviceScaleFactor - b.y * deviceScaleFactor) < std::numeric_limits<float>::epsilon();
+}
+
 static CGSize roundScrollViewContentSize(const WebKit::WebPageProxy& page, CGSize contentSize)
 {
     float deviceScaleFactor = page.deviceScaleFactor();
@@ -1513,6 +1519,16 @@ static WebCore::FloatPoint constrainContentOffset(WebCore::FloatPoint contentOff
     return [self convertRect:unobscuredRect toView:self._currentContentView];
 }
 
+// Ideally UIScrollView would expose this for us: <rdar://problem/21394567>.
+- (BOOL)_scrollViewIsRubberBanding
+{
+    float deviceScaleFactor = _page->deviceScaleFactor();
+
+    CGPoint contentOffset = [_scrollView contentOffset];
+    CGPoint boundedOffset = contentOffsetBoundedInValidRange(_scrollView.get(), contentOffset);
+    return !pointsEqualInDevicePixels(contentOffset, boundedOffset, deviceScaleFactor);
+}
+
 - (void)_updateVisibleContentRects
 {
     if (![self usesStandardContentView]) {
@@ -1539,7 +1555,7 @@ static WebCore::FloatPoint constrainContentOffset(WebCore::FloatPoint contentOff
 
     CGFloat scaleFactor = contentZoomScale(self);
 
-    BOOL isStableState = !(_isChangingObscuredInsetsInteractively || [_scrollView isDragging] || [_scrollView isDecelerating] || [_scrollView isZooming] || [_scrollView isZoomBouncing] || [_scrollView _isAnimatingZoom] || [_scrollView _isScrollingToTop]);
+    BOOL isStableState = !(_isChangingObscuredInsetsInteractively || [_scrollView isDragging] || [_scrollView isDecelerating] || [_scrollView isZooming] || [_scrollView isZoomBouncing] || [_scrollView _isAnimatingZoom] || [_scrollView _isScrollingToTop] || [self _scrollViewIsRubberBanding]);
 
     // FIXME: this can be made static after we stop supporting iOS 8.x.
     if (isStableState && [_scrollView respondsToSelector:@selector(_isInterruptingDeceleration)])