Chromium Code Reviews| 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 /** | |
| 98 * Called when this element gains or loses 'lead' status. Updates editing | 86 * Called when this element gains or loses 'lead' status. Updates editing |
| 99 * mode accordingly. | 87 * mode accordingly. |
| 100 * @private | 88 * @private |
| 101 */ | 89 */ |
| 102 handleLeadChange_: function() { | 90 handleLeadChange_: function() { |
| 103 this.updateEditState(); | 91 this.updateEditState(); |
| 104 }, | 92 }, |
| 105 | 93 |
| 106 /** | 94 /** |
| 107 * Updates the edit state based on the current selected and lead states. | 95 * Updates the edit state based on the current selected and lead states. |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 135 var focusElement = this.editClickTarget_ || this.initialFocusElement; | 123 var focusElement = this.editClickTarget_ || this.initialFocusElement; |
| 136 this.editClickTarget_ = null; | 124 this.editClickTarget_ = null; |
| 137 | 125 |
| 138 // When this is called in response to the selectedChange event, | 126 // When this is called in response to the selectedChange event, |
| 139 // the list grabs focus immediately afterwards. Thus we must delay | 127 // the list grabs focus immediately afterwards. Thus we must delay |
| 140 // our focus grab. | 128 // our focus grab. |
| 141 var self = this; | 129 var self = this; |
| 142 if (focusElement) { | 130 if (focusElement) { |
| 143 window.setTimeout(function() { | 131 window.setTimeout(function() { |
| 144 // Make sure we are still in edit mode by the time we execute. | 132 // Make sure we are still in edit mode by the time we execute. |
| 145 if (self.editing && self.focusPlaceholder) { | 133 if (self.editing) { |
|
James Hawkins
2011/09/19 23:00:07
You're right. I checked it out, and this check is
| |
| 146 focusElement.focus(); | 134 focusElement.focus(); |
| 147 focusElement.select(); | 135 focusElement.select(); |
| 148 } | 136 } |
| 149 }, 50); | 137 }, 50); |
| 150 } | 138 } |
| 151 } else { | 139 } else { |
| 152 if (!this.editCancelled_ && this.hasBeenEdited && | 140 if (!this.editCancelled_ && this.hasBeenEdited && |
| 153 this.currentInputIsValid) { | 141 this.currentInputIsValid) { |
| 154 if (this.isPlaceholder) | 142 if (this.isPlaceholder) |
| 155 this.parentNode.focusPlaceholder = true; | 143 this.parentNode.focusPlaceholder = true; |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 417 return true; | 405 return true; |
| 418 }, | 406 }, |
| 419 }; | 407 }; |
| 420 | 408 |
| 421 // Export | 409 // Export |
| 422 return { | 410 return { |
| 423 InlineEditableItem: InlineEditableItem, | 411 InlineEditableItem: InlineEditableItem, |
| 424 InlineEditableItemList: InlineEditableItemList, | 412 InlineEditableItemList: InlineEditableItemList, |
| 425 }; | 413 }; |
| 426 }); | 414 }); |
| OLD | NEW |