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..5d65fcd1a71280ed62e43b9bc2b2a2bf2ca7dd11 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,7 @@ int NativeTextfieldViews::OnPerformDrop(const DropTargetEvent& event) { |
| GetRenderText()->FindCursorPosition(event.location()); |
| string16 text; |
| event.data().GetString(&text); |
| + MaybeLowerCase(&text); |
| // We'll delete the current selection for a drag and drop within this view. |
| bool move = initiating_drag_ && !event.IsControlDown() && |
| @@ -321,7 +321,9 @@ string16 NativeTextfieldViews::GetText() const { |
| } |
| void NativeTextfieldViews::UpdateText() { |
| - model_->SetText(textfield_->text()); |
| + string16 text = textfield_->text(); |
| + MaybeLowerCase(&text); |
| + model_->SetText(text); |
| OnCaretBoundsChanged(); |
| SchedulePaint(); |
| textfield_->GetWidget()->NotifyAccessibilityEvent( |
| @@ -331,7 +333,8 @@ void NativeTextfieldViews::UpdateText() { |
| void NativeTextfieldViews::AppendText(const string16& text) { |
| if (text.empty()) |
| return; |
| - model_->Append(text); |
| + model_->Append(textfield_->style() & Textfield::STYLE_LOWERCASE ? |
| + base::i18n::ToLower(text) : text); |
| OnCaretBoundsChanged(); |
| SchedulePaint(); |
| } |
| @@ -668,10 +671,14 @@ void NativeTextfieldViews::InsertText(const string16& text) { |
| OnBeforeUserAction(); |
| skip_input_method_cancel_composition_ = true; |
| + |
| + string16 new_text = text; |
| + MaybeLowerCase(&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 +697,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 +1060,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 |
|
msw
2012/04/12 16:15:29
Every call to MaybeLowerCase is sent to the model.
kochi
2012/04/13 09:44:09
Sorry, I'm not clear about your comment.
If the co
msw
2012/04/13 18:13:25
Yeah, it's not necessarily the right approach; jus
|
| + // 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; |
| } |
| @@ -1109,6 +1130,11 @@ bool NativeTextfieldViews::ImeEditingAllowed() const { |
| return (t != ui::TEXT_INPUT_TYPE_NONE && t != ui::TEXT_INPUT_TYPE_PASSWORD); |
| } |
| +void NativeTextfieldViews::MaybeLowerCase(string16* text) { |
|
sky
2012/04/12 15:28:56
I think making this return the string would make f
msw
2012/04/12 16:15:29
Ditto to Sky's comment:
Each MaybeLowerCase string
kochi
2012/04/13 09:44:09
Done.
|
| + if (textfield_->style() & Textfield::STYLE_LOWERCASE) |
| + *text = base::i18n::ToLower(*text); |
| +} |
| + |
| // static |
| bool NativeTextfieldViews::ShouldInsertChar(char16 ch, int flags) { |
| // Filter out all control characters, including tab and new line characters, |