Bug 1634051 - don't eagerly initialize the all tabs menu, r=mstriemer

The initialization costs of the TabList constructors is very small compared to
the cost of actually calling _populate, so instead of calling init() from an
idle task, we can just wait until the view actually needs to be shown.

Differential Revision: https://phabricator.services.mozilla.com/D73946
This commit is contained in:
Gijs Kruitbosch 2020-05-15 17:04:29 +00:00
parent 37b62ce349
commit 08cecbdc20
5 changed files with 48 additions and 55 deletions

View file

@ -2,53 +2,44 @@
- License, v. 2.0. If a copy of the MPL was not distributed with this - License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. --> - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<panel id="allTabsMenu" <html:template id="allTabsMenu-container">
class="cui-widget-panel" <panelview id="allTabsMenu-allTabsView" class="PanelUI-subView">
role="group" <vbox class="panel-subview-body">
type="arrow" <toolbarbutton id="allTabsMenu-undoCloseTab"
hidden="true" class="subviewbutton subviewbutton-iconic"
flip="slide" data-l10n-id="all-tabs-menu-undo-close-tab"
position="bottomcenter topright" key="key_undoCloseTab"
noautofocus="true"> command="History:UndoCloseTab"/>
<panelmultiview mainViewId="allTabsMenu-allTabsView" disablekeynav="true"> <toolbarbutton id="allTabsMenu-searchTabs"
<panelview id="allTabsMenu-allTabsView" class="PanelUI-subView"> class="subviewbutton subviewbutton-iconic"
<vbox class="panel-subview-body"> oncommand="gTabsPanel.searchTabs();"
<toolbarbutton id="allTabsMenu-undoCloseTab" data-l10n-id="all-tabs-menu-search-tabs"/>
class="subviewbutton subviewbutton-iconic" <toolbarbutton id="allTabsMenu-containerTabsButton"
data-l10n-id="all-tabs-menu-undo-close-tab" class="subviewbutton subviewbutton-nav"
key="key_undoCloseTab" closemenu="none"
command="History:UndoCloseTab"/> oncommand="PanelUI.showSubView('allTabsMenu-containerTabsView', this);"
<toolbarbutton id="allTabsMenu-searchTabs" data-l10n-id="all-tabs-menu-new-user-context"/>
class="subviewbutton subviewbutton-iconic" <toolbarseparator id="allTabsMenu-hiddenTabsSeparator"/>
oncommand="gTabsPanel.searchTabs();" <toolbarbutton id="allTabsMenu-hiddenTabsButton"
data-l10n-id="all-tabs-menu-search-tabs"/> class="subviewbutton subviewbutton-nav"
<toolbarbutton id="allTabsMenu-containerTabsButton" closemenu="none"
class="subviewbutton subviewbutton-nav" oncommand="PanelUI.showSubView('allTabsMenu-hiddenTabsView', this);"
closemenu="none" data-l10n-id="all-tabs-menu-hidden-tabs"/>
oncommand="PanelUI.showSubView('allTabsMenu-containerTabsView', this);" <toolbarseparator id="allTabsMenu-tabsSeparator"/>
data-l10n-id="all-tabs-menu-new-user-context"/> <vbox id="allTabsMenu-allTabsViewTabs" class="panel-subview-body"/>
<toolbarseparator id="allTabsMenu-hiddenTabsSeparator"/> </vbox>
<toolbarbutton id="allTabsMenu-hiddenTabsButton" </panelview>
class="subviewbutton subviewbutton-nav"
closemenu="none"
oncommand="PanelUI.showSubView('allTabsMenu-hiddenTabsView', this);"
data-l10n-id="all-tabs-menu-hidden-tabs"/>
<toolbarseparator id="allTabsMenu-tabsSeparator"/>
<vbox id="allTabsMenu-allTabsViewTabs" class="panel-subview-body"/>
</vbox>
</panelview>
<panelview id="allTabsMenu-hiddenTabsView" class="PanelUI-subView"> <panelview id="allTabsMenu-hiddenTabsView" class="PanelUI-subView">
<vbox class="panel-subview-body"/> <vbox class="panel-subview-body"/>
</panelview> </panelview>
<panelview id="allTabsMenu-containerTabsView" class="PanelUI-subView"> <panelview id="allTabsMenu-containerTabsView" class="PanelUI-subView">
<vbox class="panel-subview-body"> <vbox class="panel-subview-body">
<toolbarseparator class="container-tabs-submenu-separator"/> <toolbarseparator class="container-tabs-submenu-separator"/>
<toolbarbutton class="subviewbutton" <toolbarbutton class="subviewbutton"
data-l10n-id="all-tabs-menu-manage-user-context" data-l10n-id="all-tabs-menu-manage-user-context"
command="Browser:OpenAboutContainers"/> command="Browser:OpenAboutContainers"/>
</vbox> </vbox>
</panelview> </panelview>
</panelmultiview> </html:template>
</panel>

View file

@ -27,6 +27,8 @@ var gTabsPanel = {
if (this._initializedElements) { if (this._initializedElements) {
return; return;
} }
let template = document.getElementById("allTabsMenu-container");
template.replaceWith(template.content);
for (let [name, id] of Object.entries(this.kElements)) { for (let [name, id] of Object.entries(this.kElements)) {
this[name] = document.getElementById(id); this[name] = document.getElementById(id);
@ -147,8 +149,9 @@ var gTabsPanel = {
}, },
hideAllTabsPanel() { hideAllTabsPanel() {
this.init(); if (this.allTabsView) {
PanelMultiView.hidePopup(this.allTabsView.closest("panel")); PanelMultiView.hidePopup(this.allTabsView.closest("panel"));
}
}, },
showHiddenTabsPanel(event) { showHiddenTabsPanel(event) {

View file

@ -2269,11 +2269,6 @@ var gBrowserInit = {
gSync.init(); gSync.init();
}); });
scheduleIdleTask(() => {
// Initialize the all tabs menu
gTabsPanel.init();
});
scheduleIdleTask(() => { scheduleIdleTask(() => {
// Read prefers-reduced-motion setting // Read prefers-reduced-motion setting
let reduceMotionQuery = window.matchMedia( let reduceMotionQuery = window.matchMedia(

View file

@ -320,6 +320,8 @@ async function doTestForAllTabsFavicon(
assertIconIsData(tabInfo.tab); assertIconIsData(tabInfo.tab);
gTabsPanel.init();
// Make the popup of allTabs showing up and trigger the loading of the favicon. // Make the popup of allTabs showing up and trigger the loading of the favicon.
let allTabsView = document.getElementById("allTabsMenu-allTabsView"); let allTabsView = document.getElementById("allTabsMenu-allTabsView");
let allTabsPopupShownPromise = BrowserTestUtils.waitForEvent( let allTabsPopupShownPromise = BrowserTestUtils.waitForEvent(

View file

@ -266,6 +266,8 @@ async function doTestForAllTabsFavicon(aTestPage, aFaviconHost, aFaviconURL) {
// be made for the favicon of allTabs menuitem. // be made for the favicon of allTabs menuitem.
clearAllImageCaches(); clearAllImageCaches();
gTabsPanel.init();
// Make the popup of allTabs showing up and trigger the loading of the favicon. // Make the popup of allTabs showing up and trigger the loading of the favicon.
let allTabsView = document.getElementById("allTabsMenu-allTabsView"); let allTabsView = document.getElementById("allTabsMenu-allTabsView");
let allTabsPopupShownPromise = BrowserTestUtils.waitForEvent( let allTabsPopupShownPromise = BrowserTestUtils.waitForEvent(