[SCM] WebKit Debian packaging branch, webkit-1.3, updated. upstream/1.3.7-4207-g178b198
ap at apple.com
ap at apple.com
Sun Feb 20 23:07:50 UTC 2011
The following commit has been merged in the webkit-1.3 branch:
commit 0909d924eb2646f6415d28be107b461aa0a07d40
Author: ap at apple.com <ap at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Tue Jan 18 00:27:12 2011 +0000
Reviewed by Anders Carlsson and Darin Adler.
https://bugs.webkit.org/show_bug.cgi?id=52595
Make basic printing work in WebKit2
* Shared/WebPreferencesStore.h:
* UIProcess/API/C/WKPreferences.cpp:
(WKPreferencesSetShouldPrintBackgrounds):
(WKPreferencesGetShouldPrintBackgrounds):
* UIProcess/API/C/WKPreferences.h:
Implement a preference for printing backgrounds.
* Shared/PrintInfo.cpp: Added.
(WebKit::PrintInfo::encode):
(WebKit::PrintInfo::decode):
* Shared/PrintInfo.h: Added.
* Shared/mac/PrintInfoMac.mm: Added.
(WebKit::PrintInfo::PrintInfo):
A new class for passing page setup information down to the web process.
* WebKit2.xcodeproj/project.pbxproj:
* GNUmakefile.am:
* WebKit2.pro:
* win/WebKit2.vcproj:
Added PrintInfo.
* Scripts/webkit2/messages.py: Added PrintInfo.h to a list of structs.
* UIProcess/API/mac/WKView.mm:
(WKViewData): Cache page count and geometry.
(WebFrameWrapper): Added a wrapper class for adding a WebFrameProxy to an NSDictionary.
(-[WKView drawRect:]): Added logging.
(setFrameBeingPrinted): Store a frame into NSPrintOperation's NSPrintInfo, so that all
methods invoked for this operation would know what's being printed.
(frameBeingPrinted): Retrieve this data.
(-[WKView printOperationWithPrintInfo:forFrame:]): Create a print operation that's appropriate
for the frame.
(-[WKView knowsPageRange:]): Ask the web process.
(-[WKView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:]):
Take over printing, because I couldn't make drawRect: work correctly with WebKit custom fit
to page implementation.
(-[WKView _provideTotalScaleFactorForPrintOperation:]): Help AppKit clip correctly.
(-[WKView rectForPage:]): Return a pre-calculated rect.
* UIProcess/WebPageProxy.h: Added m_isInPrintingMode to track whether the web page is in
printing mode. The UI process controls that.
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::WebPageProxy): Initialize m_isInPrintingMode.
(WebKit::WebPageProxy::beginPrinting): Change printing mode in web process if the value changes.
(WebKit::WebPageProxy::endPrinting): Ditto.
(WebKit::WebPageProxy::computePagesForPrinting): Ask the web process about output page geometry.
(WebKit::WebPageProxy::drawRectToPDF): Ask the web process about printed page data.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::close): Delete m_printContext while there is still a Frame pointer.
(WebKit::WebPage::updatePreferences): Pass through ShouldPrintBackgrounds.
(WebKit::WebPage::beginPrinting): Switch into printing mode (or update parameters if we're
already in printing mode).
(WebKit::WebPage::endPrinting): Delete m_printContext, implicitly calling end().
(WebKit::WebPage::computePagesForPrinting): Make sure that we're in printing mode, and
copmute page rects.
(WebKit::WebPage::drawRectToPDF): Added a CG specific function to create a PDF document out
of a page rect. It should really work for onscreen content, but we only need it for printing.
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in: Added BeginPrinting, EndPrinting,
ComputePagesForPrinting and DrawRectToPDF.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@75979 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebKit2/ChangeLog b/Source/WebKit2/ChangeLog
index c836cfa..eb21be7 100644
--- a/Source/WebKit2/ChangeLog
+++ b/Source/WebKit2/ChangeLog
@@ -1,3 +1,75 @@
+2011-01-17 Alexey Proskuryakov <ap at apple.com>
+
+ Reviewed by Anders Carlsson and Darin Adler.
+
+ https://bugs.webkit.org/show_bug.cgi?id=52595
+ Make basic printing work in WebKit2
+
+ * Shared/WebPreferencesStore.h:
+ * UIProcess/API/C/WKPreferences.cpp:
+ (WKPreferencesSetShouldPrintBackgrounds):
+ (WKPreferencesGetShouldPrintBackgrounds):
+ * UIProcess/API/C/WKPreferences.h:
+ Implement a preference for printing backgrounds.
+
+ * Shared/PrintInfo.cpp: Added.
+ (WebKit::PrintInfo::encode):
+ (WebKit::PrintInfo::decode):
+ * Shared/PrintInfo.h: Added.
+ * Shared/mac/PrintInfoMac.mm: Added.
+ (WebKit::PrintInfo::PrintInfo):
+ A new class for passing page setup information down to the web process.
+
+ * WebKit2.xcodeproj/project.pbxproj:
+ * GNUmakefile.am:
+ * WebKit2.pro:
+ * win/WebKit2.vcproj:
+ Added PrintInfo.
+
+ * Scripts/webkit2/messages.py: Added PrintInfo.h to a list of structs.
+
+ * UIProcess/API/mac/WKView.mm:
+ (WKViewData): Cache page count and geometry.
+ (WebFrameWrapper): Added a wrapper class for adding a WebFrameProxy to an NSDictionary.
+ (-[WKView drawRect:]): Added logging.
+ (setFrameBeingPrinted): Store a frame into NSPrintOperation's NSPrintInfo, so that all
+ methods invoked for this operation would know what's being printed.
+ (frameBeingPrinted): Retrieve this data.
+ (-[WKView printOperationWithPrintInfo:forFrame:]): Create a print operation that's appropriate
+ for the frame.
+ (-[WKView knowsPageRange:]): Ask the web process.
+ (-[WKView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:]):
+ Take over printing, because I couldn't make drawRect: work correctly with WebKit custom fit
+ to page implementation.
+ (-[WKView _provideTotalScaleFactorForPrintOperation:]): Help AppKit clip correctly.
+ (-[WKView rectForPage:]): Return a pre-calculated rect.
+
+ * UIProcess/WebPageProxy.h: Added m_isInPrintingMode to track whether the web page is in
+ printing mode. The UI process controls that.
+
+ * UIProcess/WebPageProxy.cpp:
+ (WebKit::WebPageProxy::WebPageProxy): Initialize m_isInPrintingMode.
+ (WebKit::WebPageProxy::beginPrinting): Change printing mode in web process if the value changes.
+ (WebKit::WebPageProxy::endPrinting): Ditto.
+ (WebKit::WebPageProxy::computePagesForPrinting): Ask the web process about output page geometry.
+ (WebKit::WebPageProxy::drawRectToPDF): Ask the web process about printed page data.
+
+ * WebProcess/WebPage/WebPage.cpp:
+ (WebKit::WebPage::close): Delete m_printContext while there is still a Frame pointer.
+ (WebKit::WebPage::updatePreferences): Pass through ShouldPrintBackgrounds.
+ (WebKit::WebPage::beginPrinting): Switch into printing mode (or update parameters if we're
+ already in printing mode).
+ (WebKit::WebPage::endPrinting): Delete m_printContext, implicitly calling end().
+ (WebKit::WebPage::computePagesForPrinting): Make sure that we're in printing mode, and
+ copmute page rects.
+ (WebKit::WebPage::drawRectToPDF): Added a CG specific function to create a PDF document out
+ of a page rect. It should really work for onscreen content, but we only need it for printing.
+
+ * WebProcess/WebPage/WebPage.h:
+
+ * WebProcess/WebPage/WebPage.messages.in: Added BeginPrinting, EndPrinting,
+ ComputePagesForPrinting and DrawRectToPDF.
+
2011-01-17 Tony Gentilcore <tonyg at chromium.org>
Reviewed by Alexey Proskuryakov.
diff --git a/Source/WebKit2/GNUmakefile.am b/Source/WebKit2/GNUmakefile.am
index ddc4d12..be64c8e 100644
--- a/Source/WebKit2/GNUmakefile.am
+++ b/Source/WebKit2/GNUmakefile.am
@@ -184,6 +184,8 @@ libWebKit2_la_SOURCES = \
Source/WebKit2/Shared/OriginAndDatabases.h \
Source/WebKit2/Shared/PlatformPopupMenuData.cpp \
Source/WebKit2/Shared/PlatformPopupMenuData.h \
+ Source/WebKit2/Shared/PrintInfo.cpp \
+ Source/WebKit2/Shared/PrintInfo.h \
Source/WebKit2/Shared/Plugins/Netscape/NetscapePluginModule.cpp \
Source/WebKit2/Shared/Plugins/Netscape/NetscapePluginModule.h \
Source/WebKit2/Shared/Plugins/Netscape/x11/NetscapePluginModuleX11.cpp \
diff --git a/Source/WebKit2/Scripts/webkit2/messages.py b/Source/WebKit2/Scripts/webkit2/messages.py
index 6b6431e..8fc0eaa 100644
--- a/Source/WebKit2/Scripts/webkit2/messages.py
+++ b/Source/WebKit2/Scripts/webkit2/messages.py
@@ -252,6 +252,7 @@ def struct_or_class(namespace, type):
'WebCore::CompositionUnderline',
'WebCore::KeypressCommand',
'WebCore::PluginInfo',
+ 'WebCore::PrintInfo',
'WebCore::ViewportArguments',
'WebCore::WindowFeatures',
'WebKit::DrawingAreaInfo',
diff --git a/Source/WebKit2/Shared/PrintInfo.cpp b/Source/WebKit2/Shared/PrintInfo.cpp
new file mode 100644
index 0000000..6c27a73
--- /dev/null
+++ b/Source/WebKit2/Shared/PrintInfo.cpp
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2011 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.
+ */
+
+#import "PrintInfo.h"
+
+#include "ArgumentDecoder.h"
+#include "ArgumentEncoder.h"
+#include "Arguments.h"
+
+namespace WebKit {
+
+PrintInfo::PrintInfo()
+ : pageSetupScaleFactor(0)
+ , availablePaperWidth(0)
+ , availablePaperHeight(0)
+{
+}
+
+void PrintInfo::encode(CoreIPC::ArgumentEncoder* encoder) const
+{
+ encoder->encode(CoreIPC::In(pageSetupScaleFactor, availablePaperWidth, availablePaperHeight));
+}
+
+bool PrintInfo::decode(CoreIPC::ArgumentDecoder* decoder, PrintInfo& info)
+{
+ return decoder->decode(CoreIPC::Out(info.pageSetupScaleFactor, info.availablePaperWidth, info.availablePaperHeight));
+}
+
+}
diff --git a/Source/WebKit2/Shared/PrintInfo.h b/Source/WebKit2/Shared/PrintInfo.h
new file mode 100644
index 0000000..d6ccd4a
--- /dev/null
+++ b/Source/WebKit2/Shared/PrintInfo.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2011 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 PrintInfo_h
+#define PrintInfo_h
+
+#include <wtf/Platform.h>
+
+#ifdef __OBJC__
+ at class NSPrintInfo;
+#else
+class NSPrintInfo;
+#endif
+
+namespace CoreIPC {
+ class ArgumentDecoder;
+ class ArgumentEncoder;
+}
+
+namespace WebKit {
+
+struct PrintInfo {
+ PrintInfo();
+ explicit PrintInfo(NSPrintInfo *);
+
+ float pageSetupScaleFactor;
+ float availablePaperWidth;
+ float availablePaperHeight;
+
+ void encode(CoreIPC::ArgumentEncoder*) const;
+ static bool decode(CoreIPC::ArgumentDecoder*, PrintInfo&);
+};
+
+}
+
+#endif
diff --git a/Source/WebKit2/Shared/WebPreferencesStore.h b/Source/WebKit2/Shared/WebPreferencesStore.h
index 28a6f48..e8cf244 100644
--- a/Source/WebKit2/Shared/WebPreferencesStore.h
+++ b/Source/WebKit2/Shared/WebPreferencesStore.h
@@ -64,6 +64,7 @@ namespace WebKit {
macro(AuthorAndUserStylesEnabled, authorAndUserStylesEnabled, Bool, bool, true) \
macro(PaginateDuringLayoutEnabled, paginateDuringLayoutEnabled, Bool, bool, false) \
macro(DOMPasteAllowed, domPasteAllowed, Bool, bool, false) \
+ macro(ShouldPrintBackgrounds, shouldPrintBackgrounds, Bool, bool, false) \
\
#define FOR_EACH_WEBKIT_DOUBLE_PREFERENCE(macro) \
diff --git a/Source/WebKit2/Shared/mac/PrintInfoMac.mm b/Source/WebKit2/Shared/mac/PrintInfoMac.mm
new file mode 100644
index 0000000..78cf9df
--- /dev/null
+++ b/Source/WebKit2/Shared/mac/PrintInfoMac.mm
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2011 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.
+ */
+
+#import "PrintInfo.h"
+
+namespace WebKit {
+
+PrintInfo::PrintInfo(NSPrintInfo *printInfo)
+ : pageSetupScaleFactor([[[printInfo dictionary] objectForKey:NSPrintScalingFactor] floatValue])
+ , availablePaperWidth([printInfo paperSize].width - [printInfo leftMargin] - [printInfo rightMargin])
+ , availablePaperHeight([printInfo paperSize].height - [printInfo topMargin] - [printInfo bottomMargin])
+{
+ ASSERT(printInfo);
+}
+
+}
diff --git a/Source/WebKit2/UIProcess/API/C/WKPreferences.cpp b/Source/WebKit2/UIProcess/API/C/WKPreferences.cpp
index 598e4e9..379859c 100644
--- a/Source/WebKit2/UIProcess/API/C/WKPreferences.cpp
+++ b/Source/WebKit2/UIProcess/API/C/WKPreferences.cpp
@@ -390,6 +390,16 @@ bool WKPreferencesGetAuthorAndUserStylesEnabled(WKPreferencesRef preferencesRef)
return toImpl(preferencesRef)->authorAndUserStylesEnabled();
}
+void WKPreferencesSetShouldPrintBackgrounds(WKPreferencesRef preferencesRef, bool flag)
+{
+ toImpl(preferencesRef)->setShouldPrintBackgrounds(flag);
+}
+
+bool WKPreferencesGetShouldPrintBackgrounds(WKPreferencesRef preferencesRef)
+{
+ return toImpl(preferencesRef)->shouldPrintBackgrounds();
+}
+
void WKPreferencesSetWebArchiveDebugModeEnabled(WKPreferencesRef preferencesRef, bool enabled)
{
toImpl(preferencesRef)->setWebArchiveDebugModeEnabled(enabled);
diff --git a/Source/WebKit2/UIProcess/API/C/WKPreferences.h b/Source/WebKit2/UIProcess/API/C/WKPreferences.h
index 29dda64..8116575 100644
--- a/Source/WebKit2/UIProcess/API/C/WKPreferences.h
+++ b/Source/WebKit2/UIProcess/API/C/WKPreferences.h
@@ -142,6 +142,10 @@ WK_EXPORT bool WKPreferencesGetDNSPrefetchingEnabled(WKPreferencesRef preference
WK_EXPORT void WKPreferencesSetAuthorAndUserStylesEnabled(WKPreferencesRef preferences, bool enabled);
WK_EXPORT bool WKPreferencesGetAuthorAndUserStylesEnabled(WKPreferencesRef preferences);
+// Defaults to false.
+WK_EXPORT void WKPreferencesSetShouldPrintBackgrounds(WKPreferencesRef preferences, bool shouldPrintBackgrounds);
+WK_EXPORT bool WKPreferencesGetShouldPrintBackgrounds(WKPreferencesRef preferences);
+
#ifdef __cplusplus
}
#endif
diff --git a/Source/WebKit2/UIProcess/API/mac/WKView.mm b/Source/WebKit2/UIProcess/API/mac/WKView.mm
index f52645c..6eccc6e 100644
--- a/Source/WebKit2/UIProcess/API/mac/WKView.mm
+++ b/Source/WebKit2/UIProcess/API/mac/WKView.mm
@@ -35,6 +35,7 @@
#import "NativeWebKeyboardEvent.h"
#import "PDFViewController.h"
#import "PageClientImpl.h"
+#import "PrintInfo.h"
#import "RunLoop.h"
#import "TextChecker.h"
#import "TextCheckerState.h"
@@ -68,6 +69,10 @@
- (void)speakString:(NSString *)string;
@end
+ at interface NSView (Details)
+- (void)_recursiveDisplayRectIfNeededIgnoringOpacity:(NSRect)rect isVisibleRect:(BOOL)isVisibleRect rectIsVisibleRectForView:(NSView *)visibleView topView:(BOOL)topView;
+ at end
+
@interface NSWindow (Details)
- (NSRect)_growBoxRect;
- (BOOL)_updateGrowBoxForWindowFrameChange;
@@ -125,6 +130,9 @@ typedef HashMap<String, ValidationVector> ValidationMap;
unsigned _selectionStart;
unsigned _selectionEnd;
+ Vector<IntRect> _printingPageRects;
+ double _totalScaleFactorForPrinting;
+
bool _inBecomeFirstResponder;
bool _inResignFirstResponder;
}
@@ -133,6 +141,36 @@ typedef HashMap<String, ValidationVector> ValidationMap;
@implementation WKViewData
@end
+ at interface WebFrameWrapper : NSObject {
+ at public
+ RefPtr<WebFrameProxy> _frame;
+}
+
+- (id)initWithFrameProxy:(WebFrameProxy*)frame;
+- (WebFrameProxy*)webFrame;
+ at end
+
+ at implementation WebFrameWrapper
+
+- (id)initWithFrameProxy:(WebFrameProxy*)frame
+{
+ self = [super init];
+ if (!self)
+ return nil;
+
+ _frame = frame;
+ return self;
+}
+
+- (WebFrameProxy*)webFrame
+{
+ return _frame.get();
+}
+
+ at end
+
+NSString * const PrintedFrameKey = @"WebKitPrintedFrameKey";
+
@interface NSObject (NSTextInputContextDetails)
- (BOOL)wantsToHandleMouseEvents;
- (BOOL)handleMouseEvent:(NSEvent *)event;
@@ -1192,6 +1230,7 @@ static void extractUnderlines(NSAttributedString *string, Vector<CompositionUnde
- (void)drawRect:(NSRect)rect
{
+ LOG(View, "drawRect: x:%g, y:%g, width:%g, height:%g", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
if (useNewDrawingArea()) {
if (DrawingAreaProxyImpl* drawingArea = static_cast<DrawingAreaProxyImpl*>(_data->_page->drawingArea())) {
CGContextRef context = static_cast<CGContextRef>([[NSGraphicsContext currentContext] graphicsPort]);
@@ -1282,14 +1321,31 @@ static void extractUnderlines(NSAttributedString *string, Vector<CompositionUnde
return (NSInteger)self;
}
+static void setFrameBeingPrinted(NSPrintOperation *printOperation, WebFrameProxy* frame)
+{
+ RetainPtr<WebFrameWrapper> frameWrapper(AdoptNS, [[WebFrameWrapper alloc] initWithFrameProxy:frame]);
+ [[[printOperation printInfo] dictionary] setObject:frameWrapper.get() forKey:PrintedFrameKey];
+}
+
+static WebFrameProxy* frameBeingPrinted()
+{
+ return [[[[[NSPrintOperation currentOperation] printInfo] dictionary] objectForKey:PrintedFrameKey] webFrame];
+}
+
- (NSPrintOperation *)printOperationWithPrintInfo:(NSPrintInfo *)printInfo forFrame:(WKFrameRef)frameRef
{
+ LOG(View, "Creating an NSPrintOperation for frame '%s'", toImpl(frameRef)->url().utf8().data());
+ NSPrintOperation *printOperation;
+
// Only the top frame can currently contain a PDF view.
if (_data->_pdfViewController) {
ASSERT(toImpl(frameRef)->isMainFrame());
- return _data->_pdfViewController->makePrintOperation(printInfo);
- }
- return [NSPrintOperation printOperationWithView:self printInfo:printInfo];
+ printOperation = _data->_pdfViewController->makePrintOperation(printInfo);
+ } else
+ printOperation = [NSPrintOperation printOperationWithView:self printInfo:printInfo];
+
+ setFrameBeingPrinted(printOperation, toImpl(frameRef));
+ return printOperation;
}
- (BOOL)canChangeFrameLayout:(WKFrameRef)frameRef
@@ -1298,6 +1354,91 @@ static void extractUnderlines(NSAttributedString *string, Vector<CompositionUnde
return !toImpl(frameRef)->isMainFrame() || !_data->_pdfViewController;
}
+// Return the number of pages available for printing
+- (BOOL)knowsPageRange:(NSRangePointer)range
+{
+ LOG(View, "knowsPageRange:");
+ WebFrameProxy* frame = frameBeingPrinted();
+ ASSERT(frame);
+
+ if (frame->isMainFrame() && _data->_pdfViewController)
+ return [super knowsPageRange:range];
+
+ _data->_page->computePagesForPrinting(frame, PrintInfo([[NSPrintOperation currentOperation] printInfo]), _data->_printingPageRects, _data->_totalScaleFactorForPrinting);
+
+ *range = NSMakeRange(1, _data->_printingPageRects.size());
+ return YES;
+}
+
+// Take over printing. AppKit applies incorrect clipping, and doesn't print pages beyond the first one.
+- (void)_recursiveDisplayRectIfNeededIgnoringOpacity:(NSRect)rect isVisibleRect:(BOOL)isVisibleRect rectIsVisibleRectForView:(NSView *)visibleView topView:(BOOL)topView
+{
+ if ([NSGraphicsContext currentContextDrawingToScreen]) {
+ // FIXME:
+ _data->_page->endPrinting();
+ [super _recursiveDisplayRectIfNeededIgnoringOpacity:rect isVisibleRect:isVisibleRect rectIsVisibleRectForView:visibleView topView:topView];
+ return;
+ }
+
+ LOG(View, "Printing rect x:%g, y:%g, width:%g, height:%g", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
+
+ ASSERT(self == visibleView);
+ ASSERT(frameBeingPrinted());
+
+ WebFrameProxy* frame = frameBeingPrinted();
+ ASSERT(frame);
+
+ _data->_page->beginPrinting(frame, PrintInfo([[NSPrintOperation currentOperation] printInfo]));
+
+ // FIXME: This is optimized for print preview. Get the whole document at once when actually printing.
+ Vector<uint8_t> pdfData;
+ _data->_page->drawRectToPDF(frame, IntRect(rect), pdfData);
+
+ RetainPtr<CGDataProviderRef> pdfDataProvider(AdoptCF, CGDataProviderCreateWithData(0, pdfData.data(), pdfData.size(), 0));
+ RetainPtr<CGPDFDocumentRef> pdfDocument(AdoptCF, CGPDFDocumentCreateWithProvider(pdfDataProvider.get()));
+ if (!pdfDocument) {
+ LOG_ERROR("Couldn't create a PDF document with data passed for printing");
+ return;
+ }
+
+ CGPDFPageRef pdfPage = CGPDFDocumentGetPage(pdfDocument.get(), 1);
+ if (!pdfPage) {
+ LOG_ERROR("Printing data doesn't have page 1");
+ return;
+ }
+
+ NSGraphicsContext *nsGraphicsContext = [NSGraphicsContext currentContext];
+ CGContextRef context = static_cast<CGContextRef>([nsGraphicsContext graphicsPort]);
+
+ CGContextSaveGState(context);
+ // Flip the destination.
+ CGContextScaleCTM(context, 1, -1);
+ CGContextTranslateCTM(context, 0, -rect.size.height);
+ CGContextDrawPDFPage(context, pdfPage);
+ CGContextRestoreGState(context);
+}
+
+// FIXME 3491344: This is an AppKit-internal method that we need to override in order
+// to get our shrink-to-fit to work with a custom pagination scheme. We can do this better
+// if AppKit makes it SPI/API.
+- (CGFloat)_provideTotalScaleFactorForPrintOperation:(NSPrintOperation *)printOperation
+{
+ return _data->_totalScaleFactorForPrinting;
+}
+
+// Return the drawing rectangle for a particular page number
+- (NSRect)rectForPage:(NSInteger)page
+{
+ WebFrameProxy* frame = frameBeingPrinted();
+ ASSERT(frame);
+
+ if (frame->isMainFrame() && _data->_pdfViewController)
+ return [super rectForPage:page];
+
+ LOG(View, "rectForPage:%d -> x %d, y %d, width %d, height %d\n", (int)page, _data->_printingPageRects[page - 1].x(), _data->_printingPageRects[page - 1].y(), _data->_printingPageRects[page - 1].width(), _data->_printingPageRects[page - 1].height());
+ return _data->_printingPageRects[page - 1];
+}
+
@end
@implementation WKView (Internal)
diff --git a/Source/WebKit2/UIProcess/WebPageProxy.cpp b/Source/WebKit2/UIProcess/WebPageProxy.cpp
index 650bd57..f433fbd 100644
--- a/Source/WebKit2/UIProcess/WebPageProxy.cpp
+++ b/Source/WebKit2/UIProcess/WebPageProxy.cpp
@@ -33,6 +33,7 @@
#include "MessageID.h"
#include "NativeWebKeyboardEvent.h"
#include "PageClient.h"
+#include "PrintInfo.h"
#include "SessionState.h"
#include "StringPairVector.h"
#include "TextChecker.h"
@@ -111,6 +112,7 @@ WebPageProxy::WebPageProxy(PageClient* pageClient, WebContext* context, WebPageG
, m_useFixedLayout(false)
, m_isValid(true)
, m_isClosed(false)
+ , m_isInPrintingMode(false)
, m_inDecidePolicyForMIMEType(false)
, m_syncMimeTypePolicyActionIsValid(false)
, m_syncMimeTypePolicyAction(PolicyUse)
@@ -2330,4 +2332,36 @@ void WebPageProxy::backForwardRemovedItem(uint64_t itemID)
process()->send(Messages::WebPage::DidRemoveBackForwardItem(itemID), m_pageID);
}
+void WebPageProxy::beginPrinting(WebFrameProxy* frame, const PrintInfo& printInfo)
+{
+ if (m_isInPrintingMode)
+ return;
+
+ m_isInPrintingMode = true;
+ process()->send(Messages::WebPage::BeginPrinting(frame->frameID(), printInfo), m_pageID);
+}
+
+void WebPageProxy::endPrinting()
+{
+ if (!m_isInPrintingMode)
+ return;
+
+ m_isInPrintingMode = false;
+ process()->send(Messages::WebPage::EndPrinting(), m_pageID);
+}
+
+void WebPageProxy::computePagesForPrinting(WebFrameProxy* frame, const PrintInfo& printInfo, Vector<WebCore::IntRect>& resultPageRects, double& resultTotalScaleFactorForPrinting)
+{
+ // Layout for printing can take a long time, but we need to have the answer.
+ process()->sendSync(Messages::WebPage::ComputePagesForPrinting(frame->frameID(), printInfo), Messages::WebPage::ComputePagesForPrinting::Reply(resultPageRects, resultTotalScaleFactorForPrinting), m_pageID);
+}
+
+#if PLATFORM(MAC)
+void WebPageProxy::drawRectToPDF(WebFrameProxy* frame, const IntRect& rect, Vector<uint8_t>& pdfData)
+{
+ // Printing can take a long time, but we need to have the answer.
+ process()->sendSync(Messages::WebPage::DrawRectToPDF(frame->frameID(), rect), Messages::WebPage::DrawRectToPDF::Reply(pdfData), m_pageID);
+}
+#endif
+
} // namespace WebKit
diff --git a/Source/WebKit2/UIProcess/WebPageProxy.h b/Source/WebKit2/UIProcess/WebPageProxy.h
index 74678ca..4a9e478 100644
--- a/Source/WebKit2/UIProcess/WebPageProxy.h
+++ b/Source/WebKit2/UIProcess/WebPageProxy.h
@@ -101,6 +101,7 @@ class WebProcessProxy;
class WebURLRequest;
class WebWheelEvent;
struct PlatformPopupMenuData;
+struct PrintInfo;
struct WebPageCreationParameters;
struct WebPopupItem;
@@ -341,6 +342,13 @@ public:
void setSmartInsertDeleteEnabled(bool);
#endif
+ void beginPrinting(WebFrameProxy*, const PrintInfo&);
+ void endPrinting();
+ void computePagesForPrinting(WebFrameProxy*, const PrintInfo&, Vector<WebCore::IntRect>& resultPageRects, double& resultTotalScaleFactorForPrinting);
+#if PLATFORM(MAC)
+ void drawRectToPDF(WebFrameProxy*, const WebCore::IntRect&, Vector<uint8_t>& pdfData);
+#endif
+
private:
WebPageProxy(PageClient*, WebContext*, WebPageGroup*, uint64_t pageID);
@@ -580,6 +588,8 @@ private:
// Whether WebPageProxy::close() has been called on this page.
bool m_isClosed;
+ bool m_isInPrintingMode;
+
bool m_inDecidePolicyForMIMEType;
bool m_syncMimeTypePolicyActionIsValid;
WebCore::PolicyAction m_syncMimeTypePolicyAction;
diff --git a/Source/WebKit2/WebKit2.pro b/Source/WebKit2/WebKit2.pro
index 2c8d331..f4e007b 100644
--- a/Source/WebKit2/WebKit2.pro
+++ b/Source/WebKit2/WebKit2.pro
@@ -266,6 +266,7 @@ HEADERS += \
Shared/NotImplemented.h \
Shared/OriginAndDatabases.h \
Shared/PlatformPopupMenuData.h \
+ Shared/PrintInfo.h \
Shared/SameDocumentNavigationType.h \
Shared/SessionState.h \
Shared/StringPairVector.h \
@@ -492,6 +493,7 @@ SOURCES += \
Shared/MutableDictionary.cpp \
Shared/OriginAndDatabases.cpp \
Shared/PlatformPopupMenuData.cpp \
+ Shared/PrintInfo.cpp \
Shared/SessionState.cpp \
Shared/VisitedLinkTable.cpp \
Shared/WebBackForwardListItem.cpp \
diff --git a/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj b/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj
index 80cb9f3..20143f5 100644
--- a/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj
+++ b/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj
@@ -665,6 +665,11 @@
D3B9484711FF4B6500032B39 /* WebPopupMenu.h in Headers */ = {isa = PBXBuildFile; fileRef = D3B9484311FF4B6500032B39 /* WebPopupMenu.h */; };
D3B9484811FF4B6500032B39 /* WebSearchPopupMenu.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D3B9484411FF4B6500032B39 /* WebSearchPopupMenu.cpp */; };
D3B9484911FF4B6500032B39 /* WebSearchPopupMenu.h in Headers */ = {isa = PBXBuildFile; fileRef = D3B9484511FF4B6500032B39 /* WebSearchPopupMenu.h */; };
+ E18C92F412DB9E7100CF2AEB /* PrintInfo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E18C92F312DB9E7100CF2AEB /* PrintInfo.cpp */; };
+ E18C92F512DB9E7A00CF2AEB /* PrintInfo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E18C92F312DB9E7100CF2AEB /* PrintInfo.cpp */; };
+ E18C92F612DB9E9400CF2AEB /* PrintInfoMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = E1CC1B8F12D7EADF00625838 /* PrintInfoMac.mm */; };
+ E1CC1B9012D7EADF00625838 /* PrintInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = E1CC1B8E12D7EADF00625838 /* PrintInfo.h */; };
+ E1CC1B9112D7EADF00625838 /* PrintInfoMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = E1CC1B8F12D7EADF00625838 /* PrintInfoMac.mm */; };
E1EE53E311F8CFC000CCBEE4 /* InjectedBundlePageEditorClient.h in Headers */ = {isa = PBXBuildFile; fileRef = E1EE53DC11F8CF9F00CCBEE4 /* InjectedBundlePageEditorClient.h */; };
E1EE53E711F8CFFB00CCBEE4 /* InjectedBundlePageEditorClient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1EE53E611F8CFFB00CCBEE4 /* InjectedBundlePageEditorClient.cpp */; };
ED82A7F2128C6FAF004477B3 /* WKBundlePageOverlay.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A22F0FF1289FCD90085E74F /* WKBundlePageOverlay.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -1420,6 +1425,9 @@
D3B9484311FF4B6500032B39 /* WebPopupMenu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebPopupMenu.h; sourceTree = "<group>"; };
D3B9484411FF4B6500032B39 /* WebSearchPopupMenu.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebSearchPopupMenu.cpp; sourceTree = "<group>"; };
D3B9484511FF4B6500032B39 /* WebSearchPopupMenu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebSearchPopupMenu.h; sourceTree = "<group>"; };
+ E18C92F312DB9E7100CF2AEB /* PrintInfo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PrintInfo.cpp; sourceTree = "<group>"; };
+ E1CC1B8E12D7EADF00625838 /* PrintInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PrintInfo.h; sourceTree = "<group>"; };
+ E1CC1B8F12D7EADF00625838 /* PrintInfoMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PrintInfoMac.mm; sourceTree = "<group>"; };
E1EE53DC11F8CF9F00CCBEE4 /* InjectedBundlePageEditorClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InjectedBundlePageEditorClient.h; sourceTree = "<group>"; };
E1EE53E611F8CFFB00CCBEE4 /* InjectedBundlePageEditorClient.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InjectedBundlePageEditorClient.cpp; sourceTree = "<group>"; };
F6113E24126CE1820057D0A7 /* WebUserContentURLPattern.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebUserContentURLPattern.h; sourceTree = "<group>"; };
@@ -1757,6 +1765,8 @@
BCCF672C12C7EDF7008F9C35 /* OriginAndDatabases.h */,
BCC43AB8127B95DC00317F16 /* PlatformPopupMenuData.cpp */,
BCC43AB9127B95DC00317F16 /* PlatformPopupMenuData.h */,
+ E18C92F312DB9E7100CF2AEB /* PrintInfo.cpp */,
+ E1CC1B8E12D7EADF00625838 /* PrintInfo.h */,
BC2D021612AC41CB00E732A3 /* SameDocumentNavigationType.h */,
1AAB4A8C1296F0A20023952F /* SandboxExtension.h */,
1AA41AB412C02EC4002BE67B /* SelectionState.h */,
@@ -2316,6 +2326,7 @@
C02BFF1D1251502E009CCBEA /* NativeWebKeyboardEventMac.mm */,
BCF505E61243047B005955AE /* PlatformCertificateInfo.mm */,
BCF505E51243047B005955AE /* PlatformCertificateInfo.h */,
+ E1CC1B8F12D7EADF00625838 /* PrintInfoMac.mm */,
BC9E95D211449B0300870E71 /* UpdateChunk.cpp */,
BC9E95D111449B0300870E71 /* UpdateChunk.h */,
BCE23262122C6CF300D5C35A /* WebCoreArgumentCodersMac.mm */,
@@ -3026,6 +3037,7 @@
BC1BE1F212D54DBD0004A228 /* WebGeolocationProvider.h in Headers */,
1A2C307112D555450063DAA2 /* ContextMenuState.h in Headers */,
518D2CCB12D51DFB003BB93B /* SessionState.h in Headers */,
+ E1CC1B9012D7EADF00625838 /* PrintInfo.h in Headers */,
BC54CACB12D64291005C67B0 /* WebGeolocationManagerProxy.h in Headers */,
BC54CC1212D674EE005C67B0 /* WKGeolocationManager.h in Headers */,
BC0E5FE512D697160012A72A /* WebGeolocationManager.h in Headers */,
@@ -3183,6 +3195,8 @@
1A6FA31111E3921E00DB1371 /* MainMac.cpp in Sources */,
1A1FA285127A13BC0050E709 /* NPObjectProxy.cpp in Sources */,
1A1FA35D127A45BF0050E709 /* NPObjectMessageReceiver.cpp in Sources */,
+ E18C92F512DB9E7A00CF2AEB /* PrintInfo.cpp in Sources */,
+ E18C92F612DB9E9400CF2AEB /* PrintInfoMac.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -3483,6 +3497,8 @@
BC1BE1E112D54A410004A228 /* WebGeolocationClient.cpp in Sources */,
BC1BE1F312D54DBD0004A228 /* WebGeolocationProvider.cpp in Sources */,
518D2CCA12D51DFB003BB93B /* SessionState.cpp in Sources */,
+ E1CC1B9112D7EADF00625838 /* PrintInfoMac.mm in Sources */,
+ E18C92F412DB9E7100CF2AEB /* PrintInfo.cpp in Sources */,
BC54CACC12D64291005C67B0 /* WebGeolocationManagerProxy.cpp in Sources */,
BC54CC1312D674EE005C67B0 /* WKGeolocationManager.cpp in Sources */,
BC0E5FE612D697160012A72A /* WebGeolocationManager.cpp in Sources */,
diff --git a/Source/WebKit2/WebProcess/WebPage/WebPage.cpp b/Source/WebKit2/WebProcess/WebPage/WebPage.cpp
index 97ee909..2259387 100644
--- a/Source/WebKit2/WebProcess/WebPage/WebPage.cpp
+++ b/Source/WebKit2/WebProcess/WebPage/WebPage.cpp
@@ -36,6 +36,7 @@
#include "PageOverlay.h"
#include "PluginProxy.h"
#include "PluginView.h"
+#include "PrintInfo.h"
#include "SessionState.h"
#include "ShareableBitmap.h"
#include "WebBackForwardList.h"
@@ -82,7 +83,10 @@
#include <WebCore/KeyboardEvent.h>
#include <WebCore/Page.h>
#include <WebCore/PlatformKeyboardEvent.h>
+#include <WebCore/PrintContext.h>
#include <WebCore/RenderTreeAsText.h>
+#include <WebCore/RenderLayer.h>
+#include <WebCore/RenderView.h>
#include <WebCore/ReplaceSelectionCommand.h>
#include <WebCore/ResourceRequest.h>
#include <WebCore/Settings.h>
@@ -362,6 +366,8 @@ void WebPage::close()
m_sandboxExtensionTracker.invalidate();
+ m_printContext = nullptr;
+
m_mainFrame->coreFrame()->loader()->detachFromParent();
m_page.clear();
@@ -1188,6 +1194,7 @@ void WebPage::updatePreferences(const WebPreferencesStore& store)
settings->setAuthorAndUserStylesEnabled(store.getBoolValueForKey(WebPreferencesKey::authorAndUserStylesEnabledKey()));
settings->setPaginateDuringLayoutEnabled(store.getBoolValueForKey(WebPreferencesKey::paginateDuringLayoutEnabledKey()));
settings->setDOMPasteAllowed(store.getBoolValueForKey(WebPreferencesKey::domPasteAllowedKey()));
+ settings->setShouldPrintBackgrounds(store.getBoolValueForKey(WebPreferencesKey::shouldPrintBackgroundsKey()));
settings->setMinimumFontSize(store.getUInt32ValueForKey(WebPreferencesKey::minimumFontSizeKey()));
settings->setMinimumLogicalFontSize(store.getUInt32ValueForKey(WebPreferencesKey::minimumLogicalFontSizeKey()));
@@ -1672,4 +1679,79 @@ void WebPage::stopSpeaking()
#endif
+void WebPage::beginPrinting(uint64_t frameID, const PrintInfo& printInfo)
+{
+ WebFrame* frame = WebProcess::shared().webFrame(frameID);
+ if (!frame)
+ return;
+
+ Frame* coreFrame = frame->coreFrame();
+ if (!coreFrame)
+ return;
+
+ if (!m_printContext)
+ m_printContext = adoptPtr(new PrintContext(coreFrame));
+
+ m_printContext->begin(printInfo.availablePaperWidth, printInfo.availablePaperHeight);
+}
+
+void WebPage::endPrinting()
+{
+ m_printContext = nullptr;
+}
+
+void WebPage::computePagesForPrinting(uint64_t frameID, const PrintInfo& printInfo, Vector<IntRect>& resultPageRects, double& resultTotalScaleFactorForPrinting)
+{
+ beginPrinting(frameID, printInfo);
+
+ WebFrame* frame = WebProcess::shared().webFrame(frameID);
+ if (!frame)
+ return;
+
+ float fullPageHeight;
+ m_printContext->computePageRects(FloatRect(0, 0, printInfo.availablePaperWidth, printInfo.availablePaperHeight), 0, 0, printInfo.pageSetupScaleFactor, fullPageHeight, true);
+
+ resultTotalScaleFactorForPrinting = m_printContext->computeAutomaticScaleFactor(printInfo.availablePaperWidth) * printInfo.pageSetupScaleFactor;
+ resultPageRects = m_printContext->pageRects();
+
+ // If we're asked to print, we should actually print at least a blank page.
+ if (resultPageRects.isEmpty())
+ resultPageRects.append(IntRect(0, 0, 1, 1));
+}
+
+#if PLATFORM(MAC)
+// FIXME: Find a better place for Mac specific code.
+void WebPage::drawRectToPDF(uint64_t frameID, const WebCore::IntRect& rect, Vector<uint8_t>& pdfData)
+{
+ WebFrame* frame = WebProcess::shared().webFrame(frameID);
+ if (!frame)
+ return;
+
+ Frame* coreFrame = frame->coreFrame();
+ if (!coreFrame)
+ return;
+
+ ASSERT(coreFrame->document()->printing());
+
+ RetainPtr<CFMutableDataRef> pdfPageData(AdoptCF, CFDataCreateMutable(0, 0));
+
+ // FIXME: Use CGDataConsumerCreate with callbacks to avoid copying the data.
+ RetainPtr<CGDataConsumerRef> pdfDataConsumer(AdoptCF, CGDataConsumerCreateWithCFData(pdfPageData.get()));
+
+ CGRect mediaBox = CGRectMake(0, 0, frame->size().width(), frame->size().height());
+ RetainPtr<CGContextRef> context(AdoptCF, CGPDFContextCreate(pdfDataConsumer.get(), &mediaBox, 0));
+ CFDictionaryRef pageInfo = CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
+ CGPDFContextBeginPage(context.get(), pageInfo);
+
+ GraphicsContext ctx(context.get());
+ m_printContext->spoolRect(ctx, rect);
+
+ CGPDFContextEndPage(context.get());
+ CGPDFContextClose(context.get());
+
+ pdfData.resize(CFDataGetLength(pdfPageData.get()));
+ CFDataGetBytes(pdfPageData.get(), CFRangeMake(0, pdfData.size()), pdfData.data());
+}
+#endif
+
} // namespace WebKit
diff --git a/Source/WebKit2/WebProcess/WebPage/WebPage.h b/Source/WebKit2/WebProcess/WebPage/WebPage.h
index 21ca442..7649ab6 100644
--- a/Source/WebKit2/WebProcess/WebPage/WebPage.h
+++ b/Source/WebKit2/WebProcess/WebPage/WebPage.h
@@ -72,6 +72,7 @@ namespace WebCore {
class GraphicsContext;
class KeyboardEvent;
class Page;
+ class PrintContext;
class ResourceRequest;
class SharedBuffer;
}
@@ -95,7 +96,7 @@ class WebOpenPanelResultListener;
class WebPageGroupProxy;
class WebPopupMenu;
class WebWheelEvent;
-
+struct PrintInfo;
struct WebPageCreationParameters;
struct WebPreferencesStore;
@@ -300,6 +301,13 @@ public:
void replaceSelectionWithText(WebCore::Frame*, const String&);
void performDragControllerAction(uint64_t action, WebCore::IntPoint clientPosition, WebCore::IntPoint globalPosition, uint64_t draggingSourceOperationMask, const WTF::String& dragStorageName, uint32_t flags);
+ void beginPrinting(uint64_t frameID, const PrintInfo&);
+ void endPrinting();
+ void computePagesForPrinting(uint64_t frameID, const PrintInfo&, Vector<WebCore::IntRect>& resultPageRects, double& resultTotalScaleFactorForPrinting);
+#if PLATFORM(MAC)
+ void drawRectToPDF(uint64_t frameID, const WebCore::IntRect&, Vector<uint8_t>& pdfData);
+#endif
+
bool mainFrameHasCustomRepresentation() const;
private:
@@ -480,6 +488,8 @@ private:
RefPtr<WebOpenPanelResultListener> m_activeOpenPanelResultListener;
GeolocationPermissionRequestManager m_geolocationPermissionRequestManager;
+ OwnPtr<WebCore::PrintContext> m_printContext;
+
SandboxExtensionTracker m_sandboxExtensionTracker;
uint64_t m_pageID;
};
diff --git a/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in b/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in
index 3a2e394..bd6bf1a 100644
--- a/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in
+++ b/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in
@@ -128,6 +128,14 @@ messages -> WebPage {
SetWindowResizerSize(WebCore::IntSize intersectsView)
+ # Printing.
+ BeginPrinting(uint64_t frameID, WebKit::PrintInfo printInfo);
+ EndPrinting();
+ ComputePagesForPrinting(uint64_t frameID, WebKit::PrintInfo printInfo) -> (Vector<WebCore::IntRect> pageRects, double totalScaleFactorForPrinting)
+#if PLATFORM(MAC)
+ DrawRectToPDF(uint64_t frameID, WebCore::IntRect rect) -> (Vector<uint8_t> pdfData)
+#endif
+
// FIXME: This a dummy message, to avoid breaking the build for platforms that don't require
// any synchronous messages, and should be removed when <rdar://problem/8775115> is fixed.
Dummy() -> (bool dummyReturn)
diff --git a/Source/WebKit2/win/WebKit2.vcproj b/Source/WebKit2/win/WebKit2.vcproj
index 2c548c3..0742c6e 100755
--- a/Source/WebKit2/win/WebKit2.vcproj
+++ b/Source/WebKit2/win/WebKit2.vcproj
@@ -491,6 +491,14 @@
>
</File>
<File
+ RelativePath="..\Shared\PrintInfo.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\Shared\PrintInfo.h"
+ >
+ </File>
+ <File
RelativePath="..\Shared\SameDocumentNavigationType.h"
>
</File>
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list