Skip to content

[cssom-view] elementFromPoint and elementsFromPoint interop issues #12907

@lukewarlow

Description

@lukewarlow

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() (see also #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 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions