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.
This commit is contained in:
parent
54d6c2436c
commit
1eaa3b8a08
@ -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,14 @@ class PDFPageView {
|
||||
this.annotationLayer.cancel();
|
||||
this.annotationLayer = null;
|
||||
}
|
||||
|
||||
if (renderingState !== RenderingStates.INITIAL) {
|
||||
this.eventBus.dispatch('pagecancelled', {
|
||||
source: this,
|
||||
pageNumber: this.id,
|
||||
renderingState,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
cssTransform(target, redrawAnnotations = false) {
|
||||
|
@ -56,6 +56,9 @@ class TextLayerBuilder {
|
||||
this.textLayerRenderTask = null;
|
||||
this.enhanceTextSelection = enhanceTextSelection;
|
||||
|
||||
this._boundEvents = Object.create(null);
|
||||
this._bindEvents();
|
||||
|
||||
this._bindMouse();
|
||||
}
|
||||
|
||||
@ -331,6 +334,33 @@ class TextLayerBuilder {
|
||||
this.renderMatches(this.matches);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_bindEvents() {
|
||||
const { eventBus, _boundEvents, } = this;
|
||||
|
||||
_boundEvents.pageCancelled = (evt) => {
|
||||
if (evt.pageNumber !== this.pageNumber) {
|
||||
return;
|
||||
}
|
||||
if (this.textLayerRenderTask) {
|
||||
console.error('TextLayerBuilder._bindEvents: `this.cancel()` should ' +
|
||||
'have been called when the page was reset, or rendering cancelled.');
|
||||
return;
|
||||
}
|
||||
// Ensure that all event listeners are cleaned up when the page is reset,
|
||||
// since re-rendering will create new `TextLayerBuilder` instances and the
|
||||
// number of (stale) event listeners would otherwise grow without bound.
|
||||
for (const name in _boundEvents) {
|
||||
eventBus.off(name.toLowerCase(), _boundEvents[name]);
|
||||
delete _boundEvents[name];
|
||||
}
|
||||
};
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user