summaryrefslogtreecommitdiff
path: root/Libraries/LibHTML/Layout
diff options
context:
space:
mode:
Diffstat (limited to 'Libraries/LibHTML/Layout')
-rw-r--r--Libraries/LibHTML/Layout/LayoutBlock.cpp54
-rw-r--r--Libraries/LibHTML/Layout/LayoutBlock.h2
-rw-r--r--Libraries/LibHTML/Layout/LayoutDocument.cpp4
-rw-r--r--Libraries/LibHTML/Layout/LayoutDocument.h5
-rw-r--r--Libraries/LibHTML/Layout/LayoutInline.cpp4
-rw-r--r--Libraries/LibHTML/Layout/LayoutInline.h2
-rw-r--r--Libraries/LibHTML/Layout/LayoutNode.cpp5
-rw-r--r--Libraries/LibHTML/Layout/LayoutNode.h11
-rw-r--r--Libraries/LibHTML/Layout/LayoutText.cpp5
-rw-r--r--Libraries/LibHTML/Layout/LayoutText.h4
10 files changed, 42 insertions, 54 deletions
diff --git a/Libraries/LibHTML/Layout/LayoutBlock.cpp b/Libraries/LibHTML/Layout/LayoutBlock.cpp
index 72c6a36834..abbf5e7e25 100644
--- a/Libraries/LibHTML/Layout/LayoutBlock.cpp
+++ b/Libraries/LibHTML/Layout/LayoutBlock.cpp
@@ -1,9 +1,8 @@
-#include <LibHTML/CSS/StyledNode.h>
#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(const Node* node, StyleProperties&& style_properties)
+ : LayoutNode(node, move(style_properties))
{
}
@@ -14,7 +13,7 @@ LayoutBlock::~LayoutBlock()
LayoutNode& LayoutBlock::inline_wrapper()
{
if (!last_child() || !last_child()->is_block()) {
- append_child(adopt(*new LayoutBlock(nullptr, nullptr)));
+ append_child(adopt(*new LayoutBlock(nullptr, {})));
}
return *last_child();
}
@@ -42,21 +41,17 @@ void LayoutBlock::layout()
void LayoutBlock::compute_width()
{
- if (!styled_node()) {
- // I guess the size is "auto" in this case.
- return;
- }
+ auto& style_properties = this->style_properties();
- auto& styled_node = *this->styled_node();
auto auto_value = Length();
auto zero_value = Length(0, Length::Type::Absolute);
- auto width = styled_node.length_or_fallback("width", auto_value);
- auto margin_left = styled_node.length_or_fallback("margin-left", zero_value);
- auto margin_right = styled_node.length_or_fallback("margin-right", zero_value);
- auto border_left = styled_node.length_or_fallback("border-left", zero_value);
- auto border_right = styled_node.length_or_fallback("border-right", zero_value);
- auto padding_left = styled_node.length_or_fallback("padding-left", zero_value);
- auto padding_right = styled_node.length_or_fallback("padding-right", zero_value);
+ auto width = style_properties.length_or_fallback("width", auto_value);
+ auto margin_left = style_properties.length_or_fallback("margin-left", zero_value);
+ auto margin_right = style_properties.length_or_fallback("margin-right", zero_value);
+ auto border_left = style_properties.length_or_fallback("border-left", zero_value);
+ auto border_right = style_properties.length_or_fallback("border-right", zero_value);
+ auto padding_left = style_properties.length_or_fallback("padding-left", zero_value);
+ auto padding_right = style_properties.length_or_fallback("padding-right", zero_value);
dbg() << " Left: " << margin_left << "+" << border_left << "+" << padding_left;
dbg() << "Right: " << margin_right << "+" << border_right << "+" << padding_right;
@@ -116,32 +111,27 @@ void LayoutBlock::compute_width()
void LayoutBlock::compute_position()
{
- if (!styled_node()) {
- // I guess the size is "auto" in this case.
- return;
- }
+ auto& style_properties = this->style_properties();
- auto& styled_node = *this->styled_node();
auto auto_value = Length();
auto zero_value = Length(0, Length::Type::Absolute);
- auto width = styled_node.length_or_fallback("width", auto_value);
- style().margin().top = styled_node.length_or_fallback("margin-top", zero_value);
- style().margin().bottom = styled_node.length_or_fallback("margin-bottom", zero_value);
- style().border().top = styled_node.length_or_fallback("border-top", zero_value);
- style().border().bottom = styled_node.length_or_fallback("border-bottom", zero_value);
- style().padding().top = styled_node.length_or_fallback("padding-top", zero_value);
- style().padding().bottom = styled_node.length_or_fallback("padding-bottom", zero_value);
+ auto width = style_properties.length_or_fallback("width", auto_value);
+ style().margin().top = style_properties.length_or_fallback("margin-top", zero_value);
+ style().margin().bottom = style_properties.length_or_fallback("margin-bottom", zero_value);
+ style().border().top = style_properties.length_or_fallback("border-top", zero_value);
+ style().border().bottom = style_properties.length_or_fallback("border-bottom", zero_value);
+ style().padding().top = style_properties.length_or_fallback("padding-top", zero_value);
+ style().padding().bottom = style_properties.length_or_fallback("padding-bottom", zero_value);
rect().set_x(containing_block()->rect().x() + style().margin().left.to_px() + style().border().left.to_px() + style().padding().left.to_px());
rect().set_y(containing_block()->rect().y() + style().margin().top.to_px() + style().border().top.to_px() + style().padding().top.to_px());
}
void LayoutBlock::compute_height()
{
- if (!styled_node())
- return;
- auto& styled_node = *this->styled_node();
- auto height_property = styled_node.property("height");
+ auto& style_properties = this->style_properties();
+
+ auto height_property = style_properties.property("height");
if (!height_property.has_value())
return;
auto height_length = height_property.value()->to_length();
diff --git a/Libraries/LibHTML/Layout/LayoutBlock.h b/Libraries/LibHTML/Layout/LayoutBlock.h
index 7c75cb40e1..61b9de2a70 100644
--- a/Libraries/LibHTML/Layout/LayoutBlock.h
+++ b/Libraries/LibHTML/Layout/LayoutBlock.h
@@ -6,7 +6,7 @@ class Element;
class LayoutBlock : public LayoutNode {
public:
- LayoutBlock(const Node*, const StyledNode*);
+ LayoutBlock(const Node*, StyleProperties&&);
virtual ~LayoutBlock() override;
virtual const char* class_name() const override { return "LayoutBlock"; }
diff --git a/Libraries/LibHTML/Layout/LayoutDocument.cpp b/Libraries/LibHTML/Layout/LayoutDocument.cpp
index 1447cafda6..a734dca5b5 100644
--- a/Libraries/LibHTML/Layout/LayoutDocument.cpp
+++ b/Libraries/LibHTML/Layout/LayoutDocument.cpp
@@ -1,7 +1,7 @@
#include <LibHTML/Layout/LayoutDocument.h>
-LayoutDocument::LayoutDocument(const Document& document, const StyledNode& styled_node)
- : LayoutBlock(&document, &styled_node)
+LayoutDocument::LayoutDocument(const Document& document, StyleProperties&& style_properties)
+ : LayoutBlock(&document, move(style_properties))
{
}
diff --git a/Libraries/LibHTML/Layout/LayoutDocument.h b/Libraries/LibHTML/Layout/LayoutDocument.h
index 8b49a1ab8b..88acbb8e69 100644
--- a/Libraries/LibHTML/Layout/LayoutDocument.h
+++ b/Libraries/LibHTML/Layout/LayoutDocument.h
@@ -1,15 +1,16 @@
#pragma once
-#include <LibHTML/Layout/LayoutBlock.h>
#include <LibHTML/DOM/Document.h>
+#include <LibHTML/Layout/LayoutBlock.h>
class LayoutDocument final : public LayoutBlock {
public:
- LayoutDocument(const Document&, const StyledNode&);
+ LayoutDocument(const Document&, StyleProperties&&);
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:
};
diff --git a/Libraries/LibHTML/Layout/LayoutInline.cpp b/Libraries/LibHTML/Layout/LayoutInline.cpp
index a41b8d4f16..69f7474c14 100644
--- a/Libraries/LibHTML/Layout/LayoutInline.cpp
+++ b/Libraries/LibHTML/Layout/LayoutInline.cpp
@@ -1,8 +1,8 @@
#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(const Node& node, StyleProperties&& style_properties)
+ : LayoutNode(&node, move(style_properties))
{
}
diff --git a/Libraries/LibHTML/Layout/LayoutInline.h b/Libraries/LibHTML/Layout/LayoutInline.h
index b5b5fc16b1..2760581098 100644
--- a/Libraries/LibHTML/Layout/LayoutInline.h
+++ b/Libraries/LibHTML/Layout/LayoutInline.h
@@ -6,7 +6,7 @@ class Element;
class LayoutInline : public LayoutNode {
public:
- LayoutInline(const Node&, const StyledNode&);
+ LayoutInline(const Node&, StyleProperties&&);
virtual ~LayoutInline() override;
virtual const char* class_name() const override { return "LayoutInline"; }
diff --git a/Libraries/LibHTML/Layout/LayoutNode.cpp b/Libraries/LibHTML/Layout/LayoutNode.cpp
index f66ef64fff..0b7dc8bc68 100644
--- a/Libraries/LibHTML/Layout/LayoutNode.cpp
+++ b/Libraries/LibHTML/Layout/LayoutNode.cpp
@@ -1,10 +1,9 @@
#include <LibHTML/Layout/LayoutBlock.h>
#include <LibHTML/Layout/LayoutNode.h>
-#include <LibHTML/CSS/StyledNode.h>
-LayoutNode::LayoutNode(const Node* node, const StyledNode* styled_node)
+LayoutNode::LayoutNode(const Node* node, StyleProperties&& style_properties)
: m_node(node)
- , m_styled_node(styled_node)
+ , m_style_properties(style_properties)
{
}
diff --git a/Libraries/LibHTML/Layout/LayoutNode.h b/Libraries/LibHTML/Layout/LayoutNode.h
index 938fd6cd7b..a531922420 100644
--- a/Libraries/LibHTML/Layout/LayoutNode.h
+++ b/Libraries/LibHTML/Layout/LayoutNode.h
@@ -2,13 +2,13 @@
#include <AK/NonnullRefPtr.h>
#include <AK/Vector.h>
+#include <LibDraw/Rect.h>
+#include <LibHTML/CSS/StyleProperties.h>
#include <LibHTML/Layout/ComputedStyle.h>
#include <LibHTML/TreeNode.h>
-#include <LibDraw/Rect.h>
class Node;
class LayoutBlock;
-class StyledNode;
class LayoutNode : public TreeNode<LayoutNode> {
public:
@@ -49,16 +49,15 @@ public:
virtual LayoutNode& inline_wrapper() { return *this; }
- StyledNode* styled_node() { return m_styled_node; }
- const StyledNode* styled_node() const { return m_styled_node; }
+ const StyleProperties& style_properties() const { return m_style_properties; }
protected:
- explicit LayoutNode(const Node*, const StyledNode*);
+ explicit LayoutNode(const Node*, StyleProperties&&);
private:
const Node* m_node { nullptr };
- RefPtr<StyledNode> m_styled_node;
+ StyleProperties m_style_properties;
ComputedStyle m_style;
Rect m_rect;
};
diff --git a/Libraries/LibHTML/Layout/LayoutText.cpp b/Libraries/LibHTML/Layout/LayoutText.cpp
index aef9451762..a54d9e9344 100644
--- a/Libraries/LibHTML/Layout/LayoutText.cpp
+++ b/Libraries/LibHTML/Layout/LayoutText.cpp
@@ -1,8 +1,8 @@
#include <LibHTML/Layout/LayoutText.h>
#include <ctype.h>
-LayoutText::LayoutText(const Text& text, const StyledNode& styled_node)
- : LayoutNode(&text, &styled_node)
+LayoutText::LayoutText(const Text& text, StyleProperties&& style_properties)
+ : LayoutNode(&text, move(style_properties))
{
}
@@ -29,7 +29,6 @@ const String& LayoutText::text() const
void LayoutText::compute_runs()
{
-
}
void LayoutText::layout()
diff --git a/Libraries/LibHTML/Layout/LayoutText.h b/Libraries/LibHTML/Layout/LayoutText.h
index 5ad24fa839..ad1e556e91 100644
--- a/Libraries/LibHTML/Layout/LayoutText.h
+++ b/Libraries/LibHTML/Layout/LayoutText.h
@@ -1,11 +1,11 @@
#pragma once
-#include <LibHTML/Layout/LayoutNode.h>
#include <LibHTML/DOM/Text.h>
+#include <LibHTML/Layout/LayoutNode.h>
class LayoutText : public LayoutNode {
public:
- LayoutText(const Text&, const StyledNode&);
+ LayoutText(const Text&, StyleProperties&&);
virtual ~LayoutText() override;
const Text& node() const { return static_cast<const Text&>(*LayoutNode::node()); }