mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:37:35 +00:00
LibHTML: Create anonymous blocks around inline children of blocks.
This commit is contained in:
parent
2caec95d30
commit
fc127eb769
9 changed files with 33 additions and 17 deletions
|
@ -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();
|
||||
|
|
|
@ -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; }
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -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:
|
||||
};
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include <ctype.h>
|
||||
|
||||
LayoutText::LayoutText(const Text& text, const StyledNode& styled_node)
|
||||
: LayoutNode(&text, styled_node)
|
||||
: LayoutNode(&text, &styled_node)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue