| OLD | NEW |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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 * Component that renders the scaling settings UI. | 9 * Component that renders the scaling settings UI. |
| 10 * @param {!print_preview.ticket_items.scalingTicketItem} scalingTicketItem | 10 * @param {!print_preview.ticket_items.scalingTicketItem} scalingTicketItem |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 * Whether this component is enabled or not. | 45 * Whether this component is enabled or not. |
| 46 * @private {boolean} | 46 * @private {boolean} |
| 47 */ | 47 */ |
| 48 this.isEnabled_ = true; | 48 this.isEnabled_ = true; |
| 49 | 49 |
| 50 /** | 50 /** |
| 51 * The textfield input element | 51 * The textfield input element |
| 52 * @private {HTMLElement} | 52 * @private {HTMLElement} |
| 53 */ | 53 */ |
| 54 this.inputField_ = null; | 54 this.inputField_ = null; |
| 55 | |
| 56 }; | 55 }; |
| 57 | 56 |
| 58 /** | 57 /** |
| 59 * Delay in milliseconds before processing the textfield. | 58 * Delay in milliseconds before processing the textfield. |
| 60 * @private {number} | 59 * @private {number} |
| 61 * @const | 60 * @const |
| 62 */ | 61 */ |
| 63 ScalingSettings.TEXTFIELD_DELAY_MS_ = 250; | 62 ScalingSettings.TEXTFIELD_DELAY_MS_ = 250; |
| 64 | 63 |
| 65 ScalingSettings.prototype = { | 64 ScalingSettings.prototype = { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 81 this.isEnabled_ = isEnabled; | 80 this.isEnabled_ = isEnabled; |
| 82 if (isEnabled) | 81 if (isEnabled) |
| 83 this.updateState_(); | 82 this.updateState_(); |
| 84 }, | 83 }, |
| 85 | 84 |
| 86 /** @override */ | 85 /** @override */ |
| 87 enterDocument: function() { | 86 enterDocument: function() { |
| 88 this.inputField_ = this.getChildElement('input.user-value'); | 87 this.inputField_ = this.getChildElement('input.user-value'); |
| 89 print_preview.SettingsSection.prototype.enterDocument.call(this); | 88 print_preview.SettingsSection.prototype.enterDocument.call(this); |
| 90 this.tracker.add( | 89 this.tracker.add( |
| 91 this.inputField_, | 90 this.inputField_, 'keydown', this.onTextfieldKeyDown_.bind(this)); |
| 92 'keydown', | |
| 93 this.onTextfieldKeyDown_.bind(this)); | |
| 94 this.tracker.add( | 91 this.tracker.add( |
| 95 this.inputField_, | 92 this.inputField_, 'input', this.onTextfieldInput_.bind(this)); |
| 96 'input', | |
| 97 this.onTextfieldInput_.bind(this)); | |
| 98 this.tracker.add( | 93 this.tracker.add( |
| 99 this.inputField_, | 94 this.inputField_, 'blur', this.onTextfieldBlur_.bind(this)); |
| 100 'blur', | |
| 101 this.onTextfieldBlur_.bind(this)); | |
| 102 this.tracker.add( | 95 this.tracker.add( |
| 103 this.scalingTicketItem_, | 96 this.scalingTicketItem_, |
| 104 print_preview.ticket_items.TicketItem.EventType.CHANGE, | 97 print_preview.ticket_items.TicketItem.EventType.CHANGE, |
| 105 this.updateState_.bind(this)); | 98 this.updateState_.bind(this)); |
| 106 this.tracker.add( | 99 this.tracker.add( |
| 107 this.fitToPageTicketItem_, | 100 this.fitToPageTicketItem_, |
| 108 print_preview.ticket_items.TicketItem.EventType.CHANGE, | 101 print_preview.ticket_items.TicketItem.EventType.CHANGE, |
| 109 this.onFitToPageChange_.bind(this)); | 102 this.onFitToPageChange_.bind(this)); |
| 110 }, | 103 }, |
| 111 | 104 |
| 112 /** | 105 /** |
| 113 * @return {boolean} true if fit to page is available and selected. | 106 * @return {boolean} true if fit to page is available and selected. |
| 114 * @private | 107 * @private |
| 115 */ | 108 */ |
| 116 isFitToPageSelected: function() { | 109 isFitToPageSelected: function() { |
| 117 return this.fitToPageTicketItem_.isCapabilityAvailable() && | 110 return this.fitToPageTicketItem_.isCapabilityAvailable() && |
| 118 this.fitToPageTicketItem_.getValue(); | 111 this.fitToPageTicketItem_.getValue(); |
| 119 }, | 112 }, |
| 120 | 113 |
| 121 /** | 114 /** |
| 122 * @return {number} The current input field value as an integer. | 115 * @return {number} The current input field value as an integer. |
| 123 * @private | 116 * @private |
| 124 */ | 117 */ |
| 125 getInputAsNumber: function() { | 118 getInputAsNumber: function() { |
| 126 return (/[^\d]+/.test(this.inputField_.value)) ? | 119 return (/[^\d]+/.test(this.inputField_.value)) ? |
| 127 0 : // Return an invalid scaling so that the hint will display. | 120 0 : // Return an invalid scaling so that the hint will display. |
| 128 parseInt(this.inputField_.value, 10); | 121 parseInt(this.inputField_.value, 10); |
| 129 }, | 122 }, |
| 130 | 123 |
| 131 /** | 124 /** |
| 132 * Display the fit to page scaling in the scaling field if there is a valid | 125 * Display the fit to page scaling in the scaling field if there is a valid |
| 133 * fit to page scaling value. If not, make the field blank. | 126 * fit to page scaling value. If not, make the field blank. |
| 134 * @private | 127 * @private |
| 135 */ | 128 */ |
| 136 displayFitToPageScaling: function() { | 129 displayFitToPageScaling: function() { |
| 137 this.inputField_.value = this.fitToPageScaling_ || ''; | 130 this.inputField_.value = this.fitToPageScaling_ || ''; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 (this.isFitToPageSelected() && | 169 (this.isFitToPageSelected() && |
| 177 (displayedValue == this.fitToPageScaling_ || | 170 (displayedValue == this.fitToPageScaling_ || |
| 178 (!this.fitToPageScaling_ && inputString == '')))) { | 171 (!this.fitToPageScaling_ && inputString == '')))) { |
| 179 this.inputField_.classList.remove('invalid'); | 172 this.inputField_.classList.remove('invalid'); |
| 180 fadeOutElement(this.getChildElement('.hint')); | 173 fadeOutElement(this.getChildElement('.hint')); |
| 181 } else { | 174 } else { |
| 182 // Invalid value. Display the hint. | 175 // Invalid value. Display the hint. |
| 183 this.inputField_.classList.add('invalid'); | 176 this.inputField_.classList.add('invalid'); |
| 184 fadeInElement(this.getChildElement('.hint')); | 177 fadeInElement(this.getChildElement('.hint')); |
| 185 } | 178 } |
| 186 | |
| 187 } | 179 } |
| 188 this.updateUiStateInternal(); | 180 this.updateUiStateInternal(); |
| 189 }, | 181 }, |
| 190 | 182 |
| 191 /** | 183 /** |
| 192 * Helper function to adjust the scaling display if fit to page is checked | 184 * Helper function to adjust the scaling display if fit to page is checked |
| 193 * by the user. | 185 * by the user. |
| 194 * @private | 186 * @private |
| 195 */ | 187 */ |
| 196 onFitToPageChange_: function() { | 188 onFitToPageChange_: function() { |
| 197 if (this.isFitToPageSelected()) { | 189 if (this.isFitToPageSelected()) { |
| 198 // Fit to page was checked. Set scaling to the fit to page scaling. | 190 // Fit to page was checked. Set scaling to the fit to page scaling. |
| 199 this.displayFitToPageScaling(); | 191 this.displayFitToPageScaling(); |
| 200 } else if (this.fitToPageTicketItem_.isCapabilityAvailable() && | 192 } else if ( |
| 201 (this.getInputAsNumber() == this.fitToPageScaling_ || | 193 this.fitToPageTicketItem_.isCapabilityAvailable() && |
| 202 this.inputField_.value == '')) { | 194 (this.getInputAsNumber() == this.fitToPageScaling_ || |
| 195 this.inputField_.value == '')) { |
| 203 // Fit to page unchecked. Return to last scaling. | 196 // Fit to page unchecked. Return to last scaling. |
| 204 this.inputField_.value = this.scalingTicketItem_.getValue(); | 197 this.inputField_.value = this.scalingTicketItem_.getValue(); |
| 205 } | 198 } |
| 206 }, | 199 }, |
| 207 | 200 |
| 208 /** | 201 /** |
| 209 * Called after a timeout after user input into the textfield. | 202 * Called after a timeout after user input into the textfield. |
| 210 * @private | 203 * @private |
| 211 */ | 204 */ |
| 212 onTextfieldTimeout_: function() { | 205 onTextfieldTimeout_: function() { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 this.inputField_.value = '100'; | 269 this.inputField_.value = '100'; |
| 277 else | 270 else |
| 278 this.scalingTicketItem_.updateValue('100'); | 271 this.scalingTicketItem_.updateValue('100'); |
| 279 } | 272 } |
| 280 } | 273 } |
| 281 }, | 274 }, |
| 282 | 275 |
| 283 }; | 276 }; |
| 284 | 277 |
| 285 // Export | 278 // Export |
| 286 return { | 279 return {ScalingSettings: ScalingSettings}; |
| 287 ScalingSettings: ScalingSettings | |
| 288 }; | |
| 289 }); | 280 }); |
| OLD | NEW |