mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 06:38:07 +02:00
Use the stopEvent
helper function everywhere possible
This commit is contained in:
parent
22babd722f
commit
e1760aab8d
10 changed files with 32 additions and 31 deletions
|
@ -28,9 +28,9 @@ import {
|
||||||
HighlightAnnotationElement,
|
HighlightAnnotationElement,
|
||||||
InkAnnotationElement,
|
InkAnnotationElement,
|
||||||
} from "../annotation_layer.js";
|
} from "../annotation_layer.js";
|
||||||
|
import { noContextMenu, stopEvent } from "../display_utils.js";
|
||||||
import { AnnotationEditor } from "./editor.js";
|
import { AnnotationEditor } from "./editor.js";
|
||||||
import { ColorPicker } from "./color_picker.js";
|
import { ColorPicker } from "./color_picker.js";
|
||||||
import { noContextMenu } from "../display_utils.js";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Basic draw editor in order to generate an Highlight annotation.
|
* Basic draw editor in order to generate an Highlight annotation.
|
||||||
|
@ -778,22 +778,21 @@ class HighlightEditor extends AnnotationEditor {
|
||||||
const ac = new AbortController();
|
const ac = new AbortController();
|
||||||
const signal = parent.combinedSignal(ac);
|
const signal = parent.combinedSignal(ac);
|
||||||
|
|
||||||
const pointerDown = e => {
|
|
||||||
// Avoid to have undesired clicks during the drawing.
|
|
||||||
e.preventDefault();
|
|
||||||
e.stopPropagation();
|
|
||||||
};
|
|
||||||
const pointerUpCallback = e => {
|
const pointerUpCallback = e => {
|
||||||
ac.abort();
|
ac.abort();
|
||||||
this.#endHighlight(parent, e);
|
this.#endHighlight(parent, e);
|
||||||
};
|
};
|
||||||
window.addEventListener("blur", pointerUpCallback, { signal });
|
window.addEventListener("blur", pointerUpCallback, { signal });
|
||||||
window.addEventListener("pointerup", pointerUpCallback, { signal });
|
window.addEventListener("pointerup", pointerUpCallback, { signal });
|
||||||
window.addEventListener("pointerdown", pointerDown, {
|
window.addEventListener(
|
||||||
capture: true,
|
"pointerdown",
|
||||||
passive: false,
|
stopEvent /* Avoid to have undesired clicks during the drawing. */,
|
||||||
signal,
|
{
|
||||||
});
|
capture: true,
|
||||||
|
passive: false,
|
||||||
|
signal,
|
||||||
|
}
|
||||||
|
);
|
||||||
window.addEventListener("contextmenu", noContextMenu, { signal });
|
window.addEventListener("contextmenu", noContextMenu, { signal });
|
||||||
|
|
||||||
textLayer.addEventListener(
|
textLayer.addEventListener(
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { noContextMenu } from "../display_utils.js";
|
import { noContextMenu, stopEvent } from "../display_utils.js";
|
||||||
|
|
||||||
class EditorToolbar {
|
class EditorToolbar {
|
||||||
#toolbar = null;
|
#toolbar = null;
|
||||||
|
@ -81,14 +81,12 @@ class EditorToolbar {
|
||||||
|
|
||||||
#focusIn(e) {
|
#focusIn(e) {
|
||||||
this.#editor._focusEventsAllowed = false;
|
this.#editor._focusEventsAllowed = false;
|
||||||
e.preventDefault();
|
stopEvent(e);
|
||||||
e.stopPropagation();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#focusOut(e) {
|
#focusOut(e) {
|
||||||
this.#editor._focusEventsAllowed = true;
|
this.#editor._focusEventsAllowed = true;
|
||||||
e.preventDefault();
|
stopEvent(e);
|
||||||
e.stopPropagation();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#addListenersToElement(element) {
|
#addListenersToElement(element) {
|
||||||
|
|
|
@ -32,6 +32,7 @@ import {
|
||||||
getColorValues,
|
getColorValues,
|
||||||
getRGB,
|
getRGB,
|
||||||
PixelsPerInch,
|
PixelsPerInch,
|
||||||
|
stopEvent,
|
||||||
} from "../display_utils.js";
|
} from "../display_utils.js";
|
||||||
import { HighlightToolbar } from "./toolbar.js";
|
import { HighlightToolbar } from "./toolbar.js";
|
||||||
|
|
||||||
|
@ -501,8 +502,7 @@ class KeyboardManager {
|
||||||
// For example, ctrl+s in a FreeText must be handled by the viewer, hence
|
// For example, ctrl+s in a FreeText must be handled by the viewer, hence
|
||||||
// the event must bubble.
|
// the event must bubble.
|
||||||
if (!bubbles) {
|
if (!bubbles) {
|
||||||
event.stopPropagation();
|
stopEvent(event);
|
||||||
event.preventDefault();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,6 +61,7 @@ import {
|
||||||
PixelsPerInch,
|
PixelsPerInch,
|
||||||
RenderingCancelledException,
|
RenderingCancelledException,
|
||||||
setLayerDimensions,
|
setLayerDimensions,
|
||||||
|
stopEvent,
|
||||||
} from "./display/display_utils.js";
|
} from "./display/display_utils.js";
|
||||||
import { AnnotationEditorLayer } from "./display/editor/annotation_editor_layer.js";
|
import { AnnotationEditorLayer } from "./display/editor/annotation_editor_layer.js";
|
||||||
import { AnnotationEditorUIManager } from "./display/editor/tools.js";
|
import { AnnotationEditorUIManager } from "./display/editor/tools.js";
|
||||||
|
@ -124,6 +125,7 @@ export {
|
||||||
RenderingCancelledException,
|
RenderingCancelledException,
|
||||||
setLayerDimensions,
|
setLayerDimensions,
|
||||||
shadow,
|
shadow,
|
||||||
|
stopEvent,
|
||||||
TextLayer,
|
TextLayer,
|
||||||
UnexpectedResponseException,
|
UnexpectedResponseException,
|
||||||
Util,
|
Util,
|
||||||
|
|
|
@ -53,6 +53,7 @@ import {
|
||||||
PixelsPerInch,
|
PixelsPerInch,
|
||||||
RenderingCancelledException,
|
RenderingCancelledException,
|
||||||
setLayerDimensions,
|
setLayerDimensions,
|
||||||
|
stopEvent,
|
||||||
} from "../../src/display/display_utils.js";
|
} from "../../src/display/display_utils.js";
|
||||||
import { AnnotationEditorLayer } from "../../src/display/editor/annotation_editor_layer.js";
|
import { AnnotationEditorLayer } from "../../src/display/editor/annotation_editor_layer.js";
|
||||||
import { AnnotationEditorUIManager } from "../../src/display/editor/tools.js";
|
import { AnnotationEditorUIManager } from "../../src/display/editor/tools.js";
|
||||||
|
@ -102,6 +103,7 @@ const expectedAPI = Object.freeze({
|
||||||
RenderingCancelledException,
|
RenderingCancelledException,
|
||||||
setLayerDimensions,
|
setLayerDimensions,
|
||||||
shadow,
|
shadow,
|
||||||
|
stopEvent,
|
||||||
TextLayer,
|
TextLayer,
|
||||||
UnexpectedResponseException,
|
UnexpectedResponseException,
|
||||||
Util,
|
Util,
|
||||||
|
|
|
@ -53,6 +53,7 @@ import {
|
||||||
MissingPDFException,
|
MissingPDFException,
|
||||||
PDFWorker,
|
PDFWorker,
|
||||||
shadow,
|
shadow,
|
||||||
|
stopEvent,
|
||||||
UnexpectedResponseException,
|
UnexpectedResponseException,
|
||||||
version,
|
version,
|
||||||
} from "pdfjs-lib";
|
} from "pdfjs-lib";
|
||||||
|
@ -715,8 +716,7 @@ const PDFViewerApplication = {
|
||||||
if (item.type === "application/pdf") {
|
if (item.type === "application/pdf") {
|
||||||
evt.dataTransfer.dropEffect =
|
evt.dataTransfer.dropEffect =
|
||||||
evt.dataTransfer.effectAllowed === "copy" ? "copy" : "move";
|
evt.dataTransfer.effectAllowed === "copy" ? "copy" : "move";
|
||||||
evt.preventDefault();
|
stopEvent(evt);
|
||||||
evt.stopPropagation();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -725,8 +725,7 @@ const PDFViewerApplication = {
|
||||||
if (evt.dataTransfer.files?.[0].type !== "application/pdf") {
|
if (evt.dataTransfer.files?.[0].type !== "application/pdf") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
evt.preventDefault();
|
stopEvent(evt);
|
||||||
evt.stopPropagation();
|
|
||||||
eventBus.dispatch("fileinputchange", {
|
eventBus.dispatch("fileinputchange", {
|
||||||
source: this,
|
source: this,
|
||||||
fileInput: evt.dataTransfer,
|
fileInput: evt.dataTransfer,
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { stopEvent } from "pdfjs-lib";
|
||||||
|
|
||||||
// Class name of element which can be grabbed.
|
// Class name of element which can be grabbed.
|
||||||
const CSS_CLASS_GRAB = "grab-to-pan-grab";
|
const CSS_CLASS_GRAB = "grab-to-pan-grab";
|
||||||
|
|
||||||
|
@ -131,8 +133,7 @@ class GrabToPan {
|
||||||
capture: true,
|
capture: true,
|
||||||
signal: this.#scrollAC.signal,
|
signal: this.#scrollAC.signal,
|
||||||
});
|
});
|
||||||
event.preventDefault();
|
stopEvent(event);
|
||||||
event.stopPropagation();
|
|
||||||
|
|
||||||
const focusedElement = document.activeElement;
|
const focusedElement = document.activeElement;
|
||||||
if (focusedElement && !focusedElement.contains(event.target)) {
|
if (focusedElement && !focusedElement.contains(event.target)) {
|
||||||
|
|
|
@ -35,6 +35,7 @@ import {
|
||||||
PermissionFlag,
|
PermissionFlag,
|
||||||
PixelsPerInch,
|
PixelsPerInch,
|
||||||
shadow,
|
shadow,
|
||||||
|
stopEvent,
|
||||||
version,
|
version,
|
||||||
} from "pdfjs-lib";
|
} from "pdfjs-lib";
|
||||||
import {
|
import {
|
||||||
|
@ -748,8 +749,7 @@ class PDFViewer {
|
||||||
this.#getAllTextInProgress ||
|
this.#getAllTextInProgress ||
|
||||||
textLayerMode === TextLayerMode.ENABLE_PERMISSIONS
|
textLayerMode === TextLayerMode.ENABLE_PERMISSIONS
|
||||||
) {
|
) {
|
||||||
event.preventDefault();
|
stopEvent(event);
|
||||||
event.stopPropagation();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.#getAllTextInProgress = true;
|
this.#getAllTextInProgress = true;
|
||||||
|
@ -786,8 +786,7 @@ class PDFViewer {
|
||||||
classList.remove("copyAll");
|
classList.remove("copyAll");
|
||||||
});
|
});
|
||||||
|
|
||||||
event.preventDefault();
|
stopEvent(event);
|
||||||
event.stopPropagation();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,7 @@ const {
|
||||||
RenderingCancelledException,
|
RenderingCancelledException,
|
||||||
setLayerDimensions,
|
setLayerDimensions,
|
||||||
shadow,
|
shadow,
|
||||||
|
stopEvent,
|
||||||
TextLayer,
|
TextLayer,
|
||||||
UnexpectedResponseException,
|
UnexpectedResponseException,
|
||||||
Util,
|
Util,
|
||||||
|
@ -97,6 +98,7 @@ export {
|
||||||
RenderingCancelledException,
|
RenderingCancelledException,
|
||||||
setLayerDimensions,
|
setLayerDimensions,
|
||||||
shadow,
|
shadow,
|
||||||
|
stopEvent,
|
||||||
TextLayer,
|
TextLayer,
|
||||||
UnexpectedResponseException,
|
UnexpectedResponseException,
|
||||||
Util,
|
Util,
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
// eslint-disable-next-line max-len
|
// eslint-disable-next-line max-len
|
||||||
/** @typedef {import("./text_accessibility.js").TextAccessibilityManager} TextAccessibilityManager */
|
/** @typedef {import("./text_accessibility.js").TextAccessibilityManager} TextAccessibilityManager */
|
||||||
|
|
||||||
import { normalizeUnicode, TextLayer } from "pdfjs-lib";
|
import { normalizeUnicode, stopEvent, TextLayer } from "pdfjs-lib";
|
||||||
import { removeNullCharacters } from "./ui_utils.js";
|
import { removeNullCharacters } from "./ui_utils.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -162,8 +162,7 @@ class TextLayerBuilder {
|
||||||
removeNullCharacters(normalizeUnicode(selection.toString()))
|
removeNullCharacters(normalizeUnicode(selection.toString()))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
event.preventDefault();
|
stopEvent(event);
|
||||||
event.stopPropagation();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
TextLayerBuilder.#textLayers.set(div, end);
|
TextLayerBuilder.#textLayers.set(div, end);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue