| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "printing/print_settings.h" | 5 #include "printing/print_settings.h" |
| 6 | 6 |
| 7 #include "base/atomic_sequence_num.h" | 7 #include "base/atomic_sequence_num.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "printing/print_job_constants.h" | 9 #include "printing/print_job_constants.h" |
| 10 #include "printing/units.h" | 10 #include "printing/units.h" |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 color_mode != BLACK && | 103 color_mode != BLACK && |
| 104 color_mode != PRINTOUTMODE_NORMAL_GRAY && | 104 color_mode != PRINTOUTMODE_NORMAL_GRAY && |
| 105 color_mode != COLORMODE_MONOCHROME && | 105 color_mode != COLORMODE_MONOCHROME && |
| 106 color_mode != PROCESSCOLORMODEL_GREYSCALE && | 106 color_mode != PROCESSCOLORMODEL_GREYSCALE && |
| 107 color_mode != HP_COLOR_BLACK); | 107 color_mode != HP_COLOR_BLACK); |
| 108 } | 108 } |
| 109 | 109 |
| 110 // Global SequenceNumber used for generating unique cookie values. | 110 // Global SequenceNumber used for generating unique cookie values. |
| 111 static base::StaticAtomicSequenceNumber cookie_seq; | 111 static base::StaticAtomicSequenceNumber cookie_seq; |
| 112 | 112 |
| 113 PrintSettings::PrintSettings() | 113 PrintSettings::PrintSettings() { |
| 114 : min_shrink(1.25), | 114 Clear(); |
| 115 max_shrink(2.0), | |
| 116 desired_dpi(72), | |
| 117 selection_only(false), | |
| 118 margin_type(DEFAULT_MARGINS), | |
| 119 display_header_footer(false), | |
| 120 should_print_backgrounds(false), | |
| 121 dpi_(0), | |
| 122 landscape_(false), | |
| 123 supports_alpha_blend_(true) { | |
| 124 } | 115 } |
| 125 | 116 |
| 126 PrintSettings::~PrintSettings() { | 117 PrintSettings::~PrintSettings() { |
| 127 } | 118 } |
| 128 | 119 |
| 129 void PrintSettings::Clear() { | 120 void PrintSettings::Clear() { |
| 130 ranges.clear(); | 121 ranges_.clear(); |
| 131 min_shrink = 1.25; | 122 margin_type_ = DEFAULT_MARGINS; |
| 132 max_shrink = 2.; | 123 min_shrink_ = 1.25; |
| 133 desired_dpi = 72; | 124 max_shrink_ = 2.; |
| 134 selection_only = false; | 125 desired_dpi_ = 72; |
| 135 title = base::string16(); | 126 selection_only_ = false; |
| 136 url = base::string16(); | 127 title_ = base::string16(); |
| 137 display_header_footer = false; | 128 url_ = base::string16(); |
| 129 display_header_footer_ = false; |
| 138 device_name_.clear(); | 130 device_name_.clear(); |
| 139 page_setup_device_units_.Clear(); | 131 page_setup_device_units_.Clear(); |
| 140 dpi_ = 0; | 132 dpi_ = 0; |
| 141 landscape_ = false; | 133 landscape_ = false; |
| 142 supports_alpha_blend_ = true; | 134 supports_alpha_blend_ = true; |
| 143 should_print_backgrounds = false; | 135 should_print_backgrounds_ = false; |
| 136 collate_ = false; |
| 137 color_ = UNKNOWN_COLOR_MODEL; |
| 138 copies_ = 0; |
| 139 duplex_mode_ = UNKNOWN_DUPLEX_MODE; |
| 144 } | 140 } |
| 145 | 141 |
| 146 void PrintSettings::SetPrinterPrintableArea( | 142 void PrintSettings::SetPrinterPrintableArea( |
| 147 gfx::Size const& physical_size_device_units, | 143 gfx::Size const& physical_size_device_units, |
| 148 gfx::Rect const& printable_area_device_units, | 144 gfx::Rect const& printable_area_device_units, |
| 149 int units_per_inch) { | 145 int units_per_inch, |
| 146 bool landscape_needs_flip) { |
| 150 int header_footer_text_height = 0; | 147 int header_footer_text_height = 0; |
| 151 if (display_header_footer) { | 148 if (display_header_footer_) { |
| 152 // Hard-code text_height = 0.5cm = ~1/5 of inch. | 149 // Hard-code text_height = 0.5cm = ~1/5 of inch. |
| 153 header_footer_text_height = ConvertUnit(kSettingHeaderFooterInterstice, | 150 header_footer_text_height = ConvertUnit(kSettingHeaderFooterInterstice, |
| 154 kPointsPerInch, units_per_inch); | 151 kPointsPerInch, units_per_inch); |
| 155 } | 152 } |
| 156 | 153 |
| 157 PageMargins margins; | 154 PageMargins margins; |
| 158 switch (margin_type) { | 155 switch (margin_type_) { |
| 159 case DEFAULT_MARGINS: { | 156 case DEFAULT_MARGINS: { |
| 160 // Default margins 1.0cm = ~2/5 of an inch. | 157 // Default margins 1.0cm = ~2/5 of an inch. |
| 161 int margin_printer_units = ConvertUnit(1000, kHundrethsMMPerInch, | 158 int margin_printer_units = ConvertUnit(1000, kHundrethsMMPerInch, |
| 162 units_per_inch); | 159 units_per_inch); |
| 163 margins.header = header_footer_text_height; | 160 margins.header = header_footer_text_height; |
| 164 margins.footer = header_footer_text_height; | 161 margins.footer = header_footer_text_height; |
| 165 margins.top = margin_printer_units; | 162 margins.top = margin_printer_units; |
| 166 margins.bottom = margin_printer_units; | 163 margins.bottom = margin_printer_units; |
| 167 margins.left = margin_printer_units; | 164 margins.left = margin_printer_units; |
| 168 margins.right = margin_printer_units; | 165 margins.right = margin_printer_units; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 197 requested_custom_margins_in_points_.right, | 194 requested_custom_margins_in_points_.right, |
| 198 kPointsPerInch, | 195 kPointsPerInch, |
| 199 units_per_inch); | 196 units_per_inch); |
| 200 break; | 197 break; |
| 201 } | 198 } |
| 202 default: { | 199 default: { |
| 203 NOTREACHED(); | 200 NOTREACHED(); |
| 204 } | 201 } |
| 205 } | 202 } |
| 206 | 203 |
| 207 if (margin_type == DEFAULT_MARGINS || margin_type == PRINTABLE_AREA_MARGINS) | 204 if (margin_type_ == DEFAULT_MARGINS || margin_type_ == PRINTABLE_AREA_MARGINS) |
| 208 page_setup_device_units_.SetRequestedMargins(margins); | 205 page_setup_device_units_.SetRequestedMargins(margins); |
| 209 else | 206 else |
| 210 page_setup_device_units_.ForceRequestedMargins(margins); | 207 page_setup_device_units_.ForceRequestedMargins(margins); |
| 211 | 208 |
| 212 page_setup_device_units_.Init(physical_size_device_units, | 209 page_setup_device_units_.Init(physical_size_device_units, |
| 213 printable_area_device_units, | 210 printable_area_device_units, |
| 214 header_footer_text_height); | 211 header_footer_text_height); |
| 212 if (landscape_ && landscape_needs_flip) |
| 213 page_setup_device_units_.FlipOrientation(); |
| 215 } | 214 } |
| 216 | 215 |
| 217 void PrintSettings::SetCustomMargins( | 216 void PrintSettings::SetCustomMargins( |
| 218 const PageMargins& requested_margins_in_points) { | 217 const PageMargins& requested_margins_in_points) { |
| 219 requested_custom_margins_in_points_ = requested_margins_in_points; | 218 requested_custom_margins_in_points_ = requested_margins_in_points; |
| 220 margin_type = CUSTOM_MARGINS; | 219 margin_type_ = CUSTOM_MARGINS; |
| 221 } | |
| 222 | |
| 223 bool PrintSettings::Equals(const PrintSettings& rhs) const { | |
| 224 // Do not test the display device name (printer_name_) for equality since it | |
| 225 // may sometimes be chopped off at 30 chars. As long as device_name is the | |
| 226 // same, that's fine. | |
| 227 return ranges == rhs.ranges && | |
| 228 min_shrink == rhs.min_shrink && | |
| 229 max_shrink == rhs.max_shrink && | |
| 230 desired_dpi == rhs.desired_dpi && | |
| 231 device_name_ == rhs.device_name_ && | |
| 232 page_setup_device_units_.Equals(rhs.page_setup_device_units_) && | |
| 233 dpi_ == rhs.dpi_ && | |
| 234 landscape_ == rhs.landscape_ && | |
| 235 should_print_backgrounds == rhs.should_print_backgrounds; | |
| 236 } | 220 } |
| 237 | 221 |
| 238 int PrintSettings::NewCookie() { | 222 int PrintSettings::NewCookie() { |
| 239 // A cookie of 0 is used to mark a document as unassigned, count from 1. | 223 // A cookie of 0 is used to mark a document as unassigned, count from 1. |
| 240 return cookie_seq.GetNext() + 1; | 224 return cookie_seq.GetNext() + 1; |
| 241 } | 225 } |
| 242 | 226 |
| 243 void PrintSettings::SetOrientation(bool landscape) { | 227 void PrintSettings::SetOrientation(bool landscape) { |
| 244 if (landscape_ != landscape) { | 228 if (landscape_ != landscape) { |
| 245 landscape_ = landscape; | 229 landscape_ = landscape; |
| 246 page_setup_device_units_.FlipOrientation(); | 230 page_setup_device_units_.FlipOrientation(); |
| 247 } | 231 } |
| 248 } | 232 } |
| 249 | 233 |
| 250 } // namespace printing | 234 } // namespace printing |
| OLD | NEW |