mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 18:38:12 +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:
parent
09dccb3224
commit
f150134de9
8 changed files with 36 additions and 27 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue