Truly independent web browser
LibWeb: Let negative block margins shrink a float’s margin box
sideshowbarkerd2563318aef2
diff --git a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rsindex 42ba425d121..e7dfa761abd 100644--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs@@ -1612,16 +1612,17 @@ impl<'pass> BlockFormattingContext<'pass> {}fn margin_box_rect(metrics: &impl BoxMetricCells) -> CssPixelRect {- // NB: Negative inline margins shrink the margin box, down to no width at all, so that it intrudes on nothing.+ // NB: Negative margins shrink the margin box, down to no width or height 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());+ let block_start = -metrics.margin_box_top(false);+ let block_end = (metrics.content_block_size() + metrics.margin_box_bottom(false)).max(block_start);CssPixelRect {x: -left,- y: -top,+ y: block_start,width: left + metrics.content_inline_size() + right,- height: top + metrics.content_block_size() + bottom,+ height: block_end - block_start,}}diff --git a/Tests/LibWeb/Text/expected/css/float-with-negative-margin-after-inline-image.txt b/Tests/LibWeb/Text/expected/css/float-with-negative-margin-after-inline-image.txtnew file mode 100644index 00000000000..e3db2765319--- /dev/null+++ b/Tests/LibWeb/Text/expected/css/float-with-negative-margin-after-inline-image.txt@@ -0,0 +1,3 @@+a: 0+b: 0+c: 0diff --git a/Tests/LibWeb/Text/input/css/float-with-negative-margin-after-inline-image.html b/Tests/LibWeb/Text/input/css/float-with-negative-margin-after-inline-image.htmlnew file mode 100644index 00000000000..d634487028c--- /dev/null+++ b/Tests/LibWeb/Text/input/css/float-with-negative-margin-after-inline-image.html@@ -0,0 +1,41 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<style>+ body {+ margin: 0;+ }+ .box {+ width: 600px;+ }+ img {+ width: 600px;+ height: 300px;+ vertical-align: middle;+ }+ .float {+ float: left;+ width: 100%;+ height: 80px;+ }+</style>+<div class="box">+ <img id="a" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='600' height='300'/%3E">+ <div class="float" style="margin-top: -180px"></div>+</div>+<div class="box">+ <img id="b" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='600' height='300'/%3E">+ <div class="float" style="margin-top: -20px"></div>+</div>+<div class="box">+ <img id="c" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='600' height='300'/%3E">+ <div class="float" style="margin-top: 0"></div>+</div>+<script>+ asyncTest(done => {+ window.onload = () => {+ for (const id of "abc")+ println(`${id}: ${document.getElementById(id).getBoundingClientRect().left}`);+ done();+ };+ });+</script>