| 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 // Save the original page size here to avoid rounding errors incurred by |
| 1851 // converting to pixels and back and by scaling the page for reflow and |
| 1852 // scaling back. Windows uses |page_size_in_dpi| for the actual page size |
| 1853 // so requires an accurate value. |
| 1854 gfx::Size original_page_size = params.params.page_size; |
| 1849 ComputePageLayoutInPointsForCss(frame, params.page_number, params.params, | 1855 ComputePageLayoutInPointsForCss(frame, params.page_number, params.params, |
| 1850 ignore_css_margins_, &css_scale_factor, | 1856 ignore_css_margins_, &css_scale_factor, |
| 1851 &page_layout_in_points); | 1857 &page_layout_in_points); |
| 1852 gfx::Size page_size; | 1858 gfx::Size page_size; |
| 1853 gfx::Rect content_area; | 1859 gfx::Rect content_area; |
| 1854 GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, &page_size, | 1860 GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, &page_size, |
| 1855 &content_area); | 1861 &content_area); |
| 1856 int dpi = static_cast<int>(params.params.dpi); | 1862 |
| 1857 // Calculate the actual page size and content area in dpi. | 1863 // Calculate the actual page size and content area in dpi. |
| 1858 if (page_size_in_dpi) { | 1864 if (page_size_in_dpi) { |
| 1859 // Windows uses this for the actual page size. We have scaled page size | 1865 *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 } | 1866 } |
| 1870 | 1867 |
| 1871 if (content_area_in_dpi) { | 1868 if (content_area_in_dpi) { |
| 1872 // Output PDF matches paper size and should be printer edge to edge. | 1869 // Output PDF matches paper size and should be printer edge to edge. |
| 1873 *content_area_in_dpi = | 1870 *content_area_in_dpi = |
| 1874 gfx::Rect(0, 0, page_size_in_dpi->width(), page_size_in_dpi->height()); | 1871 gfx::Rect(0, 0, page_size_in_dpi->width(), page_size_in_dpi->height()); |
| 1875 } | 1872 } |
| 1876 if (printable_area_in_dpi) { | 1873 if (printable_area_in_dpi) { |
| 1877 *printable_area_in_dpi = printer_printable_area_; | 1874 *printable_area_in_dpi = printer_printable_area_; |
| 1878 } | 1875 } |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2360 blink::WebConsoleMessage::LevelWarning, message)); | 2357 blink::WebConsoleMessage::LevelWarning, message)); |
| 2361 return false; | 2358 return false; |
| 2362 } | 2359 } |
| 2363 | 2360 |
| 2364 void PrintWebViewHelper::ScriptingThrottler::Reset() { | 2361 void PrintWebViewHelper::ScriptingThrottler::Reset() { |
| 2365 // Reset counter on successful print. | 2362 // Reset counter on successful print. |
| 2366 count_ = 0; | 2363 count_ = 0; |
| 2367 } | 2364 } |
| 2368 | 2365 |
| 2369 } // namespace printing | 2366 } // namespace printing |
| OLD | NEW |