-
Notifications
You must be signed in to change notification settings - Fork 3k
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
base: main
Are you sure you want to change the base?
Changes from 3 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,30 @@ 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>Let <var>retargetAgainst</var> be <var>event</var>'s <code | ||
| data-x="dom-Event-currentTarget">currentTarget</code>.</p></li> | ||
|
|
||
| <li><p>If <var>retargetAgainst</var> is null, then set <var>retargetAgainst</var> to | ||
| <var>event</var>'s <span data-x="concept-event-target">target</span>.</p></li> | ||
|
||
|
|
||
| <li><p>If <var>retargetAgainst</var> 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> | ||
| </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.