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

Side by Side Diff: ui/views/controls/textfield/textfield_unittest.cc

Issue 1257603006: Refactoring for the InputMethod & InputMethodDelegate interfaces. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed Sadrul's comment. Created 5 years, 4 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/textfield.h" 5 #include "ui/views/controls/textfield/textfield.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 const base::char16 kHebrewLetterSamekh = 0x05E1; 66 const base::char16 kHebrewLetterSamekh = 0x05E1;
67 67
68 class MockInputMethod : public ui::InputMethodBase { 68 class MockInputMethod : public ui::InputMethodBase {
69 public: 69 public:
70 MockInputMethod(); 70 MockInputMethod();
71 ~MockInputMethod() override; 71 ~MockInputMethod() override;
72 72
73 // Overridden from InputMethod: 73 // Overridden from InputMethod:
74 bool OnUntranslatedIMEMessage(const base::NativeEvent& event, 74 bool OnUntranslatedIMEMessage(const base::NativeEvent& event,
75 NativeEventResult* result) override; 75 NativeEventResult* result) override;
76 bool DispatchKeyEvent(const ui::KeyEvent& key) override; 76 void DispatchKeyEvent(ui::KeyEvent* key) override;
77 void OnTextInputTypeChanged(const ui::TextInputClient* client) override; 77 void OnTextInputTypeChanged(const ui::TextInputClient* client) override;
78 void OnCaretBoundsChanged(const ui::TextInputClient* client) override {} 78 void OnCaretBoundsChanged(const ui::TextInputClient* client) override {}
79 void CancelComposition(const ui::TextInputClient* client) override; 79 void CancelComposition(const ui::TextInputClient* client) override;
80 void OnInputLocaleChanged() override {} 80 void OnInputLocaleChanged() override {}
81 std::string GetInputLocale() override; 81 std::string GetInputLocale() override;
82 bool IsCandidatePopupOpen() const override; 82 bool IsCandidatePopupOpen() const override;
83 void ShowImeIfNeeded() override {} 83 void ShowImeIfNeeded() override {}
84 84
85 bool untranslated_ime_message_called() const { 85 bool untranslated_ime_message_called() const {
86 return untranslated_ime_message_called_; 86 return untranslated_ime_message_called_;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 MockInputMethod::~MockInputMethod() { 134 MockInputMethod::~MockInputMethod() {
135 } 135 }
136 136
137 bool MockInputMethod::OnUntranslatedIMEMessage(const base::NativeEvent& event, 137 bool MockInputMethod::OnUntranslatedIMEMessage(const base::NativeEvent& event,
138 NativeEventResult* result) { 138 NativeEventResult* result) {
139 if (result) 139 if (result)
140 *result = NativeEventResult(); 140 *result = NativeEventResult();
141 return false; 141 return false;
142 } 142 }
143 143
144 bool MockInputMethod::DispatchKeyEvent(const ui::KeyEvent& key) { 144 void MockInputMethod::DispatchKeyEvent(ui::KeyEvent* key) {
145 // Checks whether the key event is from EventGenerator on Windows which will 145 // Checks whether the key event is from EventGenerator on Windows which will
146 // generate key event for WM_CHAR. 146 // generate key event for WM_CHAR.
147 // The MockInputMethod will insert char on WM_KEYDOWN so ignore WM_CHAR here. 147 // The MockInputMethod will insert char on WM_KEYDOWN so ignore WM_CHAR here.
148 if (key.is_char() && key.HasNativeEvent()) 148 if (key->is_char() && key->HasNativeEvent())
149 return true; 149 return;
150 150
151 bool handled = !IsTextInputTypeNone() && HasComposition(); 151 bool handled = !IsTextInputTypeNone() && HasComposition();
152 ClearStates(); 152 ClearStates();
153 if (handled) { 153 if (handled) {
154 DCHECK(!key.is_char()); 154 DCHECK(!key->is_char());
155 ui::KeyEvent mock_key(ui::ET_KEY_PRESSED, ui::VKEY_PROCESSKEY, key.flags()); 155 ui::KeyEvent mock_key(ui::ET_KEY_PRESSED,
156 DispatchKeyEventPostIME(mock_key); 156 ui::VKEY_PROCESSKEY,
157 key->flags());
158 DispatchKeyEventPostIME(&mock_key);
157 } else { 159 } else {
158 DispatchKeyEventPostIME(key); 160 DispatchKeyEventPostIME(key);
159 } 161 }
160 162
161 ui::TextInputClient* client = GetTextInputClient(); 163 ui::TextInputClient* client = GetTextInputClient();
162 if (client) { 164 if (client) {
163 if (handled) { 165 if (handled) {
164 if (result_text_.length()) 166 if (result_text_.length())
165 client->InsertText(result_text_); 167 client->InsertText(result_text_);
166 if (composition_.text.length()) 168 if (composition_.text.length())
167 client->SetCompositionText(composition_); 169 client->SetCompositionText(composition_);
168 else 170 else
169 client->ClearCompositionText(); 171 client->ClearCompositionText();
170 } else if (key.type() == ui::ET_KEY_PRESSED) { 172 } else if (key->type() == ui::ET_KEY_PRESSED) {
171 base::char16 ch = key.GetCharacter(); 173 base::char16 ch = key->GetCharacter();
172 if (ch) 174 if (ch)
173 client->InsertChar(ch, key.flags()); 175 client->InsertChar(ch, key->flags());
174 } 176 }
175 } 177 }
176 178
177 ClearComposition(); 179 ClearComposition();
178 return true;
179 } 180 }
180 181
181 void MockInputMethod::OnTextInputTypeChanged( 182 void MockInputMethod::OnTextInputTypeChanged(
182 const ui::TextInputClient* client) { 183 const ui::TextInputClient* client) {
183 if (IsTextInputClientFocused(client)) 184 if (IsTextInputClientFocused(client))
184 text_input_type_changed_ = true; 185 text_input_type_changed_ = true;
185 InputMethodBase::OnTextInputTypeChanged(client); 186 InputMethodBase::OnTextInputTypeChanged(client);
186 } 187 }
187 188
188 void MockInputMethod::CancelComposition(const ui::TextInputClient* client) { 189 void MockInputMethod::CancelComposition(const ui::TextInputClient* client) {
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 478
478 #if defined(OS_MACOSX) && !defined(USE_AURA) 479 #if defined(OS_MACOSX) && !defined(USE_AURA)
479 // The Mac EventGenerator hooks in before IME. It sends events first to an 480 // The Mac EventGenerator hooks in before IME. It sends events first to an
480 // NSResponder, which is necessary to interpret keyboard events into 481 // NSResponder, which is necessary to interpret keyboard events into
481 // appropriate editing commands. 482 // appropriate editing commands.
482 event_generator_->PressKey(key_code, flags); 483 event_generator_->PressKey(key_code, flags);
483 #else 484 #else
484 // TODO(shuchen): making EventGenerator support input method and using 485 // TODO(shuchen): making EventGenerator support input method and using
485 // EventGenerator here. crbug.com/512315. 486 // EventGenerator here. crbug.com/512315.
486 ui::KeyEvent event(ui::ET_KEY_PRESSED, key_code, flags); 487 ui::KeyEvent event(ui::ET_KEY_PRESSED, key_code, flags);
487 input_method_->DispatchKeyEvent(event); 488 input_method_->DispatchKeyEvent(&event);
488 #endif 489 #endif
489 } 490 }
490 491
491 void SendKeyEvent(ui::KeyboardCode key_code, 492 void SendKeyEvent(ui::KeyboardCode key_code,
492 bool shift, 493 bool shift,
493 bool control_or_command) { 494 bool control_or_command) {
494 SendKeyEvent(key_code, false, shift, control_or_command, false); 495 SendKeyEvent(key_code, false, shift, control_or_command, false);
495 } 496 }
496 497
497 void SendKeyEvent(ui::KeyboardCode key_code) { 498 void SendKeyEvent(ui::KeyboardCode key_code) {
498 SendKeyEvent(key_code, false, false); 499 SendKeyEvent(key_code, false, false);
499 } 500 }
500 501
501 void SendKeyEvent(base::char16 ch) { 502 void SendKeyEvent(base::char16 ch) {
502 if (ch < 0x80) { 503 if (ch < 0x80) {
503 ui::KeyboardCode code = 504 ui::KeyboardCode code =
504 ch == ' ' ? ui::VKEY_SPACE : 505 ch == ' ' ? ui::VKEY_SPACE :
505 static_cast<ui::KeyboardCode>(ui::VKEY_A + ch - 'a'); 506 static_cast<ui::KeyboardCode>(ui::VKEY_A + ch - 'a');
506 SendKeyEvent(code); 507 SendKeyEvent(code);
507 } else { 508 } else {
508 // For unicode characters, assume they come from IME rather than the 509 // For unicode characters, assume they come from IME rather than the
509 // keyboard. So they are dispatched directly to the input method. 510 // keyboard. So they are dispatched directly to the input method.
510 ui::KeyEvent event(ch, ui::VKEY_UNKNOWN, ui::EF_NONE); 511 ui::KeyEvent event(ch, ui::VKEY_UNKNOWN, ui::EF_NONE);
511 input_method_->DispatchKeyEvent(event); 512 input_method_->DispatchKeyEvent(&event);
512 } 513 }
513 } 514 }
514 515
515 // Sends a platform-specific move (and select) to start of line. 516 // Sends a platform-specific move (and select) to start of line.
516 void SendHomeEvent(bool shift) { 517 void SendHomeEvent(bool shift) {
517 if (TestingNativeMac()) { 518 if (TestingNativeMac()) {
518 // Use Cmd+Left on native Mac. An RTL-agnostic "end" doesn't have a 519 // Use Cmd+Left on native Mac. An RTL-agnostic "end" doesn't have a
519 // default key-binding on Mac. 520 // default key-binding on Mac.
520 SendKeyEvent(ui::VKEY_LEFT, shift /* shift */, true /* command */); 521 SendKeyEvent(ui::VKEY_LEFT, shift /* shift */, true /* command */);
521 return; 522 return;
(...skipping 2028 matching lines...) Expand 10 before | Expand all | Expand 10 after
2550 2551
2551 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); 2552 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
2552 ui::AXViewState state_protected; 2553 ui::AXViewState state_protected;
2553 textfield_->GetAccessibleState(&state_protected); 2554 textfield_->GetAccessibleState(&state_protected);
2554 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); 2555 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role);
2555 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); 2556 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value);
2556 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); 2557 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED));
2557 } 2558 }
2558 2559
2559 } // namespace views 2560 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/cocoa/bridged_native_widget.mm ('k') | ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698