Commit ce23bf69 authored by ap@apple.com's avatar ap@apple.com
Browse files

[Mac] USPS Shipping label prints without barcode

https://bugs.webkit.org/show_bug.cgi?id=84099
<rdar://problem/11133877>

Reviewed by Sam Weinig.

Use PDFDocuemnt instead of CGPDFDocument when printing PDFs, because PDFKit knows
how to draw PDF buttons, and CG does not.

* Shared/mac/PDFKitImports.h: Added.
* Shared/mac/PDFKitImports.mm: Added.
* UIProcess/API/mac/WKPrintingView.mm:
Moved code for dealing with dynamically loaded PDFKit from WKPrintingView, as we
now also need it elsewhere.

* WebKit2.xcodeproj/project.pbxproj: Added
* WebProcess/Plugins/PDF/BuiltInPDFView.cpp: Rebamed to .mm.

* WebProcess/Plugins/PDF/BuiltInPDFView.h: Changed m_pdfDocument to PDFDocument.

* WebProcess/Plugins/PDF/BuiltInPDFView.mm: Copied from Source/WebKit2/WebProcess/Plugins/PDF/BuiltInPDFView.cpp.
(WebKit::BuiltInPDFView::pdfDocumentDidLoad):
(WebKit::BuiltInPDFView::calculateSizes):
(WebKit::BuiltInPDFView::paintContent):
Changed m_pdfDocument to PDFDocument, and updated for the changes. We still use
CGPDF when drawing to screen though, because that doesn't affect USPS.

* WebProcess/Plugins/Plugin.h: (WebKit::Plugin::pdfDocumentForPrinting): Updated
the type, and changed ifsed from CG to MAC, as we're now fully dependent on Cocoa.

* WebProcess/Plugins/PluginView.h: (WebKit::PluginView::pdfDocumentForPrinting):
Ditto.

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::pdfDocumentForPrintingFrame):
(WebKit::WebPage::beginPrinting):
(WebKit::WebPage::computePagesForPrinting):
(WebKit::WebPage::drawRectToPDF):
(WebKit::WebPage::drawPagesToPDF):
* WebProcess/WebPage/WebPage.h:
Moved PDF document printing code to WebPageMac.mm, as it's now Objective C.

* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::computePagesForPrintingPDFDocument):
(WebKit::roundCGFloat):
(WebKit::drawPDFPage): While moving, also fixed a logic error in calculating the box
(it used to intersect with an empty box).
(WebKit::WebPage::drawRectToPDFFromPDFDocument):
(WebKit::WebPage::drawPagesToPDFFromPDFDocument):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@114476 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent c2521457
2012-04-17 Alexey Proskuryakov <ap@apple.com>
[Mac] USPS Shipping label prints without barcode
https://bugs.webkit.org/show_bug.cgi?id=84099
<rdar://problem/11133877>
Reviewed by Sam Weinig.
Use PDFDocuemnt instead of CGPDFDocument when printing PDFs, because PDFKit knows
how to draw PDF buttons, and CG does not.
* Shared/mac/PDFKitImports.h: Added.
* Shared/mac/PDFKitImports.mm: Added.
* UIProcess/API/mac/WKPrintingView.mm:
Moved code for dealing with dynamically loaded PDFKit from WKPrintingView, as we
now also need it elsewhere.
* WebKit2.xcodeproj/project.pbxproj: Added
* WebProcess/Plugins/PDF/BuiltInPDFView.cpp: Rebamed to .mm.
* WebProcess/Plugins/PDF/BuiltInPDFView.h: Changed m_pdfDocument to PDFDocument.
* WebProcess/Plugins/PDF/BuiltInPDFView.mm: Copied from Source/WebKit2/WebProcess/Plugins/PDF/BuiltInPDFView.cpp.
(WebKit::BuiltInPDFView::pdfDocumentDidLoad):
(WebKit::BuiltInPDFView::calculateSizes):
(WebKit::BuiltInPDFView::paintContent):
Changed m_pdfDocument to PDFDocument, and updated for the changes. We still use
CGPDF when drawing to screen though, because that doesn't affect USPS.
* WebProcess/Plugins/Plugin.h: (WebKit::Plugin::pdfDocumentForPrinting): Updated
the type, and changed ifsed from CG to MAC, as we're now fully dependent on Cocoa.
* WebProcess/Plugins/PluginView.h: (WebKit::PluginView::pdfDocumentForPrinting):
Ditto.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::pdfDocumentForPrintingFrame):
(WebKit::WebPage::beginPrinting):
(WebKit::WebPage::computePagesForPrinting):
(WebKit::WebPage::drawRectToPDF):
(WebKit::WebPage::drawPagesToPDF):
* WebProcess/WebPage/WebPage.h:
Moved PDF document printing code to WebPageMac.mm, as it's now Objective C.
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::computePagesForPrintingPDFDocument):
(WebKit::roundCGFloat):
(WebKit::drawPDFPage): While moving, also fixed a logic error in calculating the box
(it used to intersect with an empty box).
(WebKit::WebPage::drawRectToPDFFromPDFDocument):
(WebKit::WebPage::drawPagesToPDFFromPDFDocument):
2012-04-17 Anders Carlsson <andersca@apple.com>
 
Need a client callback for when the user tires to interact with an already unresponsive page
/*
* Copyright (C) 2012 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef PDFKitImports_h
#define PDFKitImports_h
namespace WebKit {
NSString *pdfKitFrameworkPath();
Class classFromPDFKit(NSString *className);
Class pdfAnnotationLinkClass();
Class pdfDocumentClass();
}
#endif // PDFKitImports_h
/*
* Copyright (C) 2012 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "PDFKitImports.h"
namespace WebKit {
NSString *pdfKitFrameworkPath()
{
NSString *systemLibraryPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSSystemDomainMask, NO) objectAtIndex:0];
return [systemLibraryPath stringByAppendingPathComponent:@"Frameworks/Quartz.framework/Frameworks/PDFKit.framework"];
}
Class classFromPDFKit(NSString *className)
{
static NSBundle *pdfKitBundle = [NSBundle bundleWithPath:pdfKitFrameworkPath()];
[pdfKitBundle load];
return [pdfKitBundle classNamed:className];
}
Class pdfAnnotationLinkClass()
{
static Class pdfAnnotationLinkClass = classFromPDFKit(@"PDFAnnotationLink");
ASSERT(pdfAnnotationLinkClass);
return pdfAnnotationLinkClass;
}
Class pdfDocumentClass()
{
static Class pdfDocumentClass = classFromPDFKit(@"PDFDocument");
ASSERT(pdfDocumentClass);
return pdfDocumentClass;
}
}
......@@ -27,6 +27,7 @@
#import "WKPrintingView.h"
#import "Logging.h"
#import "PDFKitImports.h"
#import "PrintInfo.h"
#import "WebData.h"
#import "WebPageProxy.h"
......@@ -411,33 +412,6 @@ static void prepareDataForPrintingOnSecondaryThread(void* untypedContext)
return 0; // Invalid page number.
}
static NSString *pdfKitFrameworkPath()
{
NSString *systemLibraryPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSSystemDomainMask, NO) objectAtIndex:0];
return [systemLibraryPath stringByAppendingPathComponent:@"Frameworks/Quartz.framework/Frameworks/PDFKit.framework"];
}
static Class classFromPDFKit(NSString *className)
{
static NSBundle *pdfKitBundle = [NSBundle bundleWithPath:pdfKitFrameworkPath()];
[pdfKitBundle load];
return [pdfKitBundle classNamed:className];
}
static Class pdfAnnotationLinkClass()
{
static Class pdfAnnotationLinkClass = classFromPDFKit(@"PDFAnnotationLink");
ASSERT(pdfAnnotationLinkClass);
return pdfAnnotationLinkClass;
}
static Class pdfDocumentClass()
{
static Class pdfDocumentClass = classFromPDFKit(@"PDFDocument");
ASSERT(pdfDocumentClass);
return pdfDocumentClass;
}
- (void)_drawPDFDocument:(PDFDocument *)pdfDocument page:(unsigned)page atPoint:(NSPoint)point
{
if (!pdfDocument) {
......
......@@ -898,9 +898,11 @@
E17BF99614D0A73E00A5A069 /* NetscapeSandboxFunctions.h in Headers */ = {isa = PBXBuildFile; fileRef = E17BF99514D0A73E00A5A069 /* NetscapeSandboxFunctions.h */; };
E17BF99814D0AA8300A5A069 /* NetscapeSandboxFunctions.mm in Sources */ = {isa = PBXBuildFile; fileRef = E17BF99714D0AA8300A5A069 /* NetscapeSandboxFunctions.mm */; };
E18C92F412DB9E7100CF2AEB /* PrintInfo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E18C92F312DB9E7100CF2AEB /* PrintInfo.cpp */; };
E19582D3153CBFD700B60875 /* PDFKitImports.h in Headers */ = {isa = PBXBuildFile; fileRef = E19582D2153CBFD700B60875 /* PDFKitImports.h */; };
E19582D6153CC05400B60875 /* PDFKitImports.mm in Sources */ = {isa = PBXBuildFile; fileRef = E19582D4153CC05300B60875 /* PDFKitImports.mm */; };
E1967E36150AB5D500C73169 /* com.apple.WebKit.PluginProcess.sb in Resources */ = {isa = PBXBuildFile; fileRef = E1967E35150AB5D500C73169 /* com.apple.WebKit.PluginProcess.sb */; };
E1967E38150AB5E200C73169 /* com.apple.WebProcess.sb in Resources */ = {isa = PBXBuildFile; fileRef = E1967E37150AB5E200C73169 /* com.apple.WebProcess.sb */; };
E199875E142C045400BB2DE7 /* BuiltInPDFView.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E199875C142BFC9700BB2DE7 /* BuiltInPDFView.cpp */; };
E199875E142C045400BB2DE7 /* BuiltInPDFView.mm in Sources */ = {isa = PBXBuildFile; fileRef = E199875C142BFC9700BB2DE7 /* BuiltInPDFView.mm */; };
E1A31732134CEA6C007C9A4F /* AttributedString.h in Headers */ = {isa = PBXBuildFile; fileRef = E1A31731134CEA6C007C9A4F /* AttributedString.h */; };
E1A31735134CEA80007C9A4F /* AttributedString.mm in Sources */ = {isa = PBXBuildFile; fileRef = E1A31734134CEA80007C9A4F /* AttributedString.mm */; };
E1AEA22F14687BDB00804569 /* WKFullKeyboardAccessWatcher.h in Headers */ = {isa = PBXBuildFile; fileRef = E1AEA22D14687BDB00804569 /* WKFullKeyboardAccessWatcher.h */; };
......@@ -1958,10 +1960,12 @@
E17BF99714D0AA8300A5A069 /* NetscapeSandboxFunctions.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NetscapeSandboxFunctions.mm; sourceTree = "<group>"; };
E17BF99914D0CBF100A5A069 /* com.apple.WebKit.PluginProcess.sb.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = com.apple.WebKit.PluginProcess.sb.in; sourceTree = "<group>"; };
E18C92F312DB9E7100CF2AEB /* PrintInfo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PrintInfo.cpp; sourceTree = "<group>"; };
E19582D2153CBFD700B60875 /* PDFKitImports.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PDFKitImports.h; sourceTree = "<group>"; };
E19582D4153CC05300B60875 /* PDFKitImports.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PDFKitImports.mm; sourceTree = "<group>"; };
E1967E35150AB5D500C73169 /* com.apple.WebKit.PluginProcess.sb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = com.apple.WebKit.PluginProcess.sb; sourceTree = "<group>"; };
E1967E37150AB5E200C73169 /* com.apple.WebProcess.sb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = com.apple.WebProcess.sb; sourceTree = "<group>"; };
E199875A142BF9B800BB2DE7 /* BuiltInPDFView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BuiltInPDFView.h; path = PDF/BuiltInPDFView.h; sourceTree = "<group>"; };
E199875C142BFC9700BB2DE7 /* BuiltInPDFView.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = BuiltInPDFView.cpp; path = PDF/BuiltInPDFView.cpp; sourceTree = "<group>"; };
E199875C142BFC9700BB2DE7 /* BuiltInPDFView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = BuiltInPDFView.mm; path = PDF/BuiltInPDFView.mm; sourceTree = "<group>"; };
E1A31731134CEA6C007C9A4F /* AttributedString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AttributedString.h; sourceTree = "<group>"; };
E1A31734134CEA80007C9A4F /* AttributedString.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AttributedString.mm; sourceTree = "<group>"; };
E1AEA22D14687BDB00804569 /* WKFullKeyboardAccessWatcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKFullKeyboardAccessWatcher.h; sourceTree = "<group>"; };
......@@ -3172,6 +3176,8 @@
C02BFF1D1251502E009CCBEA /* NativeWebKeyboardEventMac.mm */,
31EA25D0134F78B2005B1452 /* NativeWebMouseEventMac.mm */,
DF58C6351371ACA000F9A37C /* NativeWebWheelEventMac.mm */,
E19582D2153CBFD700B60875 /* PDFKitImports.h */,
E19582D4153CC05300B60875 /* PDFKitImports.mm */,
C574A57F12E66681002DFE98 /* PasteboardTypes.h */,
C574A58012E66681002DFE98 /* PasteboardTypes.mm */,
BCF505E51243047B005955AE /* PlatformCertificateInfo.h */,
......@@ -3707,7 +3713,7 @@
E199875B142BF9CF00BB2DE7 /* PDF */ = {
isa = PBXGroup;
children = (
E199875C142BFC9700BB2DE7 /* BuiltInPDFView.cpp */,
E199875C142BFC9700BB2DE7 /* BuiltInPDFView.mm */,
E199875A142BF9B800BB2DE7 /* BuiltInPDFView.h */,
);
name = PDF;
......@@ -4185,6 +4191,7 @@
37948404150C350600E52CE9 /* WebRenderLayer.h in Headers */,
37948409150C4B9700E52CE9 /* WKRenderLayer.h in Headers */,
CEDA12E3152CD1B300D9E08D /* WebAlternativeTextClient.h in Headers */,
E19582D3153CBFD700B60875 /* PDFKitImports.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -4519,7 +4526,7 @@
1A64256912DE42EC00CAAE2C /* BackingStore.cpp in Sources */,
1A64292D12DE5F9800CAAE2C /* BackingStoreMac.mm in Sources */,
1AC41AC81263C88300054E94 /* BinarySemaphore.cpp in Sources */,
E199875E142C045400BB2DE7 /* BuiltInPDFView.cpp in Sources */,
E199875E142C045400BB2DE7 /* BuiltInPDFView.mm in Sources */,
1AA2E51E12E4C05E00BC4966 /* CGUtilities.cpp in Sources */,
1A2D957012848564001EB962 /* ChildProcess.cpp in Sources */,
1A6F9FB711E1408500DB1371 /* CommandLineMac.cpp in Sources */,
......@@ -4929,6 +4936,7 @@
37948403150C350600E52CE9 /* WebRenderLayer.cpp in Sources */,
37948408150C4B9700E52CE9 /* WKRenderLayer.cpp in Sources */,
CEDA12E2152CD1AE00D9E08D /* WebAlternativeTextClient.cpp in Sources */,
E19582D6153CC05400B60875 /* PDFKitImports.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......
/*
* Copyright (C) 2011 Apple Inc. All rights reserved.
* Copyright (C) 2011, 2012 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -114,7 +114,7 @@ private:
virtual WebCore::Scrollbar* horizontalScrollbar();
virtual WebCore::Scrollbar* verticalScrollbar();
virtual RetainPtr<CGPDFDocumentRef> pdfDocumentForPrinting() const OVERRIDE { return m_pdfDocument; }
virtual RetainPtr<PDFDocument> pdfDocumentForPrinting() const OVERRIDE { return m_pdfDocument; }
// ScrollableArea methods.
virtual WebCore::IntRect scrollCornerRect() const;
......@@ -151,7 +151,7 @@ private:
String m_suggestedFilename;
RetainPtr<CFMutableDataRef> m_dataBuffer;
RetainPtr<CGPDFDocumentRef> m_pdfDocument;
RetainPtr<PDFDocument> m_pdfDocument;
Vector<WebCore::IntRect> m_pageBoxes;
WebCore::IntSize m_pdfDocumentSize; // All pages, including gaps.
......
/*
* Copyright (C) 2009, 2011 Apple Inc. All rights reserved.
* Copyright (C) 2009, 2011, 2012 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -23,31 +23,33 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "BuiltInPDFView.h"
#include "PluginView.h"
#include "ShareableBitmap.h"
#include "WebEvent.h"
#include "WebEventConversion.h"
#include <JavaScriptCore/JSContextRef.h>
#include <JavaScriptCore/JSObjectRef.h>
#include <JavaScriptCore/JSStringRef.h>
#include <JavaScriptCore/JSStringRefCF.h>
#include <WebCore/ArchiveResource.h>
#include <WebCore/Chrome.h>
#include <WebCore/DocumentLoader.h>
#include <WebCore/FocusController.h>
#include <WebCore/Frame.h>
#include <WebCore/FrameView.h>
#include <WebCore/GraphicsContext.h>
#include <WebCore/HTTPHeaderMap.h>
#include <WebCore/LocalizedStrings.h>
#include <WebCore/Page.h>
#include <WebCore/PluginData.h>
#include <WebCore/RenderBoxModelObject.h>
#include <WebCore/ScrollAnimator.h>
#include <WebCore/ScrollbarTheme.h>
#import "config.h"
#import "BuiltInPDFView.h"
#import "PDFKitImports.h"
#import "PluginView.h"
#import "ShareableBitmap.h"
#import "WebEvent.h"
#import "WebEventConversion.h"
#import <JavaScriptCore/JSContextRef.h>
#import <JavaScriptCore/JSObjectRef.h>
#import <JavaScriptCore/JSStringRef.h>
#import <JavaScriptCore/JSStringRefCF.h>
#import <PDFKit/PDFKit.h>
#import <WebCore/ArchiveResource.h>
#import <WebCore/Chrome.h>
#import <WebCore/DocumentLoader.h>
#import <WebCore/FocusController.h>
#import <WebCore/Frame.h>
#import <WebCore/FrameView.h>
#import <WebCore/GraphicsContext.h>
#import <WebCore/HTTPHeaderMap.h>
#import <WebCore/LocalizedStrings.h>
#import <WebCore/Page.h>
#import <WebCore/PluginData.h>
#import <WebCore/RenderBoxModelObject.h>
#import <WebCore/ScrollAnimator.h>
#import <WebCore/ScrollbarTheme.h>
using namespace WebCore;
using namespace std;
......@@ -283,8 +285,7 @@ void BuiltInPDFView::pdfDocumentDidLoad()
{
addArchiveResource();
RetainPtr<CGDataProviderRef> pdfDataProvider(AdoptCF, CGDataProviderCreateWithCFData(m_dataBuffer.get()));
m_pdfDocument.adoptCF(CGPDFDocumentCreateWithProvider(pdfDataProvider.get()));
m_pdfDocument.adoptNS([[pdfDocumentClass() alloc] initWithData:(NSData *)m_dataBuffer.get()]);
calculateSizes();
updateScrollbars();
......@@ -292,7 +293,7 @@ void BuiltInPDFView::pdfDocumentDidLoad()
controller()->invalidate(IntRect(0, 0, m_pluginSize.width(), m_pluginSize.height()));
Vector<RetainPtr<CFStringRef> > scripts;
getAllScriptsInPDFDocument(m_pdfDocument.get(), scripts);
getAllScriptsInPDFDocument([m_pdfDocument.get() documentRef], scripts);
size_t scriptCount = scripts.size();
if (!scriptCount)
......@@ -312,9 +313,9 @@ void BuiltInPDFView::pdfDocumentDidLoad()
void BuiltInPDFView::calculateSizes()
{
size_t pageCount = CGPDFDocumentGetNumberOfPages(m_pdfDocument.get());
size_t pageCount = CGPDFDocumentGetNumberOfPages([m_pdfDocument.get() documentRef]);
for (size_t i = 0; i < pageCount; ++i) {
CGPDFPageRef pdfPage = CGPDFDocumentGetPage(m_pdfDocument.get(), i + 1);
CGPDFPageRef pdfPage = CGPDFDocumentGetPage([m_pdfDocument.get() documentRef], i + 1);
ASSERT(pdfPage);
CGRect box = CGPDFPageGetBoxRect(pdfPage, kCGPDFCropBox);
......@@ -394,7 +395,7 @@ void BuiltInPDFView::paintContent(GraphicsContext* graphicsContext, const IntRec
if (pageTop > contentRect.maxY())
break;
if (pageTop + pageBox.height() + extraOffsetForCenteringY + gutterHeight >= contentRect.y()) {
CGPDFPageRef pdfPage = CGPDFDocumentGetPage(m_pdfDocument.get(), i + 1);
CGPDFPageRef pdfPage = CGPDFDocumentGetPage([m_pdfDocument.get() documentRef], i + 1);
graphicsContext->save();
graphicsContext->translate(extraOffsetForCenteringX - pageBox.x(), -extraOffsetForCenteringY - pageBox.y() - pageBox.height());
......
......@@ -35,6 +35,8 @@
#if PLATFORM(MAC)
#include "LayerHostingContext.h"
OBJC_CLASS PDFDocument;
#endif
struct NPObject;
......@@ -223,8 +225,8 @@ public:
virtual WebCore::Scrollbar* horizontalScrollbar() = 0;
virtual WebCore::Scrollbar* verticalScrollbar() = 0;
#if USE(CG)
virtual RetainPtr<CGPDFDocumentRef> pdfDocumentForPrinting() const { return 0; }
#if PLATFORM(MAC)
virtual RetainPtr<PDFDocument> pdfDocumentForPrinting() const { return 0; }
#endif
protected:
......
......@@ -66,10 +66,7 @@ public:
void windowAndViewFramesChanged(const WebCore::IntRect& windowFrameInScreenCoordinates, const WebCore::IntRect& viewFrameInWindowCoordinates);
bool sendComplexTextInput(uint64_t pluginComplexTextInputIdentifier, const String& textInput);
void setLayerHostingMode(LayerHostingMode);
#endif
#if USE(CG)
RetainPtr<CGPDFDocumentRef> pdfDocumentForPrinting() const { return m_plugin->pdfDocumentForPrinting(); }
RetainPtr<PDFDocument> pdfDocumentForPrinting() const { return m_plugin->pdfDocumentForPrinting(); }
#endif
// FIXME: Remove this; nobody should have to know about the plug-in view's renderer except the plug-in view itself.
......
......@@ -2797,8 +2797,8 @@ void WebPage::stopSpeaking()
#endif
#if USE(CG)
static RetainPtr<CGPDFDocumentRef> pdfDocumentForPrintingFrame(Frame* coreFrame)
#if PLATFORM(MAC)
RetainPtr<PDFDocument> WebPage::pdfDocumentForPrintingFrame(Frame* coreFrame)
{
Document* document = coreFrame->document();
if (!document)
......@@ -2813,7 +2813,7 @@ static RetainPtr<CGPDFDocumentRef> pdfDocumentForPrintingFrame(Frame* coreFrame)
return pluginView->pdfDocumentForPrinting();
}
#endif // USE(CG)
#endif // PLATFORM(MAC)
void WebPage::beginPrinting(uint64_t frameID, const PrintInfo& printInfo)
{
......@@ -2825,10 +2825,10 @@ void WebPage::beginPrinting(uint64_t frameID, const PrintInfo& printInfo)
if (!coreFrame)
return;
#if USE(CG)
#if PLATFORM(MAC)
if (pdfDocumentForPrintingFrame(coreFrame))
return;
#endif // USE(CG)
#endif // PLATFORM(MAC)
if (!m_printContext)
m_printContext = adoptPtr(new PrintContext(coreFrame));
......@@ -2865,21 +2865,10 @@ void WebPage::computePagesForPrinting(uint64_t frameID, const PrintInfo& printIn
resultPageRects = m_printContext->pageRects();
resultTotalScaleFactorForPrinting = m_printContext->computeAutomaticScaleFactor(FloatSize(printInfo.availablePaperWidth, printInfo.availablePaperHeight)) * printInfo.pageSetupScaleFactor;
}
#if USE(CG)
else {
WebFrame* frame = WebProcess::shared().webFrame(frameID);
Frame* coreFrame = frame ? frame->coreFrame() : 0;
RetainPtr<CGPDFDocumentRef> pdfDocument = coreFrame ? pdfDocumentForPrintingFrame(coreFrame) : 0;
if (pdfDocument && CGPDFDocumentAllowsPrinting(pdfDocument.get())) {
CFIndex pageCount = CGPDFDocumentGetNumberOfPages(pdfDocument.get());
IntRect pageRect(0, 0, ceilf(printInfo.availablePaperWidth), ceilf(printInfo.availablePaperHeight));
for (CFIndex i = 1; i <= pageCount; ++i) {
resultPageRects.append(pageRect);
pageRect.move(0, pageRect.height());
}
}
}
#endif // USE(CG)
#if PLATFORM(MAC)
else
computePagesForPrintingPDFDocument(frameID, printInfo, resultPageRects);
#endif // PLATFORM(MAC)
// If we're asked to print, we should actually print at least a blank page.
if (resultPageRects.isEmpty())
......@@ -2888,48 +2877,6 @@ void WebPage::computePagesForPrinting(uint64_t frameID, const PrintInfo& printIn
send(Messages::WebPageProxy::ComputedPagesCallback(resultPageRects, resultTotalScaleFactorForPrinting, callbackID));
}
#if USE(CG)
static inline CGFloat roundCGFloat(CGFloat f)
{
if (sizeof(CGFloat) == sizeof(float))
return roundf(static_cast<float>(f));
return static_cast<CGFloat>(round(f));
}
static void drawPDFPage(CGPDFDocumentRef pdfDocument, CFIndex pageIndex, CGContextRef context, CGFloat pageSetupScaleFactor, CGSize paperSize)
{
CGContextSaveGState(context);
CGContextScaleCTM(context, pageSetupScaleFactor, pageSetupScaleFactor);
CGPDFPageRef page = CGPDFDocumentGetPage(pdfDocument, pageIndex + 1);
CGRect cropBox = CGPDFPageGetBoxRect(page, kCGPDFCropBox);
if (CGRectIsEmpty(cropBox))
cropBox = CGRectIntersection(cropBox, CGPDFPageGetBoxRect(page, kCGPDFMediaBox));
else
cropBox = CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
bool shouldRotate = (paperSize.width < paperSize.height) != (cropBox.size.width < cropBox.size.height);
if (shouldRotate)
swap(cropBox.size.width, cropBox.size.height);
// Center.
CGFloat widthDifference = paperSize.width / pageSetupScaleFactor - cropBox.size.width;
CGFloat heightDifference = paperSize.height / pageSetupScaleFactor - cropBox.size.height;
if (widthDifference || heightDifference)
CGContextTranslateCTM(context, roundCGFloat(widthDifference / 2), roundCGFloat(heightDifference / 2));
if (shouldRotate) {
CGContextRotateCTM(context, static_cast<CGFloat>(piOverTwoDouble));
CGContextTranslateCTM(context, 0, -cropBox.size.width);
}
CGContextDrawPDFPage(context, page);
CGContextRestoreGState(context);
}
#endif // USE(CG)
#if PLATFORM(MAC) || PLATFORM(WIN)
void WebPage::drawRectToPDF(uint64_t frameID, const PrintInfo& printInfo, const WebCore::IntRect& rect, uint64_t callbackID)
{
......@@ -2939,12 +2886,11 @@ void WebPage::drawRectToPDF(uint64_t frameID, const PrintInfo& printInfo, const
RetainPtr<CFMutableDataRef> pdfPageData(AdoptCF, CFDataCreateMutable(0, 0));
if (coreFrame) {
#if !USE(CG)
UNUSED_PARAM(printInfo);
ASSERT(coreFrame->document()->printing());
#else
#if PLATFORM(MAC)
ASSERT(coreFrame->document()->printing() || pdfDocumentForPrintingFrame(coreFrame));
#else
ASSERT(coreFrame->document()->printing());
#endif
// FIXME: Use CGDataConsumerCreate with callbacks to avoid copying the data.
RetainPtr<CGDataConsumerRef> pdfDataConsumer(AdoptCF, CGDataConsumerCreateWithCFData(pdfPageData.get()));
......@@ -2954,22 +2900,13 @@ void WebPage::drawRectToPDF(uint64_t frameID, const PrintInfo& printInfo, const
RetainPtr<CFDictionaryRef> pageInfo(AdoptCF, CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
CGPDFContextBeginPage(context.get(), pageInfo.get());
if (RetainPtr<CGPDFDocumentRef> pdfDocument = pdfDocumentForPrintingFrame(coreFrame)) {
CFIndex pageCount = CGPDFDocumentGetNumberOfPages(pdfDocument.get());
IntSize paperSize(ceilf(printInfo.availablePaperWidth), ceilf(printInfo.availablePaperHeight));
IntRect pageRect(IntPoint(), paperSize);
for (CFIndex i = 0; i < pageCount; ++i) {
if (pageRect.intersects(rect)) {
CGContextSaveGState(context.get());
CGContextTranslateCTM(context.get(), pageRect.x() - rect.x(), pageRect.y() - rect.y());
drawPDFPage(pdfDocument.get(), i, context.get(), printInfo.pageSetupScaleFactor, paperSize);
CGContextRestoreGState(context.get());
}
pageRect.move(0, pageRect.height());
}
} else {
#if PLATFORM(MAC)
if (RetainPtr<PDFDocument> pdfDocument = pdfDocumentForPrintingFrame(coreFrame)) {
ASSERT(!m_printContext);
drawRectToPDFFromPDFDocument(context.get(), pdfDocument.get(), printInfo, rect);
} else
#endif
{
GraphicsContext ctx(context.get());
ctx.scale(FloatSize(1, -1));
ctx.translate(0, -rect.height());
......@@ -2978,7 +2915,6 @@ void WebPage::drawRectToPDF(uint64_t frameID, const PrintInfo& printInfo, const
CGPDFContextEndPage(context.get());
CGPDFContextClose(context.get());
#endif
}
send(Messages::WebPageProxy::DataCallback(CoreIPC::DataReference(CFDataGetBytePtr(pdfPageData.get()), CFDataGetLength(pdfPageData.get())), callbackID));
......@@ -2993,44 +2929,49 @@ void WebPage::drawPagesToPDF(uint64_t frameID, const PrintInfo& printInfo, uint3