From d6c075db8b109488d3af331c5bf7682b8df77044 Mon Sep 17 00:00:00 2001 From: Bryant Chandler Date: Mon, 27 Mar 2023 17:50:01 +0000 Subject: [PATCH] [fuchsia] Migrate fuchsia.ui.input3 to Natural FIDL bindings Bug: 1351487 Change-Id: I7a543e660371f8d98aa1f856481870d82ffdf5c7 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4327451 Reviewed-by: David Dorwin Commit-Queue: Bryant Chandler Cr-Commit-Position: refs/heads/main@{#1122520} --- fuchsia_web/webengine/BUILD.gn | 3 +- .../webengine/browser/input_browsertest.cc | 318 +++++++++--------- .../browser/virtual_keyboard_browsertest.cc | 7 +- .../test/scoped_connection_checker.h | 22 +- ui/base/ime/fuchsia/BUILD.gn | 2 +- ui/base/ime/fuchsia/keyboard_client.cc | 163 ++++----- ui/base/ime/fuchsia/keyboard_client.h | 34 +- ui/events/BUILD.gn | 4 +- .../keyboard_code_conversion_fuchsia.cc | 28 +- .../keyboard_code_conversion_fuchsia.h | 10 +- ...yboard_code_conversion_fuchsia_unittest.cc | 13 +- ui/ozone/platform/flatland/BUILD.gn | 4 +- ui/ozone/platform/flatland/flatland_window.cc | 21 +- ui/ozone/platform/flatland/flatland_window.h | 7 +- ui/ozone/platform/scenic/BUILD.gn | 2 + ui/ozone/platform/scenic/scenic_window.cc | 21 +- ui/ozone/platform/scenic/scenic_window.h | 8 +- 17 files changed, 351 insertions(+), 316 deletions(-) diff --git a/fuchsia_web/webengine/BUILD.gn b/fuchsia_web/webengine/BUILD.gn index 292689416b4128..f794ce2cbd4070 100644 --- a/fuchsia_web/webengine/BUILD.gn +++ b/fuchsia_web/webengine/BUILD.gn @@ -610,10 +610,11 @@ test("web_engine_browsertests") { "//testing/gtest", "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.accessibility.semantics:fuchsia.accessibility.semantics_hlcpp", "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.element:fuchsia.element_hlcpp", + "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.input.virtualkeyboard:fuchsia.input.virtualkeyboard_cpp", "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.input.virtualkeyboard:fuchsia.input.virtualkeyboard_hlcpp", "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.mediacodec:fuchsia.mediacodec_hlcpp", "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.mem:fuchsia.mem_hlcpp", - "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.ui.input3:fuchsia.ui.input3_hlcpp", + "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.ui.input3:fuchsia.ui.input3_cpp", "//third_party/fuchsia-sdk/sdk/pkg/scenic_cpp", "//ui/gfx", "//ui/ozone", diff --git a/fuchsia_web/webengine/browser/input_browsertest.cc b/fuchsia_web/webengine/browser/input_browsertest.cc index 4a153c48d49715..14342fef5aa37f 100644 --- a/fuchsia_web/webengine/browser/input_browsertest.cc +++ b/fuchsia_web/webengine/browser/input_browsertest.cc @@ -2,9 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include -#include -#include +#include +#include +#include + #include #include "base/fuchsia/scoped_service_binding.h" @@ -23,11 +24,9 @@ #include "fuchsia_web/webengine/test/web_engine_browser_test.h" #include "testing/gtest/include/gtest/gtest.h" -using fuchsia::input::Key; -using fuchsia::ui::input3::KeyEvent; -using fuchsia::ui::input3::KeyEventType; -using fuchsia::ui::input3::KeyMeaning; -using fuchsia::ui::input3::NonPrintableKey; +using fuchsia_input::Key; +using fuchsia_ui_input3::KeyEvent; +using fuchsia_ui_input3::KeyEventType; namespace { @@ -39,42 +38,41 @@ const char kKeyDicts[] = "keyDicts"; // Returns a KeyEvent with |key_meaning| set based on the supplied codepoint, // the |key| field left not set. KeyEvent CreateCharacterKeyEvent(uint32_t codepoint, KeyEventType event_type) { - KeyEvent key_event; - - fuchsia::ui::input3::KeyMeaning meaning; - meaning.set_codepoint(codepoint); - key_event.set_key_meaning(std::move(meaning)); - key_event.set_type(event_type); - key_event.set_timestamp(base::TimeTicks::Now().ToZxTime()); - return key_event; + return {{ + .timestamp = base::TimeTicks::Now().ToZxTime(), + .type = event_type, + .key_meaning = fuchsia_ui_input3::KeyMeaning::WithCodepoint(codepoint), + }}; } struct KeyEventOptions { bool repeat; - std::vector modifiers; + std::vector modifiers; }; // Returns a KeyEvent with both |key| and |key_meaning| set. KeyEvent CreateKeyEvent(Key key, - KeyMeaning key_meaning, + fuchsia_ui_input3::KeyMeaning key_meaning, KeyEventType event_type, KeyEventOptions options = {}) { - KeyEvent key_event; - key_event.set_timestamp(base::TimeTicks::Now().ToZxTime()); - key_event.set_type(event_type); - key_event.set_key(key); - key_event.set_key_meaning(std::move(key_meaning)); + KeyEvent key_event{{ + .timestamp = base::TimeTicks::Now().ToZxTime(), + .type = event_type, + .key = key, + .key_meaning = std::move(key_meaning), + }}; + if (options.repeat) { // Chromium doesn't look at the value of this, it just check if the field is // present. - key_event.set_repeat_sequence(1); + key_event.repeat_sequence(1); } if (!options.modifiers.empty()) { - fuchsia::ui::input3::Modifiers modifiers; + fuchsia_ui_input3::Modifiers modifiers; for (const auto modifier : options.modifiers) { modifiers |= modifier; } - key_event.set_modifiers(modifiers); + key_event.modifiers(modifiers); } return key_event; } @@ -82,37 +80,39 @@ KeyEvent CreateKeyEvent(Key key, uint32_t codepoint, KeyEventType event_type, KeyEventOptions options = {}) { - return CreateKeyEvent(key, KeyMeaning::WithCodepoint(std::move(codepoint)), - event_type, options); + return CreateKeyEvent( + key, fuchsia_ui_input3::KeyMeaning::WithCodepoint(std::move(codepoint)), + event_type, options); } KeyEvent CreateKeyEvent(Key key, - NonPrintableKey non_printable_key, + fuchsia_ui_input3::NonPrintableKey non_printable_key, KeyEventType event_type, KeyEventOptions options = {}) { - return CreateKeyEvent( - key, KeyMeaning::WithNonPrintableKey(std::move(non_printable_key)), - event_type, options); + return CreateKeyEvent(key, + fuchsia_ui_input3::KeyMeaning::WithNonPrintableKey( + std::move(non_printable_key)), + event_type, options); } base::Value::List FuchsiaModifiersToWebModifiers( - const std::vector fuchsia_modifiers) { + const std::vector fuchsia_modifiers) { base::Value::List web_modifiers; for (const auto modifier : fuchsia_modifiers) { - if (modifier == fuchsia::ui::input3::Modifiers::ALT) { + if (modifier == fuchsia_ui_input3::Modifiers::kAlt) { web_modifiers.Append("Alt"); - } else if (modifier == fuchsia::ui::input3::Modifiers::ALT_GRAPH) { + } else if (modifier == fuchsia_ui_input3::Modifiers::kAltGraph) { web_modifiers.Append("AltGraph"); - } else if (modifier == fuchsia::ui::input3::Modifiers::CAPS_LOCK) { + } else if (modifier == fuchsia_ui_input3::Modifiers::kCapsLock) { web_modifiers.Append("CapsLock"); - } else if (modifier == fuchsia::ui::input3::Modifiers::CTRL) { + } else if (modifier == fuchsia_ui_input3::Modifiers::kCtrl) { web_modifiers.Append("Control"); - } else if (modifier == fuchsia::ui::input3::Modifiers::META) { + } else if (modifier == fuchsia_ui_input3::Modifiers::kMeta) { web_modifiers.Append("Meta"); - } else if (modifier == fuchsia::ui::input3::Modifiers::NUM_LOCK) { + } else if (modifier == fuchsia_ui_input3::Modifiers::kNumLock) { web_modifiers.Append("NumLock"); - } else if (modifier == fuchsia::ui::input3::Modifiers::SCROLL_LOCK) { + } else if (modifier == fuchsia_ui_input3::Modifiers::kScrollLock) { web_modifiers.Append("ScrollLock"); - } else if (modifier == fuchsia::ui::input3::Modifiers::SHIFT) { + } else if (modifier == fuchsia_ui_input3::Modifiers::kShift) { web_modifiers.Append("Shift"); } else { NOTREACHED() << static_cast(modifier) << " has no web mapping"; @@ -134,49 +134,46 @@ base::Value ExpectedKeyValue(base::StringPiece code, return base::Value(std::move(expected)); } -class FakeKeyboard : public fuchsia::ui::input3::testing::Keyboard_TestBase { +class FakeKeyboard : public fidl::Server { public: explicit FakeKeyboard(sys::OutgoingDirectory* additional_services) - : binding_(additional_services, this) {} + : binding_(additional_services, this, async_get_default_dispatcher()) {} ~FakeKeyboard() override = default; FakeKeyboard(const FakeKeyboard&) = delete; FakeKeyboard& operator=(const FakeKeyboard&) = delete; - base::ScopedServiceBinding* binding() { + base::ScopedNaturalServiceBinding* binding() { return &binding_; } // Sends |key_event| to |listener_|; void SendKeyEvent(KeyEvent key_event) { - listener_->OnKeyEvent(std::move(key_event), - [num_sent_events = num_sent_events_, - this](fuchsia::ui::input3::KeyEventStatus status) { - ASSERT_EQ(num_acked_events_, num_sent_events) - << "Key events are acked out of order"; - num_acked_events_++; - }); + listener_->OnKeyEvent(std::move(key_event)) + .ThenExactlyOnce( + [num_sent_events = num_sent_events_, + this](const fidl::Result< + fuchsia_ui_input3::KeyboardListener::OnKeyEvent>& result) { + ASSERT_EQ(num_acked_events_, num_sent_events) + << "Key events are acked out of order"; + num_acked_events_++; + }); num_sent_events_++; } - // fuchsia::ui::input3::Keyboard implementation. - void AddListener( - fuchsia::ui::views::ViewRef view_ref, - fidl::InterfaceHandle<::fuchsia::ui::input3::KeyboardListener> listener, - AddListenerCallback callback) final { + // fuchsia_ui_input3::Keyboard implementation. + void AddListener(AddListenerRequest& request, + AddListenerCompleter::Sync& completer) final { // This implementation is only set up to have up to one listener. EXPECT_FALSE(listener_); - listener_ = listener.Bind(); - callback(); - } - - void NotImplemented_(const std::string& name) final { - NOTIMPLEMENTED() << name; + listener_.Bind(std::move(request.listener()), + async_get_default_dispatcher()); + completer.Reply(); } private: - fuchsia::ui::input3::KeyboardListenerPtr listener_; - base::ScopedServiceBinding binding_; + fidl::Client listener_; + base::ScopedNaturalServiceBinding binding_; // Counters to make sure key events are acked in order. int num_sent_events_ = 0; @@ -214,7 +211,8 @@ class KeyboardInputTest : public WebEngineBrowserTest { component_context_.emplace( base::TestComponentContextForProcess::InitialState::kCloneAll); component_context_->additional_services() - ->RemovePublicService(); + ->RemovePublicService( + fidl::DiscoverableProtocolName); SetUpService(); virtual_keyboard_checker_.emplace( component_context_->additional_services()); @@ -269,7 +267,7 @@ class KeyboardInputTest : public WebEngineBrowserTest { absl::optional keyboard_service_; base::test::ScopedFeatureList scoped_feature_list_; absl::optional< - NeverConnectedChecker> + NeverConnectedChecker> virtual_keyboard_checker_; }; @@ -279,13 +277,13 @@ IN_PROC_BROWSER_TEST_F(KeyboardInputTest, PrintableKeys) { // Pressing character keys will generate a JavaScript keydown event followed // by a keypress event. Releasing any key generates a keyup event. keyboard_service_->SendKeyEvent( - CreateKeyEvent(Key::A, 'a', KeyEventType::PRESSED)); + CreateKeyEvent(Key::kA, 'a', KeyEventType::kPressed)); keyboard_service_->SendKeyEvent( - CreateKeyEvent(Key::KEY_8, '8', KeyEventType::PRESSED)); + CreateKeyEvent(Key::kKey8, '8', KeyEventType::kPressed)); keyboard_service_->SendKeyEvent( - CreateKeyEvent(Key::KEY_8, '8', KeyEventType::RELEASED)); + CreateKeyEvent(Key::kKey8, '8', KeyEventType::kReleased)); keyboard_service_->SendKeyEvent( - CreateKeyEvent(Key::A, 'a', KeyEventType::RELEASED)); + CreateKeyEvent(Key::kA, 'a', KeyEventType::kReleased)); ExpectKeyEventsEqual(ExpectedKeyValue("KeyA", "a", kKeyDown), ExpectedKeyValue("KeyA", "a", kKeyPress), @@ -301,11 +299,11 @@ IN_PROC_BROWSER_TEST_F(KeyboardInputTest, Characters) { // Pressing character keys will generate a JavaScript keydown event followed // by a keypress event. Releasing any key generates a keyup event. keyboard_service_->SendKeyEvent( - CreateCharacterKeyEvent('A', KeyEventType::PRESSED)); + CreateCharacterKeyEvent('A', KeyEventType::kPressed)); keyboard_service_->SendKeyEvent( - CreateCharacterKeyEvent('A', KeyEventType::RELEASED)); + CreateCharacterKeyEvent('A', KeyEventType::kReleased)); keyboard_service_->SendKeyEvent( - CreateCharacterKeyEvent('b', KeyEventType::PRESSED)); + CreateCharacterKeyEvent('b', KeyEventType::kPressed)); ExpectKeyEventsEqual( ExpectedKeyValue("", "A", kKeyDown), ExpectedKeyValue("", "A", kKeyPress), @@ -318,13 +316,13 @@ IN_PROC_BROWSER_TEST_F(KeyboardInputTest, ShiftCharacter) { // TODO(fxbug.dev/106600): Update the WithCodepoint(0)s when the platform is // fixed to provide valid KeyMeanings for these keys. keyboard_service_->SendKeyEvent( - CreateKeyEvent(Key::LEFT_SHIFT, 0, KeyEventType::PRESSED)); + CreateKeyEvent(Key::kLeftShift, 0, KeyEventType::kPressed)); keyboard_service_->SendKeyEvent( - CreateCharacterKeyEvent('a', KeyEventType::PRESSED)); + CreateCharacterKeyEvent('a', KeyEventType::kPressed)); keyboard_service_->SendKeyEvent( - CreateCharacterKeyEvent('a', KeyEventType::RELEASED)); + CreateCharacterKeyEvent('a', KeyEventType::kReleased)); keyboard_service_->SendKeyEvent( - CreateKeyEvent(Key::LEFT_SHIFT, 0, KeyEventType::RELEASED)); + CreateKeyEvent(Key::kLeftShift, 0, KeyEventType::kReleased)); ExpectKeyEventsEqual( ExpectedKeyValue("ShiftLeft", "Shift", kKeyDown), @@ -338,9 +336,9 @@ IN_PROC_BROWSER_TEST_F(KeyboardInputTest, ShiftCharacter) { IN_PROC_BROWSER_TEST_F(KeyboardInputTest, CharacterInBmp) { const wchar_t kSigma = 0x03C3; keyboard_service_->SendKeyEvent( - CreateCharacterKeyEvent(kSigma, KeyEventType::PRESSED)); + CreateCharacterKeyEvent(kSigma, KeyEventType::kPressed)); keyboard_service_->SendKeyEvent( - CreateCharacterKeyEvent(kSigma, KeyEventType::RELEASED)); + CreateCharacterKeyEvent(kSigma, KeyEventType::kReleased)); std::string expected_utf8; ASSERT_TRUE(base::WideToUTF8(&kSigma, 1, &expected_utf8)); @@ -355,13 +353,13 @@ IN_PROC_BROWSER_TEST_F(KeyboardInputTest, CharacterBeyondBmp) { const uint32_t kRamenEmoji = 0x1F35C; keyboard_service_->SendKeyEvent( - CreateCharacterKeyEvent(kRamenEmoji, KeyEventType::PRESSED)); + CreateCharacterKeyEvent(kRamenEmoji, KeyEventType::kPressed)); keyboard_service_->SendKeyEvent( - CreateCharacterKeyEvent(kRamenEmoji, KeyEventType::RELEASED)); + CreateCharacterKeyEvent(kRamenEmoji, KeyEventType::kReleased)); keyboard_service_->SendKeyEvent( - CreateCharacterKeyEvent('a', KeyEventType::PRESSED)); + CreateCharacterKeyEvent('a', KeyEventType::kPressed)); keyboard_service_->SendKeyEvent( - CreateCharacterKeyEvent('a', KeyEventType::RELEASED)); + CreateCharacterKeyEvent('a', KeyEventType::kReleased)); ExpectKeyEventsEqual(ExpectedKeyValue("", "a", kKeyDown), ExpectedKeyValue("", "a", kKeyPress), @@ -370,17 +368,17 @@ IN_PROC_BROWSER_TEST_F(KeyboardInputTest, CharacterBeyondBmp) { IN_PROC_BROWSER_TEST_F(KeyboardInputTest, ShiftPrintableKeys) { keyboard_service_->SendKeyEvent( - CreateKeyEvent(Key::LEFT_SHIFT, 0, KeyEventType::PRESSED)); + CreateKeyEvent(Key::kLeftShift, 0, KeyEventType::kPressed)); keyboard_service_->SendKeyEvent( - CreateKeyEvent(Key::B, 'B', KeyEventType::PRESSED)); + CreateKeyEvent(Key::kB, 'B', KeyEventType::kPressed)); keyboard_service_->SendKeyEvent( - CreateKeyEvent(Key::KEY_1, '!', KeyEventType::PRESSED)); + CreateKeyEvent(Key::kKey1, '!', KeyEventType::kPressed)); keyboard_service_->SendKeyEvent( - CreateKeyEvent(Key::SPACE, ' ', KeyEventType::PRESSED)); + CreateKeyEvent(Key::kSpace, ' ', KeyEventType::kPressed)); keyboard_service_->SendKeyEvent( - CreateKeyEvent(Key::LEFT_SHIFT, 0, KeyEventType::RELEASED)); + CreateKeyEvent(Key::kLeftShift, 0, KeyEventType::kReleased)); keyboard_service_->SendKeyEvent( - CreateKeyEvent(Key::DOT, '.', KeyEventType::PRESSED)); + CreateKeyEvent(Key::kDot, '.', KeyEventType::kPressed)); // Note that non-character keys (e.g. shift, control) only generate key down // and key up web events. They do not generate key pressed events. @@ -398,13 +396,14 @@ IN_PROC_BROWSER_TEST_F(KeyboardInputTest, ShiftPrintableKeys) { IN_PROC_BROWSER_TEST_F(KeyboardInputTest, ShiftNonPrintableKeys) { keyboard_service_->SendKeyEvent( - CreateKeyEvent(Key::RIGHT_SHIFT, 0, KeyEventType::PRESSED)); - keyboard_service_->SendKeyEvent(CreateKeyEvent( - Key::ENTER, NonPrintableKey::ENTER, KeyEventType::PRESSED)); + CreateKeyEvent(Key::kRightShift, 0, KeyEventType::kPressed)); keyboard_service_->SendKeyEvent( - CreateKeyEvent(Key::LEFT_CTRL, 0, KeyEventType::PRESSED)); + CreateKeyEvent(Key::kEnter, fuchsia_ui_input3::NonPrintableKey::kEnter, + KeyEventType::kPressed)); keyboard_service_->SendKeyEvent( - CreateKeyEvent(Key::RIGHT_SHIFT, 0, KeyEventType::RELEASED)); + CreateKeyEvent(Key::kLeftCtrl, 0, KeyEventType::kPressed)); + keyboard_service_->SendKeyEvent( + CreateKeyEvent(Key::kRightShift, 0, KeyEventType::kReleased)); // Note that non-character keys (e.g. shift, control) only generate key down // and key up web events. They do not generate key pressed events. @@ -417,9 +416,9 @@ IN_PROC_BROWSER_TEST_F(KeyboardInputTest, ShiftNonPrintableKeys) { IN_PROC_BROWSER_TEST_F(KeyboardInputTest, RepeatedKeys) { keyboard_service_->SendKeyEvent( - CreateKeyEvent(Key::A, 'a', KeyEventType::PRESSED, {.repeat = true})); - keyboard_service_->SendKeyEvent( - CreateKeyEvent(Key::KEY_8, '8', KeyEventType::PRESSED, {.repeat = true})); + CreateKeyEvent(Key::kA, 'a', KeyEventType::kPressed, {.repeat = true})); + keyboard_service_->SendKeyEvent(CreateKeyEvent( + Key::kKey8, '8', KeyEventType::kPressed, {.repeat = true})); // Note that non-character keys (e.g. shift, control) only generate key down // and key up web events. They do not generate key pressed events. @@ -437,17 +436,17 @@ IN_PROC_BROWSER_TEST_F(KeyboardInputTest, AllSupportedWebModifierKeys) { // * LEFT_*/RIGHT_* are not valid by themselves. // * FUNCTION and SYMBOL. See AllUnsupportedWebModifierKeys test. const std::vector kAllSupportedModifiers = { - fuchsia::ui::input3::Modifiers::CAPS_LOCK, - fuchsia::ui::input3::Modifiers::NUM_LOCK, - fuchsia::ui::input3::Modifiers::SCROLL_LOCK, - fuchsia::ui::input3::Modifiers::SHIFT, - fuchsia::ui::input3::Modifiers::ALT, - fuchsia::ui::input3::Modifiers::ALT_GRAPH, - fuchsia::ui::input3::Modifiers::META, - fuchsia::ui::input3::Modifiers::CTRL}; + fuchsia_ui_input3::Modifiers::kCapsLock, + fuchsia_ui_input3::Modifiers::kNumLock, + fuchsia_ui_input3::Modifiers::kScrollLock, + fuchsia_ui_input3::Modifiers::kShift, + fuchsia_ui_input3::Modifiers::kAlt, + fuchsia_ui_input3::Modifiers::kAltGraph, + fuchsia_ui_input3::Modifiers::kMeta, + fuchsia_ui_input3::Modifiers::kCtrl}; for (const auto& modifier : kAllSupportedModifiers) { keyboard_service_->SendKeyEvent(CreateKeyEvent( - Key::M, 'm', KeyEventType::PRESSED, {.modifiers = {modifier}})); + Key::kM, 'm', KeyEventType::kPressed, {.modifiers = {modifier}})); } base::Value::List expected_events; @@ -456,8 +455,8 @@ IN_PROC_BROWSER_TEST_F(KeyboardInputTest, AllSupportedWebModifierKeys) { ExpectedKeyValue("KeyM", "m", kKeyDown, {.modifiers = {modifier}})); // Chrome doesn't emit keypress events when an ALT or CTRL modifier is // present. - if (modifier != fuchsia::ui::input3::Modifiers::ALT && - modifier != fuchsia::ui::input3::Modifiers::CTRL) { + if (modifier != fuchsia_ui_input3::Modifiers::kAlt && + modifier != fuchsia_ui_input3::Modifiers::kCtrl) { expected_events.Append( ExpectedKeyValue("KeyM", "m", kKeyPress, {.modifiers = {modifier}})); } @@ -471,11 +470,11 @@ IN_PROC_BROWSER_TEST_F(KeyboardInputTest, AllUnsupportedWebModifierKeys) { // because they aren't included in // https://crsrc.org/c/ui/events/blink/blink_event_util.cc;l=268?q=EventFlagsToWebEventModifiers const std::vector kAllUnsupportedModifiers = { - fuchsia::ui::input3::Modifiers::FUNCTION, - fuchsia::ui::input3::Modifiers::SYMBOL}; + fuchsia_ui_input3::Modifiers::kFunction, + fuchsia_ui_input3::Modifiers::kSymbol}; for (const auto& modifier : kAllUnsupportedModifiers) { keyboard_service_->SendKeyEvent(CreateKeyEvent( - Key::M, 'm', KeyEventType::PRESSED, {.modifiers = {modifier}})); + Key::kM, 'm', KeyEventType::kPressed, {.modifiers = {modifier}})); } base::Value::List expected_events; @@ -492,76 +491,75 @@ IN_PROC_BROWSER_TEST_F(KeyboardInputTest, AllUnsupportedWebModifierKeys) { IN_PROC_BROWSER_TEST_F(KeyboardInputTest, AssortedModifierKeyCombos) { // Test that sending LEFT/RIGHT SHIFT with agnostic SHIFT passes DCHECK. keyboard_service_->SendKeyEvent(CreateKeyEvent( - Key::A, 'a', KeyEventType::PRESSED, - {.modifiers = {fuchsia::ui::input3::Modifiers::SHIFT, - fuchsia::ui::input3::Modifiers::LEFT_SHIFT, - fuchsia::ui::input3::Modifiers::RIGHT_SHIFT}})); + Key::kA, 'a', KeyEventType::kPressed, + {.modifiers = {fuchsia_ui_input3::Modifiers::kShift, + fuchsia_ui_input3::Modifiers::kLeftShift, + fuchsia_ui_input3::Modifiers::kRightShift}})); // Test that sending LEFT/RIGHT ALT with agnostic ALT passes DCHECK. - keyboard_service_->SendKeyEvent(CreateKeyEvent( - Key::KEY_8, '8', KeyEventType::PRESSED, - {.modifiers = {fuchsia::ui::input3::Modifiers::ALT, - fuchsia::ui::input3::Modifiers::LEFT_ALT, - fuchsia::ui::input3::Modifiers::RIGHT_ALT}})); + keyboard_service_->SendKeyEvent( + CreateKeyEvent(Key::kKey8, '8', KeyEventType::kPressed, + {.modifiers = {fuchsia_ui_input3::Modifiers::kAlt, + fuchsia_ui_input3::Modifiers::kLeftAlt, + fuchsia_ui_input3::Modifiers::kRightAlt}})); // Test that sending LEFT/RIGHT META with agnostic META passes DCHECK. keyboard_service_->SendKeyEvent(CreateKeyEvent( - Key::B, 'b', KeyEventType::PRESSED, - {.modifiers = {fuchsia::ui::input3::Modifiers::META, - fuchsia::ui::input3::Modifiers::LEFT_META, - fuchsia::ui::input3::Modifiers::RIGHT_META}})); + Key::kB, 'b', KeyEventType::kPressed, + {.modifiers = {fuchsia_ui_input3::Modifiers::kMeta, + fuchsia_ui_input3::Modifiers::kLeftMeta, + fuchsia_ui_input3::Modifiers::kRightMeta}})); // Test that sending LEFT/RIGHT CTRL with agnostic CTRL passes DCHECK. keyboard_service_->SendKeyEvent(CreateKeyEvent( - Key::LEFT, 0, KeyEventType::PRESSED, - {.modifiers = {fuchsia::ui::input3::Modifiers::CTRL, - fuchsia::ui::input3::Modifiers::LEFT_CTRL, - fuchsia::ui::input3::Modifiers::RIGHT_CTRL}})); - keyboard_service_->SendKeyEvent( - CreateKeyEvent(Key::P, 'p', KeyEventType::PRESSED, - {.modifiers = {fuchsia::ui::input3::Modifiers::CTRL, - fuchsia::ui::input3::Modifiers::SHIFT}})); - keyboard_service_->SendKeyEvent(CreateKeyEvent( - Key::RIGHT, 0, KeyEventType::PRESSED, - {.modifiers = {fuchsia::ui::input3::Modifiers::ALT_GRAPH}})); - keyboard_service_->SendKeyEvent(CreateKeyEvent( - Key::UP, 0, KeyEventType::PRESSED, - {.modifiers = {fuchsia::ui::input3::Modifiers::CAPS_LOCK}})); - keyboard_service_->SendKeyEvent(CreateKeyEvent( - Key::DOWN, 0, KeyEventType::PRESSED, - {.modifiers = {fuchsia::ui::input3::Modifiers::NUM_LOCK}})); + Key::kLeft, 0, KeyEventType::kPressed, + {.modifiers = {fuchsia_ui_input3::Modifiers::kCtrl, + fuchsia_ui_input3::Modifiers::kLeftCtrl, + fuchsia_ui_input3::Modifiers::kRightCtrl}})); + keyboard_service_->SendKeyEvent( + CreateKeyEvent(Key::kP, 'p', KeyEventType::kPressed, + {.modifiers = {fuchsia_ui_input3::Modifiers::kCtrl, + fuchsia_ui_input3::Modifiers::kShift}})); + keyboard_service_->SendKeyEvent( + CreateKeyEvent(Key::kRight, 0, KeyEventType::kPressed, + {.modifiers = {fuchsia_ui_input3::Modifiers::kAltGraph}})); + keyboard_service_->SendKeyEvent( + CreateKeyEvent(Key::kUp, 0, KeyEventType::kPressed, + {.modifiers = {fuchsia_ui_input3::Modifiers::kCapsLock}})); + keyboard_service_->SendKeyEvent( + CreateKeyEvent(Key::kDown, 0, KeyEventType::kPressed, + {.modifiers = {fuchsia_ui_input3::Modifiers::kNumLock}})); keyboard_service_->SendKeyEvent(CreateKeyEvent( - Key::LEFT, 0, KeyEventType::PRESSED, - {.modifiers = {fuchsia::ui::input3::Modifiers::SCROLL_LOCK}})); + Key::kLeft, 0, KeyEventType::kPressed, + {.modifiers = {fuchsia_ui_input3::Modifiers::kScrollLock}})); ExpectKeyEventsEqual( ExpectedKeyValue("KeyA", "a", kKeyDown, - {.modifiers = {fuchsia::ui::input3::Modifiers::SHIFT}}), + {.modifiers = {fuchsia_ui_input3::Modifiers::kShift}}), ExpectedKeyValue("KeyA", "a", kKeyPress, - {.modifiers = {fuchsia::ui::input3::Modifiers::SHIFT}}), + {.modifiers = {fuchsia_ui_input3::Modifiers::kShift}}), ExpectedKeyValue("Digit8", "8", kKeyDown, - {.modifiers = {fuchsia::ui::input3::Modifiers::ALT}}), + {.modifiers = {fuchsia_ui_input3::Modifiers::kAlt}}), ExpectedKeyValue("KeyB", "b", kKeyDown, - {.modifiers = {fuchsia::ui::input3::Modifiers::META}}), + {.modifiers = {fuchsia_ui_input3::Modifiers::kMeta}}), ExpectedKeyValue("KeyB", "b", kKeyPress, - {.modifiers = {fuchsia::ui::input3::Modifiers::META}}), + {.modifiers = {fuchsia_ui_input3::Modifiers::kMeta}}), ExpectedKeyValue("ArrowLeft", "ArrowLeft", kKeyDown, - {.modifiers = {fuchsia::ui::input3::Modifiers::CTRL}}), + {.modifiers = {fuchsia_ui_input3::Modifiers::kCtrl}}), ExpectedKeyValue("KeyP", "p", kKeyDown, - {.modifiers = {fuchsia::ui::input3::Modifiers::CTRL, - fuchsia::ui::input3::Modifiers::SHIFT}}), + {.modifiers = {fuchsia_ui_input3::Modifiers::kCtrl, + fuchsia_ui_input3::Modifiers::kShift}}), ExpectedKeyValue("KeyP", "p", kKeyPress, - {.modifiers = {fuchsia::ui::input3::Modifiers::CTRL, - fuchsia::ui::input3::Modifiers::SHIFT}}), + {.modifiers = {fuchsia_ui_input3::Modifiers::kCtrl, + fuchsia_ui_input3::Modifiers::kShift}}), ExpectedKeyValue( "ArrowRight", "ArrowRight", kKeyDown, - {.modifiers = {fuchsia::ui::input3::Modifiers::ALT_GRAPH}}), + {.modifiers = {fuchsia_ui_input3::Modifiers::kAltGraph}}), ExpectedKeyValue( "ArrowUp", "ArrowUp", kKeyDown, - {.modifiers = {fuchsia::ui::input3::Modifiers::CAPS_LOCK}}), - ExpectedKeyValue( - "ArrowDown", "ArrowDown", kKeyDown, - {.modifiers = {fuchsia::ui::input3::Modifiers::NUM_LOCK}}), + {.modifiers = {fuchsia_ui_input3::Modifiers::kCapsLock}}), + ExpectedKeyValue("ArrowDown", "ArrowDown", kKeyDown, + {.modifiers = {fuchsia_ui_input3::Modifiers::kNumLock}}), ExpectedKeyValue( "ArrowLeft", "ArrowLeft", kKeyDown, - {.modifiers = {fuchsia::ui::input3::Modifiers::SCROLL_LOCK}})); + {.modifiers = {fuchsia_ui_input3::Modifiers::kScrollLock}})); } IN_PROC_BROWSER_TEST_F(KeyboardInputTest, Disconnect) { @@ -590,7 +588,7 @@ class KeyboardInputTestWithoutKeyboardFeature : public KeyboardInputTest { keyboard_input_checker_.emplace(component_context_->additional_services()); } - absl::optional> + absl::optional> keyboard_input_checker_; }; diff --git a/fuchsia_web/webengine/browser/virtual_keyboard_browsertest.cc b/fuchsia_web/webengine/browser/virtual_keyboard_browsertest.cc index 6203645ca42d54..7b239cf1a5e527 100644 --- a/fuchsia_web/webengine/browser/virtual_keyboard_browsertest.cc +++ b/fuchsia_web/webengine/browser/virtual_keyboard_browsertest.cc @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include #include -#include #include #include "base/fuchsia/fuchsia_logging.h" @@ -73,7 +73,8 @@ class VirtualKeyboardTest : public WebEngineBrowserTest { // Ensure that the fuchsia.ui.input3.Keyboard service is connected. component_context_->additional_services() - ->RemovePublicService(); + ->RemovePublicService( + fidl::DiscoverableProtocolName); keyboard_input_checker_.emplace(component_context_->additional_services()); fuchsia::web::NavigationControllerPtr controller; @@ -134,7 +135,7 @@ class VirtualKeyboardTest : public WebEngineBrowserTest { ScenicTestHelper scenic_test_helper_; base::test::ScopedFeatureList scoped_feature_list_; - absl::optional> + absl::optional> keyboard_input_checker_; // Fake virtual keyboard services for the InputMethod to use. diff --git a/fuchsia_web/webengine/test/scoped_connection_checker.h b/fuchsia_web/webengine/test/scoped_connection_checker.h index 8bc24413654750..9a6b3132321b03 100644 --- a/fuchsia_web/webengine/test/scoped_connection_checker.h +++ b/fuchsia_web/webengine/test/scoped_connection_checker.h @@ -6,7 +6,9 @@ #define FUCHSIA_WEB_WEBENGINE_TEST_SCOPED_CONNECTION_CHECKER_H_ #include +#include #include + #include #include @@ -14,8 +16,8 @@ #include "testing/gtest/include/gtest/gtest.h" // Verifies that a connection was made, or never attempted, for a given -// |Service| without needing to provide an implementation. -template +// `Protocol` without needing to provide an implementation. +template class ScopedConnectionCheckerBase { public: explicit ScopedConnectionCheckerBase( @@ -25,7 +27,7 @@ class ScopedConnectionCheckerBase { [this](zx::channel channel, async_dispatcher_t*) { pending_channels_.push_back(std::move(channel)); }), - std::string(Service::Name_)); + fidl::DiscoverableProtocolName); ZX_CHECK(status == ZX_OK, status) << "OutgoingDirectory::AddPublicService"; } @@ -43,16 +45,16 @@ class ScopedConnectionCheckerBase { private: // Client channels are held in a pending (unconnected) state for the - // lifetime of |this|, so that the client never sees a disconnection event. + // lifetime of `this`, so that the client never sees a disconnection event. std::vector pending_channels_; }; -// Checks that no client attempted to connect to |Service|. -template -using NeverConnectedChecker = ScopedConnectionCheckerBase; +// Checks that no client attempted to connect to `Protocol`. +template +using NeverConnectedChecker = ScopedConnectionCheckerBase; -// Checks that at least one client attempted to connect to |Service|. -template -using EnsureConnectedChecker = ScopedConnectionCheckerBase; +// Checks that at least one client attempted to connect to `Protocol`. +template +using EnsureConnectedChecker = ScopedConnectionCheckerBase; #endif // FUCHSIA_WEB_WEBENGINE_TEST_SCOPED_CONNECTION_CHECKER_H_ diff --git a/ui/base/ime/fuchsia/BUILD.gn b/ui/base/ime/fuchsia/BUILD.gn index db19f4ef8b8024..1fc9873fdb9916 100644 --- a/ui/base/ime/fuchsia/BUILD.gn +++ b/ui/base/ime/fuchsia/BUILD.gn @@ -22,7 +22,7 @@ component("fuchsia") { "//base", "//third_party/abseil-cpp:absl", "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.input.virtualkeyboard:fuchsia.input.virtualkeyboard_hlcpp", - "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.ui.input3:fuchsia.ui.input3_hlcpp", + "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.ui.input3:fuchsia.ui.input3_cpp", "//third_party/fuchsia-sdk/sdk/pkg/scenic_cpp", "//third_party/fuchsia-sdk/sdk/pkg/sys_cpp", "//ui/base/ime", diff --git a/ui/base/ime/fuchsia/keyboard_client.cc b/ui/base/ime/fuchsia/keyboard_client.cc index 4ee5911f39ff7e..fa04d03788c73b 100644 --- a/ui/base/ime/fuchsia/keyboard_client.cc +++ b/ui/base/ime/fuchsia/keyboard_client.cc @@ -4,13 +4,15 @@ #include "ui/base/ime/fuchsia/keyboard_client.h" +#include + #include #include #include +#include "base/fuchsia/fuchsia_logging.h" #include "base/logging.h" #include "base/notreached.h" -#include "third_party/abseil-cpp/absl/types/optional.h" #include "ui/events/event.h" #include "ui/events/fuchsia/input_event_sink.h" #include "ui/events/keycodes/dom/dom_code.h" @@ -24,10 +26,10 @@ namespace { // Adds `flag` to `event_flags` if `modifier` is present. Also removes handled // modifiers from `unhandled_modifiers`. -inline void MaybeAddFlag(fuchsia::ui::input3::Modifiers modifier, +inline void MaybeAddFlag(fuchsia_ui_input3::Modifiers modifier, EventFlags flag, EventFlags& event_flags, - fuchsia::ui::input3::Modifiers& unhandled_modifiers) { + fuchsia_ui_input3::Modifiers& unhandled_modifiers) { if (unhandled_modifiers & modifier) { event_flags |= flag; // Remove modifier from unhandled. @@ -37,72 +39,72 @@ inline void MaybeAddFlag(fuchsia::ui::input3::Modifiers modifier, // Converts the state of modifiers managed by Fuchsia (e.g. Caps and Num Lock) // into ui::Event flags. -int ModifiersToEventFlags(fuchsia::ui::input3::Modifiers modifiers) { +int ModifiersToEventFlags(fuchsia_ui_input3::Modifiers modifiers) { EventFlags event_flags = EF_NONE; - MaybeAddFlag(fuchsia::ui::input3::Modifiers::CAPS_LOCK, EF_CAPS_LOCK_ON, + MaybeAddFlag(fuchsia_ui_input3::Modifiers::kCapsLock, EF_CAPS_LOCK_ON, event_flags, modifiers); - MaybeAddFlag(fuchsia::ui::input3::Modifiers::NUM_LOCK, EF_NUM_LOCK_ON, + MaybeAddFlag(fuchsia_ui_input3::Modifiers::kNumLock, EF_NUM_LOCK_ON, event_flags, modifiers); - MaybeAddFlag(fuchsia::ui::input3::Modifiers::SCROLL_LOCK, EF_SCROLL_LOCK_ON, + MaybeAddFlag(fuchsia_ui_input3::Modifiers::kScrollLock, EF_SCROLL_LOCK_ON, event_flags, modifiers); // This mapping is present in case blink adds support in the future, but blink // doesn't currently output the Function modifier. See // https://crsrc.org/c/ui/events/blink/blink_event_util.cc;l=268?q=EventFlagsToWebEventModifiers - MaybeAddFlag(fuchsia::ui::input3::Modifiers::FUNCTION, EF_FUNCTION_DOWN, + MaybeAddFlag(fuchsia_ui_input3::Modifiers::kFunction, EF_FUNCTION_DOWN, event_flags, modifiers); - if (modifiers & fuchsia::ui::input3::Modifiers::SYMBOL) { - // fuchsia::ui::input3::Modifiers::SYMBOL has no equivalent in + if (modifiers & fuchsia_ui_input3::Modifiers::kSymbol) { + // fuchsia_ui_input3::Modifiers::SYMBOL has no equivalent in // //ui/events/event_constants.h. DLOG(WARNING) << "Ignoring unsupported Symbol modifier."; - modifiers &= ~fuchsia::ui::input3::Modifiers::SYMBOL; + modifiers &= ~fuchsia_ui_input3::Modifiers::kSymbol; } - MaybeAddFlag(fuchsia::ui::input3::Modifiers::SHIFT, EF_SHIFT_DOWN, - event_flags, modifiers); - if (modifiers & (fuchsia::ui::input3::Modifiers::LEFT_SHIFT | - fuchsia::ui::input3::Modifiers::RIGHT_SHIFT)) { + MaybeAddFlag(fuchsia_ui_input3::Modifiers::kShift, EF_SHIFT_DOWN, event_flags, + modifiers); + if (modifiers & (fuchsia_ui_input3::Modifiers::kLeftShift | + fuchsia_ui_input3::Modifiers::kRightShift)) { DCHECK(event_flags & EF_SHIFT_DOWN) << "Fuchsia is expected to provide an agnostic SHIFT modifier for both " "LEFT and RIGHT SHIFT"; - modifiers &= ~fuchsia::ui::input3::Modifiers::LEFT_SHIFT & - ~fuchsia::ui::input3::Modifiers::RIGHT_SHIFT; + modifiers &= ~fuchsia_ui_input3::Modifiers::kLeftShift & + ~fuchsia_ui_input3::Modifiers::kRightShift; } - MaybeAddFlag(fuchsia::ui::input3::Modifiers::ALT, EF_ALT_DOWN, event_flags, + MaybeAddFlag(fuchsia_ui_input3::Modifiers::kAlt, EF_ALT_DOWN, event_flags, modifiers); - if (modifiers & (fuchsia::ui::input3::Modifiers::LEFT_ALT | - fuchsia::ui::input3::Modifiers::RIGHT_ALT)) { + if (modifiers & (fuchsia_ui_input3::Modifiers::kLeftAlt | + fuchsia_ui_input3::Modifiers::kRightAlt)) { DCHECK(event_flags & EF_ALT_DOWN) << "Fuchsia is expected to provide an agnostic ALT modifier for both " "LEFT and RIGHT ALT"; - modifiers &= ~fuchsia::ui::input3::Modifiers::LEFT_ALT & - ~fuchsia::ui::input3::Modifiers::RIGHT_ALT; + modifiers &= ~fuchsia_ui_input3::Modifiers::kLeftAlt & + ~fuchsia_ui_input3::Modifiers::kRightAlt; } - MaybeAddFlag(fuchsia::ui::input3::Modifiers::ALT_GRAPH, EF_ALTGR_DOWN, + MaybeAddFlag(fuchsia_ui_input3::Modifiers::kAltGraph, EF_ALTGR_DOWN, event_flags, modifiers); - MaybeAddFlag(fuchsia::ui::input3::Modifiers::META, EF_COMMAND_DOWN, + MaybeAddFlag(fuchsia_ui_input3::Modifiers::kMeta, EF_COMMAND_DOWN, event_flags, modifiers); - if (modifiers & (fuchsia::ui::input3::Modifiers::LEFT_META | - fuchsia::ui::input3::Modifiers::RIGHT_META)) { + if (modifiers & (fuchsia_ui_input3::Modifiers::kLeftMeta | + fuchsia_ui_input3::Modifiers::kRightMeta)) { DCHECK(event_flags & EF_COMMAND_DOWN) << "Fuchsia is expected to provide an agnostic META modifier for both " "LEFT and RIGHT META"; - modifiers &= ~fuchsia::ui::input3::Modifiers::LEFT_META & - ~fuchsia::ui::input3::Modifiers::RIGHT_META; + modifiers &= ~fuchsia_ui_input3::Modifiers::kLeftMeta & + ~fuchsia_ui_input3::Modifiers::kRightMeta; } - MaybeAddFlag(fuchsia::ui::input3::Modifiers::CTRL, EF_CONTROL_DOWN, + MaybeAddFlag(fuchsia_ui_input3::Modifiers::kCtrl, EF_CONTROL_DOWN, event_flags, modifiers); - if (modifiers & (fuchsia::ui::input3::Modifiers::LEFT_CTRL | - fuchsia::ui::input3::Modifiers::RIGHT_CTRL)) { + if (modifiers & (fuchsia_ui_input3::Modifiers::kLeftCtrl | + fuchsia_ui_input3::Modifiers::kRightCtrl)) { DCHECK(event_flags & EF_CONTROL_DOWN) << "Fuchsia is expected to provide an agnostic CTRL modifier for both " "LEFT and RIGHT CTRL"; - modifiers &= ~fuchsia::ui::input3::Modifiers::LEFT_CTRL & - ~fuchsia::ui::input3::Modifiers::RIGHT_CTRL; + modifiers &= ~fuchsia_ui_input3::Modifiers::kLeftCtrl & + ~fuchsia_ui_input3::Modifiers::kRightCtrl; } DLOG_IF(WARNING, modifiers) @@ -111,14 +113,14 @@ int ModifiersToEventFlags(fuchsia::ui::input3::Modifiers modifiers) { } absl::optional ConvertKeyEventType( - fuchsia::ui::input3::KeyEventType type) { + fuchsia_ui_input3::KeyEventType type) { switch (type) { - case fuchsia::ui::input3::KeyEventType::PRESSED: + case fuchsia_ui_input3::KeyEventType::kPressed: return ET_KEY_PRESSED; - case fuchsia::ui::input3::KeyEventType::RELEASED: + case fuchsia_ui_input3::KeyEventType::kReleased: return ET_KEY_RELEASED; - case fuchsia::ui::input3::KeyEventType::SYNC: - case fuchsia::ui::input3::KeyEventType::CANCEL: + case fuchsia_ui_input3::KeyEventType::kSync: + case fuchsia_ui_input3::KeyEventType::kCancel: // SYNC and CANCEL should not generate ui::Events. return absl::nullopt; default: @@ -130,73 +132,84 @@ absl::optional ConvertKeyEventType( } // namespace -KeyboardClient::KeyboardClient(fuchsia::ui::input3::Keyboard* keyboard_service, - fuchsia::ui::views::ViewRef view_ref, - InputEventSink* event_sink) - : binding_(this), event_sink_(event_sink) { +KeyboardClient::KeyboardClient( + fidl::Client& keyboard_fidl_client, + fuchsia_ui_views::ViewRef view_ref, + InputEventSink* event_sink) + : event_sink_(event_sink) { DCHECK(event_sink_); - // Connect to the Keyboard service and register |keyboard_client_| as a + // Connect to the Keyboard service and register `keyboard_client_` as a // listener. - fidl::InterfaceHandle - keyboard_listener; - fidl::InterfaceRequest - keyboard_listener_request = keyboard_listener.NewRequest(); - keyboard_service->AddListener(std::move(view_ref), - std::move(keyboard_listener), [] {}); - binding_.Bind(std::move(keyboard_listener_request)); + auto keyboard_listener_endpoints = + fidl::CreateEndpoints(); + ZX_CHECK(keyboard_listener_endpoints.is_ok(), + keyboard_listener_endpoints.status_value()); + keyboard_fidl_client + ->AddListener( + {{.view_ref = std::move(view_ref), + .listener = std::move(keyboard_listener_endpoints->client)}}) + .ThenExactlyOnce([](auto result) {}); + binding_.emplace(async_get_default_dispatcher(), + std::move(keyboard_listener_endpoints->server), this, + fidl::kIgnoreBindingClosure); } KeyboardClient::~KeyboardClient() = default; void KeyboardClient::OnKeyEvent( - fuchsia::ui::input3::KeyEvent key_event, - fuchsia::ui::input3::KeyboardListener::OnKeyEventCallback callback) { - if (!IsValid(key_event)) { - binding_.Close(ZX_ERR_INVALID_ARGS); + KeyboardClient::OnKeyEventRequest& request, + KeyboardClient::OnKeyEventCompleter::Sync& completer) { + if (!IsValid(request.event())) { + binding_->Close(ZX_ERR_INVALID_ARGS); return; } - if (ProcessKeyEvent(key_event)) { - callback(fuchsia::ui::input3::KeyEventStatus::HANDLED); + if (ProcessKeyEvent(request.event())) { + completer.Reply(fuchsia_ui_input3::KeyEventStatus::kHandled); } else { - callback(fuchsia::ui::input3::KeyEventStatus::NOT_HANDLED); + completer.Reply(fuchsia_ui_input3::KeyEventStatus::kNotHandled); } } -bool KeyboardClient::IsValid(const fuchsia::ui::input3::KeyEvent& key_event) { - if (!key_event.has_type() || !key_event.has_timestamp()) +bool KeyboardClient::IsValid(const fuchsia_ui_input3::KeyEvent& key_event) { + if (!key_event.type() || !key_event.timestamp()) { return false; + } - if (!key_event.has_key() && !key_event.has_key_meaning()) + if (!key_event.key() && !key_event.key_meaning()) { return false; + } return true; } bool KeyboardClient::ProcessKeyEvent( - const fuchsia::ui::input3::KeyEvent& key_event) { - absl::optional event_type = ConvertKeyEventType(key_event.type()); + const fuchsia_ui_input3::KeyEvent& key_event) { + absl::optional event_type = + ConvertKeyEventType(key_event.type().value()); if (!event_type) return false; - // Convert |key_event| to a ui::KeyEvent. + // Convert `key_event` to a ui::KeyEvent. int event_flags = EF_NONE; - if (key_event.has_modifiers()) - event_flags |= ModifiersToEventFlags(key_event.modifiers()); - if (key_event.has_repeat_sequence()) { + if (key_event.modifiers()) { + event_flags |= ModifiersToEventFlags(key_event.modifiers().value()); + } + if (key_event.repeat_sequence()) { event_flags |= EF_IS_REPEAT; } // Derive the DOM Key and Code directly from the event's fields. - // |key_event| has already been validated, so is guaranteed to have one - // or both of the |key| or |key_meaning| fields set. + // `key_event` has already been validated, so is guaranteed to have one + // or both of the `key` or `key_meaning` fields set. DomCode dom_code = DomCode::NONE; DomKey dom_key = DomKey::UNIDENTIFIED; KeyboardCode key_code = VKEY_UNKNOWN; - if (key_event.has_key()) { - dom_code = KeycodeConverter::UsbKeycodeToDomCode(key_event.key()); + if (key_event.key()) { + dom_code = KeycodeConverter::UsbKeycodeToDomCode( + static_cast(key_event.key().value())); // Derive the legacy key_code. At present this only takes into account the // DOM Code, and event flags, so requires that key() be set. @@ -208,26 +221,26 @@ bool KeyboardClient::ProcessKeyEvent( DomCodeToUsLayoutDomKey(dom_code, event_flags, &dom_key, &key_code); } - if (key_event.has_key_meaning()) { + if (key_event.key_meaning()) { // If the KeyMeaning is specified then use it to set the DOM Key. // Ignore events with codepoints outside the Basic Multilingual Plane, // since the Chromium keyboard pipeline cannot currently handle them. - if (key_event.key_meaning().is_codepoint() && - (key_event.key_meaning().codepoint() > + if (key_event.key_meaning()->codepoint() && + (key_event.key_meaning()->codepoint().value() > std::numeric_limits::max())) { return false; } DomKey dom_key_from_meaning = - DomKeyFromFuchsiaKeyMeaning(key_event.key_meaning()); + DomKeyFromFuchsiaKeyMeaning(key_event.key_meaning().value()); if (dom_key_from_meaning != DomKey::UNIDENTIFIED) dom_key = dom_key_from_meaning; } ui::KeyEvent converted_event( *event_type, key_code, dom_code, event_flags, dom_key, - base::TimeTicks::FromZxTime(key_event.timestamp())); + base::TimeTicks::FromZxTime(key_event.timestamp().value())); event_sink_->DispatchEvent(&converted_event); return converted_event.handled(); } diff --git a/ui/base/ime/fuchsia/keyboard_client.h b/ui/base/ime/fuchsia/keyboard_client.h index 8e27ead81c870c..ab0785773f9936 100644 --- a/ui/base/ime/fuchsia/keyboard_client.h +++ b/ui/base/ime/fuchsia/keyboard_client.h @@ -5,10 +5,11 @@ #ifndef UI_BASE_IME_FUCHSIA_KEYBOARD_CLIENT_H_ #define UI_BASE_IME_FUCHSIA_KEYBOARD_CLIENT_H_ -#include +#include #include #include "base/component_export.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace ui { @@ -16,40 +17,41 @@ class InputEventSink; // Handles keyboard events from the Fuchsia keyboard service. class COMPONENT_EXPORT(UI_BASE_IME_FUCHSIA) KeyboardClient - : public fuchsia::ui::input3::KeyboardListener { + : public fidl::Server { public: - // |keyboard_service| and |event_sink| must outlive |this|. - KeyboardClient(fuchsia::ui::input3::Keyboard* keyboard_service, - fuchsia::ui::views::ViewRef view_ref, - InputEventSink* event_sink); + // `keyboard_service` and `event_sink` must outlive `this`. + KeyboardClient( + fidl::Client& keyboard_fidl_client, + fuchsia_ui_views::ViewRef view_ref, + InputEventSink* event_sink); ~KeyboardClient() override; KeyboardClient(const KeyboardClient&) = delete; KeyboardClient& operator=(const KeyboardClient&) = delete; - // fuchsia::ui::input3::KeyboardListener implementation. - void OnKeyEvent( - fuchsia::ui::input3::KeyEvent key_event, - fuchsia::ui::input3::KeyboardListener::OnKeyEventCallback callback) final; + // fuchsia_ui_input3::KeyboardListener implementation. + void OnKeyEvent(OnKeyEventRequest& request, + OnKeyEventCompleter::Sync& completer) final; private: - bool IsValid(const fuchsia::ui::input3::KeyEvent& key_event); + bool IsValid(const fuchsia_ui_input3::KeyEvent& key_event); - // Handles converting and propagating |key_event|. Returns false if critical - // information about |key_event| is missing, or if the key's event type is not + // Handles converting and propagating `key_event`. Returns false if critical + // information about `key_event` is missing, or if the key's event type is not // supported. // TODO(http://fxbug.dev/69620): Add support for SYNC and CANCEL key event // types. - bool ProcessKeyEvent(const fuchsia::ui::input3::KeyEvent& key_event); + bool ProcessKeyEvent(const fuchsia_ui_input3::KeyEvent& key_event); // Update the value of modifiers such as shift. - void UpdateCachedModifiers(const fuchsia::ui::input3::KeyEvent& key_event); + void UpdateCachedModifiers(const fuchsia_ui_input3::KeyEvent& key_event); // Translate state of locally tracked modifier keys (e.g. shift, alt) into // ui::Event flags. int EventFlagsForCachedModifiers(); - fidl::Binding binding_; + absl::optional> + binding_; // Dispatches events into Chromium once they have been converted to // ui::KeyEvents. diff --git a/ui/events/BUILD.gn b/ui/events/BUILD.gn index af2d65cac3a181..7a99006dd31ff9 100644 --- a/ui/events/BUILD.gn +++ b/ui/events/BUILD.gn @@ -166,7 +166,7 @@ component("events_base") { "keycodes/keyboard_code_conversion_fuchsia.h", ] - deps += [ "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.ui.input3:fuchsia.ui.input3_hlcpp" ] + deps += [ "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.ui.input3:fuchsia.ui.input3_cpp" ] } if (ozone_platform_x11) { @@ -734,7 +734,7 @@ if (!is_ios) { deps += [ "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.ui.input:fuchsia.ui.input_hlcpp", - "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.ui.input3:fuchsia.ui.input3_hlcpp", + "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.ui.input3:fuchsia.ui.input3_cpp", "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.ui.pointer:fuchsia.ui.pointer_cpp", "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.ui.pointer:fuchsia.ui.pointer_cpp_hlcpp_conversion", "//third_party/fuchsia-sdk/sdk/pkg/scenic_cpp_testing", diff --git a/ui/events/keycodes/keyboard_code_conversion_fuchsia.cc b/ui/events/keycodes/keyboard_code_conversion_fuchsia.cc index db086acfa3cad6..8cc76262cf439d 100644 --- a/ui/events/keycodes/keyboard_code_conversion_fuchsia.cc +++ b/ui/events/keycodes/keyboard_code_conversion_fuchsia.cc @@ -4,7 +4,7 @@ #include "ui/events/keycodes/keyboard_code_conversion_fuchsia.h" -#include +#include #include "base/containers/flat_map.h" @@ -12,13 +12,16 @@ namespace ui { namespace { DomKey DomKeyFromFuchsiaNonPrintableKey( - const fuchsia::ui::input3::NonPrintableKey& key) { - if (key == fuchsia::ui::input3::NonPrintableKey::ENTER) + const fuchsia_ui_input3::NonPrintableKey& key) { + if (key == fuchsia_ui_input3::NonPrintableKey::kEnter) { return DomKey::ENTER; - if (key == fuchsia::ui::input3::NonPrintableKey::TAB) + } + if (key == fuchsia_ui_input3::NonPrintableKey::kTab) { return DomKey::TAB; - if (key == fuchsia::ui::input3::NonPrintableKey::BACKSPACE) + } + if (key == fuchsia_ui_input3::NonPrintableKey::kBackspace) { return DomKey::BACKSPACE; + } return DomKey::UNIDENTIFIED; } @@ -26,18 +29,21 @@ DomKey DomKeyFromFuchsiaNonPrintableKey( } // namespace DomKey DomKeyFromFuchsiaKeyMeaning( - const fuchsia::ui::input3::KeyMeaning& key_meaning) { - if (key_meaning.is_codepoint()) { + const fuchsia_ui_input3::KeyMeaning& key_meaning) { + if (key_meaning.codepoint()) { // TODO(fxbug.dev/106600): Remove this check for codepoint zero, once the // platform provides non-printable key meanings consistently. - if (key_meaning.codepoint() == 0) + if (key_meaning.codepoint().value() == 0) { return DomKey::UNIDENTIFIED; + } - return DomKey::FromCharacter(key_meaning.codepoint()); + return DomKey::FromCharacter(key_meaning.codepoint().value()); } - if (key_meaning.is_non_printable_key()) - return DomKeyFromFuchsiaNonPrintableKey(key_meaning.non_printable_key()); + if (key_meaning.non_printable_key()) { + return DomKeyFromFuchsiaNonPrintableKey( + key_meaning.non_printable_key().value()); + } return DomKey::UNIDENTIFIED; } diff --git a/ui/events/keycodes/keyboard_code_conversion_fuchsia.h b/ui/events/keycodes/keyboard_code_conversion_fuchsia.h index 0e9d30ca17d89c..3989108975db2b 100644 --- a/ui/events/keycodes/keyboard_code_conversion_fuchsia.h +++ b/ui/events/keycodes/keyboard_code_conversion_fuchsia.h @@ -8,19 +8,15 @@ #include "ui/events/events_base_export.h" #include "ui/events/keycodes/dom/dom_key.h" -namespace fuchsia { -namespace ui { -namespace input3 { +namespace fuchsia_ui_input3 { class KeyMeaning; -} // namespace input3 -} // namespace ui -} // namespace fuchsia +} // namespace fuchsia_ui_input3 namespace ui { // Converts a Fuchsia KeyMeaning to a DomKey. EVENTS_BASE_EXPORT DomKey -DomKeyFromFuchsiaKeyMeaning(const fuchsia::ui::input3::KeyMeaning& key_meaning); +DomKeyFromFuchsiaKeyMeaning(const fuchsia_ui_input3::KeyMeaning& key_meaning); } // namespace ui diff --git a/ui/events/keycodes/keyboard_code_conversion_fuchsia_unittest.cc b/ui/events/keycodes/keyboard_code_conversion_fuchsia_unittest.cc index f4e1db4de77e94..22821a947c1cba 100644 --- a/ui/events/keycodes/keyboard_code_conversion_fuchsia_unittest.cc +++ b/ui/events/keycodes/keyboard_code_conversion_fuchsia_unittest.cc @@ -4,8 +4,7 @@ #include "ui/events/keycodes/keyboard_code_conversion_fuchsia.h" -#include -#include +#include #include #include "base/logging.h" @@ -15,9 +14,9 @@ namespace { -using fuchsia::input::Key; -using fuchsia::ui::input3::KeyMeaning; -using fuchsia::ui::input3::NonPrintableKey; +using fuchsia_input::Key; +using fuchsia_ui_input3::KeyMeaning; +using fuchsia_ui_input3::NonPrintableKey; #define EXPECT_CODEPOINT_MAPS(codepoint) \ EXPECT_EQ( \ @@ -60,8 +59,8 @@ TEST(FuchsiaKeyboardCodeConversion, FuchsiaKeyToDomKeySpecificValues) { // Check that NonPrintableKeys are converted correctly. EXPECT_EQ(ui::DomKey::ENTER, - ui::DomKeyFromFuchsiaKeyMeaning(KeyMeaning::WithNonPrintableKey( - NonPrintableKey(NonPrintableKey::ENTER)))); + ui::DomKeyFromFuchsiaKeyMeaning( + KeyMeaning::WithNonPrintableKey(NonPrintableKey::kEnter))); } } // namespace diff --git a/ui/ozone/platform/flatland/BUILD.gn b/ui/ozone/platform/flatland/BUILD.gn index ff5da9b839ff0c..8750b5a82d93ef 100644 --- a/ui/ozone/platform/flatland/BUILD.gn +++ b/ui/ozone/platform/flatland/BUILD.gn @@ -60,6 +60,8 @@ source_set("flatland") { "//third_party/angle/src/common/fuchsia_egl", "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.mem:fuchsia.mem_hlcpp", "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.sysmem:fuchsia.sysmem_hlcpp", + "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.ui.views:fuchsia.ui.views_cpp_hlcpp_conversion", + "//third_party/fuchsia-sdk/sdk/pkg/component_incoming_cpp", "//third_party/fuchsia-sdk/sdk/pkg/sys_cpp", "//ui/base", "//ui/base/cursor", @@ -75,7 +77,7 @@ source_set("flatland") { public_deps = [ "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.ui.composition:fuchsia.ui.composition_hlcpp", "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.ui.gfx:fuchsia.ui.gfx_hlcpp", - "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.ui.input3:fuchsia.ui.input3_hlcpp", + "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.ui.input3:fuchsia.ui.input3_cpp", "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.ui.pointer:fuchsia.ui.pointer_cpp", "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.ui.pointer:fuchsia.ui.pointer_cpp_hlcpp_conversion", "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.ui.views:fuchsia.ui.views_hlcpp", diff --git a/ui/ozone/platform/flatland/flatland_window.cc b/ui/ozone/platform/flatland/flatland_window.cc index c2ee8fc4e59bc3..c6fbab79bebbda 100644 --- a/ui/ozone/platform/flatland/flatland_window.cc +++ b/ui/ozone/platform/flatland/flatland_window.cc @@ -5,7 +5,9 @@ #include "ui/ozone/platform/flatland/flatland_window.h" #include +#include #include +#include #include #include @@ -17,8 +19,8 @@ #include #include "base/check_op.h" +#include "base/fuchsia/fuchsia_component_connect.h" #include "base/fuchsia/fuchsia_logging.h" -#include "base/fuchsia/process_context.h" #include "base/functional/bind.h" #include "base/memory/scoped_refptr.h" #include "ui/base/cursor/platform_cursor.h" @@ -121,14 +123,15 @@ FlatlandWindow::FlatlandWindow(FlatlandWindowManager* window_manager, if (properties.enable_keyboard) { is_virtual_keyboard_enabled_ = properties.enable_virtual_keyboard; - keyboard_service_ = base::ComponentContextForProcess() - ->svc() - ->Connect(); - keyboard_service_.set_error_handler([](zx_status_t status) { - ZX_LOG(ERROR, status) << "input3.Keyboard service disconnected."; - }); - keyboard_client_ = std::make_unique(keyboard_service_.get(), - CloneViewRef(), this); + auto keyboard_client_end = + base::fuchsia_component::Connect(); + CHECK(keyboard_client_end.is_ok()) + << base::FidlConnectionErrorMessage(keyboard_client_end); + keyboard_fidl_client_.Bind(std::move(keyboard_client_end.value()), + async_get_default_dispatcher(), + &fidl_error_event_logger_); + keyboard_client_ = std::make_unique( + keyboard_fidl_client_, fidl::HLCPPToNatural(CloneViewRef()), this); } else { DCHECK(!properties.enable_virtual_keyboard); } diff --git a/ui/ozone/platform/flatland/flatland_window.h b/ui/ozone/platform/flatland/flatland_window.h index acb7cc1413ed96..8c5382dcc3bb80 100644 --- a/ui/ozone/platform/flatland/flatland_window.h +++ b/ui/ozone/platform/flatland/flatland_window.h @@ -5,8 +5,8 @@ #ifndef UI_OZONE_PLATFORM_FLATLAND_FLATLAND_WINDOW_H_ #define UI_OZONE_PLATFORM_FLATLAND_FLATLAND_WINDOW_H_ +#include #include -#include #include #include @@ -15,6 +15,7 @@ #include #include "base/component_export.h" +#include "base/fuchsia/fidl_event_handler.h" #include "base/functional/callback.h" #include "third_party/abseil-cpp/absl/types/optional.h" #include "ui/base/ime/fuchsia/keyboard_client.h" @@ -121,7 +122,9 @@ class COMPONENT_EXPORT(OZONE) FlatlandWindow : public PlatformWindow, ScenicWindowDelegate* const scenic_window_delegate_; gfx::AcceleratedWidget const window_id_; - fuchsia::ui::input3::KeyboardPtr keyboard_service_; + fidl::Client keyboard_fidl_client_; + base::FidlErrorEventLogger + fidl_error_event_logger_; std::unique_ptr keyboard_client_; std::unique_ptr pointer_handler_; diff --git a/ui/ozone/platform/scenic/BUILD.gn b/ui/ozone/platform/scenic/BUILD.gn index 112607dc50cb00..29e29e87a0ac96 100644 --- a/ui/ozone/platform/scenic/BUILD.gn +++ b/ui/ozone/platform/scenic/BUILD.gn @@ -67,6 +67,8 @@ source_set("scenic") { "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.mem:fuchsia.mem_hlcpp", "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.sysmem:fuchsia.sysmem_hlcpp", "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.ui.pointer:fuchsia.ui.pointer_cpp_hlcpp_conversion", + "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.ui.views:fuchsia.ui.views_cpp_hlcpp_conversion", + "//third_party/fuchsia-sdk/sdk/pkg/component_incoming_cpp", "//third_party/fuchsia-sdk/sdk/pkg/scenic_cpp", "//third_party/fuchsia-sdk/sdk/pkg/sys_cpp", "//ui/base", diff --git a/ui/ozone/platform/scenic/scenic_window.cc b/ui/ozone/platform/scenic/scenic_window.cc index c2e282e8ea2ef3..1bfa94091b47cf 100644 --- a/ui/ozone/platform/scenic/scenic_window.cc +++ b/ui/ozone/platform/scenic/scenic_window.cc @@ -5,7 +5,9 @@ #include "ui/ozone/platform/scenic/scenic_window.h" #include +#include #include +#include #include #include @@ -15,8 +17,8 @@ #include #include +#include "base/fuchsia/fuchsia_component_connect.h" #include "base/fuchsia/fuchsia_logging.h" -#include "base/fuchsia/process_context.h" #include "base/memory/scoped_refptr.h" #include "ui/base/cursor/platform_cursor.h" #include "ui/display/types/display_constants.h" @@ -136,14 +138,15 @@ ScenicWindow::ScenicWindow(ScenicWindowManager* window_manager, if (properties.enable_keyboard) { is_virtual_keyboard_enabled_ = properties.enable_virtual_keyboard; - keyboard_service_ = base::ComponentContextForProcess() - ->svc() - ->Connect(); - keyboard_service_.set_error_handler([](zx_status_t status) { - ZX_LOG(ERROR, status) << "input3.Keyboard service disconnected."; - }); - keyboard_client_ = std::make_unique(keyboard_service_.get(), - CloneViewRef(), this); + auto keyboard_client_end = + base::fuchsia_component::Connect(); + CHECK(keyboard_client_end.is_ok()) + << base::FidlConnectionErrorMessage(keyboard_client_end); + keyboard_fidl_client_.Bind(std::move(keyboard_client_end.value()), + async_get_default_dispatcher(), + &fidl_error_event_logger_); + keyboard_client_ = std::make_unique( + keyboard_fidl_client_, fidl::HLCPPToNatural(CloneViewRef()), this); } else { DCHECK(!properties.enable_virtual_keyboard); } diff --git a/ui/ozone/platform/scenic/scenic_window.h b/ui/ozone/platform/scenic/scenic_window.h index 9ad70996187be9..bac1e0ab82b444 100644 --- a/ui/ozone/platform/scenic/scenic_window.h +++ b/ui/ozone/platform/scenic/scenic_window.h @@ -5,9 +5,10 @@ #ifndef UI_OZONE_PLATFORM_SCENIC_SCENIC_WINDOW_H_ #define UI_OZONE_PLATFORM_SCENIC_SCENIC_WINDOW_H_ +#include #include #include -#include +#include #include #include #include @@ -16,6 +17,7 @@ #include #include "base/component_export.h" +#include "base/fuchsia/fidl_event_handler.h" #include "ui/base/ime/fuchsia/keyboard_client.h" #include "ui/events/fuchsia/input_event_sink.h" #include "ui/events/fuchsia/pointer_events_handler.h" @@ -145,7 +147,9 @@ class COMPONENT_EXPORT(OZONE) ScenicWindow final : public PlatformWindow, // Used to coordinate window closure requests with the shell. fuchsia::element::ViewControllerPtr view_controller_; - fuchsia::ui::input3::KeyboardPtr keyboard_service_; + fidl::Client keyboard_fidl_client_; + base::FidlErrorEventLogger + fidl_error_event_logger_; std::unique_ptr keyboard_client_; // React to view-focus coming and going.