Skip to content

Truly independent web browser

LibWeb: Resolve currentcolor in color-mix() against the right color

Andreas Klingdded86b55888
diff --git a/Libraries/LibWeb/CSS/CSSStyleProperties.cpp b/Libraries/LibWeb/CSS/CSSStyleProperties.cpp
index 09e7836d923..8dca9cb8b9c 100644
--- a/Libraries/LibWeb/CSS/CSSStyleProperties.cpp
+++ b/Libraries/LibWeb/CSS/CSSStyleProperties.cpp
@@ -1007,6 +1007,13 @@ static RefPtr<StyleValue const> resolve_color_style_value(StyleValue const& styl
}
}
+ // NB: A computed color-mix() is still a mix only where it reads currentcolor, which the used value resolves.
+ if (color_resolution_style.has_value() && style_value.is_color()) {
+ auto ffi_color_resolution_style = color_resolution_style->to_ffi();
+ if (auto const* resolved = StyleValueFFI::rust_color_mix_resolved_value(style_value.rust_style_value_data(), &ffi_color_resolution_style))
+ return StyleValue::adopt_rust_style_value_data(static_cast<StyleValueFFI::StyleValueData const*>(resolved));
+ }
+
if (style_value.is_color_function() && as<ColorFunctionStyleValue>(style_value).serializes_as_color_function())
return style_value;
if (style_value.is_color()) {
diff --git a/Libraries/LibWeb/Rust/src/css/absolutize.rs b/Libraries/LibWeb/Rust/src/css/absolutize.rs
index 413443fda38..bb9f19c835e 100644
--- a/Libraries/LibWeb/Rust/src/css/absolutize.rs
+++ b/Libraries/LibWeb/Rust/src/css/absolutize.rs
@@ -41,6 +41,7 @@ mod grid_tests {
random_base_values: &[],
document_base_url: &[],
style_sheet_resource_context: None,
+ current_color: None,
};
match absolutize(value, &context).unwrap() {
Absolutized::Unchanged => unsafe {
@@ -217,7 +218,7 @@ use crate::css::css_enums::keyword;
use crate::css::style_compute::{FfiLengthResolutionContext, absolutize_length, keyword_is_color};
use crate::css::style_value::{
BasicShapeData, ColorBase, CssString, OwnedBasicShapeData, RetainedGridTrackEntryList, RetainedStyleValueData,
- RetainedStyleValueDataList, StyleValueData,
+ RetainedStyleValueDataList, StyleValueData, value_depends_on_current_color,
};
use crate::css::value_codes::*;
@@ -237,6 +238,10 @@ pub(crate) struct AbsolutizationContext<'a> {
pub(crate) document_base_url: &'a [u8],
/// The stylesheet resource context for the selected cascade source, if any.
pub(crate) style_sheet_resource_context: Option<StyleSheetResourceContext<'a>>,
+ /// The computed value `currentcolor` names while the value computes, which only the `color` property knows: its
+ /// inherited value. Elsewhere `currentcolor` names the element's own color, which the computed value keeps
+ /// unresolved until it is used.
+ pub(crate) current_color: Option<&'a StyleValueData>,
}
#[derive(Clone, Copy)]
@@ -378,15 +383,20 @@ fn absolutize_image(value: &StyleValueData, context: &AbsolutizationContext) ->
}
/// The color-resolution input the C++ absolutizers build from a computation context: the
-/// context's color scheme and calculation inputs, no currentcolor and no channels.
+/// context's color scheme and calculation inputs, the currentcolor it knows of, and no channels.
fn color_resolution_input<'a>(context: &'a AbsolutizationContext) -> ColorResolutionInput<'a> {
- ColorResolutionInput {
+ let mut input = ColorResolutionInput {
scheme: context.scheme,
current_color: None,
current_color_value: None,
length: Some(context.length),
channels: None,
+ };
+ if let Some(current_color) = context.current_color {
+ input.current_color = to_color(current_color, &input);
+ input.current_color_value = Some(current_color);
}
+ input
}
/// The rgb() function form ColorFunctionStyleValue::create builds for an already-resolved
@@ -679,7 +689,16 @@ fn absolutize_color_mix(value: &StyleValueData, context: &AbsolutizationContext)
let resolved_first = resolved_first_storage.as_ref().unwrap_or(first_color.data());
let resolved_second = resolved_second_storage.as_ref().unwrap_or(second_color.data());
+ // NB: Without a currentcolor to resolve against, a mix reading it keeps the mix, which the color it is used as
+ // resolves against the element's own color.
+ let reads_unknown_current_color = context.current_color.is_none()
+ && [first_color, second_color]
+ .iter()
+ .any(|color| color.optional_data().is_some_and(value_depends_on_current_color));
let interpolated = (|| -> Option<RetainedStyleValueData> {
+ if reads_unknown_current_color {
+ return None;
+ }
let resolved_from = resolve_color_for_interpolation(resolved_first, &input)?;
let resolved_to = resolve_color_for_interpolation(resolved_second, &input)?;
let result = crate::css::color_interpolation::interpolate_color(
@@ -700,11 +719,19 @@ fn absolutize_color_mix(value: &StyleValueData, context: &AbsolutizationContext)
let mut colors_changed = false;
let absolutized_first = absolutize_child(first_color, context, &mut colors_changed)?;
let absolutized_second = absolutize_child(second_color, context, &mut colors_changed)?;
- let percentage_matches = |slot: &RetainedStyleValueData, normalized_value: f64| matches!(slot.optional_data(), Some(StyleValueData::Percentage { value }) if *value == normalized_value);
- if !colors_changed
- && percentage_matches(first_percentage, normalized.first_percentage)
- && percentage_matches(second_percentage, normalized.second_percentage)
- {
+ // NB: The percentages are kept as given, since normalizing them here would lose the alpha multiplier of a sum
+ // under 100%. The mix normalizes them when it resolves.
+ let percentage_matches =
+ |slot: &RetainedStyleValueData, absolutized: Option<f64>| match (slot.optional_data(), absolutized) {
+ (None, None) => true,
+ (Some(StyleValueData::Percentage { value }), Some(absolutized)) => *value == absolutized,
+ _ => false,
+ };
+ let retained_percentage = |absolutized: Option<f64>| match absolutized {
+ Some(value) => retain_new(StyleValueData::Percentage { value }),
+ None => retained_null(),
+ };
+ if !colors_changed && percentage_matches(first_percentage, p1) && percentage_matches(second_percentage, p2) {
return Some(Absolutized::Unchanged);
}
Some(Absolutized::Changed(retain_new(StyleValueData::ColorMix {
@@ -715,13 +742,9 @@ fn absolutize_color_mix(value: &StyleValueData, context: &AbsolutizationContext)
},
color_interpolation_method: absolutized_method,
first_color: absolutized_first,
- first_percentage: retain_new(StyleValueData::Percentage {
- value: normalized.first_percentage,
- }),
+ first_percentage: retained_percentage(p1),
second_color: absolutized_second,
- second_percentage: retain_new(StyleValueData::Percentage {
- value: normalized.second_percentage,
- }),
+ second_percentage: retained_percentage(p2),
})))
}
@@ -2086,6 +2109,7 @@ pub(crate) fn absolutize_with_element_facts(
random_base_values: &random_base_values,
document_base_url,
style_sheet_resource_context: None,
+ current_color: None,
},
)
}
diff --git a/Libraries/LibWeb/Rust/src/css/color_resolution.rs b/Libraries/LibWeb/Rust/src/css/color_resolution.rs
index abe4f86470f..e5dddf8389c 100644
--- a/Libraries/LibWeb/Rust/src/css/color_resolution.rs
+++ b/Libraries/LibWeb/Rust/src/css/color_resolution.rs
@@ -1392,6 +1392,30 @@ pub unsafe extern "C" fn rust_relative_color_resolved_value(
}
}
+/// The resolved value of a `color-mix()` against a style: the color it mixes, in the form a mix whose colors are all
+/// known computes to. A computed mix stays a mix only where it reads `currentcolor`, which the style names. Returns
+/// one strong reference, or null when the value is no mix or does not resolve.
+///
+/// # Safety
+/// `value` must point at live style value data, and `style` must be null or point at a style
+/// whose group payloads outlive the call.
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn rust_color_mix_resolved_value(
+ value: *const core::ffi::c_void,
+ style: *const FfiColorResolutionStyle,
+) -> *const StyleValueData {
+ let value = unsafe { &*value.cast::<StyleValueData>() };
+ if !matches!(value, StyleValueData::ColorMix { .. }) {
+ return core::ptr::null();
+ }
+ // SAFETY: Guaranteed by the caller.
+ let resolution_input = unsafe { ColorResolutionInput::for_ffi_style(style) };
+ match resolve_color_mix(value, &resolution_input) {
+ Some(resolved) => Arc::into_raw(Arc::new(resolved)),
+ None => core::ptr::null(),
+ }
+}
+
/// Port of ColorStyleValue::extract_channels_in_color_space().
///
/// NB: The C++ code computes linear sRGB with the direct transfer function; that function is
@@ -1539,7 +1563,6 @@ pub(crate) fn percentage_from_style_value(value: &StyleValueData) -> Option<f64>
/// Percentages are represented as values from 0 to 100.
pub(crate) struct NormalizedPercentages {
- pub(crate) first_percentage: f64,
pub(crate) second_percentage: f64,
pub(crate) alpha_multiplier: f64,
}
@@ -1550,7 +1573,7 @@ pub(crate) fn normalize_percentage_pair(p1: Option<f64>, p2: Option<f64>) -> Nor
// 1. Let p1 be the first percentage and p2 the second one.
// NB: Provided by the caller.
- let (p1, p2) = match (p1, p2) {
+ let (_, p2) = match (p1, p2) {
// 2. If both percentages are omitted, they each default to 50% (an equal mix of the two
// colors).
(None, None) => (50.0, 50.0),
@@ -1582,7 +1605,6 @@ pub(crate) fn normalize_percentage_pair(p1: Option<f64>, p2: Option<f64>) -> Nor
};
NormalizedPercentages {
- first_percentage: p1,
second_percentage: p2,
alpha_multiplier,
}
@@ -1696,6 +1718,20 @@ pub(crate) fn resolve_color_for_interpolation(
resolved_relative_storage = resolve_relative_form(input_value, input)?;
style_value = &resolved_relative_storage;
}
+ // NB: currentcolor and a nested mix interpolate from the color they name, not from that color rounded to 8-bit
+ // channels.
+ if let StyleValueData::Keyword { keyword: code } = style_value
+ && *code == keyword::CURRENTCOLOR
+ && let Some(current_color_value) = input.current_color_value
+ && !value_depends_on_current_color(current_color_value)
+ {
+ return resolve_color_for_interpolation(current_color_value, input);
+ }
+ let resolved_mix_storage;
+ if let StyleValueData::ColorMix { .. } = style_value {
+ resolved_mix_storage = resolve_color_mix(style_value, input)?;
+ style_value = &resolved_mix_storage;
+ }
if let Some((color_type, components)) = resolve_native_color_components(style_value, input) {
let StyleValueData::ColorFunction {
@@ -2177,7 +2213,6 @@ mod tests {
#[test]
fn percentage_pair_normalization_matches_the_spec_steps() {
let normalized = normalize_percentage_pair(None, None);
- assert_eq!(normalized.first_percentage, 50.0);
assert_eq!(normalized.second_percentage, 50.0);
assert_eq!(normalized.alpha_multiplier, 1.0);
@@ -2185,15 +2220,13 @@ mod tests {
assert_eq!(normalized.second_percentage, 70.0);
let normalized = normalize_percentage_pair(None, Some(30.0));
- assert_eq!(normalized.first_percentage, 70.0);
+ assert_eq!(normalized.second_percentage, 30.0);
let normalized = normalize_percentage_pair(Some(100.0), Some(100.0));
- assert_eq!(normalized.first_percentage, 50.0);
assert_eq!(normalized.second_percentage, 50.0);
assert_eq!(normalized.alpha_multiplier, 1.0);
let normalized = normalize_percentage_pair(Some(20.0), Some(30.0));
- assert_eq!(normalized.first_percentage, 40.0);
assert_eq!(normalized.second_percentage, 60.0);
assert_eq!(normalized.alpha_multiplier, 0.5);
diff --git a/Libraries/LibWeb/Rust/src/css/custom_properties.rs b/Libraries/LibWeb/Rust/src/css/custom_properties.rs
index c6a31ef411f..a7ae1ae4e66 100644
--- a/Libraries/LibWeb/Rust/src/css/custom_properties.rs
+++ b/Libraries/LibWeb/Rust/src/css/custom_properties.rs
@@ -521,6 +521,7 @@ impl CustomPropertyRegistry {
random_base_values: &random_base_values,
document_base_url: &self.document_base_url,
style_sheet_resource_context: None,
+ current_color: None,
};
let computed = match crate::css::absolutize::absolutize(parsed.data(), &context) {
Some(crate::css::absolutize::Absolutized::Changed(computed)) => computed,
diff --git a/Libraries/LibWeb/Rust/src/css/style_compute.rs b/Libraries/LibWeb/Rust/src/css/style_compute.rs
index eeebeda3692..a434ac6bcd1 100644
--- a/Libraries/LibWeb/Rust/src/css/style_compute.rs
+++ b/Libraries/LibWeb/Rust/src/css/style_compute.rs
@@ -3226,9 +3226,16 @@ impl<'a> ParentSnapshot<'a> {
{
return Some(entry.value_handle());
}
- for (property, value) in self.table.retained_inheritance_dependent_values() {
- if property == property_id && crate::css::style_value::style_value_dependency_flags(value.data()) & 1 != 0 {
- return Some(value);
+ // NB: A value reading currentcolor is inherited as specified, to resolve against the inheriting element's own
+ // color, except in the color property, whose currentcolor is the inherited value and so resolved where
+ // it computes.
+ if property_id != crate::css::property_metadata::property_id::COLOR {
+ for (property, value) in self.table.retained_inheritance_dependent_values() {
+ if property == property_id
+ && crate::css::style_value::style_value_dependency_flags(value.data()) & 1 != 0
+ {
+ return Some(value);
+ }
}
}
self.table.get(property_id)
@@ -3769,6 +3776,15 @@ pub(crate) unsafe fn drive_property_computation(
} else {
None
};
+ // https://www.w3.org/TR/css-color-4/#resolving-other-colors
+ // In the color property, the used value of currentcolor is the resolved inherited value.
+ let current_color = (inherited_property_id == prop::COLOR).then(|| {
+ highlight_parent_snapshot
+ .or(snapshot)
+ .and_then(|snapshot| snapshot.value_handle(prop::COLOR))
+ .and_then(RetainedStyleValueData::optional_data)
+ .unwrap_or_else(|| initial_value_handle(prop::COLOR).data())
+ });
// Absolutizes a value against this element's facts, noting in `results` when it resolved a viewport-relative
// length.
let absolutize_value = |value: &StyleValueData,
@@ -3783,6 +3799,7 @@ pub(crate) unsafe fn drive_property_computation(
random_base_values,
document_base_url,
style_sheet_resource_context,
+ current_color,
};
let outcome = crate::css::absolutize::absolutize(value, &context);
if context.resolved_viewport_relative_length.get() {
diff --git a/Tests/LibWeb/Text/expected/css/getComputedStyle-color-mix-currentcolor-parent-change.txt b/Tests/LibWeb/Text/expected/css/getComputedStyle-color-mix-currentcolor-parent-change.txt
new file mode 100644
index 00000000000..4b2752dcf32
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/css/getComputedStyle-color-mix-currentcolor-parent-change.txt
@@ -0,0 +1,6 @@
+mix color color(srgb 0.5 0.5 0.5)
+child color color(srgb 0.5 0.5 0.5)
+child background-color color(srgb 0.75 0.75 0.75)
+mix color color(srgb 1 0.5 0.5)
+child color color(srgb 1 0.5 0.5)
+child background-color color(srgb 1 0.75 0.75)
diff --git a/Tests/LibWeb/Text/expected/css/getComputedStyle-color-mix-currentcolor-percentages.txt b/Tests/LibWeb/Text/expected/css/getComputedStyle-color-mix-currentcolor-percentages.txt
new file mode 100644
index 00000000000..4f3b7a97830
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/css/getComputedStyle-color-mix-currentcolor-percentages.txt
@@ -0,0 +1,8 @@
+ownUnder background-color color(srgb 1 0.5 0.5 / 0.4)
+ownExact background-color color(srgb 1 0.7 0.7)
+ownOver background-color color(srgb 1 0.5 0.5)
+inheritedUnder background-color color(srgb 1 0.5 0.5 / 0.4)
+inheritedExact background-color color(srgb 1 0.7 0.7)
+inheritedOver background-color color(srgb 1 0.5 0.5)
+mixColorUnder background-color color(srgb 1 0.857143 0.857143 / 0.28)
+mixColor color color(srgb 1 0.5 0.5 / 0.4)
diff --git a/Tests/LibWeb/Text/expected/css/getComputedStyle-color-mix-currentcolor.txt b/Tests/LibWeb/Text/expected/css/getComputedStyle-color-mix-currentcolor.txt
index 56077c335dd..5226e350781 100644
--- a/Tests/LibWeb/Text/expected/css/getComputedStyle-color-mix-currentcolor.txt
+++ b/Tests/LibWeb/Text/expected/css/getComputedStyle-color-mix-currentcolor.txt
@@ -1,20 +1,20 @@
color rgb(255, 0, 0)
-background-color color(srgb 0.5 0.5 0.5)
-border-top-color color(srgb 0 0 0 / 0.5)
-outline-color color(srgb 0.5 0.5 0.5)
+background-color color(srgb 1 0.5 0.5)
+border-top-color color(srgb 1 0 0 / 0.5)
+outline-color color(srgb 0.75 0.5 0.5)
color rgb(0, 0, 255)
-background-color color(srgb 0.5 0.5 0.5)
-border-top-color color(srgb 0 0 0 / 0.5)
-outline-color color(srgb 0.5 0.5 0.5)
+background-color color(srgb 0.5 0.5 1)
+border-top-color color(srgb 0 0 1 / 0.5)
+outline-color color(srgb 0.5 0.5 0.75)
color rgb(0, 128, 0)
-background-color color(srgb 0.5 0.5 0.5)
-border-top-color color(srgb 0 0 0 / 0.5)
-outline-color color(srgb 0.5 0.5 0.5)
-color color(srgb 0.5 0.5 0.5)
+background-color color(srgb 0.5 0.75098 0.5)
+border-top-color color(srgb 0 0.501961 0 / 0.5)
+outline-color color(srgb 0.5 0.62549 0.5)
+color color(srgb 1 0.5 0.5)
background-color rgba(0, 0, 0, 0)
-border-top-color rgb(128, 128, 128)
-outline-color rgb(128, 128, 128)
-color rgb(128, 128, 128)
-background-color color(srgb 0.5 0.5 0.5)
-border-top-color color(srgb 0 0 0 / 0.5)
-outline-color color(srgb 0.5 0.5 0.5)
+border-top-color rgb(255, 128, 128)
+outline-color rgb(255, 128, 128)
+color color(srgb 1 0.5 0.5)
+background-color color(srgb 1 0.75 0.75)
+border-top-color color(srgb 1 0.5 0.5 / 0.5)
+outline-color color(srgb 0.75 0.625 0.625)
diff --git a/Tests/LibWeb/Text/expected/css/style-engine/inherited-group-swap.txt b/Tests/LibWeb/Text/expected/css/style-engine/inherited-group-swap.txt
index 5dbd44c536a..f458c53f4e1 100644
--- a/Tests/LibWeb/Text/expected/css/style-engine/inherited-group-swap.txt
+++ b/Tests/LibWeb/Text/expected/css/style-engine/inherited-group-swap.txt
@@ -8,7 +8,7 @@ plain background color: rgb(0, 128, 0)
plain border color: rgb(0, 128, 0)
plain outline color: rgb(0, 128, 0)
plain text decoration color: rgb(0, 128, 0)
-mixed background color: rgb(128, 191, 128)
+mixed background color: color(srgb 0.5 0.75098 0.5)
shadow color: rgb(128, 191, 128) 0px 0px 0px 0px
stop color: rgb(128, 191, 128)
color C++ recomputations: 0
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-backgrounds/animations/background-color-transition-colormix.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-backgrounds/animations/background-color-transition-colormix.txt
index e1f8de7909f..4fed92d08cc 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-backgrounds/animations/background-color-transition-colormix.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-backgrounds/animations/background-color-transition-colormix.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail Transition with currentColor in color-mix
\ No newline at end of file
+1 Pass
+Pass Transition with currentColor in color-mix
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-color/parsing/color-computed-relative-color.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-color/parsing/color-computed-relative-color.txt
index d8e668c1810..77c21be3f1c 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-color/parsing/color-computed-relative-color.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-color/parsing/color-computed-relative-color.txt
@@ -2,8 +2,8 @@ Harness status: OK
Found 1169 tests
-1126 Pass
-43 Fail
+1127 Pass
+42 Fail
Pass Property color value 'rgb(from rebeccapurple r g b)'
Pass Property color value 'rgb(from rebeccapurple r g b / alpha)'
Pass Property color value 'rgb(from rgb(20%, 40%, 60%, 80%) r g b / alpha)'
@@ -79,7 +79,7 @@ Fail Property color value 'rgb(from rgb(20% 40% 60% / none) r g b / alpha)'
Pass Property color value 'color-mix(in srgb, rgb(from rebeccapurple none g b), rebeccapurple)'
Pass Property background-color value 'rgb(from currentColor r g b)'
Pass Property color value 'rgb(from color-mix(in srgb, red, red) r g b / alpha)'
-Fail Property background-color value 'rgb(from color-mix(in srgb, currentColor, red) r g b / alpha)'
+Pass Property background-color value 'rgb(from color-mix(in srgb, currentColor, red) r g b / alpha)'
Pass Property background-color value 'rgb(from rgb(from currentColor r g b) r g b)'
Pass Property color value 'light-dark(rgb(from rebeccapurple r g b), rgb(from rebeccapurple r g b))'
Pass Property color value 'light-dark(color-mix(in srgb, rgb(from rebeccapurple none g b), rebeccapurple), color-mix(in srgb, rgb(from rebeccapurple none g b), rebeccapurple))'
diff --git a/Tests/LibWeb/Text/input/css/getComputedStyle-color-mix-currentcolor-parent-change.html b/Tests/LibWeb/Text/input/css/getComputedStyle-color-mix-currentcolor-parent-change.html
new file mode 100644
index 00000000000..e4373300dd2
--- /dev/null
+++ b/Tests/LibWeb/Text/input/css/getComputedStyle-color-mix-currentcolor-parent-change.html
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<style>
+ #parent { color: black; }
+ #parent.red { color: red; }
+ #mix { color: color-mix(in srgb, currentcolor, white); }
+ .background { background-color: color-mix(in srgb, currentcolor, white); }
+</style>
+<div id="parent"><div id="mix"><div id="child" class="background"></div></div></div>
+<script>
+ test(() => {
+ const report = () => {
+ println(`mix color ${getComputedStyle(mix).color}`);
+ println(`child color ${getComputedStyle(child).color}`);
+ println(`child background-color ${getComputedStyle(child).backgroundColor}`);
+ };
+ report();
+ document.getElementById("parent").classList.add("red");
+ report();
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/css/getComputedStyle-color-mix-currentcolor-percentages.html b/Tests/LibWeb/Text/input/css/getComputedStyle-color-mix-currentcolor-percentages.html
new file mode 100644
index 00000000000..b8d5cb56ccf
--- /dev/null
+++ b/Tests/LibWeb/Text/input/css/getComputedStyle-color-mix-currentcolor-percentages.html
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<style>
+ .under { background-color: color-mix(in srgb, currentcolor 20%, white 20%); }
+ .exact { background-color: color-mix(in srgb, currentcolor 30%, white 70%); }
+ .over { background-color: color-mix(in srgb, currentcolor 60%, white 60%); }
+ .mix-color { color: color-mix(in srgb, currentcolor 20%, white 20%); }
+</style>
+<div id="ownUnder" class="under" style="color: rgb(255, 0, 0)"></div>
+<div id="ownExact" class="exact" style="color: rgb(255, 0, 0)"></div>
+<div id="ownOver" class="over" style="color: rgb(255, 0, 0)"></div>
+<div style="color: rgb(255, 0, 0)">
+ <div id="inheritedUnder" class="under"></div>
+ <div id="inheritedExact" class="exact"></div>
+ <div id="inheritedOver" class="over"></div>
+ <div id="mixColor" class="mix-color"><div id="mixColorUnder" class="under"></div></div>
+</div>
+<script>
+ test(() => {
+ for (const element of [ownUnder, ownExact, ownOver, inheritedUnder, inheritedExact, inheritedOver, mixColorUnder])
+ println(`${element.id} background-color ${getComputedStyle(element).backgroundColor}`);
+ println(`mixColor color ${getComputedStyle(mixColor).color}`);
+ });
+</script>