Ensure that we cancel any pending textLayer rendering operations when the viewer is closed (issue 7274)

This commit is contained in:
Jonas Jenwald 2016-07-29 20:51:37 +02:00
parent a824c6c4f6
commit 3904be8889
3 changed files with 24 additions and 14 deletions

View File

@ -1641,7 +1641,7 @@ function webViewerTextLayerRendered(e) {
} }
//#endif //#endif
//#if (FIREFOX || MOZCENTRAL) //#if (FIREFOX || MOZCENTRAL)
if (pageView.textLayer && pageView.textLayer.textDivs && if (pageView && pageView.textLayer && pageView.textLayer.textDivs &&
pageView.textLayer.textDivs.length > 0 && pageView.textLayer.textDivs.length > 0 &&
!PDFViewerApplication.supportsDocumentColors) { !PDFViewerApplication.supportsDocumentColors) {
console.error(mozL10n.get('document_colors_not_allowed', null, console.error(mozL10n.get('document_colors_not_allowed', null,

View File

@ -229,6 +229,11 @@ var PDFPageView = (function PDFPageViewClosure() {
} }
this.renderingState = RenderingStates.INITIAL; this.renderingState = RenderingStates.INITIAL;
this.resume = null; this.resume = null;
if (this.textLayer) {
this.textLayer.cancel();
this.textLayer = null;
}
}, },
/** /**

View File

@ -18,8 +18,7 @@
(function (root, factory) { (function (root, factory) {
if (typeof define === 'function' && define.amd) { if (typeof define === 'function' && define.amd) {
define('pdfjs-web/text_layer_builder', ['exports', 'pdfjs-web/dom_events', define('pdfjs-web/text_layer_builder', ['exports', 'pdfjs-web/dom_events',
'pdfjs-web/pdfjs'], 'pdfjs-web/pdfjs'], factory);
factory);
} else if (typeof exports !== 'undefined') { } else if (typeof exports !== 'undefined') {
factory(exports, require('./dom_events.js'), require('./pdfjs.js')); factory(exports, require('./dom_events.js'), require('./pdfjs.js'));
} else { } else {
@ -52,8 +51,8 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
function TextLayerBuilder(options) { function TextLayerBuilder(options) {
this.textLayerDiv = options.textLayerDiv; this.textLayerDiv = options.textLayerDiv;
this.eventBus = options.eventBus || domEvents.getGlobalEventBus(); this.eventBus = options.eventBus || domEvents.getGlobalEventBus();
this.textContent = null;
this.renderingDone = false; this.renderingDone = false;
this.divContentDone = false;
this.pageIdx = options.pageIndex; this.pageIdx = options.pageIndex;
this.pageNumber = this.pageIdx + 1; this.pageNumber = this.pageIdx + 1;
this.matches = []; this.matches = [];
@ -87,14 +86,10 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
* for specified amount of ms. * for specified amount of ms.
*/ */
render: function TextLayerBuilder_render(timeout) { render: function TextLayerBuilder_render(timeout) {
if (!this.divContentDone || this.renderingDone) { if (!this.textContent || this.renderingDone) {
return; return;
} }
this.cancel();
if (this.textLayerRenderTask) {
this.textLayerRenderTask.cancel();
this.textLayerRenderTask = null;
}
this.textDivs = []; this.textDivs = [];
var textLayerFrag = document.createDocumentFragment(); var textLayerFrag = document.createDocumentFragment();
@ -111,17 +106,23 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
this._finishRendering(); this._finishRendering();
this.updateMatches(); this.updateMatches();
}.bind(this), function (reason) { }.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) { if (this.textLayerRenderTask) {
this.textLayerRenderTask.cancel(); this.textLayerRenderTask.cancel();
this.textLayerRenderTask = null; this.textLayerRenderTask = null;
} }
},
setTextContent: function TextLayerBuilder_setTextContent(textContent) {
this.cancel();
this.textContent = textContent; this.textContent = textContent;
this.divContentDone = true;
}, },
convertMatches: function TextLayerBuilder_convertMatches(matches, convertMatches: function TextLayerBuilder_convertMatches(matches,
@ -324,6 +325,7 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
var div = this.textLayerDiv; var div = this.textLayerDiv;
var self = this; var self = this;
var expandDivsTimer = null; var expandDivsTimer = null;
div.addEventListener('mousedown', function (e) { div.addEventListener('mousedown', function (e) {
if (self.enhanceTextSelection && self.textLayerRenderTask) { if (self.enhanceTextSelection && self.textLayerRenderTask) {
self.textLayerRenderTask.expandTextDivs(true); self.textLayerRenderTask.expandTextDivs(true);
@ -357,11 +359,14 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
//#endif //#endif
end.classList.add('active'); end.classList.add('active');
}); });
div.addEventListener('mouseup', function (e) { div.addEventListener('mouseup', function (e) {
if (self.enhanceTextSelection && self.textLayerRenderTask) { if (self.enhanceTextSelection && self.textLayerRenderTask) {
//#if !(MOZCENTRAL || FIREFOX) //#if !(MOZCENTRAL || FIREFOX)
expandDivsTimer = setTimeout(function() { expandDivsTimer = setTimeout(function() {
self.textLayerRenderTask.expandTextDivs(false); if (self.textLayerRenderTask) {
self.textLayerRenderTask.expandTextDivs(false);
}
expandDivsTimer = null; expandDivsTimer = null;
}, EXPAND_DIVS_TIMEOUT); }, EXPAND_DIVS_TIMEOUT);
//#else //#else