Bug 1392361 - Fix zooming sensitivity on macOS

The original code would get a long sequence of miniscule "tick" values while
pinch-zooming, and each tick value would cause a 1.1x zoom. So even the smallest
pinch gesture on a trackpad would cause high amounts of zoom. This patch
accumulates the wheel deltas until they reach an integer threshold (with a
tweak of the scaling factor to make it feel more natural) at which point it
triggers the zoom based on the integer component of the accumulated delta. The
fractional part is retained in the accumulator.
This commit is contained in:
Kartikaya Gupta 2020-08-12 14:30:45 -04:00
parent 7edc5cb79f
commit 213676b5e8
2 changed files with 50 additions and 6 deletions

View file

@ -636,13 +636,18 @@ function getPDFFileNameFromURL(url, defaultFilename = "document.pdf") {
return suggestedFilename || defaultFilename;
}
function normalizeWheelEventDelta(evt) {
function normalizeWheelEventDirection(evt) {
let delta = Math.sqrt(evt.deltaX * evt.deltaX + evt.deltaY * evt.deltaY);
const angle = Math.atan2(evt.deltaY, evt.deltaX);
if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
// All that is left-up oriented has to change the sign.
delta = -delta;
}
return delta;
}
function normalizeWheelEventDelta(evt) {
let delta = normalizeWheelEventDirection(evt);
const MOUSE_DOM_DELTA_PIXEL_MODE = 0;
const MOUSE_DOM_DELTA_LINE_MODE = 1;
@ -1017,6 +1022,7 @@ export {
scrollIntoView,
watchScroll,
binarySearchFirstItem,
normalizeWheelEventDirection,
normalizeWheelEventDelta,
animationStarted,
WaitOnType,