Title: [169549] trunk/Source/WebKit2
Revision
169549
Author
benja...@webkit.org
Date
2014-06-02 15:18:54 -0700 (Mon, 02 Jun 2014)

Log Message

[iOS][WK2] Round the UIScrollView content size to device pixel
https://bugs.webkit.org/show_bug.cgi?id=133417
<rdar://problem/15922440>

Patch by Benjamin Poulain <bpoul...@apple.com> on 2014-06-02
Reviewed by Simon Fraser.

We should really have the scaled content size floored to device pixels, but that will be for another
time.
This patch ensure the content size as seen by the API is rounded to device pixels. The value is floored
to avoid showing partial pixels when the content is stable.

* UIProcess/API/Cocoa/WKWebView.mm:
(floorFloatToPixels):
(roundScrollViewCountentSize):
(-[WKWebView _setHasCustomContentView:loadedMIMEType:WTF::]):
(-[WKWebView _didCommitLayerTree:WebKit::]):
(-[WKWebView scrollView:contentSizeForZoomScale:withProposedSize:]):
(-[WKWebView _beginAnimatedResizeWithUpdates:]):
(-[WKWebView _endAnimatedResize]):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (169548 => 169549)


--- trunk/Source/WebKit2/ChangeLog	2014-06-02 22:13:43 UTC (rev 169548)
+++ trunk/Source/WebKit2/ChangeLog	2014-06-02 22:18:54 UTC (rev 169549)
@@ -1,3 +1,25 @@
+2014-06-02  Benjamin Poulain  <bpoul...@apple.com>
+
+        [iOS][WK2] Round the UIScrollView content size to device pixel
+        https://bugs.webkit.org/show_bug.cgi?id=133417
+        <rdar://problem/15922440>
+
+        Reviewed by Simon Fraser.
+
+        We should really have the scaled content size floored to device pixels, but that will be for another
+        time.
+        This patch ensure the content size as seen by the API is rounded to device pixels. The value is floored
+        to avoid showing partial pixels when the content is stable.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (floorFloatToPixels):
+        (roundScrollViewCountentSize):
+        (-[WKWebView _setHasCustomContentView:loadedMIMEType:WTF::]):
+        (-[WKWebView _didCommitLayerTree:WebKit::]):
+        (-[WKWebView scrollView:contentSizeForZoomScale:withProposedSize:]):
+        (-[WKWebView _beginAnimatedResizeWithUpdates:]):
+        (-[WKWebView _endAnimatedResize]):
+
 2014-06-02  Oliver Hunt  <oli...@apple.com>
 
         Move ifdef to the right place.

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (169548 => 169549)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2014-06-02 22:13:43 UTC (rev 169548)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2014-06-02 22:18:54 UTC (rev 169549)
@@ -452,6 +452,17 @@
     return [_contentView browsingContextController];
 }
 
+static inline CGFloat floorToDevicePixel(CGFloat input, float deviceScaleFactor)
+{
+    return CGFloor(input * deviceScaleFactor) / deviceScaleFactor;
+}
+
+static CGSize roundScrollViewContentSize(const WebKit::WebPageProxy& page, CGSize contentSize)
+{
+    float deviceScaleFactor = page.deviceScaleFactor();
+    return CGSizeMake(floorToDevicePixel(contentSize.width, deviceScaleFactor), floorToDevicePixel(contentSize.height, deviceScaleFactor));
+}
+
 - (void)_setHasCustomContentView:(BOOL)pageHasCustomContentView loadedMIMEType:(const WTF::String&)mimeType
 {
     if (pageHasCustomContentView) {
@@ -480,7 +491,7 @@
         _customContentFixedOverlayView = nullptr;
 
         [_scrollView addSubview:_contentView.get()];
-        [_scrollView setContentSize:[_contentView frame].size];
+        [_scrollView setContentSize:roundScrollViewContentSize(*_page, [_contentView frame].size)];
 
         [_customContentFixedOverlayView setFrame:self.bounds];
         [self addSubview:_customContentFixedOverlayView.get()];
@@ -599,7 +610,7 @@
         return;
     }
 
-    [_scrollView setContentSize:[_contentView frame].size];
+    [_scrollView setContentSize:roundScrollViewContentSize(*_page, [_contentView frame].size)];
     [_scrollView setMinimumZoomScale:layerTreeTransaction.minimumScaleFactor()];
     [_scrollView setMaximumZoomScale:layerTreeTransaction.maximumScaleFactor()];
     [_scrollView setZoomEnabled:layerTreeTransaction.allowsUserScaling()];
@@ -928,6 +939,11 @@
     return !_customContentView;
 }
 
+- (CGSize)scrollView:(UIScrollView*)scrollView contentSizeForZoomScale:(CGFloat)scale withProposedSize:(CGSize)proposedSize
+{
+    return roundScrollViewContentSize(*_page, proposedSize);
+}
+
 - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
 {
     ASSERT(_scrollView == scrollView);
@@ -1772,7 +1788,7 @@
         contentOffset.y = -_obscuredInsets.top;
 
     // FIXME: if we have content centered after double tap to zoom, we should also try to keep that rect in view.
-    [_scrollView setContentSize:futureContentSizeInSelfCoordinates];
+    [_scrollView setContentSize:roundScrollViewContentSize(*_page, futureContentSizeInSelfCoordinates)];
     [_scrollView setContentOffset:contentOffset];
 
     CGRect visibleRectInContentCoordinates = [self convertRect:newBounds toView:_contentView.get()];
@@ -1824,7 +1840,7 @@
         double horizontalScrollAdjustement = _resizeAnimationTransformAdjustments.m41 * animatingScaleTarget;
         double verticalScrollAdjustment = _resizeAnimationTransformAdjustments.m42 * animatingScaleTarget;
 
-        [_scrollView setContentSize:[_contentView frame].size];
+        [_scrollView setContentSize:roundScrollViewContentSize(*_page, [_contentView frame].size)];
         [_scrollView setContentOffset:CGPointMake(currentScrollOffset.x - horizontalScrollAdjustement, currentScrollOffset.y - verticalScrollAdjustment)];
 
         [_resizeAnimationView removeFromSuperview];
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to