Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(181)

Side by Side Diff: Source/core/page/PrintContext.cpp

Issue 465983003: Delete PrintContext::spoolAllPagesWithBoundaries (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007 Alp Toker <alp@atoker.com> 2 * Copyright (C) 2007 Alp Toker <alp@atoker.com>
3 * Copyright (C) 2007 Apple Inc. 3 * Copyright (C) 2007 Apple Inc.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 // This function can be called multiple times to adjust printing parameters without going back to screen mode. 164 // This function can be called multiple times to adjust printing parameters without going back to screen mode.
165 m_isPrinting = true; 165 m_isPrinting = true;
166 166
167 FloatSize originalPageSize = FloatSize(width, height); 167 FloatSize originalPageSize = FloatSize(width, height);
168 FloatSize minLayoutSize = m_frame->resizePageRectsKeepingRatio(originalPageS ize, FloatSize(width * printingMinimumShrinkFactor, height * printingMinimumShri nkFactor)); 168 FloatSize minLayoutSize = m_frame->resizePageRectsKeepingRatio(originalPageS ize, FloatSize(width * printingMinimumShrinkFactor, height * printingMinimumShri nkFactor));
169 169
170 // This changes layout, so callers need to make sure that they don't paint t o screen while in printing mode. 170 // This changes layout, so callers need to make sure that they don't paint t o screen while in printing mode.
171 m_frame->setPrinting(true, minLayoutSize, originalPageSize, printingMaximumS hrinkFactor / printingMinimumShrinkFactor); 171 m_frame->setPrinting(true, minLayoutSize, originalPageSize, printingMaximumS hrinkFactor / printingMinimumShrinkFactor);
172 } 172 }
173 173
174 void PrintContext::spoolPage(GraphicsContext& ctx, int pageNumber, float width)
175 {
176 // FIXME: Not correct for vertical text.
177 IntRect pageRect = m_pageRects[pageNumber];
178 float scale = width / pageRect.width();
179
180 ctx.save();
181 ctx.scale(scale, scale);
182 ctx.translate(-pageRect.x(), -pageRect.y());
183 ctx.clip(pageRect);
184 m_frame->view()->paintContents(&ctx, pageRect);
185 if (ctx.supportsURLFragments())
186 outputLinkedDestinations(ctx, m_frame->document(), pageRect);
187 ctx.restore();
188 }
189
190 void PrintContext::end() 174 void PrintContext::end()
191 { 175 {
192 ASSERT(m_isPrinting); 176 ASSERT(m_isPrinting);
193 m_isPrinting = false; 177 m_isPrinting = false;
194 m_frame->setPrinting(false, FloatSize(), FloatSize(), 0); 178 m_frame->setPrinting(false, FloatSize(), FloatSize(), 0);
195 m_linkedDestinations.clear(); 179 m_linkedDestinations.clear();
196 m_linkedDestinationsValid = false; 180 m_linkedDestinationsValid = false;
197 } 181 }
198 182
199 static RenderBoxModelObject* enclosingBoxModelObject(RenderObject* object) 183 static RenderBoxModelObject* enclosingBoxModelObject(RenderObject* object)
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 FloatRect pageRect(FloatPoint(0, 0), pageSizeInPixels); 308 FloatRect pageRect(FloatPoint(0, 0), pageSizeInPixels);
325 PrintContext printContext(frame); 309 PrintContext printContext(frame);
326 printContext.begin(pageRect.width(), pageRect.height()); 310 printContext.begin(pageRect.width(), pageRect.height());
327 // Account for shrink-to-fit. 311 // Account for shrink-to-fit.
328 FloatSize scaledPageSize = pageSizeInPixels; 312 FloatSize scaledPageSize = pageSizeInPixels;
329 scaledPageSize.scale(frame->view()->contentsSize().width() / pageRect.width( )); 313 scaledPageSize.scale(frame->view()->contentsSize().width() / pageRect.width( ));
330 printContext.computePageRectsWithPageSize(scaledPageSize, false); 314 printContext.computePageRectsWithPageSize(scaledPageSize, false);
331 return printContext.pageCount(); 315 return printContext.pageCount();
332 } 316 }
333 317
334 void PrintContext::spoolAllPagesWithBoundaries(LocalFrame* frame, GraphicsContex t& graphicsContext, const FloatSize& pageSizeInPixels)
335 {
336 if (!frame->document() || !frame->view() || !frame->document()->renderView() )
337 return;
338
339 frame->document()->updateLayout();
340
341 PrintContext printContext(frame);
342 printContext.begin(pageSizeInPixels.width(), pageSizeInPixels.height());
343
344 float pageHeight;
345 printContext.computePageRects(FloatRect(FloatPoint(0, 0), pageSizeInPixels), 0, 0, 1, pageHeight);
346
347 const float pageWidth = pageSizeInPixels.width();
348 const Vector<IntRect>& pageRects = printContext.pageRects();
349 int totalHeight = pageRects.size() * (pageSizeInPixels.height() + 1) - 1;
350
351 // Fill the whole background by white.
352 graphicsContext.setFillColor(Color(255, 255, 255));
353 graphicsContext.fillRect(FloatRect(0, 0, pageWidth, totalHeight));
354
355 graphicsContext.save();
356 graphicsContext.translate(0, totalHeight);
357 graphicsContext.scale(1, -1);
358
359 int currentHeight = 0;
360 for (size_t pageIndex = 0; pageIndex < pageRects.size(); pageIndex++) {
361 // Draw a line for a page boundary if this isn't the first page.
362 if (pageIndex > 0) {
363 graphicsContext.save();
364 graphicsContext.setStrokeColor(Color(0, 0, 255));
365 graphicsContext.setFillColor(Color(0, 0, 255));
366 graphicsContext.drawLine(IntPoint(0, currentHeight),
367 IntPoint(pageWidth, currentHeight));
368 graphicsContext.restore();
369 }
370
371 graphicsContext.save();
372 graphicsContext.translate(0, currentHeight);
373 printContext.spoolPage(graphicsContext, pageIndex, pageWidth);
374 graphicsContext.restore();
375
376 currentHeight += pageSizeInPixels.height() + 1;
377 }
378
379 graphicsContext.restore();
380 }
381
382 void PrintContext::trace(Visitor* visitor) 318 void PrintContext::trace(Visitor* visitor)
383 { 319 {
384 #if ENABLE(OILPAN) 320 #if ENABLE(OILPAN)
385 visitor->trace(m_linkedDestinations); 321 visitor->trace(m_linkedDestinations);
386 #endif 322 #endif
387 } 323 }
388 324
389 } 325 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698