Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(538)

Unified Diff: ui/gfx/render_text.cc

Issue 637293002: Correct style ranges on text eliding instead of clearing them (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Restore style ranges for RenderText copy on eliding text Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/render_text.cc
diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc
index d5d4011d8c08bd7dc86eb9d1f943cba32d79df52..a821b532db92ab94c182eb61467f92333a141111 100644
--- a/ui/gfx/render_text.cc
+++ b/ui/gfx/render_text.cc
@@ -1255,8 +1255,7 @@ base::string16 RenderText::Elide(const base::string16& text,
size_t hi = text.length() - 1;
const base::i18n::TextDirection text_direction = GetTextDirection();
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.
- render_text->styles_ = styles_;
+ // Restore colors. They will be truncated to size by SetText.
render_text->colors_ = colors_;
base::string16 new_text =
slicer.CutString(guess, insert_ellipsis && behavior != ELIDE_TAIL);
@@ -1282,6 +1281,25 @@ base::string16 RenderText::Elide(const base::string16& 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
// handle kerning/ligatures/etc. correctly.
const float guess_width = render_text->GetContentWidth();
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698