[LayoutNG] Fix PDI/PDF not to affect line breaking
This patch fixes PDI/PDF before spaces not to suppress the
line breaking opportunity at the space. For example, before
this fix, `<bdo dir=ltr>a</bdo> b` could not break between
"a" and "b".
PDI and PDF are injected by the `unicode-bidi` property, or
elements that imply the `unicode-bidi` property such as
`<bdi>`, `<bdo>`, or any elements with `dir` attributes.
Bug: 989094
Change-Id: I2128774e2b062ecb86880812c54d46299a19a18a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1735146
Commit-Queue: Emil A Eklund <eae@chromium.org>
Reviewed-by: Emil A Eklund <eae@chromium.org>
Cr-Commit-Position: refs/heads/master@{#683881}
diff --git a/third_party/blink/renderer/core/layout/ng/inline/ng_line_breaker.cc b/third_party/blink/renderer/core/layout/ng/inline/ng_line_breaker.cc
index 6253874..e863dafc 100644
--- a/third_party/blink/renderer/core/layout/ng/inline/ng_line_breaker.cc
+++ b/third_party/blink/renderer/core/layout/ng/inline/ng_line_breaker.cc
@@ -1133,8 +1133,16 @@
if (!item_results->IsEmpty()) {
NGInlineItemResult* item_result = AddItem(item, line_info);
NGInlineItemResult* last = &(*item_results)[item_results->size() - 2];
- item_result->can_break_after = last->can_break_after;
- last->can_break_after = false;
+ // Honor the last |can_break_after| if it's true, in case it was
+ // artificially set to true for break-after-space.
+ if (last->can_break_after) {
+ item_result->can_break_after = last->can_break_after;
+ last->can_break_after = false;
+ } else {
+ // Otherwise compute from the text. |LazyLineBreakIterator| knows how to
+ // break around bidi control characters.
+ ComputeCanBreakAfter(item_result, auto_wrap_, break_iterator_);
+ }
} else {
AddItem(item, line_info);
}
diff --git a/third_party/blink/web_tests/external/wpt/css/css-writing-modes/bidi-line-break-001.html b/third_party/blink/web_tests/external/wpt/css/css-writing-modes/bidi-line-break-001.html
new file mode 100644
index 0000000..f46b56b
--- /dev/null
+++ b/third_party/blink/web_tests/external/wpt/css/css-writing-modes/bidi-line-break-001.html
@@ -0,0 +1,56 @@
+<!DOCTYPE html>
+<title>Test implicit bidi controls do not affect line breaking</title>
+<link rel="help" href="https://drafts.csswg.org/css-writing-modes-3/#unicode-bidi">
+<link rel="author" title="Koji Ishii" href="mailto:kojii@chromium.org">
+<style>
+html {
+ font-size: 10px;
+ line-height: 1;
+}
+.isolate {
+ unicode-bidi: isolate;
+}
+.embed {
+ unicode-bidi: embed;
+}
+</style>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<body>
+<div id=log></div>
+<div id="container">
+ <div style="width: 4ch" data-expected-height="20">
+ <span class="isolate" dir="ltr">00</span> <span class="isolate" dir="ltr">00</span>
+ </div>
+ <div style="width: 4ch" data-expected-height="20">
+ <span class="embed" dir="ltr">00</span> <span class="embed" dir="ltr">00</span>
+ </div>
+
+ <div style="width: 4ch" data-expected-height="20">
+ <span dir="ltr">00</span> <span dir="ltr">00</span>
+ </div>
+ <div style="width: 4ch" data-expected-height="20">
+ <bdi dir="ltr">00</bdi> <bdi dir="ltr">00</bdi>
+ </div>
+ <div style="width: 4ch" data-expected-height="20">
+ <bdo dir="ltr">00</bdo> <bdo dir="ltr">00</bdo>
+ </div>
+
+ <div style="width: 4ch" data-expected-height="20">
+ <span class="isolate" dir="ltr">00 </span><span class="isolate" dir="ltr">00</span>
+ </div>
+ <div style="width: 4ch" data-expected-height="20">
+ <span class="embed" dir="ltr">00 </span><span class="embed" dir="ltr">00</span>
+ </div>
+</div>
+<script>
+run();
+function run() {
+ for (let node of document.getElementById('container').children) {
+ test(() => {
+ assert_approx_equals(node.offsetHeight, 20, 1);
+ }, node.innerHTML);
+ }
+}
+</script>
+</body>