Bug 1396784 - Lazy load Layout view when opening the inspector. r=gl

MozReview-Commit-ID: I5PiZbfy2J2

--HG--
extra : rebase_source : 8c9b36fee29816551bdac59a494a0d07ee662759
This commit is contained in:
Alexandre Poirot 2017-09-13 10:56:18 +02:00
parent 55daa8694b
commit a9f4169300
4 changed files with 34 additions and 11 deletions

View File

@ -631,8 +631,28 @@ Inspector.prototype = {
// calling inspector.addSidebarTab
this.gridInspector = new GridInspector(this, this.panelWin);
const LayoutView = this.browserRequire("devtools/client/inspector/layout/layout");
this.layoutview = new LayoutView(this, this.panelWin);
// Inject a lazy loaded react tab by exposing a fake React object
// with a lazy defined Tab thanks to `panel` being a function
let layoutId = "layoutview";
let layoutTitle = INSPECTOR_L10N.getStr("inspector.sidebar.layoutViewTitle2");
this.sidebar.addTab(
layoutId,
layoutTitle,
{
props: {
id: layoutId,
title: layoutTitle
},
panel: () => {
if (!this.layoutview) {
const LayoutView =
this.browserRequire("devtools/client/inspector/layout/layout");
this.layoutview = new LayoutView(this, this.panelWin);
}
return this.layoutview.provider;
}
},
defaultTab == layoutId);
if (this.target.form.animationsActor) {
this.sidebar.addFrameTab(

View File

@ -101,14 +101,8 @@ LayoutView.prototype = {
showBadge: () => Services.prefs.getIntPref(PROMOTE_COUNT_PREF) > 0,
}, app);
let defaultTab = Services.prefs.getCharPref("devtools.inspector.activeSidebar");
this.inspector.addSidebarTab(
"layoutview",
INSPECTOR_L10N.getStr("inspector.sidebar.layoutViewTitle2"),
provider,
defaultTab == "layoutview"
);
// Expose the provider to let inspector.js use it in setupSidebar.
this.provider = provider;
},
/**

View File

@ -53,6 +53,7 @@ var openInspectorSidebarTab = Task.async(function* (id) {
info("Selecting the " + id + " sidebar");
let onSidebarSelect = inspector.sidebar.once("select");
if (id === "computedview" || id === "layoutview") {
// The layout and computed views should wait until the box-model widget is ready.
let onBoxModelViewReady = inspector.once("boxmodel-view-updated");
@ -61,6 +62,7 @@ var openInspectorSidebarTab = Task.async(function* (id) {
} else {
inspector.sidebar.select(id);
}
yield onSidebarSelect;
return {
toolbox,

View File

@ -334,6 +334,13 @@ define(function (require, exports, module) {
width: selected ? "100%" : "0",
};
// Allows lazy loading panels by creating them only if they are selected,
// then store a copy of the lazy created panel in `tab.panel`.
if (typeof tab.panel == "function" && selected) {
tab.panel = tab.panel(tab);
}
let panel = tab.panel || tab;
return (
DOM.div({
id: id ? id + "-panel" : "panel-" + index,
@ -343,7 +350,7 @@ define(function (require, exports, module) {
role: "tabpanel",
"aria-labelledby": id ? id + "-tab" : "tab-" + index,
},
(selected || this.state.created[index]) ? tab : null
(selected || this.state.created[index]) ? panel : null
)
);
});