Don't attempt to re-create the annotationLayer
, for pages without any annotations, on zooming and rotation
For pages without any annotations, applies e.g. to the `tracemonkey.pdf` document, we'll repeatedly try to re-create the `annotationLayer` on every zoom and rotation operation. The reason that this happens is because we don't insert the `annotationLayer`-div into the DOM unless there's annotations present on the page, which thus means that we miss the existing `annotationLayer`-caching present in the `PDFPageView` implementation. This is a very old issue, and the easiest solution is to simply always insert an *empty* (and hidden) `annotationLayer`-div such that the existing code/caching starts working for the "no annotations" case as well. Note that this is consistent with other layers, since e.g. the `textLayer` and/or `annotationEditorLayer` may be empty. Given that only a limited, by default ten, number of pages are ever active at once the additional DOM-elements shouldn't effect things negatively here.
This commit is contained in:
parent
d9f13558d6
commit
8e56f072e0
@ -47,6 +47,8 @@ import { PresentationModeState } from "./ui_utils.js";
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
class AnnotationLayerBuilder {
|
class AnnotationLayerBuilder {
|
||||||
|
#numAnnotations = 0;
|
||||||
|
|
||||||
#onPresentationModeChanged = null;
|
#onPresentationModeChanged = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -77,8 +79,8 @@ class AnnotationLayerBuilder {
|
|||||||
this.l10n = l10n;
|
this.l10n = l10n;
|
||||||
this.annotationStorage = annotationStorage;
|
this.annotationStorage = annotationStorage;
|
||||||
this.enableScripting = enableScripting;
|
this.enableScripting = enableScripting;
|
||||||
this._hasJSActionsPromise = hasJSActionsPromise;
|
this._hasJSActionsPromise = hasJSActionsPromise || Promise.resolve(false);
|
||||||
this._fieldObjectsPromise = fieldObjectsPromise;
|
this._fieldObjectsPromise = fieldObjectsPromise || Promise.resolve(null);
|
||||||
this._mouseState = mouseState;
|
this._mouseState = mouseState;
|
||||||
this._annotationCanvasMap = annotationCanvasMap;
|
this._annotationCanvasMap = annotationCanvasMap;
|
||||||
this._accessibilityManager = accessibilityManager;
|
this._accessibilityManager = accessibilityManager;
|
||||||
@ -95,18 +97,41 @@ class AnnotationLayerBuilder {
|
|||||||
* annotations is complete.
|
* annotations is complete.
|
||||||
*/
|
*/
|
||||||
async render(viewport, intent = "display") {
|
async render(viewport, intent = "display") {
|
||||||
const [annotations, hasJSActions = false, fieldObjects = null] =
|
if (this.div) {
|
||||||
await Promise.all([
|
if (this._cancelled || this.#numAnnotations === 0) {
|
||||||
this.pdfPage.getAnnotations({ intent }),
|
return;
|
||||||
this._hasJSActionsPromise,
|
}
|
||||||
this._fieldObjectsPromise,
|
// If an annotationLayer already exists, refresh its children's
|
||||||
]);
|
// transformation matrices.
|
||||||
|
AnnotationLayer.update({
|
||||||
if (this._cancelled || annotations.length === 0) {
|
viewport: viewport.clone({ dontFlip: true }),
|
||||||
|
div: this.div,
|
||||||
|
annotationCanvasMap: this._annotationCanvasMap,
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const parameters = {
|
const [annotations, hasJSActions, fieldObjects] = await Promise.all([
|
||||||
|
this.pdfPage.getAnnotations({ intent }),
|
||||||
|
this._hasJSActionsPromise,
|
||||||
|
this._fieldObjectsPromise,
|
||||||
|
]);
|
||||||
|
if (this._cancelled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.#numAnnotations = annotations.length;
|
||||||
|
|
||||||
|
// Create an annotation layer div and render the annotations
|
||||||
|
// if there is at least one annotation.
|
||||||
|
this.div = document.createElement("div");
|
||||||
|
this.div.className = "annotationLayer";
|
||||||
|
this.pageDiv.append(this.div);
|
||||||
|
|
||||||
|
if (this.#numAnnotations === 0) {
|
||||||
|
this.hide();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
AnnotationLayer.render({
|
||||||
viewport: viewport.clone({ dontFlip: true }),
|
viewport: viewport.clone({ dontFlip: true }),
|
||||||
div: this.div,
|
div: this.div,
|
||||||
annotations,
|
annotations,
|
||||||
@ -122,36 +147,22 @@ class AnnotationLayerBuilder {
|
|||||||
mouseState: this._mouseState,
|
mouseState: this._mouseState,
|
||||||
annotationCanvasMap: this._annotationCanvasMap,
|
annotationCanvasMap: this._annotationCanvasMap,
|
||||||
accessibilityManager: this._accessibilityManager,
|
accessibilityManager: this._accessibilityManager,
|
||||||
};
|
});
|
||||||
|
this.l10n.translate(this.div);
|
||||||
|
|
||||||
if (this.div) {
|
// Ensure that interactive form elements in the annotationLayer are
|
||||||
// If an annotationLayer already exists, refresh its children's
|
// disabled while PresentationMode is active (see issue 12232).
|
||||||
// transformation matrices.
|
if (this.linkService.isInPresentationMode) {
|
||||||
AnnotationLayer.update(parameters);
|
this.#updatePresentationModeState(PresentationModeState.FULLSCREEN);
|
||||||
} else {
|
}
|
||||||
// Create an annotation layer div and render the annotations
|
if (!this.#onPresentationModeChanged) {
|
||||||
// if there is at least one annotation.
|
this.#onPresentationModeChanged = evt => {
|
||||||
this.div = parameters.div = document.createElement("div");
|
this.#updatePresentationModeState(evt.state);
|
||||||
this.div.className = "annotationLayer";
|
};
|
||||||
this.pageDiv.append(this.div);
|
this._eventBus?._on(
|
||||||
|
"presentationmodechanged",
|
||||||
AnnotationLayer.render(parameters);
|
this.#onPresentationModeChanged
|
||||||
this.l10n.translate(this.div);
|
);
|
||||||
|
|
||||||
// Ensure that interactive form elements in the annotationLayer are
|
|
||||||
// disabled while PresentationMode is active (see issue 12232).
|
|
||||||
if (this.linkService.isInPresentationMode) {
|
|
||||||
this.#updatePresentationModeState(PresentationModeState.FULLSCREEN);
|
|
||||||
}
|
|
||||||
if (!this.#onPresentationModeChanged) {
|
|
||||||
this.#onPresentationModeChanged = evt => {
|
|
||||||
this.#updatePresentationModeState(evt.state);
|
|
||||||
};
|
|
||||||
this._eventBus?._on(
|
|
||||||
"presentationmodechanged",
|
|
||||||
this.#onPresentationModeChanged
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user