Closed Bug 1833963 Opened 2 years ago Closed 8 months ago

Ship fractional coordinates of Pointer Events

Categories

(Core :: DOM: UI Events & Focus Handling, enhancement)

enhancement

Tracking

()

RESOLVED FIXED
135 Branch
Tracking Status
relnote-firefox --- 135+
firefox135 --- fixed

People

(Reporter: hsinyi, Assigned: masayuki)

References

(Blocks 1 open bug, )

Details

Attachments

(1 file)

The current spec still defines "long" types for coordinates.

Filing this bug to track interests from web developers (see bug 1234669 comment 2) and the open spec issue https://github.com/w3c/uievents/issues/40.

Just want to add some additional context and a maybe unpleasant addendum here:

This is needed when a canvas in a high DPI setup is in play, that is, the canvas takes more physical device pixels than it does CSS pixels.
In that case, pointer events must be accurate to device pixels, otherwise some pixels are skipped in input processing, which results in apparent jagged motion when the input coordinates are used to render something in the canvas.

But that is not quite all.
See this discussion: https://github.com/KhronosGroup/WebGL/issues/2460
(there's a whole bunch of related issues mostly from the WebGL team)

Summary: Multiplying CSS pixel coordinates with the devicePixelRatio value will de facto produce off-by-one errors due to rounding issues, depending on circumstances. Any attempt to calculate the number of physical device pixels occupied by an arbitrary canvas given its bounds in CSS pixels, by using devicePixelRatio is doomed to fail with current browser implementations, and can lead to visible moire patterns in the canvas. This led to the creation of device-pixel-border-box in ResizeObserver, which gives the size in actual device pixels.

I am mentioning this because technically, pointer coordinates have a similar problem. Most code I've seen multiplies the pointer event coordinates with devicePixelRatio (I am not aware of any way to get raw device coordinates here - if there is, disregard this comment). As a user, given fractional pointer coordinates, and a fractional device pixel ratio, I would expect the resulting device pixel coordinate to be accurate within the limits of floating point arithmetic, and a rounding error should not occur in this order of magnitude.

See Also: → 1644307

This is being handled in bug 1680669 IIUC, while I am not sure if there's anything left even after bug 1680669 is done.

Depends on: 1680669
Duplicate of this bug: 1931595

Let's use this bug to ship the fix of bug 1680669.

Assignee: nobody → masayuki
Status: NEW → ASSIGNED
OS: Unspecified → All
Hardware: Unspecified → All
Summary: [pointer event] convert coordinates from long to double → Ship fractional coordinates of Pointer Events

Although it's tested only 3 weeks in the Nightly channel, it may be okay to
ship it because there is no regression report and the value new value is not
far over 1px.

Depends on D232822

Pushed by masayuki@d-toybox.com: https://hg.mozilla.org/integration/autoland/rev/dd8dce538c37 Ship fractional coordinates of `PointerEvent` r=smaug
Status: ASSIGNED → RESOLVED
Closed: 8 months ago
Resolution: --- → FIXED
Target Milestone: --- → 135 Branch

Is this something we should call out in the Fx135 relnotes? Please add a relnote-firefox request if so.

Flags: needinfo?(masayuki)

Release Note Request (optional, but appreciated)
[Why is this notable]: A major improvement of Pointer Events
[Affects Firefox for Android]: Yes, and important for Android
[Suggested wording]: The attribute values which indicate the coordinates of PointerEvent may be fractional values rather than integer. This allows web app developers to handle the events with higher precision coordinates when the target element is transitioned by CSS and/or the viewport is zoomed.

This is applied to untrusted events too, but is not applied to click, auxclick nor contextmenu events which were introduced as MouseEvent (for backward compatibility).
[Links (documentation, blog post, etc)]: https://w3c.github.io/pointerevents/#event-coordinates

relnote-firefox: --- → ?
Flags: needinfo?(masayuki)

Added to the Fx135 relnotes.

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: