Truly independent web browser
LibWeb: Build a box for a shown element whose children changed
sideshowbarkerac55232f2b84
diff --git a/Libraries/LibWeb/Rust/src/css/style/style_invalidation.rs b/Libraries/LibWeb/Rust/src/css/style/style_invalidation.rsindex 68ff20a31a5..e63b49e847c 100644--- a/Libraries/LibWeb/Rust/src/css/style/style_invalidation.rs+++ b/Libraries/LibWeb/Rust/src/css/style/style_invalidation.rs@@ -1396,6 +1396,17 @@ pub(crate) fn element_record_damage_of_views(facts: ElementDamageFacts, record_mdamage.any_computed_value_changed = true;damage.merge(StyleInvalidation::full());}+ // NB: An element that leaves `display: none` has no box to build again, so whatever else changed along with its+ // display, its box appears: its layout parent takes the box in as a change of its child list, as it takes in+ // the box of an inserted element. And the host tells an element whose box appears from one just inserted,+ // whose insertion already asked for its box, by this root.+ if !facts.is_pseudo_element+ && damage.level >= INVALIDATION_REBUILD_LAYOUT_TREE+ && old_values.display().is_none()+ && !new_values.display().is_none()+ {+ damage.rebuild_root = REBUILD_ROOT_BOX_PRESENCE_CHANGE;+ }damage.pack()}diff --git a/Tests/LibWeb/Text/expected/display-none-element-shown-after-child-list-change.txt b/Tests/LibWeb/Text/expected/display-none-element-shown-after-child-list-change.txtnew file mode 100644index 00000000000..d34ec8d2d11--- /dev/null+++ b/Tests/LibWeb/Text/expected/display-none-element-shown-after-child-list-change.txt@@ -0,0 +1,26 @@+abspos-span: has a box, 200px wide+float-span: has a box, 200px wide+abspos-div: has a box, 200px wide+shown-before-insertion: has a box, 200px wide+element-child: has a box, 200px wide+child-removed-again: has a box, 200px wide+layout-between: has a box, 200px wide+hidden-attribute: has a box, 200px wide+shown-as-block: has a box, 200px wide+shown-by-class-on-parent: has a box, 200px wide+fixed: has a box, 200px wide+before-text: has a box, 200px wide+after-text: has a box, 200px wide+after-block: has a box, 200px wide+before-block: has a box, 200px wide+in-nested-block: has a box, 200px wide+in-inline-box: has a box, 200px wide+in-flex-container: has a box, 200px wide+in-grid-container: has a box, 200px wide+inline-span: has a box+block-div: has a box+table-row-group: has a box+table-caption: has a box+list-item: has a box+hidden-after-insertion: has no box+the tree matches a full rebuild: truediff --git a/Tests/LibWeb/Text/input/display-none-element-shown-after-child-list-change.html b/Tests/LibWeb/Text/input/display-none-element-shown-after-child-list-change.htmlnew file mode 100644index 00000000000..c60ec6ca2cc--- /dev/null+++ b/Tests/LibWeb/Text/input/display-none-element-shown-after-child-list-change.html@@ -0,0 +1,87 @@+<!DOCTYPE html>+<script src="include.js"></script>+<style>+ .container { position: relative; width: 200px; height: 50px; }+ .abspos { position: absolute; inset: 0; }+ .float { float: left; width: 100%; height: 100%; }+ .hide-children > * { display: none; }+</style>+<div class="tests">+<div class="container"><span id="abspos-span" class="abspos" style="display: none"></span></div>+<div class="container"><span id="float-span" class="float" style="display: none"></span></div>+<div class="container"><div id="abspos-div" class="abspos" style="display: none"></div></div>+<div class="container"><span id="shown-before-insertion" class="abspos" style="display: none"></span></div>+<div class="container"><span id="element-child" class="abspos" style="display: none"></span></div>+<div class="container"><span id="child-removed-again" class="abspos" style="display: none"></span></div>+<div class="container"><span id="layout-between" class="abspos" style="display: none"></span></div>+<div class="container"><span id="hidden-attribute" class="abspos" hidden></span></div>+<div class="container"><span id="shown-as-block" class="abspos" style="display: none"></span></div>+<div class="container"><span id="shown-by-class-on-parent" class="abspos"></span></div>+<div class="container" style="transform: translate(0)"><span id="fixed" class="abspos" style="display: none; position: fixed"></span></div>+<div class="container"><span id="before-text" class="abspos" style="display: none"></span>x</div>+<div class="container">x<span id="after-text" class="abspos" style="display: none"></span></div>+<div class="container"><div></div><span id="after-block" class="abspos" style="display: none"></span></div>+<div class="container"><span id="before-block" class="abspos" style="display: none"></span><div></div></div>+<div class="container"><div><span id="in-nested-block" class="abspos" style="display: none"></span></div></div>+<div class="container"><span><span id="in-inline-box" class="abspos" style="display: none"></span></span></div>+<div class="container" style="display: flex"><span id="in-flex-container" class="abspos" style="display: none"></span></div>+<div class="container" style="display: grid"><span id="in-grid-container" class="abspos" style="display: none"></span></div>+<div class="container"><span id="inline-span" style="display: none"></span></div>+<div class="container"><div id="block-div" style="display: none"></div></div>+<table><tbody id="table-row-group" style="display: none"></tbody></table>+<table><caption id="table-caption" style="display: none"></caption></table>+<ul><li id="list-item" style="display: none"></li></ul>+<div class="container"><span id="hidden-after-insertion" class="abspos"></span></div>+</div>+<script>+ test(() => {+ // An element that isn't displayed has no box. When its children change while it's hidden, and it's then+ // displayed before anything lays the page out again, it gets its box like any other element that's shown.+ document.body.offsetWidth;+ const element = id => document.getElementById(id);+ const show = id => element(id).style.display = "";+ const insertingFirst = [+ "abspos-span", "float-span", "abspos-div", "fixed", "before-text", "after-text", "after-block",+ "before-block", "in-nested-block", "in-inline-box", "in-flex-container", "in-grid-container",+ "inline-span", "block-div", "table-caption", "list-item",+ ];+ for (const id of insertingFirst) {+ element(id).append("text");+ show(id);+ }+ show("shown-before-insertion");+ element("shown-before-insertion").append("text");+ element("element-child").append(document.createElement("b"));+ show("element-child");+ const text = document.createTextNode("text");+ element("child-removed-again").append(text);+ text.remove();+ show("child-removed-again");+ element("layout-between").append("text");+ document.body.offsetWidth;+ show("layout-between");+ element("hidden-attribute").append("text");+ element("hidden-attribute").hidden = false;+ element("shown-as-block").append("text");+ element("shown-as-block").style.display = "block";+ const parent = element("shown-by-class-on-parent").parentNode;+ parent.classList.add("hide-children");+ document.body.offsetWidth;+ element("shown-by-class-on-parent").append("text");+ parent.classList.remove("hide-children");+ const row = document.createElement("tr");+ row.innerHTML = "<td>text</td>";+ element("table-row-group").append(row);+ show("table-row-group");+ element("hidden-after-insertion").append("text");+ element("hidden-after-insertion").style.display = "none";++ for (const target of document.querySelectorAll(".tests [id]")) {+ const hasBox = target.getClientRects().length > 0;+ const size = target.classList.length ? `, ${target.offsetWidth}px wide` : "";+ println(`${target.id}: ${hasBox ? "has a box" : "has no box"}${hasBox ? size : ""}`);+ }+ if (window.internals)+ println(`the tree matches a full rebuild: ${internals.compareLayoutTreeWithFullRebuild().matches}`);+ });+</script>