[whatwg] [2D Canvas] Do canvases in documents without a browsing context need to be rendered?

Hello whatwg,

Say you create a new document using
document.implementation.createHTMLDocument(), you get a document without a
browsing context. This means that style and layout will never be calculated
on the document.  Some of those calculations are context dependent, so they
can't even be resolved.  Now, what about canvas elements? If JS code draws
to a canvas that is in a document with no browsing context, what should
happen?  Should the draw calls produce pixels?  Even though the canvas is
not displayed, it can still be used as an image source. So technically, as
currently specified, such canvases should be rendered.  Drawing to a canvas
in a context-less document is unfortunately a little bit problematic
because some aspects of canvas painting (drawing text in particular) are
affected by the browsing context.  For example, there is no locale for font
family resolution and it is not possible to resolve font sizes in physical
length units unless the document is associated with a view.

My 2 cents: specifying fallback behaviors for all use cases that are
context dependent could be tedious and I have yet to see a real-world use
case that requires being able to paint a canvas in a frame-less document.
 Therefore, I think the spec should clearly state <canvas> elements that
are in a document without a browsing context are unusable.  Not sure what
the exact behavior should be though.  Should an exception be thrown upon
trying to use the rendering context? Perhaps canvas draws should fail
silently, and using the canvas as an image source should give transparent
black pixels?

Cheers,

    Justin

Received on Monday, 3 March 2014 17:57:54 UTC