From 841ae4439234abde6c186f021845dd5448586ab2 Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Wed, 25 Sep 2019 12:33:28 +0300 Subject: [PATCH] LibHTML: Implement basic style inheritance --- Libraries/LibHTML/CSS/StyleResolver.cpp | 11 ++++++++++- Libraries/LibHTML/CSS/StyleResolver.h | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Libraries/LibHTML/CSS/StyleResolver.cpp b/Libraries/LibHTML/CSS/StyleResolver.cpp index 81dd368c82..d18c5cde74 100644 --- a/Libraries/LibHTML/CSS/StyleResolver.cpp +++ b/Libraries/LibHTML/CSS/StyleResolver.cpp @@ -52,9 +52,18 @@ NonnullRefPtrVector StyleResolver::collect_matching_rules(const Eleme return matching_rules; } -StyleProperties StyleResolver::resolve_style(const Element& element) +StyleProperties StyleResolver::resolve_style(const Element& element, const StyleProperties* parent_properties) const { StyleProperties style_properties; + + if (parent_properties) { + parent_properties->for_each_property([&](const StringView& name, auto& value) { + // TODO: proper inheritance + if (name.starts_with("font") || name == "white-space") + style_properties.set_property(name, value); + }); + } + auto matching_rules = collect_matching_rules(element); for (auto& rule : matching_rules) { for (auto& declaration : rule.declarations()) { diff --git a/Libraries/LibHTML/CSS/StyleResolver.h b/Libraries/LibHTML/CSS/StyleResolver.h index 1b77e8f90d..9f814ace07 100644 --- a/Libraries/LibHTML/CSS/StyleResolver.h +++ b/Libraries/LibHTML/CSS/StyleResolver.h @@ -18,7 +18,7 @@ public: Document& document() { return m_document; } const Document& document() const { return m_document; } - StyleProperties resolve_style(const Element&); + StyleProperties resolve_style(const Element&, const StyleProperties* parent_properties) const; NonnullRefPtrVector collect_matching_rules(const Element&) const;