Truly independent web browser
LibWeb: Resolve “color: initial” against the color scheme
sideshowbarkerbd7877ada93c
diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/compute.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/compute.rsindex da70e21ad21..3d00c95c539 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/compute.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/compute.rs@@ -2296,7 +2296,16 @@ impl<'a> DecidedWinners<'_, 'a> {).filter(|value| !value.pointer().is_null())};- initial_value(property).filter(|value| initial_value(inherited_property) == Some(*value))+ // NB: A system color resolves against the element's own used color scheme, which the+ // initial style can't know, so that initial value computes with the element.+ initial_value(property)+ .filter(|value| initial_value(inherited_property) == Some(*value))+ .filter(|_| {+ !matches!(+ crate::css::style_compute::initial_value_handle(property).data(),+ StyleValueData::Keyword { keyword } if crate::css::style_compute::keyword_is_color(*keyword)+ )+ })}}.filter(|value| {diff --git a/Tests/LibWeb/Text/expected/css/color-initial-follows-color-scheme.txt b/Tests/LibWeb/Text/expected/css/color-initial-follows-color-scheme.txtnew file mode 100644index 00000000000..2d6bed6d585--- /dev/null+++ b/Tests/LibWeb/Text/expected/css/color-initial-follows-color-scheme.txt@@ -0,0 +1,5 @@+dark-initial: rgb(255, 255, 255)+dark-canvastext: rgb(255, 255, 255)+dark-light-initial: rgb(0, 0, 0)+light-initial: rgb(0, 0, 0)+light-dark-initial: rgb(255, 255, 255)diff --git a/Tests/LibWeb/Text/input/css/color-initial-follows-color-scheme.html b/Tests/LibWeb/Text/input/css/color-initial-follows-color-scheme.htmlnew file mode 100644index 00000000000..de3171e7128--- /dev/null+++ b/Tests/LibWeb/Text/input/css/color-initial-follows-color-scheme.html@@ -0,0 +1,22 @@+<!DOCTYPE html>+<style>+ .dark { color-scheme: dark; }+ .light { color-scheme: light; }+</style>+<div class="dark">+ <div id="dark-initial" style="color: initial">x</div>+ <div id="dark-canvastext" style="color: canvastext">x</div>+ <div id="dark-light-initial" class="light" style="color: initial">x</div>+</div>+<div class="light">+ <div id="light-initial" style="color: initial">x</div>+ <div id="light-dark-initial" class="dark" style="color: initial">x</div>+</div>+<script src="../include.js"></script>+<script>+ // The initial value of color is canvastext, which resolves against the element's used color scheme.+ test(() => {+ for (const id of ["dark-initial", "dark-canvastext", "dark-light-initial", "light-initial", "light-dark-initial"])+ println(`${id}: ${getComputedStyle(document.getElementById(id)).color}`);+ });+</script>