Skip to content

Commit

Permalink
Dispatch event when annotations have finished rendering.
Browse files Browse the repository at this point in the history
This is needed for some smoke tests in mozilla central for testing forms
in pdf.js.

Note: AnnotationLayerBuilder.render() doesn't really need to be async, but
we're talking of making the annotation's render functions async, so this
will make that switch easier.
  • Loading branch information
Brendan Dahl committed Aug 17, 2020
1 parent ebb903e commit 4db9228
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
4 changes: 3 additions & 1 deletion web/annotation_layer_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ class AnnotationLayerBuilder {
/**
* @param {PageViewport} viewport
* @param {string} intent (default value is 'display')
* @returns {Promise<void>} A promise resolved when rendering the annotations
* is complete.
*/
render(viewport, intent = "display") {
this.pdfPage.getAnnotations({ intent }).then(annotations => {
return this.pdfPage.getAnnotations({ intent }).then(annotations => {
if (this._cancelled) {
return;
}
Expand Down
22 changes: 20 additions & 2 deletions web/pdf_page_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,24 @@ class PDFPageView {
}
}

/**
* @private
*/
async _renderAnnotationLayer() {
let error = null;
try {
await this.annotationLayer.render(this.viewport, "display");
} catch (e) {
error = e;
} finally {
this.eventBus.dispatch("annotationsrendered", {
source: this,
pageNumber: this.id,
error,
});
}
}

/**
* @private
*/
Expand Down Expand Up @@ -384,7 +402,7 @@ class PDFPageView {
}

if (redrawAnnotations && this.annotationLayer) {
this.annotationLayer.render(this.viewport, "display");
this._renderAnnotationLayer();
}
}

Expand Down Expand Up @@ -542,7 +560,7 @@ class PDFPageView {
this.l10n
);
}
this.annotationLayer.render(this.viewport, "display");
this._renderAnnotationLayer();
}
div.setAttribute("data-loaded", true);

Expand Down

0 comments on commit 4db9228

Please sign in to comment.