[csswg-drafts] [css-pseudo] [css-highlight-api] defaults and inheritance for ::spelling-error + ::grammar-error + ::highlight (#6779)

delan has just created a new issue for https://github.com/w3c/csswg-drafts:

== [css-pseudo] [css-highlight-api] defaults and inheritance for ::spelling-error + ::grammar-error + ::highlight ==
* https://drafts.csswg.org/css-pseudo-4/#highlight-pseudos
* https://drafts.csswg.org/css-highlight-api-1/#default-styles

### Problem 1: UA default highlight colors

If I understand conventional behaviour and [#highlight-ua-styles](https://drafts.csswg.org/css-pseudo-4/#highlight-ua-styles) correctly, the intended default behaviour of ::spelling-error and ::grammar-error is to decorate the highlighted text without changing the foreground color.

Similarly, if I understand #6375 correctly, the intended default behaviour of an unstyled ::highlight is to yield no visible change in rendering, or at least not change the foreground color.

But given the following statements…

1. Highlight pseudo computed styles inherit all properties from the same highlight’s styles in the parent, eventually defaulting to initial values ([#highlight-cascade](https://drafts.csswg.org/css-pseudo-4/#highlight-cascade)). Used values can differ due to paired cascade (#6386).

2. color:currentColor is the only way to grab the foreground color from lower layers, that is to say, “don’t change the color compared to if this text was unhighlighted” ([#highlight-text](https://drafts.csswg.org/css-pseudo-4/#highlight-text)).

3. The initial value of color is a UA-defined ordinary color ([css-color-3](https://drafts.csswg.org/css-color-3/#foreground)) or CanvasText ([css-color-4](https://drafts.csswg.org/css-color-4/#the-color-property)), _not_ currentColor.

4. There are no _recommended_ UA default highlight colors for ::spelling-error + ::grammar-error ([#highlight-ua-styles](https://drafts.csswg.org/css-pseudo-4/#highlight-ua-styles)), be they magic used colors via paired cascade or just declarations in the UA stylesheet, and UA default highlight colors are _forbidden_ for ::highlight as of #6534 ([#default-styles](https://drafts.csswg.org/css-highlight-api-1/#default-styles)).

…then by default, highlights will effectively reset the foreground color of highlighted text to initial (usually black), which is probably not what we want.

### Problem 2: custom highlight inheritance clause

As of #6534, [#default-styles](https://drafts.csswg.org/css-highlight-api-1/#default-styles) says:

> A custom highlight pseudo-element inherits the styles of its originating element.

I don’t think this really makes sense, because taken at face value, it essentially clobbers highlight inheritance ([#highlight-cascade](https://drafts.csswg.org/css-pseudo-4/#highlight-cascade)) in favour of the legacy behaviour (like how ::selection currently works in most impls).

### Possible solutions

I think [#highlight-ua-styles](https://drafts.csswg.org/css-pseudo-4/#highlight-ua-styles) and [#default-styles](https://drafts.csswg.org/css-highlight-api-1/#default-styles) should explicitly recommend (or require) UA defaults for these three pseudos that behave like color:currentColor. I believe the defaults should come from magic paired cascade, not UA stylesheet rules, to keep paired cascade as consistent and predictable as possible.

No change is needed for the other highlight color (background-color), because its initial value is transparent.

I think the spec text in Problem 2 should be removed.

(cc @mrego, @frivoal, @dandclark)

Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/6779 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Friday, 29 October 2021 11:05:44 UTC