PDFs don't snapshot properly in iOS Safari
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Mar 2015 17:27:26 +0000 (17:27 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Mar 2015 17:27:26 +0000 (17:27 +0000)
https://bugs.webkit.org/show_bug.cgi?id=142623

Patch by Ian Henderson <ian@ianhenderson.org> on 2015-03-12
Reviewed by Tim Horton.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _snapshotRect:intoImageOfWidth:completionHandler:]):
If we have a _customContentView, use UIView snapshotting instead of
trying to snapshot the web page.

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

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

index dc302cc..8bb1ca2 100644 (file)
@@ -1,3 +1,15 @@
+2015-03-12  Ian Henderson  <ian@ianhenderson.org>
+
+        PDFs don't snapshot properly in iOS Safari
+        https://bugs.webkit.org/show_bug.cgi?id=142623
+
+        Reviewed by Tim Horton.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _snapshotRect:intoImageOfWidth:completionHandler:]):
+        If we have a _customContentView, use UIView snapshotting instead of
+        trying to snapshot the web page.
+
 2015-03-12  Eric Carlson  <eric.carlson@apple.com>
 
         [Mac] Update AirPlay handling
index b3e30f4..8147654 100644 (file)
@@ -2446,9 +2446,30 @@ static inline WebKit::FindOptions toFindOptions(_WKFindOptions wkFindOptions)
 
 - (void)_snapshotRect:(CGRect)rectInViewCoordinates intoImageOfWidth:(CGFloat)imageWidth completionHandler:(void(^)(CGImageRef))completionHandler
 {
-    CGRect snapshotRectInContentCoordinates = [self convertRect:rectInViewCoordinates toView:_contentView.get()];
-    CGFloat imageHeight = imageWidth / snapshotRectInContentCoordinates.size.width * snapshotRectInContentCoordinates.size.height;
+    CGRect snapshotRectInContentCoordinates = [self convertRect:rectInViewCoordinates toView:self._currentContentView];
+    CGFloat imageScale = imageWidth / snapshotRectInContentCoordinates.size.width;
+    CGFloat imageHeight = imageScale * snapshotRectInContentCoordinates.size.height;
     CGSize imageSize = CGSizeMake(imageWidth, imageHeight);
+
+    if (_customContentView) {
+        UIGraphicsBeginImageContextWithOptions(imageSize, YES, 1);
+
+        UIView *customContentView = _customContentView.get();
+        [customContentView.backgroundColor set];
+        UIRectFill(CGRectMake(0, 0, imageWidth, imageHeight));
+
+        CGRect destinationRect = customContentView.bounds;
+        destinationRect.origin.x = -snapshotRectInContentCoordinates.origin.x * imageScale;
+        destinationRect.origin.y = -snapshotRectInContentCoordinates.origin.y * imageScale;
+        destinationRect.size.width *= imageScale;
+        destinationRect.size.height *= imageScale;
+        [customContentView drawViewHierarchyInRect:destinationRect afterScreenUpdates:NO];
+
+        completionHandler([UIGraphicsGetImageFromCurrentImageContext() CGImage]);
+
+        UIGraphicsEndImageContext();
+        return;
+    }
     
     void(^copiedCompletionHandler)(CGImageRef) = [completionHandler copy];
     _page->takeSnapshot(WebCore::enclosingIntRect(snapshotRectInContentCoordinates), WebCore::expandedIntSize(WebCore::FloatSize(imageSize)), WebKit::SnapshotOptionsExcludeDeviceScaleFactor, [=](const WebKit::ShareableBitmap::Handle& imageHandle, WebKit::CallbackBase::Error) {