When a canvas element is created via document.createElement('canvas') and then
drawn to via methods such as fillRect, the canvas does not reflect those method
calls. However once the canvas has been appended to the document, subsequent
calls to drawing methods "work".
Created attachment 5360 [details]
simple html document illustrating the problem
If you click the second link in the testcase first, nothing happens, the other way around, it does. Needs a better reduction but i think i can confirm this one.
To further explain the sample document. The first click tries to create a canvas element, draw to it then append it to the document. In safari you wont see a black square in the canvas after you click the first link, however in opera and Firefox you do.
The problem seems to be that the Canvas render object (RenderCanvasImage) has not been created yet, although there is a valid DOM element. By memory, render objects are not created until they are attached to the DOM tree. I believe this is because the engine does not know how to provide the style information needed to create a render object until it knows it's location within the tree.
So, although the getContext function will return with a valid canvas context, no methods on that object will succeed until it is attached to the DOM.
I am not sure what can be done about this.
The same root cause as http://bugzilla.opendarwin.org/show_bug.cgi?id=4884
*** This bug has been marked as a duplicate of 4884 ***