Merge pull request #15761 from Snuffleupagus/platform

Stop duplicating the `platform` getter in multiple files
This commit is contained in:
Jonas Jenwald 2022-11-29 17:32:52 +01:00 committed by GitHub
commit 1f082d3e1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 27 deletions

View File

@ -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);
}

View File

@ -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;

View File

@ -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();

View File

@ -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.

View File

@ -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 =>