Skip to content

Commit

Permalink
Dispatch a 'pagecancelled' event, in PDFPageView.cancelRendering, w…
Browse files Browse the repository at this point in the history
…hen rendering is cancelled

Also, the patch updates `TextLayerBuilder` to use the new 'pagecancelled' event for (future) event removal purposes.
  • Loading branch information
Snuffleupagus committed Sep 23, 2018
1 parent 54d6c24 commit 2fb4904
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
8 changes: 8 additions & 0 deletions web/pdf_page_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ class PDFPageView {
}

cancelRendering(keepAnnotations = false) {
const renderingState = this.renderingState;

if (this.paintTask) {
this.paintTask.cancel();
this.paintTask = null;
Expand All @@ -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) {
Expand Down
22 changes: 22 additions & 0 deletions web/text_layer_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class TextLayerBuilder {
this.textLayerRenderTask = null;
this.enhanceTextSelection = enhanceTextSelection;

this._boundEvents = Object.create(null);
this._bindEvents();

this._bindMouse();
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2fb4904

Please sign in to comment.