Avi Drissman | db497b3 | 2022-09-15 19:47:28 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
sverrir@google.com | 8ff1d42 | 2009-07-07 21:31:39 | [diff] [blame] | 5 | #ifndef PRINTING_PRINT_SETTINGS_H_ |
| 6 | #define PRINTING_PRINT_SETTINGS_H_ |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 7 | |
rbpotter | 116c2e1 | 2017-04-04 19:21:28 | [diff] [blame] | 8 | #include <algorithm> |
thestig@chromium.org | dcd1e886 | 2011-08-09 06:06:58 | [diff] [blame] | 9 | #include <string> |
Sparik Hayrapetyan | 48216b3 | 2022-12-16 16:07:26 | [diff] [blame] | 10 | #include <utility> |
| 11 | #include <vector> |
thestig@chromium.org | dcd1e886 | 2011-08-09 06:06:58 | [diff] [blame] | 12 | |
Arthur Sonzogni | 59ac822 | 2023-11-10 09:46:54 | [diff] [blame] | 13 | #include <optional> |
Alan Screen | 9347cae | 2021-04-27 18:11:24 | [diff] [blame] | 14 | #include "base/component_export.h" |
Daniel Hosseinian | c3db7f4c | 2020-06-25 02:09:52 | [diff] [blame] | 15 | #include "build/build_config.h" |
Andrew Rayskiy | 16f8cab | 2022-12-15 16:28:33 | [diff] [blame] | 16 | #include "printing/buildflags/buildflags.h" |
Julie Jeongeun Kim | e454f260 | 2020-04-30 05:20:07 | [diff] [blame] | 17 | #include "printing/mojom/print.mojom.h" |
sverrir@google.com | 8ff1d42 | 2009-07-07 21:31:39 | [diff] [blame] | 18 | #include "printing/page_range.h" |
| 19 | #include "printing/page_setup.h" |
vandebo@chromium.org | 1c23b4e | 2011-10-15 22:30:48 | [diff] [blame] | 20 | #include "printing/print_job_constants.h" |
tfarina | 3b0452d | 2014-12-31 15:20:09 | [diff] [blame] | 21 | #include "ui/gfx/geometry/rect.h" |
rbpotter | 213a4f7 | 2017-12-22 22:58:09 | [diff] [blame] | 22 | #include "ui/gfx/geometry/size.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 23 | |
Alan Screen | 2750f0905 | 2023-09-01 22:32:33 | [diff] [blame] | 24 | #if BUILDFLAG(ENABLE_OOP_PRINTING_NO_OOP_BASIC_PRINT_DIALOG) |
| 25 | #include "base/values.h" |
| 26 | #endif |
| 27 | |
Xiaohan Wang | e3d00dd6 | 2022-01-08 02:33:28 | [diff] [blame] | 28 | #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) |
Vladislav Kuzkokov | d4e4ff3 | 2019-09-13 11:55:56 | [diff] [blame] | 29 | #include <map> |
| 30 | |
| 31 | #include "base/values.h" |
Xiaohan Wang | e3d00dd6 | 2022-01-08 02:33:28 | [diff] [blame] | 32 | #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) |
Vladislav Kuzkokov | d4e4ff3 | 2019-09-13 11:55:56 | [diff] [blame] | 33 | |
Gavin Williams | abc0a7d | 2023-02-22 20:34:03 | [diff] [blame] | 34 | #if BUILDFLAG(IS_CHROMEOS) |
| 35 | #include "chromeos/crosapi/mojom/local_printer.mojom.h" |
| 36 | #endif // BUILDFLAG(IS_CHROMEOS) |
| 37 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 38 | namespace printing { |
| 39 | |
Alan Screen | 2750f0905 | 2023-09-01 22:32:33 | [diff] [blame] | 40 | #if BUILDFLAG(ENABLE_OOP_PRINTING_NO_OOP_BASIC_PRINT_DIALOG) |
| 41 | |
| 42 | #if BUILDFLAG(IS_MAC) |
| 43 | inline constexpr char kMacSystemPrintDialogDataDestinationType[] = |
| 44 | "destination_type"; |
| 45 | inline constexpr char kMacSystemPrintDialogDataDestinationFormat[] = |
| 46 | "destination_format"; |
| 47 | inline constexpr char kMacSystemPrintDialogDataDestinationLocation[] = |
| 48 | "destination_location"; |
| 49 | inline constexpr char kMacSystemPrintDialogDataPageFormat[] = "page_format"; |
| 50 | inline constexpr char kMacSystemPrintDialogDataPrintSettings[] = |
| 51 | "print_settings"; |
| 52 | #endif // BUILDFLAG(IS_MAC) |
| 53 | |
| 54 | #if BUILDFLAG(IS_LINUX) |
| 55 | inline constexpr char kLinuxSystemPrintDialogDataPrinter[] = "printer_name"; |
| 56 | inline constexpr char kLinuxSystemPrintDialogDataPrintSettings[] = |
| 57 | "print_settings"; |
| 58 | inline constexpr char kLinuxSystemPrintDialogDataPageSetup[] = "page_setup"; |
| 59 | #endif // BUILDFLAG(IS_LINUX) |
| 60 | |
| 61 | #endif // BUILDFLAG(ENABLE_OOP_PRINTING_NO_OOP_BASIC_PRINT_DIALOG) |
| 62 | |
Daniel Hosseinian | 3553e27 | 2021-04-24 00:51:18 | [diff] [blame] | 63 | // Convert from `color_mode` into a `color_model`. An invalid `color_mode` |
| 64 | // will give a result of `mojom::ColorModel::kUnknownColorModel`. |
Alan Screen | 9347cae | 2021-04-27 18:11:24 | [diff] [blame] | 65 | COMPONENT_EXPORT(PRINTING) |
| 66 | mojom::ColorModel ColorModeToColorModel(int color_mode); |
Alan Screen | 558045a | 2020-08-28 23:18:58 | [diff] [blame] | 67 | |
Daniel Hosseinian | 3553e27 | 2021-04-24 00:51:18 | [diff] [blame] | 68 | // Returns true if `color_model` is color and false if it is B&W. Callers |
| 69 | // are not supposed to pass in `mojom::ColorModel::kUnknownColorModel`, but |
Arthur Sonzogni | 59ac822 | 2023-11-10 09:46:54 | [diff] [blame] | 70 | // if they do then the result will be std::nullopt. |
Alan Screen | 9347cae | 2021-04-27 18:11:24 | [diff] [blame] | 71 | COMPONENT_EXPORT(PRINTING) |
Arthur Sonzogni | 59ac822 | 2023-11-10 09:46:54 | [diff] [blame] | 72 | std::optional<bool> IsColorModelSelected(mojom::ColorModel color_model); |
kmadhusu@chromium.org | 63313ae | 2011-10-13 00:40:39 | [diff] [blame] | 73 | |
Andrew Rayskiy | 16f8cab | 2022-12-15 16:28:33 | [diff] [blame] | 74 | #if BUILDFLAG(USE_CUPS) |
Daniel Hosseinian | 3553e27 | 2021-04-24 00:51:18 | [diff] [blame] | 75 | // Get the color model setting name and value for the `color_model`. |
Alan Screen | 9347cae | 2021-04-27 18:11:24 | [diff] [blame] | 76 | COMPONENT_EXPORT(PRINTING) |
| 77 | void GetColorModelForModel(mojom::ColorModel color_model, |
| 78 | std::string* color_setting_name, |
| 79 | std::string* color_value); |
Lei Zhang | 04f9ea3 | 2023-07-08 01:48:05 | [diff] [blame] | 80 | #endif // BUILDFLAG(USE_CUPS) |
Daniel Hosseinian | 0f7cafd | 2020-07-18 01:38:00 | [diff] [blame] | 81 | |
Lei Zhang | 04f9ea3 | 2023-07-08 01:48:05 | [diff] [blame] | 82 | #if BUILDFLAG(USE_CUPS_IPP) |
Daniel Hosseinian | 3553e27 | 2021-04-24 00:51:18 | [diff] [blame] | 83 | // Convert from `color_model` to a print-color-mode value from PWG 5100.13. |
Alan Screen | 9347cae | 2021-04-27 18:11:24 | [diff] [blame] | 84 | COMPONENT_EXPORT(PRINTING) |
| 85 | std::string GetIppColorModelForModel(mojom::ColorModel color_model); |
Lei Zhang | 04f9ea3 | 2023-07-08 01:48:05 | [diff] [blame] | 86 | #endif // BUILDFLAG(USE_CUPS_IPP) |
kmadhusu@chromium.org | 63313ae | 2011-10-13 00:40:39 | [diff] [blame] | 87 | |
Alan Screen | 9347cae | 2021-04-27 18:11:24 | [diff] [blame] | 88 | class COMPONENT_EXPORT(PRINTING) PrintSettings { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 89 | public: |
alekseys@chromium.org | 72ddef9 | 2014-06-12 08:08:06 | [diff] [blame] | 90 | // Media properties requested by the user. Default instance represents |
| 91 | // default media selection. |
| 92 | struct RequestedMedia { |
Alan Screen | b411fe6 | 2023-02-16 18:53:20 | [diff] [blame] | 93 | bool operator==(const RequestedMedia& other) const; |
| 94 | bool IsDefault() const { |
| 95 | return size_microns.IsEmpty() && vendor_id.empty(); |
| 96 | } |
| 97 | |
alekseys@chromium.org | 72ddef9 | 2014-06-12 08:08:06 | [diff] [blame] | 98 | // Size of the media, in microns. |
| 99 | gfx::Size size_microns; |
| 100 | // Platform specific id to map it back to the particular media. |
| 101 | std::string vendor_id; |
alekseys@chromium.org | 72ddef9 | 2014-06-12 08:08:06 | [diff] [blame] | 102 | }; |
| 103 | |
Xiaohan Wang | e3d00dd6 | 2022-01-08 02:33:28 | [diff] [blame] | 104 | #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) |
Vladislav Kuzkokov | d4e4ff3 | 2019-09-13 11:55:56 | [diff] [blame] | 105 | using AdvancedSettings = std::map<std::string, base::Value>; |
Xiaohan Wang | e3d00dd6 | 2022-01-08 02:33:28 | [diff] [blame] | 106 | #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) |
Vladislav Kuzkokov | d4e4ff3 | 2019-09-13 11:55:56 | [diff] [blame] | 107 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 108 | PrintSettings(); |
Alan Screen | 2fc197d | 2021-08-25 00:47:09 | [diff] [blame] | 109 | PrintSettings(const PrintSettings&); |
| 110 | PrintSettings& operator=(const PrintSettings&); |
erg@google.com | 20f0487a | 2010-09-30 20:06:30 | [diff] [blame] | 111 | ~PrintSettings(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 112 | |
Alan Screen | b411fe6 | 2023-02-16 18:53:20 | [diff] [blame] | 113 | bool operator==(const PrintSettings& other) const; |
| 114 | |
Vladislav Kuzkokov | 56e6bbbd | 2019-08-21 18:48:18 | [diff] [blame] | 115 | // Reinitialize the settings to the default values. |
| 116 | void Clear(); |
| 117 | |
vandebo@chromium.org | b076a08 | 2011-10-20 01:26:32 | [diff] [blame] | 118 | void SetCustomMargins(const PageMargins& requested_margins_in_points); |
vitalybuka@chromium.org | c95198b | 2014-06-12 16:56:55 | [diff] [blame] | 119 | const PageMargins& requested_custom_margins_in_points() const { |
| 120 | return requested_custom_margins_in_points_; |
| 121 | } |
Julie Jeongeun Kim | cb00d1ab | 2020-08-14 07:43:32 | [diff] [blame] | 122 | void set_margin_type(mojom::MarginType margin_type) { |
| 123 | margin_type_ = margin_type; |
| 124 | } |
| 125 | mojom::MarginType margin_type() const { return margin_type_; } |
vandebo@chromium.org | 1c23b4e | 2011-10-15 22:30:48 | [diff] [blame] | 126 | |
vitalybuka@chromium.org | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 127 | // Updates the orientation and flip the page if needed. |
| 128 | void SetOrientation(bool landscape); |
| 129 | bool landscape() const { return landscape_; } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 130 | |
alekseys@chromium.org | 72ddef9 | 2014-06-12 08:08:06 | [diff] [blame] | 131 | // Updates user requested media. |
| 132 | void set_requested_media(const RequestedMedia& media) { |
| 133 | requested_media_ = media; |
| 134 | } |
| 135 | // Media properties requested by the user. Translated into device media by the |
| 136 | // platform specific layers. |
Lei Zhang | 01a1d3c | 2019-05-21 04:59:10 | [diff] [blame] | 137 | const RequestedMedia& requested_media() const { return requested_media_; } |
alekseys@chromium.org | 72ddef9 | 2014-06-12 08:08:06 | [diff] [blame] | 138 | |
vitalybuka@chromium.org | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 139 | // Set printer printable area in in device units. |
Daniel Hosseinian | 3553e27 | 2021-04-24 00:51:18 | [diff] [blame] | 140 | // Some platforms already provide flipped area. Set `landscape_needs_flip` |
vitalybuka@chromium.org | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 141 | // to false on those platforms to avoid double flipping. |
Vladislav Kuzkokov | a3f4af8f | 2017-11-28 15:20:26 | [diff] [blame] | 142 | // This method assumes correct DPI is already set. |
vitalybuka@chromium.org | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 143 | void SetPrinterPrintableArea(const gfx::Size& physical_size_device_units, |
| 144 | const gfx::Rect& printable_area_device_units, |
vitalybuka@chromium.org | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 145 | bool landscape_needs_flip); |
Alan Screen | 0bc5a4e | 2023-04-10 21:15:13 | [diff] [blame] | 146 | #if BUILDFLAG(IS_WIN) |
| 147 | // Update the printer printable area for the current media using the |
| 148 | // provided area in microns. |
| 149 | void UpdatePrinterPrintableArea(const gfx::Rect& printable_area_um); |
| 150 | #endif |
vitalybuka@chromium.org | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 151 | const PageSetup& page_setup_device_units() const { |
| 152 | return page_setup_device_units_; |
| 153 | } |
Alan Screen | 2fc197d | 2021-08-25 00:47:09 | [diff] [blame] | 154 | // `set_page_setup_device_units()` intended to be used only for mojom |
| 155 | // validation. |
| 156 | void set_page_setup_device_units(const PageSetup& page_setup_device_units) { |
| 157 | page_setup_device_units_ = page_setup_device_units; |
| 158 | } |
vitalybuka@chromium.org | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 159 | |
Jan Wilken Dörrie | 739ccc21 | 2021-03-11 18:13:05 | [diff] [blame] | 160 | void set_device_name(const std::u16string& device_name) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 161 | device_name_ = device_name; |
| 162 | } |
Jan Wilken Dörrie | 739ccc21 | 2021-03-11 18:13:05 | [diff] [blame] | 163 | const std::u16string& device_name() const { return device_name_; } |
vitalybuka@chromium.org | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 164 | |
Bryan Cain | ea23cf0 | 2023-08-28 19:19:47 | [diff] [blame] | 165 | void set_borderless(bool borderless) { borderless_ = borderless; } |
| 166 | bool borderless() const { return borderless_; } |
| 167 | |
Bryan Cain | deee87d | 2023-08-10 18:07:54 | [diff] [blame] | 168 | void set_media_type(const std::string& media_type) { |
| 169 | media_type_ = media_type; |
| 170 | } |
| 171 | const std::string& media_type() const { return media_type_; } |
| 172 | |
rbpotter | 213a4f7 | 2017-12-22 22:58:09 | [diff] [blame] | 173 | void set_dpi(int dpi) { dpi_ = gfx::Size(dpi, dpi); } |
rbpotter | 116c2e1 | 2017-04-04 19:21:28 | [diff] [blame] | 174 | void set_dpi_xy(int dpi_horizontal, int dpi_vertical) { |
rbpotter | 213a4f7 | 2017-12-22 22:58:09 | [diff] [blame] | 175 | dpi_ = gfx::Size(dpi_horizontal, dpi_vertical); |
rbpotter | 116c2e1 | 2017-04-04 19:21:28 | [diff] [blame] | 176 | } |
rbpotter | 213a4f7 | 2017-12-22 22:58:09 | [diff] [blame] | 177 | |
| 178 | int dpi() const { return std::max(dpi_.width(), dpi_.height()); } |
| 179 | int dpi_horizontal() const { return dpi_.width(); } |
| 180 | int dpi_vertical() const { return dpi_.height(); } |
rbpotter | e33e8e62 | 2018-01-25 01:10:33 | [diff] [blame] | 181 | const gfx::Size& dpi_size() const { return dpi_; } |
vitalybuka@chromium.org | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 182 | |
rbpotter | 769ffdf | 2016-10-26 00:53:57 | [diff] [blame] | 183 | void set_scale_factor(double scale_factor) { scale_factor_ = scale_factor; } |
| 184 | double scale_factor() const { return scale_factor_; } |
| 185 | |
rbpotter | 0fab35602 | 2016-12-28 22:00:23 | [diff] [blame] | 186 | void set_rasterize_pdf(bool rasterize_pdf) { rasterize_pdf_ = rasterize_pdf; } |
| 187 | bool rasterize_pdf() const { return rasterize_pdf_; } |
| 188 | |
Alan Screen | dce2e58 | 2021-08-12 21:10:47 | [diff] [blame] | 189 | void set_rasterize_pdf_dpi(int32_t dpi) { rasterize_pdf_dpi_ = dpi; } |
| 190 | int32_t rasterize_pdf_dpi() const { return rasterize_pdf_dpi_; } |
| 191 | |
sanjeevr@chromium.org | 6ab86ac | 2010-05-29 07:18:29 | [diff] [blame] | 192 | int device_units_per_inch() const { |
Xiaohan Wang | e3d00dd6 | 2022-01-08 02:33:28 | [diff] [blame] | 193 | #if BUILDFLAG(IS_MAC) |
Lei Zhang | c57fc30f | 2022-12-07 22:49:41 | [diff] [blame] | 194 | return kMacDeviceUnitsPerInch; |
Xiaohan Wang | e3d00dd6 | 2022-01-08 02:33:28 | [diff] [blame] | 195 | #else // BUILDFLAG(IS_MAC) |
sanjeevr@chromium.org | 6ab86ac | 2010-05-29 07:18:29 | [diff] [blame] | 196 | return dpi(); |
Xiaohan Wang | e3d00dd6 | 2022-01-08 02:33:28 | [diff] [blame] | 197 | #endif // BUILDFLAG(IS_MAC) |
sanjeevr@chromium.org | 6ab86ac | 2010-05-29 07:18:29 | [diff] [blame] | 198 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 199 | |
Lei Zhang | c57fc30f | 2022-12-07 22:49:41 | [diff] [blame] | 200 | const gfx::Size& device_units_per_inch_size() const { |
| 201 | #if BUILDFLAG(IS_MAC) |
| 202 | static constexpr gfx::Size kSize{kMacDeviceUnitsPerInch, |
| 203 | kMacDeviceUnitsPerInch}; |
| 204 | return kSize; |
| 205 | #else // BUILDFLAG(IS_MAC) |
| 206 | return dpi_size(); |
| 207 | #endif // BUILDFLAG(IS_MAC) |
| 208 | } |
| 209 | |
thestig | e85e6b6 | 2016-08-25 00:00:06 | [diff] [blame] | 210 | void set_ranges(const PageRanges& ranges) { ranges_ = ranges; } |
| 211 | const PageRanges& ranges() const { return ranges_; } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 212 | |
vitalybuka@chromium.org | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 213 | void set_selection_only(bool selection_only) { |
| 214 | selection_only_ = selection_only; |
| 215 | } |
| 216 | bool selection_only() const { return selection_only_; } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 217 | |
vitalybuka@chromium.org | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 218 | void set_should_print_backgrounds(bool should_print_backgrounds) { |
| 219 | should_print_backgrounds_ = should_print_backgrounds; |
| 220 | } |
| 221 | bool should_print_backgrounds() const { return should_print_backgrounds_; } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 222 | |
vitalybuka@chromium.org | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 223 | void set_display_header_footer(bool display_header_footer) { |
| 224 | display_header_footer_ = display_header_footer; |
| 225 | } |
| 226 | bool display_header_footer() const { return display_header_footer_; } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 227 | |
Jan Wilken Dörrie | 739ccc21 | 2021-03-11 18:13:05 | [diff] [blame] | 228 | void set_title(const std::u16string& title) { title_ = title; } |
| 229 | const std::u16string& title() const { return title_; } |
sverrir@google.com | c8ad40c | 2009-06-08 17:05:21 | [diff] [blame] | 230 | |
Jan Wilken Dörrie | 739ccc21 | 2021-03-11 18:13:05 | [diff] [blame] | 231 | void set_url(const std::u16string& url) { url_ = url; } |
| 232 | const std::u16string& url() const { return url_; } |
vitalybuka@chromium.org | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 233 | |
| 234 | void set_collate(bool collate) { collate_ = collate; } |
| 235 | bool collate() const { return collate_; } |
| 236 | |
Alan Screen | 3fb63bf | 2020-08-19 00:11:23 | [diff] [blame] | 237 | void set_color(mojom::ColorModel color) { color_ = color; } |
| 238 | mojom::ColorModel color() const { return color_; } |
vitalybuka@chromium.org | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 239 | |
| 240 | void set_copies(int copies) { copies_ = copies; } |
| 241 | int copies() const { return copies_; } |
| 242 | |
Julie Jeongeun Kim | e454f260 | 2020-04-30 05:20:07 | [diff] [blame] | 243 | void set_duplex_mode(mojom::DuplexMode duplex_mode) { |
| 244 | duplex_mode_ = duplex_mode; |
| 245 | } |
| 246 | mojom::DuplexMode duplex_mode() const { return duplex_mode_; } |
vitalybuka@chromium.org | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 247 | |
Xiaohan Wang | e3d00dd6 | 2022-01-08 02:33:28 | [diff] [blame] | 248 | #if BUILDFLAG(IS_WIN) |
Alan Screen | ee634e7 | 2021-07-02 20:08:51 | [diff] [blame] | 249 | void set_printer_language_type(mojom::PrinterLanguageType type) { |
| 250 | printer_language_type_ = type; |
rbpotter | 0437a171 | 2017-07-14 21:23:24 | [diff] [blame] | 251 | } |
Alan Screen | 2fc197d | 2021-08-25 00:47:09 | [diff] [blame] | 252 | mojom::PrinterLanguageType printer_language_type() const { |
| 253 | return printer_language_type_; |
| 254 | } |
Alan Screen | ee634e7 | 2021-07-02 20:08:51 | [diff] [blame] | 255 | bool printer_language_is_textonly() const { |
| 256 | return printer_language_type_ == mojom::PrinterLanguageType::kTextOnly; |
rbpotter | 58bc882e | 2017-02-01 03:44:24 | [diff] [blame] | 257 | } |
Alan Screen | ee634e7 | 2021-07-02 20:08:51 | [diff] [blame] | 258 | bool printer_language_is_xps() const { |
| 259 | return printer_language_type_ == mojom::PrinterLanguageType::kXps; |
| 260 | } |
| 261 | bool printer_language_is_ps2() const { |
| 262 | return printer_language_type_ == |
| 263 | mojom::PrinterLanguageType::kPostscriptLevel2; |
| 264 | } |
| 265 | bool printer_language_is_ps3() const { |
| 266 | return printer_language_type_ == |
| 267 | mojom::PrinterLanguageType::kPostscriptLevel3; |
rbpotter | 58bc882e | 2017-02-01 03:44:24 | [diff] [blame] | 268 | } |
thestig | e85e6b6 | 2016-08-25 00:00:06 | [diff] [blame] | 269 | #endif |
| 270 | |
Wei Li | 02720a4 | 2017-10-25 22:06:48 | [diff] [blame] | 271 | void set_is_modifiable(bool is_modifiable) { is_modifiable_ = is_modifiable; } |
| 272 | bool is_modifiable() const { return is_modifiable_; } |
| 273 | |
xlou | 6bd7c2d | 2018-07-10 01:35:40 | [diff] [blame] | 274 | int pages_per_sheet() const { return pages_per_sheet_; } |
| 275 | void set_pages_per_sheet(int pages_per_sheet) { |
| 276 | pages_per_sheet_ = pages_per_sheet; |
xlou | 19420756 | 2018-04-26 23:42:44 | [diff] [blame] | 277 | } |
| 278 | |
Xiaohan Wang | e3d00dd6 | 2022-01-08 02:33:28 | [diff] [blame] | 279 | #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) |
Daniel Hosseinian | c3db7f4c | 2020-06-25 02:09:52 | [diff] [blame] | 280 | AdvancedSettings& advanced_settings() { return advanced_settings_; } |
| 281 | const AdvancedSettings& advanced_settings() const { |
| 282 | return advanced_settings_; |
| 283 | } |
Xiaohan Wang | e3d00dd6 | 2022-01-08 02:33:28 | [diff] [blame] | 284 | #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) |
Daniel Hosseinian | c3db7f4c | 2020-06-25 02:09:52 | [diff] [blame] | 285 | |
Xiaohan Wang | e3d00dd6 | 2022-01-08 02:33:28 | [diff] [blame] | 286 | #if BUILDFLAG(IS_CHROMEOS) |
Vladislav Kuzkokov | 48b1500 | 2019-01-30 17:13:35 | [diff] [blame] | 287 | void set_send_user_info(bool send_user_info) { |
| 288 | send_user_info_ = send_user_info; |
| 289 | } |
| 290 | bool send_user_info() const { return send_user_info_; } |
| 291 | |
| 292 | void set_username(const std::string& username) { username_ = username; } |
| 293 | const std::string& username() const { return username_; } |
Nikita Podguzov | c1bf3f8 | 2019-03-19 15:23:23 | [diff] [blame] | 294 | |
Piotr Pawliczek | a7b3534 | 2022-11-01 18:18:50 | [diff] [blame] | 295 | void set_oauth_token(const std::string& oauth_token) { |
| 296 | oauth_token_ = oauth_token; |
| 297 | } |
| 298 | const std::string& oauth_token() const { return oauth_token_; } |
| 299 | |
Nikita Podguzov | c1bf3f8 | 2019-03-19 15:23:23 | [diff] [blame] | 300 | void set_pin_value(const std::string& pin_value) { pin_value_ = pin_value; } |
| 301 | const std::string& pin_value() const { return pin_value_; } |
Sparik Hayrapetyan | 48216b3 | 2022-12-16 16:07:26 | [diff] [blame] | 302 | |
| 303 | void set_client_infos(std::vector<mojom::IppClientInfo> client_infos) { |
| 304 | client_infos_ = std::move(client_infos); |
| 305 | } |
| 306 | const std::vector<mojom::IppClientInfo>& client_infos() const { |
| 307 | return client_infos_; |
| 308 | } |
Gavin Williams | 9324ed69 | 2023-02-15 04:19:31 | [diff] [blame] | 309 | |
| 310 | void set_printer_manually_selected(bool printer_manually_selected) { |
| 311 | printer_manually_selected_ = printer_manually_selected; |
| 312 | } |
| 313 | bool printer_manually_selected() const { return printer_manually_selected_; } |
Gavin Williams | abc0a7d | 2023-02-22 20:34:03 | [diff] [blame] | 314 | |
| 315 | void set_printer_status_reason( |
| 316 | crosapi::mojom::StatusReason::Reason printer_status_reason) { |
| 317 | printer_status_reason_ = printer_status_reason; |
| 318 | } |
Arthur Sonzogni | 59ac822 | 2023-11-10 09:46:54 | [diff] [blame] | 319 | std::optional<crosapi::mojom::StatusReason::Reason> printer_status_reason() |
Gavin Williams | abc0a7d | 2023-02-22 20:34:03 | [diff] [blame] | 320 | const { |
| 321 | return printer_status_reason_; |
| 322 | } |
Xiaohan Wang | e3d00dd6 | 2022-01-08 02:33:28 | [diff] [blame] | 323 | #endif // BUILDFLAG(IS_CHROMEOS) |
Vladislav Kuzkokov | 48b1500 | 2019-01-30 17:13:35 | [diff] [blame] | 324 | |
Alan Screen | 2750f0905 | 2023-09-01 22:32:33 | [diff] [blame] | 325 | #if BUILDFLAG(ENABLE_OOP_PRINTING_NO_OOP_BASIC_PRINT_DIALOG) |
| 326 | void set_system_print_dialog_data(base::Value::Dict data) { |
| 327 | system_print_dialog_data_ = std::move(data); |
| 328 | } |
| 329 | const base::Value::Dict& system_print_dialog_data() const { |
| 330 | return system_print_dialog_data_; |
| 331 | } |
| 332 | #endif |
Alan Screen | ee634e7 | 2021-07-02 20:08:51 | [diff] [blame] | 333 | // Cookie generator. It is used to initialize `PrintedDocument` with its |
| 334 | // associated `PrintSettings`, to be sure that each generated `PrintedPage` |
| 335 | // is correctly associated with its corresponding `PrintedDocument`. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 336 | static int NewCookie(); |
| 337 | |
Lei Zhang | eb67682 | 2023-06-30 19:11:52 | [diff] [blame] | 338 | // Creates an invalid cookie for use in situations where the cookie needs to |
| 339 | // be marked as invalid. |
| 340 | static int NewInvalidCookie(); |
| 341 | |
vitalybuka@chromium.org | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 342 | private: |
Lei Zhang | c57fc30f | 2022-12-07 22:49:41 | [diff] [blame] | 343 | #if BUILDFLAG(IS_MAC) |
| 344 | static constexpr int kMacDeviceUnitsPerInch = 72; |
| 345 | #endif |
| 346 | |
Alan Screen | ee634e7 | 2021-07-02 20:08:51 | [diff] [blame] | 347 | // Multi-page printing. Each `PageRange` describes a from-to page combination. |
vitalybuka@chromium.org | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 348 | // This permits printing selected pages only. |
| 349 | PageRanges ranges_; |
| 350 | |
vitalybuka@chromium.org | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 351 | // Indicates if the user only wants to print the current selection. |
Vladislav Kuzkokov | 56e6bbbd | 2019-08-21 18:48:18 | [diff] [blame] | 352 | bool selection_only_; |
vitalybuka@chromium.org | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 353 | |
| 354 | // Indicates what kind of margins should be applied to the printable area. |
Julie Jeongeun Kim | cb00d1ab | 2020-08-14 07:43:32 | [diff] [blame] | 355 | mojom::MarginType margin_type_; |
thestig@chromium.org | c48bee2 | 2011-03-29 02:36:26 | [diff] [blame] | 356 | |
aayushkumar@chromium.org | 55b23a0 | 2011-08-17 23:09:36 | [diff] [blame] | 357 | // Strings to be printed as headers and footers if requested by the user. |
Jan Wilken Dörrie | 739ccc21 | 2021-03-11 18:13:05 | [diff] [blame] | 358 | std::u16string title_; |
| 359 | std::u16string url_; |
aayushkumar@chromium.org | 55b23a0 | 2011-08-17 23:09:36 | [diff] [blame] | 360 | |
| 361 | // True if the user wants headers and footers to be displayed. |
Vladislav Kuzkokov | 56e6bbbd | 2019-08-21 18:48:18 | [diff] [blame] | 362 | bool display_header_footer_; |
aayushkumar@chromium.org | 55b23a0 | 2011-08-17 23:09:36 | [diff] [blame] | 363 | |
rltoscano@chromium.org | 19d1c2d | 2013-01-14 00:59:46 | [diff] [blame] | 364 | // True if the user wants to print CSS backgrounds. |
Vladislav Kuzkokov | 56e6bbbd | 2019-08-21 18:48:18 | [diff] [blame] | 365 | bool should_print_backgrounds_; |
rltoscano@chromium.org | 19d1c2d | 2013-01-14 00:59:46 | [diff] [blame] | 366 | |
vitalybuka@chromium.org | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 367 | // True if the user wants to print with collate. |
Vladislav Kuzkokov | 56e6bbbd | 2019-08-21 18:48:18 | [diff] [blame] | 368 | bool collate_; |
vitalybuka@chromium.org | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 369 | |
Alan Screen | 3fb63bf | 2020-08-19 00:11:23 | [diff] [blame] | 370 | // Color model type for the printer to use. |
| 371 | mojom::ColorModel color_; |
vitalybuka@chromium.org | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 372 | |
| 373 | // Number of copies user wants to print. |
Vladislav Kuzkokov | 56e6bbbd | 2019-08-21 18:48:18 | [diff] [blame] | 374 | int copies_; |
vitalybuka@chromium.org | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 375 | |
| 376 | // Duplex type user wants to use. |
Julie Jeongeun Kim | e454f260 | 2020-04-30 05:20:07 | [diff] [blame] | 377 | mojom::DuplexMode duplex_mode_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 378 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 379 | // Printer device name as opened by the OS. |
Jan Wilken Dörrie | 739ccc21 | 2021-03-11 18:13:05 | [diff] [blame] | 380 | std::u16string device_name_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 381 | |
Alan Screen | 2750f0905 | 2023-09-01 22:32:33 | [diff] [blame] | 382 | #if BUILDFLAG(ENABLE_OOP_PRINTING_NO_OOP_BASIC_PRINT_DIALOG) |
| 383 | // Platform-specific print settings captured from a system print dialog. |
| 384 | // The settings are captured in the browser process for transmission to |
| 385 | // the Print Backend service for OOP printing. |
| 386 | base::Value::Dict system_print_dialog_data_; |
| 387 | #endif |
| 388 | |
alekseys@chromium.org | 72ddef9 | 2014-06-12 08:08:06 | [diff] [blame] | 389 | // Media requested by the user. |
| 390 | RequestedMedia requested_media_; |
| 391 | |
sanjeevr@chromium.org | 6ab86ac | 2010-05-29 07:18:29 | [diff] [blame] | 392 | // Page setup in device units. |
| 393 | PageSetup page_setup_device_units_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 394 | |
Bryan Cain | ea23cf0 | 2023-08-28 19:19:47 | [diff] [blame] | 395 | // Whether the user has requested borderless (zero margin) printing. |
| 396 | bool borderless_; |
| 397 | |
Bryan Cain | deee87d | 2023-08-10 18:07:54 | [diff] [blame] | 398 | // Media type requested by the user. |
| 399 | std::string media_type_; |
| 400 | |
rbpotter | 116c2e1 | 2017-04-04 19:21:28 | [diff] [blame] | 401 | // Printer's device effective dots per inch in both axes. The two values will |
| 402 | // generally be identical. However, on Windows, there are a few rare printers |
| 403 | // that support resolutions with different DPI in different dimensions. |
rbpotter | 213a4f7 | 2017-12-22 22:58:09 | [diff] [blame] | 404 | gfx::Size dpi_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 405 | |
rbpotter | 769ffdf | 2016-10-26 00:53:57 | [diff] [blame] | 406 | // Scale factor |
Vladislav Kuzkokov | 56e6bbbd | 2019-08-21 18:48:18 | [diff] [blame] | 407 | double scale_factor_; |
rbpotter | 769ffdf | 2016-10-26 00:53:57 | [diff] [blame] | 408 | |
rbpotter | 0fab35602 | 2016-12-28 22:00:23 | [diff] [blame] | 409 | // True if PDF should be printed as a raster PDF |
Vladislav Kuzkokov | 56e6bbbd | 2019-08-21 18:48:18 | [diff] [blame] | 410 | bool rasterize_pdf_; |
rbpotter | 0fab35602 | 2016-12-28 22:00:23 | [diff] [blame] | 411 | |
Alan Screen | dce2e58 | 2021-08-12 21:10:47 | [diff] [blame] | 412 | // The DPI which overrides the calculated value normally used when |
| 413 | // rasterizing a PDF. A non-positive value would be an invalid choice of a |
| 414 | // DPI and indicates no override. |
| 415 | int32_t rasterize_pdf_dpi_; |
| 416 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 417 | // Is the orientation landscape or portrait. |
Vladislav Kuzkokov | 56e6bbbd | 2019-08-21 18:48:18 | [diff] [blame] | 418 | bool landscape_; |
senorblanco@chromium.org | b2b0fce | 2011-01-12 16:34:40 | [diff] [blame] | 419 | |
Xiaohan Wang | e3d00dd6 | 2022-01-08 02:33:28 | [diff] [blame] | 420 | #if BUILDFLAG(IS_WIN) |
Alan Screen | ee634e7 | 2021-07-02 20:08:51 | [diff] [blame] | 421 | mojom::PrinterLanguageType printer_language_type_; |
thestig | e85e6b6 | 2016-08-25 00:00:06 | [diff] [blame] | 422 | #endif |
| 423 | |
Vladislav Kuzkokov | 56e6bbbd | 2019-08-21 18:48:18 | [diff] [blame] | 424 | bool is_modifiable_; |
Wei Li | 02720a4 | 2017-10-25 22:06:48 | [diff] [blame] | 425 | |
vandebo@chromium.org | b076a08 | 2011-10-20 01:26:32 | [diff] [blame] | 426 | // If margin type is custom, this is what was requested. |
| 427 | PageMargins requested_custom_margins_in_points_; |
xlou | 19420756 | 2018-04-26 23:42:44 | [diff] [blame] | 428 | |
| 429 | // Number of pages per sheet. |
Vladislav Kuzkokov | 56e6bbbd | 2019-08-21 18:48:18 | [diff] [blame] | 430 | int pages_per_sheet_; |
Vladislav Kuzkokov | 48b1500 | 2019-01-30 17:13:35 | [diff] [blame] | 431 | |
Xiaohan Wang | e3d00dd6 | 2022-01-08 02:33:28 | [diff] [blame] | 432 | #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) |
Daniel Hosseinian | c3db7f4c | 2020-06-25 02:09:52 | [diff] [blame] | 433 | // Advanced settings. |
| 434 | AdvancedSettings advanced_settings_; |
Xiaohan Wang | e3d00dd6 | 2022-01-08 02:33:28 | [diff] [blame] | 435 | #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) |
Daniel Hosseinian | c3db7f4c | 2020-06-25 02:09:52 | [diff] [blame] | 436 | |
Xiaohan Wang | e3d00dd6 | 2022-01-08 02:33:28 | [diff] [blame] | 437 | #if BUILDFLAG(IS_CHROMEOS) |
Vladislav Kuzkokov | 48b1500 | 2019-01-30 17:13:35 | [diff] [blame] | 438 | // Whether to send user info. |
Vladislav Kuzkokov | 56e6bbbd | 2019-08-21 18:48:18 | [diff] [blame] | 439 | bool send_user_info_; |
Vladislav Kuzkokov | 48b1500 | 2019-01-30 17:13:35 | [diff] [blame] | 440 | |
| 441 | // Username if it's required by the printer. |
| 442 | std::string username_; |
Nikita Podguzov | c1bf3f8 | 2019-03-19 15:23:23 | [diff] [blame] | 443 | |
Piotr Pawliczek | a7b3534 | 2022-11-01 18:18:50 | [diff] [blame] | 444 | // OAuth access token if it's required by the printer. |
| 445 | std::string oauth_token_; |
| 446 | |
Nikita Podguzov | c1bf3f8 | 2019-03-19 15:23:23 | [diff] [blame] | 447 | // PIN code entered by the user. |
| 448 | std::string pin_value_; |
Sparik Hayrapetyan | 48216b3 | 2022-12-16 16:07:26 | [diff] [blame] | 449 | |
| 450 | // Value of the 'client-info' that will be sent to the printer. |
| 451 | // Should only be set for printers that support 'client-info'. |
| 452 | std::vector<mojom::IppClientInfo> client_infos_; |
Gavin Williams | 9324ed69 | 2023-02-15 04:19:31 | [diff] [blame] | 453 | |
| 454 | // True if the user selects to print to a different printer than the original |
| 455 | // destination shown when Print Preview opens. |
| 456 | bool printer_manually_selected_; |
Gavin Williams | abc0a7d | 2023-02-22 20:34:03 | [diff] [blame] | 457 | |
| 458 | // The printer status reason shown for the selected printer at the time print |
| 459 | // is requested. Only local CrOS printers set printer statuses. |
Arthur Sonzogni | 59ac822 | 2023-11-10 09:46:54 | [diff] [blame] | 460 | std::optional<crosapi::mojom::StatusReason::Reason> printer_status_reason_; |
Sparik Hayrapetyan | 48216b3 | 2022-12-16 16:07:26 | [diff] [blame] | 461 | #endif // BUILDFLAG(IS_CHROMEOS) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 462 | }; |
| 463 | |
| 464 | } // namespace printing |
| 465 | |
sverrir@google.com | 8ff1d42 | 2009-07-07 21:31:39 | [diff] [blame] | 466 | #endif // PRINTING_PRINT_SETTINGS_H_ |