[csswg-drafts] [cssom-view] Synthetic click's `pageX/Y` and `offsetX/Y` are ambiguous in the spec and inconsistently implemented (#8531)

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

== [cssom-view] Synthetic click's `pageX/Y` and `offsetX/Y` are ambiguous in the spec and inconsistently implemented ==
This might be more appropriately moved to https://github.com/whatwg/html to clarify [this section](https://html.spec.whatwg.org/multipage/webappapis.html#fire-a-synthetic-pointer-event), but opening it here to start a discussion.

According to CSSOM View, `pageX/pageY` should return the `coordinate of the position where the event occurred relative to the origin of the initial containing block` (i.e. document). Similarly, `offsetX/offsetY` should return the `position where the event occurred relative to the origin of the padding edge of the target node`.

What's not clear for synthetic events is `the position where the event occurred`. Based on the `clientX/Y` defaults of `0`, one could infer that the default position is the origin of the viewport, and that is indeed what Chrome does with respect to computing `pageX/Y` (i.e. they reflect the scroll offset). However:
1. Webkit and Safari do not consider the scroll offset when computing `pageX/Y` (i.e. it's always `0`)
2. All browsers set the `offsetX/Y` to `0`. At a glance this seems reasonable, but this is actually incompatible with the `pageX/Y` value. If the event did in fact occur at the the origin of the target node, that means that that node must be positioned at `pageX/Y`, which is generally not going to be the case.

To resolve these discrepancies, we need to clarify what the position should be for synthetic pointer events. Some options:
1. Document origin, so `pageX/Y` should be `(0, 0)` and `offsetX/Y` should be the target node's `-offsetLeft/-offsetTop`
2. Viewport origin, so `pageX/Y` should reflect the scroll offset and `offsetX/Y` should be the scroll offset minus the target node's `offsetLeft/offsetTop`
3. Target node origin, so `pageX/Y` should reflect the target node's `offsetLeft/offsetTop` minus the scroll offset, and `offsetX/Y` should be `(0, 0)`.

IMO 3 makes the most sense (i.e. it's weird for a "click" on an node to be positioned outside that node). This might also be the most straightforward since `offsetX/Y` are already correct for this in all implementations, it's "just" a matter of fixing `pageX/Y` 😄. Regardless, any approach will require updates to spec(s) and fixes in the major implementations.

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


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

Received on Monday, 6 March 2023 18:56:02 UTC