Truly independent web browser
LibWeb: Resolve relative color channels during computation
Andreas Kling960caeefa976
diff --git a/Libraries/LibWeb/Rust/src/css/absolutize.rs b/Libraries/LibWeb/Rust/src/css/absolutize.rsindex edd8e4d33d6..9616503007f 100644--- a/Libraries/LibWeb/Rust/src/css/absolutize.rs+++ b/Libraries/LibWeb/Rust/src/css/absolutize.rs@@ -666,10 +666,7 @@ fn absolutize_color_function(value: &StyleValueData, context: &AbsolutizationCon} else {absolutize_child(origin_color, context, &mut changed)?};- if !changed {- return Some(Absolutized::Unchanged);- }- return Some(Absolutized::Changed(retain_new(StyleValueData::ColorFunction {+ let rebuilt = StyleValueData::ColorFunction {color_base: *color_base,channel_0: absolutized_c1,channel_1: absolutized_c2,@@ -678,7 +675,20 @@ fn absolutize_color_function(value: &StyleValueData, context: &AbsolutizationConhas_name: *has_name,name: name.clone(),origin_color: absolutized_origin,- })));+ };+ // NB: Other properties keep currentcolor unresolved until the element's own color is available.+ if !(context.current_color.is_none() && value_depends_on_current_color(&rebuilt))+ && let Some(resolved) = resolve_relative_form(&rebuilt, &color_resolution_input(context))+ {+ return Some(Absolutized::Changed(retain_new(+ crate::css::color_resolution::relative_color_computed_value_form(resolved),+ )));+ }+ return Some(if changed {+ Absolutized::Changed(retain_new(rebuilt))+ } else {+ Absolutized::Unchanged+ });}let descriptor = descriptor_for_color_type(color_base.color_type);diff --git a/Libraries/LibWeb/Rust/src/css/color_resolution.rs b/Libraries/LibWeb/Rust/src/css/color_resolution.rsindex 34e723130f7..a40aa5e89a9 100644--- a/Libraries/LibWeb/Rust/src/css/color_resolution.rs+++ b/Libraries/LibWeb/Rust/src/css/color_resolution.rs@@ -1547,7 +1547,7 @@ fn resolve_relative_alpha(/// The computed value form of an absolute rgb(), hsl() or hwb() function: the same color as/// color(srgb ...). Other color functions compute to themselves.// https://drafts.csswg.org/css-color-4/#resolving-sRGB-values-fn computed_value_form(value: StyleValueData) -> StyleValueData {+pub(crate) fn relative_color_computed_value_form(value: StyleValueData) -> StyleValueData {use color_conversion as ct;let StyleValueData::ColorFunction {color_base,@@ -1637,7 +1637,7 @@ pub unsafe extern "C" fn rust_relative_color_resolved_value(// SAFETY: Guaranteed by the caller.let resolution_input = unsafe { ColorResolutionInput::for_ffi_style(style) };match resolve_relative_form(value, &resolution_input) {- Some(resolved) => Arc::into_raw(Arc::new(computed_value_form(resolved))),+ Some(resolved) => Arc::into_raw(Arc::new(relative_color_computed_value_form(resolved))),None => core::ptr::null(),}}diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-properties-values-api/registered-property-computation.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-properties-values-api/registered-property-computation.txtindex 6b6d49eb464..9733df07856 100644--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-properties-values-api/registered-property-computation.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-properties-values-api/registered-property-computation.txt@@ -2,8 +2,8 @@ Harness status: OKFound 75 tests-68 Pass-7 Fail+69 Pass+6 FailPass <length> values computed are correctly via var()-referencePass <length> values computed are correctly via var()-reference when font-size is inheritedPass <length> values are computed correctly when font-size is inherited [14em]@@ -60,7 +60,7 @@ Fail <color> values are computed correctly [color-mix(in srgb, currentcolor, #ffFail <color> values are computed correctly [color-mix(in srgb, currentcolor 20%, #ffffff 20%)]Fail <color> values are computed correctly [light-dark(currentcolor, red)]Pass <color> values are computed correctly [light-dark(lime, red)]-Fail <color> values are computed correctly [color(from lime srgb g g g)]+Pass <color> values are computed correctly [color(from lime srgb g g g)]Fail <color> values are computed correctly [color(from currentcolor srgb b g r)]Pass <color> values are computed correctly [color(srgb 1 1 1 / calc(NaN))]Pass * values are computed correctly [tomato]