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.textfield_ = $('copies'); | 14 this.textfield_ = $('copies'); |
| 14 this.incrementButton_ = $('increment'); | 15 this.incrementButton_ = $('increment'); |
| 15 this.decrementButton_ = $('decrement'); | 16 this.decrementButton_ = $('decrement'); |
| 16 // Minimum allowed value for number of copies. | 17 // Minimum allowed value for number of copies. |
| 17 this.minValue_ = 1; | 18 this.minValue_ = 1; |
| 18 // Maximum allowed value for number of copies. | 19 // Maximum allowed value for number of copies. |
| 19 this.maxValue_ = 999; | 20 this.maxValue_ = 999; |
| 20 this.collateOption_ = $('collate-option'); | 21 this.collateOption_ = $('collate-option'); |
| 22 this.collateCheckbox_ = $('collate'); | |
| 21 this.hint_ = $('copies-hint'); | 23 this.hint_ = $('copies-hint'); |
| 22 this.twoSidedCheckbox_ = $('two-sided'); | 24 this.twoSidedCheckbox_ = $('two-sided'); |
| 23 } | 25 } |
| 24 | 26 |
| 25 cr.addSingletonGetter(CopiesSettings); | 27 cr.addSingletonGetter(CopiesSettings); |
| 26 | 28 |
| 27 CopiesSettings.prototype = { | 29 CopiesSettings.prototype = { |
| 28 /** | 30 /** |
| 29 * The number of copies represented by the contents of |this.textfield_|. | 31 * The number of copies represented by the contents of |this.textfield_|. |
| 30 * If the text is not valid returns |this.minValue_|. | 32 * If the text is not valid returns |this.minValue_|. |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 47 | 49 |
| 48 /** | 50 /** |
| 49 * Getter method for |twoSidedCheckbox_|. | 51 * Getter method for |twoSidedCheckbox_|. |
| 50 * @type {HTMLInputElement} | 52 * @type {HTMLInputElement} |
| 51 */ | 53 */ |
| 52 get twoSidedCheckbox() { | 54 get twoSidedCheckbox() { |
| 53 return this.twoSidedCheckbox_; | 55 return this.twoSidedCheckbox_; |
| 54 }, | 56 }, |
| 55 | 57 |
| 56 /** | 58 /** |
| 59 * Gets the duplex mode for printing. | |
| 60 * @return {number} duplex mode. | |
| 61 */ | |
| 62 get duplexMode() { | |
| 63 // Constant values matches printing::DuplexMode enum. Not using const | |
| 64 // keyword because it is not allowed by JS strict mode. | |
| 65 var SIMPLEX = 0; | |
| 66 var LONG_EDGE = 1; | |
| 67 return !this.twoSidedCheckbox_.checked ? SIMPLEX : LONG_EDGE; | |
| 68 }, | |
| 69 | |
| 70 /** | |
| 57 * @return {boolean} true if |this.textfield_| is empty, or represents a | 71 * @return {boolean} true if |this.textfield_| is empty, or represents a |
| 58 * positive integer value. | 72 * positive integer value. |
| 59 */ | 73 */ |
| 60 isValid: function() { | 74 isValid: function() { |
| 61 return !this.textfield_.value || isPositiveInteger(this.textfield_.value); | 75 return !this.textfield_.value || isPositiveInteger(this.textfield_.value); |
| 62 }, | 76 }, |
| 63 | 77 |
| 64 /** | 78 /** |
| 79 * Checks whether the preview collate setting value is set or not. | |
| 80 * | |
|
Evan Stade
2011/07/15 19:47:21
remove blank line
| |
| 81 * @return {boolean} true if collate option is enabled and checked. | |
| 82 */ | |
| 83 isCollated: function() { | |
| 84 return !this.collateOption_.hidden && this.collateCheckbox_.checked; | |
| 85 }, | |
| 86 | |
| 87 /** | |
| 65 * Resets |this.textfield_| to |this.minValue_|. | 88 * Resets |this.textfield_| to |this.minValue_|. |
| 66 * @private | 89 * @private |
| 67 */ | 90 */ |
| 68 reset_: function() { | 91 reset_: function() { |
| 69 this.textfield_.value = this.minValue_; | 92 this.textfield_.value = this.minValue_; |
| 70 }, | 93 }, |
| 71 | 94 |
| 72 /** | 95 /** |
| 73 * Listener function to execute whenever the increment/decrement buttons are | 96 * Listener function to execute whenever the increment/decrement buttons are |
| 74 * clicked. | 97 * clicked. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 addEventListeners: function() { | 136 addEventListeners: function() { |
| 114 this.textfield_.oninput = this.onTextfieldChanged_.bind(this); | 137 this.textfield_.oninput = this.onTextfieldChanged_.bind(this); |
| 115 this.incrementButton_.onclick = this.onIncrementButtonClicked_.bind(this); | 138 this.incrementButton_.onclick = this.onIncrementButtonClicked_.bind(this); |
| 116 this.decrementButton_.onclick = this.onDecrementButtonClicked_.bind(this); | 139 this.decrementButton_.onclick = this.onDecrementButtonClicked_.bind(this); |
| 117 this.twoSidedCheckbox_.onclick = function() { | 140 this.twoSidedCheckbox_.onclick = function() { |
| 118 if (!hasPendingPreviewRequest) | 141 if (!hasPendingPreviewRequest) |
| 119 updatePrintSummary(); | 142 updatePrintSummary(); |
| 120 } | 143 } |
| 121 document.addEventListener('PDFLoaded', | 144 document.addEventListener('PDFLoaded', |
| 122 this.updateButtonsState_.bind(this)); | 145 this.updateButtonsState_.bind(this)); |
| 146 document.addEventListener('printerCapabilitiesUpdated', | |
| 147 this.onPrinterCapabilitiesUpdated_.bind(this)); | |
| 123 }, | 148 }, |
| 124 | 149 |
| 125 /** | 150 /** |
| 151 * Listener triggered when a printerCapabilitiesUpdated event occurs. | |
| 152 * @private | |
| 153 */ | |
| 154 onPrinterCapabilitiesUpdated_: function(e) { | |
| 155 if (e.printerCapabilities.disableCopiesOption) { | |
| 156 fadeOutElement(this.copiesOption_); | |
| 157 $('hr-before-copies').classList.remove('invisible'); | |
| 158 } else { | |
| 159 fadeInElement(this.copiesOption_); | |
| 160 $('hr-before-copies').classList.add('invisible'); | |
| 161 } | |
| 162 this.twoSidedCheckbox_.checked = e.printerCapabilities.setDuplexAsDefault; | |
| 163 }, | |
| 164 | |
| 165 /** | |
| 126 * Listener triggered when |incrementButton_| is clicked. | 166 * Listener triggered when |incrementButton_| is clicked. |
| 127 * @private | 167 * @private |
| 128 */ | 168 */ |
| 129 onIncrementButtonClicked_: function() { | 169 onIncrementButtonClicked_: function() { |
| 130 this.onButtonClicked_(1); | 170 this.onButtonClicked_(1); |
| 131 }, | 171 }, |
| 132 | 172 |
| 133 /** | 173 /** |
| 134 * Listener triggered when |decrementButton_| is clicked. | 174 * Listener triggered when |decrementButton_| is clicked. |
| 135 * @private | 175 * @private |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 163 this.decrementButton_.disabled = this.numberOfCopies == this.minValue_; | 203 this.decrementButton_.disabled = this.numberOfCopies == this.minValue_; |
| 164 fadeOutElement(this.hint_); | 204 fadeOutElement(this.hint_); |
| 165 } | 205 } |
| 166 } | 206 } |
| 167 }; | 207 }; |
| 168 | 208 |
| 169 return { | 209 return { |
| 170 CopiesSettings: CopiesSettings, | 210 CopiesSettings: CopiesSettings, |
| 171 }; | 211 }; |
| 172 }); | 212 }); |
| OLD | NEW |