Merge pull request #7440 from Snuffleupagus/bug-874482
Prevent destinations with bad left/top values from scrolling the wrong page into view (bug 874482)
This commit is contained in:
commit
b0a0bef267
@ -1187,7 +1187,7 @@ var PDFViewerApplication = {
|
|||||||
|
|
||||||
this.forceRendering();
|
this.forceRendering();
|
||||||
|
|
||||||
this.pdfViewer.scrollPageIntoView(pageNumber);
|
this.pdfViewer.currentPageNumber = pageNumber;
|
||||||
},
|
},
|
||||||
|
|
||||||
requestPresentationMode: function pdfViewRequestPresentationMode() {
|
requestPresentationMode: function pdfViewRequestPresentationMode() {
|
||||||
|
@ -308,7 +308,7 @@ var PDFFindController = (function PDFFindControllerClosure() {
|
|||||||
// If the page is selected, scroll the page into view, which triggers
|
// If the page is selected, scroll the page into view, which triggers
|
||||||
// rendering the page, which adds the textLayer. Once the textLayer is
|
// rendering the page, which adds the textLayer. Once the textLayer is
|
||||||
// build, it will scroll onto the selected match.
|
// build, it will scroll onto the selected match.
|
||||||
this.pdfViewer.scrollPageIntoView(index + 1);
|
this.pdfViewer.currentPageNumber = index + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
var page = this.pdfViewer.getPageView(index);
|
var page = this.pdfViewer.getPageView(index);
|
||||||
|
@ -115,7 +115,10 @@ var PDFLinkService = (function PDFLinkServiceClosure() {
|
|||||||
'Trying to navigate to a non-existent page.');
|
'Trying to navigate to a non-existent page.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self.pdfViewer.scrollPageIntoView(pageNumber, dest);
|
self.pdfViewer.scrollPageIntoView({
|
||||||
|
pageNumber: pageNumber,
|
||||||
|
destArray: dest,
|
||||||
|
});
|
||||||
|
|
||||||
if (self.pdfHistory) {
|
if (self.pdfHistory) {
|
||||||
// Update the browsing history.
|
// Update the browsing history.
|
||||||
@ -241,7 +244,11 @@ var PDFLinkService = (function PDFLinkServiceClosure() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (dest) {
|
if (dest) {
|
||||||
this.pdfViewer.scrollPageIntoView(pageNumber || this.page, dest);
|
this.pdfViewer.scrollPageIntoView({
|
||||||
|
pageNumber: pageNumber || this.page,
|
||||||
|
destArray: dest,
|
||||||
|
allowNegativeOffset: true,
|
||||||
|
});
|
||||||
} else if (pageNumber) {
|
} else if (pageNumber) {
|
||||||
this.page = pageNumber; // simple page
|
this.page = pageNumber; // simple page
|
||||||
}
|
}
|
||||||
|
@ -458,7 +458,11 @@ var PDFViewer = (function pdfViewer() {
|
|||||||
dest = [null, { name: 'XYZ' }, this._location.left,
|
dest = [null, { name: 'XYZ' }, this._location.left,
|
||||||
this._location.top, null];
|
this._location.top, null];
|
||||||
}
|
}
|
||||||
this.scrollPageIntoView(page, dest);
|
this.scrollPageIntoView({
|
||||||
|
pageNumber: page,
|
||||||
|
destArray: dest,
|
||||||
|
allowNegativeOffset: true,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this._setScaleDispatchEvent(newScale, newValue, preset);
|
this._setScaleDispatchEvent(newScale, newValue, preset);
|
||||||
@ -531,16 +535,38 @@ var PDFViewer = (function pdfViewer() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scrolls page into view.
|
* @typedef ScrollPageIntoViewParameters
|
||||||
* @param {number} pageNumber
|
* @param {number} pageNumber - The page number.
|
||||||
* @param {Array} dest - (optional) original PDF destination array:
|
* @param {Array} destArray - (optional) The original PDF destination array,
|
||||||
* <page-ref> </XYZ|FitXXX> <args..>
|
* in the format: <page-ref> </XYZ|/FitXXX> <args..>
|
||||||
|
* @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) {
|
if (!this.pdfDocument) {
|
||||||
return;
|
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) {
|
if (this.isInPresentationMode || !dest) {
|
||||||
this._setCurrentPageNumber(pageNumber, /* resetCurrentPageView */ true);
|
this._setCurrentPageNumber(pageNumber, /* resetCurrentPageView */ true);
|
||||||
@ -548,6 +574,11 @@ var PDFViewer = (function pdfViewer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var pageView = this._pages[pageNumber - 1];
|
var pageView = this._pages[pageNumber - 1];
|
||||||
|
if (!pageView) {
|
||||||
|
console.error('PDFViewer_scrollPageIntoView: ' +
|
||||||
|
'Invalid "pageNumber" parameter.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
var x = 0, y = 0;
|
var x = 0, y = 0;
|
||||||
var width = 0, height = 0, widthScale, heightScale;
|
var width = 0, height = 0, widthScale, heightScale;
|
||||||
var changeOrientation = (pageView.rotation % 180 === 0 ? false : true);
|
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 left = Math.min(boundingRect[0][0], boundingRect[1][0]);
|
||||||
var top = Math.min(boundingRect[0][1], boundingRect[1][1]);
|
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 });
|
scrollIntoView(pageView.div, { left: left, top: top });
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user