Chromium Code Reviews| Index: ui/views/controls/textfield/native_textfield_views.cc |
| diff --git a/ui/views/controls/textfield/native_textfield_views.cc b/ui/views/controls/textfield/native_textfield_views.cc |
| index a635e0baf6e38acd99aca1fe4f5d5e999a6df942..a33240257ce2fded1c5cd9674d37c46ecf1c56d6 100644 |
| --- a/ui/views/controls/textfield/native_textfield_views.cc |
| +++ b/ui/views/controls/textfield/native_textfield_views.cc |
| @@ -9,6 +9,7 @@ |
| #include "base/bind.h" |
| #include "base/command_line.h" |
| #include "base/debug/trace_event.h" |
| +#include "base/i18n/case_conversion.h" |
| #include "base/logging.h" |
| #include "base/message_loop.h" |
| #include "base/utf_string_conversions.h" |
| @@ -37,6 +38,7 @@ |
| #include "ui/views/metrics.h" |
| #include "ui/views/views_delegate.h" |
| #include "ui/views/widget/widget.h" |
| +#include "unicode/uchar.h" |
| #if defined(USE_AURA) |
| #include "ui/base/cursor/cursor.h" |
| @@ -77,9 +79,6 @@ NativeTextfieldViews::NativeTextfieldViews(Textfield* parent) |
| TouchSelectionController::create(this))) { |
| set_border(text_border_); |
| - // Lowercase is not supported. |
| - DCHECK_NE(parent->style(), Textfield::STYLE_LOWERCASE); |
| - |
| #if defined(OS_CHROMEOS) |
| GetRenderText()->SetFontList(gfx::FontList(l10n_util::GetStringUTF8( |
| IDS_UI_FONT_FAMILY_CROS))); |
| @@ -198,6 +197,8 @@ int NativeTextfieldViews::OnPerformDrop(const DropTargetEvent& event) { |
| GetRenderText()->FindCursorPosition(event.location()); |
| string16 text; |
| event.data().GetString(&text); |
| + if (textfield_->style() & Textfield::STYLE_LOWERCASE) |
|
sky
2012/04/12 03:58:33
You check STYLE_LOWERCASE in a number of places. H
kochi
2012/04/12 05:39:01
Added MaybeLowerCase() and use it where possible.
|
| + text = base::i18n::ToLower(text); |
| // We'll delete the current selection for a drag and drop within this view. |
| bool move = initiating_drag_ && !event.IsControlDown() && |
| @@ -321,7 +322,10 @@ string16 NativeTextfieldViews::GetText() const { |
| } |
| void NativeTextfieldViews::UpdateText() { |
| - model_->SetText(textfield_->text()); |
| + string16 text = textfield_->text(); |
| + if (textfield_->style() & Textfield::STYLE_LOWERCASE) |
| + text = base::i18n::ToLower(text); |
| + model_->SetText(text); |
| OnCaretBoundsChanged(); |
| SchedulePaint(); |
| textfield_->GetWidget()->NotifyAccessibilityEvent( |
| @@ -331,7 +335,10 @@ void NativeTextfieldViews::UpdateText() { |
| void NativeTextfieldViews::AppendText(const string16& text) { |
| if (text.empty()) |
| return; |
| - model_->Append(text); |
| + if (textfield_->style() & Textfield::STYLE_LOWERCASE) |
| + model_->Append(base::i18n::ToLower(text)); |
| + else |
| + model_->Append(text); |
| OnCaretBoundsChanged(); |
| SchedulePaint(); |
| } |
| @@ -668,10 +675,15 @@ void NativeTextfieldViews::InsertText(const string16& text) { |
| OnBeforeUserAction(); |
| skip_input_method_cancel_composition_ = true; |
| + |
| + string16 new_text = text; |
| + if (textfield_->style() & Textfield::STYLE_LOWERCASE) |
| + new_text = base::i18n::ToLower(new_text); |
| + |
| if (GetRenderText()->insert_mode()) |
| - model_->InsertText(text); |
| + model_->InsertText(new_text); |
| else |
| - model_->ReplaceText(text); |
| + model_->ReplaceText(new_text); |
| skip_input_method_cancel_composition_ = false; |
| UpdateAfterChange(true, true); |
| OnAfterUserAction(); |
| @@ -690,6 +702,10 @@ void NativeTextfieldViews::InsertChar(char16 ch, int flags) { |
| else |
| model_->ReplaceChar(ch); |
| skip_input_method_cancel_composition_ = false; |
| + |
| + if (textfield_->style() & Textfield::STYLE_LOWERCASE) |
| + model_->SetText(base::i18n::ToLower(GetText())); |
| + |
| UpdateAfterChange(true, true); |
| OnAfterUserAction(); |
| } |
| @@ -1049,12 +1065,22 @@ bool NativeTextfieldViews::Copy() { |
| bool NativeTextfieldViews::Paste() { |
| const bool success = model_->Paste(); |
| - // Calls TextfieldController::ContentsChanged() explicitly if the paste action |
| - // did not change the content at all. See http://crbug.com/79002 |
| - if (success && GetText() == textfield_->text()) { |
| - TextfieldController* controller = textfield_->GetController(); |
| - if (controller) |
| - controller->ContentsChanged(textfield_, textfield_->text()); |
| + if (success) { |
| + string16 textfield_text = textfield_->text(); |
| + // As Paste is handled in model_->Paste(), the RenderText may contain |
| + // upper case characters. This is not consistent with other places |
| + // which keeps RenderText only containing lower case characters. |
| + if (textfield_->style() & Textfield::STYLE_LOWERCASE) { |
| + model_->SetText(base::i18n::ToLower(GetText())); |
| + textfield_text = base::i18n::ToLower(textfield_text); |
| + } |
| + // Calls TextfieldController::ContentsChanged() explicitly if the paste |
| + // action did not change the content at all. See http://crbug.com/79002 |
| + if (GetText() == textfield_text) { |
| + TextfieldController* controller = textfield_->GetController(); |
| + if (controller) |
| + controller->ContentsChanged(textfield_, textfield_->text()); |
| + } |
| } |
| return success; |
| } |