Skip to content

Truly independent web browser

LibWeb: Don’t mirror vertical-lr lines across their clearance

sideshowbarker021ba453599b
diff --git a/Libraries/LibWeb/Rust/src/layout/inline_content.rs b/Libraries/LibWeb/Rust/src/layout/inline_content.rs
index 6f8200416f1..d779cab01b5 100644
--- a/Libraries/LibWeb/Rust/src/layout/inline_content.rs
+++ b/Libraries/LibWeb/Rust/src/layout/inline_content.rs
@@ -124,6 +124,9 @@ pub struct LineRecord {
pub block_length: CssPixels,
pub block_start: CssPixels,
pub block_end: CssPixels,
+ /// The part of the block length that a clearing break after the line adds past the line's own content, so that
+ /// the line reaches down to the clearance.
+ pub(crate) clearance_block_length: CssPixels,
pub(crate) next_line_block_offset: CssPixels,
pub baseline: CssPixels,
pub block_level_box_block_end_margin: CssPixels,
@@ -661,8 +664,11 @@ impl<'content> PhysicalPlane<'content> {
let Some(line) = self.content.lines.get(line_index as usize) else {
return block_offset;
};
+ // The line's content is mirrored within its own extent: a clearing break after the line extends the line
+ // toward the clearance, and the content stays where it is.
let line_block_start = line.block_end - line.block_length;
- line_block_start + line.block_end - block_offset - block_length
+ let line_content_block_end = line.block_end - line.clearance_block_length;
+ line_block_start + line_content_block_end - block_offset - block_length
}
fn unmoved_fragment_rect(
diff --git a/Libraries/LibWeb/Rust/src/layout/line_builder.rs b/Libraries/LibWeb/Rust/src/layout/line_builder.rs
index 1bff91ea90a..45f9fb5e9b8 100644
--- a/Libraries/LibWeb/Rust/src/layout/line_builder.rs
+++ b/Libraries/LibWeb/Rust/src/layout/line_builder.rs
@@ -1417,6 +1417,7 @@ impl<'builder, 'context> LineBuilder<'builder, 'context> {
let block_end = line.block_end;
if clearance > block_end {
line.block_length += clearance - block_end;
+ line.clearance_block_length += clearance - block_end;
line.block_end = clearance;
}
}
diff --git a/Tests/LibWeb/Text/expected/css/br-clear-keeps-vertical-lr-line-content-in-place.txt b/Tests/LibWeb/Text/expected/css/br-clear-keeps-vertical-lr-line-content-in-place.txt
new file mode 100644
index 00000000000..18d962643de
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/css/br-clear-keeps-vertical-lr-line-content-in-place.txt
@@ -0,0 +1,2 @@
+before: x=0 y=50
+after: x=60 y=0
diff --git a/Tests/LibWeb/Text/input/css/br-clear-keeps-vertical-lr-line-content-in-place.html b/Tests/LibWeb/Text/input/css/br-clear-keeps-vertical-lr-line-content-in-place.html
new file mode 100644
index 00000000000..a82ede9aca5
--- /dev/null
+++ b/Tests/LibWeb/Text/input/css/br-clear-keeps-vertical-lr-line-content-in-place.html
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<style>
+ body {
+ margin: 0;
+ font: 20px/1 monospace;
+ }
+ .box {
+ writing-mode: vertical-lr;
+ height: 200px;
+ }
+ .float {
+ float: left;
+ inline-size: 50px;
+ block-size: 60px;
+ }
+ br {
+ clear: left;
+ }
+</style>
+<div class="box" id="box"><div class="float"></div><span id="before">abc</span><br><span id="after">def</span></div>
+<script>
+ test(() => {
+ // The text beside the float stays at the line's block start, and the text after the clearing break starts
+ // past the float.
+ const box = document.getElementById("box").getBoundingClientRect();
+ for (const id of ["before", "after"]) {
+ const rect = document.getElementById(id).getBoundingClientRect();
+ println(`${id}: x=${rect.left - box.left} y=${rect.top - box.top}`);
+ }
+ });
+</script>