mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:57:45 +00:00
LibWeb: Don't generate ::before/::after for BR elements
We shouldn't be putting generated pseudo elements inside elements that can't have children in the first place. This patch fixes two issues: - We stop generating pseudo elements for layout nodes that can't have children anyway. - We mark Layout::BreakNode as not being able to have children.
This commit is contained in:
parent
a7c1af08ca
commit
80a78c4deb
4 changed files with 34 additions and 1 deletions
|
@ -0,0 +1,29 @@
|
||||||
|
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
|
||||||
|
BlockContainer <html> at (0,0) content-size 800x84.875 [BFC] children: not-inline
|
||||||
|
BlockContainer <body> at (8,16) content-size 784x68.875 children: not-inline
|
||||||
|
BlockContainer <p> at (8,16) content-size 784x17.46875 children: inline
|
||||||
|
line 0 width: 310.625, height: 17.46875, bottom: 17.46875, baseline: 13.53125
|
||||||
|
frag 0 from TextNode start: 0, length: 1, rect: [8,16 10.625x17.46875]
|
||||||
|
"+"
|
||||||
|
frag 1 from TextNode start: 0, length: 36, rect: [19,16 300x17.46875]
|
||||||
|
"P should generate a ::before pseudo."
|
||||||
|
InlineNode <(anonymous)>
|
||||||
|
TextNode <#text>
|
||||||
|
TextNode <#text>
|
||||||
|
BlockContainer <(anonymous)> at (8,49.46875) content-size 784x35.40625 children: inline
|
||||||
|
line 0 width: 0, height: 17.46875, bottom: 17.46875, baseline: 13.53125
|
||||||
|
line 1 width: 120.578125, height: 17.9375, bottom: 35.40625, baseline: 13.53125
|
||||||
|
frag 0 from TextNode start: 0, length: 14, rect: [8,66.46875 120.578125x17.46875]
|
||||||
|
"BR should not!"
|
||||||
|
BreakNode <br>
|
||||||
|
TextNode <#text>
|
||||||
|
|
||||||
|
ViewportPaintable (Viewport<#document>) [0,0 800x600]
|
||||||
|
PaintableWithLines (BlockContainer<HTML>) [0,0 800x84.875]
|
||||||
|
PaintableWithLines (BlockContainer<BODY>) [8,16 784x68.875]
|
||||||
|
PaintableWithLines (BlockContainer<P>) [8,16 784x17.46875]
|
||||||
|
InlinePaintable (InlineNode(anonymous))
|
||||||
|
TextPaintable (TextNode<#text>)
|
||||||
|
TextPaintable (TextNode<#text>)
|
||||||
|
PaintableWithLines (BlockContainer(anonymous)) [8,49.46875 784x35.40625]
|
||||||
|
TextPaintable (TextNode<#text>)
|
|
@ -0,0 +1,3 @@
|
||||||
|
<!doctype html><style>
|
||||||
|
body ::before { content: "+"; }
|
||||||
|
</style><body><p>P should generate a ::before pseudo.</p><br>BR should not!
|
|
@ -22,6 +22,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual bool is_break_node() const final { return true; }
|
virtual bool is_break_node() const final { return true; }
|
||||||
|
virtual bool can_have_children() const override { return false; }
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
|
|
|
@ -427,7 +427,7 @@ ErrorOr<void> TreeBuilder::create_layout_tree(DOM::Node& dom_node, TreeBuilder::
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add nodes for the ::before and ::after pseudo-elements.
|
// Add nodes for the ::before and ::after pseudo-elements.
|
||||||
if (is<DOM::Element>(dom_node)) {
|
if (is<DOM::Element>(dom_node) && layout_node->can_have_children()) {
|
||||||
auto& element = static_cast<DOM::Element&>(dom_node);
|
auto& element = static_cast<DOM::Element&>(dom_node);
|
||||||
push_parent(verify_cast<NodeWithStyle>(*layout_node));
|
push_parent(verify_cast<NodeWithStyle>(*layout_node));
|
||||||
TRY(create_pseudo_element_if_needed(element, CSS::Selector::PseudoElement::Before, AppendOrPrepend::Prepend));
|
TRY(create_pseudo_element_if_needed(element, CSS::Selector::PseudoElement::Before, AppendOrPrepend::Prepend));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue