Title: [213674] trunk/Source/WebKit2
Revision
213674
Author
[email protected]
Date
2017-03-09 14:37:13 -0800 (Thu, 09 Mar 2017)

Log Message

[iOS] Add SPI to print to a single tall PDF page
https://bugs.webkit.org/show_bug.cgi?id=169439
<rdar://problem/30120532>

Reviewed by Tim Horton.

* Shared/PrintInfo.cpp:
(WebKit::PrintInfo::encode): Encoded snapshotFirstPage.
(WebKit::PrintInfo::decode): Decoded snapshotFirstPage.
(WebKit::PrintInfo::PrintInfo): Deleted.
* Shared/PrintInfo.h: Initialized member variables in place instead of in a default ctor.
* UIProcess/_WKWebViewPrintFormatter.h: Declared BOOL property snapshotFirstPage.
* UIProcess/_WKWebViewPrintFormatter.mm:
(-[_WKWebViewPrintFormatter _setSnapshotPaperRect:]): Added to set a custom paper size.
(-[_WKWebViewPrintFormatter rectForPageAtIndex:]): Returned the custom paper rect if
snapshotFirstPage is true.
* UIProcess/_WKWebViewPrintFormatterInternal.h:
* UIProcess/ios/WKContentView.mm:
(-[WKContentView _wk_pageCountForPrintFormatter:]): Computed the custom paper size to be the
smaller of the document height and the maximum PDF page height.
* UIProcess/ios/WKPDFView.mm:
(-[WKPDFView _wk_pageCountForPrintFormatter:]): Changed to return a maximum page size of 1
if snapshotFirstPage is true.
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::computePagesForPrintingAndDrawToPDF): Ditto.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (213673 => 213674)


--- trunk/Source/WebKit2/ChangeLog	2017-03-09 22:34:52 UTC (rev 213673)
+++ trunk/Source/WebKit2/ChangeLog	2017-03-09 22:37:13 UTC (rev 213674)
@@ -1,3 +1,31 @@
+2017-03-09  Andy Estes  <[email protected]>
+
+        [iOS] Add SPI to print to a single tall PDF page
+        https://bugs.webkit.org/show_bug.cgi?id=169439
+        <rdar://problem/30120532>
+
+        Reviewed by Tim Horton.
+
+        * Shared/PrintInfo.cpp:
+        (WebKit::PrintInfo::encode): Encoded snapshotFirstPage.
+        (WebKit::PrintInfo::decode): Decoded snapshotFirstPage.
+        (WebKit::PrintInfo::PrintInfo): Deleted.
+        * Shared/PrintInfo.h: Initialized member variables in place instead of in a default ctor.
+        * UIProcess/_WKWebViewPrintFormatter.h: Declared BOOL property snapshotFirstPage.
+        * UIProcess/_WKWebViewPrintFormatter.mm:
+        (-[_WKWebViewPrintFormatter _setSnapshotPaperRect:]): Added to set a custom paper size.
+        (-[_WKWebViewPrintFormatter rectForPageAtIndex:]): Returned the custom paper rect if
+        snapshotFirstPage is true.
+        * UIProcess/_WKWebViewPrintFormatterInternal.h: 
+        * UIProcess/ios/WKContentView.mm:
+        (-[WKContentView _wk_pageCountForPrintFormatter:]): Computed the custom paper size to be the
+        smaller of the document height and the maximum PDF page height.
+        * UIProcess/ios/WKPDFView.mm:
+        (-[WKPDFView _wk_pageCountForPrintFormatter:]): Changed to return a maximum page size of 1
+        if snapshotFirstPage is true.
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::computePagesForPrintingAndDrawToPDF): Ditto.
+
 2017-03-09  Anders Carlsson  <[email protected]>
 
         Add delegate support to WebCore

Modified: trunk/Source/WebKit2/Shared/PrintInfo.cpp (213673 => 213674)


--- trunk/Source/WebKit2/Shared/PrintInfo.cpp	2017-03-09 22:34:52 UTC (rev 213673)
+++ trunk/Source/WebKit2/Shared/PrintInfo.cpp	2017-03-09 22:37:13 UTC (rev 213674)
@@ -35,13 +35,6 @@
 
 namespace WebKit {
 
-PrintInfo::PrintInfo()
-    : pageSetupScaleFactor(0)
-    , availablePaperWidth(0)
-    , availablePaperHeight(0)
-{
-}
-
 void PrintInfo::encode(IPC::Encoder& encoder) const
 {
     encoder << pageSetupScaleFactor;
@@ -53,6 +46,10 @@
     IPC::encode(encoder, pageSetup.get());
     encoder.encodeEnum(printMode);
 #endif
+
+#if PLATFORM(IOS)
+    encoder << snapshotFirstPage;
+#endif
 }
 
 bool PrintInfo::decode(IPC::Decoder& decoder, PrintInfo& info)
@@ -73,6 +70,11 @@
         return false;
 #endif
 
+#if PLATFORM(IOS)
+    if (!decoder.decode(info.snapshotFirstPage))
+        return false;
+#endif
+
     return true;
 }
 

Modified: trunk/Source/WebKit2/Shared/PrintInfo.h (213673 => 213674)


--- trunk/Source/WebKit2/Shared/PrintInfo.h	2017-03-09 22:34:52 UTC (rev 213673)
+++ trunk/Source/WebKit2/Shared/PrintInfo.h	2017-03-09 22:37:13 UTC (rev 213674)
@@ -23,8 +23,7 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef PrintInfo_h
-#define PrintInfo_h
+#pragma once
 
 #if USE(APPKIT)
 OBJC_CLASS NSPrintInfo;
@@ -45,7 +44,7 @@
 namespace WebKit {
 
 struct PrintInfo {
-    PrintInfo();
+    PrintInfo() = default;
 #if PLATFORM(GTK)
     enum PrintMode {
         PrintModeAsync,
@@ -57,9 +56,12 @@
     explicit PrintInfo(NSPrintInfo *);
 #endif
 
-    float pageSetupScaleFactor;
-    float availablePaperWidth;
-    float availablePaperHeight;
+    float pageSetupScaleFactor { 0 };
+    float availablePaperWidth { 0 };
+    float availablePaperHeight { 0 };
+#if PLATFORM(IOS)
+    bool snapshotFirstPage { false };
+#endif
 
 #if PLATFORM(GTK)
     GRefPtr<GtkPrintSettings> printSettings;
@@ -72,5 +74,3 @@
 };
 
 }
-
-#endif

Modified: trunk/Source/WebKit2/UIProcess/_WKWebViewPrintFormatter.h (213673 => 213674)


--- trunk/Source/WebKit2/UIProcess/_WKWebViewPrintFormatter.h	2017-03-09 22:34:52 UTC (rev 213673)
+++ trunk/Source/WebKit2/UIProcess/_WKWebViewPrintFormatter.h	2017-03-09 22:37:13 UTC (rev 213674)
@@ -34,6 +34,7 @@
 @interface _WKWebViewPrintFormatter : UIViewPrintFormatter
 
 @property (nonatomic, strong) _WKFrameHandle *frameToPrint;
+@property (nonatomic) BOOL snapshotFirstPage;
 
 @end
 

Modified: trunk/Source/WebKit2/UIProcess/_WKWebViewPrintFormatter.mm (213673 => 213674)


--- trunk/Source/WebKit2/UIProcess/_WKWebViewPrintFormatter.mm	2017-03-09 22:34:52 UTC (rev 213673)
+++ trunk/Source/WebKit2/UIProcess/_WKWebViewPrintFormatter.mm	2017-03-09 22:37:13 UTC (rev 213674)
@@ -32,6 +32,11 @@
 #import "_WKFrameHandle.h"
 #import <wtf/RetainPtr.h>
 
+@interface UIPrintPageRenderer ()
+@property (nonatomic) CGRect paperRect;
+@property (nonatomic) CGRect printableRect;
+@end
+
 @implementation _WKWebViewPrintFormatter {
     RetainPtr<_WKFrameHandle> _frameToPrint;
     RetainPtr<CGPDFDocumentRef> _printedDocument;
@@ -54,6 +59,13 @@
     return static_cast<WKWebView *>(view);
 }
 
+- (void)_setSnapshotPaperRect:(CGRect)paperRect
+{
+    UIPrintPageRenderer *printPageRenderer = self.printPageRenderer;
+    printPageRenderer.paperRect = paperRect;
+    printPageRenderer.printableRect = paperRect;
+}
+
 - (NSInteger)_recalcPageCount
 {
     _printedDocument = nullptr;
@@ -63,6 +75,8 @@
 
 - (CGRect)rectForPageAtIndex:(NSInteger)pageIndex
 {
+    if (self.snapshotFirstPage)
+        return self.printPageRenderer.paperRect;
     return [self _pageContentRect:pageIndex == self.startPage];
 }
 

Modified: trunk/Source/WebKit2/UIProcess/_WKWebViewPrintFormatterInternal.h (213673 => 213674)


--- trunk/Source/WebKit2/UIProcess/_WKWebViewPrintFormatterInternal.h	2017-03-09 22:34:52 UTC (rev 213673)
+++ trunk/Source/WebKit2/UIProcess/_WKWebViewPrintFormatterInternal.h	2017-03-09 22:37:13 UTC (rev 213674)
@@ -31,6 +31,10 @@
 - (CGRect)_pageContentRect:(BOOL)firstPage;
 @end
 
+@interface _WKWebViewPrintFormatter ()
+- (void)_setSnapshotPaperRect:(CGRect)paperRect;
+@end
+
 @protocol _WKWebViewPrintProvider <NSObject>
 - (NSUInteger)_wk_pageCountForPrintFormatter:(_WKWebViewPrintFormatter *)printFormatter;
 @property (nonatomic, readonly) CGPDFDocumentRef _wk_printedDocument;

Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentView.mm (213673 => 213674)


--- trunk/Source/WebKit2/UIProcess/ios/WKContentView.mm	2017-03-09 22:34:52 UTC (rev 213673)
+++ trunk/Source/WebKit2/UIProcess/ios/WKContentView.mm	2017-03-09 22:37:13 UTC (rev 213674)
@@ -694,6 +694,12 @@
 
     PrintInfo printInfo;
     printInfo.pageSetupScaleFactor = 1;
+    printInfo.snapshotFirstPage = printFormatter.snapshotFirstPage;
+    if (printInfo.snapshotFirstPage) {
+        static const CGFloat maximumPDFHeight = 200 * 72; // maximum PDF height for a single page is 200 inches
+        printingRect = (CGRect) { CGPointZero, { self.bounds.size.width, std::min(_webView.scrollView.contentSize.height, maximumPDFHeight) } };
+        [printFormatter _setSnapshotPaperRect:printingRect];
+    }
     printInfo.availablePaperWidth = CGRectGetWidth(printingRect);
     printInfo.availablePaperHeight = CGRectGetHeight(printingRect);
 

Modified: trunk/Source/WebKit2/UIProcess/ios/WKPDFView.mm (213673 => 213674)


--- trunk/Source/WebKit2/UIProcess/ios/WKPDFView.mm	2017-03-09 22:34:52 UTC (rev 213673)
+++ trunk/Source/WebKit2/UIProcess/ios/WKPDFView.mm	2017-03-09 22:37:13 UTC (rev 213674)
@@ -825,9 +825,14 @@
 - (NSUInteger)_wk_pageCountForPrintFormatter:(_WKWebViewPrintFormatter *)printFormatter
 {
     CGPDFDocumentRef document = _cgPDFDocument.get();
-    if (CGPDFDocumentAllowsPrinting(document))
-        return CGPDFDocumentGetNumberOfPages(document);
-    return 0;
+    if (!CGPDFDocumentAllowsPrinting(document))
+        return 0;
+
+    size_t numberOfPages = CGPDFDocumentGetNumberOfPages(document);
+    if (printFormatter.snapshotFirstPage)
+        return std::min<NSUInteger>(numberOfPages, 1);
+
+    return numberOfPages;
 }
 
 - (CGPDFDocumentRef)_wk_printedDocument

Modified: trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm (213673 => 213674)


--- trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm	2017-03-09 22:34:52 UTC (rev 213673)
+++ trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm	2017-03-09 22:37:13 UTC (rev 213674)
@@ -39,6 +39,7 @@
 #import "InteractionInformationAtPosition.h"
 #import "Logging.h"
 #import "PluginView.h"
+#import "PrintInfo.h"
 #import "RemoteLayerTreeDrawingArea.h"
 #import "UserData.h"
 #import "VisibleContentRectUpdateInfo.h"
@@ -3265,7 +3266,8 @@
     double totalScaleFactor;
     computePagesForPrintingImpl(frameID, printInfo, pageRects, totalScaleFactor);
 
-    std::size_t pageCount = pageRects.size();
+    ASSERT(pageRects.size() >= 1);
+    std::size_t pageCount = printInfo.snapshotFirstPage ? 1 : pageRects.size();
     ASSERT(pageCount <= std::numeric_limits<uint32_t>::max());
     reply->send(pageCount);
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to