Skip to content

Truly independent web browser

LibWeb: Measure text that ends at a forced break when wrapping lines

Tim Ledbetter60715f02bda9
diff --git a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
index 49cb28c47f9..156cdd528b0 100644
--- a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
@@ -2103,7 +2103,9 @@ impl<'context> InlineFormattingContext<'context> {
item_index: item_index + 1,
offset_in_node: 0,
});
- let continuation = iterator.next_inline_run_size(self);
+ let continuation = iterator
+ .next_inline_run_size(self)
+ .map(|_| iterator.next_unbreakable_run_inline_size(self));
line_builder.break_line(line_builder::ForcedBreak::Yes, item.node, continuation);
if !item.node.is_invalid() && self.clear_floating_boxes(item.node) {
line_builder.did_introduce_clearance(self.block_axis_float_clearance.get());
diff --git a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
index af4628e7eff..b73035f9d86 100644
--- a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
+++ b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
@@ -1849,7 +1849,7 @@ pub(crate) fn sequence_inline_size(
let mut size = CssPixels::default();
for (index, item) in items.iter().enumerate() {
match item.type_ {
- ItemType::ForcedBreak => return Some(CssPixels::default()),
+ ItemType::ForcedBreak => return Some(size),
ItemType::BlockLevelBox => break,
_ => {}
}
diff --git a/Tests/LibWeb/Layout/expected/unbreakable-run-across-inline-box-boundaries.txt b/Tests/LibWeb/Layout/expected/unbreakable-run-across-inline-box-boundaries.txt
new file mode 100644
index 00000000000..322f7e9d7b9
--- /dev/null
+++ b/Tests/LibWeb/Layout/expected/unbreakable-run-across-inline-box-boundaries.txt
@@ -0,0 +1,50 @@
+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 288 0+0+0] [BFC] children: not-inline
+ BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 270 0+0+8] children: not-inline
+ BlockContainer <div> at [8,8] [0+0+0 100 0+0+684] [0+0+0 30 0+0+10] children: inline
+ frag 0 from TextNode start: 0, length: 4, rect: [8,8 40x10] baseline: 8
+ "aaaa"
+ frag 1 from TextNode start: 5, length: 4, rect: [8,18 40x10] baseline: 8
+ "bbbb"
+ frag 2 from TextNode start: 0, length: 1, rect: [8,28 10x10] baseline: 8
+ "d"
+ TextNode <#text> (not painted)
+ InlineNode <b> at [48,18] [0+0+0 20 0+0+0] [0+0+0 10 0+0+0]
+ frag 0 from TextNode start: 0, length: 2, rect: [48,18 20x10] baseline: 8
+ "cc"
+ TextNode <#text> (not painted)
+ BreakNode <br> (not painted)
+ TextNode <#text> (not painted)
+ BlockContainer <div> at [8,48] [0+0+0 100 0+0+684] [0+0+0 120 0+0+10] [BFC] children: inline
+ frag 0 from TextNode start: 0, length: 1, rect: [58,48 10x10] baseline: 8
+ "x"
+ frag 1 from TextNode start: 0, length: 1, rect: [8,158 10x10] baseline: 8
+ "c"
+ BlockContainer <span> at [8,48] floating [0+0+0 50 0+0+0] [0+0+0 100 0+0+0] [BFC] children: not-inline
+ TextNode <#text> (not painted)
+ BreakNode <br> (not painted)
+ InlineNode <span> at [8,148] [0+0+0 80 0+0+0] [0+0+0 10 0+0+0]
+ frag 0 from TextNode start: 0, length: 8, rect: [8,148 80x10] baseline: 8
+ "aaaaaaaa"
+ TextNode <#text> (not painted)
+ BreakNode <br> (not painted)
+ TextNode <#text> (not painted)
+ BlockContainer <div> at [8,178] [0+0+0 100 0+0+684] [0+0+0 100 0+0+10] [BFC] children: inline
+ frag 0 from TextNode start: 0, length: 1, rect: [58,178 10x10] baseline: 8
+ "x"
+ frag 1 from TextNode start: 0, length: 1, rect: [58,208 10x10] baseline: 8
+ "c"
+ BlockContainer <span> at [8,178] floating [0+0+0 50 0+0+0] [0+0+0 100 0+0+0] [BFC] children: not-inline
+ TextNode <#text> (not painted)
+ BreakNode <br> (not painted)
+ InlineNode <span> at [58,188] [0+0+0 50 0+0+0] [0+0+0 20 0+0+0]
+ frag 0 from TextNode start: 0, length: 5, rect: [58,188 50x10] baseline: 8
+ "aaaaa"
+ frag 0 from TextNode start: 5, length: 3, rect: [58,198 30x10] baseline: 8
+ "aaa"
+ TextNode <#text> (not painted)
+ BreakNode <br> (not painted)
+ TextNode <#text> (not painted)
+
+SC for Viewport<#document> [0,0 800x600] (z-index: auto)
+ SC for BlockContainer<HTML> [0,0 800x288] (z-index: auto)
diff --git a/Tests/LibWeb/Layout/input/unbreakable-run-across-inline-box-boundaries.html b/Tests/LibWeb/Layout/input/unbreakable-run-across-inline-box-boundaries.html
new file mode 100644
index 00000000000..601ae7ee79a
--- /dev/null
+++ b/Tests/LibWeb/Layout/input/unbreakable-run-across-inline-box-boundaries.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<style>
+ @font-face {
+ font-family: Ahem;
+ src: url("../../Ref/data/fonts/Ahem.ttf");
+ }
+ div {
+ font: 10px/10px Ahem;
+ width: 100px;
+ margin-bottom: 10px;
+ }
+</style>
+<div>aaaa bbbb<b>cc</b><br>d</div>
+<div style="display: flow-root"><span style="float: left; width: 50px; height: 100px"></span>x<br><span>aaaaaaaa</span><br>c</div>
+<div style="display: flow-root; overflow-wrap: anywhere"><span style="float: left; width: 50px; height: 100px"></span>x<br><span>aaaaaaaa</span><br>c</div>