| OLD | NEW |
| 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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 | 278 |
| 279 public: | 279 public: |
| 280 ChromePrintContext(LocalFrame* frame) | 280 ChromePrintContext(LocalFrame* frame) |
| 281 : PrintContext(frame), m_printedPageWidth(0) {} | 281 : PrintContext(frame), m_printedPageWidth(0) {} |
| 282 | 282 |
| 283 ~ChromePrintContext() override {} | 283 ~ChromePrintContext() override {} |
| 284 | 284 |
| 285 virtual void begin(float width, float height) { | 285 virtual void begin(float width, float height) { |
| 286 DCHECK(!m_printedPageWidth); | 286 DCHECK(!m_printedPageWidth); |
| 287 m_printedPageWidth = width; | 287 m_printedPageWidth = width; |
| 288 m_printedPageHeight = height; |
| 288 PrintContext::begin(m_printedPageWidth, height); | 289 PrintContext::begin(m_printedPageWidth, height); |
| 289 } | 290 } |
| 290 | 291 |
| 291 virtual float getPageShrink(int pageNumber) const { | 292 virtual float getPageShrink(int pageNumber) const { |
| 292 IntRect pageRect = m_pageRects[pageNumber]; | 293 IntRect pageRect = m_pageRects[pageNumber]; |
| 293 return m_printedPageWidth / pageRect.width(); | 294 return m_printedPageWidth / pageRect.width(); |
| 294 } | 295 } |
| 295 | 296 |
| 296 float spoolSinglePage(WebCanvas* canvas, int pageNumber) { | 297 float spoolSinglePage(WebCanvas* canvas, int pageNumber) { |
| 297 dispatchEventsForPrintingOnAllFrames(); | 298 dispatchEventsForPrintingOnAllFrames(); |
| 298 if (!frame()->document() || frame()->document()->layoutViewItem().isNull()) | 299 if (!frame()->document() || frame()->document()->layoutViewItem().isNull()) |
| 299 return 0; | 300 return 0; |
| 300 | 301 |
| 301 frame()->view()->updateAllLifecyclePhasesExceptPaint(); | 302 frame()->view()->updateAllLifecyclePhasesExceptPaint(); |
| 302 if (!frame()->document() || frame()->document()->layoutViewItem().isNull()) | 303 if (!frame()->document() || frame()->document()->layoutViewItem().isNull()) |
| 303 return 0; | 304 return 0; |
| 304 | 305 |
| 305 IntRect pageRect = m_pageRects[pageNumber]; | 306 // The page rect gets scaled and translated, so specify the entire |
| 306 PaintRecordBuilder builder(pageRect, &canvas->getMetaData()); | 307 // print content area here as the recording rect. |
| 308 IntRect printedPageRect(0, 0, m_printedPageHeight, m_printedPageWidth); |
| 309 PaintRecordBuilder builder(printedPageRect, &canvas->getMetaData()); |
| 307 builder.context().setPrinting(true); | 310 builder.context().setPrinting(true); |
| 308 | 311 |
| 309 float scale = spoolPage(builder, pageNumber); | 312 float scale = spoolPage(builder, pageNumber); |
| 310 canvas->drawPicture(builder.endRecording()); | 313 canvas->drawPicture(builder.endRecording()); |
| 311 return scale; | 314 return scale; |
| 312 } | 315 } |
| 313 | 316 |
| 314 void spoolAllPagesWithBoundaries(WebCanvas* canvas, | 317 void spoolAllPagesWithBoundaries(WebCanvas* canvas, |
| 315 const FloatSize& pageSizeInPixels) { | 318 const FloatSize& pageSizeInPixels) { |
| 316 dispatchEventsForPrintingOnAllFrames(); | 319 dispatchEventsForPrintingOnAllFrames(); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 if (currentFrame->isLocalFrame()) | 422 if (currentFrame->isLocalFrame()) |
| 420 documents.push_back(toLocalFrame(currentFrame)->document()); | 423 documents.push_back(toLocalFrame(currentFrame)->document()); |
| 421 } | 424 } |
| 422 | 425 |
| 423 for (auto& doc : documents) | 426 for (auto& doc : documents) |
| 424 doc->dispatchEventsForPrinting(); | 427 doc->dispatchEventsForPrinting(); |
| 425 } | 428 } |
| 426 | 429 |
| 427 // Set when printing. | 430 // Set when printing. |
| 428 float m_printedPageWidth; | 431 float m_printedPageWidth; |
| 432 float m_printedPageHeight; |
| 429 }; | 433 }; |
| 430 | 434 |
| 431 // Simple class to override some of PrintContext behavior. This is used when | 435 // Simple class to override some of PrintContext behavior. This is used when |
| 432 // the frame hosts a plugin that supports custom printing. In this case, we | 436 // the frame hosts a plugin that supports custom printing. In this case, we |
| 433 // want to delegate all printing related calls to the plugin. | 437 // want to delegate all printing related calls to the plugin. |
| 434 class ChromePluginPrintContext final : public ChromePrintContext { | 438 class ChromePluginPrintContext final : public ChromePrintContext { |
| 435 public: | 439 public: |
| 436 ChromePluginPrintContext(LocalFrame* frame, | 440 ChromePluginPrintContext(LocalFrame* frame, |
| 437 WebPluginContainerImpl* plugin, | 441 WebPluginContainerImpl* plugin, |
| 438 const WebPrintParams& printParams) | 442 const WebPrintParams& printParams) |
| (...skipping 2021 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2460 createMarkup(startPosition, endPosition, AnnotateForInterchange, | 2464 createMarkup(startPosition, endPosition, AnnotateForInterchange, |
| 2461 ConvertBlocksToInlines::NotConvert, ResolveNonLocalURLs); | 2465 ConvertBlocksToInlines::NotConvert, ResolveNonLocalURLs); |
| 2462 } else { | 2466 } else { |
| 2463 clipHtml = | 2467 clipHtml = |
| 2464 createMarkup(endPosition, startPosition, AnnotateForInterchange, | 2468 createMarkup(endPosition, startPosition, AnnotateForInterchange, |
| 2465 ConvertBlocksToInlines::NotConvert, ResolveNonLocalURLs); | 2469 ConvertBlocksToInlines::NotConvert, ResolveNonLocalURLs); |
| 2466 } | 2470 } |
| 2467 } | 2471 } |
| 2468 | 2472 |
| 2469 } // namespace blink | 2473 } // namespace blink |
| OLD | NEW |