From 444426764ce61307b1a72d9c3f5bdabf992e23d4 Mon Sep 17 00:00:00 2001 From: yadeno Date: Tue, 12 Apr 2022 11:50:22 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0SetCallingWindow=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yadeno --- .../include/i_input_method_agent.h | 2 ++ .../include/input_method_ability.h | 1 + .../include/input_method_agent_proxy.h | 2 +- .../include/input_method_agent_stub.h | 2 +- .../src/input_method_ability.cpp | 15 ++++++++++++++- .../src/input_method_agent_proxy.cpp | 14 ++++++++++++++ .../src/input_method_agent_stub.cpp | 14 ++++++++++++++ .../include/input_method_controller.h | 1 + .../src/input_method_controller.cpp | 12 ++++++++++++ .../include/js_input_method_engine_listener.h | 1 + .../src/js_input_method_engine_listener.cpp | 15 +++++++++++++++ 11 files changed, 76 insertions(+), 3 deletions(-) diff --git a/frameworks/inputmethod_ability/include/i_input_method_agent.h b/frameworks/inputmethod_ability/include/i_input_method_agent.h index 8af4173..f7dadfb 100644 --- a/frameworks/inputmethod_ability/include/i_input_method_agent.h +++ b/frameworks/inputmethod_ability/include/i_input_method_agent.h @@ -31,6 +31,7 @@ namespace MiscServices { DISPATCH_KEY_EVENT = FIRST_CALL_TRANSACTION, ON_CURSOR_UPDATE, ON_SELECTION_CHANGE, + SET_CALLING_WINDOW_ID, }; DECLARE_INTERFACE_DESCRIPTOR(u"ohos.miscservices.inputmethod.IInputMethodAgent"); @@ -39,6 +40,7 @@ namespace MiscServices { virtual void OnCursorUpdate(int32_t positionX, int32_t positionY, int height) = 0; virtual void OnSelectionChange(std::u16string text, int32_t oldBegin, int32_t oldEnd, int32_t newBegin, int32_t newEnd) = 0; + virtual void SetCallingWindow(uint32_t windowId) = 0; }; } // namespace MiscServices } // namespace OHOS diff --git a/frameworks/inputmethod_ability/include/input_method_ability.h b/frameworks/inputmethod_ability/include/input_method_ability.h index 026990d..e93b84f 100644 --- a/frameworks/inputmethod_ability/include/input_method_ability.h +++ b/frameworks/inputmethod_ability/include/input_method_ability.h @@ -54,6 +54,7 @@ namespace MiscServices { void SendFunctionKey(int32_t funcKey); void MoveCursor(int32_t keyCode); bool DispatchKeyEvent(int32_t keyCode, int32_t keyStatus); + void SetCallingWindow(uint32_t windowId); int32_t GetEnterKeyType(); int32_t GetInputPattern(); void StopInput(); diff --git a/frameworks/inputmethod_ability/include/input_method_agent_proxy.h b/frameworks/inputmethod_ability/include/input_method_agent_proxy.h index 425b729..568eb0b 100644 --- a/frameworks/inputmethod_ability/include/input_method_agent_proxy.h +++ b/frameworks/inputmethod_ability/include/input_method_agent_proxy.h @@ -31,7 +31,7 @@ namespace MiscServices { void OnCursorUpdate(int32_t positionX, int32_t positionY, int32_t height) override; void OnSelectionChange(std::u16string text, int32_t oldBegin, int32_t oldEnd, int32_t newBegin, int32_t newEnd) override; - + void SetCallingWindow(uint32_t windowId) override; private: static inline BrokerDelegator delegator_; }; diff --git a/frameworks/inputmethod_ability/include/input_method_agent_stub.h b/frameworks/inputmethod_ability/include/input_method_agent_stub.h index b247aab..c8150ab 100644 --- a/frameworks/inputmethod_ability/include/input_method_agent_stub.h +++ b/frameworks/inputmethod_ability/include/input_method_agent_stub.h @@ -36,8 +36,8 @@ namespace MiscServices { void OnCursorUpdate(int32_t positionX, int32_t positionY, int height) override; void OnSelectionChange(std::u16string text, int32_t oldBegin, int32_t oldEnd, int32_t newBegin, int32_t newEnd) override; + void SetCallingWindow(uint32_t windowId) override; void SetMessageHandler(MessageHandler *msgHandler); - private: MessageHandler *msgHandler_; }; diff --git a/frameworks/inputmethod_ability/src/input_method_ability.cpp b/frameworks/inputmethod_ability/src/input_method_ability.cpp index 32fad04..e9ffd73 100644 --- a/frameworks/inputmethod_ability/src/input_method_ability.cpp +++ b/frameworks/inputmethod_ability/src/input_method_ability.cpp @@ -272,7 +272,6 @@ namespace MiscServices { bool InputMethodAbility::DispatchKeyEvent(int32_t keyCode, int32_t keyStatus) { - IMSA_HILOGI("InputMethodAbility::DispatchKeyEvent"); IMSA_HILOGI("InputMethodAbility::DispatchKeyEvent: key = %{public}d, status = %{public}d", keyCode, keyStatus); if (!isBindClient) { IMSA_HILOGI("InputMethodAbility::DispatchKeyEvent abort. no client"); @@ -284,6 +283,19 @@ namespace MiscServices { } return kdListener_->OnKeyEvent(keyCode, keyStatus); } + + void InputMethodAbility::SetCallingWindow(uint32_t windowId) + { + IMSA_HILOGI("InputMethodAbility::SetCallingWindow"); + + if (!imeListener_) { + IMSA_HILOGI("InputMethodAbility::SetCallingWindow imeListener_ is nullptr"); + return; + } + imeListener_->OnSetCallingWindow(windowId); + return; + } + void InputMethodAbility::OnCursorUpdate(Message *msg) { @@ -459,5 +471,6 @@ namespace MiscServices { } inputDataChannel->StopInput(); } + } // namespace MiscServices } // namespace OHOS diff --git a/frameworks/inputmethod_ability/src/input_method_agent_proxy.cpp b/frameworks/inputmethod_ability/src/input_method_agent_proxy.cpp index eecec80..62abd35 100644 --- a/frameworks/inputmethod_ability/src/input_method_agent_proxy.cpp +++ b/frameworks/inputmethod_ability/src/input_method_agent_proxy.cpp @@ -73,5 +73,19 @@ namespace MiscServices { Remote()->SendRequest(ON_SELECTION_CHANGE, data, reply, option); } + + void InputMethodAgentProxy::SetCallingWindow(uint32_t windowId) + { + IMSA_HILOGI("InputMethodAgentProxy::SetCallingWindow"); + MessageParcel data, reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + IMSA_HILOGI("InputMethodAgentProxy::SetCallingWindow descriptor is not match"); + return; + } + + data.WriteInt32(windowId); + Remote()->SendRequest(SET_CALLING_WINDOW_ID, data, reply, option); + } } // namespace MiscServices } // namespace OHOS diff --git a/frameworks/inputmethod_ability/src/input_method_agent_stub.cpp b/frameworks/inputmethod_ability/src/input_method_agent_stub.cpp index 099ae66..e14097c 100644 --- a/frameworks/inputmethod_ability/src/input_method_agent_stub.cpp +++ b/frameworks/inputmethod_ability/src/input_method_agent_stub.cpp @@ -47,6 +47,10 @@ namespace MiscServices { reply.WriteBool(DispatchKeyEvent(*msgParcel)); break; } + case SET_CALLING_WINDOW_ID: { + uint32_t windowId = data.ReadInt32; + SetCallingWindow(windowId); + } case ON_CURSOR_UPDATE: { int32_t positionX = data.ReadInt32(); int32_t positionY = data.ReadInt32(); @@ -81,6 +85,16 @@ namespace MiscServices { return InputMethodAbility::GetInstance()->DispatchKeyEvent(data.ReadInt32(), data.ReadInt32()); } + void InputMethodAgentStub::SetCallingWindow(uint32_t windowId) + { + IMSA_HILOGI("InputMethodAgentStub::SetCallingWindow"); + if (!msgHandler_) { + return false; + } + InputMethodAbility::SetCallingWindow(windowId); + return; + } + void InputMethodAgentStub::OnCursorUpdate(int32_t positionX, int32_t positionY, int height) { IMSA_HILOGI("InputMethodAgentStub::OnCursorUpdate"); diff --git a/frameworks/inputmethod_controller/include/input_method_controller.h b/frameworks/inputmethod_controller/include/input_method_controller.h index 0c80239..ebe06c4 100644 --- a/frameworks/inputmethod_controller/include/input_method_controller.h +++ b/frameworks/inputmethod_controller/include/input_method_controller.h @@ -71,6 +71,7 @@ namespace MiscServices { int32_t GetEnterKeyType(); int32_t GetInputPattern(); void HideCurrentInput(); + void SetCallingWindow(uint32_t windowId); private: InputMethodController(); diff --git a/frameworks/inputmethod_controller/src/input_method_controller.cpp b/frameworks/inputmethod_controller/src/input_method_controller.cpp index 5feec06..ef46d9c 100644 --- a/frameworks/inputmethod_controller/src/input_method_controller.cpp +++ b/frameworks/inputmethod_controller/src/input_method_controller.cpp @@ -420,5 +420,17 @@ using namespace MessageID; IMSA_HILOGI("InputMethodController::GetInputPattern"); return inputPattern_; } + + void InputMethodController::SetCallingWindow(uint32_t windowId) + { + IMSA_HILOGI("InputMethodController::SetCallingWindow windowId = %{public}d", windowId); + if (!mAgent) { + IMSA_HILOGI("InputMethodController::SetCallingWindow mAgent is nullptr"); + return; + } + mAgent->SetCallingWindow(windowId); + return; + } + } // namespace MiscServices } // namespace OHOS diff --git a/interfaces/kits/js/napi/inputmethodengine/include/js_input_method_engine_listener.h b/interfaces/kits/js/napi/inputmethodengine/include/js_input_method_engine_listener.h index d942b4c..e994ae4 100644 --- a/interfaces/kits/js/napi/inputmethodengine/include/js_input_method_engine_listener.h +++ b/interfaces/kits/js/napi/inputmethodengine/include/js_input_method_engine_listener.h @@ -39,6 +39,7 @@ namespace MiscServices { void OnKeyboardStatus(bool isShow); void OnInputStart(); void OnInputStop(std::string imeId); + void OnSetCallingWindow(uint32_t windowId); private: void AddCallback(std::string type, NativeValue* jsListenerObject); diff --git a/interfaces/kits/js/napi/inputmethodengine/src/js_input_method_engine_listener.cpp b/interfaces/kits/js/napi/inputmethodengine/src/js_input_method_engine_listener.cpp index b3f66fd..d79e688 100644 --- a/interfaces/kits/js/napi/inputmethodengine/src/js_input_method_engine_listener.cpp +++ b/interfaces/kits/js/napi/inputmethodengine/src/js_input_method_engine_listener.cpp @@ -198,5 +198,20 @@ namespace MiscServices { }; mainHandler_->PostTask(task); } + + void JsInputMethodEngineListener::OnSetCallingWindow(uint32_t windowId) + { + std::lock_guard lock(mMutex); + IMSA_HILOGI("JsInputMethodEngineListener::OnSetCallingWindow"); + + auto task = [this, windowId] () { + NativeValue* nativeValue = CreateJsValue(*engine_, windowId); + NativeValue* argv[] = { nativeValue }; + std::string methodName = "setCallingWindow"; + CallJsMethod(methodName, argv, ArraySize(argv)); + }; + mainHandler_->PostTask(task); + } + } // namespace MiscServices } // namespace OHOS From 744f97f2cd612ebe3fd1e5794c6434533f44537b Mon Sep 17 00:00:00 2001 From: yadeno Date: Tue, 12 Apr 2022 11:55:27 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8DIMA=E8=B0=83=E7=94=A8bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yadeno --- frameworks/inputmethod_ability/src/input_method_agent_stub.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/inputmethod_ability/src/input_method_agent_stub.cpp b/frameworks/inputmethod_ability/src/input_method_agent_stub.cpp index e14097c..d9bc285 100644 --- a/frameworks/inputmethod_ability/src/input_method_agent_stub.cpp +++ b/frameworks/inputmethod_ability/src/input_method_agent_stub.cpp @@ -91,7 +91,7 @@ namespace MiscServices { if (!msgHandler_) { return false; } - InputMethodAbility::SetCallingWindow(windowId); + InputMethodAbility::GetInstance()->SetCallingWindow(windowId); return; } From 7ff1240555248cf7eaa91b7ef917aeffe4bc504e Mon Sep 17 00:00:00 2001 From: yadeno Date: Tue, 12 Apr 2022 14:26:59 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dcodecheck=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yadeno --- frameworks/inputmethod_ability/src/input_method_ability.cpp | 1 - .../inputmethod_controller/src/input_method_controller.cpp | 1 - .../inputmethodengine/src/js_input_method_engine_listener.cpp | 1 - .../napi/inputmethodengine/src/js_keyboard_delegate_listener.cpp | 1 - 4 files changed, 4 deletions(-) diff --git a/frameworks/inputmethod_ability/src/input_method_ability.cpp b/frameworks/inputmethod_ability/src/input_method_ability.cpp index e9ffd73..0d439bd 100644 --- a/frameworks/inputmethod_ability/src/input_method_ability.cpp +++ b/frameworks/inputmethod_ability/src/input_method_ability.cpp @@ -471,6 +471,5 @@ namespace MiscServices { } inputDataChannel->StopInput(); } - } // namespace MiscServices } // namespace OHOS diff --git a/frameworks/inputmethod_controller/src/input_method_controller.cpp b/frameworks/inputmethod_controller/src/input_method_controller.cpp index ef46d9c..ed07a7d 100644 --- a/frameworks/inputmethod_controller/src/input_method_controller.cpp +++ b/frameworks/inputmethod_controller/src/input_method_controller.cpp @@ -431,6 +431,5 @@ using namespace MessageID; mAgent->SetCallingWindow(windowId); return; } - } // namespace MiscServices } // namespace OHOS diff --git a/interfaces/kits/js/napi/inputmethodengine/src/js_input_method_engine_listener.cpp b/interfaces/kits/js/napi/inputmethodengine/src/js_input_method_engine_listener.cpp index d79e688..bbc1b05 100644 --- a/interfaces/kits/js/napi/inputmethodengine/src/js_input_method_engine_listener.cpp +++ b/interfaces/kits/js/napi/inputmethodengine/src/js_input_method_engine_listener.cpp @@ -212,6 +212,5 @@ namespace MiscServices { }; mainHandler_->PostTask(task); } - } // namespace MiscServices } // namespace OHOS diff --git a/interfaces/kits/js/napi/inputmethodengine/src/js_keyboard_delegate_listener.cpp b/interfaces/kits/js/napi/inputmethodengine/src/js_keyboard_delegate_listener.cpp index decd009..a9cda11 100644 --- a/interfaces/kits/js/napi/inputmethodengine/src/js_keyboard_delegate_listener.cpp +++ b/interfaces/kits/js/napi/inputmethodengine/src/js_keyboard_delegate_listener.cpp @@ -220,7 +220,6 @@ namespace MiscServices { std::string methodName = "textChange"; CallJsMethod(methodName, argv, ArraySize(argv)); }; - mainHandler_->PostTask(task); } } // namespace MiscServices From 36dff3986061151d5ef0996231838d93532bc724 Mon Sep 17 00:00:00 2001 From: yadeno Date: Tue, 12 Apr 2022 15:19:28 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yadeno --- .../inputmethod_ability/src/input_method_agent_proxy.cpp | 2 +- .../inputmethod_ability/src/input_method_agent_stub.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frameworks/inputmethod_ability/src/input_method_agent_proxy.cpp b/frameworks/inputmethod_ability/src/input_method_agent_proxy.cpp index 62abd35..357d2f5 100644 --- a/frameworks/inputmethod_ability/src/input_method_agent_proxy.cpp +++ b/frameworks/inputmethod_ability/src/input_method_agent_proxy.cpp @@ -84,7 +84,7 @@ namespace MiscServices { return; } - data.WriteInt32(windowId); + data.WriteUint32(windowId); Remote()->SendRequest(SET_CALLING_WINDOW_ID, data, reply, option); } } // namespace MiscServices diff --git a/frameworks/inputmethod_ability/src/input_method_agent_stub.cpp b/frameworks/inputmethod_ability/src/input_method_agent_stub.cpp index d9bc285..e3d8f4e 100644 --- a/frameworks/inputmethod_ability/src/input_method_agent_stub.cpp +++ b/frameworks/inputmethod_ability/src/input_method_agent_stub.cpp @@ -48,7 +48,7 @@ namespace MiscServices { break; } case SET_CALLING_WINDOW_ID: { - uint32_t windowId = data.ReadInt32; + uint32_t windowId = data.ReadUint32(); SetCallingWindow(windowId); } case ON_CURSOR_UPDATE: { @@ -89,7 +89,7 @@ namespace MiscServices { { IMSA_HILOGI("InputMethodAgentStub::SetCallingWindow"); if (!msgHandler_) { - return false; + return; } InputMethodAbility::GetInstance()->SetCallingWindow(windowId); return;