Merge pull request #5606 from Snuffleupagus/textlayerrendered

Add a |textlayerrendered| event
This commit is contained in:
Yury Delendik 2015-01-06 14:42:06 -06:00
commit 039c7b4085
2 changed files with 30 additions and 14 deletions

View File

@ -46,6 +46,7 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
this.renderingDone = false;
this.divContentDone = false;
this.pageIdx = options.pageIndex;
this.pageNumber = this.pageIdx + 1;
this.matches = [];
this.viewport = options.viewport;
this.textDivs = [];
@ -53,6 +54,16 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
}
TextLayerBuilder.prototype = {
_finishRendering: function TextLayerBuilder_finishRendering() {
this.renderingDone = true;
var event = document.createEvent('CustomEvent');
event.initCustomEvent('textlayerrendered', true, true, {
pageNumber: this.pageNumber
});
this.textLayerDiv.dispatchEvent(event);
},
renderLayer: function TextLayerBuilder_renderLayer() {
var textLayerFrag = document.createDocumentFragment();
var textDivs = this.textDivs;
@ -63,7 +74,7 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
// No point in rendering many divs as it would make the browser
// unusable even after the divs are rendered.
if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
this.renderingDone = true;
this._finishRendering();
return;
}
@ -107,7 +118,7 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
}
this.textLayerDiv.appendChild(textLayerFrag);
this.renderingDone = true;
this._finishRendering();
this.updateMatches();
},

View File

@ -1741,18 +1741,6 @@ document.addEventListener('pagerendered', function (e) {
Stats.add(pageNumber, pageView.stats);
}
//#if (FIREFOX || MOZCENTRAL)
//if (pageView.textLayer && pageView.textLayer.textDivs &&
// pageView.textLayer.textDivs.length > 0 &&
// !PDFViewerApplication.supportsDocumentColors) {
// console.error(mozL10n.get('document_colors_disabled', null,
// 'PDF documents are not allowed to use their own colors: ' +
// '\'Allow pages to choose their own colors\' ' +
// 'is deactivated in the browser.'));
// PDFViewerApplication.fallback();
//}
//#endif
if (pageView.error) {
PDFViewerApplication.error(mozL10n.get('rendering_error', null,
'An error occurred while rendering the page.'), pageView.error);
@ -1779,6 +1767,23 @@ document.addEventListener('pagerendered', function (e) {
}
}, true);
document.addEventListener('textlayerrendered', function (e) {
var pageIndex = e.detail.pageNumber - 1;
var pageView = PDFViewerApplication.pdfViewer.getPageView(pageIndex);
//#if (FIREFOX || MOZCENTRAL)
//if (pageView.textLayer && pageView.textLayer.textDivs &&
// pageView.textLayer.textDivs.length > 0 &&
// !PDFViewerApplication.supportsDocumentColors) {
// console.error(mozL10n.get('document_colors_disabled', null,
// 'PDF documents are not allowed to use their own colors: ' +
// '\'Allow pages to choose their own colors\' ' +
// 'is deactivated in the browser.'));
// PDFViewerApplication.fallback();
//}
//#endif
}, true);
window.addEventListener('presentationmodechanged', function (e) {
var active = e.detail.active;
var switchInProgress = e.detail.switchInProgress;