Move the PresentationMode-specific scrollWheel code from PDFViewerApplication

This commit is contained in:
Jonas Jenwald 2015-01-31 16:46:23 +01:00
parent 2dc1af8028
commit 95b2ec124b
2 changed files with 82 additions and 70 deletions

View file

@ -111,8 +111,6 @@ var PDFViewerApplication = {
updateScaleControls: true,
isInitialViewSet: false,
animationStartedPromise: null,
mouseScrollTimeStamp: 0,
mouseScrollDelta: 0,
preferenceSidebarViewOnLoad: SidebarView.NONE,
preferencePdfBugEnabled: false,
preferenceShowPreviousViewOnLoad: true,
@ -1342,72 +1340,11 @@ var PDFViewerApplication = {
PresentationMode.request();
},
/**
* This function flips the page in presentation mode if the user scrolls up
* or down with large enough motion and prevents page flipping too often.
*
* @this {PDFView}
* @param {number} mouseScrollDelta The delta value from the mouse event.
*/
mouseScroll: function pdfViewMouseScroll(mouseScrollDelta) {
var MOUSE_SCROLL_COOLDOWN_TIME = 50;
var currentTime = (new Date()).getTime();
var storedTime = this.mouseScrollTimeStamp;
// In case one page has already been flipped there is a cooldown time
// which has to expire before next page can be scrolled on to.
if (currentTime > storedTime &&
currentTime - storedTime < MOUSE_SCROLL_COOLDOWN_TIME) {
scrollPresentationMode: function pdfViewScrollPresentationMode(delta) {
if (!this.supportsFullscreen) {
return;
}
// In case the user decides to scroll to the opposite direction than before
// clear the accumulated delta.
if ((this.mouseScrollDelta > 0 && mouseScrollDelta < 0) ||
(this.mouseScrollDelta < 0 && mouseScrollDelta > 0)) {
this.clearMouseScrollState();
}
this.mouseScrollDelta += mouseScrollDelta;
var PAGE_FLIP_THRESHOLD = 120;
if (Math.abs(this.mouseScrollDelta) >= PAGE_FLIP_THRESHOLD) {
var PageFlipDirection = {
UP: -1,
DOWN: 1
};
// In presentation mode scroll one page at a time.
var pageFlipDirection = (this.mouseScrollDelta > 0) ?
PageFlipDirection.UP :
PageFlipDirection.DOWN;
this.clearMouseScrollState();
var currentPage = this.page;
// In case we are already on the first or the last page there is no need
// to do anything.
if ((currentPage === 1 && pageFlipDirection === PageFlipDirection.UP) ||
(currentPage === this.pagesCount &&
pageFlipDirection === PageFlipDirection.DOWN)) {
return;
}
this.page += pageFlipDirection;
this.mouseScrollTimeStamp = currentTime;
}
},
/**
* This function clears the member attributes used with mouse scrolling in
* presentation mode.
*
* @this {PDFView}
*/
clearMouseScrollState: function pdfViewClearMouseScrollState() {
this.mouseScrollTimeStamp = 0;
this.mouseScrollDelta = 0;
PresentationMode.mouseScroll(delta);
}
};
//#if GENERIC
@ -1986,9 +1923,10 @@ function handleMouseWheel(evt) {
if (PDFViewerApplication.pdfViewer.isInPresentationMode) {
evt.preventDefault();
PDFViewerApplication.mouseScroll(ticks * MOUSE_WHEEL_DELTA_FACTOR);
PDFViewerApplication.scrollPresentationMode(ticks *
MOUSE_WHEEL_DELTA_FACTOR);
} else if (evt.ctrlKey || evt.metaKey) {
// Only zoom the pages, not the entire viewer
// Only zoom the pages, not the entire viewer.
evt.preventDefault();
PDFViewerApplication[direction](Math.abs(ticks));
}
@ -2256,7 +2194,6 @@ window.addEventListener('keydown', function keydown(evt) {
if (handled) {
evt.preventDefault();
PDFViewerApplication.clearMouseScrollState();
}
});