From 58d7206259591009e48f0058dc9f560566849a1a Mon Sep 17 00:00:00 2001 From: erixreyes Date: Sat, 19 Jul 2025 07:50:34 +0800 Subject: [PATCH] Issue #2489: Add color-mix computation support --- layout/style/nsRuleNode.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/layout/style/nsRuleNode.cpp b/layout/style/nsRuleNode.cpp index a0a5ec1fd6..53dfe3ef09 100644 --- a/layout/style/nsRuleNode.cpp +++ b/layout/style/nsRuleNode.cpp @@ -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,