зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
69b67fa839
Коммит
0549d5f10b
|
@ -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");
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -113,8 +117,6 @@ class ZoomChild extends JSWindowActorChild {
|
|||
);
|
||||
this._resolutionBeforeFullZoomChange = 0;
|
||||
}
|
||||
|
||||
this.sendAsyncMessage("PostFullZoomChange", {});
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,14 +15,21 @@ 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 two types of messages:
|
||||
* 1) "Do" messages. These are requests from the ZoomChild that represent
|
||||
* action requests from the platform code. We pass these events on to
|
||||
* the frontend FullZoom actor that will take the requested action.
|
||||
* 2) ZoomChange messages. These are updates from the ZoomChild that
|
||||
* changes have already been made to the zoom. We pass these events on
|
||||
* other listeners so that they can also update state. FullZoom has
|
||||
* a PostFullZoomChange method to support automated testing, which
|
||||
* needs to know that both the zoom has changed and the resolution has
|
||||
* been updated by the ZoomChild. TextZoom has no such requirement, and
|
||||
* therefore no need for a PostTextZoomChange event.
|
||||
**/
|
||||
|
||||
switch (message.name) {
|
||||
case "FullZoomChange": {
|
||||
browser._fullZoom = message.data.value;
|
||||
let event = document.createEvent("Events");
|
||||
|
@ -46,9 +53,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;
|
||||
}
|
||||
|
|
|
@ -348,7 +348,14 @@ let ACTORS = {
|
|||
PreFullZoomChange: {},
|
||||
FullZoomChange: {},
|
||||
TextZoomChange: {},
|
||||
ZoomChangeUsingMouseWheel: {},
|
||||
DoZoomEnlargeBy10: {
|
||||
capture: true,
|
||||
mozSystemGroup: true,
|
||||
},
|
||||
DoZoomReduceBy10: {
|
||||
capture: true,
|
||||
mozSystemGroup: true,
|
||||
},
|
||||
mozupdatedremoteframedimensions: {
|
||||
capture: true,
|
||||
mozSystemGroup: true,
|
||||
|
|
Загрузка…
Ссылка в новой задаче