Bug 1438511 - Don't update sidebar UI density before SidebarUI is initialized, or if the sidebar is not open. r=florian
MozReview-Commit-ID: GTfBrSccecX
--- a/browser/base/content/browser-sidebar.js
+++ b/browser/base/content/browser-sidebar.js
@@ -43,29 +43,36 @@ var SidebarUI = {
return this.__title = document.getElementById("sidebar-title");
},
_splitter: null,
_icon: null,
_reversePositionButton: null,
_switcherPanel: null,
_switcherTarget: null,
_switcherArrow: null,
+ _inited: false,
+
+ get initialized() {
+ return this._inited;
+ },
init() {
this._box = document.getElementById("sidebar-box");
this._splitter = document.getElementById("sidebar-splitter");
this._icon = document.getElementById("sidebar-icon");
this._reversePositionButton = document.getElementById("sidebar-reverse-position");
this._switcherPanel = document.getElementById("sidebarMenu-popup");
this._switcherTarget = document.getElementById("sidebar-switcher-target");
this._switcherArrow = document.getElementById("sidebar-switcher-arrow");
this._switcherTarget.addEventListener("command", () => {
this.toggleSwitcherPanel();
});
+
+ this._inited = true;
},
uninit() {
// If this is the last browser window, persist various values that should be
// remembered for after a restart / reopening a browser window.
let enumerator = Services.wm.getEnumerator("navigator:browser");
if (!enumerator.hasMoreElements()) {
document.persist("sidebar-box", "sidebarcommand");
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -5631,39 +5631,42 @@ var gUIDensity = {
Services.prefs.setIntPref(this.uiDensityPref, mode);
},
update(mode) {
if (mode == null) {
mode = this.getCurrentDensity().mode;
}
- let docs = [
- document.documentElement,
- SidebarUI.browser.contentDocument.documentElement,
- ];
+ let docs = [document.documentElement];
+ let shouldUpdateSidebar = SidebarUI.initialized && SidebarUI.isOpen;
+ if (shouldUpdateSidebar) {
+ docs.push(SidebarUI.browser.contentDocument.documentElement);
+ }
for (let doc of docs) {
switch (mode) {
case this.MODE_COMPACT:
doc.setAttribute("uidensity", "compact");
break;
case this.MODE_TOUCH:
doc.setAttribute("uidensity", "touch");
break;
default:
doc.removeAttribute("uidensity");
break;
}
}
- let tree = SidebarUI.browser.contentDocument.querySelector(".sidebar-placesTree");
- if (tree) {
- // Tree items don't update their styles without changing some property on the
- // parent tree element, like background-color or border. See bug 1407399.
- tree.style.border = "1px";
- tree.style.border = "";
+ if (shouldUpdateSidebar) {
+ let tree = SidebarUI.browser.contentDocument.querySelector(".sidebar-placesTree");
+ if (tree) {
+ // Tree items don't update their styles without changing some property on the
+ // parent tree element, like background-color or border. See bug 1407399.
+ tree.style.border = "1px";
+ tree.style.border = "";
+ }
}
TabsInTitlebar.updateAppearance(true);
gBrowser.tabContainer.uiDensityChanged();
},
};
var gHomeButton = {