diff --git a/frameworks/inputmethod_ability/include/i_input_method_agent.h b/frameworks/inputmethod_ability/include/i_input_method_agent.h index 74d7156..18d578c 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; }; } } diff --git a/frameworks/inputmethod_ability/include/input_method_ability.h b/frameworks/inputmethod_ability/include/input_method_ability.h index 6372251..a25feae 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 967e651..2afab53 100644 --- a/frameworks/inputmethod_ability/include/input_method_agent_proxy.h +++ b/frameworks/inputmethod_ability/include/input_method_agent_proxy.h @@ -31,9 +31,10 @@ 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_; }; } } -#endif // FM_IMC_PROJECT_INPUTMETHODAGENTPROXY_H \ No newline at end of file +#endif // FM_IMC_PROJECT_INPUTMETHODAGENTPROXY_H diff --git a/frameworks/inputmethod_ability/include/input_method_agent_stub.h b/frameworks/inputmethod_ability/include/input_method_agent_stub.h index b5c22f2..5065841 100644 --- a/frameworks/inputmethod_ability/include/input_method_agent_stub.h +++ b/frameworks/inputmethod_ability/include/input_method_agent_stub.h @@ -36,6 +36,7 @@ namespace MiscServices { virtual void OnCursorUpdate(int32_t positionX, int32_t positionY, int height) override; virtual 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 7a26b6b..c3c5721 100644 --- a/frameworks/inputmethod_ability/src/input_method_ability.cpp +++ b/frameworks/inputmethod_ability/src/input_method_ability.cpp @@ -271,7 +271,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"); @@ -283,6 +282,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) { diff --git a/frameworks/inputmethod_ability/src/input_method_agent_proxy.cpp b/frameworks/inputmethod_ability/src/input_method_agent_proxy.cpp index a987337..357d2f5 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.WriteUint32(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 b058415..f5ba22a 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.ReadUint32(); + 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; + } + InputMethodAbility::GetInstance()->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 8acfdfe..246bcd8 100644 --- a/frameworks/inputmethod_controller/include/input_method_controller.h +++ b/frameworks/inputmethod_controller/include/input_method_controller.h @@ -71,6 +71,8 @@ namespace MiscServices { int32_t GetEnterKeyType(); int32_t GetInputPattern(); void HideCurrentInput(); + void SetCallingWindow(uint32_t windowId); + private: InputMethodController(); ~InputMethodController(); @@ -108,4 +110,4 @@ namespace MiscServices { }; } } -#endif \ No newline at end of file +#endif diff --git a/frameworks/inputmethod_controller/src/input_method_controller.cpp b/frameworks/inputmethod_controller/src/input_method_controller.cpp index 8a09e04..17b6467 100644 --- a/frameworks/inputmethod_controller/src/input_method_controller.cpp +++ b/frameworks/inputmethod_controller/src/input_method_controller.cpp @@ -416,5 +416,16 @@ using namespace MessageID; IMSA_HILOGI("InputMethodController::GetInputPattern"); return inputPattern_; } -} -} \ No newline at end of file + + 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 37bc588..5201312 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,8 @@ 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); void CallJsMethod(std::string methodName, NativeValue* const* argv = nullptr, size_t argc = 0); 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 d61a3e7..3a5bce0 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,19 @@ namespace MiscServices { }; mainHandler_->PostTask(task); } -} -} \ No newline at end of file + + 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 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 5427c42..8f1be61 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); } }