Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 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 <string> |
| 9 | |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 10 | #include "base/strings/string16.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 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/rect.h" |
| 16 | |
| 17 | namespace printing { |
| 18 | |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame] | 19 | // Returns true if |color_mode| is color and not B&W. |
| 20 | PRINTING_EXPORT bool IsColorModelSelected(int color_mode); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 21 | |
| 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 |
| 28 | |
| 29 | // OS-independent print settings. |
| 30 | class 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) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 38 | void SetCustomMargins(const PageMargins& requested_margins_in_points); |
Torne (Richard Coles) | 1e9bf3e | 2013-10-31 11:16:26 +0000 | [diff] [blame] | 39 | void set_margin_type(MarginType margin_type) { margin_type_ = margin_type; } |
| 40 | MarginType margin_type() const { return margin_type_; } |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 41 | |
Torne (Richard Coles) | 1e9bf3e | 2013-10-31 11:16:26 +0000 | [diff] [blame] | 42 | // Updates the orientation and flip the page if needed. |
| 43 | void SetOrientation(bool landscape); |
| 44 | bool landscape() const { return landscape_; } |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 45 | |
Torne (Richard Coles) | 1e9bf3e | 2013-10-31 11:16:26 +0000 | [diff] [blame] | 46 | // 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) | 1e9bf3e | 2013-10-31 11:16:26 +0000 | [diff] [blame] | 51 | bool landscape_needs_flip); |
| 52 | const PageSetup& page_setup_device_units() const { |
| 53 | return page_setup_device_units_; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 54 | } |
Torne (Richard Coles) | 1e9bf3e | 2013-10-31 11:16:26 +0000 | [diff] [blame] | 55 | |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame] | 56 | void set_device_name(const base::string16& device_name) { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 57 | device_name_ = device_name; |
| 58 | } |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame] | 59 | const base::string16& device_name() const { return device_name_; } |
Torne (Richard Coles) | 1e9bf3e | 2013-10-31 11:16:26 +0000 | [diff] [blame] | 60 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 61 | void set_dpi(int dpi) { dpi_ = dpi; } |
| 62 | int dpi() const { return dpi_; } |
Torne (Richard Coles) | 1e9bf3e | 2013-10-31 11:16:26 +0000 | [diff] [blame] | 63 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 64 | 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) | 1e9bf3e | 2013-10-31 11:16:26 +0000 | [diff] [blame] | 68 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 69 | 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) | 1e9bf3e | 2013-10-31 11:16:26 +0000 | [diff] [blame] | 77 | void set_ranges(const PageRanges& ranges) { ranges_ = ranges; }; |
| 78 | const PageRanges& ranges() const { return ranges_; }; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 79 | |
Torne (Richard Coles) | 1e9bf3e | 2013-10-31 11:16:26 +0000 | [diff] [blame] | 80 | void set_selection_only(bool selection_only) { |
| 81 | selection_only_ = selection_only; |
| 82 | } |
| 83 | bool selection_only() const { return selection_only_; } |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 84 | |
Torne (Richard Coles) | 1e9bf3e | 2013-10-31 11:16:26 +0000 | [diff] [blame] | 85 | 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) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 89 | |
Torne (Richard Coles) | 1e9bf3e | 2013-10-31 11:16:26 +0000 | [diff] [blame] | 90 | 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) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 94 | |
Torne (Richard Coles) | 1e9bf3e | 2013-10-31 11:16:26 +0000 | [diff] [blame] | 95 | void set_title(const base::string16& title) { title_ = title; } |
| 96 | const base::string16& title() const { return title_; } |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 97 | |
Torne (Richard Coles) | 1e9bf3e | 2013-10-31 11:16:26 +0000 | [diff] [blame] | 98 | 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) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 118 | |
| 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) | 1e9bf3e | 2013-10-31 11:16:26 +0000 | [diff] [blame] | 124 | 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) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 151 | |
| 152 | // Strings to be printed as headers and footers if requested by the user. |
Torne (Richard Coles) | 1e9bf3e | 2013-10-31 11:16:26 +0000 | [diff] [blame] | 153 | base::string16 title_; |
| 154 | base::string16 url_; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 155 | |
| 156 | // True if the user wants headers and footers to be displayed. |
Torne (Richard Coles) | 1e9bf3e | 2013-10-31 11:16:26 +0000 | [diff] [blame] | 157 | bool display_header_footer_; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 158 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 159 | // True if the user wants to print CSS backgrounds. |
Torne (Richard Coles) | 1e9bf3e | 2013-10-31 11:16:26 +0000 | [diff] [blame] | 160 | bool should_print_backgrounds_; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 161 | |
Torne (Richard Coles) | 1e9bf3e | 2013-10-31 11:16:26 +0000 | [diff] [blame] | 162 | // True if the user wants to print with collate. |
| 163 | bool collate_; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 164 | |
Torne (Richard Coles) | 1e9bf3e | 2013-10-31 11:16:26 +0000 | [diff] [blame] | 165 | // 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) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 173 | |
| 174 | // Printer device name as opened by the OS. |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame] | 175 | base::string16 device_name_; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 176 | |
| 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_ |