| 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 * @constructor | 6 * @constructor |
| 7 * @extends {WebInspector.VBox} | 7 * @extends {WebInspector.VBox} |
| 8 * @param {string} title | 8 * @param {string} title |
| 9 * @param {boolean=} isWebComponent | 9 * @param {boolean=} isWebComponent |
| 10 */ | 10 */ |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 | 46 |
| 47 /** | 47 /** |
| 48 * @interface | 48 * @interface |
| 49 */ | 49 */ |
| 50 WebInspector.ViewLocation = function() { } | 50 WebInspector.ViewLocation = function() { } |
| 51 | 51 |
| 52 WebInspector.ViewLocation.prototype = { | 52 WebInspector.ViewLocation.prototype = { |
| 53 /** | 53 /** |
| 54 * @param {string} viewId | 54 * @param {string} viewId |
| 55 */ | 55 */ |
| 56 showView: function(viewId) { } | 56 showView: function(viewId) { }, |
| 57 |
| 58 /** |
| 59 * @return {!WebInspector.Widget} |
| 60 */ |
| 61 widget: function() { } |
| 57 } | 62 } |
| 58 | 63 |
| 59 /** | 64 /** |
| 65 * @interface |
| 66 * @extends {WebInspector.ViewLocation} |
| 67 */ |
| 68 WebInspector.TabbedViewLocation = function() { } |
| 69 |
| 70 WebInspector.TabbedViewLocation.prototype = { |
| 71 /** |
| 72 * @return {!WebInspector.TabbedPane} |
| 73 */ |
| 74 tabbedPane: function() { }, |
| 75 } |
| 76 |
| 77 /** |
| 60 * @interface | 78 * @interface |
| 61 */ | 79 */ |
| 62 WebInspector.ViewLocationResolver = function() { } | 80 WebInspector.ViewLocationResolver = function() { } |
| 63 | 81 |
| 64 WebInspector.ViewLocationResolver.prototype = { | 82 WebInspector.ViewLocationResolver.prototype = { |
| 65 /** | 83 /** |
| 66 * @param {string} locationName | 84 * @param {string} location |
| 67 * @return {?WebInspector.ViewLocation} | 85 * @return {?WebInspector.ViewLocation} |
| 68 */ | 86 */ |
| 69 resolveLocation: function(locationName) { } | 87 revealLocation: function(location) { } |
| 70 } | 88 } |
| 71 | 89 |
| 72 /** | 90 /** |
| 73 * @constructor | 91 * @constructor |
| 74 */ | 92 */ |
| 75 WebInspector.ViewManager = function() | 93 WebInspector.ViewManager = function() |
| 76 { | 94 { |
| 77 } | 95 } |
| 78 | 96 |
| 79 WebInspector.ViewManager.prototype = { | 97 WebInspector.ViewManager.prototype = { |
| 80 /** | 98 /** |
| 81 * @param {string} viewId | 99 * @param {string} viewId |
| 82 */ | 100 */ |
| 83 showView: function(viewId) | 101 showView: function(viewId) |
| 84 { | 102 { |
| 85 var extensions = self.runtime.extensions("view").filter(extension => ext
ension.descriptor()["id"] === viewId); | 103 var extensions = self.runtime.extensions("view").filter(extension => ext
ension.descriptor()["id"] === viewId); |
| 86 if (!extensions.length) { | 104 if (!extensions.length) { |
| 87 console.error("Could not find view for id: '" + viewId + "'"); | 105 console.error("Could not find view for id: '" + viewId + "'"); |
| 88 return; | 106 return; |
| 89 } | 107 } |
| 90 var extension = extensions[0]; | 108 var extension = extensions[0]; |
| 91 var location = extensions[0].descriptor()["location"]; | 109 var location = extensions[0].descriptor()["location"]; |
| 92 if (location === "drawer-view") | 110 if (location === "drawer-view") |
| 93 WebInspector.userMetrics.drawerShown(viewId); | 111 WebInspector.userMetrics.drawerShown(viewId); |
| 94 var resolverExtensions = self.runtime.extensions(WebInspector.ViewLocati
onResolver).filter(extension => extension.descriptor()["name"] === location); | 112 var resolverExtensions = self.runtime.extensions(WebInspector.ViewLocati
onResolver).filter(extension => extension.descriptor()["name"] === location); |
| 95 if (!resolverExtensions.length) | 113 if (!resolverExtensions.length) |
| 96 return; | 114 return; |
| 97 var resolverExtension = resolverExtensions[0]; | 115 var resolverExtension = resolverExtensions[0]; |
| 98 resolverExtension.instance().then(this._resolveLocation.bind(this, viewI
d, location)); | 116 resolverExtension.instance().then(this._revealLocation.bind(this, viewId
, location)); |
| 99 }, | 117 }, |
| 100 | 118 |
| 101 /** | 119 /** |
| 120 * @param {string} location |
| 121 * @param {boolean=} restoreSelection |
| 122 * @param {boolean=} enableMoreTabsButton |
| 123 * @return {!WebInspector.TabbedViewLocation} |
| 124 */ |
| 125 createTabbedLocation: function(location, restoreSelection, enableMoreTabsBut
ton) |
| 126 { |
| 127 return new WebInspector.ViewManager._TabbedLocation(this, location, rest
oreSelection, enableMoreTabsButton); |
| 128 }, |
| 129 |
| 130 /** |
| 102 * @param {string} viewId | 131 * @param {string} viewId |
| 103 * @param {string} location | 132 * @param {string} location |
| 104 * @param {!WebInspector.ViewLocationResolver} resolver | 133 * @param {!WebInspector.ViewLocationResolver} resolver |
| 105 */ | 134 */ |
| 106 _resolveLocation: function(viewId, location, resolver) | 135 _revealLocation: function(viewId, location, resolver) |
| 107 { | 136 { |
| 108 var viewLocation = resolver.resolveLocation(location); | 137 var viewLocation = resolver.revealLocation(location); |
| 109 if (viewLocation) | 138 if (viewLocation) |
| 110 viewLocation.showView(viewId); | 139 viewLocation.showView(viewId); |
| 140 }, |
| 141 |
| 142 /** |
| 143 * @param {string} location |
| 144 * @return {!Array<!Runtime.Extension>} |
| 145 */ |
| 146 _viewsForLocation: function(location) |
| 147 { |
| 148 return self.runtime.extensions("view").filter(extension => extension.des
criptor()["location"] === location); |
| 111 } | 149 } |
| 112 } | 150 } |
| 113 | 151 |
| 114 WebInspector.viewManager = new WebInspector.ViewManager(); | 152 /** |
| 153 * @constructor |
| 154 * @implements {WebInspector.TabbedViewLocation} |
| 155 * @param {!WebInspector.ViewManager} manager |
| 156 * @param {string} location |
| 157 * @param {boolean=} restoreSelection |
| 158 * @param {boolean=} enableMoreTabsButton |
| 159 */ |
| 160 WebInspector.ViewManager._TabbedLocation = function(manager, location, restoreSe
lection, enableMoreTabsButton) |
| 161 { |
| 162 this._manager = manager; |
| 163 this._tabbedPane = new WebInspector.TabbedPane(); |
| 164 this._location = location; |
| 165 /** @type {!Object.<string, !Promise.<?WebInspector.Widget>>} */ |
| 166 this._promiseForId = {}; |
| 167 |
| 168 this._tabbedPane.addEventListener(WebInspector.TabbedPane.EventTypes.TabSele
cted, this._tabSelected, this); |
| 169 this._tabbedPane.addEventListener(WebInspector.TabbedPane.EventTypes.TabClos
ed, this._tabClosed, this); |
| 170 this._closeableTabSetting = WebInspector.settings.createSetting(location + "
-closeableTabs", {}); |
| 171 if (restoreSelection) |
| 172 this._lastSelectedTabSetting = WebInspector.settings.createSetting(locat
ion + "-selectedTab", ""); |
| 173 this._initialize(); |
| 174 if (enableMoreTabsButton) { |
| 175 var toolbar = new WebInspector.Toolbar("drawer-toolbar"); |
| 176 toolbar.appendToolbarItem(new WebInspector.ToolbarMenuButton(this._appen
dTabsToMenu.bind(this))); |
| 177 this._tabbedPane.insertBeforeTabStrip(toolbar.element); |
| 178 this._tabbedPane.disableOverflowMenu(); |
| 179 } |
| 180 } |
| 181 |
| 182 WebInspector.ViewManager._TabbedLocation.prototype = { |
| 183 /** |
| 184 * @override |
| 185 * @return {!WebInspector.Widget} |
| 186 */ |
| 187 widget: function() |
| 188 { |
| 189 return this._tabbedPane; |
| 190 }, |
| 191 |
| 192 /** |
| 193 * @override |
| 194 * @return {!WebInspector.TabbedPane} |
| 195 */ |
| 196 tabbedPane: function() |
| 197 { |
| 198 return this._tabbedPane; |
| 199 }, |
| 200 |
| 201 _initialize: function() |
| 202 { |
| 203 /** @type {!Map.<string, !Runtime.Extension>} */ |
| 204 this._extensions = new Map(); |
| 205 var extensions = this._manager._viewsForLocation(this._location); |
| 206 |
| 207 for (var i = 0; i < extensions.length; ++i) { |
| 208 var id = extensions[i].descriptor()["id"]; |
| 209 this._extensions.set(id, extensions[i]); |
| 210 if (this._isPermanentTab(id)) |
| 211 this._appendTab(extensions[i]); |
| 212 else if (this._isCloseableTab(id) && this._closeableTabSetting.get()
[id]) |
| 213 this._appendTab(extensions[i]); |
| 214 } |
| 215 }, |
| 216 |
| 217 wasShown: function() |
| 218 { |
| 219 if (this._wasAlreadyShown || !this._lastSelectedTabSetting) |
| 220 return; |
| 221 this._wasAlreadyShown = true; |
| 222 if (this._tabbedPane.hasTab(this._lastSelectedTabSetting.get())) |
| 223 this._tabbedPane.selectTab(this._lastSelectedTabSetting.get()); |
| 224 }, |
| 225 |
| 226 /** |
| 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 |
| 246 */ |
| 247 _appendTabsToMenu: function(contextMenu) |
| 248 { |
| 249 var extensions = self.runtime.extensions("view", undefined, true); |
| 250 for (var extension of extensions) { |
| 251 if (extension.descriptor()["location"] !== this._location) |
| 252 continue; |
| 253 var title = WebInspector.UIString(extension.title()); |
| 254 contextMenu.appendItem(title, this.showView.bind(this, extension.des
criptor()["id"])); |
| 255 } |
| 256 }, |
| 257 |
| 258 /** |
| 259 * @param {!Runtime.Extension} extension |
| 260 */ |
| 261 _appendTab: function(extension) |
| 262 { |
| 263 var descriptor = extension.descriptor(); |
| 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 }, |
| 269 |
| 270 /** |
| 271 * @override |
| 272 * @param {string} id |
| 273 */ |
| 274 showView: function(id) |
| 275 { |
| 276 if (!this._tabbedPane.hasTab(id)) |
| 277 this._appendTab(/** @type {!Runtime.Extension} */(this._extensions.g
et(id))); |
| 278 this._tabbedPane.focus(); |
| 279 this._tabbedPane.selectTab(id); |
| 280 }, |
| 281 |
| 282 /** |
| 283 * @param {!WebInspector.Event} event |
| 284 */ |
| 285 _tabSelected: function(event) |
| 286 { |
| 287 var tabId = /** @type {string} */ (event.data.tabId); |
| 288 if (this._lastSelectedTabSetting && event.data["isUserGesture"]) |
| 289 this._lastSelectedTabSetting.set(tabId); |
| 290 if (!this._extensions.has(tabId)) |
| 291 return; |
| 292 |
| 293 this._viewForId(tabId); |
| 294 |
| 295 var descriptor = this._extensions.get(tabId).descriptor(); |
| 296 if (descriptor["persistence"] === "closeable") { |
| 297 var tabs = this._closeableTabSetting.get(); |
| 298 if (!tabs[tabId]) { |
| 299 tabs[tabId] = true; |
| 300 this._closeableTabSetting.set(tabs); |
| 301 } |
| 302 } |
| 303 }, |
| 304 |
| 305 /** |
| 306 * @param {!WebInspector.Event} event |
| 307 */ |
| 308 _tabClosed: function(event) |
| 309 { |
| 310 var id = /** @type {string} */ (event.data["tabId"]); |
| 311 var tabs = this._closeableTabSetting.get(); |
| 312 if (tabs[id]) { |
| 313 delete tabs[id]; |
| 314 this._closeableTabSetting.set(tabs); |
| 315 } |
| 316 delete this._promiseForId[id]; |
| 317 }, |
| 318 |
| 319 /** |
| 320 * @param {string} id |
| 321 * @return {!Promise.<?WebInspector.Widget>} |
| 322 */ |
| 323 _viewForId: function(id) |
| 324 { |
| 325 if (this._promiseForId[id]) |
| 326 return this._promiseForId[id]; |
| 327 |
| 328 var promise = this._extensions.get(id).instance(); |
| 329 this._promiseForId[id] = /** @type {!Promise.<?WebInspector.Widget>} */
(promise); |
| 330 return promise.then(cacheView.bind(this)); |
| 331 |
| 332 /** |
| 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 } |
| 343 } |
| 344 |
| 345 WebInspector.viewManager = new WebInspector.ViewManager(); |
| OLD | NEW |