From f68510a45cbb49ec3fc1298238162122d87ed7aa Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 8 Aug 2019 12:43:20 -0700 Subject: [PATCH] feat: allow customization of more print settings --- docs/api/web-contents.md | 3 +++ shell/browser/api/atom_api_web_contents.cc | 24 ++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index e081c3cb35d4c..6e2df7e8aa18f 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -1264,6 +1264,9 @@ Returns [`PrinterInfo[]`](structures/printer-info.md). * `dpi` Object (optional) * `horizontal` Number (optional) - The horizontal dpi. * `vertical` Number (optional) - The vertical dpi. + * `headerFooterInfo` Object (optional) + * `header` String - String to be printed as page header. + * `footer` String - String to be printed as page footer. * `callback` Function (optional) * `success` Boolean - Indicates success of the print call. * `failureReason` String - Called back if the print fails; can be `cancelled` or `failed`. diff --git a/shell/browser/api/atom_api_web_contents.cc b/shell/browser/api/atom_api_web_contents.cc index 685ac6fb7cea4..cff57077d0009 100644 --- a/shell/browser/api/atom_api_web_contents.cc +++ b/shell/browser/api/atom_api_web_contents.cc @@ -1637,20 +1637,20 @@ void WebContents::Print(mate::Arguments* args) { printing::DEFAULT_MARGINS); } - settings.SetBoolean(printing::kSettingHeaderFooterEnabled, false); - // Set whether to print color or greyscale bool print_color = true; options.Get("color", &print_color); int color_setting = print_color ? printing::COLOR : printing::GRAY; settings.SetInteger(printing::kSettingColor, color_setting); + // Is the orientation landscape or portrait. bool landscape = false; options.Get("landscape", &landscape); settings.SetBoolean(printing::kSettingLandscape, landscape); // We set the default to empty string here and only update // if at the Chromium level if it's non-empty + // Printer device name as opened by the OS. base::string16 device_name; options.Get("deviceName", &device_name); settings.SetString(printing::kSettingDeviceName, device_name); @@ -1663,15 +1663,31 @@ void WebContents::Print(mate::Arguments* args) { options.Get("pagesPerSheet", &pages_per_sheet); settings.SetInteger(printing::kSettingPagesPerSheet, pages_per_sheet); + // True if the user wants to print with collate. bool collate = true; options.Get("collate", &collate); settings.SetBoolean(printing::kSettingCollate, collate); + // The number of individual copies to print int copies = 1; options.Get("copies", &copies); settings.SetInteger(printing::kSettingCopies, copies); - // For now we don't want to allow the user to enable these settings + // Strings to be printed as headers and footers if requested by the user. + mate::Dictionary header_footer; + if (options.Get("headerFooterInfo", &header_footer)) { + settings.SetBoolean(printing::kSettingHeaderFooterEnabled, true); + + std::string header; + header_footer.Get("header", &header); + std::string footer; + header_footer.Get("footer", &footer); + + settings.SetString(printing::kSettingHeaderFooterTitle, header); + settings.SetString(printing::kSettingHeaderFooterURL, footer); + } + + // We don't want to allow the user to enable these settings // but we need to set them or a CHECK is hit. settings.SetBoolean(printing::kSettingPrintToPDF, false); settings.SetBoolean(printing::kSettingCloudPrintDialog, false); @@ -1700,7 +1716,7 @@ void WebContents::Print(mate::Arguments* args) { settings.SetList(printing::kSettingPageRange, std::move(page_range_list)); } - // Set custom duplex mode + // Duplex type user wants to use. printing::DuplexMode duplex_mode; options.Get("duplexMode", &duplex_mode); settings.SetInteger(printing::kSettingDuplexMode, duplex_mode);