Commit 9c26e3fa authored by Xiyuan Xia's avatar Xiyuan Xia Committed by Commit Bot

SPM: Fix VK issue of special chars with no key code

- Make InputMethodMus not forwarding synthetic key events
  as InputMethodChromeOS does not expect to receive them;
- ChromeVirtualKeyboardDelegate to insert char to the
  correct ui::TextInputClient instance;

Bug: 931931
Change-Id: If783fcf53c833c360d6a733d22b5b30308528363
Reviewed-on: https://chromium-review.googlesource.com/c/1474635Reviewed-by: default avatarDarren Shen <shend@chromium.org>
Commit-Queue: Xiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#632396}
parent bbac65f0
......@@ -71,6 +71,16 @@ keyboard::mojom::ContainerType ConvertKeyboardModeToContainerType(int mode) {
return keyboard::mojom::ContainerType::kFullWidth;
}
// Returns the ui::TextInputClient of the active InputMethod or nullptr.
ui::TextInputClient* GetFocusedTextInputClient() {
ui::InputMethod* input_method =
ui::IMEBridge::Get()->GetInputContextHandler()->GetInputMethod();
if (!input_method)
return nullptr;
return input_method->GetTextInputClient();
}
const char kKeyDown[] = "keydown";
const char kKeyUp[] = "keyup";
......@@ -104,16 +114,12 @@ bool SendKeyEventImpl(const std::string& type,
ui::KeyboardCode code = static_cast<ui::KeyboardCode>(key_code);
ui::InputMethod* input_method = host->GetInputMethod();
if (code == ui::VKEY_UNKNOWN) {
// Handling of special printable characters (e.g. accented characters) for
// which there is no key code.
if (event_type == ui::ET_KEY_RELEASED) {
if (!input_method)
return false;
// This can be null if no text input field is focused.
ui::TextInputClient* tic = input_method->GetTextInputClient();
ui::TextInputClient* tic = GetFocusedTextInputClient();
SendProcessKeyEvent(ui::ET_KEY_PRESSED, host);
......@@ -196,12 +202,7 @@ bool ChromeVirtualKeyboardDelegate::HideKeyboard() {
bool ChromeVirtualKeyboardDelegate::InsertText(const base::string16& text) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
ui::InputMethod* input_method =
ui::IMEBridge::Get()->GetInputContextHandler()->GetInputMethod();
if (!input_method)
return false;
ui::TextInputClient* tic = input_method->GetTextInputClient();
ui::TextInputClient* tic = GetFocusedTextInputClient();
if (!tic || tic->GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE)
return false;
......
......@@ -107,8 +107,9 @@ ui::EventDispatchDetails InputMethodMus::DispatchKeyEvent(
DCHECK(event->type() == ui::ET_KEY_PRESSED ||
event->type() == ui::ET_KEY_RELEASED);
// If no text input client, do nothing.
if (!GetTextInputClient()) {
// If no text input client or the event is synthesized, dispatch the devent
// directly without forwarding it to the real input method.
if (!GetTextInputClient() || (event->flags() & ui::EF_IS_SYNTHESIZED)) {
return DispatchKeyEventPostIME(
event,
base::BindOnce(&CallEventResultCallback, std::move(ack_callback)));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment