whatwg / html

HTML Standard
https://html.spec.whatwg.org/multipage/
Other
8.16k stars 2.69k forks source link

Why is <object> doing half of replaced element sizing negotiation? #7037

Open tabatkins opened 3 years ago

tabatkins commented 3 years ago

(Copied from https://github.com/w3c/csswg-drafts/issues/6469 to solicit wider review.)

Why are object elements doing only half of the object size negotiation? They're passing up sizing information from the embedded SVG to the OBJECT box (as you can see it respecting the SVG's aspect ratio to calculate the object's height), but the resulting SVG is laid out inside the OBJECT as if in an IFRAME rather than in an IMG element.

Afaict, nothing in the HTML spec says to treat them differently than IMG... https://html.spec.whatwg.org/multipage/rendering.html

Testcase comparing img, object, iframe, inline svg; source code below:

<!doctype html>
<img src="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100' style='background: orange'><circle cx='50' cy='50' r='50' fill='blue' /></svg>">

<object type="image/svg+xml" data="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100' style='background: orange'><circle cx='50' cy='50' r='50' fill='blue' /></svg>"></object>

<iframe type="image/svg+xml" src="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100' style='background: orange'><circle cx='50' cy='50' r='50' fill='blue' /></svg>"></iframe>

<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100' style='background: orange'><circle cx='50' cy='50' r='50' fill='blue' /></svg>

<style>
img, object, iframe, svg { border: thick dotted; width: 200px; }
</style>
annevk commented 3 years ago

For a number of cases object and embed create a nested browsing context. They do so for SVG as well, otherwise getSVGDocument() would not work.

That sizing is still passed around to some extent is not exactly desirable as this presents an information leak and is something we should try to remove over time.

In general both object and embed probably need to be deprecated. (And they also need cleanup, as per #1460 and various other issues, not all of them recorded.)