SVG:Use
From MozillaWiki
Contents
Mental Testcases
- svg:use linked to:
- same document displayed content
- same document undisplayed content
- other document
- foreignObject containing HTML form elements (textbox)
- dynamic changes
- attribute change within used content
- style change inherited from ancestor of use
- tree structure changes within use
- addition/removal of use itself
- non-DOM content changes (e.g. form contents)
- event delivery to shadow instance tree
Implementation Strategies
No Frame Tree
- remove multiple presentations
- Move SVG painting and event handling to content
- ownership of style context also therefore goes to content
- Clone content for svg:use
- Let style contexts know they're held by content (bit)
Single Content Tree, Multiple Frame Trees
- leverage multiple presentations
- extend current architecture to support multiple primary frames for an element in the same frame tree
- useful for table header/footers, repeating fixed elements too
- extend current architecture to support multiple primary frames for an element in the same frame tree
- use existing content-style-frame setup
- SVG elements whose style we need (e.g. gradients) continue to need frames
- hack style system to get inheritance-across-use to work (how?)
Application of style from stylesheets
Say you have:
<style> rect:hover ( fill: yellow; } </style> <rect id="rect" ...> <use xlink:href="url(#rect" .../>
Opera highlights both rects when the first is hovered. Webkit only ever highlights the first when the first is hovered. Mozilla highlights only the rect you hover over.
Opera's justification is that technically there is only one rect. Mozilla does an actual clone.
Alternatives
It would have been better if the spec had defined a 'clone' element, where 'clone' acts just like a 'g', but with anonymous content. If users wanted a viewport they could wrap the 'clone' in an 'svg' tag, instead of being forced to have one as 'use' forces you now.
Whereas 'clone' would create an anonymous (on non-anonymous?) content clone of the referenced content, we could also have a 'ref' element.