Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(507)

Side by Side Diff: components/printing/renderer/print_web_view_helper.cc

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

Powered by Google App Engine
This is Rietveld 408576698