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

Unified Diff: ui/gfx/render_text.cc

Issue 371413002: Don't split text runs on underline style change (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Avoid applying style change mid-grapheme Created 6 years, 3 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 | ui/gfx/render_text_unittest.cc » ('j') | 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 fe4c59cee9b3239dd18b982628203b55a885b9f6..bf98bc0cde55524f3fba35a8657a9f3bf99e8600 100644
--- a/ui/gfx/render_text.cc
+++ b/ui/gfx/render_text.cc
@@ -412,10 +412,15 @@ void RenderText::SetText(const base::string16& text) {
text_ = text;
// Adjust ranged styles and colors to accommodate a new text length.
+ // Clear style ranges as they might break new text graphemes and apply
+ // the first style to the whole text instead.
const size_t text_length = text_.length();
colors_.SetMax(text_length);
- for (size_t style = 0; style < NUM_TEXT_STYLES; ++style)
- styles_[style].SetMax(text_length);
+ for (size_t style = 0; style < NUM_TEXT_STYLES; ++style) {
+ BreakList<bool>& break_list = styles_[style];
+ break_list.SetValue(break_list.breaks().begin()->second);
+ break_list.SetMax(text_length);
+ }
cached_bounds_and_offset_valid_ = false;
// Reset selection model. SetText should always followed by SetSelectionModel
@@ -651,7 +656,12 @@ void RenderText::SetStyle(TextStyle style, bool value) {
}
void RenderText::ApplyStyle(TextStyle style, bool value, const Range& range) {
- styles_[style].ApplyValue(value, range);
+ // Do not change styles mid-grapheme to avoid breaking ligatures.
+ const size_t start = IsValidCursorIndex(range.start()) ? range.start() :
+ IndexOfAdjacentGrapheme(range.start(), CURSOR_BACKWARD);
+ const size_t end = IsValidCursorIndex(range.end()) ? range.end() :
+ IndexOfAdjacentGrapheme(range.end(), CURSOR_FORWARD);
+ styles_[style].ApplyValue(value, Range(start, end));
cached_bounds_and_offset_valid_ = false;
ResetLayout();
« no previous file with comments | « no previous file | ui/gfx/render_text_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698