1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:48:10 +00:00

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.
This commit is contained in:
Andreas Kling 2019-09-28 22:18:19 +02:00
parent b8cab2a934
commit 62cbaa74f3
7 changed files with 56 additions and 10 deletions

View file

@ -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);
}