-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Improve CommandEvent and ToggleEvent source retargeting #11345
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
Changes from 4 commits
9b41097
33ce103
68da488
f5d97a2
894dd14
6bd255f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80604,11 +80604,10 @@ dictionary <dfn dictionary>ToggleEventInit</dfn> : <span>EventInit</span> { | |
| data-x="dom-ToggleEvent-newState">newState</code></dfn> attributes must return the values they are | ||
| initialized to.</p> | ||
|
|
||
| <p>The <dfn attribute for="ToggleEvent"><code | ||
| data-x="dom-ToggleEvent-source">source</code></dfn> getter steps are to return the result of | ||
| <span data-x="dom-retarget">retargeting</span> <code | ||
| data-x="dom-ToggleEvent-source">source</code> against <span>this</span>'s <code | ||
| data-x="dom-Event-currentTarget">currentTarget</code>.</p> | ||
| <p>The <dfn attribute for="ToggleEvent"><code data-x="dom-ToggleEvent-source">source</code></dfn> | ||
| getter steps are to return the result of <span>retarget against an event</span> given | ||
| <span>this</span> and <span>this</span>'s <code | ||
| data-x="dom-ToggleEvent-source">source</code>.</p> | ||
|
|
||
| <p class="XXX"><a href="https://github.com/whatwg/dom/issues/1328">DOM standard issue #1328</a> | ||
| tracks how to better standardize associated event data in a way which makes sense on Events. | ||
|
|
@@ -80662,15 +80661,25 @@ dictionary <dfn dictionary>CommandEventInit</dfn> : <span>EventInit</span> { | |
|
|
||
| <p>The <dfn attribute | ||
| for="CommandEvent"><code data-x="dom-CommandEvent-source">source</code></dfn> getter steps are to | ||
| return the result of <span data-x="dom-retarget">retargeting</span> <code | ||
| data-x="dom-CommandEvent-source">source</code> against <span>this</span>'s <code | ||
| data-x="dom-Event-currentTarget">currentTarget</code>.</p> | ||
| return the result of <span>retarget against an event</span> given <span>this</span> and | ||
| <span>this</span>'s <code data-x="dom-CommandEvent-source">source</code>.</p> | ||
|
|
||
| <p class="XXX"><a href="https://github.com/whatwg/dom/issues/1328">DOM standard issue #1328</a> | ||
| tracks how to better standardize associated event data in a way which makes sense on Events. | ||
| Currently an event attribute initialized to a value cannot also have a getter, and so an internal | ||
| slot (or map of additional fields) is required to properly specify this.</p> | ||
|
|
||
| <p>To <dfn>retarget against an event</dfn>, given an <code>Event</code> <var>event</var> and a | ||
| <code>Node</code> <var>node</var>:</p> | ||
|
|
||
| <ol> | ||
| <li><p>If <var>event</var>'s <span data-x="concept-event-target">target</span> is null, then | ||
| return null.</p></li> | ||
|
|
||
| <li><p>Return the result of <span data-x="dom-retarget">retargeting</span> <var>node</var> | ||
| against <var>retargetAgainst</var>.</p></li> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand this setup. We want events which have been dispatched in light DOM to have their .source retargeted? What is the use case for that. Events dispatched in shadow DOM would get just null.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If the event has been dispatched in light DOM, then retargeting won't change the resulting source element that we return; we are effectively not retargeting events that are dispatched in light DOM.
If the event was dispatched in shadow DOM, then source will become null after event dispatch is done, just like target and relatedTarget. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the event has been dispatched in light dom and source is in shadow DOM, retargeting will happen. But what are we trying to achieve with this rather unusual setup? Why do we need to fall back to 'target'?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ah yes, that is true. In this case, I'm assuming that you still don't want source to be leaked somewhere since it is in a shadow root, so we should do retargeting.
Target is better than currentTarget because after event dispatch target is likely still set to something we can retarget against which won't leak any nodes, whereas currentTarget just becomes null. Now that I think about it, maybe we can just always retarget against target instead of currentTarget
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed the usage of currentTarget and now it just uses target. It shouldn't change the behavior.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is that also what happens for relatedTarget? Ideally source works the same way as relatedTarget. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. retargetAgainst isn't defined anywhere There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But what is actually wrong with the current .source handling. I'm still not quite sure what we're trying to fix here. The current spec retargets shadow course to first light DOM host after dispatch. And during dispatch it is retargeted so that .source will be in the same or "higher" subtree than currentTarget/target. The discussion about having relatedTarget type of behavior is more about tweaking the propagation path if we kept command event as composed, since once relatedTarget and target are in the same subtree, the event won't propagate higher up.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Thanks, I fixed that.
Since it returns the original source element when currentTarget is not set, after event dispatch you can get the original element without retargeting: #11255 (comment)
I agree, I made this more simple assuming that we are going to make the command event not composed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Well, only if the original source element is in light DOM. |
||
| </ol> | ||
|
|
||
| <h3>Focus</h3> | ||
|
|
||
| <!-- https://software.hixie.ch/utilities/js/live-dom-viewer/?saved=2807 --> | ||
|
|
||
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.
I still don't understand what we're trying to fix here. The current setup doesn't leak shadow DOM .source, or I don't understand how it does that. Could you explain?
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.
It would only leak if you create a synthetic event with
sourceset to something in a shadow tree. Or if a new specification comes along that does something similar and reuses this event class. The question has become if we should put in protections for these cases as well. I kinda think we should.I still don't understand why this is not the same as relatedTarget though. It seems weird to have a completely different mechanism.
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.
Why would it leak even with synthetic events?
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.
If you don't retarget wouldn't it just return the node it was set to? Which could be from a shadow tree?
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.
It actually looks like neither Chrome nor Firefox follow the existing spec, as is written today. The spec today says:
But both implementations do more like:
This can be seen in the Chrome implementation of command_event.cc L46-50:
And in the Firefox implementation CommandEvent.cpp L83-93:
So the spec is right and two impls are wrong. If the implementations followed the spec this would be a non-issue, and this PR is perhaps redundant.
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.
there is already the existing retarget in the spec.
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.
I see, your concern is with the rewrite in particular, not with retargeting in general. Glad we're in agreement on retargeting in general. @keithamus or @josepharhar will have to answer this then.