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

Unified Diff: ui/views/controls/textfield/textfield_model.cc

Issue 1031533002: Supports the invisible underline for native input fields. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: revised per comments. Created 5 years, 9 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 | « ui/views/controls/textfield/textfield_model.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..d270a20c0a01e8cbcaddd8a6949f208e33dd6e26 100644
--- a/ui/views/controls/textfield/textfield_model.cc
+++ b/ui/views/controls/textfield/textfield_model.cc
@@ -564,8 +564,12 @@ 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());
+ // Don't render transparent composition underlines.
+ if (composition.underlines.size() > 0 && composition.underlines[0].color != 0)
+ render_text_->SetCompositionRange(composition_range_);
+ else
+ render_text_->SetCompositionRange(gfx::Range::InvalidRange());
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 +593,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,7 +607,7 @@ void TextfieldModel::ConfirmCompositionText() {
void TextfieldModel::CancelCompositionText() {
DCHECK(HasCompositionText());
- gfx::Range range = render_text_->GetCompositionRange();
+ gfx::Range range = composition_range_;
ClearComposition();
base::string16 new_text = text();
render_text_->SetText(new_text.erase(range.start(), range.length()));
@@ -612,15 +617,16 @@ void TextfieldModel::CancelCompositionText() {
}
void TextfieldModel::ClearComposition() {
- render_text_->SetCompositionRange(gfx::Range::InvalidRange());
+ composition_range_ = gfx::Range::InvalidRange();
+ render_text_->SetCompositionRange(composition_range_);
}
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() {
« no previous file with comments | « ui/views/controls/textfield/textfield_model.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698