[Pkg-javascript-commits] [pdf.js] 114/204: Removes PresentationMode dependency from PDFViewer

David Prévot taffit at moszumanska.debian.org
Sat Oct 25 18:50:40 UTC 2014


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

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

commit fbd7eedce8d945ea3c14191a61b4329631f429e2
Author: Yury Delendik <ydelendik at mozilla.com>
Date:   Mon Sep 15 12:37:03 2014 -0500

    Removes PresentationMode dependency from PDFViewer
---
 web/page_view.js         | 13 ++++++++-----
 web/pdf_viewer.js        | 35 ++++++++++++++++++++++-------------
 web/presentation_mode.js | 14 ++++++++++++++
 web/viewer.js            | 10 +++++++++-
 4 files changed, 53 insertions(+), 19 deletions(-)

diff --git a/web/page_view.js b/web/page_view.js
index c6cc9e3..583cba5 100644
--- a/web/page_view.js
+++ b/web/page_view.js
@@ -15,9 +15,9 @@
  * limitations under the License.
  */
 /* globals RenderingStates, PDFView, PDFJS, mozL10n, CustomStyle,
-           PresentationMode, scrollIntoView, SCROLLBAR_PADDING, CSS_UNITS,
-           UNKNOWN_SCALE, DEFAULT_SCALE, getOutputScale, TextLayerBuilder,
-           Stats */
+           SCROLLBAR_PADDING, CSS_UNITS, UNKNOWN_SCALE, DEFAULT_SCALE,
+           getOutputScale, TextLayerBuilder, scrollIntoView, Stats,
+           PresentationModeState */
 
 'use strict';
 
@@ -346,7 +346,8 @@ var PageView = function pageView(container, id, scale, defaultViewport,
   };
 
   this.scrollIntoView = function pageViewScrollIntoView(dest) {
-    if (PresentationMode.active) {
+    if (this.viewer.presentationModeState ===
+        PresentationModeState.FULLSCREEN) {
       if (this.linkService.page !== this.id) {
         // Avoid breaking getVisiblePages in presentation mode.
         this.linkService.page = this.id;
@@ -520,13 +521,15 @@ var PageView = function pageView(container, id, scale, defaultViewport,
         div.appendChild(textLayerDiv);
       }
     }
+    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: PresentationMode.active,
+        isViewerInPresentationMode: isViewerInPresentationMode,
         findController: PDFView.findController
       }) : null;
     // TODO(mack): use data attributes to store these
diff --git a/web/pdf_viewer.js b/web/pdf_viewer.js
index 8e6105d..1f5ac7c 100644
--- a/web/pdf_viewer.js
+++ b/web/pdf_viewer.js
@@ -16,11 +16,18 @@
  */
  /*globals watchScroll, Cache, DEFAULT_CACHE_SIZE, PageView, UNKNOWN_SCALE,
            IGNORE_CURRENT_POSITION_ON_ZOOM, SCROLLBAR_PADDING, VERTICAL_PADDING,
-           MAX_AUTO_SCALE, getVisibleElements, PresentationMode,
-           RenderingStates, Promise, CSS_UNITS, PDFJS */
+           MAX_AUTO_SCALE, getVisibleElements, RenderingStates, Promise,
+           CSS_UNITS, PDFJS */
 
 'use strict';
 
+var PresentationModeState = {
+  UNKNOWN: 0,
+  NORMAL: 1,
+  CHANGING: 2,
+  FULLSCREEN: 3,
+};
+
 var PDFViewer = (function pdfViewer() {
   function PDFViewer(options) {
     this.container = options.container;
@@ -30,6 +37,7 @@ var PDFViewer = (function pdfViewer() {
 
     this.scroll = watchScroll(this.container, this._scrollUpdate.bind(this));
     this.updateInProgress = false;
+    this.presentationModeState = PresentationModeState.UNKNOWN;
     this.resetView();
   }
 
@@ -191,7 +199,10 @@ var PDFViewer = (function pdfViewer() {
 
       if (!noScroll) {
         var page = this.currentPageNumber, dest;
-        if (this.location && !this.inPresentationMode &&
+        var inPresentationMode =
+          this.presentationModeState === PresentationModeState.CHANGING ||
+          this.presentationModeState === PresentationModeState.FULLSCREEN;
+        if (this.location && !inPresentationMode &&
           !IGNORE_CURRENT_POSITION_ON_ZOOM) {
           page = this.location.pageNumber;
           dest = [null, { name: 'XYZ' }, this.location.left,
@@ -223,8 +234,10 @@ var PDFViewer = (function pdfViewer() {
         if (!currentPage) {
           return;
         }
-        var hPadding = PresentationMode.active ? 0 : SCROLLBAR_PADDING;
-        var vPadding = PresentationMode.active ? 0 : VERTICAL_PADDING;
+        var inPresentationMode =
+          this.presentationModeState === PresentationModeState.FULLSCREEN;
+        var hPadding = inPresentationMode ? 0 : SCROLLBAR_PADDING;
+        var vPadding = inPresentationMode ? 0 : VERTICAL_PADDING;
         var pageWidthScale = (this.container.clientWidth - hPadding) /
                              currentPage.width * currentPage.scale;
         var pageHeightScale = (this.container.clientHeight - vPadding) /
@@ -295,10 +308,6 @@ var PDFViewer = (function pdfViewer() {
       };
     },
 
-    get inPresentationMode() {
-      return PresentationMode.active || PresentationMode.switchInProgress;
-    },
-
     update: function () {
       var visible = this.getVisiblePages();
       var visiblePages = visible.views;
@@ -334,7 +343,7 @@ var PDFViewer = (function pdfViewer() {
         currentId = visiblePages[0].id;
       }
 
-      if (!PresentationMode.active) {
+      if (this.presentationModeState !== PresentationModeState.FULLSCREEN) {
         this.setCurrentPageNumber(currentId);
       }
 
@@ -360,12 +369,12 @@ var PDFViewer = (function pdfViewer() {
     },
 
     get isHorizontalScrollbarEnabled() {
-      return (PresentationMode.active ? false :
-        (this.container.scrollWidth > this.container.clientWidth));
+      return (this.presentationModeState === PresentationModeState.FULLSCREEN ?
+        false : (this.container.scrollWidth > this.container.clientWidth));
     },
 
     getVisiblePages: function () {
-      if (!PresentationMode.active) {
+      if (this.presentationModeState !== PresentationModeState.FULLSCREEN) {
         return getVisibleElements(this.container, this.pages, true);
       } else {
         // The algorithm in getVisibleElements doesn't work in all browsers and
diff --git a/web/presentation_mode.js b/web/presentation_mode.js
index f297623..ee4e781 100644
--- a/web/presentation_mode.js
+++ b/web/presentation_mode.js
@@ -81,6 +81,7 @@ var PresentationMode = {
     }
     this.switchInProgress = setTimeout(function switchInProgressTimeout() {
       delete this.switchInProgress;
+      this._notifyStateChange();
     }.bind(this), DELAY_BEFORE_RESETTING_SWITCH_IN_PROGRESS);
   },
 
@@ -97,6 +98,7 @@ var PresentationMode = {
       return false;
     }
     this._setSwitchInProgress();
+    this._notifyStateChange();
 
     if (this.container.requestFullscreen) {
       this.container.requestFullscreen();
@@ -118,9 +120,19 @@ var PresentationMode = {
     return true;
   },
 
+  _notifyStateChange: function presentationModeNotifyStateChange() {
+    var event = document.createEvent('CustomEvent');
+    event.initCustomEvent('presentationmodechanged', true, true, {
+      active: PresentationMode.active,
+      switchInProgress: !!PresentationMode.switchInProgress
+    });
+    window.dispatchEvent(event);
+  },
+
   enter: function presentationModeEnter() {
     this.active = true;
     this._resetSwitchInProgress();
+    this._notifyStateChange();
 
     // Ensure that the correct page is scrolled into view when entering
     // Presentation Mode, by waiting until fullscreen mode in enabled.
@@ -148,6 +160,8 @@ var PresentationMode = {
     // Note: This is only necessary in non-Mozilla browsers.
     setTimeout(function exitPresentationModeTimeout() {
       this.active = false;
+      this._notifyStateChange();
+
       PDFView.setScale(this.args.previousScale, true);
       PDFView.page = page;
       this.args = null;
diff --git a/web/viewer.js b/web/viewer.js
index 43b0fea..00ba94f 100644
--- a/web/viewer.js
+++ b/web/viewer.js
@@ -21,7 +21,7 @@
            PasswordPrompt, PresentationMode, HandTool, Promise,
            DocumentProperties, DocumentOutlineView, DocumentAttachmentsView,
            OverlayManager, PDFFindController, PDFFindBar, getVisibleElements,
-           watchScroll, PDFViewer, PDFRenderingQueue */
+           watchScroll, PDFViewer, PDFRenderingQueue, PresentationModeState */
 
 'use strict';
 
@@ -1668,6 +1668,14 @@ document.addEventListener('pagerendered', function (e) {
   thumbnailView.setImage(pageView.canvas);
 }, true);
 
+window.addEventListener('presentationmodechanged', function (e) {
+  var active = e.detail.active;
+  var switchInProgress = e.detail.switchInProgress;
+  PDFView.pdfViewer.presentationModeState =
+    switchInProgress ? PresentationModeState.CHANGING :
+    active ? PresentationModeState.FULLSCREEN : PresentationModeState.NORMAL;
+});
+
 function updateViewarea() {
   if (!PDFView.initialized) {
     return;

-- 
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