[Pkg-javascript-commits] [pdf.js] 143/204: Moves scrollPageIntoView to the PDFViewer.

David Prévot taffit at moszumanska.debian.org
Sat Oct 25 18:50:43 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 374b94381d298c2de9ecc18bb23acbaad70f2a64
Author: Yury Delendik <ydelendik at mozilla.com>
Date:   Tue Sep 30 07:13:46 2014 -0500

    Moves scrollPageIntoView to the PDFViewer.
---
 web/page_view.js           |  95 +---------------------------------------
 web/pdf_find_controller.js |   2 +-
 web/pdf_viewer.js          | 106 +++++++++++++++++++++++++++++++++++++++++++--
 web/viewer.js              |  22 +++-------
 4 files changed, 113 insertions(+), 112 deletions(-)

diff --git a/web/page_view.js b/web/page_view.js
index 3db952f..92ed39b 100644
--- a/web/page_view.js
+++ b/web/page_view.js
@@ -14,9 +14,8 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals RenderingStates, PDFJS, mozL10n, CustomStyle,
-           SCROLLBAR_PADDING, CSS_UNITS, UNKNOWN_SCALE, DEFAULT_SCALE,
-           getOutputScale, scrollIntoView, Stats, PresentationModeState */
+/* globals RenderingStates, PDFJS, mozL10n, CustomStyle, getOutputScale, Stats,
+           CSS_UNITS */
 
 'use strict';
 
@@ -358,96 +357,6 @@ var PageView = function pageView(container, id, scale, defaultViewport,
     return this.viewport.convertToPdfPoint(x, y);
   };
 
-  this.scrollIntoView = function pageViewScrollIntoView(dest) {
-    if (this.viewer.presentationModeState ===
-        PresentationModeState.FULLSCREEN) {
-      if (this.linkService.page !== this.id) {
-        // Avoid breaking getVisiblePages in presentation mode.
-        this.linkService.page = this.id;
-        return;
-      }
-      dest = null;
-      // Fixes the case when PDF has different page sizes.
-      this.viewer._setScale(this.viewer.currentScaleValue, true);
-    }
-    if (!dest) {
-      scrollIntoView(div);
-      return;
-    }
-
-    var x = 0, y = 0;
-    var width = 0, height = 0, widthScale, heightScale;
-    var changeOrientation = (this.rotation % 180 === 0 ? false : true);
-    var pageWidth = (changeOrientation ? this.height : this.width) /
-      this.scale / CSS_UNITS;
-    var pageHeight = (changeOrientation ? this.width : this.height) /
-      this.scale / CSS_UNITS;
-    var scale = 0;
-    switch (dest[1].name) {
-      case 'XYZ':
-        x = dest[2];
-        y = dest[3];
-        scale = dest[4];
-        // If x and/or y coordinates are not supplied, default to
-        // _top_ left of the page (not the obvious bottom left,
-        // since aligning the bottom of the intended page with the
-        // top of the window is rarely helpful).
-        x = x !== null ? x : 0;
-        y = y !== null ? y : pageHeight;
-        break;
-      case 'Fit':
-      case 'FitB':
-        scale = 'page-fit';
-        break;
-      case 'FitH':
-      case 'FitBH':
-        y = dest[2];
-        scale = 'page-width';
-        break;
-      case 'FitV':
-      case 'FitBV':
-        x = dest[2];
-        width = pageWidth;
-        height = pageHeight;
-        scale = 'page-height';
-        break;
-      case 'FitR':
-        x = dest[2];
-        y = dest[3];
-        width = dest[4] - x;
-        height = dest[5] - y;
-        var viewerContainer = this.viewer.container;
-        widthScale = (viewerContainer.clientWidth - SCROLLBAR_PADDING) /
-          width / CSS_UNITS;
-        heightScale = (viewerContainer.clientHeight - SCROLLBAR_PADDING) /
-          height / CSS_UNITS;
-        scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
-        break;
-      default:
-        return;
-    }
-
-    if (scale && scale !== this.viewer.currentScale) {
-      this.viewer.currentScaleValue = scale;
-    } else if (this.viewer.currentScale === UNKNOWN_SCALE) {
-      this.viewer.currentScaleValue = DEFAULT_SCALE;
-    }
-
-    if (scale === 'page-fit' && !dest[4]) {
-      scrollIntoView(div);
-      return;
-    }
-
-    var boundingRect = [
-      this.viewport.convertToViewportPoint(x, y),
-      this.viewport.convertToViewportPoint(x + width, y + height)
-    ];
-    var left = Math.min(boundingRect[0][0], boundingRect[1][0]);
-    var top = Math.min(boundingRect[0][1], boundingRect[1][1]);
-
-    scrollIntoView(div, { left: left, top: top });
-  };
-
   this.draw = function pageviewDraw(callback) {
     var pdfPage = this.pdfPage;
 
diff --git a/web/pdf_find_controller.js b/web/pdf_find_controller.js
index 1b2dc64..9de1d04 100644
--- a/web/pdf_find_controller.js
+++ b/web/pdf_find_controller.js
@@ -202,7 +202,7 @@ var PDFFindController = (function PDFFindControllerClosure() {
         // If the page is selected, scroll the page into view, which triggers
         // rendering the page, which adds the textLayer. Once the textLayer is
         // build, it will scroll onto the selected match.
-        page.scrollIntoView();
+        this.pdfViewer.scrollPageIntoView(index + 1);
       }
 
       if (page.textLayer) {
diff --git a/web/pdf_viewer.js b/web/pdf_viewer.js
index 7645282..146c02e 100644
--- a/web/pdf_viewer.js
+++ b/web/pdf_viewer.js
@@ -16,8 +16,8 @@
  */
  /*globals watchScroll, Cache, DEFAULT_CACHE_SIZE, PageView, UNKNOWN_SCALE,
            SCROLLBAR_PADDING, VERTICAL_PADDING, MAX_AUTO_SCALE, CSS_UNITS,
-           getVisibleElements, RenderingStates, Promise,
-           PDFJS, TextLayerBuilder, PDFRenderingQueue */
+           DEFAULT_SCALE, scrollIntoView, getVisibleElements, RenderingStates,
+           PDFJS, Promise, TextLayerBuilder, PDFRenderingQueue */
 
 'use strict';
 
@@ -322,7 +322,7 @@ var PDFViewer = (function pdfViewer() {
           dest = [null, { name: 'XYZ' }, this.location.left,
             this.location.top, null];
         }
-        this.pages[page - 1].scrollIntoView(dest);
+        this.scrollPageIntoView(page, dest);
       }
 
       var event = document.createEvent('UIEvents');
@@ -383,6 +383,106 @@ var PDFViewer = (function pdfViewer() {
       }
     },
 
+    /**
+     * Scrolls page into view.
+     * @param {number} pageNumber
+     * @param {Array} dest - (optional) original PDF destination array:
+     *   <page-ref> </XYZ|FitXXX> <args..>
+     */
+    scrollPageIntoView: function PDFViewer_scrollPageIntoView(pageNumber,
+                                                              dest) {
+      var pageView = this.pages[pageNumber - 1];
+      var pageViewDiv = pageView.el;
+
+      if (this.presentationModeState ===
+        PresentationModeState.FULLSCREEN) {
+        if (this.linkService.page !== pageView.id) {
+          // Avoid breaking getVisiblePages in presentation mode.
+          this.linkService.page = pageView.id;
+          return;
+        }
+        dest = null;
+        // Fixes the case when PDF has different page sizes.
+        this._setScale(this.currentScaleValue, true);
+      }
+      if (!dest) {
+        scrollIntoView(pageViewDiv);
+        return;
+      }
+
+      var x = 0, y = 0;
+      var width = 0, height = 0, widthScale, heightScale;
+      var changeOrientation = (pageView.rotation % 180 === 0 ? false : true);
+      var pageWidth = (changeOrientation ? pageView.height : pageView.width) /
+        pageView.scale / CSS_UNITS;
+      var pageHeight = (changeOrientation ? pageView.width : pageView.height) /
+        pageView.scale / CSS_UNITS;
+      var scale = 0;
+      switch (dest[1].name) {
+        case 'XYZ':
+          x = dest[2];
+          y = dest[3];
+          scale = dest[4];
+          // If x and/or y coordinates are not supplied, default to
+          // _top_ left of the page (not the obvious bottom left,
+          // since aligning the bottom of the intended page with the
+          // top of the window is rarely helpful).
+          x = x !== null ? x : 0;
+          y = y !== null ? y : pageHeight;
+          break;
+        case 'Fit':
+        case 'FitB':
+          scale = 'page-fit';
+          break;
+        case 'FitH':
+        case 'FitBH':
+          y = dest[2];
+          scale = 'page-width';
+          break;
+        case 'FitV':
+        case 'FitBV':
+          x = dest[2];
+          width = pageWidth;
+          height = pageHeight;
+          scale = 'page-height';
+          break;
+        case 'FitR':
+          x = dest[2];
+          y = dest[3];
+          width = dest[4] - x;
+          height = dest[5] - y;
+          var viewerContainer = this.container;
+          widthScale = (viewerContainer.clientWidth - SCROLLBAR_PADDING) /
+            width / CSS_UNITS;
+          heightScale = (viewerContainer.clientHeight - SCROLLBAR_PADDING) /
+            height / CSS_UNITS;
+          scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
+          break;
+        default:
+          return;
+      }
+
+      if (scale && scale !== this.currentScale) {
+        this.currentScaleValue = scale;
+      } else if (this.currentScale === UNKNOWN_SCALE) {
+        this.currentScaleValue = DEFAULT_SCALE;
+      }
+
+      if (scale === 'page-fit' && !dest[4]) {
+        scrollIntoView(pageViewDiv);
+        return;
+      }
+
+      var boundingRect = [
+        pageView.viewport.convertToViewportPoint(x, y),
+        pageView.viewport.convertToViewportPoint(x + width, y + height)
+      ];
+      var left = Math.min(boundingRect[0][0], boundingRect[1][0]);
+      var top = Math.min(boundingRect[0][1], boundingRect[1][1]);
+
+      scrollIntoView(pageViewDiv, { left: left, top: top });
+    },
+
     _updateLocation: function (firstPage) {
       var currentScale = this._currentScale;
       var currentScaleValue = this._currentScaleValue;
diff --git a/web/viewer.js b/web/viewer.js
index 87416c8..f523466 100644
--- a/web/viewer.js
+++ b/web/viewer.js
@@ -253,10 +253,6 @@ var PDFViewerApplication = {
     });
   },
 
-  getPageView: function pdfViewGetPageView(index) {
-    return this.pdfViewer.pages[index];
-  },
-
   zoomIn: function pdfViewZoomIn(ticks) {
     var newScale = this.pdfViewer.currentScale;
     do {
@@ -663,8 +659,7 @@ var PDFViewerApplication = {
         if (pageNumber > self.pagesCount) {
           pageNumber = self.pagesCount;
         }
-        var currentPage = self.getPageView(pageNumber - 1);
-        currentPage.scrollIntoView(dest);
+        self.pdfViewer.scrollPageIntoView(pageNumber, dest);
 
         // Update the browsing history.
         PDFHistory.push({ dest: dest, hash: destString, page: pageNumber });
@@ -1190,8 +1185,7 @@ var PDFViewerApplication = {
                 zoomArg];
       }
       if (dest) {
-        var currentPage = this.getPageView((pageNumber || this.page) - 1);
-        currentPage.scrollIntoView(dest);
+        this.pdfViewer.scrollPageIntoView(pageNumber || this.page, dest);
       } else if (pageNumber) {
         this.page = pageNumber; // simple page
       }
@@ -1297,7 +1291,7 @@ var PDFViewerApplication = {
       alertNotReady = true;
     } else {
       for (i = 0, ii = this.pagesCount; i < ii; ++i) {
-        if (!this.getPageView(i).pdfPage) {
+        if (!this.pdfViewer.getPageView(i).pdfPage) {
           alertNotReady = true;
           break;
         }
@@ -1316,7 +1310,7 @@ var PDFViewerApplication = {
     var body = document.querySelector('body');
     body.setAttribute('data-mozPrintCallback', true);
     for (i = 0, ii = this.pagesCount; i < ii; ++i) {
-      this.getPageView(i).beforePrint();
+      this.pdfViewer.getPageView(i).beforePrint();
     }
 
 //#if (FIREFOX || MOZCENTRAL)
@@ -1343,7 +1337,7 @@ var PDFViewerApplication = {
   },
 
   rotatePages: function pdfViewRotatePages(delta) {
-    var currentPage = this.getPageView(this.page - 1);
+    var pageNumber = this.page;
 
     this.pageRotation = (this.pageRotation + 360 + delta) % 360;
     this.pdfViewer.pagesRotation = this.pageRotation;
@@ -1351,9 +1345,7 @@ var PDFViewerApplication = {
 
     this.forceRendering();
 
-    if (currentPage) {
-      currentPage.scrollIntoView();
-    }
+    this.pdfViewer.scrollPageIntoView(pageNumber);
   },
 
   /**
@@ -1949,7 +1941,7 @@ window.addEventListener('pagechange', function pagechange(evt) {
   if (this.loading && page === 1) {
     return;
   }
-  PDFViewerApplication.getPageView(page - 1).scrollIntoView();
+  PDFViewerApplication.pdfViewer.scrollPageIntoView(page);
 }, true);
 
 function handleMouseWheel(evt) {

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