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

How :fullscreen CSS pseudo class works in shadow dom? #149

Open
beaufortfrancois opened this issue Mar 20, 2019 · 13 comments · May be fixed by #212
Open

How :fullscreen CSS pseudo class works in shadow dom? #149

beaufortfrancois opened this issue Mar 20, 2019 · 13 comments · May be fixed by #212
Labels
topic: shadow Relates to shadow trees (as defined in DOM)

Comments

@beaufortfrancois
Copy link

After reading the spec, I'm still not sure how CSS pseudo-class :fullscreen works in the context of shadow dom. See example below:

<style>
  :fullscreen { color: blue }
</style>
<my-web-component>
  #shadow-root
    <style>
      :fullscreen { color: green }
    </style>
    <video></video>
</my-web-component>

What happens after await video.requestFullscreen()?

  • Is <video> element color green?
  • Is <my-web-component> element color blue?

Note that I wasn't able to find web platform tests for this.

@beaufortfrancois
Copy link
Author

beaufortfrancois commented Mar 20, 2019

FYI @foolip @TakayoshiKochi

@foolip
Copy link
Member

foolip commented Mar 20, 2019

Per "element is a shadow host and the result of retargeting its node document’s fullscreen element against element is element" in https://fullscreen.spec.whatwg.org/#:fullscreen-pseudo-class both the video element and the my-web-component element should match the :fullscreen pseudo class.

However, this isn't implemented in Chromium. Which behavior are you actually seeing?

@beaufortfrancois
Copy link
Author

I only see video element matching the :fullscreen pseudo class in Chromium hence my question.

@foolip
Copy link
Member

foolip commented Mar 20, 2019

OK, that's not too surprising. It's probably not too difficult to match the spec here, but it might require an extra flag on all elements. Haven't tried to implement it myself thought, could be trivial.

@beaufortfrancois
Copy link
Author

Following discussions at https://groups.google.com/a/chromium.org/d/msg/blink-dev/X-qPSmdSR_g/mRKxdlVICgAJ and WICG/webcomponents#804, I believe the fullscreen API spec should removes retargeting for the :fullscreen CSS pseudo class.

@foolip
Copy link
Member

foolip commented Jun 5, 2019

@beaufortfrancois that would follow w3c/picture-in-picture#126, right? There's also retargeting in https://fullscreen.spec.whatwg.org/#dom-document-fullscreenelement, what should happen to that?

@nt1m
Copy link
Member

nt1m commented Dec 15, 2022

@foolip @beaufortfrancois Has any progress been made on this issue? Removing retargeting would simplify implementations.

@beaufortfrancois
Copy link
Author

Picture-in-Picture spec has removed retargeting. I didn't follow up with the current state of Fullscreen API.

@nt1m nt1m linked a pull request Dec 19, 2022 that will close this issue
4 tasks
@annevk
Copy link
Member

annevk commented Dec 21, 2022

Based on what @rniwa just wrote in WICG/webcomponents#804 (comment) it seems like that change to picutre-in-picture was wrong and we shouldn't be changing :fullscreen either.

@foolip
Copy link
Member

foolip commented Dec 21, 2022

I wrote this test to see if anyone has implemented the second condition (element is a shadow host and the result of retargeting its node document’s fullscreen element against element is element) of https://fullscreen.spec.whatwg.org/#:fullscreen-pseudo-class yet:

<!DOCTYPE html>
<div id="host"></div>
<button onclick="test()">button to go fullscreen</button>
<script>
var root = host.attachShadow({mode: 'open'});
root.innerHTML = '<div>div that will go fullscreen</div>';
function test() {
  var el = root.firstChild;
  console.log(el)
  if (el.requestFullscreen) {
    el.requestFullscreen();
    document.addEventListener('fullscreenchange', () => {
      const hostMatches = host.matches(':fullscreen');
      console.log('host matches: ' + hostMatches);
      document.exitFullscreen();
    }, { once: true });
  } else if (el.webkitRequestFullscreen) {
    el.webkitRequestFullscreen();
    document.addEventListener('webkitfullscreenchange', () => {
      var hostMatches = host.matches(':-webkit-full-screen');
      console.log('host matches: ' + hostMatches);
      document.webkitExitFullscreen();
    }, { once: true });
  }
};
</script>

Chrome, Firefox and Safari all log "host matches: false".

I suspected WebKit might have an implementation, and it does:

https://github.com/WebKit/WebKit/blob/35db0b62befe4e0457c8adb56d156ed47c712621/Source/WebCore/css/SelectorCheckerTestFunctions.h#L409-L416

But this isn't shipping yet.

@annevk
Copy link
Member

annevk commented Dec 21, 2022

cc @smaug---- @emilio

@annevk annevk added the topic: shadow Relates to shadow trees (as defined in DOM) label Dec 21, 2022
@smaug----
Copy link

:fullscreen should follow whatever behavior :focus has.
The current spec does make sense, but I'm worried about changing implementations, that might break sites.
Has webkit shipped the change to its behavior?

@foolip
Copy link
Member

foolip commented Mar 7, 2023

It looks like the WebKit change is on its way to Safari stable. I've tested #149 (comment) in Safari 16.3 which logs "host matches: false", but in STP 164 I get "host matches: true".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: shadow Relates to shadow trees (as defined in DOM)
Development

Successfully merging a pull request may close this issue.

5 participants