[iOS] Rotating PDF in Safari scrolls to the wrong position
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 31 Mar 2015 20:50:12 +0000 (20:50 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 31 Mar 2015 20:50:12 +0000 (20:50 +0000)
https://bugs.webkit.org/show_bug.cgi?id=143259
<rdar://problem/19872693>

Reviewed by Dan Bernstein.

* UIProcess/ios/WKPDFView.mm:
(-[WKPDFView web_setMinimumSize:]):
Maintan the relative top/left within the rescaled document.

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/ios/WKPDFView.mm

index 9349319..e8125c1 100644 (file)
@@ -1,3 +1,15 @@
+2015-03-31  Timothy Horton  <timothy_horton@apple.com>
+
+        [iOS] Rotating PDF in Safari scrolls to the wrong position
+        https://bugs.webkit.org/show_bug.cgi?id=143259
+        <rdar://problem/19872693>
+
+        Reviewed by Dan Bernstein.
+
+        * UIProcess/ios/WKPDFView.mm:
+        (-[WKPDFView web_setMinimumSize:]):
+        Maintan the relative top/left within the rescaled document.
+
 2015-03-31  Chris Dumez  <cdumez@apple.com>
 
         [WK2][iOS] Extend ProcessThrottler use to the NetworkProcess
index 043492c..d45ba39 100644 (file)
@@ -173,8 +173,28 @@ typedef struct {
 {
     _minimumSize = size;
 
+    CGFloat oldDocumentLeftFraction = 0;
+    CGFloat oldDocumentTopFraction = 0;
+    CGSize contentSize = _scrollView.contentSize;
+    if (contentSize.width && contentSize.height) {
+        CGPoint contentOffset = _scrollView.contentOffset;
+        UIEdgeInsets contentInset = _scrollView.contentInset;
+        oldDocumentLeftFraction = (contentOffset.x + contentInset.left) / contentSize.width;
+        oldDocumentTopFraction = (contentOffset.y + contentInset.top) / contentSize.height;
+    }
+
     [self _computePageAndDocumentFrames];
-    [self _revalidateViews];
+
+    // FIXME: This dispatch_async is unnecessary except to work around rdar://problem/15035620.
+    // Once that is resolved, we should do the setContentOffset without the dispatch_async.
+    RetainPtr<WKPDFView> retainedSelf = self;
+    dispatch_async(dispatch_get_main_queue(), [retainedSelf, oldDocumentLeftFraction, oldDocumentTopFraction] {
+        CGSize contentSize = retainedSelf->_scrollView.contentSize;
+        UIEdgeInsets contentInset = retainedSelf->_scrollView.contentInset;
+        [retainedSelf->_scrollView setContentOffset:CGPointMake((oldDocumentLeftFraction * contentSize.width) - contentInset.left, (oldDocumentTopFraction * contentSize.height) - contentInset.top) animated:NO];
+
+        [retainedSelf _revalidateViews];
+    });
 }
 
 - (void)scrollViewDidScroll:(UIScrollView *)scrollView