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

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

Issue 9358049: Implement STYLE_LOWERCASE style for Aura NativeTextfield. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update for comments. Created 8 years, 8 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
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 299d5a7de1d299fc930f2d0427f03769ba11fafb..9a01779ca92cbccf2769405ee7a44f69342fa148 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)
+ 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();
}
@@ -1042,12 +1058,20 @@ 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) {
+ // As Paste is handled in model_->Paste(), the RenderText may contain
+ // lower-case characters. This is not consistent with other places
msw 2012/04/09 18:29:24 I think you mean "upper case" here, not "lower-cas
kochi 2012/04/10 07:38:11 Good catch, thanks!
+ // which keeps RenderText only containing lower case characters.
+ if (textfield_->style() & Textfield::STYLE_LOWERCASE)
+ model_->SetText(base::i18n::ToLower(GetText()));
+
+ // Calls TextfieldController::ContentsChanged() explicitly if the paste
+ // action did not change the content at all. See http://crbug.com/79002
msw 2012/04/09 18:29:24 This isn't part of your change, but I don't unders
kochi 2012/04/10 07:38:11 I suppose that this case is for when you have sele
msw 2012/04/10 07:50:25 Yes, that's the intent, but TextfieldViewsModel::P
xji 2012/04/10 22:53:27 Looks like it is the wrong comment. As long as the
kochi 2012/04/11 01:56:41 OK, I changed the original comment in TextfieldVie
+ if (GetText() == textfield_->text()) {
+ TextfieldController* controller = textfield_->GetController();
+ if (controller)
+ controller->ContentsChanged(textfield_, textfield_->text());
+ }
}
return success;
}

Powered by Google App Engine
This is Rietveld 408576698