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

Merge pull request #19121 from Snuffleupagus/more-stopEvent

Use the `stopEvent` helper function everywhere possible
This commit is contained in:
Jonas Jenwald 2024-11-28 17:21:34 +01:00 committed by GitHub
commit 65f20b0392
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 32 additions and 31 deletions

View file

@ -28,9 +28,9 @@ import {
HighlightAnnotationElement,
InkAnnotationElement,
} from "../annotation_layer.js";
import { noContextMenu, stopEvent } from "../display_utils.js";
import { AnnotationEditor } from "./editor.js";
import { ColorPicker } from "./color_picker.js";
import { noContextMenu } from "../display_utils.js";
/**
* Basic draw editor in order to generate an Highlight annotation.
@ -778,22 +778,21 @@ class HighlightEditor extends AnnotationEditor {
const ac = new AbortController();
const signal = parent.combinedSignal(ac);
const pointerDown = e => {
// Avoid to have undesired clicks during the drawing.
e.preventDefault();
e.stopPropagation();
};
const pointerUpCallback = e => {
ac.abort();
this.#endHighlight(parent, e);
};
window.addEventListener("blur", pointerUpCallback, { signal });
window.addEventListener("pointerup", pointerUpCallback, { signal });
window.addEventListener("pointerdown", pointerDown, {
capture: true,
passive: false,
signal,
});
window.addEventListener(
"pointerdown",
stopEvent /* Avoid to have undesired clicks during the drawing. */,
{
capture: true,
passive: false,
signal,
}
);
window.addEventListener("contextmenu", noContextMenu, { signal });
textLayer.addEventListener(

View file

@ -13,7 +13,7 @@
* limitations under the License.
*/
import { noContextMenu } from "../display_utils.js";
import { noContextMenu, stopEvent } from "../display_utils.js";
class EditorToolbar {
#toolbar = null;
@ -81,14 +81,12 @@ class EditorToolbar {
#focusIn(e) {
this.#editor._focusEventsAllowed = false;
e.preventDefault();
e.stopPropagation();
stopEvent(e);
}
#focusOut(e) {
this.#editor._focusEventsAllowed = true;
e.preventDefault();
e.stopPropagation();
stopEvent(e);
}
#addListenersToElement(element) {

View file

@ -32,6 +32,7 @@ import {
getColorValues,
getRGB,
PixelsPerInch,
stopEvent,
} from "../display_utils.js";
import { HighlightToolbar } from "./toolbar.js";
@ -516,8 +517,7 @@ class KeyboardManager {
// For example, ctrl+s in a FreeText must be handled by the viewer, hence
// the event must bubble.
if (!bubbles) {
event.stopPropagation();
event.preventDefault();
stopEvent(event);
}
}
}

View file

@ -61,6 +61,7 @@ import {
PixelsPerInch,
RenderingCancelledException,
setLayerDimensions,
stopEvent,
} from "./display/display_utils.js";
import { AnnotationEditorLayer } from "./display/editor/annotation_editor_layer.js";
import { AnnotationEditorUIManager } from "./display/editor/tools.js";
@ -124,6 +125,7 @@ export {
RenderingCancelledException,
setLayerDimensions,
shadow,
stopEvent,
TextLayer,
UnexpectedResponseException,
Util,