Merge pull request #15761 from Snuffleupagus/platform
Stop duplicating the `platform` getter in multiple files
This commit is contained in:
commit
1f082d3e1d
@ -22,6 +22,7 @@ import {
|
||||
AnnotationBorderStyleType,
|
||||
AnnotationType,
|
||||
assert,
|
||||
FeatureTest,
|
||||
LINE_FACTOR,
|
||||
shadow,
|
||||
unreachable,
|
||||
@ -563,15 +564,6 @@ class AnnotationElement {
|
||||
}
|
||||
return fields;
|
||||
}
|
||||
|
||||
static get platform() {
|
||||
const platform = typeof navigator !== "undefined" ? navigator.platform : "";
|
||||
|
||||
return shadow(this, "platform", {
|
||||
isWin: platform.includes("Win"),
|
||||
isMac: platform.includes("Mac"),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class LinkAnnotationElement extends AnnotationElement {
|
||||
@ -904,7 +896,7 @@ class WidgetAnnotationElement extends AnnotationElement {
|
||||
}
|
||||
|
||||
_getKeyModifier(event) {
|
||||
const { isWin, isMac } = AnnotationElement.platform;
|
||||
const { isWin, isMac } = FeatureTest.platform;
|
||||
return (isWin && event.ctrlKey) || (isMac && event.metaKey);
|
||||
}
|
||||
|
||||
|
@ -22,8 +22,8 @@
|
||||
/** @typedef {import("../../web/text_accessibility.js").TextAccessibilityManager} TextAccessibilityManager */
|
||||
/** @typedef {import("../../web/interfaces").IL10n} IL10n */
|
||||
|
||||
import { bindEvents, KeyboardManager } from "./tools.js";
|
||||
import { AnnotationEditorType } from "../../shared/util.js";
|
||||
import { AnnotationEditorType, FeatureTest } from "../../shared/util.js";
|
||||
import { bindEvents } from "./tools.js";
|
||||
import { FreeTextEditor } from "./freetext.js";
|
||||
import { InkEditor } from "./ink.js";
|
||||
|
||||
@ -429,7 +429,7 @@ class AnnotationEditorLayer {
|
||||
* @param {PointerEvent} event
|
||||
*/
|
||||
pointerup(event) {
|
||||
const isMac = KeyboardManager.platform.isMac;
|
||||
const { isMac } = FeatureTest.platform;
|
||||
if (event.button !== 0 || (event.ctrlKey && isMac)) {
|
||||
// Don't create an editor on right click.
|
||||
return;
|
||||
@ -461,7 +461,7 @@ class AnnotationEditorLayer {
|
||||
* @param {PointerEvent} event
|
||||
*/
|
||||
pointerdown(event) {
|
||||
const isMac = KeyboardManager.platform.isMac;
|
||||
const { isMac } = FeatureTest.platform;
|
||||
if (event.button !== 0 || (event.ctrlKey && isMac)) {
|
||||
// Do nothing on right click.
|
||||
return;
|
||||
|
@ -16,8 +16,8 @@
|
||||
// eslint-disable-next-line max-len
|
||||
/** @typedef {import("./annotation_editor_layer.js").AnnotationEditorLayer} AnnotationEditorLayer */
|
||||
|
||||
import { bindEvents, ColorManager, KeyboardManager } from "./tools.js";
|
||||
import { shadow, unreachable } from "../../shared/util.js";
|
||||
import { bindEvents, ColorManager } from "./tools.js";
|
||||
import { FeatureTest, shadow, unreachable } from "../../shared/util.js";
|
||||
|
||||
/**
|
||||
* @typedef {Object} AnnotationEditorParameters
|
||||
@ -274,7 +274,7 @@ class AnnotationEditor {
|
||||
* @param {PointerEvent} event
|
||||
*/
|
||||
pointerdown(event) {
|
||||
const isMac = KeyboardManager.platform.isMac;
|
||||
const { isMac } = FeatureTest.platform;
|
||||
if (event.button !== 0 || (event.ctrlKey && isMac)) {
|
||||
// Avoid to focus this editor because of a non-left click.
|
||||
event.preventDefault();
|
||||
|
@ -20,6 +20,7 @@
|
||||
import {
|
||||
AnnotationEditorPrefix,
|
||||
AnnotationEditorType,
|
||||
FeatureTest,
|
||||
shadow,
|
||||
Util,
|
||||
warn,
|
||||
@ -211,7 +212,7 @@ class KeyboardManager {
|
||||
this.callbacks = new Map();
|
||||
this.allKeys = new Set();
|
||||
|
||||
const isMac = KeyboardManager.platform.isMac;
|
||||
const { isMac } = FeatureTest.platform;
|
||||
for (const [keys, callback] of callbacks) {
|
||||
for (const key of keys) {
|
||||
const isMacKey = key.startsWith("mac+");
|
||||
@ -226,15 +227,6 @@ class KeyboardManager {
|
||||
}
|
||||
}
|
||||
|
||||
static get platform() {
|
||||
const platform = typeof navigator !== "undefined" ? navigator.platform : "";
|
||||
|
||||
return shadow(this, "platform", {
|
||||
isWin: platform.includes("Win"),
|
||||
isMac: platform.includes("Mac"),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize an event into a string in order to match a
|
||||
* potential key for a callback.
|
||||
|
@ -738,6 +738,19 @@ class FeatureTest {
|
||||
typeof OffscreenCanvas !== "undefined"
|
||||
);
|
||||
}
|
||||
|
||||
static get platform() {
|
||||
if (
|
||||
(typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) &&
|
||||
typeof navigator === "undefined"
|
||||
) {
|
||||
return shadow(this, "platform", { isWin: false, isMac: false });
|
||||
}
|
||||
return shadow(this, "platform", {
|
||||
isWin: navigator.platform.includes("Win"),
|
||||
isMac: navigator.platform.includes("Mac"),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const hexNumbers = [...Array(256).keys()].map(n =>
|
||||
|
Loading…
Reference in New Issue
Block a user