Skip to content
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

[Shadow]: Make event retargeting optional (bugzilla: 28444) #89

Closed
hayatoito opened this issue May 25, 2015 · 2 comments
Closed

[Shadow]: Make event retargeting optional (bugzilla: 28444) #89

hayatoito opened this issue May 25, 2015 · 2 comments

Comments

@hayatoito
Copy link
Contributor

Title: [Shadow]: Make event retargeting optional (bugzilla: 28444)

Migrated from: https://www.w3.org/Bugs/Public/show_bug.cgi?id=28444


comment: 0
comment_url: https://www.w3.org/Bugs/Public/show_bug.cgi?id=28444#c0
Dimitri Glazkov wrote on 2015-04-08 16:00:41 +0000.

From https://lists.w3.org/Archives/Public/public-webapps/2015AprJun/0052.html

Annevk: "I think opt-in (or only
with isolated) would be better and perhaps if the API needs to change
anyway we can do that, but we could probably live with opt-out as
well. When you use shadow DOM to compose, global reasoning about state
and events is a fairly established pattern that we should enable."


comment: 1
comment_url: https://www.w3.org/Bugs/Public/show_bug.cgi?id=28444#c1
Dimitri Glazkov wrote on 2015-04-08 18:27:59 +0000.

As far as I understand, the event.path is the mechanism to enable global reasoning about events. Optional event retargeting seems to be only complicating already complex algos. Consider a scenario where you have a mix of trees with and without retargeting.


comment: 2
comment_url: https://www.w3.org/Bugs/Public/show_bug.cgi?id=28444#c2
Anne wrote on 2015-04-13 09:32:36 +0000.

Yeah, which is why perhaps we should only do retargeting if the tree is explicitly closed. (Isolated would also have to do it of course.)

That seems like a much more logical model and allows for event.path and event.target to be consistent. The current approach seems a lot like the originalTarget approach from XBL.


comment: 3
comment_url: https://www.w3.org/Bugs/Public/show_bug.cgi?id=28444#c3
Dimitri Glazkov wrote on 2015-04-13 17:42:47 +0000.

(In reply to Anne from comment #2)

Yeah, which is why perhaps we should only do retargeting if the tree is
explicitly closed. (Isolated would also have to do it of course.)

This suggestion is interesting, but it is orthogonal to the complexity concern. I would still need extra branch points in the retargeting algos in order to account for nested trees that interleave the setting with and without retargeting (whether or not coupled to the closed/open setting), plus the extra transitive complexity of managing insertion points.

That seems like a much more logical model and allows for event.path and
event.target to be consistent. The current approach seems a lot like the
originalTarget approach from XBL.

Can you explain a bit more why event.path seems bad? As far as I can tell, it works well for consumers with event delegation needs.


comment: 4
comment_url: https://www.w3.org/Bugs/Public/show_bug.cgi?id=28444#c4
Dimitri Glazkov wrote on 2015-04-13 18:01:23 +0000.

+dfreedm to comment on the coupling of closed/open and retargeting opt-in idea.


comment: 5
comment_url: https://www.w3.org/Bugs/Public/show_bug.cgi?id=28444#c5
Daniel Freedman wrote on 2015-04-13 22:17:16 +0000.

I think retargeting events for "open" shadowroots is still the right paradigm.

When composing elements with ShadowRoots together, it is far more useful to think of those elements as one whole, rather than their constituent pieces.
With retargeting, a developer can use very simple event delegation in their own scope with event.target for discrete composition points, rather than some more complicated ancestry checking.

For example:

If I have a fancy tab bar that controls content

#shadow-root #shadow-root Tab One! (..snip..) Tab Two!

and click on the first tab, with retargeting I can just check event.target === #one to show the associated content.

With event retargeting, each composition boundary can have this simple event delegation construct and be very intuitive for development.

I see event.path as more useful for a global event delegation mechanism, such as for determining desired scrolling behavior with touch events:

for (var i = 0, el; el = touchEvent.path[i]; i++)
if (el._shouldStopScrolling)
touchEvent.preventDefault();


comment: 6
comment_url: https://www.w3.org/Bugs/Public/show_bug.cgi?id=28444#c6
Hayato Ito wrote on 2015-04-27 03:17:25 +0000.

Let me move this bug to v2 since it is not a blocker for v1.

@hayatoito
Copy link
Contributor Author

Note: According to the resolution at f2f, [1], "no separation--always retarget".
[1] https://www.w3.org/wiki/Webapps/WebComponentsApril2015Meeting

We should do "retargeting events" for "open shadow trees" by default.

I don't think we should allow turning retargeting off, it violates the "never fall into a shadowRoot by mistake principle". Unless there is an explicit intention, any existing APIs shouldn't allow users to access the shadow tree by accident. "event.target" is one of such APIs.

Note that you can use event.deepPath[0] to access the event's target without retargeting.

See also #76 for relatedTarget.

As for "opt-out of retargeting", which might be an explicit intention, I don't have any strong opinion.
If you feel that we should have a way to "opt-out", please give us feedback.

@hayatoito
Copy link
Contributor Author

Let me close this issue. I think we have a consensus that we should retarget, always.
As a work around, we can use Event.deepPath() or Event.deepRelatedTarget, which is being discussed in #76.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants