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 cr.exportPath('print_preview.ticket_items'); | 5 cr.exportPath('print_preview.ticket_items'); |
6 | 6 |
7 /** | 7 /** |
8 * Enumeration of the orientations of margins. | 8 * Enumeration of the orientations of margins. |
9 * @enum {string} | 9 * @enum {string} |
10 */ | 10 */ |
(...skipping 15 matching lines...) Expand all Loading... |
26 * {@code print_preview.Margins}. | 26 * {@code print_preview.Margins}. |
27 * @param {!print_preview.AppState} appState App state used to persist custom | 27 * @param {!print_preview.AppState} appState App state used to persist custom |
28 * margins. | 28 * margins. |
29 * @param {!print_preview.DocumentInfo} documentInfo Information about the | 29 * @param {!print_preview.DocumentInfo} documentInfo Information about the |
30 * document to print. | 30 * document to print. |
31 * @constructor | 31 * @constructor |
32 * @extends {print_preview.ticket_items.TicketItem} | 32 * @extends {print_preview.ticket_items.TicketItem} |
33 */ | 33 */ |
34 function CustomMargins(appState, documentInfo) { | 34 function CustomMargins(appState, documentInfo) { |
35 print_preview.ticket_items.TicketItem.call( | 35 print_preview.ticket_items.TicketItem.call( |
36 this, | 36 this, appState, print_preview.AppStateField.CUSTOM_MARGINS, |
37 appState, | 37 null /*destinationStore*/, documentInfo); |
38 print_preview.AppStateField.CUSTOM_MARGINS, | |
39 null /*destinationStore*/, | |
40 documentInfo); | |
41 } | 38 } |
42 | 39 |
43 /** | 40 /** |
44 * Mapping of a margin orientation to its opposite. | 41 * Mapping of a margin orientation to its opposite. |
45 * @type {!Object<!print_preview.ticket_items.CustomMarginsOrientation, | 42 * @type {!Object<!print_preview.ticket_items.CustomMarginsOrientation, |
46 * !print_preview.ticket_items.CustomMarginsOrientation>} | 43 * !print_preview.ticket_items.CustomMarginsOrientation>} |
47 * @private | 44 * @private |
48 */ | 45 */ |
49 CustomMargins.OppositeOrientation_ = {}; | 46 CustomMargins.OppositeOrientation_ = {}; |
50 CustomMargins.OppositeOrientation_[CustomMarginsOrientation.TOP] = | 47 CustomMargins.OppositeOrientation_[CustomMarginsOrientation.TOP] = |
51 CustomMarginsOrientation.BOTTOM; | 48 CustomMarginsOrientation.BOTTOM; |
52 CustomMargins.OppositeOrientation_[CustomMarginsOrientation.RIGHT] = | 49 CustomMargins.OppositeOrientation_[CustomMarginsOrientation.RIGHT] = |
53 CustomMarginsOrientation.LEFT; | 50 CustomMarginsOrientation.LEFT; |
54 CustomMargins.OppositeOrientation_[CustomMarginsOrientation.BOTTOM] = | 51 CustomMargins.OppositeOrientation_[CustomMarginsOrientation.BOTTOM] = |
55 CustomMarginsOrientation.TOP; | 52 CustomMarginsOrientation.TOP; |
56 CustomMargins.OppositeOrientation_[CustomMarginsOrientation.LEFT] = | 53 CustomMargins.OppositeOrientation_[CustomMarginsOrientation.LEFT] = |
57 CustomMarginsOrientation.RIGHT; | 54 CustomMarginsOrientation.RIGHT; |
58 | 55 |
59 /** | 56 /** |
60 * Minimum distance in points that two margins can be separated by. | 57 * Minimum distance in points that two margins can be separated by. |
61 * @type {number} | 58 * @type {number} |
62 * @const | 59 * @const |
63 * @private | 60 * @private |
64 */ | 61 */ |
65 CustomMargins.MINIMUM_MARGINS_DISTANCE_ = 72; // 1 inch. | 62 CustomMargins.MINIMUM_MARGINS_DISTANCE_ = 72; // 1 inch. |
66 | 63 |
67 CustomMargins.prototype = { | 64 CustomMargins.prototype = { |
68 __proto__: print_preview.ticket_items.TicketItem.prototype, | 65 __proto__: print_preview.ticket_items.TicketItem.prototype, |
69 | 66 |
70 /** @override */ | 67 /** @override */ |
71 wouldValueBeValid: function(value) { | 68 wouldValueBeValid: function(value) { |
72 var margins = /** @type {!print_preview.Margins} */ (value); | 69 var margins = /** @type {!print_preview.Margins} */ (value); |
73 for (var key in CustomMarginsOrientation) { | 70 for (var key in CustomMarginsOrientation) { |
74 var o = CustomMarginsOrientation[key]; | 71 var o = CustomMarginsOrientation[key]; |
75 var max = this.getMarginMax_( | 72 var max = this.getMarginMax_( |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 var oppositeOrientation = CustomMargins.OppositeOrientation_[orientation]; | 125 var oppositeOrientation = CustomMargins.OppositeOrientation_[orientation]; |
129 var max = | 126 var max = |
130 this.getMarginMax_(orientation, margins.get(oppositeOrientation)); | 127 this.getMarginMax_(orientation, margins.get(oppositeOrientation)); |
131 value = Math.max(0, Math.min(max, value)); | 128 value = Math.max(0, Math.min(max, value)); |
132 this.updateValue(margins.set(orientation, value)); | 129 this.updateValue(margins.set(orientation, value)); |
133 }, | 130 }, |
134 | 131 |
135 /** @override */ | 132 /** @override */ |
136 getDefaultValueInternal: function() { | 133 getDefaultValueInternal: function() { |
137 return this.getDocumentInfoInternal().margins || | 134 return this.getDocumentInfoInternal().margins || |
138 new print_preview.Margins(72, 72, 72, 72); | 135 new print_preview.Margins(72, 72, 72, 72); |
139 }, | 136 }, |
140 | 137 |
141 /** @override */ | 138 /** @override */ |
142 getCapabilityNotAvailableValueInternal: function() { | 139 getCapabilityNotAvailableValueInternal: function() { |
143 return this.getDocumentInfoInternal().margins || | 140 return this.getDocumentInfoInternal().margins || |
144 new print_preview.Margins(72, 72, 72, 72); | 141 new print_preview.Margins(72, 72, 72, 72); |
145 }, | 142 }, |
146 | 143 |
147 /** | 144 /** |
148 * @param {!print_preview.ticket_items.CustomMarginsOrientation} | 145 * @param {!print_preview.ticket_items.CustomMarginsOrientation} |
149 * orientation Specifies which margin to get the maximum value of. | 146 * orientation Specifies which margin to get the maximum value of. |
150 * @param {number} oppositeMargin Value of the margin in points | 147 * @param {number} oppositeMargin Value of the margin in points |
151 * opposite the specified margin. | 148 * opposite the specified margin. |
152 * @return {number} Maximum value in points of the specified margin. | 149 * @return {number} Maximum value in points of the specified margin. |
153 * @private | 150 * @private |
154 */ | 151 */ |
155 getMarginMax_: function(orientation, oppositeMargin) { | 152 getMarginMax_: function(orientation, oppositeMargin) { |
156 var dimensionLength = (orientation == CustomMarginsOrientation.TOP || | 153 var dimensionLength = (orientation == CustomMarginsOrientation.TOP || |
157 orientation == CustomMarginsOrientation.BOTTOM) ? | 154 orientation == CustomMarginsOrientation.BOTTOM) ? |
158 this.getDocumentInfoInternal().pageSize.height : | 155 this.getDocumentInfoInternal().pageSize.height : |
159 this.getDocumentInfoInternal().pageSize.width; | 156 this.getDocumentInfoInternal().pageSize.width; |
160 | 157 |
161 var totalMargin = dimensionLength - | 158 var totalMargin = |
162 CustomMargins.MINIMUM_MARGINS_DISTANCE_; | 159 dimensionLength - CustomMargins.MINIMUM_MARGINS_DISTANCE_; |
163 return Math.round(totalMargin > 0 ? totalMargin - oppositeMargin : 0); | 160 return Math.round(totalMargin > 0 ? totalMargin - oppositeMargin : 0); |
164 } | 161 } |
165 }; | 162 }; |
166 | 163 |
167 // Export | 164 // Export |
168 return { | 165 return {CustomMargins: CustomMargins}; |
169 CustomMargins: CustomMargins | |
170 }; | |
171 }); | 166 }); |
OLD | NEW |