[csswg-drafts] [cssom-view] elementFromPoint and elementsFromPoint interop issues (#12907)

lukewarlow has just created a new issue for https://github.com/w3c/csswg-drafts:

== [cssom-view] elementFromPoint and elementsFromPoint interop issues ==
Note: poorly defined might actually be better presented as incorrectly defined depending on your opinions on expected behaviour.

While working on tests for a new [nodesFromRect()](https://github.com/Igalia/explainers/blob/main/nodes-from-rect/README.md) (see also https://github.com/w3c/csswg-drafts/issues/11605) I've discovered an interop issue with the existing functions of the same sort. Namely elementFromPoint and elementsFromPoint (I haven't explored further so it's possible this extends to other functions).

I added [tests](https://github.com/web-platform-tests/wpt/pull/55253) for what I interpreted expected behaviour to be but Emilio raised a counter argument, either way browsers are mostlly inconsistent between `elementFromPoint` and `elementsFromPoint` which suggests the spec is ambiguous.

To summarise handling of display:contents elements is inconsistent across browsers and between element and elementsFromPoint.

`data:text/html,<div style="display:contents">Foobar</div><style>* {padding: 0;margin: 0;}</style><script>const x = document.elementFromPoint(5, 5);alert(x.tagName);const y = document.elementsFromPoint(5, 5);alert(y[0].tagName);</script>`

In Chromium, WebKit, Firefox and Servo the first alert shows "DIV".
In WebKit the second alert also shows "DIV", but in the other 3 it shows "BODY".

Based on the spec text I don't think either of the functions should include the div because no box exists for a display:contents element. Emilio says that perhaps it should include the div because the text node gets hit tested and that's its parent, the spec currently doesn't mention "text sequences" for these functions though.

This issue is essentially to discuss what we actually want to happen and update the spec and tests to match accordingly.

Both I and Emilio agree that if an element is returned by the single function it should be included in the array one.

Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/12907 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Tuesday, 7 October 2025 12:15:53 UTC