-
Notifications
You must be signed in to change notification settings - Fork 682
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
[css-color-5] What should the behavior of the CSS Color 5 color functions be when passed currentcolor
as <color>
#6168
Comments
FWIW, in Gecko we resolve all colors at computed value time to a mix of currentcolor and a foreground color (like this). That allows us to resolve the functions at computed-value time. So my implementation of I think that's generally preferable as I'd rather not do a lot of color mixing during rendering for every element if we can do it once and let it inherit through. |
@emilio, I can't quite understand what you are proposing here. What would the computed and used values of something like the following be: background-color: color-mix(in lch, currentcolor 40%, palegoldenrod) |
Yeah, I'm a little confused too, particularly with the other resolutions about Ignoring any discussion that's gone on in this thread, tho, my intuition is that we'd use the same logic (and can just copy over the text with light modifications) as the math functions - mixing functions resolve as far as possible at computed-value time, and resolve the rest of the way at used-value time if needed. |
@tabatkins that makes sense to me. |
(sidenote, @emilio, is the behavior of using part of using part of currentcolor and part of color for a final color value specified anywhere? I don't believe that is something we do in WebKit, and would interested to find out what that is all about). |
I was wondering a similar thing. For example, we are maintaining a component library. In one of the components, we would like one of its elements to have a semi-transparent background color based on the <div class="wrapper">
<div class="my-component">
<p>Some text</p>
<div class="my-component__semi-transparent-thing"></div>
</div>
</div> .wrapper {
background: darkslateblue;
color: white;
}
.my-component__semi-transparent-thing {
background-color: rgb(from currentcolor r g b / 50%);
} We would like to use |
Sorry I missed this ping before. @weinig @tabatkins resolving these at computed value time would break My point is that something like Here's a test-case that shows what I meant. The expected output is greenish, but if you resolve I think Firefox's behavior is correct here (WebKit doesn't support <!doctype html>
<style>
div {
width: 100px;
height: 100px;
}
.outer {
background-color: color-mix(in srgb, currentcolor 90%, red 10%);
color: red;
}
.inner {
background-color: inherit;
color: green;
}
</style>
<div class="outer">
<div class="inner"></div>
</div> |
Correct, in WebKit we currently just don't accept currentColor in the CSS 5 color functions at all. I was waiting for the resolution of this issue before going forward with it. I agree it should follow normal currentcolor inheritance rules for rendering (I say as much in the first comment). What I am not sure is what the computed value should be. If it should preserve the complete "color-mix(..., currentColor, ...)" that would be fine with me, it just needs to be spec'd. |
I think the computed value of this is not currently visible, because |
Right, which is why we didn't say to do that. ^_^ As far as I can tell, we're agreeing - resolve the function as far as possible at computed-value time (so you're left with just the parts that depend on Yeah, I think gCS() returns used values for all properties with colors (but I'm not 100% certain on that), but Typed OM should be returning the actual computed value. I think I'm fine with just returning the fully unresolved representation when a currentcolor is present? Trying to figure out exactly how much simplification can be done, like we do with math functions, sounds unfun, even if the UA has done that work under the covers to avoid duplicate work later. |
Yes
That seems way simpler to specify. It isn't just |
Yup, they also persist thru to used-value time for the same reason as |
That seems way simpler to specify. It now is just currentcolor due to the resolution of |
…tColor; add resolved section for color-mix(). See #6168
@weinig wrote:
I just clarified that in the spec, following the suggestions from yourself, @emilio and @tabatkins : The computed value is the specified ''color-contrast()'' function
with each <<color>> parameter resolved according to [[css-color-4#resolving-color-values]],
and the keywords ''AA'', ''AA-large'', ''AAA'', ''AAA-large'' replaced with their corresponding numeric value.
If all <<color>> parameters resolve
to the corresponding colors in their respective color spaces,
the used value is the winning color
resolved according to [[css-color-4#resolving-color-values]].
Otherwise (if ''currentColor'' was used in the function),
the used value is the same as the computed value
thus preserving inheritance into child elements. I also changed the example, to now do what the text says. I also added a new section on resolving The computed value is the specified ''color-mix()'' function
with each <<color>> parameter resolved according to [[css-color-4#resolving-color-values]].
If all <<color>> parameters resolve
to the corresponding colors in their respective color spaces,
the used value is the mixed color,
in the specified mixing color space,
resolved according to [[css-color-4#resolving-color-values]].
Otherwise (if ''currentColor'' was used in the function),
the used value is the same as the computed value
thus preserving inheritance into child elements. |
@svgeesus I think you need to replace
I think in order to deal with nested Also, it's a bit unfortunate that the "resolving color values" section is called like that, because CSS has the concept of "resolved value", which is not necessarily what that is describing, but that's another matter :-) |
But anyways, great we are in agreement! |
@emilio so, the computed value isn't the function but is the mixed result (unless currentColor is involved)?
That is where the text I added above is located: 7. Resolving
I named it that because of the similar section in CSS Color 4, which has been there a while: [4.7. Resolving Values](https://drafts.csswg.org/css-color-4/#resolving-color-values). What should these sections be called? |
To have a concrete example to discuss (initial value of div { color: black; }
p { color: color-mix(in oklab, currentColor 60%, white 40%); }
em { text-emphasis: dot; }
strong { color: red; } <div><p><em>Some <strong>really</strong> emphasized text.</em></p></div> so on the and on the CodePen by @LeaVerou to calculate |
The CSS Working Group just discussed
The full IRC log of that discussion<fantasai> Topic: [css-color-5] What should the behavior of the CSS Color 5 color functions be when passed currentcolor as <color><fantasai> github: https://github.com//issues/6168 <astearns> ack chris <fantasai> chris: I think we solved this in the issue, iterated the text with emilio <fantasai> emilio: for context with the group, it behaves like calc() - doesn't go away in specified style <fantasai> emilio: goes away in computed style if possible, but preserves currentColor <fantasai> emilio: but this is only observable in typedOM because getComptedStyle returns resolved colors <fantasai> RESOLVED: specified style maintains calculations, computed style computes everything as far as possible (but maintains currentColor's identity), resolved color resolves through to absolute color <fantasai> chris: I believe this also resolves item 5 on the agenda, <fantasai> https://github.com//issues/7302 |
From this conversation, for serialization I'm assuming that: const div = document.createElement('div');
document.body.appendChild(div);
div.style.color = "red";
div.style.backgroundColor = "color-mix(in srgb, currentColor, magenta)";
div.style.getPropertyValue("color")); // 'red'
div.style.getPropertyValue("background-color")); // 'color-mix(in srgb, currentColor, magenta)'
getComputedStyle(div)['color']; // 'rgb(255, 0, 0)'
getComputedStyle(div)['backgroundColor']; // 'rgb(255, 0, 127)' Is that all correct? If so, we are missing tests in the color-mix-valid and color-mix-invalid wpt tests. I'm happy to add these tests if I'm correct in my assumptions. |
@mysteryDate I don't recall whether we decided that color-mix serialized to rgb or to |
Yes, this is described here so the computed value is |
What should the behavior (both rendered result and computed value) be for the CSS Color 5 color functions (e.g.
color-mix()
,color-contrast()
,color-adjust()
and the relative color syntax forms) when one of the passed in values iscurrentcolor
(https://drafts.csswg.org/css-color-4/#currentcolor-color)?For rendering, I assume we just need to delay computation of the color functions until use time when
currentcolor
is used and use the resolved value, but it would be good to clarify that in the spec if it is the case.For computed value I am not quite sure since none of the color functions currently have anything about their computed value's specified. Should:
have a computed value of
color-mix(in lch, currentcolor 40%, palegoldenrod)
?In my current implementation, I am eagerly computing the color-mix(), so in all cases that don't involve currentcolor it computes to the resolved color, but this is just an arbitrary choice I made, and I do not think should motivate the direction of the spec.
The text was updated successfully, but these errors were encountered: