Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / printing / print_settings.h
blob1f35e90b9ae0b29bf7c6eedb2fbede9170f7562a
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.
5 #ifndef PRINTING_PRINT_SETTINGS_H_
6 #define PRINTING_PRINT_SETTINGS_H_
8 #include <string>
10 #include "base/strings/string16.h"
11 #include "printing/page_range.h"
12 #include "printing/page_setup.h"
13 #include "printing/print_job_constants.h"
14 #include "printing/printing_export.h"
15 #include "ui/gfx/geometry/rect.h"
17 namespace printing {
19 // Returns true if |color_mode| is color and not B&W.
20 PRINTING_EXPORT bool IsColorModelSelected(int color_mode);
22 #if defined(USE_CUPS)
23 // Get the color model setting name and value for the |color_mode|.
24 PRINTING_EXPORT void GetColorModelForMode(int color_mode,
25 std::string* color_setting_name,
26 std::string* color_value);
27 #endif
29 // OS-independent print settings.
30 class PRINTING_EXPORT PrintSettings {
31 public:
32 // Media properties requested by the user. Default instance represents
33 // default media selection.
34 struct RequestedMedia {
35 // Size of the media, in microns.
36 gfx::Size size_microns;
37 // Platform specific id to map it back to the particular media.
38 std::string vendor_id;
40 bool IsDefault() const {
41 return size_microns.IsEmpty() && vendor_id.empty();
45 PrintSettings();
46 ~PrintSettings();
48 // Reinitialize the settings to the default values.
49 void Clear();
51 void SetCustomMargins(const PageMargins& requested_margins_in_points);
52 const PageMargins& requested_custom_margins_in_points() const {
53 return requested_custom_margins_in_points_;
55 void set_margin_type(MarginType margin_type) { margin_type_ = margin_type; }
56 MarginType margin_type() const { return margin_type_; }
58 // Updates the orientation and flip the page if needed.
59 void SetOrientation(bool landscape);
60 bool landscape() const { return landscape_; }
62 // Updates user requested media.
63 void set_requested_media(const RequestedMedia& media) {
64 requested_media_ = media;
66 // Media properties requested by the user. Translated into device media by the
67 // platform specific layers.
68 const RequestedMedia& requested_media() const {
69 return requested_media_;
72 // Set printer printable area in in device units.
73 // Some platforms already provide flipped area. Set |landscape_needs_flip|
74 // to false on those platforms to avoid double flipping.
75 void SetPrinterPrintableArea(const gfx::Size& physical_size_device_units,
76 const gfx::Rect& printable_area_device_units,
77 bool landscape_needs_flip);
78 const PageSetup& page_setup_device_units() const {
79 return page_setup_device_units_;
82 void set_device_name(const base::string16& device_name) {
83 device_name_ = device_name;
85 const base::string16& device_name() const { return device_name_; }
87 void set_dpi(int dpi) { dpi_ = dpi; }
88 int dpi() const { return dpi_; }
90 void set_supports_alpha_blend(bool supports_alpha_blend) {
91 supports_alpha_blend_ = supports_alpha_blend;
93 bool supports_alpha_blend() const { return supports_alpha_blend_; }
95 int device_units_per_inch() const {
96 #if defined(OS_MACOSX)
97 return 72;
98 #else // defined(OS_MACOSX)
99 return dpi();
100 #endif // defined(OS_MACOSX)
103 void set_ranges(const PageRanges& ranges) { ranges_ = ranges; };
104 const PageRanges& ranges() const { return ranges_; };
106 void set_selection_only(bool selection_only) {
107 selection_only_ = selection_only;
109 bool selection_only() const { return selection_only_; }
111 void set_should_print_backgrounds(bool should_print_backgrounds) {
112 should_print_backgrounds_ = should_print_backgrounds;
114 bool should_print_backgrounds() const { return should_print_backgrounds_; }
116 void set_display_header_footer(bool display_header_footer) {
117 display_header_footer_ = display_header_footer;
119 bool display_header_footer() const { return display_header_footer_; }
121 void set_title(const base::string16& title) { title_ = title; }
122 const base::string16& title() const { return title_; }
124 void set_url(const base::string16& url) { url_ = url; }
125 const base::string16& url() const { return url_; }
127 void set_collate(bool collate) { collate_ = collate; }
128 bool collate() const { return collate_; }
130 void set_color(ColorModel color) { color_ = color; }
131 ColorModel color() const { return color_; }
133 void set_copies(int copies) { copies_ = copies; }
134 int copies() const { return copies_; }
136 void set_duplex_mode(DuplexMode duplex_mode) { duplex_mode_ = duplex_mode; }
137 DuplexMode duplex_mode() const { return duplex_mode_; }
139 int desired_dpi() const { return desired_dpi_; }
141 double max_shrink() const { return max_shrink_; }
143 double min_shrink() const { return min_shrink_; }
145 // Cookie generator. It is used to initialize PrintedDocument with its
146 // associated PrintSettings, to be sure that each generated PrintedPage is
147 // correctly associated with its corresponding PrintedDocument.
148 static int NewCookie();
150 private:
151 // Multi-page printing. Each PageRange describes a from-to page combination.
152 // This permits printing selected pages only.
153 PageRanges ranges_;
155 // By imaging to a width a little wider than the available pixels, thin pages
156 // will be scaled down a little, matching the way they print in IE and Camino.
157 // This lets them use fewer sheets than they would otherwise, which is
158 // presumably why other browsers do this. Wide pages will be scaled down more
159 // than this.
160 double min_shrink_;
162 // This number determines how small we are willing to reduce the page content
163 // in order to accommodate the widest line. If the page would have to be
164 // reduced smaller to make the widest line fit, we just clip instead (this
165 // behavior matches MacIE and Mozilla, at least)
166 double max_shrink_;
168 // Desired visible dots per inch rendering for output. Printing should be
169 // scaled to ScreenDpi/dpix*desired_dpi.
170 int desired_dpi_;
172 // Indicates if the user only wants to print the current selection.
173 bool selection_only_;
175 // Indicates what kind of margins should be applied to the printable area.
176 MarginType margin_type_;
178 // Strings to be printed as headers and footers if requested by the user.
179 base::string16 title_;
180 base::string16 url_;
182 // True if the user wants headers and footers to be displayed.
183 bool display_header_footer_;
185 // True if the user wants to print CSS backgrounds.
186 bool should_print_backgrounds_;
188 // True if the user wants to print with collate.
189 bool collate_;
191 // True if the user wants to print with collate.
192 ColorModel color_;
194 // Number of copies user wants to print.
195 int copies_;
197 // Duplex type user wants to use.
198 DuplexMode duplex_mode_;
200 // Printer device name as opened by the OS.
201 base::string16 device_name_;
203 // Media requested by the user.
204 RequestedMedia requested_media_;
206 // Page setup in device units.
207 PageSetup page_setup_device_units_;
209 // Printer's device effective dots per inch in both axis.
210 int dpi_;
212 // Is the orientation landscape or portrait.
213 bool landscape_;
215 // True if this printer supports AlphaBlend.
216 bool supports_alpha_blend_;
218 // If margin type is custom, this is what was requested.
219 PageMargins requested_custom_margins_in_points_;
222 } // namespace printing
224 #endif // PRINTING_PRINT_SETTINGS_H_