From dfccc8ffd989070645bceb58220d4340b63e979d Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Fri, 12 Jul 2024 10:49:36 +0200 Subject: [PATCH] [Editor] Add an option to use the new 'add an image' flow (bug 1907207) UX team designed in a new flow we'll implement soon and we want to be able to make an experiment to be able to compare current flow vs the new one. --- extensions/chromium/preferences_schema.json | 4 ++++ src/display/editor/tools.js | 8 ++++++++ web/app.js | 1 + web/app_options.js | 8 ++++++++ web/pdf_viewer.js | 4 ++++ 5 files changed, 25 insertions(+) diff --git a/extensions/chromium/preferences_schema.json b/extensions/chromium/preferences_schema.json index fc08e6933..3035f6500 100644 --- a/extensions/chromium/preferences_schema.json +++ b/extensions/chromium/preferences_schema.json @@ -55,6 +55,10 @@ "type": "boolean", "default": false }, + "enableUpdatedAddImage": { + "type": "boolean", + "default": false + }, "cursorToolOnLoad": { "title": "Cursor tool on load", "description": "The cursor tool that is enabled upon load.\n 0 = Text selection tool.\n 1 = Hand tool.", diff --git a/src/display/editor/tools.js b/src/display/editor/tools.js index 17d7e497a..53d494175 100644 --- a/src/display/editor/tools.js +++ b/src/display/editor/tools.js @@ -562,6 +562,8 @@ class AnnotationEditorUIManager { #enableHighlightFloatingButton = false; + #enableUpdatedAddImage = false; + #filterFactory = null; #focusMainContainerTimeoutId = null; @@ -779,6 +781,7 @@ class AnnotationEditorUIManager { pageColors, highlightColors, enableHighlightFloatingButton, + enableUpdatedAddImage, mlManager ) { this._signal = this.#abortController.signal; @@ -798,6 +801,7 @@ class AnnotationEditorUIManager { this.#pageColors = pageColors; this.#highlightColors = highlightColors || null; this.#enableHighlightFloatingButton = enableHighlightFloatingButton; + this.#enableUpdatedAddImage = enableUpdatedAddImage; this.#mlManager = mlManager || null; this.viewParameters = { realScale: PixelsPerInch.PDF_TO_CSS_UNITS, @@ -855,6 +859,10 @@ class AnnotationEditorUIManager { return !!this.#mlManager?.isEnabledFor(name); } + get useNewAltTextFlow() { + return this.#enableUpdatedAddImage; + } + get hcmFilter() { return shadow( this, diff --git a/web/app.js b/web/app.js index 136c9b0ca..3eab6e6ae 100644 --- a/web/app.js +++ b/web/app.js @@ -477,6 +477,7 @@ const PDFViewerApplication = { enableHighlightFloatingButton: AppOptions.get( "enableHighlightFloatingButton" ), + enableUpdatedAddImage: AppOptions.get("enableUpdatedAddImage"), imageResourcesPath: AppOptions.get("imageResourcesPath"), enablePrintAutoRotate: AppOptions.get("enablePrintAutoRotate"), maxCanvasPixels: AppOptions.get("maxCanvasPixels"), diff --git a/web/app_options.js b/web/app_options.js index c1a306237..70884696a 100644 --- a/web/app_options.js +++ b/web/app_options.js @@ -178,6 +178,14 @@ const defaultOptions = { value: typeof PDFJSDev === "undefined" || !PDFJSDev.test("CHROME"), kind: OptionKind.VIEWER + OptionKind.PREFERENCE, }, + enableUpdatedAddImage: { + // We'll probably want to make some experiments before enabling this + // in Firefox release, but it has to be temporary. + // TODO: remove it when unnecessary. + /** @type {boolean} */ + value: false, + kind: OptionKind.VIEWER + OptionKind.PREFERENCE, + }, externalLinkRel: { /** @type {string} */ value: "noopener noreferrer nofollow", diff --git a/web/pdf_viewer.js b/web/pdf_viewer.js index d56328014..6adf76345 100644 --- a/web/pdf_viewer.js +++ b/web/pdf_viewer.js @@ -219,6 +219,8 @@ class PDFViewer { #enablePermissions = false; + #enableUpdatedAddImage = false; + #eventAbortController = null; #mlManager = null; @@ -291,6 +293,7 @@ class PDFViewer { options.annotationEditorHighlightColors || null; this.#enableHighlightFloatingButton = options.enableHighlightFloatingButton === true; + this.#enableUpdatedAddImage = options.enableUpdatedAddImage === true; this.imageResourcesPath = options.imageResourcesPath || ""; this.enablePrintAutoRotate = options.enablePrintAutoRotate || false; if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { @@ -890,6 +893,7 @@ class PDFViewer { pageColors, this.#annotationEditorHighlightColors, this.#enableHighlightFloatingButton, + this.#enableUpdatedAddImage, this.#mlManager ); eventBus.dispatch("annotationeditoruimanager", {