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

Use one noContextMenu function in both the src/- and web/-folders

Currently we duplicate this event handler function in multiple places, which seems unnecessary.
This commit is contained in:
Jonas Jenwald 2023-09-23 15:37:13 +02:00
parent a09b7228fb
commit 1df31c0284
7 changed files with 20 additions and 32 deletions

View file

@ -789,6 +789,13 @@ function isValidFetchUrl(url, baseUrl) {
}
}
/**
* Event handler to suppress context menu.
*/
function noContextMenu(e) {
e.preventDefault();
}
/**
* @param {string} src
* @param {boolean} [removeScriptElement]
@ -1020,6 +1027,7 @@ export {
isPdfFile,
isValidFetchUrl,
loadScript,
noContextMenu,
PageViewport,
PDFDateString,
PixelsPerInch,

View file

@ -20,6 +20,7 @@
import { bindEvents, ColorManager } from "./tools.js";
import { FeatureTest, shadow, unreachable } from "../../shared/util.js";
import { noContextMenu } from "../display_utils.js";
/**
* @typedef {Object} AnnotationEditorParameters
@ -589,10 +590,6 @@ class AnnotationEditor {
return [0, 0];
}
static #noContextMenu(e) {
e.preventDefault();
}
#createResizers() {
if (this.#resizersDiv) {
return;
@ -611,7 +608,7 @@ class AnnotationEditor {
"pointerdown",
this.#resizerPointerdown.bind(this, name)
);
div.addEventListener("contextmenu", AnnotationEditor.#noContextMenu);
div.addEventListener("contextmenu", noContextMenu);
}
this.div.prepend(this.#resizersDiv);
}
@ -834,7 +831,7 @@ class AnnotationEditor {
altText.textContent = msg;
altText.setAttribute("aria-label", msg);
altText.tabIndex = "0";
altText.addEventListener("contextmenu", AnnotationEditor.#noContextMenu);
altText.addEventListener("contextmenu", noContextMenu);
altText.addEventListener("pointerdown", event => event.stopPropagation());
altText.addEventListener(
"click",

View file

@ -20,6 +20,7 @@ import {
} from "../../shared/util.js";
import { AnnotationEditor } from "./editor.js";
import { InkAnnotationElement } from "../annotation_layer.js";
import { noContextMenu } from "../display_utils.js";
import { opacityToHex } from "./tools.js";
/**
@ -30,8 +31,6 @@ class InkEditor extends AnnotationEditor {
#baseWidth = 0;
#boundCanvasContextMenu = this.canvasContextMenu.bind(this);
#boundCanvasPointermove = this.canvasPointermove.bind(this);
#boundCanvasPointerleave = this.canvasPointerleave.bind(this);
@ -360,7 +359,7 @@ class InkEditor extends AnnotationEditor {
* @param {number} y
*/
#startDrawing(x, y) {
this.canvas.addEventListener("contextmenu", this.#boundCanvasContextMenu);
this.canvas.addEventListener("contextmenu", noContextMenu);
this.canvas.addEventListener("pointerleave", this.#boundCanvasPointerleave);
this.canvas.addEventListener("pointermove", this.#boundCanvasPointermove);
this.canvas.addEventListener("pointerup", this.#boundCanvasPointerup);
@ -661,14 +660,6 @@ class InkEditor extends AnnotationEditor {
this.#startDrawing(event.offsetX, event.offsetY);
}
/**
* oncontextmenu callback for the canvas we're drawing on.
* @param {PointerEvent} event
*/
canvasContextMenu(event) {
event.preventDefault();
}
/**
* onpointermove callback for the canvas we're drawing on.
* @param {PointerEvent} event
@ -714,10 +705,7 @@ class InkEditor extends AnnotationEditor {
// Slight delay to avoid the context menu to appear (it can happen on a long
// tap with a pen).
setTimeout(() => {
this.canvas.removeEventListener(
"contextmenu",
this.#boundCanvasContextMenu
);
this.canvas.removeEventListener("contextmenu", noContextMenu);
}, 10);
this.#stopDrawing(event.offsetX, event.offsetY);

View file

@ -61,6 +61,7 @@ import {
isDataScheme,
isPdfFile,
loadScript,
noContextMenu,
PDFDateString,
PixelsPerInch,
RenderingCancelledException,
@ -104,6 +105,7 @@ export {
isPdfFile,
loadScript,
MissingPDFException,
noContextMenu,
normalizeUnicode,
OPS,
PasswordResponses,