Skip to content

Commit 884b7fc

Browse files
amhnduAtkinsSJ
authored andcommitted
LibWeb: Peek after extracting next chunk in InlineLevelIterator
Peek is used to determine if the current chunk is the last and if so, add trailing box metrics. For this to work correctly, it must be done only after calling next(), otherwise peek gives us the current chunk.
1 parent eeef370 commit 884b7fc

File tree

6 files changed

+41
-13
lines changed

6 files changed

+41
-13
lines changed

Libraries/LibWeb/Layout/InlineLevelIterator.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,10 +497,11 @@ Optional<InlineLevelIterator::Item> InlineLevelIterator::next_without_lookahead(
497497
else
498498
m_text_node_context->is_first_chunk = false;
499499

500+
auto chunk_opt = m_text_node_context->chunk_iterator.next();
501+
500502
if (!m_text_node_context->chunk_iterator.peek(0).has_value())
501503
m_text_node_context->is_last_chunk = true;
502504

503-
auto chunk_opt = m_text_node_context->chunk_iterator.next();
504505
auto is_empty_editable = false;
505506
if (!chunk_opt.has_value()) {
506507
auto const is_only_chunk = m_text_node_context->is_first_chunk && m_text_node_context->is_last_chunk;

Tests/LibWeb/Layout/expected/block-and-inline/inline-block-leading-and-trailing-metrics.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] children: not-
1818
BlockContainer <(anonymous)> at [8,28] [0+0+0 784 0+0+0] [0+0+0 0 0+0+0] children: inline
1919
TextNode <#text> (not painted)
2020
BlockContainer <div#b> at [9,29] [0+1+0 782 0+1+0] [0+1+0 18 0+1+0] children: inline
21-
frag 0 from BlockContainer start: 0, length: 0, rect: [50.296875,29 88.453125x18] baseline: 13.796875
21+
frag 0 from BlockContainer start: 0, length: 0, rect: [70.296875,29 88.453125x18] baseline: 13.796875
2222
InlineNode <i> at [9,29] [0+0+0 41.296875 20+0+0] [0+0+0 18 0+0+0]
2323
frag 0 from TextNode start: 0, length: 6, rect: [9,29 41.296875x18] baseline: 13.796875
2424
"inline"
2525
TextNode <#text> (not painted)
26-
BlockContainer <b> at [50.296875,29] inline-block [0+0+0 88.453125 0+0+0] [0+0+0 18 0+0+0] [BFC] children: inline
27-
frag 0 from TextNode start: 0, length: 12, rect: [50.296875,29 88.453125x18] baseline: 13.796875
26+
BlockContainer <b> at [70.296875,29] inline-block [0+0+0 88.453125 0+0+0] [0+0+0 18 0+0+0] [BFC] children: inline
27+
frag 0 from TextNode start: 0, length: 12, rect: [70.296875,29 88.453125x18] baseline: 13.796875
2828
"inline-block"
2929
TextNode <#text> (not painted)
3030
InlineNode <u> at [158.75,29] [0+0+0 41.296875 0+0+0] [0+0+0 18 0+0+0]
@@ -34,7 +34,7 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] children: not-
3434
BlockContainer <(anonymous)> at [8,48] [0+0+0 784 0+0+0] [0+0+0 0 0+0+0] children: inline
3535
TextNode <#text> (not painted)
3636
BlockContainer <div#c> at [9,49] [0+1+0 782 0+1+0] [0+1+0 18 0+1+0] children: inline
37-
frag 0 from BlockContainer start: 0, length: 0, rect: [111.59375,49 88.453125x18] baseline: 13.796875
37+
frag 0 from BlockContainer start: 0, length: 0, rect: [131.59375,49 88.453125x18] baseline: 13.796875
3838
InlineNode <i> at [9,49] [0+0+0 41.296875 0+0+0] [0+0+0 18 0+0+0]
3939
frag 0 from TextNode start: 0, length: 6, rect: [9,49 41.296875x18] baseline: 13.796875
4040
"inline"
@@ -43,8 +43,8 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] children: not-
4343
frag 0 from TextNode start: 0, length: 6, rect: [70.296875,49 41.296875x18] baseline: 13.796875
4444
"inline"
4545
TextNode <#text> (not painted)
46-
BlockContainer <u> at [111.59375,49] inline-block [0+0+0 88.453125 0+0+0] [0+0+0 18 0+0+0] [BFC] children: inline
47-
frag 0 from TextNode start: 0, length: 12, rect: [111.59375,49 88.453125x18] baseline: 13.796875
46+
BlockContainer <u> at [131.59375,49] inline-block [0+0+0 88.453125 0+0+0] [0+0+0 18 0+0+0] [BFC] children: inline
47+
frag 0 from TextNode start: 0, length: 12, rect: [131.59375,49 88.453125x18] baseline: 13.796875
4848
"inline-block"
4949
TextNode <#text> (not painted)
5050
BlockContainer <(anonymous)> at [8,68] [0+0+0 784 0+0+0] [0+0+0 0 0+0+0] children: inline
@@ -64,7 +64,7 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600]
6464
PaintableWithLines (BlockContainer<DIV>#b) [8,28 784x20]
6565
PaintableWithLines (InlineNode<I>) [9,29 61.296875x18]
6666
TextPaintable (TextNode<#text>)
67-
PaintableWithLines (BlockContainer<B>) [50.296875,29 88.453125x18]
67+
PaintableWithLines (BlockContainer<B>) [70.296875,29 88.453125x18]
6868
TextPaintable (TextNode<#text>)
6969
PaintableWithLines (InlineNode<U>) [158.75,29 41.296875x18]
7070
TextPaintable (TextNode<#text>)
@@ -74,7 +74,7 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600]
7474
TextPaintable (TextNode<#text>)
7575
PaintableWithLines (InlineNode<B>) [50.296875,49 81.296875x18]
7676
TextPaintable (TextNode<#text>)
77-
PaintableWithLines (BlockContainer<U>) [111.59375,49 88.453125x18]
77+
PaintableWithLines (BlockContainer<U>) [131.59375,49 88.453125x18]
7878
TextPaintable (TextNode<#text>)
7979
PaintableWithLines (BlockContainer(anonymous)) [8,68 784x0]
8080

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] children: not-inline
2+
BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 34 0+0+0] [BFC] children: not-inline
3+
BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 18 0+0+8] children: inline
4+
frag 0 from TextNode start: 0, length: 2, rect: [60.15625,8 19.234375x18] baseline: 13.796875
5+
"bu"
6+
InlineNode <span#inline-margin> at [8,8] [0+0+0 27.15625 0+0+25] [0+0+0 18 0+0+0]
7+
frag 0 from TextNode start: 0, length: 3, rect: [8,8 27.15625x18] baseline: 13.796875
8+
"foo"
9+
TextNode <#text> (not painted)
10+
TextNode <#text> (not painted)
11+
12+
ViewportPaintable (Viewport<#document>) [0,0 800x600]
13+
PaintableWithLines (BlockContainer<HTML>) [0,0 800x34]
14+
PaintableWithLines (BlockContainer<BODY>) [8,8 784x18]
15+
PaintableWithLines (InlineNode<SPAN>#inline-margin) [8,8 27.15625x18]
16+
TextPaintable (TextNode<#text>)
17+
TextPaintable (TextNode<#text>)
18+
19+
SC for Viewport<#document> [0,0 800x600] [children: 1] (z-index: auto)
20+
SC for BlockContainer<HTML> [0,0 800x34] [children: 0] (z-index: auto)

Tests/LibWeb/Layout/expected/block-and-inline/leading-margin-on-inline-content-that-starts-with-collapsible-whitespace.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] children: not-
55
frag 0 from TextNode start: 1, length: 9, rect: [28,8 82.125x18] baseline: 13.796875
66
"Download "
77
TextNode <#text> (not painted)
8-
InlineNode <div> at [130.125,8] [20+0+0 39.5625 0+0+20] [0+0+0 18 0+0+0]
9-
frag 0 from TextNode start: 1, length: 4, rect: [130.125,8 39.5625x18] baseline: 13.796875
8+
InlineNode <div> at [150.125,8] [20+0+0 39.5625 0+0+20] [0+0+0 18 0+0+0]
9+
frag 0 from TextNode start: 1, length: 4, rect: [150.125,8 39.5625x18] baseline: 13.796875
1010
"News"
1111
TextNode <#text> (not painted)
1212
TextNode <#text> (not painted)
@@ -16,7 +16,7 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600]
1616
PaintableWithLines (BlockContainer<BODY>) [8,8 784x18]
1717
PaintableWithLines (InlineNode<DIV>) [28,8 82.125x18]
1818
TextPaintable (TextNode<#text>)
19-
PaintableWithLines (InlineNode<DIV>) [130.125,8 39.5625x18]
19+
PaintableWithLines (InlineNode<DIV>) [150.125,8 39.5625x18]
2020
TextPaintable (TextNode<#text>)
2121

2222
SC for Viewport<#document> [0,0 800x600] [children: 1] (z-index: auto)

Tests/LibWeb/Layout/expected/inline-nested-with-padding.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] children: not-
1515
InlineNode <span.b> at [40,44] [0+0+30 130.109375 30+0+0] [0+0+0 18 0+0+0]
1616
frag 0 from TextNode start: 0, length: 2, rect: [40,44 20.515625x18] baseline: 13.796875
1717
"wh"
18-
frag 1 from TextNode start: 0, length: 1, rect: [133.671875,44 6.4375x18] baseline: 13.796875
18+
frag 1 from TextNode start: 0, length: 1, rect: [163.671875,44 6.4375x18] baseline: 13.796875
1919
"f"
2020
TextNode <#text> (not painted)
2121
InlineNode <span.b> at [90.515625,44] [0+0+30 43.15625 30+0+0] [0+0+0 18 0+0+0]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<!DOCTYPE html>
2+
<style>
3+
#inline-margin {
4+
background-color: red;
5+
margin-right: 25px;
6+
}
7+
</style><span id="inline-margin">foo</span>bu

0 commit comments

Comments
 (0)