Bug 587663 - Page only paints once during load [r=mfinkle]
authorBenjamin Stover <bstover@mozilla.com>
Mon, 16 Aug 2010 20:35:34 -0700
changeset 1797 b769b2f7fd9e362b61b200005e3fc96a3aea9658
parent 1796 9e68083047aa055342807f215c176beb98765576
child 1798 cf3163be3e8db8d9579099f25f4eebed1ddde754
push id1605
push userbstover@mozilla.com
push dateTue, 17 Aug 2010 15:43:07 +0000
reviewersmfinkle
bugs587663
Bug 587663 - Page only paints once during load [r=mfinkle]
chrome/content/Util.js
--- a/chrome/content/Util.js
+++ b/chrome/content/Util.js
@@ -219,70 +219,72 @@ let Util = {
 
 /**
  * Helper class to nsITimer that adds a little more pizazz.  Callback can be an
  * object with a notify method or a function.
  */
 Util.Timeout = function(aCallback) {
   this._callback = aCallback;
   this._timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
-  this._active = false;
+  this._type = null;
 };
 
 Util.Timeout.prototype = {
   /** Timer callback. Don't call this manually. */
   notify: function notify() {
-    this._active = false;
+    if (this._type == this._timer.TYPE_ONE_SHOT)
+      this._type = null;
+
     if (this._callback.notify)
       this._callback.notify();
     else
       this._callback.apply(null);
   },
 
-  /** Do the callback once.  Cancels other timeouts on this object. */
-  once: function once(aDelay, aCallback) {
+  /** Helper function for once and interval. */
+  _start: function _start(aDelay, aType, aCallback) {
     if (aCallback)
       this._callback = aCallback;
     this.clear();
-    this._timer.initWithCallback(this, aDelay, this._timer.TYPE_ONE_SHOT);
-    this._active = true;
+    this._timer.initWithCallback(this, aDelay, aType);
+    this._type = aType;
     return this;
   },
 
+  /** Do the callback once.  Cancels other timeouts on this object. */
+  once: function once(aDelay, aCallback) {
+    return this._start(aDelay, this._timer.TYPE_ONE_SHOT, aCallback);
+  },
+
   /** Do the callback every aDelay msecs. Cancels other timeouts on this object. */
   interval: function interval(aDelay, aCallback) {
-    if (aCallback)
-      this._callback = aCallback;
-    this.clear();
-    this._timer.initWithCallback(this, aDelay, this._timer.TYPE_REPEATING_SLACK);
-    this._active = true;
-    return this;
+    return this._start(aDelay, this._timer.TYPE_REPEATING_SLACK, aCallback);
   },
 
   /** Clear any pending timeouts. */
   clear: function clear() {
-    if (this._active) {
+    if (this._type) {
       this._timer.cancel();
-      this._active = false;
+      this._type = null;
     }
     return this;
   },
 
   /** If there is a pending timeout, call it and cancel the timeout. */
   flush: function flush() {
-    if (this._active) {
+    if (this._type) {
+      this.notify();
       this.clear();
-      this.notify();
     }
     return this;
   },
 
   /** Return true iff we are waiting for a callback. */
   isPending: function isPending() {
-    return this._active;
+    return !!this._type;
   }
 };
 
 
 
 /**
  * Cache of commonly used elements.
  */