Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 /** | 5 /** |
| 6 * @template T | 6 * @template T |
| 7 * @interface | 7 * @interface |
| 8 */ | 8 */ |
| 9 UI.ListDelegate = function() {}; | 9 UI.ListDelegate = function() {}; |
| 10 | 10 |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 174 } | 174 } |
| 175 } | 175 } |
| 176 | 176 |
| 177 /** | 177 /** |
| 178 * @param {!Array<T>} items | 178 * @param {!Array<T>} items |
| 179 */ | 179 */ |
| 180 replaceAllItems(items) { | 180 replaceAllItems(items) { |
| 181 this.replaceItemsInRange(0, this._items.length, items); | 181 this.replaceItemsInRange(0, this._items.length, items); |
| 182 } | 182 } |
| 183 | 183 |
| 184 | |
|
dgozman
2017/05/08 23:16:47
nit: remove extra blank line
einbinder
2017/05/09 22:00:45
Done.
| |
| 185 refreshAllItems() { | |
| 186 this.refreshItemsInRange(0, this._items.length); | |
| 187 } | |
| 188 | |
| 184 /** | 189 /** |
| 185 * @param {number} from | 190 * @param {number} from |
| 186 * @param {number} to | 191 * @param {number} to |
| 192 */ | |
| 193 refreshItemsInRange(from, to) { | |
| 194 for (var i = from; i < to; i++) | |
| 195 this._itemToElement.delete(this._items[i]); | |
| 196 this.invalidateRange(from, to); | |
| 197 if (this._selectedIndex !== -1) | |
| 198 this._select(this._selectedIndex, null, null); | |
| 199 } | |
| 200 | |
| 201 /** | |
| 202 * @param {number} from | |
| 203 * @param {number} to | |
| 187 */ | 204 */ |
| 188 invalidateRange(from, to) { | 205 invalidateRange(from, to) { |
| 189 this._invalidate(from, to, to - from); | 206 this._invalidate(from, to, to - from); |
| 190 } | 207 } |
| 191 | 208 |
| 192 viewportResized() { | 209 viewportResized() { |
| 193 if (this._mode === UI.ListMode.NonViewport) | 210 if (this._mode === UI.ListMode.NonViewport) |
| 194 return; | 211 return; |
| 195 // TODO(dgozman): try to keep visible scrollTop the same. | 212 // TODO(dgozman): try to keep visible scrollTop the same. |
| 196 var scrollTop = this.element.scrollTop; | 213 var scrollTop = this.element.scrollTop; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 /** | 254 /** |
| 238 * @return {?T} | 255 * @return {?T} |
| 239 */ | 256 */ |
| 240 selectedItem() { | 257 selectedItem() { |
| 241 return this._selectedIndex === -1 ? null : this._items[this._selectedIndex]; | 258 return this._selectedIndex === -1 ? null : this._items[this._selectedIndex]; |
| 242 } | 259 } |
| 243 | 260 |
| 244 /** | 261 /** |
| 245 * @param {?T} item | 262 * @param {?T} item |
| 246 * @param {boolean=} center | 263 * @param {boolean=} center |
| 264 * @param {boolean=} dontScroll | |
| 247 */ | 265 */ |
| 248 selectItem(item, center) { | 266 selectItem(item, center, dontScroll) { |
| 249 var index = -1; | 267 var index = -1; |
| 250 if (item !== null) { | 268 if (item !== null) { |
| 251 index = this._items.indexOf(item); | 269 index = this._items.indexOf(item); |
| 252 if (index === -1) | 270 if (index === -1) |
| 253 throw 'Attempt to select missing item'; | 271 throw 'Attempt to select missing item'; |
| 254 if (!this._delegate.isItemSelectable(item)) | 272 if (!this._delegate.isItemSelectable(item)) |
| 255 throw 'Attempt to select non-selectable item'; | 273 throw 'Attempt to select non-selectable item'; |
| 256 } | 274 } |
| 257 if (this._selectedIndex !== index) | 275 if (this._selectedIndex !== index) |
| 258 this._select(index); | 276 this._select(index); |
| 259 if (index !== -1) | 277 if (index !== -1 && !dontScroll) |
| 260 this._scrollIntoView(index, center); | 278 this._scrollIntoView(index, center); |
| 261 } | 279 } |
| 262 | 280 |
| 263 /** | 281 /** |
| 264 * @param {boolean=} canWrap | 282 * @param {boolean=} canWrap |
| 265 * @param {boolean=} center | 283 * @param {boolean=} center |
| 266 * @return {boolean} | 284 * @return {boolean} |
| 267 */ | 285 */ |
| 268 selectPreviousItem(canWrap, center) { | 286 selectPreviousItem(canWrap, center) { |
| 269 if (this._selectedIndex === -1 && !canWrap) | 287 if (this._selectedIndex === -1 && !canWrap) |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 661 this._firstIndex = firstIndex; | 679 this._firstIndex = firstIndex; |
| 662 this._lastIndex = lastIndex; | 680 this._lastIndex = lastIndex; |
| 663 this._topHeight = this._offsetAtIndex(firstIndex); | 681 this._topHeight = this._offsetAtIndex(firstIndex); |
| 664 this._topElement.style.height = this._topHeight + 'px'; | 682 this._topElement.style.height = this._topHeight + 'px'; |
| 665 this._bottomHeight = totalHeight - this._offsetAtIndex(lastIndex); | 683 this._bottomHeight = totalHeight - this._offsetAtIndex(lastIndex); |
| 666 this._bottomElement.style.height = this._bottomHeight + 'px'; | 684 this._bottomElement.style.height = this._bottomHeight + 'px'; |
| 667 this._renderedHeight = totalHeight; | 685 this._renderedHeight = totalHeight; |
| 668 this.element.scrollTop = scrollTop; | 686 this.element.scrollTop = scrollTop; |
| 669 } | 687 } |
| 670 }; | 688 }; |
| OLD | NEW |