mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:08:10 +00:00
LibHTML: Create some subdirectories.
This commit is contained in:
parent
0522a8f71c
commit
1f51c2b7da
25 changed files with 49 additions and 50 deletions
66
LibHTML/DOM/Element.cpp
Normal file
66
LibHTML/DOM/Element.cpp
Normal file
|
@ -0,0 +1,66 @@
|
|||
#include <LibHTML/DOM/Element.h>
|
||||
#include <LibHTML/Layout/LayoutBlock.h>
|
||||
#include <LibHTML/Layout/LayoutInline.h>
|
||||
|
||||
Element::Element(const String& tag_name)
|
||||
: ParentNode(NodeType::ELEMENT_NODE)
|
||||
, m_tag_name(tag_name)
|
||||
{
|
||||
}
|
||||
|
||||
Element::~Element()
|
||||
{
|
||||
}
|
||||
|
||||
Attribute* Element::find_attribute(const String& name)
|
||||
{
|
||||
for (auto& attribute : m_attributes) {
|
||||
if (attribute.name() == name)
|
||||
return &attribute;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const Attribute* Element::find_attribute(const String& name) const
|
||||
{
|
||||
for (auto& attribute : m_attributes) {
|
||||
if (attribute.name() == name)
|
||||
return &attribute;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
String Element::attribute(const String& name) const
|
||||
{
|
||||
if (auto* attribute = find_attribute(name))
|
||||
return attribute->value();
|
||||
return { };
|
||||
}
|
||||
|
||||
void Element::set_attribute(const String& name, const String& value)
|
||||
{
|
||||
if (auto* attribute = find_attribute(name))
|
||||
attribute->set_value(value);
|
||||
else
|
||||
m_attributes.append({ name, value });
|
||||
}
|
||||
|
||||
void Element::set_attributes(Vector<Attribute>&& attributes)
|
||||
{
|
||||
m_attributes = move(attributes);
|
||||
}
|
||||
|
||||
RetainPtr<LayoutNode> Element::create_layout_node()
|
||||
{
|
||||
if (m_tag_name == "html")
|
||||
return adopt(*new LayoutBlock(*this));
|
||||
if (m_tag_name == "body")
|
||||
return adopt(*new LayoutBlock(*this));
|
||||
if (m_tag_name == "h1")
|
||||
return adopt(*new LayoutBlock(*this));
|
||||
if (m_tag_name == "p")
|
||||
return adopt(*new LayoutBlock(*this));
|
||||
if (m_tag_name == "b")
|
||||
return adopt(*new LayoutInline(*this));
|
||||
return nullptr;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue