Truly independent web browser
LibWeb: Find a soft wrap opportunity after `word-break: break-all` text
Tim Ledbetter0517e6a64658
diff --git a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rsindex b73035f9d86..b8fed51c616 100644--- a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs+++ b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs@@ -643,6 +643,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]>,+ /// 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.previous_text_regional_indicators: usize,/// The number of regional indicators that end the text before the current text node.@@ -698,6 +700,7 @@ impl<'pass> InlineContentPreparer<'pass> {walks_within_item: false,previous_chunk_can_break_after: false,previous_text: None,+ previous_text_breaks_all: false,previous_text_regional_indicators: 0,regional_indicators_before_text: 0,code_unit_before_previous_text: None,@@ -971,6 +974,8 @@ impl<'pass> InlineContentPreparer<'pass> {};self.code_unit_before_previous_text = self.code_unit_before_text;self.previous_text = Some(text_context.text);+ self.previous_text_breaks_all =+ text_context.should_wrap_lines && text_context.style.word_break() == word_break::BREAK_ALL;}self.text_node_context = None;self.previous_chunk_can_break_after = false;@@ -1061,7 +1066,8 @@ impl<'pass> InlineContentPreparer<'pass> {}let mut can_break_before = self.previous_chunk_can_break_after;// NB: Look for a soft wrap opportunity between the texts of two text nodes, which the chunker of either text- // cannot see. This uses the line breaking properties of the text after it.+ // cannot see. This uses the line breaking properties of the text after it, and `word-break: break-all` text+ // before it also breaks there.if is_first_chunk {self.regional_indicators_before_text = if self.previous_text.is_some() {self.previous_text_regional_indicators@@ -1081,15 +1087,19 @@ impl<'pass> InlineContentPreparer<'pass> {} else {text_chunker::LineBreakLanguage::Other};- can_break_before = text_chunker::soft_wrap_opportunity_between(- previous_text,- &full_text[chunk.start..],- self.code_unit_before_previous_text,- self.regional_indicators_before_text,- style.word_break(),- style.line_break(),- line_break_language,- );+ let opportunity_with = |word_break| {+ text_chunker::soft_wrap_opportunity_between(+ previous_text,+ &full_text[chunk.start..],+ self.code_unit_before_previous_text,+ self.regional_indicators_before_text,+ word_break,+ style.line_break(),+ line_break_language,+ )+ };+ can_break_before = opportunity_with(style.word_break())+ || (self.previous_text_breaks_all && opportunity_with(word_break::BREAK_ALL));}self.previous_text = None;self.previous_chunk_can_break_after = chunk.can_break_after;diff --git a/Tests/LibWeb/Layout/expected/soft-wrap-opportunity-after-break-all-text-node.txt b/Tests/LibWeb/Layout/expected/soft-wrap-opportunity-after-break-all-text-node.txtnew file mode 100644index 00000000000..a52ee3b9016--- /dev/null+++ b/Tests/LibWeb/Layout/expected/soft-wrap-opportunity-after-break-all-text-node.txt@@ -0,0 +1,14 @@+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 36 0+0+0] [BFC] children: not-inline+ BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 20 0+0+8] children: not-inline+ BlockContainer <div> at [8,8] [0+0+0 100 0+0+684] [0+0+0 20 0+0+0] children: inline+ frag 0 from TextNode start: 0, length: 5, rect: [8,18 50x10] baseline: 8+ "bcabe"+ InlineNode <span> at [8,8] [0+0+0 80 0+0+0] [0+0+0 10 0+0+0]+ frag 0 from TextNode start: 0, length: 8, rect: [8,8 80x10] baseline: 8+ "dcedde -"+ TextNode <#text> (not painted)+ TextNode <#text> (not painted)++SC for Viewport<#document> [0,0 800x600] (z-index: auto)+ SC for BlockContainer<HTML> [0,0 800x36] (z-index: auto)diff --git a/Tests/LibWeb/Layout/input/soft-wrap-opportunity-after-break-all-text-node.html b/Tests/LibWeb/Layout/input/soft-wrap-opportunity-after-break-all-text-node.htmlnew file mode 100644index 00000000000..e4960560918--- /dev/null+++ b/Tests/LibWeb/Layout/input/soft-wrap-opportunity-after-break-all-text-node.html@@ -0,0 +1,12 @@+<!DOCTYPE html>+<style>+ @font-face {+ font-family: Ahem;+ src: url("../../Ref/data/fonts/Ahem.ttf");+ }+ div {+ font: 10px/10px Ahem;+ width: 100px;+ }+</style>+<div><span style="word-break: break-all">dcedde -</span>bcabe</div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/word-break/word-break-break-all-inline-009.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/word-break/word-break-break-all-inline-009.htmlnew file mode 100644index 00000000000..d6eccf59490--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/word-break/word-break-break-all-inline-009.html@@ -0,0 +1,34 @@+<!DOCTYPE html>+<html lang=en>+<meta charset="utf-8">+<title>word-break: break-all on inline element</title>+<link rel="author" title="Javier Fernandez Garcia-Boente" href="mailto:[email protected]">+<link rel="help" title="5.2. Breaking Rules for Letters: the word-break property" href="https://drafts.csswg.org/css-text-3/#word-break-property">+<link rel="help" href="https://drafts.csswg.org/css-text-3/#valdef-word-break-break-all">+<meta name="flags" content="Ahem">+<link rel="match" href="../../../../../expected/wpt-import/css/css-text/word-break/reference/word-break-break-all-010-ref.html">+<meta name="assert" content="'overflow-wrap: anywhere' works when specified on inline element">+<link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css" />+<style>+div, span {+ font: 10px / 1 Ahem;+ color: green;+}+.fail {+ position: absolute;+ background: green;+ color: red;+ height: 100px;+ z-index: -1;+}+.testdiv {+ width: 5ch;+}+.test {+ word-break: break-all;+}+</style>++<p>Test passes if there is a <strong>filled green square</strong> and <strong>no red</strong>.</p>+<div class="fail">XXXXXXXXXX<br>XXXXX<br>XXXX<br>XXX</div>+<div class="testdiv">XXXXXXXXXX<span class="test">XXXXXXXXX</span>XXX</div>