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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 */ | 119 */ |
120 set suggestions(suggestions) { | 120 set suggestions(suggestions) { |
121 this.dataModel = new ArrayDataModel(suggestions); | 121 this.dataModel = new ArrayDataModel(suggestions); |
122 this.hidden = !this.targetInput_ || suggestions.length == 0; | 122 this.hidden = !this.targetInput_ || suggestions.length == 0; |
123 }, | 123 }, |
124 | 124 |
125 /** | 125 /** |
126 * Requests new suggestions. Called when new suggestions are needed. | 126 * Requests new suggestions. Called when new suggestions are needed. |
127 * @param {string} query the text to autocomplete from. | 127 * @param {string} query the text to autocomplete from. |
128 */ | 128 */ |
129 requestSuggestions: function(query) { | 129 requestSuggestions: function(query) {}, |
130 }, | |
131 | 130 |
132 /** | 131 /** |
133 * Handles the Enter keydown event. | 132 * Handles the Enter keydown event. |
134 * By default, clears and hides the autocomplete popup. Note that the | 133 * By default, clears and hides the autocomplete popup. Note that the |
135 * keydown event bubbles up, so the input field can handle the event. | 134 * keydown event bubbles up, so the input field can handle the event. |
136 */ | 135 */ |
137 handleEnterKeydown: function() { | 136 handleEnterKeydown: function() { this.suggestions = []; }, |
138 this.suggestions = []; | |
139 }, | |
140 | 137 |
141 /** | 138 /** |
142 * Handles the selected suggestion. Called when a suggestion is selected. | 139 * Handles the selected suggestion. Called when a suggestion is selected. |
143 * By default, sets the target input element's value to the 'url' field | 140 * By default, sets the target input element's value to the 'url' field |
144 * of the selected suggestion. | 141 * of the selected suggestion. |
145 * @param {Object} selectedSuggestion | 142 * @param {Object} selectedSuggestion |
146 */ | 143 */ |
147 handleSelectedSuggestion: function(selectedSuggestion) { | 144 handleSelectedSuggestion: function(selectedSuggestion) { |
148 var input = this.targetInput_; | 145 var input = this.targetInput_; |
149 if (!input) | 146 if (!input) |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 * syncWidthAndPositionToInput function bound to |this|. | 215 * syncWidthAndPositionToInput function bound to |this|. |
219 * @type {!Function|undefined} | 216 * @type {!Function|undefined} |
220 * @private | 217 * @private |
221 */ | 218 */ |
222 boundSyncWidthAndPositionToInput_: undefined, | 219 boundSyncWidthAndPositionToInput_: undefined, |
223 | 220 |
224 /** | 221 /** |
225 * @return {HTMLElement} The text field the autocomplete popup is currently | 222 * @return {HTMLElement} The text field the autocomplete popup is currently |
226 * attached to, if any. | 223 * attached to, if any. |
227 */ | 224 */ |
228 get targetInput() { | 225 get targetInput() { return this.targetInput_; }, |
229 return this.targetInput_; | |
230 }, | |
231 | 226 |
232 /** | 227 /** |
233 * Handles input field key events that should be interpreted as autocomplete | 228 * Handles input field key events that should be interpreted as autocomplete |
234 * commands. | 229 * commands. |
235 * @param {Event} event The keydown event. | 230 * @param {Event} event The keydown event. |
236 * @private | 231 * @private |
237 */ | 232 */ |
238 handleAutocompleteKeydown_: function(event) { | 233 handleAutocompleteKeydown_: function(event) { |
239 if (this.hidden) | 234 if (this.hidden) |
240 return; | 235 return; |
(...skipping 17 matching lines...) Expand all Loading... |
258 } | 253 } |
259 // Don't let arrow keys affect the text field, or bubble up to, e.g., | 254 // Don't let arrow keys affect the text field, or bubble up to, e.g., |
260 // an enclosing list item. | 255 // an enclosing list item. |
261 if (handled) { | 256 if (handled) { |
262 event.preventDefault(); | 257 event.preventDefault(); |
263 event.stopPropagation(); | 258 event.stopPropagation(); |
264 } | 259 } |
265 }, | 260 }, |
266 }; | 261 }; |
267 | 262 |
268 return { | 263 return {AutocompleteList: AutocompleteList}; |
269 AutocompleteList: AutocompleteList | |
270 }; | |
271 }); | 264 }); |
OLD | NEW |