Ensure that any pending rendering operations in PDFViewer
/PDFThumbnailViewer
are cancelled when the viewer is closed
This commit is contained in:
parent
fb5aa58008
commit
a824c6c4f6
20
web/app.js
20
web/app.js
@ -1583,6 +1583,19 @@ function webViewerPageRendered(e) {
|
||||
var pageIndex = pageNumber - 1;
|
||||
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.
|
||||
if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
|
||||
var thumbnailView = PDFViewerApplication.pdfThumbnailViewer.
|
||||
@ -1599,13 +1612,6 @@ function webViewerPageRendered(e) {
|
||||
'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 (true) {
|
||||
return;
|
||||
|
@ -92,6 +92,7 @@ var PDFPageView = (function PDFPageViewClosure() {
|
||||
this.textLayerFactory = textLayerFactory;
|
||||
this.annotationLayerFactory = annotationLayerFactory;
|
||||
|
||||
this.renderTask = null;
|
||||
this.renderingState = RenderingStates.INITIAL;
|
||||
this.resume = null;
|
||||
|
||||
@ -135,11 +136,7 @@ var PDFPageView = (function PDFPageViewClosure() {
|
||||
},
|
||||
|
||||
reset: function PDFPageView_reset(keepZoomLayer, keepAnnotations) {
|
||||
if (this.renderTask) {
|
||||
this.renderTask.cancel();
|
||||
}
|
||||
this.resume = null;
|
||||
this.renderingState = RenderingStates.INITIAL;
|
||||
this.cancelRendering();
|
||||
|
||||
var div = this.div;
|
||||
div.style.width = Math.floor(this.viewport.width) + 'px';
|
||||
@ -225,6 +222,15 @@ var PDFPageView = (function PDFPageViewClosure() {
|
||||
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;
|
||||
},
|
||||
|
||||
/**
|
||||
* Called when moved in the parent's container.
|
||||
*/
|
||||
@ -320,6 +326,7 @@ var PDFPageView = (function PDFPageViewClosure() {
|
||||
draw: function PDFPageView_draw() {
|
||||
if (this.renderingState !== RenderingStates.INITIAL) {
|
||||
console.error('Must be in new state before drawing');
|
||||
this.reset(); // Ensure that we reset all state to prevent issues.
|
||||
}
|
||||
|
||||
this.renderingState = RenderingStates.RUNNING;
|
||||
|
@ -98,8 +98,9 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
|
||||
this.linkService = linkService;
|
||||
this.renderingQueue = renderingQueue;
|
||||
|
||||
this.resume = null;
|
||||
this.renderTask = null;
|
||||
this.renderingState = RenderingStates.INITIAL;
|
||||
this.resume = null;
|
||||
this.disableCanvasToImageConversion = disableCanvasToImageConversion;
|
||||
|
||||
this.pageWidth = this.viewport.width;
|
||||
@ -151,11 +152,7 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
|
||||
},
|
||||
|
||||
reset: function PDFThumbnailView_reset() {
|
||||
if (this.renderTask) {
|
||||
this.renderTask.cancel();
|
||||
}
|
||||
this.resume = null;
|
||||
this.renderingState = RenderingStates.INITIAL;
|
||||
this.cancelRendering();
|
||||
|
||||
this.pageWidth = this.viewport.width;
|
||||
this.pageHeight = this.viewport.height;
|
||||
@ -199,6 +196,15 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
|
||||
this.reset();
|
||||
},
|
||||
|
||||
cancelRendering: function PDFThumbnailView_cancelRendering() {
|
||||
if (this.renderTask) {
|
||||
this.renderTask.cancel();
|
||||
this.renderTask = null;
|
||||
}
|
||||
this.renderingState = RenderingStates.INITIAL;
|
||||
this.resume = null;
|
||||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
|
@ -135,15 +135,14 @@ var PDFThumbnailViewer = (function PDFThumbnailViewerClosure() {
|
||||
this.thumbnails = [];
|
||||
this._pagesRotation = 0;
|
||||
this._pagesRequests = [];
|
||||
|
||||
// Remove the thumbnails from the DOM.
|
||||
this.container.textContent = '';
|
||||
},
|
||||
|
||||
setDocument: function PDFThumbnailViewer_setDocument(pdfDocument) {
|
||||
if (this.pdfDocument) {
|
||||
// cleanup of the elements and views
|
||||
var thumbsView = this.container;
|
||||
while (thumbsView.hasChildNodes()) {
|
||||
thumbsView.removeChild(thumbsView.lastChild);
|
||||
}
|
||||
this._cancelRendering();
|
||||
this._resetView();
|
||||
}
|
||||
|
||||
@ -169,6 +168,17 @@ var PDFThumbnailViewer = (function PDFThumbnailViewerClosure() {
|
||||
}.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
|
||||
* @returns {PDFPage}
|
||||
|
@ -299,6 +299,7 @@ var PDFViewer = (function pdfViewer() {
|
||||
*/
|
||||
setDocument: function (pdfDocument) {
|
||||
if (this.pdfDocument) {
|
||||
this._cancelRendering();
|
||||
this._resetView();
|
||||
}
|
||||
|
||||
@ -424,10 +425,8 @@ var PDFViewer = (function pdfViewer() {
|
||||
this._pagesRequests = [];
|
||||
this._pageViewsReady = false;
|
||||
|
||||
var container = this.viewer;
|
||||
while (container.hasChildNodes()) {
|
||||
container.removeChild(container.lastChild);
|
||||
}
|
||||
// Remove the pages from the DOM.
|
||||
this.viewer.textContent = '';
|
||||
},
|
||||
|
||||
_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
|
||||
* @returns {PDFPage}
|
||||
|
Loading…
Reference in New Issue
Block a user