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