Issue #2489: Add color-mix computation support

This commit is contained in:
erixreyes 2025-07-19 07:50:34 +08:00 • committed by roytam1
commit 58d7206259

View file

@ -1137,6 +1137,21 @@ static bool SetColor(const nsCSSValue& aValue, const nscolor aParentColor,
aResult = aParentColor;
result = true;
aConditions.SetUncacheable();
} else if (eCSSUnit_ColorMix == unit) {
const mozilla::css::ColorMixValue* colorMix = aValue.GetColorMixValue();
if (colorMix) {
nscolor color1, color2;
if (SetColor(colorMix->mColor1, aParentColor, aPresContext, aContext, color1, aConditions) &&
SetColor(colorMix->mColor2, aParentColor, aPresContext, aContext, color2, aConditions)) {
// simple linear interpolation (50/50 sRGB mix)
uint8_t r = (NS_GET_R(color1) + NS_GET_R(color2)) / 2;
uint8_t g = (NS_GET_G(color1) + NS_GET_G(color2)) / 2;
uint8_t b = (NS_GET_B(color1) + NS_GET_B(color2)) / 2;
uint8_t a = (NS_GET_A(color1) + NS_GET_A(color2)) / 2;
aResult = NS_RGBA(r, g, b, a);
result = true;
}
}
} else if (eCSSUnit_Enumerated == unit &&
aValue.GetIntValue() == NS_STYLE_COLOR_INHERIT_FROM_BODY) {
NS_ASSERTION(aPresContext->CompatibilityMode() == eCompatibility_NavQuirks,