From 550538df72f9b4c9b533cb4ec4fb64b2f1553246 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 21 Jun 2018 21:45:03 +0200 Subject: [PATCH] [Regression] Ensure that pre-rendering of the next/previous page works correctly in Presentation Mode, when horizontal scrolling was enabled Note how in `BaseViewer.forceRendering` the Scroll mode is used to determine how pre-rendering will work. Currently this is broken in Presentation Mode, if horizontal scrolling was enabled prior to entering fullscreen. Furthermore, there's a few additional cases where the `this.scrollMode === ScrollMode.HORIZONTAL` check is pointless either in Presentation Mode or when a `PDFSinglePageViewer` instance is used. --- web/base_viewer.js | 18 +++++++++++------- web/pdf_single_page_viewer.js | 5 +++++ web/pdf_viewer.js | 9 ++++++++- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/web/base_viewer.js b/web/base_viewer.js index d259ef4d38b3d1..79c65c9d41205e 100644 --- a/web/base_viewer.js +++ b/web/base_viewer.js @@ -597,11 +597,11 @@ class BaseViewer { if (!currentPage) { return; } - let hPadding = (this.isInPresentationMode || this.removePageBorders) ? - 0 : SCROLLBAR_PADDING; - let vPadding = (this.isInPresentationMode || this.removePageBorders) ? - 0 : VERTICAL_PADDING; - if (this.scrollMode === ScrollMode.HORIZONTAL) { + const noPadding = (this.isInPresentationMode || this.removePageBorders); + let hPadding = noPadding ? 0 : SCROLLBAR_PADDING; + let vPadding = noPadding ? 0 : VERTICAL_PADDING; + + if (!noPadding && this._isScrollModeHorizontal) { const temp = hPadding; hPadding = vPadding; vPadding = temp; @@ -834,6 +834,10 @@ class BaseViewer { this.container.focus(); } + get _isScrollModeHorizontal() { + throw new Error('Not implemented: _isScrollModeHorizontal'); + } + get isInPresentationMode() { return this.presentationModeState === PresentationModeState.FULLSCREEN; } @@ -906,8 +910,8 @@ class BaseViewer { forceRendering(currentlyVisiblePages) { let visiblePages = currentlyVisiblePages || this._getVisiblePages(); - let scrollAhead = this.scrollMode === ScrollMode.HORIZONTAL ? - this.scroll.right : this.scroll.down; + let scrollAhead = (this._isScrollModeHorizontal ? + this.scroll.right : this.scroll.down); let pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, scrollAhead); diff --git a/web/pdf_single_page_viewer.js b/web/pdf_single_page_viewer.js index 94fb7823e3d57c..4a446f457e6206 100644 --- a/web/pdf_single_page_viewer.js +++ b/web/pdf_single_page_viewer.js @@ -142,6 +142,11 @@ class PDFSinglePageViewer extends BaseViewer { location: this._location, }); } + + get _isScrollModeHorizontal() { + // The Scroll/Spread modes are never used in `PDFSinglePageViewer`. + return shadow(this, '_isScrollModeHorizontal', false); + } } export { diff --git a/web/pdf_viewer.js b/web/pdf_viewer.js index 10d11a4c620329..78a2ce3a506fba 100644 --- a/web/pdf_viewer.js +++ b/web/pdf_viewer.js @@ -23,7 +23,7 @@ class PDFViewer extends BaseViewer { } _scrollIntoView({ pageDiv, pageSpot = null, }) { - if (!pageSpot) { + if (!pageSpot && !this.isInPresentationMode) { const left = pageDiv.offsetLeft + pageDiv.clientLeft; const right = left + pageDiv.clientWidth; const { scrollLeft, clientWidth, } = this.container; @@ -87,6 +87,13 @@ class PDFViewer extends BaseViewer { }); } + get _isScrollModeHorizontal() { + // Used to ensure that pre-rendering of the next/previous page works + // correctly, since Scroll/Spread modes are ignored in Presentation Mode. + return (this.isInPresentationMode ? + false : this.scrollMode === ScrollMode.HORIZONTAL); + } + setScrollMode(mode) { if (mode === this.scrollMode) { return;