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

LibHTML: Implement basic support for inline style attributes

You can now style elements with inline styles:

    <div style="color: #ff0000">This is red!</div>

Pretty neat :^)
This commit is contained in:
Andreas Kling 2019-09-30 20:25:33 +02:00
parent b2a0d20580
commit a5e5a3fab7

View file

@ -3,6 +3,7 @@
#include <LibHTML/DOM/Document.h>
#include <LibHTML/DOM/Element.h>
#include <LibHTML/Dump.h>
#include <LibHTML/Parser/CSSParser.h>
#include <stdio.h>
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;
}