Fix {PDFPageView, PDFThumbnailView}.cancelRendering to avoid visual artifacts when called directly

Currently these methods are only used from the respective `reset` methods, and from `{BaseViewer, PDFThumbnailViewer}._cancelRendering` which only runs when the active document is closed.

This patch changes `{PDFPageView, PDFThumbnailView}.cancelRendering` to *only* cancel any pending rendering operations, and doesn't attempt to reset e.g. the `renderingState`, since that causes visual glitches (duplicated canvases in the viewer) when called directly.
Furthermore, unless you "know" what you're doing, the `{PDFPageView, PDFThumbnailView}.reset` methods are what *should* normally be used instead.
This commit is contained in:
Jonas Jenwald 2019-02-14 18:47:32 +01:00
parent 1ded729130
commit 599dcf5a44
2 changed files with 10 additions and 2 deletions

View File

@ -154,6 +154,7 @@ class PDFPageView {
reset(keepZoomLayer = false, keepAnnotations = false) {
this.cancelRendering(keepAnnotations);
this.renderingState = RenderingStates.INITIAL;
let div = this.div;
div.style.width = Math.floor(this.viewport.width) + 'px';
@ -258,12 +259,15 @@ class PDFPageView {
this.reset(/* keepZoomLayer = */ true, /* keepAnnotations = */ true);
}
/**
* PLEASE NOTE: Most likely you want to use the `this.reset()` method,
* rather than calling this one directly.
*/
cancelRendering(keepAnnotations = false) {
if (this.paintTask) {
this.paintTask.cancel();
this.paintTask = null;
}
this.renderingState = RenderingStates.INITIAL;
this.resume = null;
if (this.textLayer) {

View File

@ -152,6 +152,7 @@ class PDFThumbnailView {
reset() {
this.cancelRendering();
this.renderingState = RenderingStates.INITIAL;
this.pageWidth = this.viewport.width;
this.pageHeight = this.viewport.height;
@ -195,12 +196,15 @@ class PDFThumbnailView {
this.reset();
}
/**
* PLEASE NOTE: Most likely you want to use the `this.reset()` method,
* rather than calling this one directly.
*/
cancelRendering() {
if (this.renderTask) {
this.renderTask.cancel();
this.renderTask = null;
}
this.renderingState = RenderingStates.INITIAL;
this.resume = null;
}