Chromium Code Reviews| Index: ui/gfx/render_text.cc |
| diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc |
| index 2b51d8aa8c75156871e18fda188ba726cad0c33a..9e75dafc44e81977f0890fa3ad30604559e6bcc7 100644 |
| --- a/ui/gfx/render_text.cc |
| +++ b/ui/gfx/render_text.cc |
| @@ -445,21 +445,17 @@ void RenderText::SetText(const base::string16& text) { |
| DCHECK(!composition_range_.IsValid()); |
| if (text_ == text) |
| return; |
| - text_ = text; |
| + text_.clear(); |
| + AppendText(text); |
| - // Adjust ranged styles, baselines, and colors to accommodate a new text |
| - // length. Clear style ranges as they might break new text graphemes and apply |
| + // 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); |
| + colors_.SetValue(colors_.breaks().begin()->second); |
| baselines_.SetValue(baselines_.breaks().begin()->second); |
| - baselines_.SetMax(text_length); |
| for (size_t style = 0; style < NUM_TEXT_STYLES; ++style) { |
|
msw
2015/03/18 18:03:37
nit: inline this for a one-liner and remove loop c
dschuyler
2015/03/18 19:16:49
Done.
|
| 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 |
| // or SetCursorPosition in upper layer. |
| @@ -468,7 +464,19 @@ void RenderText::SetText(const base::string16& text) { |
| // Invalidate the cached text direction if it depends on the text contents. |
| if (directionality_mode_ == DIRECTIONALITY_FROM_TEXT) |
| text_direction_ = base::i18n::UNKNOWN_DIRECTION; |
| +} |
| +void RenderText::AppendText(const base::string16& text) { |
| + text_ += text; |
| + // Adjust ranged styles and colors to accommodate a new text length. |
| + const size_t text_length = text_.length(); |
| + colors_.SetMax(text_length); |
| + baselines_.SetMax(text_length); |
| + for (size_t style = 0; style < NUM_TEXT_STYLES; ++style) { |
| + BreakList<bool>& break_list = styles_[style]; |
|
msw
2015/03/18 18:03:37
ditto nit: inline this for a one-liner and remove
dschuyler
2015/03/18 19:16:49
Done.
|
| + break_list.SetMax(text_length); |
| + } |
| + cached_bounds_and_offset_valid_ = false; |
| obscured_reveal_index_ = -1; |
| OnTextAttributeChanged(); |
|
msw
2015/03/18 18:03:37
+CC oshima... I think that calling this in the mid
dschuyler
2015/03/18 19:16:49
I went ahead and separated out AppendText into a D
|
| } |