printing does not use minimum page zoom factor
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 17 Sep 2015 07:24:50 +0000 (07:24 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 17 Sep 2015 07:24:50 +0000 (07:24 +0000)
https://bugs.webkit.org/show_bug.cgi?id=108507

Reviewed by Darin Adler.

Source/WebCore:

* page/PrintContext.cpp:
(WebCore::PrintContext::beginAndComputePageRectsWithPageSize):
Helper function to share common code from numberOfPages() and
spoolAllPagesWithBoundaries().
(WebCore::PrintContext::numberOfPages): Use beginAndComputePageRectsWithPageSize().
(WebCore::PrintContext::spoolAllPagesWithBoundaries): Use
beginAndComputePageRectsWithPageSize() and don't flip the Y axis
for non Cocoa platforms.
* page/PrintContext.h:

Source/WebKit/mac:

Pass a the frame as a reference instead of using pointers.

* Misc/WebCoreStatistics.mm:
(-[WebFrame numberOfPagesWithPageWidth:pageHeight:]):
(-[WebFrame printToCGContext:pageWidth:pageHeight:]):

Source/WebKit2:

Add kWKSnapshotOptionsPrinting flag to indicate the snapshot
should be generated in printing mode.

* Shared/API/c/WKImage.h:
* Shared/API/c/WKSharedAPICast.h:
(WebKit::toSnapshotOptions):
* Shared/ImageOptions.h:
* WebProcess/InjectedBundle/InjectedBundle.cpp:
(WebKit::InjectedBundle::numberOfPages): Pass the frame as a
reference instead of a pointer.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::scaledSnapshotWithOptions): In case of printing,
calculate the bitmap height based on the number of pages.
(WebKit::WebPage::snapshotAtSize): In case of printing, use
PrintContext::spoolAllPagesWithBoundaries() and return.

Tools:

WebKitTestRunner always takes the snapshots from the UI process
(expect for IOS), so in the case of printing, the layout in the
web view is not the expected one. When printing, we need to take
the snapshot in the web process and ensure it's rendered with a
PrintContext.

* WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp:
(WTR::InjectedBundlePage::dump): When dumping pixels, pass
kWKSnapshotOptionsPrinting option to
WKBundlePageCreateSnapshotWithOptions() when printing. When not
printing, don't even create the snapshot, since it will be ignored
by the UI process that always creates its own from the WebView (expect for IOS platform)
* WebKitTestRunner/TestInvocation.cpp:
(WTR::TestInvocation::dumpResults): Use always the snapshot image
received from the web process if any when comparing pixel
results. Now we only receive a snapshot from the web process in
case of printing, or when platform is IOS. Otherwhise, generate
the snapshot from the WebView as usual.
* WebKitTestRunner/TestInvocation.h: Add SnapshotResultType enum
parameter to dumpPixelsAndCompareWithExpected, since the snapshot
is created by the caller now, but the CG implementation needs to
know if it's a Web or UI process snapshot.
* WebKitTestRunner/cairo/TestInvocationCairo.cpp:
(WTR::TestInvocation::dumpPixelsAndCompareWithExpected): Create a
cairo surface for the given image.
* WebKitTestRunner/cg/TestInvocationCG.cpp:
(WTR::TestInvocation::dumpPixelsAndCompareWithExpected): Create a
CGContext for the given image.

LayoutTests:

Unskip printing reftests that should pass now.

* platform/gtk/TestExpectations:
* platform/mac-wk2/TestExpectations:

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

21 files changed:
LayoutTests/ChangeLog
LayoutTests/platform/gtk/TestExpectations
LayoutTests/platform/mac-wk2/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/page/PrintContext.cpp
Source/WebCore/page/PrintContext.h
Source/WebCore/testing/Internals.cpp
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/Misc/WebCoreStatistics.mm
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/API/c/WKImage.h
Source/WebKit2/Shared/API/c/WKSharedAPICast.h
Source/WebKit2/Shared/ImageOptions.h
Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Tools/ChangeLog
Tools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp
Tools/WebKitTestRunner/TestInvocation.cpp
Tools/WebKitTestRunner/TestInvocation.h
Tools/WebKitTestRunner/cairo/TestInvocationCairo.cpp
Tools/WebKitTestRunner/cg/TestInvocationCG.cpp

index f887259..fbed258 100644 (file)
@@ -1,3 +1,15 @@
+2015-09-16  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        printing does not use minimum page zoom factor
+        https://bugs.webkit.org/show_bug.cgi?id=108507
+
+        Reviewed by Darin Adler.
+
+        Unskip printing reftests that should pass now.
+
+        * platform/gtk/TestExpectations:
+        * platform/mac-wk2/TestExpectations:
+
 2015-09-16  Ryosuke Niwa  <rniwa@webkit.org>
 
         Add failing expectation to css3/font-feature-settings-rendering-2.html on Mavericks.
index 5c6bf79..dc8de11 100644 (file)
@@ -2406,10 +2406,6 @@ webkit.org/b/143871 svg/W3C-SVG-1.1-SE/linking-uri-01-b.svg [ Failure ]
 
 webkit.org/b/143924 fast/text/hyphen-min-preferred-width.html [ Skip ]
 
-webkit.org/b/144494 printing/quirks-percentage-height-body.html [ ImageOnlyFailure ]
-webkit.org/b/144494 printing/quirks-percentage-height.html [ ImageOnlyFailure ]
-webkit.org/b/144494 printing/standards-percentage-heights.html [ ImageOnlyFailure ]
-
 webkit.org/b/144575 http/tests/loading/promote-img-preload-priority.html [ Failure ]
 
 webkit.org/b/144673 fast/forms/button-line-height.html [ ImageOnlyFailure ]
index 9ff054e..4a776f8 100644 (file)
@@ -196,10 +196,6 @@ webkit.org/b/105954 http/tests/navigation/reload-subframe-object.html [ Failure
 
 webkit.org/b/105960 plugins/navigator-plugins.html [ Failure ]
 
-webkit.org/b/108507 printing/quirks-percentage-height-body.html [ Skip ]
-webkit.org/b/108507 printing/quirks-percentage-height.html [ Skip ]
-webkit.org/b/108507 printing/standards-percentage-heights.html [ Skip ]
-
 webkit.org/b/104954 http/tests/canvas/canvas-slow-font-loading.html [ ImageOnlyFailure ]
 
 # Flaky everywhere.
index eb8fac6..953e8a9 100644 (file)
@@ -1,3 +1,20 @@
+2015-09-16  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        printing does not use minimum page zoom factor
+        https://bugs.webkit.org/show_bug.cgi?id=108507
+
+        Reviewed by Darin Adler.
+
+        * page/PrintContext.cpp:
+        (WebCore::PrintContext::beginAndComputePageRectsWithPageSize):
+        Helper function to share common code from numberOfPages() and
+        spoolAllPagesWithBoundaries().
+        (WebCore::PrintContext::numberOfPages): Use beginAndComputePageRectsWithPageSize().
+        (WebCore::PrintContext::spoolAllPagesWithBoundaries): Use
+        beginAndComputePageRectsWithPageSize() and don't flip the Y axis
+        for non Cocoa platforms.
+        * page/PrintContext.h:
+
 2015-09-16  Ryosuke Niwa  <rniwa@webkit.org>
 
         removeShadow shouldn't call ChildNodeRemovalNotifier with the shadow host as the removal point
index f62dfa6..2637511 100644 (file)
@@ -301,32 +301,36 @@ String PrintContext::pageSizeAndMarginsInPixels(Frame* frame, int pageNumber, in
            String::number(marginTop) + ' ' + String::number(marginRight) + ' ' + String::number(marginBottom) + ' ' + String::number(marginLeft);
 }
 
-int PrintContext::numberOfPages(Frame* frame, const FloatSize& pageSizeInPixels)
+bool PrintContext::beginAndComputePageRectsWithPageSize(Frame& frame, const FloatSize& pageSizeInPixels)
 {
-    frame->document()->updateLayout();
+    if (!frame.document() || !frame.view() || !frame.document()->renderView())
+        return false;
 
-    FloatRect pageRect(FloatPoint(0, 0), pageSizeInPixels);
-    PrintContext printContext(frame);
-    printContext.begin(pageRect.width(), pageRect.height());
+    frame.document()->updateLayout();
+
+    begin(pageSizeInPixels.width(), pageSizeInPixels.height());
     // Account for shrink-to-fit.
     FloatSize scaledPageSize = pageSizeInPixels;
-    scaledPageSize.scale(frame->view()->contentsSize().width() / pageRect.width());
-    printContext.computePageRectsWithPageSize(scaledPageSize, false);
-    return printContext.pageCount();
+    scaledPageSize.scale(frame.view()->contentsSize().width() / pageSizeInPixels.width());
+    computePageRectsWithPageSize(scaledPageSize, false);
+
+    return true;
 }
 
-void PrintContext::spoolAllPagesWithBoundaries(Frame* frame, GraphicsContext& graphicsContext, const FloatSize& pageSizeInPixels)
+int PrintContext::numberOfPages(Frame& frame, const FloatSize& pageSizeInPixels)
 {
-    if (!frame->document() || !frame->view() || !frame->document()->renderView())
-        return;
-
-    frame->document()->updateLayout();
+    PrintContext printContext(&frame);
+    if (!printContext.beginAndComputePageRectsWithPageSize(frame, pageSizeInPixels))
+        return -1;
 
-    PrintContext printContext(frame);
-    printContext.begin(pageSizeInPixels.width(), pageSizeInPixels.height());
+    return printContext.pageCount();
+}
 
-    float pageHeight;
-    printContext.computePageRects(FloatRect(FloatPoint(0, 0), pageSizeInPixels), 0, 0, 1, pageHeight);
+void PrintContext::spoolAllPagesWithBoundaries(Frame& frame, GraphicsContext& graphicsContext, const FloatSize& pageSizeInPixels)
+{
+    PrintContext printContext(&frame);
+    if (!printContext.beginAndComputePageRectsWithPageSize(frame, pageSizeInPixels))
+        return;
 
     const float pageWidth = pageSizeInPixels.width();
     const Vector<IntRect>& pageRects = printContext.pageRects();
@@ -337,18 +341,24 @@ void PrintContext::spoolAllPagesWithBoundaries(Frame* frame, GraphicsContext& gr
     graphicsContext.fillRect(FloatRect(0, 0, pageWidth, totalHeight));
 
     graphicsContext.save();
+#if PLATFORM(COCOA)
     graphicsContext.translate(0, totalHeight);
     graphicsContext.scale(FloatSize(1, -1));
+#endif
 
     int currentHeight = 0;
     for (size_t pageIndex = 0; pageIndex < pageRects.size(); pageIndex++) {
         // Draw a line for a page boundary if this isn't the first page.
         if (pageIndex > 0) {
+#if PLATFORM(COCOA)
+            int boundaryLineY = currentHeight;
+#else
+            int boundaryLineY = currentHeight - 1;
+#endif
             graphicsContext.save();
             graphicsContext.setStrokeColor(Color(0, 0, 255), ColorSpaceDeviceRGB);
             graphicsContext.setFillColor(Color(0, 0, 255), ColorSpaceDeviceRGB);
-            graphicsContext.drawLine(IntPoint(0, currentHeight),
-                                     IntPoint(pageWidth, currentHeight));
+            graphicsContext.drawLine(IntPoint(0, boundaryLineY), IntPoint(pageWidth, boundaryLineY));
             graphicsContext.restore();
         }
 
index 7c51ca4..d3d3eae 100644 (file)
@@ -73,11 +73,11 @@ public:
     WEBCORE_EXPORT static String pageProperty(Frame*, const char* propertyName, int pageNumber);
     WEBCORE_EXPORT static bool isPageBoxVisible(Frame*, int pageNumber);
     WEBCORE_EXPORT static String pageSizeAndMarginsInPixels(Frame*, int pageNumber, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft);
-    WEBCORE_EXPORT static int numberOfPages(Frame*, const FloatSize& pageSizeInPixels);
+    WEBCORE_EXPORT static int numberOfPages(Frame&, const FloatSize& pageSizeInPixels);
     // Draw all pages into a graphics context with lines which mean page boundaries.
     // The height of the graphics context should be
     // (pageSizeInPixels.height() + 1) * number-of-pages - 1
-    WEBCORE_EXPORT static void spoolAllPagesWithBoundaries(Frame*, GraphicsContext&, const FloatSize& pageSizeInPixels);
+    WEBCORE_EXPORT static void spoolAllPagesWithBoundaries(Frame&, GraphicsContext&, const FloatSize& pageSizeInPixels);
 
 protected:
     Frame* m_frame;
@@ -85,6 +85,7 @@ protected:
 
 private:
     void computePageRectsWithPageSizeInternal(const FloatSize& pageSizeInPixels, bool allowHorizontalTiling);
+    bool beginAndComputePageRectsWithPageSize(Frame&, const FloatSize& pageSizeInPixels);
 
     // Used to prevent misuses of begin() and end() (e.g., call end without begin).
     bool m_isPrinting;
index 7378479..d93628b 100644 (file)
@@ -1991,7 +1991,7 @@ int Internals::numberOfPages(float pageWidth, float pageHeight)
     if (!frame())
         return -1;
 
-    return PrintContext::numberOfPages(frame(), FloatSize(pageWidth, pageHeight));
+    return PrintContext::numberOfPages(*frame(), FloatSize(pageWidth, pageHeight));
 }
 
 String Internals::pageProperty(String propertyName, int pageNumber, ExceptionCode& ec) const
index 651774c..0502345 100644 (file)
@@ -1,3 +1,16 @@
+2015-09-16  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        printing does not use minimum page zoom factor
+        https://bugs.webkit.org/show_bug.cgi?id=108507
+
+        Reviewed by Darin Adler.
+
+        Pass a the frame as a reference instead of using pointers.
+
+        * Misc/WebCoreStatistics.mm:
+        (-[WebFrame numberOfPagesWithPageWidth:pageHeight:]):
+        (-[WebFrame printToCGContext:pageWidth:pageHeight:]):
+
 2015-09-16  Brady Eidson  <beidson@apple.com>
 
         Have window.indexedDB.deleteDatabase return an IDBOpenDBRequest.
index 78210ac..c0cafed 100644 (file)
@@ -276,7 +276,11 @@ using namespace WebCore;
 
 - (int)numberOfPagesWithPageWidth:(float)pageWidthInPixels pageHeight:(float)pageHeightInPixels
 {
-    return PrintContext::numberOfPages(_private->coreFrame, FloatSize(pageWidthInPixels, pageHeightInPixels));
+    Frame* coreFrame = _private->coreFrame;
+    if (!coreFrame)
+        return -1;
+
+    return PrintContext::numberOfPages(*coreFrame, FloatSize(pageWidthInPixels, pageHeightInPixels));
 }
 
 - (void)printToCGContext:(CGContextRef)cgContext pageWidth:(float)pageWidthInPixels pageHeight:(float)pageHeightInPixels
@@ -286,7 +290,7 @@ using namespace WebCore;
         return;
 
     GraphicsContext graphicsContext(cgContext);
-    PrintContext::spoolAllPagesWithBoundaries(coreFrame, graphicsContext, FloatSize(pageWidthInPixels, pageHeightInPixels));
+    PrintContext::spoolAllPagesWithBoundaries(*coreFrame, graphicsContext, FloatSize(pageWidthInPixels, pageHeightInPixels));
 }
 
 @end
index 044dfbe..d91a440 100644 (file)
@@ -1,3 +1,26 @@
+2015-09-16  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        printing does not use minimum page zoom factor
+        https://bugs.webkit.org/show_bug.cgi?id=108507
+
+        Reviewed by Darin Adler.
+
+        Add kWKSnapshotOptionsPrinting flag to indicate the snapshot
+        should be generated in printing mode.
+
+        * Shared/API/c/WKImage.h:
+        * Shared/API/c/WKSharedAPICast.h:
+        (WebKit::toSnapshotOptions):
+        * Shared/ImageOptions.h:
+        * WebProcess/InjectedBundle/InjectedBundle.cpp:
+        (WebKit::InjectedBundle::numberOfPages): Pass the frame as a
+        reference instead of a pointer.
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::scaledSnapshotWithOptions): In case of printing,
+        calculate the bitmap height based on the number of pages.
+        (WebKit::WebPage::snapshotAtSize): In case of printing, use
+        PrintContext::spoolAllPagesWithBoundaries() and return.
+
 2015-09-16  Joseph Pecoraro  <pecoraro@apple.com>
 
         Web Inspector: Fix common typo "supress" => "suppress"
index 8dd56cc..27a3454 100644 (file)
@@ -45,6 +45,7 @@ enum {
     kWKSnapshotOptionsPaintSelectionRectangle = 1 << 3,
     kWKSnapshotOptionsForceBlackText = 1 << 4,
     kWKSnapshotOptionsForceWhiteText = 1 << 5,
+    kWKSnapshotOptionsPrinting = 1 << 6,
 };
 typedef uint32_t WKSnapshotOptions;
 
index 03546c6..4f17e37 100644 (file)
@@ -951,6 +951,8 @@ inline SnapshotOptions toSnapshotOptions(WKSnapshotOptions wkSnapshotOptions)
         snapshotOptions |= SnapshotOptionsForceBlackText;
     if (wkSnapshotOptions & kWKSnapshotOptionsForceWhiteText)
         snapshotOptions |= SnapshotOptionsForceWhiteText;
+    if (wkSnapshotOptions & kWKSnapshotOptionsPrinting)
+        snapshotOptions |= SnapshotOptionsPrinting;
 
     return snapshotOptions;
 }
index 99ba79f..312ca6d 100644 (file)
@@ -40,6 +40,7 @@ enum {
     SnapshotOptionsExcludeDeviceScaleFactor = 1 << 5,
     SnapshotOptionsForceBlackText = 1 << 6,
     SnapshotOptionsForceWhiteText = 1 << 7,
+    SnapshotOptionsPrinting = 1 << 8,
 };
 typedef uint32_t SnapshotOptions;
 
index 0393658..244401b 100644 (file)
@@ -407,7 +407,7 @@ int InjectedBundle::numberOfPages(WebFrame* frame, double pageWidthInPixels, dou
     if (!pageHeightInPixels)
         pageHeightInPixels = coreFrame->view()->height();
 
-    return PrintContext::numberOfPages(coreFrame, FloatSize(pageWidthInPixels, pageHeightInPixels));
+    return PrintContext::numberOfPages(*coreFrame, FloatSize(pageWidthInPixels, pageHeightInPixels));
 }
 
 int InjectedBundle::pageNumberForElementById(WebFrame* frame, const String& id, double pageWidthInPixels, double pageHeightInPixels)
index 0be51eb..05ca812 100644 (file)
@@ -1711,10 +1711,18 @@ PassRefPtr<WebImage> WebPage::scaledSnapshotWithOptions(const IntRect& rect, dou
 {
     IntRect snapshotRect = rect;
     IntSize bitmapSize = snapshotRect.size();
-    double scaleFactor = additionalScaleFactor;
-    if (!(options & SnapshotOptionsExcludeDeviceScaleFactor))
-        scaleFactor *= corePage()->deviceScaleFactor();
-    bitmapSize.scale(scaleFactor);
+    if (options & SnapshotOptionsPrinting) {
+        ASSERT(additionalScaleFactor == 1);
+        Frame* coreFrame = m_mainFrame->coreFrame();
+        if (!coreFrame)
+            return nullptr;
+        bitmapSize.setHeight(PrintContext::numberOfPages(*coreFrame, bitmapSize) * (bitmapSize.height() + 1) - 1);
+    } else {
+        double scaleFactor = additionalScaleFactor;
+        if (!(options & SnapshotOptionsExcludeDeviceScaleFactor))
+            scaleFactor *= corePage()->deviceScaleFactor();
+        bitmapSize.scale(scaleFactor);
+    }
 
     return snapshotAtSize(rect, bitmapSize, options);
 }
@@ -1740,6 +1748,11 @@ PassRefPtr<WebImage> WebPage::snapshotAtSize(const IntRect& rect, const IntSize&
 
     auto graphicsContext = snapshot->bitmap()->createGraphicsContext();
 
+    if (options & SnapshotOptionsPrinting) {
+        PrintContext::spoolAllPagesWithBoundaries(*coreFrame, *graphicsContext, snapshotRect.size());
+        return snapshot.release();
+    }
+
     Color documentBackgroundColor = frameView->documentBackgroundColor();
     Color backgroundColor = (coreFrame->settings().backgroundShouldExtendBeyondPage() && documentBackgroundColor.isValid()) ? documentBackgroundColor : frameView->baseBackgroundColor();
     graphicsContext->fillRect(IntRect(IntPoint(), bitmapSize), backgroundColor, ColorSpaceDeviceRGB);
index 1383efc..f7ed167 100644 (file)
@@ -1,3 +1,39 @@
+2015-09-16  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        printing does not use minimum page zoom factor
+        https://bugs.webkit.org/show_bug.cgi?id=108507
+
+        Reviewed by Darin Adler.
+
+        WebKitTestRunner always takes the snapshots from the UI process
+        (expect for IOS), so in the case of printing, the layout in the
+        web view is not the expected one. When printing, we need to take
+        the snapshot in the web process and ensure it's rendered with a
+        PrintContext.
+
+        * WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp:
+        (WTR::InjectedBundlePage::dump): When dumping pixels, pass
+        kWKSnapshotOptionsPrinting option to
+        WKBundlePageCreateSnapshotWithOptions() when printing. When not
+        printing, don't even create the snapshot, since it will be ignored
+        by the UI process that always creates its own from the WebView (expect for IOS platform)
+        * WebKitTestRunner/TestInvocation.cpp:
+        (WTR::TestInvocation::dumpResults): Use always the snapshot image
+        received from the web process if any when comparing pixel
+        results. Now we only receive a snapshot from the web process in
+        case of printing, or when platform is IOS. Otherwhise, generate
+        the snapshot from the WebView as usual.
+        * WebKitTestRunner/TestInvocation.h: Add SnapshotResultType enum
+        parameter to dumpPixelsAndCompareWithExpected, since the snapshot
+        is created by the caller now, but the CG implementation needs to
+        know if it's a Web or UI process snapshot.
+        * WebKitTestRunner/cairo/TestInvocationCairo.cpp:
+        (WTR::TestInvocation::dumpPixelsAndCompareWithExpected): Create a
+        cairo surface for the given image.
+        * WebKitTestRunner/cg/TestInvocationCG.cpp:
+        (WTR::TestInvocation::dumpPixelsAndCompareWithExpected): Create a
+        CGContext for the given image.
+
 2015-09-16  Myles C. Maxfield  <mmaxfield@apple.com>
 
         Create a font which can be used for testing font features
index cb22d6d..aff2a9d 100644 (file)
@@ -889,12 +889,26 @@ void InjectedBundlePage::dump()
         injectedBundle.dumpBackForwardListsForAllPages(stringBuilder);
 
     if (injectedBundle.shouldDumpPixels() && injectedBundle.testRunner()->shouldDumpPixels()) {
-        WKSnapshotOptions options = kWKSnapshotOptionsShareable | kWKSnapshotOptionsInViewCoordinates;
-        if (injectedBundle.testRunner()->shouldDumpSelectionRect())
-            options |= kWKSnapshotOptionsPaintSelectionRectangle;
+        WKSnapshotOptions options = kWKSnapshotOptionsShareable;
+        WKRect snapshotRect = WKBundleFrameGetVisibleContentBounds(WKBundlePageGetMainFrame(m_page));
+        bool shouldCreateSnapshot = false;
+        if (injectedBundle.testRunner()->isPrinting()) {
+            shouldCreateSnapshot = true;
+            options |= kWKSnapshotOptionsPrinting;
+        } else {
+#if PLATFORM(IOS)
+            // Only IOS needs to generate the snapshot in the web process, all other ports generate
+            // a snapshot from the web view contents in the UI process.
+            shouldCreateSnapshot = true;
+            options |= kWKSnapshotOptionsInViewCoordinates;
+            if (injectedBundle.testRunner()->shouldDumpSelectionRect())
+                options |= kWKSnapshotOptionsPaintSelectionRectangle;
+#endif
+        }
 
-        injectedBundle.setPixelResult(adoptWK(WKBundlePageCreateSnapshotWithOptions(m_page, WKBundleFrameGetVisibleContentBounds(WKBundlePageGetMainFrame(m_page)), options)).get());
-        if (WKBundlePageIsTrackingRepaints(m_page))
+        if (shouldCreateSnapshot)
+            injectedBundle.setPixelResult(adoptWK(WKBundlePageCreateSnapshotWithOptions(m_page, snapshotRect, options)).get());
+        if (WKBundlePageIsTrackingRepaints(m_page) && !injectedBundle.testRunner()->isPrinting())
             injectedBundle.setRepaintRects(adoptWK(WKBundlePageCopyTrackedRepaintRects(m_page)).get());
     }
 
index c4dee36..6f18066 100644 (file)
@@ -267,16 +267,22 @@ void TestInvocation::dumpResults()
     else
         dumpAudio(m_audioResult.get());
 
-    if (m_dumpPixels && m_pixelResult) {
-        m_gotRepaint = false;
-        WKPageForceRepaint(TestController::singleton().mainWebView()->page(), this, TestInvocation::forceRepaintDoneCallback);
-        TestController::singleton().runUntil(m_gotRepaint, TestController::shortTimeout);
-        if (!m_gotRepaint) {
-            m_errorMessage = "Timed out waiting for pre-pixel dump repaint\n";
-            m_webProcessIsUnresponsive = true;
-            return;
+    if (m_dumpPixels) {
+        if (m_pixelResult)
+            dumpPixelsAndCompareWithExpected(m_pixelResult.get(), m_repaintRects.get(), TestInvocation::SnapshotResultType::WebContents);
+        else {
+            m_gotRepaint = false;
+            WKPageForceRepaint(TestController::singleton().mainWebView()->page(), this, TestInvocation::forceRepaintDoneCallback);
+            TestController::singleton().runUntil(m_gotRepaint, TestController::shortTimeout);
+            if (!m_gotRepaint) {
+                m_errorMessage = "Timed out waiting for pre-pixel dump repaint\n";
+                m_webProcessIsUnresponsive = true;
+                return;
+            }
+            WKRetainPtr<WKImageRef> windowSnapshot = TestController::singleton().mainWebView()->windowSnapshotImage();
+            ASSERT(windowSnapshot);
+            dumpPixelsAndCompareWithExpected(windowSnapshot.get(), m_repaintRects.get(), TestInvocation::SnapshotResultType::WebView);
         }
-        dumpPixelsAndCompareWithExpected(m_pixelResult.get(), m_repaintRects.get());
     }
 
     fputs("#EOF\n", stdout);
index 5981ada..617bba0 100644 (file)
@@ -63,7 +63,8 @@ public:
 private:
     void dumpResults();
     static void dump(const char* textToStdout, const char* textToStderr = 0, bool seenError = false);
-    void dumpPixelsAndCompareWithExpected(WKImageRef, WKArrayRef repaintRects);
+    enum class SnapshotResultType { WebView, WebContents };
+    void dumpPixelsAndCompareWithExpected(WKImageRef, WKArrayRef repaintRects, SnapshotResultType);
     void dumpAudio(WKDataRef);
     bool compareActualHashToExpectedAndDumpResults(const char[33]);
 
index 4fafb18..376f319 100644 (file)
@@ -106,9 +106,9 @@ static void paintRepaintRectOverlay(cairo_surface_t* surface, WKArrayRef repaint
     cairo_destroy(context);
 }
 
-void TestInvocation::dumpPixelsAndCompareWithExpected(WKImageRef, WKArrayRef repaintRects)
+void TestInvocation::dumpPixelsAndCompareWithExpected(WKImageRef image, WKArrayRef repaintRects, SnapshotResultType)
 {
-    cairo_surface_t* surface = WKImageCreateCairoSurface(TestController::singleton().mainWebView()->windowSnapshotImage().get());
+    cairo_surface_t* surface = WKImageCreateCairoSurface(image);
 
     if (repaintRects)
         paintRepaintRectOverlay(surface, repaintRects);
index ec8392a..7f3f2b8 100644 (file)
@@ -154,16 +154,9 @@ static void paintRepaintRectOverlay(CGContextRef context, WKImageRef image, WKAr
     CGContextRestoreGState(context);
 }
 
-void TestInvocation::dumpPixelsAndCompareWithExpected(WKImageRef image, WKArrayRef repaintRects)
+void TestInvocation::dumpPixelsAndCompareWithExpected(WKImageRef image, WKArrayRef repaintRects, SnapshotResultType snapshotType)
 {
-    PlatformWebView* webView = TestController::singleton().mainWebView();
-    WKRetainPtr<WKImageRef> windowSnapshot = webView->windowSnapshotImage();
-
-    RetainPtr<CGContextRef> context;
-    if (windowSnapshot)
-        context = adoptCF(createCGContextFromImage(windowSnapshot.get(), DontFlipGraphicsContext));
-    else
-        context = adoptCF(createCGContextFromImage(image));
+    RetainPtr<CGContextRef> context = adoptCF(createCGContextFromImage(image, snapshotType == SnapshotResultType::WebView ? DontFlipGraphicsContext : FlipGraphicsContext));
 
     // A non-null repaintRects array means we're doing a repaint test.
     if (repaintRects)