Changeset 75955 in webkit
- Timestamp:
- Jan 17, 2011 10:31:12 AM (13 years ago)
- Location:
- trunk/Source
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r75952 r75955 1 2011-01-17 Alexey Proskuryakov <ap@apple.com> 2 3 Reviewed by Dan Bernstein. 4 5 https://bugs.webkit.org/show_bug.cgi?id=52495 6 7 No change in behavior, so no tests. 8 9 * WebCore.exp.in: Export additional methods, as I'm going to use more code from PrintContext. 10 11 * page/PrintContext.cpp: 12 (WebCore::PrintContext::~PrintContext): No need to clear m_pageRects, the object is being 13 destroyed already. 14 (WebCore::PrintContext::pageCount): Changed page count from int to size_t. 15 (WebCore::PrintContext::pageRect): Ditto. 16 (WebCore::PrintContext::computePageRects): Pass allowHorizontalTiling as an argument. 17 PrintContext already has code to calculate scale factor, so it makes sense to make methods 18 that contain it universal (allowHorizontalTiling is always true for Safari). 19 Round page height to an integer, because Mac code does that, and because page height is 20 treated as integer almost everywhere else in code. 21 (WebCore::PrintContext::begin): Allow calling this function multiple times. There is no need 22 to return to screen mode if e.g. "print backgounds" option changes. 23 (WebCore::PrintContext::computeAutomaticScaleFactor): Expose scale factor computation, so 24 that clients don't have to copy it. 25 (WebCore::PrintContext::spoolRect): Add a way to spool a precomputed rect - handy if a request 26 comes from code that doesn't have page number. 27 (WebCore::PrintContext::pageNumberForElement): Page number int -> size_t. 28 29 * page/PrintContext.h: Added comments and FIXMEs. PrintContext needs cleanup, but that 30 depends on deciding how it really needs to work (e.g. whether computePageRects() should 31 cause relayout). 32 1 33 2011-01-17 Pavel Feldman <pfeldman@chromium.org> 2 34 -
trunk/Source/WebCore/WebCore.exp.in
r75939 r75955 263 263 __ZN7WebCore12PrintContext12pagePropertyEPNS_5FrameEPKci 264 264 __ZN7WebCore12PrintContext13numberOfPagesEPNS_5FrameERKNS_9FloatSizeE 265 __ZN7WebCore12PrintContext16computePageRectsERKNS_9FloatRectEfffRfb 265 266 __ZN7WebCore12PrintContext16isPageBoxVisibleEPNS_5FrameEi 266 267 __ZN7WebCore12PrintContext20pageNumberForElementEPNS_7ElementERKNS_9FloatSizeE 267 268 __ZN7WebCore12PrintContext26pageSizeAndMarginsInPixelsEPNS_5FrameEiiiiiii 269 __ZN7WebCore12PrintContext27computeAutomaticScaleFactorEf 268 270 __ZN7WebCore12PrintContext27spoolAllPagesWithBoundariesEPNS_5FrameERNS_15GraphicsContextERKNS_9FloatSizeE 269 271 __ZN7WebCore12PrintContext28computePageRectsWithPageSizeERKNS_9FloatSizeEb 272 __ZN7WebCore12PrintContext3endEv 273 __ZN7WebCore12PrintContext5beginEff 274 __ZN7WebCore12PrintContext9spoolPageERNS_15GraphicsContextEif 275 __ZN7WebCore12PrintContext9spoolRectERNS_15GraphicsContextERKNS_7IntRectE 270 276 __ZN7WebCore12PrintContextC1EPNS_5FrameE 271 277 __ZN7WebCore12PrintContextD1Ev -
trunk/Source/WebCore/page/PrintContext.cpp
r74908 r75955 29 29 #include <wtf/text/StringConcatenate.h> 30 30 31 using namespace WebCore;32 33 31 namespace WebCore { 32 33 // By imaging to a width a little wider than the available pixels, 34 // thin pages will be scaled down a little, matching the way they 35 // print in IE and Camino. This lets them use fewer sheets than they 36 // would otherwise, which is presumably why other browsers do this. 37 // Wide pages will be scaled down more than this. 38 const float printingMinimumShrinkFactor = 1.25; 39 40 // This number determines how small we are willing to reduce the page content 41 // in order to accommodate the widest line. If the page would have to be 42 // reduced smaller to make the widest line fit, we just clip instead (this 43 // behavior matches MacIE and Mozilla, at least) 44 const float printingMaximumShrinkFactor = 2; 34 45 35 46 PrintContext::PrintContext(Frame* frame) … … 43 54 if (m_isPrinting) 44 55 end(); 45 m_pageRects.clear(); 46 } 47 48 int PrintContext::pageCount() const 56 } 57 58 size_t PrintContext::pageCount() const 49 59 { 50 60 return m_pageRects.size(); 51 61 } 52 62 53 const IntRect& PrintContext::pageRect( int pageNumber) const63 const IntRect& PrintContext::pageRect(size_t pageNumber) const 54 64 { 55 65 return m_pageRects[pageNumber]; 56 66 } 57 67 58 void PrintContext::computePageRects(const FloatRect& printRect, float headerHeight, float footerHeight, float userScaleFactor, float& outPageHeight )68 void PrintContext::computePageRects(const FloatRect& printRect, float headerHeight, float footerHeight, float userScaleFactor, float& outPageHeight, bool allowHorizontalTiling) 59 69 { 60 70 m_pageRects.clear(); … … 74 84 75 85 float pageWidth = view->docWidth(); 76 float pageHeight = pageWidth * ratio;86 float pageHeight = floorf(pageWidth * ratio); 77 87 outPageHeight = pageHeight; // this is the height of the page adjusted by margins 78 88 pageHeight -= headerHeight + footerHeight; … … 83 93 } 84 94 85 computePageRectsWithPageSizeInternal(FloatSize(pageWidth / userScaleFactor, pageHeight / userScaleFactor), false);86 } 87 88 void PrintContext::computePageRectsWithPageSize(const FloatSize& pageSizeInPixels, bool allowHorizontal MultiPages)95 computePageRectsWithPageSizeInternal(FloatSize(pageWidth / userScaleFactor, pageHeight / userScaleFactor), allowHorizontalTiling); 96 } 97 98 void PrintContext::computePageRectsWithPageSize(const FloatSize& pageSizeInPixels, bool allowHorizontalTiling) 89 99 { 90 100 m_pageRects.clear(); 91 computePageRectsWithPageSizeInternal(pageSizeInPixels, allowHorizontal MultiPages);92 } 93 94 void PrintContext::computePageRectsWithPageSizeInternal(const FloatSize& pageSizeInPixels, bool allowHorizontal MultiPages)101 computePageRectsWithPageSizeInternal(pageSizeInPixels, allowHorizontalTiling); 102 } 103 104 void PrintContext::computePageRectsWithPageSizeInternal(const FloatSize& pageSizeInPixels, bool allowHorizontalTiling) 95 105 { 96 106 if (!m_frame->document() || !m_frame->view() || !m_frame->document()->renderer()) … … 106 116 unsigned pageCount = ceilf((float)docRect.height() / pageHeight); 107 117 for (unsigned i = 0; i < pageCount; ++i) { 108 if (allowHorizontal MultiPages) {118 if (allowHorizontalTiling) { 109 119 for (int currentX = docRect.x(); currentX < docRect.right(); currentX += pageWidth) 110 120 m_pageRects.append(IntRect(currentX, docRect.y() + i * pageHeight, pageWidth, pageHeight)); … … 116 126 void PrintContext::begin(float width, float height) 117 127 { 118 ASSERT(!m_isPrinting);128 // This function can be called multiple times to adjust printing parameters without going back to screen mode. 119 129 m_isPrinting = true; 120 130 121 // By imaging to a width a little wider than the available pixels,122 // thin pages will be scaled down a little, matching the way they123 // print in IE and Camino. This lets them use fewer sheets than they 124 // would otherwise, which is presumably why other browsers do this.125 // Wide pages will be scaled down more than this.126 const float PrintingMinimumShrinkFactor = 1.25f; 127 128 // This number determines how small we are willing to reduce the page content 129 // in order to accommodate the widest line. If the page would have to be 130 // reduced smaller to make the widest line fit, we just clip instead (this131 // behavior matches MacIE and Mozilla, at least)132 const float PrintingMaximumShrinkFactor = 2.0f; 133 134 float minLayoutWidth = width * PrintingMinimumShrinkFactor;135 float minLayoutHeight = height * PrintingMinimumShrinkFactor;136 137 // FIXME: This will modify the rendering of the on-screen frame.138 // Could lead to flicker during printing.139 m_frame->setPrinting(true, FloatSize(minLayoutWidth, minLayoutHeight), PrintingMaximumShrinkFactor / PrintingMinimumShrinkFactor, Frame::AdjustViewSize);131 float minLayoutWidth = width * printingMinimumShrinkFactor; 132 float minLayoutHeight = height * printingMinimumShrinkFactor; 133 134 // This changes layout, so callers need to make sure that they don't paint to screen while in printing mode. 135 m_frame->setPrinting(true, FloatSize(minLayoutWidth, minLayoutHeight), printingMaximumShrinkFactor / printingMinimumShrinkFactor, Frame::AdjustViewSize); 136 } 137 138 float PrintContext::computeAutomaticScaleFactor(float availablePaperWidth) 139 { 140 if (!m_frame->view()) 141 return 1; 142 143 float viewWidth = m_frame->view()->contentsWidth(); 144 if (viewWidth < 1) 145 return 1; 146 147 float maxShrinkToFitScaleFactor = 1 / printingMaximumShrinkFactor; 148 float shrinkToFitScaleFactor = availablePaperWidth / viewWidth; 149 return max(maxShrinkToFitScaleFactor, shrinkToFitScaleFactor); 140 150 } 141 151 … … 150 160 ctx.clip(pageRect); 151 161 m_frame->view()->paintContents(&ctx, pageRect); 162 ctx.restore(); 163 } 164 165 void PrintContext::spoolRect(GraphicsContext& ctx, const IntRect& rect) 166 { 167 ctx.save(); 168 ctx.scale(FloatSize(1, -1)); 169 ctx.translate(0, -rect.height()); 170 ctx.clip(rect); 171 m_frame->view()->paintContents(&ctx, rect); 152 172 ctx.restore(); 153 173 } … … 190 210 int top = box->offsetTop(); 191 211 int left = box->offsetLeft(); 192 int pageNumber = 0;212 size_t pageNumber = 0; 193 213 for (; pageNumber < printContext.pageCount(); pageNumber++) { 194 214 const IntRect& page = printContext.pageRect(pageNumber); -
trunk/Source/WebCore/page/PrintContext.h
r65021 r75955 39 39 ~PrintContext(); 40 40 41 int pageCount() const; 42 const IntRect& pageRect(int pageNumber) const; 41 Frame* frame() const { return m_frame; } 42 43 // Break up a page into rects without relayout. 44 // FIXME: This means that CSS page breaks won't be on page boundary if the size is different than what was passed to begin(). That's probably not always desirable. 45 // FIXME: Header and footer height should be applied before layout, not after. 46 // FIXME: The printRect argument is only used to determine page aspect ratio, it would be better to pass a FloatSize with page dimensions instead. 47 void computePageRects(const FloatRect& printRect, float headerHeight, float footerHeight, float userScaleFactor, float& outPageHeight, bool allowHorizontalTiling = false); 48 49 // Deprecated. Page size computation is already in this class, clients shouldn't be copying it. 50 void computePageRectsWithPageSize(const FloatSize& pageSizeInPixels, bool allowHorizontalTiling); 51 52 // These are only valid after page rects are computed. 53 size_t pageCount() const; 54 const IntRect& pageRect(size_t pageNumber) const; 43 55 const Vector<IntRect>& pageRects() const { return m_pageRects; } 44 56 45 void computePageRects(const FloatRect& printRect, float headerHeight, float footerHeight, float userScaleFactor, float& outPageHeight); 46 void computePageRectsWithPageSize(const FloatSize& pageSizeInPixels, bool allowHorizontalMultiPages); 57 float computeAutomaticScaleFactor(float availablePaperWidth); 47 58 48 // TODO: eliminate width param 59 // Enter print mode, updating layout for new page size. 60 // This function can be called multiple times to apply new print options without going back to screen mode. 49 61 void begin(float width, float height = 0); 50 62 51 // TODO: eliminate width param63 // FIXME: eliminate width argument. 52 64 void spoolPage(GraphicsContext& ctx, int pageNumber, float width); 53 65 66 void spoolRect(GraphicsContext& ctx, const IntRect&); 67 68 // Return to screen mode. 54 69 void end(); 55 70 56 71 // Used by layout tests. 57 static int pageNumberForElement(Element*, const FloatSize& pageSizeInPixels); 72 static int pageNumberForElement(Element*, const FloatSize& pageSizeInPixels); // Returns -1 if page isn't found. 58 73 static String pageProperty(Frame* frame, const char* propertyName, int pageNumber); 59 74 static bool isPageBoxVisible(Frame* frame, int pageNumber); … … 70 85 71 86 private: 72 void computePageRectsWithPageSizeInternal(const FloatSize& pageSizeInPixels, bool allowHorizontal MultiPages);87 void computePageRectsWithPageSizeInternal(const FloatSize& pageSizeInPixels, bool allowHorizontalTiling); 73 88 74 89 // Used to prevent misuses of begin() and end() (e.g., call end without begin). -
trunk/Source/WebKit/qt/Api/qwebframe.cpp
r73865 r75955 1455 1455 // paranoia check 1456 1456 fromPage = qMax(1, fromPage); 1457 toPage = qMin( printContext.pageCount(), toPage);1457 toPage = qMin(static_cast<int>(printContext.pageCount()), toPage); 1458 1458 if (toPage < fromPage) { 1459 1459 // if the user entered a page range outside the actual number -
trunk/Source/WebKit/qt/ChangeLog
r75944 r75955 1 2011-01-17 Alexey Proskuryakov <ap@apple.com> 2 3 https://bugs.webkit.org/show_bug.cgi?id=52495 4 5 * Api/qwebframe.cpp: (QWebFrame::print): Avoid breaking the build due to type mismatch. 6 Longer term, this code should be changed to use an unsigned type for page count. 7 1 8 2011-01-17 Yi Shen <yi.4.shen@nokia.com> 2 9
Note: See TracChangeset
for help on using the changeset viewer.