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

Side by Side Diff: Source/web/WebLocalFrameImpl.cpp

Issue 471623003: WebLocalFrameImpl::printPage needs to ensure layout, style, and compositing are up-to-date (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
« no previous file with comments | « Source/core/rendering/RenderLayer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 m_printedPageWidth = width; 301 m_printedPageWidth = width;
302 PrintContext::begin(m_printedPageWidth, height); 302 PrintContext::begin(m_printedPageWidth, height);
303 } 303 }
304 304
305 virtual float getPageShrink(int pageNumber) const 305 virtual float getPageShrink(int pageNumber) const
306 { 306 {
307 IntRect pageRect = m_pageRects[pageNumber]; 307 IntRect pageRect = m_pageRects[pageNumber];
308 return m_printedPageWidth / pageRect.width(); 308 return m_printedPageWidth / pageRect.width();
309 } 309 }
310 310
311 // Spools the printed page, a subrect of frame(). Skip the scale step. 311 float spoolSinglePage(GraphicsContext& graphicsContext, int pageNumber)
312 // NativeTheme doesn't play well with scaling. Scaling is done browser side
313 // instead. Returns the scale to be applied.
314 // On Linux, we don't have the problem with NativeTheme, hence we let WebKit
315 // do the scaling and ignore the return value.
316 virtual float spoolPage(GraphicsContext& context, int pageNumber)
317 { 312 {
318 IntRect pageRect = m_pageRects[pageNumber]; 313 // FIXME: Why is it ok to proceed without all the null checks that
319 float scale = m_printedPageWidth / pageRect.width(); 314 // spoolAllPagesWithBoundaries does?
320 315 frame()->view()->updateLayoutAndStyleForPainting();
321 context.save(); 316 return spoolPage(graphicsContext, pageNumber);
322 #if OS(POSIX) && !OS(MACOSX)
323 context.scale(scale, scale);
324 #endif
325 context.translate(static_cast<float>(-pageRect.x()), static_cast<float>( -pageRect.y()));
326 context.clip(pageRect);
327 frame()->view()->paintContents(&context, pageRect);
328 if (context.supportsURLFragments())
329 outputLinkedDestinations(context, frame()->document(), pageRect);
330 context.restore();
331 return scale;
332 } 317 }
333 318
334 void spoolAllPagesWithBoundaries(GraphicsContext& graphicsContext, const Flo atSize& pageSizeInPixels) 319 void spoolAllPagesWithBoundaries(GraphicsContext& graphicsContext, const Flo atSize& pageSizeInPixels)
335 { 320 {
336 if (!frame()->document() || !frame()->view() || !frame()->document()->re nderView()) 321 if (!frame()->document() || !frame()->view() || !frame()->document()->re nderView())
337 return; 322 return;
338 323
339 frame()->view()->updateLayoutAndStyleForPainting(); 324 frame()->view()->updateLayoutAndStyleForPainting();
340 325
341 float pageHeight; 326 float pageHeight;
(...skipping 27 matching lines...) Expand all
369 float scale = getPageShrink(pageIndex); 354 float scale = getPageShrink(pageIndex);
370 graphicsContext.scale(scale, scale); 355 graphicsContext.scale(scale, scale);
371 #endif 356 #endif
372 spoolPage(graphicsContext, pageIndex); 357 spoolPage(graphicsContext, pageIndex);
373 graphicsContext.restore(); 358 graphicsContext.restore();
374 359
375 currentHeight += pageSizeInPixels.height() + 1; 360 currentHeight += pageSizeInPixels.height() + 1;
376 } 361 }
377 } 362 }
378 363
364 protected:
365 // Spools the printed page, a subrect of frame(). Skip the scale step.
366 // NativeTheme doesn't play well with scaling. Scaling is done browser side
367 // instead. Returns the scale to be applied.
368 // On Linux, we don't have the problem with NativeTheme, hence we let WebKit
369 // do the scaling and ignore the return value.
370 virtual float spoolPage(GraphicsContext& context, int pageNumber)
371 {
372 IntRect pageRect = m_pageRects[pageNumber];
373 float scale = m_printedPageWidth / pageRect.width();
374
375 context.save();
376 #if OS(POSIX) && !OS(MACOSX)
377 context.scale(scale, scale);
378 #endif
379 context.translate(static_cast<float>(-pageRect.x()), static_cast<float>( -pageRect.y()));
380 context.clip(pageRect);
381 frame()->view()->paintContents(&context, pageRect);
382 if (context.supportsURLFragments())
383 outputLinkedDestinations(context, frame()->document(), pageRect);
384 context.restore();
385 return scale;
386 }
387
379 private: 388 private:
380 // Set when printing. 389 // Set when printing.
381 float m_printedPageWidth; 390 float m_printedPageWidth;
382 }; 391 };
383 392
384 // Simple class to override some of PrintContext behavior. This is used when 393 // Simple class to override some of PrintContext behavior. This is used when
385 // the frame hosts a plugin that supports custom printing. In this case, we 394 // the frame hosts a plugin that supports custom printing. In this case, we
386 // want to delegate all printing related calls to the plugin. 395 // want to delegate all printing related calls to the plugin.
387 class ChromePluginPrintContext FINAL : public ChromePrintContext { 396 class ChromePluginPrintContext FINAL : public ChromePrintContext {
388 public: 397 public:
(...skipping 23 matching lines...) Expand all
412 { 421 {
413 m_printParams.printContentArea = IntRect(printRect); 422 m_printParams.printContentArea = IntRect(printRect);
414 m_pageCount = m_plugin->printBegin(m_printParams); 423 m_pageCount = m_plugin->printBegin(m_printParams);
415 } 424 }
416 425
417 virtual int pageCount() const 426 virtual int pageCount() const
418 { 427 {
419 return m_pageCount; 428 return m_pageCount;
420 } 429 }
421 430
431 protected:
422 // Spools the printed page, a subrect of frame(). Skip the scale step. 432 // Spools the printed page, a subrect of frame(). Skip the scale step.
423 // NativeTheme doesn't play well with scaling. Scaling is done browser side 433 // NativeTheme doesn't play well with scaling. Scaling is done browser side
424 // instead. Returns the scale to be applied. 434 // instead. Returns the scale to be applied.
425 virtual float spoolPage(GraphicsContext& context, int pageNumber) 435 virtual float spoolPage(GraphicsContext& context, int pageNumber)
426 { 436 {
427 m_plugin->printPage(pageNumber, &context); 437 m_plugin->printPage(pageNumber, &context);
428 return 1.0; 438 return 1.0;
429 } 439 }
430 440
431 private: 441 private:
(...skipping 848 matching lines...) Expand 10 before | Expand all | Expand 10 after
1280 return m_printContext->getPageShrink(page); 1290 return m_printContext->getPageShrink(page);
1281 } 1291 }
1282 1292
1283 float WebLocalFrameImpl::printPage(int page, WebCanvas* canvas) 1293 float WebLocalFrameImpl::printPage(int page, WebCanvas* canvas)
1284 { 1294 {
1285 #if ENABLE(PRINTING) 1295 #if ENABLE(PRINTING)
1286 ASSERT(m_printContext && page >= 0 && frame() && frame()->document()); 1296 ASSERT(m_printContext && page >= 0 && frame() && frame()->document());
1287 1297
1288 GraphicsContext graphicsContext(canvas); 1298 GraphicsContext graphicsContext(canvas);
1289 graphicsContext.setPrinting(true); 1299 graphicsContext.setPrinting(true);
1290 return m_printContext->spoolPage(graphicsContext, page); 1300 return m_printContext->spoolSinglePage(graphicsContext, page);
1291 #else 1301 #else
1292 return 0; 1302 return 0;
1293 #endif 1303 #endif
1294 } 1304 }
1295 1305
1296 void WebLocalFrameImpl::printEnd() 1306 void WebLocalFrameImpl::printEnd()
1297 { 1307 {
1298 ASSERT(m_printContext); 1308 ASSERT(m_printContext);
1299 m_printContext->end(); 1309 m_printContext->end();
1300 m_printContext.clear(); 1310 m_printContext.clear();
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
1860 1870
1861 void WebLocalFrameImpl::invalidateAll() const 1871 void WebLocalFrameImpl::invalidateAll() const
1862 { 1872 {
1863 ASSERT(frame() && frame()->view()); 1873 ASSERT(frame() && frame()->view());
1864 FrameView* view = frame()->view(); 1874 FrameView* view = frame()->view();
1865 view->invalidateRect(view->frameRect()); 1875 view->invalidateRect(view->frameRect());
1866 invalidateScrollbar(); 1876 invalidateScrollbar();
1867 } 1877 }
1868 1878
1869 } // namespace blink 1879 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/rendering/RenderLayer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698