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:
Andreas Kling 2019-10-05 22:27:52 +02:00
commit f150134de9
Notes: sideshowbarker 2024-07-19 11:48:31 +09:00
8 changed files with 36 additions and 27 deletions

View file

@ -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);