Merge pull request #8324 from timvandermeij/es6-annotation-presentation-rendering

Convert the annotation layer builder, presentation mode and rendering queue to ES6 syntax
This commit is contained in:
Tim van der Meij 2017-04-27 16:30:07 +02:00 committed by GitHub
commit 32c0ea5909
4 changed files with 588 additions and 629 deletions

View File

@ -26,15 +26,11 @@ import { SimpleLinkService } from './pdf_link_service';
* @property {DownloadManager} downloadManager * @property {DownloadManager} downloadManager
*/ */
/** class AnnotationLayerBuilder {
* @class
*/
var AnnotationLayerBuilder = (function AnnotationLayerBuilderClosure() {
/** /**
* @param {AnnotationLayerBuilderOptions} options * @param {AnnotationLayerBuilderOptions} options
* @constructs AnnotationLayerBuilder
*/ */
function AnnotationLayerBuilder(options) { constructor(options) {
this.pageDiv = options.pageDiv; this.pageDiv = options.pageDiv;
this.pdfPage = options.pdfPage; this.pdfPage = options.pdfPage;
this.renderInteractiveForms = options.renderInteractiveForms; this.renderInteractiveForms = options.renderInteractiveForms;
@ -44,32 +40,23 @@ var AnnotationLayerBuilder = (function AnnotationLayerBuilderClosure() {
this.div = null; this.div = null;
} }
AnnotationLayerBuilder.prototype =
/** @lends AnnotationLayerBuilder.prototype */ {
/** /**
* @param {PageViewport} viewport * @param {PageViewport} viewport
* @param {string} intent (default value is 'display') * @param {string} intent (default value is 'display')
*/ */
render: function AnnotationLayerBuilder_render(viewport, intent) { render(viewport, intent = 'display') {
var self = this; this.pdfPage.getAnnotations({ intent }).then((annotations) => {
var parameters = { var parameters = {
intent: (intent === undefined ? 'display' : intent), viewport: viewport.clone({ dontFlip: true }),
div: this.div,
annotations,
page: this.pdfPage,
renderInteractiveForms: this.renderInteractiveForms,
linkService: this.linkService,
downloadManager: this.downloadManager,
}; };
this.pdfPage.getAnnotations(parameters).then(function (annotations) { if (this.div) {
viewport = viewport.clone({ dontFlip: true });
parameters = {
viewport: viewport,
div: self.div,
annotations: annotations,
page: self.pdfPage,
renderInteractiveForms: self.renderInteractiveForms,
linkService: self.linkService,
downloadManager: self.downloadManager,
};
if (self.div) {
// If an annotationLayer already exists, refresh its children's // If an annotationLayer already exists, refresh its children's
// transformation matrices. // transformation matrices.
AnnotationLayer.update(parameters); AnnotationLayer.update(parameters);
@ -80,52 +67,47 @@ var AnnotationLayerBuilder = (function AnnotationLayerBuilderClosure() {
return; return;
} }
self.div = document.createElement('div'); this.div = document.createElement('div');
self.div.className = 'annotationLayer'; this.div.className = 'annotationLayer';
self.pageDiv.appendChild(self.div); this.pageDiv.appendChild(this.div);
parameters.div = self.div; parameters.div = this.div;
AnnotationLayer.render(parameters); AnnotationLayer.render(parameters);
if (typeof mozL10n !== 'undefined') { if (typeof mozL10n !== 'undefined') {
mozL10n.translate(self.div); mozL10n.translate(this.div);
} }
} }
}); });
}, }
hide: function AnnotationLayerBuilder_hide() { hide() {
if (!this.div) { if (!this.div) {
return; return;
} }
this.div.setAttribute('hidden', 'true'); this.div.setAttribute('hidden', 'true');
} }
}; }
return AnnotationLayerBuilder;
})();
/** /**
* @constructor
* @implements IPDFAnnotationLayerFactory * @implements IPDFAnnotationLayerFactory
*/ */
function DefaultAnnotationLayerFactory() {} class DefaultAnnotationLayerFactory {
DefaultAnnotationLayerFactory.prototype = {
/** /**
* @param {HTMLDivElement} pageDiv * @param {HTMLDivElement} pageDiv
* @param {PDFPage} pdfPage * @param {PDFPage} pdfPage
* @param {boolean} renderInteractiveForms * @param {boolean} renderInteractiveForms
* @returns {AnnotationLayerBuilder} * @returns {AnnotationLayerBuilder}
*/ */
createAnnotationLayerBuilder: function (pageDiv, pdfPage, createAnnotationLayerBuilder(pageDiv, pdfPage,
renderInteractiveForms) { renderInteractiveForms = false) {
return new AnnotationLayerBuilder({ return new AnnotationLayerBuilder({
pageDiv: pageDiv, pageDiv,
pdfPage: pdfPage, pdfPage,
renderInteractiveForms: renderInteractiveForms, renderInteractiveForms,
linkService: new SimpleLinkService(), linkService: new SimpleLinkService(),
}); });
} }
}; }
export { export {
AnnotationLayerBuilder, AnnotationLayerBuilder,

View File

@ -108,14 +108,13 @@ IPDFTextLayerFactory.prototype = {
/** /**
* @interface * @interface
*/ */
function IPDFAnnotationLayerFactory() {} class IPDFAnnotationLayerFactory { // eslint-disable-line no-unused-vars
IPDFAnnotationLayerFactory.prototype = {
/** /**
* @param {HTMLDivElement} pageDiv * @param {HTMLDivElement} pageDiv
* @param {PDFPage} pdfPage * @param {PDFPage} pdfPage
* @param {boolean} renderInteractiveForms * @param {boolean} renderInteractiveForms
* @returns {AnnotationLayerBuilder} * @returns {AnnotationLayerBuilder}
*/ */
createAnnotationLayerBuilder: function (pageDiv, pdfPage, createAnnotationLayerBuilder(pageDiv, pdfPage,
renderInteractiveForms) {} renderInteractiveForms = false) {}
}; }

View File

@ -15,10 +15,19 @@
import { normalizeWheelEventDelta } from './ui_utils'; import { normalizeWheelEventDelta } from './ui_utils';
var DELAY_BEFORE_RESETTING_SWITCH_IN_PROGRESS = 1500; // in ms const DELAY_BEFORE_RESETTING_SWITCH_IN_PROGRESS = 1500; // in ms
var DELAY_BEFORE_HIDING_CONTROLS = 3000; // in ms const DELAY_BEFORE_HIDING_CONTROLS = 3000; // in ms
var ACTIVE_SELECTOR = 'pdfPresentationMode'; const ACTIVE_SELECTOR = 'pdfPresentationMode';
var CONTROLS_SELECTOR = 'pdfPresentationModeControls'; const CONTROLS_SELECTOR = 'pdfPresentationModeControls';
const MOUSE_SCROLL_COOLDOWN_TIME = 50; // in ms
const PAGE_SWITCH_THRESHOLD = 0.1;
// Number of CSS pixels for a movement to count as a swipe.
const SWIPE_MIN_DISTANCE_THRESHOLD = 50;
// Swipe angle deviation from the x or y axis before it is not
// considered a swipe in that direction any more.
const SWIPE_ANGLE_THRESHOLD = Math.PI / 6;
/** /**
* @typedef {Object} PDFPresentationModeOptions * @typedef {Object} PDFPresentationModeOptions
@ -30,15 +39,11 @@ var CONTROLS_SELECTOR = 'pdfPresentationModeControls';
* to the context menu in Presentation Mode. * to the context menu in Presentation Mode.
*/ */
/** class PDFPresentationMode {
* @class
*/
var PDFPresentationMode = (function PDFPresentationModeClosure() {
/** /**
* @constructs PDFPresentationMode
* @param {PDFPresentationModeOptions} options * @param {PDFPresentationModeOptions} options
*/ */
function PDFPresentationMode(options) { constructor(options) {
this.container = options.container; this.container = options.container;
this.viewer = options.viewer || options.container.firstElementChild; this.viewer = options.viewer || options.container.firstElementChild;
this.pdfViewer = options.pdfViewer; this.pdfViewer = options.pdfViewer;
@ -53,37 +58,31 @@ var PDFPresentationMode = (function PDFPresentationModeClosure() {
this.touchSwipeState = null; this.touchSwipeState = null;
if (contextMenuItems) { if (contextMenuItems) {
contextMenuItems.contextFirstPage.addEventListener('click', contextMenuItems.contextFirstPage.addEventListener('click', () => {
function PDFPresentationMode_contextFirstPageClick(e) {
this.contextMenuOpen = false; this.contextMenuOpen = false;
this.eventBus.dispatch('firstpage'); this.eventBus.dispatch('firstpage');
}.bind(this)); });
contextMenuItems.contextLastPage.addEventListener('click', contextMenuItems.contextLastPage.addEventListener('click', () => {
function PDFPresentationMode_contextLastPageClick(e) {
this.contextMenuOpen = false; this.contextMenuOpen = false;
this.eventBus.dispatch('lastpage'); this.eventBus.dispatch('lastpage');
}.bind(this)); });
contextMenuItems.contextPageRotateCw.addEventListener('click', contextMenuItems.contextPageRotateCw.addEventListener('click', () => {
function PDFPresentationMode_contextPageRotateCwClick(e) {
this.contextMenuOpen = false; this.contextMenuOpen = false;
this.eventBus.dispatch('rotatecw'); this.eventBus.dispatch('rotatecw');
}.bind(this)); });
contextMenuItems.contextPageRotateCcw.addEventListener('click', contextMenuItems.contextPageRotateCcw.addEventListener('click', () => {
function PDFPresentationMode_contextPageRotateCcwClick(e) {
this.contextMenuOpen = false; this.contextMenuOpen = false;
this.eventBus.dispatch('rotateccw'); this.eventBus.dispatch('rotateccw');
}.bind(this)); });
} }
} }
PDFPresentationMode.prototype = {
/** /**
* Request the browser to enter fullscreen mode. * Request the browser to enter fullscreen mode.
* @returns {boolean} Indicating if the request was successful. * @returns {boolean} Indicating if the request was successful.
*/ */
request: function PDFPresentationMode_request() { request() {
if (this.switchInProgress || this.active || if (this.switchInProgress || this.active || !this.viewer.hasChildNodes()) {
!this.viewer.hasChildNodes()) {
return false; return false;
} }
this._addFullscreenChangeListeners(); this._addFullscreenChangeListeners();
@ -108,12 +107,12 @@ var PDFPresentationMode = (function PDFPresentationModeClosure() {
}; };
return true; return true;
}, }
/** /**
* @private * @private
*/ */
_mouseWheel: function PDFPresentationMode_mouseWheel(evt) { _mouseWheel(evt) {
if (!this.active) { if (!this.active) {
return; return;
} }
@ -121,10 +120,6 @@ var PDFPresentationMode = (function PDFPresentationModeClosure() {
evt.preventDefault(); evt.preventDefault();
var delta = normalizeWheelEventDelta(evt); var delta = normalizeWheelEventDelta(evt);
var MOUSE_SCROLL_COOLDOWN_TIME = 50;
var PAGE_SWITCH_THRESHOLD = 0.1;
var currentTime = (new Date()).getTime(); var currentTime = (new Date()).getTime();
var storedTime = this.mouseScrollTimeStamp; var storedTime = this.mouseScrollTimeStamp;
@ -149,19 +144,17 @@ var PDFPresentationMode = (function PDFPresentationModeClosure() {
this.mouseScrollTimeStamp = currentTime; this.mouseScrollTimeStamp = currentTime;
} }
} }
}, }
get isFullscreen() { get isFullscreen() {
return !!(document.fullscreenElement || return !!(document.fullscreenElement || document.mozFullScreen ||
document.mozFullScreen || document.webkitIsFullScreen || document.msFullscreenElement);
document.webkitIsFullScreen || }
document.msFullscreenElement);
},
/** /**
* @private * @private
*/ */
_goToPreviousPage: function PDFPresentationMode_goToPreviousPage() { _goToPreviousPage() {
var page = this.pdfViewer.currentPageNumber; var page = this.pdfViewer.currentPageNumber;
// If we're at the first page, we don't need to do anything. // If we're at the first page, we don't need to do anything.
if (page <= 1) { if (page <= 1) {
@ -169,12 +162,12 @@ var PDFPresentationMode = (function PDFPresentationModeClosure() {
} }
this.pdfViewer.currentPageNumber = (page - 1); this.pdfViewer.currentPageNumber = (page - 1);
return true; return true;
}, }
/** /**
* @private * @private
*/ */
_goToNextPage: function PDFPresentationMode_goToNextPage() { _goToNextPage() {
var page = this.pdfViewer.currentPageNumber; var page = this.pdfViewer.currentPageNumber;
// If we're at the last page, we don't need to do anything. // If we're at the last page, we don't need to do anything.
if (page >= this.pdfViewer.pagesCount) { if (page >= this.pdfViewer.pagesCount) {
@ -182,18 +175,18 @@ var PDFPresentationMode = (function PDFPresentationModeClosure() {
} }
this.pdfViewer.currentPageNumber = (page + 1); this.pdfViewer.currentPageNumber = (page + 1);
return true; return true;
}, }
/** /**
* @private * @private
*/ */
_notifyStateChange: function PDFPresentationMode_notifyStateChange() { _notifyStateChange() {
this.eventBus.dispatch('presentationmodechanged', { this.eventBus.dispatch('presentationmodechanged', {
source: this, source: this,
active: this.active, active: this.active,
switchInProgress: !!this.switchInProgress switchInProgress: !!this.switchInProgress,
}); });
}, }
/** /**
* Used to initialize a timeout when requesting Presentation Mode, * Used to initialize a timeout when requesting Presentation Mode,
@ -201,34 +194,34 @@ var PDFPresentationMode = (function PDFPresentationModeClosure() {
* This timeout is used to prevent the current page from being scrolled * This timeout is used to prevent the current page from being scrolled
* partially, or completely, out of view when entering Presentation Mode. * partially, or completely, out of view when entering Presentation Mode.
* NOTE: This issue seems limited to certain zoom levels (e.g. page-width). * NOTE: This issue seems limited to certain zoom levels (e.g. page-width).
*
* @private * @private
*/ */
_setSwitchInProgress: function PDFPresentationMode_setSwitchInProgress() { _setSwitchInProgress() {
if (this.switchInProgress) { if (this.switchInProgress) {
clearTimeout(this.switchInProgress); clearTimeout(this.switchInProgress);
} }
this.switchInProgress = setTimeout(function switchInProgressTimeout() { this.switchInProgress = setTimeout(() => {
this._removeFullscreenChangeListeners(); this._removeFullscreenChangeListeners();
delete this.switchInProgress; delete this.switchInProgress;
this._notifyStateChange(); this._notifyStateChange();
}.bind(this), DELAY_BEFORE_RESETTING_SWITCH_IN_PROGRESS); }, DELAY_BEFORE_RESETTING_SWITCH_IN_PROGRESS);
}, }
/** /**
* @private * @private
*/ */
_resetSwitchInProgress: _resetSwitchInProgress() {
function PDFPresentationMode_resetSwitchInProgress() {
if (this.switchInProgress) { if (this.switchInProgress) {
clearTimeout(this.switchInProgress); clearTimeout(this.switchInProgress);
delete this.switchInProgress; delete this.switchInProgress;
} }
}, }
/** /**
* @private * @private
*/ */
_enter: function PDFPresentationMode_enter() { _enter() {
this.active = true; this.active = true;
this._resetSwitchInProgress(); this._resetSwitchInProgress();
this._notifyStateChange(); this._notifyStateChange();
@ -236,10 +229,10 @@ var PDFPresentationMode = (function PDFPresentationModeClosure() {
// Ensure that the correct page is scrolled into view when entering // Ensure that the correct page is scrolled into view when entering
// Presentation Mode, by waiting until fullscreen mode in enabled. // Presentation Mode, by waiting until fullscreen mode in enabled.
setTimeout(function enterPresentationModeTimeout() { setTimeout(() => {
this.pdfViewer.currentPageNumber = this.args.page; this.pdfViewer.currentPageNumber = this.args.page;
this.pdfViewer.currentScaleValue = 'page-fit'; this.pdfViewer.currentScaleValue = 'page-fit';
}.bind(this), 0); }, 0);
this._addWindowListeners(); this._addWindowListeners();
this._showControls(); this._showControls();
@ -250,18 +243,18 @@ var PDFPresentationMode = (function PDFPresentationModeClosure() {
// for the user to deselect text that is selected (e.g. with "Select all") // for the user to deselect text that is selected (e.g. with "Select all")
// when entering Presentation Mode, hence we remove any active selection. // when entering Presentation Mode, hence we remove any active selection.
window.getSelection().removeAllRanges(); window.getSelection().removeAllRanges();
}, }
/** /**
* @private * @private
*/ */
_exit: function PDFPresentationMode_exit() { _exit() {
var page = this.pdfViewer.currentPageNumber; var page = this.pdfViewer.currentPageNumber;
this.container.classList.remove(ACTIVE_SELECTOR); this.container.classList.remove(ACTIVE_SELECTOR);
// Ensure that the correct page is scrolled into view when exiting // Ensure that the correct page is scrolled into view when exiting
// Presentation Mode, by waiting until fullscreen mode is disabled. // Presentation Mode, by waiting until fullscreen mode is disabled.
setTimeout(function exitPresentationModeTimeout() { setTimeout(() => {
this.active = false; this.active = false;
this._removeFullscreenChangeListeners(); this._removeFullscreenChangeListeners();
this._notifyStateChange(); this._notifyStateChange();
@ -269,27 +262,27 @@ var PDFPresentationMode = (function PDFPresentationModeClosure() {
this.pdfViewer.currentScaleValue = this.args.previousScale; this.pdfViewer.currentScaleValue = this.args.previousScale;
this.pdfViewer.currentPageNumber = page; this.pdfViewer.currentPageNumber = page;
this.args = null; this.args = null;
}.bind(this), 0); }, 0);
this._removeWindowListeners(); this._removeWindowListeners();
this._hideControls(); this._hideControls();
this._resetMouseScrollState(); this._resetMouseScrollState();
this.container.removeAttribute('contextmenu'); this.container.removeAttribute('contextmenu');
this.contextMenuOpen = false; this.contextMenuOpen = false;
}, }
/** /**
* @private * @private
*/ */
_mouseDown: function PDFPresentationMode_mouseDown(evt) { _mouseDown(evt) {
if (this.contextMenuOpen) { if (this.contextMenuOpen) {
this.contextMenuOpen = false; this.contextMenuOpen = false;
evt.preventDefault(); evt.preventDefault();
return; return;
} }
if (evt.button === 0) { if (evt.button === 0) {
// Enable clicking of links in presentation mode. Please note: // Enable clicking of links in presentation mode. Note: only links
// Only links pointing to destinations in the current PDF document work. // pointing to destinations in the current PDF document work.
var isInternalLink = (evt.target.href && var isInternalLink = (evt.target.href &&
evt.target.classList.contains('internalLink')); evt.target.classList.contains('internalLink'));
if (!isInternalLink) { if (!isInternalLink) {
@ -298,78 +291,72 @@ var PDFPresentationMode = (function PDFPresentationModeClosure() {
this.pdfViewer.currentPageNumber += (evt.shiftKey ? -1 : 1); this.pdfViewer.currentPageNumber += (evt.shiftKey ? -1 : 1);
} }
} }
}, }
/** /**
* @private * @private
*/ */
_contextMenu: function PDFPresentationMode_contextMenu() { _contextMenu() {
this.contextMenuOpen = true; this.contextMenuOpen = true;
}, }
/** /**
* @private * @private
*/ */
_showControls: function PDFPresentationMode_showControls() { _showControls() {
if (this.controlsTimeout) { if (this.controlsTimeout) {
clearTimeout(this.controlsTimeout); clearTimeout(this.controlsTimeout);
} else { } else {
this.container.classList.add(CONTROLS_SELECTOR); this.container.classList.add(CONTROLS_SELECTOR);
} }
this.controlsTimeout = setTimeout(function showControlsTimeout() { this.controlsTimeout = setTimeout(() => {
this.container.classList.remove(CONTROLS_SELECTOR); this.container.classList.remove(CONTROLS_SELECTOR);
delete this.controlsTimeout; delete this.controlsTimeout;
}.bind(this), DELAY_BEFORE_HIDING_CONTROLS); }, DELAY_BEFORE_HIDING_CONTROLS);
}, }
/** /**
* @private * @private
*/ */
_hideControls: function PDFPresentationMode_hideControls() { _hideControls() {
if (!this.controlsTimeout) { if (!this.controlsTimeout) {
return; return;
} }
clearTimeout(this.controlsTimeout); clearTimeout(this.controlsTimeout);
this.container.classList.remove(CONTROLS_SELECTOR); this.container.classList.remove(CONTROLS_SELECTOR);
delete this.controlsTimeout; delete this.controlsTimeout;
}, }
/** /**
* Resets the properties used for tracking mouse scrolling events. * Resets the properties used for tracking mouse scrolling events.
*
* @private * @private
*/ */
_resetMouseScrollState: _resetMouseScrollState() {
function PDFPresentationMode_resetMouseScrollState() {
this.mouseScrollTimeStamp = 0; this.mouseScrollTimeStamp = 0;
this.mouseScrollDelta = 0; this.mouseScrollDelta = 0;
}, }
/** /**
* @private * @private
*/ */
_touchSwipe: function PDFPresentationMode_touchSwipe(evt) { _touchSwipe(evt) {
if (!this.active) { if (!this.active) {
return; return;
} }
// Must move at least these many CSS pixels for it to count as a swipe
var SWIPE_MIN_DISTANCE_THRESHOLD = 50;
// The swipe angle is allowed to deviate from the x or y axis by this much
// before it is not considered a swipe in that direction any more.
var SWIPE_ANGLE_THRESHOLD = Math.PI / 6;
if (evt.touches.length > 1) { if (evt.touches.length > 1) {
// Multiple touch points detected, cancel the swipe. // Multiple touch points detected; cancel the swipe.
this.touchSwipeState = null; this.touchSwipeState = null;
return; return;
} }
switch (evt.type) { switch (evt.type) {
case 'touchstart': case 'touchstart':
this.touchSwipeState = { this.touchSwipeState = {
startX: evt.touches[0].pageX, startX: evt.touches[0].pageX,
startY: evt.touches[0].pageY, startY: evt.touches[0].pageY,
endX: evt.touches[0].pageX, endX: evt.touches[0].pageX,
endY: evt.touches[0].pageY endY: evt.touches[0].pageY,
}; };
break; break;
case 'touchmove': case 'touchmove':
@ -378,9 +365,8 @@ var PDFPresentationMode = (function PDFPresentationModeClosure() {
} }
this.touchSwipeState.endX = evt.touches[0].pageX; this.touchSwipeState.endX = evt.touches[0].pageX;
this.touchSwipeState.endY = evt.touches[0].pageY; this.touchSwipeState.endY = evt.touches[0].pageY;
// Do a preventDefault to avoid the swipe from triggering browser // Avoid the swipe from triggering browser gestures (Chrome in
// gestures (Chrome in particular has some sort of swipe gesture in // particular has some sort of swipe gesture in fullscreen mode).
// fullscreen mode).
evt.preventDefault(); evt.preventDefault();
break; break;
case 'touchend': case 'touchend':
@ -394,11 +380,11 @@ var PDFPresentationMode = (function PDFPresentationModeClosure() {
if (Math.abs(dx) > SWIPE_MIN_DISTANCE_THRESHOLD && if (Math.abs(dx) > SWIPE_MIN_DISTANCE_THRESHOLD &&
(absAngle <= SWIPE_ANGLE_THRESHOLD || (absAngle <= SWIPE_ANGLE_THRESHOLD ||
absAngle >= (Math.PI - SWIPE_ANGLE_THRESHOLD))) { absAngle >= (Math.PI - SWIPE_ANGLE_THRESHOLD))) {
// horizontal swipe // Horizontal swipe.
delta = dx; delta = dx;
} else if (Math.abs(dy) > SWIPE_MIN_DISTANCE_THRESHOLD && } else if (Math.abs(dy) > SWIPE_MIN_DISTANCE_THRESHOLD &&
Math.abs(absAngle - (Math.PI / 2)) <= SWIPE_ANGLE_THRESHOLD) { Math.abs(absAngle - (Math.PI / 2)) <= SWIPE_ANGLE_THRESHOLD) {
// vertical swipe // Vertical swipe.
delta = dy; delta = dy;
} }
if (delta > 0) { if (delta > 0) {
@ -408,12 +394,12 @@ var PDFPresentationMode = (function PDFPresentationModeClosure() {
} }
break; break;
} }
}, }
/** /**
* @private * @private
*/ */
_addWindowListeners: function PDFPresentationMode_addWindowListeners() { _addWindowListeners() {
this.showControlsBind = this._showControls.bind(this); this.showControlsBind = this._showControls.bind(this);
this.mouseDownBind = this._mouseDown.bind(this); this.mouseDownBind = this._mouseDown.bind(this);
this.mouseWheelBind = this._mouseWheel.bind(this); this.mouseWheelBind = this._mouseWheel.bind(this);
@ -429,13 +415,12 @@ var PDFPresentationMode = (function PDFPresentationModeClosure() {
window.addEventListener('touchstart', this.touchSwipeBind); window.addEventListener('touchstart', this.touchSwipeBind);
window.addEventListener('touchmove', this.touchSwipeBind); window.addEventListener('touchmove', this.touchSwipeBind);
window.addEventListener('touchend', this.touchSwipeBind); window.addEventListener('touchend', this.touchSwipeBind);
}, }
/** /**
* @private * @private
*/ */
_removeWindowListeners: _removeWindowListeners() {
function PDFPresentationMode_removeWindowListeners() {
window.removeEventListener('mousemove', this.showControlsBind); window.removeEventListener('mousemove', this.showControlsBind);
window.removeEventListener('mousedown', this.mouseDownBind); window.removeEventListener('mousedown', this.mouseDownBind);
window.removeEventListener('wheel', this.mouseWheelBind); window.removeEventListener('wheel', this.mouseWheelBind);
@ -451,24 +436,23 @@ var PDFPresentationMode = (function PDFPresentationModeClosure() {
delete this.resetMouseScrollStateBind; delete this.resetMouseScrollStateBind;
delete this.contextMenuBind; delete this.contextMenuBind;
delete this.touchSwipeBind; delete this.touchSwipeBind;
}, }
/** /**
* @private * @private
*/ */
_fullscreenChange: function PDFPresentationMode_fullscreenChange() { _fullscreenChange() {
if (this.isFullscreen) { if (this.isFullscreen) {
this._enter(); this._enter();
} else { } else {
this._exit(); this._exit();
} }
}, }
/** /**
* @private * @private
*/ */
_addFullscreenChangeListeners: _addFullscreenChangeListeners() {
function PDFPresentationMode_addFullscreenChangeListeners() {
this.fullscreenChangeBind = this._fullscreenChange.bind(this); this.fullscreenChangeBind = this._fullscreenChange.bind(this);
window.addEventListener('fullscreenchange', this.fullscreenChangeBind); window.addEventListener('fullscreenchange', this.fullscreenChangeBind);
@ -480,13 +464,12 @@ var PDFPresentationMode = (function PDFPresentationModeClosure() {
window.addEventListener('MSFullscreenChange', window.addEventListener('MSFullscreenChange',
this.fullscreenChangeBind); this.fullscreenChangeBind);
} }
}, }
/** /**
* @private * @private
*/ */
_removeFullscreenChangeListeners: _removeFullscreenChangeListeners() {
function PDFPresentationMode_removeFullscreenChangeListeners() {
window.removeEventListener('fullscreenchange', this.fullscreenChangeBind); window.removeEventListener('fullscreenchange', this.fullscreenChangeBind);
window.removeEventListener('mozfullscreenchange', window.removeEventListener('mozfullscreenchange',
this.fullscreenChangeBind); this.fullscreenChangeBind);
@ -500,10 +483,7 @@ var PDFPresentationMode = (function PDFPresentationModeClosure() {
delete this.fullscreenChangeBind; delete this.fullscreenChangeBind;
} }
}; }
return PDFPresentationMode;
})();
export { export {
PDFPresentationMode, PDFPresentationMode,

View File

@ -13,60 +13,55 @@
* limitations under the License. * limitations under the License.
*/ */
var CLEANUP_TIMEOUT = 30000; const CLEANUP_TIMEOUT = 30000;
var RenderingStates = { const RenderingStates = {
INITIAL: 0, INITIAL: 0,
RUNNING: 1, RUNNING: 1,
PAUSED: 2, PAUSED: 2,
FINISHED: 3 FINISHED: 3,
}; };
/** /**
* Controls rendering of the views for pages and thumbnails. * Controls rendering of the views for pages and thumbnails.
* @class
*/ */
var PDFRenderingQueue = (function PDFRenderingQueueClosure() { class PDFRenderingQueue {
/** constructor() {
* @constructs
*/
function PDFRenderingQueue() {
this.pdfViewer = null; this.pdfViewer = null;
this.pdfThumbnailViewer = null; this.pdfThumbnailViewer = null;
this.onIdle = null; this.onIdle = null;
this.highestPriorityPage = null; this.highestPriorityPage = null;
this.idleTimeout = null; this.idleTimeout = null;
this.printing = false; this.printing = false;
this.isThumbnailViewEnabled = false; this.isThumbnailViewEnabled = false;
} }
PDFRenderingQueue.prototype = /** @lends PDFRenderingQueue.prototype */ {
/** /**
* @param {PDFViewer} pdfViewer * @param {PDFViewer} pdfViewer
*/ */
setViewer: function PDFRenderingQueue_setViewer(pdfViewer) { setViewer(pdfViewer) {
this.pdfViewer = pdfViewer; this.pdfViewer = pdfViewer;
}, }
/** /**
* @param {PDFThumbnailViewer} pdfThumbnailViewer * @param {PDFThumbnailViewer} pdfThumbnailViewer
*/ */
setThumbnailViewer: setThumbnailViewer(pdfThumbnailViewer) {
function PDFRenderingQueue_setThumbnailViewer(pdfThumbnailViewer) {
this.pdfThumbnailViewer = pdfThumbnailViewer; this.pdfThumbnailViewer = pdfThumbnailViewer;
}, }
/** /**
* @param {IRenderableView} view * @param {IRenderableView} view
* @returns {boolean} * @returns {boolean}
*/ */
isHighestPriority: function PDFRenderingQueue_isHighestPriority(view) { isHighestPriority(view) {
return this.highestPriorityPage === view.renderingId; return this.highestPriorityPage === view.renderingId;
}, }
renderHighestPriority: function /**
PDFRenderingQueue_renderHighestPriority(currentlyVisiblePages) { * @param {Object} currentlyVisiblePages
*/
renderHighestPriority(currentlyVisiblePages) {
if (this.idleTimeout) { if (this.idleTimeout) {
clearTimeout(this.idleTimeout); clearTimeout(this.idleTimeout);
this.idleTimeout = null; this.idleTimeout = null;
@ -76,7 +71,7 @@ var PDFRenderingQueue = (function PDFRenderingQueueClosure() {
if (this.pdfViewer.forceRendering(currentlyVisiblePages)) { if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
return; return;
} }
// No pages needed rendering so check thumbnails. // No pages needed rendering, so check thumbnails.
if (this.pdfThumbnailViewer && this.isThumbnailViewEnabled) { if (this.pdfThumbnailViewer && this.isThumbnailViewEnabled) {
if (this.pdfThumbnailViewer.forceRendering()) { if (this.pdfThumbnailViewer.forceRendering()) {
return; return;
@ -91,16 +86,23 @@ var PDFRenderingQueue = (function PDFRenderingQueueClosure() {
if (this.onIdle) { if (this.onIdle) {
this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT); this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT);
} }
}, }
getHighestPriority: function /**
PDFRenderingQueue_getHighestPriority(visible, views, scrolledDown) { * @param {Object} visible
// The state has changed figure out which page has the highest priority to * @param {Array} views
// render next (if any). * @param {boolean} scrolledDown
// Priority: */
// 1 visible pages getHighestPriority(visible, views, scrolledDown) {
// 2 if last scrolled down page after the visible pages /**
// 2 if last scrolled up page before the visible pages * The state has changed. Figure out which page has the highest priority to
* render next (if any).
*
* Priority:
* 1. visible pages
* 2. if last scrolled down, the page after the visible pages, or
* if last scrolled up, the page before the visible pages
*/
var visibleViews = visible.views; var visibleViews = visible.views;
var numVisible = visibleViews.length; var numVisible = visibleViews.length;
@ -114,12 +116,11 @@ var PDFRenderingQueue = (function PDFRenderingQueueClosure() {
} }
} }
// All the visible views have rendered, try to render next/previous pages. // All the visible views have rendered; try to render next/previous pages.
if (scrolledDown) { if (scrolledDown) {
var nextPageIndex = visible.last.id; var nextPageIndex = visible.last.id;
// ID's start at 1 so no need to add 1. // IDs start at 1, so no need to add 1.
if (views[nextPageIndex] && if (views[nextPageIndex] && !this.isViewFinished(views[nextPageIndex])) {
!this.isViewFinished(views[nextPageIndex])) {
return views[nextPageIndex]; return views[nextPageIndex];
} }
} else { } else {
@ -131,25 +132,25 @@ var PDFRenderingQueue = (function PDFRenderingQueueClosure() {
} }
// Everything that needs to be rendered has been. // Everything that needs to be rendered has been.
return null; return null;
}, }
/** /**
* @param {IRenderableView} view * @param {IRenderableView} view
* @returns {boolean} * @returns {boolean}
*/ */
isViewFinished: function PDFRenderingQueue_isViewFinished(view) { isViewFinished(view) {
return view.renderingState === RenderingStates.FINISHED; return view.renderingState === RenderingStates.FINISHED;
}, }
/** /**
* Render a page or thumbnail view. This calls the appropriate function * Render a page or thumbnail view. This calls the appropriate function
* based on the views state. If the view is already rendered it will return * based on the views state. If the view is already rendered it will return
* false. * `false`.
*
* @param {IRenderableView} view * @param {IRenderableView} view
*/ */
renderView: function PDFRenderingQueue_renderView(view) { renderView(view) {
var state = view.renderingState; switch (view.renderingState) {
switch (state) {
case RenderingStates.FINISHED: case RenderingStates.FINISHED:
return false; return false;
case RenderingStates.PAUSED: case RenderingStates.PAUSED:
@ -161,18 +162,15 @@ var PDFRenderingQueue = (function PDFRenderingQueueClosure() {
break; break;
case RenderingStates.INITIAL: case RenderingStates.INITIAL:
this.highestPriorityPage = view.renderingId; this.highestPriorityPage = view.renderingId;
var continueRendering = function () { var continueRendering = () => {
this.renderHighestPriority(); this.renderHighestPriority();
}.bind(this); };
view.draw().then(continueRendering, continueRendering); view.draw().then(continueRendering, continueRendering);
break; break;
} }
return true; return true;
}, }
}; }
return PDFRenderingQueue;
})();
export { export {
RenderingStates, RenderingStates,