blob: b18d86022a5e669a93cf63c76ca7b5366198ce11 [file] [log] [blame]
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001// 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 <string>
9
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010010#include "base/strings/string16.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000011#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/rect.h"
16
17namespace printing {
18
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +010019// Returns true if |color_mode| is color and not B&W.
20PRINTING_EXPORT bool IsColorModelSelected(int color_mode);
Torne (Richard Coles)58218062012-11-14 11:43:16 +000021
22#if defined(USE_CUPS)
23// Get the color model setting name and value for the |color_mode|.
24PRINTING_EXPORT void GetColorModelForMode(int color_mode,
25 std::string* color_setting_name,
26 std::string* color_value);
27#endif
28
29// OS-independent print settings.
30class PRINTING_EXPORT PrintSettings {
31 public:
32 PrintSettings();
33 ~PrintSettings();
34
35 // Reinitialize the settings to the default values.
36 void Clear();
37
Torne (Richard Coles)58218062012-11-14 11:43:16 +000038 void SetCustomMargins(const PageMargins& requested_margins_in_points);
Torne (Richard Coles)1e9bf3e2013-10-31 11:16:26 +000039 void set_margin_type(MarginType margin_type) { margin_type_ = margin_type; }
40 MarginType margin_type() const { return margin_type_; }
Torne (Richard Coles)58218062012-11-14 11:43:16 +000041
Torne (Richard Coles)1e9bf3e2013-10-31 11:16:26 +000042 // Updates the orientation and flip the page if needed.
43 void SetOrientation(bool landscape);
44 bool landscape() const { return landscape_; }
Torne (Richard Coles)58218062012-11-14 11:43:16 +000045
Torne (Richard Coles)1e9bf3e2013-10-31 11:16:26 +000046 // Set printer printable area in in device units.
47 // Some platforms already provide flipped area. Set |landscape_needs_flip|
48 // to false on those platforms to avoid double flipping.
49 void SetPrinterPrintableArea(const gfx::Size& physical_size_device_units,
50 const gfx::Rect& printable_area_device_units,
Torne (Richard Coles)1e9bf3e2013-10-31 11:16:26 +000051 bool landscape_needs_flip);
52 const PageSetup& page_setup_device_units() const {
53 return page_setup_device_units_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000054 }
Torne (Richard Coles)1e9bf3e2013-10-31 11:16:26 +000055
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +010056 void set_device_name(const base::string16& device_name) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +000057 device_name_ = device_name;
58 }
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +010059 const base::string16& device_name() const { return device_name_; }
Torne (Richard Coles)1e9bf3e2013-10-31 11:16:26 +000060
Torne (Richard Coles)58218062012-11-14 11:43:16 +000061 void set_dpi(int dpi) { dpi_ = dpi; }
62 int dpi() const { return dpi_; }
Torne (Richard Coles)1e9bf3e2013-10-31 11:16:26 +000063
Torne (Richard Coles)58218062012-11-14 11:43:16 +000064 void set_supports_alpha_blend(bool supports_alpha_blend) {
65 supports_alpha_blend_ = supports_alpha_blend;
66 }
67 bool supports_alpha_blend() const { return supports_alpha_blend_; }
Torne (Richard Coles)1e9bf3e2013-10-31 11:16:26 +000068
Torne (Richard Coles)58218062012-11-14 11:43:16 +000069 int device_units_per_inch() const {
70#if defined(OS_MACOSX)
71 return 72;
72#else // defined(OS_MACOSX)
73 return dpi();
74#endif // defined(OS_MACOSX)
75 }
76
Torne (Richard Coles)1e9bf3e2013-10-31 11:16:26 +000077 void set_ranges(const PageRanges& ranges) { ranges_ = ranges; };
78 const PageRanges& ranges() const { return ranges_; };
Torne (Richard Coles)58218062012-11-14 11:43:16 +000079
Torne (Richard Coles)1e9bf3e2013-10-31 11:16:26 +000080 void set_selection_only(bool selection_only) {
81 selection_only_ = selection_only;
82 }
83 bool selection_only() const { return selection_only_; }
Torne (Richard Coles)58218062012-11-14 11:43:16 +000084
Torne (Richard Coles)1e9bf3e2013-10-31 11:16:26 +000085 void set_should_print_backgrounds(bool should_print_backgrounds) {
86 should_print_backgrounds_ = should_print_backgrounds;
87 }
88 bool should_print_backgrounds() const { return should_print_backgrounds_; }
Torne (Richard Coles)58218062012-11-14 11:43:16 +000089
Torne (Richard Coles)1e9bf3e2013-10-31 11:16:26 +000090 void set_display_header_footer(bool display_header_footer) {
91 display_header_footer_ = display_header_footer;
92 }
93 bool display_header_footer() const { return display_header_footer_; }
Torne (Richard Coles)58218062012-11-14 11:43:16 +000094
Torne (Richard Coles)1e9bf3e2013-10-31 11:16:26 +000095 void set_title(const base::string16& title) { title_ = title; }
96 const base::string16& title() const { return title_; }
Torne (Richard Coles)58218062012-11-14 11:43:16 +000097
Torne (Richard Coles)1e9bf3e2013-10-31 11:16:26 +000098 void set_url(const base::string16& url) { url_ = url; }
99 const base::string16& url() const { return url_; }
100
101 void set_collate(bool collate) { collate_ = collate; }
102 bool collate() const { return collate_; }
103
104 void set_color(ColorModel color) { color_ = color; }
105 ColorModel color() const { return color_; }
106
107 void set_copies(int copies) { copies_ = copies; }
108 int copies() const { return copies_; }
109
110 void set_duplex_mode(DuplexMode duplex_mode) { duplex_mode_ = duplex_mode; }
111 DuplexMode duplex_mode() const { return duplex_mode_; }
112
113 int desired_dpi() const { return desired_dpi_; }
114
115 double max_shrink() const { return max_shrink_; }
116
117 double min_shrink() const { return min_shrink_; }
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000118
119 // Cookie generator. It is used to initialize PrintedDocument with its
120 // associated PrintSettings, to be sure that each generated PrintedPage is
121 // correctly associated with its corresponding PrintedDocument.
122 static int NewCookie();
123
Torne (Richard Coles)1e9bf3e2013-10-31 11:16:26 +0000124 private:
125 // Multi-page printing. Each PageRange describes a from-to page combination.
126 // This permits printing selected pages only.
127 PageRanges ranges_;
128
129 // By imaging to a width a little wider than the available pixels, thin pages
130 // will be scaled down a little, matching the way they print in IE and Camino.
131 // This lets them use fewer sheets than they would otherwise, which is
132 // presumably why other browsers do this. Wide pages will be scaled down more
133 // than this.
134 double min_shrink_;
135
136 // This number determines how small we are willing to reduce the page content
137 // in order to accommodate the widest line. If the page would have to be
138 // reduced smaller to make the widest line fit, we just clip instead (this
139 // behavior matches MacIE and Mozilla, at least)
140 double max_shrink_;
141
142 // Desired visible dots per inch rendering for output. Printing should be
143 // scaled to ScreenDpi/dpix*desired_dpi.
144 int desired_dpi_;
145
146 // Indicates if the user only wants to print the current selection.
147 bool selection_only_;
148
149 // Indicates what kind of margins should be applied to the printable area.
150 MarginType margin_type_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000151
152 // Strings to be printed as headers and footers if requested by the user.
Torne (Richard Coles)1e9bf3e2013-10-31 11:16:26 +0000153 base::string16 title_;
154 base::string16 url_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000155
156 // True if the user wants headers and footers to be displayed.
Torne (Richard Coles)1e9bf3e2013-10-31 11:16:26 +0000157 bool display_header_footer_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000158
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000159 // True if the user wants to print CSS backgrounds.
Torne (Richard Coles)1e9bf3e2013-10-31 11:16:26 +0000160 bool should_print_backgrounds_;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000161
Torne (Richard Coles)1e9bf3e2013-10-31 11:16:26 +0000162 // True if the user wants to print with collate.
163 bool collate_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000164
Torne (Richard Coles)1e9bf3e2013-10-31 11:16:26 +0000165 // True if the user wants to print with collate.
166 ColorModel color_;
167
168 // Number of copies user wants to print.
169 int copies_;
170
171 // Duplex type user wants to use.
172 DuplexMode duplex_mode_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000173
174 // Printer device name as opened by the OS.
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +0100175 base::string16 device_name_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000176
177 // Page setup in device units.
178 PageSetup page_setup_device_units_;
179
180 // Printer's device effective dots per inch in both axis.
181 int dpi_;
182
183 // Is the orientation landscape or portrait.
184 bool landscape_;
185
186 // True if this printer supports AlphaBlend.
187 bool supports_alpha_blend_;
188
189 // If margin type is custom, this is what was requested.
190 PageMargins requested_custom_margins_in_points_;
191};
192
193} // namespace printing
194
195#endif // PRINTING_PRINT_SETTINGS_H_