1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-23 08:38:06 +02:00

[Editor] Avoid to use event.movementX/Y when resizing an editor

Those propertie can have some non-expected values so use screenX/Y instead.
This commit is contained in:
Calixte Denizet 2024-11-21 23:25:15 +01:00
parent 5b600e8f84
commit c08b5b2a94

View file

@ -52,6 +52,8 @@ class AnnotationEditor {
#resizersDiv = null;
#lastPointerCoords = null;
#savedDimensions = null;
#focusAC = null;
@ -736,6 +738,7 @@ class AnnotationEditor {
const savedDraggable = this._isDraggable;
this._isDraggable = false;
this.#lastPointerCoords = [event.screenX, event.screenY];
const ac = new AbortController();
const signal = this._uiManager.combinedSignal(ac);
@ -746,6 +749,14 @@ class AnnotationEditor {
this.#resizerPointermove.bind(this, name),
{ passive: true, capture: true, signal }
);
window.addEventListener(
"touchmove",
e => {
// Prevent the page from scrolling.
e.preventDefault();
},
{ passive: false, signal }
);
window.addEventListener("contextmenu", noContextMenu, { signal });
const savedX = this.x;
const savedY = this.y;
@ -886,10 +897,23 @@ class AnnotationEditor {
let ratioX = 1;
let ratioY = 1;
let [deltaX, deltaY] = this.screenToPageTranslation(
event.movementX,
event.movementY
);
let deltaX, deltaY;
if (!event.fromKeyboard) {
// We can't use event.movementX/Y because they're not reliable:
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/movementX
// (it was buggy on a laptop with a touch screen).
const { screenX, screenY } = event;
const [lastScreenX, lastScreenY] = this.#lastPointerCoords;
[deltaX, deltaY] = this.screenToPageTranslation(
screenX - lastScreenX,
screenY - lastScreenY
);
this.#lastPointerCoords[0] = screenX;
this.#lastPointerCoords[1] = screenY;
} else {
({ deltaX, deltaY } = event);
}
[deltaX, deltaY] = invTransf(deltaX / parentWidth, deltaY / parentHeight);
if (isDiagonal) {
@ -1559,8 +1583,9 @@ class AnnotationEditor {
return;
}
this.#resizerPointermove(this.#focusedResizerName, {
movementX: x,
movementY: y,
deltaX: x,
deltaY: y,
fromKeyboard: true,
});
}