Slightly refactor the pages rotation handling code in the viewer

This changes both `PDFViewer` and `PDFThumbnailViewer` to return early in the `pagesRotation` setters if the rotation doesn't change.
It also fixes an existing issue, in `PDFViewer`, that would cause errors if the rotation changes *before* the scale has been set to a non-default value.

Finally, in preparation for subsequent patches, it also refactors the rotation code in `web/app.js` to update the thumbnails and trigger rendering with the new `rotationchanging` event.
This commit is contained in:
Jonas Jenwald 2017-08-19 14:23:40 +02:00
parent c8b5ba277a
commit 5565a6f8bf
5 changed files with 67 additions and 18 deletions

View file

@ -1232,16 +1232,10 @@ let PDFViewerApplication = {
if (!this.pdfDocument) {
return;
}
let { pdfViewer, pdfThumbnailViewer, } = this;
let pageNumber = pdfViewer.currentPageNumber;
let newRotation = (pdfViewer.pagesRotation + 360 + delta) % 360;
pdfViewer.pagesRotation = newRotation;
pdfThumbnailViewer.pagesRotation = newRotation;
this.forceRendering();
// Ensure that the active page doesn't change during rotation.
pdfViewer.currentPageNumber = pageNumber;
let newRotation = (this.pdfViewer.pagesRotation + 360 + delta) % 360;
this.pdfViewer.pagesRotation = newRotation;
// Note that the thumbnail viewer is updated, and rendering is triggered,
// in the 'rotationchanging' event handler.
},
requestPresentationMode() {
@ -1266,6 +1260,7 @@ let PDFViewerApplication = {
eventBus.on('updateviewarea', webViewerUpdateViewarea);
eventBus.on('pagechanging', webViewerPageChanging);
eventBus.on('scalechanging', webViewerScaleChanging);
eventBus.on('rotationchanging', webViewerRotationChanging);
eventBus.on('sidebarviewchanged', webViewerSidebarViewChanged);
eventBus.on('pagemode', webViewerPageMode);
eventBus.on('namedaction', webViewerNamedAction);
@ -1343,6 +1338,7 @@ let PDFViewerApplication = {
eventBus.off('updateviewarea', webViewerUpdateViewarea);
eventBus.off('pagechanging', webViewerPageChanging);
eventBus.off('scalechanging', webViewerScaleChanging);
eventBus.off('rotationchanging', webViewerRotationChanging);
eventBus.off('sidebarviewchanged', webViewerSidebarViewChanged);
eventBus.off('pagemode', webViewerPageMode);
eventBus.off('namedaction', webViewerNamedAction);
@ -1926,6 +1922,14 @@ function webViewerScaleChanging(evt) {
PDFViewerApplication.pdfViewer.update();
}
function webViewerRotationChanging(evt) {
PDFViewerApplication.pdfThumbnailViewer.pagesRotation = evt.pagesRotation;
PDFViewerApplication.forceRendering();
// Ensure that the active page doesn't change during rotation.
PDFViewerApplication.pdfViewer.currentPageNumber = evt.pageNumber;
}
function webViewerPageChanging(evt) {
let page = evt.pageNumber;