A single leading space is not considered as a word break even when word-break: break...
authorjfernandez@igalia.com <jfernandez@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 25 Mar 2019 15:07:35 +0000 (15:07 +0000)
committerjfernandez@igalia.com <jfernandez@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 25 Mar 2019 15:07:35 +0000 (15:07 +0000)
https://bugs.webkit.org/show_bug.cgi?id=195361

Reviewed by Ryosuke Niwa.

LayoutTests/imported/w3c:

Imported additonal WPT from the CSS Text Suite that verify the
change doesn't regress in any case, specially for the word-break:
break-word feature.

* web-platform-tests/css/css-text/overflow-wrap/overflow-wrap-break-word-007-expected.html: Added.
* web-platform-tests/css/css-text/overflow-wrap/overflow-wrap-break-word-007.html: Added.
* web-platform-tests/css/css-text/overflow-wrap/w3c-import.log:
* web-platform-tests/css/css-text/white-space/pre-wrap-008-expected.html: Added.
* web-platform-tests/css/css-text/white-space/pre-wrap-008.html: Added.
* web-platform-tests/css/css-text/white-space/w3c-import.log:
* web-platform-tests/css/css-text/word-break/w3c-import.log:
* web-platform-tests/css/css-text/word-break/word-break-break-all-015-expected.html: Added.
* web-platform-tests/css/css-text/word-break/word-break-break-all-015.html: Added.

Source/WebCore:

We must consider leading white-spaces as potential soft-breaking
opportunities that may avoid breaking in the middle of the word.

However, 'break-word: break-all' [1] implies that we should ignore
previous opportunities and break at any character (among the ones
valid for 'break-all') that prevents the line to overflow. Note,
that these breakable characters are different from the ones
provided by 'line-break: anywhere' [2].

This change is covered by the already existent tests of the CSS
Text 3 suite of the Web Platform Tests.

The word-break-break-all-010.html was precisely designed to cover
the basic issue fixed with this change, verifying that the word is
indeed broken even if a single leading space constitutes a
previous soft-breaking opportunity.

There are other Web Platform Tests. which already pass before this
change, to verify that such leading white-space must be used
instead of breaking the word in any other case, including
overflow-wrap: break-word and even the deprecated word-break:
break-word.

   - white-space/pre-wrap-008.html
   - white-space/pre-wrap-015.html
   - white-space/pre-wrap-016.html
   - overflow-wrap/overflow-wrap-break-word-004.html
   - overflow-wrap/overflow-wrap-break-word-005.html
   - overflow-wrap/overflow-wrap-break-word-007.html
   - word-break/word-break-break-all-011.html
   - word-break/word-break-break-all-014.html

The reason why the word-break-break-all-010.html passes in Mac
platform is that for that case the SimpleLineLayout codepath is
executed instead, which doesn't have this bug, present in the old
line-breaking logic implemented in the BreakingContext class.

In order to verify the validity of this change, I've added several
tests under fast/text with the SimpleLineLayout disabled.

Tests: fast/text/overflow-wrap-break-word-004.html
       fast/text/overflow-wrap-break-word-005.html
       fast/text/overflow-wrap-break-word-007.html
       fast/text/whitespace/pre-wrap-008.html
       fast/text/whitespace/pre-wrap-015.html
       fast/text/whitespace/pre-wrap-016.html
       fast/text/word-break-break-all-010.html
       fast/text/word-break-break-all-011.html
       fast/text/word-break-break-all-015.html
       imported/w3c/web-platform-tests/css/css-text/overflow-wrap/overflow-wrap-break-word-007.html
       imported/w3c/web-platform-tests/css/css-text/white-space/pre-wrap-008.html
       imported/w3c/web-platform-tests/css/css-text/word-break/word-break-break-all-015.html

* rendering/line/BreakingContext.h:
(WebCore::BreakingContext::handleText):

LayoutTests:

Removed some entries from the GTK expectation file.
Added tests to verify the codepath with SimpleLineLayout disabled.

* fast/text/overflow-wrap-break-word-004-expected.html: Added.
* fast/text/overflow-wrap-break-word-004.html: Added.
* fast/text/overflow-wrap-break-word-005-expected.html: Added.
* fast/text/overflow-wrap-break-word-005.html: Added.
* fast/text/overflow-wrap-break-word-007-expected.html: Added.
* fast/text/overflow-wrap-break-word-007.html: Added.
* fast/text/whitespace/pre-wrap-008-expected.html: Added.
* fast/text/whitespace/pre-wrap-008.html: Added.
* fast/text/whitespace/pre-wrap-015-expected.html: Added.
* fast/text/whitespace/pre-wrap-015.html: Added.
* fast/text/whitespace/pre-wrap-016-expected.html: Added.
* fast/text/whitespace/pre-wrap-016.html: Added.
* fast/text/word-break-break-all-010-expected.html: Added.
* fast/text/word-break-break-all-010.html: Added.
* fast/text/word-break-break-all-011-expected.html: Added.
* fast/text/word-break-break-all-011.html: Added.
* fast/text/word-break-break-all-015-expected.html: Added.
* fast/text/word-break-break-all-015.html: Added.
* platform/gtk/TestExpectations:
  - word-break-break-all-010.html passes now thanks to this change.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@243437 268f45cc-cd09-0410-ab3c-d52691b4dbfc

32 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/text/overflow-wrap-break-word-004-expected.html [new file with mode: 0644]
LayoutTests/fast/text/overflow-wrap-break-word-004.html [new file with mode: 0644]
LayoutTests/fast/text/overflow-wrap-break-word-005-expected.html [new file with mode: 0644]
LayoutTests/fast/text/overflow-wrap-break-word-005.html [new file with mode: 0644]
LayoutTests/fast/text/overflow-wrap-break-word-007-expected.html [new file with mode: 0644]
LayoutTests/fast/text/overflow-wrap-break-word-007.html [new file with mode: 0644]
LayoutTests/fast/text/whitespace/pre-wrap-008-expected.html [new file with mode: 0644]
LayoutTests/fast/text/whitespace/pre-wrap-008.html [new file with mode: 0644]
LayoutTests/fast/text/whitespace/pre-wrap-015-expected.html [new file with mode: 0644]
LayoutTests/fast/text/whitespace/pre-wrap-015.html [new file with mode: 0644]
LayoutTests/fast/text/whitespace/pre-wrap-016-expected.html [new file with mode: 0644]
LayoutTests/fast/text/whitespace/pre-wrap-016.html [new file with mode: 0644]
LayoutTests/fast/text/word-break-break-all-010-expected.html [new file with mode: 0644]
LayoutTests/fast/text/word-break-break-all-010.html [new file with mode: 0644]
LayoutTests/fast/text/word-break-break-all-011-expected.html [new file with mode: 0644]
LayoutTests/fast/text/word-break-break-all-011.html [new file with mode: 0644]
LayoutTests/fast/text/word-break-break-all-015-expected.html [new file with mode: 0644]
LayoutTests/fast/text/word-break-break-all-015.html [new file with mode: 0644]
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/css/css-text/overflow-wrap/overflow-wrap-break-word-007-expected.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/css/css-text/overflow-wrap/overflow-wrap-break-word-007.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/css/css-text/overflow-wrap/w3c-import.log
LayoutTests/imported/w3c/web-platform-tests/css/css-text/white-space/pre-wrap-008-expected.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/css/css-text/white-space/pre-wrap-008.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/css/css-text/white-space/w3c-import.log
LayoutTests/imported/w3c/web-platform-tests/css/css-text/word-break/w3c-import.log
LayoutTests/imported/w3c/web-platform-tests/css/css-text/word-break/word-break-break-all-015-expected.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/css/css-text/word-break/word-break-break-all-015.html [new file with mode: 0644]
LayoutTests/platform/gtk/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/rendering/line/BreakingContext.h

index 288d800..3917dde 100644 (file)
@@ -1,3 +1,34 @@
+2019-03-25  Javier Fernandez  <jfernandez@igalia.com>
+
+        A single leading space is not considered as a word break even when word-break: break-all is set
+        https://bugs.webkit.org/show_bug.cgi?id=195361
+
+        Reviewed by Ryosuke Niwa.
+
+        Removed some entries from the GTK expectation file.
+        Added tests to verify the codepath with SimpleLineLayout disabled.
+
+        * fast/text/overflow-wrap-break-word-004-expected.html: Added.
+        * fast/text/overflow-wrap-break-word-004.html: Added.
+        * fast/text/overflow-wrap-break-word-005-expected.html: Added.
+        * fast/text/overflow-wrap-break-word-005.html: Added.
+        * fast/text/overflow-wrap-break-word-007-expected.html: Added.
+        * fast/text/overflow-wrap-break-word-007.html: Added.
+        * fast/text/whitespace/pre-wrap-008-expected.html: Added.
+        * fast/text/whitespace/pre-wrap-008.html: Added.
+        * fast/text/whitespace/pre-wrap-015-expected.html: Added.
+        * fast/text/whitespace/pre-wrap-015.html: Added.
+        * fast/text/whitespace/pre-wrap-016-expected.html: Added.
+        * fast/text/whitespace/pre-wrap-016.html: Added.
+        * fast/text/word-break-break-all-010-expected.html: Added.
+        * fast/text/word-break-break-all-010.html: Added.
+        * fast/text/word-break-break-all-011-expected.html: Added.
+        * fast/text/word-break-break-all-011.html: Added.
+        * fast/text/word-break-break-all-015-expected.html: Added.
+        * fast/text/word-break-break-all-015.html: Added.
+        * platform/gtk/TestExpectations:
+          - word-break-break-all-010.html passes now thanks to this change.
+
 2019-03-25  Diego Pino Garcia  <dpino@igalia.com>
 
         [GTK][WPE] Gardening, update test expectations.
diff --git a/LayoutTests/fast/text/overflow-wrap-break-word-004-expected.html b/LayoutTests/fast/text/overflow-wrap-break-word-004-expected.html
new file mode 100644 (file)
index 0000000..fe87735
--- /dev/null
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text Reference File</title>
+<link rel="author" title="Javier Fernandez Garcia-Boente" href="mailto:jfernandez@igalia.com">
+<style>
+div {
+  position: relative;
+  width: 100px;
+  height: 100px;
+  background: green;
+}
+</style>
+<body>
+  <p>Test passes if there is a <strong>filled green square</strong> and <strong>no red</strong>.</p>
+  <div></div>
+</body>
diff --git a/LayoutTests/fast/text/overflow-wrap-break-word-004.html b/LayoutTests/fast/text/overflow-wrap-break-word-004.html
new file mode 100644 (file)
index 0000000..ce5872f
--- /dev/null
@@ -0,0 +1,42 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text Test: overflow-wrap: break-word</title>
+<link rel="author" title="Javier Fernandez Garcia-Boente" href="mailto:jfernandez@igalia.com">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#valdef-overflow-wrap-break-word">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#valdef-white-space-pre-wrap">
+<meta name="flags" content="ahem">
+<link rel="match" href="reference/overflow-wrap-break-word-001-ref.html">
+<meta name="assert" content="A Single leading white-space constitutes a soft breaking opportunity, honoring the 'white-space: pre-wrap' property, that must prevent the word to be broken.">
+<style>
+div {
+  position: relative;
+  font-size: 20px;
+  font-family: Ahem;
+  line-height: 1em;
+}
+.red {
+  position: absolute;
+  background: green;
+  color: red;
+  width: 100px;
+  height: 100px;
+  z-index: -1;
+}
+.test {
+  color: green;
+  width: 5ch;
+
+  white-space: pre-wrap;
+  overflow-wrap: break-word;
+}
+</style>
+<script>
+// Force line box path.
+if (window.internals)
+    internals.settings.setSimpleLineLayoutEnabled(false);
+</script>
+<body>
+  <p>Test passes if there is a <strong>filled green square</strong> and <strong>no red</strong>.</p>
+  <div class="red"><br>XXXXX</div>
+  <div class="test"> XXXXX </div>
+</body>
diff --git a/LayoutTests/fast/text/overflow-wrap-break-word-005-expected.html b/LayoutTests/fast/text/overflow-wrap-break-word-005-expected.html
new file mode 100644 (file)
index 0000000..fe87735
--- /dev/null
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text Reference File</title>
+<link rel="author" title="Javier Fernandez Garcia-Boente" href="mailto:jfernandez@igalia.com">
+<style>
+div {
+  position: relative;
+  width: 100px;
+  height: 100px;
+  background: green;
+}
+</style>
+<body>
+  <p>Test passes if there is a <strong>filled green square</strong> and <strong>no red</strong>.</p>
+  <div></div>
+</body>
diff --git a/LayoutTests/fast/text/overflow-wrap-break-word-005.html b/LayoutTests/fast/text/overflow-wrap-break-word-005.html
new file mode 100644 (file)
index 0000000..cb342f1
--- /dev/null
@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text Test: overflow-wrap: break-word</title>
+<link rel="author" title="Javier Fernandez Garcia-Boente" href="mailto:jfernandez@igalia.com">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#valdef-overflow-wrap-break-word">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#valdef-white-space-pre-wrap">
+<meta name="flags" content="ahem">
+<link rel="match" href="reference/overflow-wrap-break-word-001-ref.html">
+<meta name="assert" content="A Single leading white-space constitutes a soft breaking opportunity, honoring the 'white-space: pre-wrap' property, that must prevent the word to be broken.">
+<style>
+div {
+  position: relative;
+  font-size: 20px;
+  font-family: Ahem;
+  line-height: 1em;
+}
+.fail {
+  position: absolute;
+  color: red;
+  z-index: -1;
+}
+span { color: green; }
+.test {
+  color: green;
+  width: 5ch;
+
+  white-space: pre-wrap;
+  overflow-wrap: break-word;
+}
+</style>
+<script>
+// Force line box path.
+if (window.internals)
+    internals.settings.setSimpleLineLayoutEnabled(false);
+</script>
+<body>
+  <p>Test passes if there is a <strong>filled green square</strong> and <strong>no red</strong>.</p>
+  <div class="fail">XXX<span>XX<br></span><span>XXXXX<br></span>XXXXX<br>XXXX<span>X<br></span><span>XXXXX</span></div>
+  <div class="test">XXX
+ XXXXXXXXX</div>
+</body>
diff --git a/LayoutTests/fast/text/overflow-wrap-break-word-007-expected.html b/LayoutTests/fast/text/overflow-wrap-break-word-007-expected.html
new file mode 100644 (file)
index 0000000..0e0300a
--- /dev/null
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text Reference File</title>
+<link rel="author" title="Florian Rivoal" href="http://florian.rivoal.net/">
+<style>
+div {
+  position: relative;
+  width: 100px;
+  height: 100px;
+  background: green;
+}
+</style>
+<body>
+  <p>Test passes if there is a <strong>filled green square</strong> and <strong>no red</strong>.</p>
+  <div></div>
+</body>
diff --git a/LayoutTests/fast/text/overflow-wrap-break-word-007.html b/LayoutTests/fast/text/overflow-wrap-break-word-007.html
new file mode 100644 (file)
index 0000000..377bc1a
--- /dev/null
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text Test: overflow-wrap: break-word</title>
+<link rel="author" title="Javier Fernandez Garcia-Boente" href="mailto:jfernandez@igalia.com">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#valdef-overflow-wrap-break-word">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#valdef-white-space-break-spaces">
+<meta name="flags" content="ahem">
+<link rel="match" href="reference/overflow-wrap-break-word-001-ref.html">
+<meta name="assert" content="A Single leading white-space constitutes a soft breaking opportunity, honoring the 'white-space: break-spaces' property, that must prevent the word to be broken.">
+<style>
+div {
+  position: relative;
+  font-size: 20px;
+  font-family: Ahem;
+  line-height: 1em;
+}
+.red {
+  position: absolute;
+  background: green;
+  color: red;
+  width: 100px;
+  height: 100px;
+  z-index: -1;
+  white-space: pre;
+}
+.test {
+  color: green;
+  width: 5ch;
+
+  white-space: pre-wrap;
+  overflow-wrap: break-word;
+}
+</style>
+<script>
+// Force line box path.
+if (window.internals)
+    internals.settings.setSimpleLineLayoutEnabled(false);
+</script>
+<body>
+  <p>Test passes if there is a <strong>filled green square</strong> and <strong>no red</strong>.</p>
+  <div class="red"> XX  <br>XXX</div>
+  <div class="test"> XX XXX </div>
+</body>
diff --git a/LayoutTests/fast/text/whitespace/pre-wrap-008-expected.html b/LayoutTests/fast/text/whitespace/pre-wrap-008-expected.html
new file mode 100644 (file)
index 0000000..3247ae5
--- /dev/null
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text Reference File</title>
+<link rel="author" title="Javier Fernandez" href="mailto:jfernandez@igalia.com" />
+<style>
+div {
+  position: relative;
+  width: 100px;
+  height: 100px;
+  background: green;
+}
+</style>
+<body>
+    <p>Test passes if there is a <strong>filled green square</strong> and <strong>no red</strong>.</p>
+  <div></div>
+</body>
diff --git a/LayoutTests/fast/text/whitespace/pre-wrap-008.html b/LayoutTests/fast/text/whitespace/pre-wrap-008.html
new file mode 100644 (file)
index 0000000..a3259c5
--- /dev/null
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text Test: white-space: pre-wrap</title>
+<link rel="author" title="Javier Fernandez Garcia-Boente" href="mailto:jfernandez@igalia.com">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#valdef-white-space-pre-wrap">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#valdef-word-break-break-word">
+<meta name="flags" content="ahem">
+<link rel="match" href="reference/white-space-break-spaces-005-ref.html">
+<meta name="assert" content="The word is not broken despite the 'word-break: break-word' if there are previous breaking opportunities, honoring the white-space: pre-wrap value.">
+<style>
+div {
+   position: relative;
+   font-size: 20px;
+   font-family: Ahem;
+   line-height: 1em;
+}
+.red {
+  position: absolute;
+  background: green;
+  color: red;
+  width: 100px;
+  height: 100px;
+  z-index: -1;
+  white-space: pre;
+}
+.test {
+  color: green;
+  width: 5ch;
+
+  white-space: pre-wrap;
+  word-break: break-word;
+}
+</style>
+<script>
+// Force line box path.
+if (window.internals)
+    internals.settings.setSimpleLineLayoutEnabled(false);
+</script>
+<body>
+  <p>Test passes if there is a <strong>filled green square</strong> and <strong>no red</strong>.</p>
+  <div class="red"> XX  <br>XXX</div>
+  <div class="test"> XX XXX </div>
+</body>
diff --git a/LayoutTests/fast/text/whitespace/pre-wrap-015-expected.html b/LayoutTests/fast/text/whitespace/pre-wrap-015-expected.html
new file mode 100644 (file)
index 0000000..cdc737a
--- /dev/null
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text level 3 Test reference file</title>
+<link rel="author" title="Javier Fernandez Garcia-Boente" href="mailto:jfernandez@igalia.com">
+<style>
+div {
+  font-size: 20px;
+  font-family: Ahem;
+  line-height: 1em;
+  color: green;
+}
+</style>
+<body>
+  <p>Test passes if there is a <strong>filled green square</strong> and <strong>no red</strong>.</p>
+  <div>XX<br>XX</div>
+</body>
diff --git a/LayoutTests/fast/text/whitespace/pre-wrap-015.html b/LayoutTests/fast/text/whitespace/pre-wrap-015.html
new file mode 100644 (file)
index 0000000..fa4c2cf
--- /dev/null
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text Test: white-space: pre-wrap</title>
+<link rel="author" title="Javier Fernandez Garcia-Boente" href="mailto:jfernandez@igalia.com">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#valdef-white-space-pre-wrap">
+<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="reference/pre-wrap-001-ref.html">
+<meta name="assert" content="The text is broken at the end of the space between the two words, never before, so it hangs and cause an overflow">
+<style>
+div {
+   position: relative;
+   font: 20px/1 Ahem;
+}
+.ref {
+  position: absolute;
+  color: red;
+  z-index: -1;
+}
+.test {
+  color: green;
+  width: 20px;
+
+  white-space: pre-wrap;
+  word-break: break-all;
+}
+</style>
+<script>
+// Force line box path.
+if (window.internals)
+    internals.settings.setSimpleLineLayoutEnabled(false);
+</script>
+<body>
+  <p>Test passes if there is a <strong>filled green square</strong> and <strong>no red</strong>.</p>
+  <div class="ref">X<span style="color: green">X</span><br>X<span style="color: green">X</span></div>
+  <div class="test">X X</div>
+</body>
diff --git a/LayoutTests/fast/text/whitespace/pre-wrap-016-expected.html b/LayoutTests/fast/text/whitespace/pre-wrap-016-expected.html
new file mode 100644 (file)
index 0000000..cdc737a
--- /dev/null
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text level 3 Test reference file</title>
+<link rel="author" title="Javier Fernandez Garcia-Boente" href="mailto:jfernandez@igalia.com">
+<style>
+div {
+  font-size: 20px;
+  font-family: Ahem;
+  line-height: 1em;
+  color: green;
+}
+</style>
+<body>
+  <p>Test passes if there is a <strong>filled green square</strong> and <strong>no red</strong>.</p>
+  <div>XX<br>XX</div>
+</body>
diff --git a/LayoutTests/fast/text/whitespace/pre-wrap-016.html b/LayoutTests/fast/text/whitespace/pre-wrap-016.html
new file mode 100644 (file)
index 0000000..4751880
--- /dev/null
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text Test: white-space: pre-wrap</title>
+<link rel="author" title="Javier Fernandez Garcia-Boente" href="mailto:jfernandez@igalia.com">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#valdef-white-space-pre-wrap">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#valdef-word-break-break-word">
+<meta name="flags" content="ahem">
+<link rel="match" href="reference/pre-wrap-001-ref.html">
+<meta name="assert" content="The word is not broken if there are previous breaking opportunities, honoring the white-space: pre-wrap value.">
+<style>
+div {
+   position: relative;
+   font-size: 20px;
+   font-family: Ahem;
+   line-height: 1em;
+}
+.red {
+  position: absolute;
+  white-space: pre;
+  background: green;
+  color: red;
+  width: 40px;
+  height: 40px;
+  z-index: -1;
+}
+.test {
+  color: green;
+  width: 2ch;
+
+  white-space: pre-wrap;
+  word-break: break-word;
+}
+</style>
+<script>
+// Force line box path.
+if (window.internals)
+    internals.settings.setSimpleLineLayoutEnabled(false);
+</script>
+<body>
+  <p>Test passes if there is a <strong>filled green square</strong> and <strong>no red</strong>.</p>
+  <div class="red"><br>XX</div>
+  <div class="test"> XX</div>
+</body>
diff --git a/LayoutTests/fast/text/word-break-break-all-010-expected.html b/LayoutTests/fast/text/word-break-break-all-010-expected.html
new file mode 100644 (file)
index 0000000..fe87735
--- /dev/null
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text Reference File</title>
+<link rel="author" title="Javier Fernandez Garcia-Boente" href="mailto:jfernandez@igalia.com">
+<style>
+div {
+  position: relative;
+  width: 100px;
+  height: 100px;
+  background: green;
+}
+</style>
+<body>
+  <p>Test passes if there is a <strong>filled green square</strong> and <strong>no red</strong>.</p>
+  <div></div>
+</body>
diff --git a/LayoutTests/fast/text/word-break-break-all-010.html b/LayoutTests/fast/text/word-break-break-all-010.html
new file mode 100644 (file)
index 0000000..5fa47a2
--- /dev/null
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text Test: word-break: break-all</title>
+<link rel="author" title="Javier Fernandez Garcia-Boente" href="mailto:jfernandez@igalia.com">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#valdef-word-break-break-all">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#valdef-white-space-pre-wrap">
+<meta name="flags" content="ahem">
+<link rel="match" href="reference/word-break-break-all-010-ref.html">
+<meta name="assert" content="The word is broken even if pre-wrap provides a former breaking opportunity in leading white-space.">
+<style>
+div {
+  position: relative;
+  font-size: 20px;
+  font-family: Ahem;
+  line-height: 1em;
+}
+.red {
+  position: absolute;
+  white-space: pre;
+  background: green;
+  color: red;
+  width: 100px;
+  height: 100px;
+  z-index: -1;
+}
+.test {
+  color: green;
+  width: 5ch;
+
+  white-space: pre-wrap;
+  word-break: break-all;
+}
+</style>
+<script>
+// Force line box path.
+if (window.internals)
+    internals.settings.setSimpleLineLayoutEnabled(false);
+</script>
+<body>
+  <p>Test passes if there is a <strong>filled green square</strong> and <strong>no red</strong>.</p>
+  <div class="red"> XXXX<br>X</div>
+  <div class="test"> XXXXX</div>
+</body>
diff --git a/LayoutTests/fast/text/word-break-break-all-011-expected.html b/LayoutTests/fast/text/word-break-break-all-011-expected.html
new file mode 100644 (file)
index 0000000..fe87735
--- /dev/null
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text Reference File</title>
+<link rel="author" title="Javier Fernandez Garcia-Boente" href="mailto:jfernandez@igalia.com">
+<style>
+div {
+  position: relative;
+  width: 100px;
+  height: 100px;
+  background: green;
+}
+</style>
+<body>
+  <p>Test passes if there is a <strong>filled green square</strong> and <strong>no red</strong>.</p>
+  <div></div>
+</body>
diff --git a/LayoutTests/fast/text/word-break-break-all-011.html b/LayoutTests/fast/text/word-break-break-all-011.html
new file mode 100644 (file)
index 0000000..a412c5f
--- /dev/null
@@ -0,0 +1,44 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text Test: word-break: break-all</title>
+<link rel="author" title="Javier Fernandez Garcia-Boente" href="mailto:jfernandez@igalia.com">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#valdef-word-break-break-all">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#valdef-white-space-pre-wrap">
+<meta name="flags" content="ahem">
+<link rel="match" href="reference/word-break-break-all-010-ref.html">
+<meta name="assert" content="A single leading white-space should account as soft breaking opportunity, honoring the 'white-space: pre-wrap', on top to the ones provided by 'word-break: break-all'.">
+<style>
+div {
+  position: relative;
+  font-size: 20px;
+  font-family: Ahem;
+  line-height: 1em;
+}
+.red {
+  position: absolute;
+  background: green;
+  color: red;
+  width: 100px;
+  height: 100px;
+  z-index: -1;
+  white-space: pre;
+}
+span { color: green; }
+.test {
+  color: green;
+  width: 1ch;
+
+  white-space: pre-wrap;
+  word-break: break-all;
+}
+</style>
+<script>
+// Force line box path.
+if (window.internals)
+    internals.settings.setSimpleLineLayoutEnabled(false);
+</script>
+<body>
+  <p>Test passes if there is a <strong>filled green square</strong> and <strong>no red</strong>.</p>
+  <div class="red"> <br>X<br>X</div>
+  <div class="test"> XX</div>
+</body>
diff --git a/LayoutTests/fast/text/word-break-break-all-015-expected.html b/LayoutTests/fast/text/word-break-break-all-015-expected.html
new file mode 100644 (file)
index 0000000..fe87735
--- /dev/null
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text Reference File</title>
+<link rel="author" title="Javier Fernandez Garcia-Boente" href="mailto:jfernandez@igalia.com">
+<style>
+div {
+  position: relative;
+  width: 100px;
+  height: 100px;
+  background: green;
+}
+</style>
+<body>
+  <p>Test passes if there is a <strong>filled green square</strong> and <strong>no red</strong>.</p>
+  <div></div>
+</body>
diff --git a/LayoutTests/fast/text/word-break-break-all-015.html b/LayoutTests/fast/text/word-break-break-all-015.html
new file mode 100644 (file)
index 0000000..d17b80a
--- /dev/null
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text Test: word-break: break-all</title>
+<link rel="author" title="Javier Fernandez Garcia-Boente" href="mailto:jfernandez@igalia.com">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#valdef-word-break-break-all">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#valdef-white-space-pre-wrap">
+<meta name="flags" content="ahem">
+<link rel="match" href="reference/word-break-break-all-010-ref.html">
+<meta name="assert" content="The word is broken even if white-space: pre-wrap provides a former breaking opportunity in leading white-space.">
+<style>
+div {
+   position: relative;
+   font-size: 20px;
+   font-family: Ahem;
+}
+.red {
+  position: absolute;
+  background: green;
+  color: red;
+  width: 100px;
+  height: 100px;
+  z-index: -1;
+  white-space: pre;
+}
+.test {
+  color: green;
+  line-height: 1em;
+  width: 5ch;
+  line-break: strict; /* Avoid WebKit's SimpleLineLayout codepath */
+
+  white-space: pre-wrap;
+  word-break: break-all;
+}
+</style>
+<body>
+  <p>Test passes if there is a <strong>filled green square</strong> and <strong>no red</strong>.</p>
+  <div class="red"> XX X<br>XX</div>
+  <div class="test"> XX XXX </div>
+</body>
index d975c93..591ca53 100644 (file)
@@ -1,3 +1,24 @@
+2019-03-25  Javier Fernandez  <jfernandez@igalia.com>
+
+        A single leading space is not considered as a word break even when word-break: break-all is set
+        https://bugs.webkit.org/show_bug.cgi?id=195361
+
+        Reviewed by Ryosuke Niwa.
+
+        Imported additonal WPT from the CSS Text Suite that verify the
+        change doesn't regress in any case, specially for the word-break:
+        break-word feature.
+
+        * web-platform-tests/css/css-text/overflow-wrap/overflow-wrap-break-word-007-expected.html: Added.
+        * web-platform-tests/css/css-text/overflow-wrap/overflow-wrap-break-word-007.html: Added.
+        * web-platform-tests/css/css-text/overflow-wrap/w3c-import.log:
+        * web-platform-tests/css/css-text/white-space/pre-wrap-008-expected.html: Added.
+        * web-platform-tests/css/css-text/white-space/pre-wrap-008.html: Added.
+        * web-platform-tests/css/css-text/white-space/w3c-import.log:
+        * web-platform-tests/css/css-text/word-break/w3c-import.log:
+        * web-platform-tests/css/css-text/word-break/word-break-break-all-015-expected.html: Added.
+        * web-platform-tests/css/css-text/word-break/word-break-break-all-015.html: Added.
+
 2019-03-25  Rob Buis  <rbuis@igalia.com>
 
         Reflect HTMLLinkElement.as according to the spec
diff --git a/LayoutTests/imported/w3c/web-platform-tests/css/css-text/overflow-wrap/overflow-wrap-break-word-007-expected.html b/LayoutTests/imported/w3c/web-platform-tests/css/css-text/overflow-wrap/overflow-wrap-break-word-007-expected.html
new file mode 100644 (file)
index 0000000..0e0300a
--- /dev/null
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text Reference File</title>
+<link rel="author" title="Florian Rivoal" href="http://florian.rivoal.net/">
+<style>
+div {
+  position: relative;
+  width: 100px;
+  height: 100px;
+  background: green;
+}
+</style>
+<body>
+  <p>Test passes if there is a <strong>filled green square</strong> and <strong>no red</strong>.</p>
+  <div></div>
+</body>
diff --git a/LayoutTests/imported/w3c/web-platform-tests/css/css-text/overflow-wrap/overflow-wrap-break-word-007.html b/LayoutTests/imported/w3c/web-platform-tests/css/css-text/overflow-wrap/overflow-wrap-break-word-007.html
new file mode 100644 (file)
index 0000000..261f781
--- /dev/null
@@ -0,0 +1,38 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text Test: overflow-wrap: break-word</title>
+<link rel="author" title="Javier Fernandez Garcia-Boente" href="mailto:jfernandez@igalia.com">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#valdef-overflow-wrap-break-word">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#valdef-white-space-break-spaces">
+<meta name="flags" content="ahem">
+<link rel="match" href="reference/overflow-wrap-break-word-001-ref.html">
+<meta name="assert" content="A Single leading white-space constitutes a soft breaking opportunity, honoring the 'white-space: break-spaces' property, that must prevent the word to be broken.">
+<style>
+div {
+  position: relative;
+  font-size: 20px;
+  font-family: Ahem;
+  line-height: 1em;
+}
+.red {
+  position: absolute;
+  background: green;
+  color: red;
+  width: 100px;
+  height: 100px;
+  z-index: -1;
+  white-space: pre;
+}
+.test {
+  color: green;
+  width: 5ch;
+
+  white-space: pre-wrap;
+  overflow-wrap: break-word;
+}
+</style>
+<body>
+  <p>Test passes if there is a <strong>filled green square</strong> and <strong>no red</strong>.</p>
+  <div class="red"> XX  <br>XXX</div>
+  <div class="test"> XX XXX </div>
+</body>
index 2a3c287..a901a5a 100644 (file)
@@ -47,6 +47,8 @@ List of files:
 /LayoutTests/imported/w3c/web-platform-tests/css/css-text/overflow-wrap/overflow-wrap-break-word-005.html
 /LayoutTests/imported/w3c/web-platform-tests/css/css-text/overflow-wrap/overflow-wrap-break-word-006-expected.html
 /LayoutTests/imported/w3c/web-platform-tests/css/css-text/overflow-wrap/overflow-wrap-break-word-006.html
+/LayoutTests/imported/w3c/web-platform-tests/css/css-text/overflow-wrap/overflow-wrap-break-word-007-expected.html
+/LayoutTests/imported/w3c/web-platform-tests/css/css-text/overflow-wrap/overflow-wrap-break-word-007.html
 /LayoutTests/imported/w3c/web-platform-tests/css/css-text/overflow-wrap/overflow-wrap-break-word-fit-content-001-expected.html
 /LayoutTests/imported/w3c/web-platform-tests/css/css-text/overflow-wrap/overflow-wrap-break-word-fit-content-001.html
 /LayoutTests/imported/w3c/web-platform-tests/css/css-text/overflow-wrap/overflow-wrap-break-word-span-001-expected.html
diff --git a/LayoutTests/imported/w3c/web-platform-tests/css/css-text/white-space/pre-wrap-008-expected.html b/LayoutTests/imported/w3c/web-platform-tests/css/css-text/white-space/pre-wrap-008-expected.html
new file mode 100644 (file)
index 0000000..3247ae5
--- /dev/null
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text Reference File</title>
+<link rel="author" title="Javier Fernandez" href="mailto:jfernandez@igalia.com" />
+<style>
+div {
+  position: relative;
+  width: 100px;
+  height: 100px;
+  background: green;
+}
+</style>
+<body>
+    <p>Test passes if there is a <strong>filled green square</strong> and <strong>no red</strong>.</p>
+  <div></div>
+</body>
diff --git a/LayoutTests/imported/w3c/web-platform-tests/css/css-text/white-space/pre-wrap-008.html b/LayoutTests/imported/w3c/web-platform-tests/css/css-text/white-space/pre-wrap-008.html
new file mode 100644 (file)
index 0000000..a360bdc
--- /dev/null
@@ -0,0 +1,38 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text Test: white-space: pre-wrap</title>
+<link rel="author" title="Javier Fernandez Garcia-Boente" href="mailto:jfernandez@igalia.com">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#valdef-white-space-pre-wrap">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#valdef-word-break-break-word">
+<meta name="flags" content="ahem">
+<link rel="match" href="reference/white-space-break-spaces-005-ref.html">
+<meta name="assert" content="The word is not broken despite the 'word-break: break-word' if there are previous breaking opportunities, honoring the white-space: pre-wrap value.">
+<style>
+div {
+  position: relative;
+  font-size: 20px;
+  font-family: Ahem;
+  line-height: 1em;
+}
+.red {
+  position: absolute;
+  background: green;
+  color: red;
+  width: 100px;
+  height: 100px;
+  z-index: -1;
+  white-space: pre;
+}
+.test {
+  color: green;
+  width: 5ch;
+
+  white-space: pre-wrap;
+  word-break: break-word;
+}
+</style>
+<body>
+  <p>Test passes if there is a <strong>filled green square</strong> and <strong>no red</strong>.</p>
+  <div class="red"> XX  <br>XXX</div>
+  <div class="test"> XX XXX </div>
+</body>
index e0b1a64..d16fd81 100644 (file)
@@ -172,6 +172,8 @@ List of files:
 /LayoutTests/imported/w3c/web-platform-tests/css/css-text/white-space/pre-wrap-006.html
 /LayoutTests/imported/w3c/web-platform-tests/css/css-text/white-space/pre-wrap-007-expected.html
 /LayoutTests/imported/w3c/web-platform-tests/css/css-text/white-space/pre-wrap-007.html
+/LayoutTests/imported/w3c/web-platform-tests/css/css-text/white-space/pre-wrap-008-expected.html
+/LayoutTests/imported/w3c/web-platform-tests/css/css-text/white-space/pre-wrap-008.html
 /LayoutTests/imported/w3c/web-platform-tests/css/css-text/white-space/pre-wrap-011-expected.html
 /LayoutTests/imported/w3c/web-platform-tests/css/css-text/white-space/pre-wrap-011.html
 /LayoutTests/imported/w3c/web-platform-tests/css/css-text/white-space/pre-wrap-012-expected.html
index 4f20e18..ee480b5 100644 (file)
@@ -42,6 +42,8 @@ List of files:
 /LayoutTests/imported/w3c/web-platform-tests/css/css-text/word-break/word-break-break-all-013.html
 /LayoutTests/imported/w3c/web-platform-tests/css/css-text/word-break/word-break-break-all-014-expected.html
 /LayoutTests/imported/w3c/web-platform-tests/css/css-text/word-break/word-break-break-all-014.html
+/LayoutTests/imported/w3c/web-platform-tests/css/css-text/word-break/word-break-break-all-015-expected.html
+/LayoutTests/imported/w3c/web-platform-tests/css/css-text/word-break/word-break-break-all-015.html
 /LayoutTests/imported/w3c/web-platform-tests/css/css-text/word-break/word-break-break-all-020-expected.html
 /LayoutTests/imported/w3c/web-platform-tests/css/css-text/word-break/word-break-break-all-020.html
 /LayoutTests/imported/w3c/web-platform-tests/css/css-text/word-break/word-break-keep-all-000-expected.html
diff --git a/LayoutTests/imported/w3c/web-platform-tests/css/css-text/word-break/word-break-break-all-015-expected.html b/LayoutTests/imported/w3c/web-platform-tests/css/css-text/word-break/word-break-break-all-015-expected.html
new file mode 100644 (file)
index 0000000..0e0300a
--- /dev/null
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text Reference File</title>
+<link rel="author" title="Florian Rivoal" href="http://florian.rivoal.net/">
+<style>
+div {
+  position: relative;
+  width: 100px;
+  height: 100px;
+  background: green;
+}
+</style>
+<body>
+  <p>Test passes if there is a <strong>filled green square</strong> and <strong>no red</strong>.</p>
+  <div></div>
+</body>
diff --git a/LayoutTests/imported/w3c/web-platform-tests/css/css-text/word-break/word-break-break-all-015.html b/LayoutTests/imported/w3c/web-platform-tests/css/css-text/word-break/word-break-break-all-015.html
new file mode 100644 (file)
index 0000000..d9645be
--- /dev/null
@@ -0,0 +1,38 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text Test: word-break: break-all</title>
+<link rel="author" title="Javier Fernandez Garcia-Boente" href="mailto:jfernandez@igalia.com">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#valdef-word-break-break-all">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#valdef-white-space-pre-wrap">
+<meta name="flags" content="ahem">
+<link rel="match" href="reference/word-break-break-all-010-ref.html">
+<meta name="assert" content="The word is broken even if white-space: pre-wrap provides a former breaking opportunity in leading white-space.">
+<style>
+div {
+  position: relative;
+  font-size: 20px;
+  font-family: Ahem;
+  line-height: 1em;
+}
+.red {
+  position: absolute;
+  background: green;
+  color: red;
+  width: 100px;
+  height: 100px;
+  z-index: -1;
+  white-space: pre;
+}
+.test {
+  color: green;
+  width: 5ch;
+
+  white-space: pre-wrap;
+  word-break: break-all;
+}
+</style>
+<body>
+  <p>Test passes if there is a <strong>filled green square</strong> and <strong>no red</strong>.</p>
+  <div class="red"> XX X<br>XX</div>
+  <div class="test"> XX XXX </div>
+</body>
index 3fe4cf5..ecb205d 100644 (file)
@@ -3499,7 +3499,6 @@ webkit.org/b/183258 imported/w3c/web-platform-tests/css/css-text/word-break/word
 webkit.org/b/183258 imported/w3c/web-platform-tests/css/css-text/word-break/word-break-normal-bo-000.html [ ImageOnlyFailure ]
 webkit.org/b/183258 imported/w3c/web-platform-tests/css/css-text/word-break/word-break-normal-lo-000.html [ ImageOnlyFailure ]
 
-webkit.org/b/195275 imported/w3c/web-platform-tests/css/css-text/word-break/word-break-break-all-010.html [ ImageOnlyFailure ]
 webkit.org/b/195275 imported/w3c/web-platform-tests/css/css-text/word-break/word-break-break-all-014.html [ ImageOnlyFailure ]
 
 webkit.org/b/195275 imported/w3c/web-platform-tests/css/css-text/boundary-shaping/boundary-shaping-004.html [ Timeout ImageOnlyFailure ]
index 4e62863..26b49b1 100644 (file)
@@ -1,3 +1,66 @@
+2019-03-25  Javier Fernandez  <jfernandez@igalia.com>
+
+        A single leading space is not considered as a word break even when word-break: break-all is set
+        https://bugs.webkit.org/show_bug.cgi?id=195361
+
+        Reviewed by Ryosuke Niwa.
+
+        We must consider leading white-spaces as potential soft-breaking
+        opportunities that may avoid breaking in the middle of the word.
+
+        However, 'break-word: break-all' [1] implies that we should ignore
+        previous opportunities and break at any character (among the ones
+        valid for 'break-all') that prevents the line to overflow. Note,
+        that these breakable characters are different from the ones
+        provided by 'line-break: anywhere' [2].
+
+        This change is covered by the already existent tests of the CSS
+        Text 3 suite of the Web Platform Tests.
+
+        The word-break-break-all-010.html was precisely designed to cover
+        the basic issue fixed with this change, verifying that the word is
+        indeed broken even if a single leading space constitutes a
+        previous soft-breaking opportunity.
+
+        There are other Web Platform Tests. which already pass before this
+        change, to verify that such leading white-space must be used
+        instead of breaking the word in any other case, including
+        overflow-wrap: break-word and even the deprecated word-break:
+        break-word.
+
+           - white-space/pre-wrap-008.html
+           - white-space/pre-wrap-015.html
+           - white-space/pre-wrap-016.html
+           - overflow-wrap/overflow-wrap-break-word-004.html
+           - overflow-wrap/overflow-wrap-break-word-005.html
+           - overflow-wrap/overflow-wrap-break-word-007.html
+           - word-break/word-break-break-all-011.html
+           - word-break/word-break-break-all-014.html
+
+        The reason why the word-break-break-all-010.html passes in Mac
+        platform is that for that case the SimpleLineLayout codepath is
+        executed instead, which doesn't have this bug, present in the old
+        line-breaking logic implemented in the BreakingContext class.
+
+        In order to verify the validity of this change, I've added several
+        tests under fast/text with the SimpleLineLayout disabled.
+
+        Tests: fast/text/overflow-wrap-break-word-004.html
+               fast/text/overflow-wrap-break-word-005.html
+               fast/text/overflow-wrap-break-word-007.html
+               fast/text/whitespace/pre-wrap-008.html
+               fast/text/whitespace/pre-wrap-015.html
+               fast/text/whitespace/pre-wrap-016.html
+               fast/text/word-break-break-all-010.html
+               fast/text/word-break-break-all-011.html
+               fast/text/word-break-break-all-015.html
+               imported/w3c/web-platform-tests/css/css-text/overflow-wrap/overflow-wrap-break-word-007.html
+               imported/w3c/web-platform-tests/css/css-text/white-space/pre-wrap-008.html
+               imported/w3c/web-platform-tests/css/css-text/word-break/word-break-break-all-015.html
+
+        * rendering/line/BreakingContext.h:
+        (WebCore::BreakingContext::handleText):
+
 2019-03-25  Rob Buis  <rbuis@igalia.com>
 
         Reflect HTMLLinkElement.as according to the spec
index 4a0158d..983f6e3 100644 (file)
@@ -817,6 +817,11 @@ inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements, bool
         UChar c = m_current.current();
         m_currentCharacterIsSpace = c == ' ' || c == '\t' || (!m_preservesNewline && (c == '\n'));
 
+        // A single preserved leading white-space doesn't fulfill the 'betweenWords' condition, however it's indeed a
+        // soft-breaking opportunty so we may want to avoid breaking in the middle of the word.
+        if (m_atStart && m_currentCharacterIsSpace && !previousCharacterIsSpace)
+            breakWords = false;
+
         if (canHangPunctuationAtStart && m_width.isFirstLine() && !m_width.committedWidth() && !wrapW && !inlineLogicalWidth(m_current.renderer(), true, false)) {
             m_width.addUncommittedWidth(-renderText.hangablePunctuationStartWidth(m_current.offset()));
             canHangPunctuationAtStart = false;
@@ -839,7 +844,7 @@ inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements, bool
 
         m_currentCharacterIsWS = m_currentCharacterIsSpace || (breakNBSP && c == noBreakSpace);
 
-        if ((breakAll || breakWords) && !midWordBreak && (!m_currentCharacterIsSpace || style.whiteSpace() != WhiteSpace::PreWrap)) {
+        if ((breakAll || breakWords) && !midWordBreak && (!m_currentCharacterIsSpace || m_atStart || style.whiteSpace() != WhiteSpace::PreWrap)) {
             wrapW += charWidth;
             bool midWordBreakIsBeforeSurrogatePair = U16_IS_LEAD(c) && U16_IS_TRAIL(renderText.characterAt(m_current.offset() + 1));
             charWidth = textWidth(renderText, m_current.offset(), midWordBreakIsBeforeSurrogatePair ? 2 : 1, font, m_width.committedWidth() + wrapW, isFixedPitch, m_collapseWhiteSpace, fallbackFonts, textLayout);