Media controls and element state

Four ideas that came out of the parts of the native media player. That page found that a canvas can restyle the native controls and can't reach any one of them. I wanted to know what a canvas could do if media controls were ordinary elements with named parts and states, whether the state of any element can drive an effect through CSS alone, whether drawElementImage() takes a pseudo-element or a part, and whether the composed picture can be sent to another screen.

Media controls as a custom element with parts and states

<media-bar> is a mock of customisable media controls: a play button, a timeline, a time and a sound button in an open shadow tree, each with a part name, and custom states for playing and muted. Press Play. The film takes its colour back, because a CSS rule reads media-bar:state(playing). Then tick the box: the canvas stops using the element's layout and draws each part where it wants it, and each part still takes input where it is drawn.

The glass behind the controls is the film drawn a second time with a blur, inside the box of the control. With the box ticked there is no bar: the play button is a part of the shadow tree drawn at more than twice its size in the middle of the film, and the timeline is stretched to the width of the canvas. The component's author made that possible by putting drawable on the parts. A page can't do it for a part it doesn't own.

Show the code
  1. The video and its controls are two drawable children of the canvas.
  2. The custom element: parts, custom states, and drawable on each part when asked.
  3. The rule that turns the playing state into --fx-amount, and the part styles.
  4. Draw the film, the glass and the controls, as one picture or as four.
  5. Read the numbers, and ask for frames while a transition runs.

State pseudo-classes that drive an effect through :has()

Tick Lamp. Open the opening hours. Press Save with the email field empty, or type something that isn't an address and leave the field. Press Help. Each of the four changes how the card is drawn, and the script has no listener on any of the four elements: a CSS rule for each state sets a number on the canvas.

Opening hours

Monday to Friday, 9 to 5. Saturday, 10 to 2.

The lamp, the opening hours and the email field are in the canvas. This popover is not: it's a sibling of the canvas. Tap outside it to close it.

The numbers have the names that Shader CSS uses for its uniforms. Here a 2D paint handler reads them, so the same rules could drive a shader. A state that belongs to an element outside the canvas works the same way, because :has() is written on an ancestor of both.

Show the code
  1. The form is one drawable child of the canvas.
  2. Four rules, one for each state.
  3. The four numbers, registered so that they can be eased.
  4. Draw the card from the four numbers.
  5. Read the numbers, and ask for frames while a transition runs.

A pseudo-element as a picture of its own

The proposal under test: drawElementImage() that takes a pseudo-element or a ::part(), so that a canvas could draw the quotation mark of this quote apart from its text. The line under the canvas says what the browser did with that call. The drawing shows the way round it, which needs the page to know where the pseudo-element's box is.

The mark at the start of this quote is not an element. It is a ::before box. The parts of the native player are out of reach in the same way.From this page

A part of an open shadow tree is different: it's an element, and the first demo draws four of them. What's missing is a way to name a box that isn't an element, or an element in a tree the page can't open.

Show the code
  1. The quote is one drawable child. Its mark is a ::before box.
  2. Hand the pseudo-element to drawElementImage().
  3. The way round it: two clipped draws of the whole element.
  4. Styles. The mark has a fixed box.

Casting the composed canvas

The first canvas on this page, film and controls together, as a stream for another screen. Three routes are tried. The Remote Playback API is asked to play a <video> that shows the stream. The Presentation API is asked to open a receiver page on a second screen. The third route opens the same receiver page in a tab, which works with one device: press Play in the first demo, open the receiver, and come back here.

Open the receiver in a tab

A receiver page gets messages and no media, so the stream travels over WebRTC and the Presentation connection, or the BroadcastChannel, carries only the offer and the answer. The controls in the stream are pixels: the receiver can't press Play.

Show the code
  1. Capture the canvas.
  2. Remote Playback API.
  3. Presentation API.
  4. Send the stream over WebRTC.
  5. The receiver in a tab.
  6. The receiver page.

How it works

Show the code
  1. Each demo starts when its section comes near the screen.
  2. The paint handler shared by the three canvases.
  3. A lost context stops every demo.
  4. The elements are then shown as plain HTML.

Live checks

The checks wait for a tap. Each builds its own small canvas in a corner of the window, and none of them touches the demos above. :user-invalid isn't checked here, because it needs real input: the tool script types into the field.

Findings

Measured in headless Chromium 157 on 2026-11-21. Not yet run on a phone.