Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(286)

Side by Side Diff: printing/print_settings.cc

Issue 8342059: Clarify that the custom margin value is not validated and add tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « printing/print_settings.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 margins.footer = 0; 177 margins.footer = 0;
178 margins.top = 0; 178 margins.top = 0;
179 margins.bottom = 0; 179 margins.bottom = 0;
180 margins.left = 0; 180 margins.left = 0;
181 margins.right = 0; 181 margins.right = 0;
182 break; 182 break;
183 } 183 }
184 case CUSTOM_MARGINS: { 184 case CUSTOM_MARGINS: {
185 margins.header = 0; 185 margins.header = 0;
186 margins.footer = 0; 186 margins.footer = 0;
187 margins.top = ConvertUnitDouble(custom_margins_in_points_.top, 187 margins.top = ConvertUnitDouble(
188 kPointsPerInch, 188 requested_custom_margins_in_points_.top,
189 units_per_inch); 189 kPointsPerInch,
190 margins.bottom = ConvertUnitDouble(custom_margins_in_points_.bottom, 190 units_per_inch);
191 kPointsPerInch, 191 margins.bottom = ConvertUnitDouble(
192 units_per_inch); 192 requested_custom_margins_in_points_.bottom,
193 margins.left = ConvertUnitDouble(custom_margins_in_points_.left, 193 kPointsPerInch,
194 kPointsPerInch, 194 units_per_inch);
195 units_per_inch); 195 margins.left = ConvertUnitDouble(
196 margins.right = ConvertUnitDouble(custom_margins_in_points_.right, 196 requested_custom_margins_in_points_.left,
197 kPointsPerInch, 197 kPointsPerInch,
198 units_per_inch); 198 units_per_inch);
199 margins.right = ConvertUnitDouble(
200 requested_custom_margins_in_points_.right,
201 kPointsPerInch,
202 units_per_inch);
199 break; 203 break;
200 } 204 }
201 default: { 205 default: {
202 NOTREACHED(); 206 NOTREACHED();
203 } 207 }
204 } 208 }
205 209
206 if (margin_type == DEFAULT_MARGINS || margin_type == PRINTABLE_AREA_MARGINS) 210 if (margin_type == DEFAULT_MARGINS || margin_type == PRINTABLE_AREA_MARGINS)
207 page_setup_device_units_.SetRequestedMargins(margins); 211 page_setup_device_units_.SetRequestedMargins(margins);
208 else 212 else
209 page_setup_device_units_.ForceRequestedMargins(margins); 213 page_setup_device_units_.ForceRequestedMargins(margins);
210 } 214 }
211 215
212 void PrintSettings::SetCustomMargins(const PageMargins& margins_in_points) { 216 void PrintSettings::SetCustomMargins(
213 custom_margins_in_points_ = margins_in_points; 217 const PageMargins& requested_margins_in_points) {
218 requested_custom_margins_in_points_ = requested_margins_in_points;
214 margin_type = CUSTOM_MARGINS; 219 margin_type = CUSTOM_MARGINS;
215 } 220 }
216 221
217 bool PrintSettings::Equals(const PrintSettings& rhs) const { 222 bool PrintSettings::Equals(const PrintSettings& rhs) const {
218 // Do not test the display device name (printer_name_) for equality since it 223 // Do not test the display device name (printer_name_) for equality since it
219 // may sometimes be chopped off at 30 chars. As long as device_name is the 224 // may sometimes be chopped off at 30 chars. As long as device_name is the
220 // same, that's fine. 225 // same, that's fine.
221 return ranges == rhs.ranges && 226 return ranges == rhs.ranges &&
222 min_shrink == rhs.min_shrink && 227 min_shrink == rhs.min_shrink &&
223 max_shrink == rhs.max_shrink && 228 max_shrink == rhs.max_shrink &&
(...skipping 10 matching lines...) Expand all
234 } 239 }
235 240
236 void PrintSettings::SetOrientation(bool landscape) { 241 void PrintSettings::SetOrientation(bool landscape) {
237 if (landscape_ != landscape) { 242 if (landscape_ != landscape) {
238 landscape_ = landscape; 243 landscape_ = landscape;
239 page_setup_device_units_.FlipOrientation(); 244 page_setup_device_units_.FlipOrientation();
240 } 245 }
241 } 246 }
242 247
243 } // namespace printing 248 } // namespace printing
OLDNEW
« no previous file with comments | « printing/print_settings.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698