Merge pull request #7514 from Snuffleupagus/viewer-abort-rendering-on-close
Ensure that we cancel any pending rendering operations when the viewer is closed (issue 7274)
This commit is contained in:
commit
8c5b925547
27
web/app.js
27
web/app.js
@ -1583,6 +1583,19 @@ function webViewerPageRendered(e) {
|
|||||||
var pageIndex = pageNumber - 1;
|
var pageIndex = pageNumber - 1;
|
||||||
var pageView = PDFViewerApplication.pdfViewer.getPageView(pageIndex);
|
var pageView = PDFViewerApplication.pdfViewer.getPageView(pageIndex);
|
||||||
|
|
||||||
|
// If the page is still visible when it has finished rendering,
|
||||||
|
// ensure that the page number input loading indicator is hidden.
|
||||||
|
if (pageNumber === PDFViewerApplication.page) {
|
||||||
|
var pageNumberInput = PDFViewerApplication.appConfig.toolbar.pageNumber;
|
||||||
|
pageNumberInput.classList.remove(PAGE_NUMBER_LOADING_INDICATOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prevent errors in the edge-case where the PDF document is removed *before*
|
||||||
|
// the 'pagerendered' event handler is invoked.
|
||||||
|
if (!pageView) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Use the rendered page to set the corresponding thumbnail image.
|
// Use the rendered page to set the corresponding thumbnail image.
|
||||||
if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
|
if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
|
||||||
var thumbnailView = PDFViewerApplication.pdfThumbnailViewer.
|
var thumbnailView = PDFViewerApplication.pdfThumbnailViewer.
|
||||||
@ -1599,13 +1612,6 @@ function webViewerPageRendered(e) {
|
|||||||
'An error occurred while rendering the page.'), pageView.error);
|
'An error occurred while rendering the page.'), pageView.error);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the page is still visible when it has finished rendering,
|
|
||||||
// ensure that the page number input loading indicator is hidden.
|
|
||||||
if (pageNumber === PDFViewerApplication.page) {
|
|
||||||
var pageNumberInput = PDFViewerApplication.appConfig.toolbar.pageNumber;
|
|
||||||
pageNumberInput.classList.remove(PAGE_NUMBER_LOADING_INDICATOR);
|
|
||||||
}
|
|
||||||
|
|
||||||
//#if !PRODUCTION
|
//#if !PRODUCTION
|
||||||
if (true) {
|
if (true) {
|
||||||
return;
|
return;
|
||||||
@ -1626,18 +1632,13 @@ function webViewerPageRendered(e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function webViewerTextLayerRendered(e) {
|
function webViewerTextLayerRendered(e) {
|
||||||
var pageIndex = e.pageNumber - 1;
|
|
||||||
var pageView = PDFViewerApplication.pdfViewer.getPageView(pageIndex);
|
|
||||||
|
|
||||||
//#if !PRODUCTION
|
//#if !PRODUCTION
|
||||||
if (true) {
|
if (true) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//#endif
|
//#endif
|
||||||
//#if (FIREFOX || MOZCENTRAL)
|
//#if (FIREFOX || MOZCENTRAL)
|
||||||
if (pageView.textLayer && pageView.textLayer.textDivs &&
|
if (e.numTextDivs > 0 && !PDFViewerApplication.supportsDocumentColors) {
|
||||||
pageView.textLayer.textDivs.length > 0 &&
|
|
||||||
!PDFViewerApplication.supportsDocumentColors) {
|
|
||||||
console.error(mozL10n.get('document_colors_not_allowed', null,
|
console.error(mozL10n.get('document_colors_not_allowed', null,
|
||||||
'PDF documents are not allowed to use their own colors: ' +
|
'PDF documents are not allowed to use their own colors: ' +
|
||||||
'\'Allow pages to choose their own colors\' ' +
|
'\'Allow pages to choose their own colors\' ' +
|
||||||
|
@ -92,6 +92,7 @@ var PDFPageView = (function PDFPageViewClosure() {
|
|||||||
this.textLayerFactory = textLayerFactory;
|
this.textLayerFactory = textLayerFactory;
|
||||||
this.annotationLayerFactory = annotationLayerFactory;
|
this.annotationLayerFactory = annotationLayerFactory;
|
||||||
|
|
||||||
|
this.renderTask = null;
|
||||||
this.renderingState = RenderingStates.INITIAL;
|
this.renderingState = RenderingStates.INITIAL;
|
||||||
this.resume = null;
|
this.resume = null;
|
||||||
|
|
||||||
@ -135,11 +136,7 @@ var PDFPageView = (function PDFPageViewClosure() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
reset: function PDFPageView_reset(keepZoomLayer, keepAnnotations) {
|
reset: function PDFPageView_reset(keepZoomLayer, keepAnnotations) {
|
||||||
if (this.renderTask) {
|
this.cancelRendering();
|
||||||
this.renderTask.cancel();
|
|
||||||
}
|
|
||||||
this.resume = null;
|
|
||||||
this.renderingState = RenderingStates.INITIAL;
|
|
||||||
|
|
||||||
var div = this.div;
|
var div = this.div;
|
||||||
div.style.width = Math.floor(this.viewport.width) + 'px';
|
div.style.width = Math.floor(this.viewport.width) + 'px';
|
||||||
@ -225,6 +222,20 @@ var PDFPageView = (function PDFPageViewClosure() {
|
|||||||
this.reset(/* keepZoomLayer = */ true, /* keepAnnotations = */ true);
|
this.reset(/* keepZoomLayer = */ true, /* keepAnnotations = */ true);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
cancelRendering: function PDFPageView_cancelRendering() {
|
||||||
|
if (this.renderTask) {
|
||||||
|
this.renderTask.cancel();
|
||||||
|
this.renderTask = null;
|
||||||
|
}
|
||||||
|
this.renderingState = RenderingStates.INITIAL;
|
||||||
|
this.resume = null;
|
||||||
|
|
||||||
|
if (this.textLayer) {
|
||||||
|
this.textLayer.cancel();
|
||||||
|
this.textLayer = null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when moved in the parent's container.
|
* Called when moved in the parent's container.
|
||||||
*/
|
*/
|
||||||
@ -320,6 +331,7 @@ var PDFPageView = (function PDFPageViewClosure() {
|
|||||||
draw: function PDFPageView_draw() {
|
draw: function PDFPageView_draw() {
|
||||||
if (this.renderingState !== RenderingStates.INITIAL) {
|
if (this.renderingState !== RenderingStates.INITIAL) {
|
||||||
console.error('Must be in new state before drawing');
|
console.error('Must be in new state before drawing');
|
||||||
|
this.reset(); // Ensure that we reset all state to prevent issues.
|
||||||
}
|
}
|
||||||
|
|
||||||
this.renderingState = RenderingStates.RUNNING;
|
this.renderingState = RenderingStates.RUNNING;
|
||||||
|
@ -98,8 +98,9 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
|
|||||||
this.linkService = linkService;
|
this.linkService = linkService;
|
||||||
this.renderingQueue = renderingQueue;
|
this.renderingQueue = renderingQueue;
|
||||||
|
|
||||||
this.resume = null;
|
this.renderTask = null;
|
||||||
this.renderingState = RenderingStates.INITIAL;
|
this.renderingState = RenderingStates.INITIAL;
|
||||||
|
this.resume = null;
|
||||||
this.disableCanvasToImageConversion = disableCanvasToImageConversion;
|
this.disableCanvasToImageConversion = disableCanvasToImageConversion;
|
||||||
|
|
||||||
this.pageWidth = this.viewport.width;
|
this.pageWidth = this.viewport.width;
|
||||||
@ -151,11 +152,7 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
reset: function PDFThumbnailView_reset() {
|
reset: function PDFThumbnailView_reset() {
|
||||||
if (this.renderTask) {
|
this.cancelRendering();
|
||||||
this.renderTask.cancel();
|
|
||||||
}
|
|
||||||
this.resume = null;
|
|
||||||
this.renderingState = RenderingStates.INITIAL;
|
|
||||||
|
|
||||||
this.pageWidth = this.viewport.width;
|
this.pageWidth = this.viewport.width;
|
||||||
this.pageHeight = this.viewport.height;
|
this.pageHeight = this.viewport.height;
|
||||||
@ -199,6 +196,15 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
|
|||||||
this.reset();
|
this.reset();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
cancelRendering: function PDFThumbnailView_cancelRendering() {
|
||||||
|
if (this.renderTask) {
|
||||||
|
this.renderTask.cancel();
|
||||||
|
this.renderTask = null;
|
||||||
|
}
|
||||||
|
this.renderingState = RenderingStates.INITIAL;
|
||||||
|
this.resume = null;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
|
@ -135,15 +135,14 @@ var PDFThumbnailViewer = (function PDFThumbnailViewerClosure() {
|
|||||||
this.thumbnails = [];
|
this.thumbnails = [];
|
||||||
this._pagesRotation = 0;
|
this._pagesRotation = 0;
|
||||||
this._pagesRequests = [];
|
this._pagesRequests = [];
|
||||||
|
|
||||||
|
// Remove the thumbnails from the DOM.
|
||||||
|
this.container.textContent = '';
|
||||||
},
|
},
|
||||||
|
|
||||||
setDocument: function PDFThumbnailViewer_setDocument(pdfDocument) {
|
setDocument: function PDFThumbnailViewer_setDocument(pdfDocument) {
|
||||||
if (this.pdfDocument) {
|
if (this.pdfDocument) {
|
||||||
// cleanup of the elements and views
|
this._cancelRendering();
|
||||||
var thumbsView = this.container;
|
|
||||||
while (thumbsView.hasChildNodes()) {
|
|
||||||
thumbsView.removeChild(thumbsView.lastChild);
|
|
||||||
}
|
|
||||||
this._resetView();
|
this._resetView();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,6 +168,17 @@ var PDFThumbnailViewer = (function PDFThumbnailViewerClosure() {
|
|||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
_cancelRendering: function PDFThumbnailViewer_cancelRendering() {
|
||||||
|
for (var i = 0, ii = this.thumbnails.length; i < ii; i++) {
|
||||||
|
if (this.thumbnails[i]) {
|
||||||
|
this.thumbnails[i].cancelRendering();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {PDFThumbnailView} thumbView
|
* @param {PDFThumbnailView} thumbView
|
||||||
* @returns {PDFPage}
|
* @returns {PDFPage}
|
||||||
|
@ -299,6 +299,7 @@ var PDFViewer = (function pdfViewer() {
|
|||||||
*/
|
*/
|
||||||
setDocument: function (pdfDocument) {
|
setDocument: function (pdfDocument) {
|
||||||
if (this.pdfDocument) {
|
if (this.pdfDocument) {
|
||||||
|
this._cancelRendering();
|
||||||
this._resetView();
|
this._resetView();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -424,10 +425,8 @@ var PDFViewer = (function pdfViewer() {
|
|||||||
this._pagesRequests = [];
|
this._pagesRequests = [];
|
||||||
this._pageViewsReady = false;
|
this._pageViewsReady = false;
|
||||||
|
|
||||||
var container = this.viewer;
|
// Remove the pages from the DOM.
|
||||||
while (container.hasChildNodes()) {
|
this.viewer.textContent = '';
|
||||||
container.removeChild(container.lastChild);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_scrollUpdate: function PDFViewer_scrollUpdate() {
|
_scrollUpdate: function PDFViewer_scrollUpdate() {
|
||||||
@ -802,6 +801,17 @@ var PDFViewer = (function pdfViewer() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
_cancelRendering: function PDFViewer_cancelRendering() {
|
||||||
|
for (var i = 0, ii = this._pages.length; i < ii; i++) {
|
||||||
|
if (this._pages[i]) {
|
||||||
|
this._pages[i].cancelRendering();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {PDFPageView} pageView
|
* @param {PDFPageView} pageView
|
||||||
* @returns {PDFPage}
|
* @returns {PDFPage}
|
||||||
|
@ -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 = [];
|
||||||
@ -66,6 +65,9 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TextLayerBuilder.prototype = {
|
TextLayerBuilder.prototype = {
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
_finishRendering: function TextLayerBuilder_finishRendering() {
|
_finishRendering: function TextLayerBuilder_finishRendering() {
|
||||||
this.renderingDone = true;
|
this.renderingDone = true;
|
||||||
|
|
||||||
@ -77,7 +79,8 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
|
|||||||
|
|
||||||
this.eventBus.dispatch('textlayerrendered', {
|
this.eventBus.dispatch('textlayerrendered', {
|
||||||
source: this,
|
source: this,
|
||||||
pageNumber: this.pageNumber
|
pageNumber: this.pageNumber,
|
||||||
|
numTextDivs: this.textDivs.length,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -87,14 +90,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 +110,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 +329,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 +363,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
|
||||||
|
Loading…
Reference in New Issue
Block a user