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

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

Issue 2412023002: DevTools: migrate InspectorView to tabbed view location. (Closed)
Patch Set: test fixed Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // 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 6 * @interface
7 */ 7 */
8 WebInspector.View = function() 8 WebInspector.View = function()
9 { 9 {
10 } 10 }
(...skipping 24 matching lines...) Expand all
35 */ 35 */
36 toolbarItems: function() { }, 36 toolbarItems: function() { },
37 37
38 /** 38 /**
39 * @return {!Promise<!WebInspector.Widget>} 39 * @return {!Promise<!WebInspector.Widget>}
40 */ 40 */
41 widget: function() { } 41 widget: function() { }
42 } 42 }
43 43
44 WebInspector.View._symbol = Symbol("view"); 44 WebInspector.View._symbol = Symbol("view");
45 WebInspector.View._widgetSymbol = Symbol("widget");
45 46
46 /** 47 /**
47 * @constructor 48 * @constructor
48 * @extends {WebInspector.VBox} 49 * @extends {WebInspector.VBox}
49 * @implements {WebInspector.View} 50 * @implements {WebInspector.View}
50 * @param {string} title 51 * @param {string} title
51 * @param {boolean=} isWebComponent 52 * @param {boolean=} isWebComponent
52 */ 53 */
53 WebInspector.SimpleView = function(title, isWebComponent) 54 WebInspector.SimpleView = function(title, isWebComponent)
54 { 55 {
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 * @param {string} viewId 324 * @param {string} viewId
324 * @return {?WebInspector.View} 325 * @return {?WebInspector.View}
325 */ 326 */
326 view: function(viewId) 327 view: function(viewId)
327 { 328 {
328 return this._views.get(viewId); 329 return this._views.get(viewId);
329 }, 330 },
330 331
331 /** 332 /**
332 * @param {string} viewId 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
333 * @return {!Promise} 344 * @return {!Promise}
334 */ 345 */
335 showView: function(viewId) 346 showView: function(viewId)
336 { 347 {
337 var view = this._views.get(viewId); 348 var view = this._views.get(viewId);
338 if (!view) { 349 if (!view) {
339 console.error("Could not find view for id: '" + viewId + "' " + new Error().stack); 350 console.error("Could not find view for id: '" + viewId + "' " + new Error().stack);
340 return Promise.resolve(); 351 return Promise.resolve();
341 } 352 }
342 353
(...skipping 28 matching lines...) Expand all
371 if (!resolverExtensions.length) 382 if (!resolverExtensions.length)
372 throw new Error("Unresolved location: " + location); 383 throw new Error("Unresolved location: " + location);
373 var resolverExtension = resolverExtensions[0]; 384 var resolverExtension = resolverExtensions[0];
374 return resolverExtension.instance().then(resolver => /** @type {?WebInsp ector.ViewManager._Location} */(resolver.resolveLocation(location))); 385 return resolverExtension.instance().then(resolver => /** @type {?WebInsp ector.ViewManager._Location} */(resolver.resolveLocation(location)));
375 }, 386 },
376 387
377 /** 388 /**
378 * @param {function()=} revealCallback 389 * @param {function()=} revealCallback
379 * @param {string=} location 390 * @param {string=} location
380 * @param {boolean=} restoreSelection 391 * @param {boolean=} restoreSelection
392 * @param {boolean=} allowReorder
381 * @return {!WebInspector.TabbedViewLocation} 393 * @return {!WebInspector.TabbedViewLocation}
382 */ 394 */
383 createTabbedLocation: function(revealCallback, location, restoreSelection) 395 createTabbedLocation: function(revealCallback, location, restoreSelection, a llowReorder)
384 { 396 {
385 return new WebInspector.ViewManager._TabbedLocation(this, revealCallback , location, restoreSelection); 397 return new WebInspector.ViewManager._TabbedLocation(this, revealCallback , location, restoreSelection, allowReorder);
386 }, 398 },
387 399
388 /** 400 /**
389 * @param {function()=} revealCallback 401 * @param {function()=} revealCallback
390 * @param {string=} location 402 * @param {string=} location
391 * @return {!WebInspector.ViewLocation} 403 * @return {!WebInspector.ViewLocation}
392 */ 404 */
393 createStackLocation: function(revealCallback, location) 405 createStackLocation: function(revealCallback, location)
394 { 406 {
395 return new WebInspector.ViewManager._StackLocation(this, revealCallback, location); 407 return new WebInspector.ViewManager._StackLocation(this, revealCallback, location);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 WebInspector.ViewManager._ContainerWidget.prototype = { 452 WebInspector.ViewManager._ContainerWidget.prototype = {
441 /** 453 /**
442 * @return {!Promise} 454 * @return {!Promise}
443 */ 455 */
444 _materialize: function() 456 _materialize: function()
445 { 457 {
446 if (this._materializePromise) 458 if (this._materializePromise)
447 return this._materializePromise; 459 return this._materializePromise;
448 var promises = []; 460 var promises = [];
449 promises.push(this._view.toolbarItems().then(WebInspector.ViewManager._p opulateToolbar.bind(WebInspector.ViewManager, this.element))); 461 promises.push(this._view.toolbarItems().then(WebInspector.ViewManager._p opulateToolbar.bind(WebInspector.ViewManager, this.element)));
450 promises.push(this._view.widget().then(widget => widget.show(this.elemen t))); 462 promises.push(this._view.widget().then(widget => {
463 widget.show(this.element);
464 this._view[WebInspector.View._widgetSymbol] = widget;
dgozman 2016/10/12 04:47:40 Let's set symbol before showing widget.
pfeldman 2016/10/12 19:02:33 Done.
465 }));
451 this._materializePromise = Promise.all(promises); 466 this._materializePromise = Promise.all(promises);
452 return this._materializePromise; 467 return this._materializePromise;
453 }, 468 },
454 469
455 __proto__: WebInspector.VBox.prototype 470 __proto__: WebInspector.VBox.prototype
456 } 471 }
457 472
458 /** 473 /**
459 * @constructor 474 * @constructor
460 * @extends {WebInspector.VBox} 475 * @extends {WebInspector.VBox}
(...skipping 24 matching lines...) Expand all
485 * @return {!Promise} 500 * @return {!Promise}
486 */ 501 */
487 _materialize: function() 502 _materialize: function()
488 { 503 {
489 if (this._materializePromise) 504 if (this._materializePromise)
490 return this._materializePromise; 505 return this._materializePromise;
491 var promises = []; 506 var promises = [];
492 promises.push(this._view.toolbarItems().then(WebInspector.ViewManager._p opulateToolbar.bind(WebInspector.ViewManager, this._titleElement))); 507 promises.push(this._view.toolbarItems().then(WebInspector.ViewManager._p opulateToolbar.bind(WebInspector.ViewManager, this._titleElement)));
493 promises.push(this._view.widget().then(widget => { 508 promises.push(this._view.widget().then(widget => {
494 this._widget = widget; 509 this._widget = widget;
510 this._view[WebInspector.View._widgetSymbol] = widget;
495 widget.show(this.element); 511 widget.show(this.element);
496 })); 512 }));
497 this._materializePromise = Promise.all(promises); 513 this._materializePromise = Promise.all(promises);
498 return this._materializePromise; 514 return this._materializePromise;
499 }, 515 },
500 516
501 /** 517 /**
502 * @return {!Promise} 518 * @return {!Promise}
503 */ 519 */
504 _expand: function() 520 _expand: function()
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 } 585 }
570 586
571 /** 587 /**
572 * @constructor 588 * @constructor
573 * @extends {WebInspector.ViewManager._Location} 589 * @extends {WebInspector.ViewManager._Location}
574 * @implements {WebInspector.TabbedViewLocation} 590 * @implements {WebInspector.TabbedViewLocation}
575 * @param {!WebInspector.ViewManager} manager 591 * @param {!WebInspector.ViewManager} manager
576 * @param {function()=} revealCallback 592 * @param {function()=} revealCallback
577 * @param {string=} location 593 * @param {string=} location
578 * @param {boolean=} restoreSelection 594 * @param {boolean=} restoreSelection
595 * @param {boolean=} allowReorder
579 */ 596 */
580 WebInspector.ViewManager._TabbedLocation = function(manager, revealCallback, loc ation, restoreSelection) 597 WebInspector.ViewManager._TabbedLocation = function(manager, revealCallback, loc ation, restoreSelection, allowReorder)
581 { 598 {
582 this._tabbedPane = new WebInspector.TabbedPane(); 599 this._tabbedPane = new WebInspector.TabbedPane();
600 if (allowReorder)
601 this._tabbedPane.setAllowTabReorder(true);
602 this._allowReorder = allowReorder;
583 WebInspector.ViewManager._Location.call(this, manager, this._tabbedPane, rev ealCallback); 603 WebInspector.ViewManager._Location.call(this, manager, this._tabbedPane, rev ealCallback);
584 604
585 this._tabbedPane.addEventListener(WebInspector.TabbedPane.Events.TabSelected , this._tabSelected, this); 605 this._tabbedPane.addEventListener(WebInspector.TabbedPane.Events.TabSelected , this._tabSelected, this);
586 this._tabbedPane.addEventListener(WebInspector.TabbedPane.Events.TabClosed, this._tabClosed, this); 606 this._tabbedPane.addEventListener(WebInspector.TabbedPane.Events.TabClosed, this._tabClosed, this);
587 this._closeableTabSetting = WebInspector.settings.createSetting(location + " -closeableTabs", {}); 607 this._closeableTabSetting = WebInspector.settings.createSetting(location + " -closeableTabs", {});
608 this._tabOrderSetting = WebInspector.settings.createSetting(location + "-tab Order", {});
609 this._tabbedPane.addEventListener(WebInspector.TabbedPane.Events.TabOrderCha nged, this._persistTabOrder, this);
588 if (restoreSelection) 610 if (restoreSelection)
589 this._lastSelectedTabSetting = WebInspector.settings.createSetting(locat ion + "-selectedTab", ""); 611 this._lastSelectedTabSetting = WebInspector.settings.createSetting(locat ion + "-selectedTab", "");
590 612
591 /** @type {!Map.<string, !WebInspector.View>} */ 613 /** @type {!Map.<string, !WebInspector.View>} */
592 this._views = new Map(); 614 this._views = new Map();
593 615
594 if (location) 616 if (location)
595 this.appendApplicableItems(location); 617 this.appendApplicableItems(location);
596 } 618 }
597 619
620 WebInspector.ViewManager._TabbedLocation.orderStep = 10; // Keep in sync with d escriptors.
621
598 WebInspector.ViewManager._TabbedLocation.prototype = { 622 WebInspector.ViewManager._TabbedLocation.prototype = {
599 /** 623 /**
600 * @override 624 * @override
601 * @return {!WebInspector.Widget} 625 * @return {!WebInspector.Widget}
602 */ 626 */
603 widget: function() 627 widget: function()
604 { 628 {
605 return this._tabbedPane; 629 return this._tabbedPane;
606 }, 630 },
607 631
(...skipping 14 matching lines...) Expand all
622 this._tabbedPane.leftToolbar().appendToolbarItem(new WebInspector.Toolba rMenuButton(this._appendTabsToMenu.bind(this))); 646 this._tabbedPane.leftToolbar().appendToolbarItem(new WebInspector.Toolba rMenuButton(this._appendTabsToMenu.bind(this)));
623 this._tabbedPane.disableOverflowMenu(); 647 this._tabbedPane.disableOverflowMenu();
624 }, 648 },
625 649
626 /** 650 /**
627 * @override 651 * @override
628 * @param {string} locationName 652 * @param {string} locationName
629 */ 653 */
630 appendApplicableItems: function(locationName) 654 appendApplicableItems: function(locationName)
631 { 655 {
632 for (var view of this._manager._viewsForLocation(locationName)) { 656 var views = this._manager._viewsForLocation(locationName);
657 if (this._allowReorder) {
658 var i = 0;
659 var persistedOrders = this._tabOrderSetting.get();
660 var orders = new Map();
661 for (var view of views)
662 orders.set(view.viewId(), persistedOrders[view.viewId()] || (++i ) * 10);
dgozman 2016/10/12 04:47:41 Either use constant defined above or remove it.
pfeldman 2016/10/12 19:02:33 Done.
663 views.sort((a, b) => orders.get(a.viewId()) - orders.get(b.viewId()) );
664 }
665
666 for (var view of views) {
633 var id = view.viewId(); 667 var id = view.viewId();
634 this._views.set(id, view); 668 this._views.set(id, view);
635 view[WebInspector.ViewManager._Location.symbol] = this; 669 view[WebInspector.ViewManager._Location.symbol] = this;
636 if (view.isTransient()) 670 if (view.isTransient())
637 continue; 671 continue;
638 if (!view.isCloseable()) 672 if (!view.isCloseable())
639 this._appendTab(view); 673 this._appendTab(view);
640 else if (this._closeableTabSetting.get()[id]) 674 else if (this._closeableTabSetting.get()[id])
641 this._appendTab(view); 675 this._appendTab(view);
642 } 676 }
(...skipping 14 matching lines...) Expand all
657 _appendTabsToMenu: function(contextMenu) 691 _appendTabsToMenu: function(contextMenu)
658 { 692 {
659 for (var view of this._views.values()) { 693 for (var view of this._views.values()) {
660 var title = WebInspector.UIString(view.title()); 694 var title = WebInspector.UIString(view.title());
661 contextMenu.appendItem(title, this.showView.bind(this, view)); 695 contextMenu.appendItem(title, this.showView.bind(this, view));
662 } 696 }
663 }, 697 },
664 698
665 /** 699 /**
666 * @param {!WebInspector.View} view 700 * @param {!WebInspector.View} view
701 * @param {number=} index
667 */ 702 */
668 _appendTab: function(view) 703 _appendTab: function(view, index)
669 { 704 {
670 this._tabbedPane.appendTab(view.viewId(), view.title(), new WebInspector .ViewManager._ContainerWidget(view), undefined, false, view.isCloseable() || vie w.isTransient()); 705 this._tabbedPane.appendTab(view.viewId(), view.title(), new WebInspector .ViewManager._ContainerWidget(view), undefined, false, view.isCloseable() || vie w.isTransient(), index);
671 }, 706 },
672 707
673 /** 708 /**
674 * @override 709 * @override
675 * @param {!WebInspector.View} view 710 * @param {!WebInspector.View} view
676 * @param {?WebInspector.View=} insertBefore 711 * @param {?WebInspector.View=} insertBefore
677 */ 712 */
678 appendView: function(view, insertBefore) 713 appendView: function(view, insertBefore)
679 { 714 {
680 if (insertBefore) 715 if (this._tabbedPane.hasTab(view.viewId()))
681 throw new Error("Insert before in tabbed pane is not supported"); 716 return;
682 if (!this._tabbedPane.hasTab(view.viewId())) { 717 view[WebInspector.ViewManager._Location.symbol] = this;
683 view[WebInspector.ViewManager._Location.symbol] = this; 718 this._manager._views.set(view.viewId(), view);
684 this._manager._views.set(view.viewId(), view); 719 this._views.set(view.viewId(), view);
685 this._views.set(view.viewId(), view); 720
686 this._appendTab(view); 721 var index = undefined;
722 var tabIds = this._tabbedPane.tabIds();
723 if (this._allowReorder) {
724 var orderSetting = this._tabOrderSetting.get();
725 var order = orderSetting[view.viewId()];
726 for (var i = 0; order && i < tabIds.length; ++i) {
727 if (orderSetting[tabIds[i]] && orderSetting[tabIds[i]] > order) {
728 index = i;
729 break;
730 }
731 }
732 } else if (insertBefore) {
733 for (var i = 0; i < tabIds.length; ++i) {
734 if (tabIds[i] === insertBefore.viewId()) {
735 index = i;
736 break;
737 }
738 }
687 } 739 }
740 this._appendTab(view, index);
688 }, 741 },
689 742
690 /** 743 /**
691 * @override 744 * @override
692 * @param {!WebInspector.View} view 745 * @param {!WebInspector.View} view
693 * @param {?WebInspector.View=} insertBefore 746 * @param {?WebInspector.View=} insertBefore
694 * @return {!Promise} 747 * @return {!Promise}
695 */ 748 */
696 showView: function(view, insertBefore) 749 showView: function(view, insertBefore)
697 { 750 {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 /** 809 /**
757 * @param {!WebInspector.View} view 810 * @param {!WebInspector.View} view
758 * @return {!Promise} 811 * @return {!Promise}
759 */ 812 */
760 _materializeWidget: function(view) 813 _materializeWidget: function(view)
761 { 814 {
762 var widget = /** @type {!WebInspector.ViewManager._ContainerWidget} */ ( this._tabbedPane.tabView(view.viewId())); 815 var widget = /** @type {!WebInspector.ViewManager._ContainerWidget} */ ( this._tabbedPane.tabView(view.viewId()));
763 return widget._materialize(); 816 return widget._materialize();
764 }, 817 },
765 818
819 /**
820 * @param {!WebInspector.Event} event
821 */
822 _persistTabOrder: function(event)
823 {
824 var tabIds = this._tabbedPane.tabIds();
825 var tabOrders = {};
826 for (var i = 0; i < tabIds.length; i++)
827 tabOrders[tabIds[i]] = (i + 1) * WebInspector.ViewManager._TabbedLoc ation.orderStep;
828 if (Object.keys(tabOrders).length)
dgozman 2016/10/12 04:47:41 Remove this debugging code.
pfeldman 2016/10/12 19:02:33 Done.
829 this._tabOrderSetting.set(tabOrders);
830 else debugger;
831 },
832
766 __proto__: WebInspector.ViewManager._Location.prototype 833 __proto__: WebInspector.ViewManager._Location.prototype
767 } 834 }
768 835
769 /** 836 /**
770 * @constructor 837 * @constructor
771 * @extends {WebInspector.ViewManager._Location} 838 * @extends {WebInspector.ViewManager._Location}
772 * @implements {WebInspector.ViewLocation} 839 * @implements {WebInspector.ViewLocation}
773 * @param {!WebInspector.ViewManager} manager 840 * @param {!WebInspector.ViewManager} manager
774 * @param {function()=} revealCallback 841 * @param {function()=} revealCallback
775 * @param {string=} location 842 * @param {string=} location
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 this.appendView(view); 916 this.appendView(view);
850 }, 917 },
851 918
852 __proto__: WebInspector.ViewManager._Location.prototype 919 __proto__: WebInspector.ViewManager._Location.prototype
853 } 920 }
854 921
855 /** 922 /**
856 * @type {!WebInspector.ViewManager} 923 * @type {!WebInspector.ViewManager}
857 */ 924 */
858 WebInspector.viewManager; 925 WebInspector.viewManager;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698