mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 03:17:35 +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
9
Libraries/LibHTML/Layout/ComputedStyle.cpp
Normal file
9
Libraries/LibHTML/Layout/ComputedStyle.cpp
Normal file
|
@ -0,0 +1,9 @@
|
|||
#include <LibHTML/Layout/ComputedStyle.h>
|
||||
|
||||
ComputedStyle::ComputedStyle()
|
||||
{
|
||||
}
|
||||
|
||||
ComputedStyle::~ComputedStyle()
|
||||
{
|
||||
}
|
47
Libraries/LibHTML/Layout/ComputedStyle.h
Normal file
47
Libraries/LibHTML/Layout/ComputedStyle.h
Normal file
|
@ -0,0 +1,47 @@
|
|||
#pragma once
|
||||
|
||||
#include <LibHTML/CSS/LengthBox.h>
|
||||
#include <SharedGraphics/Color.h>
|
||||
#include <SharedGraphics/Size.h>
|
||||
|
||||
enum FontStyle {
|
||||
Normal,
|
||||
Bold,
|
||||
};
|
||||
|
||||
class ComputedStyle {
|
||||
public:
|
||||
ComputedStyle();
|
||||
~ComputedStyle();
|
||||
|
||||
Color text_color() const { return m_text_color; }
|
||||
Color background_color() const { return m_background_color; }
|
||||
|
||||
LengthBox& offset() { return m_offset; }
|
||||
LengthBox& margin() { return m_margin; }
|
||||
LengthBox& padding() { return m_padding; }
|
||||
LengthBox& border() { return m_border; }
|
||||
|
||||
const LengthBox& offset() const { return m_offset; }
|
||||
const LengthBox& margin() const { return m_margin; }
|
||||
const LengthBox& padding() const { return m_padding; }
|
||||
const LengthBox& border() const { return m_border; }
|
||||
|
||||
FontStyle font_style() const { return m_font_style; }
|
||||
|
||||
const Size& size() const { return m_size; }
|
||||
Size& size() { return m_size; }
|
||||
|
||||
private:
|
||||
Color m_text_color;
|
||||
Color m_background_color;
|
||||
|
||||
LengthBox m_offset;
|
||||
LengthBox m_margin;
|
||||
LengthBox m_padding;
|
||||
LengthBox m_border;
|
||||
|
||||
Size m_size;
|
||||
|
||||
FontStyle m_font_style { FontStyle::Normal };
|
||||
};
|
28
Libraries/LibHTML/Layout/LayoutBlock.cpp
Normal file
28
Libraries/LibHTML/Layout/LayoutBlock.cpp
Normal file
|
@ -0,0 +1,28 @@
|
|||
#include <LibHTML/DOM/Element.h>
|
||||
#include <LibHTML/Layout/LayoutBlock.h>
|
||||
|
||||
LayoutBlock::LayoutBlock(const Node& node, const StyledNode& styled_node)
|
||||
: LayoutNode(&node, styled_node)
|
||||
{
|
||||
}
|
||||
|
||||
LayoutBlock::~LayoutBlock()
|
||||
{
|
||||
}
|
||||
|
||||
void LayoutBlock::layout()
|
||||
{
|
||||
compute_width();
|
||||
|
||||
LayoutNode::layout();
|
||||
|
||||
compute_height();
|
||||
}
|
||||
|
||||
void LayoutBlock::compute_width()
|
||||
{
|
||||
}
|
||||
|
||||
void LayoutBlock::compute_height()
|
||||
{
|
||||
}
|
21
Libraries/LibHTML/Layout/LayoutBlock.h
Normal file
21
Libraries/LibHTML/Layout/LayoutBlock.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
#pragma once
|
||||
|
||||
#include <LibHTML/Layout/LayoutNode.h>
|
||||
|
||||
class Element;
|
||||
|
||||
class LayoutBlock : public LayoutNode {
|
||||
public:
|
||||
LayoutBlock(const Node&, const StyledNode&);
|
||||
virtual ~LayoutBlock() override;
|
||||
|
||||
virtual const char* class_name() const override { return "LayoutBlock"; }
|
||||
|
||||
virtual void layout() override;
|
||||
|
||||
private:
|
||||
virtual bool is_block() const override { return true; }
|
||||
|
||||
void compute_width();
|
||||
void compute_height();
|
||||
};
|
16
Libraries/LibHTML/Layout/LayoutDocument.cpp
Normal file
16
Libraries/LibHTML/Layout/LayoutDocument.cpp
Normal file
|
@ -0,0 +1,16 @@
|
|||
#include <LibHTML/Layout/LayoutDocument.h>
|
||||
|
||||
LayoutDocument::LayoutDocument(const Document& document, const StyledNode& styled_node)
|
||||
: LayoutBlock(document, styled_node)
|
||||
{
|
||||
}
|
||||
|
||||
LayoutDocument::~LayoutDocument()
|
||||
{
|
||||
}
|
||||
|
||||
void LayoutDocument::layout()
|
||||
{
|
||||
rect().set_width(style().size().width());
|
||||
LayoutNode::layout();
|
||||
}
|
15
Libraries/LibHTML/Layout/LayoutDocument.h
Normal file
15
Libraries/LibHTML/Layout/LayoutDocument.h
Normal file
|
@ -0,0 +1,15 @@
|
|||
#pragma once
|
||||
|
||||
#include <LibHTML/Layout/LayoutBlock.h>
|
||||
#include <LibHTML/DOM/Document.h>
|
||||
|
||||
class LayoutDocument final : public LayoutBlock {
|
||||
public:
|
||||
LayoutDocument(const Document&, const StyledNode&);
|
||||
virtual ~LayoutDocument() override;
|
||||
|
||||
const Document& node() const { return static_cast<const Document&>(*LayoutNode::node()); }
|
||||
virtual const char* class_name() const override { return "LayoutDocument"; }
|
||||
virtual void layout() override;
|
||||
private:
|
||||
};
|
11
Libraries/LibHTML/Layout/LayoutInline.cpp
Normal file
11
Libraries/LibHTML/Layout/LayoutInline.cpp
Normal file
|
@ -0,0 +1,11 @@
|
|||
#include <LibHTML/DOM/Element.h>
|
||||
#include <LibHTML/Layout/LayoutInline.h>
|
||||
|
||||
LayoutInline::LayoutInline(const Node& node, const StyledNode& styled_node)
|
||||
: LayoutNode(&node, styled_node)
|
||||
{
|
||||
}
|
||||
|
||||
LayoutInline::~LayoutInline()
|
||||
{
|
||||
}
|
15
Libraries/LibHTML/Layout/LayoutInline.h
Normal file
15
Libraries/LibHTML/Layout/LayoutInline.h
Normal file
|
@ -0,0 +1,15 @@
|
|||
#pragma once
|
||||
|
||||
#include <LibHTML/Layout/LayoutNode.h>
|
||||
|
||||
class Element;
|
||||
|
||||
class LayoutInline : public LayoutNode {
|
||||
public:
|
||||
LayoutInline(const Node&, const StyledNode&);
|
||||
virtual ~LayoutInline() override;
|
||||
|
||||
virtual const char* class_name() const override { return "LayoutInline"; }
|
||||
|
||||
private:
|
||||
};
|
29
Libraries/LibHTML/Layout/LayoutNode.cpp
Normal file
29
Libraries/LibHTML/Layout/LayoutNode.cpp
Normal file
|
@ -0,0 +1,29 @@
|
|||
#include <LibHTML/Layout/LayoutBlock.h>
|
||||
#include <LibHTML/Layout/LayoutNode.h>
|
||||
#include <LibHTML/CSS/StyledNode.h>
|
||||
|
||||
LayoutNode::LayoutNode(const Node* node, const StyledNode& styled_node)
|
||||
: m_node(node)
|
||||
, m_styled_node(styled_node)
|
||||
{
|
||||
}
|
||||
|
||||
LayoutNode::~LayoutNode()
|
||||
{
|
||||
}
|
||||
|
||||
void LayoutNode::layout()
|
||||
{
|
||||
for_each_child([](auto& child) {
|
||||
child.layout();
|
||||
});
|
||||
}
|
||||
|
||||
const LayoutBlock* LayoutNode::containing_block() const
|
||||
{
|
||||
for (auto* ancestor = parent(); ancestor; ancestor = ancestor->parent()) {
|
||||
if (ancestor->is_block())
|
||||
return static_cast<const LayoutBlock*>(ancestor);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
58
Libraries/LibHTML/Layout/LayoutNode.h
Normal file
58
Libraries/LibHTML/Layout/LayoutNode.h
Normal file
|
@ -0,0 +1,58 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/NonnullRefPtr.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibHTML/Layout/ComputedStyle.h>
|
||||
#include <LibHTML/TreeNode.h>
|
||||
#include <SharedGraphics/Rect.h>
|
||||
|
||||
class Node;
|
||||
class LayoutBlock;
|
||||
class StyledNode;
|
||||
|
||||
class LayoutNode : public TreeNode<LayoutNode> {
|
||||
public:
|
||||
virtual ~LayoutNode();
|
||||
|
||||
const Rect& rect() const { return m_rect; }
|
||||
Rect& rect() { return m_rect; }
|
||||
void set_rect(const Rect& rect) { m_rect = rect; }
|
||||
|
||||
ComputedStyle& style() { return m_style; }
|
||||
const ComputedStyle& style() const { return m_style; }
|
||||
|
||||
bool is_anonymous() const { return !m_node; }
|
||||
const Node* node() const { return m_node; }
|
||||
|
||||
template<typename Callback>
|
||||
inline void for_each_child(Callback callback) const
|
||||
{
|
||||
for (auto* node = first_child(); node; node = node->next_sibling())
|
||||
callback(*node);
|
||||
}
|
||||
|
||||
template<typename Callback>
|
||||
inline void for_each_child(Callback callback)
|
||||
{
|
||||
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; }
|
||||
virtual bool is_block() const { return false; }
|
||||
|
||||
virtual void layout();
|
||||
|
||||
const LayoutBlock* containing_block() const;
|
||||
|
||||
protected:
|
||||
explicit LayoutNode(const Node*, const StyledNode&);
|
||||
|
||||
private:
|
||||
const Node* m_node { nullptr };
|
||||
NonnullRefPtr<StyledNode> m_styled_node;
|
||||
|
||||
ComputedStyle m_style;
|
||||
Rect m_rect;
|
||||
};
|
39
Libraries/LibHTML/Layout/LayoutText.cpp
Normal file
39
Libraries/LibHTML/Layout/LayoutText.cpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
#include <LibHTML/Layout/LayoutText.h>
|
||||
#include <ctype.h>
|
||||
|
||||
LayoutText::LayoutText(const Text& text, const StyledNode& styled_node)
|
||||
: LayoutNode(&text, styled_node)
|
||||
{
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
void LayoutText::compute_runs()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void LayoutText::layout()
|
||||
{
|
||||
ASSERT(!has_children());
|
||||
compute_runs();
|
||||
}
|
30
Libraries/LibHTML/Layout/LayoutText.h
Normal file
30
Libraries/LibHTML/Layout/LayoutText.h
Normal file
|
@ -0,0 +1,30 @@
|
|||
#pragma once
|
||||
|
||||
#include <LibHTML/Layout/LayoutNode.h>
|
||||
#include <LibHTML/DOM/Text.h>
|
||||
|
||||
class LayoutText : public LayoutNode {
|
||||
public:
|
||||
LayoutText(const Text&, const StyledNode&);
|
||||
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; }
|
||||
virtual void layout() override;
|
||||
|
||||
struct Run {
|
||||
Point pos;
|
||||
String text;
|
||||
};
|
||||
|
||||
const Vector<Run>& runs() const { return m_runs; }
|
||||
|
||||
private:
|
||||
void compute_runs();
|
||||
|
||||
Vector<Run> m_runs;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue