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 this.twoSidedOption_ = $('two-sided-div'); | |
26 | |
27 // Constant values matches printing::DuplexMode enum. Not using const | |
28 // keyword because it is not allowed by JS strict mode. | |
29 this.SIMPLEX = 0; | |
30 this.LONG_EDGE = 1; | |
31 this.UNKNOWN_DUPLEX_MODE = -1; | |
32 } | 25 } |
33 | 26 |
34 cr.addSingletonGetter(CopiesSettings); | 27 cr.addSingletonGetter(CopiesSettings); |
35 | 28 |
36 CopiesSettings.prototype = { | 29 CopiesSettings.prototype = { |
37 /** | 30 /** |
38 * The number of copies represented by the contents of |this.textfield_|. | 31 * The number of copies represented by the contents of |this.textfield_|. |
39 * If the text is not valid returns |this.minValue_|. | 32 * If the text is not valid returns |this.minValue_|. |
40 * @type {number} | 33 * @type {number} |
41 */ | 34 */ |
(...skipping 14 matching lines...) Expand all Loading... |
56 | 49 |
57 /** | 50 /** |
58 * Getter method for |twoSidedCheckbox_|. | 51 * Getter method for |twoSidedCheckbox_|. |
59 * @type {HTMLInputElement} | 52 * @type {HTMLInputElement} |
60 */ | 53 */ |
61 get twoSidedCheckbox() { | 54 get twoSidedCheckbox() { |
62 return this.twoSidedCheckbox_; | 55 return this.twoSidedCheckbox_; |
63 }, | 56 }, |
64 | 57 |
65 /** | 58 /** |
66 * Gets the duplex mode information for printing. | 59 * Gets the duplex mode for printing. |
67 * @return {number} duplex mode. | 60 * @return {number} duplex mode. |
68 */ | 61 */ |
69 get duplexMode() { | 62 get duplexMode() { |
70 if (this.twoSidedOption_.hidden) | 63 // Constant values matches printing::DuplexMode enum. Not using const |
71 return this.UNKNOWN_DUPLEX_MODE; | 64 // keyword because it is not allowed by JS strict mode. |
72 else if (this.twoSidedCheckbox_.checked) | 65 var SIMPLEX = 0; |
73 return this.LONG_EDGE; | 66 var LONG_EDGE = 1; |
74 else | 67 return !this.twoSidedCheckbox_.checked ? SIMPLEX : LONG_EDGE; |
75 return this.SIMPLEX; | |
76 }, | 68 }, |
77 | 69 |
78 /** | 70 /** |
79 * @return {boolean} true if |this.textfield_| is empty, or represents a | 71 * @return {boolean} true if |this.textfield_| is empty, or represents a |
80 * positive integer value. | 72 * positive integer value. |
81 */ | 73 */ |
82 isValid: function() { | 74 isValid: function() { |
83 return !this.textfield_.value || isPositiveInteger(this.textfield_.value); | 75 return !this.textfield_.value || isPositiveInteger(this.textfield_.value); |
84 }, | 76 }, |
85 | 77 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 * @private | 151 * @private |
160 */ | 152 */ |
161 onPrinterCapabilitiesUpdated_: function(e) { | 153 onPrinterCapabilitiesUpdated_: function(e) { |
162 if (e.printerCapabilities.disableCopiesOption) { | 154 if (e.printerCapabilities.disableCopiesOption) { |
163 fadeOutElement(this.copiesOption_); | 155 fadeOutElement(this.copiesOption_); |
164 $('hr-before-copies').classList.remove('invisible'); | 156 $('hr-before-copies').classList.remove('invisible'); |
165 } else { | 157 } else { |
166 fadeInElement(this.copiesOption_); | 158 fadeInElement(this.copiesOption_); |
167 $('hr-before-copies').classList.add('invisible'); | 159 $('hr-before-copies').classList.add('invisible'); |
168 } | 160 } |
169 this.updateTwoSidedOption_( | 161 this.twoSidedCheckbox_.checked = e.printerCapabilities.setDuplexAsDefault; |
170 e.printerCapabilities.printerDefaultDuplexValue); | |
171 }, | 162 }, |
172 | 163 |
173 /** | 164 /** |
174 * Listener triggered when |incrementButton_| is clicked. | 165 * Listener triggered when |incrementButton_| is clicked. |
175 * @private | 166 * @private |
176 */ | 167 */ |
177 onIncrementButtonClicked_: function() { | 168 onIncrementButtonClicked_: function() { |
178 this.onButtonClicked_(1); | 169 this.onButtonClicked_(1); |
179 }, | 170 }, |
180 | 171 |
(...skipping 11 matching lines...) Expand all Loading... |
192 */ | 183 */ |
193 showHideCollateOption_: function() { | 184 showHideCollateOption_: function() { |
194 this.collateOption_.hidden = this.numberOfCopies <= 1; | 185 this.collateOption_.hidden = this.numberOfCopies <= 1; |
195 // TODO(aayushkumar): Remove aria-hidden attribute once elements within | 186 // TODO(aayushkumar): Remove aria-hidden attribute once elements within |
196 // the hidden attribute are no longer read out by a screen-reader. | 187 // the hidden attribute are no longer read out by a screen-reader. |
197 // (Currently a bug in webkit). | 188 // (Currently a bug in webkit). |
198 this.collateOption_.setAttribute('aria-hidden', | 189 this.collateOption_.setAttribute('aria-hidden', |
199 this.collateOption_.hidden); | 190 this.collateOption_.hidden); |
200 }, | 191 }, |
201 | 192 |
202 /* | |
203 * Takes care of showing/hiding the two sided option and also updates the | |
204 * default state of the checkbox. | |
205 * @param {number} defaultDuplexValue Specifies the default duplex value. | |
206 * @private | |
207 */ | |
208 updateTwoSidedOption_: function(defaultDuplexValue) { | |
209 // On Windows, some printers don't specify their duplex values in the | |
210 // printer schema. If the printer duplex value is UNKNOWN_DUPLEX_MODE, | |
211 // hide the two sided option in preview tab UI. | |
212 // Ref bug: http://crbug.com/89204 | |
213 this.twoSidedOption_.hidden = | |
214 (defaultDuplexValue == this.UNKNOWN_DUPLEX_MODE); | |
215 this.twoSidedOption_.setAttribute('aria-hidden', | |
216 this.twoSidedOption_.hidden); | |
217 if (!this.twoSidedOption_.hidden) | |
218 this.twoSidedCheckbox_.checked = !!defaultDuplexValue; | |
219 }, | |
220 | |
221 /** | 193 /** |
222 * Updates the state of the increment/decrement buttons based on the current | 194 * Updates the state of the increment/decrement buttons based on the current |
223 * |textfield_| value. | 195 * |textfield_| value. |
224 * @private | 196 * @private |
225 */ | 197 */ |
226 updateButtonsState_: function() { | 198 updateButtonsState_: function() { |
227 if (!this.isValid()) { | 199 if (!this.isValid()) { |
228 this.textfield_.classList.add('invalid'); | 200 this.textfield_.classList.add('invalid'); |
229 this.incrementButton_.disabled = false; | 201 this.incrementButton_.disabled = false; |
230 this.decrementButton_.disabled = false; | 202 this.decrementButton_.disabled = false; |
231 fadeInElement(this.hint_); | 203 fadeInElement(this.hint_); |
232 } else { | 204 } else { |
233 this.textfield_.classList.remove('invalid'); | 205 this.textfield_.classList.remove('invalid'); |
234 this.incrementButton_.disabled = this.numberOfCopies == this.maxValue_; | 206 this.incrementButton_.disabled = this.numberOfCopies == this.maxValue_; |
235 this.decrementButton_.disabled = this.numberOfCopies == this.minValue_; | 207 this.decrementButton_.disabled = this.numberOfCopies == this.minValue_; |
236 fadeOutElement(this.hint_); | 208 fadeOutElement(this.hint_); |
237 } | 209 } |
238 this.hint_.setAttribute('aria-hidden', this.isValid()); | 210 this.hint_.setAttribute('aria-hidden', this.isValid()); |
239 } | 211 } |
240 }; | 212 }; |
241 | 213 |
242 return { | 214 return { |
243 CopiesSettings: CopiesSettings, | 215 CopiesSettings: CopiesSettings, |
244 }; | 216 }; |
245 }); | 217 }); |
OLD | NEW |