Skip to content

Commit

Permalink
Prevent emulated mouse events on PDF view touch
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtcode committed Sep 8, 2023
1 parent cbea76b commit 5f4c4b9
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/pdf/pdf-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ class PDFView {
this._iframeWindow.addEventListener('mousedown', this._handlePointerDown.bind(this), true);
// Touch events are passive by default
this._iframeWindow.addEventListener('touchmove', this._handleTouchMove.bind(this), { passive: false });
this._iframeWindow.addEventListener('touchend', this._handleTouchEnd.bind(this), { passive: false });
this._iframeWindow.addEventListener('pointermove', this._handlePointerMove.bind(this), { passive: true });
this._iframeWindow.addEventListener('pointerup', this._handlePointerUp.bind(this));
this._iframeWindow.addEventListener('dragstart', this._handleDragStart.bind(this), { capture: true });
Expand Down Expand Up @@ -1604,6 +1605,14 @@ class PDFView {
}
}

_handleTouchEnd(event) {
// Prevent emulated mouse event firing (i.e. mousedown, which messes up things).
// Although on chrome we get an error when trying to scroll:
// "[Intervention] Ignored attempt to cancel a touchend event with cancelable=false,
// for example because scrolling is in progress and cannot be interrupted"
event.preventDefault();
}

_handlePointerMove = throttle((event) => {
let dragging = !!event.dataTransfer;
// Set action cursor on hover
Expand Down

0 comments on commit 5f4c4b9

Please sign in to comment.