Re-factor document.getElementsByName lookups in the AnnotationLayer (issue 14003)

This replaces direct `document.getElementsByName` lookups with a helper method which:
 - Lets the AnnotationLayer use the data returned by the `PDFDocumentProxy.getFieldObjects` API-method, such that we can directly lookup only the necessary DOM elements.
 - Fallback to using `document.getElementsByName` as before, such that e.g. the standalone viewer components still work.

Finally, to fix the problems reported in issue 14003, regardless of the code-path we now also enforce that the DOM elements found were actually created by the AnnotationLayer code.
With these changes we'll thus be able to update form elements on all visible pages just as before, but we'll additionally update the AnnotationStorage for not-yet-rendered elements thus fixing a pre-existing bug.
This commit is contained in:
Jonas Jenwald 2021-09-14 12:06:28 +02:00
parent 8dc22f40c7
commit 6cba5509f2
6 changed files with 149 additions and 78 deletions

View file

@ -166,6 +166,8 @@ class IPDFAnnotationLayerFactory {
* @param {boolean} [enableScripting]
* @param {Promise<boolean>} [hasJSActionsPromise]
* @param {Object} [mouseState]
* @param {Promise<Object<string, Array<Object>> | null>}
* [fieldObjectsPromise]
* @returns {AnnotationLayerBuilder}
*/
createAnnotationLayerBuilder(
@ -177,7 +179,8 @@ class IPDFAnnotationLayerFactory {
l10n = undefined,
enableScripting = false,
hasJSActionsPromise = null,
mouseState = null
mouseState = null,
fieldObjectsPromise = null
) {}
}