[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:40:07 UTC 2011
The following commit has been merged in the webkit-1.3 branch:
commit d08b07e47360a97fa8e3d56fa062393a6ef5288f
Author: ap at apple.com <ap at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Sun Jan 23 22:28:01 2011 +0000
2011-01-23 Alexey Proskuryakov <ap at apple.com>
Reviewed by Dan Bernstein.
https://bugs.webkit.org/show_bug.cgi?id=52968
Use a separate NSView for printing
Also addresses <rdar://problem/8900148> Improper check for
-[NSGraphicsContext currentContextDrawingToScreen]
* UIProcess/API/mac/WKPrintingView.h: Added.
* UIProcess/API/mac/WKPrintingView.mm: Added.
(-[WKPrintingView initWithFrameProxy:]):
(-[WKPrintingView isFlipped]):
(-[WKPrintingView _adjustPrintingMarginsForHeaderAndFooter]):
(-[WKPrintingView knowsPageRange:]):
(-[WKPrintingView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:]):
(-[WKPrintingView drawPageBorderWithSize:]):
(-[WKPrintingView _provideTotalScaleFactorForPrintOperation:]):
(-[WKPrintingView rectForPage:]):
* UIProcess/API/mac/WKView.mm:
(-[WKView drawRect:]):
(-[WKView canChangeFrameLayout:]):
(-[WKView printOperationWithPrintInfo:forFrame:]):
* WebKit2.xcodeproj/project.pbxproj:
Moved printing code to a separate view, simplifying as appropriate. The view is currently not
referenced by anything in WebKit2 directly, being owned by NSPrintOperation.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@76470 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebKit2/ChangeLog b/Source/WebKit2/ChangeLog
index d0f7682..1f79716 100644
--- a/Source/WebKit2/ChangeLog
+++ b/Source/WebKit2/ChangeLog
@@ -1,3 +1,31 @@
+2011-01-23 Alexey Proskuryakov <ap at apple.com>
+
+ Reviewed by Dan Bernstein.
+
+ https://bugs.webkit.org/show_bug.cgi?id=52968
+ Use a separate NSView for printing
+
+ Also addresses <rdar://problem/8900148> Improper check for
+ -[NSGraphicsContext currentContextDrawingToScreen]
+
+ * UIProcess/API/mac/WKPrintingView.h: Added.
+ * UIProcess/API/mac/WKPrintingView.mm: Added.
+ (-[WKPrintingView initWithFrameProxy:]):
+ (-[WKPrintingView isFlipped]):
+ (-[WKPrintingView _adjustPrintingMarginsForHeaderAndFooter]):
+ (-[WKPrintingView knowsPageRange:]):
+ (-[WKPrintingView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:]):
+ (-[WKPrintingView drawPageBorderWithSize:]):
+ (-[WKPrintingView _provideTotalScaleFactorForPrintOperation:]):
+ (-[WKPrintingView rectForPage:]):
+ * UIProcess/API/mac/WKView.mm:
+ (-[WKView drawRect:]):
+ (-[WKView canChangeFrameLayout:]):
+ (-[WKView printOperationWithPrintInfo:forFrame:]):
+ * WebKit2.xcodeproj/project.pbxproj:
+ Moved printing code to a separate view, simplifying as appropriate. The view is currently not
+ referenced by anything in WebKit2 directly, being owned by NSPrintOperation.
+
2011-01-22 Anders Carlsson <andersca at apple.com>
Reviewed by Sam Weinig.
diff --git a/Source/WebKit2/UIProcess/API/mac/WKPrintingView.h b/Source/WebKit2/UIProcess/API/mac/WKPrintingView.h
new file mode 100644
index 0000000..42e2c30
--- /dev/null
+++ b/Source/WebKit2/UIProcess/API/mac/WKPrintingView.h
@@ -0,0 +1,44 @@
+/*
+ * 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 <WebCore/IntRect.h>
+#import <wtf/RefPtr.h>
+
+ at class WKPrintingViewData;
+
+namespace WebKit {
+ class WebFrameProxy;
+}
+
+ at interface WKPrintingView : NSView {
+ at public
+ RefPtr<WebKit::WebFrameProxy> _webFrame;
+ Vector<WebCore::IntRect> _webPrintingPageRects;
+ double _webTotalScaleFactorForPrinting;
+}
+
+- (id)initWithFrameProxy:(WebKit::WebFrameProxy*)frame;
+
+ at end
diff --git a/Source/WebKit2/UIProcess/API/mac/WKPrintingView.mm b/Source/WebKit2/UIProcess/API/mac/WKPrintingView.mm
new file mode 100644
index 0000000..99b8610
--- /dev/null
+++ b/Source/WebKit2/UIProcess/API/mac/WKPrintingView.mm
@@ -0,0 +1,181 @@
+/*
+ * 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 "WKPrintingView.h"
+
+#import "Logging.h"
+#import "PrintInfo.h"
+#import "WebPageProxy.h"
+
+ at interface NSView (WebNSViewDetails)
+- (void)_recursiveDisplayRectIfNeededIgnoringOpacity:(NSRect)rect isVisibleRect:(BOOL)isVisibleRect rectIsVisibleRectForView:(NSView *)visibleView topView:(BOOL)topView;
+ at end
+
+using namespace WebKit;
+using namespace WebCore;
+
+NSString * const WebKitOriginalTopPrintingMarginKey = @"WebKitOriginalTopMargin";
+NSString * const WebKitOriginalBottomPrintingMarginKey = @"WebKitOriginalBottomMargin";
+
+ at implementation WKPrintingView
+
+- (id)initWithFrameProxy:(WebFrameProxy*)frame
+{
+ self = [super init]; // No frame rect to pass to NSView.
+ if (!self)
+ return nil;
+
+ _webFrame = frame;
+
+ return self;
+}
+
+- (BOOL)isFlipped
+{
+ return YES;
+}
+
+- (void)_adjustPrintingMarginsForHeaderAndFooter
+{
+ NSPrintOperation *printOperation = [NSPrintOperation currentOperation];
+ NSPrintInfo *info = [printOperation printInfo];
+ NSMutableDictionary *infoDictionary = [info dictionary];
+
+ // We need to modify the top and bottom margins in the NSPrintInfo to account for the space needed by the
+ // header and footer. Because this method can be called more than once on the same NSPrintInfo (see 5038087),
+ // we stash away the unmodified top and bottom margins the first time this method is called, and we read from
+ // those stashed-away values on subsequent calls.
+ double originalTopMargin;
+ double originalBottomMargin;
+ NSNumber *originalTopMarginNumber = [infoDictionary objectForKey:WebKitOriginalTopPrintingMarginKey];
+ if (!originalTopMarginNumber) {
+ ASSERT(![infoDictionary objectForKey:WebKitOriginalBottomPrintingMarginKey]);
+ originalTopMargin = [info topMargin];
+ originalBottomMargin = [info bottomMargin];
+ [infoDictionary setObject:[NSNumber numberWithDouble:originalTopMargin] forKey:WebKitOriginalTopPrintingMarginKey];
+ [infoDictionary setObject:[NSNumber numberWithDouble:originalBottomMargin] forKey:WebKitOriginalBottomPrintingMarginKey];
+ } else {
+ ASSERT([originalTopMarginNumber isKindOfClass:[NSNumber class]]);
+ ASSERT([[infoDictionary objectForKey:WebKitOriginalBottomPrintingMarginKey] isKindOfClass:[NSNumber class]]);
+ originalTopMargin = [originalTopMarginNumber doubleValue];
+ originalBottomMargin = [[infoDictionary objectForKey:WebKitOriginalBottomPrintingMarginKey] doubleValue];
+ }
+
+ CGFloat scale = [info scalingFactor];
+ [info setTopMargin:originalTopMargin + _webFrame->page()->headerHeight(_webFrame.get()) * scale];
+ [info setBottomMargin:originalBottomMargin + _webFrame->page()->footerHeight(_webFrame.get()) * scale];
+}
+
+- (BOOL)knowsPageRange:(NSRangePointer)range
+{
+ LOG(View, "knowsPageRange:");
+ [self _adjustPrintingMarginsForHeaderAndFooter];
+
+ _webFrame->page()->computePagesForPrinting(_webFrame.get(), PrintInfo([[NSPrintOperation currentOperation] printInfo]), _webPrintingPageRects, _webTotalScaleFactorForPrinting);
+
+ *range = NSMakeRange(1, _webPrintingPageRects.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
+{
+ 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);
+
+ _webFrame->page()->beginPrinting(_webFrame.get(), PrintInfo([[NSPrintOperation currentOperation] printInfo]));
+
+ // FIXME: This is optimized for print preview. Get the whole document at once when actually printing.
+ Vector<uint8_t> pdfData;
+ _webFrame->page()->drawRectToPDF(_webFrame.get(), 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, -CGPDFPageGetBoxRect(pdfPage, kCGPDFMediaBox).size.height);
+ CGContextDrawPDFPage(context, pdfPage);
+ CGContextRestoreGState(context);
+}
+
+- (void)drawPageBorderWithSize:(NSSize)borderSize
+{
+ ASSERT(NSEqualSizes(borderSize, [[[NSPrintOperation currentOperation] printInfo] paperSize]));
+
+ // The header and footer rect height scales with the page, but the width is always
+ // all the way across the printed page (inset by printing margins).
+ NSPrintOperation *printOperation = [NSPrintOperation currentOperation];
+ NSPrintInfo *printInfo = [printOperation printInfo];
+ CGFloat scale = [printInfo scalingFactor];
+ NSSize paperSize = [printInfo paperSize];
+ CGFloat headerFooterLeft = [printInfo leftMargin] / scale;
+ CGFloat headerFooterWidth = (paperSize.width - ([printInfo leftMargin] + [printInfo rightMargin])) / scale;
+ NSRect footerRect = NSMakeRect(headerFooterLeft, [printInfo bottomMargin] / scale - _webFrame->page()->footerHeight(_webFrame.get()), headerFooterWidth, _webFrame->page()->footerHeight(_webFrame.get()));
+ NSRect headerRect = NSMakeRect(headerFooterLeft, (paperSize.height - [printInfo topMargin]) / scale, headerFooterWidth, _webFrame->page()->headerHeight(_webFrame.get()));
+
+ NSGraphicsContext *currentContext = [NSGraphicsContext currentContext];
+ [currentContext saveGraphicsState];
+ NSRectClip(headerRect);
+ _webFrame->page()->drawHeader(_webFrame.get(), headerRect);
+ [currentContext restoreGraphicsState];
+
+ [currentContext saveGraphicsState];
+ NSRectClip(footerRect);
+ _webFrame->page()->drawFooter(_webFrame.get(), footerRect);
+ [currentContext restoreGraphicsState];
+}
+
+// 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 _webTotalScaleFactorForPrinting;
+}
+
+// Return the drawing rectangle for a particular page number
+- (NSRect)rectForPage:(NSInteger)page
+{
+ LOG(View, "rectForPage:%d -> x %d, y %d, width %d, height %d\n", (int)page, _webPrintingPageRects[page - 1].x(), _webPrintingPageRects[page - 1].y(), _webPrintingPageRects[page - 1].width(), _webPrintingPageRects[page - 1].height());
+ return _webPrintingPageRects[page - 1];
+}
+
+ at end
diff --git a/Source/WebKit2/UIProcess/API/mac/WKView.mm b/Source/WebKit2/UIProcess/API/mac/WKView.mm
index 1f83ac7..cc2ec92 100644
--- a/Source/WebKit2/UIProcess/API/mac/WKView.mm
+++ b/Source/WebKit2/UIProcess/API/mac/WKView.mm
@@ -36,12 +36,12 @@
#import "PDFViewController.h"
#import "PageClientImpl.h"
#import "PasteboardTypes.h"
-#import "PrintInfo.h"
#import "Region.h"
#import "RunLoop.h"
#import "TextChecker.h"
#import "TextCheckerState.h"
#import "WKAPICast.h"
+#import "WKPrintingView.h"
#import "WKStringCF.h"
#import "WKTextInputWindowController.h"
#import "WebContext.h"
@@ -71,10 +71,6 @@
- (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;
@@ -97,9 +93,6 @@ typedef HashMap<String, ValidationVector> ValidationMap;
}
-NSString* const WebKitOriginalTopPrintingMarginKey = @"WebKitOriginalTopMargin";
-NSString* const WebKitOriginalBottomPrintingMarginKey = @"WebKitOriginalBottomMargin";
-
@interface WKViewData : NSObject {
@public
OwnPtr<PageClientImpl> _pageClient;
@@ -135,9 +128,6 @@ NSString* const WebKitOriginalBottomPrintingMarginKey = @"WebKitOriginalBottomMa
unsigned _selectionStart;
unsigned _selectionEnd;
- Vector<IntRect> _printingPageRects;
- double _totalScaleFactorForPrinting;
-
bool _inBecomeFirstResponder;
bool _inResignFirstResponder;
NSEvent *_mouseDownEvent;
@@ -149,36 +139,6 @@ NSString* const WebKitOriginalBottomPrintingMarginKey = @"WebKitOriginalBottomMa
@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;
@@ -1267,6 +1227,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);
+ _data->_page->endPrinting();
if (useNewDrawingArea()) {
if (DrawingAreaProxyImpl* drawingArea = static_cast<DrawingAreaProxyImpl*>(_data->_page->drawingArea())) {
CGContextRef context = static_cast<CGContextRef>([[NSGraphicsContext currentContext] graphicsPort]);
@@ -1365,190 +1326,27 @@ 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];
-}
-static float currentPrintOperationScale()
-{
- ASSERT([NSPrintOperation currentOperation]);
- ASSERT([[[[NSPrintOperation currentOperation] printInfo] dictionary] objectForKey:NSPrintScalingFactor]);
- return [[[[[NSPrintOperation currentOperation] printInfo] dictionary] objectForKey:NSPrintScalingFactor] floatValue];
-}
-
-- (void)_adjustPrintingMarginsForHeaderAndFooter
+- (BOOL)canChangeFrameLayout:(WKFrameRef)frameRef
{
- NSPrintOperation *printOperation = [NSPrintOperation currentOperation];
- NSPrintInfo *info = [printOperation printInfo];
- NSMutableDictionary *infoDictionary = [info dictionary];
-
- // We need to modify the top and bottom margins in the NSPrintInfo to account for the space needed by the
- // header and footer. Because this method can be called more than once on the same NSPrintInfo (see 5038087),
- // we stash away the unmodified top and bottom margins the first time this method is called, and we read from
- // those stashed-away values on subsequent calls.
- float originalTopMargin;
- float originalBottomMargin;
- NSNumber *originalTopMarginNumber = [infoDictionary objectForKey:WebKitOriginalTopPrintingMarginKey];
- if (!originalTopMarginNumber) {
- ASSERT(![infoDictionary objectForKey:WebKitOriginalBottomPrintingMarginKey]);
- originalTopMargin = [info topMargin];
- originalBottomMargin = [info bottomMargin];
- [infoDictionary setObject:[NSNumber numberWithFloat:originalTopMargin] forKey:WebKitOriginalTopPrintingMarginKey];
- [infoDictionary setObject:[NSNumber numberWithFloat:originalBottomMargin] forKey:WebKitOriginalBottomPrintingMarginKey];
- } else {
- ASSERT([originalTopMarginNumber isKindOfClass:[NSNumber class]]);
- ASSERT([[infoDictionary objectForKey:WebKitOriginalBottomPrintingMarginKey] isKindOfClass:[NSNumber class]]);
- originalTopMargin = [originalTopMarginNumber floatValue];
- originalBottomMargin = [[infoDictionary objectForKey:WebKitOriginalBottomPrintingMarginKey] floatValue];
- }
-
- float scale = currentPrintOperationScale();
- [info setTopMargin:originalTopMargin + _data->_page->headerHeight(frameBeingPrinted()) * scale];
- [info setBottomMargin:originalBottomMargin + _data->_page->footerHeight(frameBeingPrinted()) * scale];
+ // PDF documents are already paginated, so we can't change them to add headers and footers.
+ return !toImpl(frameRef)->isMainFrame() || !_data->_pdfViewController;
}
- (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());
- printOperation = _data->_pdfViewController->makePrintOperation(printInfo);
- } else
- printOperation = [NSPrintOperation printOperationWithView:self printInfo:printInfo];
-
- setFrameBeingPrinted(printOperation, toImpl(frameRef));
- return printOperation;
-}
-
-- (BOOL)canChangeFrameLayout:(WKFrameRef)frameRef
-{
- // PDF documents are already paginated, so we can't change them to add headers and footers.
- 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];
-
- [self _adjustPrintingMarginsForHeaderAndFooter];
-
- _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
-{
- // FIXME: This check isn't right for some non-printing cases, such as capturing into a buffer using cacheDisplayInRect:toBitmapImageRep:.
- if ([NSGraphicsContext currentContextDrawingToScreen]) {
- _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;
+ if (!toImpl(frameRef)->isMainFrame())
+ return 0;
+ return _data->_pdfViewController->makePrintOperation(printInfo);
+ } else {
+ RetainPtr<WKPrintingView> printingView(AdoptNS, [[WKPrintingView alloc] initWithFrameProxy:toImpl(frameRef)]);
+ // NSPrintOperation takes ownership of the view.
+ return [NSPrintOperation printOperationWithView:printingView.get()];
}
-
- NSGraphicsContext *nsGraphicsContext = [NSGraphicsContext currentContext];
- CGContextRef context = static_cast<CGContextRef>([nsGraphicsContext graphicsPort]);
-
- CGContextSaveGState(context);
- // Flip the destination.
- CGContextScaleCTM(context, 1, -1);
- CGContextTranslateCTM(context, 0, -CGPDFPageGetBoxRect(pdfPage, kCGPDFMediaBox).size.height);
- CGContextDrawPDFPage(context, pdfPage);
- CGContextRestoreGState(context);
-}
-
-- (void)drawPageBorderWithSize:(NSSize)borderSize
-{
- ASSERT(NSEqualSizes(borderSize, [[[NSPrintOperation currentOperation] printInfo] paperSize]));
-
- // The header and footer rect height scales with the page, but the width is always
- // all the way across the printed page (inset by printing margins).
- NSPrintOperation *printOperation = [NSPrintOperation currentOperation];
- NSPrintInfo *printInfo = [printOperation printInfo];
- float scale = currentPrintOperationScale();
- NSSize paperSize = [printInfo paperSize];
- float headerFooterLeft = [printInfo leftMargin] / scale;
- float headerFooterWidth = (paperSize.width - ([printInfo leftMargin] + [printInfo rightMargin])) / scale;
- WebFrameProxy* frame = frameBeingPrinted();
- NSRect footerRect = NSMakeRect(headerFooterLeft, [printInfo bottomMargin] / scale - _data->_page->footerHeight(frame), headerFooterWidth, _data->_page->footerHeight(frame));
- NSRect headerRect = NSMakeRect(headerFooterLeft, (paperSize.height - [printInfo topMargin]) / scale, headerFooterWidth, _data->_page->headerHeight(frame));
-
- NSGraphicsContext *currentContext = [NSGraphicsContext currentContext];
- [currentContext saveGraphicsState];
- NSRectClip(headerRect);
- _data->_page->drawHeader(frame, headerRect);
- [currentContext restoreGraphicsState];
-
- [currentContext saveGraphicsState];
- NSRectClip(footerRect);
- _data->_page->drawFooter(frame, footerRect);
- [currentContext restoreGraphicsState];
-}
-
-// 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
diff --git a/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj b/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj
index b83c16c..fed1ef6 100644
--- a/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj
+++ b/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj
@@ -668,6 +668,8 @@
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 */; };
+ E134F01712EA5D33004EC58D /* WKPrintingView.h in Headers */ = {isa = PBXBuildFile; fileRef = E134F01512EA5D11004EC58D /* WKPrintingView.h */; };
+ E134F01A12EA5D99004EC58D /* WKPrintingView.mm in Sources */ = {isa = PBXBuildFile; fileRef = E134F01912EA5D99004EC58D /* WKPrintingView.mm */; };
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 */; };
@@ -1431,6 +1433,8 @@
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>"; };
+ E134F01512EA5D11004EC58D /* WKPrintingView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKPrintingView.h; sourceTree = "<group>"; };
+ E134F01912EA5D99004EC58D /* WKPrintingView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKPrintingView.mm; 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>"; };
@@ -2317,6 +2321,8 @@
1AAF061312B01131008E49E2 /* PDFViewController.mm */,
BC111B4B112F619200337BAB /* PageClientImpl.h */,
BC111B4C112F619200337BAB /* PageClientImpl.mm */,
+ E134F01512EA5D11004EC58D /* WKPrintingView.h */,
+ E134F01912EA5D99004EC58D /* WKPrintingView.mm */,
1A4A9AA612B7E796008FE984 /* WKTextInputWindowController.h */,
1A4A9AA712B7E796008FE984 /* WKTextInputWindowController.mm */,
BC8699B2116AADAA002A925B /* WKView.h */,
@@ -3069,6 +3075,7 @@
C517388112DF8F4F00EE3F47 /* DragControllerAction.h in Headers */,
1AA2E51D12E4C05E00BC4966 /* CGUtilities.h in Headers */,
C574A58112E66681002DFE98 /* PasteboardTypes.h in Headers */,
+ E134F01712EA5D33004EC58D /* WKPrintingView.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -3532,6 +3539,7 @@
1AA2E51E12E4C05E00BC4966 /* CGUtilities.cpp in Sources */,
C574A37712E6099D002DFE98 /* WebDragClientMac.mm in Sources */,
C574A58212E66681002DFE98 /* PasteboardTypes.mm in Sources */,
+ E134F01A12EA5D99004EC58D /* WKPrintingView.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list