Commit 6fd052ff authored by Darren Shen's avatar Darren Shen Committed by Commit Bot

ime: Send input method changes to IME service.

Add Mojo and protobuf messages for Chrome to send input method changes
to the IME service.

Bug: b/161490915
Change-Id: Ie1ec9a50f6c0c4daaa6e28af9f669ea7c469b9ea
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2497942Reviewed-by: default avatarMartin Barbella <mbarbella@chromium.org>
Reviewed-by: default avatarKeith Lee <keithlee@chromium.org>
Commit-Queue: Darren Shen <shend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#822090}
parent 6dacf7c3
...@@ -395,6 +395,9 @@ void NativeInputMethodEngine::ImeObserver::OnConnected(base::Time start, ...@@ -395,6 +395,9 @@ void NativeInputMethodEngine::ImeObserver::OnConnected(base::Time start,
: ImeServiceEvent::kActivateImeSuccess); : ImeServiceEvent::kActivateImeSuccess);
active_engine_id_ = engine_id; active_engine_id_ = engine_id;
if (ShouldUseFstMojoEngine(engine_id)) {
remote_to_engine_->OnInputMethodChanged(engine_id);
}
} }
void NativeInputMethodEngine::ImeObserver::OnError(base::Time start) { void NativeInputMethodEngine::ImeObserver::OnError(base::Time start) {
......
...@@ -92,6 +92,7 @@ class NativeInputMethodEngine : public InputMethodEngine { ...@@ -92,6 +92,7 @@ class NativeInputMethodEngine : public InputMethodEngine {
// mojom::InputChannel: // mojom::InputChannel:
void ProcessMessage(const std::vector<uint8_t>& message, void ProcessMessage(const std::vector<uint8_t>& message,
ProcessMessageCallback callback) override; ProcessMessageCallback callback) override;
void OnInputMethodChanged(const std::string& engine_id) override {}
void OnFocus(ime::mojom::InputFieldInfoPtr input_field_info) override {} void OnFocus(ime::mojom::InputFieldInfoPtr input_field_info) override {}
void OnBlur() override {} void OnBlur() override {}
void OnSurroundingTextChanged( void OnSurroundingTextChanged(
......
...@@ -138,6 +138,15 @@ bool DecoderEngine::IsImeSupportedByDecoder(const std::string& ime_spec) { ...@@ -138,6 +138,15 @@ bool DecoderEngine::IsImeSupportedByDecoder(const std::string& ime_spec) {
engine_main_entry_->IsImeSupported(ime_spec.c_str()); engine_main_entry_->IsImeSupported(ime_spec.c_str());
} }
void DecoderEngine::OnInputMethodChanged(const std::string& engine_id) {
const uint64_t seq_id = current_seq_id_;
++current_seq_id_;
ProcessMessage(
WrapAndSerializeMessage(OnInputMethodChangedToProto(seq_id, engine_id)),
base::DoNothing());
}
void DecoderEngine::OnFocus(mojom::InputFieldInfoPtr input_field_info) { void DecoderEngine::OnFocus(mojom::InputFieldInfoPtr input_field_info) {
const uint64_t seq_id = current_seq_id_; const uint64_t seq_id = current_seq_id_;
++current_seq_id_; ++current_seq_id_;
......
...@@ -32,6 +32,7 @@ class DecoderEngine : public InputEngine { ...@@ -32,6 +32,7 @@ class DecoderEngine : public InputEngine {
void ProcessMessage(const std::vector<uint8_t>& message, void ProcessMessage(const std::vector<uint8_t>& message,
ProcessMessageCallback callback) override; ProcessMessageCallback callback) override;
void OnInputMethodChanged(const std::string& engine_id) override;
void OnFocus(mojom::InputFieldInfoPtr input_field_info) override; void OnFocus(mojom::InputFieldInfoPtr input_field_info) override;
void OnBlur() override; void OnBlur() override;
void OnKeyEvent(mojom::PhysicalKeyEventPtr event, void OnKeyEvent(mojom::PhysicalKeyEventPtr event,
......
...@@ -53,6 +53,7 @@ class StubInputChannel : public mojom::InputChannel { ...@@ -53,6 +53,7 @@ class StubInputChannel : public mojom::InputChannel {
ProcessMessageCallback callback) final { ProcessMessageCallback callback) final {
std::move(callback).Run({}); std::move(callback).Run({});
} }
void OnInputMethodChanged(const std::string& engine_id) final {}
void OnFocus(mojom::InputFieldInfoPtr input_field_info) final {} void OnFocus(mojom::InputFieldInfoPtr input_field_info) final {}
void OnBlur() final {} void OnBlur() final {}
void ProcessKeypressForRulebased( void ProcessKeypressForRulebased(
...@@ -103,6 +104,23 @@ TEST_F(DecoderEngineTest, BindRequestBindsInterfaces) { ...@@ -103,6 +104,23 @@ TEST_F(DecoderEngineTest, BindRequestBindsInterfaces) {
EXPECT_TRUE(receiver.is_bound()); EXPECT_TRUE(receiver.is_bound());
} }
TEST_F(DecoderEngineTest, OnInputMethodChangedSendsMessageToSharedLib) {
DecoderEngine engine(/*platform=*/nullptr);
StubInputChannel stub_channel;
mojo::Receiver<mojom::InputChannel> receiver(&stub_channel);
mojo::Remote<mojom::InputChannel> client;
ASSERT_TRUE(engine.BindRequest(kImeSpec, client.BindNewPipeAndPassReceiver(),
receiver.BindNewPipeAndPassRemote(), {}));
ime::Wrapper expected_proto;
*expected_proto.mutable_public_message() =
OnInputMethodChangedToProto(/*seq_id=*/0, "xkb:us::eng");
EXPECT_CALL(mock_main_entry_, Process).With(EqualsProto(expected_proto));
client->OnInputMethodChanged("xkb:us::eng");
client.FlushForTesting();
}
TEST_F(DecoderEngineTest, OnFocusSendsMessageToSharedLib) { TEST_F(DecoderEngineTest, OnFocusSendsMessageToSharedLib) {
DecoderEngine engine(/*platform=*/nullptr); DecoderEngine engine(/*platform=*/nullptr);
StubInputChannel stub_channel; StubInputChannel stub_channel;
......
...@@ -63,6 +63,15 @@ InputFieldInfo::PersonalizationMode PersonalizationModeToProto( ...@@ -63,6 +63,15 @@ InputFieldInfo::PersonalizationMode PersonalizationModeToProto(
} // namespace } // namespace
ime::PublicMessage OnInputMethodChangedToProto(uint64_t seq_id,
const std::string& engine_id) {
ime::PublicMessage message;
message.set_seq_id(seq_id);
message.mutable_on_input_method_changed()->set_engine_id(engine_id);
return message;
}
ime::PublicMessage OnFocusToProto(uint64_t seq_id, ime::PublicMessage OnFocusToProto(uint64_t seq_id,
mojom::InputFieldInfoPtr input_field_info) { mojom::InputFieldInfoPtr input_field_info) {
ime::PublicMessage message; ime::PublicMessage message;
......
...@@ -13,6 +13,11 @@ ...@@ -13,6 +13,11 @@
namespace chromeos { namespace chromeos {
namespace ime { namespace ime {
// Converts arguments of a Mojo call to InputChannel::OnInputMethodChanged into
// a proto.
ime::PublicMessage OnInputMethodChangedToProto(uint64_t seq_id,
const std::string& engine_id);
// Converts arguments of a Mojo call to InputChannel::OnFocus into a proto. // Converts arguments of a Mojo call to InputChannel::OnFocus into a proto.
ime::PublicMessage OnFocusToProto(uint64_t seq_id, ime::PublicMessage OnFocusToProto(uint64_t seq_id,
mojom::InputFieldInfoPtr input_field_info); mojom::InputFieldInfoPtr input_field_info);
......
...@@ -10,6 +10,20 @@ ...@@ -10,6 +10,20 @@
namespace chromeos { namespace chromeos {
namespace ime { namespace ime {
TEST(ProtoConversionTest, OnInputMethodChangedToProto) {
ime::PublicMessage expected_message;
expected_message.set_seq_id(42);
ime::OnInputMethodChanged& args =
*expected_message.mutable_on_input_method_changed();
args.set_engine_id("xkb:us::eng");
ime::PublicMessage actual_message =
OnInputMethodChangedToProto(/*seq_id=*/42, "xkb:us::eng");
EXPECT_EQ(actual_message.SerializeAsString(),
expected_message.SerializeAsString());
}
TEST(ProtoConversionTest, OnFocusToProto) { TEST(ProtoConversionTest, OnFocusToProto) {
auto info = mojom::InputFieldInfo::New(mojom::InputFieldType::kNumber, auto info = mojom::InputFieldInfo::New(mojom::InputFieldType::kNumber,
mojom::AutocorrectMode::kEnabled, mojom::AutocorrectMode::kEnabled,
......
...@@ -55,6 +55,7 @@ class TestClientChannel : mojom::InputChannel { ...@@ -55,6 +55,7 @@ class TestClientChannel : mojom::InputChannel {
MOCK_METHOD2(ProcessMessage, MOCK_METHOD2(ProcessMessage,
void(const std::vector<uint8_t>& message, void(const std::vector<uint8_t>& message,
ProcessMessageCallback)); ProcessMessageCallback));
MOCK_METHOD1(OnInputMethodChanged, void(const std::string& engine_id));
MOCK_METHOD1(OnFocus, void(mojom::InputFieldInfoPtr input_field_info)); MOCK_METHOD1(OnFocus, void(mojom::InputFieldInfoPtr input_field_info));
MOCK_METHOD0(OnBlur, void()); MOCK_METHOD0(OnBlur, void());
MOCK_METHOD2(ProcessKeypressForRulebased, MOCK_METHOD2(ProcessKeypressForRulebased,
......
...@@ -107,6 +107,10 @@ void InputEngine::ProcessMessage(const std::vector<uint8_t>& message, ...@@ -107,6 +107,10 @@ void InputEngine::ProcessMessage(const std::vector<uint8_t>& message,
NOTIMPLEMENTED(); // Protobuf message is not used in the rulebased engine. NOTIMPLEMENTED(); // Protobuf message is not used in the rulebased engine.
} }
void InputEngine::OnInputMethodChanged(const std::string& engine_id) {
NOTIMPLEMENTED(); // Not used in the rulebased engine.
}
void InputEngine::OnFocus(mojom::InputFieldInfoPtr input_field_info) { void InputEngine::OnFocus(mojom::InputFieldInfoPtr input_field_info) {
NOTIMPLEMENTED(); // Not used in the rulebased engine. NOTIMPLEMENTED(); // Not used in the rulebased engine.
} }
......
...@@ -46,6 +46,7 @@ class InputEngine : public mojom::InputChannel { ...@@ -46,6 +46,7 @@ class InputEngine : public mojom::InputChannel {
// mojom::InputChannel overrides: // mojom::InputChannel overrides:
void ProcessMessage(const std::vector<uint8_t>& message, void ProcessMessage(const std::vector<uint8_t>& message,
ProcessMessageCallback callback) override; ProcessMessageCallback callback) override;
void OnInputMethodChanged(const std::string& engine_id) override;
void OnFocus(mojom::InputFieldInfoPtr input_field_info) override; void OnFocus(mojom::InputFieldInfoPtr input_field_info) override;
void OnBlur() override; void OnBlur() override;
void OnSurroundingTextChanged( void OnSurroundingTextChanged(
......
...@@ -164,6 +164,11 @@ interface InputChannel { ...@@ -164,6 +164,11 @@ interface InputChannel {
// protobuf message. // protobuf message.
ProcessMessage(array<uint8> message) => (array<uint8> result); ProcessMessage(array<uint8> message) => (array<uint8> result);
// Called when the input method changes.
// |engine_id| is the unique identifier for the input method, as specified in:
// chrome/browser/resources/chromeos/input_method/google_xkb_manifest.json
OnInputMethodChanged(string engine_id);
// Called when there's a new focused input field. // Called when there's a new focused input field.
OnFocus(InputFieldInfo input_field_info); OnFocus(InputFieldInfo input_field_info);
......
...@@ -35,6 +35,7 @@ message PublicMessage { ...@@ -35,6 +35,7 @@ message PublicMessage {
OnSurroundingTextChanged on_surrounding_text_changed = 5; OnSurroundingTextChanged on_surrounding_text_changed = 5;
OnBlur on_blur = 6; OnBlur on_blur = 6;
OnCompositionCanceled on_composition_canceled = 7; OnCompositionCanceled on_composition_canceled = 7;
OnInputMethodChanged on_input_method_changed = 8;
} }
} }
...@@ -70,6 +71,12 @@ message InputFieldInfo { ...@@ -70,6 +71,12 @@ message InputFieldInfo {
optional PersonalizationMode personalization = 3; optional PersonalizationMode personalization = 3;
} }
// Protobuf version of InputEngine::OnInputMethodChanged in
// chromeos/services/ime/public/mojom/input_engine.mojom
message OnInputMethodChanged {
optional string engine_id = 1;
}
// Protobuf version of InputEngine::OnFocus in // Protobuf version of InputEngine::OnFocus in
// chromeos/services/ime/public/mojom/input_engine.mojom // chromeos/services/ime/public/mojom/input_engine.mojom
message OnFocus { message OnFocus {
......
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