summaryrefslogtreecommitdiff
path: root/Libraries/LibHTML
diff options
context:
space:
mode:
authorSergey Bugaev <bugaevc@gmail.com>2019-09-21 15:32:17 +0300
committerAndreas Kling <awesomekling@gmail.com>2019-09-28 18:29:42 +0200
commitfd0aa5dd43bdf9b3184a891481157113496de4cb (patch)
tree6aa9442e2e68c78d794e6d93f8b7ac3a9e0c6e47 /Libraries/LibHTML
parenta9ebd676e5446f2d1da1c93c5dd4e2dc98f2b1ba (diff)
downloadserenity-fd0aa5dd43bdf9b3184a891481157113496de4cb.zip
LibHTML: Get rid of the style tree
We now create a layout tree directly from the DOM tree. This way we don't actually lose text nodes ^)
Diffstat (limited to 'Libraries/LibHTML')
-rw-r--r--Libraries/LibHTML/CSS/StyleProperties.cpp22
-rw-r--r--Libraries/LibHTML/CSS/StyleProperties.h23
-rw-r--r--Libraries/LibHTML/CSS/StyleResolver.cpp14
-rw-r--r--Libraries/LibHTML/CSS/StyleResolver.h8
-rw-r--r--Libraries/LibHTML/CSS/StyledNode.cpp25
-rw-r--r--Libraries/LibHTML/CSS/StyledNode.h78
-rw-r--r--Libraries/LibHTML/Dump.cpp34
-rw-r--r--Libraries/LibHTML/Dump.h2
-rw-r--r--Libraries/LibHTML/Frame.cpp77
-rw-r--r--Libraries/LibHTML/Frame.h5
-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
-rw-r--r--Libraries/LibHTML/Makefile.shared2
-rw-r--r--Libraries/LibHTML/test.cpp1
22 files changed, 126 insertions, 261 deletions
diff --git a/Libraries/LibHTML/CSS/StyleProperties.cpp b/Libraries/LibHTML/CSS/StyleProperties.cpp
new file mode 100644
index 0000000000..9cdf4af97c
--- /dev/null
+++ b/Libraries/LibHTML/CSS/StyleProperties.cpp
@@ -0,0 +1,22 @@
+#include <LibHTML/CSS/StyleProperties.h>
+
+void StyleProperties::set_property(const String& name, NonnullRefPtr<StyleValue> value)
+{
+ m_property_values.set(name, move(value));
+}
+
+Optional<NonnullRefPtr<StyleValue>> StyleProperties::property(const String& name) const
+{
+ auto it = m_property_values.find(name);
+ if (it == m_property_values.end())
+ return {};
+ return it->value;
+}
+
+Length StyleProperties::length_or_fallback(const StringView& property_name, const Length& fallback) const
+{
+ auto value = property(property_name);
+ if (!value.has_value())
+ return fallback;
+ return value.value()->to_length();
+}
diff --git a/Libraries/LibHTML/CSS/StyleProperties.h b/Libraries/LibHTML/CSS/StyleProperties.h
new file mode 100644
index 0000000000..d449363de5
--- /dev/null
+++ b/Libraries/LibHTML/CSS/StyleProperties.h
@@ -0,0 +1,23 @@
+#pragma once
+
+#include <AK/HashMap.h>
+#include <AK/NonnullRefPtr.h>
+#include <LibHTML/CSS/StyleValue.h>
+
+class StyleProperties {
+public:
+ template<typename Callback>
+ inline void for_each_property(Callback callback) const
+ {
+ for (auto& it : m_property_values)
+ callback(it.key, *it.value);
+ }
+
+ void set_property(const String& name, NonnullRefPtr<StyleValue> value);
+ Optional<NonnullRefPtr<StyleValue>> property(const String& name) const;
+
+ Length length_or_fallback(const StringView& property_name, const Length& fallback) const;
+
+private:
+ HashMap<String, NonnullRefPtr<StyleValue>> m_property_values;
+};
diff --git a/Libraries/LibHTML/CSS/StyleResolver.cpp b/Libraries/LibHTML/CSS/StyleResolver.cpp
index 88d693c374..81dd368c82 100644
--- a/Libraries/LibHTML/CSS/StyleResolver.cpp
+++ b/Libraries/LibHTML/CSS/StyleResolver.cpp
@@ -1,6 +1,5 @@
#include <LibHTML/CSS/StyleResolver.h>
#include <LibHTML/CSS/StyleSheet.h>
-#include <LibHTML/CSS/StyledNode.h>
#include <LibHTML/DOM/Document.h>
#include <LibHTML/DOM/Element.h>
#include <LibHTML/Dump.h>
@@ -53,19 +52,14 @@ NonnullRefPtrVector<StyleRule> StyleResolver::collect_matching_rules(const Eleme
return matching_rules;
}
-NonnullRefPtr<StyledNode> StyleResolver::create_styled_node(const Document& document)
+StyleProperties StyleResolver::resolve_style(const Element& element)
{
- return StyledNode::create(document);
-}
-
-NonnullRefPtr<StyledNode> StyleResolver::create_styled_node(const Element& element)
-{
- auto style = StyledNode::create(element);
+ StyleProperties style_properties;
auto matching_rules = collect_matching_rules(element);
for (auto& rule : matching_rules) {
for (auto& declaration : rule.declarations()) {
- style->set_property(declaration.property_name(), declaration.value());
+ style_properties.set_property(declaration.property_name(), declaration.value());
}
}
- return style;
+ return style_properties;
}
diff --git a/Libraries/LibHTML/CSS/StyleResolver.h b/Libraries/LibHTML/CSS/StyleResolver.h
index 2e093b687f..1b77e8f90d 100644
--- a/Libraries/LibHTML/CSS/StyleResolver.h
+++ b/Libraries/LibHTML/CSS/StyleResolver.h
@@ -1,14 +1,14 @@
#pragma once
-#include <AK/OwnPtr.h>
#include <AK/NonnullRefPtrVector.h>
+#include <AK/OwnPtr.h>
+#include <LibHTML/CSS/StyleProperties.h>
class Document;
class Element;
class ParentNode;
class StyleRule;
class StyleSheet;
-class StyledNode;
class StyleResolver {
public:
@@ -18,12 +18,10 @@ public:
Document& document() { return m_document; }
const Document& document() const { return m_document; }
- NonnullRefPtr<StyledNode> create_styled_node(const Element&);
- NonnullRefPtr<StyledNode> create_styled_node(const Document&);
+ StyleProperties resolve_style(const Element&);
NonnullRefPtrVector<StyleRule> collect_matching_rules(const Element&) const;
-
private:
Document& m_document;
};
diff --git a/Libraries/LibHTML/CSS/StyledNode.cpp b/Libraries/LibHTML/CSS/StyledNode.cpp
deleted file mode 100644
index 57745b9858..0000000000
--- a/Libraries/LibHTML/CSS/StyledNode.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-#include <LibHTML/CSS/StyledNode.h>
-
-StyledNode::StyledNode(const Node* node)
- : m_node(node)
-{
-}
-
-StyledNode::~StyledNode()
-{
-}
-
-Display StyledNode::display() const
-{
- auto it = m_property_values.find("display");
- if (it == m_property_values.end())
- return Display::Inline;
- auto value = it->value->to_string();
- if (value == "none")
- return Display::None;
- if (value == "block")
- return Display::Block;
- if (value == "inline")
- return Display::Inline;
- ASSERT_NOT_REACHED();
-}
diff --git a/Libraries/LibHTML/CSS/StyledNode.h b/Libraries/LibHTML/CSS/StyledNode.h
deleted file mode 100644
index 1681b6c9c7..0000000000
--- a/Libraries/LibHTML/CSS/StyledNode.h
+++ /dev/null
@@ -1,78 +0,0 @@
-#pragma once
-
-#include <AK/String.h>
-#include <AK/HashMap.h>
-#include <AK/NonnullRefPtr.h>
-#include <AK/Optional.h>
-#include <LibHTML/CSS/StyleValue.h>
-#include <LibHTML/TreeNode.h>
-
-class Node;
-
-enum class Display {
- None,
- Block,
- Inline,
-};
-
-class StyledNode : public TreeNode<StyledNode> {
-public:
- static NonnullRefPtr<StyledNode> create(const Node& node)
- {
- return adopt(*new StyledNode(&node));
- }
- ~StyledNode();
-
- 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);
- }
-
- template<typename Callback>
- inline void for_each_property(Callback callback) const
- {
- for (auto& it : m_property_values)
- callback(it.key, *it.value);
- }
-
- void set_property(const String& name, NonnullRefPtr<StyleValue> value)
- {
- m_property_values.set(name, move(value));
- }
-
- Optional<NonnullRefPtr<StyleValue>> property(const String& name) const
- {
- auto it = m_property_values.find(name);
- if (it == m_property_values.end())
- return {};
- return it->value;
- }
-
- Display display() const;
-
- Length length_or_fallback(const StringView& property_name, const Length& fallback)
- {
- auto value = property(property_name);
- if (!value.has_value())
- return fallback;
- return value.value()->to_length();
- }
-
-protected:
- explicit StyledNode(const Node*);
-
-private:
- const Node* m_node { nullptr };
- HashMap<String, NonnullRefPtr<StyleValue>> m_property_values;
-};
diff --git a/Libraries/LibHTML/Dump.cpp b/Libraries/LibHTML/Dump.cpp
index 9f14f7fde5..928cbc0c94 100644
--- a/Libraries/LibHTML/Dump.cpp
+++ b/Libraries/LibHTML/Dump.cpp
@@ -1,5 +1,4 @@
#include <LibHTML/CSS/StyleSheet.h>
-#include <LibHTML/CSS/StyledNode.h>
#include <LibHTML/DOM/Document.h>
#include <LibHTML/DOM/Element.h>
#include <LibHTML/DOM/Text.h>
@@ -37,7 +36,7 @@ void dump_tree(const LayoutNode& layout_node)
{
static int indent = 0;
for (int i = 0; i < indent; ++i)
- printf(" ");
+ printf(" ");
String tag_name;
if (layout_node.is_anonymous())
@@ -83,40 +82,15 @@ void dump_tree(const LayoutNode& layout_node)
printf(" \"%s\"", static_cast<const LayoutText&>(layout_node).text().characters());
printf("\n");
- ++indent;
- layout_node.for_each_child([](auto& child) {
- dump_tree(child);
- });
- --indent;
-}
-void dump_tree(const StyledNode& styled_node)
-{
- static int indent = 0;
- for (int i = 0; i < indent; ++i)
- printf(" ");
-
- String tag_name;
- auto& node = *styled_node.node();
- if (node.is_text())
- tag_name = "#text";
- else if (node.is_document())
- tag_name = "#document";
- else if (node.is_element())
- tag_name = static_cast<const Element&>(node).tag_name();
- else
- tag_name = "???";
-
- printf("%s", tag_name.characters());
- printf("\n");
-
- styled_node.for_each_property([&](auto& key, auto& value) {
+ layout_node.style_properties().for_each_property([&](auto& key, auto& value) {
for (int i = 0; i < indent; ++i)
printf(" ");
printf(" (%s: %s)\n", key.characters(), value.to_string().characters());
});
+
++indent;
- styled_node.for_each_child([](auto& child) {
+ layout_node.for_each_child([](auto& child) {
dump_tree(child);
});
--indent;
diff --git a/Libraries/LibHTML/Dump.h b/Libraries/LibHTML/Dump.h
index c7c0953e6d..546e556ba7 100644
--- a/Libraries/LibHTML/Dump.h
+++ b/Libraries/LibHTML/Dump.h
@@ -4,10 +4,8 @@ class Node;
class LayoutNode;
class StyleRule;
class StyleSheet;
-class StyledNode;
void dump_tree(const Node&);
-void dump_tree(const StyledNode&);
void dump_tree(const LayoutNode&);
void dump_sheet(const StyleSheet&);
void dump_rule(const StyleRule&);
diff --git a/Libraries/LibHTML/Frame.cpp b/Libraries/LibHTML/Frame.cpp
index f4d26da501..78005562b3 100644
--- a/Libraries/LibHTML/Frame.cpp
+++ b/Libraries/LibHTML/Frame.cpp
@@ -1,6 +1,5 @@
#include <AK/Function.h>
#include <LibHTML/CSS/StyleResolver.h>
-#include <LibHTML/CSS/StyledNode.h>
#include <LibHTML/DOM/Element.h>
#include <LibHTML/Dump.h>
#include <LibHTML/Frame.h>
@@ -23,71 +22,46 @@ void Frame::set_document(Document* document)
m_document = document;
}
-RefPtr<StyledNode> Frame::generate_style_tree()
+RefPtr<LayoutNode> Frame::generate_layout_tree()
{
- if (!m_document)
- return nullptr;
+ auto resolver = m_document->style_resolver();
+ auto create_layout_node = [&](const Node& node) -> RefPtr<LayoutNode> {
+ if (node.is_document())
+ return adopt(*new LayoutDocument(static_cast<const Document&>(node), {}));
- auto& resolver = m_document->style_resolver();
- Function<RefPtr<StyledNode>(const Node&, StyledNode*)> resolve_style = [&](const Node& node, StyledNode* parent_styled_node) -> RefPtr<StyledNode> {
- RefPtr<StyledNode> styled_node;
- if (node.is_element())
- styled_node = resolver.create_styled_node(static_cast<const Element&>(node));
- else if (node.is_document())
- styled_node = resolver.create_styled_node(static_cast<const Document&>(node));
- if (!styled_node)
- return nullptr;
- if (parent_styled_node)
- parent_styled_node->append_child(*styled_node);
- static_cast<const ParentNode&>(node).for_each_child([&](const Node& child) {
- if (!child.is_element())
- return;
- auto styled_child_node = resolve_style(static_cast<const Element&>(child), styled_node.ptr());
- printf("Created StyledNode{%p} for Element{%p}\n", styled_child_node.ptr(), &node);
- });
- return styled_node;
- };
- auto styled_root = resolve_style(*m_document, nullptr);
- dump_tree(*styled_root);
- return styled_root;
-}
+ auto style_properties = resolver.resolve_style(static_cast<const Element&>(node));
+ auto display_property = style_properties.property("display");
+ String display = display_property.has_value() ? display_property.release_value()->to_string() : "inline";
-RefPtr<LayoutNode> Frame::generate_layout_tree(const StyledNode& styled_root)
-{
- auto create_layout_node = [](const StyledNode& styled_node) -> RefPtr<LayoutNode> {
- if (styled_node.node() && styled_node.node()->is_document())
- return adopt(*new LayoutDocument(static_cast<const Document&>(*styled_node.node()), styled_node));
- switch (styled_node.display()) {
- case Display::None:
+ if (display == "none")
return nullptr;
- case Display::Block:
- return adopt(*new LayoutBlock(styled_node.node(), &styled_node));
- case Display::Inline:
- return adopt(*new LayoutInline(*styled_node.node(), styled_node));
- default:
- ASSERT_NOT_REACHED();
- }
+ if (display == "block")
+ return adopt(*new LayoutBlock(&node, move(style_properties)));
+ if (display == "inline")
+ return adopt(*new LayoutInline(node, move(style_properties)));
+
+ ASSERT_NOT_REACHED();
};
- Function<RefPtr<LayoutNode>(const StyledNode&)> build_layout_tree;
- build_layout_tree = [&](const StyledNode& styled_node) -> RefPtr<LayoutNode> {
- auto layout_node = create_layout_node(styled_node);
+ Function<RefPtr<LayoutNode>(const Node&)> build_layout_tree;
+ build_layout_tree = [&](const Node& node) -> RefPtr<LayoutNode> {
+ auto layout_node = create_layout_node(node);
if (!layout_node)
return nullptr;
- if (!styled_node.has_children())
+ if (!node.has_children())
return layout_node;
- for (auto* styled_child = styled_node.first_child(); styled_child; styled_child = styled_child->next_sibling()) {
- auto layout_child = build_layout_tree(*styled_child);
+ static_cast<const ParentNode&>(node).for_each_child([&](const Node& child) {
+ auto layout_child = build_layout_tree(child);
if (!layout_child)
- continue;
+ return;
if (layout_child->is_inline())
layout_node->inline_wrapper().append_child(*layout_child);
else
layout_node->append_child(*layout_child);
- }
+ });
return layout_node;
};
- return build_layout_tree(styled_root);
+ return build_layout_tree(*m_document);
}
void Frame::layout()
@@ -95,8 +69,7 @@ void Frame::layout()
if (!m_document)
return;
- auto styled_root = generate_style_tree();
- auto layout_root = generate_layout_tree(*styled_root);
+ auto layout_root = generate_layout_tree();
layout_root->style().size().set_width(m_size.width());
diff --git a/Libraries/LibHTML/Frame.h b/Libraries/LibHTML/Frame.h
index b58021fa5c..31b1bb6c9d 100644
--- a/Libraries/LibHTML/Frame.h
+++ b/Libraries/LibHTML/Frame.h
@@ -1,7 +1,7 @@
#pragma once
-#include <LibHTML/DOM/Document.h>
#include <LibDraw/Size.h>
+#include <LibHTML/DOM/Document.h>
class Frame {
public:
@@ -16,8 +16,7 @@ public:
void layout();
private:
- RefPtr<StyledNode> generate_style_tree();
- RefPtr<LayoutNode> generate_layout_tree(const StyledNode&);
+ RefPtr<LayoutNode> generate_layout_tree();
RefPtr<Document> m_document;
Size m_size;
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()); }
diff --git a/Libraries/LibHTML/Makefile.shared b/Libraries/LibHTML/Makefile.shared
index e93ccf54c7..00c045ef3e 100644
--- a/Libraries/LibHTML/Makefile.shared
+++ b/Libraries/LibHTML/Makefile.shared
@@ -9,7 +9,7 @@ LIBHTML_OBJS = \
CSS/StyleRule.o \
CSS/StyleDeclaration.o \
CSS/StyleValue.o \
- CSS/StyledNode.o \
+ CSS/StyleProperties.o \
CSS/StyleResolver.o \
CSS/DefaultStyleSheetSource.o \
Parser/HTMLParser.o \
diff --git a/Libraries/LibHTML/test.cpp b/Libraries/LibHTML/test.cpp
index f10f9b9679..6e47918e91 100644
--- a/Libraries/LibHTML/test.cpp
+++ b/Libraries/LibHTML/test.cpp
@@ -1,6 +1,5 @@
#include <LibCore/CFile.h>
#include <LibHTML/CSS/StyleResolver.h>
-#include <LibHTML/CSS/StyledNode.h>
#include <LibHTML/DOM/Element.h>
#include <LibHTML/Dump.h>
#include <LibHTML/Frame.h>