Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(354)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/ui/ListControl.js

Issue 2842843003: DevTools: Display product information in ConsoleContextSelector (Closed)
Patch Set: Usability fixes Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 117
118 /** 118 /**
119 * @param {number} index 119 * @param {number} index
120 * @param {T} item 120 * @param {T} item
121 */ 121 */
122 insertItemAtIndex(index, item) { 122 insertItemAtIndex(index, item) {
123 this.replaceItemsInRange(index, index, [item]); 123 this.replaceItemsInRange(index, index, [item]);
124 } 124 }
125 125
126 /** 126 /**
127 * @param {T} item
128 * @param {function(T, T):number} comparator
129 */
130 insertItemWithComparator(item, comparator) {
131 var index = this._items.lowerBound(item, comparator);
132 this.insertItemAtIndex(index, item);
133 }
134
135 /**
136 * @param {T} item
137 * @return {number}
138 */
139 indexOfItem(item) {
140 return this._items.indexOf(item);
141 }
142
143 /**
127 * @param {number} index 144 * @param {number} index
128 * @return {T} 145 * @return {T}
129 */ 146 */
130 removeItemAtIndex(index) { 147 removeItemAtIndex(index) {
131 var result = this._items[index]; 148 var result = this._items[index];
132 this.replaceItemsInRange(index, index + 1, []); 149 this.replaceItemsInRange(index, index + 1, []);
133 return result; 150 return result;
134 } 151 }
135 152
136 /** 153 /**
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 } 191 }
175 } 192 }
176 193
177 /** 194 /**
178 * @param {!Array<T>} items 195 * @param {!Array<T>} items
179 */ 196 */
180 replaceAllItems(items) { 197 replaceAllItems(items) {
181 this.replaceItemsInRange(0, this._items.length, items); 198 this.replaceItemsInRange(0, this._items.length, items);
182 } 199 }
183 200
201 refreshAllItems() {
202 this.refreshItemsInRange(0, this._items.length);
203 }
204
184 /** 205 /**
185 * @param {number} from 206 * @param {number} from
186 * @param {number} to 207 * @param {number} to
208 */
209 refreshItemsInRange(from, to) {
210 for (var i = from; i < to; i++)
211 this._itemToElement.delete(this._items[i]);
212 this.invalidateRange(from, to);
213 if (this._selectedIndex !== -1)
214 this._select(this._selectedIndex, null, null);
215 }
216
217 /**
218 * @param {number} from
219 * @param {number} to
187 */ 220 */
188 invalidateRange(from, to) { 221 invalidateRange(from, to) {
189 this._invalidate(from, to, to - from); 222 this._invalidate(from, to, to - from);
190 } 223 }
191 224
192 viewportResized() { 225 viewportResized() {
193 if (this._mode === UI.ListMode.NonViewport) 226 if (this._mode === UI.ListMode.NonViewport)
194 return; 227 return;
195 // TODO(dgozman): try to keep visible scrollTop the same. 228 // TODO(dgozman): try to keep visible scrollTop the same.
196 var scrollTop = this.element.scrollTop; 229 var scrollTop = this.element.scrollTop;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 } 268 }
236 269
237 /** 270 /**
238 * @return {?T} 271 * @return {?T}
239 */ 272 */
240 selectedItem() { 273 selectedItem() {
241 return this._selectedIndex === -1 ? null : this._items[this._selectedIndex]; 274 return this._selectedIndex === -1 ? null : this._items[this._selectedIndex];
242 } 275 }
243 276
244 /** 277 /**
278 * @return {number}
279 */
280 selectedIndex() {
281 return this._selectedIndex;
282 }
283
284 /**
245 * @param {?T} item 285 * @param {?T} item
246 * @param {boolean=} center 286 * @param {boolean=} center
287 * @param {boolean=} dontScroll
247 */ 288 */
248 selectItem(item, center) { 289 selectItem(item, center, dontScroll) {
249 var index = -1; 290 var index = -1;
250 if (item !== null) { 291 if (item !== null) {
251 index = this._items.indexOf(item); 292 index = this._items.indexOf(item);
252 if (index === -1) 293 if (index === -1) {
253 throw 'Attempt to select missing item'; 294 console.error('Attempt to select missing item');
dgozman 2017/05/11 21:14:52 Let's change all of them to console.errors then.
einbinder 2017/05/11 21:47:22 I kept the throw on methods that need to return va
254 if (!this._delegate.isItemSelectable(item)) 295 return;
255 throw 'Attempt to select non-selectable item'; 296 }
297 if (!this._delegate.isItemSelectable(item)) {
298 console.error('Attempt to select non-selectable item');
299 return;
300 }
256 } 301 }
257 if (this._selectedIndex !== index) 302 if (this._selectedIndex !== index)
258 this._select(index); 303 this._select(index);
259 if (index !== -1) 304 if (index !== -1 && !dontScroll)
260 this._scrollIntoView(index, center); 305 this._scrollIntoView(index, center);
261 } 306 }
262 307
263 /** 308 /**
264 * @param {boolean=} canWrap 309 * @param {boolean=} canWrap
265 * @param {boolean=} center 310 * @param {boolean=} center
266 * @return {boolean} 311 * @return {boolean}
267 */ 312 */
268 selectPreviousItem(canWrap, center) { 313 selectPreviousItem(canWrap, center) {
269 if (this._selectedIndex === -1 && !canWrap) 314 if (this._selectedIndex === -1 && !canWrap)
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 this._firstIndex = firstIndex; 706 this._firstIndex = firstIndex;
662 this._lastIndex = lastIndex; 707 this._lastIndex = lastIndex;
663 this._topHeight = this._offsetAtIndex(firstIndex); 708 this._topHeight = this._offsetAtIndex(firstIndex);
664 this._topElement.style.height = this._topHeight + 'px'; 709 this._topElement.style.height = this._topHeight + 'px';
665 this._bottomHeight = totalHeight - this._offsetAtIndex(lastIndex); 710 this._bottomHeight = totalHeight - this._offsetAtIndex(lastIndex);
666 this._bottomElement.style.height = this._bottomHeight + 'px'; 711 this._bottomElement.style.height = this._bottomHeight + 'px';
667 this._renderedHeight = totalHeight; 712 this._renderedHeight = totalHeight;
668 this.element.scrollTop = scrollTop; 713 this.element.scrollTop = scrollTop;
669 } 714 }
670 }; 715 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698