From 2f8a0638a6af82aec09c942b40bfd66997b133ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 25 Jan 2022 18:54:21 +0100 Subject: [PATCH] web: Read WheelEvent.deltaMode before deltas. So that Firefox doesn't switch to pixel mode for compat with other browsers. This should fix https://github.com/mozilla/pdf.js/issues/14476, in terms of restoring the previous behavior. We probably want to change the pixel-based scrolling code to not scroll so much (the deltaMode stuff normalizes to +/-1 tick for each wheel event, perhaps the pixel-based value should do the same). --- web/app.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/web/app.js b/web/app.js index 347ab5261..7883a802e 100644 --- a/web/app.js +++ b/web/app.js @@ -2691,13 +2691,17 @@ function webViewerWheel(evt) { return; } + // It is important that we query deltaMode before delta{X,Y}, so that + // Firefox doesn't switch to DOM_DELTA_PIXEL mode for compat with other + // browsers, see https://bugzilla.mozilla.org/show_bug.cgi?id=1392460. + const deltaMode = evt.deltaMode; + const delta = normalizeWheelEventDirection(evt); const previousScale = pdfViewer.currentScale; - const delta = normalizeWheelEventDirection(evt); let ticks = 0; if ( - evt.deltaMode === WheelEvent.DOM_DELTA_LINE || - evt.deltaMode === WheelEvent.DOM_DELTA_PAGE + deltaMode === WheelEvent.DOM_DELTA_LINE || + deltaMode === WheelEvent.DOM_DELTA_PAGE ) { // For line-based devices, use one tick per event, because different // OSs have different defaults for the number lines. But we generally