Changeset 77220 in webkit
- Timestamp:
- Jan 31, 2011 9:53:05 PM (13 years ago)
- Location:
- trunk/Source
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r77216 r77220 1 2011-01-31 Alexey Proskuryakov <ap@apple.com> 2 3 Reviewed by Maciej Stachowiak. 4 5 https://bugs.webkit.org/show_bug.cgi?id=53466 6 Move WebKit2 to printing via API methods 7 8 * WebCore.exp.in: Export IntRect::scale(). 9 1 10 2011-01-31 Patrick Gansterer <paroga@webkit.org> 2 11 -
trunk/Source/WebCore/WebCore.exp.in
r77153 r77220 751 751 __ZN7WebCore7Console21shouldPrintExceptionsEv 752 752 __ZN7WebCore7Console24setShouldPrintExceptionsEb 753 __ZN7WebCore7IntRect5scaleEf 753 754 __ZN7WebCore7IntRect5uniteERKS0_ 754 755 __ZN7WebCore7IntRect9intersectERKS0_ -
trunk/Source/WebKit2/ChangeLog
r77182 r77220 1 2011-01-31 Alexey Proskuryakov <ap@apple.com> 2 3 Reviewed by Maciej Stachowiak. 4 5 https://bugs.webkit.org/show_bug.cgi?id=53466 6 Move WebKit2 to printing via API methods 7 8 Also fixes <rdar://problem/8933724> REGRESSION: Wrong pages are printed when not printing from page 1 9 10 Also fixes horizontal tiling (no bug filed). 11 12 The main idea here is that we don't force AppKit to use a different scaling factor when 13 a Web view can't be resized to exact page size, and scale when drawing instead. 14 15 * UIProcess/API/mac/WKPrintingView.mm: 16 (-[WKPrintingView _firstPrintedPageNumber]): Factored out into a separate method. 17 (-[WKPrintingView _lastPrintedPageNumber]): Ditto. 18 (pageDidDrawToPDF): Avoid crashing if data is null. 19 (-[WKPrintingView _preparePDFDataForPrintingOnSecondaryThread]): Use -_firstPrintedPageNumber 20 and -_lastPrintedPageNumber. 21 (pageDidComputePageRects): Set frame size to what it would have been for a normal NSView 22 that's been asked to resize. 23 (-[WKPrintingView _pageForRect:]): Check x(), because several pages can be at the same y() 24 when tiling horizontally. 25 (-[WKPrintingView _drawPDFDocument:page:atPoint:]): Point to draw at and frame size are 26 now using different units, translate as appropriate. 27 (-[WKPrintingView _drawPreview:]): Scale the rect to WebCore units. 28 (-[WKPrintingView drawRect:]): Correctly calculate page number when the first page to print 29 isn't page 1. 30 (-[WKPrintingView rectForPage:]): Scale the rect to AppKit units. 31 1 32 2011-01-31 Darin Adler <darin@apple.com> 2 33 -
trunk/Source/WebKit2/UIProcess/API/mac/WKPrintingView.mm
r77051 r77220 32 32 #import "WebPageProxy.h" 33 33 34 @interface NSView (WebNSViewDetails)35 - (void)_recursiveDisplayRectIfNeededIgnoringOpacity:(NSRect)rect isVisibleRect:(BOOL)isVisibleRect rectIsVisibleRectForView:(NSView *)visibleView topView:(BOOL)topView;36 @end37 38 34 using namespace WebKit; 39 35 using namespace WebCore; … … 113 109 } 114 110 111 - (NSUInteger)_firstPrintedPageNumber 112 { 113 // Need to directly access the dictionary because -[NSPrintOperation pageRange] verifies pagination, potentially causing recursion. 114 return [[[[_printOperation printInfo] dictionary] objectForKey:NSPrintFirstPage] unsignedIntegerValue]; 115 } 116 117 - (NSUInteger)_lastPrintedPageNumber 118 { 119 ASSERT([self _hasPageRects]); 120 121 // Need to directly access the dictionary because -[NSPrintOperation pageRange] verifies pagination, potentially causing recursion. 122 NSUInteger firstPage = [[[[_printOperation printInfo] dictionary] objectForKey:NSPrintFirstPage] unsignedIntegerValue]; 123 NSUInteger lastPage = [[[[_printOperation printInfo] dictionary] objectForKey:NSPrintLastPage] unsignedIntegerValue]; 124 if (lastPage - firstPage >= _printingPageRects.size()) 125 return _printingPageRects.size(); 126 return lastPage; 127 } 128 115 129 - (uint64_t)_expectedPreviewCallbackForRect:(const IntRect&)rect 116 130 { … … 150 164 ASSERT([view _isPrintingPreview]); 151 165 152 pair<HashMap<WebCore::IntRect, Vector<uint8_t> >::iterator, bool> entry = view->_pagePreviews.add(iter->second, Vector<uint8_t>()); 153 entry.first->second.append(data->bytes(), data->size()); 154 166 if (data) { 167 pair<HashMap<WebCore::IntRect, Vector<uint8_t> >::iterator, bool> entry = view->_pagePreviews.add(iter->second, Vector<uint8_t>()); 168 entry.first->second.append(data->bytes(), data->size()); 169 } 155 170 bool receivedResponseToLatestRequest = view->_latestExpectedPreviewCallback == context->callbackID; 156 171 view->_latestExpectedPreviewCallback = 0; … … 178 193 ASSERT(!_expectedPrintCallback); 179 194 180 unsigned firstPage = [[[[_printOperation printInfo] dictionary] objectForKey:NSPrintFirstPage] unsignedIntValue]; 181 unsigned lastPage = [[[[_printOperation printInfo] dictionary] objectForKey:NSPrintLastPage] unsignedIntValue]; 182 if (lastPage > _printingPageRects.size()) // Last page is NSIntegerMax if not set by the user. 183 lastPage = _printingPageRects.size(); 195 NSUInteger firstPage = [self _firstPrintedPageNumber]; 196 NSUInteger lastPage = [self _lastPrintedPageNumber]; 184 197 185 198 ASSERT(firstPage > 0); … … 218 231 view->_printingPageRects = pageRects; 219 232 view->_totalScaleFactorForPrinting = totalScaleFactorForPrinting; 233 234 const IntRect& lastPrintingPageRect = view->_printingPageRects[view->_printingPageRects.size() - 1]; 235 NSRect newFrameSize = NSMakeRect(0, 0, 236 ceil(lastPrintingPageRect.right() * view->_totalScaleFactorForPrinting), 237 ceil(lastPrintingPageRect.bottom() * view->_totalScaleFactorForPrinting)); 238 LOG(View, "WKPrintingView setting frame size to x:%g y:%g width:%g height:%g", newFrameSize.origin.x, newFrameSize.origin.y, newFrameSize.size.width, newFrameSize.size.height); 239 [view setFrame:newFrameSize]; 220 240 221 241 if ([view _isPrintingPreview]) { … … 302 322 // Assuming that rect exactly matches one of the pages. 303 323 for (size_t i = 0; i < _printingPageRects.size(); ++i) { 304 if (rect.origin.y == _printingPageRects[i].y()) 324 IntRect currentRect(_printingPageRects[i]); 325 currentRect.scale(_totalScaleFactorForPrinting); 326 if (rect.origin.y == currentRect.y() && rect.origin.x == currentRect.x()) 305 327 return i + 1; 306 328 } 329 ASSERT_NOT_REACHED(); 307 330 return 0; // Invalid page number. 308 331 } … … 325 348 326 349 CGContextSaveGState(context); 327 // Flip the destination.328 CGContextScaleCTM(context, 1, -1);329 CGContextTranslateCTM(context, point.x, -point.y-CGPDFPageGetBoxRect(pdfPage, kCGPDFMediaBox).size.height);350 CGContextTranslateCTM(context, point.x, point.y); 351 CGContextScaleCTM(context, _totalScaleFactorForPrinting, -_totalScaleFactorForPrinting); 352 CGContextTranslateCTM(context, 0, -CGPDFPageGetBoxRect(pdfPage, kCGPDFMediaBox).size.height); 330 353 CGContextDrawPDFPage(context, pdfPage); 331 354 CGContextRestoreGState(context); … … 337 360 338 361 IntRect rect(nsRect); 362 rect.scale(1 / _totalScaleFactorForPrinting); 339 363 HashMap<WebCore::IntRect, Vector<uint8_t> >::iterator pagePreviewIterator = _pagePreviews.find(rect); 340 364 if (pagePreviewIterator == _pagePreviews.end()) { … … 377 401 } 378 402 379 // Take over printing. AppKit applies incorrect clipping, and doesn't print pages beyond the first one. 380 - (void)_recursiveDisplayRectIfNeededIgnoringOpacity:(NSRect)nsRect isVisibleRect:(BOOL)isVisibleRect rectIsVisibleRectForView:(NSView *)visibleView topView:(BOOL)topView 381 { 382 LOG(View, "WKPrintingView printing rect x:%g, y:%g, width:%g, height:%g", nsRect.origin.x, nsRect.origin.y, nsRect.size.width, nsRect.size.height); 403 - (void)drawRect:(NSRect)nsRect 404 { 405 LOG(View, "WKPrintingView printing rect x:%g, y:%g, width:%g, height:%g%s", nsRect.origin.x, nsRect.origin.y, nsRect.size.width, nsRect.size.height, [self _isPrintingPreview] ? " for preview" : ""); 383 406 384 407 ASSERT(_printOperation == [NSPrintOperation currentOperation]); 385 ASSERT(self == visibleView);386 408 387 409 if (!_webFrame->page()) … … 401 423 } 402 424 403 [self _drawPDFDocument:_printedPagesPDFDocument.get() page:[self _pageForRect:nsRect] atPoint:NSMakePoint(nsRect.origin.x, nsRect.origin.y)]; 425 unsigned printedPageNumber = [self _pageForRect:nsRect] - [self _firstPrintedPageNumber] + 1; 426 [self _drawPDFDocument:_printedPagesPDFDocument.get() page:printedPageNumber atPoint:NSMakePoint(nsRect.origin.x, nsRect.origin.y)]; 404 427 } 405 428 … … 460 483 } 461 484 462 // FIXME 3491344: This is an AppKit-internal method that we need to override in order463 // to get our shrink-to-fit to work with a custom pagination scheme. We can do this better464 // if AppKit makes it SPI/API.465 - (CGFloat)_provideTotalScaleFactorForPrintOperation:(NSPrintOperation *)printOperation466 {467 ASSERT(_printOperation == printOperation);468 return _totalScaleFactorForPrinting;469 }470 471 // Return the drawing rectangle for a particular page number472 485 - (NSRect)rectForPage:(NSInteger)page 473 486 { … … 479 492 return NSMakeRect(0, 0, 1, 1); 480 493 } 481 LOG(View, "-[WKPrintingView rectForPage:%d] -> x %d, y %d, width %d, height %d", (int)page, _printingPageRects[page - 1].x(), _printingPageRects[page - 1].y(), _printingPageRects[page - 1].width(), _printingPageRects[page - 1].height()); 482 return _printingPageRects[page - 1]; 494 495 IntRect rect = _printingPageRects[page - 1]; 496 rect.scale(_totalScaleFactorForPrinting); 497 LOG(View, "-[WKPrintingView rectForPage:%d] -> x %d, y %d, width %d, height %d", (int)page, rect.x(), rect.y(), rect.width(), rect.height()); 498 return rect; 483 499 } 484 500
Note: See TracChangeset
for help on using the changeset viewer.