1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

[Editor] Add a new dialog for alt-text settings (bug 1909604)

This patch adds a new entry in the secondary menu in order to open a dialog to let the user:
 - disables the alt-text generation thanks to a ML model;
 - deletes the alt-text model downloaded in Firefox;
 - disabled the new alt-text flow.
This commit is contained in:
Calixte Denizet 2024-08-01 15:29:01 +02:00
parent d562e0525d
commit 32d09276f0
17 changed files with 627 additions and 54 deletions

View file

@ -126,7 +126,11 @@ class StampEditor extends AnnotationEditor {
if (!this.#canvas) {
return;
}
if (this._uiManager.useNewAltTextFlow && this.#bitmap) {
if (
this._uiManager.useNewAltTextWhenAddingImage &&
this._uiManager.useNewAltTextFlow &&
this.#bitmap
) {
this._editToolbar.hide();
this._uiManager.editAltText(this, /* firstTime = */ true);
} else {
@ -341,7 +345,10 @@ class StampEditor extends AnnotationEditor {
this._uiManager.enableWaiting(false);
const canvas = (this.#canvas = document.createElement("canvas"));
div.append(canvas);
if (!this._uiManager.useNewAltTextFlow) {
if (
!this._uiManager.useNewAltTextWhenAddingImage ||
!this._uiManager.useNewAltTextFlow
) {
div.hidden = false;
}
this.#drawBitmap(width, height);

View file

@ -564,6 +564,8 @@ class AnnotationEditorUIManager {
#enableUpdatedAddImage = false;
#enableNewAltTextWhenAddingImage = false;
#filterFactory = null;
#focusMainContainerTimeoutId = null;
@ -616,6 +618,8 @@ class AnnotationEditorUIManager {
#boundOnScaleChanging = this.onScaleChanging.bind(this);
#boundOnSetPreference = this.onSetPreference.bind(this);
#boundOnRotationChanging = this.onRotationChanging.bind(this);
#previousStates = {
@ -782,17 +786,21 @@ class AnnotationEditorUIManager {
highlightColors,
enableHighlightFloatingButton,
enableUpdatedAddImage,
enableNewAltTextWhenAddingImage,
mlManager
) {
this._signal = this.#abortController.signal;
const signal = (this._signal = this.#abortController.signal);
this.#container = container;
this.#viewer = viewer;
this.#altTextManager = altTextManager;
this._eventBus = eventBus;
this._eventBus._on("editingaction", this.#boundOnEditingAction);
this._eventBus._on("pagechanging", this.#boundOnPageChanging);
this._eventBus._on("scalechanging", this.#boundOnScaleChanging);
this._eventBus._on("rotationchanging", this.#boundOnRotationChanging);
this._eventBus._on("editingaction", this.#boundOnEditingAction, { signal });
this._eventBus._on("pagechanging", this.#boundOnPageChanging, { signal });
this._eventBus._on("scalechanging", this.#boundOnScaleChanging, { signal });
this._eventBus._on("rotationchanging", this.#boundOnRotationChanging, {
signal,
});
this._eventBus._on("setpreference", this.#boundOnSetPreference, { signal });
this.#addSelectionListener();
this.#addDragAndDropListeners();
this.#addKeyboardManager();
@ -802,6 +810,7 @@ class AnnotationEditorUIManager {
this.#highlightColors = highlightColors || null;
this.#enableHighlightFloatingButton = enableHighlightFloatingButton;
this.#enableUpdatedAddImage = enableUpdatedAddImage;
this.#enableNewAltTextWhenAddingImage = enableNewAltTextWhenAddingImage;
this.#mlManager = mlManager || null;
this.viewParameters = {
realScale: PixelsPerInch.PDF_TO_CSS_UNITS,
@ -825,10 +834,6 @@ class AnnotationEditorUIManager {
this.#abortController = null;
this._signal = null;
this._eventBus._off("editingaction", this.#boundOnEditingAction);
this._eventBus._off("pagechanging", this.#boundOnPageChanging);
this._eventBus._off("scalechanging", this.#boundOnScaleChanging);
this._eventBus._off("rotationchanging", this.#boundOnRotationChanging);
for (const layer of this.#allLayers.values()) {
layer.destroy();
}
@ -871,6 +876,10 @@ class AnnotationEditorUIManager {
return this.#enableUpdatedAddImage;
}
get useNewAltTextWhenAddingImage() {
return this.#enableNewAltTextWhenAddingImage;
}
get hcmFilter() {
return shadow(
this,
@ -944,6 +953,14 @@ class AnnotationEditorUIManager {
});
}
onSetPreference({ name, value }) {
switch (name) {
case "enableNewAltTextWhenAddingImage":
this.#enableNewAltTextWhenAddingImage = value;
break;
}
}
onPageChanging({ pageNumber }) {
this.#currentPageIndex = pageNumber - 1;
}