diff --git a/frameworks/inputmethod_ability/src/input_method_ability.cpp b/frameworks/inputmethod_ability/src/input_method_ability.cpp index 3545afe..6fff114 100644 --- a/frameworks/inputmethod_ability/src/input_method_ability.cpp +++ b/frameworks/inputmethod_ability/src/input_method_ability.cpp @@ -99,8 +99,8 @@ namespace MiscServices { MessageParcel data; if (!(data.WriteInterfaceToken(mImms->GetDescriptor()) - && data.WriteRemoteObject(stub2->AsObject()) - && data.WriteRemoteObject(inputMethodAgent->AsObject()))) { + && data.WriteRemoteObject(stub2->AsObject()) + && data.WriteRemoteObject(inputMethodAgent->AsObject()))) { return; } mImms->SetCoreAndAgent(data); diff --git a/frameworks/inputmethod_controller/src/input_client_stub.cpp b/frameworks/inputmethod_controller/src/input_client_stub.cpp index 7415d01..40c3552 100644 --- a/frameworks/inputmethod_controller/src/input_client_stub.cpp +++ b/frameworks/inputmethod_controller/src/input_client_stub.cpp @@ -18,7 +18,6 @@ namespace OHOS { namespace MiscServices { -// using namespace Message; InputClientStub::InputClientStub() { } diff --git a/frameworks/inputmethod_controller/src/input_method_controller.cpp b/frameworks/inputmethod_controller/src/input_method_controller.cpp index 929082f..c477697 100644 --- a/frameworks/inputmethod_controller/src/input_method_controller.cpp +++ b/frameworks/inputmethod_controller/src/input_method_controller.cpp @@ -41,7 +41,6 @@ using namespace MessageID; sptr InputMethodController::GetInstance() { - IMSA_HILOGI("InputMethodController::GetInstance"); if (instance_ == nullptr) { std::lock_guard autoLock(instanceLock_); if (instance_ == nullptr) { @@ -296,7 +295,7 @@ using namespace MessageID; return; } - if(cursorInfo_.left == cursorInfo.left && cursorInfo_.top == cursorInfo.top && cursorInfo_.height == cursorInfo.height){ + if (cursorInfo_.left == cursorInfo.left && cursorInfo_.top == cursorInfo.top && cursorInfo_.height == cursorInfo.height) { return; } cursorInfo_ = cursorInfo; @@ -305,10 +304,10 @@ using namespace MessageID; void InputMethodController::OnSelectionChange(std::u16string text, int start, int end) { - IMSA_HILOGI("InputMethodController::OnSelectionChange"); if (mTextString == text && mSelectNewBegin == start && mSelectNewEnd == end) { return; } + IMSA_HILOGI("InputMethodController::OnSelectionChange"); mTextString = text; mSelectOldBegin = mSelectNewBegin; mSelectOldEnd = mSelectNewEnd; diff --git a/interfaces/kits/js/napi/include/js_input_method_engine_listener.h b/interfaces/kits/js/napi/include/js_input_method_engine_listener.h index d7f5c79..d7bff00 100644 --- a/interfaces/kits/js/napi/include/js_input_method_engine_listener.h +++ b/interfaces/kits/js/napi/include/js_input_method_engine_listener.h @@ -20,9 +20,9 @@ #include #include #include +#include #include "native_engine/native_engine.h" #include "native_engine/native_value.h" -#include namespace OHOS { namespace MiscServices { class JsInputMethodEngineListener : virtual public RefBase { diff --git a/interfaces/kits/js/napi/src/js_input_method_engine.cpp b/interfaces/kits/js/napi/src/js_input_method_engine.cpp index a2a4edc..efaed8a 100644 --- a/interfaces/kits/js/napi/src/js_input_method_engine.cpp +++ b/interfaces/kits/js/napi/src/js_input_method_engine.cpp @@ -14,9 +14,9 @@ */ #include "js_input_method_engine.h" +#include #include "js_input_method_engine_listener.h" #include "input_method_ability.h" -#include #include "napi/native_api.h" #include "napi/native_node_api.h" #include "string_ex.h" @@ -29,290 +29,291 @@ namespace MiscServices { constexpr size_t ARGC_ONE = 1; constexpr size_t ARGC_TWO = 2; } -class JsInputMethodEngine{ -public: - sptr imeListener_; - explicit JsInputMethodEngine(NativeEngine* engine) { - IMSA_HILOGI("JsInputMethodEngine::Constructor is called"); - imeListener_ = new JsInputMethodEngineListener(engine); - InputMethodAbility::GetInstance()->setImeListener(imeListener_); - } + class JsInputMethodEngine { + public: + sptr imeListener_; + explicit JsInputMethodEngine(NativeEngine* engine) + { + IMSA_HILOGI("JsInputMethodEngine::Constructor is called"); + imeListener_ = new JsInputMethodEngineListener(engine); + InputMethodAbility::GetInstance()->setImeListener(imeListener_); + } - ~JsInputMethodEngine() = default; + ~JsInputMethodEngine() = default; - static void Finalizer(NativeEngine* engine, void* data, void* hint) - { - IMSA_HILOGI("JsInputMethodEngine::Finalizer is called"); - std::unique_ptr(static_cast(data)); - } + static void Finalizer(NativeEngine* engine, void* data, void* hint) + { + IMSA_HILOGI("JsInputMethodEngine::Finalizer is called"); + std::unique_ptr(static_cast(data)); + } - static NativeValue* InsertText(NativeEngine* engine, NativeCallbackInfo* info) - { - JsInputMethodEngine* me = AbilityRuntime::CheckParamsAndGetThis(engine, info); - return (me != nullptr) ? me->OnInsertText(*engine, *info) : nullptr; - } + static NativeValue* InsertText(NativeEngine* engine, NativeCallbackInfo* info) + { + JsInputMethodEngine* me = AbilityRuntime::CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnInsertText(*engine, *info) : nullptr; + } - static NativeValue* DeleteForward(NativeEngine* engine, NativeCallbackInfo* info) - { - JsInputMethodEngine* me = AbilityRuntime::CheckParamsAndGetThis(engine, info); - return (me != nullptr) ? me->OnDeleteForward(*engine, *info) : nullptr; - } + static NativeValue* DeleteForward(NativeEngine* engine, NativeCallbackInfo* info) + { + JsInputMethodEngine* me = AbilityRuntime::CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnDeleteForward(*engine, *info) : nullptr; + } - static NativeValue* DeleteBackward(NativeEngine* engine, NativeCallbackInfo* info) - { - JsInputMethodEngine* me = AbilityRuntime::CheckParamsAndGetThis(engine, info); - return (me != nullptr) ? me->OnDeleteBackward(*engine, *info) : nullptr; - } + static NativeValue* DeleteBackward(NativeEngine* engine, NativeCallbackInfo* info) + { + JsInputMethodEngine* me = AbilityRuntime::CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnDeleteBackward(*engine, *info) : nullptr; + } - static NativeValue* MoveCursor(NativeEngine* engine, NativeCallbackInfo* info) - { - JsInputMethodEngine* me = AbilityRuntime::CheckParamsAndGetThis(engine, info); - return (me != nullptr) ? me->OnMoveCursor(*engine, *info) : nullptr; - } + static NativeValue* MoveCursor(NativeEngine* engine, NativeCallbackInfo* info) + { + JsInputMethodEngine* me = AbilityRuntime::CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnMoveCursor(*engine, *info) : nullptr; + } - static NativeValue* HideKeyboardSelf(NativeEngine* engine, NativeCallbackInfo* info) - { - JsInputMethodEngine* me = AbilityRuntime::CheckParamsAndGetThis(engine, info); - return (me != nullptr) ? me->OnHideKeyboardSelf(*engine, *info) : nullptr; - } + static NativeValue* HideKeyboardSelf(NativeEngine* engine, NativeCallbackInfo* info) + { + JsInputMethodEngine* me = AbilityRuntime::CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnHideKeyboardSelf(*engine, *info) : nullptr; + } - static NativeValue* GetTextBeforeCursor(NativeEngine* engine, NativeCallbackInfo* info) - { - JsInputMethodEngine* me = AbilityRuntime::CheckParamsAndGetThis(engine, info); - return (me != nullptr) ? me->OnGetTextBeforeCursor(*engine, *info) : nullptr; - } + static NativeValue* GetTextBeforeCursor(NativeEngine* engine, NativeCallbackInfo* info) + { + JsInputMethodEngine* me = AbilityRuntime::CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnGetTextBeforeCursor(*engine, *info) : nullptr; + } - static NativeValue* GetTextAfterCursor(NativeEngine* engine, NativeCallbackInfo* info) - { - JsInputMethodEngine* me = AbilityRuntime::CheckParamsAndGetThis(engine, info); - return (me != nullptr) ? me->OnGetTextAfterCursor(*engine, *info) : nullptr; - } + static NativeValue* GetTextAfterCursor(NativeEngine* engine, NativeCallbackInfo* info) + { + JsInputMethodEngine* me = AbilityRuntime::CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnGetTextAfterCursor(*engine, *info) : nullptr; + } - static NativeValue* SendFunctionKey(NativeEngine* engine, NativeCallbackInfo* info) - { - JsInputMethodEngine* me = AbilityRuntime::CheckParamsAndGetThis(engine, info); - return (me != nullptr) ? me->OnSendFunctionKey(*engine, *info) : nullptr; - } + static NativeValue* SendFunctionKey(NativeEngine* engine, NativeCallbackInfo* info) + { + JsInputMethodEngine* me = AbilityRuntime::CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnSendFunctionKey(*engine, *info) : nullptr; + } - static NativeValue* RegisterCallback(NativeEngine* engine, NativeCallbackInfo* info) - { - JsInputMethodEngine* me = AbilityRuntime::CheckParamsAndGetThis(engine, info); - return (me != nullptr) ? me->OnRegisterCallback(*engine, *info) : nullptr; - } + static NativeValue* RegisterCallback(NativeEngine* engine, NativeCallbackInfo* info) + { + JsInputMethodEngine* me = AbilityRuntime::CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnRegisterCallback(*engine, *info) : nullptr; + } - static NativeValue* UnRegisterCallback(NativeEngine* engine, NativeCallbackInfo* info) - { - JsInputMethodEngine* me = AbilityRuntime::CheckParamsAndGetThis(engine, info); - return (me != nullptr) ? me->OnUnRegisterCallback(*engine, *info) : nullptr; - } + static NativeValue* UnRegisterCallback(NativeEngine* engine, NativeCallbackInfo* info) + { + JsInputMethodEngine* me = AbilityRuntime::CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnUnRegisterCallback(*engine, *info) : nullptr; + } -private: - std::mutex mtx_; + private: + std::mutex mtx_; + + NativeValue* OnInsertText(NativeEngine& engine, NativeCallbackInfo& info) + { + IMSA_HILOGI("JsInputMethodEngine::OnInsertText is called!"); + if (info.argc < ARGC_ONE) { + IMSA_HILOGI("JsInputMethodEngine::OnInsertText has no params!"); + return engine.CreateUndefined(); + } + + NativeValue* nativeString = nullptr; + nativeString = info.argv[ARGC_ZERO]; + + std::string textString; + if (!AbilityRuntime::ConvertFromJsValue(engine, nativeString, textString)) { + IMSA_HILOGI("JsInputMethodEngine::OnInsertText Failed to convert parameter to string"); + return engine.CreateUndefined(); + } + + bool ret = InputMethodAbility::GetInstance()->InsertText(textString); + + NativeValue* result = AbilityRuntime::CreateJsValue(engine, ret); + + return result; + } + + NativeValue* OnDeleteForward(NativeEngine& engine, NativeCallbackInfo& info) + { + IMSA_HILOGI("JsInputMethodEngine::OnDeleteForward is called!"); + if (info.argc < ARGC_ONE) { + IMSA_HILOGI("JsInputMethodEngine::OnDeleteForward has no params!"); + return engine.CreateUndefined(); + } + + NativeValue* nativeString = nullptr; + nativeString = info.argv[ARGC_ZERO]; + + int32_t number; + if(!AbilityRuntime::ConvertFromJsValue(engine, nativeString, number)) { + IMSA_HILOGI("JsInputMethodEngine::OnDeleteForward Failed to convert parameter to string"); + return engine.CreateUndefined(); + } + + InputMethodAbility::GetInstance()->DeleteForward(number); + + NativeValue* result = AbilityRuntime::CreateJsValue(engine, true); + + return result; + } + + NativeValue* OnDeleteBackward(NativeEngine& engine, NativeCallbackInfo& info) + { + IMSA_HILOGI("JsInputMethodEngine::OnDeleteBackward is called!"); + if (info.argc < ARGC_ONE) { + IMSA_HILOGI("JsInputMethodEngine::OnDeleteBackward has no params!"); + return engine.CreateUndefined(); + } + + NativeValue* nativeString = nullptr; + nativeString = info.argv[ARGC_ZERO]; + + int32_t number; + if (!AbilityRuntime::ConvertFromJsValue(engine, nativeString, number)) { + IMSA_HILOGI("JsInputMethodEngine::OnDeleteBackward Failed to convert parameter to string"); + return engine.CreateUndefined(); + } + + InputMethodAbility::GetInstance()->DeleteBackward(number); + + NativeValue* result = AbilityRuntime::CreateJsValue(engine, true); + + return result; + } + + NativeValue* OnMoveCursor(NativeEngine& engine, NativeCallbackInfo& info) + { + IMSA_HILOGI("JsInputMethodEngine::OnMoveCursor is called!"); + if (info.argc < ARGC_ONE) { + IMSA_HILOGI("JsInputMethodEngine::OnMoveCursor has no params!"); + return engine.CreateUndefined(); + } + + NativeValue* nativeString = nullptr; + nativeString = info.argv[ARGC_ZERO]; + + int32_t number; + if (!AbilityRuntime::ConvertFromJsValue(engine, nativeString, number)) { + IMSA_HILOGI("JsInputMethodEngine::OnMoveCursor Failed to convert parameter to string"); + return engine.CreateUndefined(); + } + + InputMethodAbility::GetInstance()->MoveCursor(number); + + NativeValue* result = AbilityRuntime::CreateJsValue(engine, true); + + return result; + } + + NativeValue* OnHideKeyboardSelf(NativeEngine& engine, NativeCallbackInfo& info) + { + IMSA_HILOGI("JsInputMethodEngine::OnHideKeyboardSelf is called!"); + if (info.argc != ARGC_ZERO) { + IMSA_HILOGI("JsInputMethodEngine::OnHideKeyboardSelf has params, return!"); + return engine.CreateUndefined(); + } + + InputMethodAbility::GetInstance()->HideKeyboardSelf(); - NativeValue* OnInsertText(NativeEngine& engine, NativeCallbackInfo& info) - { - IMSA_HILOGI("JsInputMethodEngine::OnInsertText is called!"); - if (info.argc < ARGC_ONE) { - IMSA_HILOGI("JsInputMethodEngine::OnInsertText has no params!"); return engine.CreateUndefined(); } - NativeValue* nativeString = nullptr; - nativeString = info.argv[ARGC_ZERO]; + NativeValue* OnGetTextBeforeCursor(NativeEngine& engine, NativeCallbackInfo& info) + { + IMSA_HILOGI("JsInputMethodEngine::OnGetTextBeforeCursor is called!"); + if (info.argc != ARGC_ZERO) { + IMSA_HILOGI("JsInputMethodEngine::OnGetTextBeforeCursor has params, return!"); + return engine.CreateUndefined(); + } + + std::string ret = Str16ToStr8(InputMethodAbility::GetInstance()->GetTextBeforeCursor()); + + NativeValue* result = AbilityRuntime::CreateJsValue(engine, ret); + + return result; + } + + NativeValue* OnGetTextAfterCursor(NativeEngine& engine, NativeCallbackInfo& info) + { + IMSA_HILOGI("JsInputMethodEngine::OnGetTextAfterCursor is called!"); + if (info.argc != ARGC_ZERO) { + IMSA_HILOGI("JsInputMethodEngine::OnGetTextAfterCursor has params, return!"); + return engine.CreateUndefined(); + } + + std::string ret = Str16ToStr8(InputMethodAbility::GetInstance()->GetTextAfterCursor()); + + NativeValue* result = AbilityRuntime::CreateJsValue(engine, ret); + + return result; + } + + NativeValue* OnSendFunctionKey(NativeEngine& engine, NativeCallbackInfo& info) + { + IMSA_HILOGI("JsInputMethodEngine::OnSendFunctionKey is called!"); + if (info.argc < ARGC_ONE) { + IMSA_HILOGI("JsInputMethodEngine::OnSendFunctionKey has no params!"); + return engine.CreateUndefined(); + } + + NativeValue* nativeString = nullptr; + nativeString = info.argv[ARGC_ZERO]; + + int32_t number; + if (!AbilityRuntime::ConvertFromJsValue(engine, nativeString, number)) { + IMSA_HILOGI("JsInputMethodEngine::OnSendFunctionKey Failed to convert parameter to string"); + return engine.CreateUndefined(); + } + + InputMethodAbility::GetInstance()->SendFunctionKey(number); - std::string textString; - if(!AbilityRuntime::ConvertFromJsValue(engine, nativeString, textString)) { - IMSA_HILOGI("JsInputMethodEngine::OnInsertText Failed to convert parameter to string"); return engine.CreateUndefined(); } - bool ret = InputMethodAbility::GetInstance()->InsertText(textString); + NativeValue* OnRegisterCallback(NativeEngine& engine, NativeCallbackInfo& info) + { + IMSA_HILOGI("JsInputMethodEngine::OnRegisterCallback is called!"); + if (info.argc != ARGC_TWO) { + IMSA_HILOGI("JsInputMethodEngine::OnRegisterCallback Params not match"); + return engine.CreateUndefined(); + } - NativeValue* result = AbilityRuntime::CreateJsValue(engine, ret); + std::string cbType; + if (!AbilityRuntime::ConvertFromJsValue(engine, info.argv[0], cbType)) { + IMSA_HILOGI("JsInputMethodEngine::OnRegisterCallback Failed to convert parameter to callbackType"); + return engine.CreateUndefined(); + } - return result; - } - - NativeValue* OnDeleteForward(NativeEngine& engine, NativeCallbackInfo& info) - { - IMSA_HILOGI("JsInputMethodEngine::OnDeleteForward is called!"); - if (info.argc < ARGC_ONE) { - IMSA_HILOGI("JsInputMethodEngine::OnDeleteForward has no params!"); + NativeValue* value = info.argv[1]; + imeListener_->RegisterListenerWithType(engine, cbType, value); return engine.CreateUndefined(); } - NativeValue* nativeString = nullptr; - nativeString = info.argv[ARGC_ZERO]; + NativeValue* OnUnRegisterCallback(NativeEngine& engine, NativeCallbackInfo& info) + { + IMSA_HILOGI("JsInputMethodEngine::OnUnRegisterCallback is called!"); + if (info.argc == 0) { + IMSA_HILOGI("JsInputMethodEngine::OnUnRegisterCallback Params not match"); + return engine.CreateUndefined(); + } - int32_t number; - if(!AbilityRuntime::ConvertFromJsValue(engine, nativeString, number)) { - IMSA_HILOGI("JsInputMethodEngine::OnDeleteForward Failed to convert parameter to string"); + std::string cbType; + if (!AbilityRuntime::ConvertFromJsValue(engine, info.argv[0], cbType)) { + IMSA_HILOGI("JsInputMethodEngine::OnUnRegisterCallback Failed to convert parameter to callbackType"); + return engine.CreateUndefined(); + } + + std::lock_guard lock(mtx_); + NativeValue* value = info.argv[1]; + if (!value->IsCallable()) { + IMSA_HILOGI("JsInputMethodEngine::OnUnregisterWindowManagerCallback info->argv[1] is not callable"); + return engine.CreateUndefined(); + } + imeListener_->UnregisterListenerWithType(cbType, value); return engine.CreateUndefined(); } - - InputMethodAbility::GetInstance()->DeleteForward(number); - - NativeValue* result = AbilityRuntime::CreateJsValue(engine, true); - - return result; - } - - NativeValue* OnDeleteBackward(NativeEngine& engine, NativeCallbackInfo& info) - { - IMSA_HILOGI("JsInputMethodEngine::OnDeleteBackward is called!"); - if (info.argc < ARGC_ONE) { - IMSA_HILOGI("JsInputMethodEngine::OnDeleteBackward has no params!"); - return engine.CreateUndefined(); - } - - NativeValue* nativeString = nullptr; - nativeString = info.argv[ARGC_ZERO]; - - int32_t number; - if(!AbilityRuntime::ConvertFromJsValue(engine, nativeString, number)) { - IMSA_HILOGI("JsInputMethodEngine::OnDeleteBackward Failed to convert parameter to string"); - return engine.CreateUndefined(); - } - - InputMethodAbility::GetInstance()->DeleteBackward(number); - - NativeValue* result = AbilityRuntime::CreateJsValue(engine, true); - - return result; - } - - NativeValue* OnMoveCursor(NativeEngine& engine, NativeCallbackInfo& info) - { - IMSA_HILOGI("JsInputMethodEngine::OnMoveCursor is called!"); - if (info.argc < ARGC_ONE) { - IMSA_HILOGI("JsInputMethodEngine::OnMoveCursor has no params!"); - return engine.CreateUndefined(); - } - - NativeValue* nativeString = nullptr; - nativeString = info.argv[ARGC_ZERO]; - - int32_t number; - if(!AbilityRuntime::ConvertFromJsValue(engine, nativeString, number)) { - IMSA_HILOGI("JsInputMethodEngine::OnMoveCursor Failed to convert parameter to string"); - return engine.CreateUndefined(); - } - - InputMethodAbility::GetInstance()->MoveCursor(number); - - NativeValue* result = AbilityRuntime::CreateJsValue(engine, true); - - return result; - } - - NativeValue* OnHideKeyboardSelf(NativeEngine& engine, NativeCallbackInfo& info) - { - IMSA_HILOGI("JsInputMethodEngine::OnHideKeyboardSelf is called!"); - if (info.argc != ARGC_ZERO) { - IMSA_HILOGI("JsInputMethodEngine::OnHideKeyboardSelf has params, return!"); - return engine.CreateUndefined(); - } - - InputMethodAbility::GetInstance()->HideKeyboardSelf(); - - return engine.CreateUndefined(); - } - - NativeValue* OnGetTextBeforeCursor(NativeEngine& engine, NativeCallbackInfo& info) - { - IMSA_HILOGI("JsInputMethodEngine::OnGetTextBeforeCursor is called!"); - if (info.argc != ARGC_ZERO) { - IMSA_HILOGI("JsInputMethodEngine::OnGetTextBeforeCursor has params, return!"); - return engine.CreateUndefined(); - } - - std::string ret = Str16ToStr8(InputMethodAbility::GetInstance()->GetTextBeforeCursor()); - - NativeValue* result = AbilityRuntime::CreateJsValue(engine, ret); - - return result; - } - - NativeValue* OnGetTextAfterCursor(NativeEngine& engine, NativeCallbackInfo& info) - { - IMSA_HILOGI("JsInputMethodEngine::OnGetTextAfterCursor is called!"); - if (info.argc != ARGC_ZERO) { - IMSA_HILOGI("JsInputMethodEngine::OnGetTextAfterCursor has params, return!"); - return engine.CreateUndefined(); - } - - std::string ret = Str16ToStr8(InputMethodAbility::GetInstance()->GetTextAfterCursor()); - - NativeValue* result = AbilityRuntime::CreateJsValue(engine, ret); - - return result; - } - - NativeValue* OnSendFunctionKey(NativeEngine& engine, NativeCallbackInfo& info) - { - IMSA_HILOGI("JsInputMethodEngine::OnSendFunctionKey is called!"); - if (info.argc < ARGC_ONE) { - IMSA_HILOGI("JsInputMethodEngine::OnSendFunctionKey has no params!"); - return engine.CreateUndefined(); - } - - NativeValue* nativeString = nullptr; - nativeString = info.argv[ARGC_ZERO]; - - int32_t number; - if(!AbilityRuntime::ConvertFromJsValue(engine, nativeString, number)) { - IMSA_HILOGI("JsInputMethodEngine::OnSendFunctionKey Failed to convert parameter to string"); - return engine.CreateUndefined(); - } - - InputMethodAbility::GetInstance()->SendFunctionKey(number); - - return engine.CreateUndefined(); - } - - NativeValue* OnRegisterCallback(NativeEngine& engine, NativeCallbackInfo& info) - { - IMSA_HILOGI("JsInputMethodEngine::OnRegisterCallback is called!"); - if (info.argc != ARGC_TWO) { - IMSA_HILOGI("JsInputMethodEngine::OnRegisterCallback Params not match"); - return engine.CreateUndefined(); - } - - std::string cbType; - if (!AbilityRuntime::ConvertFromJsValue(engine, info.argv[0], cbType)) { - IMSA_HILOGI("JsInputMethodEngine::OnRegisterCallback Failed to convert parameter to callbackType"); - return engine.CreateUndefined(); - } - - NativeValue* value = info.argv[1]; - imeListener_->RegisterListenerWithType(engine, cbType, value); - return engine.CreateUndefined(); - } - - NativeValue* OnUnRegisterCallback(NativeEngine& engine, NativeCallbackInfo& info) - { - IMSA_HILOGI("JsInputMethodEngine::OnUnRegisterCallback is called!"); - if (info.argc == 0) { - IMSA_HILOGI("JsInputMethodEngine::OnUnRegisterCallback Params not match"); - return engine.CreateUndefined(); - } - - std::string cbType; - if (!AbilityRuntime::ConvertFromJsValue(engine, info.argv[0], cbType)) { - IMSA_HILOGI("JsInputMethodEngine::OnUnRegisterCallback Failed to convert parameter to callbackType"); - return engine.CreateUndefined(); - } - - std::lock_guard lock(mtx_); - NativeValue* value = info.argv[1]; - if (!value->IsCallable()) { - IMSA_HILOGI("JsInputMethodEngine::OnUnregisterWindowManagerCallback info->argv[1] is not callable"); - return engine.CreateUndefined(); - } - imeListener_->UnregisterListenerWithType(cbType, value); - return engine.CreateUndefined(); - } -}; + }; NativeValue* JsInputMethodEngineInit(NativeEngine* engine, NativeValue* exportObj) { @@ -337,7 +338,8 @@ NativeValue* JsInputMethodEngineInit(NativeEngine* engine, NativeValue* exportOb AbilityRuntime::BindNativeFunction(*engine, *object, "DeleteBackward", JsInputMethodEngine::DeleteBackward); AbilityRuntime::BindNativeFunction(*engine, *object, "MoveCursor", JsInputMethodEngine::MoveCursor); AbilityRuntime::BindNativeFunction(*engine, *object, "HideKeyboardSelf", JsInputMethodEngine::HideKeyboardSelf); - AbilityRuntime::BindNativeFunction(*engine, *object, "GetTextBeforeCursor", JsInputMethodEngine::GetTextBeforeCursor); + AbilityRuntime::BindNativeFunction(*engine, *object, "GetTextBeforeCursor", + JsInputMethodEngine::GetTextBeforeCursor); AbilityRuntime::BindNativeFunction(*engine, *object, "GetTextAfterCursor", JsInputMethodEngine::GetTextAfterCursor); AbilityRuntime::BindNativeFunction(*engine, *object, "SendFunctionKey", JsInputMethodEngine::SendFunctionKey); diff --git a/interfaces/kits/js/napi/src/js_input_method_engine_listener.cpp b/interfaces/kits/js/napi/src/js_input_method_engine_listener.cpp index 238be37..71dec2b 100644 --- a/interfaces/kits/js/napi/src/js_input_method_engine_listener.cpp +++ b/interfaces/kits/js/napi/src/js_input_method_engine_listener.cpp @@ -38,17 +38,18 @@ namespace MiscServices { std::unique_ptr callbackRef; callbackRef.reset(engine_->CreateReference(jsListenerObject, 1)); jsCbMap_[type].push_back(std::move(callbackRef)); - IMSA_HILOGI("JsInputMethodEngineListener::AddCallback success jsCbMap_ size: %{public}d, and type[%{public}s] size: %{public}d!", + IMSA_HILOGI("JsInputMethodEngineListener::AddCallback success"); + IMSA_HILOGI("jsCbMap_ size: %{public}d, and type[%{public}s] size: %{public}d!", static_cast(jsCbMap_.size()), type.c_str(), static_cast(jsCbMap_[type].size())); return; } void JsInputMethodEngineListener::UnregisterListenerWithType(std::string type, NativeValue* value) { + IMSA_HILOGI("JsInputMethodEngineListener::UnregisterListenerWithType"); // should do type check if (jsCbMap_.empty() || jsCbMap_.find(type) == jsCbMap_.end()) { - IMSA_HILOGI("JsInputMethodEngineListener::UnregisterListenerWithType methodName %{public}s not registerted!", - type.c_str()); + IMSA_HILOGI("methodName %{public}s not registerted!", type.c_str()); return; } for (auto it = jsCbMap_[type].begin(); it != jsCbMap_[type].end();) { @@ -66,8 +67,9 @@ namespace MiscServices { bool JsInputMethodEngineListener::IfCallbackRegistered(std::string type, NativeValue* jsListenerObject) { + IMSA_HILOGI("JsInputMethodEngineListener::IfCallbackRegistered"); if (jsCbMap_.empty() || jsCbMap_.find(type) == jsCbMap_.end()) { - IMSA_HILOGI("JsInputMethodEngineListener::IfCallbackRegistered methodName %{public}s not registertd!", type.c_str()); + IMSA_HILOGI("methodName %{public}s not registertd!", type.c_str()); return false; } @@ -89,7 +91,7 @@ namespace MiscServices { } if (jsCbMap_.empty() || jsCbMap_.find(methodName) == jsCbMap_.end()) { - IMSA_HILOGI("JsInputMethodEngineListener::CallJsMethod methodName %{public}s not registertd!", methodName.c_str()); + IMSA_HILOGI("methodName %{public}s not registertd!", methodName.c_str()); return; } @@ -98,7 +100,8 @@ namespace MiscServices { } } - bool JsInputMethodEngineListener::CallJsMethodReturnBool(std::string methodName, NativeValue* const* argv, size_t argc) + bool JsInputMethodEngineListener::CallJsMethodReturnBool(std::string methodName, + NativeValue* const* argv, size_t argc) { IMSA_HILOGI("JsInputMethodEngineListener::CallJsMethodReturnBool"); if (engine_ == nullptr) { @@ -107,7 +110,7 @@ namespace MiscServices { } if (jsCbMap_.empty() || jsCbMap_.find(methodName) == jsCbMap_.end()) { - IMSA_HILOGI("JsInputMethodEngineListener::CallJsMethodReturnBool methodName %{public}s not registertd!", methodName.c_str()); + IMSA_HILOGI("methodName %{public}s not registertd!", methodName.c_str()); return false; } @@ -200,7 +203,8 @@ namespace MiscServices { CallJsMethod(methodName, argv, AbilityRuntime::ArraySize(argv)); } - void JsInputMethodEngineListener::OnSelectionChange(int32_t oldBegin, int32_t oldEnd, int32_t newBegin, int32_t newEnd) + void JsInputMethodEngineListener::OnSelectionChange(int32_t oldBegin, int32_t oldEnd, + int32_t newBegin, int32_t newEnd) { std::lock_guard lock(mMutex); IMSA_HILOGI("JsInputMethodEngineListener::OnSelectionChange"); diff --git a/services/BUILD.gn b/services/BUILD.gn index 963c9de..675ba62 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -51,8 +51,8 @@ ohos_shared_library("inputmethod_service") { public_configs = [ ":inputmethod_services_native_config" ] deps = [ - "//base/miscservices/inputmethod/frameworks/inputmethod_ability:inputmethod_ability", "//base/global/resmgr_standard/frameworks/resmgr:global_resmgr", + "//base/miscservices/inputmethod/frameworks/inputmethod_ability:inputmethod_ability", "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", "//foundation/aafwk/standard/interfaces/innerkits/app_manager:app_manager", "//foundation/aafwk/standard/interfaces/innerkits/base:base", diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index e9b61af..51491dc 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -59,7 +59,7 @@ namespace MiscServices { } std::map::const_iterator it; - for (it = userSessions.cbegin(); it != userSessions.cend(); ) { + for (it = userSessions.cbegin(); it != userSessions.cend();) { PerUserSession *session = it->second; it = userSessions.erase(it); delete session; @@ -67,7 +67,7 @@ namespace MiscServices { } userSessions.clear(); std::map::const_iterator it1; - for (it1 = userSettings.cbegin(); it1 != userSettings.cend(); ) { + for (it1 = userSettings.cbegin(); it1 != userSettings.cend();) { PerUserSetting *setting = it1->second; it1 = userSettings.erase(it1); delete setting; @@ -75,7 +75,7 @@ namespace MiscServices { } userSettings.clear(); std::map::const_iterator it2; - for (it2 = msgHandlers.cbegin(); it2 != msgHandlers.cend(); ) { + for (it2 = msgHandlers.cbegin(); it2 != msgHandlers.cend();) { MessageHandler *handler = it2->second; it2 = msgHandlers.erase(it2); delete handler; diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index be5141a..dfc9ad6 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -1189,7 +1189,8 @@ namespace MiscServices { SendAgentToSingleClient(client); } - void PerUserSession::SendAgentToSingleClient(const sptr& inputClient) { + void PerUserSession::SendAgentToSingleClient(const sptr& inputClient) + { IMSA_HILOGI("PerUserSession::SendAgentToSingleClient"); if (imsAgent == nullptr) { IMSA_HILOGI("PerUserSession::SendAgentToSingleClient imsAgent is nullptr"); @@ -1260,16 +1261,18 @@ namespace MiscServices { SendAgentToAllClients(); } - void PerUserSession::SendAgentToAllClients() { + void PerUserSession::SendAgentToAllClients() + { IMSA_HILOGI("PerUserSession::SendAgentToAllClients"); if (imsAgent == nullptr) { IMSA_HILOGI("PerUserSession::SendAgentToAllClients imsAgent is nullptr"); return; } - for (std::map, ClientInfo*>::iterator it = mapClients.begin(); it != mapClients.end(); it++) { + for (std::map, ClientInfo*>::iterator it = mapClients.begin(); + it != mapClients.end(); ++it) { ClientInfo *clientInfo = (ClientInfo*) it->second; - if(clientInfo != nullptr) { + if (clientInfo != nullptr) { clientInfo->client->onInputReady(imsAgent); } } diff --git a/unitest/src/input_method_ability_test.cpp b/unitest/src/input_method_ability_test.cpp index c7e665d..7e5fff1 100644 --- a/unitest/src/input_method_ability_test.cpp +++ b/unitest/src/input_method_ability_test.cpp @@ -106,17 +106,6 @@ namespace MiscServices { EXPECT_TRUE(iface != nullptr); } - /** - * @tc.name: testGetInputMethodAbilityInstance - * @tc.desc: Checkout the function of getInstance. - * @tc.type: FUNC - */ - HWTEST_F(InputMethodAbilityTest, testGetInputMethodAbilityInstance, TestSize.Level0) - { - auto ima = InputMethodAbility::GetInstance(); - EXPECT_TRUE(ima != nullptr); - } - /** * @tc.name: testSerializedInputAttribute * @tc.desc: Checkout the serialization of InputAttribute.