| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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('cr.ui', function() { | 5 cr.define('cr.ui', function() { |
| 6 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; | 6 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; |
| 7 /** @const */ var List = cr.ui.List; | 7 /** @const */ var List = cr.ui.List; |
| 8 /** @const */ var ListItem = cr.ui.ListItem; | 8 /** @const */ var ListItem = cr.ui.ListItem; |
| 9 | 9 |
| 10 /** | 10 /** |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 /** | 232 /** |
| 233 * Handles input field key events that should be interpreted as autocomplete | 233 * Handles input field key events that should be interpreted as autocomplete |
| 234 * commands. | 234 * commands. |
| 235 * @param {Event} event The keydown event. | 235 * @param {Event} event The keydown event. |
| 236 * @private | 236 * @private |
| 237 */ | 237 */ |
| 238 handleAutocompleteKeydown_: function(event) { | 238 handleAutocompleteKeydown_: function(event) { |
| 239 if (this.hidden) | 239 if (this.hidden) |
| 240 return; | 240 return; |
| 241 var handled = false; | 241 var handled = false; |
| 242 switch (event.keyIdentifier) { | 242 switch (event.key) { |
| 243 case 'U+001B': // Esc | 243 case 'Escape': |
| 244 this.suggestions = []; | 244 this.suggestions = []; |
| 245 handled = true; | 245 handled = true; |
| 246 break; | 246 break; |
| 247 case 'Enter': | 247 case 'Enter': |
| 248 // If the user has already selected an item using the arrow keys then | 248 // If the user has already selected an item using the arrow keys then |
| 249 // presses Enter, keep |handled| = false, so the input field can | 249 // presses Enter, keep |handled| = false, so the input field can |
| 250 // handle the event as well. | 250 // handle the event as well. |
| 251 this.handleEnterKeydown(); | 251 this.handleEnterKeydown(); |
| 252 break; | 252 break; |
| 253 case 'Up': | 253 case 'ArrowUp': |
| 254 case 'Down': | 254 case 'ArrowDown': |
| 255 var newEvent = new Event(event.type); | 255 this.dispatchEvent(new KeyboardEvent(event.type, event)); |
| 256 newEvent.keyIdentifier = event.keyIdentifier; | |
| 257 this.dispatchEvent(newEvent); | |
| 258 handled = true; | 256 handled = true; |
| 259 break; | 257 break; |
| 260 } | 258 } |
| 261 // Don't let arrow keys affect the text field, or bubble up to, e.g., | 259 // Don't let arrow keys affect the text field, or bubble up to, e.g., |
| 262 // an enclosing list item. | 260 // an enclosing list item. |
| 263 if (handled) { | 261 if (handled) { |
| 264 event.preventDefault(); | 262 event.preventDefault(); |
| 265 event.stopPropagation(); | 263 event.stopPropagation(); |
| 266 } | 264 } |
| 267 }, | 265 }, |
| 268 }; | 266 }; |
| 269 | 267 |
| 270 return { | 268 return { |
| 271 AutocompleteList: AutocompleteList | 269 AutocompleteList: AutocompleteList |
| 272 }; | 270 }; |
| 273 }); | 271 }); |
| OLD | NEW |