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 * @interface | |
| 7 */ | |
| 8 WebInspector.View = function() | |
| 9 { | |
| 10 } | |
| 11 | |
| 12 WebInspector.View.prototype = { | |
| 13 /** | |
| 14 * @return {string} | |
| 15 */ | |
| 16 viewId: function() { }, | |
| 17 | |
| 18 /** | |
| 19 * @return {string} | |
| 20 */ | |
| 21 title: function() { }, | |
| 22 | |
| 23 /** | |
| 24 * @return {boolean} | |
| 25 */ | |
| 26 isCloseable: function() { }, | |
| 27 | |
| 28 /** | |
| 29 * @return {boolean} | |
| 30 */ | |
| 31 isTransient: function() { }, | |
| 32 | |
| 33 /** | |
| 34 * @return {!Promise<!Array<!WebInspector.ToolbarItem>>} | |
| 35 */ | |
| 36 toolbarItems: function() { }, | |
| 37 | |
| 38 /** | |
| 39 * @return {!Promise<!WebInspector.Widget>} | |
| 40 */ | |
| 41 widget: function() { } | |
| 42 } | |
| 43 | |
| 44 /** | |
| 6 * @constructor | 45 * @constructor |
| 7 * @extends {WebInspector.VBox} | 46 * @extends {WebInspector.VBox} |
| 47 * @implements {WebInspector.View} | |
| 8 * @param {string} title | 48 * @param {string} title |
| 9 * @param {boolean=} isWebComponent | 49 * @param {boolean=} isWebComponent |
| 10 */ | 50 */ |
| 11 WebInspector.View = function(title, isWebComponent) | 51 WebInspector.SimpleView = function(title, isWebComponent) |
| 12 { | 52 { |
| 13 WebInspector.VBox.call(this, isWebComponent); | 53 WebInspector.VBox.call(this, isWebComponent); |
| 14 this._title = title; | 54 this._title = title; |
| 15 /** @type {!Array<!WebInspector.ToolbarItem>} */ | 55 /** @type {!Array<!WebInspector.ToolbarItem>} */ |
| 16 this._toolbarItems = []; | 56 this._toolbarItems = []; |
| 17 } | 57 } |
| 18 | 58 |
| 19 WebInspector.View.prototype = { | 59 WebInspector.SimpleView.prototype = { |
| 20 /** | 60 /** |
| 61 * @override | |
| 62 * @return {string} | |
| 63 */ | |
| 64 viewId: function() | |
| 65 { | |
| 66 return this._title; | |
| 67 }, | |
| 68 | |
| 69 /** | |
| 70 * @override | |
| 21 * @return {string} | 71 * @return {string} |
| 22 */ | 72 */ |
| 23 title: function() | 73 title: function() |
| 24 { | 74 { |
| 25 return this._title; | 75 return this._title; |
| 26 }, | 76 }, |
| 27 | 77 |
| 28 /** | 78 /** |
| 79 * @override | |
| 80 * @return {boolean} | |
| 81 */ | |
| 82 isCloseable: function() | |
| 83 { | |
| 84 return false; | |
| 85 }, | |
| 86 | |
| 87 /** | |
| 88 * @override | |
| 89 * @return {boolean} | |
| 90 */ | |
| 91 isTransient: function() | |
| 92 { | |
| 93 return false; | |
| 94 }, | |
| 95 | |
| 96 /** | |
| 97 * @override | |
| 98 * @return {!Promise<!Array<!WebInspector.ToolbarItem>>} | |
| 99 */ | |
| 100 toolbarItems: function() | |
| 101 { | |
| 102 return Promise.resolve(this._toolbarItems); | |
|
dgozman
2016/08/05 01:32:09
this.syncToolbarItems()
| |
| 103 }, | |
| 104 | |
| 105 /** | |
| 106 * @return {!Array<!WebInspector.ToolbarItem>} | |
| 107 */ | |
| 108 syncToolbarItems: function() | |
| 109 { | |
| 110 return this._toolbarItems; | |
| 111 }, | |
| 112 | |
| 113 /** | |
| 114 * @override | |
| 115 * @return {!Promise<!WebInspector.Widget>} | |
| 116 */ | |
| 117 widget: function() | |
| 118 { | |
| 119 return /** @type {!Promise<!WebInspector.Widget>} */ (Promise.resolve(th is)); | |
| 120 }, | |
| 121 | |
| 122 /** | |
| 29 * @param {!WebInspector.ToolbarItem} item | 123 * @param {!WebInspector.ToolbarItem} item |
| 30 */ | 124 */ |
| 31 addToolbarItem: function(item) | 125 addToolbarItem: function(item) |
| 32 { | 126 { |
| 33 this._toolbarItems.push(item); | 127 this._toolbarItems.push(item); |
| 34 }, | 128 }, |
| 35 | 129 |
| 36 /** | |
| 37 * @return {!Array<!WebInspector.ToolbarItem>} | |
| 38 */ | |
| 39 toolbarItems: function() | |
| 40 { | |
| 41 return this._toolbarItems; | |
| 42 }, | |
| 43 | |
| 44 __proto__: WebInspector.VBox.prototype | 130 __proto__: WebInspector.VBox.prototype |
| 45 } | 131 } |
| 46 | 132 |
| 47 /** | 133 /** |
| 134 * @constructor | |
| 135 * @implements {WebInspector.View} | |
| 136 * @param {!Runtime.Extension} extension | |
| 137 */ | |
| 138 WebInspector.ProvidedView = function(extension) | |
| 139 { | |
| 140 this._extension = extension; | |
| 141 } | |
| 142 | |
| 143 WebInspector.ProvidedView.prototype = { | |
| 144 /** | |
| 145 * @override | |
| 146 * @return {string} | |
| 147 */ | |
| 148 viewId: function() | |
| 149 { | |
| 150 return this._extension.descriptor()["id"]; | |
| 151 }, | |
| 152 | |
| 153 /** | |
| 154 * @override | |
| 155 * @return {string} | |
| 156 */ | |
| 157 title: function() | |
| 158 { | |
| 159 return this._extension.title(); | |
| 160 }, | |
| 161 | |
| 162 /** | |
| 163 * @override | |
| 164 * @return {boolean} | |
| 165 */ | |
| 166 isCloseable: function() | |
| 167 { | |
| 168 return this._extension.descriptor()["persistence"] === "closeable"; | |
| 169 }, | |
| 170 | |
| 171 /** | |
| 172 * @override | |
| 173 * @return {boolean} | |
| 174 */ | |
| 175 isTransient: function() | |
| 176 { | |
| 177 return this._extension.descriptor()["persistence"] === "transient"; | |
| 178 }, | |
| 179 | |
| 180 /** | |
| 181 * @override | |
| 182 * @return {!Promise<!Array<!WebInspector.ToolbarItem>>} | |
| 183 */ | |
| 184 toolbarItems: function() | |
| 185 { | |
| 186 return Promise.resolve([]); | |
| 187 }, | |
| 188 | |
| 189 /** | |
| 190 * @override | |
| 191 * @return {!Promise<!WebInspector.Widget>} | |
| 192 */ | |
| 193 widget: function() | |
| 194 { | |
| 195 return /** @type {!Promise<!WebInspector.Widget>} */ (this._extension.i nstance()); | |
| 196 } | |
| 197 } | |
| 198 | |
| 199 /** | |
| 48 * @interface | 200 * @interface |
| 49 */ | 201 */ |
| 50 WebInspector.ViewLocation = function() { } | 202 WebInspector.ViewLocation = function() { } |
| 51 | 203 |
| 52 WebInspector.ViewLocation.prototype = { | 204 WebInspector.ViewLocation.prototype = { |
| 53 /** | 205 /** |
| 54 * @param {string} viewId | 206 * @param {!WebInspector.View} view |
| 55 */ | 207 */ |
| 56 showView: function(viewId) { }, | 208 appendView: function(view) { }, |
| 209 | |
| 210 /** | |
| 211 * @param {!WebInspector.View} view | |
| 212 */ | |
| 213 showView: function(view) { }, | |
| 57 | 214 |
| 58 /** | 215 /** |
| 59 * @return {!WebInspector.Widget} | 216 * @return {!WebInspector.Widget} |
| 60 */ | 217 */ |
| 61 widget: function() { } | 218 widget: function() { } |
| 62 } | 219 } |
| 63 | 220 |
| 64 /** | 221 /** |
| 65 * @interface | 222 * @interface |
| 66 * @extends {WebInspector.ViewLocation} | 223 * @extends {WebInspector.ViewLocation} |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 85 * @return {?WebInspector.ViewLocation} | 242 * @return {?WebInspector.ViewLocation} |
| 86 */ | 243 */ |
| 87 revealLocation: function(location) { } | 244 revealLocation: function(location) { } |
| 88 } | 245 } |
| 89 | 246 |
| 90 /** | 247 /** |
| 91 * @constructor | 248 * @constructor |
| 92 */ | 249 */ |
| 93 WebInspector.ViewManager = function() | 250 WebInspector.ViewManager = function() |
| 94 { | 251 { |
| 252 /** @type {!Map<string, !WebInspector.View>} */ | |
| 253 this._views = new Map(); | |
| 254 /** @type {!Map<string, string>} */ | |
| 255 this._locations = new Map(); | |
|
dgozman
2016/08/05 01:32:09
_locationIdByViewId
| |
| 256 | |
| 257 for (var extension of self.runtime.extensions("view")) { | |
| 258 var descriptor = extension.descriptor(); | |
| 259 this._views.set(descriptor["id"], new WebInspector.ProvidedView(extensio n)); | |
| 260 this._locations.set(descriptor["id"], descriptor["location"]); | |
| 261 } | |
| 95 } | 262 } |
| 96 | 263 |
| 97 WebInspector.ViewManager.prototype = { | 264 WebInspector.ViewManager.prototype = { |
| 265 | |
|
dgozman
2016/08/05 01:32:09
nit: extra blank line
| |
| 98 /** | 266 /** |
| 99 * @param {string} viewId | 267 * @param {string} viewId |
| 100 */ | 268 */ |
| 101 showView: function(viewId) | 269 showView: function(viewId) |
| 102 { | 270 { |
| 103 var extensions = self.runtime.extensions("view").filter(extension => ext ension.descriptor()["id"] === viewId); | 271 var view = this._views.get(viewId); |
| 104 if (!extensions.length) { | 272 if (!view) { |
| 105 console.error("Could not find view for id: '" + viewId + "'"); | 273 console.error("Could not find view for id: '" + viewId + "'"); |
| 106 return; | 274 return; |
| 107 } | 275 } |
| 108 var extension = extensions[0]; | 276 var location = this._locations.get(viewId); |
| 109 var location = extensions[0].descriptor()["location"]; | 277 if (!location) { |
|
dgozman
2016/08/05 01:32:09
Can just assert since _locations and _views share
| |
| 278 console.error("Could not find location for id: '" + viewId + "'"); | |
| 279 return; | |
| 280 } | |
| 110 if (location === "drawer-view") | 281 if (location === "drawer-view") |
| 111 WebInspector.userMetrics.drawerShown(viewId); | 282 WebInspector.userMetrics.drawerShown(viewId); |
| 283 | |
| 112 var resolverExtensions = self.runtime.extensions(WebInspector.ViewLocati onResolver).filter(extension => extension.descriptor()["name"] === location); | 284 var resolverExtensions = self.runtime.extensions(WebInspector.ViewLocati onResolver).filter(extension => extension.descriptor()["name"] === location); |
| 113 if (!resolverExtensions.length) | 285 if (!resolverExtensions.length) |
| 114 return; | 286 return; |
| 115 var resolverExtension = resolverExtensions[0]; | 287 var resolverExtension = resolverExtensions[0]; |
| 116 resolverExtension.instance().then(this._revealLocation.bind(this, viewId , location)); | 288 resolverExtension.instance().then(this._revealLocation.bind(this, view, location)); |
| 117 }, | 289 }, |
| 118 | 290 |
| 119 /** | 291 /** |
| 120 * @param {string} location | 292 * @param {string=} location |
| 121 * @param {boolean=} restoreSelection | 293 * @param {boolean=} restoreSelection |
| 122 * @param {boolean=} enableMoreTabsButton | 294 * @param {boolean=} enableMoreTabsButton |
| 123 * @return {!WebInspector.TabbedViewLocation} | 295 * @return {!WebInspector.TabbedViewLocation} |
| 124 */ | 296 */ |
| 125 createTabbedLocation: function(location, restoreSelection, enableMoreTabsBut ton) | 297 createTabbedLocation: function(location, restoreSelection, enableMoreTabsBut ton) |
| 126 { | 298 { |
| 127 return new WebInspector.ViewManager._TabbedLocation(this, location, rest oreSelection, enableMoreTabsButton); | 299 return new WebInspector.ViewManager._TabbedLocation(this, location, rest oreSelection, enableMoreTabsButton); |
| 128 }, | 300 }, |
| 129 | 301 |
| 130 /** | 302 /** |
| 131 * @param {string} viewId | 303 * @param {string=} location |
| 304 * @return {!WebInspector.ViewLocation} | |
| 305 */ | |
| 306 createStackLocation: function(location) | |
| 307 { | |
| 308 return new WebInspector.ViewManager._StackLocation(this, location); | |
| 309 }, | |
| 310 | |
| 311 /** | |
| 312 * @param {!WebInspector.View} view | |
| 132 * @param {string} location | 313 * @param {string} location |
| 133 * @param {!WebInspector.ViewLocationResolver} resolver | 314 * @param {!WebInspector.ViewLocationResolver} resolver |
| 134 */ | 315 */ |
| 135 _revealLocation: function(viewId, location, resolver) | 316 _revealLocation: function(view, location, resolver) |
| 136 { | 317 { |
| 137 var viewLocation = resolver.revealLocation(location); | 318 var viewLocation = resolver.revealLocation(location); |
| 138 if (viewLocation) | 319 if (viewLocation) |
| 139 viewLocation.showView(viewId); | 320 viewLocation.showView(view); |
| 140 }, | 321 }, |
| 141 | 322 |
| 142 /** | 323 /** |
| 143 * @param {string} location | 324 * @param {string} location |
| 144 * @return {!Array<!Runtime.Extension>} | 325 * @return {!Array<!WebInspector.View>} |
| 145 */ | 326 */ |
| 146 _viewsForLocation: function(location) | 327 _viewsForLocation: function(location) |
| 147 { | 328 { |
| 148 return self.runtime.extensions("view").filter(extension => extension.des criptor()["location"] === location); | 329 var result = []; |
| 330 for (var id of this._views.keys()) { | |
| 331 if (this._locations.get(id) === location) | |
| 332 result.push(this._views.get(id)); | |
| 333 } | |
| 334 return result; | |
| 149 } | 335 } |
| 150 } | 336 } |
| 151 | 337 |
| 152 /** | 338 /** |
| 153 * @constructor | 339 * @constructor |
| 340 * @extends {WebInspector.VBox} | |
| 341 * @param {!WebInspector.View} view | |
| 342 */ | |
| 343 WebInspector.ViewManager._ContainerWidget = function(view) | |
| 344 { | |
| 345 WebInspector.VBox.call(this); | |
| 346 this.element.classList.add("flex-auto", "view-container", "overflow-auto"); | |
| 347 this._view = view; | |
| 348 } | |
| 349 | |
| 350 WebInspector.ViewManager._ContainerWidget.prototype = { | |
| 351 /** | |
| 352 * @return {!Promise<!WebInspector.Widget>} | |
| 353 */ | |
| 354 _materialize: function() | |
| 355 { | |
| 356 if (this._materializePromise) | |
| 357 return this._materializePromise; | |
| 358 var promises = []; | |
| 359 promises.push(this._view.toolbarItems().then(toolbarItems => { | |
|
dgozman
2016/08/05 01:32:09
style: named function please
| |
| 360 if (toolbarItems.length) { | |
| 361 var toolbar = new WebInspector.Toolbar("", this.element); | |
| 362 for (var item of toolbarItems) | |
| 363 toolbar.appendToolbarItem(item); | |
| 364 } | |
| 365 })); | |
| 366 promises.push(this._view.widget().then(widget => widget.show(this.elemen t))); | |
| 367 this._materializePromise = Promise.all(promises).then(() => this); | |
| 368 return this._materializePromise; | |
| 369 }, | |
| 370 | |
| 371 __proto__: WebInspector.VBox.prototype | |
| 372 } | |
| 373 | |
| 374 /** | |
| 375 * @constructor | |
| 376 * @extends {WebInspector.VBox} | |
| 377 * @param {!WebInspector.View} view | |
| 378 */ | |
| 379 WebInspector.ViewManager._ExpandableContainerWidget = function(view) | |
| 380 { | |
| 381 WebInspector.VBox.call(this, true); | |
| 382 this.element.classList.add("flex-none"); | |
| 383 this.registerRequiredCSS("ui/viewContainers.css"); | |
| 384 | |
| 385 this._titleElement = createElementWithClass("div", "expandable-view-title"); | |
| 386 this._titleElement.textContent = view.title(); | |
| 387 this._titleElement.tabIndex = 0; | |
| 388 this._titleElement.addEventListener("click", this._toggleExpanded.bind(this) , false); | |
| 389 this._titleElement.addEventListener("keydown", this._onTitleKeyDown.bind(thi s), false); | |
| 390 this.contentElement.insertBefore(this._titleElement, this.contentElement.fir stChild); | |
| 391 | |
| 392 this.contentElement.createChild("content"); | |
| 393 this._view = view; | |
| 394 } | |
| 395 | |
| 396 WebInspector.ViewManager._ExpandableContainerWidget.prototype = { | |
| 397 /** | |
| 398 * @return {!Promise<!WebInspector.Widget>} | |
| 399 */ | |
| 400 _materialize: function() | |
|
dgozman
2016/08/05 01:32:09
All this boilerplate code...
| |
| 401 { | |
| 402 if (this._materializePromise) | |
| 403 return this._materializePromise; | |
| 404 var promises = []; | |
| 405 promises.push(this._view.toolbarItems().then(toolbarItems => { | |
| 406 if (toolbarItems.length) { | |
| 407 var toolbar = new WebInspector.Toolbar("", this._titleElement); | |
| 408 for (var item of toolbarItems) | |
| 409 toolbar.appendToolbarItem(item); | |
| 410 } | |
| 411 })); | |
| 412 promises.push(this._view.widget().then(widget => { | |
| 413 this._widget = widget; | |
| 414 widget.show(this.element); | |
| 415 })); | |
| 416 this._materializePromise = Promise.all(promises).then(() => this); | |
| 417 return this._materializePromise; | |
| 418 }, | |
| 419 | |
| 420 _expand: function() | |
| 421 { | |
| 422 if (this._titleElement.classList.contains("expanded")) | |
| 423 return; | |
| 424 this._titleElement.classList.add("expanded"); | |
| 425 this._materialize().then(() => this._widget.show(this.element)); | |
| 426 }, | |
| 427 | |
| 428 _collapse: function() | |
| 429 { | |
| 430 if (!this._titleElement.classList.contains("expanded")) | |
| 431 return; | |
| 432 this._titleElement.classList.remove("expanded"); | |
| 433 this._materialize().then(() => this._widget.detach()); | |
| 434 }, | |
| 435 | |
| 436 _toggleExpanded: function() | |
| 437 { | |
| 438 if (this._titleElement.classList.contains("expanded")) | |
| 439 this._collapse(); | |
| 440 else | |
| 441 this._expand(); | |
| 442 }, | |
| 443 | |
| 444 /** | |
| 445 * @param {!Event} event | |
| 446 */ | |
| 447 _onTitleKeyDown: function(event) | |
| 448 { | |
| 449 if (isEnterKey(event) || event.keyCode === WebInspector.KeyboardShortcut .Keys.Space.code) | |
| 450 this._toggleExpanded(); | |
| 451 }, | |
| 452 | |
| 453 __proto__: WebInspector.VBox.prototype | |
| 454 } | |
| 455 | |
| 456 /** | |
| 457 * @constructor | |
| 154 * @implements {WebInspector.TabbedViewLocation} | 458 * @implements {WebInspector.TabbedViewLocation} |
| 155 * @param {!WebInspector.ViewManager} manager | 459 * @param {!WebInspector.ViewManager} manager |
| 156 * @param {string} location | 460 * @param {string=} location |
| 157 * @param {boolean=} restoreSelection | 461 * @param {boolean=} restoreSelection |
| 158 * @param {boolean=} enableMoreTabsButton | 462 * @param {boolean=} enableMoreTabsButton |
| 159 */ | 463 */ |
| 160 WebInspector.ViewManager._TabbedLocation = function(manager, location, restoreSe lection, enableMoreTabsButton) | 464 WebInspector.ViewManager._TabbedLocation = function(manager, location, restoreSe lection, enableMoreTabsButton) |
| 161 { | 465 { |
| 162 this._manager = manager; | 466 this._manager = manager; |
| 163 this._tabbedPane = new WebInspector.TabbedPane(); | 467 this._tabbedPane = new WebInspector.TabbedPane(); |
| 164 this._location = location; | 468 this._location = location; |
| 165 /** @type {!Object.<string, !Promise.<?WebInspector.Widget>>} */ | 469 /** @type {!Object.<string, !Promise>} */ |
| 166 this._promiseForId = {}; | 470 this._promiseForId = {}; |
| 167 | 471 |
| 168 this._tabbedPane.addEventListener(WebInspector.TabbedPane.EventTypes.TabSele cted, this._tabSelected, this); | 472 this._tabbedPane.addEventListener(WebInspector.TabbedPane.EventTypes.TabSele cted, this._tabSelected, this); |
| 169 this._tabbedPane.addEventListener(WebInspector.TabbedPane.EventTypes.TabClos ed, this._tabClosed, this); | 473 this._tabbedPane.addEventListener(WebInspector.TabbedPane.EventTypes.TabClos ed, this._tabClosed, this); |
| 170 this._closeableTabSetting = WebInspector.settings.createSetting(location + " -closeableTabs", {}); | 474 this._closeableTabSetting = WebInspector.settings.createSetting(location + " -closeableTabs", {}); |
| 171 if (restoreSelection) | 475 if (restoreSelection) |
| 172 this._lastSelectedTabSetting = WebInspector.settings.createSetting(locat ion + "-selectedTab", ""); | 476 this._lastSelectedTabSetting = WebInspector.settings.createSetting(locat ion + "-selectedTab", ""); |
| 173 this._initialize(); | 477 |
| 478 /** @type {!Map.<string, !WebInspector.View>} */ | |
| 479 this._views = new Map(); | |
| 480 this._populateLocation(); | |
| 481 | |
| 174 if (enableMoreTabsButton) { | 482 if (enableMoreTabsButton) { |
| 175 var toolbar = new WebInspector.Toolbar("drawer-toolbar"); | 483 var toolbar = new WebInspector.Toolbar("drawer-toolbar"); |
| 176 toolbar.appendToolbarItem(new WebInspector.ToolbarMenuButton(this._appen dTabsToMenu.bind(this))); | 484 toolbar.appendToolbarItem(new WebInspector.ToolbarMenuButton(this._appen dTabsToMenu.bind(this))); |
| 177 this._tabbedPane.insertBeforeTabStrip(toolbar.element); | 485 this._tabbedPane.insertBeforeTabStrip(toolbar.element); |
| 178 this._tabbedPane.disableOverflowMenu(); | 486 this._tabbedPane.disableOverflowMenu(); |
| 179 } | 487 } |
| 180 } | 488 } |
| 181 | 489 |
| 182 WebInspector.ViewManager._TabbedLocation.prototype = { | 490 WebInspector.ViewManager._TabbedLocation.prototype = { |
| 183 /** | 491 /** |
| 184 * @override | 492 * @override |
| 185 * @return {!WebInspector.Widget} | 493 * @return {!WebInspector.Widget} |
| 186 */ | 494 */ |
| 187 widget: function() | 495 widget: function() |
| 188 { | 496 { |
| 189 return this._tabbedPane; | 497 return this._tabbedPane; |
| 190 }, | 498 }, |
| 191 | 499 |
| 192 /** | 500 /** |
| 193 * @override | 501 * @override |
| 194 * @return {!WebInspector.TabbedPane} | 502 * @return {!WebInspector.TabbedPane} |
| 195 */ | 503 */ |
| 196 tabbedPane: function() | 504 tabbedPane: function() |
| 197 { | 505 { |
| 198 return this._tabbedPane; | 506 return this._tabbedPane; |
| 199 }, | 507 }, |
| 200 | 508 |
| 201 _initialize: function() | 509 _populateLocation: function() |
| 202 { | 510 { |
| 203 /** @type {!Map.<string, !Runtime.Extension>} */ | 511 if (!this._location) |
| 204 this._extensions = new Map(); | 512 return; |
| 205 var extensions = this._manager._viewsForLocation(this._location); | 513 for (var view of this._manager._viewsForLocation(this._location)) { |
| 206 | 514 var id = view.viewId(); |
| 207 for (var i = 0; i < extensions.length; ++i) { | 515 this._views.set(id, view); |
| 208 var id = extensions[i].descriptor()["id"]; | 516 if (view.isTransient()) |
| 209 this._extensions.set(id, extensions[i]); | 517 continue; |
| 210 if (this._isPermanentTab(id)) | 518 if (!view.isCloseable()) |
| 211 this._appendTab(extensions[i]); | 519 this._appendTab(view); |
| 212 else if (this._isCloseableTab(id) && this._closeableTabSetting.get() [id]) | 520 else if (this._closeableTabSetting.get()[id]) |
| 213 this._appendTab(extensions[i]); | 521 this._appendTab(view); |
| 214 } | 522 } |
| 215 }, | 523 }, |
| 216 | 524 |
| 217 wasShown: function() | 525 wasShown: function() |
| 218 { | 526 { |
| 219 if (this._wasAlreadyShown || !this._lastSelectedTabSetting) | 527 if (this._wasAlreadyShown || !this._lastSelectedTabSetting) |
| 220 return; | 528 return; |
| 221 this._wasAlreadyShown = true; | 529 this._wasAlreadyShown = true; |
| 222 if (this._tabbedPane.hasTab(this._lastSelectedTabSetting.get())) | 530 if (this._tabbedPane.hasTab(this._lastSelectedTabSetting.get())) |
| 223 this._tabbedPane.selectTab(this._lastSelectedTabSetting.get()); | 531 this._tabbedPane.selectTab(this._lastSelectedTabSetting.get()); |
| 224 }, | 532 }, |
| 225 | 533 |
| 226 /** | 534 /** |
| 227 * @param {string} id | |
| 228 * @return {boolean} | |
| 229 */ | |
| 230 _isPermanentTab: function(id) | |
| 231 { | |
| 232 return this._extensions.get(id).descriptor()["persistence"] === "permane nt" || !this._extensions.get(id).descriptor()["persistence"]; | |
| 233 }, | |
| 234 | |
| 235 /** | |
| 236 * @param {string} id | |
| 237 * @return {boolean} | |
| 238 */ | |
| 239 _isCloseableTab: function(id) | |
| 240 { | |
| 241 return this._extensions.get(id).descriptor()["persistence"] === "closeab le"; | |
| 242 }, | |
| 243 | |
| 244 /** | |
| 245 * @param {!WebInspector.ContextMenu} contextMenu | 535 * @param {!WebInspector.ContextMenu} contextMenu |
| 246 */ | 536 */ |
| 247 _appendTabsToMenu: function(contextMenu) | 537 _appendTabsToMenu: function(contextMenu) |
| 248 { | 538 { |
| 249 var extensions = self.runtime.extensions("view", undefined, true); | 539 for (var view of this._views.values()) { |
| 250 for (var extension of extensions) { | 540 var title = WebInspector.UIString(view.title()); |
| 251 if (extension.descriptor()["location"] !== this._location) | 541 contextMenu.appendItem(title, this.showView.bind(this, view)); |
| 252 continue; | |
| 253 var title = WebInspector.UIString(extension.title()); | |
| 254 contextMenu.appendItem(title, this.showView.bind(this, extension.des criptor()["id"])); | |
| 255 } | 542 } |
| 256 }, | 543 }, |
| 257 | 544 |
| 258 /** | 545 /** |
| 259 * @param {!Runtime.Extension} extension | 546 * @param {!WebInspector.View} view |
| 260 */ | 547 */ |
| 261 _appendTab: function(extension) | 548 _appendTab: function(view) |
| 262 { | 549 { |
| 263 var descriptor = extension.descriptor(); | 550 this._tabbedPane.appendTab(view.viewId(), view.title(), new WebInspector .Widget(), undefined, false, view.isCloseable() || view.isTransient()); |
| 264 var id = descriptor["id"]; | |
| 265 var title = WebInspector.UIString(extension.title()); | |
| 266 var closeable = descriptor["persistence"] === "closeable" || descriptor[ "persistence"] === "temporary"; | |
| 267 this._tabbedPane.appendTab(id, title, new WebInspector.Widget(), undefin ed, false, closeable); | |
| 268 }, | 551 }, |
| 269 | 552 |
| 270 /** | 553 /** |
| 271 * @override | 554 * @override |
| 272 * @param {string} id | 555 * @param {!WebInspector.View} view |
| 273 */ | 556 */ |
| 274 showView: function(id) | 557 appendView: function(view) |
| 275 { | 558 { |
| 276 if (!this._tabbedPane.hasTab(id)) | 559 if (!this._tabbedPane.hasTab(view.viewId())) { |
|
dgozman
2016/08/05 01:32:09
Who calls it twice for the same id?
| |
| 277 this._appendTab(/** @type {!Runtime.Extension} */(this._extensions.g et(id))); | 560 this._views.set(view.viewId(), view); |
| 278 this._tabbedPane.focus(); | 561 this._appendTab(view); |
| 279 this._tabbedPane.selectTab(id); | 562 } |
| 280 }, | 563 }, |
| 281 | 564 |
| 282 /** | 565 /** |
| 566 * @override | |
| 567 * @param {!WebInspector.View} view | |
| 568 */ | |
| 569 showView: function(view) | |
| 570 { | |
| 571 if (!this._tabbedPane.hasTab(view.viewId())) | |
| 572 this._appendTab(view); | |
| 573 this._tabbedPane.focus(); | |
| 574 this._tabbedPane.selectTab(view.viewId()); | |
| 575 }, | |
| 576 | |
| 577 /** | |
| 283 * @param {!WebInspector.Event} event | 578 * @param {!WebInspector.Event} event |
| 284 */ | 579 */ |
| 285 _tabSelected: function(event) | 580 _tabSelected: function(event) |
| 286 { | 581 { |
| 287 var tabId = /** @type {string} */ (event.data.tabId); | 582 var tabId = /** @type {string} */ (event.data.tabId); |
| 288 if (this._lastSelectedTabSetting && event.data["isUserGesture"]) | 583 if (this._lastSelectedTabSetting && event.data["isUserGesture"]) |
| 289 this._lastSelectedTabSetting.set(tabId); | 584 this._lastSelectedTabSetting.set(tabId); |
| 290 if (!this._extensions.has(tabId)) | 585 var view = this._views.get(tabId); |
| 586 if (!view) | |
| 291 return; | 587 return; |
| 292 | 588 |
| 293 this._viewForId(tabId); | 589 this._materializeWidget(view); |
| 294 | 590 |
| 295 var descriptor = this._extensions.get(tabId).descriptor(); | 591 if (view.isCloseable()) { |
| 296 if (descriptor["persistence"] === "closeable") { | |
| 297 var tabs = this._closeableTabSetting.get(); | 592 var tabs = this._closeableTabSetting.get(); |
| 298 if (!tabs[tabId]) { | 593 if (!tabs[tabId]) { |
| 299 tabs[tabId] = true; | 594 tabs[tabId] = true; |
| 300 this._closeableTabSetting.set(tabs); | 595 this._closeableTabSetting.set(tabs); |
| 301 } | 596 } |
| 302 } | 597 } |
| 303 }, | 598 }, |
| 304 | 599 |
| 305 /** | 600 /** |
| 306 * @param {!WebInspector.Event} event | 601 * @param {!WebInspector.Event} event |
| 307 */ | 602 */ |
| 308 _tabClosed: function(event) | 603 _tabClosed: function(event) |
| 309 { | 604 { |
| 310 var id = /** @type {string} */ (event.data["tabId"]); | 605 var id = /** @type {string} */ (event.data["tabId"]); |
| 311 var tabs = this._closeableTabSetting.get(); | 606 var tabs = this._closeableTabSetting.get(); |
| 312 if (tabs[id]) { | 607 if (tabs[id]) { |
| 313 delete tabs[id]; | 608 delete tabs[id]; |
| 314 this._closeableTabSetting.set(tabs); | 609 this._closeableTabSetting.set(tabs); |
| 315 } | 610 } |
| 316 delete this._promiseForId[id]; | 611 delete this._promiseForId[id]; |
| 317 }, | 612 }, |
| 318 | 613 |
| 319 /** | 614 /** |
| 320 * @param {string} id | 615 * @param {!WebInspector.View} view |
| 321 * @return {!Promise.<?WebInspector.Widget>} | |
| 322 */ | 616 */ |
| 323 _viewForId: function(id) | 617 _materializeWidget: function(view) |
| 324 { | 618 { |
| 325 if (this._promiseForId[id]) | 619 if (this._promiseForId[view.viewId()]) |
| 326 return this._promiseForId[id]; | 620 return; |
| 327 | 621 |
| 328 var promise = this._extensions.get(id).instance(); | 622 var widget = new WebInspector.ViewManager._ContainerWidget(view); |
| 329 this._promiseForId[id] = /** @type {!Promise.<?WebInspector.Widget>} */ (promise); | 623 var promise = widget._materialize().then(() => { |
| 330 return promise.then(cacheView.bind(this)); | 624 this._tabbedPane.changeTabView(view.viewId(), widget); |
| 331 | 625 }); |
| 332 /** | 626 this._promiseForId[view.viewId()] = promise; |
| 333 * @param {!Object} object | |
| 334 * @this {WebInspector.ViewManager._TabbedLocation} | |
| 335 */ | |
| 336 function cacheView(object) | |
| 337 { | |
| 338 var view = /** @type {!WebInspector.Widget} */ (object); | |
| 339 this._tabbedPane.changeTabView(id, view); | |
| 340 return view; | |
| 341 } | |
| 342 } | 627 } |
| 343 } | 628 } |
| 344 | 629 |
| 345 WebInspector.viewManager = new WebInspector.ViewManager(); | 630 /** |
| 631 * @constructor | |
| 632 * @implements {WebInspector.ViewLocation} | |
| 633 * @param {!WebInspector.ViewManager} manager | |
| 634 * @param {string=} location | |
| 635 */ | |
| 636 WebInspector.ViewManager._StackLocation = function(manager, location) | |
| 637 { | |
| 638 this._manager = manager; | |
| 639 this._location = location; | |
| 640 this._vbox = new WebInspector.VBox(); | |
| 641 /** @type {!Map<string, !WebInspector.ViewManager._ExpandableContainerWidget >} */ | |
| 642 this._expandableContainers = new Map(); | |
| 643 this._populateLocation(); | |
| 644 } | |
| 645 | |
| 646 WebInspector.ViewManager._StackLocation.prototype = { | |
| 647 /** | |
| 648 * @override | |
| 649 * @return {!WebInspector.Widget} | |
| 650 */ | |
| 651 widget: function() | |
| 652 { | |
| 653 return this._vbox; | |
| 654 }, | |
| 655 | |
| 656 /** | |
| 657 * @override | |
| 658 * @param {!WebInspector.View} view | |
| 659 */ | |
| 660 appendView: function(view) | |
| 661 { | |
| 662 var container = this._expandableContainers.get(view.viewId()); | |
| 663 if (!container) { | |
|
dgozman
2016/08/05 01:32:09
Let's move this if to showView, and don't call app
pfeldman
2016/08/05 04:42:16
We need it for appendView.
| |
| 664 container = new WebInspector.ViewManager._ExpandableContainerWidget( view); | |
| 665 container.show(this._vbox.contentElement); | |
| 666 this._expandableContainers.set(view.viewId(), container); | |
| 667 } | |
| 668 }, | |
| 669 | |
| 670 /** | |
| 671 * @override | |
| 672 * @param {!WebInspector.View} view | |
| 673 */ | |
| 674 showView: function(view) | |
| 675 { | |
| 676 this.appendView(view); | |
| 677 var container = this._expandableContainers.get(view.viewId()); | |
| 678 container._expand(); | |
| 679 }, | |
| 680 | |
| 681 _populateLocation: function() | |
| 682 { | |
| 683 if (!this._location) | |
| 684 return; | |
| 685 for (var view of this._manager._viewsForLocation(this._location)) | |
| 686 this.appendView(view); | |
| 687 } | |
| 688 } | |
| 689 | |
| 690 /** | |
| 691 * @type {!WebInspector.ViewManager} | |
| 692 */ | |
| 693 WebInspector.viewManager; | |
| OLD | NEW |