Bug 6291 - Drawing to a dynamically created canvas element before it is appended to document doesnt work
Summary: Drawing to a dynamically created canvas element before it is appended to docu...
Status: RESOLVED DUPLICATE of bug 4884
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: 420+
Hardware: PC Windows XP
: P2 Normal
Assignee: Nobody
URL: http://andrewwooldridge.com/canvas/ca...
Keywords: NeedsReduction
Depends on:
Blocks:
 
Reported: 2005-12-29 17:03 PST by Andrew Wooldridge
Modified: 2006-03-08 18:27 PST (History)
1 user (show)

See Also:


Attachments
simple html document illustrating the problem (1.11 KB, text/html)
2005-12-29 17:07 PST, Andrew Wooldridge
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Wooldridge 2005-12-29 17:03:42 PST
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".
Comment 1 Andrew Wooldridge 2005-12-29 17:07:06 PST
Created attachment 5360 [details]
simple html document illustrating the problem
Comment 2 Joost de Valk (AlthA) 2006-02-07 14:32:46 PST
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.
Comment 3 Andrew Wooldridge 2006-02-07 17:17:31 PST
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.  
Comment 4 David Carson 2006-03-08 16:47:35 PST
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.

Comment 5 David Carson 2006-03-08 16:58:10 PST
The same root cause as http://bugzilla.opendarwin.org/show_bug.cgi?id=4884
Comment 6 David Carson 2006-03-08 18:27:37 PST

*** This bug has been marked as a duplicate of 4884 ***