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

Unified Diff: chrome/browser/ui/input_method/input_method_engine.cc

Issue 1771173002: Implement input.ime.sendKeyEvents API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Shu's comment and update implementation on Windows. Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
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
« no previous file with comments | « chrome/browser/ui/input_method/input_method_engine.h ('k') | chrome/browser/ui/input_method/input_method_engine_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698