Truly independent web browser
LibWeb: Shrink a float’s margin box by its negative inline margins
sideshowbarkere0758c360441
diff --git a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rsindex 648e01e53d6..6aeaa3e9f0a 100644--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs@@ -1557,8 +1557,9 @@ impl<'pass> BlockFormattingContext<'pass> {}fn margin_box_rect(metrics: &impl BoxMetricCells) -> CssPixelRect {- let left = (metrics.margin_left() + metrics.border_box_left(false)).max(CssPixels::default());- let right = (metrics.margin_right() + metrics.border_box_right(false)).max(CssPixels::default());+ // NB: Negative inline margins shrink the margin box, down to no width at all, so that it intrudes on nothing.+ let left = metrics.margin_left() + metrics.border_box_left(false);+ let right = metrics.margin_right() + metrics.border_box_right(false);let top = metrics.margin_box_top(false).max(CssPixels::default());let bottom = metrics.margin_box_bottom(false).max(CssPixels::default());CssPixelRect {diff --git a/Tests/LibWeb/Ref/expected/float-negative-margin-beside-formatting-context-ref.html b/Tests/LibWeb/Ref/expected/float-negative-margin-beside-formatting-context-ref.htmlnew file mode 100644index 00000000000..91ba85df73e--- /dev/null+++ b/Tests/LibWeb/Ref/expected/float-negative-margin-beside-formatting-context-ref.html@@ -0,0 +1,27 @@+<!DOCTYPE html>+<style>+body {+ margin: 0;+}++div {+ position: absolute;+ height: 60px;+}++.float {+ width: 125px;+ background: blue;+}++.beside {+ height: 40px;+ background: green;+}+</style>+<div class="float" style="left: 150px; top: 0"></div>+<div class="beside" style="left: 275px; width: 225px; top: 0"></div>+<div class="float" style="left: 50px; top: 70px"></div>+<div class="beside" style="left: 200px; width: 300px; top: 70px"></div>+<div class="beside" style="left: 200px; width: 300px; top: 140px"></div>+<div class="float" style="left: 200px; top: 140px"></div>diff --git a/Tests/LibWeb/Ref/input/float-negative-margin-beside-formatting-context.html b/Tests/LibWeb/Ref/input/float-negative-margin-beside-formatting-context.htmlnew file mode 100644index 00000000000..e824d6cbc9e--- /dev/null+++ b/Tests/LibWeb/Ref/input/float-negative-margin-beside-formatting-context.html@@ -0,0 +1,32 @@+<!DOCTYPE html>+<link rel="match" href="../expected/float-negative-margin-beside-formatting-context-ref.html">+<style>+body {+ margin: 0;+ padding-left: 200px;+}++.container {+ display: flow-root;+ width: 300px;+ margin-bottom: 10px;+}++.float {+ float: left;+ width: 125px;+ height: 60px;+ background: blue;+}++/* A box with a formatting context of its own goes beside a float's margin box, which negative margins shrink. */+.beside {+ height: 40px;+ background: green;+}+</style>+<!-- The margin box is 75px wide. -->+<div class="container"><div class="float" style="margin-left: -50px"></div><div class="beside" style="display: flow-root"></div></div>+<!-- The margin boxes have no width at all. -->+<div class="container"><div class="float" style="margin-left: -150px"></div><div class="beside" style="display: flex"></div></div>+<div class="container"><div class="float" style="margin-right: -150px"></div><div class="beside" style="display: flow-root"></div></div>