mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:58:11 +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
|
@ -1,3 +1,4 @@
|
|||
#include <LibHTML/CSS/StyleResolver.h>
|
||||
#include <LibHTML/DOM/Element.h>
|
||||
#include <LibHTML/Layout/LayoutBlock.h>
|
||||
#include <LibHTML/Layout/LayoutInline.h>
|
||||
|
@ -34,7 +35,7 @@ String Element::attribute(const String& name) const
|
|||
{
|
||||
if (auto* attribute = find_attribute(name))
|
||||
return attribute->value();
|
||||
return { };
|
||||
return {};
|
||||
}
|
||||
|
||||
void Element::set_attribute(const String& name, const String& value)
|
||||
|
@ -62,3 +63,20 @@ bool Element::has_class(const StringView& class_name) const
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
RefPtr<LayoutNode> Element::create_layout_node(const StyleResolver& resolver, const StyleProperties* parent_properties) const
|
||||
{
|
||||
auto style_properties = resolver.resolve_style(*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();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue