Index: chrome/browser/ui/input_method/input_method_engine.cc |
diff --git a/chrome/browser/ui/input_method/input_method_engine.cc b/chrome/browser/ui/input_method/input_method_engine.cc |
index 6d5a1595a531253b974100e6f0ff8bf9ffec9084..07b598107a41cc4e714cfabddbbb972806b76175 100644 |
--- a/chrome/browser/ui/input_method/input_method_engine.cc |
+++ b/chrome/browser/ui/input_method/input_method_engine.cc |
@@ -4,10 +4,17 @@ |
#include "chrome/browser/ui/input_method/input_method_engine.h" |
+#include "chrome/browser/ui/browser.h" |
+#include "chrome/browser/ui/browser_finder.h" |
+#include "chrome/browser/ui/browser_window.h" |
#include "content/public/browser/render_frame_host.h" |
+#include "ui/aura/window.h" |
+#include "ui/aura/window_tree_host.h" |
#include "ui/base/ime/composition_text.h" |
#include "ui/base/ime/ime_bridge.h" |
#include "ui/base/ime/ime_input_context_handler_interface.h" |
+#include "ui/base/ime/input_method.h" |
+#include "ui/events/keycodes/keyboard_code_conversion.h" |
namespace { |
@@ -30,13 +37,6 @@ InputMethodEngine::~InputMethodEngine() { |
CloseImeWindows(); |
} |
-bool InputMethodEngine::SendKeyEvents( |
- int context_id, |
- const std::vector<KeyboardEvent>& events) { |
- // TODO(azurewei) Implement SendKeyEvents funciton |
- return false; |
-} |
- |
bool InputMethodEngine::IsActive() const { |
return true; |
} |
@@ -166,4 +166,40 @@ void InputMethodEngine::OnWindowDestroyed(ui::ImeWindow* ime_window) { |
} |
} |
+bool InputMethodEngine::SendKeyEvent(ui::KeyEvent* event) { |
+ Browser* browser = chrome::FindLastActiveWithProfile(profile_); |
+ if (!browser) |
+ return false; |
+ |
+ if (event->key_code() == ui::VKEY_UNKNOWN) |
+ event->set_key_code(ui::DomCodeToUsLayoutKeyboardCode(event->code())); |
+ |
+ ui::InputMethod* input_method = |
+ browser->window()->GetNativeWindow()->GetHost()->GetInputMethod(); |
+ |
+#if defined(OS_WIN) |
Shu Chen
2016/03/08 14:38:03
I think we should NOT hack for OS_WIN here.
Instea
Shu Chen
2016/03/09 04:00:24
Per offline discussion, please add SendKeyEvents()
Azure Wei
2016/03/09 05:01:57
Done. Please review the latest patch set.
|
+ const uint16_t kNativeCode = |
+ ui::KeycodeConverter::DomCodeToNativeKeycode(event->code()); |
+ const LPARAM lParam = ui::GetLParamFromScanCode(kNativeCode); |
+ |
+ MSG native_event; |
+ if (event->type() == ui::ET_KEY_PRESSED) |
+ native_event = {NULL, WM_KEYDOWN, event->key_code(), lParam}; |
+ else |
+ native_event = {NULL, WM_KEYUP, event->key_code(), lParam}; |
+ ui::KeyEvent key_event(native_event); |
+ input_method->DispatchKeyEvent(&key_event); |
+ |
+ if (event->type() == ui::ET_KEY_PRESSED && event->GetDomKey().IsCharacter()) { |
+ MSG native_event_char = {NULL, WM_CHAR, event->GetCharacter(), lParam}; |
+ ui::KeyEvent key_event_char(native_event_char); |
+ input_method->DispatchKeyEvent(&key_event_char); |
+ } |
+#else |
+ input_method->DispatchKeyEvent(event); |
+#endif |
+ |
+ return true; |
+} |
+ |
} // namespace input_method |