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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/resources/ApplicationPanelSidebar.js

Issue 2873843003: [DevTools] Restore tree selection after reload (Closed)
Patch Set: 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 /* 1 /*
2 * Copyright (C) 2007, 2008, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2008, 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2009 Joseph Pecoraro 3 * Copyright (C) 2009 Joseph Pecoraro
4 * Copyright (C) 2013 Samsung Electronics. All rights reserved. 4 * Copyright (C) 2013 Samsung Electronics. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 9 *
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 this._databaseTableViews = new Map(); 96 this._databaseTableViews = new Map();
97 /** @type {!Map.<!Resources.Database, !Resources.DatabaseQueryView>} */ 97 /** @type {!Map.<!Resources.Database, !Resources.DatabaseQueryView>} */
98 this._databaseQueryViews = new Map(); 98 this._databaseQueryViews = new Map();
99 /** @type {!Map.<!Resources.Database, !Resources.DatabaseTreeElement>} */ 99 /** @type {!Map.<!Resources.Database, !Resources.DatabaseTreeElement>} */
100 this._databaseTreeElements = new Map(); 100 this._databaseTreeElements = new Map();
101 /** @type {!Map.<!Resources.DOMStorage, !Resources.DOMStorageTreeElement>} * / 101 /** @type {!Map.<!Resources.DOMStorage, !Resources.DOMStorageTreeElement>} * /
102 this._domStorageTreeElements = new Map(); 102 this._domStorageTreeElements = new Map();
103 /** @type {!Object.<string, boolean>} */ 103 /** @type {!Object.<string, boolean>} */
104 this._domains = {}; 104 this._domains = {};
105 105
106 /** @type {!Array<string>} */
107 this._storedSelection = [];
108
106 this._sidebarTree.contentElement.addEventListener('mousemove', this._onmouse move.bind(this), false); 109 this._sidebarTree.contentElement.addEventListener('mousemove', this._onmouse move.bind(this), false);
107 this._sidebarTree.contentElement.addEventListener('mouseleave', this._onmous eleave.bind(this), false); 110 this._sidebarTree.contentElement.addEventListener('mouseleave', this._onmous eleave.bind(this), false);
111 this._sidebarTree.addEventListener(UI.TreeOutline.Events.ElementAttached, ev ent => this._elementAdded(event));
dgozman 2017/05/11 23:08:41 this._elementAdded.bind(this)
eostroukhov 2017/05/12 19:36:36 Done. Waiting for "::" operator :)
108 112
109 SDK.targetManager.observeTargets(this); 113 SDK.targetManager.observeTargets(this);
110 SDK.targetManager.addModelListener( 114 SDK.targetManager.addModelListener(
111 SDK.ResourceTreeModel, SDK.ResourceTreeModel.Events.FrameNavigated, this ._frameNavigated, this); 115 SDK.ResourceTreeModel, SDK.ResourceTreeModel.Events.FrameNavigated, this ._frameNavigated, this);
116 SDK.targetManager.addModelListener(
117 SDK.ResourceTreeModel, SDK.ResourceTreeModel.Events.WillReloadPage, this ._storeSelection, this);
112 } 118 }
113 119
114 /** 120 /**
115 * @param {string} title 121 * @param {string} title
116 * @return {!UI.TreeElement} 122 * @return {!UI.TreeElement}
117 */ 123 */
118 _addSidebarSection(title) { 124 _addSidebarSection(title) {
119 var treeElement = new UI.TreeElement(title, true); 125 var treeElement = new UI.TreeElement(title, true);
120 treeElement.listItemElement.classList.add('storage-group-list-item'); 126 treeElement.listItemElement.classList.add('storage-group-list-item');
121 treeElement.setCollapsible(false); 127 treeElement.setCollapsible(false);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 this.databasesListTreeElement.removeChildren(); 238 this.databasesListTreeElement.removeChildren();
233 this.databasesListTreeElement.setExpandable(false); 239 this.databasesListTreeElement.setExpandable(false);
234 } 240 }
235 241
236 _resetAppCache() { 242 _resetAppCache() {
237 for (var frameId of Object.keys(this._applicationCacheFrameElements)) 243 for (var frameId of Object.keys(this._applicationCacheFrameElements))
238 this._applicationCacheFrameManifestRemoved({data: frameId}); 244 this._applicationCacheFrameManifestRemoved({data: frameId});
239 this.applicationCacheListTreeElement.setExpandable(false); 245 this.applicationCacheListTreeElement.setExpandable(false);
240 } 246 }
241 247
248 _storeSelection() {
249 this._storedSelection = [];
250 for (var element = this._sidebarTree.selectedTreeElement; element; element = element.parent)
251 this._storedSelection.push(element.itemURL);
252 // "Forget" the selection if the item was not restored in a timely manner.
253 // This is to prevent selection jumping on slow page loads.
dgozman 2017/05/11 23:08:41 Why not on first user interaction?
eostroukhov 2017/05/12 19:36:36 Done.
254 setTimeout(() => this._storedSelection = [], 1000);
255 }
256
257 /**
258 * @param {!Common.Event} event
259 */
260 _elementAdded(event) {
261 if (!this._storedSelection.length)
262 return;
263 var element = event.data;
264 var index = this._storedSelection.indexOf(element.itemURL);
265 if (index > 0)
266 element.expand();
267 if (index !== 0)
dgozman 2017/05/11 23:08:41 if (index)
eostroukhov 2017/05/12 19:36:36 Done. (Node.js has opposite convention ;) )
268 return;
269 for (var parent = element.parent; parent; parent = parent.parent)
270 parent.expand();
271 var selected = this._sidebarTree.selectedTreeElement;
272 if (!selected || this._storedSelection.indexOf(selected.itemURL) < 0)
273 return;
274 element.select();
275 this._storedSelection = [];
276 }
277
242 _reset() { 278 _reset() {
243 this._domains = {}; 279 this._domains = {};
244 this._resetWebSQL(); 280 this._resetWebSQL();
245 this.cookieListTreeElement.removeChildren(); 281 this.cookieListTreeElement.removeChildren();
246 } 282 }
247 283
248 _frameNavigated(event) { 284 _frameNavigated(event) {
249 var frame = event.data; 285 var frame = event.data;
250 286
251 if (!frame.parentFrame) 287 if (!frame.parentFrame)
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 629
594 /** 630 /**
595 * @override 631 * @override
596 * @return {boolean} 632 * @return {boolean}
597 */ 633 */
598 onselect(selectedByUser) { 634 onselect(selectedByUser) {
599 if (!selectedByUser) 635 if (!selectedByUser)
600 return false; 636 return false;
601 var itemURL = this.itemURL; 637 var itemURL = this.itemURL;
602 if (itemURL) 638 if (itemURL)
603 this._storagePanel.setLastSelectedItemURL(itemURL); 639 this._storagePanel.setLastSelectedItemURL(itemURL);
dgozman 2017/05/11 23:08:41 I still think we should combine with this one.
eostroukhov 2017/05/12 19:36:36 Did that. It now actually better restores selectio
604 return false; 640 return false;
605 } 641 }
606 642
607 /** 643 /**
608 * @protected 644 * @protected
609 * @param {?UI.Widget} view 645 * @param {?UI.Widget} view
610 */ 646 */
611 showView(view) { 647 showView(view) {
612 this._storagePanel.showView(view); 648 this._storagePanel.showView(view);
613 } 649 }
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after
1239 this.removeChild(objectStoreTreeElement); 1275 this.removeChild(objectStoreTreeElement);
1240 delete this._idbObjectStoreTreeElements[objectStoreName]; 1276 delete this._idbObjectStoreTreeElements[objectStoreName];
1241 } 1277 }
1242 1278
1243 clear() { 1279 clear() {
1244 for (var objectStoreName in this._idbObjectStoreTreeElements) 1280 for (var objectStoreName in this._idbObjectStoreTreeElements)
1245 this._objectStoreRemoved(objectStoreName); 1281 this._objectStoreRemoved(objectStoreName);
1246 } 1282 }
1247 }; 1283 };
1248 1284
1249 /**
1250 * @unrestricted
1251 */
1252 Resources.IDBObjectStoreTreeElement = class extends Resources.BaseStorageTreeEle ment { 1285 Resources.IDBObjectStoreTreeElement = class extends Resources.BaseStorageTreeEle ment {
1253 /** 1286 /**
1254 * @param {!Resources.ResourcesPanel} storagePanel 1287 * @param {!Resources.ResourcesPanel} storagePanel
1255 * @param {!Resources.IndexedDBModel} model 1288 * @param {!Resources.IndexedDBModel} model
1256 * @param {!Resources.IndexedDBModel.DatabaseId} databaseId 1289 * @param {!Resources.IndexedDBModel.DatabaseId} databaseId
1257 * @param {!Resources.IndexedDBModel.ObjectStore} objectStore 1290 * @param {!Resources.IndexedDBModel.ObjectStore} objectStore
1258 */ 1291 */
1259 constructor(storagePanel, model, databaseId, objectStore) { 1292 constructor(storagePanel, model, databaseId, objectStore) {
1260 super(storagePanel, objectStore.name, false); 1293 super(storagePanel, objectStore.name, false);
1261 this._model = model; 1294 this._model = model;
1262 this._databaseId = databaseId; 1295 this._databaseId = databaseId;
1263 this._idbIndexTreeElements = {}; 1296 this._idbIndexTreeElements = {};
1297 this._objectStore = objectStore;
1298 /** @type {?Resources.IDBDataView} */
1299 this._view = null;
1264 var icon = UI.Icon.create('mediumicon-table', 'resource-tree-item'); 1300 var icon = UI.Icon.create('mediumicon-table', 'resource-tree-item');
1265 this.setLeadingIcons([icon]); 1301 this.setLeadingIcons([icon]);
1266 } 1302 }
1267 1303
1268 get itemURL() { 1304 get itemURL() {
1269 return 'indexedDB://' + this._databaseId.securityOrigin + '/' + this._databa seId.name + '/' + 1305 return 'indexedDB://' + this._databaseId.securityOrigin + '/' + this._databa seId.name + '/' +
1270 this._objectStore.name; 1306 this._objectStore.name;
1271 } 1307 }
1272 1308
1273 /** 1309 /**
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1320 if (!indexNames[indexName]) { 1356 if (!indexNames[indexName]) {
1321 this.removeChild(this._idbIndexTreeElements[indexName]); 1357 this.removeChild(this._idbIndexTreeElements[indexName]);
1322 delete this._idbIndexTreeElements[indexName]; 1358 delete this._idbIndexTreeElements[indexName];
1323 } 1359 }
1324 } 1360 }
1325 1361
1326 if (this.childCount()) 1362 if (this.childCount())
1327 this.expand(); 1363 this.expand();
1328 1364
1329 if (this._view) 1365 if (this._view)
1330 this._view.update(this._objectStore); 1366 this._view.update(this._objectStore, null);
1331 1367
1332 this._updateTooltip(); 1368 this._updateTooltip();
1333 } 1369 }
1334 1370
1335 _updateTooltip() { 1371 _updateTooltip() {
1336 var keyPathString = this._objectStore.keyPathString; 1372 var keyPathString = this._objectStore.keyPathString;
1337 var tooltipString = keyPathString !== null ? (Common.UIString('Key path: ') + keyPathString) : ''; 1373 var tooltipString = keyPathString !== null ? (Common.UIString('Key path: ') + keyPathString) : '';
1338 if (this._objectStore.autoIncrement) 1374 if (this._objectStore.autoIncrement)
1339 tooltipString += '\n' + Common.UIString('autoIncrement'); 1375 tooltipString += '\n' + Common.UIString('autoIncrement');
1340 this.tooltip = tooltipString; 1376 this.tooltip = tooltipString;
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
1626 1662
1627 this.element.classList.add('storage-view'); 1663 this.element.classList.add('storage-view');
1628 this._emptyWidget = new UI.EmptyWidget(''); 1664 this._emptyWidget = new UI.EmptyWidget('');
1629 this._emptyWidget.show(this.element); 1665 this._emptyWidget.show(this.element);
1630 } 1666 }
1631 1667
1632 setText(text) { 1668 setText(text) {
1633 this._emptyWidget.text = text; 1669 this._emptyWidget.text = text;
1634 } 1670 }
1635 }; 1671 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698