| 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'); | 25 this.twoSidedOption_ = $('two-sided-option'); |
| 26 | 26 |
| 27 // Constant values matches printing::DuplexMode enum. Not using const | 27 // Constant values matches printing::DuplexMode enum. Not using const |
| 28 // keyword because it is not allowed by JS strict mode. | 28 // keyword because it is not allowed by JS strict mode. |
| 29 this.SIMPLEX = 0; | 29 this.SIMPLEX = 0; |
| 30 this.LONG_EDGE = 1; | 30 this.LONG_EDGE = 1; |
| 31 this.UNKNOWN_DUPLEX_MODE = -1; | 31 this.UNKNOWN_DUPLEX_MODE = -1; |
| 32 this.addEventListeners_(); | 32 this.addEventListeners_(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 cr.addSingletonGetter(CopiesSettings); | 35 cr.addSingletonGetter(CopiesSettings); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 onDecrementButtonClicked_: function() { | 183 onDecrementButtonClicked_: function() { |
| 184 this.onButtonClicked_(-1); | 184 this.onButtonClicked_(-1); |
| 185 }, | 185 }, |
| 186 | 186 |
| 187 /** | 187 /** |
| 188 * Takes care of showing/hiding the collate option. | 188 * Takes care of showing/hiding the collate option. |
| 189 * @private | 189 * @private |
| 190 */ | 190 */ |
| 191 showHideCollateOption_: function() { | 191 showHideCollateOption_: function() { |
| 192 this.collateOption_.hidden = this.numberOfCopies <= 1; | 192 this.collateOption_.hidden = this.numberOfCopies <= 1; |
| 193 // TODO(aayushkumar): Remove aria-hidden attribute once elements within | |
| 194 // the hidden attribute are no longer read out by a screen-reader. | |
| 195 // (Currently a bug in webkit). | |
| 196 this.collateOption_.setAttribute('aria-hidden', | |
| 197 this.collateOption_.hidden); | |
| 198 }, | 193 }, |
| 199 | 194 |
| 200 /* | 195 /* |
| 201 * Takes care of showing/hiding the two sided option and also updates the | 196 * Takes care of showing/hiding the two sided option and also updates the |
| 202 * default state of the checkbox. | 197 * default state of the checkbox. |
| 203 * @param {number} defaultDuplexValue Specifies the default duplex value. | 198 * @param {number} defaultDuplexValue Specifies the default duplex value. |
| 204 * @private | 199 * @private |
| 205 */ | 200 */ |
| 206 updateTwoSidedOption_: function(defaultDuplexValue) { | 201 updateTwoSidedOption_: function(defaultDuplexValue) { |
| 207 // On Windows, some printers don't specify their duplex values in the | 202 // On Windows, some printers don't specify their duplex values in the |
| 208 // printer schema. If the printer duplex value is UNKNOWN_DUPLEX_MODE, | 203 // printer schema. If the printer duplex value is UNKNOWN_DUPLEX_MODE, |
| 209 // hide the two sided option in preview tab UI. | 204 // hide the two sided option in preview tab UI. |
| 210 // Ref bug: http://crbug.com/89204 | 205 // Ref bug: http://crbug.com/89204 |
| 211 this.twoSidedOption_.hidden = | 206 this.twoSidedOption_.hidden = |
| 212 (defaultDuplexValue == this.UNKNOWN_DUPLEX_MODE); | 207 (defaultDuplexValue == this.UNKNOWN_DUPLEX_MODE); |
| 213 this.twoSidedOption_.setAttribute('aria-hidden', | 208 |
| 214 this.twoSidedOption_.hidden); | |
| 215 if (!this.twoSidedOption_.hidden) | 209 if (!this.twoSidedOption_.hidden) |
| 216 this.twoSidedCheckbox_.checked = !!defaultDuplexValue; | 210 this.twoSidedCheckbox_.checked = !!defaultDuplexValue; |
| 217 }, | 211 }, |
| 218 | 212 |
| 219 /** | 213 /** |
| 220 * Updates the state of the increment/decrement buttons based on the current | 214 * Updates the state of the increment/decrement buttons based on the current |
| 221 * |textfield_| value. | 215 * |textfield_| value. |
| 222 * @private | 216 * @private |
| 223 */ | 217 */ |
| 224 updateButtonsState_: function() { | 218 updateButtonsState_: function() { |
| 225 if (!this.isValid()) { | 219 if (!this.isValid()) { |
| 226 this.textfield_.classList.add('invalid'); | 220 this.textfield_.classList.add('invalid'); |
| 227 this.incrementButton_.disabled = false; | 221 this.incrementButton_.disabled = false; |
| 228 this.decrementButton_.disabled = false; | 222 this.decrementButton_.disabled = false; |
| 229 fadeInElement(this.hint_); | 223 fadeInElement(this.hint_); |
| 230 } else { | 224 } else { |
| 231 this.textfield_.classList.remove('invalid'); | 225 this.textfield_.classList.remove('invalid'); |
| 232 this.incrementButton_.disabled = this.numberOfCopies == this.maxValue_; | 226 this.incrementButton_.disabled = this.numberOfCopies == this.maxValue_; |
| 233 this.decrementButton_.disabled = this.numberOfCopies == this.minValue_; | 227 this.decrementButton_.disabled = this.numberOfCopies == this.minValue_; |
| 234 fadeOutElement(this.hint_); | 228 fadeOutElement(this.hint_); |
| 235 } | 229 } |
| 236 this.hint_.setAttribute('aria-hidden', this.isValid()); | 230 this.hint_.setAttribute('aria-hidden', this.isValid()); |
| 237 } | 231 } |
| 238 }; | 232 }; |
| 239 | 233 |
| 240 return { | 234 return { |
| 241 CopiesSettings: CopiesSettings, | 235 CopiesSettings: CopiesSettings, |
| 242 }; | 236 }; |
| 243 }); | 237 }); |
| OLD | NEW |