Map event coordinates through CSS transforms - #664
Open
nicoburns wants to merge 1 commit into
Open
Conversation
Element coordinates of pointer/wheel events, and the coordinates forwarded to sub-documents and custom widgets, were computed from the untransformed layout position, so a transform on the element (or an ancestor) shifted them. Map the event point through the same inverse transforms and scroll offsets that hit-testing applies instead. Fixes #663
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #663: a CSS transform on an element (or an ancestor) shifted the element coordinates of pointer/wheel events, and shifted the page/client coordinates forwarded to sub-documents and custom widgets.
Both paths derived coordinates from
absolute_position(), which is a plain offset sum and ignores transforms:EventDriver::adjust_element_coords:element = client - get_client_bounding_rect(target)handle_dom_event:coords -= node.absolute_position(0,0)The fix maps the event's page point into the target's local border-box space using the same math hit-testing already uses (per node along the layout chain:
- location + scroll_offset, then inversetransform, then the inline-root content-box offset):Node::page_point_to_local(x, y, scale)— walks the layout-parent chain top-down mirroringhit_innerBaseDocument::page_point_to_element_space(node_id, x, y)— wraps it, handling non-atomic inline elements (no layout box) by mapping into the inline root and offsetting by their fragment-rect originadjust_element_coordsand the sub-document/custom-widget forwarding now use these; forwarding also sets the forwarded event'selementpoint and now adjustsWheelcoords (previously forwarded unadjusted)Hoisted (z-index) children work because their accumulated
HoistedPaintChild::positionequals the sum of intermediate layout locations minus scrolls, and intermediates between a stacking-context root and a hoisted child can't carry transforms (a transform is itself an SC root).Regression tests in
tests/blitz-tests/tests/transformed_event_coords.rscover ancestor translation, the transformed element itself, hidpi scale, rotation, and the untransformed baseline.Link to Devin session: https://dioxus.staging.devinenterprise.com/sessions/f1ed0334be0c4f08a5b6b2aaa7194463
Requested by: @nicoburns
WPT results
No changes in test results compared to
main.Generated by the WPT workflow.