diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 29fbb94b..00000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,70 +0,0 @@ -{ - "files.associations": { - "algorithm": "cpp", - "array": "cpp", - "atomic": "cpp", - "bit": "cpp", - "*.tcc": "cpp", - "bitset": "cpp", - "cctype": "cpp", - "chrono": "cpp", - "cinttypes": "cpp", - "clocale": "cpp", - "cmath": "cpp", - "codecvt": "cpp", - "compare": "cpp", - "concepts": "cpp", - "condition_variable": "cpp", - "csignal": "cpp", - "cstdarg": "cpp", - "cstddef": "cpp", - "cstdint": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "cstring": "cpp", - "ctime": "cpp", - "cwchar": "cpp", - "cwctype": "cpp", - "deque": "cpp", - "list": "cpp", - "map": "cpp", - "set": "cpp", - "string": "cpp", - "unordered_map": "cpp", - "unordered_set": "cpp", - "vector": "cpp", - "exception": "cpp", - "functional": "cpp", - "iterator": "cpp", - "memory": "cpp", - "memory_resource": "cpp", - "numeric": "cpp", - "optional": "cpp", - "random": "cpp", - "ratio": "cpp", - "regex": "cpp", - "string_view": "cpp", - "system_error": "cpp", - "tuple": "cpp", - "type_traits": "cpp", - "utility": "cpp", - "fstream": "cpp", - "initializer_list": "cpp", - "iosfwd": "cpp", - "istream": "cpp", - "limits": "cpp", - "mutex": "cpp", - "new": "cpp", - "numbers": "cpp", - "ostream": "cpp", - "ranges": "cpp", - "semaphore": "cpp", - "sstream": "cpp", - "stdexcept": "cpp", - "stop_token": "cpp", - "streambuf": "cpp", - "thread": "cpp", - "typeinfo": "cpp", - "variant": "cpp" - } -} \ No newline at end of file diff --git a/BUILD.gn b/BUILD.gn index 5c7b0796..8b35a409 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -21,11 +21,11 @@ group("imf_packages") { "etc/init:inputmethodservice.cfg", "etc/para:inputmethod.para", "etc/para:inputmethod_para", + "frameworks/cj:cj_inputmethod_ffi", "frameworks/js/napi/inputmethodability:inputmethodengine", "frameworks/js/napi/inputmethodclient:inputmethod", "frameworks/js/napi/inputmethodlist:inputmethodlist", "frameworks/js/napi/keyboardpanelmanager:keyboardpanelmanager", - "frameworks/cj:cj_inputmethod_ffi", "interfaces/inner_api/inputmethod_ability:inputmethod_ability", "interfaces/inner_api/inputmethod_controller:inputmethod_client", "profile:inputmethod_inputmethod_sa_profiles", diff --git a/frameworks/cj/BUILD.gn b/frameworks/cj/BUILD.gn index 47ea5698..20e1113d 100644 --- a/frameworks/cj/BUILD.gn +++ b/frameworks/cj/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (C) 2022-2023 Huawei Device Co., Ltd. +# Copyright (C) 2024 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -42,17 +42,17 @@ ohos_shared_library("cj_inputmethod_ffi") { debug = false } sources = [ + "src/cj_input_method_controller.cpp", + "src/cj_input_method_textchanged_listener.cpp", "src/input_method_ffi.cpp", "src/setting_listeners.cpp", "src/utils.cpp", - "src/cj_input_method_controller.cpp", - "src/cj_input_method_textchanged_listener.cpp" ] configs = [ ":imf_config" ] deps = [ - "${inputmethod_path}/frameworks/js/napi/common:inputmethod_js_common", + "${inputmethod_path}/common:inputmethod_common", "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:inputmethod_client", ] diff --git a/frameworks/cj/include/cj_input_method_controller.h b/frameworks/cj/include/cj_input_method_controller.h index 27936ba6..2c5320a9 100644 --- a/frameworks/cj/include/cj_input_method_controller.h +++ b/frameworks/cj/include/cj_input_method_controller.h @@ -60,15 +60,27 @@ private: static constexpr int32_t MAX_TIMEOUT = 2500; void RegisterListener(int8_t type, int64_t id); void UnRegisterListener(int8_t type); + void InitInsertText(int64_t id); + void InitDeleteRight(int64_t id); + void InitDeleteLeft(int64_t id); + void InitSendKeyboardStatus(int64_t id); + void InitSendFunctionKey(int64_t id); + void InitMoveCursor(int64_t id); + void InitHandleExtendAction(int64_t id); + void InitGetLeftText(int64_t id); + void InitGetRightText(int64_t id); + void InitSelectByRange(int64_t id); + void InitSelectByMovement(int64_t id); + void InitGetTextIndexAtCursor(int64_t id); std::recursive_mutex mutex_; - std::function onSelectByRange; + std::function onSelectByRange; std::function onSelectByMovement; std::function insertText; std::function deleteRight; std::function deleteLeft; - std::function sendKeyboardStatus; - std::function sendFunctionKey; - std::function moveCursor; + std::function sendKeyboardStatus; + std::function sendFunctionKey; + std::function moveCursor; std::function handleExtendAction; std::function getLeftText; std::function getRightText; diff --git a/frameworks/cj/include/input_method_ffi.h b/frameworks/cj/include/input_method_ffi.h index 2d5fda0c..221a8660 100644 --- a/frameworks/cj/include/input_method_ffi.h +++ b/frameworks/cj/include/input_method_ffi.h @@ -19,34 +19,35 @@ #include "input_method_ffi_structs.h" extern "C" { - FFI_EXPORT int32_t CJ_GetDefaultInputMethod(CInputMethodProperty &props); - FFI_EXPORT int32_t CJ_GetCurrentInputMethod(CInputMethodProperty &props); - FFI_EXPORT int32_t CJ_SwitchInputMethod(bool &result, CInputMethodProperty props); - FFI_EXPORT int32_t CJ_SwitchCurrentInputMethodSubtype(bool &result, CInputMethodSubtype target); - FFI_EXPORT int32_t CJ_GetCurrentInputMethodSubtype(CInputMethodSubtype &props); - FFI_EXPORT int32_t CJ_SwitchCurrentInputMethodAndSubtype(bool &result, CInputMethodProperty target, CInputMethodSubtype subtype); - FFI_EXPORT int32_t CJ_GetSystemInputMethodConfigAbility(CElementName &elem); - FFI_EXPORT RetInputMethodSubtype CJ_ListInputMethodSubtype(CInputMethodProperty props); - FFI_EXPORT RetInputMethodSubtype CJ_ListCurrentInputMethodSubtype(); - FFI_EXPORT RetInputMethodProperty CJ_GetInputMethods(bool enable); - FFI_EXPORT RetInputMethodProperty CJ_GetAllInputMethods(); - FFI_EXPORT int32_t CJ_InputMethodSettingOn(uint32_t type, void (*func)(CInputMethodProperty, CInputMethodSubtype)); - FFI_EXPORT int32_t CJ_InputMethodSettingOff(uint32_t type); - FFI_EXPORT int32_t CJ_ShowOptionalInputMethods(bool& result); - FFI_EXPORT int32_t CJ_InputMethodControllerOn(int8_t type, int64_t id); - FFI_EXPORT int32_t CJ_InputMethodControllerOff(int8_t type); + FFI_EXPORT int32_t FfiInputMethodGetDefaultInputMethod(CInputMethodProperty &props); + FFI_EXPORT int32_t FfiInputMethodGetCurrentInputMethod(CInputMethodProperty &props); + FFI_EXPORT int32_t FfiInputMethodSwitchInputMethod(bool &result, CInputMethodProperty props); + FFI_EXPORT int32_t FfiInputMethodSwitchCurrentInputMethodSubtype(bool &result, CInputMethodSubtype target); + FFI_EXPORT int32_t FfiInputMethodGetCurrentInputMethodSubtype(CInputMethodSubtype &props); + FFI_EXPORT int32_t FfiInputMethodSwitchCurrentInputMethodAndSubtype(bool &result, CInputMethodProperty target, + CInputMethodSubtype subtype); + FFI_EXPORT int32_t FfiInputMethodGetSystemInputMethodConfigAbility(CElementName &elem); + FFI_EXPORT RetInputMethodSubtype FfiInputMethodSettingListInputMethodSubtype(CInputMethodProperty props); + FFI_EXPORT RetInputMethodSubtype FfiInputMethodSettingListCurrentInputMethodSubtype(); + FFI_EXPORT RetInputMethodProperty FfiInputMethodSettingGetInputMethods(bool enable); + FFI_EXPORT RetInputMethodProperty FfiInputMethodSettingGetAllInputMethods(); + FFI_EXPORT int32_t FfiInputMethodSettingOn(uint32_t type, void (*func)(CInputMethodProperty, CInputMethodSubtype)); + FFI_EXPORT int32_t FfiInputMethodSettingOff(uint32_t type); + FFI_EXPORT int32_t FfiInputMethodSettingShowOptionalInputMethods(bool& result); + FFI_EXPORT int32_t FfiInputMethodControllerOn(int8_t type, int64_t id); + FFI_EXPORT int32_t FfiInputMethodControllerOff(int8_t type); - FFI_EXPORT int32_t OHOSFfiAttach(bool showKeyboard, CTextConfig txtCfg); - FFI_EXPORT int32_t OHOSFfiDetach(); - FFI_EXPORT int32_t OHOSFfiShowTextInput(); - FFI_EXPORT int32_t OHOSFfiHideTextInput(); - FFI_EXPORT int32_t OHOSFfiSetCallingWindow(uint32_t windowId); - FFI_EXPORT int32_t OHOSFfiUpdateCursor(CCursorInfo cursor); - FFI_EXPORT int32_t OHOSFfiChangeSelection(char *text, int32_t start, int32_t end); - FFI_EXPORT int32_t OHOSFfiUpdateAttribute(CInputAttribute inputAttribute); - FFI_EXPORT int32_t OHOSFfiShowSoftKeyboard(); - FFI_EXPORT int32_t OHOSFfiHideSoftKeyboard(); - FFI_EXPORT int32_t OHOSFfiStopInputSession(); + FFI_EXPORT int32_t FfiInputMethodControllerAttach(bool showKeyboard, CTextConfig txtCfg); + FFI_EXPORT int32_t FfiInputMethodControllerDetach(); + FFI_EXPORT int32_t FfiInputMethodControllerShowTextInput(); + FFI_EXPORT int32_t FfiInputMethodControllerHideTextInput(); + FFI_EXPORT int32_t FfiInputMethodControllerSetCallingWindow(uint32_t windowId); + FFI_EXPORT int32_t FfiInputMethodControllerUpdateCursor(CCursorInfo cursor); + FFI_EXPORT int32_t FfiInputMethodControllerChangeSelection(char *text, int32_t start, int32_t end); + FFI_EXPORT int32_t FfiInputMethodControllerUpdateAttribute(CInputAttribute inputAttribute); + FFI_EXPORT int32_t FfiInputMethodControllerShowSoftKeyboard(); + FFI_EXPORT int32_t FfiInputMethodControllerHideSoftKeyboard(); + FFI_EXPORT int32_t FfiInputMethodControllerStopInputSession(); } #endif // INPUT_METHOD_FFI_H \ No newline at end of file diff --git a/frameworks/cj/include/setting_listeners.h b/frameworks/cj/include/setting_listeners.h index 731cf784..cd2374f4 100644 --- a/frameworks/cj/include/setting_listeners.h +++ b/frameworks/cj/include/setting_listeners.h @@ -23,7 +23,7 @@ namespace OHOS::MiscServices { class CJGetInputMethodSetting : public ImeEventListener { - public : + public: CJGetInputMethodSetting() = default; ~CJGetInputMethodSetting() = default; static std::shared_ptr GetIMSInstance(); diff --git a/frameworks/cj/src/cj_input_method_controller.cpp b/frameworks/cj/src/cj_input_method_controller.cpp index 7c87e76c..7086434a 100644 --- a/frameworks/cj/src/cj_input_method_controller.cpp +++ b/frameworks/cj/src/cj_input_method_controller.cpp @@ -39,6 +39,7 @@ const int8_t GET_LEFT_TEXT = 7; const int8_t GET_RIGHT_TEXT = 8; const int8_t GET_TEXT_INDEX = 9; const int8_t SELECT_BY_MOVEMENT = 10; +const int8_t SELECT_BY_RANGE = 11; std::shared_ptr CjInputMethodController::GetInstance() { @@ -56,7 +57,7 @@ std::shared_ptr CjInputMethodController::GetInstance() int32_t CjInputMethodController::Attach(const CTextConfig &txtCfg, bool showKeyboard) { auto textListener = CjInputMethodTextChangedListener::GetInstance(); - if (!textListener) { + if (textListener == nullptr) { IMSA_HILOGE("failed to create CjInputMethodTextChangedListener!"); return ERR_NO_MEMORY; } @@ -79,7 +80,7 @@ int32_t CjInputMethodController::Attach(const CTextConfig &txtCfg, bool showKeyb }; auto controller = InputMethodController::GetInstance(); - if (!controller) { + if (controller == nullptr) { return ERR_NO_MEMORY; } return controller->Attach(textListener, showKeyboard, textCfg); @@ -88,7 +89,7 @@ int32_t CjInputMethodController::Attach(const CTextConfig &txtCfg, bool showKeyb int32_t CjInputMethodController::Detach() { auto controller = InputMethodController::GetInstance(); - if (!controller) { + if (controller == nullptr) { return ERR_NO_MEMORY; } return controller->Close(); @@ -97,7 +98,7 @@ int32_t CjInputMethodController::Detach() int32_t CjInputMethodController::ShowTextInput() { auto controller = InputMethodController::GetInstance(); - if (!controller) { + if (controller == nullptr) { return ERR_NO_MEMORY; } return controller->ShowTextInput(); @@ -106,7 +107,7 @@ int32_t CjInputMethodController::ShowTextInput() int32_t CjInputMethodController::HideTextInput() { auto controller = InputMethodController::GetInstance(); - if (!controller) { + if (controller == nullptr) { return ERR_NO_MEMORY; } return controller->HideTextInput(); @@ -115,7 +116,7 @@ int32_t CjInputMethodController::HideTextInput() int32_t CjInputMethodController::SetCallingWindow(uint32_t windowId) { auto controller = InputMethodController::GetInstance(); - if (!controller) { + if (controller == nullptr) { return ERR_NO_MEMORY; } return controller->SetCallingWindow(windowId); @@ -124,7 +125,7 @@ int32_t CjInputMethodController::SetCallingWindow(uint32_t windowId) int32_t CjInputMethodController::UpdateCursor(const CCursorInfo &cursor) { auto controller = InputMethodController::GetInstance(); - if (!controller) { + if (controller == nullptr) { return ERR_NO_MEMORY; } CursorInfo cursorInfo = { @@ -139,7 +140,7 @@ int32_t CjInputMethodController::UpdateCursor(const CCursorInfo &cursor) int32_t CjInputMethodController::ChangeSelection(const std::string &text, int32_t start, int32_t end) { auto controller = InputMethodController::GetInstance(); - if (!controller) { + if (controller == nullptr) { return ERR_NO_MEMORY; } std::wstring_convert, char16_t> converter; @@ -150,7 +151,7 @@ int32_t CjInputMethodController::ChangeSelection(const std::string &text, int32_ int32_t CjInputMethodController::UpdateAttribute(const CInputAttribute &inputAttribute) { auto controller = InputMethodController::GetInstance(); - if (!controller) { + if (controller == nullptr) { return ERR_NO_MEMORY; } Configuration config = Configuration(); @@ -162,7 +163,7 @@ int32_t CjInputMethodController::UpdateAttribute(const CInputAttribute &inputAtt int32_t CjInputMethodController::ShowSoftKeyboard() { auto controller = InputMethodController::GetInstance(); - if (!controller) { + if (controller == nullptr) { return ERR_NO_MEMORY; } return controller->ShowSoftKeyboard(); @@ -171,7 +172,7 @@ int32_t CjInputMethodController::ShowSoftKeyboard() int32_t CjInputMethodController::HideSoftKeyboard() { auto controller = InputMethodController::GetInstance(); - if (!controller) { + if (controller == nullptr) { return ERR_NO_MEMORY; } return controller->HideSoftKeyboard(); @@ -180,7 +181,7 @@ int32_t CjInputMethodController::HideSoftKeyboard() int32_t CjInputMethodController::StopInputSession() { auto controller = InputMethodController::GetInstance(); - if (!controller) { + if (controller == nullptr) { return ERR_NO_MEMORY; } return controller->StopInputSession(); @@ -190,90 +191,44 @@ void CjInputMethodController::RegisterListener(int8_t type, int64_t id) { std::lock_guard lock(mutex_); switch (type) { - case INSERT_TEXT: { - auto callback = reinterpret_cast(id); - insertText = [lambda = CJLambda::Create(callback)](const char* text) -> void { - lambda(text); - }; + case INSERT_TEXT: + InitInsertText(id); break; - } - case DELETE_LEFT: { - auto callback = reinterpret_cast(id); - deleteLeft = [lambda = CJLambda::Create(callback)](int32_t length) -> void { - lambda(length); - }; + case DELETE_LEFT: + InitDeleteRight(id); break; - } - case DELETE_RIGHT: { - auto callback = reinterpret_cast(id); - deleteRight = [lambda = CJLambda::Create(callback)](int32_t length) -> void { - lambda(length); - }; + case DELETE_RIGHT: + InitDeleteLeft(id); break; - } - case SEND_KEYBOARD_STATUS: { - auto callback = reinterpret_cast(id); - sendKeyboardStatus = [lambda = CJLambda::Create(callback)](int64_t status) -> void { - lambda(status); - }; + case SEND_KEYBOARD_STATUS: + InitSendKeyboardStatus(id); break; - } - case SEND_FUNCTION_KEY: { - auto callback = reinterpret_cast(id); - sendFunctionKey = [lambda = CJLambda::Create(callback)](int64_t functionKey) -> void { - lambda(functionKey); - }; + case SEND_FUNCTION_KEY: + InitSendFunctionKey(id); break; - } - case MOVE_CURSOR: { - auto callback = reinterpret_cast(id); - moveCursor = [lambda = CJLambda::Create(callback)](int64_t direction) -> void { - lambda(direction); - }; + case MOVE_CURSOR: + InitMoveCursor(id); break; - } - case HANDLE_EXTEND_ACTION: { - auto callback = reinterpret_cast(id); - handleExtendAction = [lambda = CJLambda::Create(callback)](int32_t action) -> void { - lambda(action); - }; + case HANDLE_EXTEND_ACTION: + InitHandleExtendAction(id); break; - } - case GET_LEFT_TEXT: { - auto callback = reinterpret_cast(id); - getLeftText = [lambda = CJLambda::Create(callback)](int32_t number) -> char* { - return lambda(number); - }; + case GET_LEFT_TEXT: + InitGetLeftText(id); break; - } - case GET_RIGHT_TEXT: { - auto callback = reinterpret_cast(id); - getRightText = [lambda = CJLambda::Create(callback)](int32_t number) -> char* { - return lambda(number); - }; + case GET_RIGHT_TEXT: + InitGetRightText(id); break; - } - case GET_TEXT_INDEX: { - auto callback = reinterpret_cast(id); - getTextIndexAtCursor = [lambda = CJLambda::Create(callback)](void) -> int32_t { - return lambda(); - }; + case GET_TEXT_INDEX: + InitGetTextIndexAtCursor(id); break; - } - case SELECT_BY_MOVEMENT: { - auto callback = reinterpret_cast(id); - onSelectByMovement = [lambda = CJLambda::Create(callback)](int32_t direction) -> void { - lambda(direction); - }; + case SELECT_BY_MOVEMENT: + InitSelectByMovement(id); break; - } - default: { - auto callback = reinterpret_cast(id); - onSelectByRange = [lambda = CJLambda::Create(callback)](int32_t start, int32_t end) -> void { - lambda(start, end); - }; + case SELECT_BY_RANGE: + InitSelectByRange(id); break; - } + default: + return; } } @@ -314,16 +269,18 @@ void CjInputMethodController::UnRegisterListener(int8_t type) case SELECT_BY_MOVEMENT: onSelectByMovement = nullptr; break; - default: + case SELECT_BY_RANGE: onSelectByRange = nullptr; break; + default: + return; } } int32_t CjInputMethodController::Subscribe(int8_t type, int64_t id) { auto controller = CjInputMethodController::GetInstance(); - if (!controller) { + if (controller == nullptr) { return ERR_NO_MEMORY; } controller->RegisterListener(type, id); @@ -333,7 +290,7 @@ int32_t CjInputMethodController::Subscribe(int8_t type, int64_t id) int32_t CjInputMethodController::Unsubscribe(int8_t type) { auto controller = CjInputMethodController::GetInstance(); - if (!controller) { + if (controller == nullptr) { return ERR_NO_MEMORY; } controller->UnRegisterListener(type); @@ -342,21 +299,22 @@ int32_t CjInputMethodController::Unsubscribe(int8_t type) void CjInputMethodController::OnSelectByRange(int32_t start, int32_t end) { - if (onSelelctByRange == nullptr) { - IMSA_HILOGI("onSelelctByRange null"); + if (onSelectByRange == nullptr) { + IMSA_HILOGD("onSelelctByRange null"); return; } - IMSA_HILOGI("onSelelctByRange runs"); - return onSelectByRange(start, end); + IMSA_HILOGD("onSelelctByRange runs"); + Range range = { .start = start, .end = end }; + return onSelectByRange(range); } void CjInputMethodController::OnSelectByMovement(int32_t direction) { if (onSelectByMovement == nullptr) { - IMSA_HILOGI("onSelectByMovement null"); + IMSA_HILOGD("onSelectByMovement null"); return; } - IMSA_HILOGI("onSelectByMovement runs"); + IMSA_HILOGD("onSelectByMovement runs"); return onSelectByMovement(direction); } @@ -368,10 +326,11 @@ void CjInputMethodController::InsertText(const std::u16string &text) return; } if (insertText == nullptr) { - IMSA_HILOGI("insertText null"); + IMSA_HILOGD("insertText null"); + free(insertTxt); return; } - IMSA_HILOGI("insertText runs"); + IMSA_HILOGD("insertText runs"); insertText(insertTxt); free(insertTxt); return; @@ -380,10 +339,10 @@ void CjInputMethodController::InsertText(const std::u16string &text) void CjInputMethodController::DeleteRight(int32_t length) { if (deleteRight == nullptr) { - IMSA_HILOGI("deleteRight null"); + IMSA_HILOGD("deleteRight null"); return; } - IMSA_HILOGI("deleteRight runs"); + IMSA_HILOGD("deleteRight runs"); deleteRight(length); return; } @@ -391,10 +350,10 @@ void CjInputMethodController::DeleteRight(int32_t length) void CjInputMethodController::DeleteLeft(int32_t length) { if (deleteLeft == nullptr) { - IMSA_HILOGI("deleteLeft null"); + IMSA_HILOGD("deleteLeft null"); return; } - IMSA_HILOGI("deleteLeft runs"); + IMSA_HILOGD("deleteLeft runs"); deleteLeft(length); return; } @@ -402,11 +361,11 @@ void CjInputMethodController::DeleteLeft(int32_t length) void CjInputMethodController::SendKeyboardStatus(const KeyboardStatus &status) { if (sendKeyboardStatus == nullptr) { - IMSA_HILOGI("sendKeyboardStatus null"); + IMSA_HILOGD("sendKeyboardStatus null"); return; } - IMSA_HILOGI("sendKeyboardStatus runs"); - auto statusNum = static_cast(status); + IMSA_HILOGD("sendKeyboardStatus runs"); + auto statusNum = static_cast(status); sendKeyboardStatus(statusNum); return; } @@ -414,11 +373,11 @@ void CjInputMethodController::SendKeyboardStatus(const KeyboardStatus &status) void CjInputMethodController::SendFunctionKey(const FunctionKey &functionKey) { if (sendFunctionKey == nullptr) { - IMSA_HILOGI("sendFunctionKey null"); + IMSA_HILOGD("sendFunctionKey null"); return; } - IMSA_HILOGI("sendFunctionKey runs"); - auto type = static_cast(functionKey.GetEnterKeyType()); + IMSA_HILOGD("sendFunctionKey runs"); + auto type = static_cast(functionKey.GetEnterKeyType()); sendFunctionKey(type); return; } @@ -426,11 +385,11 @@ void CjInputMethodController::SendFunctionKey(const FunctionKey &functionKey) void CjInputMethodController::MoveCursor(const Direction direction) { if (moveCursor == nullptr) { - IMSA_HILOGI("moveCursor null"); + IMSA_HILOGD("moveCursor null"); return; } - IMSA_HILOGI("moveCursor runs"); - auto dir = static_cast(direction); + IMSA_HILOGD("moveCursor runs"); + auto dir = static_cast(direction); moveCursor(dir); return; } @@ -438,10 +397,10 @@ void CjInputMethodController::MoveCursor(const Direction direction) void CjInputMethodController::HandleExtendAction(int32_t action) { if (handleExtendAction == nullptr) { - IMSA_HILOGI("handleExtendAction null"); + IMSA_HILOGD("handleExtendAction null"); return; } - IMSA_HILOGI("handleExtendAction runs"); + IMSA_HILOGD("handleExtendAction runs"); handleExtendAction(action); return; } @@ -449,10 +408,10 @@ void CjInputMethodController::HandleExtendAction(int32_t action) std::u16string CjInputMethodController::GetLeftText(int32_t number) { if (getLeftText == nullptr) { - IMSA_HILOGI("getLeftText null"); + IMSA_HILOGD("getLeftText null"); return u""; } - IMSA_HILOGI("getLeftText runs"); + IMSA_HILOGD("getLeftText runs"); char *text = getLeftText(number); auto ret = Str8ToStr16(std::string(text)); free(text); @@ -462,10 +421,10 @@ std::u16string CjInputMethodController::GetLeftText(int32_t number) std::u16string CjInputMethodController::GetRightText(int32_t number) { if (getRightText == nullptr) { - IMSA_HILOGI("getRightText null"); + IMSA_HILOGD("getRightText null"); return u""; } - IMSA_HILOGI("getRightText runs"); + IMSA_HILOGD("getRightText runs"); char *text = getRightText(number); auto ret = Str8ToStr16(std::string(text)); free(text); @@ -475,11 +434,108 @@ std::u16string CjInputMethodController::GetRightText(int32_t number) int32_t CjInputMethodController::GetTextIndexAtCursor() { if (getTextIndexAtCursor == nullptr) { - IMSA_HILOGI("getTextIndexAtCursor null"); + IMSA_HILOGD("getTextIndexAtCursor null"); return -1; } - IMSA_HILOGI("getTextIndexAtCursor runs"); + IMSA_HILOGD("getTextIndexAtCursor runs"); return getTextIndexAtCursor(); } + +void CjInputMethodController::InitInsertText(int64_t id) +{ + auto callback = reinterpret_cast(id); + insertText = [lambda = CJLambda::Create(callback)](const char* text) -> void { + lambda(text); + }; +} + +void CjInputMethodController::InitDeleteRight(int64_t id) +{ + auto callback = reinterpret_cast(id); + deleteLeft = [lambda = CJLambda::Create(callback)](int32_t length) -> void { + lambda(length); + }; +} + +void CjInputMethodController::InitDeleteLeft(int64_t id) +{ + auto callback = reinterpret_cast(id); + deleteRight = [lambda = CJLambda::Create(callback)](int32_t length) -> void { + lambda(length); + }; +} + +void CjInputMethodController::InitSendKeyboardStatus(int64_t id) +{ + auto callback = reinterpret_cast(id); + sendKeyboardStatus = [lambda = CJLambda::Create(callback)](int32_t status) -> void { + lambda(status); + }; +} + +void CjInputMethodController::InitSendFunctionKey(int64_t id) +{ + auto callback = reinterpret_cast(id); + sendFunctionKey = [lambda = CJLambda::Create(callback)](int32_t functionKey) -> void { + lambda(functionKey); + }; +} + +void CjInputMethodController::InitMoveCursor(int64_t id) +{ + auto callback = reinterpret_cast(id); + moveCursor = [lambda = CJLambda::Create(callback)](int32_t direction) -> void { + lambda(direction); + }; +} + +void CjInputMethodController::InitHandleExtendAction(int64_t id) +{ + auto callback = reinterpret_cast(id); + handleExtendAction = [lambda = CJLambda::Create(callback)](int32_t action) -> void { + lambda(action); + }; +} + +void CjInputMethodController::InitGetLeftText(int64_t id) +{ + auto callback = reinterpret_cast(id); + getLeftText = [lambda = CJLambda::Create(callback)](int32_t number) -> char* { + return lambda(number); + }; +} + +void CjInputMethodController::InitGetRightText(int64_t id) +{ + auto callback = reinterpret_cast(id); + getRightText = [lambda = CJLambda::Create(callback)](int32_t number) -> char* { + return lambda(number); + }; +} + +void CjInputMethodController::InitGetTextIndexAtCursor(int64_t id) +{ + auto callback = reinterpret_cast(id); + getTextIndexAtCursor = [lambda = CJLambda::Create(callback)](void) -> int32_t { + return lambda(); + }; +} + +void CjInputMethodController::InitSelectByMovement(int64_t id) +{ + auto callback = reinterpret_cast(id); + onSelectByMovement = [lambda = CJLambda::Create(callback)](int32_t direction) -> void { + lambda(direction); + }; +} + +void CjInputMethodController::InitSelectByRange(int64_t id) +{ + auto callback = reinterpret_cast(id); + onSelectByRange = [lambda = CJLambda::Create(callback)](Range range) -> void { + lambda(range); + }; +} + } // namespace MiscServices } // namespace OHOS diff --git a/frameworks/cj/src/cj_input_method_textchanged_listener.cpp b/frameworks/cj/src/cj_input_method_textchanged_listener.cpp index a93a4f46..0e7d605e 100644 --- a/frameworks/cj/src/cj_input_method_textchanged_listener.cpp +++ b/frameworks/cj/src/cj_input_method_textchanged_listener.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/frameworks/cj/src/imput_method_mock.cpp b/frameworks/cj/src/imput_method_mock.cpp deleted file mode 100644 index 81e851fb..00000000 --- a/frameworks/cj/src/imput_method_mock.cpp +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ diff --git a/frameworks/cj/src/input_method_ffi.cpp b/frameworks/cj/src/input_method_ffi.cpp index c1d32d40..c42ff50b 100644 --- a/frameworks/cj/src/input_method_ffi.cpp +++ b/frameworks/cj/src/input_method_ffi.cpp @@ -22,285 +22,340 @@ #include "global.h" #include "utils.h" -namespace OHOS::MiscServices +namespace OHOS::MiscServices { +extern "C" { +int32_t FfiInputMethodGetDefaultInputMethod(CInputMethodProperty &props) { - extern "C" - { - int32_t CJ_GetDefaultInputMethod(CInputMethodProperty &props) - { - std::shared_ptr property; - int32_t ret = InputMethodController::GetInstance()->GetDefaultInputMethod(property); - if (property == nullptr) - { - IMSA_HILOGE("default input method is nullptr!"); - return ret; - } - Utils::InputMethodProperty2C(props, *property); - return ret; - } - - int32_t CJ_GetCurrentInputMethod(CInputMethodProperty &props) - { - std::shared_ptr property = InputMethodController::GetInstance()->GetCurrentInputMethod(); - if (property == nullptr) - { - IMSA_HILOGE("current input method is nullptr!"); - return 0; - } - Utils::InputMethodProperty2C(props, *property); - return 0; - } - - int32_t CJ_SwitchInputMethod(bool &result, CInputMethodProperty props) - { - InputMethodSyncTrace tracer("CJInputMethod_SwitchInputMethod"); - int32_t errCode = - InputMethodController::GetInstance()->SwitchInputMethod(SwitchTrigger::CURRENT_IME, std::string(props.name), std::string(props.id)); - if (errCode == ErrorCode::NO_ERROR) - { - result = true; - } - return errCode; - } - - int32_t CJ_SwitchCurrentInputMethodSubtype(bool &result, CInputMethodSubtype target) - { - InputMethodSyncTrace tracer("CJInputMethod_SwitchCurrentInputMethodSubtype"); - int32_t errCode = InputMethodController::GetInstance()->SwitchInputMethod( - SwitchTrigger::CURRENT_IME, std::string(target.name), std::string(target.id)); - if (errCode == ErrorCode::NO_ERROR) { - result = true; - } - return errCode; - } - - int32_t CJ_GetCurrentInputMethodSubtype(CInputMethodSubtype &props) - { - std::shared_ptr subProperty = InputMethodController::GetInstance()->GetCurrentInputMethodSubtype(); - if (subProperty == nullptr) { - IMSA_HILOGE("current input method subtype is nullptr!"); - return -1; - } - Utils::InputMethodSubProperty2C(props, *subProperty); - return 0; - } - - int32_t CJ_SwitchCurrentInputMethodAndSubtype(bool &result, CInputMethodProperty target, CInputMethodSubtype subtype) - { - InputMethodSyncTrace tracer("CJInputMethod_SwitchCurrentInputMethodAndSubtype"); - int32_t errCode = - InputMethodController::GetInstance()->SwitchInputMethod(SwitchTrigger::CURRENT_IME, std::string(subtype.name), std::string(subtype.id)); - if (errCode == ErrorCode::NO_ERROR) { - result = true; - } - return errCode; - } - - int32_t CJ_GetSystemInputMethodConfigAbility(CElementName &elem) - { - OHOS::AppExecFwk::ElementName inputMethodConfig; - int32_t ret = InputMethodController::GetInstance()->GetInputMethodConfig(inputMethodConfig); - if (ret == ErrorCode::NO_ERROR) { - elem.deviceId = Utils::MallocCString(inputMethodConfig.GetDeviceID()); - elem.bundleName = Utils::MallocCString(inputMethodConfig.GetBundleName()); - elem.abilityName = Utils::MallocCString(inputMethodConfig.GetAbilityName()); - elem.moduleName = Utils::MallocCString(inputMethodConfig.GetModuleName()); - } - return ret; - } - - RetInputMethodSubtype CJ_ListInputMethodSubtype(CInputMethodProperty props) - { - IMSA_HILOGD("run in ListInputMethodSubtype"); - RetInputMethodSubtype ret{}; - Property property = Utils::C2InputMethodProperty(props); - std::vector subProps; - int32_t errCode = - InputMethodController::GetInstance()->ListInputMethodSubtype(property, subProps); - ret.code = errCode; - if (errCode != ErrorCode::NO_ERROR) { - return ret; - } - IMSA_HILOGI("exec ListInputMethodSubtype success"); - ret.size = subProps.size(); - if (ret.size > 0) { - ret.head = static_cast(malloc(sizeof(CInputMethodSubtype) * ret.size)); - } - if (ret.head == nullptr) { - ret.size = 0; - return ret; - } - for (unsigned int i = 0; i < ret.size; i++) { - CInputMethodSubtype props; - Utils::InputMethodSubProperty2C(props, subProps[i]); - ret.head[i] = props; - } - return ret; - } - - RetInputMethodSubtype CJ_ListCurrentInputMethodSubtype() - { - IMSA_HILOGD("run in ListCurrentInputMethodSubtype"); - RetInputMethodSubtype ret{}; - std::vector subProps; - int32_t errCode = InputMethodController::GetInstance()->ListCurrentInputMethodSubtype(subProps); - ret.code = errCode; - if (errCode != ErrorCode::NO_ERROR) { - return ret; - } - IMSA_HILOGI("exec ListCurrentInputMethodSubtype success."); - ret.size = subProps.size(); - if (ret.size > 0) { - ret.head = static_cast(malloc(sizeof(CInputMethodSubtype) * ret.size)); - } - if (ret.head == nullptr) { - ret.size = 0; - return ret; - } - for (unsigned int i = 0; i < ret.size; i++) { - CInputMethodSubtype props; - Utils::InputMethodSubProperty2C(props, subProps[i]); - ret.head[i] = props; - } - return ret; - } - - RetInputMethodProperty CJ_GetInputMethods(bool enable) - { - IMSA_HILOGD("run in"); - RetInputMethodProperty ret{}; - std::vector properties; - int32_t errCode = InputMethodController::GetInstance()->ListInputMethod(enable, properties); - ret.code = errCode; - if (errCode != ErrorCode::NO_ERROR) { - return ret; - } - ret.size = properties.size(); - if (ret.size > 0) { - ret.head = static_cast(malloc(sizeof(CInputMethodProperty) * ret.size)); - } - if (ret.head == nullptr) { - ret.size = 0; - return ret; - } - for (unsigned int i = 0; i < ret.size; i++) { - CInputMethodProperty props; - Utils::InputMethodProperty2C(props, properties[i]); - ret.head[i] = props; - } - return ret; - } - - RetInputMethodProperty CJ_GetAllInputMethods() - { - IMSA_HILOGD("run in"); - RetInputMethodProperty ret{}; - std::vector properties; - int32_t errCode = InputMethodController::GetInstance()->ListInputMethod(properties); - ret.code = errCode; - if (errCode != ErrorCode::NO_ERROR) { - return ret; - } - ret.size = properties.size(); - if (ret.size > 0) { - ret.head = static_cast(malloc(sizeof(CInputMethodProperty) * ret.size)); - } - if (ret.head == nullptr) { - ret.size = 0; - return ret; - } - for (unsigned int i = 0; i < ret.size; i++) { - CInputMethodProperty props; - Utils::InputMethodProperty2C(props, properties[i]); - ret.head[i] = props; - } - return ret; - } - - int32_t CJ_InputMethodSettingOn(uint32_t type, void (*func)(CInputMethodProperty, CInputMethodSubtype)) - { - return CJGetInputMethodSetting::GetIMSInstance()->Subscribe(type, func); - } - - int32_t CJ_InputMethodSettingOff(uint32_t type) - { - return CJGetInputMethodSetting::GetIMSInstance()->UnSubscribe(type); - } - - int32_t CJ_ShowOptionalInputMethods(bool& result) - { - IMSA_HILOGD("start JsGetInputMethodSetting."); - int32_t errCode = InputMethodController::GetInstance()->DisplayOptionalInputMethod(); - if (errCode == ErrorCode::NO_ERROR) { - IMSA_HILOGI("exec DisplayOptionalInputMethod success"); - result = true; - } - return errCode; - } - - int32_t CJ_InputMethodControllerOn(int8_t type, int64_t id) - { - return CjInputMethodController::Subscribe(type, id); - } - - int32_t CJ_InputMethodControllerOff(int8_t type) - { - return CjInputMethodController::Unsubscribe(type); - } - - int32_t OHOSFfiAttach(bool showKeyboard, CTextConfig txtCfg) - { - return CjInputMethodController::Attach(txtCfg, showKeyboard); - } - - int32_t OHOSFfiDetach() - { - return CjInputMethodController::Detach(); - } - - int32_t OHOSFfiShowTextInput() - { - return CjInputMethodController::ShowTextInput(); - } - - int32_t OHOSFfiHideTextInput() - { - return CjInputMethodController::HideTextInput(); - } - - int32_t OHOSFfiSetCallingWindow(uint32_t windowId) - { - return CjInputMethodController::SetCallingWindow(windowId); - } - - int32_t OHOSFfiUpdateCursor(CCursorInfo cursor) - { - return CjInputMethodController::UpdateCursor(cursor); - } - - int32_t OHOSFfiChangeSelection(char *text, int32_t start, int32_t end) - { - return CjInputMethodController::ChangeSelection(std::string(text), start, end); - } - - int32_t OHOSFfiUpdateAttribute(CInputAttribute inputAttribute) - { - return CjInputMethodController::UpdateAttribute(inputAttribute); - } - - int32_t OHOSFfiShowSoftKeyboard() - { - return CjInputMethodController::ShowSoftKeyboard(); - } - - int32_t OHOSFfiHideSoftKeyboard() - { - return CjInputMethodController::HideSoftKeyboard(); - } - - int32_t OHOSFfiStopInputSession() - { - return CjInputMethodController::StopInputSession(); - } + auto ctrl = InputMethodController::GetInstance(); + if (ctrl == nullptr) { + return ERR_NO_MEMORY; } + std::shared_ptr property; + int32_t ret = ctrl->GetDefaultInputMethod(property); + if (property == nullptr) { + IMSA_HILOGE("default input method is nullptr!"); + return ret; + } + Utils::InputMethodProperty2C(props, *property); + return ret; +} + +int32_t FfiInputMethodGetCurrentInputMethod(CInputMethodProperty &props) +{ + auto ctrl = InputMethodController::GetInstance(); + if (ctrl == nullptr) { + return ERR_NO_MEMORY; + } + std::shared_ptr property = ctrl->GetCurrentInputMethod(); + if (property == nullptr) { + IMSA_HILOGE("current input method is nullptr!"); + return ERR_NO_MEMORY; + } + Utils::InputMethodProperty2C(props, *property); + return 0; +} + +int32_t FfiInputMethodSwitchInputMethod(bool &result, CInputMethodProperty props) +{ + InputMethodSyncTrace tracer("CJInputMethod_SwitchInputMethod"); + auto ctrl = InputMethodController::GetInstance(); + if (ctrl == nullptr) { + return ERR_NO_MEMORY; + } + int32_t errCode = + ctrl->SwitchInputMethod(SwitchTrigger::CURRENT_IME, std::string(props.name), std::string(props.id)); + if (errCode == ErrorCode::NO_ERROR) { + result = true; + } + return errCode; +} + +int32_t FfiInputMethodSwitchCurrentInputMethodSubtype(bool &result, CInputMethodSubtype target) +{ + InputMethodSyncTrace tracer("CJInputMethod_SwitchCurrentInputMethodSubtype"); + auto ctrl = InputMethodController::GetInstance(); + if (ctrl == nullptr) { + return ERR_NO_MEMORY; + } + int32_t errCode = + ctrl->SwitchInputMethod(SwitchTrigger::CURRENT_IME, std::string(target.name), std::string(target.id)); + if (errCode == ErrorCode::NO_ERROR) { + result = true; + } + return errCode; +} + +int32_t FfiInputMethodGetCurrentInputMethodSubtype(CInputMethodSubtype &props) +{ + auto ctrl = InputMethodController::GetInstance(); + if (ctrl == nullptr) { + return ERR_NO_MEMORY; + } + std::shared_ptr subProperty = ctrl->GetCurrentInputMethodSubtype(); + if (subProperty == nullptr) { + IMSA_HILOGE("current input method subtype is nullptr!"); + return ERR_NO_MEMORY; + } + Utils::InputMethodSubProperty2C(props, *subProperty); + return 0; +} + +int32_t FfiInputMethodSwitchCurrentInputMethodAndSubtype(bool &result, + CInputMethodProperty target, CInputMethodSubtype subtype) +{ + InputMethodSyncTrace tracer("CJInputMethod_SwitchCurrentInputMethodAndSubtype"); + auto ctrl = InputMethodController::GetInstance(); + if (ctrl == nullptr) { + return ERR_NO_MEMORY; + } + int32_t errCode = ctrl->SwitchInputMethod(SwitchTrigger::CURRENT_IME, + std::string(subtype.name), std::string(subtype.id)); + if (errCode == ErrorCode::NO_ERROR) { + result = true; + } + return errCode; +} + +int32_t FfiInputMethodGetSystemInputMethodConfigAbility(CElementName &elem) +{ + OHOS::AppExecFwk::ElementName inputMethodConfig; + auto ctrl = InputMethodController::GetInstance(); + if (ctrl == nullptr) { + return ERR_NO_MEMORY; + } + int32_t ret = ctrl->GetInputMethodConfig(inputMethodConfig); + if (ret == ErrorCode::NO_ERROR) { + elem.deviceId = Utils::MallocCString(inputMethodConfig.GetDeviceID()); + elem.bundleName = Utils::MallocCString(inputMethodConfig.GetBundleName()); + elem.abilityName = Utils::MallocCString(inputMethodConfig.GetAbilityName()); + elem.moduleName = Utils::MallocCString(inputMethodConfig.GetModuleName()); + } + return ret; +} + +RetInputMethodSubtype FfiInputMethodSettingListInputMethodSubtype(CInputMethodProperty props) +{ + IMSA_HILOGD("run in ListInputMethodSubtype"); + RetInputMethodSubtype ret{}; + Property property = Utils::C2InputMethodProperty(props); + std::vector subProps; + auto ctrl = InputMethodController::GetInstance(); + if (ctrl == nullptr) { + ret.code = ERR_NO_MEMORY; + return ret; + } + int32_t errCode = ctrl->ListInputMethodSubtype(property, subProps); + ret.code = errCode; + if (errCode != ErrorCode::NO_ERROR) { + return ret; + } + IMSA_HILOGI("exec ListInputMethodSubtype success"); + ret.size = subProps.size(); + if (ret.size > 0) { + ret.head = static_cast(malloc(sizeof(CInputMethodSubtype) * ret.size)); + } + if (ret.head == nullptr) { + ret.size = 0; + return ret; + } + for (unsigned int i = 0; i < ret.size; i++) { + CInputMethodSubtype props; + Utils::InputMethodSubProperty2C(props, subProps[i]); + ret.head[i] = props; + } + return ret; +} + +RetInputMethodSubtype FfiInputMethodSettingListCurrentInputMethodSubtype() +{ + IMSA_HILOGD("run in ListCurrentInputMethodSubtype"); + RetInputMethodSubtype ret{}; + std::vector subProps; + auto ctrl = InputMethodController::GetInstance(); + if (ctrl == nullptr) { + ret.code = ERR_NO_MEMORY; + return ret; + } + int32_t errCode = ctrl->ListCurrentInputMethodSubtype(subProps); + ret.code = errCode; + if (errCode != ErrorCode::NO_ERROR) { + return ret; + } + IMSA_HILOGI("exec ListCurrentInputMethodSubtype success."); + ret.size = subProps.size(); + if (ret.size > 0) { + ret.head = static_cast(malloc(sizeof(CInputMethodSubtype) * ret.size)); + } + if (ret.head == nullptr) { + ret.size = 0; + return ret; + } + for (unsigned int i = 0; i < ret.size; i++) { + CInputMethodSubtype props; + Utils::InputMethodSubProperty2C(props, subProps[i]); + ret.head[i] = props; + } + return ret; +} + +RetInputMethodProperty FfiInputMethodSettingGetInputMethods(bool enable) +{ + IMSA_HILOGD("run in"); + RetInputMethodProperty ret{}; + std::vector properties; + auto ctrl = InputMethodController::GetInstance(); + if (ctrl == nullptr) { + ret.code = ERR_NO_MEMORY; + return ret; + } + int32_t errCode = ctrl->ListInputMethod(enable, properties); + ret.code = errCode; + if (errCode != ErrorCode::NO_ERROR) { + return ret; + } + ret.size = properties.size(); + if (ret.size > 0) { + ret.head = static_cast(malloc(sizeof(CInputMethodProperty) * ret.size)); + } + if (ret.head == nullptr) { + ret.size = 0; + return ret; + } + for (unsigned int i = 0; i < ret.size; i++) { + CInputMethodProperty props; + Utils::InputMethodProperty2C(props, properties[i]); + ret.head[i] = props; + } + return ret; +} + +RetInputMethodProperty FfiInputMethodSettingGetAllInputMethods() +{ + IMSA_HILOGD("run in"); + RetInputMethodProperty ret{}; + std::vector properties; + auto ctrl = InputMethodController::GetInstance(); + if (ctrl == nullptr) { + ret.code = ERR_NO_MEMORY; + return ret; + } + int32_t errCode = ctrl->ListInputMethod(properties); + ret.code = errCode; + if (errCode != ErrorCode::NO_ERROR) { + return ret; + } + ret.size = properties.size(); + if (ret.size > 0) { + ret.head = static_cast(malloc(sizeof(CInputMethodProperty) * ret.size)); + } + if (ret.head == nullptr) { + ret.size = 0; + return ret; + } + for (unsigned int i = 0; i < ret.size; i++) { + CInputMethodProperty props; + Utils::InputMethodProperty2C(props, properties[i]); + ret.head[i] = props; + } + return ret; +} + +int32_t FfiInputMethodSettingOn(uint32_t type, void (*func)(CInputMethodProperty, CInputMethodSubtype)) +{ + auto setting = CJGetInputMethodSetting::GetIMSInstance(); + if (setting == nullptr) { + return ERR_NO_MEMORY; + } + return setting->Subscribe(type, func); +} + +int32_t FfiInputMethodSettingOff(uint32_t type) +{ + auto setting = CJGetInputMethodSetting::GetIMSInstance(); + if (setting == nullptr) { + return ERR_NO_MEMORY; + } + return setting->UnSubscribe(type); +} + +int32_t FfiInputMethodSettingShowOptionalInputMethods(bool& result) +{ + IMSA_HILOGD("start JsGetInputMethodSetting."); + auto ctrl = InputMethodController::GetInstance(); + if (ctrl == nullptr) { + return ERR_NO_MEMORY; + } + int32_t errCode = ctrl->DisplayOptionalInputMethod(); + if (errCode == ErrorCode::NO_ERROR) { + IMSA_HILOGI("exec DisplayOptionalInputMethod success"); + result = true; + } + return errCode; +} + +int32_t FfiInputMethodControllerOn(int8_t type, int64_t id) +{ + return CjInputMethodController::Subscribe(type, id); +} + +int32_t FfiInputMethodControllerOff(int8_t type) +{ + return CjInputMethodController::Unsubscribe(type); +} + +int32_t FfiInputMethodControllerAttach(bool showKeyboard, CTextConfig txtCfg) +{ + return CjInputMethodController::Attach(txtCfg, showKeyboard); +} + +int32_t FfiInputMethodControllerDetach() +{ + return CjInputMethodController::Detach(); +} + +int32_t FfiInputMethodControllerShowTextInput() +{ + return CjInputMethodController::ShowTextInput(); +} + +int32_t FfiInputMethodControllerHideTextInput() +{ + return CjInputMethodController::HideTextInput(); +} + +int32_t FfiInputMethodControllerSetCallingWindow(uint32_t windowId) +{ + return CjInputMethodController::SetCallingWindow(windowId); +} + +int32_t FfiInputMethodControllerUpdateCursor(CCursorInfo cursor) +{ + return CjInputMethodController::UpdateCursor(cursor); +} + +int32_t FfiInputMethodControllerChangeSelection(char *text, int32_t start, int32_t end) +{ + return CjInputMethodController::ChangeSelection(std::string(text), start, end); +} + +int32_t FfiInputMethodControllerUpdateAttribute(CInputAttribute inputAttribute) +{ + return CjInputMethodController::UpdateAttribute(inputAttribute); +} + +int32_t FfiInputMethodControllerShowSoftKeyboard() +{ + return CjInputMethodController::ShowSoftKeyboard(); +} + +int32_t FfiInputMethodControllerHideSoftKeyboard() +{ + return CjInputMethodController::HideSoftKeyboard(); +} + +int32_t FfiInputMethodControllerStopInputSession() +{ + return CjInputMethodController::StopInputSession(); +} +} } \ No newline at end of file diff --git a/frameworks/cj/src/utils.cpp b/frameworks/cj/src/utils.cpp index 1db98a96..e991254c 100644 --- a/frameworks/cj/src/utils.cpp +++ b/frameworks/cj/src/utils.cpp @@ -17,14 +17,12 @@ namespace OHOS::MiscServices { char* Utils::MallocCString(const std::string &origin) { - if (origin.empty()) - { + if (origin.empty()) { return nullptr; } auto len = origin.length() + 1; char *res = static_cast(malloc(sizeof(char) * len)); - if (res == nullptr) - { + if (res == nullptr) { return nullptr; } return std::char_traits::copy(res, origin.c_str(), len);