Add PageLabels to PDFPageView and PDFThumbnailView

This commit is contained in:
Jonas Jenwald 2016-01-27 14:27:01 +01:00
parent f461fd64aa
commit efb9619e53
4 changed files with 55 additions and 2 deletions

View File

@ -78,6 +78,7 @@ var PDFPageView = (function PDFPageViewClosure() {
this.id = id; this.id = id;
this.renderingId = 'page' + id; this.renderingId = 'page' + id;
this.pageLabel = null;
this.rotation = 0; this.rotation = 0;
this.scale = scale || DEFAULT_SCALE; this.scale = scale || DEFAULT_SCALE;
@ -554,6 +555,19 @@ var PDFPageView = (function PDFPageViewClosure() {
} }
return promise; return promise;
}, },
/**
* @param {string|null} label
*/
setPageLabel: function PDFView_setPageLabel(label) {
this.pageLabel = (typeof label === 'string' ? label : null);
if (this.pageLabel !== null) {
this.div.setAttribute('data-page-label', this.pageLabel);
} else {
this.div.removeAttribute('data-page-label');
}
},
}; };
return PDFPageView; return PDFPageView;

View File

@ -91,6 +91,7 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
this.id = id; this.id = id;
this.renderingId = 'thumbnail' + id; this.renderingId = 'thumbnail' + id;
this.pageLabel = null;
this.pdfPage = null; this.pdfPage = null;
this.rotation = 0; this.rotation = 0;
@ -120,6 +121,7 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
linkService.page = id; linkService.page = id;
return false; return false;
}; };
this.anchor = anchor;
var div = document.createElement('div'); var div = document.createElement('div');
div.id = 'thumbnailContainer' + id; div.id = 'thumbnailContainer' + id;
@ -247,7 +249,7 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
} }
var id = this.renderingId; var id = this.renderingId;
var className = 'thumbnailImage'; var className = 'thumbnailImage';
var ariaLabel = mozL10n.get('thumb_page_canvas', { page: this.id }, var ariaLabel = mozL10n.get('thumb_page_canvas', { page: this.pageId },
'Thumbnail of Page {{page}}'); 'Thumbnail of Page {{page}}');
if (this.disableCanvasToImageConversion) { if (this.disableCanvasToImageConversion) {
@ -395,7 +397,32 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight,
0, 0, canvas.width, canvas.height); 0, 0, canvas.width, canvas.height);
this._convertCanvasToImage(); this._convertCanvasToImage();
} },
get pageId() {
return (this.pageLabel !== null ? this.pageLabel : this.id);
},
/**
* @param {string|null} label
*/
setPageLabel: function PDFThumbnailView_setPageLabel(label) {
this.pageLabel = (typeof label === 'string' ? label : null);
this.anchor.title = mozL10n.get('thumb_page_title', { page: this.pageId },
'Page {{page}}');
if (this.renderingState !== RenderingStates.FINISHED) {
return;
}
var ariaLabel = mozL10n.get('thumb_page_canvas', { page: this.pageId },
'Thumbnail of Page {{page}}');
if (this.image) {
this.image.setAttribute('aria-label', ariaLabel);
} else if (this.disableCanvasToImageConversion && this.canvas) {
this.canvas.setAttribute('aria-label', ariaLabel);
}
},
}; };
return PDFThumbnailView; return PDFThumbnailView;

View File

@ -196,6 +196,12 @@ var PDFThumbnailViewer = (function PDFThumbnailViewerClosure() {
} else { } else {
this._pageLabels = labels; this._pageLabels = labels;
} }
// Update all the `PDFThumbnailView` instances.
for (var i = 0, ii = this.thumbnails.length; i < ii; i++) {
var thumbnailView = this.thumbnails[i];
var label = this._pageLabels && this._pageLabels[i];
thumbnailView.setPageLabel(label);
}
}, },
/** /**

View File

@ -453,6 +453,12 @@ var PDFViewer = (function pdfViewer() {
} else { } else {
this._pageLabels = labels; this._pageLabels = labels;
} }
// Update all the `PDFPageView` instances.
for (var i = 0, ii = this._pages.length; i < ii; i++) {
var pageView = this._pages[i];
var label = this._pageLabels && this._pageLabels[i];
pageView.setPageLabel(label);
}
}, },
_resetView: function () { _resetView: function () {