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 | |
5 /** | 4 /** |
6 * @interface | 5 * @interface |
7 */ | 6 */ |
8 WebInspector.View = function() | 7 WebInspector.View = function() {}; |
9 { | |
10 }; | |
11 | 8 |
12 WebInspector.View.prototype = { | 9 WebInspector.View.prototype = { |
13 /** | 10 /** |
14 * @return {string} | 11 * @return {string} |
15 */ | 12 */ |
16 viewId: function() { }, | 13 viewId: function() {}, |
17 | 14 |
18 /** | 15 /** |
19 * @return {string} | 16 * @return {string} |
20 */ | 17 */ |
21 title: function() { }, | 18 title: function() {}, |
22 | 19 |
23 /** | 20 /** |
24 * @return {boolean} | 21 * @return {boolean} |
25 */ | 22 */ |
26 isCloseable: function() { }, | 23 isCloseable: function() {}, |
27 | 24 |
28 /** | 25 /** |
29 * @return {boolean} | 26 * @return {boolean} |
30 */ | 27 */ |
31 isTransient: function() { }, | 28 isTransient: function() {}, |
32 | 29 |
33 /** | 30 /** |
34 * @return {!Promise<!Array<!WebInspector.ToolbarItem>>} | 31 * @return {!Promise<!Array<!WebInspector.ToolbarItem>>} |
35 */ | 32 */ |
36 toolbarItems: function() { }, | 33 toolbarItems: function() {}, |
37 | 34 |
38 /** | 35 /** |
39 * @return {!Promise<!WebInspector.Widget>} | 36 * @return {!Promise<!WebInspector.Widget>} |
40 */ | 37 */ |
41 widget: function() { } | 38 widget: function() {} |
42 }; | 39 }; |
43 | 40 |
44 WebInspector.View._symbol = Symbol("view"); | 41 WebInspector.View._symbol = Symbol('view'); |
45 WebInspector.View._widgetSymbol = Symbol("widget"); | 42 WebInspector.View._widgetSymbol = Symbol('widget'); |
46 | 43 |
47 /** | 44 /** |
48 * @constructor | |
49 * @extends {WebInspector.VBox} | |
50 * @implements {WebInspector.View} | 45 * @implements {WebInspector.View} |
51 * @param {string} title | 46 * @unrestricted |
52 * @param {boolean=} isWebComponent | 47 */ |
53 */ | 48 WebInspector.SimpleView = class extends WebInspector.VBox { |
54 WebInspector.SimpleView = function(title, isWebComponent) | 49 /** |
55 { | 50 * @param {string} title |
56 WebInspector.VBox.call(this, isWebComponent); | 51 * @param {boolean=} isWebComponent |
| 52 */ |
| 53 constructor(title, isWebComponent) { |
| 54 super(isWebComponent); |
57 this._title = title; | 55 this._title = title; |
58 /** @type {!Array<!WebInspector.ToolbarItem>} */ | 56 /** @type {!Array<!WebInspector.ToolbarItem>} */ |
59 this._toolbarItems = []; | 57 this._toolbarItems = []; |
60 this[WebInspector.View._symbol] = this; | 58 this[WebInspector.View._symbol] = this; |
61 }; | 59 } |
62 | 60 |
63 WebInspector.SimpleView.prototype = { | 61 /** |
64 /** | 62 * @override |
65 * @override | 63 * @return {string} |
66 * @return {string} | 64 */ |
67 */ | 65 viewId() { |
68 viewId: function() | 66 return this._title; |
69 { | 67 } |
70 return this._title; | 68 |
71 }, | 69 /** |
72 | 70 * @override |
73 /** | 71 * @return {string} |
74 * @override | 72 */ |
75 * @return {string} | 73 title() { |
76 */ | 74 return this._title; |
77 title: function() | 75 } |
78 { | 76 |
79 return this._title; | 77 /** |
80 }, | 78 * @override |
81 | 79 * @return {boolean} |
82 /** | 80 */ |
83 * @override | 81 isCloseable() { |
84 * @return {boolean} | 82 return false; |
85 */ | 83 } |
86 isCloseable: function() | 84 |
87 { | 85 /** |
88 return false; | 86 * @override |
89 }, | 87 * @return {boolean} |
90 | 88 */ |
91 /** | 89 isTransient() { |
92 * @override | 90 return false; |
93 * @return {boolean} | 91 } |
94 */ | 92 |
95 isTransient: function() | 93 /** |
96 { | 94 * @override |
97 return false; | 95 * @return {!Promise<!Array<!WebInspector.ToolbarItem>>} |
98 }, | 96 */ |
99 | 97 toolbarItems() { |
100 /** | 98 return Promise.resolve(this.syncToolbarItems()); |
101 * @override | 99 } |
102 * @return {!Promise<!Array<!WebInspector.ToolbarItem>>} | 100 |
103 */ | 101 /** |
104 toolbarItems: function() | 102 * @return {!Array<!WebInspector.ToolbarItem>} |
105 { | 103 */ |
106 return Promise.resolve(this.syncToolbarItems()); | 104 syncToolbarItems() { |
107 }, | 105 return this._toolbarItems; |
108 | 106 } |
109 /** | 107 |
110 * @return {!Array<!WebInspector.ToolbarItem>} | 108 /** |
111 */ | 109 * @override |
112 syncToolbarItems: function() | 110 * @return {!Promise<!WebInspector.Widget>} |
113 { | 111 */ |
114 return this._toolbarItems; | 112 widget() { |
115 }, | 113 return /** @type {!Promise<!WebInspector.Widget>} */ (Promise.resolve(this))
; |
116 | 114 } |
117 /** | 115 |
118 * @override | 116 /** |
119 * @return {!Promise<!WebInspector.Widget>} | 117 * @param {!WebInspector.ToolbarItem} item |
120 */ | 118 */ |
121 widget: function() | 119 addToolbarItem(item) { |
122 { | 120 this._toolbarItems.push(item); |
123 return /** @type {!Promise<!WebInspector.Widget>} */ (Promise.resolve(th
is)); | 121 } |
124 }, | 122 |
125 | 123 /** |
126 /** | 124 * @return {!Promise} |
127 * @param {!WebInspector.ToolbarItem} item | 125 */ |
128 */ | 126 revealView() { |
129 addToolbarItem: function(item) | 127 return WebInspector.viewManager.revealView(this); |
130 { | 128 } |
131 this._toolbarItems.push(item); | 129 }; |
132 }, | 130 |
133 | 131 /** |
134 /** | |
135 * @return {!Promise} | |
136 */ | |
137 revealView: function() | |
138 { | |
139 return WebInspector.viewManager.revealView(this); | |
140 }, | |
141 | |
142 __proto__: WebInspector.VBox.prototype | |
143 }; | |
144 | |
145 /** | |
146 * @constructor | |
147 * @implements {WebInspector.View} | 132 * @implements {WebInspector.View} |
148 * @param {!Runtime.Extension} extension | 133 * @unrestricted |
149 */ | 134 */ |
150 WebInspector.ProvidedView = function(extension) | 135 WebInspector.ProvidedView = class { |
151 { | 136 /** |
| 137 * @param {!Runtime.Extension} extension |
| 138 */ |
| 139 constructor(extension) { |
152 this._extension = extension; | 140 this._extension = extension; |
153 }; | 141 } |
154 | 142 |
155 WebInspector.ProvidedView.prototype = { | 143 /** |
156 /** | 144 * @override |
157 * @override | 145 * @return {string} |
158 * @return {string} | 146 */ |
159 */ | 147 viewId() { |
160 viewId: function() | 148 return this._extension.descriptor()['id']; |
161 { | 149 } |
162 return this._extension.descriptor()["id"]; | 150 |
163 }, | 151 /** |
164 | 152 * @override |
165 /** | 153 * @return {string} |
166 * @override | 154 */ |
167 * @return {string} | 155 title() { |
168 */ | 156 return this._extension.title(); |
169 title: function() | 157 } |
170 { | 158 |
171 return this._extension.title(); | 159 /** |
172 }, | 160 * @override |
173 | 161 * @return {boolean} |
174 /** | 162 */ |
175 * @override | 163 isCloseable() { |
176 * @return {boolean} | 164 return this._extension.descriptor()['persistence'] === 'closeable'; |
177 */ | 165 } |
178 isCloseable: function() | 166 |
179 { | 167 /** |
180 return this._extension.descriptor()["persistence"] === "closeable"; | 168 * @override |
181 }, | 169 * @return {boolean} |
182 | 170 */ |
183 /** | 171 isTransient() { |
184 * @override | 172 return this._extension.descriptor()['persistence'] === 'transient'; |
185 * @return {boolean} | 173 } |
186 */ | 174 |
187 isTransient: function() | 175 /** |
188 { | 176 * @override |
189 return this._extension.descriptor()["persistence"] === "transient"; | 177 * @return {!Promise<!Array<!WebInspector.ToolbarItem>>} |
190 }, | 178 */ |
191 | 179 toolbarItems() { |
192 /** | 180 var actionIds = this._extension.descriptor()['actionIds']; |
193 * @override | 181 if (actionIds) { |
194 * @return {!Promise<!Array<!WebInspector.ToolbarItem>>} | 182 var result = []; |
195 */ | 183 for (var id of actionIds.split(',')) { |
196 toolbarItems: function() | 184 var item = WebInspector.Toolbar.createActionButtonForId(id.trim()); |
197 { | 185 if (item) |
198 var actionIds = this._extension.descriptor()["actionIds"]; | 186 result.push(item); |
199 if (actionIds) { | 187 } |
200 var result = []; | 188 return Promise.resolve(result); |
201 for (var id of actionIds.split(",")) { | 189 } |
202 var item = WebInspector.Toolbar.createActionButtonForId(id.trim(
)); | 190 |
203 if (item) | 191 if (this._extension.descriptor()['hasToolbar']) |
204 result.push(item); | 192 return this.widget().then( |
205 } | 193 widget => /** @type {!WebInspector.ToolbarItem.ItemsProvider} */ (widg
et).toolbarItems()); |
206 return Promise.resolve(result); | 194 return Promise.resolve([]); |
207 } | 195 } |
208 | 196 |
209 if (this._extension.descriptor()["hasToolbar"]) | 197 /** |
210 return this.widget().then(widget => /** @type {!WebInspector.Toolbar
Item.ItemsProvider} */ (widget).toolbarItems()); | 198 * @override |
211 return Promise.resolve([]); | 199 * @return {!Promise<!WebInspector.Widget>} |
212 }, | 200 */ |
213 | 201 widget() { |
214 /** | 202 return this._extension.instance().then(widget => { |
215 * @override | 203 if (!(widget instanceof WebInspector.Widget)) |
216 * @return {!Promise<!WebInspector.Widget>} | 204 throw new Error('view className should point to a WebInspector.Widget'); |
217 */ | 205 widget[WebInspector.View._symbol] = this; |
218 widget: function() | 206 return /** @type {!WebInspector.Widget} */ (widget); |
219 { | 207 }); |
220 return this._extension.instance().then(widget => { | 208 } |
221 if (!(widget instanceof WebInspector.Widget)) | |
222 throw new Error("view className should point to a WebInspector.W
idget"); | |
223 widget[WebInspector.View._symbol] = this; | |
224 return /** @type {!WebInspector.Widget} */ (widget); | |
225 }); | |
226 } | |
227 }; | 209 }; |
228 | 210 |
229 /** | 211 /** |
230 * @interface | 212 * @interface |
231 */ | 213 */ |
232 WebInspector.ViewLocation = function() { }; | 214 WebInspector.ViewLocation = function() {}; |
233 | 215 |
234 WebInspector.ViewLocation.prototype = { | 216 WebInspector.ViewLocation.prototype = { |
235 /** | 217 /** |
236 * @param {string} locationName | 218 * @param {string} locationName |
237 */ | 219 */ |
238 appendApplicableItems: function(locationName) { }, | 220 appendApplicableItems: function(locationName) {}, |
239 | 221 |
240 /** | 222 /** |
241 * @param {!WebInspector.View} view | 223 * @param {!WebInspector.View} view |
242 * @param {?WebInspector.View=} insertBefore | 224 * @param {?WebInspector.View=} insertBefore |
243 */ | 225 */ |
244 appendView: function(view, insertBefore) { }, | 226 appendView: function(view, insertBefore) {}, |
245 | 227 |
246 /** | 228 /** |
247 * @param {!WebInspector.View} view | 229 * @param {!WebInspector.View} view |
248 * @param {?WebInspector.View=} insertBefore | 230 * @param {?WebInspector.View=} insertBefore |
249 * @return {!Promise} | 231 * @return {!Promise} |
250 */ | 232 */ |
251 showView: function(view, insertBefore) { }, | 233 showView: function(view, insertBefore) {}, |
252 | 234 |
253 /** | 235 /** |
254 * @param {!WebInspector.View} view | 236 * @param {!WebInspector.View} view |
255 */ | 237 */ |
256 removeView: function(view) { }, | 238 removeView: function(view) {}, |
257 | 239 |
258 /** | 240 /** |
259 * @return {!WebInspector.Widget} | 241 * @return {!WebInspector.Widget} |
260 */ | 242 */ |
261 widget: function() { } | 243 widget: function() {} |
262 }; | 244 }; |
263 | 245 |
264 /** | 246 /** |
265 * @interface | 247 * @interface |
266 * @extends {WebInspector.ViewLocation} | 248 * @extends {WebInspector.ViewLocation} |
267 */ | 249 */ |
268 WebInspector.TabbedViewLocation = function() { }; | 250 WebInspector.TabbedViewLocation = function() {}; |
269 | 251 |
270 WebInspector.TabbedViewLocation.prototype = { | 252 WebInspector.TabbedViewLocation.prototype = { |
271 /** | 253 /** |
272 * @return {!WebInspector.TabbedPane} | 254 * @return {!WebInspector.TabbedPane} |
273 */ | 255 */ |
274 tabbedPane: function() { }, | 256 tabbedPane: function() {}, |
275 | 257 |
276 enableMoreTabsButton: function() { } | 258 enableMoreTabsButton: function() {} |
277 }; | 259 }; |
278 | 260 |
279 /** | 261 /** |
280 * @interface | 262 * @interface |
281 */ | 263 */ |
282 WebInspector.ViewLocationResolver = function() { }; | 264 WebInspector.ViewLocationResolver = function() {}; |
283 | 265 |
284 WebInspector.ViewLocationResolver.prototype = { | 266 WebInspector.ViewLocationResolver.prototype = { |
285 /** | 267 /** |
286 * @param {string} location | 268 * @param {string} location |
287 * @return {?WebInspector.ViewLocation} | 269 * @return {?WebInspector.ViewLocation} |
288 */ | 270 */ |
289 resolveLocation: function(location) { } | 271 resolveLocation: function(location) {} |
290 }; | 272 }; |
291 | 273 |
292 /** | 274 /** |
293 * @constructor | 275 * @unrestricted |
294 */ | 276 */ |
295 WebInspector.ViewManager = function() | 277 WebInspector.ViewManager = class { |
296 { | 278 constructor() { |
297 /** @type {!Map<string, !WebInspector.View>} */ | 279 /** @type {!Map<string, !WebInspector.View>} */ |
298 this._views = new Map(); | 280 this._views = new Map(); |
299 /** @type {!Map<string, string>} */ | 281 /** @type {!Map<string, string>} */ |
300 this._locationNameByViewId = new Map(); | 282 this._locationNameByViewId = new Map(); |
301 | 283 |
302 for (var extension of self.runtime.extensions("view")) { | 284 for (var extension of self.runtime.extensions('view')) { |
303 var descriptor = extension.descriptor(); | 285 var descriptor = extension.descriptor(); |
304 this._views.set(descriptor["id"], new WebInspector.ProvidedView(extensio
n)); | 286 this._views.set(descriptor['id'], new WebInspector.ProvidedView(extension)
); |
305 this._locationNameByViewId.set(descriptor["id"], descriptor["location"])
; | 287 this._locationNameByViewId.set(descriptor['id'], descriptor['location']); |
306 } | 288 } |
307 }; | 289 } |
308 | 290 |
309 WebInspector.ViewManager.prototype = { | 291 /** |
310 /** | 292 * @param {!Element} element |
311 * @param {!WebInspector.View} view | 293 * @param {!Array<!WebInspector.ToolbarItem>} toolbarItems |
312 * @return {!Promise} | 294 */ |
313 */ | 295 static _populateToolbar(element, toolbarItems) { |
314 revealView: function(view) | |
315 { | |
316 var location = /** @type {?WebInspector.ViewManager._Location} */ (view[
WebInspector.ViewManager._Location.symbol]); | |
317 if (!location) | |
318 return Promise.resolve(); | |
319 location._reveal(); | |
320 return location.showView(view); | |
321 }, | |
322 | |
323 /** | |
324 * @param {string} viewId | |
325 * @return {?WebInspector.View} | |
326 */ | |
327 view: function(viewId) | |
328 { | |
329 return this._views.get(viewId); | |
330 }, | |
331 | |
332 /** | |
333 * @param {string} viewId | |
334 * @return {?WebInspector.Widget} | |
335 */ | |
336 materializedWidget: function(viewId) | |
337 { | |
338 var view = this.view(viewId); | |
339 return view ? view[WebInspector.View._widgetSymbol] : null; | |
340 }, | |
341 | |
342 /** | |
343 * @param {string} viewId | |
344 * @return {!Promise} | |
345 */ | |
346 showView: function(viewId) | |
347 { | |
348 var view = this._views.get(viewId); | |
349 if (!view) { | |
350 console.error("Could not find view for id: '" + viewId + "' " + new
Error().stack); | |
351 return Promise.resolve(); | |
352 } | |
353 | |
354 var locationName = this._locationNameByViewId.get(viewId); | |
355 if (locationName === "drawer-view") | |
356 WebInspector.userMetrics.drawerShown(viewId); | |
357 | |
358 var location = view[WebInspector.ViewManager._Location.symbol]; | |
359 if (location) { | |
360 location._reveal(); | |
361 return location.showView(view); | |
362 } | |
363 | |
364 return this._resolveLocation(locationName).then(location => { | |
365 if (!location) | |
366 throw new Error("Could not resolve location for view: " + viewId
); | |
367 location._reveal(); | |
368 return location.showView(view); | |
369 }); | |
370 }, | |
371 | |
372 /** | |
373 * @param {string=} location | |
374 * @return {!Promise<?WebInspector.ViewManager._Location>} | |
375 */ | |
376 _resolveLocation: function(location) | |
377 { | |
378 if (!location) | |
379 return /** @type {!Promise<?WebInspector.ViewManager._Location>} */
(Promise.resolve(null)); | |
380 | |
381 var resolverExtensions = self.runtime.extensions(WebInspector.ViewLocati
onResolver).filter(extension => extension.descriptor()["name"] === location); | |
382 if (!resolverExtensions.length) | |
383 throw new Error("Unresolved location: " + location); | |
384 var resolverExtension = resolverExtensions[0]; | |
385 return resolverExtension.instance().then(resolver => /** @type {?WebInsp
ector.ViewManager._Location} */(resolver.resolveLocation(location))); | |
386 }, | |
387 | |
388 /** | |
389 * @param {function()=} revealCallback | |
390 * @param {string=} location | |
391 * @param {boolean=} restoreSelection | |
392 * @param {boolean=} allowReorder | |
393 * @return {!WebInspector.TabbedViewLocation} | |
394 */ | |
395 createTabbedLocation: function(revealCallback, location, restoreSelection, a
llowReorder) | |
396 { | |
397 return new WebInspector.ViewManager._TabbedLocation(this, revealCallback
, location, restoreSelection, allowReorder); | |
398 }, | |
399 | |
400 /** | |
401 * @param {function()=} revealCallback | |
402 * @param {string=} location | |
403 * @return {!WebInspector.ViewLocation} | |
404 */ | |
405 createStackLocation: function(revealCallback, location) | |
406 { | |
407 return new WebInspector.ViewManager._StackLocation(this, revealCallback,
location); | |
408 }, | |
409 | |
410 /** | |
411 * @param {string} location | |
412 * @return {!Array<!WebInspector.View>} | |
413 */ | |
414 _viewsForLocation: function(location) | |
415 { | |
416 var result = []; | |
417 for (var id of this._views.keys()) { | |
418 if (this._locationNameByViewId.get(id) === location) | |
419 result.push(this._views.get(id)); | |
420 } | |
421 return result; | |
422 } | |
423 }; | |
424 | |
425 | |
426 /** | |
427 * @param {!Element} element | |
428 * @param {!Array<!WebInspector.ToolbarItem>} toolbarItems | |
429 */ | |
430 WebInspector.ViewManager._populateToolbar = function(element, toolbarItems) | |
431 { | |
432 if (!toolbarItems.length) | 296 if (!toolbarItems.length) |
433 return; | 297 return; |
434 var toolbar = new WebInspector.Toolbar(""); | 298 var toolbar = new WebInspector.Toolbar(''); |
435 element.insertBefore(toolbar.element, element.firstChild); | 299 element.insertBefore(toolbar.element, element.firstChild); |
436 for (var item of toolbarItems) | 300 for (var item of toolbarItems) |
437 toolbar.appendToolbarItem(item); | 301 toolbar.appendToolbarItem(item); |
438 }; | 302 } |
439 | 303 |
440 /** | 304 /** |
441 * @constructor | 305 * @param {!WebInspector.View} view |
442 * @extends {WebInspector.VBox} | 306 * @return {!Promise} |
443 * @param {!WebInspector.View} view | 307 */ |
444 */ | 308 revealView(view) { |
445 WebInspector.ViewManager._ContainerWidget = function(view) | 309 var location = /** @type {?WebInspector.ViewManager._Location} */ (view[WebI
nspector.ViewManager._Location.symbol]); |
446 { | 310 if (!location) |
447 WebInspector.VBox.call(this); | 311 return Promise.resolve(); |
448 this.element.classList.add("flex-auto", "view-container", "overflow-auto"); | 312 location._reveal(); |
| 313 return location.showView(view); |
| 314 } |
| 315 |
| 316 /** |
| 317 * @param {string} viewId |
| 318 * @return {?WebInspector.View} |
| 319 */ |
| 320 view(viewId) { |
| 321 return this._views.get(viewId); |
| 322 } |
| 323 |
| 324 /** |
| 325 * @param {string} viewId |
| 326 * @return {?WebInspector.Widget} |
| 327 */ |
| 328 materializedWidget(viewId) { |
| 329 var view = this.view(viewId); |
| 330 return view ? view[WebInspector.View._widgetSymbol] : null; |
| 331 } |
| 332 |
| 333 /** |
| 334 * @param {string} viewId |
| 335 * @return {!Promise} |
| 336 */ |
| 337 showView(viewId) { |
| 338 var view = this._views.get(viewId); |
| 339 if (!view) { |
| 340 console.error('Could not find view for id: \'' + viewId + '\' ' + new Erro
r().stack); |
| 341 return Promise.resolve(); |
| 342 } |
| 343 |
| 344 var locationName = this._locationNameByViewId.get(viewId); |
| 345 if (locationName === 'drawer-view') |
| 346 WebInspector.userMetrics.drawerShown(viewId); |
| 347 |
| 348 var location = view[WebInspector.ViewManager._Location.symbol]; |
| 349 if (location) { |
| 350 location._reveal(); |
| 351 return location.showView(view); |
| 352 } |
| 353 |
| 354 return this._resolveLocation(locationName).then(location => { |
| 355 if (!location) |
| 356 throw new Error('Could not resolve location for view: ' + viewId); |
| 357 location._reveal(); |
| 358 return location.showView(view); |
| 359 }); |
| 360 } |
| 361 |
| 362 /** |
| 363 * @param {string=} location |
| 364 * @return {!Promise<?WebInspector.ViewManager._Location>} |
| 365 */ |
| 366 _resolveLocation(location) { |
| 367 if (!location) |
| 368 return /** @type {!Promise<?WebInspector.ViewManager._Location>} */ (Promi
se.resolve(null)); |
| 369 |
| 370 var resolverExtensions = self.runtime.extensions(WebInspector.ViewLocationRe
solver) |
| 371 .filter(extension => extension.descriptor()['na
me'] === location); |
| 372 if (!resolverExtensions.length) |
| 373 throw new Error('Unresolved location: ' + location); |
| 374 var resolverExtension = resolverExtensions[0]; |
| 375 return resolverExtension.instance().then( |
| 376 resolver => /** @type {?WebInspector.ViewManager._Location} */ (resolver
.resolveLocation(location))); |
| 377 } |
| 378 |
| 379 /** |
| 380 * @param {function()=} revealCallback |
| 381 * @param {string=} location |
| 382 * @param {boolean=} restoreSelection |
| 383 * @param {boolean=} allowReorder |
| 384 * @return {!WebInspector.TabbedViewLocation} |
| 385 */ |
| 386 createTabbedLocation(revealCallback, location, restoreSelection, allowReorder)
{ |
| 387 return new WebInspector.ViewManager._TabbedLocation(this, revealCallback, lo
cation, restoreSelection, allowReorder); |
| 388 } |
| 389 |
| 390 /** |
| 391 * @param {function()=} revealCallback |
| 392 * @param {string=} location |
| 393 * @return {!WebInspector.ViewLocation} |
| 394 */ |
| 395 createStackLocation(revealCallback, location) { |
| 396 return new WebInspector.ViewManager._StackLocation(this, revealCallback, loc
ation); |
| 397 } |
| 398 |
| 399 /** |
| 400 * @param {string} location |
| 401 * @return {!Array<!WebInspector.View>} |
| 402 */ |
| 403 _viewsForLocation(location) { |
| 404 var result = []; |
| 405 for (var id of this._views.keys()) { |
| 406 if (this._locationNameByViewId.get(id) === location) |
| 407 result.push(this._views.get(id)); |
| 408 } |
| 409 return result; |
| 410 } |
| 411 }; |
| 412 |
| 413 |
| 414 /** |
| 415 * @unrestricted |
| 416 */ |
| 417 WebInspector.ViewManager._ContainerWidget = class extends WebInspector.VBox { |
| 418 /** |
| 419 * @param {!WebInspector.View} view |
| 420 */ |
| 421 constructor(view) { |
| 422 super(); |
| 423 this.element.classList.add('flex-auto', 'view-container', 'overflow-auto'); |
449 this._view = view; | 424 this._view = view; |
450 this.element.tabIndex = 0; | 425 this.element.tabIndex = 0; |
451 this.setDefaultFocusedElement(this.element); | 426 this.setDefaultFocusedElement(this.element); |
452 }; | 427 } |
453 | 428 |
454 WebInspector.ViewManager._ContainerWidget.prototype = { | 429 /** |
455 /** | 430 * @return {!Promise} |
456 * @return {!Promise} | 431 */ |
457 */ | 432 _materialize() { |
458 _materialize: function() | 433 if (this._materializePromise) |
459 { | 434 return this._materializePromise; |
460 if (this._materializePromise) | 435 var promises = []; |
461 return this._materializePromise; | 436 promises.push(this._view.toolbarItems().then( |
462 var promises = []; | 437 WebInspector.ViewManager._populateToolbar.bind(WebInspector.ViewManager,
this.element))); |
463 promises.push(this._view.toolbarItems().then(WebInspector.ViewManager._p
opulateToolbar.bind(WebInspector.ViewManager, this.element))); | 438 promises.push(this._view.widget().then(widget => { |
464 promises.push(this._view.widget().then(widget => { | 439 // Move focus from |this| to loaded |widget| if any. |
465 // Move focus from |this| to loaded |widget| if any. | 440 var shouldFocus = this.element.hasFocus(); |
466 var shouldFocus = this.element.hasFocus(); | 441 this.setDefaultFocusedElement(null); |
467 this.setDefaultFocusedElement(null); | 442 this._view[WebInspector.View._widgetSymbol] = widget; |
468 this._view[WebInspector.View._widgetSymbol] = widget; | 443 widget.show(this.element); |
469 widget.show(this.element); | 444 if (shouldFocus) |
470 if (shouldFocus) | 445 widget.focus(); |
471 widget.focus(); | 446 })); |
472 })); | 447 this._materializePromise = Promise.all(promises); |
473 this._materializePromise = Promise.all(promises); | 448 return this._materializePromise; |
474 return this._materializePromise; | 449 } |
475 }, | 450 }; |
476 | 451 |
477 __proto__: WebInspector.VBox.prototype | 452 /** |
478 }; | 453 * @unrestricted |
479 | 454 */ |
480 /** | 455 WebInspector.ViewManager._ExpandableContainerWidget = class extends WebInspector
.VBox { |
481 * @constructor | 456 /** |
482 * @extends {WebInspector.VBox} | 457 * @param {!WebInspector.View} view |
483 * @param {!WebInspector.View} view | 458 */ |
484 */ | 459 constructor(view) { |
485 WebInspector.ViewManager._ExpandableContainerWidget = function(view) | 460 super(true); |
486 { | 461 this.element.classList.add('flex-none'); |
487 WebInspector.VBox.call(this, true); | 462 this.registerRequiredCSS('ui/viewContainers.css'); |
488 this.element.classList.add("flex-none"); | 463 |
489 this.registerRequiredCSS("ui/viewContainers.css"); | 464 this._titleElement = createElementWithClass('div', 'expandable-view-title'); |
490 | |
491 this._titleElement = createElementWithClass("div", "expandable-view-title"); | |
492 this._titleElement.textContent = view.title(); | 465 this._titleElement.textContent = view.title(); |
493 this._titleElement.tabIndex = 0; | 466 this._titleElement.tabIndex = 0; |
494 this._titleElement.addEventListener("click", this._toggleExpanded.bind(this)
, false); | 467 this._titleElement.addEventListener('click', this._toggleExpanded.bind(this)
, false); |
495 this._titleElement.addEventListener("keydown", this._onTitleKeyDown.bind(thi
s), false); | 468 this._titleElement.addEventListener('keydown', this._onTitleKeyDown.bind(thi
s), false); |
496 this.contentElement.insertBefore(this._titleElement, this.contentElement.fir
stChild); | 469 this.contentElement.insertBefore(this._titleElement, this.contentElement.fir
stChild); |
497 | 470 |
498 this.contentElement.createChild("content"); | 471 this.contentElement.createChild('content'); |
499 this._view = view; | 472 this._view = view; |
500 view[WebInspector.ViewManager._ExpandableContainerWidget._symbol] = this; | 473 view[WebInspector.ViewManager._ExpandableContainerWidget._symbol] = this; |
501 }; | 474 } |
502 | 475 |
503 WebInspector.ViewManager._ExpandableContainerWidget._symbol = Symbol("container"
); | 476 /** |
504 | 477 * @return {!Promise} |
505 WebInspector.ViewManager._ExpandableContainerWidget.prototype = { | 478 */ |
506 /** | 479 _materialize() { |
507 * @return {!Promise} | 480 if (this._materializePromise) |
508 */ | 481 return this._materializePromise; |
509 _materialize: function() | 482 var promises = []; |
510 { | 483 promises.push(this._view.toolbarItems().then( |
511 if (this._materializePromise) | 484 WebInspector.ViewManager._populateToolbar.bind(WebInspector.ViewManager,
this._titleElement))); |
512 return this._materializePromise; | 485 promises.push(this._view.widget().then(widget => { |
513 var promises = []; | 486 this._widget = widget; |
514 promises.push(this._view.toolbarItems().then(WebInspector.ViewManager._p
opulateToolbar.bind(WebInspector.ViewManager, this._titleElement))); | 487 this._view[WebInspector.View._widgetSymbol] = widget; |
515 promises.push(this._view.widget().then(widget => { | 488 widget.show(this.element); |
516 this._widget = widget; | 489 })); |
517 this._view[WebInspector.View._widgetSymbol] = widget; | 490 this._materializePromise = Promise.all(promises); |
518 widget.show(this.element); | 491 return this._materializePromise; |
519 })); | 492 } |
520 this._materializePromise = Promise.all(promises); | 493 |
521 return this._materializePromise; | 494 /** |
522 }, | 495 * @return {!Promise} |
523 | 496 */ |
524 /** | 497 _expand() { |
525 * @return {!Promise} | 498 if (this._titleElement.classList.contains('expanded')) |
526 */ | 499 return this._materialize(); |
527 _expand: function() | 500 this._titleElement.classList.add('expanded'); |
528 { | 501 return this._materialize().then(() => this._widget.show(this.element)); |
529 if (this._titleElement.classList.contains("expanded")) | 502 } |
530 return this._materialize(); | 503 |
531 this._titleElement.classList.add("expanded"); | 504 _collapse() { |
532 return this._materialize().then(() => this._widget.show(this.element)); | 505 if (!this._titleElement.classList.contains('expanded')) |
533 }, | 506 return; |
534 | 507 this._titleElement.classList.remove('expanded'); |
535 _collapse: function() | 508 this._materialize().then(() => this._widget.detach()); |
536 { | 509 } |
537 if (!this._titleElement.classList.contains("expanded")) | 510 |
538 return; | 511 _toggleExpanded() { |
539 this._titleElement.classList.remove("expanded"); | 512 if (this._titleElement.classList.contains('expanded')) |
540 this._materialize().then(() => this._widget.detach()); | 513 this._collapse(); |
541 }, | 514 else |
542 | 515 this._expand(); |
543 _toggleExpanded: function() | 516 } |
544 { | 517 |
545 if (this._titleElement.classList.contains("expanded")) | 518 /** |
546 this._collapse(); | 519 * @param {!Event} event |
547 else | 520 */ |
548 this._expand(); | 521 _onTitleKeyDown(event) { |
549 }, | 522 if (isEnterKey(event) || event.keyCode === WebInspector.KeyboardShortcut.Key
s.Space.code) |
550 | 523 this._toggleExpanded(); |
551 /** | 524 } |
552 * @param {!Event} event | 525 }; |
553 */ | 526 |
554 _onTitleKeyDown: function(event) | 527 WebInspector.ViewManager._ExpandableContainerWidget._symbol = Symbol('container'
); |
555 { | 528 |
556 if (isEnterKey(event) || event.keyCode === WebInspector.KeyboardShortcut
.Keys.Space.code) | 529 /** |
557 this._toggleExpanded(); | 530 * @unrestricted |
558 }, | 531 */ |
559 | 532 WebInspector.ViewManager._Location = class { |
560 __proto__: WebInspector.VBox.prototype | 533 /** |
561 }; | 534 * @param {!WebInspector.ViewManager} manager |
562 | 535 * @param {!WebInspector.Widget} widget |
563 /** | 536 * @param {function()=} revealCallback |
564 * @constructor | 537 */ |
565 * @param {!WebInspector.ViewManager} manager | 538 constructor(manager, widget, revealCallback) { |
566 * @param {!WebInspector.Widget} widget | |
567 * @param {function()=} revealCallback | |
568 */ | |
569 WebInspector.ViewManager._Location = function(manager, widget, revealCallback) | |
570 { | |
571 this._manager = manager; | 539 this._manager = manager; |
572 this._revealCallback = revealCallback; | 540 this._revealCallback = revealCallback; |
573 this._widget = widget; | 541 this._widget = widget; |
574 }; | 542 } |
575 | 543 |
576 WebInspector.ViewManager._Location.symbol = Symbol("location"); | 544 /** |
577 | 545 * @return {!WebInspector.Widget} |
578 WebInspector.ViewManager._Location.prototype = { | 546 */ |
579 /** | 547 widget() { |
580 * @return {!WebInspector.Widget} | 548 return this._widget; |
581 */ | 549 } |
582 widget: function() | 550 |
583 { | 551 _reveal() { |
584 return this._widget; | 552 if (this._revealCallback) |
585 }, | 553 this._revealCallback(); |
586 | 554 } |
587 _reveal: function() | 555 }; |
588 { | 556 |
589 if (this._revealCallback) | 557 WebInspector.ViewManager._Location.symbol = Symbol('location'); |
590 this._revealCallback(); | 558 |
591 } | 559 /** |
592 }; | |
593 | |
594 /** | |
595 * @constructor | |
596 * @extends {WebInspector.ViewManager._Location} | |
597 * @implements {WebInspector.TabbedViewLocation} | 560 * @implements {WebInspector.TabbedViewLocation} |
598 * @param {!WebInspector.ViewManager} manager | 561 * @unrestricted |
599 * @param {function()=} revealCallback | 562 */ |
600 * @param {string=} location | 563 WebInspector.ViewManager._TabbedLocation = class extends WebInspector.ViewManage
r._Location { |
601 * @param {boolean=} restoreSelection | 564 /** |
602 * @param {boolean=} allowReorder | 565 * @param {!WebInspector.ViewManager} manager |
603 */ | 566 * @param {function()=} revealCallback |
604 WebInspector.ViewManager._TabbedLocation = function(manager, revealCallback, loc
ation, restoreSelection, allowReorder) | 567 * @param {string=} location |
605 { | 568 * @param {boolean=} restoreSelection |
| 569 * @param {boolean=} allowReorder |
| 570 */ |
| 571 constructor(manager, revealCallback, location, restoreSelection, allowReorder)
{ |
606 var tabbedPane = new WebInspector.TabbedPane(); | 572 var tabbedPane = new WebInspector.TabbedPane(); |
607 if (allowReorder) | 573 if (allowReorder) |
608 tabbedPane.setAllowTabReorder(true); | 574 tabbedPane.setAllowTabReorder(true); |
609 | 575 |
610 WebInspector.ViewManager._Location.call(this, manager, tabbedPane, revealCal
lback); | 576 super(manager, tabbedPane, revealCallback); |
611 this._tabbedPane = tabbedPane; | 577 this._tabbedPane = tabbedPane; |
612 this._allowReorder = allowReorder; | 578 this._allowReorder = allowReorder; |
613 | 579 |
614 this._tabbedPane.addEventListener(WebInspector.TabbedPane.Events.TabSelected
, this._tabSelected, this); | 580 this._tabbedPane.addEventListener(WebInspector.TabbedPane.Events.TabSelected
, this._tabSelected, this); |
615 this._tabbedPane.addEventListener(WebInspector.TabbedPane.Events.TabClosed,
this._tabClosed, this); | 581 this._tabbedPane.addEventListener(WebInspector.TabbedPane.Events.TabClosed,
this._tabClosed, this); |
616 this._closeableTabSetting = WebInspector.settings.createSetting(location + "
-closeableTabs", {}); | 582 this._closeableTabSetting = WebInspector.settings.createSetting(location + '
-closeableTabs', {}); |
617 this._tabOrderSetting = WebInspector.settings.createSetting(location + "-tab
Order", {}); | 583 this._tabOrderSetting = WebInspector.settings.createSetting(location + '-tab
Order', {}); |
618 this._tabbedPane.addEventListener(WebInspector.TabbedPane.Events.TabOrderCha
nged, this._persistTabOrder, this); | 584 this._tabbedPane.addEventListener(WebInspector.TabbedPane.Events.TabOrderCha
nged, this._persistTabOrder, this); |
619 if (restoreSelection) | 585 if (restoreSelection) |
620 this._lastSelectedTabSetting = WebInspector.settings.createSetting(locat
ion + "-selectedTab", ""); | 586 this._lastSelectedTabSetting = WebInspector.settings.createSetting(locatio
n + '-selectedTab', ''); |
621 | 587 |
622 /** @type {!Map.<string, !WebInspector.View>} */ | 588 /** @type {!Map.<string, !WebInspector.View>} */ |
623 this._views = new Map(); | 589 this._views = new Map(); |
624 | 590 |
625 if (location) | 591 if (location) |
626 this.appendApplicableItems(location); | 592 this.appendApplicableItems(location); |
| 593 } |
| 594 |
| 595 /** |
| 596 * @override |
| 597 * @return {!WebInspector.Widget} |
| 598 */ |
| 599 widget() { |
| 600 return this._tabbedPane; |
| 601 } |
| 602 |
| 603 /** |
| 604 * @override |
| 605 * @return {!WebInspector.TabbedPane} |
| 606 */ |
| 607 tabbedPane() { |
| 608 return this._tabbedPane; |
| 609 } |
| 610 |
| 611 /** |
| 612 * @override |
| 613 */ |
| 614 enableMoreTabsButton() { |
| 615 this._tabbedPane.leftToolbar().appendToolbarItem( |
| 616 new WebInspector.ToolbarMenuButton(this._appendTabsToMenu.bind(this))); |
| 617 this._tabbedPane.disableOverflowMenu(); |
| 618 } |
| 619 |
| 620 /** |
| 621 * @override |
| 622 * @param {string} locationName |
| 623 */ |
| 624 appendApplicableItems(locationName) { |
| 625 var views = this._manager._viewsForLocation(locationName); |
| 626 if (this._allowReorder) { |
| 627 var i = 0; |
| 628 var persistedOrders = this._tabOrderSetting.get(); |
| 629 var orders = new Map(); |
| 630 for (var view of views) |
| 631 orders.set( |
| 632 view.viewId(), |
| 633 persistedOrders[view.viewId()] || (++i) * WebInspector.ViewManager._
TabbedLocation.orderStep); |
| 634 views.sort((a, b) => orders.get(a.viewId()) - orders.get(b.viewId())); |
| 635 } |
| 636 |
| 637 for (var view of views) { |
| 638 var id = view.viewId(); |
| 639 this._views.set(id, view); |
| 640 view[WebInspector.ViewManager._Location.symbol] = this; |
| 641 if (view.isTransient()) |
| 642 continue; |
| 643 if (!view.isCloseable()) |
| 644 this._appendTab(view); |
| 645 else if (this._closeableTabSetting.get()[id]) |
| 646 this._appendTab(view); |
| 647 } |
| 648 if (this._lastSelectedTabSetting && this._tabbedPane.hasTab(this._lastSelect
edTabSetting.get())) |
| 649 this._tabbedPane.selectTab(this._lastSelectedTabSetting.get()); |
| 650 } |
| 651 |
| 652 /** |
| 653 * @param {!WebInspector.ContextMenu} contextMenu |
| 654 */ |
| 655 _appendTabsToMenu(contextMenu) { |
| 656 for (var view of this._views.values()) { |
| 657 var title = WebInspector.UIString(view.title()); |
| 658 contextMenu.appendItem(title, this.showView.bind(this, view)); |
| 659 } |
| 660 } |
| 661 |
| 662 /** |
| 663 * @param {!WebInspector.View} view |
| 664 * @param {number=} index |
| 665 */ |
| 666 _appendTab(view, index) { |
| 667 this._tabbedPane.appendTab( |
| 668 view.viewId(), view.title(), new WebInspector.ViewManager._ContainerWidg
et(view), undefined, false, |
| 669 view.isCloseable() || view.isTransient(), index); |
| 670 } |
| 671 |
| 672 /** |
| 673 * @override |
| 674 * @param {!WebInspector.View} view |
| 675 * @param {?WebInspector.View=} insertBefore |
| 676 */ |
| 677 appendView(view, insertBefore) { |
| 678 if (this._tabbedPane.hasTab(view.viewId())) |
| 679 return; |
| 680 view[WebInspector.ViewManager._Location.symbol] = this; |
| 681 this._manager._views.set(view.viewId(), view); |
| 682 this._views.set(view.viewId(), view); |
| 683 |
| 684 var index = undefined; |
| 685 var tabIds = this._tabbedPane.tabIds(); |
| 686 if (this._allowReorder) { |
| 687 var orderSetting = this._tabOrderSetting.get(); |
| 688 var order = orderSetting[view.viewId()]; |
| 689 for (var i = 0; order && i < tabIds.length; ++i) { |
| 690 if (orderSetting[tabIds[i]] && orderSetting[tabIds[i]] > order) { |
| 691 index = i; |
| 692 break; |
| 693 } |
| 694 } |
| 695 } else if (insertBefore) { |
| 696 for (var i = 0; i < tabIds.length; ++i) { |
| 697 if (tabIds[i] === insertBefore.viewId()) { |
| 698 index = i; |
| 699 break; |
| 700 } |
| 701 } |
| 702 } |
| 703 this._appendTab(view, index); |
| 704 } |
| 705 |
| 706 /** |
| 707 * @override |
| 708 * @param {!WebInspector.View} view |
| 709 * @param {?WebInspector.View=} insertBefore |
| 710 * @return {!Promise} |
| 711 */ |
| 712 showView(view, insertBefore) { |
| 713 this.appendView(view, insertBefore); |
| 714 this._tabbedPane.selectTab(view.viewId()); |
| 715 this._tabbedPane.focus(); |
| 716 return this._materializeWidget(view); |
| 717 } |
| 718 |
| 719 /** |
| 720 * @param {!WebInspector.View} view |
| 721 * @override |
| 722 */ |
| 723 removeView(view) { |
| 724 if (!this._tabbedPane.hasTab(view.viewId())) |
| 725 return; |
| 726 |
| 727 delete view[WebInspector.ViewManager._Location.symbol]; |
| 728 this._manager._views.delete(view.viewId()); |
| 729 this._views.delete(view.viewId()); |
| 730 this._tabbedPane.closeTab(view.viewId()); |
| 731 } |
| 732 |
| 733 /** |
| 734 * @param {!WebInspector.Event} event |
| 735 */ |
| 736 _tabSelected(event) { |
| 737 var tabId = /** @type {string} */ (event.data.tabId); |
| 738 if (this._lastSelectedTabSetting && event.data['isUserGesture']) |
| 739 this._lastSelectedTabSetting.set(tabId); |
| 740 var view = this._views.get(tabId); |
| 741 if (!view) |
| 742 return; |
| 743 |
| 744 this._materializeWidget(view); |
| 745 |
| 746 if (view.isCloseable()) { |
| 747 var tabs = this._closeableTabSetting.get(); |
| 748 if (!tabs[tabId]) { |
| 749 tabs[tabId] = true; |
| 750 this._closeableTabSetting.set(tabs); |
| 751 } |
| 752 } |
| 753 } |
| 754 |
| 755 /** |
| 756 * @param {!WebInspector.Event} event |
| 757 */ |
| 758 _tabClosed(event) { |
| 759 var id = /** @type {string} */ (event.data['tabId']); |
| 760 var tabs = this._closeableTabSetting.get(); |
| 761 if (tabs[id]) { |
| 762 delete tabs[id]; |
| 763 this._closeableTabSetting.set(tabs); |
| 764 } |
| 765 } |
| 766 |
| 767 /** |
| 768 * @param {!WebInspector.View} view |
| 769 * @return {!Promise} |
| 770 */ |
| 771 _materializeWidget(view) { |
| 772 var widget = /** @type {!WebInspector.ViewManager._ContainerWidget} */ (this
._tabbedPane.tabView(view.viewId())); |
| 773 return widget._materialize(); |
| 774 } |
| 775 |
| 776 /** |
| 777 * @param {!WebInspector.Event} event |
| 778 */ |
| 779 _persistTabOrder(event) { |
| 780 var tabIds = this._tabbedPane.tabIds(); |
| 781 var tabOrders = {}; |
| 782 for (var i = 0; i < tabIds.length; i++) |
| 783 tabOrders[tabIds[i]] = (i + 1) * WebInspector.ViewManager._TabbedLocation.
orderStep; |
| 784 this._tabOrderSetting.set(tabOrders); |
| 785 } |
627 }; | 786 }; |
628 | 787 |
629 WebInspector.ViewManager._TabbedLocation.orderStep = 10; // Keep in sync with d
escriptors. | 788 WebInspector.ViewManager._TabbedLocation.orderStep = 10; // Keep in sync with d
escriptors. |
630 | 789 |
631 WebInspector.ViewManager._TabbedLocation.prototype = { | 790 /** |
632 /** | |
633 * @override | |
634 * @return {!WebInspector.Widget} | |
635 */ | |
636 widget: function() | |
637 { | |
638 return this._tabbedPane; | |
639 }, | |
640 | |
641 /** | |
642 * @override | |
643 * @return {!WebInspector.TabbedPane} | |
644 */ | |
645 tabbedPane: function() | |
646 { | |
647 return this._tabbedPane; | |
648 }, | |
649 | |
650 /** | |
651 * @override | |
652 */ | |
653 enableMoreTabsButton: function() | |
654 { | |
655 this._tabbedPane.leftToolbar().appendToolbarItem(new WebInspector.Toolba
rMenuButton(this._appendTabsToMenu.bind(this))); | |
656 this._tabbedPane.disableOverflowMenu(); | |
657 }, | |
658 | |
659 /** | |
660 * @override | |
661 * @param {string} locationName | |
662 */ | |
663 appendApplicableItems: function(locationName) | |
664 { | |
665 var views = this._manager._viewsForLocation(locationName); | |
666 if (this._allowReorder) { | |
667 var i = 0; | |
668 var persistedOrders = this._tabOrderSetting.get(); | |
669 var orders = new Map(); | |
670 for (var view of views) | |
671 orders.set(view.viewId(), persistedOrders[view.viewId()] || (++i
) * WebInspector.ViewManager._TabbedLocation.orderStep); | |
672 views.sort((a, b) => orders.get(a.viewId()) - orders.get(b.viewId())
); | |
673 } | |
674 | |
675 for (var view of views) { | |
676 var id = view.viewId(); | |
677 this._views.set(id, view); | |
678 view[WebInspector.ViewManager._Location.symbol] = this; | |
679 if (view.isTransient()) | |
680 continue; | |
681 if (!view.isCloseable()) | |
682 this._appendTab(view); | |
683 else if (this._closeableTabSetting.get()[id]) | |
684 this._appendTab(view); | |
685 } | |
686 if (this._lastSelectedTabSetting && this._tabbedPane.hasTab(this._lastSe
lectedTabSetting.get())) | |
687 this._tabbedPane.selectTab(this._lastSelectedTabSetting.get()); | |
688 }, | |
689 | |
690 /** | |
691 * @param {!WebInspector.ContextMenu} contextMenu | |
692 */ | |
693 _appendTabsToMenu: function(contextMenu) | |
694 { | |
695 for (var view of this._views.values()) { | |
696 var title = WebInspector.UIString(view.title()); | |
697 contextMenu.appendItem(title, this.showView.bind(this, view)); | |
698 } | |
699 }, | |
700 | |
701 /** | |
702 * @param {!WebInspector.View} view | |
703 * @param {number=} index | |
704 */ | |
705 _appendTab: function(view, index) | |
706 { | |
707 this._tabbedPane.appendTab(view.viewId(), view.title(), new WebInspector
.ViewManager._ContainerWidget(view), undefined, false, view.isCloseable() || vie
w.isTransient(), index); | |
708 }, | |
709 | |
710 /** | |
711 * @override | |
712 * @param {!WebInspector.View} view | |
713 * @param {?WebInspector.View=} insertBefore | |
714 */ | |
715 appendView: function(view, insertBefore) | |
716 { | |
717 if (this._tabbedPane.hasTab(view.viewId())) | |
718 return; | |
719 view[WebInspector.ViewManager._Location.symbol] = this; | |
720 this._manager._views.set(view.viewId(), view); | |
721 this._views.set(view.viewId(), view); | |
722 | |
723 var index = undefined; | |
724 var tabIds = this._tabbedPane.tabIds(); | |
725 if (this._allowReorder) { | |
726 var orderSetting = this._tabOrderSetting.get(); | |
727 var order = orderSetting[view.viewId()]; | |
728 for (var i = 0; order && i < tabIds.length; ++i) { | |
729 if (orderSetting[tabIds[i]] && orderSetting[tabIds[i]] > order)
{ | |
730 index = i; | |
731 break; | |
732 } | |
733 } | |
734 } else if (insertBefore) { | |
735 for (var i = 0; i < tabIds.length; ++i) { | |
736 if (tabIds[i] === insertBefore.viewId()) { | |
737 index = i; | |
738 break; | |
739 } | |
740 } | |
741 } | |
742 this._appendTab(view, index); | |
743 }, | |
744 | |
745 /** | |
746 * @override | |
747 * @param {!WebInspector.View} view | |
748 * @param {?WebInspector.View=} insertBefore | |
749 * @return {!Promise} | |
750 */ | |
751 showView: function(view, insertBefore) | |
752 { | |
753 this.appendView(view, insertBefore); | |
754 this._tabbedPane.selectTab(view.viewId()); | |
755 this._tabbedPane.focus(); | |
756 return this._materializeWidget(view); | |
757 }, | |
758 | |
759 /** | |
760 * @param {!WebInspector.View} view | |
761 * @override | |
762 */ | |
763 removeView: function(view) | |
764 { | |
765 if (!this._tabbedPane.hasTab(view.viewId())) | |
766 return; | |
767 | |
768 delete view[WebInspector.ViewManager._Location.symbol]; | |
769 this._manager._views.delete(view.viewId()); | |
770 this._views.delete(view.viewId()); | |
771 this._tabbedPane.closeTab(view.viewId()); | |
772 }, | |
773 | |
774 | |
775 /** | |
776 * @param {!WebInspector.Event} event | |
777 */ | |
778 _tabSelected: function(event) | |
779 { | |
780 var tabId = /** @type {string} */ (event.data.tabId); | |
781 if (this._lastSelectedTabSetting && event.data["isUserGesture"]) | |
782 this._lastSelectedTabSetting.set(tabId); | |
783 var view = this._views.get(tabId); | |
784 if (!view) | |
785 return; | |
786 | |
787 this._materializeWidget(view); | |
788 | |
789 if (view.isCloseable()) { | |
790 var tabs = this._closeableTabSetting.get(); | |
791 if (!tabs[tabId]) { | |
792 tabs[tabId] = true; | |
793 this._closeableTabSetting.set(tabs); | |
794 } | |
795 } | |
796 }, | |
797 | |
798 /** | |
799 * @param {!WebInspector.Event} event | |
800 */ | |
801 _tabClosed: function(event) | |
802 { | |
803 var id = /** @type {string} */ (event.data["tabId"]); | |
804 var tabs = this._closeableTabSetting.get(); | |
805 if (tabs[id]) { | |
806 delete tabs[id]; | |
807 this._closeableTabSetting.set(tabs); | |
808 } | |
809 }, | |
810 | |
811 /** | |
812 * @param {!WebInspector.View} view | |
813 * @return {!Promise} | |
814 */ | |
815 _materializeWidget: function(view) | |
816 { | |
817 var widget = /** @type {!WebInspector.ViewManager._ContainerWidget} */ (
this._tabbedPane.tabView(view.viewId())); | |
818 return widget._materialize(); | |
819 }, | |
820 | |
821 /** | |
822 * @param {!WebInspector.Event} event | |
823 */ | |
824 _persistTabOrder: function(event) | |
825 { | |
826 var tabIds = this._tabbedPane.tabIds(); | |
827 var tabOrders = {}; | |
828 for (var i = 0; i < tabIds.length; i++) | |
829 tabOrders[tabIds[i]] = (i + 1) * WebInspector.ViewManager._TabbedLoc
ation.orderStep; | |
830 this._tabOrderSetting.set(tabOrders); | |
831 }, | |
832 | |
833 __proto__: WebInspector.ViewManager._Location.prototype | |
834 }; | |
835 | |
836 /** | |
837 * @constructor | |
838 * @extends {WebInspector.ViewManager._Location} | |
839 * @implements {WebInspector.ViewLocation} | 791 * @implements {WebInspector.ViewLocation} |
840 * @param {!WebInspector.ViewManager} manager | 792 * @unrestricted |
841 * @param {function()=} revealCallback | 793 */ |
842 * @param {string=} location | 794 WebInspector.ViewManager._StackLocation = class extends WebInspector.ViewManager
._Location { |
843 */ | 795 /** |
844 WebInspector.ViewManager._StackLocation = function(manager, revealCallback, loca
tion) | 796 * @param {!WebInspector.ViewManager} manager |
845 { | 797 * @param {function()=} revealCallback |
| 798 * @param {string=} location |
| 799 */ |
| 800 constructor(manager, revealCallback, location) { |
846 var vbox = new WebInspector.VBox(); | 801 var vbox = new WebInspector.VBox(); |
847 WebInspector.ViewManager._Location.call(this, manager, vbox, revealCallback)
; | 802 super(manager, vbox, revealCallback); |
848 this._vbox = vbox; | 803 this._vbox = vbox; |
849 | 804 |
850 /** @type {!Map<string, !WebInspector.ViewManager._ExpandableContainerWidget
>} */ | 805 /** @type {!Map<string, !WebInspector.ViewManager._ExpandableContainerWidget
>} */ |
851 this._expandableContainers = new Map(); | 806 this._expandableContainers = new Map(); |
852 | 807 |
853 if (location) | 808 if (location) |
854 this.appendApplicableItems(location); | 809 this.appendApplicableItems(location); |
855 }; | 810 } |
856 | 811 |
857 WebInspector.ViewManager._StackLocation.prototype = { | 812 /** |
858 | 813 * @override |
859 /** | 814 * @param {!WebInspector.View} view |
860 * @override | 815 * @param {?WebInspector.View=} insertBefore |
861 * @param {!WebInspector.View} view | 816 */ |
862 * @param {?WebInspector.View=} insertBefore | 817 appendView(view, insertBefore) { |
863 */ | 818 var container = this._expandableContainers.get(view.viewId()); |
864 appendView: function(view, insertBefore) | 819 if (!container) { |
865 { | 820 view[WebInspector.ViewManager._Location.symbol] = this; |
866 var container = this._expandableContainers.get(view.viewId()); | 821 this._manager._views.set(view.viewId(), view); |
867 if (!container) { | 822 container = new WebInspector.ViewManager._ExpandableContainerWidget(view); |
868 view[WebInspector.ViewManager._Location.symbol] = this; | 823 var beforeElement = null; |
869 this._manager._views.set(view.viewId(), view); | 824 if (insertBefore) { |
870 container = new WebInspector.ViewManager._ExpandableContainerWidget(
view); | 825 var beforeContainer = insertBefore[WebInspector.ViewManager._ExpandableC
ontainerWidget._symbol]; |
871 var beforeElement = null; | 826 beforeElement = beforeContainer ? beforeContainer.element : null; |
872 if (insertBefore) { | 827 } |
873 var beforeContainer = insertBefore[WebInspector.ViewManager._Exp
andableContainerWidget._symbol]; | 828 container.show(this._vbox.contentElement, beforeElement); |
874 beforeElement = beforeContainer ? beforeContainer.element : null
; | 829 this._expandableContainers.set(view.viewId(), container); |
875 } | 830 } |
876 container.show(this._vbox.contentElement, beforeElement); | 831 } |
877 this._expandableContainers.set(view.viewId(), container); | 832 |
878 } | 833 /** |
879 }, | 834 * @override |
880 | 835 * @param {!WebInspector.View} view |
881 /** | 836 * @param {?WebInspector.View=} insertBefore |
882 * @override | 837 * @return {!Promise} |
883 * @param {!WebInspector.View} view | 838 */ |
884 * @param {?WebInspector.View=} insertBefore | 839 showView(view, insertBefore) { |
885 * @return {!Promise} | 840 this.appendView(view, insertBefore); |
886 */ | 841 var container = this._expandableContainers.get(view.viewId()); |
887 showView: function(view, insertBefore) | 842 return container._expand(); |
888 { | 843 } |
889 this.appendView(view, insertBefore); | 844 |
890 var container = this._expandableContainers.get(view.viewId()); | 845 /** |
891 return container._expand(); | 846 * @param {!WebInspector.View} view |
892 }, | 847 * @override |
893 | 848 */ |
894 /** | 849 removeView(view) { |
895 * @param {!WebInspector.View} view | 850 var container = this._expandableContainers.get(view.viewId()); |
896 * @override | 851 if (!container) |
897 */ | 852 return; |
898 removeView: function(view) | 853 |
899 { | 854 container.detach(); |
900 var container = this._expandableContainers.get(view.viewId()); | 855 this._expandableContainers.delete(view.viewId()); |
901 if (!container) | 856 delete view[WebInspector.ViewManager._Location.symbol]; |
902 return; | 857 this._manager._views.delete(view.viewId()); |
903 | 858 } |
904 container.detach(); | 859 |
905 this._expandableContainers.delete(view.viewId()); | 860 /** |
906 delete view[WebInspector.ViewManager._Location.symbol]; | 861 * @override |
907 this._manager._views.delete(view.viewId()); | 862 * @param {string} locationName |
908 }, | 863 */ |
909 | 864 appendApplicableItems(locationName) { |
910 /** | 865 for (var view of this._manager._viewsForLocation(locationName)) |
911 * @override | 866 this.appendView(view); |
912 * @param {string} locationName | 867 } |
913 */ | 868 }; |
914 appendApplicableItems: function(locationName) | 869 |
915 { | 870 /** |
916 for (var view of this._manager._viewsForLocation(locationName)) | |
917 this.appendView(view); | |
918 }, | |
919 | |
920 __proto__: WebInspector.ViewManager._Location.prototype | |
921 }; | |
922 | |
923 /** | |
924 * @type {!WebInspector.ViewManager} | 871 * @type {!WebInspector.ViewManager} |
925 */ | 872 */ |
926 WebInspector.viewManager; | 873 WebInspector.viewManager; |
OLD | NEW |