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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 | 70 |
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 const float kPrintingMinimumShrinkFactor = 1.333f; | |
Lei Zhang
2016/03/29 01:00:46
Can you reference third_party/WebKit/Source/core/p
| |
80 | 81 |
81 #if defined(ENABLE_PRINT_PREVIEW) | 82 #if defined(ENABLE_PRINT_PREVIEW) |
82 bool g_is_preview_enabled = true; | 83 bool g_is_preview_enabled = true; |
83 | 84 |
84 const char kPageLoadScriptFormat[] = | 85 const char kPageLoadScriptFormat[] = |
85 "document.open(); document.write(%s); document.close();"; | 86 "document.open(); document.write(%s); document.close();"; |
86 | 87 |
87 const char kPageSetupScriptFormat[] = "setup(%s);"; | 88 const char kPageSetupScriptFormat[] = "setup(%s);"; |
88 | 89 |
89 void ExecuteScript(blink::WebFrame* frame, | 90 void ExecuteScript(blink::WebFrame* frame, |
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
670 } | 671 } |
671 ComputeWebKitPrintParamsInDesiredDpi(print_params, &web_print_params_); | 672 ComputeWebKitPrintParamsInDesiredDpi(print_params, &web_print_params_); |
672 } | 673 } |
673 | 674 |
674 PrepareFrameAndViewForPrint::~PrepareFrameAndViewForPrint() { | 675 PrepareFrameAndViewForPrint::~PrepareFrameAndViewForPrint() { |
675 FinishPrinting(); | 676 FinishPrinting(); |
676 } | 677 } |
677 | 678 |
678 void PrepareFrameAndViewForPrint::ResizeForPrinting() { | 679 void PrepareFrameAndViewForPrint::ResizeForPrinting() { |
679 // Layout page according to printer page size. Since WebKit shrinks the | 680 // Layout page according to printer page size. Since WebKit shrinks the |
680 // size of the page automatically (from 125% to 200%) we trick it to | 681 // size of the page automatically (from 133.3% to 200%) we trick it to |
681 // think the page is 125% larger so the size of the page is correct for | 682 // think the page is 133.3% larger so the size of the page is correct for |
682 // minimum (default) scaling. | 683 // minimum (default) scaling. |
684 // The scaling factor 1.25 was originally chosen as a magic number that | |
685 // was 'about right'. However per crbug.com/273306 1.333 seems to be | |
Lei Zhang
2016/03/29 01:00:46
https://crbug.com/...
| |
686 // the number that produces output with the correct physical size for elements | |
687 // that are specified in cm, mm, pt etc. | |
683 // This is important for sites that try to fill the page. | 688 // This is important for sites that try to fill the page. |
684 // The 1.25 value is |printingMinimumShrinkFactor|. | |
685 gfx::Size print_layout_size(web_print_params_.printContentArea.width, | 689 gfx::Size print_layout_size(web_print_params_.printContentArea.width, |
686 web_print_params_.printContentArea.height); | 690 web_print_params_.printContentArea.height); |
687 print_layout_size.set_height( | 691 print_layout_size.set_height( |
688 static_cast<int>(static_cast<double>(print_layout_size.height()) * 1.25)); | 692 static_cast<int>(static_cast<double>(print_layout_size.height()) * |
693 kPrintingMinimumShrinkFactor)); | |
689 | 694 |
690 if (!frame()) | 695 if (!frame()) |
691 return; | 696 return; |
692 blink::WebView* web_view = frame_.view(); | 697 blink::WebView* web_view = frame_.view(); |
693 // Backup size and offset. | 698 // Backup size and offset. |
694 if (blink::WebFrame* web_frame = web_view->mainFrame()) | 699 if (blink::WebFrame* web_frame = web_view->mainFrame()) |
695 prev_scroll_offset_ = web_frame->scrollOffset(); | 700 prev_scroll_offset_ = web_frame->scrollOffset(); |
696 prev_view_size_ = web_view->size(); | 701 prev_view_size_ = web_view->size(); |
697 | 702 |
698 web_view->resize(print_layout_size); | 703 web_view->resize(print_layout_size); |
(...skipping 1074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1773 | 1778 |
1774 SkCanvas* canvas = metafile->GetVectorCanvasForNewPage( | 1779 SkCanvas* canvas = metafile->GetVectorCanvasForNewPage( |
1775 page_size, canvas_area, scale_factor); | 1780 page_size, canvas_area, scale_factor); |
1776 if (!canvas) | 1781 if (!canvas) |
1777 return; | 1782 return; |
1778 | 1783 |
1779 MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); | 1784 MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); |
1780 | 1785 |
1781 #if defined(ENABLE_PRINT_PREVIEW) | 1786 #if defined(ENABLE_PRINT_PREVIEW) |
1782 if (params.params.display_header_footer) { | 1787 if (params.params.display_header_footer) { |
1783 // TODO(thestig): Figure out why Linux needs this. The value may be | 1788 // TODO(thestig): Figure out why Linux needs this. It is almost certainly |
1784 // |printingMinimumShrinkFactor|. | 1789 // |printingMinimumShrinkFactor| from Blink. |
1785 #if defined(OS_WIN) | 1790 #if defined(OS_WIN) |
1786 const float fudge_factor = 1; | 1791 const float fudge_factor = 1; |
1787 #else | 1792 #else |
1788 const float fudge_factor = 1.25; | 1793 const float fudge_factor = kPrintingMinimumShrinkFactor; |
1789 #endif | 1794 #endif |
1790 // |page_number| is 0-based, so 1 is added. | 1795 // |page_number| is 0-based, so 1 is added. |
1791 PrintHeaderAndFooter(canvas, params.page_number + 1, | 1796 PrintHeaderAndFooter(canvas, params.page_number + 1, |
1792 print_preview_context_.total_page_count(), *frame, | 1797 print_preview_context_.total_page_count(), *frame, |
1793 scale_factor / fudge_factor, page_layout_in_points, | 1798 scale_factor / fudge_factor, page_layout_in_points, |
1794 params.params); | 1799 params.params); |
1795 } | 1800 } |
1796 #endif // defined(ENABLE_PRINT_PREVIEW) | 1801 #endif // defined(ENABLE_PRINT_PREVIEW) |
1797 | 1802 |
1798 float webkit_scale_factor = | 1803 float webkit_scale_factor = |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2238 blink::WebConsoleMessage::LevelWarning, message)); | 2243 blink::WebConsoleMessage::LevelWarning, message)); |
2239 return false; | 2244 return false; |
2240 } | 2245 } |
2241 | 2246 |
2242 void PrintWebViewHelper::ScriptingThrottler::Reset() { | 2247 void PrintWebViewHelper::ScriptingThrottler::Reset() { |
2243 // Reset counter on successful print. | 2248 // Reset counter on successful print. |
2244 count_ = 0; | 2249 count_ = 0; |
2245 } | 2250 } |
2246 | 2251 |
2247 } // namespace printing | 2252 } // namespace printing |
OLD | NEW |