Skip to content

Truly independent web browser

LibWeb: Reuse the run of a float whose containing block moves

Aliaksandr Kalenikf62715dc3d71
diff --git a/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs b/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
index 80566c28f42..a5dac70bee4 100644
--- a/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
+++ b/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
@@ -87,6 +87,14 @@ impl FcRunCacheKey {
input.sizing.adopt_automatic_content_block_size = false;
input.sizing.content_block_size_after_inside_layout = None;
}
+ // NB: The parent block formatting context sizes a float against its containing block position before the
+ // run and places it after. The run lays the float out from its own origin.
+ if let ParticipationInParentFormattingContext::Float {
+ containing_block_position_in_bfc_root,
+ } = &mut input.participation
+ {
+ *containing_block_position_in_bfc_root = FfiCssPixelPoint::default();
+ }
Self {
fc_type,
input,
diff --git a/Tests/LibWeb/Text/expected/layout-run-cache-float-in-moved-containing-block.txt b/Tests/LibWeb/Text/expected/layout-run-cache-float-in-moved-containing-block.txt
new file mode 100644
index 00000000000..9da9dbcf872
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/layout-run-cache-float-in-moved-containing-block.txt
@@ -0,0 +1 @@
+PASS: a float whose containing block moves keeps the layout of its contents (work + checks)
diff --git a/Tests/LibWeb/Text/input/layout-run-cache-float-in-moved-containing-block.html b/Tests/LibWeb/Text/input/layout-run-cache-float-in-moved-containing-block.html
new file mode 100644
index 00000000000..13f64ded4b8
--- /dev/null
+++ b/Tests/LibWeb/Text/input/layout-run-cache-float-in-moved-containing-block.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html>
+<script src="include.js"></script>
+<script src="layout-test.js"></script>
+<style>
+ body { margin: 0; font: 10px/10px SerenitySans; }
+ .scenario { display: flow-root; width: 200px; }
+ #before { height: 10px; }
+ .float { float: left; width: 50px; }
+</style>
+<div class="scenario" id="scenario"><div id="before"></div><div id="container"><div class="float" id="float">float content</div><span id="beside">text beside the float</span></div></div>
+<script>
+ layoutTest({
+ steps: [
+ {
+ name: "a float whose containing block moves keeps the layout of its contents",
+ mutate: () => {
+ before.style.height = "30px";
+ beside.firstChild.data = "other text beside the float";
+ },
+ expect: `
+ layout FULL
+ @viewport/block RUN (cache=bypass)
+ BlockContainer<HTML>/block RUN (cache=miss)
+ BlockContainer<DIV>#scenario.scenario/block RUN (cache=miss)
+ BlockContainer<DIV>#float.float/block REUSE SUBTREE
+ `,
+ check: equal => {
+ equal(float.getBoundingClientRect().top, 30, "float top");
+ },
+ },
+ ],
+ });
+</script>