Changeset 80398 in webkit


Ignore:
Timestamp:
Mar 4, 2011 5:21:09 PM (13 years ago)
Author:
jhoneycutt@apple.com
Message:

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.

Location:
trunk/Source/WebKit2
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r80395 r80398  
     12011-03-04  Jon Honeycutt  <jhoneycutt@apple.com>
     2
     3        WK2 needs printing support on Windows
     4        https://bugs.webkit.org/show_bug.cgi?id=55800
     5        <rdar://problem/8903808>
     6
     7        Reviewed by Darin Adler.
     8
     9        * UIProcess/API/C/WKPage.cpp:
     10        (ComputedPagesContext::ComputedPagesContext):
     11        (computedPagesCallback):
     12        From the Vector of WebCore::IntRects, build up a Vector of WKRects.
     13        Call the callback, passing these rects and the scale factor.
     14        (printInfoFromWKPrintInfo):
     15        Return a PrintInfo structure from the WKPrintInfo.
     16        (WKPageComputePagesForPrinting):
     17        Call WebPageProxy::computePagesForPrinting(). Pass
     18        computedPagesCallback as the callback function, so that we can
     19        translate the WebCore rect type to WKRect before calling the caller's
     20        callback function.
     21        (WKPageBeginPrinting):
     22        Call WebPageProxy::beginPrinting().
     23        (WKPageDrawPagesToPDF):
     24        Call WebPageProxy::drawPagesToPDF().
     25
     26        * UIProcess/API/C/WKPagePrivate.h:
     27        Declare the WKPrintInfo type and new functions.
     28
     29        * UIProcess/WebPageProxy.cpp:
     30        Compile this code on Windows.
     31
     32        * UIProcess/WebPageProxy.h:
     33        Ditto.
     34
     35        * UIProcess/win/WebView.cpp:
     36        (WebKit::WebView::paint):
     37        We're painting the window; leave printing mode.
     38
     39        * WebProcess/WebPage/WebPage.cpp:
     40        Compile this code on Windows.
     41
     42        * WebProcess/WebPage/WebPage.h:
     43        Ditto.
     44
     45        * WebProcess/WebPage/WebPage.messages.in:
     46        Ditto.
     47
    1482011-03-04  Steve Falkenburg  <sfalken@apple.com>
    249
  • trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp

    r80394 r80398  
    2828#include "WKPagePrivate.h"
    2929
     30#include "PrintInfo.h"
    3031#include "WKAPICast.h"
    3132#include "WebBackForwardList.h"
     
    503504    toImpl(pageRef)->executeEditCommand(toImpl(command)->string());
    504505}
     506
     507#if PLATFORM(MAC) || PLATFORM(WIN)
     508struct ComputedPagesContext {
     509    ComputedPagesContext(WKPageComputePagesForPrintingFunction callback, void* context)
     510        : callback(callback)
     511        , context(context)
     512    {
     513    }
     514    WKPageComputePagesForPrintingFunction callback;
     515    void* context;
     516};
     517
     518static void computedPagesCallback(const Vector<WebCore::IntRect>& rects, double scaleFactor, WKErrorRef error, void* untypedContext)
     519{
     520    OwnPtr<ComputedPagesContext> context = adoptPtr(static_cast<ComputedPagesContext*>(untypedContext));
     521    Vector<WKRect> wkRects(rects.size());
     522    for (size_t i = 0; i < rects.size(); ++i)
     523        wkRects[i] = toAPI(rects[i]);
     524    context->callback(wkRects.data(), wkRects.size(), scaleFactor, error, context->context);
     525}
     526
     527static PrintInfo printInfoFromWKPrintInfo(const WKPrintInfo& printInfo)
     528{
     529    PrintInfo result;
     530    result.pageSetupScaleFactor = printInfo.pageSetupScaleFactor;
     531    result.availablePaperWidth = printInfo.availablePaperWidth;
     532    result.availablePaperHeight = printInfo.availablePaperHeight;
     533    return result;
     534}
     535
     536void WKPageComputePagesForPrinting(WKPageRef page, WKFrameRef frame, const WKPrintInfo& printInfo, WKPageComputePagesForPrintingFunction callback, void* context)
     537{
     538    toImpl(page)->computePagesForPrinting(toImpl(frame), printInfoFromWKPrintInfo(printInfo), ComputedPagesCallback::create(new ComputedPagesContext(callback, context), computedPagesCallback));
     539}
     540
     541void WKPageBeginPrinting(WKPageRef page, WKFrameRef frame, const WKPrintInfo& printInfo)
     542{
     543    toImpl(page)->beginPrinting(toImpl(frame), printInfoFromWKPrintInfo(printInfo));
     544}
     545
     546void WKPageDrawPagesToPDF(WKPageRef page, WKFrameRef frame, uint32_t first, uint32_t count, WKPageDrawToPDFFunction callback, void* context)
     547{
     548    toImpl(page)->drawPagesToPDF(toImpl(frame), first, count, DataCallback::create(context, callback));
     549}
     550#endif
     551
  • trunk/Source/WebKit2/UIProcess/API/C/WKPagePrivate.h

    r78488 r80398  
    5151WK_EXPORT WKPageDebugPaintFlags WKPageGetDebugPaintFlags(void);
    5252
     53struct WKPrintInfo {
     54    float pageSetupScaleFactor;
     55    float availablePaperWidth;
     56    float availablePaperHeight;
     57};
     58typedef void (*WKPageComputePagesForPrintingFunction)(WKRect* pageRects, uint32_t pageCount, double resultPageScaleFactor, WKErrorRef error, void* functionContext);
     59WK_EXPORT void WKPageComputePagesForPrinting(WKPageRef page, WKFrameRef frame, const WKPrintInfo&, WKPageComputePagesForPrintingFunction, void* context);
     60
     61typedef void (*WKPageDrawToPDFFunction)(WKDataRef data, WKErrorRef error, void* functionContext);
     62WK_EXPORT void WKPageBeginPrinting(WKPageRef page, WKFrameRef frame, const WKPrintInfo&);
     63WK_EXPORT void WKPageDrawPagesToPDF(WKPageRef page, WKFrameRef frame, uint32_t first, uint32_t count, WKPageDrawToPDFFunction callback, void* context);
     64
    5365#ifdef __cplusplus
    5466}
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp

    r80394 r80398  
    27792779}
    27802780
    2781 #if PLATFORM(MAC)
     2781#if PLATFORM(MAC) || PLATFORM(WIN)
    27822782void WebPageProxy::drawRectToPDF(WebFrameProxy* frame, const IntRect& rect, PassRefPtr<DataCallback> callback)
    27832783{
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.h

    r80394 r80398  
    446446    void endPrinting();
    447447    void computePagesForPrinting(WebFrameProxy*, const PrintInfo&, PassRefPtr<ComputedPagesCallback>);
    448 #if PLATFORM(MAC)
     448#if PLATFORM(MAC) || PLATFORM(WIN)
    449449    void drawRectToPDF(WebFrameProxy*, const WebCore::IntRect&, PassRefPtr<DataCallback>);
    450450    void drawPagesToPDF(WebFrameProxy*, uint32_t first, uint32_t count, PassRefPtr<DataCallback>);
  • trunk/Source/WebKit2/UIProcess/win/WebView.cpp

    r80394 r80398  
    415415void WebView::paint(HDC hdc, const IntRect& dirtyRect)
    416416{
     417    m_page->endPrinting();
    417418    if (useNewDrawingArea()) {
    418419        if (DrawingAreaProxyImpl* drawingArea = static_cast<DrawingAreaProxyImpl*>(m_page->drawingArea())) {
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp

    r80394 r80398  
    19891989}
    19901990
    1991 #if PLATFORM(MAC)
    1992 // FIXME: Find a better place for Mac specific code.
     1991#if PLATFORM(MAC) || PLATFORM(WIN)
    19931992void WebPage::drawRectToPDF(uint64_t frameID, const WebCore::IntRect& rect, uint64_t callbackID)
    19941993{
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h

    r80394 r80398  
    330330    void endPrinting();
    331331    void computePagesForPrinting(uint64_t frameID, const PrintInfo&, uint64_t callbackID);
    332 #if PLATFORM(MAC)
     332#if PLATFORM(MAC) || PLATFORM(WIN)
    333333    void drawRectToPDF(uint64_t frameID, const WebCore::IntRect&, uint64_t callbackID);
    334334    void drawPagesToPDF(uint64_t frameID, uint32_t first, uint32_t count, uint64_t callbackID);
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in

    r80394 r80398  
    157157    EndPrinting();
    158158    ComputePagesForPrinting(uint64_t frameID, WebKit::PrintInfo printInfo, uint64_t callbackID)
    159 #if PLATFORM(MAC)
     159#if PLATFORM(MAC) || PLATFORM(WIN)
    160160    DrawRectToPDF(uint64_t frameID, WebCore::IntRect rect, uint64_t callbackID)
    161161    DrawPagesToPDF(uint64_t frameID, uint32_t first, uint32_t count, uint64_t callbackID)
Note: See TracChangeset for help on using the changeset viewer.