Bug 1579178 Part 2: Move the full zoom save-and-restore of resolution into the ZoomActorChild. draft
authorBrad Werth <bwerth@mozilla.com>
Fri, 06 Dec 2019 14:49:08 -0800
changeset 2527408 12f9ea7683242f4ab2edcce85a2b773f943a3103
parent 2527407 c4420bd689c84b138c8f227fb9490b54dc580ac4
child 2527409 ef9bcea8d4e83264fe0000a14610289adda44893
push id463378
push userbwerth@mozilla.com
push dateTue, 10 Dec 2019 21:01:34 +0000
treeherdertry@b30f4d00c856 [default view] [failures only]
bugs1579178
milestone73.0a1
Bug 1579178 Part 2: Move the full zoom save-and-restore of resolution into the ZoomActorChild. For the existing RDM UI, the saving and restoring of resolution is done in the content frame script, which is no longer loaded in the new UI. This approach is flexible enough that it will work for BOTH UIs. The next part of the patch contains the removal of the old method. Differential Revision: https://phabricator.services.mozilla.com/D56267
toolkit/actors/ZoomChild.jsm
toolkit/actors/ZoomParent.jsm
toolkit/modules/ActorManagerParent.jsm
--- a/toolkit/actors/ZoomChild.jsm
+++ b/toolkit/actors/ZoomChild.jsm
@@ -9,16 +9,18 @@ var EXPORTED_SYMBOLS = ["ZoomChild"];
 class ZoomChild extends JSWindowActorChild {
   constructor() {
     super();
 
     this._cache = {
       fullZoom: NaN,
       textZoom: NaN,
     };
+
+    this._resolutionBeforeFullZoomChange = 0;
   }
 
   get fullZoom() {
     return this._cache.fullZoom;
   }
 
   get textZoom() {
     return this._cache.textZoom;
@@ -78,19 +80,48 @@ class ZoomChild extends JSWindowActorChi
       return;
     }
 
     // Only handle this event for top-level content.
     if (this.browsingContext != this.browsingContext.top) {
       return;
     }
 
+    if (event.type == "PreFullZoomChange") {
+      // Check if we're in the middle of a full zoom change. If we are,
+      // don't capture the resolution again, because it hasn't yet been
+      // restored and may be in an indeterminate state.
+      if (this._resolutionBeforeFullZoomChange == 0) {
+        this._resolutionBeforeFullZoomChange = this.contentWindow.windowUtils.getResolution();
+      }
+
+      this.sendAsyncMessage("PreFullZoomChange", {});
+      return;
+    }
+
     if (event.type == "FullZoomChange") {
       if (this.refreshFullZoom()) {
         this.sendAsyncMessage("FullZoomChange", { value: this.fullZoom });
       }
-    } else if (event.type == "TextZoomChange") {
+      return;
+    }
+
+    if (event.type == "mozupdatedremoteframedimensions") {
+      // Check to see if we've already restored resolution, in which case
+      // there's no need to do it again.
+      if (this._resolutionBeforeFullZoomChange != 0) {
+        this.contentWindow.windowUtils.setResolutionAndScaleTo(
+          this._resolutionBeforeFullZoomChange
+        );
+        this._resolutionBeforeFullZoomChange = 0;
+      }
+
+      this.sendAsyncMessage("PostFullZoomChange", {});
+      return;
+    }
+
+    if (event.type == "TextZoomChange") {
       if (this.refreshTextZoom()) {
         this.sendAsyncMessage("TextZoomChange", { value: this.textZoom });
       }
     }
   }
 }
--- a/toolkit/actors/ZoomParent.jsm
+++ b/toolkit/actors/ZoomParent.jsm
@@ -11,24 +11,38 @@ class ZoomParent extends JSWindowActorPa
     let browser = this.browsingContext.top.embedderElement;
     if (!browser) {
       return;
     }
 
     let document = browser.ownerGlobal.document;
 
     switch (message.name) {
+      case "PreFullZoomChange": {
+        let event = document.createEvent("Events");
+        event.initEvent("PreFullZoomChange", true, false);
+        browser.dispatchEvent(event);
+        break;
+      }
+
       case "FullZoomChange": {
         browser._fullZoom = message.data.value;
         let event = document.createEvent("Events");
         event.initEvent("FullZoomChange", true, false);
         browser.dispatchEvent(event);
         break;
       }
 
+      case "PostFullZoomChange": {
+        let event = document.createEvent("Events");
+        event.initEvent("PostFullZoomChange", true, false);
+        browser.dispatchEvent(event);
+        break;
+      }
+
       case "TextZoomChange": {
         browser._textZoom = message.data.value;
         let event = document.createEvent("Events");
         event.initEvent("TextZoomChange", true, false);
         browser.dispatchEvent(event);
         break;
       }
 
--- a/toolkit/modules/ActorManagerParent.jsm
+++ b/toolkit/modules/ActorManagerParent.jsm
@@ -312,19 +312,24 @@ let ACTORS = {
 
   Zoom: {
     parent: {
       moduleURI: "resource://gre/actors/ZoomParent.jsm",
     },
     child: {
       moduleURI: "resource://gre/actors/ZoomChild.jsm",
       events: {
+        PreFullZoomChange: {},
         FullZoomChange: {},
         TextZoomChange: {},
         ZoomChangeUsingMouseWheel: {},
+        mozupdatedremoteframedimensions: {
+          capture: true,
+          mozSystemGroup: true,
+        },
       },
     },
 
     allFrames: true,
   },
 };
 
 /*