[api-minor] Move, most of, the isPureXfa-handling from PDFViewer and into PDFPageView

By moving this code the "pageviewer"-component example will become slightly more usable on its own, it may simplify a future addition of XFA Foreground document support, and finally also serves as preparation for the following patches.
This commit is contained in:
Jonas Jenwald 2022-12-06 13:38:19 +01:00
parent dd96ee1512
commit ded02941f2
3 changed files with 20 additions and 18 deletions

View File

@ -783,7 +783,7 @@ class PDFDocumentProxy {
* @type {boolean} True if only XFA form. * @type {boolean} True if only XFA form.
*/ */
get isPureXfa() { get isPureXfa() {
return !!this._transport._htmlForXfa; return shadow(this, "isPureXfa", !!this._transport._htmlForXfa);
} }
/** /**
@ -1343,6 +1343,13 @@ class PDFPageProxy {
)); ));
} }
/**
* @type {boolean} True if only XFA form.
*/
get isPureXfa() {
return shadow(this, "isPureXfa", !!this._transport._htmlForXfa);
}
/** /**
* @returns {Promise<Object | null>} A promise that is resolved with * @returns {Promise<Object | null>} A promise that is resolved with
* an {Object} with a fake DOM object (a tree structure where elements * an {Object} with a fake DOM object (a tree structure where elements

View File

@ -753,6 +753,7 @@ class PDFPageView {
if ( if (
!this.textLayer && !this.textLayer &&
this.textLayerMode !== TextLayerMode.DISABLE && this.textLayerMode !== TextLayerMode.DISABLE &&
!pdfPage.isPureXfa &&
this.textLayerFactory this.textLayerFactory
) { ) {
this._accessibilityManager ||= new TextAccessibilityManager(); this._accessibilityManager ||= new TextAccessibilityManager();
@ -878,7 +879,7 @@ class PDFPageView {
} }
); );
if (this.xfaLayerFactory) { if (pdfPage.isPureXfa && this.xfaLayerFactory) {
this.xfaLayer ||= this.xfaLayerFactory.createXfaLayerBuilder({ this.xfaLayer ||= this.xfaLayerFactory.createXfaLayerBuilder({
pageDiv: div, pageDiv: div,
pdfPage, pdfPage,

View File

@ -658,7 +658,6 @@ class PDFViewer {
if (!pdfDocument) { if (!pdfDocument) {
return; return;
} }
const isPureXfa = pdfDocument.isPureXfa;
const pagesCount = pdfDocument.numPages; const pagesCount = pdfDocument.numPages;
const firstPagePromise = pdfDocument.getPage(1); const firstPagePromise = pdfDocument.getPage(1);
// Rendering (potentially) depends on this, hence fetching it immediately. // Rendering (potentially) depends on this, hence fetching it immediately.
@ -732,13 +731,13 @@ class PDFViewer {
if (annotationEditorMode !== AnnotationEditorType.DISABLE) { if (annotationEditorMode !== AnnotationEditorType.DISABLE) {
const mode = annotationEditorMode; const mode = annotationEditorMode;
if (isPureXfa) { if (pdfDocument.isPureXfa) {
console.warn("Warning: XFA-editing is not implemented."); console.warn("Warning: XFA-editing is not implemented.");
} else if (isValidAnnotationEditorMode(mode)) { } else if (isValidAnnotationEditorMode(mode)) {
this.#annotationEditorUIManager = new AnnotationEditorUIManager( this.#annotationEditorUIManager = new AnnotationEditorUIManager(
this.container, this.container,
this.eventBus, this.eventBus,
this.pdfDocument?.annotationStorage pdfDocument?.annotationStorage
); );
if (mode !== AnnotationEditorType.NONE) { if (mode !== AnnotationEditorType.NONE) {
this.#annotationEditorUIManager.updateMode(mode); this.#annotationEditorUIManager.updateMode(mode);
@ -758,15 +757,6 @@ class PDFViewer {
// see issue 15795. // see issue 15795.
docStyle.setProperty("--scale-factor", viewport.scale); docStyle.setProperty("--scale-factor", viewport.scale);
const textLayerFactory =
textLayerMode !== TextLayerMode.DISABLE && !isPureXfa ? this : null;
const annotationLayerFactory =
annotationMode !== AnnotationMode.DISABLE ? this : null;
const xfaLayerFactory = isPureXfa ? this : null;
const annotationEditorLayerFactory = this.#annotationEditorUIManager
? this
: null;
for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) { for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
const pageView = new PDFPageView({ const pageView = new PDFPageView({
container: viewerElement, container: viewerElement,
@ -776,12 +766,16 @@ class PDFViewer {
defaultViewport: viewport.clone(), defaultViewport: viewport.clone(),
optionalContentConfigPromise, optionalContentConfigPromise,
renderingQueue: this.renderingQueue, renderingQueue: this.renderingQueue,
textLayerFactory, textLayerFactory:
textLayerMode !== TextLayerMode.DISABLE ? this : null,
textLayerMode, textLayerMode,
annotationLayerFactory, annotationLayerFactory:
annotationMode !== AnnotationMode.DISABLE ? this : null,
annotationMode, annotationMode,
xfaLayerFactory, xfaLayerFactory: this,
annotationEditorLayerFactory, annotationEditorLayerFactory: this.#annotationEditorUIManager
? this
: null,
textHighlighterFactory: this, textHighlighterFactory: this,
structTreeLayerFactory: this, structTreeLayerFactory: this,
imageResourcesPath: this.imageResourcesPath, imageResourcesPath: this.imageResourcesPath,