Trigger a fake scrollend event in case it hasn't been triggered by the browser (bug 1957680)

This way, it should unblock zooming with ctrl+wheel after scrolling.
This commit is contained in:
Calixte Denizet 2025-08-01 19:06:14 +02:00
parent e5922f2e72
commit 287776483f

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);
}
this._isScrolling = false;
mainContainer.addEventListener("scroll", scroll, {
passive: true,
signal,
});
mainContainer.removeEventListener("scrollend", scrollend);
mainContainer.removeEventListener("blur", scrollend);
clearTimeout(scrollendTimeoutID);
if (this._isScrolling) {
scrollAbortController.abort();
scrollAbortController = null;
this._isScrolling = false;
}
};
const scroll = () => {
if (this._isCtrlKeyDown) {
@ -2253,10 +2252,27 @@ const PDFViewerApplication = {
return;
}
mainContainer.removeEventListener("scroll", scroll);
this._isScrolling = true;
mainContainer.addEventListener("scrollend", scrollend, { signal });
mainContainer.addEventListener("blur", scrollend, { signal });
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;
}
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,