w3c / csswg-drafts

CSS Working Group Editor Drafts
https://drafts.csswg.org/
Other
4.44k stars 657 forks source link

[cssom] Accessing the DOM of images #1568

Open SebastianZ opened 7 years ago

SebastianZ commented 7 years ago

Moved from https://lists.w3.org/Archives/Public/www-style/2017Jun/0029.html, posted by Henrik Andersson.

One thing I've realized is that css allows for the use of SVG images. And those have a DOM of their own. It'd be interesting if it was possible to access the DOM of the image in javascript. The user agent already needs to have it anyway.

SebastianZ commented 7 years ago

On 25 June 2017 at 23:20, Henrik Andersson henke@henke37.cjb.net wrote:

One thing I've realized is that css allows for the use of SVG images. And those have a DOM of their own.

I'm not an implementer, but I assume that currently SVGs integrated into a page via CSS don't have a DOM.

It'd be interesting if it was possible to access the DOM of the image in javascript. The user agent already needs to have it anyway.

Note that you can already access the DOM of SVGs by integrating the SVG code directly in the HTML. It might make sense to be able to access the SVG's DOM when it's integrated via CSS to allow to change it dynamically, though based on the assumption above I assume it would have some impact on speed and memory if a DOM needs to be created for them.

Sebastian

upsuper commented 7 years ago

I'm not an implementer, but I assume that currently SVGs integrated into a page via CSS don't have a DOM.

IIUC, engines need to create document, as well as DOM stuff, for SVG-as-image.

Although browsers already create that, it may still impact speed and memory depending on how it would behave. For example, if there are multiple image referring the same SVG file, would mutating one changes others? Either true or false, there could be lots of things to do if an engine tries to reuse one document everywhere.

svgeesus commented 7 years ago

SVGs do have a DOM. Depending on how the SVG is included in other content, that DOM may or may not be available. See the definitions for 'secure animated mode' and 'secure static mode': https://www.w3.org/TR/SVG2/conform.html#processing-modes