Chromium Code Reviews| 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 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 1825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1836 const PrintMsg_PrintPage_Params& params, | 1836 const PrintMsg_PrintPage_Params& params, |
| 1837 blink::WebLocalFrame* frame, | 1837 blink::WebLocalFrame* frame, |
| 1838 PdfMetafileSkia* metafile, | 1838 PdfMetafileSkia* metafile, |
| 1839 gfx::Size* page_size_in_dpi, | 1839 gfx::Size* page_size_in_dpi, |
| 1840 gfx::Rect* content_area_in_dpi, | 1840 gfx::Rect* content_area_in_dpi, |
| 1841 gfx::Rect* printable_area_in_dpi) { | 1841 gfx::Rect* printable_area_in_dpi) { |
| 1842 PageSizeMargins page_layout_in_points; | 1842 PageSizeMargins page_layout_in_points; |
| 1843 | 1843 |
| 1844 double css_scale_factor = 1.0f; | 1844 double css_scale_factor = 1.0f; |
| 1845 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) | 1845 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| 1846 if (params.params.scale_factor >= kEpsilon) | 1846 if (params.params.scale_factor >= kEpsilon) |
| 1847 css_scale_factor = params.params.scale_factor; | 1847 css_scale_factor = params.params.scale_factor; |
| 1848 #endif | 1848 #endif |
| 1849 | |
| 1850 // Pull the original page size here. Windows uses the page_size_in_dpi | |
|
Lei Zhang
2017/02/22 21:21:37
s/Pull/Save/ ?
"Windows uses |page_size_in_dpi| .
rbpotter
2017/02/23 22:27:11
Done.
| |
| 1851 // for the actual page size, and we incur rounding error by converting to | |
| 1852 // pixels and back and by scaling the page for reflow and scaling back. | |
| 1853 gfx::Size original_page_size = params.params.page_size; | |
| 1849 ComputePageLayoutInPointsForCss(frame, params.page_number, params.params, | 1854 ComputePageLayoutInPointsForCss(frame, params.page_number, params.params, |
| 1850 ignore_css_margins_, &css_scale_factor, | 1855 ignore_css_margins_, &css_scale_factor, |
| 1851 &page_layout_in_points); | 1856 &page_layout_in_points); |
| 1852 gfx::Size page_size; | 1857 gfx::Size page_size; |
| 1853 gfx::Rect content_area; | 1858 gfx::Rect content_area; |
| 1854 GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, &page_size, | 1859 GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, &page_size, |
| 1855 &content_area); | 1860 &content_area); |
| 1856 int dpi = static_cast<int>(params.params.dpi); | 1861 |
| 1857 // Calculate the actual page size and content area in dpi. | 1862 // Calculate the actual page size and content area in dpi. |
| 1858 if (page_size_in_dpi) { | 1863 if (page_size_in_dpi) { |
| 1859 // Windows uses this for the actual page size. We have scaled page size | 1864 *page_size_in_dpi = original_page_size; |
| 1860 // to get blink to reflow the page, so scale it back to the real size | |
| 1861 // before returning it. | |
| 1862 *page_size_in_dpi = | |
| 1863 gfx::Size(static_cast<int>(ConvertUnitDouble(page_size.width(), | |
| 1864 kPointsPerInch, dpi) * | |
| 1865 css_scale_factor), | |
| 1866 static_cast<int>(ConvertUnitDouble(page_size.height(), | |
| 1867 kPointsPerInch, dpi) * | |
| 1868 css_scale_factor)); | |
| 1869 } | 1865 } |
| 1870 | 1866 |
| 1871 if (content_area_in_dpi) { | 1867 if (content_area_in_dpi) { |
| 1872 // Output PDF matches paper size and should be printer edge to edge. | 1868 // Output PDF matches paper size and should be printer edge to edge. |
| 1873 *content_area_in_dpi = | 1869 *content_area_in_dpi = |
| 1874 gfx::Rect(0, 0, page_size_in_dpi->width(), page_size_in_dpi->height()); | 1870 gfx::Rect(0, 0, page_size_in_dpi->width(), page_size_in_dpi->height()); |
| 1875 } | 1871 } |
| 1876 if (printable_area_in_dpi) { | 1872 if (printable_area_in_dpi) { |
| 1877 *printable_area_in_dpi = printer_printable_area_; | 1873 *printable_area_in_dpi = printer_printable_area_; |
| 1878 } | 1874 } |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2360 blink::WebConsoleMessage::LevelWarning, message)); | 2356 blink::WebConsoleMessage::LevelWarning, message)); |
| 2361 return false; | 2357 return false; |
| 2362 } | 2358 } |
| 2363 | 2359 |
| 2364 void PrintWebViewHelper::ScriptingThrottler::Reset() { | 2360 void PrintWebViewHelper::ScriptingThrottler::Reset() { |
| 2365 // Reset counter on successful print. | 2361 // Reset counter on successful print. |
| 2366 count_ = 0; | 2362 count_ = 0; |
| 2367 } | 2363 } |
| 2368 | 2364 |
| 2369 } // namespace printing | 2365 } // namespace printing |
| OLD | NEW |