summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2020-01-02 14:52:34 +0100
committerAndreas Kling <awesomekling@gmail.com>2020-01-02 14:52:34 +0100
commitffcd395afc144b7790118b0e3db40a62c43cb6fd (patch)
treef788e8da60f56efd273a30255fd9d28221b61f01 /Libraries
parent285130cc550bc6a2f917a8353fcfaa5a0f131c92 (diff)
downloadserenity-ffcd395afc144b7790118b0e3db40a62c43cb6fd.zip
LibHTML: Have element keep a pointer to their resolved style
This will make it easy to implement a simple element style inspector.
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibHTML/DOM/Element.cpp2
-rw-r--r--Libraries/LibHTML/DOM/Element.h4
2 files changed, 6 insertions, 0 deletions
diff --git a/Libraries/LibHTML/DOM/Element.cpp b/Libraries/LibHTML/DOM/Element.cpp
index fefde6a4a8..2f339d7bf8 100644
--- a/Libraries/LibHTML/DOM/Element.cpp
+++ b/Libraries/LibHTML/DOM/Element.cpp
@@ -78,6 +78,7 @@ bool Element::has_class(const StringView& class_name) const
RefPtr<LayoutNode> Element::create_layout_node(const StyleProperties* parent_style) const
{
auto style = document().style_resolver().resolve_style(*this, parent_style);
+ const_cast<Element&>(*this).m_resolved_style = style;
auto display = style->string_or_fallback(CSS::PropertyID::Display, "inline");
if (display == "none")
@@ -139,6 +140,7 @@ void Element::recompute_style()
return;
ASSERT(parent_layout_node);
auto style = document().style_resolver().resolve_style(*this, &parent_layout_node->style());
+ m_resolved_style = style;
if (!layout_node()) {
if (style->string_or_fallback(CSS::PropertyID::Display, "inline") == "none")
return;
diff --git a/Libraries/LibHTML/DOM/Element.h b/Libraries/LibHTML/DOM/Element.h
index 4444bd497a..cf53f8221a 100644
--- a/Libraries/LibHTML/DOM/Element.h
+++ b/Libraries/LibHTML/DOM/Element.h
@@ -56,6 +56,8 @@ public:
String name() const { return attribute("name"); }
+ const StyleProperties* resolved_style() const { return m_resolved_style.ptr(); }
+
private:
RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const override;
@@ -64,6 +66,8 @@ private:
String m_tag_name;
Vector<Attribute> m_attributes;
+
+ RefPtr<StyleProperties> m_resolved_style;
};
template<>