Browse Source

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
Tim van der Meij 8 years ago committed by GitHub
parent
commit
bbec2ed1f1
  1. 9
      web/annotation_layer_builder.js
  2. 11
      web/pdf_page_view.js

9
web/annotation_layer_builder.js

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

11
web/pdf_page_view.js

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

Loading…
Cancel
Save