Commit f1167b4f authored by Yuichiro Hanada's avatar Yuichiro Hanada Committed by Chromium LUCI CQ

arc: Fall back to use scancode if key_code is not available.

The proxy IME in Android sometimes fail to find the appropriate
KeyboardCode for a Android's KEYCODE. The proxy IME uses
ui::VKEY_UNKNOWN for the key event.
However, it's rejected in a validation code and the mojo connection is
closed as a result.
This CL adds a new optional field in KeyEventData struct for a scan code
of a key event.
The field will be used when the proxy IME fails to find the appropriate
KeyboardCode.

Bug: b:174259561
Test: component_unittests
Change-Id: If4cf5514bdb6cc7026964025e42e4ae6bc3e57b0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2567141
Commit-Queue: Yuichiro Hanada <yhanada@chromium.org>
Reviewed-by: default avatarJorge Lucangeli Obes <jorgelo@chromium.org>
Reviewed-by: default avatarTetsui Ohkubo <tetsui@chromium.org>
Cr-Commit-Position: refs/heads/master@{#833105}
parent 8969b6ab
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Next MinVersion: 16
// Next MinVersion: 17
module arc.mojom;
......@@ -54,6 +54,10 @@ struct KeyEventData {
bool is_control_down;
bool is_alt_down;
bool is_capslock_on;
// An optional field used if |key_code| is undefined.
// It should be one of evdev codes (i.e. KEY_* defines)
// in <linux/input-event-codes.h>.
[MinVersion=16] uint32 scan_code;
};
// Next method ID: 8
......
......@@ -4,6 +4,8 @@
#include "components/arc/mojom/ime_mojom_traits.h"
#include "ui/events/keycodes/dom/dom_code.h"
#include "ui/events/keycodes/dom/keycode_converter.h"
#include "ui/events/keycodes/keyboard_code_conversion.h"
namespace mojo {
......@@ -16,8 +18,13 @@ bool StructTraits<arc::mojom::KeyEventDataDataView, KeyEventUniquePtr>::Read(
data.pressed() ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED;
// TODO(yhanada): Currently we have no way to know the correct keyboard layout
// here, so assuming US layout. Find a way to get the more precise DomCode.
const ui::DomCode dom_code = ui::UsLayoutKeyboardCodeToDomCode(
ui::DomCode dom_code = ui::UsLayoutKeyboardCodeToDomCode(
static_cast<ui::KeyboardCode>(data.key_code()));
if (dom_code == ui::DomCode::NONE) {
// |data.key_code| doesn't give us a proper DomCode. Let's fall back to
// scan_code.
dom_code = ui::KeycodeConverter::EvdevCodeToDomCode(data.scan_code());
}
int flags = 0;
if (data.is_shift_down())
......
......@@ -129,6 +129,9 @@ struct StructTraits<arc::mojom::KeyEventDataDataView, KeyEventUniquePtr> {
static bool is_capslock_on(const KeyEventUniquePtr& key_event) {
return key_event->IsCapsLockOn();
}
static int32_t scan_code(const KeyEventUniquePtr& key_event) {
return key_event->scan_code();
}
static bool Read(arc::mojom::KeyEventDataDataView data,
KeyEventUniquePtr* out);
......
......@@ -4,6 +4,8 @@
#include "components/arc/mojom/ime.mojom.h"
#include <linux/input.h>
#include "mojo/public/cpp/test_support/test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/events/event.h"
......@@ -41,4 +43,16 @@ TEST(KeyEventStructTraitsTest, Convert) {
}
}
TEST(KeyEventStructTraitsTest, FallbackToScancode) {
auto original = std::make_unique<ui::KeyEvent>(
ui::ET_KEY_PRESSED, ui::VKEY_UNKNOWN, ui::DomCode::NONE, ui::EF_NONE);
original->set_scan_code(KEY_A);
std::unique_ptr<ui::KeyEvent> output;
mojo::test::SerializeAndDeserialize<arc::mojom::KeyEventData>(original,
output);
EXPECT_EQ(original->type(), output->type());
EXPECT_EQ(ui::DomCode::US_A, output->code());
EXPECT_EQ(ui::VKEY_A, output->key_code());
}
} // namespace mojo
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