Avi Drissman | db497b3 | 2022-09-15 19:47:28 | [diff] [blame] | 1 | // Copyright 2020 The Chromium Authors |
Alan Screen | e86ec5b | 2020-09-30 23:17:15 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef PRINTING_BACKEND_MOJOM_PRINT_BACKEND_MOJOM_TRAITS_H_ |
| 6 | #define PRINTING_BACKEND_MOJOM_PRINT_BACKEND_MOJOM_TRAITS_H_ |
| 7 | |
| 8 | #include <string> |
Alan Screen | 05175f2 | 2020-10-01 23:22:00 | [diff] [blame] | 9 | #include <vector> |
Alan Screen | e86ec5b | 2020-09-30 23:17:15 | [diff] [blame] | 10 | |
Xiaohan Wang | e3d00dd6 | 2022-01-08 02:33:28 | [diff] [blame] | 11 | #include "build/build_config.h" |
Alan Screen | e86ec5b | 2020-09-30 23:17:15 | [diff] [blame] | 12 | #include "printing/backend/mojom/print_backend.mojom-shared.h" |
| 13 | #include "printing/backend/print_backend.h" |
Alan Screen | 7a5f8512 | 2020-10-08 08:46:36 | [diff] [blame] | 14 | #include "printing/mojom/print.mojom.h" |
Andy Phan | d4be1cb | 2023-02-01 00:27:46 | [diff] [blame] | 15 | #include "ui/gfx/geometry/rect.h" |
Alan Screen | e86ec5b | 2020-09-30 23:17:15 | [diff] [blame] | 16 | #include "ui/gfx/geometry/size.h" |
| 17 | |
| 18 | namespace mojo { |
| 19 | |
| 20 | template <> |
Alan Screen | cca43d1 | 2020-12-01 22:31:37 | [diff] [blame] | 21 | struct StructTraits<printing::mojom::PrinterBasicInfoDataView, |
| 22 | printing::PrinterBasicInfo> { |
| 23 | static const std::string& printer_name(const printing::PrinterBasicInfo& i) { |
| 24 | return i.printer_name; |
| 25 | } |
| 26 | static const std::string& display_name(const printing::PrinterBasicInfo& i) { |
| 27 | return i.display_name; |
| 28 | } |
| 29 | static const std::string& printer_description( |
| 30 | const printing::PrinterBasicInfo& i) { |
| 31 | return i.printer_description; |
| 32 | } |
| 33 | static int printer_status(const printing::PrinterBasicInfo& i) { |
| 34 | return i.printer_status; |
| 35 | } |
| 36 | static bool is_default(const printing::PrinterBasicInfo& i) { |
| 37 | return i.is_default; |
| 38 | } |
| 39 | static const printing::PrinterBasicInfoOptions& options( |
| 40 | const printing::PrinterBasicInfo& i) { |
| 41 | return i.options; |
| 42 | } |
| 43 | |
| 44 | static bool Read(printing::mojom::PrinterBasicInfoDataView data, |
| 45 | printing::PrinterBasicInfo* out); |
| 46 | }; |
| 47 | |
| 48 | template <> |
Alan Screen | e86ec5b | 2020-09-30 23:17:15 | [diff] [blame] | 49 | struct StructTraits<printing::mojom::PaperDataView, |
| 50 | printing::PrinterSemanticCapsAndDefaults::Paper> { |
| 51 | static const std::string& display_name( |
| 52 | const printing::PrinterSemanticCapsAndDefaults::Paper& p) { |
Lei Zhang | 7d971f5 | 2023-07-11 19:19:13 | [diff] [blame] | 53 | return p.display_name(); |
Alan Screen | e86ec5b | 2020-09-30 23:17:15 | [diff] [blame] | 54 | } |
| 55 | static const std::string& vendor_id( |
| 56 | const printing::PrinterSemanticCapsAndDefaults::Paper& p) { |
Lei Zhang | 7d971f5 | 2023-07-11 19:19:13 | [diff] [blame] | 57 | return p.vendor_id(); |
Alan Screen | e86ec5b | 2020-09-30 23:17:15 | [diff] [blame] | 58 | } |
| 59 | static const gfx::Size& size_um( |
| 60 | const printing::PrinterSemanticCapsAndDefaults::Paper& p) { |
Lei Zhang | 7d971f5 | 2023-07-11 19:19:13 | [diff] [blame] | 61 | return p.size_um(); |
Alan Screen | e86ec5b | 2020-09-30 23:17:15 | [diff] [blame] | 62 | } |
Andy Phan | d4be1cb | 2023-02-01 00:27:46 | [diff] [blame] | 63 | static const gfx::Rect& printable_area_um( |
| 64 | const printing::PrinterSemanticCapsAndDefaults::Paper& p) { |
Lei Zhang | 7d971f5 | 2023-07-11 19:19:13 | [diff] [blame] | 65 | return p.printable_area_um(); |
Andy Phan | d4be1cb | 2023-02-01 00:27:46 | [diff] [blame] | 66 | } |
Nathan Muggli | 97f147f | 2023-06-21 14:53:44 | [diff] [blame] | 67 | static int max_height_um( |
| 68 | const printing::PrinterSemanticCapsAndDefaults::Paper& p) { |
Lei Zhang | 7d971f5 | 2023-07-11 19:19:13 | [diff] [blame] | 69 | return p.max_height_um(); |
Nathan Muggli | 97f147f | 2023-06-21 14:53:44 | [diff] [blame] | 70 | } |
Bryan Cain | ea23cf0 | 2023-08-28 19:19:47 | [diff] [blame] | 71 | static bool has_borderless_variant( |
| 72 | const printing::PrinterSemanticCapsAndDefaults::Paper& p) { |
| 73 | return p.has_borderless_variant(); |
| 74 | } |
Alan Screen | e86ec5b | 2020-09-30 23:17:15 | [diff] [blame] | 75 | |
| 76 | static bool Read(printing::mojom::PaperDataView data, |
| 77 | printing::PrinterSemanticCapsAndDefaults::Paper* out); |
| 78 | }; |
| 79 | |
Bryan Cain | deee87d | 2023-08-10 18:07:54 | [diff] [blame] | 80 | template <> |
| 81 | struct StructTraits<printing::mojom::MediaTypeDataView, |
| 82 | printing::PrinterSemanticCapsAndDefaults::MediaType> { |
| 83 | static const std::string& display_name( |
| 84 | const printing::PrinterSemanticCapsAndDefaults::MediaType& p) { |
| 85 | return p.display_name; |
| 86 | } |
| 87 | static const std::string& vendor_id( |
| 88 | const printing::PrinterSemanticCapsAndDefaults::MediaType& p) { |
| 89 | return p.vendor_id; |
| 90 | } |
| 91 | |
| 92 | static bool Read(printing::mojom::MediaTypeDataView data, |
| 93 | printing::PrinterSemanticCapsAndDefaults::MediaType* out); |
| 94 | }; |
| 95 | |
Xiaohan Wang | e3d00dd6 | 2022-01-08 02:33:28 | [diff] [blame] | 96 | #if BUILDFLAG(IS_CHROMEOS) |
Alan Screen | 05175f2 | 2020-10-01 23:22:00 | [diff] [blame] | 97 | template <> |
| 98 | struct EnumTraits<printing::mojom::AdvancedCapabilityType, |
| 99 | ::printing::AdvancedCapability::Type> { |
| 100 | static printing::mojom::AdvancedCapabilityType ToMojom( |
| 101 | ::printing::AdvancedCapability::Type input); |
| 102 | static bool FromMojom(printing::mojom::AdvancedCapabilityType input, |
| 103 | ::printing::AdvancedCapability::Type* output); |
| 104 | }; |
| 105 | |
| 106 | template <> |
| 107 | struct StructTraits<printing::mojom::AdvancedCapabilityValueDataView, |
| 108 | ::printing::AdvancedCapabilityValue> { |
| 109 | static const std::string& name(const ::printing::AdvancedCapabilityValue& v) { |
| 110 | return v.name; |
| 111 | } |
| 112 | static const std::string& display_name( |
| 113 | const ::printing::AdvancedCapabilityValue& v) { |
| 114 | return v.display_name; |
| 115 | } |
| 116 | |
| 117 | static bool Read(printing::mojom::AdvancedCapabilityValueDataView data, |
| 118 | ::printing::AdvancedCapabilityValue* out); |
| 119 | }; |
| 120 | |
| 121 | template <> |
| 122 | struct StructTraits<printing::mojom::AdvancedCapabilityDataView, |
| 123 | ::printing::AdvancedCapability> { |
| 124 | static const std::string& name(const ::printing::AdvancedCapability& c) { |
| 125 | return c.name; |
| 126 | } |
| 127 | static const std::string& display_name( |
| 128 | const ::printing::AdvancedCapability& c) { |
| 129 | return c.display_name; |
| 130 | } |
| 131 | static ::printing::AdvancedCapability::Type type( |
| 132 | const ::printing::AdvancedCapability& c) { |
| 133 | return c.type; |
| 134 | } |
| 135 | static const std::string& default_value( |
| 136 | const ::printing::AdvancedCapability& c) { |
| 137 | return c.default_value; |
| 138 | } |
| 139 | static const std::vector<::printing::AdvancedCapabilityValue>& values( |
| 140 | const ::printing::AdvancedCapability& c) { |
| 141 | return c.values; |
| 142 | } |
| 143 | |
| 144 | static bool Read(printing::mojom::AdvancedCapabilityDataView data, |
| 145 | ::printing::AdvancedCapability* out); |
| 146 | }; |
Xiaohan Wang | e3d00dd6 | 2022-01-08 02:33:28 | [diff] [blame] | 147 | #endif // BUILDFLAG(IS_CHROMEOS) |
Alan Screen | 05175f2 | 2020-10-01 23:22:00 | [diff] [blame] | 148 | |
Andy Phan | 1e07acf | 2022-07-18 22:11:31 | [diff] [blame] | 149 | #if BUILDFLAG(IS_WIN) |
| 150 | template <> |
| 151 | struct StructTraits<printing::mojom::PageOutputQualityAttributeDataView, |
| 152 | ::printing::PageOutputQualityAttribute> { |
| 153 | static const std::string& display_name( |
| 154 | const ::printing::PageOutputQualityAttribute& p) { |
| 155 | return p.display_name; |
| 156 | } |
| 157 | |
| 158 | static const std::string& name( |
| 159 | const ::printing::PageOutputQualityAttribute& p) { |
| 160 | return p.name; |
| 161 | } |
| 162 | |
| 163 | static bool Read(printing::mojom::PageOutputQualityAttributeDataView data, |
| 164 | printing::PageOutputQualityAttribute* out); |
| 165 | }; |
| 166 | |
| 167 | template <> |
| 168 | struct StructTraits<printing::mojom::PageOutputQualityDataView, |
| 169 | printing::PageOutputQuality> { |
| 170 | static const std::vector<::printing::PageOutputQualityAttribute>& qualities( |
| 171 | const ::printing::PageOutputQuality& p) { |
| 172 | return p.qualities; |
| 173 | } |
| 174 | |
| 175 | static const absl::optional<std::string>& default_quality( |
| 176 | const ::printing::PageOutputQuality& p) { |
| 177 | return p.default_quality; |
| 178 | } |
| 179 | |
| 180 | static bool Read(printing::mojom::PageOutputQualityDataView data, |
| 181 | printing::PageOutputQuality* out); |
| 182 | }; |
| 183 | #endif // BUILDFLAG(IS_WIN) |
| 184 | |
Alan Screen | 7a5f8512 | 2020-10-08 08:46:36 | [diff] [blame] | 185 | template <> |
| 186 | struct StructTraits<printing::mojom::PrinterSemanticCapsAndDefaultsDataView, |
| 187 | printing::PrinterSemanticCapsAndDefaults> { |
| 188 | static bool collate_capable( |
| 189 | const printing::PrinterSemanticCapsAndDefaults& p) { |
| 190 | return p.collate_capable; |
| 191 | } |
| 192 | static bool collate_default( |
| 193 | const printing::PrinterSemanticCapsAndDefaults& p) { |
| 194 | return p.collate_default; |
| 195 | } |
| 196 | static int32_t copies_max(const printing::PrinterSemanticCapsAndDefaults& p) { |
| 197 | return p.copies_max; |
| 198 | } |
| 199 | static const std::vector<printing::mojom::DuplexMode>& duplex_modes( |
| 200 | const printing::PrinterSemanticCapsAndDefaults& p) { |
| 201 | return p.duplex_modes; |
| 202 | } |
| 203 | static printing::mojom::DuplexMode duplex_default( |
| 204 | const printing::PrinterSemanticCapsAndDefaults& p) { |
| 205 | return p.duplex_default; |
| 206 | } |
| 207 | static bool color_changeable( |
| 208 | const printing::PrinterSemanticCapsAndDefaults& p) { |
| 209 | return p.color_changeable; |
| 210 | } |
| 211 | static bool color_default(const printing::PrinterSemanticCapsAndDefaults& p) { |
| 212 | return p.color_default; |
| 213 | } |
| 214 | static printing::mojom::ColorModel color_model( |
| 215 | const printing::PrinterSemanticCapsAndDefaults& p) { |
| 216 | return p.color_model; |
| 217 | } |
| 218 | static printing::mojom::ColorModel bw_model( |
| 219 | const printing::PrinterSemanticCapsAndDefaults& p) { |
| 220 | return p.bw_model; |
| 221 | } |
| 222 | static const std::vector<printing::PrinterSemanticCapsAndDefaults::Paper>& |
| 223 | papers(const printing::PrinterSemanticCapsAndDefaults& p) { |
| 224 | return p.papers; |
| 225 | } |
| 226 | static const std::vector<printing::PrinterSemanticCapsAndDefaults::Paper>& |
| 227 | user_defined_papers(const printing::PrinterSemanticCapsAndDefaults& p) { |
| 228 | return p.user_defined_papers; |
| 229 | } |
| 230 | static const printing::PrinterSemanticCapsAndDefaults::Paper& default_paper( |
| 231 | const printing::PrinterSemanticCapsAndDefaults& p) { |
| 232 | return p.default_paper; |
| 233 | } |
Bryan Cain | deee87d | 2023-08-10 18:07:54 | [diff] [blame] | 234 | static const std::vector<printing::PrinterSemanticCapsAndDefaults::MediaType>& |
| 235 | media_types(const printing::PrinterSemanticCapsAndDefaults& p) { |
| 236 | return p.media_types; |
| 237 | } |
| 238 | static const printing::PrinterSemanticCapsAndDefaults::MediaType& |
| 239 | default_media_type(const printing::PrinterSemanticCapsAndDefaults& p) { |
| 240 | return p.default_media_type; |
| 241 | } |
Alan Screen | 7a5f8512 | 2020-10-08 08:46:36 | [diff] [blame] | 242 | static const std::vector<gfx::Size>& dpis( |
| 243 | const printing::PrinterSemanticCapsAndDefaults& p) { |
| 244 | return p.dpis; |
| 245 | } |
| 246 | static const gfx::Size& default_dpi( |
| 247 | const printing::PrinterSemanticCapsAndDefaults& p) { |
| 248 | return p.default_dpi; |
| 249 | } |
| 250 | |
Xiaohan Wang | e3d00dd6 | 2022-01-08 02:33:28 | [diff] [blame] | 251 | #if BUILDFLAG(IS_CHROMEOS) |
Alan Screen | 7a5f8512 | 2020-10-08 08:46:36 | [diff] [blame] | 252 | static bool pin_supported(const printing::PrinterSemanticCapsAndDefaults& p) { |
| 253 | return p.pin_supported; |
| 254 | } |
| 255 | static const printing::AdvancedCapabilities& advanced_capabilities( |
| 256 | const printing::PrinterSemanticCapsAndDefaults& p) { |
| 257 | return p.advanced_capabilities; |
| 258 | } |
Xiaohan Wang | e3d00dd6 | 2022-01-08 02:33:28 | [diff] [blame] | 259 | #endif // BUILDFLAG(IS_CHROMEOS) |
Alan Screen | 7a5f8512 | 2020-10-08 08:46:36 | [diff] [blame] | 260 | |
Andy Phan | 1e07acf | 2022-07-18 22:11:31 | [diff] [blame] | 261 | #if BUILDFLAG(IS_WIN) |
| 262 | static const absl::optional<printing::PageOutputQuality>& page_output_quality( |
| 263 | const printing::PrinterSemanticCapsAndDefaults& p) { |
| 264 | return p.page_output_quality; |
| 265 | } |
| 266 | #endif // BUILDFLAG(IS_WIN) |
| 267 | |
Alan Screen | 7a5f8512 | 2020-10-08 08:46:36 | [diff] [blame] | 268 | static bool Read(printing::mojom::PrinterSemanticCapsAndDefaultsDataView data, |
| 269 | printing::PrinterSemanticCapsAndDefaults* out); |
| 270 | }; |
| 271 | |
Alan Screen | e86ec5b | 2020-09-30 23:17:15 | [diff] [blame] | 272 | } // namespace mojo |
| 273 | |
| 274 | #endif // PRINTING_BACKEND_MOJOM_PRINT_BACKEND_MOJOM_TRAITS_H_ |