[Pkg-javascript-commits] [pdf.js] 132/161: Cleaning up the viewer and pdfbug; fixes repeats in Stepper

David Prévot taffit at moszumanska.debian.org
Sat Apr 19 14:16:38 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 ed8ecfd00a565ec844a5037bb400a31388610972
Author: Yury Delendik <ydelendik at mozilla.com>
Date:   Wed Mar 26 15:18:53 2014 -0500

    Cleaning up the viewer and pdfbug; fixes repeats in Stepper
---
 web/debugger.js | 97 ++++++++++++++++++++++++++++++++++++++++++++++++---------
 web/viewer.js   | 60 +++++++++++++++++++++--------------
 2 files changed, 118 insertions(+), 39 deletions(-)

diff --git a/web/debugger.js b/web/debugger.js
index a25136f..21e1193 100644
--- a/web/debugger.js
+++ b/web/debugger.js
@@ -79,6 +79,9 @@ var FontInspector = (function FontInspectorClosure() {
       fonts = document.createElement('div');
       panel.appendChild(fonts);
     },
+    cleanup: function cleanup() {
+      fonts.textContent = '';
+    },
     enabled: false,
     get active() {
       return active;
@@ -181,6 +184,11 @@ var StepperManager = (function StepperManagerClosure() {
         breakPoints = JSON.parse(sessionStorage.getItem('pdfjsBreakPoints'));
       }
     },
+    cleanup: function cleanup() {
+      stepperChooser.textContent = '';
+      stepperDiv.textContent = '';
+      steppers = [];
+    },
     enabled: false,
     active: false,
     // Stepper specific functions.
@@ -204,7 +212,7 @@ var StepperManager = (function StepperManagerClosure() {
     },
     selectStepper: function selectStepper(pageIndex, selectPanel) {
       if (selectPanel) {
-        this.manager.selectPanel(1);
+        this.manager.selectPanel(this);
       }
       for (var i = 0; i < steppers.length; ++i) {
         var stepper = steppers[i];
@@ -259,6 +267,33 @@ var Stepper = (function StepperClosure() {
     'nextLineSetSpacingShowText': 2
   };
 
+  function simplifyArgs(args) {
+    if (typeof args === 'string') {
+      var MAX_STRING_LENGTH = 75;
+      return args.length <= MAX_STRING_LENGTH ? args :
+        args.substr(0, MAX_STRING_LENGTH) + '...';
+    }
+    if (typeof args !== 'object' || args === null) {
+      return args;
+    }
+    if ('length' in args) { // array
+      var simpleArgs = [], i, ii;
+      var MAX_ITEMS = 10;
+      for (i = 0, ii = Math.min(MAX_ITEMS, args.length); i < ii; i++) {
+        simpleArgs.push(simplifyArgs(args[i]));
+      }
+      if (i < args.length) {
+        simpleArgs.push('...');
+      }
+      return simpleArgs;
+    }
+    var simpleObj = {};
+    for (var key in args) {
+      simpleObj[key] = simplifyArgs(args[key]);
+    }
+    return simpleObj;
+  }
+
   function Stepper(panel, pageIndex, initialBreakPoints) {
     this.panel = panel;
     this.breakPoint = 0;
@@ -291,30 +326,40 @@ var Stepper = (function StepperClosure() {
       }
     },
     updateOperatorList: function updateOperatorList(operatorList) {
+      function cboxOnClick() {
+        var x = +this.dataset.idx;
+        if (this.checked) {
+          self.breakPoints.push(x);
+        } else {
+          self.breakPoints.splice(self.breakPoints.indexOf(x), 1);
+        }
+        StepperManager.saveBreakPoints(self.pageIndex, self.breakPoints);
+      }
+
+      var MAX_OPERATORS_COUNT = 15000;
+      if (this.operatorListIdx > MAX_OPERATORS_COUNT) {
+        return;
+      }
+
       var self = this;
-      for (var i = this.operatorListIdx; i < operatorList.fnArray.length; i++) {
+      var chunk = document.createDocumentFragment();
+      var operatorsToDisplay = Math.min(MAX_OPERATORS_COUNT,
+        operatorList.fnArray.length);
+      for (var i = this.operatorListIdx; i < operatorsToDisplay; i++) {
         var line = c('tr');
         line.className = 'line';
         line.dataset.idx = i;
-        this.table.appendChild(line);
+        chunk.appendChild(line);
         var checked = this.breakPoints.indexOf(i) != -1;
-        var args = operatorList.argsArray[i] ? operatorList.argsArray[i] : [];
+        var args = operatorList.argsArray[i] || [];
 
         var breakCell = c('td');
         var cbox = c('input');
         cbox.type = 'checkbox';
         cbox.className = 'points';
         cbox.checked = checked;
-        cbox.onclick = (function(x) {
-          return function() {
-            if (this.checked) {
-              self.breakPoints.push(x);
-            } else {
-              self.breakPoints.splice(self.breakPoints.indexOf(x), 1);
-            }
-            StepperManager.saveBreakPoints(self.pageIndex, self.breakPoints);
-          };
-        })(i);
+        cbox.dataset.idx = i;
+        cbox.onclick = cboxOnClick;
 
         breakCell.appendChild(cbox);
         line.appendChild(breakCell);
@@ -341,8 +386,16 @@ var Stepper = (function StepperClosure() {
           decArgs[glyphIndex] = newArg;
         }
         line.appendChild(c('td', fn));
-        line.appendChild(c('td', JSON.stringify(decArgs)));
+        line.appendChild(c('td', JSON.stringify(simplifyArgs(decArgs))));
+      }
+      if (operatorsToDisplay < operatorList.fnArray.length) {
+        line = c('tr');
+        var lastCell = c('td', '...');
+        lastCell.colspan = 4;
+        chunk.appendChild(lastCell);
       }
+      this.operatorListIdx = operatorList.fnArray.length;
+      this.table.appendChild(chunk);
     },
     getNextBreakPoint: function getNextBreakPoint() {
       this.breakPoints.sort(function(a, b) { return a - b; });
@@ -447,6 +500,10 @@ var Stats = (function Stats() {
       for (var i = 0, ii = stats.length; i < ii; ++i) {
         this.panel.appendChild(stats[i].div);
       }
+    },
+    cleanup: function () {
+      stats = [];
+      clear(this.panel);
     }
   };
 })();
@@ -539,7 +596,17 @@ var PDFBug = (function PDFBugClosure() {
       }
       this.selectPanel(0);
     },
+    cleanup: function cleanup() {
+      for (var i = 0, ii = this.tools.length; i < ii; i++) {
+        if (this.tools[i].enabled) {
+          this.tools[i].cleanup();
+        }
+      }
+    },
     selectPanel: function selectPanel(index) {
+      if (typeof index !== 'number') {
+        index = this.tools.indexOf(index);
+      }
       if (index === activePanel) {
         return;
       }
diff --git a/web/viewer.js b/web/viewer.js
index 3e127c4..555a202 100644
--- a/web/viewer.js
+++ b/web/viewer.js
@@ -550,9 +550,43 @@ var PDFView = {
 //#endif
   },
 
+  close: function pdfViewClose() {
+    if (!this.pdfDocument) {
+      return;
+    }
+
+    this.pdfDocument.destroy();
+    this.pdfDocument = null;
+
+    var errorWrapper = document.getElementById('errorWrapper');
+    errorWrapper.setAttribute('hidden', 'true');
+
+    var thumbsView = document.getElementById('thumbnailView');
+    while (thumbsView.hasChildNodes()) {
+      thumbsView.removeChild(thumbsView.lastChild);
+    }
+
+    if ('_loadingInterval' in thumbsView) {
+      clearInterval(thumbsView._loadingInterval);
+    }
+
+    var container = document.getElementById('viewer');
+    while (container.hasChildNodes()) {
+      container.removeChild(container.lastChild);
+    }
+
+    if (typeof PDFBug !== 'undefined') {
+      PDFBug.cleanup();
+    }
+  },
+
   // TODO(mack): This function signature should really be pdfViewOpen(url, args)
   open: function pdfViewOpen(url, scale, password,
                              pdfDataRangeTransport, args) {
+    if (this.pdfDocument) {
+      this.close();
+    }
+
     var parameters = {password: password};
     if (typeof url === 'string') { // URL
       this.setTitleUsingUrl(url);
@@ -566,11 +600,6 @@ var PDFView = {
       }
     }
 
-    // Terminate worker of the previous document if any.
-    if (this.pdfDocument) {
-      this.pdfDocument.destroy();
-    }
-    this.pdfDocument = null;
     var self = this;
     self.loading = true;
     var passwordNeeded = function passwordNeeded(updatePassword, reason) {
@@ -862,31 +891,12 @@ var PDFView = {
 
     this.pdfDocument = pdfDocument;
 
-    var errorWrapper = document.getElementById('errorWrapper');
-    errorWrapper.setAttribute('hidden', 'true');
-
     pdfDocument.getDownloadInfo().then(function() {
       PDFView.loadingBar.hide();
       var outerContainer = document.getElementById('outerContainer');
       outerContainer.classList.remove('loadingInProgress');
     });
 
-    var thumbsView = document.getElementById('thumbnailView');
-    thumbsView.parentNode.scrollTop = 0;
-
-    while (thumbsView.hasChildNodes()) {
-      thumbsView.removeChild(thumbsView.lastChild);
-    }
-
-    if ('_loadingInterval' in thumbsView) {
-      clearInterval(thumbsView._loadingInterval);
-    }
-
-    var container = document.getElementById('viewer');
-    while (container.hasChildNodes()) {
-      container.removeChild(container.lastChild);
-    }
-
     var pagesCount = pdfDocument.numPages;
 
     var id = pdfDocument.fingerprint;
@@ -911,6 +921,8 @@ var PDFView = {
     this.pagesPromise = pagesPromise;
 
     var firstPagePromise = pdfDocument.getPage(1);
+    var container = document.getElementById('viewer');
+    var thumbsView = document.getElementById('thumbnailView');
 
     // Fetch a single page so we can get a viewport that will be the default
     // viewport for all pages

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