Changeset 56454 in webkit
- Timestamp:
- Mar 24, 2010 1:38:05 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r56453 r56454 1 2010-03-24 Hayato Ito <hayato@chromium.org> 2 3 Reviewed by NOBODY (Need!). 4 5 Refactor computePageRects so that Mac can make use of it. 6 https://bugs.webkit.org/show_bug.cgi?id=36159 7 8 Refactoring only, so no new tests. 9 10 * WebCore.base.exp: 11 * page/PrintContext.cpp: 12 (WebCore::PrintContext::computePageRects): 13 (WebCore::PrintContext::computePageRectsWithPageSize): 14 (WebCore::PrintContext::computePageRectsWithPageSizeInternal): 15 (WebCore::PrintContext::pageNumberForElement): 16 (WebCore::PrintContext::numberOfPages): 17 * page/PrintContext.h: 18 1 19 2010-03-24 Jeremy Moskovich <jeremy@chromium.org> 2 20 -
trunk/WebCore/WebCore.base.exp
r56439 r56454 253 253 __ZN7WebCore12PrintContext13numberOfPagesEPNS_5FrameERKNS_9FloatSizeE 254 254 __ZN7WebCore12PrintContext20pageNumberForElementEPNS_7ElementERKNS_9FloatSizeE 255 __ZN7WebCore12PrintContext28computePageRectsWithPageSizeERKNS_9FloatSizeEb 256 __ZN7WebCore12PrintContextC1EPNS_5FrameE 257 __ZN7WebCore12PrintContextD1Ev 255 258 __ZN7WebCore12RenderObject16repaintRectangleERKNS_7IntRectEb 256 259 __ZN7WebCore12RenderWidget19showSubstituteImageEN3WTF10PassRefPtrINS_5ImageEEE -
trunk/WebCore/page/PrintContext.cpp
r55988 r56454 59 59 return; 60 60 61 if (userScaleFactor <= 0) { 62 LOG_ERROR("userScaleFactor has bad value %.2f", userScaleFactor); 63 return; 64 } 65 61 66 RenderView* root = toRenderView(m_frame->document()->renderer()); 62 63 if (!root) {64 LOG_ERROR("document to be printed has no renderer");65 return;66 }67 67 68 68 float ratio = printRect.height() / printRect.width(); … … 70 70 float pageWidth = (float)root->rightLayoutOverflow(); 71 71 float pageHeight = pageWidth * ratio; 72 outPageHeight = pageHeight; 72 outPageHeight = pageHeight; // this is the height of the page adjusted by margins 73 73 pageHeight -= headerHeight + footerHeight; 74 74 … … 78 78 } 79 79 80 computePageRectsWithPageSize(FloatSize(pageWidth, pageHeight), userScaleFactor); 81 } 82 83 void PrintContext::computePageRectsWithPageSize(const FloatSize& pageSizeInPixels, float userScaleFactor) 84 { 80 computePageRectsWithPageSizeInternal(FloatSize(pageWidth / userScaleFactor, pageHeight / userScaleFactor), false); 81 } 82 83 void PrintContext::computePageRectsWithPageSize(const FloatSize& pageSizeInPixels, bool allowHorizontalMultiPages) 84 { 85 m_pageRects.clear(); 86 computePageRectsWithPageSizeInternal(pageSizeInPixels, allowHorizontalMultiPages); 87 } 88 89 void PrintContext::computePageRectsWithPageSizeInternal(const FloatSize& pageSizeInPixels, bool allowHorizontalMultiPages) 90 { 91 if (!m_frame->document() || !m_frame->view() || !m_frame->document()->renderer()) 92 return; 85 93 RenderView* root = toRenderView(m_frame->document()->renderer()); 86 94 87 if (!root) { 88 LOG_ERROR("document to be printed has no renderer"); 89 return; 90 } 91 92 if (userScaleFactor <= 0) { 93 LOG_ERROR("userScaleFactor has bad value %.2f", userScaleFactor); 94 return; 95 } 96 97 float currPageHeight = pageSizeInPixels.height() / userScaleFactor; 98 float docHeight = root->layer()->height(); 99 float currPageWidth = pageSizeInPixels.width() / userScaleFactor; 95 const float pageWidth = pageSizeInPixels.width(); 96 const float docWidth = root->layer()->width(); 97 const float docHeight = root->layer()->height(); 98 float currPageHeight = pageSizeInPixels.height(); 100 99 101 100 // always return at least one page, since empty files should print a blank page … … 105 104 m_frame->view()->adjustPageHeight(&proposedBottom, printedPagesHeight, proposedBottom, printedPagesHeight); 106 105 currPageHeight = max(1.0f, proposedBottom - printedPagesHeight); 107 108 m_pageRects.append(IntRect(0, (int)printedPagesHeight, (int)currPageWidth, (int)currPageHeight)); 106 if (allowHorizontalMultiPages) { 107 for (float curWidth = 0; curWidth < docWidth; curWidth += pageWidth) 108 m_pageRects.append(IntRect(curWidth, (int)printedPagesHeight, (int)pageWidth, (int)currPageHeight)); 109 } else 110 m_pageRects.append(IntRect(0, (int)printedPagesHeight, (int)pageWidth, (int)currPageHeight)); 109 111 printedPagesHeight += currPageHeight; 110 112 } while (printedPagesHeight < docHeight); … … 176 178 PrintContext printContext(frame); 177 179 printContext.begin(pageRect.width()); 178 printContext.computePageRectsWithPageSize(pageSizeInPixels, 1);180 printContext.computePageRectsWithPageSize(pageSizeInPixels, false); 179 181 180 182 int top = box->offsetTop(); … … 197 199 PrintContext printContext(frame); 198 200 printContext.begin(pageRect.width()); 199 printContext.computePageRectsWithPageSize(pageSizeInPixels, 1);201 printContext.computePageRectsWithPageSize(pageSizeInPixels, false); 200 202 printContext.end(); 201 203 return printContext.pageCount(); -
trunk/WebCore/page/PrintContext.h
r54533 r56454 43 43 44 44 void computePageRects(const FloatRect& printRect, float headerHeight, float footerHeight, float userScaleFactor, float& outPageHeight); 45 void computePageRectsWithPageSize(const FloatSize& pageSizeInPixels, bool allowHorizontalMultiPages); 45 46 46 47 // TODO: eliminate width param … … 57 58 58 59 protected: 59 void computePageRectsWithPageSize(const FloatSize& pageSizeInPixels, float userScaleFactor);60 61 60 Frame* m_frame; 62 61 Vector<IntRect> m_pageRects; 62 63 private: 64 void computePageRectsWithPageSizeInternal(const FloatSize& pageSizeInPixels, bool allowHorizontalMultiPages); 63 65 }; 64 66 -
trunk/WebKit/mac/ChangeLog
r56439 r56454 1 2010-03-24 Hayato Ito <hayato@chromium.org> 2 3 Reviewed by Shinichiro Hamaji. 4 5 Refactor computePageRects so that Mac can make use of it. 6 https://bugs.webkit.org/show_bug.cgi?id=36159 7 8 Refactoring only, so no new tests. 9 10 * WebView/WebFrame.mm: 11 (-[WebFrame _computePageRectsWithPrintWidthScaleFactor:printHeight:]): 12 1 13 2010-03-24 Kent Tamura <tkent@chromium.org> 2 14 -
trunk/WebKit/mac/WebView/WebFrame.mm
r55997 r56454 75 75 #import <WebCore/Page.h> 76 76 #import <WebCore/PluginData.h> 77 #import <WebCore/PrintContext.h> 77 78 #import <WebCore/RenderLayer.h> 78 79 #import <WebCore/RenderPart.h> … … 583 584 return pages; 584 585 585 float currPageHeight = printHeight;586 float docHeight = root->layer()->height();587 586 float docWidth = root->layer()->width(); 588 float printWidth = docWidth/printWidthScaleFactor; 589 590 // We need to give the part the opportunity to adjust the page height at each step. 591 for (float i = 0; i < docHeight; i += currPageHeight) { 592 float proposedBottom = min(docHeight, i + printHeight); 593 view->adjustPageHeight(&proposedBottom, i, proposedBottom, i); 594 currPageHeight = max(1.0f, proposedBottom - i); 595 for (float j = 0; j < docWidth; j += printWidth) { 596 NSValue* val = [NSValue valueWithRect: NSMakeRect(j, i, printWidth, currPageHeight)]; 597 [pages addObject: val]; 598 } 599 } 600 587 float printWidth = docWidth / printWidthScaleFactor; 588 589 PrintContext printContext(_private->coreFrame); 590 printContext.computePageRectsWithPageSize(FloatSize(printWidth, printHeight), true); 591 592 const Vector<IntRect>& pageRects = printContext.pageRects(); 593 const size_t pageCount = pageRects.size(); 594 for (size_t pageNumber = 0; pageNumber < pageCount; ++pageNumber) 595 [pages addObject: [NSValue valueWithRect: NSRect(pageRects[pageNumber])]]; 601 596 return pages; 602 597 }
Note: See TracChangeset
for help on using the changeset viewer.