From a5e5a3fab7547df0b590d8123e658c66f0ab18fe Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 30 Sep 2019 20:25:33 +0200 Subject: [PATCH] LibHTML: Implement basic support for inline style attributes You can now style elements with inline styles:
This is red!
Pretty neat :^) --- Libraries/LibHTML/CSS/StyleResolver.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Libraries/LibHTML/CSS/StyleResolver.cpp b/Libraries/LibHTML/CSS/StyleResolver.cpp index da39bcd9b2..1c53f53422 100644 --- a/Libraries/LibHTML/CSS/StyleResolver.cpp +++ b/Libraries/LibHTML/CSS/StyleResolver.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include StyleResolver::StyleResolver(Document& document) @@ -74,5 +75,15 @@ StyleProperties StyleResolver::resolve_style(const Element& element, const Style style_properties.set_property(property.name, property.value); } } + + auto style_attribute = element.attribute("style"); + if (!style_attribute.is_null()) { + if (auto declaration = parse_css_declaration(style_attribute)) { + for (auto& property : declaration->properties()) { + style_properties.set_property(property.name, property.value); + } + } + } + return style_properties; }