-
Notifications
You must be signed in to change notification settings - Fork 756
Description
This might be more appropriately moved to https://github.com/whatwg/html to clarify this section, but I'm 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 pointer events is: what is the position where the event occurred? Based on the clientX/Y defaults of (0, 0), one could infer that the event 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:
- Webkit and Gecko do not consider the scroll offset when computing
pageX/Y(i.e. it's always(0, 0)), so perhaps the event occurred at the origin of the document? - All browsers set the
offsetX/Yto(0, 0). At a glance this seems reasonable, but this is actually incompatible with thepageX/Yvalues above, since all these values are relative to the position where the event occurred. It's a little easier to see the problem visually (each col/row represents one pixel):If+--------------------+ | document | | | | +---------------+| scroll offset: (4, 3) | | viewport || | | || | | +--------+|| target position relative to document (10, 6) | | | target ||| relative to viewport (6, 3) | | +--------+|| | +---------------+| +--------------------+offsetX/Y = (0, 0)is correct (i.e. the event occurred at the target origin), thenpageX/Yshould be(10, 6), but that is not the case in any browser.
To resolve these discrepancies, we need to clarify what the position should be for synthetic pointer events. Some options:
- Event position = document origin, so
pageX/Yshould be(0, 0)andoffsetX/Yshould be the document origin's coordinate relative to the target (e.g.(-10, -6)) - Event position = viewport origin, so
pageX/Yshould reflect the scroll offset (e.g.(4, 3)) andoffsetX/Yshould be the viewport origin's coordinate relative to the target node (e.g.(-6, -3)) - Event position = target node origin, so
pageX/Yshould reflect the target node's coordinate relative to the document origin (e.g.(10, 6)) andoffsetX/Yshould be(0, 0). - Event position = 🤷, we make an exception in the CSSOM View spec for synthetic pointer events to set both
pageX/YandoffsetX/offsetYto(0, 0). This would match the current behavior in Gecko and Webkit.
IMO option 3 makes the most sense, i.e. it's weird for a "click" on an node to be positioned outside that node. It's also likely that offsetX/Y being (0, 0) is relied on in the wild (either explicitly by developers or implicitly by implementations), e.g. activating an Image Button by hitting enter adds (0, 0) entries to the form data set. Option 4 could work too, but it's a little weird and could be a source of confusion. In either case, offsetX/Y would already be correct across the board, it's "just" a matter of fixing pageX/Y in one or all implementations 😄. Options 1 and 2 seem likely to break websites and I suspect could also be more work to implement, so IMO they aren't worth exploring.