diff --git a/web/app.js b/web/app.js index f44783022..accfb1e99 100644 --- a/web/app.js +++ b/web/app.js @@ -1187,7 +1187,7 @@ var PDFViewerApplication = { this.forceRendering(); - this.pdfViewer.scrollPageIntoView(pageNumber); + this.pdfViewer.currentPageNumber = pageNumber; }, requestPresentationMode: function pdfViewRequestPresentationMode() { diff --git a/web/pdf_find_controller.js b/web/pdf_find_controller.js index bfe8027c5..2ee51e6b2 100644 --- a/web/pdf_find_controller.js +++ b/web/pdf_find_controller.js @@ -308,7 +308,7 @@ var PDFFindController = (function PDFFindControllerClosure() { // If the page is selected, scroll the page into view, which triggers // rendering the page, which adds the textLayer. Once the textLayer is // build, it will scroll onto the selected match. - this.pdfViewer.scrollPageIntoView(index + 1); + this.pdfViewer.currentPageNumber = index + 1; } var page = this.pdfViewer.getPageView(index); diff --git a/web/pdf_link_service.js b/web/pdf_link_service.js index 8263bc1a2..045913a56 100644 --- a/web/pdf_link_service.js +++ b/web/pdf_link_service.js @@ -115,7 +115,10 @@ var PDFLinkService = (function PDFLinkServiceClosure() { 'Trying to navigate to a non-existent page.'); return; } - self.pdfViewer.scrollPageIntoView(pageNumber, dest); + self.pdfViewer.scrollPageIntoView({ + pageNumber: pageNumber, + destArray: dest, + }); if (self.pdfHistory) { // Update the browsing history. @@ -241,7 +244,11 @@ var PDFLinkService = (function PDFLinkServiceClosure() { } } if (dest) { - this.pdfViewer.scrollPageIntoView(pageNumber || this.page, dest); + this.pdfViewer.scrollPageIntoView({ + pageNumber: pageNumber || this.page, + destArray: dest, + allowNegativeOffset: true, + }); } else if (pageNumber) { this.page = pageNumber; // simple page } diff --git a/web/pdf_viewer.js b/web/pdf_viewer.js index 1d70f6e5f..8f3df5189 100644 --- a/web/pdf_viewer.js +++ b/web/pdf_viewer.js @@ -458,7 +458,11 @@ var PDFViewer = (function pdfViewer() { dest = [null, { name: 'XYZ' }, this._location.left, this._location.top, null]; } - this.scrollPageIntoView(page, dest); + this.scrollPageIntoView({ + pageNumber: page, + destArray: dest, + allowNegativeOffset: true, + }); } this._setScaleDispatchEvent(newScale, newValue, preset); @@ -531,16 +535,38 @@ var PDFViewer = (function pdfViewer() { }, /** - * Scrolls page into view. - * @param {number} pageNumber - * @param {Array} dest - (optional) original PDF destination array: - * + * @typedef ScrollPageIntoViewParameters + * @param {number} pageNumber - The page number. + * @param {Array} destArray - (optional) The original PDF destination array, + * in the format: + * @param {boolean} allowNegativeOffset - (optional) Allow negative page + * offsets. The default value is `false`. */ - scrollPageIntoView: function PDFViewer_scrollPageIntoView(pageNumber, - dest) { + + /** + * Scrolls page into view. + * @param {ScrollPageIntoViewParameters} params + */ + scrollPageIntoView: function PDFViewer_scrollPageIntoView(params) { if (!this.pdfDocument) { return; } +//#if GENERIC + if (arguments.length > 1 || typeof params === 'number') { + console.warn('Call of scrollPageIntoView() with obsolete signature.'); + var paramObj = {}; + if (typeof params === 'number') { + paramObj.pageNumber = params; // pageNumber argument was found. + } + if (arguments[1] instanceof Array) { + paramObj.destArray = arguments[1]; // destArray argument was found. + } + params = paramObj; + } +//#endif + var pageNumber = params.pageNumber || 0; + var dest = params.destArray || null; + var allowNegativeOffset = params.allowNegativeOffset || false; if (this.isInPresentationMode || !dest) { this._setCurrentPageNumber(pageNumber, /* resetCurrentPageView */ true); @@ -548,6 +574,11 @@ var PDFViewer = (function pdfViewer() { } var pageView = this._pages[pageNumber - 1]; + if (!pageView) { + console.error('PDFViewer_scrollPageIntoView: ' + + 'Invalid "pageNumber" parameter.'); + return; + } var x = 0, y = 0; var width = 0, height = 0, widthScale, heightScale; var changeOrientation = (pageView.rotation % 180 === 0 ? false : true); @@ -628,6 +659,13 @@ var PDFViewer = (function pdfViewer() { var left = Math.min(boundingRect[0][0], boundingRect[1][0]); var top = Math.min(boundingRect[0][1], boundingRect[1][1]); + if (!allowNegativeOffset) { + // Some bad PDF generators will create destinations with e.g. top values + // that exceeds the page height. Ensure that offsets are not negative, + // to prevent a previous page from becoming visible (fixes bug 874482). + left = Math.max(left, 0); + top = Math.max(top, 0); + } scrollIntoView(pageView.div, { left: left, top: top }); },