Commit 9177d85b authored by Darren Shen's avatar Darren Shen Committed by Commit Bot

ime: Send on blur to IME service.

Add Mojo and protobuf messages for Chrome to send on blur to the IME
service.

Bug: 1019541
Change-Id: If01c8e2dceaa13c7218ee13913f32a26ddcfe52e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2483944Reviewed-by: default avatarKeith Lee <keithlee@chromium.org>
Reviewed-by: default avatarMartin Barbella <mbarbella@chromium.org>
Commit-Queue: Darren Shen <shend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#820085}
parent 285b9407
...@@ -187,6 +187,11 @@ void NativeInputMethodEngine::ImeObserver::OnBlur(int context_id) { ...@@ -187,6 +187,11 @@ void NativeInputMethodEngine::ImeObserver::OnBlur(int context_id) {
if (assistive_suggester_->IsAssistiveFeatureEnabled()) if (assistive_suggester_->IsAssistiveFeatureEnabled())
assistive_suggester_->OnBlur(); assistive_suggester_->OnBlur();
if (active_engine_id_ && ShouldUseFstMojoEngine(*active_engine_id_) &&
remote_to_engine_.is_bound()) {
remote_to_engine_->OnBlur();
}
base_observer_->OnBlur(context_id); base_observer_->OnBlur(context_id);
} }
......
...@@ -93,6 +93,7 @@ class NativeInputMethodEngine : public InputMethodEngine { ...@@ -93,6 +93,7 @@ class NativeInputMethodEngine : public InputMethodEngine {
void ProcessMessage(const std::vector<uint8_t>& message, void ProcessMessage(const std::vector<uint8_t>& message,
ProcessMessageCallback callback) override; ProcessMessageCallback callback) override;
void OnFocus() override {} void OnFocus() override {}
void OnBlur() override {}
void OnSurroundingTextChanged( void OnSurroundingTextChanged(
const std::string& text, const std::string& text,
uint32_t offset, uint32_t offset,
......
...@@ -145,6 +145,14 @@ void DecoderEngine::OnFocus() { ...@@ -145,6 +145,14 @@ void DecoderEngine::OnFocus() {
base::DoNothing()); base::DoNothing());
} }
void DecoderEngine::OnBlur() {
const uint64_t seq_id = current_seq_id_;
++current_seq_id_;
ProcessMessage(WrapAndSerializeMessage(OnBlurToProto(seq_id)),
base::DoNothing());
}
void DecoderEngine::OnKeyEvent(mojom::PhysicalKeyEventPtr event, void DecoderEngine::OnKeyEvent(mojom::PhysicalKeyEventPtr event,
OnKeyEventCallback callback) { OnKeyEventCallback callback) {
const uint64_t seq_id = current_seq_id_; const uint64_t seq_id = current_seq_id_;
......
...@@ -33,6 +33,7 @@ class DecoderEngine : public InputEngine { ...@@ -33,6 +33,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 OnFocus() override; void OnFocus() override;
void OnBlur() override;
void OnKeyEvent(mojom::PhysicalKeyEventPtr event, void OnKeyEvent(mojom::PhysicalKeyEventPtr event,
OnKeyEventCallback callback) override; OnKeyEventCallback callback) override;
void OnSurroundingTextChanged( void OnSurroundingTextChanged(
......
...@@ -52,6 +52,7 @@ class StubInputChannel : public mojom::InputChannel { ...@@ -52,6 +52,7 @@ class StubInputChannel : public mojom::InputChannel {
std::move(callback).Run({}); std::move(callback).Run({});
} }
void OnFocus() final {} void OnFocus() final {}
void OnBlur() final {}
void ProcessKeypressForRulebased( void ProcessKeypressForRulebased(
ime::mojom::PhysicalKeyEventPtr event, ime::mojom::PhysicalKeyEventPtr event,
ProcessKeypressForRulebasedCallback callback) final {} ProcessKeypressForRulebasedCallback callback) final {}
...@@ -109,6 +110,22 @@ TEST_F(DecoderEngineTest, OnFocusSendsMessageToSharedLib) { ...@@ -109,6 +110,22 @@ TEST_F(DecoderEngineTest, OnFocusSendsMessageToSharedLib) {
client.FlushForTesting(); client.FlushForTesting();
} }
TEST_F(DecoderEngineTest, OnBlurSendsMessageToSharedLib) {
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() = OnBlurToProto(/*seq_id=*/0);
EXPECT_CALL(mock_main_entry_, Process).With(EqualsProto(expected_proto));
client->OnBlur();
client.FlushForTesting();
}
TEST_F(DecoderEngineTest, OnKeyEventRepliesWithCallback) { TEST_F(DecoderEngineTest, OnKeyEventRepliesWithCallback) {
DecoderEngine engine(/*platform=*/nullptr); DecoderEngine engine(/*platform=*/nullptr);
StubInputChannel stub_channel; StubInputChannel stub_channel;
......
...@@ -29,6 +29,14 @@ ime::PublicMessage OnFocusToProto(uint64_t seq_id) { ...@@ -29,6 +29,14 @@ ime::PublicMessage OnFocusToProto(uint64_t seq_id) {
return message; return message;
} }
ime::PublicMessage OnBlurToProto(uint64_t seq_id) {
ime::PublicMessage message;
message.set_seq_id(seq_id);
*message.mutable_on_blur() = ime::OnBlur();
return message;
}
ime::PublicMessage OnKeyEventToProto(uint64_t seq_id, ime::PublicMessage OnKeyEventToProto(uint64_t seq_id,
mojom::PhysicalKeyEventPtr event) { mojom::PhysicalKeyEventPtr event) {
ime::PublicMessage message; ime::PublicMessage message;
......
...@@ -16,6 +16,9 @@ namespace ime { ...@@ -16,6 +16,9 @@ namespace ime {
// 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);
// Converts arguments of a Mojo call to InputChannel::OnBlur into a proto.
ime::PublicMessage OnBlurToProto(uint64_t seq_id);
// Converts arguments of a Mojo call to InputChannel::OnKeyEvent into a proto. // Converts arguments of a Mojo call to InputChannel::OnKeyEvent into a proto.
ime::PublicMessage OnKeyEventToProto(uint64_t seq_id, ime::PublicMessage OnKeyEventToProto(uint64_t seq_id,
mojom::PhysicalKeyEventPtr event); mojom::PhysicalKeyEventPtr event);
......
...@@ -21,6 +21,17 @@ TEST(ProtoConversionTest, OnFocusToProto) { ...@@ -21,6 +21,17 @@ TEST(ProtoConversionTest, OnFocusToProto) {
expected_message.SerializeAsString()); expected_message.SerializeAsString());
} }
TEST(ProtoConversionTest, OnBlurToProto) {
ime::PublicMessage expected_message;
expected_message.set_seq_id(42);
*expected_message.mutable_on_blur() = ime::OnBlur();
ime::PublicMessage actual_message = OnBlurToProto(/*seq_id=*/42);
EXPECT_EQ(actual_message.SerializeAsString(),
expected_message.SerializeAsString());
}
TEST(ProtoConversionTest, OnKeyEventToProto) { TEST(ProtoConversionTest, OnKeyEventToProto) {
auto modifier_state = mojom::ModifierState::New(); auto modifier_state = mojom::ModifierState::New();
modifier_state->shift = true; modifier_state->shift = true;
......
...@@ -56,6 +56,7 @@ class TestClientChannel : mojom::InputChannel { ...@@ -56,6 +56,7 @@ class TestClientChannel : mojom::InputChannel {
void(const std::vector<uint8_t>& message, void(const std::vector<uint8_t>& message,
ProcessMessageCallback)); ProcessMessageCallback));
MOCK_METHOD0(OnFocus, void()); MOCK_METHOD0(OnFocus, void());
MOCK_METHOD0(OnBlur, void());
MOCK_METHOD2(ProcessKeypressForRulebased, MOCK_METHOD2(ProcessKeypressForRulebased,
void(const mojom::PhysicalKeyEventPtr event, void(const mojom::PhysicalKeyEventPtr event,
ProcessKeypressForRulebasedCallback)); ProcessKeypressForRulebasedCallback));
......
...@@ -111,6 +111,10 @@ void InputEngine::OnFocus() { ...@@ -111,6 +111,10 @@ void InputEngine::OnFocus() {
NOTIMPLEMENTED(); // Not used in the rulebased engine. NOTIMPLEMENTED(); // Not used in the rulebased engine.
} }
void InputEngine::OnBlur() {
NOTIMPLEMENTED(); // Not used in the rulebased engine.
}
void InputEngine::OnSurroundingTextChanged( void InputEngine::OnSurroundingTextChanged(
const std::string& text, const std::string& text,
uint32_t offset, uint32_t offset,
......
...@@ -47,6 +47,7 @@ class InputEngine : public mojom::InputChannel { ...@@ -47,6 +47,7 @@ class InputEngine : public 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 OnFocus() override; void OnFocus() override;
void OnBlur() override;
void OnSurroundingTextChanged( void OnSurroundingTextChanged(
const std::string& text, const std::string& text,
uint32_t offset, uint32_t offset,
......
...@@ -125,6 +125,9 @@ interface InputChannel { ...@@ -125,6 +125,9 @@ interface InputChannel {
// Called when there's a new focused input field. // Called when there's a new focused input field.
OnFocus(); OnFocus();
// Called when the input field loses focus.
OnBlur();
// Process a PhysicalKeyEvent for non-rule-based engines. // Process a PhysicalKeyEvent for non-rule-based engines.
OnKeyEvent(PhysicalKeyEvent event) => (bool consumed); OnKeyEvent(PhysicalKeyEvent event) => (bool consumed);
......
...@@ -33,6 +33,7 @@ message PublicMessage { ...@@ -33,6 +33,7 @@ message PublicMessage {
OnKeyEvent on_key_event = 3; OnKeyEvent on_key_event = 3;
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;
} }
} }
...@@ -42,6 +43,10 @@ message OnFocus { ...@@ -42,6 +43,10 @@ message OnFocus {
// TODO(crbug/1019541): Add information about the input field. // TODO(crbug/1019541): Add information about the input field.
} }
// Protobuf version of InputEngine::OnBlur in
// chromeos/services/ime/public/mojom/input_engine.mojom
message OnBlur {}
// Protobuf version of InputEngine::OnKeyEvent in // Protobuf version of InputEngine::OnKeyEvent in
// chromeos/services/ime/public/mojom/input_engine.mojom // chromeos/services/ime/public/mojom/input_engine.mojom
message OnKeyEvent { message OnKeyEvent {
......
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