Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 * @unrestricted | 5 * @unrestricted |
| 6 */ | 6 */ |
| 7 UI.ListWidget = class extends UI.VBox { | 7 UI.ListWidget = class extends UI.VBox { |
| 8 /** | 8 /** |
| 9 * @param {!UI.ListWidget.Delegate} delegate | 9 * @param {!UI.ListWidget.Delegate} delegate |
| 10 */ | 10 */ |
| 11 constructor(delegate) { | 11 constructor(delegate) { |
| 12 super(true); | 12 super(true); |
| 13 this.registerRequiredCSS('ui/listWidget.css'); | 13 this.registerRequiredCSS('ui/listWidget.css'); |
| 14 this._delegate = delegate; | 14 this._delegate = delegate; |
| 15 | 15 |
| 16 this._list = this.contentElement.createChild('div', 'list'); | 16 this._list = this.contentElement.createChild('div', 'list'); |
| 17 this.element.tabIndex = -1; | |
| 17 | 18 |
| 18 /** @type {?UI.ListWidget.Editor} */ | 19 /** @type {?UI.ListWidget.Editor} */ |
| 19 this._editor = null; | 20 this._editor = null; |
| 20 /** @type {*|null} */ | 21 /** @type {*|null} */ |
| 21 this._editItem = null; | 22 this._editItem = null; |
| 22 /** @type {?Element} */ | 23 /** @type {?Element} */ |
| 23 this._editElement = null; | 24 this._editElement = null; |
| 24 | 25 |
| 25 /** @type {?Element} */ | 26 /** @type {?Element} */ |
| 26 this._emptyPlaceholder = null; | 27 this._emptyPlaceholder = null; |
| 27 | 28 |
| 29 /** @type {?Element} */ | |
| 30 this._previousFocusedElement = null; | |
|
einbinder
2017/04/19 17:02:09
Can't use focus restorer, because we don't necessa
dgozman
2017/04/19 19:59:34
Could you please describe in more details?
einbinder
2017/04/20 16:35:26
The list doesn't need to steal focus, it is up to
| |
| 31 | |
| 28 this.clear(); | 32 this.clear(); |
| 29 } | 33 } |
| 30 | 34 |
| 31 clear() { | 35 clear() { |
| 32 this._items = []; | 36 this._items = []; |
| 33 this._editable = []; | 37 this._editable = []; |
| 34 this._elements = []; | 38 this._elements = []; |
| 35 this._lastSeparator = false; | 39 this._lastSeparator = false; |
| 36 this._list.removeChildren(); | 40 this._list.removeChildren(); |
| 37 this._updatePlaceholder(); | 41 this._updatePlaceholder(); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 var index = this._elements.indexOf(element); | 141 var index = this._elements.indexOf(element); |
| 138 var insertionPoint = this._elements[index + 1] || null; | 142 var insertionPoint = this._elements[index + 1] || null; |
| 139 this._startEditing(item, element, insertionPoint); | 143 this._startEditing(item, element, insertionPoint); |
| 140 } | 144 } |
| 141 | 145 |
| 142 /** | 146 /** |
| 143 * @this {UI.ListWidget} | 147 * @this {UI.ListWidget} |
| 144 */ | 148 */ |
| 145 function onRemoveClicked() { | 149 function onRemoveClicked() { |
| 146 var index = this._elements.indexOf(element); | 150 var index = this._elements.indexOf(element); |
| 151 this.element.focus(); | |
|
einbinder
2017/04/19 17:02:09
When a remove button is clicked, I don't have a go
| |
| 147 this._delegate.removeItemRequested(this._items[index], index); | 152 this._delegate.removeItemRequested(this._items[index], index); |
| 148 } | 153 } |
| 149 } | 154 } |
| 150 | 155 |
| 151 /** | 156 /** |
| 152 * @override | 157 * @override |
| 153 */ | 158 */ |
| 154 wasShown() { | 159 wasShown() { |
| 155 super.wasShown(); | 160 super.wasShown(); |
| 156 this._stopEditing(); | 161 this._stopEditing(); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 169 /** | 174 /** |
| 170 * @param {*} item | 175 * @param {*} item |
| 171 * @param {?Element} element | 176 * @param {?Element} element |
| 172 * @param {?Element} insertionPoint | 177 * @param {?Element} insertionPoint |
| 173 */ | 178 */ |
| 174 _startEditing(item, element, insertionPoint) { | 179 _startEditing(item, element, insertionPoint) { |
| 175 if (element && this._editElement === element) | 180 if (element && this._editElement === element) |
| 176 return; | 181 return; |
| 177 | 182 |
| 178 this._stopEditing(); | 183 this._stopEditing(); |
| 184 this._previousFocusedElement = this.element.ownerDocument.deepActiveElement( ); | |
| 179 | 185 |
| 180 this._list.classList.add('list-editing'); | 186 this._list.classList.add('list-editing'); |
| 181 this._editItem = item; | 187 this._editItem = item; |
| 182 this._editElement = element; | 188 this._editElement = element; |
| 183 if (element) | 189 if (element) |
| 184 element.classList.add('hidden'); | 190 element.classList.add('hidden'); |
| 185 | 191 |
| 186 var index = element ? this._elements.indexOf(element) : -1; | 192 var index = element ? this._elements.indexOf(element) : -1; |
| 187 this._editor = this._delegate.beginEdit(item); | 193 this._editor = this._delegate.beginEdit(item); |
| 188 this._updatePlaceholder(); | 194 this._updatePlaceholder(); |
| 189 this._list.insertBefore(this._editor.element, insertionPoint); | 195 this._list.insertBefore(this._editor.element, insertionPoint); |
| 190 this._editor.beginEdit( | 196 this._editor.beginEdit( |
| 191 item, index, element ? Common.UIString('Save') : Common.UIString('Add'), this._commitEditing.bind(this), | 197 item, index, element ? Common.UIString('Save') : Common.UIString('Add'), this._commitEditing.bind(this), |
| 192 this._stopEditing.bind(this)); | 198 this._stopEditing.bind(this)); |
| 193 } | 199 } |
| 194 | 200 |
| 195 _commitEditing() { | 201 _commitEditing() { |
| 196 var editItem = this._editItem; | 202 var editItem = this._editItem; |
| 197 var isNew = !this._editElement; | 203 var isNew = !this._editElement; |
| 198 var editor = /** @type {!UI.ListWidget.Editor} */ (this._editor); | 204 var editor = /** @type {!UI.ListWidget.Editor} */ (this._editor); |
| 199 this._stopEditing(); | 205 this._stopEditing(); |
| 200 this._delegate.commitEdit(editItem, editor, isNew); | 206 this._delegate.commitEdit(editItem, editor, isNew); |
| 201 } | 207 } |
| 202 | 208 |
| 203 _stopEditing() { | 209 _stopEditing() { |
| 204 this._list.classList.remove('list-editing'); | 210 this._list.classList.remove('list-editing'); |
| 211 var hadFocus = this._editor && this._editor.element.hasFocus(); | |
| 205 if (this._editElement) | 212 if (this._editElement) |
| 206 this._editElement.classList.remove('hidden'); | 213 this._editElement.classList.remove('hidden'); |
| 207 if (this._editor && this._editor.element.parentElement) | 214 if (this._editor && this._editor.element.parentElement) |
| 208 this._editor.element.remove(); | 215 this._editor.element.remove(); |
| 209 | 216 |
| 210 this._editor = null; | 217 this._editor = null; |
| 211 this._editItem = null; | 218 this._editItem = null; |
| 212 this._editElement = null; | 219 this._editElement = null; |
| 213 this._updatePlaceholder(); | 220 this._updatePlaceholder(); |
| 221 if (this._previousFocusedElement && hadFocus) | |
| 222 this._previousFocusedElement.focus(); | |
| 223 this._previousFocusedElement = null; | |
| 214 } | 224 } |
| 215 }; | 225 }; |
| 216 | 226 |
| 217 /** | 227 /** |
| 218 * @interface | 228 * @interface |
| 219 */ | 229 */ |
| 220 UI.ListWidget.Delegate = function() {}; | 230 UI.ListWidget.Delegate = function() {}; |
| 221 | 231 |
| 222 UI.ListWidget.Delegate.prototype = { | 232 UI.ListWidget.Delegate.prototype = { |
| 223 /** | 233 /** |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 398 | 408 |
| 399 _cancelClicked() { | 409 _cancelClicked() { |
| 400 var cancel = this._cancel; | 410 var cancel = this._cancel; |
| 401 this._commit = null; | 411 this._commit = null; |
| 402 this._cancel = null; | 412 this._cancel = null; |
| 403 this._item = null; | 413 this._item = null; |
| 404 this._index = -1; | 414 this._index = -1; |
| 405 cancel(); | 415 cancel(); |
| 406 } | 416 } |
| 407 }; | 417 }; |
| OLD | NEW |