mirror of
https://github.com/openharmony/miscservices_inputmethod.git
synced 2026-07-19 20:13:32 -04:00
@@ -17,6 +17,8 @@
|
||||
#include "napi/native_api.h"
|
||||
#include "napi/native_node_api.h"
|
||||
#include "global.h"
|
||||
#include "string_ex.h"
|
||||
#include "input_method_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
@@ -64,6 +66,27 @@ namespace MiscServices {
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value JS_DeleteForward(napi_env env, napi_callback_info cbInfo)
|
||||
{
|
||||
IMSA_HILOGI("JS_DeleteForward() is called!");
|
||||
size_t argc = 1;
|
||||
napi_value argv[2] = { 0 };
|
||||
napi_value thisVar = nullptr;
|
||||
void *data = nullptr;
|
||||
napi_get_cb_info(env, cbInfo, &argc, argv, &thisVar, &data);
|
||||
|
||||
EventTarget *eventTarget = nullptr;
|
||||
napi_unwrap(env, thisVar, (void **)&eventTarget);
|
||||
|
||||
int32_t value32 = 0;
|
||||
napi_get_value_int32(env, argv[0], &value32);
|
||||
InputMethodAbility::GetInstance()->DeleteForward(value32);
|
||||
|
||||
napi_value result = nullptr;
|
||||
napi_get_undefined(env, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value JS_DeleteBackward(napi_env env, napi_callback_info cbInfo)
|
||||
{
|
||||
IMSA_HILOGI("JS_DeleteBackward() is called!");
|
||||
@@ -85,6 +108,27 @@ namespace MiscServices {
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value JS_MoveCursor(napi_env env, napi_callback_info cbInfo)
|
||||
{
|
||||
IMSA_HILOGI("JS_MoveCursor() is called!");
|
||||
size_t argc = 1;
|
||||
napi_value argv[2] = { 0 };
|
||||
napi_value thisVar = nullptr;
|
||||
void *data = nullptr;
|
||||
napi_get_cb_info(env, cbInfo, &argc, argv, &thisVar, &data);
|
||||
|
||||
EventTarget *eventTarget = nullptr;
|
||||
napi_unwrap(env, thisVar, (void **)&eventTarget);
|
||||
|
||||
int32_t value32 = 0;
|
||||
napi_get_value_int32(env, argv[0], &value32);
|
||||
InputMethodAbility::GetInstance()->MoveCursor(value32);
|
||||
|
||||
napi_value result = nullptr;
|
||||
napi_get_undefined(env, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value JS_HideKeyboardSelf(napi_env env, napi_callback_info cbInfo)
|
||||
{
|
||||
IMSA_HILOGI("JS_HideKeyboardSelf() is called!");
|
||||
@@ -104,6 +148,67 @@ namespace MiscServices {
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value JS_GetTextBeforeCursor(napi_env env, napi_callback_info cbInfo)
|
||||
{
|
||||
IMSA_HILOGI("JS_GetTextBeforeCursor() is called!");
|
||||
size_t argc = 1;
|
||||
napi_value argv[2] = { 0 };
|
||||
napi_value thisVar = nullptr;
|
||||
void *data = nullptr;
|
||||
napi_get_cb_info(env, cbInfo, &argc, argv, &thisVar, &data);
|
||||
|
||||
EventTarget *eventTarget = nullptr;
|
||||
napi_unwrap(env, thisVar, (void **)&eventTarget);
|
||||
|
||||
std::u16string textString = InputMethodAbility::GetInstance()->GetTextBeforeCursor();
|
||||
std::string outString = Str16ToStr8(textString.c_str());
|
||||
|
||||
napi_value result = nullptr;
|
||||
napi_create_string_utf8(env, outString.c_str(), NAPI_AUTO_LENGTH, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value JS_GetTextAfterCursor(napi_env env, napi_callback_info cbInfo)
|
||||
{
|
||||
IMSA_HILOGI("JS_GetTextAfterCursor() is called!");
|
||||
size_t argc = 1;
|
||||
napi_value argv[2] = { 0 };
|
||||
napi_value thisVar = nullptr;
|
||||
void *data = nullptr;
|
||||
napi_get_cb_info(env, cbInfo, &argc, argv, &thisVar, &data);
|
||||
|
||||
EventTarget *eventTarget = nullptr;
|
||||
napi_unwrap(env, thisVar, (void **)&eventTarget);
|
||||
|
||||
std::u16string textString = InputMethodAbility::GetInstance()->GetTextAfterCursor();
|
||||
std::string outString = Str16ToStr8(textString.c_str());
|
||||
|
||||
napi_value result = nullptr;
|
||||
napi_create_string_utf8(env, outString.c_str(), NAPI_AUTO_LENGTH, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value JS_SendFunctionKey(napi_env env, napi_callback_info cbInfo)
|
||||
{
|
||||
IMSA_HILOGI("JS_SendFunctionKey() is called!");
|
||||
size_t argc = 1;
|
||||
napi_value argv[2] = { 0 };
|
||||
napi_value thisVar = nullptr;
|
||||
void *data = nullptr;
|
||||
napi_get_cb_info(env, cbInfo, &argc, argv, &thisVar, &data);
|
||||
|
||||
EventTarget *eventTarget = nullptr;
|
||||
napi_unwrap(env, thisVar, (void **)&eventTarget);
|
||||
|
||||
int32_t value32 = 0;
|
||||
napi_get_value_int32(env, argv[0], &value32);
|
||||
InputMethodAbility::GetInstance()->SendFunctionKey(value32);
|
||||
|
||||
napi_value result = nullptr;
|
||||
napi_get_undefined(env, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value JS_On(napi_env env, napi_callback_info cbInfo)
|
||||
{
|
||||
IMSA_HILOGI("JS_On() is called!");
|
||||
@@ -178,17 +283,33 @@ namespace MiscServices {
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value ToInt32Value(napi_env env, int32_t value)
|
||||
{
|
||||
napi_value staticValue = nullptr;
|
||||
napi_create_int32(env, value, &staticValue);
|
||||
return staticValue;
|
||||
}
|
||||
|
||||
napi_value InputMethodEngineInit(napi_env env, napi_value exports)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodEngineInit() is called!");
|
||||
const char className[] = "EventTarget";
|
||||
napi_value constructor = nullptr;
|
||||
napi_property_descriptor desc[] = {
|
||||
DECLARE_NAPI_FUNCTION("insertText", JS_InsertText),
|
||||
DECLARE_NAPI_FUNCTION("InsertText", JS_InsertText),
|
||||
DECLARE_NAPI_FUNCTION("DeleteForward", JS_DeleteForward),
|
||||
DECLARE_NAPI_FUNCTION("DeleteBackward", JS_DeleteBackward),
|
||||
DECLARE_NAPI_FUNCTION("HideKeyboardSelf", JS_HideKeyboardSelf),
|
||||
DECLARE_NAPI_FUNCTION("GetTextBeforeCursor", JS_GetTextBeforeCursor),
|
||||
DECLARE_NAPI_FUNCTION("GetTextAfterCursor", JS_GetTextAfterCursor),
|
||||
DECLARE_NAPI_FUNCTION("SendFunctionKey", JS_SendFunctionKey),
|
||||
DECLARE_NAPI_FUNCTION("on", JS_On),
|
||||
DECLARE_NAPI_FUNCTION("off", JS_Off),
|
||||
DECLARE_NAPI_STATIC_PROPERTY("FUNCTION_KEY_CONFIRM", ToInt32Value(env, 1)),
|
||||
DECLARE_NAPI_STATIC_PROPERTY("CURSOR_UP", ToInt32Value(env, 1)),
|
||||
DECLARE_NAPI_STATIC_PROPERTY("CURSOR_DOWN", ToInt32Value(env, 2)),
|
||||
DECLARE_NAPI_STATIC_PROPERTY("CURSOR_LEFT", ToInt32Value(env, 3)),
|
||||
DECLARE_NAPI_STATIC_PROPERTY("CURSOR_RIGHT", ToInt32Value(env, 4)),
|
||||
};
|
||||
napi_define_class(env, className, sizeof(className), JS_Constructor, nullptr,
|
||||
sizeof(desc) / sizeof(desc[0]), desc, &constructor);
|
||||
|
||||
Reference in New Issue
Block a user