Ensure that automatic printing still works when the viewer and/or its pages are hidden (bug 1618621, bug 1618955)
Please note that this patch, on its own, won't magically fix all of these printing bugs without [bug 1618553](https://bugzilla.mozilla.org/show_bug.cgi?id=1618553) also being fixed. (However I don't foresee that being too difficult, famous last words :-), but it will as suggested require a platform API that we can notify when the viewer is ready.) Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1618621 Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1618955 Fixes 8208
This commit is contained in:
		
							parent
							
								
									85838fc505
								
							
						
					
					
						commit
						c5b0b5c754
					
				@ -396,6 +396,27 @@ class BaseViewer {
 | 
			
		||||
    throw new Error("Not implemented: _setDocumentViewerElement");
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * @private
 | 
			
		||||
   */
 | 
			
		||||
  _onePageRenderedOrForceFetch() {
 | 
			
		||||
    // Unless the viewer *and* its pages are visible, rendering won't start and
 | 
			
		||||
    // `this._onePageRenderedCapability` thus won't be resolved.
 | 
			
		||||
    // To ensure that automatic printing, on document load, still works even in
 | 
			
		||||
    // those cases we force-allow fetching of all pages when:
 | 
			
		||||
    //  - The viewer is hidden in the DOM, e.g. in a `display: none` <iframe>
 | 
			
		||||
    //    element; fixes bug 1618621.
 | 
			
		||||
    //  - The viewer is visible, but none of the pages are (e.g. if the
 | 
			
		||||
    //    viewer is very small); fixes bug 1618955.
 | 
			
		||||
    if (
 | 
			
		||||
      !this.container.offsetParent ||
 | 
			
		||||
      this._getVisiblePages().views.length === 0
 | 
			
		||||
    ) {
 | 
			
		||||
      return Promise.resolve();
 | 
			
		||||
    }
 | 
			
		||||
    return this._onePageRenderedCapability.promise;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * @param pdfDocument {PDFDocument}
 | 
			
		||||
   */
 | 
			
		||||
@ -492,7 +513,7 @@ class BaseViewer {
 | 
			
		||||
        // Fetch all the pages since the viewport is needed before printing
 | 
			
		||||
        // starts to create the correct size canvas. Wait until one page is
 | 
			
		||||
        // rendered so we don't tie up too many resources early on.
 | 
			
		||||
        this._onePageRenderedCapability.promise.then(() => {
 | 
			
		||||
        this._onePageRenderedOrForceFetch().then(() => {
 | 
			
		||||
          if (this.findController) {
 | 
			
		||||
            this.findController.setDocument(pdfDocument); // Enable searching.
 | 
			
		||||
          }
 | 
			
		||||
 | 
			
		||||
@ -229,7 +229,7 @@ function binarySearchFirstItem(items, condition) {
 | 
			
		||||
  let minIndex = 0;
 | 
			
		||||
  let maxIndex = items.length - 1;
 | 
			
		||||
 | 
			
		||||
  if (items.length === 0 || !condition(items[maxIndex])) {
 | 
			
		||||
  if (maxIndex < 0 || !condition(items[maxIndex])) {
 | 
			
		||||
    return items.length;
 | 
			
		||||
  }
 | 
			
		||||
  if (condition(items[minIndex])) {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user