Chromium Code Reviews| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <set> | 10 #include <set> |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 } | 140 } |
| 141 | 141 |
| 142 bool MockInputMethod::OnUntranslatedIMEMessage(const base::NativeEvent& event, | 142 bool MockInputMethod::OnUntranslatedIMEMessage(const base::NativeEvent& event, |
| 143 NativeEventResult* result) { | 143 NativeEventResult* result) { |
| 144 if (result) | 144 if (result) |
| 145 *result = NativeEventResult(); | 145 *result = NativeEventResult(); |
| 146 return false; | 146 return false; |
| 147 } | 147 } |
| 148 | 148 |
| 149 void MockInputMethod::DispatchKeyEvent(ui::KeyEvent* key) { | 149 void MockInputMethod::DispatchKeyEvent(ui::KeyEvent* key) { |
| 150 // On Mac, emulate InputMethodMac behavior for character events. Composition | |
| 151 // still needs to be mocked, since its not possible to generate test events | |
|
tapted
2016/06/30 05:33:53
nit: its -> it's
karandeepb
2016/06/30 06:02:35
Done.
| |
| 152 // which trigger the appropriate NSResponder action messages for composition. | |
| 153 #if defined(OS_MACOSX) | |
| 154 if (key->is_char()) { | |
| 155 ignore_result(DispatchKeyEventPostIME(key)); | |
| 156 return; | |
| 157 } | |
| 158 #endif | |
| 159 | |
| 150 // Checks whether the key event is from EventGenerator on Windows which will | 160 // Checks whether the key event is from EventGenerator on Windows which will |
| 151 // generate key event for WM_CHAR. | 161 // generate key event for WM_CHAR. |
| 152 // The MockInputMethod will insert char on WM_KEYDOWN so ignore WM_CHAR here. | 162 // The MockInputMethod will insert char on WM_KEYDOWN so ignore WM_CHAR here. |
| 153 if (key->is_char() && key->HasNativeEvent()) { | 163 if (key->is_char() && key->HasNativeEvent()) { |
| 154 key->SetHandled(); | 164 key->SetHandled(); |
| 155 return; | 165 return; |
| 156 } | 166 } |
| 157 | 167 |
| 158 bool handled = !IsTextInputTypeNone() && HasComposition(); | 168 bool handled = !IsTextInputTypeNone() && HasComposition(); |
| 159 ClearStates(); | 169 ClearStates(); |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 503 } | 513 } |
| 504 | 514 |
| 505 void SendKeyEvent(base::char16 ch) { | 515 void SendKeyEvent(base::char16 ch) { |
| 506 if (ch < 0x80) { | 516 if (ch < 0x80) { |
| 507 ui::KeyboardCode code = | 517 ui::KeyboardCode code = |
| 508 ch == ' ' ? ui::VKEY_SPACE : | 518 ch == ' ' ? ui::VKEY_SPACE : |
| 509 static_cast<ui::KeyboardCode>(ui::VKEY_A + ch - 'a'); | 519 static_cast<ui::KeyboardCode>(ui::VKEY_A + ch - 'a'); |
| 510 SendKeyEvent(code); | 520 SendKeyEvent(code); |
| 511 } else { | 521 } else { |
| 512 // For unicode characters, assume they come from IME rather than the | 522 // For unicode characters, assume they come from IME rather than the |
| 513 // keyboard. So they are dispatched directly to the input method. | 523 // keyboard. So they are dispatched directly to the input method. But on |
| 524 // Mac, key events don't pass through InputMethod. Hence they are | |
| 525 // dispatched regularly. | |
| 514 ui::KeyEvent event(ch, ui::VKEY_UNKNOWN, ui::EF_NONE); | 526 ui::KeyEvent event(ch, ui::VKEY_UNKNOWN, ui::EF_NONE); |
| 527 #if defined(OS_MACOSX) | |
| 528 event_generator_->Dispatch(&event); | |
| 529 #else | |
| 515 input_method_->DispatchKeyEvent(&event); | 530 input_method_->DispatchKeyEvent(&event); |
| 531 #endif | |
| 516 } | 532 } |
| 517 } | 533 } |
| 518 | 534 |
| 519 // Sends a platform-specific move (and select) to the logical start of line. | 535 // Sends a platform-specific move (and select) to the logical start of line. |
| 520 // Eg. this should move (and select) to the right end of line for RTL text. | 536 // Eg. this should move (and select) to the right end of line for RTL text. |
| 521 void SendHomeEvent(bool shift) { | 537 void SendHomeEvent(bool shift) { |
| 522 if (TestingNativeMac()) { | 538 if (TestingNativeMac()) { |
| 523 // [NSResponder moveToBeginningOfLine:] is the correct way to do this on | 539 // [NSResponder moveToBeginningOfLine:] is the correct way to do this on |
| 524 // Mac, but that doesn't have a default key binding. Since | 540 // Mac, but that doesn't have a default key binding. Since |
| 525 // views::Textfield doesn't currently support multiple lines, the same | 541 // views::Textfield doesn't currently support multiple lines, the same |
| (...skipping 2132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2658 | 2674 |
| 2659 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | 2675 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
| 2660 ui::AXViewState state_protected; | 2676 ui::AXViewState state_protected; |
| 2661 textfield_->GetAccessibleState(&state_protected); | 2677 textfield_->GetAccessibleState(&state_protected); |
| 2662 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); | 2678 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); |
| 2663 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); | 2679 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); |
| 2664 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); | 2680 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); |
| 2665 } | 2681 } |
| 2666 | 2682 |
| 2667 } // namespace views | 2683 } // namespace views |
| OLD | NEW |