Skip to content

Commit b28480f

Browse files
committed
LibWeb: Propagate layout tree update in display: contents to parent
When an element has `display: contents` and it gets marked for a layout tree rebuild, we actually have to mark its parent for rebuild as well. The structure of the parent (and siblings) may change depending on how the `display: contents` element changes (e.g position, display, etc.)
1 parent 93889c5 commit b28480f

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

Libraries/LibWeb/DOM/Node.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,6 +1669,16 @@ void Node::set_needs_layout_tree_update(bool value, SetNeedsLayoutTreeUpdateReas
16691669
break;
16701670
ancestor->m_child_needs_layout_tree_update = true;
16711671
}
1672+
1673+
// If this is an element with display: contents, we need to propagate the layout tree update to the parent.
1674+
if (auto* element = as_if<Element>(*this)) {
1675+
if (element->computed_properties() && element->computed_properties()->display().is_contents()) {
1676+
if (auto parent_element = element->parent_or_shadow_host_element()) {
1677+
parent_element->set_needs_layout_tree_update(true, reason);
1678+
}
1679+
}
1680+
}
1681+
16721682
if (auto layout_node = this->layout_node()) {
16731683
layout_node->set_needs_layout_update(SetNeedsLayoutReason::LayoutTreeUpdate);
16741684

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] children: not-inline
2+
BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 34 0+0+0] [BFC] children: not-inline
3+
BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 18 0+0+8] children: not-inline
4+
BlockContainer <article> at [8,8] positioned [0+0+0 784 0+0+0] [0+0+0 18 0+0+0] children: inline
5+
frag 0 from TextNode start: 0, length: 3, rect: [8,8 27.421875x18] baseline: 13.796875
6+
"wat"
7+
TextNode <#text> (not painted)
8+
9+
ViewportPaintable (Viewport<#document>) [0,0 800x600]
10+
PaintableWithLines (BlockContainer<HTML>) [0,0 800x34]
11+
PaintableWithLines (BlockContainer<BODY>) [8,8 784x18]
12+
PaintableWithLines (BlockContainer<ARTICLE>) [8,8 784x18]
13+
TextPaintable (TextNode<#text>)
14+
15+
SC for Viewport<#document> [0,0 800x600] [children: 1] (z-index: auto)
16+
SC for BlockContainer<HTML> [0,0 800x34] [children: 0] (z-index: auto)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!doctype html><head><script>
2+
3+
window.onload = function() {
4+
let art = document.querySelector("article");
5+
art.style.position = "static";
6+
art.offsetWidth;
7+
art.style.position = "relative";
8+
art.offsetWidth;
9+
art.style.position = "static";
10+
art.offsetWidth;
11+
art.style.position = "relative";
12+
art.offsetWidth;
13+
};
14+
15+
</script><style>
16+
main {
17+
display: contents;
18+
background: red;
19+
}
20+
</style></head><body><main><article>wat

0 commit comments

Comments
 (0)