Bug 902924 - Remove the dependency on FullZoom_onLocationChange from the zoom controls. r=mikedeboer
authorJared Wein <jwein@mozilla.com>
Thu, 08 Aug 2013 14:10:36 -0400
changeset 155643 8350a4f51a48
parent 155642 8e820dfb7ff3
child 155644 2567da54457e
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)
reviewersmikedeboer
bugs902924
milestone26.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 902924 - Remove the dependency on FullZoom_onLocationChange from the zoom controls. r=mikedeboer
browser/components/customizableui/src/CustomizableWidgets.jsm
--- a/browser/components/customizableui/src/CustomizableWidgets.jsm
+++ b/browser/components/customizableui/src/CustomizableWidgets.jsm
@@ -271,16 +271,17 @@ const CustomizableWidgets = [{
     }
   }, {
     id: "zoom-controls",
     type: "custom",
     removable: true,
     defaultArea: CustomizableUI.AREA_PANEL,
     allowedAreas: [CustomizableUI.AREA_PANEL, CustomizableUI.AREA_NAVBAR],
     onBuild: function(aDocument) {
+      const kPanelId = "PanelUI-popup";
       let inPanel = (this.currentArea == CustomizableUI.AREA_PANEL);
       let noautoclose = inPanel ? "true" : null;
       let flex = inPanel ? "1" : null;
       let cls = inPanel ? "panel-combined-button" : "toolbarbutton-1";
       let buttons = [{
         id: "zoom-out-button",
         noautoclose: noautoclose,
         command: "cmd_fullZoomReduce",
@@ -336,21 +337,23 @@ const CustomizableWidgets = [{
         zoomResetButton.setAttribute("label", CustomizableUI.getLocalizedProperty(
           buttons[1], "label", [zoomFactor]
         ));
       };
 
       // Register ourselves with the service so we know when the zoom prefs change.
       Services.obs.addObserver(updateZoomResetButton, "browser-fullZoom:zoomChange", false);
       Services.obs.addObserver(updateZoomResetButton, "browser-fullZoom:zoomReset", false);
-      Services.obs.addObserver(updateZoomResetButton, "browser-fullZoom:locationChange", false);
 
-      updateZoomResetButton();
-      if (!inPanel)
+      if (inPanel) {
+        let panel = aDocument.getElementById(kPanelId);
+        panel.addEventListener("popupshowing", updateZoomResetButton);
+      } else {
         zoomResetButton.setAttribute("hidden", "true");
+      }
 
       function updateWidgetStyle(aInPanel) {
         let attrs = {
           noautoclose: aInPanel ? "true" : null,
           flex: aInPanel ? "1" : null,
           class: aInPanel ? "panel-combined-button" : "toolbarbutton-1"
         };
         for (let i = 0, l = node.childNodes.length; i < l; ++i) {
@@ -368,26 +371,36 @@ const CustomizableWidgets = [{
           if (this.currentArea == CustomizableUI.AREA_PANEL) {
             adjustPosition(node);
           }
 
           if (aWidgetId != this.id)
             return;
 
           updateWidgetStyle(aArea == CustomizableUI.AREA_PANEL);
+          if (aArea == CustomizableUI.AREA_PANEL) {
+            zoomResetButton.removeAttribute("hidden");
+            let panel = aDocument.getElementById(kPanelId);
+            panel.addEventListener("popupshowing", updateZoomResetButton);
+          }
         }.bind(this),
 
         onWidgetRemoved: function(aWidgetId, aPrevArea) {
           if (this.currentArea == CustomizableUI.AREA_PANEL) {
             adjustPosition(node);
           }
 
           if (aWidgetId != this.id)
             return;
 
+          if (aPrevArea == CustomizableUI.AREA_PANEL) {
+            let panel = aDocument.getElementById(kPanelId);
+            panel.removeEventListener("popupshowing", updateZoomResetButton);
+          }
+
           // When a widget is demoted to the palette ('removed'), it's visual
           // style should change.
           updateWidgetStyle(false);
           zoomResetButton.setAttribute("hidden", "true");
         }.bind(this),
 
         onWidgetReset: function(aWidgetId) {
           if (aWidgetId != this.id)
@@ -407,17 +420,18 @@ const CustomizableWidgets = [{
 
         onWidgetInstanceRemoved: function(aWidgetId, aDoc) {
           if (aWidgetId != this.id || aDoc != aDocument)
             return;
 
           CustomizableUI.removeListener(listener);
           Services.obs.removeObserver(updateZoomResetButton, "browser-fullZoom:zoomChange");
           Services.obs.removeObserver(updateZoomResetButton, "browser-fullZoom:zoomReset");
-          Services.obs.removeObserver(updateZoomResetButton, "browser-fullZoom:locationChange");
+          let panel = aDoc.getElementById(kPanelId);
+          panel.removeEventListener("popupshowing", updateZoomResetButton);
         }.bind(this)
       };
       CustomizableUI.addListener(listener);
 
       return node;
     }
   }, {
     id: "edit-controls",