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