Truly independent web browser
LibWeb: Tell a size query's dependents of a rebuilt container's new size
Andreas Kling1cad5aa5e69f
diff --git a/Libraries/LibWeb/Rust/src/layout/commit.rs b/Libraries/LibWeb/Rust/src/layout/commit.rsindex 6790ad33a2c..aaa67a831e4 100644--- a/Libraries/LibWeb/Rust/src/layout/commit.rs+++ b/Libraries/LibWeb/Rust/src/layout/commit.rs@@ -464,8 +464,12 @@ impl<'tree> Commit<'_, 'tree> {if fragment.line_data.is_some() {line_root_changes_for_children = replaced.line_root_changes;}- if prepared.row_existed_before_this_commit- && let Some((old_content_size, new_content_size)) = replaced.content_size_change+ let content_size_change = if prepared.row_existed_before_this_commit {+ replaced.content_size_change+ } else {+ self.arena().content_size_change_of_rebuilt_box(node)+ };+ if let Some((old_content_size, new_content_size)) = content_size_change&& crate::layout::node_facts::node_style_view(self.arena().data(node)).is_some_and(|style| {content_size_change_affects_container_queries(style, old_content_size, new_content_size)})diff --git a/Libraries/LibWeb/Rust/src/layout/style_snapshot.rs b/Libraries/LibWeb/Rust/src/layout/style_snapshot.rsindex 1208ed525c5..de347920380 100644--- a/Libraries/LibWeb/Rust/src/layout/style_snapshot.rs+++ b/Libraries/LibWeb/Rust/src/layout/style_snapshot.rs@@ -64,6 +64,33 @@ impl LayoutNodeArena {}}+ /// What a size container's new box moved from, for a commit that has no earlier fragment of it to compare. The+ /// layout tree can rebuild the box in the update that resizes it, with no commit between to say it lost the old one,+ /// so the row still holds the size of the box it replaced.+ pub(crate) fn content_size_change_of_rebuilt_box(+ &self,+ node: NodeSlotId,+ ) -> Option<(FfiCssPixelSize, FfiCssPixelSize)> {+ if !node_is_size_container(self, node) {+ return None;+ }+ let style_node = self.snapshot_target(node)?;+ let row = self.with_style_store(|engine| engine.layout_style_snapshot(style_node))?;+ if !row.has_committed_box {+ return None;+ }+ let geometry = self.committed_geometry(node, style_node);+ let size = |width_raw, height_raw| FfiCssPixelSize {+ width: crate::css::css_pixels::CssPixels::from_raw(width_raw),+ height: crate::css::css_pixels::CssPixels::from_raw(height_raw),+ };+ let (old_size, new_size) = (+ size(row.content_width_raw, row.content_height_raw),+ size(geometry.content_width_raw, geometry.content_height_raw),+ );+ (old_size != new_size).then_some((old_size, new_size))+ }+/// Gathers the node's row for the style engine. Style asks layout only about size containers,/// and about scroll-state containers, whose rows the scroll state makes; an element that/// stops being one keeps its row up to date until it goes.diff --git a/Tests/LibWeb/Text/expected/css/style-engine/container-box-rebuilt-as-it-resizes.txt b/Tests/LibWeb/Text/expected/css/style-engine/container-box-rebuilt-as-it-resizes.txtnew file mode 100644index 00000000000..1b601e993cf--- /dev/null+++ b/Tests/LibWeb/Text/expected/css/style-engine/container-box-rebuilt-as-it-resizes.txt@@ -0,0 +1,2 @@+display change: rgb(0, 128, 0)+fixed child shown: rgb(0, 128, 0)diff --git a/Tests/LibWeb/Text/input/css/style-engine/container-box-rebuilt-as-it-resizes.html b/Tests/LibWeb/Text/input/css/style-engine/container-box-rebuilt-as-it-resizes.htmlnew file mode 100644index 00000000000..a5d7bab6649--- /dev/null+++ b/Tests/LibWeb/Text/input/css/style-engine/container-box-rebuilt-as-it-resizes.html@@ -0,0 +1,42 @@+<!DOCTYPE html>+<style>+ .container {+ container-type: inline-size;+ width: 400px;+ }+ .dependent {+ color: red;+ }+ @container (min-width: 500px) {+ .dependent {+ color: green;+ }+ }+ .fixed {+ position: fixed;+ display: none;+ }+</style>+<div id="rebuilt" class="container"><div class="dependent"></div></div>+<div id="sibling" class="container">+ <div class="fixed"></div>+ <div class="dependent"></div>+</div>+<script src="../../include.js"></script>+<script>+ test(() => {+ const colorBelow = container => getComputedStyle(container.querySelector(".dependent")).color;++ // The container's own box is rebuilt in the update that resizes it.+ rebuilt.offsetWidth;+ rebuilt.style.width = "600px";+ rebuilt.style.display = "flow-root";+ println(`display change: ${colorBelow(rebuilt)}`);++ // A fixed child that starts to show rebuilds the box of its parent.+ sibling.offsetWidth;+ sibling.style.width = "600px";+ sibling.querySelector(".fixed").style.display = "block";+ println(`fixed child shown: ${colorBelow(sibling)}`);+ });+</script>