mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 17:40:27 +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
Notes:
sideshowbarker
2024-07-17 17:55:44 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/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);
|
||||
m_specified_css_values = new_specified_css_values;
|
||||
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())
|
||||
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;
|
||||
(void)tree_builder.build(*this);
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue