mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
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:
parent
c8b5ba277a
commit
5565a6f8bf
5 changed files with 67 additions and 18 deletions
|
@ -14,8 +14,8 @@
|
|||
*/
|
||||
|
||||
import {
|
||||
binarySearchFirstItem, EventBus, getPDFFileNameFromURL, waitOnEventOrTimeout,
|
||||
WaitOnType
|
||||
binarySearchFirstItem, EventBus, getPDFFileNameFromURL, isValidRotation,
|
||||
waitOnEventOrTimeout, WaitOnType
|
||||
} from '../../web/ui_utils';
|
||||
import { createObjectURL, isNodeJS } from '../../src/shared/util';
|
||||
|
||||
|
@ -261,6 +261,29 @@ describe('ui_utils', function() {
|
|||
});
|
||||
});
|
||||
|
||||
describe('isValidRotation', function() {
|
||||
it('should reject non-integer angles', function() {
|
||||
expect(isValidRotation()).toEqual(false);
|
||||
expect(isValidRotation(null)).toEqual(false);
|
||||
expect(isValidRotation(NaN)).toEqual(false);
|
||||
expect(isValidRotation([90])).toEqual(false);
|
||||
expect(isValidRotation('90')).toEqual(false);
|
||||
expect(isValidRotation(90.5)).toEqual(false);
|
||||
});
|
||||
|
||||
it('should reject non-multiple of 90 degree angles', function() {
|
||||
expect(isValidRotation(45)).toEqual(false);
|
||||
expect(isValidRotation(-123)).toEqual(false);
|
||||
});
|
||||
|
||||
it('should accept valid angles', function() {
|
||||
expect(isValidRotation(0)).toEqual(true);
|
||||
expect(isValidRotation(90)).toEqual(true);
|
||||
expect(isValidRotation(-270)).toEqual(true);
|
||||
expect(isValidRotation(540)).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('waitOnEventOrTimeout', function() {
|
||||
let eventBus;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue