Upload upstream chromium 73.0.3683.0
[platform/framework/web/chromium-efl.git] / printing / print_settings.h
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
3 // found in the LICENSE file.
4
5 #ifndef PRINTING_PRINT_SETTINGS_H_
6 #define PRINTING_PRINT_SETTINGS_H_
7
8 #include <algorithm>
9 #include <string>
10
11 #include "base/strings/string16.h"
12 #include "printing/page_range.h"
13 #include "printing/page_setup.h"
14 #include "printing/print_job_constants.h"
15 #include "printing/printing_export.h"
16 #include "ui/gfx/geometry/rect.h"
17 #include "ui/gfx/geometry/size.h"
18
19 namespace printing {
20
21 // Returns true if |color_mode| is color and not B&W.
22 PRINTING_EXPORT bool IsColorModelSelected(int color_mode);
23
24 #if defined(USE_CUPS)
25 // Get the color model setting name and value for the |color_mode|.
26 PRINTING_EXPORT void GetColorModelForMode(int color_mode,
27                                           std::string* color_setting_name,
28                                           std::string* color_value);
29 #endif
30
31 // Inform the printing system that it may embed this user-agent string
32 // in its output's metadata.
33 PRINTING_EXPORT void SetAgent(const std::string& user_agent);
34 PRINTING_EXPORT const std::string& GetAgent();
35
36 class PRINTING_EXPORT PrintSettings {
37  public:
38 #if defined(OS_WIN)
39   enum PrinterType {
40     TYPE_NONE = 0,
41     TYPE_TEXTONLY,
42     TYPE_XPS,
43     TYPE_POSTSCRIPT_LEVEL2,
44     TYPE_POSTSCRIPT_LEVEL3
45   };
46 #endif
47
48   // Media properties requested by the user. Default instance represents
49   // default media selection.
50   struct RequestedMedia {
51     // Size of the media, in microns.
52     gfx::Size size_microns;
53     // Platform specific id to map it back to the particular media.
54     std::string vendor_id;
55
56     bool IsDefault() const {
57       return size_microns.IsEmpty() && vendor_id.empty();
58     }
59   };
60
61   PrintSettings();
62   PrintSettings(const PrintSettings& other);
63   ~PrintSettings();
64
65   // Reinitialize the settings to the default values.
66   void Clear();
67
68   void SetCustomMargins(const PageMargins& requested_margins_in_points);
69   const PageMargins& requested_custom_margins_in_points() const {
70     return requested_custom_margins_in_points_;
71   }
72   void set_margin_type(MarginType margin_type) { margin_type_ = margin_type; }
73   MarginType margin_type() const { return margin_type_; }
74
75   // Updates the orientation and flip the page if needed.
76   void SetOrientation(bool landscape);
77   bool landscape() const { return landscape_; }
78
79   // Updates user requested media.
80   void set_requested_media(const RequestedMedia& media) {
81     requested_media_ = media;
82   }
83   // Media properties requested by the user. Translated into device media by the
84   // platform specific layers.
85   const RequestedMedia& requested_media() const {
86     return requested_media_;
87   }
88
89   // Set printer printable area in in device units.
90   // Some platforms already provide flipped area. Set |landscape_needs_flip|
91   // to false on those platforms to avoid double flipping.
92   // This method assumes correct DPI is already set.
93   void SetPrinterPrintableArea(const gfx::Size& physical_size_device_units,
94                                const gfx::Rect& printable_area_device_units,
95                                bool landscape_needs_flip);
96   const PageSetup& page_setup_device_units() const {
97     return page_setup_device_units_;
98   }
99
100   void set_device_name(const base::string16& device_name) {
101     device_name_ = device_name;
102   }
103   const base::string16& device_name() const { return device_name_; }
104
105   void set_dpi(int dpi) { dpi_ = gfx::Size(dpi, dpi); }
106   void set_dpi_xy(int dpi_horizontal, int dpi_vertical) {
107     dpi_ = gfx::Size(dpi_horizontal, dpi_vertical);
108   }
109
110   int dpi() const { return std::max(dpi_.width(), dpi_.height()); }
111   int dpi_horizontal() const { return dpi_.width(); }
112   int dpi_vertical() const { return dpi_.height(); }
113   const gfx::Size& dpi_size() const { return dpi_; }
114
115   void set_scale_factor(double scale_factor) { scale_factor_ = scale_factor; }
116   double scale_factor() const { return scale_factor_; }
117
118   void set_rasterize_pdf(bool rasterize_pdf) { rasterize_pdf_ = rasterize_pdf; }
119   bool rasterize_pdf() const { return rasterize_pdf_; }
120
121   void set_supports_alpha_blend(bool supports_alpha_blend) {
122     supports_alpha_blend_ = supports_alpha_blend;
123   }
124   bool supports_alpha_blend() const { return supports_alpha_blend_; }
125
126   int device_units_per_inch() const {
127 #if defined(OS_MACOSX)
128     return 72;
129 #else  // defined(OS_MACOSX)
130     return dpi();
131 #endif  // defined(OS_MACOSX)
132   }
133
134   void set_ranges(const PageRanges& ranges) { ranges_ = ranges; }
135   const PageRanges& ranges() const { return ranges_; }
136
137   void set_selection_only(bool selection_only) {
138     selection_only_ = selection_only;
139   }
140   bool selection_only() const { return selection_only_; }
141
142   void set_should_print_backgrounds(bool should_print_backgrounds) {
143     should_print_backgrounds_ = should_print_backgrounds;
144   }
145   bool should_print_backgrounds() const { return should_print_backgrounds_; }
146
147   void set_display_header_footer(bool display_header_footer) {
148     display_header_footer_ = display_header_footer;
149   }
150   bool display_header_footer() const { return display_header_footer_; }
151
152   void set_title(const base::string16& title) { title_ = title; }
153   const base::string16& title() const { return title_; }
154
155   void set_url(const base::string16& url) { url_ = url; }
156   const base::string16& url() const { return url_; }
157
158   void set_collate(bool collate) { collate_ = collate; }
159   bool collate() const { return collate_; }
160
161   void set_color(ColorModel color) { color_ = color; }
162   ColorModel color() const { return color_; }
163
164   void set_copies(int copies) { copies_ = copies; }
165   int copies() const { return copies_; }
166
167   void set_duplex_mode(DuplexMode duplex_mode) { duplex_mode_ = duplex_mode; }
168   DuplexMode duplex_mode() const { return duplex_mode_; }
169
170 #if defined(OS_WIN)
171   void set_print_text_with_gdi(bool use_gdi) { print_text_with_gdi_ = use_gdi; }
172   bool print_text_with_gdi() const { return print_text_with_gdi_; }
173
174   void set_printer_type(PrinterType type) { printer_type_ = type; }
175   bool printer_is_textonly() const {
176     return printer_type_ == PrinterType::TYPE_TEXTONLY;
177   }
178   bool printer_is_xps() const { return printer_type_ == PrinterType::TYPE_XPS;}
179   bool printer_is_ps2() const {
180     return printer_type_ == PrinterType::TYPE_POSTSCRIPT_LEVEL2;
181   }
182   bool printer_is_ps3() const {
183     return printer_type_ == PrinterType::TYPE_POSTSCRIPT_LEVEL3;
184   }
185 #endif
186
187   void set_is_modifiable(bool is_modifiable) { is_modifiable_ = is_modifiable; }
188   bool is_modifiable() const { return is_modifiable_; }
189
190   int pages_per_sheet() const { return pages_per_sheet_; }
191   void set_pages_per_sheet(int pages_per_sheet) {
192     pages_per_sheet_ = pages_per_sheet;
193   }
194
195   // Cookie generator. It is used to initialize PrintedDocument with its
196   // associated PrintSettings, to be sure that each generated PrintedPage is
197   // correctly associated with its corresponding PrintedDocument.
198   static int NewCookie();
199
200  private:
201   // Multi-page printing. Each PageRange describes a from-to page combination.
202   // This permits printing selected pages only.
203   PageRanges ranges_;
204
205   // Indicates if the user only wants to print the current selection.
206   bool selection_only_;
207
208   // Indicates what kind of margins should be applied to the printable area.
209   MarginType margin_type_;
210
211   // Strings to be printed as headers and footers if requested by the user.
212   base::string16 title_;
213   base::string16 url_;
214
215   // True if the user wants headers and footers to be displayed.
216   bool display_header_footer_;
217
218   // True if the user wants to print CSS backgrounds.
219   bool should_print_backgrounds_;
220
221   // True if the user wants to print with collate.
222   bool collate_;
223
224   // True if the user wants to print with collate.
225   ColorModel color_;
226
227   // Number of copies user wants to print.
228   int copies_;
229
230   // Duplex type user wants to use.
231   DuplexMode duplex_mode_;
232
233   // Printer device name as opened by the OS.
234   base::string16 device_name_;
235
236   // Media requested by the user.
237   RequestedMedia requested_media_;
238
239   // Page setup in device units.
240   PageSetup page_setup_device_units_;
241
242   // Printer's device effective dots per inch in both axes. The two values will
243   // generally be identical. However, on Windows, there are a few rare printers
244   // that support resolutions with different DPI in different dimensions.
245   gfx::Size dpi_;
246
247   // Scale factor
248   double scale_factor_;
249
250   // True if PDF should be printed as a raster PDF
251   bool rasterize_pdf_;
252
253   // Is the orientation landscape or portrait.
254   bool landscape_;
255
256   // True if this printer supports AlphaBlend.
257   bool supports_alpha_blend_;
258
259 #if defined(OS_WIN)
260   // True to print text with GDI.
261   bool print_text_with_gdi_;
262
263   PrinterType printer_type_;
264 #endif
265
266   bool is_modifiable_;
267
268   // If margin type is custom, this is what was requested.
269   PageMargins requested_custom_margins_in_points_;
270
271   // Number of pages per sheet.
272   int pages_per_sheet_;
273 };
274
275 }  // namespace printing
276
277 #endif  // PRINTING_PRINT_SETTINGS_H_