Skip to content

Commit c6e5686

Browse files
committed
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.
1 parent 7edc5cb commit c6e5686

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

web/app.js

+20
Original file line numberDiff line numberDiff line change
@@ -1760,6 +1760,9 @@ const PDFViewerApplication = {
17601760

17611761
window.addEventListener("visibilitychange", webViewerVisibilityChange);
17621762
window.addEventListener("wheel", webViewerWheel, { passive: false });
1763+
window.addEventListener("touchstart", webViewerTouchStart, {
1764+
passive: false,
1765+
});
17631766
window.addEventListener("click", webViewerClick);
17641767
window.addEventListener("keydown", webViewerKeyDown);
17651768
window.addEventListener("keyup", webViewerKeyUp);
@@ -1822,6 +1825,9 @@ const PDFViewerApplication = {
18221825

18231826
window.removeEventListener("visibilitychange", webViewerVisibilityChange);
18241827
window.removeEventListener("wheel", webViewerWheel, { passive: false });
1828+
window.removeEventListener("touchstart", webViewerTouchStart, {
1829+
passive: false,
1830+
});
18251831
window.removeEventListener("click", webViewerClick);
18261832
window.removeEventListener("keydown", webViewerKeyDown);
18271833
window.removeEventListener("keyup", webViewerKeyUp);
@@ -2519,6 +2525,20 @@ function webViewerWheel(evt) {
25192525
}
25202526
}
25212527

2528+
function webViewerTouchStart(evt) {
2529+
if (evt.touches.length > 1) {
2530+
// Disable touch-based zooming, because the entire UI bits gets zoomed and
2531+
// that doesn't look great. If we do want to have a good touch-based
2532+
// zooming experience, we need to implement smooth zoom capability (probably
2533+
// using a CSS transform for faster visual response, followed by async
2534+
// re-rendering at the final zoom level) and do gesture detection on the
2535+
// touchmove events to drive it. Or if we want to settle for a less good
2536+
// experience we can make the touchmove events drive the existing step-zoom
2537+
// behaviour that the ctrl+mousewheel path takes.
2538+
evt.preventDefault();
2539+
}
2540+
}
2541+
25222542
function webViewerClick(evt) {
25232543
// Avoid triggering the fallback bar when the user clicks on the
25242544
// toolbar or sidebar.

0 commit comments

Comments
 (0)