Merge pull request #9001 from Snuffleupagus/AnnotationLayerBuilder-cancel

Prevent the `annotationLayer` from, in some cases, becoming duplicated on the first page when the document loads
This commit is contained in:
Tim van der Meij 2017-10-07 14:49:42 +02:00 committed by GitHub
commit bbec2ed1f1
2 changed files with 17 additions and 3 deletions

View File

@ -41,6 +41,7 @@ class AnnotationLayerBuilder {
this.l10n = l10n;
this.div = null;
this._cancelled = false;
}
/**
@ -49,6 +50,10 @@ class AnnotationLayerBuilder {
*/
render(viewport, intent = 'display') {
this.pdfPage.getAnnotations({ intent, }).then((annotations) => {
if (this._cancelled) {
return;
}
let parameters = {
viewport: viewport.clone({ dontFlip: true, }),
div: this.div,
@ -80,6 +85,10 @@ class AnnotationLayerBuilder {
});
}
cancel() {
this._cancelled = true;
}
hide() {
if (!this.div) {
return;

View File

@ -136,7 +136,7 @@ class PDFPageView {
}
reset(keepZoomLayer = false, keepAnnotations = false) {
this.cancelRendering();
this.cancelRendering(keepAnnotations);
let div = this.div;
div.style.width = Math.floor(this.viewport.width) + 'px';
@ -159,7 +159,8 @@ class PDFPageView {
// Hide the annotation layer until all elements are resized
// so they are not displayed on the already resized page.
this.annotationLayer.hide();
} else {
} else if (this.annotationLayer) {
this.annotationLayer.cancel();
this.annotationLayer = null;
}
@ -240,7 +241,7 @@ class PDFPageView {
this.reset(/* keepZoomLayer = */ true, /* keepAnnotations = */ true);
}
cancelRendering() {
cancelRendering(keepAnnotations = false) {
if (this.paintTask) {
this.paintTask.cancel();
this.paintTask = null;
@ -252,6 +253,10 @@ class PDFPageView {
this.textLayer.cancel();
this.textLayer = null;
}
if (!keepAnnotations && this.annotationLayer) {
this.annotationLayer.cancel();
this.annotationLayer = null;
}
}
cssTransform(target, redrawAnnotations = false) {