Commit fd2d0bb0 authored by Darren Shen's avatar Darren Shen Committed by Commit Bot

ime: Send on composition canceled to IME service.

Add Mojo and protobuf messages for Chrome to send an event the IME
service when the composition is canceled.

Bug: 1019541
Change-Id: I7077586d8df4e094300651aa81ac6be73ed7b0fc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2483946
Commit-Queue: Darren Shen <shend@chromium.org>
Reviewed-by: default avatarKeith Lee <keithlee@chromium.org>
Reviewed-by: default avatarJing Wang <jiwan@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#820641}
parent 945c129a
...@@ -227,8 +227,12 @@ void NativeInputMethodEngine::ImeObserver::OnKeyEvent( ...@@ -227,8 +227,12 @@ void NativeInputMethodEngine::ImeObserver::OnKeyEvent(
void NativeInputMethodEngine::ImeObserver::OnReset( void NativeInputMethodEngine::ImeObserver::OnReset(
const std::string& engine_id) { const std::string& engine_id) {
if (ShouldUseRuleBasedMojoEngine(engine_id) && remote_to_engine_.is_bound()) { if (remote_to_engine_.is_bound()) {
remote_to_engine_->ResetForRulebased(); if (ShouldUseRuleBasedMojoEngine(engine_id)) {
remote_to_engine_->ResetForRulebased();
} else if (ShouldUseFstMojoEngine(engine_id)) {
remote_to_engine_->OnCompositionCanceled();
}
} }
base_observer_->OnReset(engine_id); base_observer_->OnReset(engine_id);
} }
......
...@@ -98,6 +98,7 @@ class NativeInputMethodEngine : public InputMethodEngine { ...@@ -98,6 +98,7 @@ class NativeInputMethodEngine : public InputMethodEngine {
const std::string& text, const std::string& text,
uint32_t offset, uint32_t offset,
ime::mojom::SelectionRangePtr selection_range) override {} ime::mojom::SelectionRangePtr selection_range) override {}
void OnCompositionCanceled() override {}
void ProcessKeypressForRulebased( void ProcessKeypressForRulebased(
ime::mojom::PhysicalKeyEventPtr event, ime::mojom::PhysicalKeyEventPtr event,
ProcessKeypressForRulebasedCallback callback) override {} ProcessKeypressForRulebasedCallback callback) override {}
......
...@@ -177,6 +177,14 @@ void DecoderEngine::OnSurroundingTextChanged( ...@@ -177,6 +177,14 @@ void DecoderEngine::OnSurroundingTextChanged(
base::DoNothing()); base::DoNothing());
} }
void DecoderEngine::OnCompositionCanceled() {
const uint64_t seq_id = current_seq_id_;
++current_seq_id_;
ProcessMessage(WrapAndSerializeMessage(OnCompositionCanceledToProto(seq_id)),
base::DoNothing());
}
void DecoderEngine::ProcessMessage(const std::vector<uint8_t>& message, void DecoderEngine::ProcessMessage(const std::vector<uint8_t>& message,
ProcessMessageCallback callback) { ProcessMessageCallback callback) {
// TODO(https://crbug.com/837156): Set a default protobuf message. // TODO(https://crbug.com/837156): Set a default protobuf message.
......
...@@ -40,6 +40,7 @@ class DecoderEngine : public InputEngine { ...@@ -40,6 +40,7 @@ class DecoderEngine : public InputEngine {
const std::string& text, const std::string& text,
uint32_t offset, uint32_t offset,
mojom::SelectionRangePtr selection_range) override; mojom::SelectionRangePtr selection_range) override;
void OnCompositionCanceled() override;
private: private:
// Try to load the decoding functions from some decoder shared library. // Try to load the decoding functions from some decoder shared library.
......
...@@ -64,6 +64,7 @@ class StubInputChannel : public mojom::InputChannel { ...@@ -64,6 +64,7 @@ class StubInputChannel : public mojom::InputChannel {
const std::string& text, const std::string& text,
uint32_t offset, uint32_t offset,
ime::mojom::SelectionRangePtr selection_range) final {} ime::mojom::SelectionRangePtr selection_range) final {}
void OnCompositionCanceled() final {}
void ResetForRulebased() final {} void ResetForRulebased() final {}
void GetRulebasedKeypressCountForTesting( void GetRulebasedKeypressCountForTesting(
GetRulebasedKeypressCountForTestingCallback callback) final {} GetRulebasedKeypressCountForTestingCallback callback) final {}
...@@ -188,5 +189,22 @@ TEST_F(DecoderEngineTest, OnSurroundingTextChangedSendsMessageToSharedLib) { ...@@ -188,5 +189,22 @@ TEST_F(DecoderEngineTest, OnSurroundingTextChangedSendsMessageToSharedLib) {
client.FlushForTesting(); client.FlushForTesting();
} }
TEST_F(DecoderEngineTest, OnCompositionCanceledSendsMessageToSharedLib) {
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() =
OnCompositionCanceledToProto(/*seq_id=*/0);
EXPECT_CALL(mock_main_entry_, Process).With(EqualsProto(expected_proto));
client->OnCompositionCanceled();
client.FlushForTesting();
}
} // namespace ime } // namespace ime
} // namespace chromeos } // namespace chromeos
...@@ -72,5 +72,14 @@ ime::PublicMessage OnSurroundingTextChangedToProto( ...@@ -72,5 +72,14 @@ ime::PublicMessage OnSurroundingTextChangedToProto(
return message; return message;
} }
ime::PublicMessage OnCompositionCanceledToProto(uint64_t seq_id) {
ime::PublicMessage message;
message.set_seq_id(seq_id);
*message.mutable_on_composition_canceled() = ime::OnCompositionCanceled();
return message;
}
} // namespace ime } // namespace ime
} // namespace chromeos } // namespace chromeos
...@@ -31,6 +31,10 @@ ime::PublicMessage OnSurroundingTextChangedToProto( ...@@ -31,6 +31,10 @@ ime::PublicMessage OnSurroundingTextChangedToProto(
uint32_t focus, uint32_t focus,
mojom::SelectionRangePtr selection_range); mojom::SelectionRangePtr selection_range);
// Converts arguments of a Mojo call to InputChannel::OnCompositionCanceled into
// a proto.
ime::PublicMessage OnCompositionCanceledToProto(uint64_t seq_id);
} // namespace ime } // namespace ime
} // namespace chromeos } // namespace chromeos
......
...@@ -80,5 +80,18 @@ TEST(ProtoConversionTest, OnSurroundingTextChangedToProto) { ...@@ -80,5 +80,18 @@ TEST(ProtoConversionTest, OnSurroundingTextChangedToProto) {
expected_message.SerializeAsString()); expected_message.SerializeAsString());
} }
TEST(ProtoConversionTest, OnCompositionCanceledToProto) {
ime::PublicMessage expected_message;
expected_message.set_seq_id(42);
*expected_message.mutable_on_composition_canceled() =
ime::OnCompositionCanceled();
ime::PublicMessage actual_message =
OnCompositionCanceledToProto(/*seq_id=*/42);
EXPECT_EQ(actual_message.SerializeAsString(),
expected_message.SerializeAsString());
}
} // namespace ime } // namespace ime
} // namespace chromeos } // namespace chromeos
...@@ -67,6 +67,7 @@ class TestClientChannel : mojom::InputChannel { ...@@ -67,6 +67,7 @@ class TestClientChannel : mojom::InputChannel {
void(const std::string& text, void(const std::string& text,
uint32_t offset, uint32_t offset,
mojom::SelectionRangePtr selection_range)); mojom::SelectionRangePtr selection_range));
MOCK_METHOD0(OnCompositionCanceled, void());
MOCK_METHOD0(ResetForRulebased, void()); MOCK_METHOD0(ResetForRulebased, void());
MOCK_METHOD1(GetRulebasedKeypressCountForTesting, MOCK_METHOD1(GetRulebasedKeypressCountForTesting,
void(GetRulebasedKeypressCountForTestingCallback)); void(GetRulebasedKeypressCountForTestingCallback));
......
...@@ -122,6 +122,10 @@ void InputEngine::OnSurroundingTextChanged( ...@@ -122,6 +122,10 @@ void InputEngine::OnSurroundingTextChanged(
NOTIMPLEMENTED(); // Not used in the rulebased engine. NOTIMPLEMENTED(); // Not used in the rulebased engine.
} }
void InputEngine::OnCompositionCanceled() {
NOTIMPLEMENTED(); // Not used in the rulebased engine.
}
void InputEngine::ProcessKeypressForRulebased( void InputEngine::ProcessKeypressForRulebased(
mojom::PhysicalKeyEventPtr event, mojom::PhysicalKeyEventPtr event,
ProcessKeypressForRulebasedCallback callback) { ProcessKeypressForRulebasedCallback callback) {
......
...@@ -52,6 +52,7 @@ class InputEngine : public mojom::InputChannel { ...@@ -52,6 +52,7 @@ class InputEngine : public mojom::InputChannel {
const std::string& text, const std::string& text,
uint32_t offset, uint32_t offset,
mojom::SelectionRangePtr selection_range) override; mojom::SelectionRangePtr selection_range) override;
void OnCompositionCanceled() override;
void ProcessKeypressForRulebased( void ProcessKeypressForRulebased(
mojom::PhysicalKeyEventPtr event, mojom::PhysicalKeyEventPtr event,
ProcessKeypressForRulebasedCallback callback) override; ProcessKeypressForRulebasedCallback callback) override;
......
...@@ -143,6 +143,10 @@ interface InputChannel { ...@@ -143,6 +143,10 @@ interface InputChannel {
uint32 offset, uint32 offset,
SelectionRange selection_range); SelectionRange selection_range);
// Informs the IME that composition was canceled by the system. This can
// for example happen if the user presses the Escape key.
OnCompositionCanceled();
// Process a PhysicalKeyEvent using the rule-based engine and return a // Process a PhysicalKeyEvent using the rule-based engine and return a
// KeypressResponseForRulebased object with a list of operations to be handled // KeypressResponseForRulebased object with a list of operations to be handled
// by the caller. // by the caller.
......
...@@ -34,6 +34,7 @@ message PublicMessage { ...@@ -34,6 +34,7 @@ message PublicMessage {
OnKeyEventReply on_key_event_reply = 4; OnKeyEventReply on_key_event_reply = 4;
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;
} }
} }
...@@ -99,3 +100,7 @@ message OnSurroundingTextChanged { ...@@ -99,3 +100,7 @@ message OnSurroundingTextChanged {
optional uint32 offset = 2; optional uint32 offset = 2;
optional SelectionRange selection_range = 3; optional SelectionRange selection_range = 3;
} }
// Protobuf version of InputEngine::OnCompositionCanceled in
// chromeos/services/ime/public/mojom/input_engine.mojom
message OnCompositionCanceled {}
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