Bug 1345375 - Use remote-browser.xml's FullZoomChange event to simplify zoom ui-controls as well as correctly update the zoom ui-controls on ImageDocuments. r?dao draft
authorJared Wein <jwein@mozilla.com>
Thu, 09 Mar 2017 16:33:57 -0500
changeset 496160 288e7fc76a43aef44de6f3d8eb0d938256c51e33
parent 495950 34585620e529614c79ecc007705646de748e592d
child 548558 60451092df32335ae58cee05432ee3a1d015bdee
push id48538
push userjwein@mozilla.com
push dateThu, 09 Mar 2017 21:40:03 +0000
reviewersdao
bugs1345375
milestone55.0a1
Bug 1345375 - Use remote-browser.xml's FullZoomChange event to simplify zoom ui-controls as well as correctly update the zoom ui-controls on ImageDocuments. r?dao MozReview-Commit-ID: D2mft3jF2pe
browser/components/customizableui/CustomizableWidgets.jsm
browser/modules/URLBarZoom.jsm
toolkit/content/browser-content.js
--- a/browser/components/customizableui/CustomizableWidgets.jsm
+++ b/browser/components/customizableui/CustomizableWidgets.jsm
@@ -721,19 +721,18 @@ const CustomizableWidgets = [
           zoomFactor = Math.round(window.ZoomManager.zoom * 100);
         } catch (e) {}
         zoomResetButton.setAttribute("label", CustomizableUI.getLocalizedProperty(
           buttons[1], "label", [updateDisplay ? zoomFactor : 100]
         ));
       }
 
       // 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:location-change", false);
+      window.addEventListener("FullZoomChange", updateZoomResetButton);
 
       if (inPanel) {
         let panel = aDocument.getElementById(kPanelId);
         panel.addEventListener("popupshowing", updateZoomResetButton);
       } else {
         if (inToolbar) {
           let container = window.gBrowser.tabContainer;
           container.addEventListener("TabSelect", updateZoomResetButton);
@@ -800,19 +799,18 @@ const CustomizableWidgets = [
           updateZoomResetButton();
         }.bind(this),
 
         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:location-change");
+          window.removeEventListener("FullZoomChange", updateZoomResetButton);
           let panel = aDoc.getElementById(kPanelId);
           panel.removeEventListener("popupshowing", updateZoomResetButton);
           let container = aDoc.defaultView.gBrowser.tabContainer;
           container.removeEventListener("TabSelect", updateZoomResetButton);
         }.bind(this),
 
         onCustomizeStart(aWindow) {
           if (aWindow.document == aDocument) {
--- a/browser/modules/URLBarZoom.jsm
+++ b/browser/modules/URLBarZoom.jsm
@@ -9,17 +9,19 @@ this.EXPORTED_SYMBOLS = [ "URLBarZoom" ]
 
 Components.utils.import("resource://gre/modules/Services.jsm");
 
 var URLBarZoom = {
   init(aWindow) {
     aWindow.addEventListener("EndSwapDocShells", onEndSwapDocShells, true);
     aWindow.addEventListener("unload", () => {
       aWindow.removeEventListener("EndSwapDocShells", onEndSwapDocShells, true);
+      aWindow.removeEventListener("FullZoomChange", onFullZoomChange);
     }, {once: true});
+    aWindow.addEventListener("FullZoomChange", onFullZoomChange);
   },
 }
 
 function fullZoomObserver(aSubject, aTopic) {
   // If the tab was the last one in its window and has been dragged to another
   // window, the original browser's window will be unavailable here. Since that
   // window is closing, we can just ignore this notification.
   if (!aSubject.ownerGlobal) {
@@ -29,43 +31,44 @@ function fullZoomObserver(aSubject, aTop
   let animate = (aTopic != "browser-fullZoom:location-change");
   updateZoomButton(aSubject, animate);
 }
 
 function onEndSwapDocShells(event) {
   updateZoomButton(event.originalTarget);
 }
 
+function onFullZoomChange(event) {
+  updateZoomButton(event.originalTarget, true);
+}
+
   /**
    * Updates the zoom button in the location bar.
    *
    * @param {object} aBrowser The browser that the zoomed content resides in.
    * @param {boolean} aAnimate Should be True for all cases unless the zoom
    *   change is related to tab switching. Optional
-   * @param {number} aValue The value that should be used for the zoom control.
-   *   If not provided then the value will be read from the window. Useful
-   *   if the data on the window may be stale.
    */
-function updateZoomButton(aBrowser, aAnimate = false, aValue = undefined) {
+function updateZoomButton(aBrowser, aAnimate = false) {
   let win = aBrowser.ownerGlobal;
   if (aBrowser != win.gBrowser.selectedBrowser) {
     return;
   }
 
   let customizableZoomControls = win.document.getElementById("zoom-controls");
   let zoomResetButton = win.document.getElementById("urlbar-zoom-button");
 
   // Ensure that zoom controls haven't already been added to browser in Customize Mode
   if (customizableZoomControls &&
       customizableZoomControls.getAttribute("cui-areatype") == "toolbar") {
     zoomResetButton.hidden = true;
     return;
   }
 
-  let zoomFactor = Math.round((aValue || win.ZoomManager.zoom) * 100);
+  let zoomFactor = Math.round(win.ZoomManager.zoom * 100);
   if (zoomFactor != 100) {
     // Check if zoom button is visible and update label if it is
     if (zoomResetButton.hidden) {
       zoomResetButton.hidden = false;
     }
     if (aAnimate) {
       zoomResetButton.setAttribute("animate", "true");
     } else {
@@ -74,14 +77,9 @@ function updateZoomButton(aBrowser, aAni
     zoomResetButton.setAttribute("label",
         win.gNavigatorBundle.getFormattedString("urlbar-zoom-button.label", [zoomFactor]));
   } else {
     // Hide button if zoom is at 100%
     zoomResetButton.hidden = true;
   }
 }
 
-Services.obs.addObserver(fullZoomObserver, "browser-fullZoom:zoomChange", false);
-Services.obs.addObserver(fullZoomObserver, "browser-fullZoom:zoomReset", false);
 Services.obs.addObserver(fullZoomObserver, "browser-fullZoom:location-change", false);
-Services.mm.addMessageListener("SyntheticDocument:ZoomChange", function(aMessage) {
-  updateZoomButton(aMessage.target, true, aMessage.data.value);
-});
--- a/toolkit/content/browser-content.js
+++ b/toolkit/content/browser-content.js
@@ -1772,30 +1772,16 @@ let DateTimePickerListener = {
       default:
         break;
     }
   },
 }
 
 DateTimePickerListener.init();
 
-let URLBarZoom = {
-  init() {
-    addEventListener("FullZoomChange", e => {
-      if (!e.target.mozSyntheticDocument) {
-        return;
-      }
-      sendSyncMessage("SyntheticDocument:ZoomChange",
-        {"value": docShell.contentViewer.fullZoom});
-    });
-  }
-};
-
-URLBarZoom.init();
-
 addEventListener("mozshowdropdown", event => {
   if (!event.isTrusted)
     return;
 
   if (!SelectContentHelper.open) {
     new SelectContentHelper(event.target, {isOpenedViaTouch: false}, this);
   }
 });