Improve how we disable PDFThumbnailView.setImage for documents with Optional Content (PR 12170 follow-up)

Rather than always disable `PDFThumbnailView.setImage` as soon as user has changed the visibility of the Optional Content, we can utilize the new method added in the previous patch to improve thumbnail performance. Note in particular how, in the old code, even *resetting* of the Optional Content to its default state wouldn't enable `PDFThumbnailView.setImage` again.

While slightly unrelated, this patch also removes the `PDFThumbnailViewer._optionalContentConfigPromise`-property since it's completely unused.
This commit is contained in:
Jonas Jenwald 2022-07-24 13:14:58 +02:00
parent ceb4f8a6ab
commit 3446f15bf3
4 changed files with 38 additions and 25 deletions

View file

@ -99,6 +99,8 @@ const MAX_CANVAS_PIXELS = compatibilityParams.maxCanvasPixels || 16777216;
class PDFPageView {
#annotationMode = AnnotationMode.ENABLE_FORMS;
#useThumbnailCanvas = true;
/**
* @param {PDFPageViewOptions} options
*/
@ -174,6 +176,22 @@ class PDFPageView {
this.div = div;
container?.append(div);
if (this._isStandalone) {
const { optionalContentConfigPromise } = options;
if (optionalContentConfigPromise) {
// Ensure that the thumbnails always display the *initial* document
// state.
optionalContentConfigPromise.then(optionalContentConfig => {
if (
optionalContentConfigPromise !== this._optionalContentConfigPromise
) {
return;
}
this.#useThumbnailCanvas = optionalContentConfig.hasInitialVisibility;
});
}
}
}
setPdfPage(pdfPage) {
@ -376,6 +394,16 @@ class PDFPageView {
}
if (optionalContentConfigPromise instanceof Promise) {
this._optionalContentConfigPromise = optionalContentConfigPromise;
// Ensure that the thumbnails always display the *initial* document state.
optionalContentConfigPromise.then(optionalContentConfig => {
if (
optionalContentConfigPromise !== this._optionalContentConfigPromise
) {
return;
}
this.#useThumbnailCanvas = optionalContentConfig.hasInitialVisibility;
});
}
const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
@ -1003,6 +1031,14 @@ class PDFPageView {
this.div.removeAttribute("data-page-label");
}
}
/**
* For use by the `PDFThumbnailView.setImage`-method.
* @ignore
*/
get thumbnailCanvas() {
return this.#useThumbnailCanvas ? this.canvas : null;
}
}
export { PDFPageView };