Long time since I’ve posted on Planet WebKit:
Here’s a proposed high resolution Timer API for WebKit (and hopefully HTML5). It’s based off of Adobe’s “flash.utils.Timer” API found in ActionScript 3.0.
Timer : EventDispatcher
- currentCount:Number => Total number of times the timer has fired since it started (at 0)
- Â delay:Number => The time, measured in millisecondsseconds, between timer firings. Precision is browser defined, but should be at least 1ms
- repeatCount:Number => The total number of times the counter is set to run. If the timer is “0”, the timer will run forever or until its stopped.
- running:Boolean => If the timer is running or not
- start() => Starts the timer if the timer is not running
- stop() => Stops the timer if the timer is running.
- reset() => Stops the timer if its running, and resets “currentCount” back to 0.
The timer will implement the browser native event dispatching system (W3C for most, IE proprietary for MSIE), and will fire the following events:
- timer => Dispatched whenever the timer reaches the interval specified by the “delay” property.
- timerComplete => Dispatched when the timer’s repeatCount reaches 0.
Please note the timer will be a high resolution timer, with no minimum bound, so there’s no compatibility issues when using setTimeout/setInterval. Plus, the API is simple enough to be implemented in terms of setTimeout/setInterval on browsers that do not implement the proposed.
Please leave feedback on the proposed API.
- Repeat Count defaults to 0, meaning, go on forever. If you want it to be “one shot”, then set repeat count to 1.
var timer = new Timer();
timer.delay = 0.01;
timer.repeatCount = 1;
// Add Event Listeners
if(timer.addEventListener) timer.addEventListener(“timercomplete”, OnTimerComplete); // W3C
else if (timer.attachEvent) timer.attachEvent(“ontimercomplete”,OnTimerComplete); // MSIE
// Event Lsitener
if(!e) e = window.event; // MSIE
// Do Something
Since I don’t get paid to hack on Webkit (sadly), I can only contribute in my spare time.
However, I do have some short and long term personal goals for WebKit:
- Get the threading patches to Qt integrated. For the most part, its ready:Â http://bugs.webkit.org/show_bug.cgi?id=15940
- Getting NPAPI plugins working in Qt/Windows
- Potentially adding audio/video support
- Drawing issues in Qt/Windows. Some examples: http://www.neowin.net, any website with effects on rollover, etc…
Updated uber-patch. I’ll be splitting parts of this patch up that are separate from plugins
Download plugin uber-patch
I got it to work! It’s just a proof of concept right now, and I’ll clean it up later.
The patch does several things that are needed:
- Makes sure the database stuff is protected
- Hacks in support for the Windows plugins (this needs to be done in a cleaner way)
- Implement UTF-8 to UTF-16 text encoding using Qt 4
Download Patch: Current Patch