summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-07-08 17:42:23 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-07-08 17:42:23 +0200
commitfc127eb7696f115cb48e9bc2f2825c0d4283eb92 (patch)
treed7264f5a211b601650665c46cad5e8715d223449 /Libraries
parent2caec95d3064fd1304fe63ace64f6557204bcc13 (diff)
downloadserenity-fc127eb7696f115cb48e9bc2f2825c0d4283eb92.zip
LibHTML: Create anonymous blocks around inline children of blocks.
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibHTML/Frame.cpp18
-rw-r--r--Libraries/LibHTML/Layout/LayoutBlock.cpp12
-rw-r--r--Libraries/LibHTML/Layout/LayoutBlock.h4
-rw-r--r--Libraries/LibHTML/Layout/LayoutDocument.cpp2
-rw-r--r--Libraries/LibHTML/Layout/LayoutInline.cpp2
-rw-r--r--Libraries/LibHTML/Layout/LayoutInline.h1
-rw-r--r--Libraries/LibHTML/Layout/LayoutNode.cpp2
-rw-r--r--Libraries/LibHTML/Layout/LayoutNode.h7
-rw-r--r--Libraries/LibHTML/Layout/LayoutText.cpp2
9 files changed, 33 insertions, 17 deletions
diff --git a/Libraries/LibHTML/Frame.cpp b/Libraries/LibHTML/Frame.cpp
index 348f1040ef..f4d26da501 100644
--- a/Libraries/LibHTML/Frame.cpp
+++ b/Libraries/LibHTML/Frame.cpp
@@ -61,7 +61,7 @@ RefPtr<LayoutNode> Frame::generate_layout_tree(const StyledNode& styled_root)
case Display::None:
return nullptr;
case Display::Block:
- return adopt(*new LayoutBlock(*styled_node.node(), styled_node));
+ return adopt(*new LayoutBlock(styled_node.node(), &styled_node));
case Display::Inline:
return adopt(*new LayoutInline(*styled_node.node(), styled_node));
default:
@@ -74,17 +74,19 @@ RefPtr<LayoutNode> Frame::generate_layout_tree(const StyledNode& styled_root)
auto layout_node = create_layout_node(styled_node);
if (!layout_node)
return nullptr;
- if (styled_node.has_children()) {
- for (auto* styled_child = styled_node.first_child(); styled_child; styled_child = styled_child->next_sibling()) {
- auto layout_child = build_layout_tree(*styled_child);
- if (!layout_child)
- continue;
+ if (!styled_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);
+ if (!layout_child)
+ continue;
+ 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);
}
diff --git a/Libraries/LibHTML/Layout/LayoutBlock.cpp b/Libraries/LibHTML/Layout/LayoutBlock.cpp
index 602f09dfa5..7e76b7d91f 100644
--- a/Libraries/LibHTML/Layout/LayoutBlock.cpp
+++ b/Libraries/LibHTML/Layout/LayoutBlock.cpp
@@ -1,8 +1,8 @@
#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, const StyledNode* styled_node)
+ : LayoutNode(node, styled_node)
{
}
@@ -10,6 +10,14 @@ LayoutBlock::~LayoutBlock()
{
}
+LayoutNode& LayoutBlock::inline_wrapper()
+{
+ if (!last_child() || !last_child()->is_block()) {
+ append_child(adopt(*new LayoutBlock(nullptr, nullptr)));
+ }
+ return *last_child();
+}
+
void LayoutBlock::layout()
{
compute_width();
diff --git a/Libraries/LibHTML/Layout/LayoutBlock.h b/Libraries/LibHTML/Layout/LayoutBlock.h
index 007b8c5170..bf3f23c98b 100644
--- a/Libraries/LibHTML/Layout/LayoutBlock.h
+++ b/Libraries/LibHTML/Layout/LayoutBlock.h
@@ -6,13 +6,15 @@ class Element;
class LayoutBlock : public LayoutNode {
public:
- LayoutBlock(const Node&, const StyledNode&);
+ LayoutBlock(const Node*, const StyledNode*);
virtual ~LayoutBlock() override;
virtual const char* class_name() const override { return "LayoutBlock"; }
virtual void layout() override;
+ virtual LayoutNode& inline_wrapper() override;
+
private:
virtual bool is_block() const override { return true; }
diff --git a/Libraries/LibHTML/Layout/LayoutDocument.cpp b/Libraries/LibHTML/Layout/LayoutDocument.cpp
index ef57d8e991..1447cafda6 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)
+ : LayoutBlock(&document, &styled_node)
{
}
diff --git a/Libraries/LibHTML/Layout/LayoutInline.cpp b/Libraries/LibHTML/Layout/LayoutInline.cpp
index 833dc0b1d9..a41b8d4f16 100644
--- a/Libraries/LibHTML/Layout/LayoutInline.cpp
+++ b/Libraries/LibHTML/Layout/LayoutInline.cpp
@@ -2,7 +2,7 @@
#include <LibHTML/Layout/LayoutInline.h>
LayoutInline::LayoutInline(const Node& node, const StyledNode& styled_node)
- : LayoutNode(&node, styled_node)
+ : LayoutNode(&node, &styled_node)
{
}
diff --git a/Libraries/LibHTML/Layout/LayoutInline.h b/Libraries/LibHTML/Layout/LayoutInline.h
index 1032ce8dc6..b5b5fc16b1 100644
--- a/Libraries/LibHTML/Layout/LayoutInline.h
+++ b/Libraries/LibHTML/Layout/LayoutInline.h
@@ -10,6 +10,7 @@ public:
virtual ~LayoutInline() override;
virtual const char* class_name() const override { return "LayoutInline"; }
+ virtual bool is_inline() const override { return true; }
private:
};
diff --git a/Libraries/LibHTML/Layout/LayoutNode.cpp b/Libraries/LibHTML/Layout/LayoutNode.cpp
index 00a2fc44f4..f66ef64fff 100644
--- a/Libraries/LibHTML/Layout/LayoutNode.cpp
+++ b/Libraries/LibHTML/Layout/LayoutNode.cpp
@@ -2,7 +2,7 @@
#include <LibHTML/Layout/LayoutNode.h>
#include <LibHTML/CSS/StyledNode.h>
-LayoutNode::LayoutNode(const Node* node, const StyledNode& styled_node)
+LayoutNode::LayoutNode(const Node* node, const StyledNode* styled_node)
: m_node(node)
, m_styled_node(styled_node)
{
diff --git a/Libraries/LibHTML/Layout/LayoutNode.h b/Libraries/LibHTML/Layout/LayoutNode.h
index b30b26e025..9604636b11 100644
--- a/Libraries/LibHTML/Layout/LayoutNode.h
+++ b/Libraries/LibHTML/Layout/LayoutNode.h
@@ -41,17 +41,20 @@ public:
virtual const char* class_name() const { return "LayoutNode"; }
virtual bool is_text() const { return false; }
virtual bool is_block() const { return false; }
+ virtual bool is_inline() const { return false; }
virtual void layout();
const LayoutBlock* containing_block() const;
+ virtual LayoutNode& inline_wrapper() { return *this; }
+
protected:
- explicit LayoutNode(const Node*, const StyledNode&);
+ explicit LayoutNode(const Node*, const StyledNode*);
private:
const Node* m_node { nullptr };
- NonnullRefPtr<StyledNode> m_styled_node;
+ RefPtr<StyledNode> m_styled_node;
ComputedStyle m_style;
Rect m_rect;
diff --git a/Libraries/LibHTML/Layout/LayoutText.cpp b/Libraries/LibHTML/Layout/LayoutText.cpp
index 9ddd4879a9..aef9451762 100644
--- a/Libraries/LibHTML/Layout/LayoutText.cpp
+++ b/Libraries/LibHTML/Layout/LayoutText.cpp
@@ -2,7 +2,7 @@
#include <ctype.h>
LayoutText::LayoutText(const Text& text, const StyledNode& styled_node)
- : LayoutNode(&text, styled_node)
+ : LayoutNode(&text, &styled_node)
{
}