2009-05-01

HTML5 Canvas / GWT woes

I've been working on a pet project recently where I wish to control an area of the browser screen via DOM manipulation entirely on a pixel by pixel basis (and to capture all keyboard and mouse events on the area).

I investigated and found that the canvas tag seemed to match the requirements. Using this HTML-5 tag, it is possible to allocate an area of the screen for dynamic updates via Javascript.

Description of the CANVAS tag
GWT CANVAS
Canvas emulation for IE6/7/8 (non-GWT)


As I'm using GWT for my Client-Side scripting, I dug out the GWT Canvas library. The initial trials were good but I soon found that there were no text rendering functions exposed via the library.

It appears I had been experimenting on the cutting edge of the HTML-5 specification. The text functions had recently been added to the spec and only recently added to the beta of 3.5 of Firefox.

Internet Explorer does not support the Canvas at all, but the GWT Canvas library emulates the Canvas via Microsoft's VML interface (based on the standalone javascript ExplorerCanvas library). This does not include text functions.

I checked out the code for GWT Canvas and modified it to expose the text functions via JSNI. This seems trivial at first glance, and it would have been if it were not for the fact that the GWT development kit uses the integrated SWT browser (which in the case of Microsoft Windows is 'IE'). This means that even though I exposed the text rendering functions, they were not available in the test environment as they were not supported in IE. For testing purposes, I wanted to test against Firefox but I could find no option for switching the integrated Host browser in the GWT Eclipse plugin. I understand that if I run on Linux I will be able to test against Firefox but that is not feasable right now.

If I compile the GWT and launch externally in Firefox then I can see that the text functions work as expected. I just cannot see this in my development environment.

I decided to fall back to a pure HTML-4 based alternative in the interim and hope that IE adds Canvas support soon and/or that the GWT Eclipse Plugin will add the ability to switch the host browser in future.