| Index: ui/gfx/render_text.cc
|
| diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc
|
| index 2b51d8aa8c75156871e18fda188ba726cad0c33a..c3a4f00e0fd14524e3ad0247c4efb3085a34ee1d 100644
|
| --- a/ui/gfx/render_text.cc
|
| +++ b/ui/gfx/render_text.cc
|
| @@ -446,19 +446,14 @@ void RenderText::SetText(const base::string16& text) {
|
| if (text_ == text)
|
| return;
|
| text_ = text;
|
| + UpdateStyleLengths();
|
|
|
| - // 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) {
|
| - BreakList<bool>& break_list = styles_[style];
|
| - break_list.SetValue(break_list.breaks().begin()->second);
|
| - break_list.SetMax(text_length);
|
| - }
|
| + for (size_t style = 0; style < NUM_TEXT_STYLES; ++style)
|
| + styles_[style].SetValue(styles_[style].breaks().begin()->second);
|
| cached_bounds_and_offset_valid_ = false;
|
|
|
| // Reset selection model. SetText should always followed by SetSelectionModel
|
| @@ -473,6 +468,14 @@ void RenderText::SetText(const base::string16& text) {
|
| OnTextAttributeChanged();
|
| }
|
|
|
| +void RenderText::AppendText(const base::string16& text) {
|
| + text_ += text;
|
| + UpdateStyleLengths();
|
| + cached_bounds_and_offset_valid_ = false;
|
| + obscured_reveal_index_ = -1;
|
| + OnTextAttributeChanged();
|
| +}
|
| +
|
| void RenderText::SetHorizontalAlignment(HorizontalAlignment alignment) {
|
| if (horizontal_alignment_ != alignment) {
|
| horizontal_alignment_ = alignment;
|
| @@ -1241,6 +1244,14 @@ size_t RenderText::TextIndexToGivenTextIndex(const base::string16& given_text,
|
| return std::min<size_t>(given_text.length(), i);
|
| }
|
|
|
| +void RenderText::UpdateStyleLengths() {
|
| + 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)
|
| + styles_[style].SetMax(text_length);
|
| +}
|
| +
|
| // static
|
| bool RenderText::RangeContainsCaret(const Range& range,
|
| size_t caret_pos,
|
|
|