Skip to content

[canvas] How are context dependent values resolved in canvas colors #12505

@Calme1709

Description

@Calme1709

What is the issue with the HTML Standard?

When colors (i.e. fillStyle, strokeStyle and shadowColor) are set on a canvas the spec says:

"If the value of other properties on the element a is on is required to do the resolution (such as resolving a currentcolor or system color), use element if it was passed, or the initial values of the properties if not."

This implies font-relative lengths (e.g. em) should be relative to the font of the element (or the initial font in the case of OffscreenCanvas) but this differs from how they are handled on other values (e.g. letterSpacing) which resolve them relative to the canvas' font (this is unspecified and in discussion in #10893 but consistent across browsers).

It also doesn't specify how values dependent on context other than the properties of the context element, such as root-font/viewport relative lengths (e.g. rem or vw) or light-dark(), should be resolved.

Existing implementations aren't consistent in how they handle these values:

Value Chromium Gecko WebKit
rgb(calc(7px / 1px) 1 0) accepted rejected accepted
rgb(calc(1em / 1px) 1 0) resolves as though em was 0px rejected rejected
rgb(calc(1rem / 1px) 1 0) resolves as though rem was 0px rejected rejected
rgb(calc(1vw / 1px) 1 0) resolves as though vw was 0px rejected rejected
currentColor resolves to #000000 resolves to element color (black for OffscreenCanvas) resolves to #000000
light-dark(red, green) rejected always resolves to light option for <canvas>, rejected for OffscreenCanvas rejected

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions