| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 var focusElement = this.editClickTarget_ || this.initialFocusElement; | 135 var focusElement = this.editClickTarget_ || this.initialFocusElement; |
| 136 this.editClickTarget_ = null; | 136 this.editClickTarget_ = null; |
| 137 | 137 |
| 138 // When this is called in response to the selectedChange event, | 138 // When this is called in response to the selectedChange event, |
| 139 // the list grabs focus immediately afterwards. Thus we must delay | 139 // the list grabs focus immediately afterwards. Thus we must delay |
| 140 // our focus grab. | 140 // our focus grab. |
| 141 var self = this; | 141 var self = this; |
| 142 if (focusElement) { | 142 if (focusElement) { |
| 143 window.setTimeout(function() { | 143 window.setTimeout(function() { |
| 144 // Make sure we are still in edit mode by the time we execute. | 144 // Make sure we are still in edit mode by the time we execute. |
| 145 if (self.editing) { | 145 if (self.editing && self.focusPlaceholder) { |
| 146 focusElement.focus(); | 146 focusElement.focus(); |
| 147 focusElement.select(); | 147 focusElement.select(); |
| 148 } | 148 } |
| 149 }, 50); | 149 }, 50); |
| 150 } | 150 } |
| 151 } else { | 151 } else { |
| 152 if (!this.editCancelled_ && this.hasBeenEdited && | 152 if (!this.editCancelled_ && this.hasBeenEdited && |
| 153 this.currentInputIsValid) { | 153 this.currentInputIsValid) { |
| 154 if (this.isPlaceholder) | 154 if (this.isPlaceholder) |
| 155 this.parentNode.focusPlaceholder = true; | 155 this.parentNode.focusPlaceholder = true; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 inputEl.setAttribute('displaymode', 'edit'); | 246 inputEl.setAttribute('displaymode', 'edit'); |
| 247 inputEl.staticVersion = textEl; | 247 inputEl.staticVersion = textEl; |
| 248 } else { | 248 } else { |
| 249 // At this point |this| is not attached to the parent list yet, so give | 249 // At this point |this| is not attached to the parent list yet, so give |
| 250 // a short timeout in order for the attachment to occur. | 250 // a short timeout in order for the attachment to occur. |
| 251 var self = this; | 251 var self = this; |
| 252 window.setTimeout(function() { | 252 window.setTimeout(function() { |
| 253 var list = self.parentNode; | 253 var list = self.parentNode; |
| 254 if (list && list.focusPlaceholder) { | 254 if (list && list.focusPlaceholder) { |
| 255 list.focusPlaceholder = false; | 255 list.focusPlaceholder = false; |
| 256 inputEl.focus(); | 256 if (list.shouldFocusPlaceholder()) |
| 257 inputEl.focus(); |
| 257 } | 258 } |
| 258 }, 50); | 259 }, 50); |
| 259 } | 260 } |
| 260 | 261 |
| 261 inputEl.addEventListener('focus', this.handleFocus_.bind(this)); | 262 inputEl.addEventListener('focus', this.handleFocus_.bind(this)); |
| 262 container.appendChild(inputEl); | 263 container.appendChild(inputEl); |
| 263 this.editFields_.push(inputEl); | 264 this.editFields_.push(inputEl); |
| 264 | 265 |
| 265 return container; | 266 return container; |
| 266 }, | 267 }, |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 */ | 401 */ |
| 401 handleListFocusChange_: function(e) { | 402 handleListFocusChange_: function(e) { |
| 402 var leadItem = this.getListItemByIndex(this.selectionModel.leadIndex); | 403 var leadItem = this.getListItemByIndex(this.selectionModel.leadIndex); |
| 403 if (leadItem) { | 404 if (leadItem) { |
| 404 if (e.newValue) | 405 if (e.newValue) |
| 405 leadItem.updateEditState(); | 406 leadItem.updateEditState(); |
| 406 else | 407 else |
| 407 leadItem.editing = false; | 408 leadItem.editing = false; |
| 408 } | 409 } |
| 409 }, | 410 }, |
| 411 |
| 412 /** |
| 413 * May be overridden by subclasses to disable focusing the placeholder. |
| 414 * @return true if the placeholder element should be focused on edit commit. |
| 415 */ |
| 416 shouldFocusPlaceholder: function() { |
| 417 return true; |
| 418 }, |
| 410 }; | 419 }; |
| 411 | 420 |
| 412 // Export | 421 // Export |
| 413 return { | 422 return { |
| 414 InlineEditableItem: InlineEditableItem, | 423 InlineEditableItem: InlineEditableItem, |
| 415 InlineEditableItemList: InlineEditableItemList, | 424 InlineEditableItemList: InlineEditableItemList, |
| 416 }; | 425 }; |
| 417 }); | 426 }); |
| OLD | NEW |