mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:37:35 +00:00
LibHTML: Create some subdirectories.
This commit is contained in:
parent
0522a8f71c
commit
1f51c2b7da
25 changed files with 49 additions and 50 deletions
11
LibHTML/Layout/LayoutBlock.cpp
Normal file
11
LibHTML/Layout/LayoutBlock.cpp
Normal file
|
@ -0,0 +1,11 @@
|
|||
#include <LibHTML/DOM/Element.h>
|
||||
#include <LibHTML/Layout/LayoutBlock.h>
|
||||
|
||||
LayoutBlock::LayoutBlock(Element& element)
|
||||
: LayoutNode(&element)
|
||||
{
|
||||
}
|
||||
|
||||
LayoutBlock::~LayoutBlock()
|
||||
{
|
||||
}
|
15
LibHTML/Layout/LayoutBlock.h
Normal file
15
LibHTML/Layout/LayoutBlock.h
Normal file
|
@ -0,0 +1,15 @@
|
|||
#pragma once
|
||||
|
||||
#include <LibHTML/Layout/LayoutNode.h>
|
||||
|
||||
class Element;
|
||||
|
||||
class LayoutBlock : public LayoutNode {
|
||||
public:
|
||||
explicit LayoutBlock(Element&);
|
||||
virtual ~LayoutBlock() override;
|
||||
|
||||
virtual const char* class_name() const override { return "LayoutBlock"; }
|
||||
|
||||
private:
|
||||
};
|
10
LibHTML/Layout/LayoutDocument.cpp
Normal file
10
LibHTML/Layout/LayoutDocument.cpp
Normal file
|
@ -0,0 +1,10 @@
|
|||
#include <LibHTML/Layout/LayoutDocument.h>
|
||||
|
||||
LayoutDocument::LayoutDocument(const Document& document)
|
||||
: LayoutNode(&document)
|
||||
{
|
||||
}
|
||||
|
||||
LayoutDocument::~LayoutDocument()
|
||||
{
|
||||
}
|
16
LibHTML/Layout/LayoutDocument.h
Normal file
16
LibHTML/Layout/LayoutDocument.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
#pragma once
|
||||
|
||||
#include <LibHTML/Layout/LayoutNode.h>
|
||||
#include <LibHTML/DOM/Document.h>
|
||||
|
||||
class LayoutDocument : public LayoutNode {
|
||||
public:
|
||||
explicit LayoutDocument(const Document&);
|
||||
virtual ~LayoutDocument() override;
|
||||
|
||||
const Document& node() const { return static_cast<const Document&>(*LayoutNode::node()); }
|
||||
|
||||
virtual const char* class_name() const override { return "LayoutDocument"; }
|
||||
|
||||
private:
|
||||
};
|
11
LibHTML/Layout/LayoutInline.cpp
Normal file
11
LibHTML/Layout/LayoutInline.cpp
Normal file
|
@ -0,0 +1,11 @@
|
|||
#include <LibHTML/DOM/Element.h>
|
||||
#include <LibHTML/Layout/LayoutInline.h>
|
||||
|
||||
LayoutInline::LayoutInline(Element& element)
|
||||
: LayoutNode(&element)
|
||||
{
|
||||
}
|
||||
|
||||
LayoutInline::~LayoutInline()
|
||||
{
|
||||
}
|
15
LibHTML/Layout/LayoutInline.h
Normal file
15
LibHTML/Layout/LayoutInline.h
Normal file
|
@ -0,0 +1,15 @@
|
|||
#pragma once
|
||||
|
||||
#include <LibHTML/Layout/LayoutNode.h>
|
||||
|
||||
class Element;
|
||||
|
||||
class LayoutInline : public LayoutNode {
|
||||
public:
|
||||
explicit LayoutInline(Element&);
|
||||
virtual ~LayoutInline() override;
|
||||
|
||||
virtual const char* class_name() const override { return "LayoutInline"; }
|
||||
|
||||
private:
|
||||
};
|
33
LibHTML/Layout/LayoutNode.cpp
Normal file
33
LibHTML/Layout/LayoutNode.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
#include <LibHTML/Layout/LayoutNode.h>
|
||||
|
||||
LayoutNode::LayoutNode(const Node* node)
|
||||
: m_node(node)
|
||||
{
|
||||
}
|
||||
|
||||
LayoutNode::~LayoutNode()
|
||||
{
|
||||
}
|
||||
|
||||
void LayoutNode::retain()
|
||||
{
|
||||
ASSERT(m_retain_count);
|
||||
++m_retain_count;
|
||||
}
|
||||
|
||||
void LayoutNode::release()
|
||||
{
|
||||
ASSERT(m_retain_count);
|
||||
if (!--m_retain_count)
|
||||
delete this;
|
||||
}
|
||||
|
||||
void LayoutNode::append_child(Retained<LayoutNode> node)
|
||||
{
|
||||
if (m_last_child)
|
||||
m_last_child->set_next_sibling(node.ptr());
|
||||
node->m_parent_node = this;
|
||||
m_last_child = &node.leak_ref();
|
||||
if (!m_first_child)
|
||||
m_first_child = m_last_child;
|
||||
}
|
54
LibHTML/Layout/LayoutNode.h
Normal file
54
LibHTML/Layout/LayoutNode.h
Normal file
|
@ -0,0 +1,54 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Retained.h>
|
||||
#include <AK/Vector.h>
|
||||
|
||||
class Node;
|
||||
|
||||
class LayoutNode {
|
||||
public:
|
||||
virtual ~LayoutNode();
|
||||
|
||||
void retain();
|
||||
void release();
|
||||
int retain_count() const { return m_retain_count; }
|
||||
|
||||
const Node* node() const { return m_node; }
|
||||
|
||||
LayoutNode* next_sibling() { return m_next_sibling; }
|
||||
LayoutNode* previous_sibling() { return m_previous_sibling; }
|
||||
LayoutNode* first_child() { return m_first_child; }
|
||||
LayoutNode* last_child() { return m_last_child; }
|
||||
const LayoutNode* next_sibling() const { return m_next_sibling; }
|
||||
const LayoutNode* previous_sibling() const { return m_previous_sibling; }
|
||||
const LayoutNode* first_child() const { return m_first_child; }
|
||||
const LayoutNode* last_child() const { return m_last_child; }
|
||||
|
||||
void append_child(Retained<LayoutNode>);
|
||||
|
||||
void set_next_sibling(LayoutNode* node) { m_next_sibling = node; }
|
||||
void set_previous_sibling(LayoutNode* node) { m_previous_sibling = node; }
|
||||
|
||||
template<typename Callback>
|
||||
inline void for_each_child(Callback callback) const
|
||||
{
|
||||
for (auto* node = first_child(); node; node = node->next_sibling())
|
||||
callback(*node);
|
||||
}
|
||||
|
||||
virtual const char* class_name() const { return "LayoutNode"; }
|
||||
virtual bool is_text() const { return false; }
|
||||
|
||||
protected:
|
||||
explicit LayoutNode(const Node*);
|
||||
|
||||
private:
|
||||
int m_retain_count { 1 };
|
||||
const Node* m_node { nullptr };
|
||||
LayoutNode* m_parent_node { nullptr };
|
||||
LayoutNode* m_first_child { nullptr };
|
||||
LayoutNode* m_last_child { nullptr };
|
||||
LayoutNode* m_next_sibling { nullptr };
|
||||
LayoutNode* m_previous_sibling { nullptr };
|
||||
};
|
||||
|
28
LibHTML/Layout/LayoutText.cpp
Normal file
28
LibHTML/Layout/LayoutText.cpp
Normal file
|
@ -0,0 +1,28 @@
|
|||
#include <LibHTML/Layout/LayoutText.h>
|
||||
#include <ctype.h>
|
||||
|
||||
LayoutText::LayoutText(const Text& text)
|
||||
: LayoutNode(&text)
|
||||
{
|
||||
}
|
||||
|
||||
LayoutText::~LayoutText()
|
||||
{
|
||||
}
|
||||
|
||||
static bool is_all_whitespace(const String& string)
|
||||
{
|
||||
for (int i = 0; i < string.length(); ++i) {
|
||||
if (!isspace(string[i]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const String& LayoutText::text() const
|
||||
{
|
||||
static String one_space = " ";
|
||||
if (is_all_whitespace(node().data()))
|
||||
return one_space;
|
||||
return node().data();
|
||||
}
|
19
LibHTML/Layout/LayoutText.h
Normal file
19
LibHTML/Layout/LayoutText.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
#pragma once
|
||||
|
||||
#include <LibHTML/Layout/LayoutNode.h>
|
||||
#include <LibHTML/DOM/Text.h>
|
||||
|
||||
class LayoutText : public LayoutNode {
|
||||
public:
|
||||
explicit LayoutText(const Text&);
|
||||
virtual ~LayoutText() override;
|
||||
|
||||
const Text& node() const { return static_cast<const Text&>(*LayoutNode::node()); }
|
||||
|
||||
const String& text() const;
|
||||
|
||||
virtual const char* class_name() const override { return "LayoutText"; }
|
||||
virtual bool is_text() const final { return true; }
|
||||
|
||||
private:
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue