Skip to content

Truly independent web browser

LibWeb: End a run of text after a space at its next wrap opportunity

Andreas Kling7c7e28087311
diff --git a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
index 014ece5dc49..af497cb1f88 100644
--- a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
+++ b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
@@ -1276,7 +1276,7 @@ pub(crate) fn sequence_inline_size(
stop_at_overflow_breakable_text: bool,
) -> Option<CssPixels> {
let mut size = CssPixels::default();
- for item in items {
+ for (index, item) in items.iter().enumerate() {
match item.type_ {
ItemType::ForcedBreak => return Some(CssPixels::default()),
ItemType::BlockLevelBox => break,
@@ -1287,6 +1287,10 @@ pub(crate) fn sequence_inline_size(
if item.type_ != ItemType::Text || item.is_collapsible_whitespace {
break;
}
+ // NB: The sequence ends at its next soft wrap opportunity, such as the one after a hyphen.
+ if index > 0 && item.can_break_before {
+ break;
+ }
if item.is_ascii_whitespace(context) {
break;
}
diff --git a/Tests/LibWeb/Layout/expected/block-and-inline/inline-block-contained-by-abspos-element.txt b/Tests/LibWeb/Layout/expected/block-and-inline/inline-block-contained-by-abspos-element.txt
index 8e7d04a31f4..fb1c1349348 100644
--- a/Tests/LibWeb/Layout/expected/block-and-inline/inline-block-contained-by-abspos-element.txt
+++ b/Tests/LibWeb/Layout/expected/block-and-inline/inline-block-contained-by-abspos-element.txt
@@ -5,12 +5,12 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children
BlockContainer <h1> at [12,45.5] positioned [0+1+0 498 0+1+0] [33.5+1+0 302 0+1+33.5] [BFC] children: inline
frag 0 from BlockContainer start: 0, length: 0, rect: [13,46.5 496x300] baseline: 290.984375
BlockContainer <span> at [13,46.5] inline-block [0+1+0 496 0+1+0] [0+1+0 300 0+1+0] [BFC] children: inline
- frag 0 from TextNode start: 0, length: 9, rect: [13,46.5 246.515625x50] baseline: 39.984375
- "Skew is a"
- frag 1 from TextNode start: 10, length: 10, rect: [13,96.5 240.5625x50] baseline: 39.984375
- "web-first,"
- frag 2 from TextNode start: 21, length: 14, rect: [13,146.5 377.96875x50] baseline: 39.984375
- "cross-platform"
+ frag 0 from TextNode start: 0, length: 14, rect: [13,46.5 383.6875x50] baseline: 39.984375
+ "Skew is a web-"
+ frag 1 from TextNode start: 14, length: 13, rect: [13,96.5 319.8125x50] baseline: 39.984375
+ "first, cross-"
+ frag 2 from TextNode start: 27, length: 8, rect: [13,146.5 211.546875x50] baseline: 39.984375
+ "platform"
frag 3 from TextNode start: 36, length: 11, rect: [13,196.5 314.0625x50] baseline: 39.984375
"programming"
frag 4 from TextNode start: 48, length: 16, rect: [13,246.5 415.765625x50] baseline: 39.984375
diff --git a/Tests/LibWeb/Layout/expected/overflow-with-padding.txt b/Tests/LibWeb/Layout/expected/overflow-with-padding.txt
index bdff527056e..910781fa895 100644
--- a/Tests/LibWeb/Layout/expected/overflow-with-padding.txt
+++ b/Tests/LibWeb/Layout/expected/overflow-with-padding.txt
@@ -19,12 +19,12 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children
"overflow rectangle, the box’s own padding so"
frag 2 from TextNode start: 92, length: 45, rect: [35,189 366.578125x16] baseline: 12.796875
"that when its content is scrolled to the end,"
- frag 3 from TextNode start: 138, length: 44, rect: [35,205 359.828125x16] baseline: 12.796875
- "there is padding between the end-edge of its"
- frag 4 from TextNode start: 183, length: 48, rect: [35,221 391.71875x16] baseline: 12.796875
- "in-flow (or floated) content and the border edge"
- frag 5 from TextNode start: 232, length: 50, rect: [35,237 395.328125x16] baseline: 12.796875
- "of the box. It typically ends up being exactly the"
+ frag 3 from TextNode start: 138, length: 48, rect: [35,205 388.484375x16] baseline: 12.796875
+ "there is padding between the end-edge of its in-"
+ frag 4 from TextNode start: 186, length: 48, rect: [35,221 395.859375x16] baseline: 12.796875
+ "flow (or floated) content and the border edge of"
+ frag 5 from TextNode start: 235, length: 47, rect: [35,237 370.53125x16] baseline: 12.796875
+ "the box. It typically ends up being exactly the"
frag 6 from TextNode start: 283, length: 47, rect: [35,253 399.1875x16] baseline: 12.796875
"same size as the box’s own padding, except in a"
frag 7 from TextNode start: 331, length: 37, rect: [35,269 320.640625x16] baseline: 12.796875
diff --git a/Tests/LibWeb/Layout/expected/soft-wrap-opportunity-after-hyphen-after-space.txt b/Tests/LibWeb/Layout/expected/soft-wrap-opportunity-after-hyphen-after-space.txt
index 00e09c5f9f4..5c2769e861c 100644
--- a/Tests/LibWeb/Layout/expected/soft-wrap-opportunity-after-hyphen-after-space.txt
+++ b/Tests/LibWeb/Layout/expected/soft-wrap-opportunity-after-hyphen-after-space.txt
@@ -1,41 +1,39 @@
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 [0,0] [0+0+0 800 0+0+0] [0+0+0 108 0+0+0] [BFC] children: not-inline
- BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 90 0+0+8] children: not-inline
- BlockContainer <div> at [8,8] [0+0+0 110 0+0+674] [0+0+0 30 0+0+10] children: inline
- frag 0 from TextNode start: 0, length: 3, rect: [8,8 30x10] baseline: 8
- "aaa"
- frag 1 from TextNode start: 4, length: 7, rect: [8,18 70x10] baseline: 8
- "memory-"
- frag 2 from TextNode start: 11, length: 9, rect: [8,28 90x10] baseline: 8
+ BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 98 0+0+0] [BFC] children: not-inline
+ BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 80 0+0+8] children: not-inline
+ BlockContainer <div> at [8,8] [0+0+0 110 0+0+674] [0+0+0 20 0+0+10] children: inline
+ frag 0 from TextNode start: 0, length: 11, rect: [8,8 110x10] baseline: 8
+ "aaa memory-"
+ frag 1 from TextNode start: 11, length: 9, rect: [8,18 90x10] baseline: 8
"efficient"
TextNode <#text> (not painted)
- BlockContainer <(anonymous)> at [8,48] [0+0+0 784 0+0+0] [0+0+0 0 0+0+0] children: inline
+ BlockContainer <(anonymous)> at [8,38] [0+0+0 784 0+0+0] [0+0+0 0 0+0+0] children: inline
TextNode <#text> (not painted)
- BlockContainer <div> at [8,48] [0+0+0 110 0+0+674] [0+0+0 20 0+0+10] children: inline
- frag 0 from TextNode start: 0, length: 3, rect: [8,48 30x10] baseline: 8
+ BlockContainer <div> at [8,38] [0+0+0 110 0+0+674] [0+0+0 20 0+0+10] children: inline
+ frag 0 from TextNode start: 0, length: 3, rect: [8,38 30x10] baseline: 8
"aaa"
- frag 1 from TextNode start: 0, length: 9, rect: [78,58 90x10] baseline: 8
+ frag 1 from TextNode start: 0, length: 9, rect: [78,48 90x10] baseline: 8
"efficient"
TextNode <#text> (not painted)
- InlineNode <b> at [8,58] [0+0+0 70 0+0+0] [0+0+0 10 0+0+0]
- frag 0 from TextNode start: 0, length: 7, rect: [8,58 70x10] baseline: 8
+ InlineNode <b> at [8,48] [0+0+0 70 0+0+0] [0+0+0 10 0+0+0]
+ frag 0 from TextNode start: 0, length: 7, rect: [8,48 70x10] baseline: 8
"memory-"
TextNode <#text> (not painted)
TextNode <#text> (not painted)
- BlockContainer <(anonymous)> at [8,78] [0+0+0 784 0+0+0] [0+0+0 0 0+0+0] children: inline
+ BlockContainer <(anonymous)> at [8,68] [0+0+0 784 0+0+0] [0+0+0 0 0+0+0] children: inline
TextNode <#text> (not painted)
- BlockContainer <div> at [8,78] [0+0+0 110 0+0+674] [0+0+0 20 0+0+10] children: inline
- frag 0 from TextNode start: 0, length: 3, rect: [8,78 30x10] baseline: 8
+ BlockContainer <div> at [8,68] [0+0+0 110 0+0+674] [0+0+0 20 0+0+10] children: inline
+ frag 0 from TextNode start: 0, length: 3, rect: [8,68 30x10] baseline: 8
"aaa"
- frag 1 from TextNode start: 4, length: 7, rect: [8,88 70x10] baseline: 8
+ frag 1 from TextNode start: 4, length: 7, rect: [8,78 70x10] baseline: 8
"memory-"
TextNode <#text> (not painted)
- InlineNode <b> at [78,88] [0+0+0 90 0+0+0] [0+0+0 10 0+0+0]
- frag 0 from TextNode start: 0, length: 9, rect: [78,88 90x10] baseline: 8
+ InlineNode <b> at [78,78] [0+0+0 90 0+0+0] [0+0+0 10 0+0+0]
+ frag 0 from TextNode start: 0, length: 9, rect: [78,78 90x10] baseline: 8
"efficient"
TextNode <#text> (not painted)
- BlockContainer <(anonymous)> at [8,108] [0+0+0 784 0+0+0] [0+0+0 0 0+0+0] children: inline
+ BlockContainer <(anonymous)> at [8,98] [0+0+0 784 0+0+0] [0+0+0 0 0+0+0] children: inline
TextNode <#text> (not painted)
SC for Viewport<#document> [0,0 800x600] (z-index: auto)
- SC for BlockContainer<HTML> [0,0 800x108] (z-index: auto)
+ SC for BlockContainer<HTML> [0,0 800x98] (z-index: auto)