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 DOM and requestPointerLock() #192

Closed
hayatoito opened this issue Jul 6, 2015 · 10 comments
Closed

Shadow DOM and requestPointerLock() #192

hayatoito opened this issue Jul 6, 2015 · 10 comments

Comments

@hayatoito
Copy link
Contributor

Title: [Shadow]: How should Element.requestPointerLock() work in shadow DOM? (bugzilla: 26934)

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


comment: 0
comment_url: https://www.w3.org/Bugs/Public/show_bug.cgi?id=26934#c0
Olli Pettay wrote on 2014-09-29 23:47:53 +0000.

Currently requestPointerLock requires element to be in Document, but Chromium
does let one to lock pointer to a shadow dom element too.


comment: 1
comment_url: https://www.w3.org/Bugs/Public/show_bug.cgi?id=26934#c1
** wrote on 2014-09-30 15:38:41 +0000.

There's nothing fundamentally wrong with pointer lock targeting any element. Specifying the element must be in the document easily handles any kind of navigation concerns (where lock must be released) and dismiss any open ended questions about where events are headed if elements aren't in the document.

Here are the relevant sections of Pointer Lock:

"""
5.1 Methods

requestPointerLock

...

Pointer lock must succeed only if the target is in the active document of a browsing context which is (or has an ancestor browsing context which is) in focus by a window which is in focus by the operating system's window manager.

...

8 Requirements

Pointer lock must be exited if the target is removed from its document, or the user agent, window, or tab loses focus. Moving focus between elements of active documents, including between browsing contexts, does not exit pointer lock. E.g. using the keyboard to move focus between contents of frames or iframes will not exit.
"""

And here is a draft of a change to add shadow tree/host to the sections:

"""
5.1 Methods

requestPointerLock

...

Pointer lock must succeed only if the target is in the active document (or a shadow tree of a shadow host in the active document) of a browsing context which is (or has an ancestor browsing context which is) in focus by a window which is in focus by the operating system's window manager.

...

8 Requirements

Pointer lock must be exited if any of the follow occur:

  • The target is removed from its document.
  • The target is removed from its shadow tree.
  • The user agent, window, or tab loses focus.
    Moving focus between elements of active documents, including between browsing contexts, does not exit pointer lock. E.g. using the keyboard to move focus between contents of frames or iframes will not exit.
    """

Review & comments please.


comment: 2
comment_url: https://www.w3.org/Bugs/Public/show_bug.cgi?id=26934#c2
Olli Pettay wrote on 2014-09-30 15:49:09 +0000.

5.1 Methods

requestPointerLock

...

Pointer lock must succeed only if the target is in the active document (or a
shadow tree of a shadow host in the active document)
We probably don't want elements in older shadow trees which aren't projected to newer shadow trees to
be able to lock the pointer.

@annevk
Copy link
Collaborator

annevk commented Mar 11, 2016

@scheib, thoughts? See #180 for my thoughts on what to do for Fullscreen.

@annevk annevk changed the title [Shadow]: How should Element.requestPointerLock() work in shadow DOM? (bugzilla: 26934) Shadow DOM and requestPointerLock() Mar 11, 2016
@scheib
Copy link

scheib commented Mar 16, 2016

I don't know yet.

I'm not currently sufficiently familiar with Shadow DOM, and in 15 minutes could not understand open/closed trees, and thus do not understand the discussion in #180 for Fullscreen. I also don't fully understand andyearnshaw's fullscreen usecase.

From my simplistic understanding, Pointer Lock should work for any node in a tree that can eventually (even through shadow DOM boundaries) reach the root document node of a frame.

Permission should be controlled by a single origin.

Lock should be exited if the node is no longer in the tree (as above), or navigation, or loss of document focus.

Generally, if a shadow node has lock and there's a need to disambiguate that element, the shadowRoot.fullscreenElement concept seems to be reasonable, but I don't really understand it yet.

I can contribute more to this discussion after either finding more time to learn Shadow DOM or by answering more specific questions Shadow DOM folk have.

@annevk
Copy link
Collaborator

annevk commented Mar 17, 2016

@scheib the principle we try to follow is that the "light tree" cannot know about the existence of the "shadow tree". (There's a couple of exceptions to that rule, but not for normal APIs such as Fullscreen and Pointer Lock, most likely. That's why document.fullscreenElement would be null when an element inside one of its shadow trees is fullscreen.)

Looking over https://w3c.github.io/pointerlock/ I guess the additional complication for Pointer Lock beyond what Fullscreen has is event retargeting and what that means for movementX/Y.

@scheib
Copy link

scheib commented Mar 23, 2016

OK, so the goal is that when a shadow node acquires lock the light tree should be ignorant.

Then I would suggest

  • Relocking without requiring a user gesture should only work from within the same tree. See 5.1 with text: "If a user has exited pointer lock via the default unlock user gesture, or pointer lock has not previously been entered for this document...". That logic is intended for script code to exit and re-enter lock state - but it doesn't make sense for that logic to cross a shadow tree boundary.
  • When locked, no mouse event of any kind should be dispatched, or bubbled, to the light DOM.
  • When locked to a light or shadow tree A a subsequent lock to a node in a different light or shadow tree B should be blocked, similar to text in requestPointerLock

If any element in another document is already locked the request must fail and a pointerlockerror event be sent.

I don't fully understand the shadow tree document structure. Does each tree have a document, or is the document a mix of trees? Presuming the later, these are needed:

  • shadowRoot.pointerlockElement so that the shadow node can use the element, while light DOM is not affected.
  • shadowRoot.onpointerlockchange and shadowRoot.onpointerlockerror would also be needed to be hidden in shadowRoot
  • shadowRoot.exitPointerLock should only work for a lock in the currently locked tree.

I don't think changes are needed for:

  • movementX/Y. So long as no events are reached by the light tree there will be no opportunity to read those values.
  • light tree 'enabling' the feature, similar to iframe (see 5.1 requestPointerLock active sandboxing flag)

@annevk
Copy link
Collaborator

annevk commented Mar 23, 2016

Thank you, that seems pretty reasonable to me. There's no rush for Pointer Lock to move first here. I'll ping this thread when some other features have started accounting for shadow trees.

@hayatoito
Copy link
Contributor Author

It looks okay, however, DocumentOrShadowRoot is the place where pointerlockElement, onpointerlockchange, onpointerlockerror, exitPointerLock should be defined.

You can use this mixin, instead of Document, in the Pointer Lock spec.

@hayatoito hayatoito changed the title Shadow DOM and requestPointerLock() Shadow DOM and requestPointerLock(), fullscreenElement Jun 1, 2016
@hayatoito
Copy link
Contributor Author

I have merged #180 into this issue.
@scheib , could you update https://w3c.github.io/pointerlock/ ?

If you need help, I think we are happy to help you.

@hayatoito hayatoito changed the title Shadow DOM and requestPointerLock(), fullscreenElement Shadow DOM and requestPointerLock() Jun 1, 2016
@TakayoshiKochi
Copy link
Member

Now this is detached from #180 again, but it is quite similar in API surface.
If I apply the same (#180) to this, the following differs from what @scheib and @HAYATO said in the above:

  • when an element in a shadow tree acquires pointer lock, document.pointerLockElement can point to its shadow host, and its shadowRoot.pointerLockElement points to the pointer locked element. (or if the element is further down descendant shadows, points to a shadow host, recursively)
  • pointerlockchange / pointerlockerror events are dispatched on document, not on shadow roots (maybe in the future, after Shadow DOM v1)

@scheib does this look good to you?
If anything is unclear about Shadow DOM, please let me know. From reading your comments above, your understanding of Shadow DOM looks quite good.

@scheib
Copy link

scheib commented Jun 16, 2016

Thank you, I agree with these, as we discussed in person.

TakayoshiKochi added a commit to TakayoshiKochi/pointerlock that referenced this issue Jun 23, 2016
See discussion about this change at:
WICG/webcomponents#192

Splits Document.pointerLockElement into Document.pointerLockElement and
ShadowRoot.pointerLockElement and encapsulates shadow tree from
document.

Other than split, replaces document to 'shadow-including document' where
necessary.
TakayoshiKochi added a commit to TakayoshiKochi/pointerlock that referenced this issue Jun 24, 2016
See discussion about this change at:
WICG/webcomponents#192

Splits Document.pointerLockElement into Document.pointerLockElement and
ShadowRoot.pointerLockElement and encapsulates shadow tree from
document.

Other than split, replaces document to 'shadow-including document' where
necessary.
TakayoshiKochi added a commit to TakayoshiKochi/pointerlock that referenced this issue Jun 24, 2016
See discussion about this change at:
WICG/webcomponents#192

Splits Document.pointerLockElement into Document.pointerLockElement and
ShadowRoot.pointerLockElement and encapsulates shadow tree from
document.

Other than split, replaces document to 'shadow-including document' where
necessary.
TakayoshiKochi added a commit to TakayoshiKochi/pointerlock that referenced this issue Jun 27, 2016
See discussion about this change at:
WICG/webcomponents#192

Splits Document.pointerLockElement into Document.pointerLockElement and
ShadowRoot.pointerLockElement and encapsulates shadow tree from
document.

Other than split, replaces document to 'shadow-including document' where
necessary.
TakayoshiKochi added a commit to TakayoshiKochi/pointerlock that referenced this issue Jun 28, 2016
See discussion about this change at:
WICG/webcomponents#192

Splits Document.pointerLockElement into Document.pointerLockElement and
ShadowRoot.pointerLockElement and encapsulates shadow tree from
document.

Other than split, replaces document to 'shadow-including document' where
necessary.
TakayoshiKochi added a commit to TakayoshiKochi/pointerlock that referenced this issue Jun 30, 2016
See discussion about this change at:
WICG/webcomponents#192

Splits Document.pointerLockElement into Document.pointerLockElement and
ShadowRoot.pointerLockElement and encapsulates shadow tree from
document.

Other than split, replaces document to 'shadow-including document' where
necessary.
TakayoshiKochi added a commit to TakayoshiKochi/pointerlock that referenced this issue Jun 30, 2016
See discussion about this change at:
WICG/webcomponents#192

Splits Document.pointerLockElement into Document.pointerLockElement and
ShadowRoot.pointerLockElement and encapsulates shadow tree from
document.

Other than split, replaces document to 'shadow-including document' where
necessary.
TakayoshiKochi added a commit to TakayoshiKochi/pointerlock that referenced this issue Jul 1, 2016
See discussion about this change at:
WICG/webcomponents#192

Splits Document.pointerLockElement into Document.pointerLockElement and
ShadowRoot.pointerLockElement and encapsulates shadow tree from
document.

Other than split, replaces document to 'shadow-including document' where
necessary.
TakayoshiKochi added a commit to TakayoshiKochi/pointerlock that referenced this issue Jul 1, 2016
See discussion about this change at:
WICG/webcomponents#192

Splits Document.pointerLockElement into Document.pointerLockElement and
ShadowRoot.pointerLockElement and encapsulates shadow tree from
document.

Other than split, replaces document to use Shadow DOM-aware vocabulary
like 'shadow-including root' where necessary.

Fixes w3c#3.
TakayoshiKochi added a commit to TakayoshiKochi/pointerlock that referenced this issue Jul 4, 2016
See discussion about this change at:
WICG/webcomponents#192

Splits Document.pointerLockElement into Document.pointerLockElement and
ShadowRoot.pointerLockElement and encapsulates shadow tree from
document.

Other than split, replaces document to use Shadow DOM-aware vocabulary
like 'shadow-including root' where necessary.

Fixes w3c#3.
TakayoshiKochi added a commit to TakayoshiKochi/pointerlock that referenced this issue Jul 5, 2016
See discussion about this change at:
WICG/webcomponents#192

Splits Document.pointerLockElement into Document.pointerLockElement and
ShadowRoot.pointerLockElement and encapsulates shadow tree from
document.

Other than split, replaces document to use Shadow DOM-aware vocabulary
like 'shadow-including root' where necessary.

Fixes w3c#3.
TakayoshiKochi added a commit to TakayoshiKochi/pointerlock that referenced this issue Jul 5, 2016
See discussion about this change at:
WICG/webcomponents#192

Splits Document.pointerLockElement into Document.pointerLockElement and
ShadowRoot.pointerLockElement and encapsulates shadow tree from
document.

Other than split, replaces document to use Shadow DOM-aware vocabulary
like 'shadow-including root' where necessary.

Fixes w3c#3.
TakayoshiKochi added a commit to TakayoshiKochi/pointerlock that referenced this issue Jul 8, 2016
See discussion about this change at:
WICG/webcomponents#192

Splits Document.pointerLockElement into Document.pointerLockElement and
ShadowRoot.pointerLockElement and encapsulates shadow tree from
document.

Other than split, replaces document to use Shadow DOM-aware vocabulary
like 'shadow-including root' where necessary.

Fixes w3c#3.
TakayoshiKochi added a commit to TakayoshiKochi/pointerlock that referenced this issue Jul 8, 2016
See discussion about this change at:
WICG/webcomponents#192

Splits Document.pointerLockElement into Document.pointerLockElement and
ShadowRoot.pointerLockElement and encapsulates shadow tree from
document.

Other than split, replaces document to use Shadow DOM-aware vocabulary
like 'shadow-including root' where necessary.

Fixes w3c#3.
TakayoshiKochi added a commit to TakayoshiKochi/pointerlock that referenced this issue Jul 8, 2016
See discussion about this change at:
WICG/webcomponents#192

Splits Document.pointerLockElement into Document.pointerLockElement and
ShadowRoot.pointerLockElement and encapsulates shadow tree from
document.

Other than split, replaces document to use Shadow DOM-aware vocabulary
like 'shadow-including root' where necessary.

Fixes w3c#3.
TakayoshiKochi added a commit to TakayoshiKochi/pointerlock that referenced this issue Jul 12, 2016
See discussion about this change at:
WICG/webcomponents#192

Splits Document.pointerLockElement into Document.pointerLockElement and
ShadowRoot.pointerLockElement and encapsulates shadow tree from
document.

Other than split, replaces document to use Shadow DOM-aware vocabulary
like 'shadow-including root' where necessary.

Fixes w3c#3.
scheib pushed a commit to w3c/pointerlock that referenced this issue Jul 12, 2016
Splits Document.pointerLockElement into Document.pointerLockElement and
ShadowRoot.pointerLockElement and encapsulates shadow tree from
document.

Other than split, replaces document to use Shadow DOM-aware vocabulary
like 'shadow-including root' where necessary.

See discussion about this change at:
WICG/webcomponents#192

And the pull request at:
#4

Fixes #3.
@TakayoshiKochi
Copy link
Member

The spec working draft is updated to include the conclusion here.

@hayatoito could you close this?

TakayoshiKochi pushed a commit to TakayoshiKochi/web-platform-tests that referenced this issue Oct 3, 2016
TakayoshiKochi pushed a commit to web-platform-tests/wpt that referenced this issue Oct 4, 2016
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

4 participants