OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/printing/renderer/print_web_view_helper.h" | 5 #include "components/printing/renderer/print_web_view_helper.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 enum PrintPreviewHelperEvents { | 71 enum PrintPreviewHelperEvents { |
72 PREVIEW_EVENT_REQUESTED, | 72 PREVIEW_EVENT_REQUESTED, |
73 PREVIEW_EVENT_CACHE_HIT, // Unused | 73 PREVIEW_EVENT_CACHE_HIT, // Unused |
74 PREVIEW_EVENT_CREATE_DOCUMENT, | 74 PREVIEW_EVENT_CREATE_DOCUMENT, |
75 PREVIEW_EVENT_NEW_SETTINGS, // Unused | 75 PREVIEW_EVENT_NEW_SETTINGS, // Unused |
76 PREVIEW_EVENT_MAX, | 76 PREVIEW_EVENT_MAX, |
77 }; | 77 }; |
78 | 78 |
79 const double kMinDpi = 1.0; | 79 const double kMinDpi = 1.0; |
80 | 80 |
81 // Also set in third_party/WebKit/Source/core/page/PrintContext.cpp | |
82 const float kPrintingMinimumShrinkFactor = 1.333f; | |
83 | |
84 #if defined(ENABLE_PRINT_PREVIEW) | 81 #if defined(ENABLE_PRINT_PREVIEW) |
85 bool g_is_preview_enabled = true; | 82 bool g_is_preview_enabled = true; |
86 | 83 |
87 const char kPageLoadScriptFormat[] = | 84 const char kPageLoadScriptFormat[] = |
88 "document.open(); document.write(%s); document.close();"; | 85 "document.open(); document.write(%s); document.close();"; |
89 | 86 |
90 const char kPageSetupScriptFormat[] = "setup(%s);"; | 87 const char kPageSetupScriptFormat[] = "setup(%s);"; |
91 | 88 |
92 void ExecuteScript(blink::WebFrame* frame, | 89 void ExecuteScript(blink::WebFrame* frame, |
93 const char* script_format, | 90 const char* script_format, |
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 } | 670 } |
674 ComputeWebKitPrintParamsInDesiredDpi(print_params, &web_print_params_); | 671 ComputeWebKitPrintParamsInDesiredDpi(print_params, &web_print_params_); |
675 } | 672 } |
676 | 673 |
677 PrepareFrameAndViewForPrint::~PrepareFrameAndViewForPrint() { | 674 PrepareFrameAndViewForPrint::~PrepareFrameAndViewForPrint() { |
678 FinishPrinting(); | 675 FinishPrinting(); |
679 } | 676 } |
680 | 677 |
681 void PrepareFrameAndViewForPrint::ResizeForPrinting() { | 678 void PrepareFrameAndViewForPrint::ResizeForPrinting() { |
682 // Layout page according to printer page size. Since WebKit shrinks the | 679 // Layout page according to printer page size. Since WebKit shrinks the |
683 // size of the page automatically (from 133.3% to 200%) we trick it to | 680 // size of the page automatically (from 125% to 200%) we trick it to |
684 // think the page is 133.3% larger so the size of the page is correct for | 681 // think the page is 125% larger so the size of the page is correct for |
685 // minimum (default) scaling. | 682 // minimum (default) scaling. |
686 // The scaling factor 1.25 was originally chosen as a magic number that | |
687 // was 'about right'. However per https://crbug.com/273306 1.333 seems to be | |
688 // the number that produces output with the correct physical size for elements | |
689 // that are specified in cm, mm, pt etc. | |
690 // This is important for sites that try to fill the page. | 683 // This is important for sites that try to fill the page. |
| 684 // The 1.25 value is |printingMinimumShrinkFactor|. |
691 gfx::Size print_layout_size(web_print_params_.printContentArea.width, | 685 gfx::Size print_layout_size(web_print_params_.printContentArea.width, |
692 web_print_params_.printContentArea.height); | 686 web_print_params_.printContentArea.height); |
693 print_layout_size.set_height( | 687 print_layout_size.set_height( |
694 static_cast<int>(static_cast<double>(print_layout_size.height()) * | 688 static_cast<int>(static_cast<double>(print_layout_size.height()) * 1.25)); |
695 kPrintingMinimumShrinkFactor)); | |
696 | 689 |
697 if (!frame()) | 690 if (!frame()) |
698 return; | 691 return; |
699 blink::WebView* web_view = frame_.view(); | 692 blink::WebView* web_view = frame_.view(); |
700 // Backup size and offset. | 693 // Backup size and offset. |
701 if (blink::WebFrame* web_frame = web_view->mainFrame()) | 694 if (blink::WebFrame* web_frame = web_view->mainFrame()) |
702 prev_scroll_offset_ = web_frame->scrollOffset(); | 695 prev_scroll_offset_ = web_frame->scrollOffset(); |
703 prev_view_size_ = web_view->size(); | 696 prev_view_size_ = web_view->size(); |
704 | 697 |
705 web_view->resize(print_layout_size); | 698 web_view->resize(print_layout_size); |
(...skipping 1074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1780 | 1773 |
1781 SkCanvas* canvas = metafile->GetVectorCanvasForNewPage( | 1774 SkCanvas* canvas = metafile->GetVectorCanvasForNewPage( |
1782 page_size, canvas_area, scale_factor); | 1775 page_size, canvas_area, scale_factor); |
1783 if (!canvas) | 1776 if (!canvas) |
1784 return; | 1777 return; |
1785 | 1778 |
1786 MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); | 1779 MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); |
1787 | 1780 |
1788 #if defined(ENABLE_PRINT_PREVIEW) | 1781 #if defined(ENABLE_PRINT_PREVIEW) |
1789 if (params.params.display_header_footer) { | 1782 if (params.params.display_header_footer) { |
1790 // TODO(thestig): Figure out why Linux needs this. It is almost certainly | 1783 // TODO(thestig): Figure out why Linux needs this. The value may be |
1791 // |printingMinimumShrinkFactor| from Blink. | 1784 // |printingMinimumShrinkFactor|. |
1792 #if defined(OS_WIN) | 1785 #if defined(OS_WIN) |
1793 const float fudge_factor = 1; | 1786 const float fudge_factor = 1; |
1794 #else | 1787 #else |
1795 const float fudge_factor = kPrintingMinimumShrinkFactor; | 1788 const float fudge_factor = 1.25; |
1796 #endif | 1789 #endif |
1797 // |page_number| is 0-based, so 1 is added. | 1790 // |page_number| is 0-based, so 1 is added. |
1798 PrintHeaderAndFooter(canvas, params.page_number + 1, | 1791 PrintHeaderAndFooter(canvas, params.page_number + 1, |
1799 print_preview_context_.total_page_count(), *frame, | 1792 print_preview_context_.total_page_count(), *frame, |
1800 scale_factor / fudge_factor, page_layout_in_points, | 1793 scale_factor / fudge_factor, page_layout_in_points, |
1801 params.params); | 1794 params.params); |
1802 } | 1795 } |
1803 #endif // defined(ENABLE_PRINT_PREVIEW) | 1796 #endif // defined(ENABLE_PRINT_PREVIEW) |
1804 | 1797 |
1805 float webkit_scale_factor = | 1798 float webkit_scale_factor = |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2245 blink::WebConsoleMessage::LevelWarning, message)); | 2238 blink::WebConsoleMessage::LevelWarning, message)); |
2246 return false; | 2239 return false; |
2247 } | 2240 } |
2248 | 2241 |
2249 void PrintWebViewHelper::ScriptingThrottler::Reset() { | 2242 void PrintWebViewHelper::ScriptingThrottler::Reset() { |
2250 // Reset counter on successful print. | 2243 // Reset counter on successful print. |
2251 count_ = 0; | 2244 count_ = 0; |
2252 } | 2245 } |
2253 | 2246 |
2254 } // namespace printing | 2247 } // namespace printing |
OLD | NEW |