Skip to content

Commit ffcd395

Browse files
committed
LibHTML: Have element keep a pointer to their resolved style
This will make it easy to implement a simple element style inspector.
1 parent 285130c commit ffcd395

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

Libraries/LibHTML/DOM/Element.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ bool Element::has_class(const StringView& class_name) const
7878
RefPtr<LayoutNode> Element::create_layout_node(const StyleProperties* parent_style) const
7979
{
8080
auto style = document().style_resolver().resolve_style(*this, parent_style);
81+
const_cast<Element&>(*this).m_resolved_style = style;
8182
auto display = style->string_or_fallback(CSS::PropertyID::Display, "inline");
8283

8384
if (display == "none")
@@ -139,6 +140,7 @@ void Element::recompute_style()
139140
return;
140141
ASSERT(parent_layout_node);
141142
auto style = document().style_resolver().resolve_style(*this, &parent_layout_node->style());
143+
m_resolved_style = style;
142144
if (!layout_node()) {
143145
if (style->string_or_fallback(CSS::PropertyID::Display, "inline") == "none")
144146
return;

Libraries/LibHTML/DOM/Element.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ class Element : public ParentNode {
5656

5757
String name() const { return attribute("name"); }
5858

59+
const StyleProperties* resolved_style() const { return m_resolved_style.ptr(); }
60+
5961
private:
6062
RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const override;
6163

@@ -64,6 +66,8 @@ class Element : public ParentNode {
6466

6567
String m_tag_name;
6668
Vector<Attribute> m_attributes;
69+
70+
RefPtr<StyleProperties> m_resolved_style;
6771
};
6872

6973
template<>

0 commit comments

Comments
 (0)