Chromium Code Reviews| Index: chrome/browser/resources/print_preview/copies_settings.js |
| diff --git a/chrome/browser/resources/print_preview/copies_settings.js b/chrome/browser/resources/print_preview/copies_settings.js |
| index 3c48e45e271cd50787056e8a05a498e00e9954e9..c3144fa3d1663936db40679884c62ab902465167 100644 |
| --- a/chrome/browser/resources/print_preview/copies_settings.js |
| +++ b/chrome/browser/resources/print_preview/copies_settings.js |
| @@ -22,6 +22,13 @@ cr.define('print_preview', function() { |
| this.collateCheckbox_ = $('collate'); |
| this.hint_ = $('copies-hint'); |
| this.twoSidedCheckbox_ = $('two-sided'); |
| + this.twoSidedOption_ = $('two-sided-div'); |
| + |
| + // Constant values matches printing::DuplexMode enum. Not using const |
| + // keyword because it is not allowed by JS strict mode. |
| + this.SIMPLEX = 0; |
| + this.LONG_EDGE = 1; |
| + this.UNKNOWN_DUPLEX_MODE = -1; |
| } |
| cr.addSingletonGetter(CopiesSettings); |
| @@ -56,15 +63,16 @@ cr.define('print_preview', function() { |
| }, |
| /** |
| - * Gets the duplex mode for printing. |
| + * Gets the duplex mode information for printing. |
| * @return {number} duplex mode. |
| */ |
| - get duplexMode() { |
| - // Constant values matches printing::DuplexMode enum. Not using const |
| - // keyword because it is not allowed by JS strict mode. |
| - var SIMPLEX = 0; |
| - var LONG_EDGE = 1; |
| - return !this.twoSidedCheckbox_.checked ? SIMPLEX : LONG_EDGE; |
| + get duplexMode() { |
| + if (this.twoSidedOption_.hidden) |
| + return this.UNKNOWN_DUPLEX_MODE; |
| + else if (this.twoSidedCheckbox_.checked) |
| + return this.LONG_EDGE; |
| + else |
| + return this.SIMPLEX; |
|
dpapad
2011/09/08 15:52:06
Nit: you could compress this if statement to
if (t
kmadhusu
2011/09/08 17:13:10
I prefer if..elseif.. structure here.
|
| }, |
| /** |
| @@ -158,7 +166,8 @@ cr.define('print_preview', function() { |
| fadeInElement(this.copiesOption_); |
| $('hr-before-copies').classList.add('invisible'); |
| } |
| - this.twoSidedCheckbox_.checked = e.printerCapabilities.setDuplexAsDefault; |
| + this.updateTwoSidedOption_( |
| + e.printerCapabilities.printerDefaultDuplexValue); |
| }, |
| /** |
| @@ -190,6 +199,25 @@ cr.define('print_preview', function() { |
| this.collateOption_.hidden); |
| }, |
| + /* |
| + * Takes care of showing/hiding the two sided option and also updates the |
| + * default state of the checkbox. |
| + * @param {boolean} defaultDuplexValue Specifies the default duplex value. |
| + * @private |
| + */ |
| + updateTwoSidedOption_: function(defaultDuplexValue) { |
| + // On Windows, some printers don't specify their duplex values in the |
| + // printer schema. If the printer duplex value is UNKNOWN_DUPLEX_MODE, |
| + // hide the two sided option in preview tab UI. |
| + // Ref bug: http://crbug.com/89204 |
| + this.twoSidedOption_.hidden = |
| + (defaultDuplexValue == this.UNKNOWN_DUPLEX_MODE); |
|
dpapad
2011/09/08 15:52:06
Is |defaultDuplexValue| a boolean? It is compared
kmadhusu
2011/09/08 17:13:10
It is not a boolean. Updated the @param comment.
|
| + this.twoSidedOption_.setAttribute('aria-hidden', |
| + this.twoSidedOption_.hidden); |
| + if (!this.twoSidedOption_.hidden) |
| + this.twoSidedCheckbox_.checked = defaultDuplexValue; |
|
dpapad
2011/09/08 15:52:06
Same here, if |defaultDuplexValue| is not a boolea
kmadhusu
2011/09/08 17:13:10
Done.
|
| + }, |
| + |
| /** |
| * Updates the state of the increment/decrement buttons based on the current |
| * |textfield_| value. |