From 17bb913625b58c5375a1f74646bd77477b4c7208 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Thu, 16 Sep 2021 19:40:56 +0100 Subject: [PATCH] LibWeb: Implement `currentcolor` special value The `currentcolor` identifier represents the current value of the `color` property. This is the default value for `border-color` and `text-decoration-color`, and is generally useful to have. :^) --- Base/res/html/misc/colors.html | 2 ++ Userland/Libraries/LibWeb/CSS/Identifiers.json | 1 + Userland/Libraries/LibWeb/CSS/StyleValue.cpp | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/Base/res/html/misc/colors.html b/Base/res/html/misc/colors.html index df0d67de1a..f236090873 100644 --- a/Base/res/html/misc/colors.html +++ b/Base/res/html/misc/colors.html @@ -12,6 +12,7 @@ #g { background-color: rgba(0%, 100%, 0%, 1); } #h { background-color: hsl(120, 100%, 50%); } #i { background-color: hsla(120, 100%, 50%, 1); } + #j { color: lime; background-color: currentColor; } @@ -25,5 +26,6 @@
This is green, using rgba(0%, 100%, 0%, 1).
This is green, using hsl(120, 100%, 50%).
This is green, using hsla(120, 100%, 50%, 1).
+
This is green, using currentcolor.
diff --git a/Userland/Libraries/LibWeb/CSS/Identifiers.json b/Userland/Libraries/LibWeb/CSS/Identifiers.json index dbbc891b0e..fdd0ee5a09 100644 --- a/Userland/Libraries/LibWeb/CSS/Identifiers.json +++ b/Userland/Libraries/LibWeb/CSS/Identifiers.json @@ -82,6 +82,7 @@ "context-menu", "copy", "crosshair", + "currentcolor", "cursive", "dashed", "decimal", diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp index 412b6bc440..8f4cda260b 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp @@ -33,6 +33,12 @@ String IdentifierStyleValue::to_string() const Color IdentifierStyleValue::to_color(Layout::NodeWithStyle const& node) const { + if (id() == CSS::ValueID::Currentcolor) { + if (!node.has_style()) + return Color::Black; + return node.computed_values().color(); + } + auto& document = node.document(); if (id() == CSS::ValueID::LibwebLink) return document.link_color();