Merge pull request #18398 from calixteman/bug1905923

[Editor] Change the enableML pref for enableAltText (bug 1905923)
This commit is contained in:
calixteman 2024-07-05 22:51:15 +02:00 committed by GitHub
commit db9115625b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 29 additions and 10 deletions

View file

@ -51,7 +51,7 @@
"type": "boolean", "type": "boolean",
"default": true "default": true
}, },
"enableML": { "enableAltText": {
"type": "boolean", "type": "boolean",
"default": false "default": false
}, },

View file

@ -430,7 +430,7 @@ class StampEditor extends AnnotationEditor {
return; return;
} }
this.#hasMLBeenQueried = true; this.#hasMLBeenQueried = true;
if (!this._uiManager.hasMLManager || this.hasAltText()) { if (!this._uiManager.isMLEnabledFor("altText") || this.hasAltText()) {
return; return;
} }
const offscreen = new OffscreenCanvas(width, height); const offscreen = new OffscreenCanvas(width, height);

View file

@ -851,8 +851,8 @@ class AnnotationEditorUIManager {
return this.#mlManager?.guess(data) || null; return this.#mlManager?.guess(data) || null;
} }
get hasMLManager() { isMLEnabledFor(name) {
return !!this.#mlManager; return !!this.#mlManager?.isEnabledFor(name);
} }
get hcmFilter() { get hcmFilter() {

View file

@ -756,10 +756,11 @@ const PDFViewerApplication = {
}, },
get mlManager() { get mlManager() {
const enableAltText = AppOptions.get("enableAltText");
return shadow( return shadow(
this, this,
"mlManager", "mlManager",
AppOptions.get("enableML") === true ? new MLManager() : null enableAltText === true ? new MLManager({ enableAltText }) : null
); );
}, },

View file

@ -141,6 +141,11 @@ const defaultOptions = {
value: false, value: false,
kind: OptionKind.VIEWER + OptionKind.PREFERENCE, kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
}, },
enableAltText: {
/** @type {boolean} */
value: false,
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
},
enableHighlightEditor: { enableHighlightEditor: {
// We'll probably want to make some experiments before enabling this // We'll probably want to make some experiments before enabling this
// in Firefox release, but it has to be temporary. // in Firefox release, but it has to be temporary.
@ -157,11 +162,6 @@ const defaultOptions = {
value: typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING"), value: typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING"),
kind: OptionKind.VIEWER + OptionKind.PREFERENCE, kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
}, },
enableML: {
/** @type {boolean} */
value: false,
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
},
enablePermissions: { enablePermissions: {
/** @type {boolean} */ /** @type {boolean} */
value: false, value: false,

View file

@ -436,6 +436,10 @@ class ExternalServices extends BaseExternalServices {
} }
class MLManager { class MLManager {
isEnabledFor(_name) {
return false;
}
async guess() { async guess() {
return null; return null;
} }

View file

@ -303,6 +303,16 @@ class FirefoxScripting {
} }
class MLManager { class MLManager {
#enabled = new Map();
constructor({ enableAltText }) {
this.#enabled.set("altText", enableAltText);
}
isEnabledFor(name) {
return this.#enabled.get(name);
}
guess(data) { guess(data) {
return FirefoxCom.requestAsync("mlGuess", data); return FirefoxCom.requestAsync("mlGuess", data);
} }

View file

@ -48,6 +48,10 @@ class ExternalServices extends BaseExternalServices {
} }
class MLManager { class MLManager {
isEnabledFor(_name) {
return false;
}
async guess() { async guess() {
return null; return null;
} }