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 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;
|
||||||
|
@ -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,15 @@ 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;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when moved in the parent's container.
|
* Called when moved in the parent's container.
|
||||||
*/
|
*/
|
||||||
@ -320,6 +326,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}
|
||||||
|
Loading…
Reference in New Issue
Block a user