Bug 1582585 - Factor out a bit more code from AutoScrollController.jsm. r=botond

Also an idempotent change.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Emilio Cobos Álvarez 2019-09-23 15:54:19 +00:00
parent 243aae81a3
commit 2e2227708b

View File

@ -70,6 +70,16 @@ class AutoScrollController {
return aNode instanceof content.XULElement;
}
computeWindowScrollDirection(global) {
if (global.scrollMaxX != global.scrollMinX) {
return global.scrollMaxY != global.scrollMinY ? "NSEW" : "EW";
}
if (global.scrollMaxY != global.scrollMinY) {
return "NS";
}
return null;
}
computeNodeScrollDirection(node) {
if (!this.isScrollableElement(node)) {
return null;
@ -125,18 +135,13 @@ class AutoScrollController {
}
if (!this._scrollable) {
this._scrollable = aNode.ownerGlobal;
if (this._scrollable.scrollMaxX != this._scrollable.scrollMinX) {
this._scrolldir =
this._scrollable.scrollMaxY != this._scrollable.scrollMinY
? "NSEW"
: "EW";
} else if (this._scrollable.scrollMaxY != this._scrollable.scrollMinY) {
this._scrolldir = "NS";
} else if (this._scrollable.frameElement) {
this.findNearestScrollableElement(this._scrollable.frameElement);
} else {
this._scrollable = null; // abort scrolling
let direction = this.computeWindowScrollDirection(aNode.ownerGlobal);
if (direction) {
this._scrolldir = direction;
this._scrollable = aNode.ownerGlobal;
} else if (aNode.ownerGlobal.frameElement) {
// FIXME(emilio): This won't work with Fission.
this.findNearestScrollableElement(aNode.ownerGlobal.frameElement);
}
}
}