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('options', function() { | 5 cr.define('options', function() { |
6 const DeletableItem = options.DeletableItem; | 6 const DeletableItem = options.DeletableItem; |
7 const DeletableItemList = options.DeletableItemList; | 7 const DeletableItemList = options.DeletableItemList; |
8 | 8 |
9 /** | 9 /** |
10 * Creates a new list item with support for inline editing. | 10 * Creates a new list item with support for inline editing. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 this.addEventListener('keydown', this.handleKeyDown_); | 76 this.addEventListener('keydown', this.handleKeyDown_); |
77 this.addEventListener('leadChange', this.handleLeadChange_); | 77 this.addEventListener('leadChange', this.handleLeadChange_); |
78 }, | 78 }, |
79 | 79 |
80 /** @inheritDoc */ | 80 /** @inheritDoc */ |
81 selectionChanged: function() { | 81 selectionChanged: function() { |
82 this.updateEditState(); | 82 this.updateEditState(); |
83 }, | 83 }, |
84 | 84 |
85 /** | 85 /** |
| 86 * Called when the input element receives focus. Selects this item in the |
| 87 * list selection model. |
| 88 * @private |
| 89 */ |
| 90 handleFocus_: function() { |
| 91 var list = this.parentNode; |
| 92 var index = list.getIndexOfListItem(this); |
| 93 list.selectionModel.selectedIndex = index; |
| 94 list.selectionModel.anchorIndex = index; |
| 95 }, |
| 96 |
| 97 /** |
86 * Called when this element gains or loses 'lead' status. Updates editing | 98 * Called when this element gains or loses 'lead' status. Updates editing |
87 * mode accordingly. | 99 * mode accordingly. |
88 * @private | 100 * @private |
89 */ | 101 */ |
90 handleLeadChange_: function() { | 102 handleLeadChange_: function() { |
91 this.updateEditState(); | 103 this.updateEditState(); |
92 }, | 104 }, |
93 | 105 |
94 /** | 106 /** |
95 * Updates the edit state based on the current selected and lead states. | 107 * Updates the edit state based on the current selected and lead states. |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 container.appendChild(textEl); | 236 container.appendChild(textEl); |
225 } | 237 } |
226 | 238 |
227 var inputEl = this.ownerDocument.createElement('input'); | 239 var inputEl = this.ownerDocument.createElement('input'); |
228 inputEl.type = 'text'; | 240 inputEl.type = 'text'; |
229 inputEl.value = text; | 241 inputEl.value = text; |
230 if (!this.isPlaceholder) { | 242 if (!this.isPlaceholder) { |
231 inputEl.setAttribute('displaymode', 'edit'); | 243 inputEl.setAttribute('displaymode', 'edit'); |
232 inputEl.staticVersion = textEl; | 244 inputEl.staticVersion = textEl; |
233 } | 245 } |
| 246 inputEl.addEventListener('focus', this.handleFocus_.bind(this)); |
234 container.appendChild(inputEl); | 247 container.appendChild(inputEl); |
235 this.editFields_.push(inputEl); | 248 this.editFields_.push(inputEl); |
236 | 249 |
237 return container; | 250 return container; |
238 }, | 251 }, |
239 | 252 |
240 /** | 253 /** |
241 * Resets the editable version of any controls created by createEditable* | 254 * Resets the editable version of any controls created by createEditable* |
242 * to match the static text. | 255 * to match the static text. |
243 * @private | 256 * @private |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 } | 385 } |
373 }, | 386 }, |
374 }; | 387 }; |
375 | 388 |
376 // Export | 389 // Export |
377 return { | 390 return { |
378 InlineEditableItem: InlineEditableItem, | 391 InlineEditableItem: InlineEditableItem, |
379 InlineEditableItemList: InlineEditableItemList, | 392 InlineEditableItemList: InlineEditableItemList, |
380 }; | 393 }; |
381 }); | 394 }); |
OLD | NEW |