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

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: made layers panel closeable. 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 _materialize: function() 458 _materialize: function()
447 { 459 {
448 if (this._materializePromise) 460 if (this._materializePromise)
449 return this._materializePromise; 461 return this._materializePromise;
450 var promises = []; 462 var promises = [];
451 promises.push(this._view.toolbarItems().then(WebInspector.ViewManager._p opulateToolbar.bind(WebInspector.ViewManager, this.element))); 463 promises.push(this._view.toolbarItems().then(WebInspector.ViewManager._p opulateToolbar.bind(WebInspector.ViewManager, this.element)));
452 promises.push(this._view.widget().then(widget => { 464 promises.push(this._view.widget().then(widget => {
453 // Move focus from |this| to loaded |widget| if any. 465 // Move focus from |this| to loaded |widget| if any.
454 var shouldFocus = this.element.hasFocus(); 466 var shouldFocus = this.element.hasFocus();
455 this.setDefaultFocusedElement(null); 467 this.setDefaultFocusedElement(null);
468 this._view[WebInspector.View._widgetSymbol] = widget;
456 widget.show(this.element); 469 widget.show(this.element);
457 if (shouldFocus) 470 if (shouldFocus)
458 widget.focus(); 471 widget.focus();
459 })); 472 }));
460 this._materializePromise = Promise.all(promises); 473 this._materializePromise = Promise.all(promises);
461 return this._materializePromise; 474 return this._materializePromise;
462 }, 475 },
463 476
464 __proto__: WebInspector.VBox.prototype 477 __proto__: WebInspector.VBox.prototype
465 } 478 }
(...skipping 28 matching lines...) Expand all
494 * @return {!Promise} 507 * @return {!Promise}
495 */ 508 */
496 _materialize: function() 509 _materialize: function()
497 { 510 {
498 if (this._materializePromise) 511 if (this._materializePromise)
499 return this._materializePromise; 512 return this._materializePromise;
500 var promises = []; 513 var promises = [];
501 promises.push(this._view.toolbarItems().then(WebInspector.ViewManager._p opulateToolbar.bind(WebInspector.ViewManager, this._titleElement))); 514 promises.push(this._view.toolbarItems().then(WebInspector.ViewManager._p opulateToolbar.bind(WebInspector.ViewManager, this._titleElement)));
502 promises.push(this._view.widget().then(widget => { 515 promises.push(this._view.widget().then(widget => {
503 this._widget = widget; 516 this._widget = widget;
517 this._view[WebInspector.View._widgetSymbol] = widget;
504 widget.show(this.element); 518 widget.show(this.element);
505 })); 519 }));
506 this._materializePromise = Promise.all(promises); 520 this._materializePromise = Promise.all(promises);
507 return this._materializePromise; 521 return this._materializePromise;
508 }, 522 },
509 523
510 /** 524 /**
511 * @return {!Promise} 525 * @return {!Promise}
512 */ 526 */
513 _expand: function() 527 _expand: function()
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 } 592 }
579 593
580 /** 594 /**
581 * @constructor 595 * @constructor
582 * @extends {WebInspector.ViewManager._Location} 596 * @extends {WebInspector.ViewManager._Location}
583 * @implements {WebInspector.TabbedViewLocation} 597 * @implements {WebInspector.TabbedViewLocation}
584 * @param {!WebInspector.ViewManager} manager 598 * @param {!WebInspector.ViewManager} manager
585 * @param {function()=} revealCallback 599 * @param {function()=} revealCallback
586 * @param {string=} location 600 * @param {string=} location
587 * @param {boolean=} restoreSelection 601 * @param {boolean=} restoreSelection
602 * @param {boolean=} allowReorder
588 */ 603 */
589 WebInspector.ViewManager._TabbedLocation = function(manager, revealCallback, loc ation, restoreSelection) 604 WebInspector.ViewManager._TabbedLocation = function(manager, revealCallback, loc ation, restoreSelection, allowReorder)
590 { 605 {
591 this._tabbedPane = new WebInspector.TabbedPane(); 606 this._tabbedPane = new WebInspector.TabbedPane();
607 if (allowReorder)
608 this._tabbedPane.setAllowTabReorder(true);
609 this._allowReorder = allowReorder;
592 WebInspector.ViewManager._Location.call(this, manager, this._tabbedPane, rev ealCallback); 610 WebInspector.ViewManager._Location.call(this, manager, this._tabbedPane, rev ealCallback);
593 611
594 this._tabbedPane.addEventListener(WebInspector.TabbedPane.Events.TabSelected , this._tabSelected, this); 612 this._tabbedPane.addEventListener(WebInspector.TabbedPane.Events.TabSelected , this._tabSelected, this);
595 this._tabbedPane.addEventListener(WebInspector.TabbedPane.Events.TabClosed, this._tabClosed, this); 613 this._tabbedPane.addEventListener(WebInspector.TabbedPane.Events.TabClosed, this._tabClosed, this);
596 this._closeableTabSetting = WebInspector.settings.createSetting(location + " -closeableTabs", {}); 614 this._closeableTabSetting = WebInspector.settings.createSetting(location + " -closeableTabs", {});
615 this._tabOrderSetting = WebInspector.settings.createSetting(location + "-tab Order", {});
616 this._tabbedPane.addEventListener(WebInspector.TabbedPane.Events.TabOrderCha nged, this._persistTabOrder, this);
597 if (restoreSelection) 617 if (restoreSelection)
598 this._lastSelectedTabSetting = WebInspector.settings.createSetting(locat ion + "-selectedTab", ""); 618 this._lastSelectedTabSetting = WebInspector.settings.createSetting(locat ion + "-selectedTab", "");
599 619
600 /** @type {!Map.<string, !WebInspector.View>} */ 620 /** @type {!Map.<string, !WebInspector.View>} */
601 this._views = new Map(); 621 this._views = new Map();
602 622
603 if (location) 623 if (location)
604 this.appendApplicableItems(location); 624 this.appendApplicableItems(location);
605 } 625 }
606 626
627 WebInspector.ViewManager._TabbedLocation.orderStep = 10; // Keep in sync with d escriptors.
628
607 WebInspector.ViewManager._TabbedLocation.prototype = { 629 WebInspector.ViewManager._TabbedLocation.prototype = {
608 /** 630 /**
609 * @override 631 * @override
610 * @return {!WebInspector.Widget} 632 * @return {!WebInspector.Widget}
611 */ 633 */
612 widget: function() 634 widget: function()
613 { 635 {
614 return this._tabbedPane; 636 return this._tabbedPane;
615 }, 637 },
616 638
(...skipping 14 matching lines...) Expand all
631 this._tabbedPane.leftToolbar().appendToolbarItem(new WebInspector.Toolba rMenuButton(this._appendTabsToMenu.bind(this))); 653 this._tabbedPane.leftToolbar().appendToolbarItem(new WebInspector.Toolba rMenuButton(this._appendTabsToMenu.bind(this)));
632 this._tabbedPane.disableOverflowMenu(); 654 this._tabbedPane.disableOverflowMenu();
633 }, 655 },
634 656
635 /** 657 /**
636 * @override 658 * @override
637 * @param {string} locationName 659 * @param {string} locationName
638 */ 660 */
639 appendApplicableItems: function(locationName) 661 appendApplicableItems: function(locationName)
640 { 662 {
641 for (var view of this._manager._viewsForLocation(locationName)) { 663 var views = this._manager._viewsForLocation(locationName);
664 if (this._allowReorder) {
665 var i = 0;
666 var persistedOrders = this._tabOrderSetting.get();
667 var orders = new Map();
668 for (var view of views)
669 orders.set(view.viewId(), persistedOrders[view.viewId()] || (++i ) * WebInspector.ViewManager._TabbedLocation.orderStep);
670 views.sort((a, b) => orders.get(a.viewId()) - orders.get(b.viewId()) );
671 }
672
673 for (var view of views) {
642 var id = view.viewId(); 674 var id = view.viewId();
643 this._views.set(id, view); 675 this._views.set(id, view);
644 view[WebInspector.ViewManager._Location.symbol] = this; 676 view[WebInspector.ViewManager._Location.symbol] = this;
645 if (view.isTransient()) 677 if (view.isTransient())
646 continue; 678 continue;
647 if (!view.isCloseable()) 679 if (!view.isCloseable())
648 this._appendTab(view); 680 this._appendTab(view);
649 else if (this._closeableTabSetting.get()[id]) 681 else if (this._closeableTabSetting.get()[id])
650 this._appendTab(view); 682 this._appendTab(view);
651 } 683 }
(...skipping 14 matching lines...) Expand all
666 _appendTabsToMenu: function(contextMenu) 698 _appendTabsToMenu: function(contextMenu)
667 { 699 {
668 for (var view of this._views.values()) { 700 for (var view of this._views.values()) {
669 var title = WebInspector.UIString(view.title()); 701 var title = WebInspector.UIString(view.title());
670 contextMenu.appendItem(title, this.showView.bind(this, view)); 702 contextMenu.appendItem(title, this.showView.bind(this, view));
671 } 703 }
672 }, 704 },
673 705
674 /** 706 /**
675 * @param {!WebInspector.View} view 707 * @param {!WebInspector.View} view
708 * @param {number=} index
676 */ 709 */
677 _appendTab: function(view) 710 _appendTab: function(view, index)
678 { 711 {
679 this._tabbedPane.appendTab(view.viewId(), view.title(), new WebInspector .ViewManager._ContainerWidget(view), undefined, false, view.isCloseable() || vie w.isTransient()); 712 this._tabbedPane.appendTab(view.viewId(), view.title(), new WebInspector .ViewManager._ContainerWidget(view), undefined, false, view.isCloseable() || vie w.isTransient(), index);
680 }, 713 },
681 714
682 /** 715 /**
683 * @override 716 * @override
684 * @param {!WebInspector.View} view 717 * @param {!WebInspector.View} view
685 * @param {?WebInspector.View=} insertBefore 718 * @param {?WebInspector.View=} insertBefore
686 */ 719 */
687 appendView: function(view, insertBefore) 720 appendView: function(view, insertBefore)
688 { 721 {
689 if (insertBefore) 722 if (this._tabbedPane.hasTab(view.viewId()))
690 throw new Error("Insert before in tabbed pane is not supported"); 723 return;
691 if (!this._tabbedPane.hasTab(view.viewId())) { 724 view[WebInspector.ViewManager._Location.symbol] = this;
692 view[WebInspector.ViewManager._Location.symbol] = this; 725 this._manager._views.set(view.viewId(), view);
693 this._manager._views.set(view.viewId(), view); 726 this._views.set(view.viewId(), view);
694 this._views.set(view.viewId(), view); 727
695 this._appendTab(view); 728 var index = undefined;
729 var tabIds = this._tabbedPane.tabIds();
730 if (this._allowReorder) {
731 var orderSetting = this._tabOrderSetting.get();
732 var order = orderSetting[view.viewId()];
733 for (var i = 0; order && i < tabIds.length; ++i) {
734 if (orderSetting[tabIds[i]] && orderSetting[tabIds[i]] > order) {
735 index = i;
736 break;
737 }
738 }
739 } else if (insertBefore) {
740 for (var i = 0; i < tabIds.length; ++i) {
741 if (tabIds[i] === insertBefore.viewId()) {
742 index = i;
743 break;
744 }
745 }
696 } 746 }
747 this._appendTab(view, index);
697 }, 748 },
698 749
699 /** 750 /**
700 * @override 751 * @override
701 * @param {!WebInspector.View} view 752 * @param {!WebInspector.View} view
702 * @param {?WebInspector.View=} insertBefore 753 * @param {?WebInspector.View=} insertBefore
703 * @return {!Promise} 754 * @return {!Promise}
704 */ 755 */
705 showView: function(view, insertBefore) 756 showView: function(view, insertBefore)
706 { 757 {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 /** 816 /**
766 * @param {!WebInspector.View} view 817 * @param {!WebInspector.View} view
767 * @return {!Promise} 818 * @return {!Promise}
768 */ 819 */
769 _materializeWidget: function(view) 820 _materializeWidget: function(view)
770 { 821 {
771 var widget = /** @type {!WebInspector.ViewManager._ContainerWidget} */ ( this._tabbedPane.tabView(view.viewId())); 822 var widget = /** @type {!WebInspector.ViewManager._ContainerWidget} */ ( this._tabbedPane.tabView(view.viewId()));
772 return widget._materialize(); 823 return widget._materialize();
773 }, 824 },
774 825
826 /**
827 * @param {!WebInspector.Event} event
828 */
829 _persistTabOrder: function(event)
830 {
831 var tabIds = this._tabbedPane.tabIds();
832 var tabOrders = {};
833 for (var i = 0; i < tabIds.length; i++)
834 tabOrders[tabIds[i]] = (i + 1) * WebInspector.ViewManager._TabbedLoc ation.orderStep;
835 this._tabOrderSetting.set(tabOrders);
836 },
837
775 __proto__: WebInspector.ViewManager._Location.prototype 838 __proto__: WebInspector.ViewManager._Location.prototype
776 } 839 }
777 840
778 /** 841 /**
779 * @constructor 842 * @constructor
780 * @extends {WebInspector.ViewManager._Location} 843 * @extends {WebInspector.ViewManager._Location}
781 * @implements {WebInspector.ViewLocation} 844 * @implements {WebInspector.ViewLocation}
782 * @param {!WebInspector.ViewManager} manager 845 * @param {!WebInspector.ViewManager} manager
783 * @param {function()=} revealCallback 846 * @param {function()=} revealCallback
784 * @param {string=} location 847 * @param {string=} location
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 this.appendView(view); 921 this.appendView(view);
859 }, 922 },
860 923
861 __proto__: WebInspector.ViewManager._Location.prototype 924 __proto__: WebInspector.ViewManager._Location.prototype
862 } 925 }
863 926
864 /** 927 /**
865 * @type {!WebInspector.ViewManager} 928 * @type {!WebInspector.ViewManager}
866 */ 929 */
867 WebInspector.viewManager; 930 WebInspector.viewManager;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698