Bug 928722 - Resample the system scrollbar width when the UI theme is changed or mouse plugged in. (pair programmed with mconley). r=mconley
authorJared Wein <jwein@mozilla.com>
Thu, 06 Mar 2014 09:17:00 -0500
changeset 172279 dcd6cdbf6db512ce1116dbc100481ac064100d4f
parent 172278 fb4b2b7e2a2d54afb2b1001555eeac90db4e3175
child 172280 a3115bdac8fdb57e0e7329702a47ee69c21560d0
push id5499
push userjwein@mozilla.com
push dateThu, 06 Mar 2014 19:12:42 +0000
treeherderfx-team@dcd6cdbf6db5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley
bugs928722
milestone30.0a1
Bug 928722 - Resample the system scrollbar width when the UI theme is changed or mouse plugged in. (pair programmed with mconley). r=mconley
browser/components/customizableui/content/panelUI.js
browser/components/customizableui/src/ScrollbarSampler.jsm
--- a/browser/components/customizableui/content/panelUI.js
+++ b/browser/components/customizableui/content/panelUI.js
@@ -42,16 +42,18 @@ const PanelUI = {
       this.__defineGetter__(getKey, function() {
         delete this[getKey];
         return this[getKey] = document.getElementById(id);
       });
     }
 
     this.menuButton.addEventListener("mousedown", this);
     this.menuButton.addEventListener("keypress", this);
+    this._overlayScrollListenerBoundFn = this._overlayScrollListener.bind(this);
+    window.matchMedia("(-moz-overlay-scrollbars)").addListener(this._overlayScrollListenerBoundFn);
     this._initialized = true;
   },
 
   _eventListenersAdded: false,
   _ensureEventListenersAdded: function() {
     if (this._eventListenersAdded)
       return;
     this._addEventListeners();
@@ -72,16 +74,18 @@ const PanelUI = {
     }
 
     for (let event of this.kEvents) {
       this.panel.removeEventListener(event, this);
     }
     this.helpView.removeEventListener("ViewShowing", this._onHelpViewShow);
     this.menuButton.removeEventListener("mousedown", this);
     this.menuButton.removeEventListener("keypress", this);
+    window.matchMedia("(-moz-overlay-scrollbars)").removeListener(this._overlayScrollListenerBoundFn);
+    this._overlayScrollListenerBoundFn = null;
   },
 
   /**
    * Customize mode extracts the mainView and puts it somewhere else while the
    * user customizes. Upon completion, this function can be called to put the
    * panel back to where it belongs in normal browsing mode.
    *
    * @param aMainView
@@ -438,16 +442,22 @@ const PanelUI = {
 
     let key = document.getElementById("key_quitApplication");
     stringArgs.push(ShortcutUtils.prettifyShortcut(key));
     let tooltipString = CustomizableUI.getLocalizedProperty({x: tooltipId}, "x", stringArgs);
     let quitButton = document.getElementById("PanelUI-quit");
     quitButton.setAttribute("tooltiptext", tooltipString);
 #endif
   },
+
+  _overlayScrollListenerBoundFn: null,
+  _overlayScrollListener: function(aMQL) {
+    ScrollbarSampler.resetSystemScrollbarWidth();
+    this._scrollWidth = null;
+  },
 };
 
 /**
  * Gets the currently selected locale for display.
  * @return  the selected locale or "en-US" if none is selected
  */
 function getLocale() {
   try {
--- a/browser/components/customizableui/src/ScrollbarSampler.jsm
+++ b/browser/components/customizableui/src/ScrollbarSampler.jsm
@@ -26,16 +26,20 @@ this.ScrollbarSampler = {
 
     this._sampleSystemScrollbarWidth().then(function(systemScrollbarWidth) {
       gSystemScrollbarWidth = systemScrollbarWidth;
       deferred.resolve(gSystemScrollbarWidth);
     });
     return deferred.promise;
   },
 
+  resetSystemScrollbarWidth: function() {
+    gSystemScrollbarWidth = null;
+  },
+
   _sampleSystemScrollbarWidth: function() {
     let deferred = Promise.defer();
     let hwin = Services.appShell.hiddenDOMWindow;
     let hdoc = hwin.document.documentElement;
     let iframe = hwin.document.createElementNS("http://www.w3.org/1999/xhtml",
                                                "html:iframe");
     iframe.setAttribute("srcdoc", '<body style="overflow-y: scroll"></body>');
     hdoc.appendChild(iframe);