Truly independent web browser
LibWeb: Clear past a float that leaves a clearing break no room
sideshowbarker34e99282d835
diff --git a/Libraries/LibWeb/Rust/src/layout/line_builder.rs b/Libraries/LibWeb/Rust/src/layout/line_builder.rsindex a1b2230561d..708dfe85798 100644--- a/Libraries/LibWeb/Rust/src/layout/line_builder.rs+++ b/Libraries/LibWeb/Rust/src/layout/line_builder.rs@@ -1375,14 +1375,20 @@ impl<'builder, 'context> LineBuilder<'builder, 'context> {}pub(crate) fn did_introduce_clearance(&mut self, clearance: CssPixels) {- if clearance <= self.current_block_offset {- return;- }- if self.line_count() > 1 {- let previous = self.line_count() - 2;- self.line_mut(previous).block_end = clearance;+ // NB: The line the clearing break ends reaches down to the clearance, so that its block container does even+ // when no line follows. That's the last line before the current one that holds anything: Moving past a+ // float that left no room beside the break can leave empty lines between them. The line grows rather+ // than moves, so it keeps its start and its baseline.+ let current = self.line_count() - 1;+ if let Some(ended) = (0..current).rev().find(|&index| !self.line(index).is_empty()) {+ let mut line = self.line_mut(ended);+ let block_end = line.block_end;+ if clearance > block_end {+ line.block_length += clearance - block_end;+ line.block_end = clearance;+ }}- self.current_block_offset = clearance;+ self.current_block_offset = self.current_block_offset.max(clearance);}pub(crate) fn set_trailing_whitespace_on_previous_line(&mut self) {diff --git a/Tests/LibWeb/Ref/expected/wpt-import/html/rendering/non-replaced-elements/the-br-element/br-clear-presentational-hints-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/html/rendering/non-replaced-elements/the-br-element/br-clear-presentational-hints-ref.htmlnew file mode 100644index 00000000000..ae33bcdb400--- /dev/null+++ b/Tests/LibWeb/Ref/expected/wpt-import/html/rendering/non-replaced-elements/the-br-element/br-clear-presentational-hints-ref.html@@ -0,0 +1,3 @@+<!DOCTYPE html>+<meta charset="utf-8">+<div style="max-width: 100px; height: 100px; background: green;"></div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/html/rendering/non-replaced-elements/the-br-element/br-clear-presentational-hints.html b/Tests/LibWeb/Ref/input/wpt-import/html/rendering/non-replaced-elements/the-br-element/br-clear-presentational-hints.htmlnew file mode 100644index 00000000000..696eb4f3370--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/html/rendering/non-replaced-elements/the-br-element/br-clear-presentational-hints.html@@ -0,0 +1,38 @@+<!DOCTYPE html>+<meta charset="utf-8">+<title>The clear attribute applies the clear CSS property.</title>+<link rel="author" title="Psychpsyo" href="mailto:[email protected]">+<link rel="help" href="https://html.spec.whatwg.org/multipage/rendering.html#phrasing-content-3">+<link rel=match href="../../../../../../expected/wpt-import/html/rendering/non-replaced-elements/the-br-element/br-clear-presentational-hints-ref.html">+<style>+ body {+ line-height: 0;+ }+ .test > div {+ width: 25px;+ height: 50px;+ background: green;+ }+</style>+<div style="max-width: 100px; display: flex; height: 100px; background: red;">+ <div class="test">+ <div style="float:right"></div>+ <br clear="all">+ <div></div>+ </div>+ <div class="test">+ <div style="float:right"></div>+ <br clear="both">+ <div></div>+ </div>+ <div class="test">+ <div style="float:right"></div>+ <br clear="right">+ <div></div>+ </div>+ <div class="test">+ <div style="float:left"></div>+ <br clear="left">+ <div></div>+ </div>+</div>diff --git a/Tests/LibWeb/Text/expected/css/br-clear-past-float-that-fills-the-line.txt b/Tests/LibWeb/Text/expected/css/br-clear-past-float-that-fills-the-line.txtnew file mode 100644index 00000000000..d3904af0af7--- /dev/null+++ b/Tests/LibWeb/Text/expected/css/br-clear-past-float-that-fills-the-line.txt@@ -0,0 +1,4 @@+narrow: height 58+full: height 58+checkbox below legend: true+checkbox at the start of its line: truediff --git a/Tests/LibWeb/Text/input/css/br-clear-past-float-that-fills-the-line.html b/Tests/LibWeb/Text/input/css/br-clear-past-float-that-fills-the-line.htmlnew file mode 100644index 00000000000..b6bdc7d7741--- /dev/null+++ b/Tests/LibWeb/Text/input/css/br-clear-past-float-that-fills-the-line.html@@ -0,0 +1,60 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<style>+ body {+ margin: 0;+ font: 16px/16px serif;+ }+ .container {+ width: 300px;+ }+ .float {+ float: left;+ height: 50px;+ margin-bottom: 8px;+ }+ fieldset {+ width: 300px;+ margin: 0;+ padding: 0;+ border: 0;+ }+ legend {+ float: left;+ width: 100%;+ height: 20px;+ margin-top: 4px;+ padding: 0;+ }+ legend + * {+ clear: left;+ }+ .check {+ padding-left: 24px;+ }+ .check input {+ float: left;+ width: 16px;+ height: 16px;+ margin: 0 0 0 -24px;+ }+</style>+<div class="container" id="narrow"><div class="float" style="width: 100px"></div><br style="clear: left"></div>+<div class="container" id="full"><div class="float" style="width: 100%"></div><br style="clear: left"></div>+<fieldset id="fieldset">+ <legend>Privacy</legend>+ <br>+ <div class="check"><input type="checkbox" id="checkbox"><label for="checkbox">I agree</label></div>+</fieldset>+<script>+ test(() => {+ // A clearing break moves what follows below the float's margin box, however much of the line the float fills.+ for (const id of ["narrow", "full"])+ println(`${id}: height ${document.getElementById(id).getBoundingClientRect().height}`);++ const legend = document.querySelector("legend").getBoundingClientRect();+ const checkbox = document.getElementById("checkbox").getBoundingClientRect();+ println(`checkbox below legend: ${checkbox.top >= legend.bottom}`);+ println(`checkbox at the start of its line: ${checkbox.left === document.getElementById("fieldset").getBoundingClientRect().left}`);+ });+</script>