Merge pull request #8210 from Snuffleupagus/issue-8209
Refactor removing of the `zoomLayer` into a helper method, and use that in `PDFPageView.reset` to ensure that the entire `zoomLayer` is actually removed (issue 8209)
This commit is contained in:
		
						commit
						57d9a64c14
					
				@ -133,13 +133,33 @@ var PDFPageView = (function PDFPageViewClosure() {
 | 
				
			|||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    destroy: function PDFPageView_destroy() {
 | 
					    destroy: function PDFPageView_destroy() {
 | 
				
			||||||
      this.zoomLayer = null;
 | 
					 | 
				
			||||||
      this.reset();
 | 
					      this.reset();
 | 
				
			||||||
      if (this.pdfPage) {
 | 
					      if (this.pdfPage) {
 | 
				
			||||||
        this.pdfPage.cleanup();
 | 
					        this.pdfPage.cleanup();
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * @private
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    _resetZoomLayer: function(removeFromDOM) {
 | 
				
			||||||
 | 
					      if (!this.zoomLayer) {
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      var zoomLayerCanvas = this.zoomLayer.firstChild;
 | 
				
			||||||
 | 
					      this.paintedViewportMap.delete(zoomLayerCanvas);
 | 
				
			||||||
 | 
					      // Zeroing the width and height causes Firefox to release graphics
 | 
				
			||||||
 | 
					      // resources immediately, which can greatly reduce memory consumption.
 | 
				
			||||||
 | 
					      zoomLayerCanvas.width = 0;
 | 
				
			||||||
 | 
					      zoomLayerCanvas.height = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if (removeFromDOM) {
 | 
				
			||||||
 | 
					        // Note: ChildNode.remove doesn't throw if the parentNode is undefined.
 | 
				
			||||||
 | 
					        this.zoomLayer.remove();
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      this.zoomLayer = null;
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    reset: function PDFPageView_reset(keepZoomLayer, keepAnnotations) {
 | 
					    reset: function PDFPageView_reset(keepZoomLayer, keepAnnotations) {
 | 
				
			||||||
      this.cancelRendering();
 | 
					      this.cancelRendering();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -168,7 +188,8 @@ var PDFPageView = (function PDFPageViewClosure() {
 | 
				
			|||||||
        this.annotationLayer = null;
 | 
					        this.annotationLayer = null;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if (this.canvas && !currentZoomLayerNode) {
 | 
					      if (!currentZoomLayerNode) {
 | 
				
			||||||
 | 
					        if (this.canvas) {
 | 
				
			||||||
          this.paintedViewportMap.delete(this.canvas);
 | 
					          this.paintedViewportMap.delete(this.canvas);
 | 
				
			||||||
          // Zeroing the width and height causes Firefox to release graphics
 | 
					          // Zeroing the width and height causes Firefox to release graphics
 | 
				
			||||||
          // resources immediately, which can greatly reduce memory consumption.
 | 
					          // resources immediately, which can greatly reduce memory consumption.
 | 
				
			||||||
@ -176,6 +197,8 @@ var PDFPageView = (function PDFPageViewClosure() {
 | 
				
			|||||||
          this.canvas.height = 0;
 | 
					          this.canvas.height = 0;
 | 
				
			||||||
          delete this.canvas;
 | 
					          delete this.canvas;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        this._resetZoomLayer();
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
      if (this.svg) {
 | 
					      if (this.svg) {
 | 
				
			||||||
        this.paintedViewportMap.delete(this.svg);
 | 
					        this.paintedViewportMap.delete(this.svg);
 | 
				
			||||||
        delete this.svg;
 | 
					        delete this.svg;
 | 
				
			||||||
@ -429,23 +452,7 @@ var PDFPageView = (function PDFPageViewClosure() {
 | 
				
			|||||||
          div.removeChild(self.loadingIconDiv);
 | 
					          div.removeChild(self.loadingIconDiv);
 | 
				
			||||||
          delete self.loadingIconDiv;
 | 
					          delete self.loadingIconDiv;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        self._resetZoomLayer(/* removeFromDOM = */ true);
 | 
				
			||||||
        if (self.zoomLayer) {
 | 
					 | 
				
			||||||
          var zoomLayerCanvas = self.zoomLayer.firstChild;
 | 
					 | 
				
			||||||
          self.paintedViewportMap.delete(zoomLayerCanvas);
 | 
					 | 
				
			||||||
          // Zeroing the width and height causes Firefox to release graphics
 | 
					 | 
				
			||||||
          // resources immediately, which can greatly reduce memory consumption.
 | 
					 | 
				
			||||||
          zoomLayerCanvas.width = 0;
 | 
					 | 
				
			||||||
          zoomLayerCanvas.height = 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
          if (div.contains(self.zoomLayer)) {
 | 
					 | 
				
			||||||
            // Prevent "Node was not found" errors if the `zoomLayer` was
 | 
					 | 
				
			||||||
            // already removed. This may occur intermittently if the scale
 | 
					 | 
				
			||||||
            // changes many times in very quick succession.
 | 
					 | 
				
			||||||
            div.removeChild(self.zoomLayer);
 | 
					 | 
				
			||||||
          }
 | 
					 | 
				
			||||||
          self.zoomLayer = null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.error = error;
 | 
					        self.error = error;
 | 
				
			||||||
        self.stats = pdfPage.stats;
 | 
					        self.stats = pdfPage.stats;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user