<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[213674] trunk/Source/WebKit2</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/213674">213674</a></dd>
<dt>Author</dt> <dd>aestes@apple.com</dd>
<dt>Date</dt> <dd>2017-03-09 14:37:13 -0800 (Thu, 09 Mar 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>[iOS] Add SPI to print to a single tall PDF page
https://bugs.webkit.org/show_bug.cgi?id=169439
&lt;rdar://problem/30120532&gt;

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.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2SharedPrintInfocpp">trunk/Source/WebKit2/Shared/PrintInfo.cpp</a></li>
<li><a href="#trunkSourceWebKit2SharedPrintInfoh">trunk/Source/WebKit2/Shared/PrintInfo.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcess_WKWebViewPrintFormatterh">trunk/Source/WebKit2/UIProcess/_WKWebViewPrintFormatter.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcess_WKWebViewPrintFormattermm">trunk/Source/WebKit2/UIProcess/_WKWebViewPrintFormatter.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcess_WKWebViewPrintFormatterInternalh">trunk/Source/WebKit2/UIProcess/_WKWebViewPrintFormatterInternal.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosWKContentViewmm">trunk/Source/WebKit2/UIProcess/ios/WKContentView.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosWKPDFViewmm">trunk/Source/WebKit2/UIProcess/ios/WKPDFView.mm</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageiosWebPageIOSmm">trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (213673 => 213674)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,3 +1,31 @@
</span><ins>+2017-03-09  Andy Estes  &lt;aestes@apple.com&gt;
+
+        [iOS] Add SPI to print to a single tall PDF page
+        https://bugs.webkit.org/show_bug.cgi?id=169439
+        &lt;rdar://problem/30120532&gt;
+
+        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.
+
</ins><span class="cx"> 2017-03-09  Anders Carlsson  &lt;andersca@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Add delegate support to WebCore
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedPrintInfocpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/PrintInfo.cpp (213673 => 213674)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -35,13 +35,6 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><del>-PrintInfo::PrintInfo()
-    : pageSetupScaleFactor(0)
-    , availablePaperWidth(0)
-    , availablePaperHeight(0)
-{
-}
-
</del><span class="cx"> void PrintInfo::encode(IPC::Encoder&amp; encoder) const
</span><span class="cx"> {
</span><span class="cx">     encoder &lt;&lt; pageSetupScaleFactor;
</span><span class="lines">@@ -53,6 +46,10 @@
</span><span class="cx">     IPC::encode(encoder, pageSetup.get());
</span><span class="cx">     encoder.encodeEnum(printMode);
</span><span class="cx"> #endif
</span><ins>+
+#if PLATFORM(IOS)
+    encoder &lt;&lt; snapshotFirstPage;
+#endif
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool PrintInfo::decode(IPC::Decoder&amp; decoder, PrintInfo&amp; info)
</span><span class="lines">@@ -73,6 +70,11 @@
</span><span class="cx">         return false;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+#if PLATFORM(IOS)
+    if (!decoder.decode(info.snapshotFirstPage))
+        return false;
+#endif
+
</ins><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedPrintInfoh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/PrintInfo.h (213673 => 213674)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -23,8 +23,7 @@
</span><span class="cx">  * THE POSSIBILITY OF SUCH DAMAGE.
</span><span class="cx">  */
</span><span class="cx"> 
</span><del>-#ifndef PrintInfo_h
-#define PrintInfo_h
</del><ins>+#pragma once
</ins><span class="cx"> 
</span><span class="cx"> #if USE(APPKIT)
</span><span class="cx"> OBJC_CLASS NSPrintInfo;
</span><span class="lines">@@ -45,7 +44,7 @@
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><span class="cx"> struct PrintInfo {
</span><del>-    PrintInfo();
</del><ins>+    PrintInfo() = default;
</ins><span class="cx"> #if PLATFORM(GTK)
</span><span class="cx">     enum PrintMode {
</span><span class="cx">         PrintModeAsync,
</span><span class="lines">@@ -57,9 +56,12 @@
</span><span class="cx">     explicit PrintInfo(NSPrintInfo *);
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-    float pageSetupScaleFactor;
-    float availablePaperWidth;
-    float availablePaperHeight;
</del><ins>+    float pageSetupScaleFactor { 0 };
+    float availablePaperWidth { 0 };
+    float availablePaperHeight { 0 };
+#if PLATFORM(IOS)
+    bool snapshotFirstPage { false };
+#endif
</ins><span class="cx"> 
</span><span class="cx"> #if PLATFORM(GTK)
</span><span class="cx">     GRefPtr&lt;GtkPrintSettings&gt; printSettings;
</span><span class="lines">@@ -72,5 +74,3 @@
</span><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> }
</span><del>-
-#endif
</del></span></pre></div>
<a id="trunkSourceWebKit2UIProcess_WKWebViewPrintFormatterh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/_WKWebViewPrintFormatter.h (213673 => 213674)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -34,6 +34,7 @@
</span><span class="cx"> @interface _WKWebViewPrintFormatter : UIViewPrintFormatter
</span><span class="cx"> 
</span><span class="cx"> @property (nonatomic, strong) _WKFrameHandle *frameToPrint;
</span><ins>+@property (nonatomic) BOOL snapshotFirstPage;
</ins><span class="cx"> 
</span><span class="cx"> @end
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcess_WKWebViewPrintFormattermm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/_WKWebViewPrintFormatter.mm (213673 => 213674)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -32,6 +32,11 @@
</span><span class="cx"> #import &quot;_WKFrameHandle.h&quot;
</span><span class="cx"> #import &lt;wtf/RetainPtr.h&gt;
</span><span class="cx"> 
</span><ins>+@interface UIPrintPageRenderer ()
+@property (nonatomic) CGRect paperRect;
+@property (nonatomic) CGRect printableRect;
+@end
+
</ins><span class="cx"> @implementation _WKWebViewPrintFormatter {
</span><span class="cx">     RetainPtr&lt;_WKFrameHandle&gt; _frameToPrint;
</span><span class="cx">     RetainPtr&lt;CGPDFDocumentRef&gt; _printedDocument;
</span><span class="lines">@@ -54,6 +59,13 @@
</span><span class="cx">     return static_cast&lt;WKWebView *&gt;(view);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (void)_setSnapshotPaperRect:(CGRect)paperRect
+{
+    UIPrintPageRenderer *printPageRenderer = self.printPageRenderer;
+    printPageRenderer.paperRect = paperRect;
+    printPageRenderer.printableRect = paperRect;
+}
+
</ins><span class="cx"> - (NSInteger)_recalcPageCount
</span><span class="cx"> {
</span><span class="cx">     _printedDocument = nullptr;
</span><span class="lines">@@ -63,6 +75,8 @@
</span><span class="cx"> 
</span><span class="cx"> - (CGRect)rectForPageAtIndex:(NSInteger)pageIndex
</span><span class="cx"> {
</span><ins>+    if (self.snapshotFirstPage)
+        return self.printPageRenderer.paperRect;
</ins><span class="cx">     return [self _pageContentRect:pageIndex == self.startPage];
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcess_WKWebViewPrintFormatterInternalh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/_WKWebViewPrintFormatterInternal.h (213673 => 213674)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -31,6 +31,10 @@
</span><span class="cx"> - (CGRect)_pageContentRect:(BOOL)firstPage;
</span><span class="cx"> @end
</span><span class="cx"> 
</span><ins>+@interface _WKWebViewPrintFormatter ()
+- (void)_setSnapshotPaperRect:(CGRect)paperRect;
+@end
+
</ins><span class="cx"> @protocol _WKWebViewPrintProvider &lt;NSObject&gt;
</span><span class="cx"> - (NSUInteger)_wk_pageCountForPrintFormatter:(_WKWebViewPrintFormatter *)printFormatter;
</span><span class="cx"> @property (nonatomic, readonly) CGPDFDocumentRef _wk_printedDocument;
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosWKContentViewmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentView.mm (213673 => 213674)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -694,6 +694,12 @@
</span><span class="cx"> 
</span><span class="cx">     PrintInfo printInfo;
</span><span class="cx">     printInfo.pageSetupScaleFactor = 1;
</span><ins>+    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];
+    }
</ins><span class="cx">     printInfo.availablePaperWidth = CGRectGetWidth(printingRect);
</span><span class="cx">     printInfo.availablePaperHeight = CGRectGetHeight(printingRect);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosWKPDFViewmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/WKPDFView.mm (213673 => 213674)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -825,9 +825,14 @@
</span><span class="cx"> - (NSUInteger)_wk_pageCountForPrintFormatter:(_WKWebViewPrintFormatter *)printFormatter
</span><span class="cx"> {
</span><span class="cx">     CGPDFDocumentRef document = _cgPDFDocument.get();
</span><del>-    if (CGPDFDocumentAllowsPrinting(document))
-        return CGPDFDocumentGetNumberOfPages(document);
-    return 0;
</del><ins>+    if (!CGPDFDocumentAllowsPrinting(document))
+        return 0;
+
+    size_t numberOfPages = CGPDFDocumentGetNumberOfPages(document);
+    if (printFormatter.snapshotFirstPage)
+        return std::min&lt;NSUInteger&gt;(numberOfPages, 1);
+
+    return numberOfPages;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (CGPDFDocumentRef)_wk_printedDocument
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageiosWebPageIOSmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm (213673 => 213674)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -39,6 +39,7 @@
</span><span class="cx"> #import &quot;InteractionInformationAtPosition.h&quot;
</span><span class="cx"> #import &quot;Logging.h&quot;
</span><span class="cx"> #import &quot;PluginView.h&quot;
</span><ins>+#import &quot;PrintInfo.h&quot;
</ins><span class="cx"> #import &quot;RemoteLayerTreeDrawingArea.h&quot;
</span><span class="cx"> #import &quot;UserData.h&quot;
</span><span class="cx"> #import &quot;VisibleContentRectUpdateInfo.h&quot;
</span><span class="lines">@@ -3265,7 +3266,8 @@
</span><span class="cx">     double totalScaleFactor;
</span><span class="cx">     computePagesForPrintingImpl(frameID, printInfo, pageRects, totalScaleFactor);
</span><span class="cx"> 
</span><del>-    std::size_t pageCount = pageRects.size();
</del><ins>+    ASSERT(pageRects.size() &gt;= 1);
+    std::size_t pageCount = printInfo.snapshotFirstPage ? 1 : pageRects.size();
</ins><span class="cx">     ASSERT(pageCount &lt;= std::numeric_limits&lt;uint32_t&gt;::max());
</span><span class="cx">     reply-&gt;send(pageCount);
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>