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 1082 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1093 // Print page onto entire page not just printable area. Preview PDF already | 1093 // Print page onto entire page not just printable area. Preview PDF already |
1094 // has content in correct position taking into account page size and printable | 1094 // has content in correct position taking into account page size and printable |
1095 // area. | 1095 // area. |
1096 // TODO(vitalybuka) : Make this consistent on all platform. This change | 1096 // TODO(vitalybuka) : Make this consistent on all platform. This change |
1097 // affects Windows only. On Linux and OSX RenderPagesForPrint does not use | 1097 // affects Windows only. On Linux and OSX RenderPagesForPrint does not use |
1098 // printable_area. Also we can't change printable_area deeper inside | 1098 // printable_area. Also we can't change printable_area deeper inside |
1099 // RenderPagesForPrint for Windows, because it's used also by native | 1099 // RenderPagesForPrint for Windows, because it's used also by native |
1100 // printing and it expects real printable_area value. | 1100 // printing and it expects real printable_area value. |
1101 // See http://crbug.com/123408 | 1101 // See http://crbug.com/123408 |
1102 PrintMsg_Print_Params& print_params = print_pages_params_->params; | 1102 PrintMsg_Print_Params& print_params = print_pages_params_->params; |
| 1103 printer_printable_area_ = print_params.printable_area; |
1103 print_params.printable_area = gfx::Rect(print_params.page_size); | 1104 print_params.printable_area = gfx::Rect(print_params.page_size); |
1104 | 1105 |
1105 // Render Pages for printing. | 1106 // Render Pages for printing. |
1106 if (!RenderPagesForPrint(plugin_frame, plugin_element)) { | 1107 if (!RenderPagesForPrint(plugin_frame, plugin_element)) { |
1107 LOG(ERROR) << "RenderPagesForPrint failed"; | 1108 LOG(ERROR) << "RenderPagesForPrint failed"; |
1108 DidFinishPrinting(FAIL_PRINT); | 1109 DidFinishPrinting(FAIL_PRINT); |
1109 } | 1110 } |
1110 } | 1111 } |
1111 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) && BUILDFLAG(ENABLE_PRINT_PREVIEW) | 1112 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) && BUILDFLAG(ENABLE_PRINT_PREVIEW) |
1112 | 1113 |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1327 page_params.page_number = page_number; | 1328 page_params.page_number = page_number; |
1328 std::unique_ptr<PdfMetafileSkia> draft_metafile; | 1329 std::unique_ptr<PdfMetafileSkia> draft_metafile; |
1329 PdfMetafileSkia* initial_render_metafile = print_preview_context_.metafile(); | 1330 PdfMetafileSkia* initial_render_metafile = print_preview_context_.metafile(); |
1330 if (print_preview_context_.IsModifiable() && is_print_ready_metafile_sent_) { | 1331 if (print_preview_context_.IsModifiable() && is_print_ready_metafile_sent_) { |
1331 draft_metafile.reset(new PdfMetafileSkia(PDF_SKIA_DOCUMENT_TYPE)); | 1332 draft_metafile.reset(new PdfMetafileSkia(PDF_SKIA_DOCUMENT_TYPE)); |
1332 initial_render_metafile = draft_metafile.get(); | 1333 initial_render_metafile = draft_metafile.get(); |
1333 } | 1334 } |
1334 | 1335 |
1335 base::TimeTicks begin_time = base::TimeTicks::Now(); | 1336 base::TimeTicks begin_time = base::TimeTicks::Now(); |
1336 PrintPageInternal(page_params, print_preview_context_.prepared_frame(), | 1337 PrintPageInternal(page_params, print_preview_context_.prepared_frame(), |
1337 initial_render_metafile, nullptr, nullptr); | 1338 initial_render_metafile, nullptr, nullptr, nullptr); |
1338 print_preview_context_.RenderedPreviewPage( | 1339 print_preview_context_.RenderedPreviewPage( |
1339 base::TimeTicks::Now() - begin_time); | 1340 base::TimeTicks::Now() - begin_time); |
1340 if (draft_metafile.get()) { | 1341 if (draft_metafile.get()) { |
1341 draft_metafile->FinishDocument(); | 1342 draft_metafile->FinishDocument(); |
1342 } else if (print_preview_context_.IsModifiable() && | 1343 } else if (print_preview_context_.IsModifiable() && |
1343 print_preview_context_.generate_draft_pages()) { | 1344 print_preview_context_.generate_draft_pages()) { |
1344 DCHECK(!draft_metafile.get()); | 1345 DCHECK(!draft_metafile.get()); |
1345 draft_metafile = | 1346 draft_metafile = |
1346 print_preview_context_.metafile()->GetMetafileForCurrentPage( | 1347 print_preview_context_.metafile()->GetMetafileForCurrentPage( |
1347 PDF_SKIA_DOCUMENT_TYPE); | 1348 PDF_SKIA_DOCUMENT_TYPE); |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1828 return true; | 1829 return true; |
1829 } | 1830 } |
1830 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) | 1831 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) |
1831 | 1832 |
1832 #if !defined(OS_MACOSX) | 1833 #if !defined(OS_MACOSX) |
1833 void PrintWebViewHelper::PrintPageInternal( | 1834 void PrintWebViewHelper::PrintPageInternal( |
1834 const PrintMsg_PrintPage_Params& params, | 1835 const PrintMsg_PrintPage_Params& params, |
1835 blink::WebLocalFrame* frame, | 1836 blink::WebLocalFrame* frame, |
1836 PdfMetafileSkia* metafile, | 1837 PdfMetafileSkia* metafile, |
1837 gfx::Size* page_size_in_dpi, | 1838 gfx::Size* page_size_in_dpi, |
1838 gfx::Rect* content_area_in_dpi) { | 1839 gfx::Rect* content_area_in_dpi, |
| 1840 gfx::Rect* printable_area_in_dpi) { |
1839 PageSizeMargins page_layout_in_points; | 1841 PageSizeMargins page_layout_in_points; |
1840 | 1842 |
1841 double css_scale_factor = 1.0f; | 1843 double css_scale_factor = 1.0f; |
1842 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) | 1844 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
1843 if (params.params.scale_factor >= kEpsilon) | 1845 if (params.params.scale_factor >= kEpsilon) |
1844 css_scale_factor = params.params.scale_factor; | 1846 css_scale_factor = params.params.scale_factor; |
1845 #endif | 1847 #endif |
1846 ComputePageLayoutInPointsForCss(frame, params.page_number, params.params, | 1848 ComputePageLayoutInPointsForCss(frame, params.page_number, params.params, |
1847 ignore_css_margins_, &css_scale_factor, | 1849 ignore_css_margins_, &css_scale_factor, |
1848 &page_layout_in_points); | 1850 &page_layout_in_points); |
1849 gfx::Size page_size; | 1851 gfx::Size page_size; |
1850 gfx::Rect content_area; | 1852 gfx::Rect content_area; |
1851 GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, &page_size, | 1853 GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, &page_size, |
1852 &content_area); | 1854 &content_area); |
1853 int dpi = static_cast<int>(params.params.dpi); | 1855 int dpi = static_cast<int>(params.params.dpi); |
1854 // Calculate the actual page size and content area in dpi. | 1856 // Calculate the actual page size and content area in dpi. |
1855 if (page_size_in_dpi) { | 1857 if (page_size_in_dpi) { |
1856 *page_size_in_dpi = | 1858 *page_size_in_dpi = |
1857 gfx::Size(static_cast<int>(ConvertUnitDouble(page_size.width(), | 1859 gfx::Size(static_cast<int>(ConvertUnitDouble(page_size.width(), |
1858 kPointsPerInch, dpi)), | 1860 kPointsPerInch, dpi)), |
1859 static_cast<int>(ConvertUnitDouble(page_size.height(), | 1861 static_cast<int>(ConvertUnitDouble(page_size.height(), |
1860 kPointsPerInch, dpi))); | 1862 kPointsPerInch, dpi))); |
1861 } | 1863 } |
1862 | 1864 |
1863 if (content_area_in_dpi) { | 1865 if (content_area_in_dpi) { |
1864 // Output PDF matches paper size and should be printer edge to edge. | 1866 // Output PDF matches paper size and should be printer edge to edge. |
1865 *content_area_in_dpi = | 1867 *content_area_in_dpi = |
1866 gfx::Rect(0, 0, page_size_in_dpi->width(), page_size_in_dpi->height()); | 1868 gfx::Rect(0, 0, page_size_in_dpi->width(), page_size_in_dpi->height()); |
1867 } | 1869 } |
| 1870 if (printable_area_in_dpi) { |
| 1871 *printable_area_in_dpi = printer_printable_area_; |
| 1872 } |
1868 | 1873 |
1869 gfx::Rect canvas_area = | 1874 gfx::Rect canvas_area = |
1870 params.params.display_header_footer ? gfx::Rect(page_size) : content_area; | 1875 params.params.display_header_footer ? gfx::Rect(page_size) : content_area; |
1871 | 1876 |
1872 // TODO(thestig): Figure out why Linux is different. | 1877 // TODO(thestig): Figure out why Linux is different. |
1873 #if defined(OS_WIN) | 1878 #if defined(OS_WIN) |
1874 float webkit_page_shrink_factor = | 1879 float webkit_page_shrink_factor = |
1875 frame->getPrintPageShrink(params.page_number); | 1880 frame->getPrintPageShrink(params.page_number); |
1876 float scale_factor = css_scale_factor * webkit_page_shrink_factor; | 1881 float scale_factor = css_scale_factor * webkit_page_shrink_factor; |
1877 #else | 1882 #else |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2349 blink::WebConsoleMessage::LevelWarning, message)); | 2354 blink::WebConsoleMessage::LevelWarning, message)); |
2350 return false; | 2355 return false; |
2351 } | 2356 } |
2352 | 2357 |
2353 void PrintWebViewHelper::ScriptingThrottler::Reset() { | 2358 void PrintWebViewHelper::ScriptingThrottler::Reset() { |
2354 // Reset counter on successful print. | 2359 // Reset counter on successful print. |
2355 count_ = 0; | 2360 count_ = 0; |
2356 } | 2361 } |
2357 | 2362 |
2358 } // namespace printing | 2363 } // namespace printing |
OLD | NEW |