Merge pull request #15867 from Snuffleupagus/loadingIcon-toggle
Only display the loadingIcons when rendering is currently running
This commit is contained in:
commit
35ca6ab319
31
web/app.js
31
web/app.js
@ -1804,6 +1804,7 @@ const PDFViewerApplication = {
|
|||||||
eventBus._on("hashchange", webViewerHashchange);
|
eventBus._on("hashchange", webViewerHashchange);
|
||||||
eventBus._on("beforeprint", _boundEvents.beforePrint);
|
eventBus._on("beforeprint", _boundEvents.beforePrint);
|
||||||
eventBus._on("afterprint", _boundEvents.afterPrint);
|
eventBus._on("afterprint", _boundEvents.afterPrint);
|
||||||
|
eventBus._on("pagerender", webViewerPageRender);
|
||||||
eventBus._on("pagerendered", webViewerPageRendered);
|
eventBus._on("pagerendered", webViewerPageRendered);
|
||||||
eventBus._on("updateviewarea", webViewerUpdateViewarea);
|
eventBus._on("updateviewarea", webViewerUpdateViewarea);
|
||||||
eventBus._on("pagechanging", webViewerPageChanging);
|
eventBus._on("pagechanging", webViewerPageChanging);
|
||||||
@ -1936,6 +1937,7 @@ const PDFViewerApplication = {
|
|||||||
eventBus._off("hashchange", webViewerHashchange);
|
eventBus._off("hashchange", webViewerHashchange);
|
||||||
eventBus._off("beforeprint", _boundEvents.beforePrint);
|
eventBus._off("beforeprint", _boundEvents.beforePrint);
|
||||||
eventBus._off("afterprint", _boundEvents.afterPrint);
|
eventBus._off("afterprint", _boundEvents.afterPrint);
|
||||||
|
eventBus._off("pagerender", webViewerPageRender);
|
||||||
eventBus._off("pagerendered", webViewerPageRendered);
|
eventBus._off("pagerendered", webViewerPageRendered);
|
||||||
eventBus._off("updateviewarea", webViewerUpdateViewarea);
|
eventBus._off("updateviewarea", webViewerUpdateViewarea);
|
||||||
eventBus._off("pagechanging", webViewerPageChanging);
|
eventBus._off("pagechanging", webViewerPageChanging);
|
||||||
@ -2212,6 +2214,14 @@ function webViewerInitialized() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function webViewerPageRender({ pageNumber }) {
|
||||||
|
// If the page is (the most) visible when it starts rendering,
|
||||||
|
// ensure that the page number input loading indicator is displayed.
|
||||||
|
if (pageNumber === PDFViewerApplication.page) {
|
||||||
|
PDFViewerApplication.toolbar?.updateLoadingIndicatorState(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function webViewerPageRendered({ pageNumber, error }) {
|
function webViewerPageRendered({ pageNumber, error }) {
|
||||||
// If the page is still visible when it has finished rendering,
|
// If the page is still visible when it has finished rendering,
|
||||||
// ensure that the page number input loading indicator is hidden.
|
// ensure that the page number input loading indicator is hidden.
|
||||||
@ -2321,20 +2331,13 @@ function webViewerUpdateViewarea({ location }) {
|
|||||||
// Unable to write to storage.
|
// Unable to write to storage.
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const href = PDFViewerApplication.pdfLinkService.getAnchorUrl(
|
|
||||||
location.pdfOpenParams
|
|
||||||
);
|
|
||||||
if (PDFViewerApplication.appConfig.secondaryToolbar) {
|
if (PDFViewerApplication.appConfig.secondaryToolbar) {
|
||||||
|
const href = PDFViewerApplication.pdfLinkService.getAnchorUrl(
|
||||||
|
location.pdfOpenParams
|
||||||
|
);
|
||||||
PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href =
|
PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href =
|
||||||
href;
|
href;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show/hide the loading indicator in the page number input element.
|
|
||||||
const currentPage = PDFViewerApplication.pdfViewer.getPageView(
|
|
||||||
/* index = */ PDFViewerApplication.page - 1
|
|
||||||
);
|
|
||||||
const loading = currentPage?.renderingState !== RenderingStates.FINISHED;
|
|
||||||
PDFViewerApplication.toolbar?.updateLoadingIndicatorState(loading);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function webViewerScrollModeChanged(evt) {
|
function webViewerScrollModeChanged(evt) {
|
||||||
@ -2565,6 +2568,14 @@ function webViewerPageChanging({ pageNumber, pageLabel }) {
|
|||||||
pageNumber
|
pageNumber
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Show/hide the loading indicator in the page number input element.
|
||||||
|
const currentPage = PDFViewerApplication.pdfViewer.getPageView(
|
||||||
|
/* index = */ pageNumber - 1
|
||||||
|
);
|
||||||
|
PDFViewerApplication.toolbar?.updateLoadingIndicatorState(
|
||||||
|
currentPage?.renderingState === RenderingStates.RUNNING
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function webViewerResolutionChange(evt) {
|
function webViewerResolutionChange(evt) {
|
||||||
|
@ -120,6 +120,8 @@ class PDFPageView {
|
|||||||
|
|
||||||
#previousRotation = null;
|
#previousRotation = null;
|
||||||
|
|
||||||
|
#renderingState = RenderingStates.INITIAL;
|
||||||
|
|
||||||
#useThumbnailCanvas = {
|
#useThumbnailCanvas = {
|
||||||
initialOptionalContent: true,
|
initialOptionalContent: true,
|
||||||
regularAnnotations: true,
|
regularAnnotations: true,
|
||||||
@ -167,7 +169,6 @@ class PDFPageView {
|
|||||||
|
|
||||||
this.paintTask = null;
|
this.paintTask = null;
|
||||||
this.paintedViewportMap = new WeakMap();
|
this.paintedViewportMap = new WeakMap();
|
||||||
this.renderingState = RenderingStates.INITIAL;
|
|
||||||
this.resume = null;
|
this.resume = null;
|
||||||
this._renderError = null;
|
this._renderError = null;
|
||||||
if (
|
if (
|
||||||
@ -227,6 +228,30 @@ class PDFPageView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get renderingState() {
|
||||||
|
return this.#renderingState;
|
||||||
|
}
|
||||||
|
|
||||||
|
set renderingState(state) {
|
||||||
|
this.#renderingState = state;
|
||||||
|
|
||||||
|
switch (state) {
|
||||||
|
case RenderingStates.INITIAL:
|
||||||
|
case RenderingStates.PAUSED:
|
||||||
|
this.loadingIconDiv?.classList.add("notVisible");
|
||||||
|
break;
|
||||||
|
case RenderingStates.RUNNING:
|
||||||
|
this.loadingIconDiv?.classList.remove("notVisible");
|
||||||
|
break;
|
||||||
|
case RenderingStates.FINISHED:
|
||||||
|
if (this.loadingIconDiv) {
|
||||||
|
this.loadingIconDiv.remove();
|
||||||
|
delete this.loadingIconDiv;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#setDimensions() {
|
#setDimensions() {
|
||||||
const { viewport } = this;
|
const { viewport } = this;
|
||||||
if (this.pdfPage) {
|
if (this.pdfPage) {
|
||||||
@ -496,17 +521,6 @@ class PDFPageView {
|
|||||||
this.loadingIconDiv?.setAttribute("aria-label", msg);
|
this.loadingIconDiv?.setAttribute("aria-label", msg);
|
||||||
});
|
});
|
||||||
div.append(this.loadingIconDiv);
|
div.append(this.loadingIconDiv);
|
||||||
} else {
|
|
||||||
this.toggleLoadingIconSpinner();
|
|
||||||
div.append(this.loadingIconDiv);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
(typeof PDFJSDev === "undefined" ||
|
|
||||||
PDFJSDev.test("!PRODUCTION || GENERIC")) &&
|
|
||||||
this._isStandalone
|
|
||||||
) {
|
|
||||||
this.toggleLoadingIconSpinner(/* viewVisible = */ true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -775,13 +789,6 @@ class PDFPageView {
|
|||||||
return this.viewport.convertToPdfPoint(x, y);
|
return this.viewport.convertToPdfPoint(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @ignore
|
|
||||||
*/
|
|
||||||
toggleLoadingIconSpinner(viewVisible = false) {
|
|
||||||
this.loadingIconDiv?.classList.toggle("notVisible", !viewVisible);
|
|
||||||
}
|
|
||||||
|
|
||||||
draw() {
|
draw() {
|
||||||
if (this.renderingState !== RenderingStates.INITIAL) {
|
if (this.renderingState !== RenderingStates.INITIAL) {
|
||||||
console.error("Must be in new state before drawing");
|
console.error("Must be in new state before drawing");
|
||||||
@ -791,11 +798,6 @@ class PDFPageView {
|
|||||||
|
|
||||||
if (!pdfPage) {
|
if (!pdfPage) {
|
||||||
this.renderingState = RenderingStates.FINISHED;
|
this.renderingState = RenderingStates.FINISHED;
|
||||||
|
|
||||||
if (this.loadingIconDiv) {
|
|
||||||
this.loadingIconDiv.remove();
|
|
||||||
delete this.loadingIconDiv;
|
|
||||||
}
|
|
||||||
return Promise.reject(new Error("pdfPage is not loaded"));
|
return Promise.reject(new Error("pdfPage is not loaded"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -888,11 +890,6 @@ class PDFPageView {
|
|||||||
this._renderError = error;
|
this._renderError = error;
|
||||||
|
|
||||||
this.renderingState = RenderingStates.FINISHED;
|
this.renderingState = RenderingStates.FINISHED;
|
||||||
|
|
||||||
if (this.loadingIconDiv) {
|
|
||||||
this.loadingIconDiv.remove();
|
|
||||||
delete this.loadingIconDiv;
|
|
||||||
}
|
|
||||||
this._resetZoomLayer(/* removeFromDOM = */ true);
|
this._resetZoomLayer(/* removeFromDOM = */ true);
|
||||||
|
|
||||||
// Ensure that the thumbnails won't become partially (or fully) blank,
|
// Ensure that the thumbnails won't become partially (or fully) blank,
|
||||||
|
@ -1626,23 +1626,6 @@ class PDFViewer {
|
|||||||
return this.scroll.down;
|
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) {
|
forceRendering(currentlyVisiblePages) {
|
||||||
const visiblePages = currentlyVisiblePages || this._getVisiblePages();
|
const visiblePages = currentlyVisiblePages || this._getVisiblePages();
|
||||||
const scrollAhead = this.#getScrollAhead(visiblePages);
|
const scrollAhead = this.#getScrollAhead(visiblePages);
|
||||||
@ -1656,7 +1639,6 @@ class PDFViewer {
|
|||||||
scrollAhead,
|
scrollAhead,
|
||||||
preRenderExtra
|
preRenderExtra
|
||||||
);
|
);
|
||||||
this.#toggleLoadingIconSpinner(visiblePages.ids);
|
|
||||||
|
|
||||||
if (pageView) {
|
if (pageView) {
|
||||||
this.#ensurePdfPageLoaded(pageView).then(() => {
|
this.#ensurePdfPageLoaded(pageView).then(() => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user