Bug 708173. Use cancelRequestAnimationCallback instead of tracking booleans in scrollbox code. r=dao
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 08 Dec 2011 01:32:04 -0500
changeset 82232 70963acaf12386aad5a86fdd8ea135dd0ba938ae
parent 82231 75b7a7fd74a092e026f2066a050513ceaeec16c5
child 82233 79a0b1e9f6fd2bdc6344974c64d7499817d88c40
push id21587
push userbmo@edmorley.co.uk
push dateThu, 08 Dec 2011 15:13:43 +0000
treeherdermozilla-central@98db2311a44c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdao
bugs708173
milestone11.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 708173. Use cancelRequestAnimationCallback instead of tracking booleans in scrollbox code. r=dao
toolkit/content/widgets/scrollbox.xml
--- a/toolkit/content/widgets/scrollbox.xml
+++ b/toolkit/content/widgets/scrollbox.xml
@@ -267,36 +267,31 @@
           this._isScrolling = amountToScroll < 0 ? -1 : 1;
 
           this._scrollAnim.start(amountToScroll);
         ]]></body>
       </method>
 
       <field name="_scrollAnim"><![CDATA[({
         scrollbox: this,
-        started: false,
+        requestHandle: 0, /* 0 indicates there is no pending request */
         start: function scrollAnim_start(distance) {
           this.distance = distance;
           this.startPos = this.scrollbox.scrollPosition;
           this.duration = Math.min(1000, Math.round(50 * Math.sqrt(Math.abs(distance))));
           this.startTime = window.mozAnimationStartTime;
 
-          if (!this.started) {
-            this.started = true;
-            window.mozRequestAnimationFrame(this);
-          }
+          if (!this.requestHandle)
+            this.requestHandle = window.mozRequestAnimationFrame(this);
         },
         stop: function scrollAnim_stop() {
-          this.started = false;
+          window.mozCancelRequestAnimationFrame(this.requestHandle);
+          this.requestHandle = 0;
         },
         sample: function scrollAnim_handleEvent(timeStamp) {
-          if (!this.started) {
-            // We've been stopped
-            return;
-          }
           const timePassed = timeStamp - this.startTime;
           const pos = timePassed >= this.duration ? 1 :
                       1 - Math.pow(1 - timePassed / this.duration, 4);
 
           this.scrollbox.scrollPosition = this.startPos + (this.distance * pos);
 
           if (pos == 1)
             this.scrollbox._stopSmoothScroll();
@@ -641,32 +636,27 @@
 
           this.scrollByIndex(this._scrollIndex);
         ]]>
         </body>
       </method>
 
       <field name="_arrowScrollAnim"><![CDATA[({
         scrollbox: this,
-        started: false,
+        requestHandle: 0, /* 0 indicates there is no pending request */
         start: function arrowSmoothScroll_start() {
           this.lastFrameTime = window.mozAnimationStartTime;
-          if (!this.started) {
-            this.started = true;
-            window.mozRequestAnimationFrame(this);
-          }
+          if (!this.requestHandle)
+            this.requestHandle = window.mozRequestAnimationFrame(this);
         },
         stop: function arrowSmoothScroll_stop() {
-          this.started = false;
+          window.mozCancelRequestAnimationFrame(this.requestHandle);
+          this.requestHandle = 0;
         },
         sample: function arrowSmoothScroll_handleEvent(timeStamp) {
-          if (!this.started) {
-            // We've been stopped
-            return;
-          }
           const scrollIndex = this.scrollbox._scrollIndex;
           const timePassed = timeStamp - this.lastFrameTime;
           this.lastFrameTime = timeStamp;
           
           const scrollDelta = 0.5 * timePassed * scrollIndex;
           this.scrollbox.scrollPosition += scrollDelta;
 
           window.mozRequestAnimationFrame(this);