WK2 needs printing support on Windows
authorjhoneycutt@apple.com <jhoneycutt@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 5 Mar 2011 01:21:09 +0000 (01:21 +0000)
committerjhoneycutt@apple.com <jhoneycutt@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 5 Mar 2011 01:21:09 +0000 (01:21 +0000)
https://bugs.webkit.org/show_bug.cgi?id=55800
<rdar://problem/8903808>

Reviewed by Darin Adler.

* UIProcess/API/C/WKPage.cpp:
(ComputedPagesContext::ComputedPagesContext):
(computedPagesCallback):
From the Vector of WebCore::IntRects, build up a Vector of WKRects.
Call the callback, passing these rects and the scale factor.
(printInfoFromWKPrintInfo):
Return a PrintInfo structure from the WKPrintInfo.
(WKPageComputePagesForPrinting):
Call WebPageProxy::computePagesForPrinting(). Pass
computedPagesCallback as the callback function, so that we can
translate the WebCore rect type to WKRect before calling the caller's
callback function.
(WKPageBeginPrinting):
Call WebPageProxy::beginPrinting().
(WKPageDrawPagesToPDF):
Call WebPageProxy::drawPagesToPDF().

* UIProcess/API/C/WKPagePrivate.h:
Declare the WKPrintInfo type and new functions.

* UIProcess/WebPageProxy.cpp:
Compile this code on Windows.

* UIProcess/WebPageProxy.h:
Ditto.

* UIProcess/win/WebView.cpp:
(WebKit::WebView::paint):
We're painting the window; leave printing mode.

* WebProcess/WebPage/WebPage.cpp:
Compile this code on Windows.

* WebProcess/WebPage/WebPage.h:
Ditto.

* WebProcess/WebPage/WebPage.messages.in:
Ditto.

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/C/WKPage.cpp
Source/WebKit2/UIProcess/API/C/WKPagePrivate.h
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/UIProcess/win/WebView.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h
Source/WebKit2/WebProcess/WebPage/WebPage.messages.in

index 2fefd59..bdfbeed 100644 (file)
@@ -1,3 +1,50 @@
+2011-03-04  Jon Honeycutt  <jhoneycutt@apple.com>
+
+        WK2 needs printing support on Windows
+        https://bugs.webkit.org/show_bug.cgi?id=55800
+        <rdar://problem/8903808>
+
+        Reviewed by Darin Adler.
+
+        * UIProcess/API/C/WKPage.cpp:
+        (ComputedPagesContext::ComputedPagesContext):
+        (computedPagesCallback):
+        From the Vector of WebCore::IntRects, build up a Vector of WKRects.
+        Call the callback, passing these rects and the scale factor.
+        (printInfoFromWKPrintInfo):
+        Return a PrintInfo structure from the WKPrintInfo.
+        (WKPageComputePagesForPrinting):
+        Call WebPageProxy::computePagesForPrinting(). Pass
+        computedPagesCallback as the callback function, so that we can
+        translate the WebCore rect type to WKRect before calling the caller's
+        callback function.
+        (WKPageBeginPrinting):
+        Call WebPageProxy::beginPrinting().
+        (WKPageDrawPagesToPDF):
+        Call WebPageProxy::drawPagesToPDF().
+
+        * UIProcess/API/C/WKPagePrivate.h:
+        Declare the WKPrintInfo type and new functions.
+
+        * UIProcess/WebPageProxy.cpp:
+        Compile this code on Windows.
+
+        * UIProcess/WebPageProxy.h:
+        Ditto.
+
+        * UIProcess/win/WebView.cpp:
+        (WebKit::WebView::paint):
+        We're painting the window; leave printing mode.
+
+        * WebProcess/WebPage/WebPage.cpp:
+        Compile this code on Windows.
+
+        * WebProcess/WebPage/WebPage.h:
+        Ditto.
+
+        * WebProcess/WebPage/WebPage.messages.in:
+        Ditto.
+
 2011-03-04  Steve Falkenburg  <sfalken@apple.com>
 
         Reviewed by Darin Adler.
index 516cd48..c40f4a5 100644 (file)
@@ -27,6 +27,7 @@
 #include "WKPage.h"
 #include "WKPagePrivate.h"
 
+#include "PrintInfo.h"
 #include "WKAPICast.h"
 #include "WebBackForwardList.h"
 #include "WebData.h"
@@ -502,3 +503,49 @@ void WKPageExecuteCommand(WKPageRef pageRef, WKStringRef command)
 {
     toImpl(pageRef)->executeEditCommand(toImpl(command)->string());
 }
+
+#if PLATFORM(MAC) || PLATFORM(WIN)
+struct ComputedPagesContext {
+    ComputedPagesContext(WKPageComputePagesForPrintingFunction callback, void* context)
+        : callback(callback)
+        , context(context)
+    {
+    }
+    WKPageComputePagesForPrintingFunction callback;
+    void* context;
+};
+
+static void computedPagesCallback(const Vector<WebCore::IntRect>& rects, double scaleFactor, WKErrorRef error, void* untypedContext)
+{
+    OwnPtr<ComputedPagesContext> context = adoptPtr(static_cast<ComputedPagesContext*>(untypedContext));
+    Vector<WKRect> wkRects(rects.size());
+    for (size_t i = 0; i < rects.size(); ++i)
+        wkRects[i] = toAPI(rects[i]);
+    context->callback(wkRects.data(), wkRects.size(), scaleFactor, error, context->context);
+}
+
+static PrintInfo printInfoFromWKPrintInfo(const WKPrintInfo& printInfo)
+{
+    PrintInfo result;
+    result.pageSetupScaleFactor = printInfo.pageSetupScaleFactor;
+    result.availablePaperWidth = printInfo.availablePaperWidth;
+    result.availablePaperHeight = printInfo.availablePaperHeight;
+    return result;
+}
+
+void WKPageComputePagesForPrinting(WKPageRef page, WKFrameRef frame, const WKPrintInfo& printInfo, WKPageComputePagesForPrintingFunction callback, void* context)
+{
+    toImpl(page)->computePagesForPrinting(toImpl(frame), printInfoFromWKPrintInfo(printInfo), ComputedPagesCallback::create(new ComputedPagesContext(callback, context), computedPagesCallback));
+}
+
+void WKPageBeginPrinting(WKPageRef page, WKFrameRef frame, const WKPrintInfo& printInfo)
+{
+    toImpl(page)->beginPrinting(toImpl(frame), printInfoFromWKPrintInfo(printInfo));
+}
+
+void WKPageDrawPagesToPDF(WKPageRef page, WKFrameRef frame, uint32_t first, uint32_t count, WKPageDrawToPDFFunction callback, void* context)
+{
+    toImpl(page)->drawPagesToPDF(toImpl(frame), first, count, DataCallback::create(context, callback));
+}
+#endif
+
index 7770b25..a280d3a 100644 (file)
@@ -50,6 +50,18 @@ typedef unsigned WKPageDebugPaintFlags;
 WK_EXPORT void WKPageSetDebugPaintFlags(WKPageDebugPaintFlags flags);
 WK_EXPORT WKPageDebugPaintFlags WKPageGetDebugPaintFlags(void);
 
+struct WKPrintInfo {
+    float pageSetupScaleFactor;
+    float availablePaperWidth;
+    float availablePaperHeight;
+};
+typedef void (*WKPageComputePagesForPrintingFunction)(WKRect* pageRects, uint32_t pageCount, double resultPageScaleFactor, WKErrorRef error, void* functionContext);
+WK_EXPORT void WKPageComputePagesForPrinting(WKPageRef page, WKFrameRef frame, const WKPrintInfo&, WKPageComputePagesForPrintingFunction, void* context);
+
+typedef void (*WKPageDrawToPDFFunction)(WKDataRef data, WKErrorRef error, void* functionContext);
+WK_EXPORT void WKPageBeginPrinting(WKPageRef page, WKFrameRef frame, const WKPrintInfo&);
+WK_EXPORT void WKPageDrawPagesToPDF(WKPageRef page, WKFrameRef frame, uint32_t first, uint32_t count, WKPageDrawToPDFFunction callback, void* context);
+
 #ifdef __cplusplus
 }
 #endif
index af34cb2..d20a677 100644 (file)
@@ -2778,7 +2778,7 @@ void WebPageProxy::computePagesForPrinting(WebFrameProxy* frame, const PrintInfo
     process()->send(Messages::WebPage::ComputePagesForPrinting(frame->frameID(), printInfo, callbackID), m_pageID, m_isPerformingDOMPrintOperation ? CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply : 0);
 }
 
-#if PLATFORM(MAC)
+#if PLATFORM(MAC) || PLATFORM(WIN)
 void WebPageProxy::drawRectToPDF(WebFrameProxy* frame, const IntRect& rect, PassRefPtr<DataCallback> callback)
 {
     uint64_t callbackID = callback->callbackID();
index eb073e1..c7d1fe6 100644 (file)
@@ -445,7 +445,7 @@ public:
     void beginPrinting(WebFrameProxy*, const PrintInfo&);
     void endPrinting();
     void computePagesForPrinting(WebFrameProxy*, const PrintInfo&, PassRefPtr<ComputedPagesCallback>);
-#if PLATFORM(MAC)
+#if PLATFORM(MAC) || PLATFORM(WIN)
     void drawRectToPDF(WebFrameProxy*, const WebCore::IntRect&, PassRefPtr<DataCallback>);
     void drawPagesToPDF(WebFrameProxy*, uint32_t first, uint32_t count, PassRefPtr<DataCallback>);
 #endif
index ab488cb..62e0c42 100644 (file)
@@ -414,6 +414,7 @@ static void drawPageBackground(HDC dc, const RECT& rect)
 
 void WebView::paint(HDC hdc, const IntRect& dirtyRect)
 {
+    m_page->endPrinting();
     if (useNewDrawingArea()) {
         if (DrawingAreaProxyImpl* drawingArea = static_cast<DrawingAreaProxyImpl*>(m_page->drawingArea())) {
             // FIXME: We should port WebKit1's rect coalescing logic here.
index 62c037e..bacaa97 100644 (file)
@@ -1988,8 +1988,7 @@ void WebPage::computePagesForPrinting(uint64_t frameID, const PrintInfo& printIn
     send(Messages::WebPageProxy::ComputedPagesCallback(resultPageRects, resultTotalScaleFactorForPrinting, callbackID));
 }
 
-#if PLATFORM(MAC)
-// FIXME: Find a better place for Mac specific code.
+#if PLATFORM(MAC) || PLATFORM(WIN)
 void WebPage::drawRectToPDF(uint64_t frameID, const WebCore::IntRect& rect, uint64_t callbackID)
 {
     WebFrame* frame = WebProcess::shared().webFrame(frameID);
index 6b6b731..8ce6405 100644 (file)
@@ -329,7 +329,7 @@ public:
     void beginPrinting(uint64_t frameID, const PrintInfo&);
     void endPrinting();
     void computePagesForPrinting(uint64_t frameID, const PrintInfo&, uint64_t callbackID);
-#if PLATFORM(MAC)
+#if PLATFORM(MAC) || PLATFORM(WIN)
     void drawRectToPDF(uint64_t frameID, const WebCore::IntRect&, uint64_t callbackID);
     void drawPagesToPDF(uint64_t frameID, uint32_t first, uint32_t count, uint64_t callbackID);
 #endif
index b67b5a4..0c0eea5 100644 (file)
@@ -156,7 +156,7 @@ messages -> WebPage {
     BeginPrinting(uint64_t frameID, WebKit::PrintInfo printInfo)
     EndPrinting();
     ComputePagesForPrinting(uint64_t frameID, WebKit::PrintInfo printInfo, uint64_t callbackID)
-#if PLATFORM(MAC)
+#if PLATFORM(MAC) || PLATFORM(WIN)
     DrawRectToPDF(uint64_t frameID, WebCore::IntRect rect, uint64_t callbackID)
     DrawPagesToPDF(uint64_t frameID, uint32_t first, uint32_t count, uint64_t callbackID)
 #endif