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

@ -14,7 +14,7 @@
*/
import {
getVisibleElements, NullL10n, scrollIntoView, watchScroll
getVisibleElements, isValidRotation, NullL10n, scrollIntoView, watchScroll
} from './ui_utils';
import { PDFThumbnailView } from './pdf_thumbnail_view';
@ -95,12 +95,15 @@ class PDFThumbnailViewer {
}
set pagesRotation(rotation) {
if (!(typeof rotation === 'number' && rotation % 90 === 0)) {
if (!isValidRotation(rotation)) {
throw new Error('Invalid thumbnails rotation angle.');
}
if (!this.pdfDocument) {
return;
}
if (this._pagesRotation === rotation) {
return; // The rotation didn't change.
}
this._pagesRotation = rotation;
for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {