From c6e5686b6a908a16a8fbc2ca93b5c12b08dba146 Mon Sep 17 00:00:00 2001 From: Kartikaya Gupta Date: Wed, 12 Aug 2020 15:09:42 -0400 Subject: [PATCH] Bug 1643508 - Disable touch-based pinch zooming on pdf.js. Currently using a touchscreen with pdf.js doesn't work so well. In Firefox, with apz.allow_zooming = false (default on current release/beta), it does a reflow zoom which makes the UI elements bigger. And with apz.allow_zooming = true (default on current Firefox nightly), or in Chrome, it does a smooth pinch-zoom but that also scales up the entire UI. Neither of these is a particularly good experience, so this patch just disables any multi-touch gestures. Touch-based panning (which involves a single touch point) is left unaffected. --- web/app.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/web/app.js b/web/app.js index d568e049b..da6fd5ea2 100644 --- a/web/app.js +++ b/web/app.js @@ -1760,6 +1760,9 @@ const PDFViewerApplication = { window.addEventListener("visibilitychange", webViewerVisibilityChange); window.addEventListener("wheel", webViewerWheel, { passive: false }); + window.addEventListener("touchstart", webViewerTouchStart, { + passive: false, + }); window.addEventListener("click", webViewerClick); window.addEventListener("keydown", webViewerKeyDown); window.addEventListener("keyup", webViewerKeyUp); @@ -1822,6 +1825,9 @@ const PDFViewerApplication = { window.removeEventListener("visibilitychange", webViewerVisibilityChange); window.removeEventListener("wheel", webViewerWheel, { passive: false }); + window.removeEventListener("touchstart", webViewerTouchStart, { + passive: false, + }); window.removeEventListener("click", webViewerClick); window.removeEventListener("keydown", webViewerKeyDown); window.removeEventListener("keyup", webViewerKeyUp); @@ -2519,6 +2525,20 @@ function webViewerWheel(evt) { } } +function webViewerTouchStart(evt) { + if (evt.touches.length > 1) { + // Disable touch-based zooming, because the entire UI bits gets zoomed and + // that doesn't look great. If we do want to have a good touch-based + // zooming experience, we need to implement smooth zoom capability (probably + // using a CSS transform for faster visual response, followed by async + // re-rendering at the final zoom level) and do gesture detection on the + // touchmove events to drive it. Or if we want to settle for a less good + // experience we can make the touchmove events drive the existing step-zoom + // behaviour that the ctrl+mousewheel path takes. + evt.preventDefault(); + } +} + function webViewerClick(evt) { // Avoid triggering the fallback bar when the user clicks on the // toolbar or sidebar.