Commit 4dc66411 authored by Javier Fernandez's avatar Javier Fernandez Committed by Commit Bot

[css-text] Keep track of the initial offset for each handled text

In order to identify single leading white-spaces as potential line
breaking opportunities we need to know the offset the iterator starts
at for the current text to handle.

When we landed the change in r596406 we incorrectly assumed that
leading white-spaces were always at offset 1. However, this is not
valid when such leading white-spaces are generated by previous broken
lines.

This CL solves the issue by using the stored initial offset to identify
such single leading white-spaces as potential breaking opportunities.

Bug: 900727
Change-Id: Ibc9dda7632d72ed82a61025015489ec3b70d6919
Reviewed-on: https://chromium-review.googlesource.com/c/1311274
Commit-Queue: Javier Fernandez <jfernandez@igalia.com>
Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605055}
parent 10d6bece
<!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;
}
.fail {
position: absolute;
color: red;
z-index: -1;
}
span { color: green; }
.test {
color: green;
line-height: 1em;
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="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>
......@@ -208,6 +208,7 @@ class BreakingContext {
bool ignoring_spaces_;
bool current_character_is_space_;
bool single_leading_space_;
unsigned current_start_offset_; // initial offset for the current text
bool applied_start_width_;
bool include_end_width_;
bool auto_wrap_;
......@@ -379,6 +380,10 @@ inline void BreakingContext::InitializeForCurrentObject() {
if (collapse_white_space_ && !ComputedStyle::CollapseWhiteSpace(last_ws_))
current_character_is_space_ = false;
// Since current_ iterates all along the text's length, we need to store the
// initial offset of the current handle text so that we can then identify
// a single leading white-space as potential breaking opportunities.
current_start_offset_ = current_.Offset();
single_leading_space_ = false;
}
......@@ -1362,7 +1367,7 @@ inline void BreakingContext::PrepareForNextCharacter(
if (auto_wrap_ && current_style_->BreakOnlyAfterWhiteSpace()) {
line_break_.MoveTo(current_.GetLineLayoutItem(), current_.Offset(),
current_.NextBreakablePosition());
if (current_.Offset() == 1)
if (current_.Offset() == current_start_offset_ + 1)
single_leading_space_ = true;
}
}
......
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