Bug 1472491: Part 5s - Add ZoomChild actor. r=mconley
MozReview-Commit-ID: 9vTa1PbTh5t
--- a/browser/base/content/test/performance/browser_startup_content.js
+++ b/browser/base/content/test/performance/browser_startup_content.js
@@ -56,16 +56,17 @@ const whitelist = {
"resource://gre/modules/ActorChild.jsm",
"resource://gre/modules/ActorManagerChild.jsm",
"resource://gre/modules/BrowserUtils.jsm",
"resource://gre/modules/E10SUtils.jsm",
"resource://gre/modules/PrivateBrowsingUtils.jsm",
"resource://gre/modules/ReaderMode.jsm",
"resource://gre/modules/WebProgressChild.jsm",
"resource://gre/modules/WebNavigationChild.jsm",
+ "resource://gre/modules/ZoomChild.jsm",
// Pocket
"chrome://pocket/content/AboutPocket.jsm",
// Telemetry
"resource://gre/modules/TelemetryController.jsm", // bug 1470339
"resource://gre/modules/TelemetrySession.jsm", // bug 1470339
"resource://gre/modules/TelemetryUtils.jsm", // bug 1470339
new file mode 100644
--- /dev/null
+++ b/toolkit/actors/ZoomChild.jsm
@@ -0,0 +1,89 @@
+/* vim: set ts=2 sw=2 sts=2 et tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+"use strict";
+
+var EXPORTED_SYMBOLS = ["ZoomChild"];
+
+ChromeUtils.import("resource://gre/modules/ActorChild.jsm");
+
+class ZoomChild extends ActorChild {
+ constructor(mm) {
+ super(mm);
+ this._cache = {
+ fullZoom: NaN,
+ textZoom: NaN,
+ };
+ }
+
+ get fullZoom() {
+ return this._cache.fullZoom;
+ }
+
+ get textZoom() {
+ return this._cache.textZoom;
+ }
+
+ set fullZoom(value) {
+ this._cache.fullZoom = value;
+ this._markupViewer.fullZoom = value;
+ }
+
+ set textZoom(value) {
+ this._cache.textZoom = value;
+ this._markupViewer.textZoom = value;
+ }
+
+ refreshFullZoom() {
+ return this._refreshZoomValue("fullZoom");
+ }
+
+ refreshTextZoom() {
+ return this._refreshZoomValue("textZoom");
+ }
+
+ /**
+ * Retrieves specified zoom property value from markupViewer and refreshes
+ * cache if needed.
+ * @param valueName Either 'fullZoom' or 'textZoom'.
+ * @returns Returns true if cached value was actually refreshed.
+ * @private
+ */
+ _refreshZoomValue(valueName) {
+ let actualZoomValue = this._markupViewer[valueName];
+ // Round to remove any floating-point error.
+ actualZoomValue = Number(actualZoomValue.toFixed(2));
+ if (actualZoomValue != this._cache[valueName]) {
+ this._cache[valueName] = actualZoomValue;
+ return true;
+ }
+ return false;
+ }
+
+ get _markupViewer() {
+ return this.docShell.contentViewer;
+ }
+
+ receiveMessage(message) {
+ if (message.name == "FullZoom") {
+ this.fullZoom = message.data.value;
+ } else if (message.name == "TextZoom") {
+ this.textZoom = message.data.value;
+ }
+ }
+
+ handleEvent(event) {
+ if (event.type == "FullZoomChange") {
+ if (this.refreshFullZoom()) {
+ this.mm.sendAsyncMessage("FullZoomChange", { value: this.fullZoom });
+ }
+ } else if (event.type == "TextZoomChange") {
+ if (this.refreshTextZoom()) {
+ this.mm.sendAsyncMessage("TextZoomChange", { value: this.textZoom });
+ }
+ } else if (event.type == "ZoomChangeUsingMouseWheel") {
+ this.mm.sendAsyncMessage("ZoomChangeUsingMouseWheel", {});
+ }
+ }
+}
--- a/toolkit/actors/moz.build
+++ b/toolkit/actors/moz.build
@@ -5,9 +5,10 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
FINAL_TARGET_FILES.actors += [
'AudioPlaybackChild.jsm',
'ExtFindChild.jsm',
'FindBarChild.jsm',
'PrintingChild.jsm',
'SelectChild.jsm',
+ 'ZoomChild.jsm',
]
--- a/toolkit/content/browser-child.js
+++ b/toolkit/content/browser-child.js
@@ -70,100 +70,16 @@ addEventListener("ImageContentLoaded", f
let req = content.document.imageRequest;
if (!req.image)
return;
sendAsyncMessage("ImageDocumentLoaded", { width: req.image.width,
height: req.image.height });
}
}, false);
-const ZoomManager = {
- get fullZoom() {
- return this._cache.fullZoom;
- },
-
- get textZoom() {
- return this._cache.textZoom;
- },
-
- set fullZoom(value) {
- this._cache.fullZoom = value;
- this._markupViewer.fullZoom = value;
- },
-
- set textZoom(value) {
- this._cache.textZoom = value;
- this._markupViewer.textZoom = value;
- },
-
- refreshFullZoom() {
- return this._refreshZoomValue("fullZoom");
- },
-
- refreshTextZoom() {
- return this._refreshZoomValue("textZoom");
- },
-
- /**
- * Retrieves specified zoom property value from markupViewer and refreshes
- * cache if needed.
- * @param valueName Either 'fullZoom' or 'textZoom'.
- * @returns Returns true if cached value was actually refreshed.
- * @private
- */
- _refreshZoomValue(valueName) {
- let actualZoomValue = this._markupViewer[valueName];
- // Round to remove any floating-point error.
- actualZoomValue = Number(actualZoomValue.toFixed(2));
- if (actualZoomValue != this._cache[valueName]) {
- this._cache[valueName] = actualZoomValue;
- return true;
- }
- return false;
- },
-
- get _markupViewer() {
- return docShell.contentViewer;
- },
-
- _cache: {
- fullZoom: NaN,
- textZoom: NaN
- }
-};
-
-addMessageListener("FullZoom", function(aMessage) {
- ZoomManager.fullZoom = aMessage.data.value;
-});
-
-addMessageListener("TextZoom", function(aMessage) {
- ZoomManager.textZoom = aMessage.data.value;
-});
-
-addEventListener("FullZoomChange", function() {
- if (ZoomManager.refreshFullZoom()) {
- sendAsyncMessage("FullZoomChange", { value: ZoomManager.fullZoom });
- }
-}, false);
-
-addEventListener("TextZoomChange", function(aEvent) {
- if (ZoomManager.refreshTextZoom()) {
- sendAsyncMessage("TextZoomChange", { value: ZoomManager.textZoom });
- }
-}, false);
-
-addEventListener("ZoomChangeUsingMouseWheel", function() {
- sendAsyncMessage("ZoomChangeUsingMouseWheel", {});
-}, false);
-
-addMessageListener("UpdateCharacterSet", function(aMessage) {
- docShell.charset = aMessage.data.value;
- docShell.gatherCharsetMenuTelemetry();
-});
-
/**
* Remote thumbnail request handler for PageThumbs thumbnails.
*/
addMessageListener("Browser:Thumbnail:Request", function(aMessage) {
let snapshot;
let args = aMessage.data.additionalArgs;
let fullScale = args ? args.fullScale : false;
if (fullScale) {
--- a/toolkit/modules/ActorManagerParent.jsm
+++ b/toolkit/modules/ActorManagerParent.jsm
@@ -152,16 +152,31 @@ let ACTORS = {
child: {
module: "resource://gre/actors/SelectChild.jsm",
events: {
"mozshowdropdown": {},
"mozshowdropdown-sourcetouch": {},
},
},
},
+
+ Zoom: {
+ child: {
+ module: "resource://gre/actors/ZoomChild.jsm",
+ events: {
+ "FullZoomChange": {},
+ "TextZoomChange": {},
+ "ZoomChangeUsingMouseWheel": {},
+ },
+ messages: [
+ "FullZoom",
+ "TextZoom",
+ ],
+ },
+ },
};
class ActorSet {
constructor(group, actorSide) {
this.group = group;
this.actorSide = actorSide;
this.actors = new Map();