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

Side by Side 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: rebase. Created 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/controls/textfield/native_textfield_views.h" 5 #include "ui/views/controls/textfield/native_textfield_views.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/debug/trace_event.h" 11 #include "base/debug/trace_event.h"
12 #include "base/i18n/case_conversion.h"
12 #include "base/logging.h" 13 #include "base/logging.h"
13 #include "base/message_loop.h" 14 #include "base/message_loop.h"
14 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
15 #include "grit/app_locale_settings.h" 16 #include "grit/app_locale_settings.h"
16 #include "grit/ui_strings.h" 17 #include "grit/ui_strings.h"
17 #include "third_party/skia/include/core/SkColor.h" 18 #include "third_party/skia/include/core/SkColor.h"
18 #include "ui/base/clipboard/clipboard.h" 19 #include "ui/base/clipboard/clipboard.h"
19 #include "ui/base/dragdrop/drag_drop_types.h" 20 #include "ui/base/dragdrop/drag_drop_types.h"
20 #include "ui/base/l10n/l10n_util.h" 21 #include "ui/base/l10n/l10n_util.h"
21 #include "ui/base/range/range.h" 22 #include "ui/base/range/range.h"
22 #include "ui/gfx/canvas.h" 23 #include "ui/gfx/canvas.h"
23 #include "ui/gfx/insets.h" 24 #include "ui/gfx/insets.h"
24 #include "ui/gfx/render_text.h" 25 #include "ui/gfx/render_text.h"
25 #include "ui/views/background.h" 26 #include "ui/views/background.h"
26 #include "ui/views/border.h" 27 #include "ui/views/border.h"
27 #include "ui/views/controls/focusable_border.h" 28 #include "ui/views/controls/focusable_border.h"
28 #include "ui/views/controls/menu/menu_item_view.h" 29 #include "ui/views/controls/menu/menu_item_view.h"
29 #include "ui/views/controls/menu/menu_model_adapter.h" 30 #include "ui/views/controls/menu/menu_model_adapter.h"
30 #include "ui/views/controls/menu/menu_runner.h" 31 #include "ui/views/controls/menu/menu_runner.h"
31 #include "ui/views/controls/textfield/textfield.h" 32 #include "ui/views/controls/textfield/textfield.h"
32 #include "ui/views/controls/textfield/textfield_controller.h" 33 #include "ui/views/controls/textfield/textfield_controller.h"
33 #include "ui/views/controls/textfield/textfield_views_model.h" 34 #include "ui/views/controls/textfield/textfield_views_model.h"
34 #include "ui/views/events/event.h" 35 #include "ui/views/events/event.h"
35 #include "ui/views/ime/input_method.h" 36 #include "ui/views/ime/input_method.h"
36 #include "ui/views/metrics.h" 37 #include "ui/views/metrics.h"
37 #include "ui/views/views_delegate.h" 38 #include "ui/views/views_delegate.h"
38 #include "ui/views/widget/widget.h" 39 #include "ui/views/widget/widget.h"
40 #include "unicode/uchar.h"
39 41
40 #if defined(OS_LINUX) 42 #if defined(OS_LINUX)
41 #include "ui/gfx/gtk_util.h" 43 #include "ui/gfx/gtk_util.h"
42 #endif 44 #endif
43 45
44 #if defined(USE_AURA) 46 #if defined(USE_AURA)
45 #include "ui/aura/cursor.h" 47 #include "ui/aura/cursor.h"
46 #endif 48 #endif
47 49
48 namespace { 50 namespace {
(...skipping 24 matching lines...) Expand all
73 skip_input_method_cancel_composition_(false), 75 skip_input_method_cancel_composition_(false),
74 initiating_drag_(false), 76 initiating_drag_(false),
75 ALLOW_THIS_IN_INITIALIZER_LIST(cursor_timer_(this)), 77 ALLOW_THIS_IN_INITIALIZER_LIST(cursor_timer_(this)),
76 aggregated_clicks_(0), 78 aggregated_clicks_(0),
77 last_click_time_(), 79 last_click_time_(),
78 last_click_location_(), 80 last_click_location_(),
79 ALLOW_THIS_IN_INITIALIZER_LIST(touch_selection_controller_( 81 ALLOW_THIS_IN_INITIALIZER_LIST(touch_selection_controller_(
80 TouchSelectionController::create(this))) { 82 TouchSelectionController::create(this))) {
81 set_border(text_border_); 83 set_border(text_border_);
82 84
83 // Lowercase is not supported.
84 DCHECK_NE(parent->style(), Textfield::STYLE_LOWERCASE);
85
86 #if defined(OS_CHROMEOS) 85 #if defined(OS_CHROMEOS)
87 GetRenderText()->SetFontList(gfx::FontList(l10n_util::GetStringUTF8( 86 GetRenderText()->SetFontList(gfx::FontList(l10n_util::GetStringUTF8(
88 IDS_UI_FONT_FAMILY_CROS))); 87 IDS_UI_FONT_FAMILY_CROS)));
89 #else 88 #else
90 GetRenderText()->SetFontList(gfx::FontList(textfield_->font())); 89 GetRenderText()->SetFontList(gfx::FontList(textfield_->font()));
91 #endif 90 #endif
92 // Set the default text style. 91 // Set the default text style.
93 gfx::StyleRange default_style; 92 gfx::StyleRange default_style;
94 default_style.foreground = textfield_->text_color(); 93 default_style.foreground = textfield_->text_color();
95 GetRenderText()->set_default_style(default_style); 94 GetRenderText()->set_default_style(default_style);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 DCHECK(CanDrop(event.data())); 193 DCHECK(CanDrop(event.data()));
195 DCHECK(!initiating_drag_ || 194 DCHECK(!initiating_drag_ ||
196 !GetRenderText()->IsPointInSelection(event.location())); 195 !GetRenderText()->IsPointInSelection(event.location()));
197 OnBeforeUserAction(); 196 OnBeforeUserAction();
198 skip_input_method_cancel_composition_ = true; 197 skip_input_method_cancel_composition_ = true;
199 198
200 gfx::SelectionModel drop_destination_model = 199 gfx::SelectionModel drop_destination_model =
201 GetRenderText()->FindCursorPosition(event.location()); 200 GetRenderText()->FindCursorPosition(event.location());
202 string16 text; 201 string16 text;
203 event.data().GetString(&text); 202 event.data().GetString(&text);
203 if (textfield_->style() & Textfield::STYLE_LOWERCASE)
204 text = base::i18n::ToLower(text);
204 205
205 // We'll delete the current selection for a drag and drop within this view. 206 // We'll delete the current selection for a drag and drop within this view.
206 bool move = initiating_drag_ && !event.IsControlDown() && 207 bool move = initiating_drag_ && !event.IsControlDown() &&
207 event.source_operations() & ui::DragDropTypes::DRAG_MOVE; 208 event.source_operations() & ui::DragDropTypes::DRAG_MOVE;
208 if (move) { 209 if (move) {
209 gfx::SelectionModel selected; 210 gfx::SelectionModel selected;
210 model_->GetSelectionModel(&selected); 211 model_->GetSelectionModel(&selected);
211 // Adjust the drop destination if it is on or after the current selection. 212 // Adjust the drop destination if it is on or after the current selection.
212 size_t drop_destination = drop_destination_model.caret_pos(); 213 size_t drop_destination = drop_destination_model.caret_pos();
213 drop_destination -= 214 drop_destination -=
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 } 320 }
320 321
321 ///////////////////////////////////////////////////////////////// 322 /////////////////////////////////////////////////////////////////
322 // NativeTextfieldViews, NativeTextifieldWrapper overrides: 323 // NativeTextfieldViews, NativeTextifieldWrapper overrides:
323 324
324 string16 NativeTextfieldViews::GetText() const { 325 string16 NativeTextfieldViews::GetText() const {
325 return model_->GetText(); 326 return model_->GetText();
326 } 327 }
327 328
328 void NativeTextfieldViews::UpdateText() { 329 void NativeTextfieldViews::UpdateText() {
329 model_->SetText(textfield_->text()); 330 string16 text = textfield_->text();
331 if (textfield_->style() & Textfield::STYLE_LOWERCASE)
332 text = base::i18n::ToLower(text);
333 model_->SetText(text);
330 OnCaretBoundsChanged(); 334 OnCaretBoundsChanged();
331 SchedulePaint(); 335 SchedulePaint();
332 textfield_->GetWidget()->NotifyAccessibilityEvent( 336 textfield_->GetWidget()->NotifyAccessibilityEvent(
333 textfield_, ui::AccessibilityTypes::EVENT_TEXT_CHANGED, true); 337 textfield_, ui::AccessibilityTypes::EVENT_TEXT_CHANGED, true);
334 } 338 }
335 339
336 void NativeTextfieldViews::AppendText(const string16& text) { 340 void NativeTextfieldViews::AppendText(const string16& text) {
337 if (text.empty()) 341 if (text.empty())
338 return; 342 return;
339 model_->Append(text); 343 if (textfield_->style() & Textfield::STYLE_LOWERCASE)
344 model_->Append(base::i18n::ToLower(text));
345 else
346 model_->Append(text);
340 OnCaretBoundsChanged(); 347 OnCaretBoundsChanged();
341 SchedulePaint(); 348 SchedulePaint();
342 } 349 }
343 350
344 string16 NativeTextfieldViews::GetSelectedText() const { 351 string16 NativeTextfieldViews::GetSelectedText() const {
345 return model_->GetSelectedText(); 352 return model_->GetSelectedText();
346 } 353 }
347 354
348 void NativeTextfieldViews::SelectAll() { 355 void NativeTextfieldViews::SelectAll() {
349 OnBeforeUserAction(); 356 OnBeforeUserAction();
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 OnAfterUserAction(); 673 OnAfterUserAction();
667 } 674 }
668 675
669 void NativeTextfieldViews::InsertText(const string16& text) { 676 void NativeTextfieldViews::InsertText(const string16& text) {
670 // TODO(suzhe): Filter invalid characters. 677 // TODO(suzhe): Filter invalid characters.
671 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE || text.empty()) 678 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE || text.empty())
672 return; 679 return;
673 680
674 OnBeforeUserAction(); 681 OnBeforeUserAction();
675 skip_input_method_cancel_composition_ = true; 682 skip_input_method_cancel_composition_ = true;
683
684 string16 new_text = text;
685 if (textfield_->style() & Textfield::STYLE_LOWERCASE)
686 new_text = base::i18n::ToLower(new_text);
687
676 if (GetRenderText()->insert_mode()) 688 if (GetRenderText()->insert_mode())
677 model_->InsertText(text); 689 model_->InsertText(new_text);
678 else 690 else
679 model_->ReplaceText(text); 691 model_->ReplaceText(new_text);
680 skip_input_method_cancel_composition_ = false; 692 skip_input_method_cancel_composition_ = false;
681 UpdateAfterChange(true, true); 693 UpdateAfterChange(true, true);
682 OnAfterUserAction(); 694 OnAfterUserAction();
683 } 695 }
684 696
685 void NativeTextfieldViews::InsertChar(char16 ch, int flags) { 697 void NativeTextfieldViews::InsertChar(char16 ch, int flags) {
jungshik at Google 2012/03/26 22:04:34 This is not a part of your change, but this API se
kochi 2012/04/09 06:34:20 According to the native_textfield_views.h comment,
686 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE || 698 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE ||
687 !ShouldInsertChar(ch, flags)) { 699 !ShouldInsertChar(ch, flags)) {
688 return; 700 return;
689 } 701 }
690 702
703 if (textfield_->style() & Textfield::STYLE_LOWERCASE)
704 ch = u_tolower(ch);
705
691 OnBeforeUserAction(); 706 OnBeforeUserAction();
692 skip_input_method_cancel_composition_ = true; 707 skip_input_method_cancel_composition_ = true;
693 if (GetRenderText()->insert_mode()) 708 if (GetRenderText()->insert_mode())
694 model_->InsertChar(ch); 709 model_->InsertChar(ch);
695 else 710 else
696 model_->ReplaceChar(ch); 711 model_->ReplaceChar(ch);
697 skip_input_method_cancel_composition_ = false; 712 skip_input_method_cancel_composition_ = false;
698 UpdateAfterChange(true, true); 713 UpdateAfterChange(true, true);
699 OnAfterUserAction(); 714 OnAfterUserAction();
700 } 715 }
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 if (controller) 1054 if (controller)
1040 controller->OnAfterCutOrCopy(); 1055 controller->OnAfterCutOrCopy();
1041 return true; 1056 return true;
1042 } 1057 }
1043 return false; 1058 return false;
1044 } 1059 }
1045 1060
1046 bool NativeTextfieldViews::Paste() { 1061 bool NativeTextfieldViews::Paste() {
1047 const bool success = model_->Paste(); 1062 const bool success = model_->Paste();
1048 1063
1064 if (textfield_->style() & Textfield::STYLE_LOWERCASE) {
1065 string16 text = model_->GetText();
1066 text = base::i18n::ToLower(text);
1067 model_->SetText(text);
1068 }
1069
1049 // Calls TextfieldController::ContentsChanged() explicitly if the paste action 1070 // Calls TextfieldController::ContentsChanged() explicitly if the paste action
1050 // did not change the content at all. See http://crbug.com/79002 1071 // did not change the content at all. See http://crbug.com/79002
1051 if (success && GetText() == textfield_->text()) { 1072 if (success && GetText() == textfield_->text()) {
1052 TextfieldController* controller = textfield_->GetController(); 1073 TextfieldController* controller = textfield_->GetController();
1053 if (controller) 1074 if (controller)
1054 controller->ContentsChanged(textfield_, textfield_->text()); 1075 controller->ContentsChanged(textfield_, textfield_->text());
1055 } 1076 }
1056 return success; 1077 return success;
1057 } 1078 }
1058 1079
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1119 1140
1120 #if defined(USE_AURA) 1141 #if defined(USE_AURA)
1121 // static 1142 // static
1122 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( 1143 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper(
1123 Textfield* field) { 1144 Textfield* field) {
1124 return new NativeTextfieldViews(field); 1145 return new NativeTextfieldViews(field);
1125 } 1146 }
1126 #endif 1147 #endif
1127 1148
1128 } // namespace views 1149 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698