Bug 891104 - Only run onOverflow if an overflow event has occurred. r=mconley
authorJared Wein <jwein@mozilla.com>
Mon, 29 Jul 2013 15:36:39 -0400
changeset 155606 8637eb5091824ad386dce4eb3edf802a90d7c15a
parent 155605 b0549e859d2201b8f079b12c2b16256594adb34b
child 155607 e2fa6332a90779546f623d34da43d31445735793
push id25666
push userjwein@mozilla.com
push dateMon, 18 Nov 2013 15:56:58 +0000
treeherdermozilla-central@f2adb62d07eb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley
bugs891104
milestone25.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 891104 - Only run onOverflow if an overflow event has occurred. r=mconley
browser/components/customizableui/src/CustomizableUI.jsm
--- a/browser/components/customizableui/src/CustomizableUI.jsm
+++ b/browser/components/customizableui/src/CustomizableUI.jsm
@@ -2167,76 +2167,87 @@ function XULWidgetSingleWrapper(aWidgetI
 
 const LAZY_RESIZE_INTERVAL_MS = 200;
 
 function OverflowableToolbar(aToolbarNode) {
   this._toolbar = aToolbarNode;
   this._collapsed = [];
   this._enabled = true;
 
+  this._toolbar.customizationTarget.addEventListener("overflow", this);
   this._toolbar.setAttribute("overflowable", "true");
   Services.obs.addObserver(this, "browser-delayed-startup-finished", false);
 }
 
 OverflowableToolbar.prototype = {
+  _initialized: false,
+  _forceOnOverflow: false,
+
   observe: function(aSubject, aTopic, aData) {
     if (aTopic == "browser-delayed-startup-finished" &&
         aSubject == this._toolbar.ownerDocument.defaultView) {
       Services.obs.removeObserver(this, "browser-delayed-startup-finished");
       this.init();
     }
   },
 
   init: function() {
     this._target = this._toolbar.customizationTarget;
     let doc = this._toolbar.ownerDocument;
     this._list = doc.getElementById(this._toolbar.getAttribute("overflowtarget"));
-    this._toolbar.customizationTarget.addEventListener("overflow", this);
 
     let window = doc.defaultView;
     window.addEventListener("resize", this);
     window.gNavToolbox.addEventListener("customizationstarting", this);
     window.gNavToolbox.addEventListener("aftercustomization", this);
 
     let chevronId = this._toolbar.getAttribute("overflowbutton");
     this._chevron = doc.getElementById(chevronId);
     this._chevron.addEventListener("command", this);
 
     this._panel = doc.getElementById("widget-overflow");
     this._panel.addEventListener("popuphiding", this);
     CustomizableUIInternal.addPanelCloseListeners(this._panel);
 
-    this.initialized = true;
+    this._initialized = true;
 
-    // The toolbar could initialize in an overflowed state, in which case
-    // the 'overflow' event may have been fired before the handler was registered.
-    this._onOverflow();
+    // The 'overflow' event may have been fired before init was called.
+    if (this._forceOnOverflow) {
+      this._onOverflow();
+    }
   },
 
   uninit: function() {
-    if (!this.initialized) {
+    this._toolbar.customizationTarget.removeEventListener("overflow", this);
+    this._toolbar.removeAttribute("overflowable");
+
+    if (!this._initialized) {
+      Services.obs.removeObserver(this, "browser-delayed-startup-finished");
       return;
     }
+
     this._disable();
 
-    this._toolbar.removeAttribute("overflowable");
-    this._toolbar.customizationTarget.removeEventListener("overflow", this);
     let window = this._toolbar.ownerDocument.defaultView;
     window.removeEventListener("resize", this);
     window.gNavToolbox.removeEventListener("customizationstarting", this);
     window.gNavToolbox.removeEventListener("aftercustomization", this);
     this._chevron.removeEventListener("command", this);
     this._panel.removeEventListener("popuphiding", this);
     CustomizableUIInternal.removePanelCloseListeners(this._panel);
   },
 
   handleEvent: function(aEvent) {
     switch(aEvent.type) {
       case "overflow":
-        this._onOverflow();
+        if (this._initialized) {
+          this._onOverflow();
+        } else {
+          this._forceOnOverflow = true;
+        }
         break;
       case "resize":
         this._onResize(aEvent);
         break;
       case "command":
         this._onClickChevron(aEvent);
         break;
       case "popuphiding":