Merge pull request #11646 from Snuffleupagus/_setDocumentAllowFetchPages
Ensure that automatic printing still works when the viewer and/or its pages are hidden (bug 1618621, bug 1618955)
This commit is contained in:
commit
8745286dc1
@ -391,9 +391,30 @@ class BaseViewer {
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
get _setDocumentViewerElement() {
|
||||
get _viewerElement() {
|
||||
// In most viewers, e.g. `PDFViewer`, this should return `this.viewer`.
|
||||
throw new Error("Not implemented: _setDocumentViewerElement");
|
||||
throw new Error("Not implemented: _viewerElement");
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -458,7 +479,7 @@ class BaseViewer {
|
||||
|
||||
for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
|
||||
const pageView = new PDFPageView({
|
||||
container: this._setDocumentViewerElement,
|
||||
container: this._viewerElement,
|
||||
eventBus: this.eventBus,
|
||||
id: pageNum,
|
||||
scale,
|
||||
@ -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.
|
||||
}
|
||||
|
@ -27,12 +27,12 @@ class PDFSinglePageViewer extends BaseViewer {
|
||||
});
|
||||
}
|
||||
|
||||
get _setDocumentViewerElement() {
|
||||
get _viewerElement() {
|
||||
// Since we only want to display *one* page at a time when using the
|
||||
// `PDFSinglePageViewer`, we cannot append them to the `viewer` DOM element.
|
||||
// Instead, they are placed in a `DocumentFragment`, and only the current
|
||||
// page is displayed in the viewer (refer to `this._ensurePageViewVisible`).
|
||||
return shadow(this, "_setDocumentViewerElement", this._shadowViewer);
|
||||
return shadow(this, "_viewerElement", this._shadowViewer);
|
||||
}
|
||||
|
||||
_resetView() {
|
||||
|
@ -17,8 +17,8 @@ import { BaseViewer } from "./base_viewer.js";
|
||||
import { shadow } from "pdfjs-lib";
|
||||
|
||||
class PDFViewer extends BaseViewer {
|
||||
get _setDocumentViewerElement() {
|
||||
return shadow(this, "_setDocumentViewerElement", this.viewer);
|
||||
get _viewerElement() {
|
||||
return shadow(this, "_viewerElement", this.viewer);
|
||||
}
|
||||
|
||||
_scrollIntoView({ pageDiv, pageSpot = null, pageNumber = null }) {
|
||||
|
@ -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…
Reference in New Issue
Block a user