From f2f67a5b0cd0d394752e4e4badf33a9a9097ef54 Mon Sep 17 00:00:00 2001 From: Colin Liang Date: Tue, 30 May 2023 15:20:32 -0700 Subject: [PATCH] Add Android record keycode mapping, and send the key event to Kabuki (#491) Co-authored-by: Colin Liang --- cobalt/dom/keyboard_event.cc | 4 ++++ cobalt/dom/keyboard_event_test.cc | 11 ++++++++++- cobalt/dom/keycode.h | 3 +++ starboard/android/shared/input_events_generator.cc | 4 ++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/cobalt/dom/keyboard_event.cc b/cobalt/dom/keyboard_event.cc index 892dad98cea3d..48792214adca8 100644 --- a/cobalt/dom/keyboard_event.cc +++ b/cobalt/dom/keyboard_event.cc @@ -337,6 +337,10 @@ std::string KeyboardEvent::NonPrintableKey(int32_t key_code) const { return "MediaStop"; case keycode::kMediaPlayPause: return "MediaPlayPause"; +#if SB_API_VERSION >= 15 + case keycode::kMediaRecord: + return "MediaRecord"; +#endif case keycode::kMediaLaunchMail: return "LaunchMail"; case keycode::kMediaLaunchMediaSelect: diff --git a/cobalt/dom/keyboard_event_test.cc b/cobalt/dom/keyboard_event_test.cc index ad1db1f727447..0f9843e728810 100644 --- a/cobalt/dom/keyboard_event_test.cc +++ b/cobalt/dom/keyboard_event_test.cc @@ -15,9 +15,9 @@ #include "cobalt/dom/keyboard_event.h" #include "cobalt/base/tokens.h" +#include "cobalt/dom/global_stats.h" #include "cobalt/dom/keyboard_event_init.h" #include "cobalt/dom/keycode.h" -#include "cobalt/dom/global_stats.h" #include "testing/gtest/include/gtest/gtest.h" namespace cobalt { @@ -134,6 +134,15 @@ TEST_F(KeyboardEventTest, CanGetKeyIdentifierAndKeyAndCode) { EXPECT_EQ(keyboard_event_space->key_identifier(), " "); EXPECT_EQ(keyboard_event_space->key(), " "); EXPECT_EQ(keyboard_event_space->code(), "Space"); + +#if SB_API_VERSION >= 15 + init.set_key_code(keycode::kMediaRecord); + scoped_refptr keyboard_event_record = + new KeyboardEvent("keydown", init); + EXPECT_EQ(keyboard_event_record->key_identifier(), "MediaRecord"); + EXPECT_EQ(keyboard_event_record->key(), "MediaRecord"); + EXPECT_EQ(keyboard_event_record->code(), "MediaRecord"); +#endif } TEST_F(KeyboardEventTest, CanGetAltKey) { diff --git a/cobalt/dom/keycode.h b/cobalt/dom/keycode.h index 2dd2b2fa8d126..afda18fa6df4d 100644 --- a/cobalt/dom/keycode.h +++ b/cobalt/dom/keycode.h @@ -200,6 +200,9 @@ enum { // Not present in Windows virtual key codes, but would be used by the client. kMediaRewind = 0xE3, kMediaFastForward = 0xE4, +#if SB_API_VERSION >= 15 + kMediaRecord = 0x1A0, +#endif }; } // namespace keycode diff --git a/starboard/android/shared/input_events_generator.cc b/starboard/android/shared/input_events_generator.cc index a8ef1e532fe8f..0b3452421eec6 100644 --- a/starboard/android/shared/input_events_generator.cc +++ b/starboard/android/shared/input_events_generator.cc @@ -232,6 +232,10 @@ SbKey AInputEventToSbKey(GameActivityKeyEvent* event) { return kSbKeyMediaRewind; case AKEYCODE_MEDIA_FAST_FORWARD: return kSbKeyMediaFastForward; +#if SB_API_VERSION >= 15 + case AKEYCODE_MEDIA_RECORD: + return kSbKeyRecord; +#endif // TV Remote specific case AKEYCODE_CHANNEL_UP: