Commit a044ebbf authored by Javier Fernandez's avatar Javier Fernandez Committed by Commit Bot

[css-text] Use always the BreakIterator to compute the intrinsic size

As part of the preferred width computation of LayoutText objects, we
have an specific function to implement the min-word-fragment of a text.

We are handling the case of break-all and break-word differently, and
that's right. However, we are using the BreakIterator only in case of
break-all. This caused that we consider valid to break grapheme clusters
when computing the min-content size, which leads to wrong values in some
cases, like the one described in the bug.

This CL changes the mentioned logic to rely always into the
BreakIterator, which knows better when is valid to break the text.

Bug: 1013775
Change-Id: Ia152d346a61b6b54eaac185a399b0d572e3aba4d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1857319
Commit-Queue: Javier Fernandez <jfernandez@igalia.com>
Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#710594}
parent 05b50bd9
......@@ -1083,20 +1083,20 @@ static float MinWordFragmentWidthForBreakAll(
int length,
EWordBreak break_all_or_break_word) {
DCHECK_GT(length, 0);
DCHECK(break_all_or_break_word == EWordBreak::kBreakAll ||
break_all_or_break_word == EWordBreak::kBreakWord);
LazyLineBreakIterator break_iterator(layout_text->GetText(),
style.LocaleForLineBreakIterator());
int next_breakable = -1;
float min = std::numeric_limits<float>::max();
int end = start + length;
LineBreakType line_break_type =
break_all_or_break_word == EWordBreak::kBreakAll
? LineBreakType::kBreakAll
: LineBreakType::kBreakCharacter;
for (int i = start; i < end;) {
int fragment_length;
if (break_all_or_break_word == EWordBreak::kBreakAll) {
break_iterator.IsBreakable(i + 1, next_breakable,
LineBreakType::kBreakAll);
fragment_length = (next_breakable > i ? next_breakable : length) - i;
} else {
fragment_length = U16_LENGTH(layout_text->CodepointAt(i));
}
break_iterator.IsBreakable(i + 1, next_breakable, line_break_type);
int fragment_length = (next_breakable > i ? next_breakable : length) - i;
// Ensure that malformed surrogate pairs don't cause us to read
// past the end of the string.
......
<!DOCTYPE html>
<meta charset="utf-8">
<title>CSS Text Test: overflow-wrap: anywhere and intrinsic sizing</title>
<link rel="author" title="Xidorn Quan" href="https://www.upsuper.org/">
<link rel="author" title="Mozilla" href="https://www.mozilla.org/">
<link rel="help" href="https://drafts.csswg.org/css-text-3/#overflow-wrap-property">
<meta name="flags" content="">
<link rel="match" href="../overflow-wrap/reference/overflow-wrap-min-content-size-002-ref.html">
<meta name="assert" content="overflow-wrap:anywhere doesn't break grapheme cluster and min-content intrinsic size should take that into account.">
<style>
#wrapper {
width: 0px;
word-break: break-word;
}
#test {
float: left;
border: 2px solid blue;
}
</style>
<p>Test passes if the glyphs are completely inside the blue box.
<div id="wrapper">
<div id="test">&#x0ba8;&#x0bbf;&#x0bbf;&#x0bbf;&#x0bbf;&#x0ba8;&#x0bbf;&#x0bbf;&#x0bbf;&#x0bbf;</div>
</div>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment