1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-03 05:32:13 +00:00

LibHTML: LayoutText should always use parent's style properties

This patch makes StyleProperties heap-allocated and ref-counted so that
a LayoutNode can be without one. The ref-counting also allows anonymous
blocks to share style with their parent block.

LayoutText never needs a StyleProperties, since text always inherits
style from its parent element. This is handled by style_properties().
This commit is contained in:
Andreas Kling 2019-10-04 12:12:39 +02:00
parent 79d8b9ae75
commit 4e35bbffdd
14 changed files with 45 additions and 39 deletions

View file

@ -57,22 +57,22 @@ NonnullRefPtrVector<StyleRule> StyleResolver::collect_matching_rules(const Eleme
return matching_rules;
}
StyleProperties StyleResolver::resolve_style(const Element& element, const StyleProperties* parent_properties) const
NonnullRefPtr<StyleProperties> StyleResolver::resolve_style(const Element& element, const StyleProperties* parent_properties) const
{
StyleProperties style_properties;
auto style_properties = StyleProperties::create();
if (parent_properties) {
parent_properties->for_each_property([&](const StringView& name, auto& value) {
// TODO: proper inheritance
if (name.starts_with("font") || name == "white-space" || name == "color" || name == "text-decoration")
style_properties.set_property(name, value);
style_properties->set_property(name, value);
});
}
auto matching_rules = collect_matching_rules(element);
for (auto& rule : matching_rules) {
for (auto& property : rule.declaration().properties()) {
style_properties.set_property(property.name, property.value);
style_properties->set_property(property.name, property.value);
}
}
@ -80,7 +80,7 @@ StyleProperties StyleResolver::resolve_style(const Element& element, const 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);
style_properties->set_property(property.name, property.value);
}
}
}