[Pkg-javascript-commits] [pdf.js] 76/119: Move the PresentationMode-specific scrollWheel code from PDFViewerApplication

David Prévot taffit at moszumanska.debian.org
Wed May 13 21:27:43 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository pdf.js.

commit 95b2ec124bb8bdcfabfc69e377b7d28e9dcab569
Author: Jonas Jenwald <jonas.jenwald at gmail.com>
Date:   Sat Jan 31 16:46:23 2015 +0100

    Move the PresentationMode-specific scrollWheel code from PDFViewerApplication
---
 web/presentation_mode.js | 77 +++++++++++++++++++++++++++++++++++++++++++++++-
 web/viewer.js            | 75 ++++------------------------------------------
 2 files changed, 82 insertions(+), 70 deletions(-)

diff --git a/web/presentation_mode.js b/web/presentation_mode.js
index 6c4fe46..6fc223b 100644
--- a/web/presentation_mode.js
+++ b/web/presentation_mode.js
@@ -30,6 +30,8 @@ var PresentationMode = {
 //#if (GENERIC || CHROME)
   prevCoords: { x: null, y: null },
 //#endif
+  mouseScrollTimeStamp: 0,
+  mouseScrollDelta: 0,
 
   initialize: function presentationModeInitialize(options) {
     this.initialized = true;
@@ -146,6 +148,7 @@ var PresentationMode = {
 
     window.addEventListener('mousemove', this.mouseMove, false);
     window.addEventListener('mousedown', this.mouseDown, false);
+    window.addEventListener('keydown', this.keyDown, false);
     window.addEventListener('contextmenu', this.contextMenu, false);
 
     this.showControls();
@@ -175,10 +178,11 @@ var PresentationMode = {
 
     window.removeEventListener('mousemove', this.mouseMove, false);
     window.removeEventListener('mousedown', this.mouseDown, false);
+    window.removeEventListener('keydown', this.keyDown, false);
     window.removeEventListener('contextmenu', this.contextMenu, false);
 
     this.hideControls();
-    PDFViewerApplication.clearMouseScrollState();
+    this.clearMouseScrollState();
     this.container.removeAttribute('contextmenu');
     this.contextMenuOpen = false;
 
@@ -246,8 +250,79 @@ var PresentationMode = {
     }
   },
 
+  keyDown: function presentationModeKeyDown(evt) {
+    PresentationMode.clearMouseScrollState();
+  },
+
   contextMenu: function presentationModeContextMenu(evt) {
     PresentationMode.contextMenuOpen = true;
+  },
+
+  /**
+   * 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.
+   * @param {number} mouseScrollDelta The delta value from the mouse event.
+   */
+  mouseScroll: function presentationModeMouseScroll(mouseScrollDelta) {
+    if (!this.initialized) {
+      return;
+    }
+    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) {
+      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 = PDFViewerApplication.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 === PDFViewerApplication.pagesCount &&
+           pageFlipDirection === PageFlipDirection.DOWN)) {
+        return;
+      }
+
+      PDFViewerApplication.page += pageFlipDirection;
+      this.mouseScrollTimeStamp = currentTime;
+    }
+  },
+
+  /**
+   * This function clears the member attributes used with mouse scrolling in
+   * presentation mode.
+   */
+  clearMouseScrollState: function presentationModeClearMouseScrollState() {
+    this.mouseScrollTimeStamp = 0;
+    this.mouseScrollDelta = 0;
   }
 };
 
diff --git a/web/viewer.js b/web/viewer.js
index b80d978..994835d 100644
--- a/web/viewer.js
+++ b/web/viewer.js
@@ -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();
   }
 });
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git



More information about the Pkg-javascript-commits mailing list