Ensure that we cancel any pending textLayer
rendering operations when the viewer is closed (issue 7274)
This commit is contained in:
parent
a824c6c4f6
commit
3904be8889
@ -1641,7 +1641,7 @@ function webViewerTextLayerRendered(e) {
|
||||
}
|
||||
//#endif
|
||||
//#if (FIREFOX || MOZCENTRAL)
|
||||
if (pageView.textLayer && pageView.textLayer.textDivs &&
|
||||
if (pageView && pageView.textLayer && pageView.textLayer.textDivs &&
|
||||
pageView.textLayer.textDivs.length > 0 &&
|
||||
!PDFViewerApplication.supportsDocumentColors) {
|
||||
console.error(mozL10n.get('document_colors_not_allowed', null,
|
||||
|
@ -229,6 +229,11 @@ var PDFPageView = (function PDFPageViewClosure() {
|
||||
}
|
||||
this.renderingState = RenderingStates.INITIAL;
|
||||
this.resume = null;
|
||||
|
||||
if (this.textLayer) {
|
||||
this.textLayer.cancel();
|
||||
this.textLayer = null;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -18,8 +18,7 @@
|
||||
(function (root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
define('pdfjs-web/text_layer_builder', ['exports', 'pdfjs-web/dom_events',
|
||||
'pdfjs-web/pdfjs'],
|
||||
factory);
|
||||
'pdfjs-web/pdfjs'], factory);
|
||||
} else if (typeof exports !== 'undefined') {
|
||||
factory(exports, require('./dom_events.js'), require('./pdfjs.js'));
|
||||
} else {
|
||||
@ -52,8 +51,8 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
|
||||
function TextLayerBuilder(options) {
|
||||
this.textLayerDiv = options.textLayerDiv;
|
||||
this.eventBus = options.eventBus || domEvents.getGlobalEventBus();
|
||||
this.textContent = null;
|
||||
this.renderingDone = false;
|
||||
this.divContentDone = false;
|
||||
this.pageIdx = options.pageIndex;
|
||||
this.pageNumber = this.pageIdx + 1;
|
||||
this.matches = [];
|
||||
@ -87,14 +86,10 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
|
||||
* for specified amount of ms.
|
||||
*/
|
||||
render: function TextLayerBuilder_render(timeout) {
|
||||
if (!this.divContentDone || this.renderingDone) {
|
||||
if (!this.textContent || this.renderingDone) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.textLayerRenderTask) {
|
||||
this.textLayerRenderTask.cancel();
|
||||
this.textLayerRenderTask = null;
|
||||
}
|
||||
this.cancel();
|
||||
|
||||
this.textDivs = [];
|
||||
var textLayerFrag = document.createDocumentFragment();
|
||||
@ -111,17 +106,23 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
|
||||
this._finishRendering();
|
||||
this.updateMatches();
|
||||
}.bind(this), function (reason) {
|
||||
// canceled or failed to render text layer -- skipping errors
|
||||
// cancelled or failed to render text layer -- skipping errors
|
||||
});
|
||||
},
|
||||
|
||||
setTextContent: function TextLayerBuilder_setTextContent(textContent) {
|
||||
/**
|
||||
* Cancels rendering of the text layer.
|
||||
*/
|
||||
cancel: function TextLayerBuilder_cancel() {
|
||||
if (this.textLayerRenderTask) {
|
||||
this.textLayerRenderTask.cancel();
|
||||
this.textLayerRenderTask = null;
|
||||
}
|
||||
},
|
||||
|
||||
setTextContent: function TextLayerBuilder_setTextContent(textContent) {
|
||||
this.cancel();
|
||||
this.textContent = textContent;
|
||||
this.divContentDone = true;
|
||||
},
|
||||
|
||||
convertMatches: function TextLayerBuilder_convertMatches(matches,
|
||||
@ -324,6 +325,7 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
|
||||
var div = this.textLayerDiv;
|
||||
var self = this;
|
||||
var expandDivsTimer = null;
|
||||
|
||||
div.addEventListener('mousedown', function (e) {
|
||||
if (self.enhanceTextSelection && self.textLayerRenderTask) {
|
||||
self.textLayerRenderTask.expandTextDivs(true);
|
||||
@ -357,11 +359,14 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
|
||||
//#endif
|
||||
end.classList.add('active');
|
||||
});
|
||||
|
||||
div.addEventListener('mouseup', function (e) {
|
||||
if (self.enhanceTextSelection && self.textLayerRenderTask) {
|
||||
//#if !(MOZCENTRAL || FIREFOX)
|
||||
expandDivsTimer = setTimeout(function() {
|
||||
self.textLayerRenderTask.expandTextDivs(false);
|
||||
if (self.textLayerRenderTask) {
|
||||
self.textLayerRenderTask.expandTextDivs(false);
|
||||
}
|
||||
expandDivsTimer = null;
|
||||
}, EXPAND_DIVS_TIMEOUT);
|
||||
//#else
|
||||
|
Loading…
x
Reference in New Issue
Block a user