Only show the loadingIcon
-spinner on visible pages (issue 14242)
This patch preserves the old behaviour of appending a `loadingIcon`-div to all pages that are not yet loaded/rendered. However, the actual `loadingIcon`-spinner (i.e. the `loading-icon.gif` image) will only be displayed on *visible* pages to improve performance. To avoid having to iterate through all pages in the document, which doesn't seem like a good idea for a PDF document with thousands of pages, we use a combination of the currently visible *and* cached pages to toggle the `loadingIcon`-spinner.
This commit is contained in:
parent
e4f97a2a91
commit
e909fcdba8
@ -158,6 +158,10 @@ class PDFPageViewBuffer {
|
||||
return this.#buf.has(view);
|
||||
}
|
||||
|
||||
[Symbol.iterator]() {
|
||||
return this.#buf.keys();
|
||||
}
|
||||
|
||||
#destroyFirstView() {
|
||||
const firstView = this.#buf.keys().next().value;
|
||||
|
||||
@ -1402,6 +1406,23 @@ class BaseViewer {
|
||||
return this.scroll.down;
|
||||
}
|
||||
|
||||
/**
|
||||
* Only show the `loadingIcon`-spinner on visible pages (see issue 14242).
|
||||
*/
|
||||
#toggleLoadingIconSpinner(visibleIds) {
|
||||
for (const id of visibleIds) {
|
||||
const pageView = this._pages[id - 1];
|
||||
pageView?.toggleLoadingIconSpinner(/* viewVisible = */ true);
|
||||
}
|
||||
for (const pageView of this.#buffer) {
|
||||
if (visibleIds.has(pageView.id)) {
|
||||
// Handled above, since the "buffer" may not contain all visible pages.
|
||||
continue;
|
||||
}
|
||||
pageView.toggleLoadingIconSpinner(/* viewVisible = */ false);
|
||||
}
|
||||
}
|
||||
|
||||
forceRendering(currentlyVisiblePages) {
|
||||
const visiblePages = currentlyVisiblePages || this._getVisiblePages();
|
||||
const scrollAhead = this.#getScrollAhead(visiblePages);
|
||||
@ -1415,6 +1436,8 @@ class BaseViewer {
|
||||
scrollAhead,
|
||||
preRenderExtra
|
||||
);
|
||||
this.#toggleLoadingIconSpinner(visiblePages.ids);
|
||||
|
||||
if (pageView) {
|
||||
this._ensurePdfPageLoaded(pageView).then(() => {
|
||||
this.renderingQueue.renderView(pageView);
|
||||
|
@ -289,7 +289,10 @@ class PDFPageView {
|
||||
}
|
||||
|
||||
this.loadingIconDiv = document.createElement("div");
|
||||
this.loadingIconDiv.className = "loadingIcon";
|
||||
this.loadingIconDiv.className = "loadingIcon notVisible";
|
||||
if (this._isStandalone) {
|
||||
this.toggleLoadingIconSpinner(/* viewVisible = */ true);
|
||||
}
|
||||
this.loadingIconDiv.setAttribute("role", "img");
|
||||
this.l10n.get("loading").then(msg => {
|
||||
this.loadingIconDiv?.setAttribute("aria-label", msg);
|
||||
@ -523,6 +526,13 @@ class PDFPageView {
|
||||
return this.viewport.convertToPdfPoint(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
toggleLoadingIconSpinner(viewVisible = false) {
|
||||
this.loadingIconDiv?.classList.toggle("notVisible", !viewVisible);
|
||||
}
|
||||
|
||||
draw() {
|
||||
if (this.renderingState !== RenderingStates.INITIAL) {
|
||||
console.error("Must be in new state before drawing");
|
||||
|
@ -129,6 +129,9 @@
|
||||
bottom: 0;
|
||||
background: url("images/loading-icon.gif") center no-repeat;
|
||||
}
|
||||
.pdfViewer .page .loadingIcon.notVisible {
|
||||
background: none;
|
||||
}
|
||||
|
||||
.pdfPresentationMode .pdfViewer {
|
||||
margin-left: 0;
|
||||
|
Loading…
Reference in New Issue
Block a user