Open yi-gu opened 5 years ago
It may be worth to start by noting that the SVG specification does not claim to specify behavior for non-SVG elements (note how "Applies to" only lists SVG elements) - pointer-events
on anything else is currently a de-facto standard without a specification (there has been intentions to move it to css-ui but nothing has happened there AFAICT). It seems a tall order to require SVG to specify hit-testing for the CSS box model and how that interacts with pointer-events
.
But to try and answer some of your questions... based on what the SVG spec says.
pointer-events
is an inherited property, which defines exactly how it is propagated (inherited) to the descendants, so unless cascading produces a value they inherit the value from the ancestor.
When you start to mix in <iframe>
s you get another document, and CSS does not cross into that document, hence the value would not be "propagated". Given that <iframe>
s are replaced content though, the waters are potentially a bit murky as to what should happen in that case. In general though comparing <div>
s with <iframe>
s will largely be like comparing apples and oranges.
In the nested <div>
s case we could reason about what geometry they have (this is a basic property of SVG hit-testing works). So the boxes likely have geometry in the form of, uhm, boxes. Per SVG[1], you'd pick the top-most target, so for the nested <div>
s (which have nothing that changes z-ordering) that would mean the #child
is on top, and is allowed to receive "pointer events" (pointer-events
is not none
).
Since <iframe>
s are replaced content they would essentially be considered to be "black boxes". They would still have their CSS box geometry in the document they are in, but how (and if) they forward anything would be a detail of the specific replaced content I think (but that is really not specified anywhere).
[1] https://svgwg.org/svg2-draft/interact.html#PointerEvents
I made a CSS issue (since there didn't seem to be one) about getting a proper spec of `pointer-events): w3c/csswg-drafts#4438
I suppose we could add some text to the SVG spec about how to handle nested CSS layout boxes with a <foreignObject>
construct, but I don't really want to get into the kind of detail discussed here. I'd rather see this properly defined in a general CSS spec & then we can reopen this discussion.
(But yes, there is no inheritance of CSS properties to iframes. The So the question is whether pointer-events
affects the event retargetting that happens as a click bubbles in and out of the iframe from the parent document.)
The SVG Working Group just discussed Clarify behavior of pointer-events on nested elements
, and agreed to the following:
RESOLVED: Request the CSS WG takes over the pointer events property
RESOLVED: Add a note to the SVG spec describing how behavior for pointer events will be defined in a yet-as-of-now unwritten CSS spec
RESOLVED: Add a note to the SVG spec describing how behavior for the pointer-events property in foreign content will be defined in a yet-as-of-now unwritten CSS spec
Link to the spec: https://svgwg.org/svg2-draft/interact.html#PointerEventsProperty
The spec does not mention how the pointer-events property in descendants [gets inherited from] or [overrides] the one from their ancestor. e.g.
In this example, the
pointer-events
property in thechild
is inherited to benone
. However, when the elements areiframe
s:The
pointer-events
property does not get propagated.If the nested element has its own
pointer-events
property, the behavior is also inconsistent between divs and iframes. e.g.In this example,
auto
in thechild
overridesnone
from theparent
. For iframes:child
will not accept events. See example here. This behavior makes sense because page owners will lose the control of the outer iframe if the inner one could override the decision on whether the region can accept events (especially for cross origin iframes).It seems like the
pointer-events
propagation stops at the iframe level. In the following example:child
will accept events because it overrides the property from the parent. See example here.The existing behavior mentioned above is consistent in Chrome, Firefox and Safari. The specification needs to clarify it.