Truly independent web browser
LibWeb: Accept light-dark() and system colors as initial values
sideshowbarker8fb19b429089
diff --git a/Libraries/LibWeb/Rust/src/css/style_compute.rs b/Libraries/LibWeb/Rust/src/css/style_compute.rsindex a9e0436cafa..912c2b62d90 100644--- a/Libraries/LibWeb/Rust/src/css/style_compute.rs+++ b/Libraries/LibWeb/Rust/src/css/style_compute.rs@@ -1139,13 +1139,13 @@ pub(crate) fn value_is_computationally_independent(value: &StyleValueData) -> OpSome(independent)};match value {- StyleValueData::Keyword { keyword } => {+ StyleValueData::Keyword { .. } => {if value_is_css_wide_keyword(value) {return Some(false);}- if *keyword != keyword::CURRENTCOLOR && keyword_is_color(*keyword) {- return Some(false);- }+ // NB: System colors are computationally independent, although the color scheme decides what they compute+ // to, and so is light-dark() below:+ // https://github.com/w3c/csswg-drafts/issues/12735// FIXME: Are there any other keywords which aren't computationally independent?Some(true)}@@ -1176,7 +1176,11 @@ pub(crate) fn value_is_computationally_independent(value: &StyleValueData) -> Op| StyleValueData::Url { .. }| StyleValueData::FontSource { .. }| StyleValueData::ScrollbarGutter { .. } => Some(true),- StyleValueData::LightDark { .. } | StyleValueData::TreeCountingFunction { .. } => Some(false),+ StyleValueData::LightDark(light_dark) => Some(+ value_is_computationally_independent(light_dark.light.data())?+ && value_is_computationally_independent(light_dark.dark.data())?,+ ),+ StyleValueData::TreeCountingFunction { .. } => Some(false),// The calculation tree decides natively; its style value leaves resolve through the// same decision, falling back for the types the core cannot decide.StyleValueData::Calculated(calculated_payload) => {diff --git a/Tests/LibWeb/Text/expected/css/register-property-color-scheme-dependent-initial-value.txt b/Tests/LibWeb/Text/expected/css/register-property-color-scheme-dependent-initial-value.txtnew file mode 100644index 00000000000..c77e3c4d848--- /dev/null+++ b/Tests/LibWeb/Text/expected/css/register-property-color-scheme-dependent-initial-value.txt@@ -0,0 +1,4 @@+light-dark(black, white): OK+Canvas: OK+light-dark(Canvas, CanvasText): OK+1em: SyntaxErrordiff --git a/Tests/LibWeb/Text/input/css/register-property-color-scheme-dependent-initial-value.html b/Tests/LibWeb/Text/input/css/register-property-color-scheme-dependent-initial-value.htmlnew file mode 100644index 00000000000..698332c6b8d--- /dev/null+++ b/Tests/LibWeb/Text/input/css/register-property-color-scheme-dependent-initial-value.html@@ -0,0 +1,22 @@+<!doctype html>+<script src="../include.js"></script>+<script>+ // System colors and light-dark() are computationally independent, although the color scheme decides what they+ // compute to: https://github.com/w3c/csswg-drafts/issues/12735+ test(() => {+ const cases = [+ ["<color>", "light-dark(black, white)"],+ ["<color>", "Canvas"],+ ["<color>", "light-dark(Canvas, CanvasText)"],+ ["<length>", "1em"],+ ];+ cases.forEach(([syntax, initialValue], index) => {+ try {+ CSS.registerProperty({ name: `--p${index}`, syntax, inherits: false, initialValue });+ println(`${initialValue}: OK`);+ } catch (error) {+ println(`${initialValue}: ${error.name}`);+ }+ });+ });+</script>