Skip to content

Truly independent web browser

LibWeb: Allow a soft wrap after an atomic inline

sideshowbarker8d5529a3eec1
diff --git a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
index 2b107c8b87e..b2815fc7a50 100644
--- a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
+++ b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
@@ -686,6 +686,8 @@ struct InlineContentPreparer<'pass> {
/// The text of the text node before the current one, when nothing but inline box boundaries and out-of-flow
/// boxes lies between them.
previous_text: Option<&'pass [u16]>,
+ /// The atomic inline that `previous_text` stands for, if it stands for one.
+ previous_atomic_inline: Option<Node>,
/// Whether the previous text wraps with `word-break: break-all`.
previous_text_breaks_all: bool,
/// The number of regional indicators that end the previous text, including any in the text nodes before it.
@@ -743,6 +745,7 @@ impl<'pass> InlineContentPreparer<'pass> {
walks_within_item: false,
previous_chunk_can_break_after: false,
previous_text: None,
+ previous_atomic_inline: None,
previous_text_breaks_all: false,
previous_text_regional_indicators: 0,
regional_indicators_before_text: 0,
@@ -765,6 +768,22 @@ impl<'pass> InlineContentPreparer<'pass> {
StyleValues::for_node(&self.pass, node)
}
+ /// The nearest node that's an ancestor of both `a` and `b`.
+ fn nearest_common_ancestor(&self, a: Node, b: Node) -> Node {
+ let mut ancestor = self.pass.parent(b);
+ while !ancestor.is_invalid() {
+ let mut node = a;
+ while !node.is_invalid() && node != ancestor {
+ node = self.pass.parent(node);
+ }
+ if node == ancestor {
+ return ancestor;
+ }
+ ancestor = self.pass.parent(ancestor);
+ }
+ self.pass.parent(b)
+ }
+
fn facts(&self, node: Node) -> NodeFacts<'pass> {
NodeFacts::new(&self.pass, node)
}
@@ -1020,6 +1039,7 @@ impl<'pass> InlineContentPreparer<'pass> {
};
self.code_unit_before_previous_text = self.code_unit_before_text;
self.previous_text = Some(text_context.text);
+ self.previous_atomic_inline = None;
self.previous_text_breaks_all =
text_context.should_wrap_lines && text_context.style.word_break() == word_break::BREAK_ALL;
}
@@ -1122,10 +1142,30 @@ impl<'pass> InlineContentPreparer<'pass> {
};
self.code_unit_before_text = self.previous_text.and_then(|text| text.last().copied());
}
+ // https://drafts.csswg.org/css-text-3/#valdef-white-space-nowrap
+ // "For soft wrap opportunities defined by the boundary between two characters or atomic inlines, the
+ // white-space property on the nearest common ancestor of the two characters controls breaking"
+ // NB: The caret chunk of an empty text node has no characters to break before, so the boundary stays for the
+ // text after it.
+ let keeps_boundary = text_context.text.is_empty();
+ let previous_atomic_inline = if keeps_boundary {
+ None
+ } else {
+ self.previous_atomic_inline.take()
+ };
+ let wraps_at_boundary = match previous_atomic_inline {
+ Some(atomic_inline) if is_first_chunk => {
+ self.style(self.nearest_common_ancestor(atomic_inline, text_node))
+ .text_wrap_mode()
+ == text_wrap_mode::WRAP
+ }
+ _ => text_context.should_wrap_lines,
+ };
if is_first_chunk
&& !can_break_before
+ && !keeps_boundary
&& let Some(previous_text) = self.previous_text.take()
- && (text_context.should_wrap_lines || self.previous_text_breaks_all)
+ && (wraps_at_boundary || self.previous_text_breaks_all)
{
let style = text_context.style;
let line_break_language = if style.line_break() == line_break::LOOSE {
@@ -1144,11 +1184,18 @@ impl<'pass> InlineContentPreparer<'pass> {
line_break_language,
)
};
- can_break_before = (text_context.should_wrap_lines && opportunity_with(style.word_break()))
- || (self.previous_text_breaks_all && opportunity_with(word_break::BREAK_ALL));
+ can_break_before = (wraps_at_boundary && opportunity_with(style.word_break()))
+ || (self.previous_text_breaks_all && opportunity_with(word_break::BREAK_ALL))
+ // NB: UAX #14 keeps U+00A0 NO-BREAK SPACE with U+FFFC, but CSS Text has a soft wrap opportunity
+ // between an atomic inline and it.
+ || (wraps_at_boundary
+ && std::ptr::eq(previous_text, OBJECT_REPLACEMENT_CHARACTER.as_slice())
+ && full_text.get(chunk.start) == Some(&0x00A0));
+ }
+ if !keeps_boundary {
+ self.previous_text = None;
+ self.previous_chunk_can_break_after = chunk.can_break_after;
}
- self.previous_text = None;
- self.previous_chunk_can_break_after = chunk.can_break_after;
if can_break_before {
flags |= PreparedItem::CAN_BREAK_BEFORE;
}
@@ -1200,6 +1247,7 @@ impl<'pass> InlineContentPreparer<'pass> {
}
if facts.is_break_node() {
self.previous_text = None;
+ self.previous_atomic_inline = None;
self.skip_to_next_within_item();
return Some(PreparedItem::new(ItemType::ForcedBreak, node, 0));
}
@@ -1223,10 +1271,24 @@ impl<'pass> InlineContentPreparer<'pass> {
}
if facts.is_inline_flow_interrupting_block() {
self.previous_text = None;
+ self.previous_atomic_inline = None;
self.skip_to_next_within_item();
return Some(PreparedItem::new(ItemType::BlockLevelBox, node, 0));
}
- self.previous_text = None;
+ // https://drafts.csswg.org/css-text-3/#line-break-details
+ // "For Web-compatibility there is a soft wrap opportunity before and after each replaced element or other
+ // atomic inline, even when adjacent to a character that would normally suppress them, including U+00A0
+ // NO-BREAK SPACE. However, with the exception of U+00A0 NO-BREAK SPACE, there must be no soft wrap
+ // opportunity between atomic inlines and adjacent characters belonging to the Unicode GL, WJ, or ZWJ line
+ // breaking classes."
+ // NB: The line breaker allows the break before the box. For the one after it, the box stands in the text
+ // before what follows it as U+FFFC OBJECT REPLACEMENT CHARACTER, which UAX #14 lets text break from
+ // except for those classes, and which the text's own line breaking properties then decide.
+ self.previous_text = Some(&OBJECT_REPLACEMENT_CHARACTER);
+ self.previous_atomic_inline = Some(node);
+ self.previous_text_breaks_all = false;
+ self.previous_text_regional_indicators = 0;
+ self.code_unit_before_previous_text = None;
self.skip_to_next_within_item();
return Some(PreparedItem::new(
ItemType::Element,
@@ -2103,3 +2165,6 @@ fn inline_extent_without_removed_whitespace<'item>(
}
extent.unwrap_or_default()
}
+
+/// What an atomic inline stands for in the text around it when looking for soft wrap opportunities.
+static OBJECT_REPLACEMENT_CHARACTER: [u16; 1] = [0xFFFC];
diff --git a/Tests/LibWeb/Layout/expected/list-item-inside-marker-wraps.txt b/Tests/LibWeb/Layout/expected/list-item-inside-marker-wraps.txt
new file mode 100644
index 00000000000..d5291bf0279
--- /dev/null
+++ b/Tests/LibWeb/Layout/expected/list-item-inside-marker-wraps.txt
@@ -0,0 +1,18 @@
+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 82 0+0+0] [BFC] children: not-inline
+ BlockContainer <body> at [8,16] [8+0+0 784 0+0+8] [8+0+0 50 0+0+8] children: not-inline
+ BlockContainer <ul> at [49,17] [0+1+40 16 0+1+726] [16+1+0 48 0+1+16] children: not-inline
+ ListItemBox <li> at [49,17] [0+0+0 16 0+0+0] [0+0+0 48 0+0+0] children: inline
+ frag 0 from ListItemMarkerBox start: 0, length: 0, rect: [49,17 13.84375x16] baseline: 12.796875
+ frag 1 from TextNode start: 0, length: 4, rect: [49,33 37.578125x16] baseline: 12.796875
+ "Text"
+ frag 2 from TextNode start: 5, length: 4, rect: [49,49 39.671875x16] baseline: 12.796875
+ "More"
+ ListItemMarkerBox <(anonymous)> at [49,17] [0+0+0 13.84375 0+0+0] [0+0+0 16 0+0+0] [BFC] children: inline
+ frag 0 from GeneratedTextNode start: 0, length: 2, rect: [49,17 13.84375x16] baseline: 12.796875
+ "• "
+ GeneratedTextNode <(anonymous)> (not painted)
+ TextNode <#text> (not painted)
+
+SC for Viewport<#document> [0,0 800x600] (z-index: auto)
+ SC for BlockContainer<HTML> [0,0 800x82] (z-index: auto)
diff --git a/Tests/LibWeb/Layout/expected/text-wraps-after-atomic-inline.txt b/Tests/LibWeb/Layout/expected/text-wraps-after-atomic-inline.txt
new file mode 100644
index 00000000000..7a9e917e352
--- /dev/null
+++ b/Tests/LibWeb/Layout/expected/text-wraps-after-atomic-inline.txt
@@ -0,0 +1,11 @@
+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 67.40625 0+0+0] [BFC] children: not-inline
+ BlockContainer <body> at [8,8] [8+0+0 200 0+0+592] [8+0+0 51.40625 0+0+8] children: inline
+ frag 0 from BlockContainer start: 0, length: 0, rect: [8,8 200x32] baseline: 32
+ frag 1 from TextNode start: 0, length: 18, rect: [8,43 156.546875x16] baseline: 12.796875
+ "I am below the box"
+ BlockContainer <div> at [8,8] inline-block [0+0+0 200 0+0+0] [0+0+0 32 0+0+0] [BFC] children: not-inline
+ TextNode <#text> (not painted)
+
+SC for Viewport<#document> [0,0 800x600] (z-index: auto)
+ SC for BlockContainer<HTML> [0,0 800x67.40625] (z-index: auto)
diff --git a/Tests/LibWeb/Layout/input/list-item-inside-marker-wraps.html b/Tests/LibWeb/Layout/input/list-item-inside-marker-wraps.html
new file mode 100644
index 00000000000..f670f9885cb
--- /dev/null
+++ b/Tests/LibWeb/Layout/input/list-item-inside-marker-wraps.html
@@ -0,0 +1,3 @@
+<!DOCTYPE html><style>
+ ul { width: 1rem; border: 1px solid black; list-style-position: inside; }
+</style><ul><li>Text More</li></ul>
diff --git a/Tests/LibWeb/Layout/input/text-wraps-after-atomic-inline.html b/Tests/LibWeb/Layout/input/text-wraps-after-atomic-inline.html
new file mode 100644
index 00000000000..3d234e15b4d
--- /dev/null
+++ b/Tests/LibWeb/Layout/input/text-wraps-after-atomic-inline.html
@@ -0,0 +1,4 @@
+<!DOCTYPE html><style>
+ body { max-width: 200px; }
+ div { background: red; display: inline-block; width: 100%; height: 32px; }
+</style><div></div>I am below the box
diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/line-breaking/reference/line-breaking-atomic-007-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/line-breaking/reference/line-breaking-atomic-007-ref.html
new file mode 100644
index 00000000000..edcad69b222
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/line-breaking/reference/line-breaking-atomic-007-ref.html
@@ -0,0 +1,16 @@
+<!doctype html>
+<html>
+<meta charset="utf-8">
+<title>Test reference</title>
+<link rel=author title="Florian Rivoal" href="https://florian.rivoal.net">
+<link rel="stylesheet" type="text/css" href="../../../../fonts/ahem.css" />
+<style>
+div {
+ font: 50px/1 Ahem;
+ color: green;
+}
+</style>
+
+<p>Test passes if there is a green rectangle and <strong>no red</strong>.
+
+<div>A<br>B<br>C</div>
diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/line-breaking/reference/line-breaking-atomic-008-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/line-breaking/reference/line-breaking-atomic-008-ref.html
new file mode 100644
index 00000000000..edcad69b222
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/line-breaking/reference/line-breaking-atomic-008-ref.html
@@ -0,0 +1,16 @@
+<!doctype html>
+<html>
+<meta charset="utf-8">
+<title>Test reference</title>
+<link rel=author title="Florian Rivoal" href="https://florian.rivoal.net">
+<link rel="stylesheet" type="text/css" href="../../../../fonts/ahem.css" />
+<style>
+div {
+ font: 50px/1 Ahem;
+ color: green;
+}
+</style>
+
+<p>Test passes if there is a green rectangle and <strong>no red</strong>.
+
+<div>A<br>B<br>C</div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-001.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-001.html
new file mode 100644
index 00000000000..bbe66e7c804
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-001.html
@@ -0,0 +1,25 @@
+<!doctype html>
+<html>
+<meta charset="utf-8">
+<title>CSS Text — NBSP before atomic inline</title>
+<meta name=assert content="There's a soft wrap opportunity between an atomic inline and a preceeding NBSP">
+<link rel=help href="https://www.w3.org/TR/css-text-3/#line-break-details">
+<link rel=match href="../../../../../expected/wpt-import/css/css-text/line-breaking/../../reference/ref-filled-green-100px-square.xht">
+<link rel=author title="Florian Rivoal" href="https://florian.rivoal.net">
+<link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css" />
+<style>
+div {
+ font: 50px/1 Ahem;
+ color: green;
+ width: 100px;
+ height: 100px;
+ background: red;
+}
+span {
+ display: inline-block;
+}
+</style>
+
+<p>Test passes if there is a filled green square and <strong>no red</strong>.
+
+<div>AB&nbsp;<span>CD</span></div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-002.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-002.html
new file mode 100644
index 00000000000..98fbfdf5e14
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-002.html
@@ -0,0 +1,34 @@
+<!doctype html>
+<html>
+<meta charset="utf-8">
+<title>CSS Text — NBSP after atomic inline</title>
+<meta name=assert content="There's a soft wrap opportunity between an atomic inline and a following NBSP">
+<link rel=help href="https://www.w3.org/TR/css-text-3/#line-break-details">
+<link rel=match href="../../../../../expected/wpt-import/css/css-text/line-breaking/../../reference/ref-filled-green-100px-square.xht">
+<link rel=author title="Florian Rivoal" href="https://florian.rivoal.net">
+<link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css" />
+<style>
+.red {
+ width: 100px;
+ height: 100px;
+ background: red;
+ position: absolute;
+ z-index: -1;
+}
+
+.test {
+ font: 50px/1 Ahem;
+ color: green;
+ width: 100px;
+ height: 100px;
+ margin-left: -50px;
+}
+span {
+ display: inline-block;
+}
+</style>
+
+<p>Test passes if there is a filled green square and <strong>no red</strong>.
+
+<div class=red></div>
+<div class=test><span>&nbsp;AB</span>&nbsp;CD</div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-004.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-004.html
new file mode 100644
index 00000000000..26ecb7ea75d
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-004.html
@@ -0,0 +1,25 @@
+<!doctype html>
+<html>
+<meta charset="utf-8">
+<title>CSS Text — NARROW NO-BREAK SPACE before atomic inline</title>
+<meta name=assert content="There is no soft wrap opportunity between an atomic inline and a following NARROW NO-BREAK SPACE">
+<link rel=help href="https://www.w3.org/TR/css-text-3/#line-break-details">
+<link rel=match href="../../../../../expected/wpt-import/css/css-text/line-breaking/../../reference/ref-filled-green-100px-square.xht">
+<link rel=author title="Florian Rivoal" href="https://florian.rivoal.net">
+<link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css" />
+<style>
+div {
+ font: 100px/1 Ahem;
+ color: transparent;
+ width: 100px;
+ background: red;
+}
+span {
+ display: inline-block;
+ color: green;
+}
+</style>
+
+<p>Test passes if there is a filled green square and <strong>no red</strong>.
+
+<div><span>A</span>&#8239;B</div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-005.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-005.html
new file mode 100644
index 00000000000..0addcf8b0b5
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-005.html
@@ -0,0 +1,25 @@
+<!doctype html>
+<html>
+<meta charset="utf-8">
+<title>CSS Text — WORD JOINER after atomic inline</title>
+<meta name=assert content="There is no soft wrap opportunity between an atomic inline and a following WORD JOINER">
+<link rel=help href="https://www.w3.org/TR/css-text-3/#line-break-details">
+<link rel=match href="../../../../../expected/wpt-import/css/css-text/line-breaking/../../reference/ref-filled-green-100px-square.xht">
+<link rel=author title="Florian Rivoal" href="https://florian.rivoal.net">
+<link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css" />
+<style>
+div {
+ font: 100px/1 Ahem;
+ color: transparent;
+ width: 100px;
+ background: red;
+}
+span {
+ display: inline-block;
+ color: green;
+}
+</style>
+
+<p>Test passes if there is a filled green square and <strong>no red</strong>.
+
+<div><span>A</span>&#8288;B</div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-007.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-007.html
new file mode 100644
index 00000000000..22678de4f63
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-007.html
@@ -0,0 +1,25 @@
+<!doctype html>
+<html>
+<meta charset="utf-8">
+<title>CSS Text — atomic inline line breaks before and after</title>
+<meta name=assert content="There's a soft wrap opportunity before and after an atomic inline">
+<link rel=match href="../../../../../expected/wpt-import/css/css-text/line-breaking/reference/line-breaking-atomic-007-ref.html">
+<link rel=help href="https://www.w3.org/TR/css-text-3/#line-break-details">
+<link rel=author title="Florian Rivoal" href="https://florian.rivoal.net">
+<link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css" />
+<style>
+div {
+ font: 50px/1 Ahem;
+ width: 40px;
+ height: 140px;
+ background: red;
+ color: green;
+}
+span {
+ display: inline-block;
+}
+</style>
+
+<p>Test passes if there is a green rectangle and <strong>no red</strong>.
+
+<div>A<span>B</span>C</div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-008.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-008.html
new file mode 100644
index 00000000000..8b4e64e5a39
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-008.html
@@ -0,0 +1,33 @@
+<!doctype html>
+<html>
+<meta charset="utf-8">
+<title>CSS Text — atomic inline line not affected by keep-all</title>
+<meta name=assert content="There is a soft wrap opportunity before and after an atomic inline even when word-break is keep-all">
+<link rel=match href="../../../../../expected/wpt-import/css/css-text/line-breaking/reference/line-breaking-atomic-008-ref.html">
+<link rel=help href="https://www.w3.org/TR/css-text-3/#line-break-details">
+<link rel=help href="https://drafts.csswg.org/css-text-3/#valdef-word-break-keep-all">
+<link rel=author title="Florian Rivoal" href="https://florian.rivoal.net">
+<link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css" />
+<style>
+div {
+ font: 50px/1 Ahem;
+}
+.red {
+ position: absolute;
+ z-index: -1;
+ color: red;
+}
+.test {
+ width: 0;
+ color: green;
+ word-break: keep-all;
+}
+span {
+ display: inline-block;
+}
+</style>
+
+<p>Test passes if there is a green rectangle and <strong>no red</strong>.
+
+<div class=red>A<br>B<br>C</div>
+<div class=test>A<span>B</span>C</div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-010.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-010.html
new file mode 100644
index 00000000000..70b1cbbd8f8
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-010.html
@@ -0,0 +1,25 @@
+<!doctype html>
+<html>
+<meta charset="utf-8">
+<title>CSS Text — ZERO WIDTH JOINER after atomic inline</title>
+<meta name=assert content="There is no soft wrap opportunity between an atomic inline and a following ZERO WIDTH JOINER">
+<link rel=help href="https://www.w3.org/TR/css-text-3/#line-break-details">
+<link rel=match href="../../../../../expected/wpt-import/css/css-text/line-breaking/../../reference/ref-filled-green-100px-square.xht">
+<link rel=author title="Florian Rivoal" href="https://florian.rivoal.net">
+<link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css" />
+<style>
+div {
+ font: 100px/1 Ahem;
+ color: transparent;
+ width: 100px;
+ background: red;
+}
+span {
+ display: inline-block;
+ color: green;
+}
+</style>
+
+<p>Test passes if there is a filled green square and <strong>no red</strong>.
+
+<div><span>A</span>&#x200D;B</div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-012.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-012.html
new file mode 100644
index 00000000000..3c1ec7ceb46
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-012.html
@@ -0,0 +1,25 @@
+<!doctype html>
+<html>
+<meta charset="utf-8">
+<title>CSS Text — ZERO WIDTH NO-BREAK SPACE after atomic inline</title>
+<meta name=assert content="There is no soft wrap opportunity between an atomic inline and a following ZERO WIDTH NO-BREAK SPACE">
+<link rel=help href="https://www.w3.org/TR/css-text-3/#line-break-details">
+<link rel=match href="../../../../../expected/wpt-import/css/css-text/line-breaking/../../reference/ref-filled-green-100px-square.xht">
+<link rel=author title="Florian Rivoal" href="https://florian.rivoal.net">
+<link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css" />
+<style>
+div {
+ font: 100px/1 Ahem;
+ color: transparent;
+ width: 100px;
+ background: red;
+}
+span {
+ display: inline-block;
+ color: green;
+}
+</style>
+
+<p>Test passes if there is a filled green square and <strong>no red</strong>.
+
+<div><span>A</span>&#xFEFF;B</div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-015.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-015.html
new file mode 100644
index 00000000000..3edd56cdf43
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-015.html
@@ -0,0 +1,25 @@
+<!doctype html>
+<html>
+<meta charset="utf-8">
+<title>CSS Text — MONGOLIAN VOWEL SEPARATOR before atomic inline</title>
+<meta name=assert content="There is no soft wrap opportunity between an atomic inline and a following MONGOLIAN VOWEL SEPARATOR">
+<link rel=help href="https://www.w3.org/TR/css-text-3/#line-break-details">
+<link rel=match href="../../../../../expected/wpt-import/css/css-text/line-breaking/../../reference/ref-filled-green-100px-square.xht">
+<link rel=author title="Florian Rivoal" href="https://florian.rivoal.net">
+<link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css" />
+<style>
+div {
+ font: 100px/1 Ahem;
+ color: transparent;
+ width: 100px;
+ background: red;
+}
+span {
+ display: inline-block;
+ color: green;
+}
+</style>
+
+<p>Test passes if there is a filled green square and <strong>no red</strong>.
+
+<div><span>A</span>&#x180E;B</div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-017.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-017.html
new file mode 100644
index 00000000000..8d5ae7f161e
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-017.html
@@ -0,0 +1,25 @@
+<!doctype html>
+<html>
+<meta charset="utf-8">
+<title>CSS Text — COMBINING GRAPHEME JOINER before atomic inline</title>
+<meta name=assert content="There is no soft wrap opportunity between an atomic inline and a following COMBINING GRAPHEME JOINER">
+<link rel=help href="https://www.w3.org/TR/css-text-3/#line-break-details">
+<link rel=match href="../../../../../expected/wpt-import/css/css-text/line-breaking/../../reference/ref-filled-green-100px-square.xht">
+<link rel=author title="Florian Rivoal" href="https://florian.rivoal.net">
+<link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css" />
+<style>
+div {
+ font: 100px/1 Ahem;
+ color: transparent;
+ width: 100px;
+ background: red;
+}
+span {
+ display: inline-block;
+ color: green;
+}
+</style>
+
+<p>Test passes if there is a filled green square and <strong>no red</strong>.
+
+<div><span>A</span>&#x034F;B</div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-019.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-019.html
new file mode 100644
index 00000000000..58910b237e8
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-019.html
@@ -0,0 +1,25 @@
+<!doctype html>
+<html>
+<meta charset="utf-8">
+<title>CSS Text — FIGURE SPACE before atomic inline</title>
+<meta name=assert content="There is no soft wrap opportunity between an atomic inline and a following FIGURE SPACE (class GL)">
+<link rel=help href="https://www.w3.org/TR/css-text-3/#line-break-details">
+<link rel=match href="../../../../../expected/wpt-import/css/css-text/line-breaking/../../reference/ref-filled-green-100px-square.xht">
+<link rel=author title="Florian Rivoal" href="https://florian.rivoal.net">
+<link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css" />
+<style>
+div {
+ font: 100px/1 Ahem;
+ color: transparent;
+ width: 100px;
+ background: red;
+}
+span {
+ display: inline-block;
+ color: green;
+}
+</style>
+
+<p>Test passes if there is a filled green square and <strong>no red</strong>.
+
+<div><span>A</span>&#x2007;B</div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-021.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-021.html
new file mode 100644
index 00000000000..583c3f34e9b
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-021.html
@@ -0,0 +1,25 @@
+<!doctype html>
+<html>
+<meta charset="utf-8">
+<title>CSS Text — NON-BREAKING HYPHEN before atomic inline</title>
+<meta name=assert content="There is no soft wrap opportunity between an atomic inline and a following NON-BREAKING HYPHEN">
+<link rel=help href="https://www.w3.org/TR/css-text-3/#line-break-details">
+<link rel=match href="../../../../../expected/wpt-import/css/css-text/line-breaking/../../reference/ref-filled-green-100px-square.xht">
+<link rel=author title="Florian Rivoal" href="https://florian.rivoal.net">
+<link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css" />
+<style>
+div {
+ font: 100px/1 Ahem;
+ color: transparent;
+ width: 100px;
+ background: red;
+}
+span {
+ display: inline-block;
+ color: green;
+}
+</style>
+
+<p>Test passes if there is a filled green square and <strong>no red</strong>.
+
+<div><span>A</span>&#x2011;B</div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-023.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-023.html
new file mode 100644
index 00000000000..eb12fca95cd
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-023.html
@@ -0,0 +1,25 @@
+<!doctype html>
+<html>
+<meta charset="utf-8">
+<title>CSS Text — TIBETAN MARK SBRUL SHAD before atomic inline</title>
+<meta name=assert content="There is no soft wrap opportunity between an atomic inline and a following TIBETAN MARK SBRUL SHAD">
+<link rel=help href="https://www.w3.org/TR/css-text-3/#line-break-details">
+<link rel=match href="../../../../../expected/wpt-import/css/css-text/line-breaking/../../reference/ref-filled-green-100px-square.xht">
+<link rel=author title="Florian Rivoal" href="https://florian.rivoal.net">
+<link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css" />
+<style>
+div {
+ font: 100px/1 Ahem;
+ color: transparent;
+ width: 100px;
+ background: red;
+}
+span {
+ display: inline-block;
+ color: green;
+}
+</style>
+
+<p>Test passes if there is a filled green square and <strong>no red</strong>.
+
+<div><span>A</span>&#x0F08;B</div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-025.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-025.html
new file mode 100644
index 00000000000..a825d1a05d9
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-025.html
@@ -0,0 +1,25 @@
+<!doctype html>
+<html>
+<meta charset="utf-8">
+<title>CSS Text — TIBETAN MARK DELIMITER TSHEG BSTAR before atomic inline</title>
+<meta name=assert content="There is no soft wrap opportunity between an atomic inline and a following TIBETAN MARK DELIMITER TSHEG BSTAR">
+<link rel=help href="https://www.w3.org/TR/css-text-3/#line-break-details">
+<link rel=match href="../../../../../expected/wpt-import/css/css-text/line-breaking/../../reference/ref-filled-green-100px-square.xht">
+<link rel=author title="Florian Rivoal" href="https://florian.rivoal.net">
+<link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css" />
+<style>
+div {
+ font: 100px/1 Ahem;
+ color: transparent;
+ width: 100px;
+ background: red;
+}
+span {
+ display: inline-block;
+ color: green;
+}
+</style>
+
+<p>Test passes if there is a filled green square and <strong>no red</strong>.
+
+<div><span>A</span>&#x0F0C;B</div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-027.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-027.html
new file mode 100644
index 00000000000..b916f5b5316
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-atomic-027.html
@@ -0,0 +1,25 @@
+<!doctype html>
+<html>
+<meta charset="utf-8">
+<title>CSS Text — TIBETAN MARK RGYA GRAM SHAD before atomic inline</title>
+<meta name=assert content="There is no soft wrap opportunity between an atomic inline and a following TIBETAN MARK RGYA GRAM SHAD">
+<link rel=help href="https://www.w3.org/TR/css-text-3/#line-break-details">
+<link rel=match href="../../../../../expected/wpt-import/css/css-text/line-breaking/../../reference/ref-filled-green-100px-square.xht">
+<link rel=author title="Florian Rivoal" href="https://florian.rivoal.net">
+<link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css" />
+<style>
+div {
+ font: 100px/1 Ahem;
+ color: transparent;
+ width: 100px;
+ background: red;
+}
+span {
+ display: inline-block;
+ color: green;
+}
+</style>
+
+<p>Test passes if there is a filled green square and <strong>no red</strong>.
+
+<div><span>A</span>&#x0F12;B</div>
diff --git a/Tests/LibWeb/Text/expected/intrinsic-inline-content-sizing.txt b/Tests/LibWeb/Text/expected/intrinsic-inline-content-sizing.txt
index 5275dff8a72..162362d0da7 100644
--- a/Tests/LibWeb/Text/expected/intrinsic-inline-content-sizing.txt
+++ b/Tests/LibWeb/Text/expected/intrinsic-inline-content-sizing.txt
@@ -21,8 +21,8 @@ nested blocks: 160x40, 50x80, 160x40, 120x60
block interruption: 110x60, 110x60, 110x60, 110x60
atomic constraints: 156x78, 96x98, 156x78, 120x98
atomic percentages: 160x82.75, 50x67, 160x82.75, 120x77.5625
-negative margins: 112x20, 62x40, 112x20, 112x20
-saturated advances: 80x20, 80x20, 80x20, 80x20
+negative margins: 112x20, 42x60, 112x20, 112x20
+saturated advances: 80x20, 50x40, 80x20, 80x20
floats: 200x20, 50x80, 200x20, 120x40
float clearance: 90x40, 50x60, 90x40, 90x40
absolute: 100x20, 50x40, 100x20, 100x20
diff --git a/Tests/LibWeb/Text/expected/soft-wrap-after-atomic-inline.txt b/Tests/LibWeb/Text/expected/soft-wrap-after-atomic-inline.txt
new file mode 100644
index 00000000000..071751d142c
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/soft-wrap-after-atomic-inline.txt
@@ -0,0 +1,8 @@
+plain: wraps after the box
+nowrap: stays on one line
+word-joiner: stays on one line
+no-break-space: wraps after the box
+nowrap-text-after-box: wraps after the box
+wrapping-text-after-box-in-nowrap: stays on one line
+empty-text-in-nowrap-editing-host-after-box: wraps after the box
+supplementary-glue: stays on one line
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/CSS2/linebox/inline-negative-margin-001.txt b/Tests/LibWeb/Text/expected/wpt-import/css/CSS2/linebox/inline-negative-margin-001.txt
index dc4951570a3..68fe4941d41 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/CSS2/linebox/inline-negative-margin-001.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/CSS2/linebox/inline-negative-margin-001.txt
@@ -2,15 +2,14 @@ Harness status: OK
Found 13 tests
-12 Pass
-1 Fail
+13 Pass
Pass [data-expected-height] 1
Pass [data-expected-height] 2
Pass [data-expected-height] 3
Pass [data-expected-height] 4
Pass [data-expected-height] 5
Pass [data-expected-height] 6
-Fail [data-expected-height] 7
+Pass [data-expected-height] 7
Pass [data-expected-height] 8
Pass [data-expected-height] 9
Pass [data-expected-height] 10
diff --git a/Tests/LibWeb/Text/input/soft-wrap-after-atomic-inline.html b/Tests/LibWeb/Text/input/soft-wrap-after-atomic-inline.html
new file mode 100644
index 00000000000..c6ff14039bd
--- /dev/null
+++ b/Tests/LibWeb/Text/input/soft-wrap-after-atomic-inline.html
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<style>
+ .measure { width: min-content; font: 20px/1 serif; }
+ .box { display: inline-block; width: 20px; height: 10px; }
+</style>
+<div class="measure" id="plain"><span class="box"></span>text</div>
+<div class="measure" id="nowrap"><span style="white-space: nowrap"><span class="box"></span>text</span></div>
+<div class="measure" id="word-joiner"><span class="box"></span>&#x2060;text</div>
+<div class="measure" id="no-break-space"><span class="box"></span>&nbsp;text</div>
+<div class="measure" id="nowrap-text-after-box"><span class="box"></span><span style="white-space: nowrap">text</span></div>
+<div class="measure" id="wrapping-text-after-box-in-nowrap" style="white-space: nowrap"><span class="box"></span><span style="white-space: normal">text</span></div>
+<div class="measure" id="empty-text-in-nowrap-editing-host-after-box"><span contenteditable style="white-space: nowrap"><span class="box"></span><span id="empty-text-parent"></span></span>text</div>
+<div class="measure" id="supplementary-glue"><span class="box"></span>&#x1107F;text</div>
+<script src="include.js"></script>
+<script>
+ test(() => {
+ document.getElementById("empty-text-parent").replaceWith(document.createTextNode(""));
+ for (const element of document.querySelectorAll(".measure"))
+ println(`${element.id}: ${element.getBoundingClientRect().height > 25 ? "wraps after the box" : "stays on one line"}`);
+ });
+</script>