From 47f5da75230b1d7f06cec5bcdbe6ef1e9ba09884 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 25 Feb 2025 20:37:10 +0100 Subject: [PATCH] LibWeb: Actually, don't align all inline content to alphabetic baseline This essentially reverts 1b46a52cfcb71f4592976a2df887b20742f7346d and adds more tests. The reverted change was an incorrect workaround for the real issue, which was that we weren't creating anonymous wrapper boxes around inline children of table-cell boxes. Now that this has been fixed, we can go back to aligning text properly. --- Libraries/LibWeb/Layout/LineBuilder.cpp | 4 --- .../table/vertical-align-middle-td-vs-div.txt | 35 +++++++++++++++++++ .../table/vertical-align-middle-vs-top.txt | 31 ++++++++++++++++ .../vertical-align-middle-td-vs-div.html | 11 ++++++ .../table/vertical-align-middle-vs-top.html | 35 +++++++++++++++++++ 5 files changed, 112 insertions(+), 4 deletions(-) create mode 100644 Tests/LibWeb/Layout/expected/table/vertical-align-middle-td-vs-div.txt create mode 100644 Tests/LibWeb/Layout/expected/table/vertical-align-middle-vs-top.txt create mode 100644 Tests/LibWeb/Layout/input/table/vertical-align-middle-td-vs-div.html create mode 100644 Tests/LibWeb/Layout/input/table/vertical-align-middle-vs-top.html diff --git a/Libraries/LibWeb/Layout/LineBuilder.cpp b/Libraries/LibWeb/Layout/LineBuilder.cpp index 7efecd83047..58a096e57c6 100644 --- a/Libraries/LibWeb/Layout/LineBuilder.cpp +++ b/Libraries/LibWeb/Layout/LineBuilder.cpp @@ -286,10 +286,6 @@ void LineBuilder::update_last_line() auto alphabetic_baseline = m_current_block_offset + line_box_baseline - fragment.baseline() + effective_box_top_offset; - // NOTE: Plain inline text content is always on the alphabetic baseline. - if (!fragment.is_atomic_inline()) - return alphabetic_baseline; - switch (vertical_align) { case CSS::VerticalAlign::Baseline: return alphabetic_baseline; diff --git a/Tests/LibWeb/Layout/expected/table/vertical-align-middle-td-vs-div.txt b/Tests/LibWeb/Layout/expected/table/vertical-align-middle-td-vs-div.txt new file mode 100644 index 00000000000..96fad1bceae --- /dev/null +++ b/Tests/LibWeb/Layout/expected/table/vertical-align-middle-td-vs-div.txt @@ -0,0 +1,35 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x600 [BFC] children: not-inline + BlockContainer at (8,8) content-size 784x204 children: not-inline + TableWrapper <(anonymous)> at (8,8) content-size 42.84375x104 [BFC] children: not-inline + Box at (8,8) content-size 42.84375x104 table-box [TFC] children: not-inline + Box at (10,10) content-size 38.84375x100 table-row-group children: not-inline + Box at (10,10) content-size 38.84375x100 table-row children: not-inline + BlockContainer
at (11,51.5) content-size 36.84375x17 table-cell [BFC] children: not-inline + BlockContainer <(anonymous)> at (11,51.5) content-size 36.84375x17 children: inline + frag 0 from TextNode start: 0, length: 5, rect: [11,51.5 36.84375x17] baseline: 13.296875 + "hello" + TextNode <#text> + BlockContainer <(anonymous)> at (8,112) content-size 784x0 children: inline + TextNode <#text> + BlockContainer
at (8,112) content-size 784x100 children: inline + frag 0 from TextNode start: 0, length: 5, rect: [8,112 36.84375x17] baseline: 13.296875 + "hello" + TextNode <#text> + BlockContainer <(anonymous)> at (8,212) content-size 784x0 children: inline + TextNode <#text> + +ViewportPaintable (Viewport<#document>) [0,0 800x600] + PaintableWithLines (BlockContainer) [0,0 800x600] + PaintableWithLines (BlockContainer) [8,8 784x204] + PaintableWithLines (TableWrapper(anonymous)) [8,8 42.84375x104] + PaintableBox (Box) [8,8 42.84375x104] + PaintableBox (Box) [10,10 38.84375x100] + PaintableBox (Box) [10,10 38.84375x100] + PaintableWithLines (BlockContainer
) [10,10 38.84375x100] + PaintableWithLines (BlockContainer(anonymous)) [11,51.5 36.84375x17] + TextPaintable (TextNode<#text>) + PaintableWithLines (BlockContainer(anonymous)) [8,112 784x0] + PaintableWithLines (BlockContainer
) [8,112 784x100] + TextPaintable (TextNode<#text>) + PaintableWithLines (BlockContainer(anonymous)) [8,212 784x0] diff --git a/Tests/LibWeb/Layout/expected/table/vertical-align-middle-vs-top.txt b/Tests/LibWeb/Layout/expected/table/vertical-align-middle-vs-top.txt new file mode 100644 index 00000000000..0a3c01b052a --- /dev/null +++ b/Tests/LibWeb/Layout/expected/table/vertical-align-middle-vs-top.txt @@ -0,0 +1,31 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x129 [BFC] children: not-inline + BlockContainer at (8,8) content-size 784x113 children: not-inline + BlockContainer
at (8,8) content-size 784x113 children: not-inline + TableWrapper <(anonymous)> at (8,8) content-size 346.5x113 [BFC] children: not-inline + Box at (8,8) content-size 346.5x113 table-box [TFC] children: not-inline + Box at (10,10) content-size 342.5x109 table-row-group children: not-inline + Box at (10,10) content-size 342.5x109 table-row children: not-inline + BlockContainer
at (10,10) content-size 342.5x109 table-cell [BFC] children: not-inline + BlockContainer <(anonymous)> at (10,10) content-size 342.5x109 children: inline + frag 0 from TextNode start: 0, length: 3, rect: [10,10 169.734375x109] baseline: 84.484375 + "foo" + TextNode <#text> + InlineNode + frag 0 from TextNode start: 0, length: 3, rect: [179.734375,10 172.765625x109] baseline: 84.484375 + "bar" + TextNode <#text> + +ViewportPaintable (Viewport<#document>) [0,0 800x600] + PaintableWithLines (BlockContainer) [0,0 800x129] + PaintableWithLines (BlockContainer) [8,8 784x113] + PaintableWithLines (BlockContainer
) [8,8 784x113] + PaintableWithLines (TableWrapper(anonymous)) [8,8 346.5x113] + PaintableBox (Box) [8,8 346.5x113] + PaintableBox (Box) [10,10 342.5x109] + PaintableBox (Box) [10,10 342.5x109] + PaintableWithLines (BlockContainer
) [10,10 342.5x109] + PaintableWithLines (BlockContainer(anonymous)) [10,10 342.5x109] + TextPaintable (TextNode<#text>) + PaintableWithLines (InlineNode) + TextPaintable (TextNode<#text>) diff --git a/Tests/LibWeb/Layout/input/table/vertical-align-middle-td-vs-div.html b/Tests/LibWeb/Layout/input/table/vertical-align-middle-td-vs-div.html new file mode 100644 index 00000000000..894d451ef56 --- /dev/null +++ b/Tests/LibWeb/Layout/input/table/vertical-align-middle-td-vs-div.html @@ -0,0 +1,11 @@ + +
hello
+
hello
diff --git a/Tests/LibWeb/Layout/input/table/vertical-align-middle-vs-top.html b/Tests/LibWeb/Layout/input/table/vertical-align-middle-vs-top.html new file mode 100644 index 00000000000..b970ba19489 --- /dev/null +++ b/Tests/LibWeb/Layout/input/table/vertical-align-middle-vs-top.html @@ -0,0 +1,35 @@ +
foobar