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