|
|
@ -14,7 +14,7 @@ |
|
|
|
* See the License for the specific language governing permissions and |
|
|
|
* See the License for the specific language governing permissions and |
|
|
|
* limitations under the License. |
|
|
|
* limitations under the License. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
/* globals mozL10n, RenderingStates, Promise, scrollIntoView, PDFPageSource, |
|
|
|
/* globals mozL10n, RenderingStates, Promise, scrollIntoView, |
|
|
|
watchScroll, getVisibleElements */ |
|
|
|
watchScroll, getVisibleElements */ |
|
|
|
|
|
|
|
|
|
|
|
'use strict'; |
|
|
|
'use strict'; |
|
|
@ -28,13 +28,11 @@ var THUMBNAIL_SCROLL_MARGIN = -19; |
|
|
|
* @param defaultViewport |
|
|
|
* @param defaultViewport |
|
|
|
* @param linkService |
|
|
|
* @param linkService |
|
|
|
* @param renderingQueue |
|
|
|
* @param renderingQueue |
|
|
|
* @param pageSource |
|
|
|
|
|
|
|
* |
|
|
|
* |
|
|
|
* @implements {IRenderableView} |
|
|
|
* @implements {IRenderableView} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
var ThumbnailView = function thumbnailView(container, id, defaultViewport, |
|
|
|
var ThumbnailView = function thumbnailView(container, id, defaultViewport, |
|
|
|
linkService, renderingQueue, |
|
|
|
linkService, renderingQueue) { |
|
|
|
pageSource) { |
|
|
|
|
|
|
|
var anchor = document.createElement('a'); |
|
|
|
var anchor = document.createElement('a'); |
|
|
|
anchor.href = linkService.getAnchorUrl('#page=' + id); |
|
|
|
anchor.href = linkService.getAnchorUrl('#page=' + id); |
|
|
|
anchor.title = mozL10n.get('thumb_page_title', {page: id}, 'Page {{page}}'); |
|
|
|
anchor.title = mozL10n.get('thumb_page_title', {page: id}, 'Page {{page}}'); |
|
|
@ -80,7 +78,6 @@ var ThumbnailView = function thumbnailView(container, id, defaultViewport, |
|
|
|
this.hasImage = false; |
|
|
|
this.hasImage = false; |
|
|
|
this.renderingState = RenderingStates.INITIAL; |
|
|
|
this.renderingState = RenderingStates.INITIAL; |
|
|
|
this.renderingQueue = renderingQueue; |
|
|
|
this.renderingQueue = renderingQueue; |
|
|
|
this.pageSource = pageSource; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.setPdfPage = function thumbnailViewSetPdfPage(pdfPage) { |
|
|
|
this.setPdfPage = function thumbnailViewSetPdfPage(pdfPage) { |
|
|
|
this.pdfPage = pdfPage; |
|
|
|
this.pdfPage = pdfPage; |
|
|
@ -143,15 +140,6 @@ var ThumbnailView = function thumbnailView(container, id, defaultViewport, |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
this.draw = function thumbnailViewDraw(callback) { |
|
|
|
this.draw = function thumbnailViewDraw(callback) { |
|
|
|
if (!this.pdfPage) { |
|
|
|
|
|
|
|
var promise = this.pageSource.getPage(this.id); |
|
|
|
|
|
|
|
promise.then(function(pdfPage) { |
|
|
|
|
|
|
|
this.setPdfPage(pdfPage); |
|
|
|
|
|
|
|
this.draw(callback); |
|
|
|
|
|
|
|
}.bind(this)); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.renderingState !== RenderingStates.INITIAL) { |
|
|
|
if (this.renderingState !== RenderingStates.INITIAL) { |
|
|
|
console.error('Must be in new state before drawing'); |
|
|
|
console.error('Must be in new state before drawing'); |
|
|
|
} |
|
|
|
} |
|
|
@ -204,18 +192,14 @@ var ThumbnailView = function thumbnailView(container, id, defaultViewport, |
|
|
|
return tempCanvas; |
|
|
|
return tempCanvas; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.setImage = function thumbnailViewSetImage(img) { |
|
|
|
this.setImage = function thumbnailViewSetImage(pageView) { |
|
|
|
if (!this.pdfPage) { |
|
|
|
var img = pageView.canvas; |
|
|
|
var promise = this.pageSource.getPage(); |
|
|
|
|
|
|
|
promise.then(function(pdfPage) { |
|
|
|
|
|
|
|
this.setPdfPage(pdfPage); |
|
|
|
|
|
|
|
this.setImage(img); |
|
|
|
|
|
|
|
}.bind(this)); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (this.hasImage || !img) { |
|
|
|
if (this.hasImage || !img) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (this.pdfPage) { |
|
|
|
|
|
|
|
this.setPdfPage(pageView.pdfPage); |
|
|
|
|
|
|
|
} |
|
|
|
this.renderingState = RenderingStates.FINISHED; |
|
|
|
this.renderingState = RenderingStates.FINISHED; |
|
|
|
var ctx = this.getPageDrawContext(); |
|
|
|
var ctx = this.getPageDrawContext(); |
|
|
|
|
|
|
|
|
|
|
@ -330,6 +314,7 @@ var PDFThumbnailViewer = (function pdfThumbnailViewer() { |
|
|
|
_resetView: function () { |
|
|
|
_resetView: function () { |
|
|
|
this.thumbnails = []; |
|
|
|
this.thumbnails = []; |
|
|
|
this._pagesRotation = 0; |
|
|
|
this._pagesRotation = 0; |
|
|
|
|
|
|
|
this._pagesRequests = []; |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
setDocument: function (pdfDocument) { |
|
|
|
setDocument: function (pdfDocument) { |
|
|
@ -351,15 +336,37 @@ var PDFThumbnailViewer = (function pdfThumbnailViewer() { |
|
|
|
var pagesCount = pdfDocument.numPages; |
|
|
|
var pagesCount = pdfDocument.numPages; |
|
|
|
var viewport = firstPage.getViewport(1.0); |
|
|
|
var viewport = firstPage.getViewport(1.0); |
|
|
|
for (var pageNum = 1; pageNum <= pagesCount; ++pageNum) { |
|
|
|
for (var pageNum = 1; pageNum <= pagesCount; ++pageNum) { |
|
|
|
var pageSource = new PDFPageSource(pdfDocument, pageNum); |
|
|
|
|
|
|
|
var thumbnail = new ThumbnailView(this.container, pageNum, |
|
|
|
var thumbnail = new ThumbnailView(this.container, pageNum, |
|
|
|
viewport.clone(), this.linkService, |
|
|
|
viewport.clone(), this.linkService, |
|
|
|
this.renderingQueue, pageSource); |
|
|
|
this.renderingQueue); |
|
|
|
this.thumbnails.push(thumbnail); |
|
|
|
this.thumbnails.push(thumbnail); |
|
|
|
} |
|
|
|
} |
|
|
|
}.bind(this)); |
|
|
|
}.bind(this)); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @param {PDFPageView} pageView |
|
|
|
|
|
|
|
* @returns {PDFPage} |
|
|
|
|
|
|
|
* @private |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
_ensurePdfPageLoaded: function (thumbView) { |
|
|
|
|
|
|
|
if (thumbView.pdfPage) { |
|
|
|
|
|
|
|
return Promise.resolve(thumbView.pdfPage); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var pageNumber = thumbView.id; |
|
|
|
|
|
|
|
if (this._pagesRequests[pageNumber]) { |
|
|
|
|
|
|
|
return this._pagesRequests[pageNumber]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var promise = this.pdfDocument.getPage(pageNumber).then( |
|
|
|
|
|
|
|
function (pdfPage) { |
|
|
|
|
|
|
|
thumbView.setPdfPage(pdfPage); |
|
|
|
|
|
|
|
this._pagesRequests[pageNumber] = null; |
|
|
|
|
|
|
|
return pdfPage; |
|
|
|
|
|
|
|
}.bind(this)); |
|
|
|
|
|
|
|
this._pagesRequests[pageNumber] = promise; |
|
|
|
|
|
|
|
return promise; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
ensureThumbnailVisible: |
|
|
|
ensureThumbnailVisible: |
|
|
|
function PDFThumbnailViewer_ensureThumbnailVisible(page) { |
|
|
|
function PDFThumbnailViewer_ensureThumbnailVisible(page) { |
|
|
|
// Ensure that the thumbnail of the current page is visible
|
|
|
|
// Ensure that the thumbnail of the current page is visible
|
|
|
@ -373,7 +380,9 @@ var PDFThumbnailViewer = (function pdfThumbnailViewer() { |
|
|
|
this.thumbnails, |
|
|
|
this.thumbnails, |
|
|
|
this.scroll.down); |
|
|
|
this.scroll.down); |
|
|
|
if (thumbView) { |
|
|
|
if (thumbView) { |
|
|
|
this.renderingQueue.renderView(thumbView); |
|
|
|
this._ensurePdfPageLoaded(thumbView).then(function () { |
|
|
|
|
|
|
|
this.renderingQueue.renderView(thumbView); |
|
|
|
|
|
|
|
}.bind(this)); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
return false; |
|
|
|
return false; |
|
|
|