From 8113560d27bd0558a387228c8d123fff29895579 Mon Sep 17 00:00:00 2001 From: Yuichiro Hanada Date: Thu, 26 Aug 2021 06:34:33 +0000 Subject: [PATCH] Observe OnKeyboardEnableFlagsChanged to get notified VK availability. OnKeyboardEnabledChanged() is called only when the Chrome OS IME is active. To capture the VK availability update while using other IMEs, exo::Keyboard should observe KeyboardEnableFlag changes instead. Bug: 1238454 Change-Id: I63ee66d49d524cbd6645b1d2853ef94d705054c0 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3120286 Commit-Queue: Yuichiro Hanada Reviewed-by: Tetsui Ohkubo Cr-Commit-Position: refs/heads/main@{#915483} --- components/exo/keyboard.cc | 24 +++++++++++++++--------- components/exo/keyboard.h | 10 +++++++--- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/components/exo/keyboard.cc b/components/exo/keyboard.cc index 6178b59fb77d4d..a62a5ad2e630e0 100644 --- a/components/exo/keyboard.cc +++ b/components/exo/keyboard.cc @@ -196,7 +196,7 @@ bool Keyboard::HasDeviceConfigurationDelegate() const { void Keyboard::SetDeviceConfigurationDelegate( KeyboardDeviceConfigurationDelegate* delegate) { device_configuration_delegate_ = delegate; - OnKeyboardEnabledChanged(IsVirtualKeyboardEnabled()); + UpdateKeyboardType(); } void Keyboard::AddObserver(KeyboardObserver* observer) { @@ -397,14 +397,9 @@ void Keyboard::OnSurfaceFocused(Surface* gained_focus) { //////////////////////////////////////////////////////////////////////////////// // ash::KeyboardControllerObserver overrides: -void Keyboard::OnKeyboardEnabledChanged(bool enabled) { - if (device_configuration_delegate_) { - // Ignore kAndroidDisabled which affects |enabled| and just test for a11y - // and touch enabled keyboards. TODO(yhanada): Fix this using an Android - // specific KeyboardUI implementation. https://crbug.com/897655. - bool is_physical = !IsVirtualKeyboardEnabled(); - device_configuration_delegate_->OnKeyboardTypeChanged(is_physical); - } +void Keyboard::OnKeyboardEnableFlagsChanged( + const std::set& flags) { + UpdateKeyboardType(); } void Keyboard::OnKeyRepeatSettingsChanged( @@ -516,4 +511,15 @@ void Keyboard::RemoveEventHandler() { toplevel_window->RemovePostTargetHandler(this); } +void Keyboard::UpdateKeyboardType() { + if (!device_configuration_delegate_) + return; + + // Ignore kAndroidDisabled which affects |enabled| and just test for a11y + // and touch enabled keyboards. TODO(yhanada): Fix this using an Android + // specific KeyboardUI implementation. https://crbug.com/897655. + const bool is_physical = !IsVirtualKeyboardEnabled(); + device_configuration_delegate_->OnKeyboardTypeChanged(is_physical); +} + } // namespace exo diff --git a/components/exo/keyboard.h b/components/exo/keyboard.h index 25724faaeec7e5..c0532aadc13111 100644 --- a/components/exo/keyboard.h +++ b/components/exo/keyboard.h @@ -67,12 +67,13 @@ class Keyboard : public ui::EventHandler, // Overridden from SeatObserver: void OnSurfaceFocused(Surface* gained_focus) override; - // Overridden from ash::KeyboardControllerObserver - void OnKeyboardEnabledChanged(bool is_enabled) override; + // Overridden from ash::KeyboardControllerObserver: + void OnKeyboardEnableFlagsChanged( + const std::set& flags) override; void OnKeyRepeatSettingsChanged( const ash::KeyRepeatSettings& settings) override; - // Overridden from ash::ImeControllerImpl::Observer + // Overridden from ash::ImeControllerImpl::Observer: void OnCapsLockChanged(bool enabled) override; void OnKeyboardLayoutNameChanged(const std::string& layout_name) override; @@ -97,6 +98,9 @@ class Keyboard : public ui::EventHandler, void AddEventHandler(); void RemoveEventHandler(); + // Notify the current keyboard type. + void UpdateKeyboardType(); + // The delegate instance that all events except for events about device // configuration are dispatched to. std::unique_ptr delegate_;