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

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

Issue 2204303003: DevTools: encapsulate extensible tabbed widget into the view manager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebaselined Created 4 years, 4 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) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 1246 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 * @param {!Array.<string>} ids 1257 * @param {!Array.<string>} ids
1258 */ 1258 */
1259 closeTabs: function(tabbedPane, ids) { }, 1259 closeTabs: function(tabbedPane, ids) { },
1260 1260
1261 /** 1261 /**
1262 * @param {string} tabId 1262 * @param {string} tabId
1263 * @param {!WebInspector.ContextMenu} contextMenu 1263 * @param {!WebInspector.ContextMenu} contextMenu
1264 */ 1264 */
1265 onContextMenu: function(tabId, contextMenu) { } 1265 onContextMenu: function(tabId, contextMenu) { }
1266 } 1266 }
1267
1268 /**
1269 * @constructor
1270 * @extends {WebInspector.VBox}
1271 * @implements {WebInspector.ViewLocation}
1272 * @param {string} location
1273 * @param {boolean=} restoreSelection
1274 */
1275 WebInspector.ExtensibleTabbedPane = function(location, restoreSelection)
1276 {
1277 WebInspector.VBox.call(this);
1278 this.element.classList.add("flex-auto");
1279 this._tabbedPane = new WebInspector.TabbedPane();
1280 this._tabbedPane.show(this.contentElement);
1281 this._location = location;
1282 /** @type {!Object.<string, !Promise.<?WebInspector.Widget>>} */
1283 this._promiseForId = {};
1284
1285 this._tabbedPane.addEventListener(WebInspector.TabbedPane.EventTypes.TabSele cted, this._tabSelected, this);
1286 this._tabbedPane.addEventListener(WebInspector.TabbedPane.EventTypes.TabClos ed, this._tabClosed, this);
1287 this._closeableTabSetting = WebInspector.settings.createSetting(location + " -closeableTabs", {});
1288 if (restoreSelection)
1289 this._lastSelectedTabSetting = WebInspector.settings.createSetting(locat ion + "-selectedTab", "");
1290 this._initialize();
1291 }
1292
1293 WebInspector.ExtensibleTabbedPane.prototype = {
1294 /**
1295 * @return {!WebInspector.TabbedPane}
1296 */
1297 tabbedPane: function()
1298 {
1299 return this._tabbedPane;
1300 },
1301
1302 _initialize: function()
1303 {
1304 /** @type {!Map.<string, !Runtime.Extension>} */
1305 this._extensions = new Map();
1306 var extensions = self.runtime.extensions("view");
1307
1308 for (var i = 0; i < extensions.length; ++i) {
1309 var location = extensions[i].descriptor()["location"];
1310 if (location !== this._location)
1311 continue;
1312 var id = extensions[i].descriptor()["id"];
1313 this._extensions.set(id, extensions[i]);
1314 if (this._isPermanentTab(id))
1315 this._appendTab(extensions[i]);
1316 else if (this._isCloseableTab(id) && this._closeableTabSetting.get() [id])
1317 this._appendTab(extensions[i]);
1318 }
1319 },
1320
1321 wasShown: function()
1322 {
1323 if (this._wasAlreadyShown || !this._lastSelectedTabSetting)
1324 return;
1325 this._wasAlreadyShown = true;
1326 if (this._tabbedPane.hasTab(this._lastSelectedTabSetting.get()))
1327 this._tabbedPane.selectTab(this._lastSelectedTabSetting.get());
1328 },
1329
1330 /**
1331 * @param {string} id
1332 * @return {boolean}
1333 */
1334 _isPermanentTab: function(id)
1335 {
1336 return this._extensions.get(id).descriptor()["persistence"] === "permane nt" || !this._extensions.get(id).descriptor()["persistence"];
1337 },
1338
1339 /**
1340 * @param {string} id
1341 * @return {boolean}
1342 */
1343 _isCloseableTab: function(id)
1344 {
1345 return this._extensions.get(id).descriptor()["persistence"] === "closeab le";
1346 },
1347
1348 enableMoreTabsButton: function()
1349 {
1350 var toolbar = new WebInspector.Toolbar("drawer-toolbar");
1351 toolbar.appendToolbarItem(new WebInspector.ToolbarMenuButton(this._appen dTabsToMenu.bind(this)));
1352 this._tabbedPane.insertBeforeTabStrip(toolbar.element);
1353 this._tabbedPane.disableOverflowMenu();
1354 },
1355
1356 /**
1357 * @param {!WebInspector.ContextMenu} contextMenu
1358 */
1359 _appendTabsToMenu: function(contextMenu)
1360 {
1361 var extensions = self.runtime.extensions("view", undefined, true);
1362 for (var extension of extensions) {
1363 if (extension.descriptor()["location"] !== this._location)
1364 continue;
1365 var title = WebInspector.UIString(extension.title());
1366 contextMenu.appendItem(title, this.showView.bind(this, extension.des criptor()["id"]));
1367 }
1368 },
1369
1370 /**
1371 * @param {!Runtime.Extension} extension
1372 */
1373 _appendTab: function(extension)
1374 {
1375 var descriptor = extension.descriptor();
1376 var id = descriptor["id"];
1377 var title = WebInspector.UIString(extension.title());
1378 var closeable = descriptor["persistence"] === "closeable" || descriptor[ "persistence"] === "temporary";
1379 this._tabbedPane.appendTab(id, title, new WebInspector.Widget(), undefin ed, false, closeable);
1380 },
1381
1382 /**
1383 * @override
1384 * @param {string} id
1385 */
1386 showView: function(id)
1387 {
1388 if (!this._tabbedPane.hasTab(id))
1389 this._appendTab(/** @type {!Runtime.Extension} */(this._extensions.g et(id)));
1390 this._tabbedPane.focus();
1391 this._tabbedPane.selectTab(id);
1392 },
1393
1394 /**
1395 * @param {!WebInspector.Event} event
1396 */
1397 _tabSelected: function(event)
1398 {
1399 var tabId = /** @type {string} */ (event.data.tabId);
1400 if (this._lastSelectedTabSetting && event.data["isUserGesture"])
1401 this._lastSelectedTabSetting.set(tabId);
1402 if (!this._extensions.has(tabId))
1403 return;
1404
1405 this._viewForId(tabId);
1406
1407 var descriptor = this._extensions.get(tabId).descriptor();
1408 if (descriptor["persistence"] === "closeable") {
1409 var tabs = this._closeableTabSetting.get();
1410 if (!tabs[tabId]) {
1411 tabs[tabId] = true;
1412 this._closeableTabSetting.set(tabs);
1413 }
1414 }
1415 },
1416
1417 /**
1418 * @param {!WebInspector.Event} event
1419 */
1420 _tabClosed: function(event)
1421 {
1422 var id = /** @type {string} */ (event.data["tabId"]);
1423 var tabs = this._closeableTabSetting.get();
1424 if (tabs[id]) {
1425 delete tabs[id];
1426 this._closeableTabSetting.set(tabs);
1427 }
1428 delete this._promiseForId[id];
1429 },
1430
1431 /**
1432 * @param {string} id
1433 * @return {!Promise.<?WebInspector.Widget>}
1434 */
1435 _viewForId: function(id)
1436 {
1437 if (this._promiseForId[id])
1438 return this._promiseForId[id];
1439
1440 var promise = this._extensions.get(id).instance();
1441 this._promiseForId[id] = /** @type {!Promise.<?WebInspector.Widget>} */ (promise);
1442 return promise.then(cacheView.bind(this));
1443
1444 /**
1445 * @param {!Object} object
1446 * @this {WebInspector.ExtensibleTabbedPane}
1447 */
1448 function cacheView(object)
1449 {
1450 var view = /** @type {!WebInspector.Widget} */ (object);
1451 this._tabbedPane.changeTabView(id, view);
1452 return view;
1453 }
1454 },
1455
1456 __proto__: WebInspector.VBox.prototype
1457 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698