Every HTML element inside a drawable canvas
What does each HTML element do as a child of <canvas content="drawable">: is it drawn, can it be hit, does it take input?
Each row below is one element that was put in a canvas and measured, with one thing that could be built with it.
The measurements also decide which of the ideas further down are possible.
Runs the draw, ink, hit-test and repaint measurements for every row on small canvases in the corner of the window. It takes about 20 seconds and doesn't click or type.
Show the code how one element is measured
- Build the test markup. Each entry in
data.jsis a tag name and a string of HTML. The element under test sits in a wrapperdiv. - Draw it and measure. The node goes into a new drawable canvas and is drawn at (6, 6). Ink is the share of the element's box with a drawn pixel. The hit test asks
elementsFromPoint()at the centre of the drawn box. Paint events counted while nothing touches the element show whether it repaints on its own. - Measure both ways. Once inside a drawable wrapper, once as the drawable child itself, and once more with
display: blockforced when the element has no box. - Turn the numbers into the label on each row.
- "Draw it here": a canvas you can use. The same markup, drawn with a small rotation so native popups and hit regions can be compared with the picture.
- Check each idea against the measurements.
ideas.jslists what each idea needs;evaluate()looks those entries up. - The list of elements and their test markup.
The recorded results also include checks made with real mouse and keyboard input. Those are driven by tools/elements/record.mjs (run npm run record:elements), because a page can't send itself trusted clicks.
Findings
Ideas
All elements
How to read a row
- Works: the element is drawn, the browser finds it at its drawn position, and every check with real input passed.
- Partly: it's drawn, but at least one check with real input failed. The row says which.
- Blank: the element has a box and takes clicks, but no pixels are drawn.
- No box: the element isn't rendered (for example
display: none), so there's nothing to draw. - Measured lines come from the recording or from this browser. Not measured lines are expectations, mostly about native popups, which headless Chromium doesn't show. They need a person with a real browser.
- "Picture match" compares a screenshot of the element in the canvas with a screenshot of the same markup outside any canvas: the share of the plain copy's non-white pixels that the canvas copy reproduces.