Chromium Code Reviews| 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.UNKNOWN = -1; | |
| 31 // Store the default duplex setting value which we got from the printer. | |
| 32 this.DUPLEX = 1; | |
| 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 |
|
vandebo (ex-Chrome)
2011/09/04 17:06:53
nit: printer doesn't => printers don't
kmadhusu
2011/09/07 20:57:33
Done.
| |
| 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://crbug.com/89204 |
| 77 if (!this.twoSidedCheckbox_.checked) | |
| 78 return this.SIMPLEX; | |
| 79 else if (this.printerDefaultDuplexValue == this.UNKNOWN) | |
| 80 return this.DUPLEX; | |
|
vandebo (ex-Chrome)
2011/09/04 17:06:53
Wait, I'm confused, this.DUPLEX and this.LONG_EDGE
kmadhusu
2011/09/07 20:57:33
It was a typo.. I have removed DUPLEX now.
| |
| 81 else | |
| 82 return this.LONG_EDGE; | |
| 68 }, | 83 }, |
| 69 | 84 |
| 70 /** | 85 /** |
| 71 * @return {boolean} true if |this.textfield_| is empty, or represents a | 86 * @return {boolean} true if |this.textfield_| is empty, or represents a |
| 72 * positive integer value. | 87 * positive integer value. |
| 73 */ | 88 */ |
| 74 isValid: function() { | 89 isValid: function() { |
| 75 return !this.textfield_.value || isPositiveInteger(this.textfield_.value); | 90 return !this.textfield_.value || isPositiveInteger(this.textfield_.value); |
| 76 }, | 91 }, |
| 77 | 92 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 * @private | 166 * @private |
| 152 */ | 167 */ |
| 153 onPrinterCapabilitiesUpdated_: function(e) { | 168 onPrinterCapabilitiesUpdated_: function(e) { |
| 154 if (e.printerCapabilities.disableCopiesOption) { | 169 if (e.printerCapabilities.disableCopiesOption) { |
| 155 fadeOutElement(this.copiesOption_); | 170 fadeOutElement(this.copiesOption_); |
| 156 $('hr-before-copies').classList.remove('invisible'); | 171 $('hr-before-copies').classList.remove('invisible'); |
| 157 } else { | 172 } else { |
| 158 fadeInElement(this.copiesOption_); | 173 fadeInElement(this.copiesOption_); |
| 159 $('hr-before-copies').classList.add('invisible'); | 174 $('hr-before-copies').classList.add('invisible'); |
| 160 } | 175 } |
| 161 this.twoSidedCheckbox_.checked = e.printerCapabilities.setDuplexAsDefault; | 176 this.printerDefaultDuplexValue = |
| 177 e.printerCapabilities.printerDefaultDuplexValue; | |
| 178 if (this.printerDefaultDuplexValue != this.UNKNOWN) | |
| 179 this.twoSidedCheckbox_.checked = this.printerDefaultDuplexValue; | |
| 162 }, | 180 }, |
| 163 | 181 |
| 164 /** | 182 /** |
| 165 * Listener triggered when |incrementButton_| is clicked. | 183 * Listener triggered when |incrementButton_| is clicked. |
| 166 * @private | 184 * @private |
| 167 */ | 185 */ |
| 168 onIncrementButtonClicked_: function() { | 186 onIncrementButtonClicked_: function() { |
| 169 this.onButtonClicked_(1); | 187 this.onButtonClicked_(1); |
| 170 }, | 188 }, |
| 171 | 189 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 fadeOutElement(this.hint_); | 226 fadeOutElement(this.hint_); |
| 209 } | 227 } |
| 210 this.hint_.setAttribute('aria-hidden', this.isValid()); | 228 this.hint_.setAttribute('aria-hidden', this.isValid()); |
| 211 } | 229 } |
| 212 }; | 230 }; |
| 213 | 231 |
| 214 return { | 232 return { |
| 215 CopiesSettings: CopiesSettings, | 233 CopiesSettings: CopiesSettings, |
| 216 }; | 234 }; |
| 217 }); | 235 }); |
| OLD | NEW |