summaryrefslogtreecommitdiff
path: root/Libraries/LibHTML/Parser/CSSParser.cpp
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-09-28 22:18:19 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-09-28 22:57:46 +0200
commit62cbaa74f3a60a30ce8a434295c6c565e4bdcde7 (patch)
tree4ca55e51243513ff6e8757c2fbaf6c3f3fa20067 /Libraries/LibHTML/Parser/CSSParser.cpp
parentb8cab2a934a8846b05c4f18453339a0b99f2c26b (diff)
downloadserenity-62cbaa74f3a60a30ce8a434295c6c565e4bdcde7.zip
LibHTML: Respect the CSS "color" property for text
Also remove the color values from the ComputedStyle object and get them via StyleProperties instead. At the moment, we only handle colors that Color::from_string() parses.
Diffstat (limited to 'Libraries/LibHTML/Parser/CSSParser.cpp')
-rw-r--r--Libraries/LibHTML/Parser/CSSParser.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/Libraries/LibHTML/Parser/CSSParser.cpp b/Libraries/LibHTML/Parser/CSSParser.cpp
index 408751f509..518ac990cf 100644
--- a/Libraries/LibHTML/Parser/CSSParser.cpp
+++ b/Libraries/LibHTML/Parser/CSSParser.cpp
@@ -3,6 +3,16 @@
#include <ctype.h>
#include <stdio.h>
+static Optional<Color> parse_css_color(const StringView& view)
+{
+ auto color = Color::from_string(view);
+ if (color.has_value())
+ return color;
+
+ // FIXME: Parse all valid color strings :^)
+ return {};
+}
+
NonnullRefPtr<StyleValue> parse_css_value(const StringView& view)
{
String string(view);
@@ -19,6 +29,11 @@ NonnullRefPtr<StyleValue> parse_css_value(const StringView& view)
return InitialStyleValue::create();
if (string == "auto")
return LengthStyleValue::create(Length());
+
+ auto color = parse_css_color(view);
+ if (color.has_value())
+ return ColorStyleValue::create(color.value());
+
return StringStyleValue::create(string);
}