From f1851c6393a233b0ad9019fa2dd8f76557b4a89b Mon Sep 17 00:00:00 2001 From: Yury Delendik Date: Mon, 15 Sep 2014 14:57:12 -0500 Subject: [PATCH] Removes any usage of PDFView in the PageView --- web/page_view.js | 51 +++++++++-------------------------------------- web/pdf_viewer.js | 22 +++++++++++++++++++- web/viewer.js | 36 ++++++++++++++++++++++++++++----- 3 files changed, 61 insertions(+), 48 deletions(-) diff --git a/web/page_view.js b/web/page_view.js index 583cba585..86572cb89 100644 --- a/web/page_view.js +++ b/web/page_view.js @@ -14,10 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* globals RenderingStates, PDFView, PDFJS, mozL10n, CustomStyle, +/* globals RenderingStates, PDFJS, mozL10n, CustomStyle, SCROLLBAR_PADDING, CSS_UNITS, UNKNOWN_SCALE, DEFAULT_SCALE, - getOutputScale, TextLayerBuilder, scrollIntoView, Stats, - PresentationModeState */ + getOutputScale, scrollIntoView, Stats, PresentationModeState */ 'use strict'; @@ -509,6 +508,7 @@ var PageView = function pageView(container, id, scale, defaultViewport, canvas._viewport = viewport; var textLayerDiv = null; + var textLayer = null; if (!PDFJS.disableTextLayer) { textLayerDiv = document.createElement('div'); textLayerDiv.className = 'textLayer'; @@ -520,18 +520,12 @@ var PageView = function pageView(container, id, scale, defaultViewport, } else { div.appendChild(textLayerDiv); } + + textLayer = this.viewer.createTextLayerBuilder(textLayerDiv, this.id - 1, + this.viewport); } - var isViewerInPresentationMode = - this.viewer.presentationModeState === PresentationModeState.FULLSCREEN; - var textLayer = this.textLayer = - textLayerDiv ? new TextLayerBuilder({ - textLayerDiv: textLayerDiv, - pageIndex: this.id - 1, - lastScrollSource: this.linkService, - viewport: this.viewport, - isViewerInPresentationMode: isViewerInPresentationMode, - findController: PDFView.findController - }) : null; + this.textLayer = textLayer; + // TODO(mack): use data attributes to store these ctx._scaleX = outputScale.sx; ctx._scaleY = outputScale.sy; @@ -566,22 +560,7 @@ var PageView = function pageView(container, id, scale, defaultViewport, self.zoomLayer = null; } -//#if (FIREFOX || MOZCENTRAL) -// if (self.textLayer && self.textLayer.textDivs && -// self.textLayer.textDivs.length > 0 && -// !PDFView.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.')); -// PDFView.fallback(); -// } -//#endif - if (error) { - PDFView.error(mozL10n.get('rendering_error', null, - 'An error occurred while rendering the page.'), error); - } - + self.error = error; self.stats = pdfPage.stats; self.updateStats(); if (self.onAfterDraw) { @@ -594,18 +573,6 @@ var PageView = function pageView(container, id, scale, defaultViewport, }); div.dispatchEvent(event); -//#if (FIREFOX || MOZCENTRAL) -// FirefoxCom.request('reportTelemetry', JSON.stringify({ -// type: 'pageInfo' -// })); -// // It is a good time to report stream and font types -// PDFView.pdfDocument.getStats().then(function (stats) { -// FirefoxCom.request('reportTelemetry', JSON.stringify({ -// type: 'documentStats', -// stats: stats -// })); -// }); -//#endif callback(); } diff --git a/web/pdf_viewer.js b/web/pdf_viewer.js index 1f5ac7c85..e5f49d2ed 100644 --- a/web/pdf_viewer.js +++ b/web/pdf_viewer.js @@ -17,7 +17,7 @@ /*globals watchScroll, Cache, DEFAULT_CACHE_SIZE, PageView, UNKNOWN_SCALE, IGNORE_CURRENT_POSITION_ON_ZOOM, SCROLLBAR_PADDING, VERTICAL_PADDING, MAX_AUTO_SCALE, getVisibleElements, RenderingStates, Promise, - CSS_UNITS, PDFJS */ + CSS_UNITS, PDFJS, TextLayerBuilder */ 'use strict'; @@ -36,6 +36,7 @@ var PDFViewer = (function pdfViewer() { this.linkService = options.linkService; this.scroll = watchScroll(this.container, this._scrollUpdate.bind(this)); + this.lastScroll = 0; this.updateInProgress = false; this.presentationModeState = PresentationModeState.UNKNOWN; this.resetView(); @@ -180,6 +181,8 @@ var PDFViewer = (function pdfViewer() { }, _scrollUpdate: function () { + this.lastScroll = Date.now(); + if (this.pagesCount === 0) { return; } @@ -411,6 +414,23 @@ var PDFViewer = (function pdfViewer() { return page.getTextContent(); }); }, + + createTextLayerBuilder: function (textLayerDiv, pageIndex, viewport) { + var isViewerInPresentationMode = + this.presentationModeState === PresentationModeState.FULLSCREEN; + return new TextLayerBuilder({ + textLayerDiv: textLayerDiv, + pageIndex: pageIndex, + viewport: viewport, + lastScrollSource: this, + isViewerInPresentationMode: isViewerInPresentationMode, + findController: this.findController + }); + }, + + setFindController: function (findController) { + this.findController = findController; + }, }; return PDFViewer; diff --git a/web/viewer.js b/web/viewer.js index 00ba94f23..4d015486a 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -104,7 +104,6 @@ var PDFView = { pageRotation: 0, mouseScrollTimeStamp: 0, mouseScrollDelta: 0, - lastScroll: 0, isViewerEmbedded: (window.parent !== window), url: '', @@ -138,6 +137,7 @@ var PDFView = { pdfViewer: this.pdfViewer, integratedFind: this.supportsIntegratedFind }); + this.pdfViewer.setFindController(this.findController); this.findBar = new PDFFindBar({ bar: document.getElementById('findbar'), @@ -211,10 +211,6 @@ var PDFView = { pageCountField: document.getElementById('pageCountField') }); - container.addEventListener('scroll', function() { - self.lastScroll = Date.now(); - }, false); - var initializedPromise = Promise.all([ Preferences.get('enableWebGL').then(function resolved(value) { PDFJS.disableWebGL = !value; @@ -1666,6 +1662,36 @@ document.addEventListener('pagerendered', function (e) { var pageView = PDFView.pdfViewer.getPageView(pageIndex); var thumbnailView = PDFView.pdfThumbnailViewer.getThumbnail(pageIndex); thumbnailView.setImage(pageView.canvas); + +//#if (FIREFOX || MOZCENTRAL) +//if (pageView.textLayer && pageView.textLayer.textDivs && +// pageView.textLayer.textDivs.length > 0 && +// !PDFView.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.')); +// PDFView.fallback(); +//} +//#endif + + if (pageView.error) { + PDFView.error(mozL10n.get('rendering_error', null, + 'An error occurred while rendering the page.'), pageView.error); + } + +//#if (FIREFOX || MOZCENTRAL) +//FirefoxCom.request('reportTelemetry', JSON.stringify({ +// type: 'pageInfo' +//})); +//// It is a good time to report stream and font types +//PDFView.pdfDocument.getStats().then(function (stats) { +// FirefoxCom.request('reportTelemetry', JSON.stringify({ +// type: 'documentStats', +// stats: stats +// })); +//}); +//#endif }, true); window.addEventListener('presentationmodechanged', function (e) {