Unblock the "load" event in inactive windows/tabs (bug 1746213, PR 11646 follow-up)

Given that `requestAnimationFrame` is being used, see the `src/diplay/api.js` file, an inactive window/tab means that rendering will not run and we'll thus not fetch all pages. The latter is a requirement for the "load" event to be unblocked, in the MOZCENTRAL-version of, the default viewer.

This patch is a *partial* solution, since it only addresses the following situations:
 - A *background*  tab (containing the viewer) is reloaded, e.g. via the tab-bar context menu.
 - The viewer is loaded in a active tab, but the user switches away from it (or switches to another program window) *before* rendering has started.
This commit is contained in:
Jonas Jenwald 2021-12-18 19:04:38 +01:00
parent a2ae56f394
commit 472bbf4592

View File

@ -533,11 +533,14 @@ class BaseViewer {
// `this._onePageRenderedCapability` thus won't be resolved. // `this._onePageRenderedCapability` thus won't be resolved.
// To ensure that automatic printing, on document load, still works even in // To ensure that automatic printing, on document load, still works even in
// those cases we force-allow fetching of all pages when: // those cases we force-allow fetching of all pages when:
// - The current window/tab is inactive, which will prevent rendering since
// `requestAnimationFrame` is being used; fixes bug 1746213.
// - The viewer is hidden in the DOM, e.g. in a `display: none` <iframe> // - The viewer is hidden in the DOM, e.g. in a `display: none` <iframe>
// element; fixes bug 1618621. // element; fixes bug 1618621.
// - The viewer is visible, but none of the pages are (e.g. if the // - The viewer is visible, but none of the pages are (e.g. if the
// viewer is very small); fixes bug 1618955. // viewer is very small); fixes bug 1618955.
if ( if (
document.visibilityState === "hidden" ||
!this.container.offsetParent || !this.container.offsetParent ||
this._getVisiblePages().views.length === 0 this._getVisiblePages().views.length === 0
) { ) {