mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:17:45 +00:00
LibWeb: Don't create unwanted layout nodes when recomputing style
When recomputing the style for an element that previously didn't have a corresponding layout node, it may become necessary to create a layout node for it. However, we should not do this if it's within a subtree that can't have layout children. Nor should we do it for elements who have an ancestor with display:none.
This commit is contained in:
parent
a6a8ba80fc
commit
7d052250f2
1 changed files with 11 additions and 1 deletions
|
@ -304,9 +304,19 @@ void Element::recompute_style()
|
||||||
auto new_specified_css_values = document().style_computer().compute_style(*this);
|
auto new_specified_css_values = document().style_computer().compute_style(*this);
|
||||||
m_specified_css_values = new_specified_css_values;
|
m_specified_css_values = new_specified_css_values;
|
||||||
if (!layout_node()) {
|
if (!layout_node()) {
|
||||||
|
// This element doesn't have a corresponding layout node.
|
||||||
|
|
||||||
|
// If the new style is display:none, bail.
|
||||||
if (new_specified_css_values->display().is_none())
|
if (new_specified_css_values->display().is_none())
|
||||||
return;
|
return;
|
||||||
// We need a new layout tree here!
|
|
||||||
|
// If we're inside a display:none ancestor or an ancestor that can't have children, bail.
|
||||||
|
for (auto* ancestor = parent_element(); ancestor; ancestor = ancestor->parent_element()) {
|
||||||
|
if (!ancestor->layout_node() || !ancestor->layout_node()->can_have_children())
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Okay, we need a new layout subtree here.
|
||||||
Layout::TreeBuilder tree_builder;
|
Layout::TreeBuilder tree_builder;
|
||||||
(void)tree_builder.build(*this);
|
(void)tree_builder.build(*this);
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue