OLD | NEW |
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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 protected: | 245 protected: |
246 void SendKeyEvent(ui::KeyboardCode key_code, | 246 void SendKeyEvent(ui::KeyboardCode key_code, |
247 bool alt, | 247 bool alt, |
248 bool shift, | 248 bool shift, |
249 bool control, | 249 bool control, |
250 bool caps_lock) { | 250 bool caps_lock) { |
251 int flags = (alt ? ui::EF_ALT_DOWN : 0) | | 251 int flags = (alt ? ui::EF_ALT_DOWN : 0) | |
252 (shift ? ui::EF_SHIFT_DOWN : 0) | | 252 (shift ? ui::EF_SHIFT_DOWN : 0) | |
253 (control ? ui::EF_CONTROL_DOWN : 0) | | 253 (control ? ui::EF_CONTROL_DOWN : 0) | |
254 (caps_lock ? ui::EF_CAPS_LOCK_DOWN : 0); | 254 (caps_lock ? ui::EF_CAPS_LOCK_DOWN : 0); |
255 ui::KeyEvent event(ui::ET_KEY_PRESSED, key_code, flags, false); | 255 ui::KeyEvent event(ui::ET_KEY_PRESSED, key_code, flags); |
256 input_method_->DispatchKeyEvent(event); | 256 input_method_->DispatchKeyEvent(event); |
257 } | 257 } |
258 | 258 |
259 void SendKeyEvent(ui::KeyboardCode key_code, bool shift, bool control) { | 259 void SendKeyEvent(ui::KeyboardCode key_code, bool shift, bool control) { |
260 SendKeyEvent(key_code, false, shift, control, false); | 260 SendKeyEvent(key_code, false, shift, control, false); |
261 } | 261 } |
262 | 262 |
263 void SendKeyEvent(ui::KeyboardCode key_code) { | 263 void SendKeyEvent(ui::KeyboardCode key_code) { |
264 SendKeyEvent(key_code, false, false); | 264 SendKeyEvent(key_code, false, false); |
265 } | 265 } |
266 | 266 |
267 void SendKeyEvent(base::char16 ch) { | 267 void SendKeyEvent(base::char16 ch) { |
268 if (ch < 0x80) { | 268 if (ch < 0x80) { |
269 ui::KeyboardCode code = | 269 ui::KeyboardCode code = |
270 ch == ' ' ? ui::VKEY_SPACE : | 270 ch == ' ' ? ui::VKEY_SPACE : |
271 static_cast<ui::KeyboardCode>(ui::VKEY_A + ch - 'a'); | 271 static_cast<ui::KeyboardCode>(ui::VKEY_A + ch - 'a'); |
272 SendKeyEvent(code); | 272 SendKeyEvent(code); |
273 } else { | 273 } else { |
274 ui::KeyEvent event(ui::ET_KEY_PRESSED, ui::VKEY_UNKNOWN, 0, false); | 274 ui::KeyEvent event(ch, ui::VKEY_UNKNOWN, ui::EF_NONE); |
275 event.set_character(ch); | |
276 input_method_->DispatchKeyEvent(event); | 275 input_method_->DispatchKeyEvent(event); |
277 } | 276 } |
278 } | 277 } |
279 | 278 |
280 View* GetFocusedView() { | 279 View* GetFocusedView() { |
281 return widget_->GetFocusManager()->GetFocusedView(); | 280 return widget_->GetFocusManager()->GetFocusedView(); |
282 } | 281 } |
283 | 282 |
284 int GetCursorPositionX(int cursor_pos) { | 283 int GetCursorPositionX(int cursor_pos) { |
285 return test_api_->GetRenderText()->GetCursorBounds( | 284 return test_api_->GetRenderText()->GetCursorBounds( |
(...skipping 1736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2022 TextfieldDestroyerController controller(textfield_); | 2021 TextfieldDestroyerController controller(textfield_); |
2023 EXPECT_TRUE(controller.target()); | 2022 EXPECT_TRUE(controller.target()); |
2024 | 2023 |
2025 // Send a key to trigger OnKeyEvent(). | 2024 // Send a key to trigger OnKeyEvent(). |
2026 SendKeyEvent('X'); | 2025 SendKeyEvent('X'); |
2027 | 2026 |
2028 EXPECT_FALSE(controller.target()); | 2027 EXPECT_FALSE(controller.target()); |
2029 } | 2028 } |
2030 | 2029 |
2031 } // namespace views | 2030 } // namespace views |
OLD | NEW |