Chromium Code Reviews| Index: ui/views/controls/textfield/textfield_model.cc |
| diff --git a/ui/views/controls/textfield/textfield_model.cc b/ui/views/controls/textfield/textfield_model.cc |
| index 8638f924c66038acc6cdba6a8cb8a6df99d4508b..76dd8eb713870719930118bcc84aa630f7de5310 100644 |
| --- a/ui/views/controls/textfield/textfield_model.cc |
| +++ b/ui/views/controls/textfield/textfield_model.cc |
| @@ -564,8 +564,11 @@ void TextfieldModel::SetCompositionText( |
| size_t cursor = GetCursorPosition(); |
| base::string16 new_text = text(); |
| render_text_->SetText(new_text.insert(cursor, composition.text)); |
| - gfx::Range range(cursor, cursor + composition.text.length()); |
| - render_text_->SetCompositionRange(range); |
| + composition_range_ = gfx::Range(cursor, cursor + composition.text.length()); |
| + if (composition.underlines.size() > 0 && composition.underlines[0].color != 0) |
|
msw
2015/03/24 20:19:01
nit: add a comment here to explain this behavior;
Shu Chen
2015/03/26 04:22:13
Done.
|
| + render_text_->SetCompositionRange(composition_range_); |
| + else |
| + render_text_->SetCompositionRange(gfx::Range()); |
| gfx::Range emphasized_range = GetFirstEmphasizedRange(composition); |
| if (emphasized_range.IsValid()) { |
| // This is a workaround due to the lack of support in RenderText to draw |
| @@ -589,12 +592,13 @@ void TextfieldModel::SetCompositionText( |
| void TextfieldModel::ConfirmCompositionText() { |
| DCHECK(HasCompositionText()); |
| - gfx::Range range = render_text_->GetCompositionRange(); |
| - base::string16 composition = text().substr(range.start(), range.length()); |
| + base::string16 composition = text().substr( |
| + composition_range_.start(), composition_range_.length()); |
| // TODO(oshima): current behavior on ChromeOS is a bit weird and not |
| // sure exactly how this should work. Find out and fix if necessary. |
| - AddOrMergeEditHistory(new InsertEdit(false, composition, range.start())); |
| - render_text_->SetCursorPosition(range.end()); |
| + AddOrMergeEditHistory( |
| + new InsertEdit(false, composition, composition_range_.start())); |
| + render_text_->SetCursorPosition(composition_range_.end()); |
| ClearComposition(); |
| if (delegate_) |
| delegate_->OnCompositionTextConfirmedOrCleared(); |
| @@ -602,11 +606,11 @@ void TextfieldModel::ConfirmCompositionText() { |
| void TextfieldModel::CancelCompositionText() { |
| DCHECK(HasCompositionText()); |
| - gfx::Range range = render_text_->GetCompositionRange(); |
| ClearComposition(); |
| base::string16 new_text = text(); |
| - render_text_->SetText(new_text.erase(range.start(), range.length())); |
| - render_text_->SetCursorPosition(range.start()); |
| + render_text_->SetText(new_text.erase( |
| + composition_range_.start(), composition_range_.length())); |
| + render_text_->SetCursorPosition(composition_range_.start()); |
| if (delegate_) |
| delegate_->OnCompositionTextConfirmedOrCleared(); |
| } |
| @@ -616,11 +620,11 @@ void TextfieldModel::ClearComposition() { |
| } |
| void TextfieldModel::GetCompositionTextRange(gfx::Range* range) const { |
| - *range = gfx::Range(render_text_->GetCompositionRange()); |
| + *range = composition_range_; |
| } |
| bool TextfieldModel::HasCompositionText() const { |
| - return !render_text_->GetCompositionRange().is_empty(); |
| + return !composition_range_.is_empty(); |
| } |
| void TextfieldModel::ClearEditHistory() { |