mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:57:45 +00:00
LibHTML: Let the layout tree own the style tree.
Each layout node is now constructed with an owning back-pointer to the style tree node that originated it.
This commit is contained in:
parent
e9ab282cfd
commit
c7cf6f00fc
11 changed files with 21 additions and 17 deletions
|
@ -61,14 +61,14 @@ void Frame::layout()
|
|||
|
||||
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())));
|
||||
return adopt(*new LayoutDocument(static_cast<const Document&>(*styled_node.node()), styled_node));
|
||||
switch (styled_node.display()) {
|
||||
case Display::None:
|
||||
return nullptr;
|
||||
case Display::Block:
|
||||
return adopt(*new LayoutBlock(*styled_node.node()));
|
||||
return adopt(*new LayoutBlock(*styled_node.node(), styled_node));
|
||||
case Display::Inline:
|
||||
return adopt(*new LayoutInline(*styled_node.node()));
|
||||
return adopt(*new LayoutInline(*styled_node.node(), styled_node));
|
||||
default:
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#include <LibHTML/DOM/Element.h>
|
||||
#include <LibHTML/Layout/LayoutBlock.h>
|
||||
|
||||
LayoutBlock::LayoutBlock(const Node& node)
|
||||
: LayoutNode(&node)
|
||||
LayoutBlock::LayoutBlock(const Node& node, const StyledNode& styled_node)
|
||||
: LayoutNode(&node, styled_node)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ class Element;
|
|||
|
||||
class LayoutBlock : public LayoutNode {
|
||||
public:
|
||||
explicit LayoutBlock(const Node&);
|
||||
LayoutBlock(const Node&, const StyledNode&);
|
||||
virtual ~LayoutBlock() override;
|
||||
|
||||
virtual const char* class_name() const override { return "LayoutBlock"; }
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include <LibHTML/Layout/LayoutDocument.h>
|
||||
|
||||
LayoutDocument::LayoutDocument(const Document& document)
|
||||
: LayoutBlock(document)
|
||||
LayoutDocument::LayoutDocument(const Document& document, const StyledNode& styled_node)
|
||||
: LayoutBlock(document, styled_node)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
class LayoutDocument final : public LayoutBlock {
|
||||
public:
|
||||
explicit LayoutDocument(const Document&);
|
||||
LayoutDocument(const Document&, const StyledNode&);
|
||||
virtual ~LayoutDocument() override;
|
||||
|
||||
const Document& node() const { return static_cast<const Document&>(*LayoutNode::node()); }
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#include <LibHTML/DOM/Element.h>
|
||||
#include <LibHTML/Layout/LayoutInline.h>
|
||||
|
||||
LayoutInline::LayoutInline(const Node& node)
|
||||
: LayoutNode(&node)
|
||||
LayoutInline::LayoutInline(const Node& node, const StyledNode& styled_node)
|
||||
: LayoutNode(&node, styled_node)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ class Element;
|
|||
|
||||
class LayoutInline : public LayoutNode {
|
||||
public:
|
||||
explicit LayoutInline(const Node&);
|
||||
LayoutInline(const Node&, const StyledNode&);
|
||||
virtual ~LayoutInline() override;
|
||||
|
||||
virtual const char* class_name() const override { return "LayoutInline"; }
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
#include <LibHTML/Layout/LayoutBlock.h>
|
||||
#include <LibHTML/Layout/LayoutNode.h>
|
||||
#include <LibHTML/CSS/StyledNode.h>
|
||||
|
||||
LayoutNode::LayoutNode(const Node* node)
|
||||
LayoutNode::LayoutNode(const Node* node, const StyledNode& styled_node)
|
||||
: m_node(node)
|
||||
, m_styled_node(styled_node)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
class Node;
|
||||
class LayoutBlock;
|
||||
class StyledNode;
|
||||
|
||||
class LayoutNode : public TreeNode<LayoutNode> {
|
||||
public:
|
||||
|
@ -46,10 +47,11 @@ public:
|
|||
const LayoutBlock* containing_block() const;
|
||||
|
||||
protected:
|
||||
explicit LayoutNode(const Node*);
|
||||
explicit LayoutNode(const Node*, const StyledNode&);
|
||||
|
||||
private:
|
||||
const Node* m_node { nullptr };
|
||||
NonnullRefPtr<StyledNode> m_styled_node;
|
||||
|
||||
LayoutStyle m_style;
|
||||
Rect m_rect;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#include <LibHTML/Layout/LayoutText.h>
|
||||
#include <ctype.h>
|
||||
|
||||
LayoutText::LayoutText(const Text& text)
|
||||
: LayoutNode(&text)
|
||||
LayoutText::LayoutText(const Text& text, const StyledNode& styled_node)
|
||||
: LayoutNode(&text, styled_node)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
class LayoutText : public LayoutNode {
|
||||
public:
|
||||
explicit LayoutText(const Text&);
|
||||
LayoutText(const Text&, const StyledNode&);
|
||||
virtual ~LayoutText() override;
|
||||
|
||||
const Text& node() const { return static_cast<const Text&>(*LayoutNode::node()); }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue