From ff2e0c8afd5e9b3b43267409b5bbce63bcddccea Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 18 Apr 2024 12:39:57 +0200 Subject: [PATCH] Skip the scroll/scrollend workaround in the Firefox PDF Viewer (PR 17724 follow-up) Given that [bug 1881974](https://bugzilla.mozilla.org/show_bug.cgi?id=1881974) has been fixed in Firefox 126, the workaround should no longer be necessary in the *built-in* Firefox PDF Viewer. --- web/app.js | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/web/app.js b/web/app.js index cda101c7c..f288c2adf 100644 --- a/web/app.js +++ b/web/app.js @@ -177,8 +177,6 @@ const PDFViewerApplication = { _nimbusDataPromise: null, _caretBrowsing: null, _isScrolling: false, - _lastScrollTop: 0, - _lastScrollLeft: 0, // Called once when the document is loaded. async initialize(appConfig) { @@ -2002,15 +2000,20 @@ const PDFViewerApplication = { ) { return; } - - // Using the values lastScrollTop and lastScrollLeft is a workaround to - // https://bugzilla.mozilla.org/show_bug.cgi?id=1881974. - // TODO: remove them once the bug is fixed. - ({ scrollTop: this._lastScrollTop, scrollLeft: this._lastScrollLeft } = - mainContainer); - const scrollend = () => { + if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) { + // Using the values lastScrollTop and lastScrollLeft is a workaround to + // https://bugzilla.mozilla.org/show_bug.cgi?id=1881974. + // TODO: remove them once the bug is fixed. ({ scrollTop: this._lastScrollTop, scrollLeft: this._lastScrollLeft } = mainContainer); + } + + 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, @@ -2020,13 +2023,17 @@ const PDFViewerApplication = { mainContainer.removeEventListener("blur", scrollend, { signal }); }; const scroll = () => { + if (this._isCtrlKeyDown) { + return; + } if ( - this._isCtrlKeyDown || - (this._lastScrollTop === mainContainer.scrollTop && - this._lastScrollLeft === mainContainer.scrollLeft) + (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) && + this._lastScrollTop === mainContainer.scrollTop && + this._lastScrollLeft === mainContainer.scrollLeft ) { return; } + mainContainer.removeEventListener("scroll", scroll, { passive: true, signal,