Merge pull request #20142 from calixteman/bug1957680

Trigger a fake scrollend event in case it hasn't been triggered by the browser (bug 1957680)
This commit is contained in:
Tim van der Meij 2025-08-03 16:03:39 +02:00 committed by GitHub
commit e9a483014d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2227,19 +2227,18 @@ const PDFViewerApplication = {
mainContainer);
}
let scrollendTimeoutID, scrollAbortController;
const scrollend = () => {
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) {
({ scrollTop: this._lastScrollTop, scrollLeft: this._lastScrollLeft } =
mainContainer);
}
clearTimeout(scrollendTimeoutID);
if (this._isScrolling) {
scrollAbortController.abort();
scrollAbortController = null;
this._isScrolling = false;
mainContainer.addEventListener("scroll", scroll, {
passive: true,
signal,
});
mainContainer.removeEventListener("scrollend", scrollend);
mainContainer.removeEventListener("blur", scrollend);
}
};
const scroll = () => {
if (this._isCtrlKeyDown) {
@ -2253,10 +2252,27 @@ const PDFViewerApplication = {
return;
}
mainContainer.removeEventListener("scroll", scroll);
if (!this._isScrolling) {
scrollAbortController = new AbortController();
const abortSignal = AbortSignal.any([
scrollAbortController.signal,
signal,
]);
mainContainer.addEventListener("scrollend", scrollend, {
signal: abortSignal,
});
mainContainer.addEventListener("blur", scrollend, {
signal: abortSignal,
});
this._isScrolling = true;
mainContainer.addEventListener("scrollend", scrollend, { signal });
mainContainer.addEventListener("blur", scrollend, { signal });
}
clearTimeout(scrollendTimeoutID);
// Why 100 ? Because of:
// https://developer.chrome.com/blog/scrollend-a-new-javascript-event
// Maybe we could find a better value... ideally the `scrollend` event
// should be correctly fired.
scrollendTimeoutID = setTimeout(scrollend, 100);
};
mainContainer.addEventListener("scroll", scroll, {
passive: true,