Removes lastScrollSource and isViewerInPresentationMode from TextLayerBuilderOptions
This commit is contained in:
parent
b930228788
commit
2ac7ac4678
@ -73,17 +73,6 @@ IRenderableView.prototype = {
|
|||||||
resume: function () {},
|
resume: function () {},
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* @interface
|
|
||||||
*/
|
|
||||||
function ILastScrollSource() {}
|
|
||||||
ILastScrollSource.prototype = {
|
|
||||||
/**
|
|
||||||
* @returns {number}
|
|
||||||
*/
|
|
||||||
get lastScroll() {},
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @interface
|
* @interface
|
||||||
*/
|
*/
|
||||||
|
@ -13,7 +13,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 PDFJS, FirefoxCom, Promise */
|
/* globals PDFJS, FirefoxCom, Promise, scrollIntoView */
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
@ -24,6 +24,9 @@ var FindStates = {
|
|||||||
FIND_PENDING: 3
|
FIND_PENDING: 3
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var FIND_SCROLL_OFFSET_TOP = -50;
|
||||||
|
var FIND_SCROLL_OFFSET_LEFT = -400;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides "search" or "find" functionality for the PDF.
|
* Provides "search" or "find" functionality for the PDF.
|
||||||
* This object actually performs the search for a given string.
|
* This object actually performs the search for a given string.
|
||||||
@ -308,6 +311,26 @@ var PDFFindController = (function PDFFindControllerClosure() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The method is called back from the text layer when match presentation
|
||||||
|
* is updated.
|
||||||
|
* @param {number} pageIndex - page index.
|
||||||
|
* @param {number} index - match index.
|
||||||
|
* @param {Array} elements - text layer div elements array.
|
||||||
|
* @param {number} beginIdx - start index of the div array for the match.
|
||||||
|
* @param {number} endIdx - end index of the div array for the match.
|
||||||
|
*/
|
||||||
|
updateMatchPosition: function PDFFindController_updateMatchPosition(
|
||||||
|
pageIndex, index, elements, beginIdx, endIdx) {
|
||||||
|
if (this.selected.matchIdx === index &&
|
||||||
|
this.selected.pageIdx === pageIndex) {
|
||||||
|
scrollIntoView(elements[beginIdx], {
|
||||||
|
top: FIND_SCROLL_OFFSET_TOP,
|
||||||
|
left: FIND_SCROLL_OFFSET_LEFT
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
nextPageMatch: function PDFFindController_nextPageMatch() {
|
nextPageMatch: function PDFFindController_nextPageMatch() {
|
||||||
if (this.resumePageIdx !== null) {
|
if (this.resumePageIdx !== null) {
|
||||||
console.error('There can only be one pending page.');
|
console.error('There can only be one pending page.');
|
||||||
|
@ -18,6 +18,8 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var TEXT_LAYER_RENDER_DELAY = 200; // ms
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} PDFPageViewOptions
|
* @typedef {Object} PDFPageViewOptions
|
||||||
* @property {HTMLDivElement} container - The viewer element.
|
* @property {HTMLDivElement} container - The viewer element.
|
||||||
@ -194,6 +196,15 @@ var PDFPageView = (function PDFPageViewClosure() {
|
|||||||
this.reset(true);
|
this.reset(true);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when moved in the parent's container.
|
||||||
|
*/
|
||||||
|
updatePosition: function PDFPageView_updatePosition() {
|
||||||
|
if (this.textLayer) {
|
||||||
|
this.textLayer.render(TEXT_LAYER_RENDER_DELAY);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
cssTransform: function PDFPageView_transform(canvas, redrawAnnotations) {
|
cssTransform: function PDFPageView_transform(canvas, redrawAnnotations) {
|
||||||
// Scale canvas, canvas wrapper, and page container.
|
// Scale canvas, canvas wrapper, and page container.
|
||||||
var width = this.viewport.width;
|
var width = this.viewport.width;
|
||||||
@ -429,6 +440,7 @@ var PDFPageView = (function PDFPageViewClosure() {
|
|||||||
self.pdfPage.getTextContent().then(
|
self.pdfPage.getTextContent().then(
|
||||||
function textContentResolved(textContent) {
|
function textContentResolved(textContent) {
|
||||||
textLayer.setTextContent(textContent);
|
textLayer.setTextContent(textContent);
|
||||||
|
textLayer.render(TEXT_LAYER_RENDER_DELAY);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,6 @@ var DEFAULT_CACHE_SIZE = 10;
|
|||||||
/**
|
/**
|
||||||
* Simple viewer control to display PDF content/pages.
|
* Simple viewer control to display PDF content/pages.
|
||||||
* @class
|
* @class
|
||||||
* @implements {ILastScrollSource}
|
|
||||||
* @implements {IRenderableView}
|
* @implements {IRenderableView}
|
||||||
*/
|
*/
|
||||||
var PDFViewer = (function pdfViewer() {
|
var PDFViewer = (function pdfViewer() {
|
||||||
@ -92,7 +91,6 @@ var PDFViewer = (function pdfViewer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.scroll = watchScroll(this.container, this._scrollUpdate.bind(this));
|
this.scroll = watchScroll(this.container, this._scrollUpdate.bind(this));
|
||||||
this.lastScroll = 0;
|
|
||||||
this.updateInProgress = false;
|
this.updateInProgress = false;
|
||||||
this.presentationModeState = PresentationModeState.UNKNOWN;
|
this.presentationModeState = PresentationModeState.UNKNOWN;
|
||||||
this._resetView();
|
this._resetView();
|
||||||
@ -333,12 +331,13 @@ var PDFViewer = (function pdfViewer() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
_scrollUpdate: function () {
|
_scrollUpdate: function () {
|
||||||
this.lastScroll = Date.now();
|
|
||||||
|
|
||||||
if (this.pagesCount === 0) {
|
if (this.pagesCount === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.update();
|
this.update();
|
||||||
|
for (var i = 0, ii = this.pages.length; i < ii; i++) {
|
||||||
|
this.pages[i].updatePosition();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_setScaleUpdatePages: function pdfViewer_setScaleUpdatePages(
|
_setScaleUpdatePages: function pdfViewer_setScaleUpdatePages(
|
||||||
@ -696,9 +695,7 @@ var PDFViewer = (function pdfViewer() {
|
|||||||
textLayerDiv: textLayerDiv,
|
textLayerDiv: textLayerDiv,
|
||||||
pageIndex: pageIndex,
|
pageIndex: pageIndex,
|
||||||
viewport: viewport,
|
viewport: viewport,
|
||||||
lastScrollSource: this,
|
findController: isViewerInPresentationMode ? null : this.findController
|
||||||
isViewerInPresentationMode: isViewerInPresentationMode,
|
|
||||||
findController: this.findController
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -13,14 +13,11 @@
|
|||||||
* 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 CustomStyle, scrollIntoView, PDFJS */
|
/* globals CustomStyle, PDFJS */
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var FIND_SCROLL_OFFSET_TOP = -50;
|
|
||||||
var FIND_SCROLL_OFFSET_LEFT = -400;
|
|
||||||
var MAX_TEXT_DIVS_TO_RENDER = 100000;
|
var MAX_TEXT_DIVS_TO_RENDER = 100000;
|
||||||
var RENDER_DELAY = 200; // ms
|
|
||||||
|
|
||||||
var NonWhitespaceRegexp = /\S/;
|
var NonWhitespaceRegexp = /\S/;
|
||||||
|
|
||||||
@ -33,9 +30,6 @@ function isAllWhitespace(str) {
|
|||||||
* @property {HTMLDivElement} textLayerDiv - The text layer container.
|
* @property {HTMLDivElement} textLayerDiv - The text layer container.
|
||||||
* @property {number} pageIndex - The page index.
|
* @property {number} pageIndex - The page index.
|
||||||
* @property {PageViewport} viewport - The viewport of the text layer.
|
* @property {PageViewport} viewport - The viewport of the text layer.
|
||||||
* @property {ILastScrollSource} lastScrollSource - The object that records when
|
|
||||||
* last time scroll happened.
|
|
||||||
* @property {boolean} isViewerInPresentationMode
|
|
||||||
* @property {PDFFindController} findController
|
* @property {PDFFindController} findController
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -49,13 +43,11 @@ function isAllWhitespace(str) {
|
|||||||
var TextLayerBuilder = (function TextLayerBuilderClosure() {
|
var TextLayerBuilder = (function TextLayerBuilderClosure() {
|
||||||
function TextLayerBuilder(options) {
|
function TextLayerBuilder(options) {
|
||||||
this.textLayerDiv = options.textLayerDiv;
|
this.textLayerDiv = options.textLayerDiv;
|
||||||
this.layoutDone = false;
|
this.renderingDone = false;
|
||||||
this.divContentDone = false;
|
this.divContentDone = false;
|
||||||
this.pageIdx = options.pageIndex;
|
this.pageIdx = options.pageIndex;
|
||||||
this.matches = [];
|
this.matches = [];
|
||||||
this.lastScrollSource = options.lastScrollSource || null;
|
|
||||||
this.viewport = options.viewport;
|
this.viewport = options.viewport;
|
||||||
this.isViewerInPresentationMode = options.isViewerInPresentationMode;
|
|
||||||
this.textDivs = [];
|
this.textDivs = [];
|
||||||
this.findController = options.findController || null;
|
this.findController = options.findController || null;
|
||||||
}
|
}
|
||||||
@ -71,6 +63,7 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
|
|||||||
// No point in rendering many divs as it would make the browser
|
// No point in rendering many divs as it would make the browser
|
||||||
// unusable even after the divs are rendered.
|
// unusable even after the divs are rendered.
|
||||||
if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
|
if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
|
||||||
|
this.renderingDone = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,23 +111,29 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
|
|||||||
this.updateMatches();
|
this.updateMatches();
|
||||||
},
|
},
|
||||||
|
|
||||||
setupRenderLayoutTimer:
|
/**
|
||||||
function TextLayerBuilder_setupRenderLayoutTimer() {
|
* Renders the text layer.
|
||||||
// Schedule renderLayout() if the user has been scrolling,
|
* @param {number} timeout (optional) if specified, the rendering waits
|
||||||
// otherwise run it right away.
|
* for specified amount of ms.
|
||||||
var self = this;
|
*/
|
||||||
var lastScroll = (this.lastScrollSource === null ?
|
render: function TextLayerBuilder_render(timeout) {
|
||||||
0 : this.lastScrollSource.lastScroll);
|
if (!this.divContentDone || this.renderingDone) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (Date.now() - lastScroll > RENDER_DELAY) { // Render right away
|
|
||||||
this.renderLayer();
|
|
||||||
} else { // Schedule
|
|
||||||
if (this.renderTimer) {
|
if (this.renderTimer) {
|
||||||
clearTimeout(this.renderTimer);
|
clearTimeout(this.renderTimer);
|
||||||
|
this.renderTimer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!timeout) { // Render right away
|
||||||
|
this.renderLayer();
|
||||||
|
} else { // Schedule
|
||||||
|
var self = this;
|
||||||
this.renderTimer = setTimeout(function() {
|
this.renderTimer = setTimeout(function() {
|
||||||
self.setupRenderLayoutTimer();
|
self.renderLayer();
|
||||||
}, RENDER_DELAY);
|
self.renderTimer = null;
|
||||||
|
}, timeout);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -204,7 +203,6 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
|
|||||||
this.appendText(textItems[i], textContent.styles);
|
this.appendText(textItems[i], textContent.styles);
|
||||||
}
|
}
|
||||||
this.divContentDone = true;
|
this.divContentDone = true;
|
||||||
this.setupRenderLayoutTimer();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
convertMatches: function TextLayerBuilder_convertMatches(matches) {
|
convertMatches: function TextLayerBuilder_convertMatches(matches) {
|
||||||
@ -266,8 +264,9 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
|
|||||||
var bidiTexts = this.textContent.items;
|
var bidiTexts = this.textContent.items;
|
||||||
var textDivs = this.textDivs;
|
var textDivs = this.textDivs;
|
||||||
var prevEnd = null;
|
var prevEnd = null;
|
||||||
|
var pageIdx = this.pageIdx;
|
||||||
var isSelectedPage = (this.findController === null ?
|
var isSelectedPage = (this.findController === null ?
|
||||||
false : (this.pageIdx === this.findController.selected.pageIdx));
|
false : (pageIdx === this.findController.selected.pageIdx));
|
||||||
var selectedMatchIdx = (this.findController === null ?
|
var selectedMatchIdx = (this.findController === null ?
|
||||||
-1 : this.findController.selected.matchIdx);
|
-1 : this.findController.selected.matchIdx);
|
||||||
var highlightAll = (this.findController === null ?
|
var highlightAll = (this.findController === null ?
|
||||||
@ -313,10 +312,9 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
|
|||||||
var isSelected = (isSelectedPage && i === selectedMatchIdx);
|
var isSelected = (isSelectedPage && i === selectedMatchIdx);
|
||||||
var highlightSuffix = (isSelected ? ' selected' : '');
|
var highlightSuffix = (isSelected ? ' selected' : '');
|
||||||
|
|
||||||
if (isSelected && !this.isViewerInPresentationMode) {
|
if (this.findController) {
|
||||||
scrollIntoView(textDivs[begin.divIdx],
|
this.findController.updateMatchPosition(pageIdx, i, textDivs,
|
||||||
{ top: FIND_SCROLL_OFFSET_TOP,
|
begin.divIdx, end.divIdx);
|
||||||
left: FIND_SCROLL_OFFSET_LEFT });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Match inside new div.
|
// Match inside new div.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user