Bug 899801 - Don't keep more than five "momentums" values in BrowserElementPanning.js. r=vingtetun, a=leo+
authorJustin Lebar <justin.lebar@gmail.com>
Wed, 31 Jul 2013 09:22:57 -0700
changeset 119827 90b792959f01e9872af43898ace0dd1fbf3ffca4
parent 119826 5317a86d17a261ae26e313eff89deb64647250fd
child 119828 ba71c64705e5dd14f90b4b7e133409213acd98ff
push id1015
push userryanvm@gmail.com
push dateThu, 01 Aug 2013 16:41:14 +0000
reviewersvingtetun, leo
bugs899801
milestone18.1
Bug 899801 - Don't keep more than five "momentums" values in BrowserElementPanning.js. r=vingtetun, a=leo+
dom/browser-element/BrowserElementPanning.js
--- a/dom/browser-element/BrowserElementPanning.js
+++ b/dom/browser-element/BrowserElementPanning.js
@@ -625,19 +625,16 @@ const KineticPanning = {
   target: null,
   start: function kp_start(target) {
     this.target = target;
 
     // Calculate the initial velocity of the movement based on user input
     let momentums = this.momentums;
     let flick = momentums[momentums.length - 1].time - momentums[0].time < 300;
 
-    // Calculate the panning based on the last moves.
-    momentums = momentums.slice(-kSamples);
-
     let distance = new Point(0, 0);
     momentums.forEach(function(momentum) {
       distance.add(momentum.dx, momentum.dy);
     });
 
     function clampFromZero(x, min, max) {
       if (x >= 0)
         return Math.max(min, Math.min(max, x));
@@ -686,16 +683,22 @@ const KineticPanning = {
 
     this.target.onKineticEnd();
     this.target = null;
   },
 
   momentums: [],
   record: function kp_record(delta, timestamp) {
     this.momentums.push({ 'time': timestamp, 'dx' : delta.x, 'dy' : delta.y });
+
+    // We only need to keep kSamples in this.momentums.
+    if (this.momentums.length > kSamples) {
+      this.momentums.shift();
+    }
+
     this.distance.add(delta.x, delta.y);
   },
 
   get threshold() {
     let dpi = content.QueryInterface(Ci.nsIInterfaceRequestor)
                      .getInterface(Ci.nsIDOMWindowUtils)
                      .displayDPI;