From 7bba4931ad0228b42c712906862ccbab56759230 Mon Sep 17 00:00:00 2001 From: Brendan Dahl Date: Mon, 17 Aug 2020 13:19:03 -0700 Subject: [PATCH] Dispatch event when annotations have finished rendering. 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. --- web/annotation_layer_builder.js | 4 +++- web/pdf_page_view.js | 22 ++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/web/annotation_layer_builder.js b/web/annotation_layer_builder.js index fc1707a74a2ab..9b1a633b79303 100644 --- a/web/annotation_layer_builder.js +++ b/web/annotation_layer_builder.js @@ -60,9 +60,11 @@ class AnnotationLayerBuilder { /** * @param {PageViewport} viewport * @param {string} intent (default value is 'display') + * @returns {Promise} A promise that is resolved when rendering of 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; } diff --git a/web/pdf_page_view.js b/web/pdf_page_view.js index 966f5b6ac963f..e0eeee9fe3158 100644 --- a/web/pdf_page_view.js +++ b/web/pdf_page_view.js @@ -142,6 +142,24 @@ class PDFPageView { } } + /** + * @private + */ + async _renderAnnotationLayer() { + let error = null; + try { + await this.annotationLayer.render(this.viewport, "display"); + } catch (ex) { + error = ex; + } finally { + this.eventBus.dispatch("annotationlayerrendered", { + source: this, + pageNumber: this.id, + error, + }); + } + } + /** * @private */ @@ -384,7 +402,7 @@ class PDFPageView { } if (redrawAnnotations && this.annotationLayer) { - this.annotationLayer.render(this.viewport, "display"); + this._renderAnnotationLayer(); } } @@ -542,7 +560,7 @@ class PDFPageView { this.l10n ); } - this.annotationLayer.render(this.viewport, "display"); + this._renderAnnotationLayer(); } div.setAttribute("data-loaded", true);