New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MouseEvent: fix pageX/Y
and offsetX/Y
during dispatch
#3514
Conversation
test/web-platform-tests/to-upstream/html/editing/activation/click-event-properties.html
Show resolved
Hide resolved
Filed this CSSOM View issue to address the issues around synthetic pointer events |
f76a390
to
2db706a
Compare
The second commit:
On a related note, I opened a wpt PR to expand the CSSOM View MouseEvent tests. There's a bit of overlap with the tests in this PR, but we can't use the wpt ones until JSDOM implements |
pageX/Y
during dispatchpageX/Y
and offsetX/Y
during dispatch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all the iteration here, and sorry I haven't had time to participate in the discussion until now!
My issue is that I'm really uncomfortable with how window.scrollX and scrollY setters appear to be a key part of the story here. I'd like us to make those readonly, or at the very least assume they never change and not write tests which rely on changing them.
Where does that leave us?
...-platform-tests/to-upstream/html/editing/activation/click-event-properties-dontupstream.html
Outdated
Show resolved
Hide resolved
} | ||
return this.pageY; | ||
} | ||
|
||
/** @override */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please avoid jsdoc here and elsewhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be worth spelling this out in Contributing.md or elsewhere? Seems like there's some existing jsdoc comments/tags in the codebase
Yeah that sounds reasonable, just two comments:
|
Ensure that `pageX/Y` reflect the coordinate relative to the origin of the window at the time of init (i.e. `clientX/Y` plus `scrollX/Y`). We record it during init, since `scrollX/Y` may change, which could result in the wrong `pageX/Y` values; see added tuWPT. Also track the target-relative coordinate during init (still just `(0, 0)` in the absence of layout support). This doesn't fundamentally change any behavior, but makes the implementation more future proof, making it safer to start handling Image Button submitters when constructing the form data set; see jsdom#3496 where this code was extracted from.
2db706a
to
263d7b2
Compare
} | ||
|
||
set target(target) { | ||
super.target = target; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another way to implement this, maybe more elegant, would be a _receivedTarget
method on the parent EventImpl
class:
class EventImpl {
set target(target) {
this._target = target;
this._receivedTarget();
}
_receivedTarget() {}
}
class MouseEventImpl {
_receivedTarget() {
// calculate offsets from this.target
}
}
Chrome's Event
implementation also has a ::ReceivedTarget
method, and JSDOM also has similar prior art in the _activationBehavior()
method on elements.
In a real browser, setting Compliant code would have access to the If we want to avoid snowballing this PR too much, I think we'll either need to accept the incorrect |
Hi @domenic 👋 what are you thoughts about what needs to be done to move this PR forward? There were concerns about setting |
I admit I've lost the plot on what we're trying to accomplish here. This thread is too long and this PR contains many changes which seem to be about future-proofing for some hypothetical future where we support layout or scrolling, which makes it hard to understand. The WPT added here does not pass in Firefox or Chrome: https://jsbin.com/sexirixixo/edit?html,output which maybe is a spec problem, maybe is a test problem. I tried setting out guidelines I'd like us to follow about, but perhaps they were too implicit. The guidelines I'd like are:
I hope that helps... I think the current PR does not meet these criteria because the WPT that was added fails in two browsers, but admittedly I haven't tested Safari, so maybe it matches the spec and Safari. So that's the immediate problem. After that, I'd encourage getting the PR into shape such that it's easy to review, per the above guidelines. |
All fair points, I'll clean this up and remove scrollX/Y stuff in the code in favor of comments. Upstream wpts should have this covered for if/when jsdom ever implements scrolling/layout, at which point the implementation could be fleshed out and comments removed. As for the test, there's a dumb oversight on my part, as it can be made to pass in browsers and jsdom. I wrote it with jsdom in mind, so I didn't consider the body margin and button border, which makes it fail in browsers 🙃 ... the test passes if the event is dispatched against window or some other border-less element at the page origin. |
Ok latest commit hopefully addresses everything. I also updated the PR summary to reflect the current state of things 🤞 |
Thanks @jenseng for greatly simplifying the PR. I'm confirming that it addresses the main concern I had: when I create a e = new MouseEvent('mousedown', { clientX: 10, clientY: 20 }); the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your patience here!
Ensure that
pageX/Y
reflect the coordinate relative to the origin of the document (i.e.clientX/Y
in the absence of scrolling support) during dispatch.Also fix the target-relative coordinate (
offsetX/Y
) during dispatch. This will typically be(0, 0)
(e.g. in a synthetic click or a dispatchedMouseEvent
with default coordinates), but it will mirrorclientX/Y
if those are set.Lastly, remove some
scrollX/Y
logic for values computed outside of dispatch. While it logically followed the spec, scrolling is not implemented and it is unsafe to base the calculation on those replaceable properties.cc @jsnajdr
See also: