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

[JS] Run the named actions before running the format when the file is open (issue #15818)

It's a follow-up of #14950: some format actions are ran when the document is open
but we must be sure we've everything ready for that, hence we have to run some
named actions before runnig the global format.
In playing with the form, I discovered that the blur event wasn't triggered when
JS called `setFocus` (because in such a case the mouse was never down). So I removed
the mouseState thing to just use the correct commitKey when blur is triggered by a
TAB key.
This commit is contained in:
Calixte Denizet 2022-12-13 16:08:36 +01:00
parent 2d596045d1
commit 2ebf8745a2
11 changed files with 182 additions and 159 deletions

View file

@ -41,7 +41,6 @@ import { PresentationModeState } from "./ui_utils.js";
* @property {Promise<boolean>} [hasJSActionsPromise]
* @property {Promise<Object<string, Array<Object>> | null>}
* [fieldObjectsPromise]
* @property {Object} [mouseState]
* @property {Map<string, HTMLCanvasElement>} [annotationCanvasMap]
* @property {TextAccessibilityManager} accessibilityManager
*/
@ -66,7 +65,6 @@ class AnnotationLayerBuilder {
enableScripting = false,
hasJSActionsPromise = null,
fieldObjectsPromise = null,
mouseState = null,
annotationCanvasMap = null,
accessibilityManager = null,
}) {
@ -81,7 +79,6 @@ class AnnotationLayerBuilder {
this.enableScripting = enableScripting;
this._hasJSActionsPromise = hasJSActionsPromise || Promise.resolve(false);
this._fieldObjectsPromise = fieldObjectsPromise || Promise.resolve(null);
this._mouseState = mouseState;
this._annotationCanvasMap = annotationCanvasMap;
this._accessibilityManager = accessibilityManager;
@ -144,7 +141,6 @@ class AnnotationLayerBuilder {
enableScripting: this.enableScripting,
hasJSActions,
fieldObjects,
mouseState: this._mouseState,
annotationCanvasMap: this._annotationCanvasMap,
accessibilityManager: this._accessibilityManager,
});

View file

@ -57,7 +57,6 @@ class DefaultAnnotationLayerFactory {
* @property {IL10n} l10n
* @property {boolean} [enableScripting]
* @property {Promise<boolean>} [hasJSActionsPromise]
* @property {Object} [mouseState]
* @property {Promise<Object<string, Array<Object>> | null>}
* [fieldObjectsPromise]
* @property {Map<string, HTMLCanvasElement>} [annotationCanvasMap] - Map some
@ -78,7 +77,6 @@ class DefaultAnnotationLayerFactory {
l10n = NullL10n,
enableScripting = false,
hasJSActionsPromise = null,
mouseState = null,
fieldObjectsPromise = null,
annotationCanvasMap = null,
accessibilityManager = null,
@ -94,7 +92,6 @@ class DefaultAnnotationLayerFactory {
enableScripting,
hasJSActionsPromise,
fieldObjectsPromise,
mouseState,
annotationCanvasMap,
accessibilityManager,
});

View file

@ -199,7 +199,6 @@ class IPDFAnnotationLayerFactory {
* @property {IL10n} l10n
* @property {boolean} [enableScripting]
* @property {Promise<boolean>} [hasJSActionsPromise]
* @property {Object} [mouseState]
* @property {Promise<Object<string, Array<Object>> | null>}
* [fieldObjectsPromise]
* @property {Map<string, HTMLCanvasElement>} [annotationCanvasMap] - Map some
@ -220,7 +219,6 @@ class IPDFAnnotationLayerFactory {
l10n = undefined,
enableScripting = false,
hasJSActionsPromise = null,
mouseState = null,
fieldObjectsPromise = null,
annotationCanvasMap = null,
accessibilityManager = null,

View file

@ -46,7 +46,6 @@ class PDFScriptingManager {
this._destroyCapability = null;
this._scripting = null;
this._mouseState = Object.create(null);
this._ready = false;
this._eventBus = eventBus;
@ -143,19 +142,9 @@ class PDFScriptingManager {
this._closeCapability?.resolve();
});
this._domEvents.set("mousedown", event => {
this._mouseState.isDown = true;
});
this._domEvents.set("mouseup", event => {
this._mouseState.isDown = false;
});
for (const [name, listener] of this._internalEvents) {
this._eventBus._on(name, listener);
}
for (const [name, listener] of this._domEvents) {
window.addEventListener(name, listener, true);
}
try {
const docProperties = await this._getDocProperties();
@ -229,10 +218,6 @@ class PDFScriptingManager {
});
}
get mouseState() {
return this._mouseState;
}
get destroyPromise() {
return this._destroyCapability?.promise || null;
}
@ -248,13 +233,6 @@ class PDFScriptingManager {
return shadow(this, "_internalEvents", new Map());
}
/**
* @private
*/
get _domEvents() {
return shadow(this, "_domEvents", new Map());
}
/**
* @private
*/
@ -508,16 +486,10 @@ class PDFScriptingManager {
}
this._internalEvents.clear();
for (const [name, listener] of this._domEvents) {
window.removeEventListener(name, listener, true);
}
this._domEvents.clear();
this._pageOpenPending.clear();
this._visitedPages.clear();
this._scripting = null;
delete this._mouseState.isDown;
this._ready = false;
this._destroyCapability?.resolve();

View file

@ -1703,7 +1703,6 @@ class PDFViewer {
* @property {IL10n} l10n
* @property {boolean} [enableScripting]
* @property {Promise<boolean>} [hasJSActionsPromise]
* @property {Object} [mouseState]
* @property {Promise<Object<string, Array<Object>> | null>}
* [fieldObjectsPromise]
* @property {Map<string, HTMLCanvasElement>} [annotationCanvasMap] - Map some
@ -1724,7 +1723,6 @@ class PDFViewer {
l10n = NullL10n,
enableScripting = this.enableScripting,
hasJSActionsPromise = this.pdfDocument?.hasJSActions(),
mouseState = this._scriptingManager?.mouseState,
fieldObjectsPromise = this.pdfDocument?.getFieldObjects(),
annotationCanvasMap = null,
accessibilityManager = null,
@ -1740,7 +1738,6 @@ class PDFViewer {
l10n,
enableScripting,
hasJSActionsPromise,
mouseState,
fieldObjectsPromise,
annotationCanvasMap,
accessibilityManager,