Commit 4757aae1 authored by tmoniuszko's avatar tmoniuszko Committed by Commit bot

Correct style ranges on text eliding instead of clearing them

BUG=416798

Review URL: https://codereview.chromium.org/637293002

Cr-Commit-Position: refs/heads/master@{#299865}
parent 94388f79
...@@ -1260,8 +1260,7 @@ base::string16 RenderText::Elide(const base::string16& text, ...@@ -1260,8 +1260,7 @@ base::string16 RenderText::Elide(const base::string16& text,
size_t hi = text.length() - 1; size_t hi = text.length() - 1;
const base::i18n::TextDirection text_direction = GetTextDirection(); const base::i18n::TextDirection text_direction = GetTextDirection();
for (size_t guess = (lo + hi) / 2; lo <= hi; guess = (lo + hi) / 2) { for (size_t guess = (lo + hi) / 2; lo <= hi; guess = (lo + hi) / 2) {
// Restore styles and colors. They will be truncated to size by SetText. // Restore colors. They will be truncated to size by SetText.
render_text->styles_ = styles_;
render_text->colors_ = colors_; render_text->colors_ = colors_;
base::string16 new_text = base::string16 new_text =
slicer.CutString(guess, insert_ellipsis && behavior != ELIDE_TAIL); slicer.CutString(guess, insert_ellipsis && behavior != ELIDE_TAIL);
...@@ -1287,6 +1286,25 @@ base::string16 RenderText::Elide(const base::string16& text, ...@@ -1287,6 +1286,25 @@ base::string16 RenderText::Elide(const base::string16& text,
render_text->SetText(new_text); render_text->SetText(new_text);
} }
// Restore styles. Make sure style ranges don't break new text graphemes.
render_text->styles_ = styles_;
for (size_t style = 0; style < NUM_TEXT_STYLES; ++style) {
BreakList<bool>& break_list = render_text->styles_[style];
break_list.SetMax(render_text->text_.length());
Range range;
while (range.end() < break_list.max()) {
BreakList<bool>::const_iterator current_break =
break_list.GetBreak(range.end());
range = break_list.GetRange(current_break);
if (range.end() < break_list.max() &&
!render_text->IsValidCursorIndex(range.end())) {
range.set_end(render_text->IndexOfAdjacentGrapheme(range.end(),
CURSOR_FORWARD));
break_list.ApplyValue(current_break->second, range);
}
}
}
// We check the width of the whole desired string at once to ensure we // We check the width of the whole desired string at once to ensure we
// handle kerning/ligatures/etc. correctly. // handle kerning/ligatures/etc. correctly.
const float guess_width = render_text->GetContentWidth(); const float guess_width = render_text->GetContentWidth();
......
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