-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Eche] Create mojo interface and bindings for keyboard layout changes
This introduces a mojo interface that allows the EcheSWA to request the current keyboard layout configuration and creates an observer interface to route the information back. Additionally, EcheKeyboardLayoutHandler also observes ImeControllerImpl and sends the same information to the SWA whenever the keyboard layout changes. Test: Manually verified app streaming is WAI, unit tests added. Fixed: b/275816267 Change-Id: I1522789ead32b2c8e009b88d668466c5fdb59fac Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4786991 Reviewed-by: Jon Mann <jonmann@chromium.org> Reviewed-by: Pu Shi <pushi@google.com> Reviewed-by: Will Harris <wfh@chromium.org> Commit-Queue: Crisrael Lucero <crisrael@google.com> Reviewed-by: Abbas Nayebi <nayebi@google.com> Cr-Commit-Position: refs/heads/main@{#1187254}
- Loading branch information
Showing
14 changed files
with
415 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "ash/webui/eche_app_ui/eche_keyboard_layout_handler.h" | ||
|
||
#include "ash/shell.h" | ||
#include "ash/webui/eche_app_ui/proto/exo_messages.pb.h" | ||
#include "base/strings/utf_string_conversions.h" | ||
#include "chromeos/ash/components/multidevice/logging/logging.h" | ||
|
||
namespace ash::eche_app { | ||
|
||
EcheKeyboardLayoutHandler::EcheKeyboardLayoutHandler() | ||
: ime_controller_(Shell::Get()->ime_controller()) { | ||
ime_controller_->AddObserver(this); | ||
} | ||
|
||
EcheKeyboardLayoutHandler::~EcheKeyboardLayoutHandler() { | ||
ime_controller_->RemoveObserver(this); | ||
} | ||
|
||
void EcheKeyboardLayoutHandler::RequestCurrentKeyboardLayout() { | ||
if (!remote_observer_.is_bound() || !ime_controller_) { | ||
return; | ||
} | ||
|
||
const ImeInfo& current_ime = ime_controller_->current_ime(); | ||
remote_observer_->OnKeyboardLayoutChanged( | ||
current_ime.id, base::UTF16ToUTF8(current_ime.name), | ||
base::UTF16ToUTF8(current_ime.short_name), | ||
ime_controller_->keyboard_layout_name()); | ||
} | ||
|
||
void EcheKeyboardLayoutHandler::SetKeyboardLayoutObserver( | ||
mojo::PendingRemote<mojom::KeyboardLayoutObserver> observer) { | ||
PA_LOG(INFO) << "echeapi EcheKeyboardLayoutHandler SetKeyboardLayoutObserver"; | ||
remote_observer_.reset(); | ||
remote_observer_.Bind(std::move(observer)); | ||
} | ||
|
||
void EcheKeyboardLayoutHandler::OnCapsLockChanged(bool enabled) {} | ||
|
||
void EcheKeyboardLayoutHandler::OnKeyboardLayoutNameChanged( | ||
const std::string& layout_name) { | ||
if (!remote_observer_.is_bound()) { | ||
return; | ||
} | ||
|
||
const ImeInfo& current_ime = ime_controller_->current_ime(); | ||
remote_observer_->OnKeyboardLayoutChanged( | ||
current_ime.id, base::UTF16ToUTF8(current_ime.name), | ||
base::UTF16ToUTF8(current_ime.short_name), layout_name); | ||
} | ||
|
||
void EcheKeyboardLayoutHandler::Bind( | ||
mojo::PendingReceiver<mojom::KeyboardLayoutHandler> receiver) { | ||
keyboard_layout_handler_.reset(); | ||
keyboard_layout_handler_.Bind(std::move(receiver)); | ||
} | ||
|
||
} // namespace ash::eche_app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef ASH_WEBUI_ECHE_APP_UI_ECHE_KEYBOARD_LAYOUT_HANDLER_H_ | ||
#define ASH_WEBUI_ECHE_APP_UI_ECHE_KEYBOARD_LAYOUT_HANDLER_H_ | ||
|
||
#include "ash/ime/ime_controller_impl.h" | ||
#include "ash/webui/eche_app_ui/mojom/eche_app.mojom.h" | ||
#include "base/memory/raw_ptr.h" | ||
#include "base/observer_list.h" | ||
#include "base/observer_list_types.h" | ||
#include "mojo/public/cpp/bindings/pending_receiver.h" | ||
#include "mojo/public/cpp/bindings/pending_remote.h" | ||
#include "mojo/public/cpp/bindings/receiver.h" | ||
#include "mojo/public/cpp/bindings/remote.h" | ||
|
||
namespace ash::eche_app { | ||
|
||
// Implements the KeyboardLayoutHandler interface and observes ImeControllerImpl | ||
// to relay keyboard layout/configuration information from ChromeOS to the Eche | ||
// SWA. Additionally, provides the current keyboard layout to the SWA upon | ||
// request. | ||
class EcheKeyboardLayoutHandler : public mojom::KeyboardLayoutHandler, | ||
public ImeControllerImpl::Observer { | ||
public: | ||
EcheKeyboardLayoutHandler(); | ||
~EcheKeyboardLayoutHandler() override; | ||
|
||
// mojom::KeyboardLayoutHandler: | ||
void RequestCurrentKeyboardLayout() override; | ||
void SetKeyboardLayoutObserver( | ||
mojo::PendingRemote<mojom::KeyboardLayoutObserver> observer) override; | ||
|
||
// ImeControllerImpl::Observer: | ||
void OnCapsLockChanged(bool enabled) override; | ||
void OnKeyboardLayoutNameChanged(const std::string& layout_name) override; | ||
|
||
void Bind(mojo::PendingReceiver<mojom::KeyboardLayoutHandler> receiver); | ||
|
||
private: | ||
friend class EcheKeyboardLayoutHandlerTest; | ||
|
||
raw_ptr<ImeControllerImpl, ExperimentalAsh> ime_controller_ = nullptr; | ||
mojo::Receiver<mojom::KeyboardLayoutHandler> keyboard_layout_handler_{this}; | ||
mojo::Remote<mojom::KeyboardLayoutObserver> remote_observer_; | ||
}; | ||
|
||
} // namespace ash::eche_app | ||
|
||
#endif // ASH_WEBUI_ECHE_APP_UI_ECHE_KEYBOARD_LAYOUT_HANDLER_H_ |
Oops, something went wrong.