Skip to content

Truly independent web browser

LibWeb: Grow the line box for boxes lowered by a vertical-align length

sideshowbarker32da6aac40cf
diff --git a/Libraries/LibWeb/Rust/src/layout/line_builder.rs b/Libraries/LibWeb/Rust/src/layout/line_builder.rs
index 45f9fb5e9b8..6d44281bae7 100644
--- a/Libraries/LibWeb/Rust/src/layout/line_builder.rs
+++ b/Libraries/LibWeb/Rust/src/layout/line_builder.rs
@@ -1277,7 +1277,7 @@ impl<'builder, 'context> LineBuilder<'builder, 'context> {
snapshot.block_offset = fragment.block_offset;
}
- let (inline_box_start, mut inline_box_end) = if snapshot.is_atomic_inline {
+ let (inline_box_start, inline_box_end) = if snapshot.is_atomic_inline {
let atomic_inline = self.line(line_index).fragments[fragment_index].box_cells();
(
snapshot.block_offset - (atomic_inline.margin_top + atomic_inline.border_box_top(false)),
@@ -1293,9 +1293,6 @@ impl<'builder, 'context> LineBuilder<'builder, 'context> {
snapshot.block_offset + snapshot.baseline + bounds.descent,
)
};
- if !alignment_style.vertical_align_is_keyword() {
- inline_box_end += alignment_style.vertical_align_value().to_px(style.line_height());
- }
if let Some((root, alignment)) = aligned_subtree {
if let Some(subtree) = aligned_subtrees.iter_mut().find(|subtree| subtree.root == root) {
subtree.block_start = subtree.block_start.min(inline_box_start);
diff --git a/Tests/LibWeb/Layout/expected/block-and-inline/atomic-inline-with-percentage-vertical-align.txt b/Tests/LibWeb/Layout/expected/block-and-inline/atomic-inline-with-percentage-vertical-align.txt
index 0aba18f21d2..87f453e5323 100644
--- a/Tests/LibWeb/Layout/expected/block-and-inline/atomic-inline-with-percentage-vertical-align.txt
+++ b/Tests/LibWeb/Layout/expected/block-and-inline/atomic-inline-with-percentage-vertical-align.txt
@@ -1,6 +1,6 @@
Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children: not-inline
- BlockContainer <html> at [1,1] [0+1+0 798 0+1+0] [0+1+0 62.8125 0+1+0] [BFC] children: not-inline
- BlockContainer <body> at [2,2] [0+1+0 796 0+1+0] [0+1+0 60.8125 0+1+0] children: inline
+ BlockContainer <html> at [1,1] [0+1+0 798 0+1+0] [0+1+0 66 0+1+0] [BFC] children: not-inline
+ BlockContainer <body> at [2,2] [0+1+0 796 0+1+0] [0+1+0 64 0+1+0] children: inline
frag 0 from BlockContainer start: 0, length: 0, rect: [3,3 30x30] baseline: 32
frag 1 from BlockContainer start: 0, length: 0, rect: [3,35 30x30] baseline: 32
BlockContainer <div.clump> at [3,3] inline-block [0+1+0 30 0+1+0] [0+1+0 30 0+1+0] [BFC] children: not-inline
@@ -8,4 +8,4 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children
BlockContainer <div.clump> at [3,35] inline-block [0+1+0 30 0+1+0] [0+1+0 30 0+1+0] [BFC] children: not-inline
SC for Viewport<#document> [0,0 800x600] (z-index: auto)
- SC for BlockContainer<HTML> [1,1 798x62.8125] (z-index: auto)
+ SC for BlockContainer<HTML> [1,1 798x66] (z-index: auto)
diff --git a/Tests/LibWeb/Text/expected/vertical-align-length-sizes-line-box.txt b/Tests/LibWeb/Text/expected/vertical-align-length-sizes-line-box.txt
new file mode 100644
index 00000000000..53686afdd97
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/vertical-align-length-sizes-line-box.txt
@@ -0,0 +1,7 @@
+lowered: 14px taller than a plain line
+lowered-pseudo: 14px taller than a plain line
+lowered-with-text: 20px taller than a plain line
+lowered-a-little: 0px taller than a plain line
+lowered-by-percentage: 14px taller than a plain line
+lowered-inline: 20px taller than a plain line
+raised: 25px taller than a plain line
diff --git a/Tests/LibWeb/Text/input/vertical-align-length-sizes-line-box.html b/Tests/LibWeb/Text/input/vertical-align-length-sizes-line-box.html
new file mode 100644
index 00000000000..fe667a8a0c4
--- /dev/null
+++ b/Tests/LibWeb/Text/input/vertical-align-length-sizes-line-box.html
@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+<script src="include.js"></script>
+<style>
+ body {
+ font: 16px/20px SerenitySans;
+ }
+ .box {
+ width: 200px;
+ }
+ .ib {
+ display: inline-block;
+ width: 0;
+ height: 20px;
+ }
+ .pseudo::after {
+ content: "";
+ display: inline-block;
+ width: 0;
+ height: 20px;
+ vertical-align: -20px;
+ }
+</style>
+<!-- A line box is tall enough to contain every inline-level box on it, wherever vertical-align puts the box. So a box
+ lowered by a negative length or percentage makes the line box grow below the baseline, and one raised by a positive
+ length makes it grow above the baseline, by just as much. -->
+<div class="box" id="plain">text</div>
+<div class="box" id="lowered">text<span class="ib" style="vertical-align: -20px"></span></div>
+<div class="box pseudo" id="lowered-pseudo">text</div>
+<div class="box" id="lowered-with-text">text<span class="ib" style="vertical-align: -20px">x</span></div>
+<div class="box" id="lowered-a-little">text<span class="ib" style="vertical-align: -5px"></span></div>
+<div class="box" id="lowered-by-percentage">text<span class="ib" style="vertical-align: -100%"></span></div>
+<div class="box" id="lowered-inline">text<span style="vertical-align: -20px">x</span></div>
+<div class="box" id="raised">text<span class="ib" style="vertical-align: 20px"></span></div>
+<script>
+ test(() => {
+ const height = id => document.getElementById(id).getBoundingClientRect().height;
+ const plain = height("plain");
+ for (const id of ["lowered", "lowered-pseudo", "lowered-with-text", "lowered-a-little", "lowered-by-percentage", "lowered-inline", "raised"])
+ println(`${id}: ${height(id) - plain}px taller than a plain line`);
+ });
+</script>