Bug 573443 - Remove Util.Timeout in Util.js [r=mfinkle]

This commit is contained in:
Vivien Nicolas 2010-06-21 22:04:59 +02:00
parent 28d8c13dcc
commit fd4e9b57cb
3 changed files with 25 additions and 90 deletions

View File

@ -210,70 +210,6 @@ 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;
}
Util.Timeout.prototype = {
/** Timer callback. Don't call this manually. */
notify: function notify() {
this._active = false;
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) {
if (aCallback)
this._callback = aCallback;
this.clear();
this._timer.initWithCallback(this, aDelay, this._timer.TYPE_ONE_SHOT);
this._active = true;
return this;
},
/** 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;
},
/** Clear any pending timeouts. */
clear: function clear() {
if (this._active) {
this._timer.cancel();
this._active = false;
}
return this;
},
/** If there is a pending timeout, call it and cancel the timeout. */
flush: function flush() {
if (this._active) {
this.clear();
this.notify();
}
return this;
},
/** Return true iff we are waiting for a callback. */
isPending: function isPending() {
return this._active;
}
};
/**
* Cache of commonly used elements.
*/
@ -297,6 +233,7 @@ let Elements = {};
});
});
/**
* Simple Point class.
*

View File

@ -575,7 +575,7 @@ var Browser = {
// Force commonly used border-images into the image cache
ImagePreloader.cache();
messageManager.addMessageListener("FennecViewportMetadata", this);
messageManager.addMessageListener("Browser:ViewportMetadata", this);
messageManager.addMessageListener("Browser:MozApplicationManifest", OfflineApps);
// broadcast a UIReady message so add-ons know we are finished with startup
@ -1402,7 +1402,7 @@ var Browser = {
receiveMessage: function receiveMessage(aMessage) {
switch (aMessage.name) {
case "FennecViewportMetadata":
case "Browser:ViewportMetadata":
let tab = Browser.getTabForBrowser(aMessage.target);
tab.updateViewportMetadata(aMessage.json);
break;

View File

@ -200,7 +200,7 @@ function getBoundingContentRect(contentElem) {
function Coalescer() {
this._pendingDirtyRect = new Rect(0, 0, 0, 0);
this._pendingSizeChange = null;
this._timer = new Util.Timeout(this);
this._timer = null;
// XXX When moving back and forward in docShell history, MozAfterPaint does not get called properly and
// some dirty rectangles are never flagged properly. To fix this, coalescer will fake a paint event that
// dirties the entire viewport.
@ -208,8 +208,15 @@ function Coalescer() {
}
Coalescer.prototype = {
notify: function notify() {
this.flush();
start: function startCoalescing() {
this._emptyPage();
this._timer = content.document.defaultView.setInterval(this, 1000);
},
stop: function stopCoalescing() {
content.document.defaultView.clearInterval(this._timer);
this._timer = null;
this.flush()
},
handleEvent: function handleEvent(aEvent) {
@ -227,7 +234,7 @@ Coalescer.prototype = {
let win = doc.defaultView;
let scrollOffset = Util.getScrollOffset(win);
if (win.parent != win) // We are only interested in root scroll pane changes
return;
return;
this.sizeChange(scrollOffset, aEvent.x, aEvent.y, aEvent.width, aEvent.height);
break;
}
@ -248,18 +255,10 @@ Coalescer.prototype = {
},
/** Next scroll size change event will invalidate all previous content. See constructor. */
emptyPage: function emptyPage() {
_emptyPage: function _emptyPage() {
this._incremental = false;
},
startCoalescing: function startCoalescing() {
this._timer.interval(1000);
},
stopCoalescing: function stopCoalescing() {
this._timer.flush();
},
sizeChange: function sizeChange(scrollOffset, x, y, width, height) {
// Adjust width and height from the incoming event properties so that we
// ignore changes to width and height contributed by growth in page
@ -273,24 +272,24 @@ Coalescer.prototype = {
// Clear any pending dirty rectangles since entire viewport will be invalidated
// anyways.
var rect = this._pendingDirtyRect;
let rect = this._pendingDirtyRect;
rect.top = rect.bottom;
rect.left = rect.right;
if (!this._timer.isPending())
if (this._timer == null)
this.flush()
},
dirty: function dirty(scrollOffset, clientRects) {
if (!this._pendingSizeChange) {
var unionRect = this._pendingDirtyRect;
for (var i = clientRects.length - 1; i >= 0; i--) {
var e = clientRects.item(i);
let unionRect = this._pendingDirtyRect;
for (let i = clientRects.length - 1; i >= 0; i--) {
let e = clientRects.item(i);
unionRect.expandToContain(new Rect(
e.left + scrollOffset.x, e.top + scrollOffset.y, e.width, e.height));
}
if (!this._timer.isPending())
if (this._timer == null)
this.flush()
}
},
@ -342,7 +341,7 @@ ProgressController.prototype = {
onStateChange: function onStateChange(aWebProgress, aRequest, aStateFlags, aStatus) {
// ignore notification that aren't about the main document (iframes, etc)
var win = aWebProgress.DOMWindow;
let win = aWebProgress.DOMWindow;
if (win != win.parent)
return;
@ -652,7 +651,7 @@ FormNavigator.prototype = {
}
// Second pass: Exclude all other radio buttons from the list.
var result = [];
let result = [];
for (let i=0; i < nodes.length; i++) {
let node = nodes[i];
if (node.type == "radio" && chosenRadios[node.name] != node)
@ -803,13 +802,12 @@ Content.prototype = {
startLoading: function startLoading() {
this._loading = true;
this._coalescer.emptyPage();
this._coalescer.startCoalescing();
this._coalescer.start();
},
stopLoading: function stopLoading() {
this._loading = false;
this._coalescer.stopCoalescing();
this._coalescer.stop();
},
isSelected: function isSelected() {