Bug 1648155 - Migrate GeckoViewScrollChild to Actor. r=snorp

Differential Revision: https://phabricator.services.mozilla.com/D93017
This commit is contained in:
Agi Sferro 2020-10-13 17:59:41 +00:00
parent 2fbfe32f08
commit 96d703076c
5 changed files with 57 additions and 46 deletions

View File

@ -0,0 +1,46 @@
/* 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/. */
const { GeckoViewActorChild } = ChromeUtils.import(
"resource://gre/modules/GeckoViewActorChild.jsm"
);
const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const EXPORTED_SYMBOLS = ["ScrollDelegateChild"];
class ScrollDelegateChild extends GeckoViewActorChild {
// eslint-disable-next-line complexity
handleEvent(aEvent) {
if (!this.isContentWindow) {
// This not a GeckoView-controlled window
return;
}
if (aEvent.originalTarget.ownerGlobal != this.contentWindow) {
return;
}
debug`handleEvent: ${aEvent.type}`;
switch (aEvent.type) {
case "mozvisualscroll":
const x = {};
const y = {};
this.contentWindow.windowUtils.getVisualViewportOffset(x, y);
this.eventDispatcher.sendRequest({
type: "GeckoView:ScrollChanged",
scrollX: x.value,
scrollY: y.value,
});
break;
}
}
}
const { debug, warn } = ScrollDelegateChild.initLogging("ScrollDelegate");

View File

@ -15,5 +15,6 @@ FINAL_TARGET_FILES.actors += [
'LoadURIDelegateChild.jsm',
'ProgressDelegateChild.jsm',
'ProgressDelegateParent.jsm',
'ScrollDelegateChild.jsm',
'WebBrowserChromeChild.jsm',
]

View File

@ -1,44 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* 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/. */
const { GeckoViewChildModule } = ChromeUtils.import(
"resource://gre/modules/GeckoViewChildModule.jsm"
);
class GeckoViewScrollChild extends GeckoViewChildModule {
onEnable() {
debug`onEnable`;
addEventListener("mozvisualscroll", this, { mozSystemGroup: true });
}
onDisable() {
debug`onDisable`;
removeEventListener("mozvisualscroll", { mozSystemGroup: true });
}
handleEvent(aEvent) {
if (aEvent.originalTarget.ownerGlobal != content) {
return;
}
debug`handleEvent: ${aEvent.type}`;
switch (aEvent.type) {
case "mozvisualscroll":
const x = {},
y = {};
content.windowUtils.getVisualViewportOffset(x, y);
this.eventDispatcher.sendRequest({
type: "GeckoView:ScrollChanged",
scrollX: x.value,
scrollY: y.value,
});
break;
}
}
}
const { debug, warn } = GeckoViewScrollChild.initLogging("GeckoViewScroll");
const module = GeckoViewScrollChild.create(this);

View File

@ -651,7 +651,16 @@ function startup() {
{
name: "GeckoViewScroll",
onEnable: {
frameScript: "chrome://geckoview/content/GeckoViewScrollChild.js",
actors: {
ScrollDelegate: {
child: {
moduleURI: "resource:///actors/ScrollDelegateChild.jsm",
events: {
mozvisualscroll: { mozSystemGroup: true },
},
},
},
},
},
},
{

View File

@ -16,7 +16,6 @@ geckoview.jar:
content/GeckoViewMediaChild.js
content/GeckoViewMediaControlChild.js
content/GeckoViewPromptChild.js
content/GeckoViewScrollChild.js
content/GeckoViewSelectionActionChild.js
content/SessionStateAggregator.js