Skip to content

Commit

Permalink
Don't allow setting various properties, such as currentPageNumber/`…
Browse files Browse the repository at this point in the history
…currentScale`/`currentScaleValue`/`pagesRotation`, before `{PDFViewer, PDFThumbnailViewer}.setDocument` has been called

Currently a number of these properties do not work correctly if set *before* calling `setDocument`; please refer to the discussion starting in mozilla#8539 (comment).

Rather than trying to have *some* of these methods working, but not others, it seems much more consistent to simply always require that `setDocument` has been called.
  • Loading branch information
Snuffleupagus authored and apoorv-mishra committed Jul 6, 2017
1 parent 10cf5be commit 60b2d52
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
9 changes: 8 additions & 1 deletion web/pdf_thumbnail_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,15 @@ class PDFThumbnailViewer {
}

set pagesRotation(rotation) {
if (!(typeof rotation === 'number' && rotation % 90 === 0)) {
throw new Error('Invalid thumbnails rotation angle.');
}
if (!this.pdfDocument) {
return;
}
this._pagesRotation = rotation;
for (let i = 0, l = this._thumbnails.length; i < l; i++) {

for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
this._thumbnails[i].update(rotation);
}
}
Expand Down
17 changes: 6 additions & 11 deletions web/pdf_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ var PDFViewer = (function pdfViewer() {
throw new Error('Invalid page number.');
}
if (!this.pdfDocument) {
this._currentPageNumber = val;
return;
}
// The intent can be to just reset a scroll position and/or scale.
Expand Down Expand Up @@ -217,9 +216,9 @@ var PDFViewer = (function pdfViewer() {
* @param {string} val - The page label.
*/
set currentPageLabel(val) {
var pageNumber = val | 0; // Fallback page number.
let pageNumber = val | 0; // Fallback page number.
if (this._pageLabels) {
var i = this._pageLabels.indexOf(val);
let i = this._pageLabels.indexOf(val);
if (i >= 0) {
pageNumber = i + 1;
}
Expand All @@ -243,8 +242,6 @@ var PDFViewer = (function pdfViewer() {
throw new Error('Invalid numeric scale');
}
if (!this.pdfDocument) {
this._currentScale = val;
this._currentScaleValue = val !== UNKNOWN_SCALE ? val.toString() : null;
return;
}
this._setScale(val, false);
Expand All @@ -262,8 +259,6 @@ var PDFViewer = (function pdfViewer() {
*/
set currentScaleValue(val) {
if (!this.pdfDocument) {
this._currentScale = isNaN(val) ? UNKNOWN_SCALE : val;
this._currentScaleValue = val.toString();
return;
}
this._setScale(val, false);
Expand All @@ -283,13 +278,13 @@ var PDFViewer = (function pdfViewer() {
if (!(typeof rotation === 'number' && rotation % 90 === 0)) {
throw new Error('Invalid pages rotation angle.');
}
this._pagesRotation = rotation;

if (!this.pdfDocument) {
return;
}
for (var i = 0, l = this._pages.length; i < l; i++) {
var pageView = this._pages[i];
this._pagesRotation = rotation;

for (let i = 0, ii = this._pages.length; i < ii; i++) {
let pageView = this._pages[i];
pageView.update(pageView.scale, rotation);
}

Expand Down

0 comments on commit 60b2d52

Please sign in to comment.