this._drawerSplitView.show(this.element);
this._tabbedPane = new WebInspector.TabbedPane();
- this._tabbedPane.setRetainTabOrder(true, self.runtime.orderComparator(WebInspector.Panel, "name", "order"));
+ this._tabbedPane.setRetainTabOrder(true);
this._tabbedPane.show(this._drawerSplitView.mainElement());
this._drawer = new WebInspector.Drawer(this._drawerSplitView);
// Patch tabbed pane header with toolbar actions.
- this._toolbarElement = document.createElement("div");
+ this._toolbarElement = createElement("div");
this._toolbarElement.className = "toolbar toolbar-background toolbar-colors";
var headerElement = this._tabbedPane.headerElement();
headerElement.parentElement.insertBefore(this._toolbarElement, headerElement);
this._rightToolbarElement = this._toolbarElement.createChild("div", "toolbar-controls-right");
this._toolbarItems = [];
- this._closeButtonToolbarItem = document.createElementWithClass("div", "toolbar-close-button-item");
+ this._closeButtonToolbarItem = createElementWithClass("div", "toolbar-close-button-item");
var closeButtonElement = this._closeButtonToolbarItem.createChild("div", "close-button");
closeButtonElement.addEventListener("click", InspectorFrontendHost.closeWindow.bind(InspectorFrontendHost), true);
this._rightToolbarElement.appendChild(this._closeButtonToolbarItem);
this._history = [];
this._historyIterator = -1;
- document.addEventListener("keydown", this._keyDown.bind(this), false);
- document.addEventListener("keypress", this._keyPress.bind(this), false);
+ this._keyDownBound = this._keyDown.bind(this);
+ this._keyPressBound = this._keyPress.bind(this);
+ /** @type {!Object.<string, !WebInspector.PanelDescriptor>} */
this._panelDescriptors = {};
+ /** @type {!Object.<string, !Promise.<!WebInspector.Panel> >} */
+ this._panelPromises = {};
// Windows and Mac have two different definitions of '[' and ']', so accept both of each.
this._openBracketIdentifiers = ["U+005B", "U+00DB"].keySet();
this._closeBracketIdentifiers = ["U+005D", "U+00DD"].keySet();
this._lastActivePanelSetting = WebInspector.settings.createSetting("lastActivePanel", "elements");
- // FIXME(399531): enable timelineOnTraceEvents experiment when running layout tests under inspector/tracing/. This code
- // should be removed along with the old Timeline implementation once we move tracing based Timeline out of experimental.
- if ("tracing" === this._lastActivePanelSetting.get()) {
- Runtime.experiments.setEnabled("timelineOnTraceEvents", true);
- this._lastActivePanelSetting.set("timeline");
- }
-
+ InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Events.ShowConsole, showConsole.bind(this));
this._loadPanelDesciptors();
- InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Events.ShowConsole, this.showPanel.bind(this, "console"));
+ /**
+ * @this {WebInspector.InspectorView}
+ */
+ function showConsole()
+ {
+ this.showPanel("console").done();
+ }
+
+ WebInspector.targetManager.addEventListener(WebInspector.TargetManager.Events.SuspendStateChanged, this._onSuspendStateChanged.bind(this));
};
WebInspector.InspectorView.prototype = {
+ wasShown: function()
+ {
+ this.element.ownerDocument.addEventListener("keydown", this._keyDownBound, false);
+ this.element.ownerDocument.addEventListener("keypress", this._keyPressBound, false);
+ },
+
+ willHide: function()
+ {
+ this.element.ownerDocument.removeEventListener("keydown", this._keyDownBound, false);
+ this.element.ownerDocument.removeEventListener("keypress", this._keyPressBound, false);
+ },
+
_loadPanelDesciptors: function()
{
WebInspector.startBatchUpdate();
- self.runtime.extensions(WebInspector.Panel).forEach(processPanelExtensions.bind(this));
+ self.runtime.extensions(WebInspector.PanelFactory).forEach(processPanelExtensions.bind(this));
/**
* @param {!Runtime.Extension} extension
* @this {!WebInspector.InspectorView}
/**
* @param {string} panelName
- * @return {?WebInspector.Panel}
+ * @return {!Promise.<!WebInspector.Panel>}
*/
panel: function(panelName)
{
var panelDescriptor = this._panelDescriptors[panelName];
- var panelOrder = this._tabbedPane.allTabs();
- if (!panelDescriptor && panelOrder.length)
- panelDescriptor = this._panelDescriptors[panelOrder[0]];
- var panel = panelDescriptor ? panelDescriptor.panel() : null;
- if (panel)
+ if (!panelDescriptor)
+ return Promise.rejectWithError("Can't load panel without the descriptor: " + panelName);
+
+ var promise = this._panelPromises[panelName];
+ if (promise)
+ return promise;
+
+ promise = panelDescriptor.panel();
+ this._panelPromises[panelName] = promise;
+
+ promise.then(cachePanel.bind(this));
+
+ /**
+ * @param {!WebInspector.Panel} panel
+ * @return {!WebInspector.Panel}
+ * @this {WebInspector.InspectorView}
+ */
+ function cachePanel(panel)
+ {
+ delete this._panelPromises[panelName];
this._panels[panelName] = panel;
- return panel;
+ return panel;
+ }
+ return promise;
},
/**
- * @param {boolean} locked
+ * @param {!WebInspector.Event} event
*/
- setCurrentPanelLocked: function(locked)
+ _onSuspendStateChanged: function(event)
{
- this._currentPanelLocked = locked;
- this._tabbedPane.setCurrentTabLocked(locked);
+ this._currentPanelLocked = WebInspector.targetManager.allTargetsSuspended();
+ this._tabbedPane.setCurrentTabLocked(this._currentPanelLocked);
for (var i = 0; i < this._toolbarItems.length; ++i)
- this._toolbarItems[i].setEnabled(!locked);
+ this._toolbarItems[i].setEnabled(!this._currentPanelLocked);
},
/**
+ * The returned Promise is resolved with null if another showPanel()
+ * gets called while this.panel(panelName) Promise is in flight.
+ *
* @param {string} panelName
- * @return {?WebInspector.Panel}
+ * @return {!Promise.<?WebInspector.Panel>}
*/
showPanel: function(panelName)
{
if (this._currentPanelLocked)
- return this._currentPanel === this._panels[panelName] ? this._currentPanel : null;
+ return this._currentPanel === this._panels[panelName] ? Promise.resolve(this._currentPanel) : Promise.rejectWithError("Current panel locked");
+
+ this._panelForShowPromise = this.panel(panelName);
+ return this._panelForShowPromise.then(setCurrentPanelIfNecessary.bind(this, this._panelForShowPromise));
+
+ /**
+ * @param {!Promise.<!WebInspector.Panel>} panelPromise
+ * @param {!WebInspector.Panel} panel
+ * @return {?WebInspector.Panel}
+ * @this {WebInspector.InspectorView}
+ */
+ function setCurrentPanelIfNecessary(panelPromise, panel)
+ {
+ if (this._panelForShowPromise !== panelPromise)
+ return null;
- var panel = this.panel(panelName);
- if (panel)
this.setCurrentPanel(panel);
- return panel;
+ return panel;
+ }
},
/**
showInitialPanel: function()
{
+ if (InspectorFrontendHost.isUnderTest())
+ return;
+ this._showInitialPanel();
+ },
+
+ _showInitialPanel: function()
+ {
this._tabbedPane.addEventListener(WebInspector.TabbedPane.EventTypes.TabSelected, this._tabSelected, this);
this._tabSelected();
this._drawer.initialPanelShown();
},
+ /**
+ * @param {string} panelName
+ */
+ showInitialPanelForTest: function(panelName)
+ {
+ this._tabbedPane.addEventListener(WebInspector.TabbedPane.EventTypes.TabSelected, this._tabSelected, this);
+ this.setCurrentPanel(this._panels[panelName]);
+ this._drawer.initialPanelShown();
+ },
+
_tabSelected: function()
{
var panelName = this._tabbedPane.selectedTabId;
if (!panelName)
return;
- var panel = this._panelDescriptors[this._tabbedPane.selectedTabId].panel();
- this._panels[panelName] = panel;
- this._tabbedPane.changeTabView(panelName, panel);
- this._currentPanel = panel;
- this._lastActivePanelSetting.set(panel.name);
- this._pushToHistory(panel.name);
- WebInspector.userMetrics.panelShown(panel.name);
- panel.focus();
+ this.showPanel(panelName).done();
},
/**
- * @param {!WebInspector.Panel} x
+ * @param {!WebInspector.Panel} panel
+ * @return {!WebInspector.Panel}
*/
- setCurrentPanel: function(x)
+ setCurrentPanel: function(panel)
{
- if (this._currentPanelLocked)
- return;
+ delete this._panelForShowPromise;
+
+ if (this._currentPanelLocked) {
+ console.error("Current panel is locked");
+ return this._currentPanel;
+ }
InspectorFrontendHost.bringToFront();
- if (this._currentPanel === x)
- return;
- this._tabbedPane.changeTabView(x.name, x);
- this._tabbedPane.selectTab(x.name);
+ if (this._currentPanel === panel)
+ return panel;
+
+ this._currentPanel = panel;
+ if (!this._panels[panel.name])
+ this._panels[panel.name] = panel;
+ this._tabbedPane.changeTabView(panel.name, panel);
+ this._tabbedPane.removeEventListener(WebInspector.TabbedPane.EventTypes.TabSelected, this._tabSelected, this);
+ this._tabbedPane.selectTab(panel.name);
+ this._tabbedPane.addEventListener(WebInspector.TabbedPane.EventTypes.TabSelected, this._tabSelected, this);
+
+ this._lastActivePanelSetting.set(panel.name);
+ this._pushToHistory(panel.name);
+ WebInspector.userMetrics.panelShown(panel.name);
+ panel.focus();
+ return panel;
},
/**
var panelName = this._tabbedPane.allTabs()[panelIndex];
if (panelName) {
if (!WebInspector.Dialog.currentInstance() && !this._currentPanelLocked)
- this.showPanel(panelName);
+ this.showPanel(panelName).done();
event.consume(true);
}
return;
event.consume(true)
},
+ /**
+ * @param {number} direction
+ */
_changePanelInDirection: function(direction)
{
var panelOrder = this._tabbedPane.allTabs();
var index = panelOrder.indexOf(this.currentPanel().name);
index = (index + panelOrder.length + direction) % panelOrder.length;
- this.showPanel(panelOrder[index]);
+ this.showPanel(panelOrder[index]).done();
},
+ /**
+ * @param {number} move
+ */
_moveInHistory: function(move)
{
var newIndex = this._historyIterator + move;