Skip to content

Truly independent web browser

LibWeb: Use the common ancestor's `white-space` between text nodes

Tim Ledbetter18e3e86d87f7
diff --git a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
index 4c9ff26cc32..34ac5595a51 100644
--- a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
+++ b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
@@ -720,8 +720,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>,
+ /// The text node that `previous_text` comes from, or the atomic inline that it stands for.
+ previous_node: 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.
@@ -825,7 +825,7 @@ impl<'pass> InlineContentPreparer<'pass> {
walks_within_item: false,
previous_chunk_can_break_after: false,
previous_text: None,
- previous_atomic_inline: None,
+ previous_node: None,
previous_text_breaks_all: false,
previous_text_regional_indicators: 0,
regional_indicators_before_text: 0,
@@ -1126,7 +1126,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_node = Some(text_node);
self.previous_text_breaks_all =
text_context.should_wrap_lines && text_context.style.word_break() == word_break::BREAK_ALL;
}
@@ -1248,14 +1248,14 @@ impl<'pass> InlineContentPreparer<'pass> {
// 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 {
+ let previous_node = if keeps_boundary {
None
} else {
- self.previous_atomic_inline.take()
+ self.previous_node.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))
+ let wraps_at_boundary = match previous_node {
+ Some(previous_node) if is_first_chunk => {
+ self.style(self.nearest_common_ancestor(previous_node, text_node))
.text_wrap_mode()
== text_wrap_mode::WRAP
}
@@ -1265,7 +1265,7 @@ impl<'pass> InlineContentPreparer<'pass> {
&& !can_break_before
&& !keeps_boundary
&& let Some(previous_text) = self.previous_text.take()
- && (wraps_at_boundary || self.previous_text_breaks_all)
+ && wraps_at_boundary
{
let style = text_context.style;
let line_break_language = if style.line_break() == line_break::LOOSE {
@@ -1284,12 +1284,11 @@ impl<'pass> InlineContentPreparer<'pass> {
line_break_language,
)
};
- can_break_before = (wraps_at_boundary && opportunity_with(style.word_break()))
+ can_break_before = 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())
+ || (std::ptr::eq(previous_text, OBJECT_REPLACEMENT_CHARACTER.as_slice())
&& full_text.get(chunk.start) == Some(&0x00A0));
}
if !keeps_boundary {
@@ -1347,7 +1346,7 @@ impl<'pass> InlineContentPreparer<'pass> {
}
if facts.is_break_node() {
self.previous_text = None;
- self.previous_atomic_inline = None;
+ self.previous_node = None;
self.skip_to_next_within_item();
return Some(PreparedItem::new(ItemType::ForcedBreak, node, 0));
}
@@ -1371,7 +1370,7 @@ impl<'pass> InlineContentPreparer<'pass> {
}
if facts.is_inline_flow_interrupting_block() {
self.previous_text = None;
- self.previous_atomic_inline = None;
+ self.previous_node = None;
self.skip_to_next_within_item();
return Some(PreparedItem::new(ItemType::BlockLevelBox, node, 0));
}
@@ -1385,7 +1384,7 @@ impl<'pass> InlineContentPreparer<'pass> {
// 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_node = Some(node);
self.previous_text_breaks_all = false;
self.previous_text_regional_indicators = 0;
self.code_unit_before_previous_text = None;
diff --git a/Tests/LibWeb/Layout/expected/wrap-before-nowrap-text.txt b/Tests/LibWeb/Layout/expected/wrap-before-nowrap-text.txt
index 6829888f1db..e6380b89042 100644
--- a/Tests/LibWeb/Layout/expected/wrap-before-nowrap-text.txt
+++ b/Tests/LibWeb/Layout/expected/wrap-before-nowrap-text.txt
@@ -1,6 +1,6 @@
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 328 0+0+0] [BFC] children: not-inline
- BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 310 0+0+8] children: not-inline
+ BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 388 0+0+0] [BFC] children: not-inline
+ BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 370 0+0+8] children: not-inline
BlockContainer <div> at [8,8] [0+0+0 100 0+0+684] [0+0+0 20 0+0+10] [BFC] children: inline
frag 0 from TextNode start: 0, length: 8, rect: [8,8 80x10] baseline: 8
"aaaaaaaa"
@@ -65,31 +65,52 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children
frag 0 from TextNode start: 0, length: 4, rect: [8,228 40x10] baseline: 8
"bbbb"
TextNode <#text> (not painted)
- BlockContainer <div> at [8,248] [0+0+0 90 0+0+694] [0+0+0 10 0+0+10] [BFC] children: inline
- frag 0 from TextNode start: 0, length: 6, rect: [8,248 60x10] baseline: 8
+ BlockContainer <div.nowrap> at [8,248] [0+0+0 40 0+0+744] [0+0+0 20 0+0+10] [BFC] children: inline
+ frag 0 from TextNode start: 0, length: 4, rect: [18,258 40x10] baseline: 8
+ "bbbb"
+ InlineNode <span> at [8,248] [0+0+0 30 0+0+0] [0+0+0 20 0+0+0]
+ frag 0 from TextNode start: 0, length: 3, rect: [8,248 30x10] baseline: 8
+ "ddd"
+ frag 0 from TextNode start: 3, length: 1, rect: [8,258 10x10] baseline: 8
+ "d"
+ TextNode <#text> (not painted)
+ TextNode <#text> (not painted)
+ BlockContainer <div.nowrap> at [8,278] [0+0+0 40 0+0+744] [0+0+0 20 0+0+10] [BFC] children: inline
+ InlineNode <span> at [8,278] [0+0+0 30 0+0+0] [0+0+0 20 0+0+0]
+ frag 0 from TextNode start: 0, length: 3, rect: [8,278 30x10] baseline: 8
+ "ddd"
+ frag 0 from TextNode start: 3, length: 1, rect: [8,288 10x10] baseline: 8
+ "d"
+ TextNode <#text> (not painted)
+ InlineNode <span> at [18,288] [0+0+0 40 0+0+0] [0+0+0 10 0+0+0]
+ frag 0 from TextNode start: 0, length: 4, rect: [18,288 40x10] baseline: 8
+ "bbbb"
+ TextNode <#text> (not painted)
+ BlockContainer <div> at [8,308] [0+0+0 90 0+0+694] [0+0+0 10 0+0+10] [BFC] children: inline
+ frag 0 from TextNode start: 0, length: 6, rect: [8,308 60x10] baseline: 8
"aaaaaa"
TextNode <#text> (not painted)
- InlineNode <span.nowrap> at [68,248] [0+0+0 30 0+0+0] [0+0+0 10 0+0+0]
- frag 0 from TextNode start: 0, length: 3, rect: [68,248 30x10] baseline: 8
+ InlineNode <span.nowrap> at [68,308] [0+0+0 30 0+0+0] [0+0+0 10 0+0+0]
+ frag 0 from TextNode start: 0, length: 3, rect: [68,308 30x10] baseline: 8
"ccc"
TextNode <#text> (not painted)
- BlockContainer <div> at [8,268] [0+0+0 40 0+0+744] [0+0+0 20 0+0+10] [BFC] children: inline
- InlineNode <span> at [8,268] [0+0+0 40 0+0+0] [0+0+0 10 0+0+0]
- frag 0 from TextNode start: 0, length: 4, rect: [8,268 40x10] baseline: 8
+ BlockContainer <div> at [8,328] [0+0+0 40 0+0+744] [0+0+0 20 0+0+10] [BFC] children: inline
+ InlineNode <span> at [8,328] [0+0+0 40 0+0+0] [0+0+0 10 0+0+0]
+ frag 0 from TextNode start: 0, length: 4, rect: [8,328 40x10] baseline: 8
"dddd"
TextNode <#text> (not painted)
- InlineNode <span.nowrap> at [8,278] [0+0+0 40 0+0+0] [0+0+0 10 0+0+0]
- frag 0 from TextNode start: 0, length: 4, rect: [8,278 40x10] baseline: 8
+ InlineNode <span.nowrap> at [8,338] [0+0+0 40 0+0+0] [0+0+0 10 0+0+0]
+ frag 0 from TextNode start: 0, length: 4, rect: [8,338 40x10] baseline: 8
"bbbb"
TextNode <#text> (not painted)
- BlockContainer <div> at [8,298] [0+0+0 40 0+0+744] [0+0+0 20 0+0+10] [BFC] children: inline
- frag 0 from TextNode start: 0, length: 4, rect: [8,298 40x10] baseline: 8
+ BlockContainer <div> at [8,358] [0+0+0 40 0+0+744] [0+0+0 20 0+0+10] [BFC] children: inline
+ frag 0 from TextNode start: 0, length: 4, rect: [8,358 40x10] baseline: 8
"aaaa"
TextNode <#text> (not painted)
- InlineNode <span.nowrap> at [8,308] [0+0+0 40 0+0+0] [0+0+0 10 0+0+0]
- frag 0 from TextNode start: 0, length: 4, rect: [8,308 40x10] baseline: 8
+ InlineNode <span.nowrap> at [8,368] [0+0+0 40 0+0+0] [0+0+0 10 0+0+0]
+ frag 0 from TextNode start: 0, length: 4, rect: [8,368 40x10] baseline: 8
"bbbb"
TextNode <#text> (not painted)
SC for Viewport<#document> [0,0 800x600] (z-index: auto)
- SC for BlockContainer<HTML> [0,0 800x328] (z-index: auto)
+ SC for BlockContainer<HTML> [0,0 800x388] (z-index: auto)
diff --git a/Tests/LibWeb/Layout/input/wrap-before-nowrap-text.html b/Tests/LibWeb/Layout/input/wrap-before-nowrap-text.html
index 861602a2b36..32f18605fd2 100644
--- a/Tests/LibWeb/Layout/input/wrap-before-nowrap-text.html
+++ b/Tests/LibWeb/Layout/input/wrap-before-nowrap-text.html
@@ -26,6 +26,8 @@
<div>aaaaaaaa<span class="nowrap">dddddd</span></div>
<div style="width: 40px; word-break: break-all">dddd<span class="nowrap">bbbb</span></div>
<div style="width: 40px"><span style="word-break: break-all">dddd</span><span class="nowrap">bbbb</span></div>
+<div class="nowrap" style="width: 40px"><span style="white-space: normal; word-break: break-all">dddd</span>bbbb</div>
+<div class="nowrap" style="width: 40px"><span style="white-space: normal; word-break: break-all">dddd</span><span style="white-space: normal">bbbb</span></div>
<div style="width: 90px; overflow-wrap: anywhere">aaaaaa<span class="nowrap">ccc </span></div>
<div style="width: min-content"><span style="word-break: break-all">dddd</span><span class="nowrap">bbbb</span></div>
<div style="width: min-content; overflow-wrap: anywhere">aaaa<span class="nowrap">bbbb</span></div>
diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/line-breaking/reference/line-breaking-001-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/line-breaking/reference/line-breaking-001-ref.html
new file mode 100644
index 00000000000..b46174bac2f
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/line-breaking/reference/line-breaking-001-ref.html
@@ -0,0 +1,19 @@
+<!doctype html>
+<html>
+<meta charset="utf-8">
+<title>Reference File for line breaking tests</title>
+<link rel=author title="Florian Rivoal" href="http://florian.rivoal.net">
+<link rel="stylesheet" type="text/css" href="../../../../fonts/ahem.css" />
+<style>
+div {
+ color:green;
+ line-height: 1em;
+ font-family: Ahem;
+ font-size: 20px;
+}
+</style>
+<body>
+ <p>There should be a green rectangle and no red.</p>
+ <div>X<br>X</div>
+</body>
+</html>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-009.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-009.html
new file mode 100644
index 00000000000..4381f989b40
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-009.html
@@ -0,0 +1,40 @@
+<!doctype html>
+<html>
+<meta charset="utf-8">
+<title>CSS Text — line breaking at element boundary</title>
+<meta name=assert content="For soft wrap opportunities defined by the boundary between two characters, the white-space property on nearest common ancestor of the two characters controls breaking.">
+<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/line-breaking-001-ref.html">
+<link rel=author title="Florian Rivoal" href="http://florian.rivoal.net">
+<link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css" />
+<style>
+div {
+ color:green;
+ width: 1em;
+ line-height: 1em;
+ font-family: Ahem;
+ white-space: normal;
+ font-size: 20px;
+}
+span {
+ white-space: pre;
+}
+.container {
+ position: relative;
+}
+.fail {
+ color: red;
+ position: absolute;
+ left: 0;
+ top: 1em;
+ z-index: -1;
+}
+</style>
+<body>
+ <p>There should be a green rectangle and no red.</p>
+ <div class=container>
+ <div><span>X</span>&#x200B;<span>X</span></div>
+ <div class=fail>X</div>
+ </div>
+</body>
+</html>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-011.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-011.html
new file mode 100644
index 00000000000..7a371fcb6c4
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/line-breaking/line-breaking-011.html
@@ -0,0 +1,40 @@
+<!doctype html>
+<html>
+<meta charset="utf-8">
+<title>CSS Text — line breaking at element boundary 3</title>
+<meta name=assert content="For soft wrap opportunities defined by the boundary between two characters, the white-space property on nearest common ancestor of the two characters controls breaking.">
+<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/line-breaking-001-ref.html">
+<link rel=author title="Florian Rivoal" href="http://florian.rivoal.net">
+<link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css" />
+<style>
+div {
+ color:green;
+ width: 1em;
+ line-height: 1em;
+ font-family: Ahem;
+ white-space: normal;
+ font-size: 20px;
+}
+span {
+ white-space: pre;
+}
+.container {
+ position: relative;
+}
+.fail {
+ color: red;
+ position: absolute;
+ left: 0;
+ top: 1em;
+ z-index: -1;
+}
+</style>
+<body>
+ <p>There should be a green rectangle and no red.</p>
+ <div class=container>
+ <div>X&#x200B;<span>X<span></div>
+ <div class=fail>X</div>
+ </div>
+</body>
+</html>