fullscreen icon indicating copy to clipboard operation
fullscreen copied to clipboard

How :fullscreen CSS pseudo class works in shadow dom?

Open beaufortfrancois opened this issue 6 years ago • 13 comments

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 avatar Mar 20 '19 13:03 beaufortfrancois

FYI @foolip @TakayoshiKochi

beaufortfrancois avatar Mar 20 '19 13:03 beaufortfrancois

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?

foolip avatar Mar 20 '19 14:03 foolip

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

beaufortfrancois avatar Mar 20 '19 15:03 beaufortfrancois

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.

foolip avatar Mar 20 '19 15:03 foolip

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

beaufortfrancois avatar Apr 18 '19 08:04 beaufortfrancois

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

foolip avatar Jun 05 '19 09:06 foolip

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

nt1m avatar Dec 15 '22 05:12 nt1m

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

beaufortfrancois avatar Dec 19 '22 08:12 beaufortfrancois

Based on what @rniwa just wrote in https://github.com/WICG/webcomponents/issues/804#issuecomment-1361017701 it seems like that change to picutre-in-picture was wrong and we shouldn't be changing :fullscreen either.

annevk avatar Dec 21 '22 10:12 annevk

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.

foolip avatar Dec 21 '22 15:12 foolip

cc @smaug---- @emilio

annevk avatar Dec 21 '22 16:12 annevk

: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?

smaug---- avatar Feb 27 '23 14:02 smaug----

It looks like the WebKit change is on its way to Safari stable. I've tested https://github.com/whatwg/fullscreen/issues/149#issuecomment-1361483842 in Safari 16.3 which logs "host matches: false", but in STP 164 I get "host matches: true".

foolip avatar Mar 07 '23 14:03 foolip