mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 22:17:42 +00:00
LibHTML: Add LayoutNodeWithStyle class, make LayoutText style-less
Since LayoutText always inherits style, it shouldn't store any style of its own. This patch adds a LayoutNodeWithStyle class to sit between LayoutNode and everyone who wants to inherit from LayoutNode except LayoutText :^) Since LayoutText can never have children, we also know that the parent of any LayoutNode is always going to be a LayoutNodeWithStyle. So this patch makes LayoutNode::parent() return LayoutNodeWithStyle*.
This commit is contained in:
parent
15f3e64862
commit
749e3f0f30
9 changed files with 46 additions and 17 deletions
|
@ -5,7 +5,7 @@
|
|||
#include <LibHTML/Layout/LayoutInline.h>
|
||||
|
||||
LayoutBlock::LayoutBlock(const Node* node, NonnullRefPtr<StyleProperties> style)
|
||||
: LayoutNode(node, move(style))
|
||||
: LayoutNodeWithStyle(node, move(style))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
class Element;
|
||||
|
||||
class LayoutBlock : public LayoutNode {
|
||||
class LayoutBlock : public LayoutNodeWithStyle {
|
||||
public:
|
||||
LayoutBlock(const Node*, NonnullRefPtr<StyleProperties>);
|
||||
virtual ~LayoutBlock() override;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include <LibHTML/Layout/LayoutInline.h>
|
||||
|
||||
LayoutInline::LayoutInline(const Element& element, NonnullRefPtr<StyleProperties> style)
|
||||
: LayoutNode(&element, move(style))
|
||||
: LayoutNodeWithStyle(&element, move(style))
|
||||
{
|
||||
set_inline(true);
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
class LayoutBlock;
|
||||
|
||||
class LayoutInline : public LayoutNode {
|
||||
class LayoutInline : public LayoutNodeWithStyle {
|
||||
public:
|
||||
LayoutInline(const Element&, NonnullRefPtr<StyleProperties>);
|
||||
virtual ~LayoutInline() override;
|
||||
|
|
|
@ -7,9 +7,8 @@
|
|||
//#define DRAW_BOXES_AROUND_LAYOUT_NODES
|
||||
//#define DRAW_BOXES_AROUND_HOVERED_NODES
|
||||
|
||||
LayoutNode::LayoutNode(const Node* node, RefPtr<StyleProperties> style)
|
||||
LayoutNode::LayoutNode(const Node* node)
|
||||
: m_node(node)
|
||||
, m_style(move(style))
|
||||
{
|
||||
if (m_node)
|
||||
m_node->set_layout_node({}, this);
|
||||
|
|
|
@ -12,6 +12,7 @@ class Document;
|
|||
class Element;
|
||||
class LayoutBlock;
|
||||
class LayoutNode;
|
||||
class LayoutNodeWithStyle;
|
||||
class LineBoxFragment;
|
||||
class Node;
|
||||
|
||||
|
@ -66,12 +67,9 @@ public:
|
|||
|
||||
virtual LayoutNode& inline_wrapper() { return *this; }
|
||||
|
||||
const StyleProperties& style() const
|
||||
{
|
||||
if (m_style)
|
||||
return *m_style;
|
||||
return parent()->style();
|
||||
}
|
||||
const StyleProperties& style() const;
|
||||
|
||||
const LayoutNodeWithStyle* parent() const;
|
||||
|
||||
void inserted_into(LayoutNode&) {}
|
||||
void removed_from(LayoutNode&) {}
|
||||
|
@ -79,13 +77,45 @@ public:
|
|||
virtual void split_into_lines(LayoutBlock& container);
|
||||
|
||||
protected:
|
||||
explicit LayoutNode(const Node*, RefPtr<StyleProperties>);
|
||||
explicit LayoutNode(const Node*);
|
||||
|
||||
private:
|
||||
friend class LayoutNodeWithStyle;
|
||||
|
||||
const Node* m_node { nullptr };
|
||||
|
||||
RefPtr<StyleProperties> m_style;
|
||||
BoxModelMetrics m_box_metrics;
|
||||
Rect m_rect;
|
||||
bool m_inline { false };
|
||||
bool m_has_style { false };
|
||||
};
|
||||
|
||||
class LayoutNodeWithStyle : public LayoutNode {
|
||||
public:
|
||||
virtual ~LayoutNodeWithStyle() override {}
|
||||
|
||||
const StyleProperties& style() const { return m_style; }
|
||||
|
||||
protected:
|
||||
explicit LayoutNodeWithStyle(const Node* node, NonnullRefPtr<StyleProperties> style)
|
||||
: LayoutNode(node)
|
||||
, m_style(move(style))
|
||||
{
|
||||
m_has_style = true;
|
||||
}
|
||||
|
||||
private:
|
||||
NonnullRefPtr<StyleProperties> m_style;
|
||||
};
|
||||
|
||||
inline const StyleProperties& LayoutNode::style() const
|
||||
{
|
||||
if (m_has_style)
|
||||
return static_cast<const LayoutNodeWithStyle*>(this)->style();
|
||||
return parent()->style();
|
||||
}
|
||||
|
||||
inline const LayoutNodeWithStyle* LayoutNode::parent() const
|
||||
{
|
||||
return static_cast<const LayoutNodeWithStyle*>(TreeNode<LayoutNode>::parent());
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include <LibHTML/Layout/LayoutReplaced.h>
|
||||
|
||||
LayoutReplaced::LayoutReplaced(const Element& element, NonnullRefPtr<StyleProperties> style)
|
||||
: LayoutNode(&element, move(style))
|
||||
: LayoutNodeWithStyle(&element, move(style))
|
||||
{
|
||||
// FIXME: Allow non-inline replaced elements.
|
||||
set_inline(true);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include <LibHTML/DOM/Element.h>
|
||||
#include <LibHTML/Layout/LayoutNode.h>
|
||||
|
||||
class LayoutReplaced : public LayoutNode {
|
||||
class LayoutReplaced : public LayoutNodeWithStyle {
|
||||
public:
|
||||
LayoutReplaced(const Element&, NonnullRefPtr<StyleProperties>);
|
||||
virtual ~LayoutReplaced() override;
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include <ctype.h>
|
||||
|
||||
LayoutText::LayoutText(const Text& text)
|
||||
: LayoutNode(&text, {})
|
||||
: LayoutNode(&text)
|
||||
{
|
||||
set_inline(true);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue