-
Notifications
You must be signed in to change notification settings - Fork 715
[css-color] Clamping component values at computed-value time vs parsing time #7677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Clamping at parse time may be an exception for sRGB color functions. CSSOM defines how to serialize
Aside: there is an extra But this same section also has... (EDIT: this section does not apply to alpha but only to rgb/hsl components)
... and I am very confused that I have to use a computed value to serialize a specified value. And 15. Serializing
Apart from this, there are also math functions, whose value is clamped at computed value time, eg. |
Looking at the serialization part of the spec, it looks like it's focused on computed values and that serializing specified values is overlooked? https://drafts.csswg.org/css-color-4/#serializing-sRGB-values |
It is, indeed. |
All the color serialization stuff got moved from CSSOM to Color 4. It makes sense to move the alpha serialization as well. The legacy forms and the newer |
This is also an issue for lightness. Per the current spec, lab()/lch(), for instance, should clamp negative lightness to 0 at computed value time, not specified/parse time: https://drafts.csswg.org/css-color/#specifying-lab-lch There are several tests in e.g. https://wpt.fyi/results/css/css-color/parsing/color-valid-lab.html that expects clamping at parse time and conflicts with the current spec. Also, both WebKit and Blink currently clamp at parse time. |
Is there any update regarding this? Should we change the spec to match the tests and assume clamping at parse time? Or are the tests wrong? |
Summary:
I propose to resolve on changing the spec to clamp at parse time for the components that currently are specfied to clamp at computed value time. |
@lilles do you have any specific text suggestions for a new sub-section covering serializing specified values? |
@svgeesus Isn't simply changing the text:
to:
sufficient? |
It looks like implementations are clamping under-range Lab l and alpha at parse time: but over-range Lab l is left unclamped (the spec used to require this, but it was changed a while ago): |
For HWB, both the initial clamp of w and b to [0%, 100%] but also the further normalization on the sum of w and b should be at parse time, right?
This isn't directly observable, but the specified value (which is in |
@mysteryDate @lilles please have a look at this commit I was slightly concerned that "parse-time" doesn't have a convenient spec link, but then again uses of "computed-value time" in this spec weren't linking anywhere either. Where are these terms defined? |
You probably want to just use the terms “computed value” and “specified value”, e.g. “the specified value is clamped to [range]” or whatever. https://www.w3.org/TR/css-cascade-5/#specified Fundamentally the question isn't about what time they get clamped, but what stage’s value gets clamped. :) |
@svgeesus Looks good to me! |
Adding @emilio for Gecko concerns. @fantasai Isn't specified to late as well? There is something called declared value. I don't even know if that is the correct term if we want it serialized clamped in the stylesheet serialization. Is the serialization for in the CSSOM spec relevant?: https://drafts.csswg.org/cssom/#serialize-a-css-component-value Regarding |
It is relevant, but 2/3 of it points to CSS Color 4 and I have been discussing with @emilio about moving over the remaining portion as well:
Particularly because that needs to be changed for named colors. |
The differences between the declared value, the cascaded value, and the specified value seem to boil down to:
So in the case that there is a declared value on a given element, it seems that will be the specified value. Right? |
Now done see |
Not clear to me whether further clarifications are needed or if this can be closed. Can we get consensus on this before Weds 8 Feb? |
At chromium we're happy with the language as it. |
It seems to affect color functions taking other colors as arguments, as reported in #10328. edit: I am wrong (sorry): the spec requires not clamping channel values in a relative colorFor example, It may be safer to clamp the serialized value (when not nested in a color function) rather than affect the parsed value. Maybe it would still be needed for a negative saturation in |
From https://www.w3.org/TR/css-color-4/#rgb-functions:
All user agents I've tested in fact do the clamping at parsing time:
Firefox, Safari and Chrome all give "specified: rgba(255, 255, 255, 0)"
Is there a disadvantage to just doing the clamping at parsing time? It is easier to implement and is already the behavior that we're living with.
The text was updated successfully, but these errors were encountered: