| 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 'strict'; | 6 'strict'; |
| 7 | 7 |
| 8 function MarginTextbox(groupName) { | 8 function MarginTextbox(groupName) { |
| 9 var box = document.createElement('input'); | 9 var box = document.createElement('input'); |
| 10 box.__proto__ = MarginTextbox.prototype; | 10 box.__proto__ = MarginTextbox.prototype; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 */ | 141 */ |
| 142 onBlur_: function() { | 142 onBlur_: function() { |
| 143 clearTimeout(this.timerId_); | 143 clearTimeout(this.timerId_); |
| 144 this.validate(); | 144 this.validate(); |
| 145 if (!this.isValid) { | 145 if (!this.isValid) { |
| 146 this.setValue_(this.lastValidValueInPoints); | 146 this.setValue_(this.lastValidValueInPoints); |
| 147 this.validate(); | 147 this.validate(); |
| 148 } | 148 } |
| 149 | 149 |
| 150 this.updateColor(); | 150 this.updateColor(); |
| 151 cr.dispatchSimpleEvent(document, 'updateSummary'); | 151 cr.dispatchSimpleEvent(document, customEvents.UPDATE_SUMMARY); |
| 152 cr.dispatchSimpleEvent(document, 'updatePrintButton'); | 152 cr.dispatchSimpleEvent(document, customEvents.UPDATE_PRINT_BUTTON); |
| 153 cr.dispatchSimpleEvent(this, 'MarginsMayHaveChanged'); | 153 cr.dispatchSimpleEvent(this, customEvents.MARGINS_MAY_HAVE_CHANGED); |
| 154 }, | 154 }, |
| 155 | 155 |
| 156 /** | 156 /** |
| 157 * Executes whenever a keypressed event occurs. Note: Only the "Enter" key | 157 * Executes whenever a keypressed event occurs. Note: Only the "Enter" key |
| 158 * event is handled. The "Escape" key does not result in such event, | 158 * event is handled. The "Escape" key does not result in such event, |
| 159 * therefore it is handled by |this.onKeyUp_|. | 159 * therefore it is handled by |this.onKeyUp_|. |
| 160 * @param {KeyboardEvent} e The event that triggered this listener. | 160 * @param {KeyboardEvent} e The event that triggered this listener. |
| 161 * @private | 161 * @private |
| 162 */ | 162 */ |
| 163 onKeyPressed_: function(e) { | 163 onKeyPressed_: function(e) { |
| 164 if (e.keyCode == MarginTextbox.ENTER_KEYCODE) | 164 if (e.keyCode == MarginTextbox.ENTER_KEYCODE) |
| 165 this.blur(); | 165 this.blur(); |
| 166 }, | 166 }, |
| 167 | 167 |
| 168 /** | 168 /** |
| 169 * Executes whenever a keyup event occurs. Note: Only the "Escape" | 169 * Executes whenever a keyup event occurs. Note: Only the "Escape" |
| 170 * key event is handled. | 170 * key event is handled. |
| 171 * @param {KeyboardEvent} e The event that triggered this listener. | 171 * @param {KeyboardEvent} e The event that triggered this listener. |
| 172 * @private | 172 * @private |
| 173 */ | 173 */ |
| 174 onKeyUp_: function(e) { | 174 onKeyUp_: function(e) { |
| 175 if (e.keyCode == MarginTextbox.ESCAPE_KEYCODE) { | 175 if (e.keyCode == MarginTextbox.ESCAPE_KEYCODE) { |
| 176 this.setValue_(this.lastValidValueInPoints); | 176 this.setValue_(this.lastValidValueInPoints); |
| 177 this.validate(); | 177 this.validate(); |
| 178 this.updateColor(); | 178 this.updateColor(); |
| 179 cr.dispatchSimpleEvent(document, 'updateSummary'); | 179 cr.dispatchSimpleEvent(document, customEvents.UPDATE_SUMMARY); |
| 180 cr.dispatchSimpleEvent(document, 'updatePrintButton'); | 180 cr.dispatchSimpleEvent(document, customEvents.UPDATE_PRINT_BUTTON); |
| 181 } | 181 } |
| 182 }, | 182 }, |
| 183 | 183 |
| 184 /** | 184 /** |
| 185 * Resetting the timer used to detect when the user stops typing in order | 185 * Resetting the timer used to detect when the user stops typing in order |
| 186 * to update the print preview. | 186 * to update the print preview. |
| 187 * @private | 187 * @private |
| 188 */ | 188 */ |
| 189 resetTimer_: function() { | 189 resetTimer_: function() { |
| 190 clearTimeout(this.timerId_); | 190 clearTimeout(this.timerId_); |
| 191 this.timerId_ = window.setTimeout( | 191 this.timerId_ = window.setTimeout( |
| 192 this.onTextValueMayHaveChanged.bind(this), 1000); | 192 this.onTextValueMayHaveChanged.bind(this), 1000); |
| 193 }, | 193 }, |
| 194 | 194 |
| 195 /** | 195 /** |
| 196 * Executes whenever the user stops typing or when a drag session associated | 196 * Executes whenever the user stops typing or when a drag session associated |
| 197 * with |this| ends. | 197 * with |this| ends. |
| 198 */ | 198 */ |
| 199 onTextValueMayHaveChanged: function() { | 199 onTextValueMayHaveChanged: function() { |
| 200 this.validate(); | 200 this.validate(); |
| 201 this.updateColor(); | 201 this.updateColor(); |
| 202 cr.dispatchSimpleEvent(document, 'updateSummary'); | 202 cr.dispatchSimpleEvent(document, customEvents.UPDATE_SUMMARY); |
| 203 cr.dispatchSimpleEvent(document, 'updatePrintButton'); | 203 cr.dispatchSimpleEvent(document, customEvents.UPDATE_PRINT_BUTTON); |
| 204 | 204 |
| 205 if (!this.isValid) | 205 if (!this.isValid) |
| 206 return; | 206 return; |
| 207 cr.dispatchSimpleEvent(this, 'MarginsMayHaveChanged'); | 207 cr.dispatchSimpleEvent(this, customEvents.MARGINS_MAY_HAVE_CHANGED); |
| 208 } | 208 } |
| 209 | 209 |
| 210 }; | 210 }; |
| 211 | 211 |
| 212 return { | 212 return { |
| 213 MarginTextbox: MarginTextbox | 213 MarginTextbox: MarginTextbox |
| 214 }; | 214 }; |
| 215 }); | 215 }); |
| OLD | NEW |