For documents with different page sizes, ensure that the correct page becomes visible on load when e.g. the 'page' hash parameter was provided (bug 1191279, issue 6393)

This issue is actually, in a sense, "caused" by the fact that the API/viewer supports partial loading/rendering. Previously when the *entire* document was always fetched before rendering begun, we knew all page sizes in advance and this issue didn't exist.

Now we use the size of *one* page in order to set the initial size of every page, until we've fetched the pages and thus know their correct sizes.
This means that during loading the size of the pages can change, which may cause the initial position to become scrolled out of view.

The most naive solution to this problem would perhaps be to delay setting the initial position on load for all documents, until all pages are fetched. However I think that would be a *really* bad idea, since doing so would make the initial rendering slower and make it feel sluggish for most documents.

Since there is generally no way of knowing if a document has different sized pages prior to loading it, we can only check once the pages are available.
Hence this patch, which treats documents with different sized pages as a special case, by re-applying the initial position when all pages have become available.
This commit is contained in:
Jonas Jenwald 2015-08-05 17:35:41 +02:00
parent 238e16feeb
commit 59548921d1

View File

@ -790,6 +790,12 @@ var PDFViewerApplication = {
}
}
var initialParams = {
destination: self.initialDestination,
bookmark: self.initialBookmark,
hash: null,
};
store.initializedPromise.then(function resolved() {
var storedHash = null;
if (self.preferenceShowPreviousViewOnLoad &&
@ -807,6 +813,8 @@ var PDFViewerApplication = {
}
self.setInitialView(storedHash, scale);
initialParams.hash = storedHash;
// Make all navigation keys work on document load,
// unless the viewer is embedded in a web page.
if (!self.isViewerEmbedded) {
@ -816,6 +824,23 @@ var PDFViewerApplication = {
console.error(reason);
self.setInitialView(null, scale);
});
// For documents with different page sizes,
// ensure that the correct location becomes visible on load.
pagesPromise.then(function resolved() {
if (!initialParams.destination && !initialParams.bookmark &&
!initialParams.hash) {
return;
}
if (self.hasEqualPageSizes) {
return;
}
self.initialDestination = initialParams.destination;
self.initialBookmark = initialParams.bookmark;
self.pdfViewer.currentScaleValue = self.pdfViewer.currentScaleValue;
self.setInitialView(initialParams.hash, scale);
});
});
pagesPromise.then(function() {