Changeset 103858 in webkit


Ignore:
Timestamp:
Dec 31, 2011 12:29:46 PM (12 years ago)
Author:
mitz@apple.com
Message:

Source/WebCore: WebCore changes for <rdar://problem/8750356> REGRESSION (WebKit2): Printing a subframe containing a PDF prints the on-screen view instead of the entire PDF document
<http://webkit.org/b/75232>

Reviewed by Alexey Proskuryakov.

  • WebCore.exp.in: Exported PluginDocument::pluginWidget().
  • WebCore.xcodeproj/project.pbxproj: Promoted PluginDocument.h to private.
  • html/PluginDocument.h: Fixed a typo in a comment.

Source/WebKit2: <rdar://problem/8750356> REGRESSION (WebKit2): Printing a subframe containing a PDF prints the on-screen view instead of the entire PDF document
<http://webkit.org/b/75232>

Reviewed by Alexey Proskuryakov.

  • UIProcess/API/C/WKPage.cpp:

(WKPageDrawPagesToPDF): Added WKPrintInfo parameter, which is passed through as a PrintInfo
to the WebPageProxy.

  • UIProcess/API/C/WKPagePrivate.h:
  • UIProcess/API/mac/WKPrintingView.mm:

(-[WKPrintingView _preparePDFDataForPrintingOnSecondaryThread]): Changed to pass the PrintInfo
down to WebPageProxy::drawPagesToPDF.
(-[WKPrintingView _drawPreview:]): Changed to pass the PrintInfo down to
WebPageProxy::drawRectToPDF.

  • UIProcess/API/mac/WKView.mm:

(-[WKView canChangeFrameLayout:]): Changed to use WebFrameProxy::isDisplayingPDFDocument, which
works for subframes as well.
(-[WKView printOperationWithPrintInfo:forFrame:]): Added a FIXME.

  • UIProcess/WebFrameProxy.cpp:

(WebKit::WebFrameProxy::isDisplayingPDFDocument): Added.

  • UIProcess/WebFrameProxy.h:
  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::drawRectToPDF): Added a PrintInfo parameter, which is passed through to
the Web process.
(WebKit::WebPageProxy::drawPagesToPDF): Ditto.

  • UIProcess/WebPageProxy.h:
  • WebProcess/Plugins/PDF/BuiltInPDFView.h:

Added an override of pdfDocumentForPrinting() which returns the PDFDocument.

  • WebProcess/Plugins/Plugin.h:

(WebKit::Plugin::pdfDocumentForPrinting): Added. This base class implementation returns 0.

  • WebProcess/Plugins/PluginView.h:

(WebKit::PluginView::pdfDocumentForPrinting): Added. Calls through to the Plugin.

  • WebProcess/WebPage/WebPage.cpp:

(WebKit::pdfDocumentForPrintingFrame): Added this helper function. If the frame is displaying
a plug-in document, allows the plug-in to provide a PDF document for printing.
(WebKit::WebPage::beginPrinting): Added an early return if the frame provides a PDF document
for printing.
(WebKit::WebPage::computePagesForPrinting): If the frame provides a PDF document for printing,
create for each page in the PDF document a page rect with the size available for printing.
(WebKit::drawPDFPage): Added this helper function, which draws a page from the PDF document
into one of the aforementioned page rects. It rotates the PDF page 90 degrees if necessary to
better match the aspect ratio of the paper, then it centers it on the paper. This matches the
behavior of a PDFView when printed with default settings.
(WebKit::WebPage::drawRectToPDF): If the frame provides a PDF document for printing, draw the
PDF pages falling within the requested rect.
(WebKit::WebPage::drawPagesToPDF): If the frame provides a PDF document for printing, draw
the requested pages.

  • WebProcess/WebPage/WebPage.h:
  • WebProcess/WebPage/WebPage.messages.in: Added a PrintInfo parameter to DrawRectToPDF and

DrawPagesToPDF.

Location:
trunk/Source
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r103856 r103858  
     12011-12-31  Dan Bernstein  <mitz@apple.com>
     2
     3        WebCore changes for <rdar://problem/8750356> REGRESSION (WebKit2): Printing a subframe containing a PDF prints the on-screen view instead of the entire PDF document
     4        <http://webkit.org/b/75232>
     5
     6        Reviewed by Alexey Proskuryakov.
     7
     8        * WebCore.exp.in: Exported PluginDocument::pluginWidget().
     9        * WebCore.xcodeproj/project.pbxproj: Promoted PluginDocument.h to private.
     10        * html/PluginDocument.h: Fixed a typo in a comment.
     11
    1122011-12-30  Andreas Kling  <awesomekling@apple.com>
    213
  • trunk/Source/WebCore/WebCore.exp.in

    r103790 r103858  
    357357__ZN7WebCore14FrameSelection9selectAllEv
    358358__ZN7WebCore14FrameSelectionC1EPNS_5FrameE
     359__ZN7WebCore14PluginDocument12pluginWidgetEv
    359360__ZN7WebCore14ResourceHandle20forceContentSniffingEv
    360361__ZN7WebCore14ResourceHandle26synchronousLoadRunLoopModeEv
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r103643 r103858  
    32653265                97205AB81239291000B17380 /* MediaDocument.h in Headers */ = {isa = PBXBuildFile; fileRef = 97205AB41239291000B17380 /* MediaDocument.h */; };
    32663266                97205ABB1239292700B17380 /* PluginDocument.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 97205AB91239292700B17380 /* PluginDocument.cpp */; };
    3267                 97205ABC1239292700B17380 /* PluginDocument.h in Headers */ = {isa = PBXBuildFile; fileRef = 97205ABA1239292700B17380 /* PluginDocument.h */; };
     3267                97205ABC1239292700B17380 /* PluginDocument.h in Headers */ = {isa = PBXBuildFile; fileRef = 97205ABA1239292700B17380 /* PluginDocument.h */; settings = {ATTRIBUTES = (Private, ); }; };
    32683268                9728C3131268E4390041E89B /* MarkupAccumulator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9728C3111268E4390041E89B /* MarkupAccumulator.cpp */; };
    32693269                9728C3141268E4390041E89B /* MarkupAccumulator.h in Headers */ = {isa = PBXBuildFile; fileRef = 9728C3121268E4390041E89B /* MarkupAccumulator.h */; };
  • trunk/Source/WebCore/html/PluginDocument.h

    r103692 r103858  
    11/*
    2  * Copyright (C) 2006, 2008, 2009Apple Inc. All rights reserved.
     2 * Copyright (C) 2006, 2008, 2009 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
  • trunk/Source/WebKit2/ChangeLog

    r103843 r103858  
     12011-12-31  Dan Bernstein  <mitz@apple.com>
     2
     3        <rdar://problem/8750356> REGRESSION (WebKit2): Printing a subframe containing a PDF prints the on-screen view instead of the entire PDF document
     4        <http://webkit.org/b/75232>
     5
     6        Reviewed by Alexey Proskuryakov.
     7
     8        * UIProcess/API/C/WKPage.cpp:
     9        (WKPageDrawPagesToPDF): Added WKPrintInfo parameter, which is passed through as a PrintInfo
     10        to the WebPageProxy.
     11        * UIProcess/API/C/WKPagePrivate.h:
     12        * UIProcess/API/mac/WKPrintingView.mm:
     13        (-[WKPrintingView _preparePDFDataForPrintingOnSecondaryThread]): Changed to pass the PrintInfo
     14        down to WebPageProxy::drawPagesToPDF.
     15        (-[WKPrintingView _drawPreview:]): Changed to pass the PrintInfo down to
     16        WebPageProxy::drawRectToPDF.
     17        * UIProcess/API/mac/WKView.mm:
     18        (-[WKView canChangeFrameLayout:]): Changed to use WebFrameProxy::isDisplayingPDFDocument, which
     19        works for subframes as well.
     20        (-[WKView printOperationWithPrintInfo:forFrame:]): Added a FIXME.
     21        * UIProcess/WebFrameProxy.cpp:
     22        (WebKit::WebFrameProxy::isDisplayingPDFDocument): Added.
     23        * UIProcess/WebFrameProxy.h:
     24        * UIProcess/WebPageProxy.cpp:
     25        (WebKit::WebPageProxy::drawRectToPDF): Added a PrintInfo parameter, which is passed through to
     26        the Web process.
     27        (WebKit::WebPageProxy::drawPagesToPDF): Ditto.
     28        * UIProcess/WebPageProxy.h:
     29        * WebProcess/Plugins/PDF/BuiltInPDFView.h:
     30        Added an override of pdfDocumentForPrinting() which returns the PDFDocument.
     31        * WebProcess/Plugins/Plugin.h:
     32        (WebKit::Plugin::pdfDocumentForPrinting): Added. This base class implementation returns 0.
     33        * WebProcess/Plugins/PluginView.h:
     34        (WebKit::PluginView::pdfDocumentForPrinting): Added. Calls through to the Plugin.
     35        * WebProcess/WebPage/WebPage.cpp:
     36        (WebKit::pdfDocumentForPrintingFrame): Added this helper function. If the frame is displaying
     37        a plug-in document, allows the plug-in to provide a PDF document for printing.
     38        (WebKit::WebPage::beginPrinting): Added an early return if the frame provides a PDF document
     39        for printing.
     40        (WebKit::WebPage::computePagesForPrinting): If the frame provides a PDF document for printing,
     41        create for each page in the PDF document a page rect with the size available for printing.
     42        (WebKit::drawPDFPage): Added this helper function, which draws a page from the PDF document
     43        into one of the aforementioned page rects. It rotates the PDF page 90 degrees if necessary to
     44        better match the aspect ratio of the paper, then it centers it on the paper. This matches the
     45        behavior of a PDFView when printed with default settings.
     46        (WebKit::WebPage::drawRectToPDF): If the frame provides a PDF document for printing, draw the
     47        PDF pages falling within the requested rect.
     48        (WebKit::WebPage::drawPagesToPDF): If the frame provides a PDF document for printing, draw
     49        the requested pages.
     50        * WebProcess/WebPage/WebPage.h:
     51        * WebProcess/WebPage/WebPage.messages.in: Added a PrintInfo parameter to DrawRectToPDF and
     52        DrawPagesToPDF.
     53
    1542011-12-30  Dan Bernstein  <mitz@apple.com>
    255
  • trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp

    r101574 r103858  
    647647}
    648648
    649 void WKPageDrawPagesToPDF(WKPageRef page, WKFrameRef frame, uint32_t first, uint32_t count, WKPageDrawToPDFFunction callback, void* context)
    650 {
    651     toImpl(page)->drawPagesToPDF(toImpl(frame), first, count, DataCallback::create(context, callback));
     649void WKPageDrawPagesToPDF(WKPageRef page, WKFrameRef frame, WKPrintInfo printInfo, uint32_t first, uint32_t count, WKPageDrawToPDFFunction callback, void* context)
     650{
     651    toImpl(page)->drawPagesToPDF(toImpl(frame), printInfoFromWKPrintInfo(printInfo), first, count, DataCallback::create(context, callback));
    652652}
    653653#endif
  • trunk/Source/WebKit2/UIProcess/API/C/WKPagePrivate.h

    r101574 r103858  
    8080
    8181typedef void (*WKPageDrawToPDFFunction)(WKDataRef data, WKErrorRef error, void* functionContext);
    82 WK_EXPORT void WKPageBeginPrinting(WKPageRef page, WKFrameRef frame, WKPrintInfo);
    83 WK_EXPORT void WKPageDrawPagesToPDF(WKPageRef page, WKFrameRef frame, uint32_t first, uint32_t count, WKPageDrawToPDFFunction callback, void* context);
     82WK_EXPORT void WKPageBeginPrinting(WKPageRef page, WKFrameRef frame, WKPrintInfo printInfo);
     83WK_EXPORT void WKPageDrawPagesToPDF(WKPageRef page, WKFrameRef frame, WKPrintInfo printInfo, uint32_t first, uint32_t count, WKPageDrawToPDFFunction callback, void* context);
    8484
    8585// FIXME https://bugs.webkit.org/show_bug.cgi?id=66979: Remove this sync call.
  • trunk/Source/WebKit2/UIProcess/API/mac/WKPrintingView.mm

    r98526 r103858  
    253253    LOG(View, "WKPrintingView requesting PDF data for pages %u...%u", firstPage, lastPage);
    254254
     255    PrintInfo printInfo([_printOperation printInfo]);
    255256    // Return to printing mode if we're already back to screen (e.g. due to window resizing).
    256     _webFrame->page()->beginPrinting(_webFrame.get(), PrintInfo([_printOperation printInfo]));
     257    _webFrame->page()->beginPrinting(_webFrame.get(), printInfo);
    257258
    258259    IPCCallbackContext* context = new IPCCallbackContext;
     
    263264    context->callbackID = callback->callbackID();
    264265
    265     _webFrame->page()->drawPagesToPDF(_webFrame.get(), firstPage - 1, lastPage - firstPage + 1, callback.get());
     266    _webFrame->page()->drawPagesToPDF(_webFrame.get(), printInfo, firstPage - 1, lastPage - firstPage + 1, callback.get());
    266267}
    267268
     
    453454                context->callbackID = callback->callbackID();
    454455
    455                 _webFrame->page()->drawRectToPDF(_webFrame.get(), rect, callback.get());
     456                _webFrame->page()->drawRectToPDF(_webFrame.get(), PrintInfo([_printOperation printInfo]), rect, callback.get());
    456457                return;
    457458            }
  • trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm

    r103643 r103858  
    27182718{
    27192719    // PDF documents are already paginated, so we can't change them to add headers and footers.
    2720     return !toImpl(frameRef)->isMainFrame() || !_data->_pdfViewController;
     2720    return !toImpl(frameRef)->isDisplayingPDFDocument();
    27212721}
    27222722
     
    27312731        return _data->_pdfViewController->makePrintOperation(printInfo);
    27322732    } else {
     2733        // FIXME: If the frame cannot be printed (e.g. if it contains an encrypted PDF that disallows
     2734        // printing), this function should return nil.
    27332735        RetainPtr<WKPrintingView> printingView(AdoptNS, [[WKPrintingView alloc] initWithFrameProxy:toImpl(frameRef) view:self]);
    27342736        // NSPrintOperation takes ownership of the view.
  • trunk/Source/WebKit2/UIProcess/WebFrameProxy.cpp

    r98513 r103858  
    11/*
    2  * Copyright (C) 2010 Apple Inc. All rights reserved.
     2 * Copyright (C) 2010, 2011 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    130130}
    131131
     132bool WebFrameProxy::isDisplayingPDFDocument() const
     133{
     134    if (m_MIMEType.isEmpty())
     135        return false;
     136
     137    return WebContext::pdfAndPostScriptMIMETypes().contains(m_MIMEType);
     138}
     139
    132140void WebFrameProxy::didStartProvisionalLoad(const String& url)
    133141{
  • trunk/Source/WebKit2/UIProcess/WebFrameProxy.h

    r95901 r103858  
    107107    bool isDisplayingStandaloneImageDocument() const;
    108108    bool isDisplayingMarkupDocument() const;
     109    bool isDisplayingPDFDocument() const;
    109110
    110111    void getWebArchive(PassRefPtr<DataCallback>);
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp

    r103281 r103858  
    34323432
    34333433#if PLATFORM(MAC) || PLATFORM(WIN)
    3434 void WebPageProxy::drawRectToPDF(WebFrameProxy* frame, const IntRect& rect, PassRefPtr<DataCallback> prpCallback)
     3434void WebPageProxy::drawRectToPDF(WebFrameProxy* frame, const PrintInfo& printInfo, const IntRect& rect, PassRefPtr<DataCallback> prpCallback)
    34353435{
    34363436    RefPtr<DataCallback> callback = prpCallback;
     
    34423442    uint64_t callbackID = callback->callbackID();
    34433443    m_dataCallbacks.set(callbackID, callback.get());
    3444     process()->send(Messages::WebPage::DrawRectToPDF(frame->frameID(), rect, callbackID), m_pageID, m_isPerformingDOMPrintOperation ? CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply : 0);
    3445 }
    3446 
    3447 void WebPageProxy::drawPagesToPDF(WebFrameProxy* frame, uint32_t first, uint32_t count, PassRefPtr<DataCallback> prpCallback)
     3444    process()->send(Messages::WebPage::DrawRectToPDF(frame->frameID(), printInfo, rect, callbackID), m_pageID, m_isPerformingDOMPrintOperation ? CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply : 0);
     3445}
     3446
     3447void WebPageProxy::drawPagesToPDF(WebFrameProxy* frame, const PrintInfo& printInfo, uint32_t first, uint32_t count, PassRefPtr<DataCallback> prpCallback)
    34483448{
    34493449    RefPtr<DataCallback> callback = prpCallback;
     
    34553455    uint64_t callbackID = callback->callbackID();
    34563456    m_dataCallbacks.set(callbackID, callback.get());
    3457     process()->send(Messages::WebPage::DrawPagesToPDF(frame->frameID(), first, count, callbackID), m_pageID, m_isPerformingDOMPrintOperation ? CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply : 0);
     3457    process()->send(Messages::WebPage::DrawPagesToPDF(frame->frameID(), printInfo, first, count, callbackID), m_pageID, m_isPerformingDOMPrintOperation ? CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply : 0);
    34583458}
    34593459#endif
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.h

    r103802 r103858  
    560560    void computePagesForPrinting(WebFrameProxy*, const PrintInfo&, PassRefPtr<ComputedPagesCallback>);
    561561#if PLATFORM(MAC) || PLATFORM(WIN)
    562     void drawRectToPDF(WebFrameProxy*, const WebCore::IntRect&, PassRefPtr<DataCallback>);
    563     void drawPagesToPDF(WebFrameProxy*, uint32_t first, uint32_t count, PassRefPtr<DataCallback>);
     562    void drawRectToPDF(WebFrameProxy*, const PrintInfo&, const WebCore::IntRect&, PassRefPtr<DataCallback>);
     563    void drawPagesToPDF(WebFrameProxy*, const PrintInfo&, uint32_t first, uint32_t count, PassRefPtr<DataCallback>);
    564564#endif
    565565
  • trunk/Source/WebKit2/WebProcess/Plugins/PDF/BuiltInPDFView.h

    r101290 r103858  
    114114    virtual WebCore::Scrollbar* verticalScrollbar();
    115115
     116    virtual RetainPtr<CGPDFDocumentRef> pdfDocumentForPrinting() const OVERRIDE { return m_pdfDocument; }
     117
    116118    // ScrollableArea methods.
    117119    virtual WebCore::IntRect scrollCornerRect() const;
  • trunk/Source/WebKit2/WebProcess/Plugins/Plugin.h

    r99241 r103858  
    3131#include <WebCore/ScrollTypes.h>
    3232#include <wtf/RefCounted.h>
     33#include <wtf/RetainPtr.h>
    3334#include <wtf/Vector.h>
    3435
     
    219220    virtual WebCore::Scrollbar* verticalScrollbar() = 0;
    220221
     222#if USE(CG)
     223    virtual RetainPtr<CGPDFDocumentRef> pdfDocumentForPrinting() const { return 0; }
     224#endif
     225
    221226protected:
    222227    Plugin();
  • trunk/Source/WebKit2/WebProcess/Plugins/PluginView.h

    r103009 r103858  
    6969#endif
    7070
     71#if USE(CG)
     72    RetainPtr<CGPDFDocumentRef> pdfDocumentForPrinting() const { return m_plugin->pdfDocumentForPrinting(); }
     73#endif
     74
    7175    // FIXME: Remove this; nobody should have to know about the plug-in view's renderer except the plug-in view itself.
    7276    WebCore::RenderBoxModelObject* renderer() const;
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp

    r103566 r103858  
    9696#include <WebCore/Page.h>
    9797#include <WebCore/PlatformKeyboardEvent.h>
     98#include <WebCore/PluginDocument.h>
    9899#include <WebCore/PrintContext.h>
    99100#include <WebCore/RenderArena.h>
     
    142143using namespace JSC;
    143144using namespace WebCore;
     145using namespace std;
    144146
    145147namespace WebKit {
     
    25652567#endif
    25662568
     2569#if USE(CG)
     2570static RetainPtr<CGPDFDocumentRef> pdfDocumentForPrintingFrame(Frame* coreFrame)
     2571{
     2572    Document* document = coreFrame->document();
     2573    if (!document)
     2574        return 0;
     2575
     2576    if (!document->isPluginDocument())
     2577        return 0;
     2578
     2579    PluginView* pluginView = static_cast<PluginView*>(toPluginDocument(document)->pluginWidget());
     2580    if (!pluginView)
     2581        return 0;
     2582
     2583    return pluginView->pdfDocumentForPrinting();
     2584}
     2585#endif // USE(CG)
     2586
    25672587void WebPage::beginPrinting(uint64_t frameID, const PrintInfo& printInfo)
    25682588{
     
    25742594    if (!coreFrame)
    25752595        return;
     2596
     2597#if USE(CG)
     2598    if (pdfDocumentForPrintingFrame(coreFrame))
     2599        return;
     2600#endif // USE(CG)
    25762601
    25772602    if (!m_printContext)
     
    26002625        resultTotalScaleFactorForPrinting = m_printContext->computeAutomaticScaleFactor(FloatSize(printInfo.availablePaperWidth, printInfo.availablePaperHeight)) * printInfo.pageSetupScaleFactor;
    26012626    }
     2627#if USE(CG)
     2628    else {
     2629        WebFrame* frame = WebProcess::shared().webFrame(frameID);
     2630        Frame* coreFrame = frame ? frame->coreFrame() : 0;
     2631        RetainPtr<CGPDFDocumentRef> pdfDocument = coreFrame ? pdfDocumentForPrintingFrame(coreFrame) : 0;
     2632        if (pdfDocument && CGPDFDocumentAllowsPrinting(pdfDocument.get())) {
     2633            CFIndex pageCount = CGPDFDocumentGetNumberOfPages(pdfDocument.get());
     2634            IntRect pageRect(0, 0, ceilf(printInfo.availablePaperWidth), ceilf(printInfo.availablePaperHeight));
     2635            for (CFIndex i = 1; i <= pageCount; ++i) {
     2636                resultPageRects.append(pageRect);
     2637                pageRect.move(0, pageRect.height());
     2638            }
     2639        }
     2640    }
     2641#endif // USE(CG)
    26022642
    26032643    // If we're asked to print, we should actually print at least a blank page.
     
    26082648}
    26092649
     2650#if USE(CG)
     2651static inline CGFloat roundCGFloat(CGFloat f)
     2652{
     2653    if (sizeof(CGFloat) == sizeof(float))
     2654        return roundf(static_cast<float>(f));
     2655    return static_cast<CGFloat>(round(f));
     2656}
     2657
     2658static void drawPDFPage(CGPDFDocumentRef pdfDocument, CFIndex pageIndex, CGContextRef context, CGFloat pageSetupScaleFactor, CGSize paperSize)
     2659{
     2660    CGContextSaveGState(context);
     2661
     2662    CGContextScaleCTM(context, pageSetupScaleFactor, pageSetupScaleFactor);
     2663
     2664    CGPDFPageRef page = CGPDFDocumentGetPage(pdfDocument, pageIndex + 1);
     2665    CGRect cropBox = CGPDFPageGetBoxRect(page, kCGPDFCropBox);
     2666    if (CGRectIsEmpty(cropBox))
     2667        cropBox = CGRectIntersection(cropBox, CGPDFPageGetBoxRect(page, kCGPDFMediaBox));
     2668    else
     2669        cropBox = CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
     2670
     2671    bool shouldRotate = (paperSize.width < paperSize.height) != (cropBox.size.width < cropBox.size.height);
     2672    if (shouldRotate)
     2673        swap(cropBox.size.width, cropBox.size.height);
     2674
     2675    // Center.
     2676    CGFloat widthDifference = paperSize.width / pageSetupScaleFactor - cropBox.size.width;
     2677    CGFloat heightDifference = paperSize.height / pageSetupScaleFactor - cropBox.size.height;
     2678    if (widthDifference || heightDifference)
     2679        CGContextTranslateCTM(context, roundCGFloat(widthDifference / 2), roundCGFloat(heightDifference / 2));
     2680
     2681    if (shouldRotate) {
     2682        CGContextRotateCTM(context, M_PI_2);
     2683        CGContextTranslateCTM(context, 0, -cropBox.size.width);
     2684    }
     2685
     2686    CGContextDrawPDFPage(context, page);
     2687
     2688    CGContextRestoreGState(context);
     2689}
     2690#endif // USE(CG)
     2691
    26102692#if PLATFORM(MAC) || PLATFORM(WIN)
    2611 void WebPage::drawRectToPDF(uint64_t frameID, const WebCore::IntRect& rect, uint64_t callbackID)
     2693void WebPage::drawRectToPDF(uint64_t frameID, const PrintInfo& printInfo, const WebCore::IntRect& rect, uint64_t callbackID)
    26122694{
    26132695    WebFrame* frame = WebProcess::shared().webFrame(frameID);
     
    26172699
    26182700    if (coreFrame) {
    2619         ASSERT(coreFrame->document()->printing());
     2701        ASSERT(coreFrame->document()->printing()
     2702#if USE(CG)
     2703            || pdfDocumentForPrintingFrame(coreFrame)
     2704#endif
     2705        );
    26202706
    26212707#if USE(CG)
     
    26282714        CGPDFContextBeginPage(context.get(), pageInfo.get());
    26292715
    2630         GraphicsContext ctx(context.get());
    2631         ctx.scale(FloatSize(1, -1));
    2632         ctx.translate(0, -rect.height());
    2633         m_printContext->spoolRect(ctx, rect);
     2716        if (RetainPtr<CGPDFDocumentRef> pdfDocument = pdfDocumentForPrintingFrame(coreFrame)) {
     2717            CFIndex pageCount = CGPDFDocumentGetNumberOfPages(pdfDocument.get());
     2718            IntSize paperSize(ceilf(printInfo.availablePaperWidth), ceilf(printInfo.availablePaperHeight));
     2719            IntRect pageRect(IntPoint(), paperSize);
     2720            for (CFIndex i = 0; i < pageCount; ++i) {
     2721                if (pageRect.intersects(rect)) {
     2722                    CGContextSaveGState(context.get());
     2723
     2724                    CGContextTranslateCTM(context.get(), pageRect.x() - rect.x(), pageRect.y() - rect.y());
     2725                    drawPDFPage(pdfDocument.get(), i, context.get(), printInfo.pageSetupScaleFactor, paperSize);
     2726
     2727                    CGContextRestoreGState(context.get());
     2728                }
     2729                pageRect.move(0, pageRect.height());
     2730            }
     2731        } else {
     2732            GraphicsContext ctx(context.get());
     2733            ctx.scale(FloatSize(1, -1));
     2734            ctx.translate(0, -rect.height());
     2735            m_printContext->spoolRect(ctx, rect);
     2736        }
    26342737
    26352738        CGPDFContextEndPage(context.get());
    26362739        CGPDFContextClose(context.get());
     2740#else
     2741        UNUSED_PARAM(printInfo);
    26372742#endif
    26382743    }
     
    26412746}
    26422747
    2643 void WebPage::drawPagesToPDF(uint64_t frameID, uint32_t first, uint32_t count, uint64_t callbackID)
     2748void WebPage::drawPagesToPDF(uint64_t frameID, const PrintInfo& printInfo, uint32_t first, uint32_t count, uint64_t callbackID)
    26442749{
    26452750    WebFrame* frame = WebProcess::shared().webFrame(frameID);
     
    26492754
    26502755    if (coreFrame) {
    2651         ASSERT(coreFrame->document()->printing());
    2652 
     2756
     2757        ASSERT(coreFrame->document()->printing()
    26532758#if USE(CG)
     2759            || pdfDocumentForPrintingFrame(coreFrame)
     2760#endif
     2761        );
     2762
     2763#if USE(CG)
     2764        RetainPtr<CGPDFDocumentRef> pdfDocument = pdfDocumentForPrintingFrame(coreFrame);
     2765
    26542766        // FIXME: Use CGDataConsumerCreate with callbacks to avoid copying the data.
    26552767        RetainPtr<CGDataConsumerRef> pdfDataConsumer(AdoptCF, CGDataConsumerCreateWithCFData(pdfPageData.get()));
    26562768
    2657         CGRect mediaBox = m_printContext->pageCount() ? m_printContext->pageRect(0) : CGRectMake(0, 0, 1, 1);
     2769        CGRect mediaBox = m_printContext && m_printContext->pageCount() ? m_printContext->pageRect(0) : CGRectMake(0, 0, printInfo.availablePaperWidth, printInfo.availablePaperHeight);
    26582770        RetainPtr<CGContextRef> context(AdoptCF, CGPDFContextCreate(pdfDataConsumer.get(), &mediaBox, 0));
     2771        size_t pageCount = m_printContext ? m_printContext->pageCount() : CGPDFDocumentGetNumberOfPages(pdfDocument.get());
    26592772        for (uint32_t page = first; page < first + count; ++page) {
    2660             if (page >= m_printContext->pageCount())
     2773            if (page >= pageCount)
    26612774                break;
    26622775
     
    26642777            CGPDFContextBeginPage(context.get(), pageInfo.get());
    26652778
    2666             GraphicsContext ctx(context.get());
    2667             ctx.scale(FloatSize(1, -1));
    2668             ctx.translate(0, -m_printContext->pageRect(page).height());
    2669             m_printContext->spoolPage(ctx, page, m_printContext->pageRect(page).width());
     2779            if (pdfDocument)
     2780                drawPDFPage(pdfDocument.get(), page, context.get(), printInfo.pageSetupScaleFactor, CGSizeMake(printInfo.availablePaperWidth, printInfo.availablePaperHeight));
     2781            else {
     2782                GraphicsContext ctx(context.get());
     2783                ctx.scale(FloatSize(1, -1));
     2784                ctx.translate(0, -m_printContext->pageRect(page).height());
     2785                m_printContext->spoolPage(ctx, page, m_printContext->pageRect(page).width());
     2786            }
    26702787
    26712788            CGPDFContextEndPage(context.get());
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h

    r103277 r103858  
    429429    void computePagesForPrinting(uint64_t frameID, const PrintInfo&, uint64_t callbackID);
    430430#if PLATFORM(MAC) || PLATFORM(WIN)
    431     void drawRectToPDF(uint64_t frameID, const WebCore::IntRect&, uint64_t callbackID);
    432     void drawPagesToPDF(uint64_t frameID, uint32_t first, uint32_t count, uint64_t callbackID);
     431    void drawRectToPDF(uint64_t frameID, const PrintInfo&, const WebCore::IntRect&, uint64_t callbackID);
     432    void drawPagesToPDF(uint64_t frameID, const PrintInfo&, uint32_t first, uint32_t count, uint64_t callbackID);
    433433#endif
    434434
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in

    r103277 r103858  
    180180    ComputePagesForPrinting(uint64_t frameID, WebKit::PrintInfo printInfo, uint64_t callbackID)
    181181#if PLATFORM(MAC) || PLATFORM(WIN)
    182     DrawRectToPDF(uint64_t frameID, WebCore::IntRect rect, uint64_t callbackID)
    183     DrawPagesToPDF(uint64_t frameID, uint32_t first, uint32_t count, uint64_t callbackID)
     182    DrawRectToPDF(uint64_t frameID, WebKit::PrintInfo printInfo, WebCore::IntRect rect, uint64_t callbackID)
     183    DrawPagesToPDF(uint64_t frameID, WebKit::PrintInfo printInfo, uint32_t first, uint32_t count, uint64_t callbackID)
    184184#endif
    185185
Note: See TracChangeset for help on using the changeset viewer.