From 2fb490488a305f26a0aecc61b9bf72c12038c0e4 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 23 Sep 2018 13:47:33 +0200 Subject: [PATCH] Dispatch a 'pagecancelled' event, in `PDFPageView.cancelRendering`, when rendering is cancelled Also, the patch updates `TextLayerBuilder` to use the new 'pagecancelled' event for (future) event removal purposes. --- web/pdf_page_view.js | 8 ++++++++ web/text_layer_builder.js | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/web/pdf_page_view.js b/web/pdf_page_view.js index 3b4f91425ecba4..cef5a00d643aa8 100644 --- a/web/pdf_page_view.js +++ b/web/pdf_page_view.js @@ -260,6 +260,8 @@ class PDFPageView { } cancelRendering(keepAnnotations = false) { + const renderingState = this.renderingState; + if (this.paintTask) { this.paintTask.cancel(); this.paintTask = null; @@ -275,6 +277,12 @@ class PDFPageView { this.annotationLayer.cancel(); this.annotationLayer = null; } + + this.eventBus.dispatch('pagecancelled', { + source: this, + pageNumber: this.id, + renderingState, + }); } cssTransform(target, redrawAnnotations = false) { diff --git a/web/text_layer_builder.js b/web/text_layer_builder.js index da78332918658a..c00438ddbba972 100644 --- a/web/text_layer_builder.js +++ b/web/text_layer_builder.js @@ -56,6 +56,9 @@ class TextLayerBuilder { this.textLayerRenderTask = null; this.enhanceTextSelection = enhanceTextSelection; + this._boundEvents = Object.create(null); + this._bindEvents(); + this._bindMouse(); } @@ -331,6 +334,25 @@ class TextLayerBuilder { this.renderMatches(this.matches); } + /** + * @private + */ + _bindEvents() { + const { eventBus, _boundEvents, pageNumber, } = this; + + _boundEvents.pageCancelled = function(evt) { + if (evt.pageNumber !== pageNumber) { + return; + } + for (const name in _boundEvents) { + eventBus.off(name.toLowerCase(), _boundEvents[name]); + _boundEvents[name] = null; + } + }; + + eventBus.on('pagecancelled', _boundEvents.pageCancelled); + } + /** * Improves text selection by adding an additional div where the mouse was * clicked. This reduces flickering of the content if the mouse is slowly