Skip to content

Truly independent web browser

LibWeb: Let a row go between pre-order positions out of order

Andreas Klingfcc56ede9a38
diff --git a/Libraries/LibWeb/Rust/src/layout/tree_plan/mod.rs b/Libraries/LibWeb/Rust/src/layout/tree_plan/mod.rs
index aad47dcd316..0e6e652e224 100644
--- a/Libraries/LibWeb/Rust/src/layout/tree_plan/mod.rs
+++ b/Libraries/LibWeb/Rust/src/layout/tree_plan/mod.rs
@@ -1522,9 +1522,14 @@ impl PlanTree {
let (preceding_name, preceding_position) = unpacked_pre_order_position(self.pre_order_position(preceding));
if preceding_name == name { preceding_position } else { 0 }
};
- let between = floor + (position - floor) / 2;
- assert!(between > floor, "a build puts few rows between the same two rows");
- packed_pre_order_position(name as u32, between)
+ // NB: A row a build moved keeps its position, so the rows around the new one can be out of order already, or so
+ // close together that no position is left between them. Then the arena labels the rows in tree order, and
+ // any position will do.
+ if position <= floor + 1 {
+ self.pre_order_positions_out_of_order = true;
+ return packed_pre_order_position(name as u32, position.max(1));
+ }
+ packed_pre_order_position(name as u32, floor + (position - floor) / 2)
}
/// The row after the subtree of `node` in pre-order, or none where the subtree is the last the walk made: that of a
diff --git a/Tests/LibWeb/Crash/Layout/fieldset-table-cell-before-legend.html b/Tests/LibWeb/Crash/Layout/fieldset-table-cell-before-legend.html
new file mode 100644
index 00000000000..e4d04b213de
--- /dev/null
+++ b/Tests/LibWeb/Crash/Layout/fieldset-table-cell-before-legend.html
@@ -0,0 +1,4 @@
+<!DOCTYPE html>
+<!-- The cell moves into the fieldset's content box, keeping a pre-order position before that box's, and table fixup then
+ puts an anonymous table before it. -->
+<fieldset><div style="display: table-cell">cell</div><legend>legend</legend></fieldset>