⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 181443 in webkit


Ignore:
Timestamp:
Mar 12, 2015, 10:27:26 AM (11 years ago)
Author:
commit-queue@webkit.org
Message:

PDFs don't snapshot properly in iOS Safari
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.

Location:
trunk/Source/WebKit2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r181442 r181443  
     12015-03-12  Ian Henderson  <ian@ianhenderson.org>
     2
     3        PDFs don't snapshot properly in iOS Safari
     4        https://bugs.webkit.org/show_bug.cgi?id=142623
     5
     6        Reviewed by Tim Horton.
     7
     8        * UIProcess/API/Cocoa/WKWebView.mm:
     9        (-[WKWebView _snapshotRect:intoImageOfWidth:completionHandler:]):
     10        If we have a _customContentView, use UIView snapshotting instead of
     11        trying to snapshot the web page.
     12
    1132015-03-12  Eric Carlson  <eric.carlson@apple.com>
    214
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm

    r181317 r181443  
    24472447- (void)_snapshotRect:(CGRect)rectInViewCoordinates intoImageOfWidth:(CGFloat)imageWidth completionHandler:(void(^)(CGImageRef))completionHandler
    24482448{
    2449     CGRect snapshotRectInContentCoordinates = [self convertRect:rectInViewCoordinates toView:_contentView.get()];
    2450     CGFloat imageHeight = imageWidth / snapshotRectInContentCoordinates.size.width * snapshotRectInContentCoordinates.size.height;
     2449    CGRect snapshotRectInContentCoordinates = [self convertRect:rectInViewCoordinates toView:self._currentContentView];
     2450    CGFloat imageScale = imageWidth / snapshotRectInContentCoordinates.size.width;
     2451    CGFloat imageHeight = imageScale * snapshotRectInContentCoordinates.size.height;
    24512452    CGSize imageSize = CGSizeMake(imageWidth, imageHeight);
     2453
     2454    if (_customContentView) {
     2455        UIGraphicsBeginImageContextWithOptions(imageSize, YES, 1);
     2456
     2457        UIView *customContentView = _customContentView.get();
     2458        [customContentView.backgroundColor set];
     2459        UIRectFill(CGRectMake(0, 0, imageWidth, imageHeight));
     2460
     2461        CGRect destinationRect = customContentView.bounds;
     2462        destinationRect.origin.x = -snapshotRectInContentCoordinates.origin.x * imageScale;
     2463        destinationRect.origin.y = -snapshotRectInContentCoordinates.origin.y * imageScale;
     2464        destinationRect.size.width *= imageScale;
     2465        destinationRect.size.height *= imageScale;
     2466        [customContentView drawViewHierarchyInRect:destinationRect afterScreenUpdates:NO];
     2467
     2468        completionHandler([UIGraphicsGetImageFromCurrentImageContext() CGImage]);
     2469
     2470        UIGraphicsEndImageContext();
     2471        return;
     2472    }
    24522473   
    24532474    void(^copiedCompletionHandler)(CGImageRef) = [completionHandler copy];
Note: See TracChangeset for help on using the changeset viewer.