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. | |
| 151 #if defined(OS_MACOSX) | |
| 152 ignore_result(DispatchKeyEventPostIME(key)); | |
| 153 return; | |
| 154 #endif | |
| 155 | |
| 150 // Checks whether the key event is from EventGenerator on Windows which will | 156 // Checks whether the key event is from EventGenerator on Windows which will |
| 151 // generate key event for WM_CHAR. | 157 // generate key event for WM_CHAR. |
| 152 // The MockInputMethod will insert char on WM_KEYDOWN so ignore WM_CHAR here. | 158 // The MockInputMethod will insert char on WM_KEYDOWN so ignore WM_CHAR here. |
| 153 if (key->is_char() && key->HasNativeEvent()) { | 159 if (key->is_char() && key->HasNativeEvent()) { |
| 154 key->SetHandled(); | 160 key->SetHandled(); |
| 155 return; | 161 return; |
| 156 } | 162 } |
| 157 | 163 |
| 158 bool handled = !IsTextInputTypeNone() && HasComposition(); | 164 bool handled = !IsTextInputTypeNone() && HasComposition(); |
| 159 ClearStates(); | 165 ClearStates(); |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 503 } | 509 } |
| 504 | 510 |
| 505 void SendKeyEvent(base::char16 ch) { | 511 void SendKeyEvent(base::char16 ch) { |
| 506 if (ch < 0x80) { | 512 if (ch < 0x80) { |
| 507 ui::KeyboardCode code = | 513 ui::KeyboardCode code = |
| 508 ch == ' ' ? ui::VKEY_SPACE : | 514 ch == ' ' ? ui::VKEY_SPACE : |
| 509 static_cast<ui::KeyboardCode>(ui::VKEY_A + ch - 'a'); | 515 static_cast<ui::KeyboardCode>(ui::VKEY_A + ch - 'a'); |
| 510 SendKeyEvent(code); | 516 SendKeyEvent(code); |
| 511 } else { | 517 } else { |
| 512 // For unicode characters, assume they come from IME rather than the | 518 // For unicode characters, assume they come from IME rather than the |
| 513 // keyboard. So they are dispatched directly to the input method. | 519 // keyboard. So they are dispatched directly to the input method. But on |
| 520 // Mac, key events don't pass through InputMethod. Hence they are | |
| 521 // dispatched regularly. | |
| 514 ui::KeyEvent event(ch, ui::VKEY_UNKNOWN, ui::EF_NONE); | 522 ui::KeyEvent event(ch, ui::VKEY_UNKNOWN, ui::EF_NONE); |
| 523 #if defined(OS_MACOSX) | |
| 524 event_generator_->Dispatch(&event); | |
|
tapted
2016/06/29 07:21:39
can you explain (in the CL description perhaps) wh
karandeepb
2016/06/29 07:54:07
Done.
| |
| 525 #else | |
| 515 input_method_->DispatchKeyEvent(&event); | 526 input_method_->DispatchKeyEvent(&event); |
|
karandeepb
2016/06/29 01:42:41
Not sure if the event needs to be dispatched direc
tapted
2016/06/29 07:21:39
This looks ok.. Event dispatch can be a bit crazy,
| |
| 527 #endif | |
| 516 } | 528 } |
| 517 } | 529 } |
| 518 | 530 |
| 519 // Sends a platform-specific move (and select) to the logical start of line. | 531 // 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. | 532 // Eg. this should move (and select) to the right end of line for RTL text. |
| 521 void SendHomeEvent(bool shift) { | 533 void SendHomeEvent(bool shift) { |
| 522 if (TestingNativeMac()) { | 534 if (TestingNativeMac()) { |
| 523 // [NSResponder moveToBeginningOfLine:] is the correct way to do this on | 535 // [NSResponder moveToBeginningOfLine:] is the correct way to do this on |
| 524 // Mac, but that doesn't have a default key binding. Since | 536 // Mac, but that doesn't have a default key binding. Since |
| 525 // views::Textfield doesn't currently support multiple lines, the same | 537 // views::Textfield doesn't currently support multiple lines, the same |
| (...skipping 2152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2678 | 2690 |
| 2679 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | 2691 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
| 2680 ui::AXViewState state_protected; | 2692 ui::AXViewState state_protected; |
| 2681 textfield_->GetAccessibleState(&state_protected); | 2693 textfield_->GetAccessibleState(&state_protected); |
| 2682 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); | 2694 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); |
| 2683 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); | 2695 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); |
| 2684 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); | 2696 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); |
| 2685 } | 2697 } |
| 2686 | 2698 |
| 2687 } // namespace views | 2699 } // namespace views |
| OLD | NEW |