mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-27 03:37:53 +00:00
LibHTML: Make Node::create_layout_node() virtual
Instead of branching on the Node type, let subclasses decide how their layout nodes get constructed. This will allow elements to create custom layout nodes if they want.
This commit is contained in:
@@ -19,31 +19,6 @@ Node::~Node()
|
||||
{
|
||||
}
|
||||
|
||||
RefPtr<LayoutNode> Node::create_layout_node(const StyleResolver& resolver, const StyleProperties* parent_properties) const
|
||||
{
|
||||
if (is_document())
|
||||
return adopt(*new LayoutDocument(static_cast<const Document&>(*this), StyleProperties::create()));
|
||||
|
||||
if (is_text())
|
||||
return adopt(*new LayoutText(static_cast<const Text&>(*this)));
|
||||
|
||||
ASSERT(is_element());
|
||||
|
||||
auto style_properties = resolver.resolve_style(static_cast<const Element&>(*this), parent_properties);
|
||||
|
||||
auto display_property = style_properties->property("display");
|
||||
String display = display_property.has_value() ? display_property.release_value()->to_string() : "inline";
|
||||
|
||||
if (display == "none")
|
||||
return nullptr;
|
||||
if (display == "block" || display == "list-item")
|
||||
return adopt(*new LayoutBlock(this, move(style_properties)));
|
||||
if (display == "inline")
|
||||
return adopt(*new LayoutInline(*this, move(style_properties)));
|
||||
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
RefPtr<LayoutNode> Node::create_layout_tree(const StyleResolver& resolver, const StyleProperties* parent_properties) const
|
||||
{
|
||||
auto layout_node = create_layout_node(resolver, parent_properties);
|
||||
|
||||
Reference in New Issue
Block a user