Commit 83d0457e authored by Javier Fernandez's avatar Javier Fernandez Committed by Commit Bot

[css-text] break-all opportunities to avoid breaking before first space

The 'white-space: break-spaces' feature, when used in combination with
'overfow-wrap: break-word' may allow breaking before the first space
after a word.

However, we should avoid it if there are previous opportunities, like
white spaces.

The 'word-break: break-all' feature allows breaking a word at any
letter. Since the goal of this feature is produce the longest line as
possible, these additional opportunities must be prioritized over any
previous white space.

Bug: 952254
Change-Id: I0b1c31219c0009c7050084dd552317342ec25b8a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1613177Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Commit-Queue: Javier Fernandez <jfernandez@igalia.com>
Cr-Commit-Position: refs/heads/master@{#660072}
parent 77c2f1cf
......@@ -384,6 +384,11 @@ inline void BreakingContext::InitializeForCurrentObject() {
// a single leading white-space as potential breaking opportunities.
current_start_offset_ = current_.Offset();
has_former_opportunity_ = false;
if (curr_ws_ == EWhiteSpace::kBreakSpaces) {
layout_text_info_.line_break_iterator_.SetBreakSpace(
BreakSpaceType::kAfterEverySpace);
}
}
inline void BreakingContext::Increment() {
......@@ -860,6 +865,8 @@ ALWAYS_INLINE bool BreakingContext::RewindToMidWordBreak(
LazyLineBreakIterator break_iterator(
text.GetText(), style.LocaleForLineBreakIterator(), line_break_type);
if (curr_ws_ == EWhiteSpace::kBreakSpaces)
break_iterator.SetBreakSpace(BreakSpaceType::kAfterEverySpace);
float x_pos_to_break = width_.AvailableWidth() - width_.CurrentWidth();
if (x_pos_to_break <= LayoutUnit::Epsilon()) {
// There were no space left. Skip computing how many characters can fit.
......
......@@ -337,12 +337,8 @@ inline int LazyLineBreakIterator::NextBreakablePosition(
case BreakSpaceType::kAfterEverySpace:
if (is_last_space)
return i;
if (is_space) {
// Might be allowed to break before the first space after a word.
if (lineBreakType == LineBreakType::kBreakAll)
return i;
if (is_space)
continue;
}
break;
}
......
......@@ -64,9 +64,6 @@ crbug.com/591099 external/wpt/css/vendor-imports/mozilla/mozilla-central-reftest
crbug.com/591099 external/wpt/css/vendor-imports/mozilla/mozilla-central-reftests/sizing/hori-block-size-small-or-larger-than-container-with-min-or-max-content-2b.html [ Pass ]
crbug.com/591099 external/wpt/css/vendor-imports/mozilla/mozilla-central-reftests/sizing/vert-block-size-small-or-larger-than-container-with-min-or-max-content-2a.html [ Pass ]
crbug.com/952254 external/wpt/css/css-text/word-break/word-break-break-all-017.html [ Failure ]
crbug.com/952254 external/wpt/css/css-text/word-break/word-break-break-all-022.html [ Failure ]
# New failures are appended below by the script.
crbug.com/591099 css3/filters/composited-layer-child-bounds-after-composited-to-sw-shadow-change.html [ Failure ]
crbug.com/591099 css3/filters/effect-drop-shadow-hw.html [ Pass ]
......
......@@ -1915,10 +1915,6 @@ crbug.com/6122 external/wpt/css/css-text/text-transform/text-transform-shaping-0
crbug.com/6122 external/wpt/css/css-text/text-transform/text-transform-shaping-002.html [ Failure ]
crbug.com/6122 external/wpt/css/css-text/text-transform/text-transform-shaping-003.html [ Failure ]
crbug.com/952254 external/wpt/css/css-text/white-space/break-spaces-008.html [ Failure ]
crbug.com/952254 external/wpt/css/css-text/white-space/break-spaces-before-first-char-004.html [ Failure ]
crbug.com/952254 external/wpt/css/css-text/white-space/break-spaces-before-first-char-005.html [ Failure ]
# These are added to W3CImportExpectations as Skip, remove when next import is done.
crbug.com/666657 external/wpt/css/css-text/hanging-punctuation [ Skip ]
......
<!DOCTYPE html>
<meta charset="utf-8">
<title>CSS Text Test: white-space: break-spaces</title>
<link rel="author" title="Javier Fernandez" href="mailto:jfernandez@igalia.com" />
<link rel="help" title="3. White Space and Wrapping: the white-space property" href="https://drafts.csswg.org/css-text-3/#white-space-property">
<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/white-space-break-spaces-005-ref.html">
<meta name="assert" content="break-spaces only allows breaking after a white space, hence, a preserved white space may overflow.">
<style>
div {
font: 25px/1 Ahem;
}
.fail {
position: absolute;
color: red;
z-index: -1;
}
span { color: green; }
.test {
color: green;
width: 4ch;
white-space: break-spaces;
}
</style>
<p>Test passes if there is a <strong>filled green square</strong> and <strong>no red</strong>.</p>
<div class="fail">XXXX<br><span>X</span>XX<span>X<br>XXXX<br>XXXX</span></div>
<div class="test">XXXX XX</div>
......@@ -30,5 +30,5 @@ div {
}
</style>
<p>Test passes if there is a <strong>filled green square</strong> and <strong>no red</strong>.</p>
<div class="red">X<br>XX X<br>X X <br>XX X</div>
<div class="red">X X <br>X X <br>X X <br>XX X</div>
<div class="test">X XX XX X XX X</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