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

Side by Side Diff: chrome/browser/resources/print_preview/data/margins.js

Issue 2862203002: Print Preview: Fix data/ errors (Closed)
Patch Set: Fix destination resolver Created 3 years, 7 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
OLDNEW
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 cr.define('print_preview', function() { 5 cr.define('print_preview', function() {
6 'use strict'; 6 'use strict';
7 7
8 /** 8 /**
9 * Creates a Margins object that holds four margin values in points. 9 * Creates a Margins object that holds four margin values in points.
10 * @param {number} top The top margin in pts. 10 * @param {number} top The top margin in pts.
11 * @param {number} right The right margin in pts. 11 * @param {number} right The right margin in pts.
12 * @param {number} bottom The bottom margin in pts. 12 * @param {number} bottom The bottom margin in pts.
13 * @param {number} left The left margin in pts. 13 * @param {number} left The left margin in pts.
14 * @constructor 14 * @constructor
15 */ 15 */
16 function Margins(top, right, bottom, left) { 16 function Margins(top, right, bottom, left) {
17 /** 17 /**
18 * Backing store for the margin values in points. 18 * Backing store for the margin values in points.
19 * @type {!Object< 19 * @type {!Object<
20 * !print_preview.ticket_items.CustomMargins.Orientation, number>} 20 * !print_preview.ticket_items.CustomMarginsOrientation, number>}
21 * @private 21 * @private
22 */ 22 */
23 this.value_ = {}; 23 this.value_ = {};
24 this.value_[print_preview.ticket_items.CustomMargins.Orientation.TOP] = top; 24 this.value_[print_preview.ticket_items.CustomMarginsOrientation.TOP] = top;
25 this.value_[print_preview.ticket_items.CustomMargins.Orientation.RIGHT] = 25 this.value_[print_preview.ticket_items.CustomMarginsOrientation.RIGHT] =
26 right; 26 right;
27 this.value_[print_preview.ticket_items.CustomMargins.Orientation.BOTTOM] = 27 this.value_[print_preview.ticket_items.CustomMarginsOrientation.BOTTOM] =
28 bottom; 28 bottom;
29 this.value_[print_preview.ticket_items.CustomMargins.Orientation.LEFT] = 29 this.value_[print_preview.ticket_items.CustomMarginsOrientation.LEFT] =
30 left; 30 left;
31 }; 31 }
32 32
33 /** 33 /**
34 * Parses a margins object from the given serialized state. 34 * Parses a margins object from the given serialized state.
35 * @param {Object} state Serialized representation of the margins created by 35 * @param {Object} state Serialized representation of the margins created by
36 * the {@code serialize} method. 36 * the {@code serialize} method.
37 * @return {!print_preview.Margins} New margins instance. 37 * @return {!print_preview.Margins} New margins instance.
38 */ 38 */
39 Margins.parse = function(state) { 39 Margins.parse = function(state) {
40 return new print_preview.Margins( 40 return new print_preview.Margins(
41 state[print_preview.ticket_items.CustomMargins.Orientation.TOP] || 0, 41 state[print_preview.ticket_items.CustomMarginsOrientation.TOP] || 0,
42 state[print_preview.ticket_items.CustomMargins.Orientation.RIGHT] || 0, 42 state[print_preview.ticket_items.CustomMarginsOrientation.RIGHT] || 0,
43 state[print_preview.ticket_items.CustomMargins.Orientation.BOTTOM] || 0, 43 state[print_preview.ticket_items.CustomMarginsOrientation.BOTTOM] || 0,
44 state[print_preview.ticket_items.CustomMargins.Orientation.LEFT] || 0); 44 state[print_preview.ticket_items.CustomMarginsOrientation.LEFT] || 0);
45 }; 45 };
46 46
47 Margins.prototype = { 47 Margins.prototype = {
48 /** 48 /**
49 * @param {!print_preview.ticket_items.CustomMargins.Orientation} 49 * @param {!print_preview.ticket_items.CustomMarginsOrientation}
50 * orientation Specifies the margin value to get. 50 * orientation Specifies the margin value to get.
51 * @return {number} Value of the margin of the given orientation. 51 * @return {number} Value of the margin of the given orientation.
52 */ 52 */
53 get: function(orientation) { 53 get: function(orientation) {
54 return this.value_[orientation]; 54 return this.value_[orientation];
55 }, 55 },
56 56
57 /** 57 /**
58 * @param {!print_preview.ticket_items.CustomMargins.Orientation} 58 * @param {!print_preview.ticket_items.CustomMarginsOrientation}
59 * orientation Specifies the margin to set. 59 * orientation Specifies the margin to set.
60 * @param {number} value Updated value of the margin in points to modify. 60 * @param {number} value Updated value of the margin in points to modify.
61 * @return {!print_preview.Margins} A new copy of |this| with the 61 * @return {!print_preview.Margins} A new copy of |this| with the
62 * modification made to the specified margin. 62 * modification made to the specified margin.
63 */ 63 */
64 set: function(orientation, value) { 64 set: function(orientation, value) {
65 var newValue = this.clone_(); 65 var newValue = this.clone_();
66 newValue[orientation] = value; 66 newValue[orientation] = value;
67 return new Margins( 67 return new Margins(
68 newValue[print_preview.ticket_items.CustomMargins.Orientation.TOP], 68 newValue[print_preview.ticket_items.CustomMarginsOrientation.TOP],
69 newValue[print_preview.ticket_items.CustomMargins.Orientation.RIGHT], 69 newValue[print_preview.ticket_items.CustomMarginsOrientation.RIGHT],
70 newValue[print_preview.ticket_items.CustomMargins.Orientation.BOTTOM], 70 newValue[print_preview.ticket_items.CustomMarginsOrientation.BOTTOM],
71 newValue[print_preview.ticket_items.CustomMargins.Orientation.LEFT]); 71 newValue[print_preview.ticket_items.CustomMarginsOrientation.LEFT]);
72 }, 72 },
73 73
74 /** 74 /**
75 * @param {print_preview.Margins} other The other margins object to compare 75 * @param {print_preview.Margins} other The other margins object to compare
76 * against. 76 * against.
77 * @return {boolean} Whether this margins object is equal to another. 77 * @return {boolean} Whether this margins object is equal to another.
78 */ 78 */
79 equals: function(other) { 79 equals: function(other) {
80 if (other == null) { 80 if (other == null) {
81 return false; 81 return false;
(...skipping 22 matching lines...) Expand all
104 } 104 }
105 return clone; 105 return clone;
106 } 106 }
107 }; 107 };
108 108
109 // Export 109 // Export
110 return { 110 return {
111 Margins: Margins 111 Margins: Margins
112 }; 112 };
113 }); 113 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698