OLD | NEW |
---|---|
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 cr.define('print_preview', function() { | 5 cr.define('print_preview', function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 /** | 8 /** |
9 * Creates a CopiesSettings object. | 9 * Creates a CopiesSettings object. |
10 * @constructor | 10 * @constructor |
11 */ | 11 */ |
12 function CopiesSettings() { | 12 function CopiesSettings() { |
13 this.copiesOption_ = $('copies-option'); | 13 this.copiesOption_ = $('copies-option'); |
14 this.textfield_ = $('copies'); | 14 this.textfield_ = $('copies'); |
15 this.incrementButton_ = $('increment'); | 15 this.incrementButton_ = $('increment'); |
16 this.decrementButton_ = $('decrement'); | 16 this.decrementButton_ = $('decrement'); |
17 // Minimum allowed value for number of copies. | 17 // Minimum allowed value for number of copies. |
18 this.minValue_ = 1; | 18 this.minValue_ = 1; |
19 // Maximum allowed value for number of copies. | 19 // Maximum allowed value for number of copies. |
20 this.maxValue_ = 999; | 20 this.maxValue_ = 999; |
21 this.collateOption_ = $('collate-option'); | 21 this.collateOption_ = $('collate-option'); |
22 this.collateCheckbox_ = $('collate'); | 22 this.collateCheckbox_ = $('collate'); |
23 this.hint_ = $('copies-hint'); | 23 this.hint_ = $('copies-hint'); |
24 this.twoSidedCheckbox_ = $('two-sided'); | 24 this.twoSidedCheckbox_ = $('two-sided'); |
25 | |
26 // Constant values matches printing::DuplexMode enum. Not using const | |
27 // keyword because it is not allowed by JS strict mode. | |
28 this.SIMPLEX = 0; | |
29 this.LONG_EDGE = 1; | |
30 this.SHORT_EDGE = 2; | |
31 this.UNKNOWN = -1; | |
32 // Store the default duplex setting value which we got from the printer. | |
33 this.printerDefaultDuplexValue_ = this.UNKNOWN; | |
25 } | 34 } |
26 | 35 |
27 cr.addSingletonGetter(CopiesSettings); | 36 cr.addSingletonGetter(CopiesSettings); |
28 | 37 |
29 CopiesSettings.prototype = { | 38 CopiesSettings.prototype = { |
30 /** | 39 /** |
31 * The number of copies represented by the contents of |this.textfield_|. | 40 * The number of copies represented by the contents of |this.textfield_|. |
32 * If the text is not valid returns |this.minValue_|. | 41 * If the text is not valid returns |this.minValue_|. |
33 * @type {number} | 42 * @type {number} |
34 */ | 43 */ |
(...skipping 14 matching lines...) Expand all Loading... | |
49 | 58 |
50 /** | 59 /** |
51 * Getter method for |twoSidedCheckbox_|. | 60 * Getter method for |twoSidedCheckbox_|. |
52 * @type {HTMLInputElement} | 61 * @type {HTMLInputElement} |
53 */ | 62 */ |
54 get twoSidedCheckbox() { | 63 get twoSidedCheckbox() { |
55 return this.twoSidedCheckbox_; | 64 return this.twoSidedCheckbox_; |
56 }, | 65 }, |
57 | 66 |
58 /** | 67 /** |
59 * Gets the duplex mode for printing. | 68 * Gets the duplex mode information for printing. |
60 * @return {number} duplex mode. | 69 * @return {number} duplex mode. |
61 */ | 70 */ |
62 get duplexMode() { | 71 get duplexMode() { |
63 // Constant values matches printing::DuplexMode enum. Not using const | 72 // On Windows, some printer doesn't specify their duplex values in the |
64 // keyword because it is not allowed by JS strict mode. | 73 // printer schema. If the printer duplex value is UNKNOWN, it is better |
65 var SIMPLEX = 0; | 74 // to assign either "0" or "1" in DEVMODE structure according to user |
66 var LONG_EDGE = 1; | 75 // selected duplex value. |
67 return !this.twoSidedCheckbox_.checked ? SIMPLEX : LONG_EDGE; | 76 // Ref bug: http://code.google.com/p/chromium/issues/detail?id=89204 |
vandebo (ex-Chrome)
2011/09/03 00:58:26
http://crbug.com/89204
kmadhusu
2011/09/03 02:44:53
Done.
| |
77 return !this.twoSidedCheckbox_.checked ? | |
vandebo (ex-Chrome)
2011/09/03 00:58:27
Double trinary is pretty ugly... how about if, els
kmadhusu
2011/09/03 02:44:53
Done.
| |
78 this.SIMPLEX : | |
79 (this.printerDefaultDuplexValue == this.UNKNOWN ? | |
80 this.SHORT_EDGE : this.LONG_EDGE); | |
vandebo (ex-Chrome)
2011/09/03 00:58:27
I wonder if it would be clearer to define this.DUP
kmadhusu
2011/09/03 02:44:53
Yeah it will be consistent with the comment. Done.
| |
68 }, | 81 }, |
69 | 82 |
70 /** | 83 /** |
71 * @return {boolean} true if |this.textfield_| is empty, or represents a | 84 * @return {boolean} true if |this.textfield_| is empty, or represents a |
72 * positive integer value. | 85 * positive integer value. |
73 */ | 86 */ |
74 isValid: function() { | 87 isValid: function() { |
75 return !this.textfield_.value || isPositiveInteger(this.textfield_.value); | 88 return !this.textfield_.value || isPositiveInteger(this.textfield_.value); |
76 }, | 89 }, |
77 | 90 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 * @private | 164 * @private |
152 */ | 165 */ |
153 onPrinterCapabilitiesUpdated_: function(e) { | 166 onPrinterCapabilitiesUpdated_: function(e) { |
154 if (e.printerCapabilities.disableCopiesOption) { | 167 if (e.printerCapabilities.disableCopiesOption) { |
155 fadeOutElement(this.copiesOption_); | 168 fadeOutElement(this.copiesOption_); |
156 $('hr-before-copies').classList.remove('invisible'); | 169 $('hr-before-copies').classList.remove('invisible'); |
157 } else { | 170 } else { |
158 fadeInElement(this.copiesOption_); | 171 fadeInElement(this.copiesOption_); |
159 $('hr-before-copies').classList.add('invisible'); | 172 $('hr-before-copies').classList.add('invisible'); |
160 } | 173 } |
161 this.twoSidedCheckbox_.checked = e.printerCapabilities.setDuplexAsDefault; | 174 this.printerDefaultDuplexValue = |
175 e.printerCapabilities.printerDefaultDuplexValue; | |
176 if (this.printerDefaultDuplexValue >= 0) | |
vandebo (ex-Chrome)
2011/09/03 00:58:27
!= UNKNOWN ?
kmadhusu
2011/09/03 02:44:53
Done.
| |
177 this.twoSidedCheckbox_.checked = this.printerDefaultDuplexValue; | |
162 }, | 178 }, |
163 | 179 |
164 /** | 180 /** |
165 * Listener triggered when |incrementButton_| is clicked. | 181 * Listener triggered when |incrementButton_| is clicked. |
166 * @private | 182 * @private |
167 */ | 183 */ |
168 onIncrementButtonClicked_: function() { | 184 onIncrementButtonClicked_: function() { |
169 this.onButtonClicked_(1); | 185 this.onButtonClicked_(1); |
170 }, | 186 }, |
171 | 187 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
208 fadeOutElement(this.hint_); | 224 fadeOutElement(this.hint_); |
209 } | 225 } |
210 this.hint_.setAttribute('aria-hidden', this.isValid()); | 226 this.hint_.setAttribute('aria-hidden', this.isValid()); |
211 } | 227 } |
212 }; | 228 }; |
213 | 229 |
214 return { | 230 return { |
215 CopiesSettings: CopiesSettings, | 231 CopiesSettings: CopiesSettings, |
216 }; | 232 }; |
217 }); | 233 }); |
OLD | NEW |