mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 11:17:44 +00:00
Libraries: Create top level directory for libraries.
Things were getting a little crowded in the project root, so this patch moves the Lib*/ directories into Libraries/.
This commit is contained in:
parent
63814ffebf
commit
04b9dc2d30
328 changed files with 36 additions and 36 deletions
21
Libraries/LibHTML/DOM/Document.cpp
Normal file
21
Libraries/LibHTML/DOM/Document.cpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
#include <LibHTML/CSS/StyleResolver.h>
|
||||
#include <LibHTML/DOM/Document.h>
|
||||
#include <LibHTML/DOM/Element.h>
|
||||
#include <LibHTML/Layout/LayoutDocument.h>
|
||||
#include <stdio.h>
|
||||
|
||||
Document::Document()
|
||||
: ParentNode(NodeType::DOCUMENT_NODE)
|
||||
{
|
||||
}
|
||||
|
||||
Document::~Document()
|
||||
{
|
||||
}
|
||||
|
||||
StyleResolver& Document::style_resolver()
|
||||
{
|
||||
if (!m_style_resolver)
|
||||
m_style_resolver = make<StyleResolver>(*this);
|
||||
return *m_style_resolver;
|
||||
}
|
27
Libraries/LibHTML/DOM/Document.h
Normal file
27
Libraries/LibHTML/DOM/Document.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/AKString.h>
|
||||
#include <AK/NonnullRefPtrVector.h>
|
||||
#include <AK/OwnPtr.h>
|
||||
#include <LibHTML/CSS/StyleResolver.h>
|
||||
#include <LibHTML/CSS/StyleSheet.h>
|
||||
#include <LibHTML/DOM/ParentNode.h>
|
||||
|
||||
class LayoutNode;
|
||||
class StyleResolver;
|
||||
class StyleSheet;
|
||||
|
||||
class Document : public ParentNode {
|
||||
public:
|
||||
Document();
|
||||
virtual ~Document() override;
|
||||
|
||||
StyleResolver& style_resolver();
|
||||
|
||||
void add_sheet(const StyleSheet& sheet) { m_sheets.append(sheet); }
|
||||
const NonnullRefPtrVector<StyleSheet>& stylesheets() const { return m_sheets; }
|
||||
|
||||
private:
|
||||
OwnPtr<StyleResolver> m_style_resolver;
|
||||
NonnullRefPtrVector<StyleSheet> m_sheets;
|
||||
};
|
64
Libraries/LibHTML/DOM/Element.cpp
Normal file
64
Libraries/LibHTML/DOM/Element.cpp
Normal file
|
@ -0,0 +1,64 @@
|
|||
#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);
|
||||
}
|
||||
|
||||
bool Element::has_class(const StringView& class_name) const
|
||||
{
|
||||
auto value = attribute("class");
|
||||
if (value.is_empty())
|
||||
return false;
|
||||
auto parts = value.split_view(' ');
|
||||
for (auto& part : parts) {
|
||||
if (part == class_name)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
52
Libraries/LibHTML/DOM/Element.h
Normal file
52
Libraries/LibHTML/DOM/Element.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
#pragma once
|
||||
|
||||
#include <LibHTML/DOM/ParentNode.h>
|
||||
#include <AK/AKString.h>
|
||||
|
||||
class Attribute {
|
||||
public:
|
||||
Attribute(const String& name, const String& value)
|
||||
: m_name(name)
|
||||
, m_value(value)
|
||||
{
|
||||
}
|
||||
|
||||
const String& name() const { return m_name; }
|
||||
const String& value() const { return m_value; }
|
||||
|
||||
void set_value(const String& value) { m_value = value; }
|
||||
|
||||
private:
|
||||
String m_name;
|
||||
String m_value;
|
||||
};
|
||||
|
||||
class Element : public ParentNode {
|
||||
public:
|
||||
explicit Element(const String& tag_name);
|
||||
virtual ~Element() override;
|
||||
|
||||
const String& tag_name() const { return m_tag_name; }
|
||||
|
||||
String attribute(const String& name) const;
|
||||
void set_attribute(const String& name, const String& value);
|
||||
|
||||
void set_attributes(Vector<Attribute>&&);
|
||||
|
||||
template<typename Callback>
|
||||
void for_each_attribute(Callback callback) const
|
||||
{
|
||||
for (auto& attribute : m_attributes)
|
||||
callback(attribute.name(), attribute.value());
|
||||
}
|
||||
|
||||
bool has_class(const StringView&) const;
|
||||
|
||||
private:
|
||||
Attribute* find_attribute(const String& name);
|
||||
const Attribute* find_attribute(const String& name) const;
|
||||
|
||||
String m_tag_name;
|
||||
Vector<Attribute> m_attributes;
|
||||
};
|
||||
|
11
Libraries/LibHTML/DOM/Node.cpp
Normal file
11
Libraries/LibHTML/DOM/Node.cpp
Normal file
|
@ -0,0 +1,11 @@
|
|||
#include <LibHTML/DOM/Node.h>
|
||||
#include <LibHTML/Layout/LayoutNode.h>
|
||||
|
||||
Node::Node(NodeType type)
|
||||
: m_type(type)
|
||||
{
|
||||
}
|
||||
|
||||
Node::~Node()
|
||||
{
|
||||
}
|
31
Libraries/LibHTML/DOM/Node.h
Normal file
31
Libraries/LibHTML/DOM/Node.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Badge.h>
|
||||
#include <AK/RefPtr.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibHTML/TreeNode.h>
|
||||
|
||||
enum class NodeType : unsigned {
|
||||
INVALID = 0,
|
||||
ELEMENT_NODE = 1,
|
||||
TEXT_NODE = 3,
|
||||
DOCUMENT_NODE = 9,
|
||||
};
|
||||
|
||||
class ParentNode;
|
||||
|
||||
class Node : public TreeNode<Node> {
|
||||
public:
|
||||
virtual ~Node();
|
||||
|
||||
NodeType type() const { return m_type; }
|
||||
bool is_element() const { return type() == NodeType::ELEMENT_NODE; }
|
||||
bool is_text() const { return type() == NodeType::TEXT_NODE; }
|
||||
bool is_document() const { return type() == NodeType::DOCUMENT_NODE; }
|
||||
bool is_parent_node() const { return is_element() || is_document(); }
|
||||
|
||||
protected:
|
||||
explicit Node(NodeType);
|
||||
|
||||
NodeType m_type { NodeType::INVALID };
|
||||
};
|
2
Libraries/LibHTML/DOM/ParentNode.cpp
Normal file
2
Libraries/LibHTML/DOM/ParentNode.cpp
Normal file
|
@ -0,0 +1,2 @@
|
|||
#include <LibHTML/DOM/ParentNode.h>
|
||||
|
29
Libraries/LibHTML/DOM/ParentNode.h
Normal file
29
Libraries/LibHTML/DOM/ParentNode.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
#pragma once
|
||||
|
||||
#include <LibHTML/DOM/Node.h>
|
||||
|
||||
class ParentNode : public Node {
|
||||
public:
|
||||
template<typename F> void for_each_child(F) const;
|
||||
template<typename F> void for_each_child(F);
|
||||
|
||||
protected:
|
||||
explicit ParentNode(NodeType type)
|
||||
: Node(type)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Callback>
|
||||
inline void ParentNode::for_each_child(Callback callback) const
|
||||
{
|
||||
for (auto* node = first_child(); node; node = node->next_sibling())
|
||||
callback(*node);
|
||||
}
|
||||
|
||||
template<typename Callback>
|
||||
inline void ParentNode::for_each_child(Callback callback)
|
||||
{
|
||||
for (auto* node = first_child(); node; node = node->next_sibling())
|
||||
callback(*node);
|
||||
}
|
12
Libraries/LibHTML/DOM/Text.cpp
Normal file
12
Libraries/LibHTML/DOM/Text.cpp
Normal file
|
@ -0,0 +1,12 @@
|
|||
#include <LibHTML/DOM/Text.h>
|
||||
#include <LibHTML/Layout/LayoutText.h>
|
||||
|
||||
Text::Text(const String& data)
|
||||
: Node(NodeType::TEXT_NODE)
|
||||
, m_data(data)
|
||||
{
|
||||
}
|
||||
|
||||
Text::~Text()
|
||||
{
|
||||
}
|
15
Libraries/LibHTML/DOM/Text.h
Normal file
15
Libraries/LibHTML/DOM/Text.h
Normal file
|
@ -0,0 +1,15 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/AKString.h>
|
||||
#include <LibHTML/DOM/Node.h>
|
||||
|
||||
class Text final : public Node {
|
||||
public:
|
||||
explicit Text(const String&);
|
||||
virtual ~Text() override;
|
||||
|
||||
const String& data() const { return m_data; }
|
||||
|
||||
private:
|
||||
String m_data;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue