Bug 1516413 Part 2: Make browser FullZoom act on the new zoom change events. r=mstange

This replaces the handling of the ZoomChangeUsingMouseWheel event with
2 new zoom events that trigger the actual zoom changes. As a side effect,
this allows the mousewheel and zoom in/out key events to have an effect
on Reader and PDFJS views as well.

Differential Revision: https://phabricator.services.mozilla.com/D59260

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Brad Werth 2020-01-30 17:17:26 +00:00
parent 23f9ccf4aa
commit 67081368c7
5 changed files with 87 additions and 29 deletions

View File

@ -48,7 +48,8 @@ var FullZoom = {
// Initialization & Destruction
init: function FullZoom_init() {
gBrowser.addEventListener("ZoomChangeUsingMouseWheel", this);
gBrowser.addEventListener("DoZoomEnlargeBy10", this);
gBrowser.addEventListener("DoZoomReduceBy10", this);
// Register ourselves with the service so we know when our pref changes.
this._cps2 = Cc["@mozilla.org/content-pref/service;1"].getService(
@ -83,7 +84,8 @@ var FullZoom = {
destroy: function FullZoom_destroy() {
Services.prefs.removeObserver("browser.zoom.", this);
this._cps2.removeObserverForName(this.name, this);
gBrowser.removeEventListener("ZoomChangeUsingMouseWheel", this);
gBrowser.removeEventListener("DoZoomEnlargeBy10", this);
gBrowser.removeEventListener("DoZoomReduceBy10", this);
},
// Event Handlers
@ -92,10 +94,11 @@ var FullZoom = {
handleEvent: function FullZoom_handleEvent(event) {
switch (event.type) {
case "ZoomChangeUsingMouseWheel":
let browser = this._getTargetedBrowser(event);
this._ignorePendingZoomAccesses(browser);
this._applyZoomToPref(browser);
case "DoZoomEnlargeBy10":
this.changeZoomBy(this._getTargetedBrowser(event), 0.1);
break;
case "DoZoomReduceBy10":
this.changeZoomBy(this._getTargetedBrowser(event), -0.1);
break;
}
},
@ -357,6 +360,35 @@ var FullZoom = {
}
},
/**
* If browser in reader mode sends message to reader in order to increase font size,
* Otherwise enlarges the zoom level of the page in the current browser.
* This function is not async like reduce/enlarge, because it is invoked by our
* event handler. This means that the call to _applyZoomToPref is not awaited and
* will happen asynchronously.
*/
changeZoomBy(aBrowser, aValue) {
if (aBrowser.currentURI.spec.startsWith("about:reader")) {
const message = aValue > 0 ? "Reader::ZoomIn" : "Reader:ZoomOut";
aBrowser.messageManager.sendAsyncMessage(message);
return;
} else if (this._isPDFViewer(aBrowser)) {
const message = aValue > 0 ? "PDFJS::ZoomIn" : "PDFJS:ZoomOut";
aBrowser.messageManager.sendAsyncMessage(message);
return;
}
let zoom = ZoomManager.getZoomForBrowser(aBrowser);
zoom += aValue;
if (zoom < ZoomManager.MIN) {
zoom = ZoomManager.MIN;
} else if (zoom > ZoomManager.MAX) {
zoom = ZoomManager.MAX;
}
ZoomManager.setZoomForBrowser(aBrowser, zoom);
this._ignorePendingZoomAccesses(aBrowser);
this._applyZoomToPref(aBrowser);
},
/**
* Sets the zoom level for the given browser to the given floating
* point value, where 1 is the default zoom level.
@ -536,7 +568,7 @@ var FullZoom = {
/**
* Returns the browser that the supplied zoom event is associated with.
* @param event The ZoomChangeUsingMouseWheel event.
* @param event The zoom event.
* @return The associated browser element, if one exists, otherwise null.
*/
_getTargetedBrowser: function FullZoom__getTargetedBrowser(event) {
@ -560,7 +592,7 @@ var FullZoom = {
return target.ownerGlobal.docShell.chromeEventHandler;
}
throw new Error("Unexpected ZoomChangeUsingMouseWheel event source");
throw new Error("Unexpected zoom event source");
},
/**

View File

@ -871,7 +871,7 @@ function promiseRDMZoom(ui, browser, zoom) {
const zoomComplete = BrowserTestUtils.waitForEvent(
browser,
"PostFullZoomChange"
"FullZoomResolutionStable"
);
ZoomManager.setZoomForBrowser(browser, zoom);

View File

@ -27,12 +27,12 @@ class ZoomChild extends JSWindowActorChild {
}
set fullZoom(value) {
this._cache.fullZoom = value;
this._cache.fullZoom = Number(value.toFixed(2));
this._markupViewer.fullZoom = value;
}
set textZoom(value) {
this._cache.textZoom = value;
this._cache.textZoom = Number(value.toFixed(2));
this._markupViewer.textZoom = value;
}
@ -75,12 +75,18 @@ class ZoomChild extends JSWindowActorChild {
}
handleEvent(event) {
if (event.type == "ZoomChangeUsingMouseWheel") {
this.sendAsyncMessage("ZoomChangeUsingMouseWheel", {});
// Send do zoom events to our parent as messages, to be re-dispatched.
if (event.type == "DoZoomEnlargeBy10") {
this.sendAsyncMessage("DoZoomEnlargeBy10", {});
return;
}
// Only handle this event for top-level content.
if (event.type == "DoZoomReduceBy10") {
this.sendAsyncMessage("DoZoomReduceBy10", {});
return;
}
// Only handle remaining events for top-level content.
if (this.browsingContext != this.browsingContext.top) {
return;
}
@ -92,8 +98,6 @@ class ZoomChild extends JSWindowActorChild {
if (this._resolutionBeforeFullZoomChange == 0) {
this._resolutionBeforeFullZoomChange = this.contentWindow.windowUtils.getResolution();
}
this.sendAsyncMessage("PreFullZoomChange", {});
return;
}
@ -114,7 +118,7 @@ class ZoomChild extends JSWindowActorChild {
this._resolutionBeforeFullZoomChange = 0;
}
this.sendAsyncMessage("PostFullZoomChange", {});
this.sendAsyncMessage("FullZoomResolutionStable", {});
return;
}

View File

@ -15,14 +15,22 @@ class ZoomParent extends JSWindowActorParent {
let document = browser.ownerGlobal.document;
switch (message.name) {
case "PreFullZoomChange": {
let event = document.createEvent("Events");
event.initEvent("PreFullZoomChange", true, false);
browser.dispatchEvent(event);
break;
}
/**
* We respond to three types of messages:
* 1) "Do" messages. These are requests from the ZoomChild that represent
* action requests from the platform code. We send matching events on
* to the frontend FullZoom actor that will take the requested action.
* 2) ZoomChange messages. These are messages from the ZoomChild that
* changes have been made to the zoom by the platform code. We create
* events for other listeners so that they can also update state.
* These messages will not be sent by the ZoomChild if the zoom change
* originated in the ZoomParent actor.
* 3) FullZoomResolutionStable. This is received after zoom is applied to
* a Responsive Design Mode frame and it has reached a stable
* resolution. We fire an event that is used by tests.
**/
switch (message.name) {
case "FullZoomChange": {
browser._fullZoom = message.data.value;
let event = document.createEvent("Events");
@ -31,9 +39,9 @@ class ZoomParent extends JSWindowActorParent {
break;
}
case "PostFullZoomChange": {
case "FullZoomResolutionStable": {
let event = document.createEvent("Events");
event.initEvent("PostFullZoomChange", true, false);
event.initEvent("FullZoomResolutionStable", true, false);
browser.dispatchEvent(event);
break;
}
@ -46,9 +54,16 @@ class ZoomParent extends JSWindowActorParent {
break;
}
case "ZoomChangeUsingMouseWheel": {
case "DoZoomEnlargeBy10": {
let event = document.createEvent("Events");
event.initEvent("ZoomChangeUsingMouseWheel", true, false);
event.initEvent("DoZoomEnlargeBy10", true, false);
browser.dispatchEvent(event);
break;
}
case "DoZoomReduceBy10": {
let event = document.createEvent("Events");
event.initEvent("DoZoomReduceBy10", true, false);
browser.dispatchEvent(event);
break;
}

View File

@ -377,7 +377,14 @@ let ACTORS = {
PreFullZoomChange: {},
FullZoomChange: {},
TextZoomChange: {},
ZoomChangeUsingMouseWheel: {},
DoZoomEnlargeBy10: {
capture: true,
mozSystemGroup: true,
},
DoZoomReduceBy10: {
capture: true,
mozSystemGroup: true,
},
mozupdatedremoteframedimensions: {
capture: true,
mozSystemGroup: true,