Bug 1438511 - Don't update sidebar UI density before SidebarUI is initialized, or if the sidebar is not open. r=florian
authorNihanth Subramanya <nhnt11@gmail.com>
Thu, 15 Feb 2018 19:31:03 +0530
changeset 404331 be58311261fcad925faeaceefe3303ceb1653865
parent 404317 6cfa628374192bc053d5837c892fc5d6f44a6778
child 404332 3ae4195fba9785117f76bdbe2cf3775cbb806a46
push id99984
push usershindli@mozilla.com
push dateSun, 18 Feb 2018 09:40:29 +0000
treeherdermozilla-inbound@473f8e78ebf9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersflorian
bugs1438511
milestone60.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
browser/base/content/browser-sidebar.js
browser/base/content/browser.js
--- 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
@@ -5605,39 +5605,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 = {