1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 05:17:35 +00:00

LibHTML: Use an enum for CSS property ID's

Instead of using string everywhere, have the CSS parser produce enum
values, since they are a lot nicer to work with.

In the future we should generate most of this code based on a list of
supported CSS properties.
This commit is contained in:
Andreas Kling 2019-10-08 15:34:19 +02:00
parent 19dbfc3153
commit 31ac19543a
18 changed files with 207 additions and 94 deletions

View file

@ -92,7 +92,7 @@ Color Document::background_color() const
if (!body_layout_node)
return Color::White;
auto background_color = body_layout_node->style().property("background-color");
auto background_color = body_layout_node->style().property(CSS::PropertyID::BackgroundColor);
if (!background_color.has_value() || !background_color.value()->is_color())
return Color::White;

View file

@ -73,7 +73,7 @@ RefPtr<LayoutNode> Element::create_layout_node(const StyleResolver& resolver, co
{
auto style = resolver.resolve_style(*this, parent_style);
auto display_property = style->property("display");
auto display_property = style->property(CSS::PropertyID::Display);
String display = display_property.has_value() ? display_property.release_value()->to_string() : "inline";
if (display == "none")

View file

@ -18,11 +18,11 @@ void HTMLBodyElement::apply_presentational_hints(StyleProperties& style) const
if (name == "bgcolor") {
auto color = Color::from_string(value);
if (color.has_value())
style.set_property("background-color", ColorStyleValue::create(color.value()));
style.set_property(CSS::PropertyID::BackgroundColor, ColorStyleValue::create(color.value()));
} else if (name == "text") {
auto color = Color::from_string(value);
if (color.has_value())
style.set_property("color", ColorStyleValue::create(color.value()));
style.set_property(CSS::PropertyID::Color, ColorStyleValue::create(color.value()));
}
});
}

View file

@ -17,7 +17,7 @@ void HTMLFontElement::apply_presentational_hints(StyleProperties& style) const
if (name == "color") {
auto color = Color::from_string(value);
if (color.has_value())
style.set_property("color", ColorStyleValue::create(color.value()));
style.set_property(CSS::PropertyID::Color, ColorStyleValue::create(color.value()));
}
});
}

View file

@ -59,7 +59,7 @@ RefPtr<LayoutNode> HTMLImageElement::create_layout_node(const StyleResolver& res
{
auto style = resolver.resolve_style(*this, parent_style);
auto display_property = style->property("display");
auto display_property = style->property(CSS::PropertyID::Display);
String display = display_property.has_value() ? display_property.release_value()->to_string() : "inline";
if (display == "none")