LibWeb: Store pseudo-element layout nodes as NodeWithStyle

We were already guaranteed to return a NodeWithStyle from
`create_layout_node_for_display_type()`, so make use of that knowledge.
This commit is contained in:
Sam Atkins 2024-08-06 11:42:49 +01:00 committed by Andreas Kling
parent 7758875cfd
commit 521cd161a8
Notes: github-actions[bot] 2024-08-07 14:16:00 +00:00
2 changed files with 7 additions and 7 deletions

View file

@ -395,7 +395,7 @@ JS::GCPtr<Layout::Node> Element::create_layout_node(NonnullRefPtr<CSS::StyleProp
return create_layout_node_for_display_type(document(), display, move(style), this);
}
JS::GCPtr<Layout::Node> Element::create_layout_node_for_display_type(DOM::Document& document, CSS::Display const& display, NonnullRefPtr<CSS::StyleProperties> style, Element* element)
JS::GCPtr<Layout::NodeWithStyle> Element::create_layout_node_for_display_type(DOM::Document& document, CSS::Display const& display, NonnullRefPtr<CSS::StyleProperties> style, Element* element)
{
if (display.is_table_inside() || display.is_table_row_group() || display.is_table_header_group() || display.is_table_footer_group() || display.is_table_row())
return document.heap().allocate_without_realm<Layout::Box>(document, element, move(style));
@ -1125,7 +1125,7 @@ void Element::children_changed()
set_needs_style_update(true);
}
void Element::set_pseudo_element_node(Badge<Layout::TreeBuilder>, CSS::Selector::PseudoElement::Type pseudo_element, JS::GCPtr<Layout::Node> pseudo_element_node)
void Element::set_pseudo_element_node(Badge<Layout::TreeBuilder>, CSS::Selector::PseudoElement::Type pseudo_element, JS::GCPtr<Layout::NodeWithStyle> pseudo_element_node)
{
auto existing_pseudo_element = get_pseudo_element(pseudo_element);
if (!existing_pseudo_element.has_value() && !pseudo_element_node)
@ -1134,7 +1134,7 @@ void Element::set_pseudo_element_node(Badge<Layout::TreeBuilder>, CSS::Selector:
ensure_pseudo_element(pseudo_element).layout_node = move(pseudo_element_node);
}
JS::GCPtr<Layout::Node> Element::get_pseudo_element_node(CSS::Selector::PseudoElement::Type pseudo_element) const
JS::GCPtr<Layout::NodeWithStyle> Element::get_pseudo_element_node(CSS::Selector::PseudoElement::Type pseudo_element) const
{
if (auto element_data = get_pseudo_element(pseudo_element); element_data.has_value())
return element_data->layout_node;

View file

@ -241,10 +241,10 @@ public:
virtual void did_receive_focus() { }
virtual void did_lose_focus() { }
static JS::GCPtr<Layout::Node> create_layout_node_for_display_type(DOM::Document&, CSS::Display const&, NonnullRefPtr<CSS::StyleProperties>, Element*);
static JS::GCPtr<Layout::NodeWithStyle> create_layout_node_for_display_type(DOM::Document&, CSS::Display const&, NonnullRefPtr<CSS::StyleProperties>, Element*);
void set_pseudo_element_node(Badge<Layout::TreeBuilder>, CSS::Selector::PseudoElement::Type, JS::GCPtr<Layout::Node>);
JS::GCPtr<Layout::Node> get_pseudo_element_node(CSS::Selector::PseudoElement::Type) const;
void set_pseudo_element_node(Badge<Layout::TreeBuilder>, CSS::Selector::PseudoElement::Type, JS::GCPtr<Layout::NodeWithStyle>);
JS::GCPtr<Layout::NodeWithStyle> get_pseudo_element_node(CSS::Selector::PseudoElement::Type) const;
void clear_pseudo_element_nodes(Badge<Layout::TreeBuilder>);
void serialize_pseudo_elements_as_json(JsonArraySerializer<StringBuilder>& children_array) const;
@ -453,7 +453,7 @@ private:
HashMap<FlyString, CSS::StyleProperty> m_custom_properties;
struct PseudoElement {
JS::GCPtr<Layout::Node> layout_node;
JS::GCPtr<Layout::NodeWithStyle> layout_node;
RefPtr<CSS::StyleProperties> computed_css_values;
HashMap<FlyString, CSS::StyleProperty> custom_properties;
};