Commit 78766e63 authored by Darren Shen's avatar Darren Shen Committed by Commit Bot

ime: Connect to Mojo for FST-based input methods.

We previously only used Mojo directly for rule-based input methods.
Connect to Mojo if the input method is FST-based.

Change-Id: I9a93ecaa13acca18e8d9ff07311d2b147c77f5c2
Bug: 1019541
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2371084
Commit-Queue: Darren Shen <shend@chromium.org>
Reviewed-by: default avatarKeith Lee <keithlee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#804640}
parent 3aa25a4f
...@@ -28,10 +28,26 @@ ui::IMEInputContextHandlerInterface* GetInputContext() { ...@@ -28,10 +28,26 @@ ui::IMEInputContextHandlerInterface* GetInputContext() {
return ui::IMEBridge::Get()->GetInputContextHandler(); return ui::IMEBridge::Get()->GetInputContextHandler();
} }
bool ShouldEngineUseMojo(const std::string& engine_id) { bool ShouldUseRuleBasedMojoEngine(const std::string& engine_id) {
return base::StartsWith(engine_id, "vkd_", base::CompareCase::SENSITIVE); return base::StartsWith(engine_id, "vkd_", base::CompareCase::SENSITIVE);
} }
bool ShouldUseFstMojoEngine(const std::string& engine_id) {
return base::FeatureList::IsEnabled(
chromeos::features::kSystemLatinPhysicalTyping) &&
base::StartsWith(engine_id, "xkb:", base::CompareCase::SENSITIVE);
}
std::string NormalizeEngineId(const std::string engine_id) {
// For legacy reasons, |engine_id| starts with "vkd_" in the input method
// manifest, but the InputEngineManager expects the prefix "m17n:".
// TODO(https://crbug.com/1012490): Migrate to m17n prefix and remove this.
if (base::StartsWith(engine_id, "vkd_", base::CompareCase::SENSITIVE)) {
return "m17n:" + engine_id.substr(4);
}
return engine_id;
}
std::string NormalizeString(const std::string& str) { std::string NormalizeString(const std::string& str) {
std::string normalized_str; std::string normalized_str;
base::ConvertToUtf8AndNormalize(str, base::kCodepageUTF8, &normalized_str); base::ConvertToUtf8AndNormalize(str, base::kCodepageUTF8, &normalized_str);
...@@ -114,7 +130,8 @@ NativeInputMethodEngine::ImeObserver::~ImeObserver() = default; ...@@ -114,7 +130,8 @@ NativeInputMethodEngine::ImeObserver::~ImeObserver() = default;
void NativeInputMethodEngine::ImeObserver::OnActivate( void NativeInputMethodEngine::ImeObserver::OnActivate(
const std::string& engine_id) { const std::string& engine_id) {
if (ShouldEngineUseMojo(engine_id)) { if (ShouldUseRuleBasedMojoEngine(engine_id) ||
ShouldUseFstMojoEngine(engine_id)) {
if (!remote_manager_.is_bound()) { if (!remote_manager_.is_bound()) {
auto* ime_manager = input_method::InputMethodManager::Get(); auto* ime_manager = input_method::InputMethodManager::Get();
const auto start = base::Time::Now(); const auto start = base::Time::Now();
...@@ -127,10 +144,7 @@ void NativeInputMethodEngine::ImeObserver::OnActivate( ...@@ -127,10 +144,7 @@ void NativeInputMethodEngine::ImeObserver::OnActivate(
LogEvent(ImeServiceEvent::kInitSuccess); LogEvent(ImeServiceEvent::kInitSuccess);
} }
// For legacy reasons, |engine_id| starts with "vkd_" in the input method const auto new_engine_id = NormalizeEngineId(engine_id);
// manifest, but the InputEngineManager expects the prefix "m17n:".
// TODO(https://crbug.com/1012490): Migrate to m17n prefix and remove this.
const auto new_engine_id = "m17n:" + engine_id.substr(4);
// Deactivate any existing engine. // Deactivate any existing engine.
remote_to_engine_.reset(); remote_to_engine_.reset();
...@@ -174,7 +188,7 @@ void NativeInputMethodEngine::ImeObserver::OnKeyEvent( ...@@ -174,7 +188,7 @@ void NativeInputMethodEngine::ImeObserver::OnKeyEvent(
return; return;
} }
} }
if (ShouldEngineUseMojo(engine_id) && remote_to_engine_.is_bound()) { if (ShouldUseRuleBasedMojoEngine(engine_id) && remote_to_engine_.is_bound()) {
remote_to_engine_->ProcessKeypressForRulebased( remote_to_engine_->ProcessKeypressForRulebased(
ime::mojom::PhysicalKeyEvent::New( ime::mojom::PhysicalKeyEvent::New(
event.type == "keydown" ? ime::mojom::KeyEventType::kKeyDown event.type == "keydown" ? ime::mojom::KeyEventType::kKeyDown
...@@ -189,7 +203,7 @@ void NativeInputMethodEngine::ImeObserver::OnKeyEvent( ...@@ -189,7 +203,7 @@ void NativeInputMethodEngine::ImeObserver::OnKeyEvent(
void NativeInputMethodEngine::ImeObserver::OnReset( void NativeInputMethodEngine::ImeObserver::OnReset(
const std::string& engine_id) { const std::string& engine_id) {
if (ShouldEngineUseMojo(engine_id) && remote_to_engine_.is_bound()) { if (ShouldUseRuleBasedMojoEngine(engine_id) && remote_to_engine_.is_bound()) {
remote_to_engine_->ResetForRulebased(); remote_to_engine_->ResetForRulebased();
} }
base_observer_->OnReset(engine_id); base_observer_->OnReset(engine_id);
...@@ -197,7 +211,7 @@ void NativeInputMethodEngine::ImeObserver::OnReset( ...@@ -197,7 +211,7 @@ void NativeInputMethodEngine::ImeObserver::OnReset(
void NativeInputMethodEngine::ImeObserver::OnDeactivated( void NativeInputMethodEngine::ImeObserver::OnDeactivated(
const std::string& engine_id) { const std::string& engine_id) {
if (ShouldEngineUseMojo(engine_id)) { if (ShouldUseRuleBasedMojoEngine(engine_id)) {
remote_to_engine_.reset(); remote_to_engine_.reset();
} }
base_observer_->OnDeactivated(engine_id); base_observer_->OnDeactivated(engine_id);
......
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