!1188 dts:sdk与doc不一致及代码提示修改

Merge pull request !1188 from hemenghao/master
This commit is contained in:
openharmony_ci 2024-05-25 02:54:39 +00:00 committed by Gitee
commit 80d3285c0c
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
14 changed files with 198 additions and 165 deletions

View File

@ -379,20 +379,22 @@ napi_value JsInputMethodEngineSetting::CreatePanel(napi_env env, napi_callback_i
{
auto ctxt = std::make_shared<PanelContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
PARAM_CHECK_RETURN(env, argc >= 2, "should has 2 or 3 parameters!", TYPE_NONE, napi_invalid_arg);
PARAM_CHECK_RETURN(env, argc >= 2, "at least two paramsters is required", TYPE_NONE, napi_invalid_arg);
napi_valuetype valueType = napi_undefined;
// 0 means parameter of ctx<BaseContext>
napi_typeof(env, argv[0], &valueType);
PARAM_CHECK_RETURN(env, valueType == napi_object, " ctx: ", TYPE_OBJECT, napi_invalid_arg);
PARAM_CHECK_RETURN(env, valueType == napi_object, "ctx type must be BaseContext",
TYPE_NONE, napi_invalid_arg);
napi_status status = GetContext(env, argv[0], ctxt->context);
if (status != napi_ok) {
return status;
}
// 1 means parameter of info<PanelInfo>
napi_typeof(env, argv[1], &valueType);
PARAM_CHECK_RETURN(env, valueType == napi_object, " panelInfo: ", TYPE_OBJECT, napi_invalid_arg);
PARAM_CHECK_RETURN(env, valueType == napi_object, "param info type must be PanelInfo",
TYPE_NONE, napi_invalid_arg);
status = JsUtils::GetValue(env, argv[1], ctxt->panelInfo);
PARAM_CHECK_RETURN(env, status == napi_ok, " panelInfo: ", TYPE_OBJECT, napi_invalid_arg);
PARAM_CHECK_RETURN(env, status == napi_ok, "js param info covert failed", TYPE_NONE, napi_invalid_arg);
return status;
};
@ -427,15 +429,17 @@ napi_value JsInputMethodEngineSetting::DestroyPanel(napi_env env, napi_callback_
{
auto ctxt = std::make_shared<PanelContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
PARAM_CHECK_RETURN(env, argc >= 1, "should has 1 parameters!", TYPE_NONE, napi_invalid_arg);
PARAM_CHECK_RETURN(env, argc >= 1, "at least one paramster is required", TYPE_NONE, napi_invalid_arg);
napi_valuetype valueType = napi_undefined;
napi_typeof(env, argv[0], &valueType);
PARAM_CHECK_RETURN(env, valueType == napi_object, " target: ", TYPE_OBJECT, napi_invalid_arg);
PARAM_CHECK_RETURN(env, valueType == napi_object, "param panel type must be Panel", TYPE_NONE,
napi_invalid_arg);
bool isPanel = false;
napi_value constructor = JsPanel::Init(env);
CHECK_RETURN(constructor != nullptr, "Failed to get panel constructor.", napi_invalid_arg);
napi_status status = napi_instanceof(env, argv[0], constructor, &isPanel);
CHECK_RETURN((status == napi_ok) && isPanel, "It's not expected panel instance!", status);
CHECK_RETURN((status == napi_ok) && isPanel, "param verification failed. It's not expected panel instance!",
status);
JsPanel *jsPanel = nullptr;
status = napi_unwrap(env, argv[0], (void **)(&jsPanel));
CHECK_RETURN((status == napi_ok) && (jsPanel != nullptr), "Can not unwrap to JsPanel!", status);

View File

@ -113,10 +113,10 @@ napi_value JsPanel::SetUiContent(napi_env env, napi_callback_info info)
auto ctxt = std::make_shared<PanelContentContext>(env, info);
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
napi_status status = napi_generic_failure;
PARAM_CHECK_RETURN(env, argc >= 1, "should 1 or 2 parameters!", TYPE_NONE, status);
PARAM_CHECK_RETURN(env, argc >= 1, "at least one paramster is required", TYPE_NONE, status);
// 0 means the first param path<std::string>
status = JsUtils::GetValue(env, argv[0], ctxt->path);
CHECK_RETURN(status == napi_ok, "get path failed!", status);
PARAM_CHECK_RETURN(env, JsUtils::GetValue(env, argv[0], ctxt->path) == napi_ok,
"js param path covert failed, must be string", TYPE_NONE, status);
// if type of argv[1] is object, we will get value of 'storage' from it.
if (argc >= 2) {
napi_valuetype valueType = napi_undefined;
@ -142,6 +142,7 @@ napi_value JsPanel::SetUiContent(napi_env env, napi_callback_info info)
auto code = ctxt->inputMethodPanel->SetUiContent(ctxt->path, env, ctxt->contentStorage);
if (code == ErrorCode::ERROR_PARAMETER_CHECK_FAILED) {
ctxt->SetErrorCode(code);
ctxt->SetErrorMessage("path should be a path to specific page.");
return napi_generic_failure;
}
return napi_ok;
@ -157,13 +158,13 @@ napi_value JsPanel::Resize(napi_env env, napi_callback_info info)
auto ctxt = std::make_shared<PanelContentContext>(env, info);
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
napi_status status = napi_generic_failure;
PARAM_CHECK_RETURN(env, argc > 1, "should 2 or 3 parameters!", TYPE_NONE, status);
PARAM_CHECK_RETURN(env, argc > 1, "at least two paramsters is required", TYPE_NONE, status);
// 0 means the first param width<uint32_t>
status = JsUtils::GetValue(env, argv[0], ctxt->width);
CHECK_RETURN(status == napi_ok, "get width failed!", status);
PARAM_CHECK_RETURN(env, JsUtils::GetValue(env, argv[0], ctxt->width) == napi_ok,
"param width type must be number", TYPE_NONE, status);
// 1 means the second param height<uint32_t>
status = JsUtils::GetValue(env, argv[1], ctxt->height);
CHECK_RETURN(status == napi_ok, "get height failed!", status);
PARAM_CHECK_RETURN(env, JsUtils::GetValue(env, argv[1], ctxt->height) == napi_ok,
"param height type must be number", TYPE_NONE, status);
return napi_ok;
};
@ -188,24 +189,24 @@ napi_value JsPanel::MoveTo(napi_env env, napi_callback_info info)
auto ctxt = std::make_shared<PanelContentContext>(env, info);
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
napi_status status = napi_generic_failure;
PARAM_CHECK_RETURN(env, argc > 1, "should 2 or 3 parameters! ", TYPE_NONE, status);
PARAM_CHECK_RETURN(env, argc > 1, "at least two paramsters is required ", TYPE_NONE, status);
// 0 means the first param x<int32_t>
status = JsUtils::GetValue(env, argv[0], ctxt->x);
CHECK_RETURN(status == napi_ok, "get x failed!", status);
PARAM_CHECK_RETURN(env, JsUtils::GetValue(env, argv[0], ctxt->x) == napi_ok, "param x type must be number",
TYPE_NONE, status);
// 1 means the second param y<int32_t>
status = JsUtils::GetValue(env, argv[1], ctxt->y);
CHECK_RETURN(status == napi_ok, "get y failed!", status);
PARAM_CHECK_RETURN(env, JsUtils::GetValue(env, argv[1], ctxt->y) == napi_ok, "param y type must be number",
TYPE_NONE, status);
return napi_ok;
};
auto exec = [ctxt](AsyncCall::Context *ctx) {
CHECK_RETURN_VOID(ctxt->inputMethodPanel != nullptr, "inputMethodPanel_ is nullptr.");
auto code = ctxt->inputMethodPanel->MoveTo(ctxt->x, ctxt->y);
if (code == ErrorCode::NO_ERROR) {
ctxt->SetState(napi_ok);
if (code == ErrorCode::ERROR_PARAMETER_CHECK_FAILED) {
ctxt->SetErrorCode(code);
return;
}
ctxt->SetErrorCode(code);
ctxt->SetState(napi_ok);
};
ctxt->SetAction(std::move(input));
// 3 means JsAPI:moveTo has 3 params at most.
@ -253,12 +254,14 @@ napi_value JsPanel::ChangeFlag(napi_env env, napi_callback_info info)
napi_value argv[ARGC_MAX] = { nullptr };
napi_value thisVar = nullptr;
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr));
PARAM_CHECK_RETURN(env, argc > 0, "should 1 parameter! ", TYPE_NONE, nullptr);
PARAM_CHECK_RETURN(env, argc > 0, "at least one paramster is required", TYPE_NONE, nullptr);
int32_t panelFlag = 0;
// 0 means the first param flag<PanelFlag>
napi_status status = JsUtils::GetValue(env, argv[0], panelFlag);
CHECK_RETURN(status == napi_ok, "get panelFlag failed!", nullptr);
PARAM_CHECK_RETURN(env, status == napi_ok, "param flag type must be PanelFlag", TYPE_NONE, nullptr);
auto inputMethodPanel = UnwrapPanel(env, thisVar);
PARAM_CHECK_RETURN(env, (panelFlag == PanelFlag::FLG_FIXED || panelFlag == PanelFlag::FLG_FLOATING ||
panelFlag == PanelFlag::FLG_CANDIDATE_COLUMN), "param flag type must be one of PanelFlag", TYPE_NONE, nullptr);
auto ret = inputMethodPanel->ChangePanelFlag(PanelFlag(panelFlag));
CHECK_RETURN(ret == ErrorCode::NO_ERROR, "ChangePanelFlag failed!", nullptr);
InputMethodAbility::GetInstance()->NotifyKeyboardHeight(inputMethodPanel);
@ -271,14 +274,11 @@ napi_value JsPanel::SetPrivacyMode(napi_env env, napi_callback_info info)
napi_value argv[ARGC_MAX] = { nullptr };
napi_value thisVar = nullptr;
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr));
PARAM_CHECK_RETURN(env, argc > 0, "should 1 parameter! ", TYPE_NONE, nullptr);
PARAM_CHECK_RETURN(env, argc > 0, "at least one paramster is required", TYPE_NONE, nullptr);
bool isPrivacyMode = false;
// 0 means the first param isPrivacyMode<boolean>
napi_status status = JsUtils::GetValue(env, argv[0], isPrivacyMode);
if (status != napi_ok) {
JsUtils::ThrowException(env, JsUtils::Convert(ErrorCode::ERROR_PARAMETER_CHECK_FAILED), " param check failed!",
TYPE_BOOLEAN);
}
PARAM_CHECK_RETURN(env, status == napi_ok, "param isPrivacyMode type must be boolean", TYPE_NONE, nullptr);
CHECK_RETURN(status == napi_ok, "get isPrivacyMode failed!", nullptr);
auto inputMethodPanel = UnwrapPanel(env, thisVar);
auto ret = inputMethodPanel->SetPrivacyMode(isPrivacyMode);
@ -328,15 +328,15 @@ napi_value JsPanel::UnSubscribe(napi_env env, napi_callback_info info)
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr));
std::string type;
// 1 means least param num.
PARAM_CHECK_RETURN(env, argc >= 1, "At least 1 param", TYPE_NONE, nullptr);
PARAM_CHECK_RETURN(env, argc >= 1, "at least one paramster is required", TYPE_NONE, nullptr);
PARAM_CHECK_RETURN(
env, JsUtil::GetValue(env, argv[0], type), "js param: type covert failed", TYPE_NONE, nullptr);
env, JsUtil::GetValue(env, argv[0], type), "param type must be string", TYPE_NONE, nullptr);
PARAM_CHECK_RETURN(env, EventChecker::IsValidEventType(EventSubscribeModule::PANEL, type),
"EventType shoule be show or hide", TYPE_NONE, nullptr);
"type shoule be show/hide/sizeChange", TYPE_NONE, nullptr);
// if the second param is not napi_function/napi_null/napi_undefined, return
auto paramType = JsUtil::GetType(env, argv[1]);
PARAM_CHECK_RETURN(env, (paramType == napi_function || paramType == napi_null || paramType == napi_undefined),
"ParamType should be function or null or undefined", TYPE_NONE, nullptr);
"callback should be function or null or undefined", TYPE_NONE, nullptr);
// if the second param is napi_function, delete it, else delete all
argv[1] = paramType == napi_function ? argv[1] : nullptr;
@ -355,20 +355,20 @@ napi_value JsPanel::AdjustPanelRect(napi_env env, napi_callback_info info)
auto ctxt = std::make_shared<PanelContentContext>(env, info);
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
napi_status status = napi_generic_failure;
PARAM_CHECK_RETURN(env, argc > 1, "should 2 parameters!", TYPE_NONE, status);
PARAM_CHECK_RETURN(env, argc > 1, "at least two paramsters is required", TYPE_NONE, status);
// 0 means the first param flag
PARAM_CHECK_RETURN(env, JsUtil::GetType(env, argv[0]) == napi_number, "flag",
TYPE_NUMBER, napi_generic_failure);
int32_t panelFlag = 0;
CHECK_RETURN(JsUtils::GetValue(env, argv[0], panelFlag) == napi_ok,
"js param: flag covert failed", napi_generic_failure);
"js param flag covert failed", napi_generic_failure);
ctxt->panelFlag = PanelFlag(panelFlag);
PARAM_CHECK_RETURN(env, ctxt->panelFlag == 0 || ctxt->panelFlag == 1,
"flag shoule be FLG_FIXED or FLG_FLOATING ", TYPE_NONE, napi_generic_failure);
"param flag type shoule be FLG_FIXED or FLG_FLOATING ", TYPE_NONE, napi_generic_failure);
// 1 means the second param rect
PARAM_CHECK_RETURN(env, JsUtil::GetType(env, argv[1]) == napi_object, "rect", TYPE_OBJECT,
napi_generic_failure);
PARAM_CHECK_RETURN(env, JsPanelRect::Read(env, argv[1], ctxt->layoutParams), "js param: rect covert failed",
PARAM_CHECK_RETURN(env, JsUtil::GetType(env, argv[1]) == napi_object, "param rect type must be PanelRect",
TYPE_NONE, napi_generic_failure);
PARAM_CHECK_RETURN(env, JsPanelRect::Read(env, argv[1], ctxt->layoutParams), "js param rect covert failed",
TYPE_NONE, napi_generic_failure);
return napi_ok;
};

View File

@ -57,7 +57,10 @@ public:
private:
struct PanelContentContext : public AsyncCall::Context {
LayoutParams layoutParams;
LayoutParams layoutParams = {
{0, 0, 0, 0},
{0, 0, 0, 0}
};
PanelFlag panelFlag = PanelFlag::FLG_FIXED;
std::string path = "";
uint32_t width = 0;

View File

@ -79,8 +79,13 @@ napi_value JsTextInputClientEngine::MoveCursor(napi_env env, napi_callback_info
{
auto ctxt = std::make_shared<MoveCursorContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
PARAM_CHECK_RETURN(env, argc > 0, "should 1 or 2 parameters! ", TYPE_NONE, napi_generic_failure);
PARAM_CHECK_RETURN(env, argc > 0, "at least one paramster is required", TYPE_NONE, napi_generic_failure);
PARAM_CHECK_RETURN(env, JsUtil::GetType(env, argv[0]) == napi_number, "param direction type must be number",
TYPE_NONE, napi_generic_failure);
auto status = JsUtils::GetValue(env, argv[0], ctxt->num);
// 1 means least param num.
PARAM_CHECK_RETURN(env, ctxt->num >= 0, "direction should be no less than 0", TYPE_NONE, napi_generic_failure);
if (status == napi_ok) {
ctxt->info = { std::chrono::system_clock::now(), EditorEvent::MOVE_CURSOR };
editorQueue_.Push(ctxt->info);
@ -114,11 +119,11 @@ napi_value JsTextInputClientEngine::MoveCursorSync(napi_env env, napi_callback_i
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
int32_t direction = 0;
// 1 means least param num.
PARAM_CHECK_RETURN(env, argc >= 1, "At least 1 param", TYPE_NONE, HandleParamCheckFailure(env));
PARAM_CHECK_RETURN(env, argc >= 1, "at least one paramster is required", TYPE_NONE, HandleParamCheckFailure(env));
PARAM_CHECK_RETURN(env, JsUtil::GetType(env, argv[0]) == napi_number, "direction", TYPE_NUMBER,
HandleParamCheckFailure(env));
PARAM_CHECK_RETURN(env, JsUtil::GetValue(env, argv[0], direction),
"js param: direction covert failed", TYPE_NONE, HandleParamCheckFailure(env));
"js param direction covert failed", TYPE_NONE, HandleParamCheckFailure(env));
PARAM_CHECK_RETURN(env, direction >= 0, "direction should be no less than 0", TYPE_NONE,
HandleParamCheckFailure(env));
IMSA_HILOGD("moveCursor , direction: %{public}d", direction);
@ -185,12 +190,12 @@ napi_status JsTextInputClientEngine::GetSelectRange(napi_env env, napi_value arg
napi_status status = napi_generic_failure;
napi_value napiValue = nullptr;
status = napi_get_named_property(env, argv, "start", &napiValue);
PARAM_CHECK_RETURN(env, status == napi_ok, "missing start parameter.", TYPE_NONE, status);
PARAM_CHECK_RETURN(env, status == napi_ok, "start of range cannot empty and must be number.", TYPE_NONE, status);
status = JsUtils::GetValue(env, napiValue, ctxt->start);
CHECK_RETURN(status == napi_ok, "failed to get start value", status);
status = napi_get_named_property(env, argv, "end", &napiValue);
PARAM_CHECK_RETURN(env, status == napi_ok, "missing end parameter.", TYPE_NONE, status);
PARAM_CHECK_RETURN(env, status == napi_ok, "end of range cannot empty and must be number.", TYPE_NONE, status);
status = JsUtils::GetValue(env, napiValue, ctxt->end);
if (status != napi_ok) {
IMSA_HILOGE("failed to get end value");
@ -204,11 +209,12 @@ napi_status JsTextInputClientEngine::GetSelectMovement(
napi_status status = napi_generic_failure;
napi_value napiValue = nullptr;
status = napi_get_named_property(env, argv, "direction", &napiValue);
PARAM_CHECK_RETURN(env, status == napi_ok, "missing direction parameter.", TYPE_NONE, status);
PARAM_CHECK_RETURN(env, status == napi_ok, "direction of movement cannot empty.", TYPE_NONE, status);
status = JsUtils::GetValue(env, napiValue, ctxt->direction);
if (status != napi_ok) {
IMSA_HILOGE("failed to get direction value");
}
PARAM_CHECK_RETURN(env, status == napi_ok, "param direction type must be Direction", TYPE_NONE, status);
return status;
}
@ -216,8 +222,10 @@ napi_value JsTextInputClientEngine::SendKeyFunction(napi_env env, napi_callback_
{
auto ctxt = std::make_shared<SendKeyFunctionContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
PARAM_CHECK_RETURN(env, argc > 0, "should 1 or 2 parameters!", TYPE_NONE, napi_generic_failure);
return JsUtils::GetValue(env, argv[0], ctxt->action);
PARAM_CHECK_RETURN(env, argc > 0, "at least one paramster is required", TYPE_NONE, napi_generic_failure);
napi_status ret = JsUtils::GetValue(env, argv[0], ctxt->action);
PARAM_CHECK_RETURN(env, ret == napi_ok, "param action type must be number", TYPE_NONE, napi_generic_failure);
return ret;
};
auto output = [ctxt](napi_env env, napi_value *result) -> napi_status {
napi_status status = napi_get_boolean(env, ctxt->isSendKeyFunction, result);
@ -243,14 +251,12 @@ napi_value JsTextInputClientEngine::SendPrivateCommand(napi_env env, napi_callba
{
auto ctxt = std::make_shared<SendPrivateCommandContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
PARAM_CHECK_RETURN(env, argc > 0, "should 1 parameter!", TYPE_NONE, napi_generic_failure);
PARAM_CHECK_RETURN(env, argc > 0, "at least one paramster is required", TYPE_NONE, napi_generic_failure);
napi_status status = JsUtils::GetValue(env, argv[0], ctxt->privateCommand);
CHECK_RETURN(status == napi_ok, "GetValue privateCommand error", status);
if (!TextConfig::IsPrivateCommandValid(ctxt->privateCommand)) {
JsUtils::ThrowException(
env, IMFErrorCode::EXCEPTION_PARAMCHECK, "privateCommand size limit 32KB, count limit 5.", TYPE_NONE);
return napi_generic_failure;
}
CHECK_RETURN(status == napi_ok,
"param commandData covert failed, type must be Record<string, CommandDataType>", status);
PARAM_CHECK_RETURN(env, TextConfig::IsPrivateCommandValid(ctxt->privateCommand),
"commandData size limit 32KB, count limit 5.", TYPE_NONE, napi_generic_failure);
ctxt->info = { std::chrono::system_clock::now(), ctxt->privateCommand };
privateCommandQueue_.Push(ctxt->info);
return status;
@ -286,10 +292,10 @@ napi_value JsTextInputClientEngine::DeleteForwardSync(napi_env env, napi_callbac
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
int32_t length = 0;
// 1 means least param num.
PARAM_CHECK_RETURN(env, argc >= 1, "At least 1 param", TYPE_NONE, HandleParamCheckFailure(env));
PARAM_CHECK_RETURN(env, argc >= 1, "at least one paramster is required", TYPE_NONE, HandleParamCheckFailure(env));
PARAM_CHECK_RETURN(env, JsUtil::GetType(env, argv[0]) == napi_number, "length", TYPE_NUMBER,
HandleParamCheckFailure(env));
PARAM_CHECK_RETURN(env, JsUtil::GetValue(env, argv[0], length), "js param: length covert failed",
PARAM_CHECK_RETURN(env, JsUtil::GetValue(env, argv[0], length), "js param length covert failed",
TYPE_NONE, HandleParamCheckFailure(env));
PARAM_CHECK_RETURN(env, length >= 0, "length should no less than 0", TYPE_NONE, HandleParamCheckFailure(env));
IMSA_HILOGD("Delete forward, length: %{public}d", length);
@ -306,8 +312,11 @@ napi_value JsTextInputClientEngine::DeleteForward(napi_env env, napi_callback_in
InputMethodSyncTrace tracer("JS_DeleteForward");
auto ctxt = std::make_shared<DeleteForwardContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
PARAM_CHECK_RETURN(env, argc > 0, "should 1 or 2 parameters!", TYPE_NONE, napi_generic_failure);
PARAM_CHECK_RETURN(env, argc > 0, "at least one paramster is required", TYPE_NONE, napi_generic_failure);
PARAM_CHECK_RETURN(env, JsUtil::GetType(env, argv[0]) == napi_number, "param length type must be number",
TYPE_NONE, napi_generic_failure);
auto status = JsUtils::GetValue(env, argv[0], ctxt->length);
PARAM_CHECK_RETURN(env, ctxt->length >= 0, "length should no less than 0", TYPE_NONE, napi_generic_failure);
if (status == napi_ok) {
ctxt->info = { std::chrono::system_clock::now(), EditorEvent::DELETE_FORWARD };
editorQueue_.Push(ctxt->info);
@ -349,10 +358,10 @@ napi_value JsTextInputClientEngine::DeleteBackwardSync(napi_env env, napi_callba
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
int32_t length = 0;
// 1 means least param num.
PARAM_CHECK_RETURN(env, argc >= 1, "At least 1 param", TYPE_NONE, HandleParamCheckFailure(env));
PARAM_CHECK_RETURN(env, argc >= 1, "at least one paramster is required", TYPE_NONE, HandleParamCheckFailure(env));
PARAM_CHECK_RETURN(env, JsUtil::GetType(env, argv[0]) == napi_number, "length", TYPE_NUMBER,
HandleParamCheckFailure(env));
PARAM_CHECK_RETURN(env, JsUtil::GetValue(env, argv[0], length), "js param: length covert failed",
PARAM_CHECK_RETURN(env, JsUtil::GetValue(env, argv[0], length), "js param length covert failed",
TYPE_NONE, HandleParamCheckFailure(env));
PARAM_CHECK_RETURN(env, length >= 0, "length should no less than 0", TYPE_NONE, HandleParamCheckFailure(env));
IMSA_HILOGD("Delete backward, length: %{public}d", length);
@ -368,7 +377,9 @@ napi_value JsTextInputClientEngine::DeleteBackward(napi_env env, napi_callback_i
{
auto ctxt = std::make_shared<DeleteBackwardContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
PARAM_CHECK_RETURN(env, argc > 0, "should 1 or 2 parameters!", TYPE_NONE, napi_generic_failure);
PARAM_CHECK_RETURN(env, argc > 0, "at least one paramster is required", TYPE_NONE, napi_generic_failure);
PARAM_CHECK_RETURN(env, JsUtil::GetType(env, argv[0]) == napi_number, "param length type must be number",
TYPE_NONE, napi_generic_failure);
auto status = JsUtils::GetValue(env, argv[0], ctxt->length);
if (status == napi_ok) {
ctxt->info = { std::chrono::system_clock::now(), EditorEvent::DELETE_BACKWARD };
@ -403,7 +414,9 @@ napi_value JsTextInputClientEngine::InsertText(napi_env env, napi_callback_info
InputMethodSyncTrace tracer("JS_InsertText");
auto ctxt = std::make_shared<InsertTextContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
PARAM_CHECK_RETURN(env, argc > 0, "should 1 or 2 parameters!", TYPE_NONE, napi_generic_failure);
PARAM_CHECK_RETURN(env, argc > 0, "at least one paramster is required", TYPE_NONE, napi_generic_failure);
PARAM_CHECK_RETURN(env, JsUtil::GetType(env, argv[0]) == napi_string, "param text type must be string",
TYPE_NONE, napi_generic_failure);
auto status = JsUtils::GetValue(env, argv[0], ctxt->text);
if (status == napi_ok) {
ctxt->info = { std::chrono::system_clock::now(), EditorEvent::INSERT_TEXT };
@ -449,10 +462,10 @@ napi_value JsTextInputClientEngine::InsertTextSync(napi_env env, napi_callback_i
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
std::string text;
// 1 means least param num.
PARAM_CHECK_RETURN(env, argc >= 1, "At least 1 param", TYPE_NONE, HandleParamCheckFailure(env));
PARAM_CHECK_RETURN(env, argc >= 1, "at least one paramster is required", TYPE_NONE, HandleParamCheckFailure(env));
PARAM_CHECK_RETURN(env, JsUtil::GetType(env, argv[0]) == napi_string, "text", TYPE_STRING,
HandleParamCheckFailure(env));
PARAM_CHECK_RETURN(env, JsUtil::GetValue(env, argv[0], text), "js param: text covert failed",
PARAM_CHECK_RETURN(env, JsUtil::GetValue(env, argv[0], text), "js param text covert failed",
TYPE_NONE, HandleParamCheckFailure(env));
IMSA_HILOGD("insert text , text: %{public}s", text.c_str());
int32_t ret = InputMethodAbility::GetInstance()->InsertText(text);
@ -476,10 +489,10 @@ napi_value JsTextInputClientEngine::GetForwardSync(napi_env env, napi_callback_i
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
int32_t length = 0;
// 1 means least param num.
PARAM_CHECK_RETURN(env, argc >= 1, "At least 1 param", TYPE_NONE, HandleParamCheckFailure(env));
PARAM_CHECK_RETURN(env, argc >= 1, "at least one paramster is required", TYPE_NONE, HandleParamCheckFailure(env));
PARAM_CHECK_RETURN(env, JsUtil::GetType(env, argv[0]) == napi_number, "length", TYPE_NUMBER,
HandleParamCheckFailure(env));
PARAM_CHECK_RETURN(env, JsUtil::GetValue(env, argv[0], length), "js param: length covert failed",
PARAM_CHECK_RETURN(env, JsUtil::GetValue(env, argv[0], length), "js param length covert failed",
TYPE_NONE, HandleParamCheckFailure(env));
PARAM_CHECK_RETURN(env, length >= 0, "length should no less than 0", TYPE_NONE, HandleParamCheckFailure(env));
IMSA_HILOGD("Get forward, length: %{public}d", length);
@ -501,7 +514,9 @@ napi_value JsTextInputClientEngine::GetForward(napi_env env, napi_callback_info
InputMethodSyncTrace tracer("JS_GetForward");
auto ctxt = std::make_shared<GetForwardContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
PARAM_CHECK_RETURN(env, argc > 0, "should 1 or 2 parameters!", TYPE_NONE, napi_generic_failure);
PARAM_CHECK_RETURN(env, argc > 0, "at least one paramster is required", TYPE_NONE, napi_generic_failure);
PARAM_CHECK_RETURN(env, JsUtil::GetType(env, argv[0]) == napi_number, "param length type must be number",
TYPE_NONE, napi_generic_failure);
auto status = JsUtils::GetValue(env, argv[0], ctxt->length);
if (status == napi_ok) {
ctxt->info = { std::chrono::system_clock::now(), EditorEvent::GET_FORWARD };
@ -546,10 +561,10 @@ napi_value JsTextInputClientEngine::GetBackwardSync(napi_env env, napi_callback_
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
int32_t length = 0;
// 1 means least param num.
PARAM_CHECK_RETURN(env, argc >= 1, "At least 1 param", TYPE_NONE, HandleParamCheckFailure(env));
PARAM_CHECK_RETURN(env, argc >= 1, "at least one paramster is required", TYPE_NONE, HandleParamCheckFailure(env));
PARAM_CHECK_RETURN(env, JsUtil::GetType(env, argv[0]) == napi_number, "length", TYPE_NUMBER,
HandleParamCheckFailure(env));
PARAM_CHECK_RETURN(env, JsUtil::GetValue(env, argv[0], length), "js param: length covert failed",
PARAM_CHECK_RETURN(env, JsUtil::GetValue(env, argv[0], length), "js param length covert failed",
TYPE_NONE, HandleParamCheckFailure(env));
PARAM_CHECK_RETURN(env, length >= 0, "length should no less than 0", TYPE_NONE, HandleParamCheckFailure(env));
IMSA_HILOGD("Get backward, length: %{public}d", length);
@ -570,7 +585,9 @@ napi_value JsTextInputClientEngine::GetBackward(napi_env env, napi_callback_info
{
auto ctxt = std::make_shared<GetBackwardContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
PARAM_CHECK_RETURN(env, argc > 0, "should 1 or 2 parameters!", TYPE_NONE, napi_generic_failure);
PARAM_CHECK_RETURN(env, argc > 0, "at least one paramster is required", TYPE_NONE, napi_generic_failure);
PARAM_CHECK_RETURN(env, JsUtil::GetType(env, argv[0]) == napi_number, "param length type must be number",
TYPE_NONE, napi_generic_failure);
auto status = JsUtils::GetValue(env, argv[0], ctxt->length);
if (status == napi_ok) {
ctxt->info = { std::chrono::system_clock::now(), EditorEvent::GET_BACKWARD };
@ -649,10 +666,11 @@ napi_value JsTextInputClientEngine::SelectByRange(napi_env env, napi_callback_in
IMSA_HILOGD("run in");
auto ctxt = std::make_shared<SelectContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
PARAM_CHECK_RETURN(env, argc > 0, "should 1 or 2 parameters!", TYPE_NONE, napi_generic_failure);
PARAM_CHECK_RETURN(env, argc > 0, "at least one paramster is required", TYPE_NONE, napi_generic_failure);
napi_valuetype valueType = napi_undefined;
napi_typeof(env, argv[0], &valueType);
PARAM_CHECK_RETURN(env, valueType == napi_object, "range", TYPE_OBJECT, napi_generic_failure);
PARAM_CHECK_RETURN(env, valueType == napi_object, "param range type must be Range", TYPE_NONE,
napi_generic_failure);
auto status = GetSelectRange(env, argv[0], ctxt);
if (status == napi_ok) {
ctxt->info = { std::chrono::system_clock::now(), EditorEvent::SELECT_BY_RANGE };
@ -687,8 +705,8 @@ napi_value JsTextInputClientEngine::SelectByRangeSync(napi_env env, napi_callbac
size_t argc = 1;
napi_value argv[1] = { nullptr };
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
PARAM_CHECK_RETURN(env, argc >= 1, "At least 1 param", TYPE_NONE, HandleParamCheckFailure(env));
PARAM_CHECK_RETURN(env, JsUtil::GetType(env, argv[0]) == napi_object, "range", TYPE_OBJECT,
PARAM_CHECK_RETURN(env, argc >= 1, "at least one paramster is required", TYPE_NONE, HandleParamCheckFailure(env));
PARAM_CHECK_RETURN(env, JsUtil::GetType(env, argv[0]) == napi_object, "param range type must be Range", TYPE_NONE,
HandleParamCheckFailure(env));
auto ctxt = std::make_shared<SelectContext>();
auto status = GetSelectRange(env, argv[0], ctxt);
@ -716,14 +734,14 @@ napi_value JsTextInputClientEngine::SelectByMovementSync(napi_env env, napi_call
size_t argc = 1;
napi_value argv[1] = { nullptr };
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
PARAM_CHECK_RETURN(env, argc >= 1, "At least 1 param", TYPE_NONE, HandleParamCheckFailure(env));
PARAM_CHECK_RETURN(env, JsUtil::GetType(env, argv[0]) == napi_object, "direction", TYPE_OBJECT,
HandleParamCheckFailure(env));
PARAM_CHECK_RETURN(env, argc >= 1, "at least one paramster is required", TYPE_NONE, HandleParamCheckFailure(env));
PARAM_CHECK_RETURN(env, JsUtil::GetType(env, argv[0]) == napi_object, "param movement type must be Movement",
TYPE_NONE, HandleParamCheckFailure(env));
auto ctxt = std::make_shared<SelectContext>();
auto status = GetSelectMovement(env, argv[0], ctxt);
if (status != napi_ok) {
editorQueue_.Pop();
JsUtils::ThrowException(env, IMFErrorCode::EXCEPTION_PARAMCHECK, "js param: direction covert failed",
JsUtils::ThrowException(env, IMFErrorCode::EXCEPTION_PARAMCHECK, "js param direction covert failed",
TYPE_NONE);
return JsUtil::Const::Null(env);
}
@ -741,10 +759,11 @@ napi_value JsTextInputClientEngine::SelectByMovement(napi_env env, napi_callback
IMSA_HILOGD("run in");
auto ctxt = std::make_shared<SelectContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
PARAM_CHECK_RETURN(env, argc > 0, "should 1 or 2 parameters!", TYPE_NONE, napi_generic_failure);
PARAM_CHECK_RETURN(env, argc > 0, "at least one paramster is required", TYPE_NONE, napi_generic_failure);
napi_valuetype valueType = napi_undefined;
napi_typeof(env, argv[0], &valueType);
PARAM_CHECK_RETURN(env, valueType == napi_object, "movement", TYPE_OBJECT, napi_generic_failure);
PARAM_CHECK_RETURN(env, valueType == napi_object, "param movement type must be Movement", TYPE_NONE,
napi_generic_failure);
auto status = GetSelectMovement(env, argv[0], ctxt);
if (status == napi_ok) {
ctxt->info = { std::chrono::system_clock::now(), EditorEvent::SELECT_BY_MOVEMENT };
@ -774,11 +793,13 @@ napi_value JsTextInputClientEngine::SendExtendAction(napi_env env, napi_callback
{
auto ctxt = std::make_shared<SendExtendActionContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
PARAM_CHECK_RETURN(env, argc > 0, "should 1 or 2 parameters!", TYPE_NONE, napi_generic_failure);
PARAM_CHECK_RETURN(env, argc > 0, "at least one paramster is required", TYPE_NONE, napi_generic_failure);
auto status = JsUtils::GetValue(env, argv[0], ctxt->action);
if (status == napi_ok) {
ctxt->info = { std::chrono::system_clock::now(), EditorEvent::SEND_EXTEND_ACTION };
editorQueue_.Push(ctxt->info);
} else {
ctxt->SetErrorMessage("action must be number and should in ExtendAction");
}
return status;
};
@ -985,12 +1006,13 @@ napi_status JsTextInputClientEngine::GetPreviewTextParam(
napi_env env, size_t argc, napi_value *argv, std::string &text, Range &range)
{
// 2 means JsAPI:setPreviewText needs 2 params at least.
PARAM_CHECK_RETURN(env, argc >= 2, "at least 2 params", TYPE_NONE, napi_generic_failure);
PARAM_CHECK_RETURN(env, JsUtil::GetValue(env, argv[0], text), "js param: text covert failed",
PARAM_CHECK_RETURN(env, argc >= 2, "at least two paramsters is required", TYPE_NONE, napi_generic_failure);
PARAM_CHECK_RETURN(env, JsUtil::GetValue(env, argv[0], text), "js param text covert failed, must be string",
TYPE_NONE, napi_generic_failure);
PARAM_CHECK_RETURN(env, JsUtil::GetType(env, argv[1]) == napi_object, "param range type must be Range",
TYPE_NONE, napi_generic_failure);
PARAM_CHECK_RETURN(env, JsUtil::GetType(env, argv[1]) == napi_object, "range", TYPE_OBJECT, napi_generic_failure);
PARAM_CHECK_RETURN(env, JsRange::Read(env, argv[1], range),
"js param covert failed, the Rang should have start and end", TYPE_NONE, napi_generic_failure);
"js param range covert failed, the range should have numbers start and end", TYPE_NONE, napi_generic_failure);
return napi_ok;
}

View File

@ -345,11 +345,11 @@ napi_value JsGetInputMethodController::Subscribe(napi_env env, napi_callback_inf
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data));
std::string type;
// 2 means least param num.
PARAM_CHECK_RETURN(env, argc >= 2, "At least 2 params", TYPE_NONE, nullptr);
PARAM_CHECK_RETURN(env, JsUtil::GetValue(env, argv[0], type), "js param: type covert failed",
PARAM_CHECK_RETURN(env, argc >= 2, "at least two paramsters is required", TYPE_NONE, nullptr);
PARAM_CHECK_RETURN(env, JsUtil::GetValue(env, argv[0], type), "js param type covert failed, must be string",
TYPE_NONE, nullptr);
PARAM_CHECK_RETURN(env, EventChecker::IsValidEventType(EventSubscribeModule::INPUT_METHOD_CONTROLLER, type),
"EventType verification failed ,should be CONTROLLER type", TYPE_NONE, nullptr);
"type verification failed, review the instructions and fill in the fixed values", TYPE_NONE, nullptr);
PARAM_CHECK_RETURN(env, JsUtil::GetType(env, argv[1]) == napi_function, "callback", TYPE_FUNCTION, nullptr);
IMSA_HILOGD("Subscribe type:%{public}s.", type.c_str());
if (TEXT_EVENT_TYPE.find(type) != TEXT_EVENT_TYPE.end()) {
@ -496,9 +496,9 @@ bool JsGetInputMethodController::GetValue(napi_env env, napi_value in, TextConfi
{
napi_value attributeResult = nullptr;
napi_status status = JsUtils::GetValue(env, in, "inputAttribute", attributeResult);
CHECK_RETURN(status == napi_ok, "get inputAttribute", false);
CHECK_RETURN(status == napi_ok, "inputAttribute must be InputAttribute", false);
bool ret = JsGetInputMethodController::GetValue(env, attributeResult, out.inputAttribute);
CHECK_RETURN(ret, "get inputAttribute of TextConfig", ret);
CHECK_RETURN(ret, "inputAttribute of TextConfig must be valid", ret);
napi_value cursorInfoResult = nullptr;
status = JsUtils::GetValue(env, in, "cursorInfo", cursorInfoResult);
@ -520,25 +520,15 @@ bool JsGetInputMethodController::GetValue(napi_env env, napi_value in, TextConfi
return ret;
}
bool JsGetInputMethodController::ParseAttachInput(
napi_env env, size_t argc, napi_value *argv, const std::shared_ptr<AttachContext> &ctxt)
{
// 0 means the first parameter: showkeyboard
bool ret = JsUtil::GetValue(env, argv[0], ctxt->showKeyboard);
IMSA_HILOGE("get showKeyboard end, ret = %{public}d", ret);
// 1 means the second parameter: textConfig
return ret && JsGetInputMethodController::GetValue(env, argv[1], ctxt->textConfig);
}
napi_value JsGetInputMethodController::Attach(napi_env env, napi_callback_info info)
{
auto ctxt = std::make_shared<AttachContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
PARAM_CHECK_RETURN(env, argc > 1, "should 2 or 3 parameters!", TYPE_NONE, napi_generic_failure);
bool ret = ParseAttachInput(env, argc, argv, ctxt);
PARAM_CHECK_RETURN(env, ret, "attach verification failed. shoule contain showKeyboard and textConfig",
TYPE_NONE, napi_generic_failure);
PARAM_CHECK_RETURN(env, argc > 1, "at least two paramsters is required", TYPE_NONE, napi_generic_failure);
PARAM_CHECK_RETURN(env, JsUtil::GetValue(env, argv[0], ctxt->showKeyboard),
"js param showKeyboard covert failed, type must be boolean", TYPE_NONE, napi_generic_failure);
PARAM_CHECK_RETURN(env, JsGetInputMethodController::GetValue(env, argv[1], ctxt->textConfig),
"js param textConfig covert failed, type must be TextConfig", TYPE_NONE, napi_generic_failure);
return napi_ok;
};
auto exec = [ctxt, env](AsyncCall::Context *ctx) {
@ -577,11 +567,10 @@ napi_value JsGetInputMethodController::SetCallingWindow(napi_env env, napi_callb
{
auto ctxt = std::make_shared<SetCallingWindowContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
PARAM_CHECK_RETURN(env, argc > 0, "should 1 or 2 parameters!", TYPE_NONE, napi_generic_failure);
PARAM_CHECK_RETURN(env, argc > 0, "at least one paramster is required", TYPE_NONE, napi_generic_failure);
// 0 means the first parameter: windowId
napi_status status = JsUtils::GetValue(env, argv[0], ctxt->windID);
PARAM_CHECK_RETURN(env, status == napi_ok, "windID verification failed. shoule be number",
TYPE_NONE, status);
PARAM_CHECK_RETURN(env, status == napi_ok, "param windowId type must be number", TYPE_NONE, status);
return status;
};
auto exec = [ctxt](AsyncCall::Context *ctx) {
@ -608,11 +597,13 @@ napi_value JsGetInputMethodController::UpdateCursor(napi_env env, napi_callback_
{
auto ctxt = std::make_shared<UpdateCursorContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
PARAM_CHECK_RETURN(env, argc > 0, "should 1 or 2 parameters!", TYPE_NONE, napi_generic_failure);
PARAM_CHECK_RETURN(env, argc > 0, "at least one paramster is required", TYPE_NONE, napi_generic_failure);
// 0 means the first parameter: cursorInfo
PARAM_CHECK_RETURN(env, JsUtil::GetType(env, argv[0]) == napi_object,
"param cursorInfo type must be CursorInfo", TYPE_NONE, napi_generic_failure);
bool ret = JsGetInputMethodController::GetValue(env, argv[0], ctxt->cursorInfo);
PARAM_CHECK_RETURN(env, ret, "cursorInfo verification failed. should contain 4 number", TYPE_NONE,
napi_generic_failure);
PARAM_CHECK_RETURN(env, ret, "param cursorInfo covert failed, must contain four numbers",
TYPE_NONE, napi_generic_failure);
return napi_ok;
};
auto exec = [ctxt](AsyncCall::Context *ctx) {
@ -631,13 +622,13 @@ napi_value JsGetInputMethodController::ChangeSelection(napi_env env, napi_callba
{
std::shared_ptr<ChangeSelectionContext> ctxt = std::make_shared<ChangeSelectionContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
PARAM_CHECK_RETURN(env, argc > 2, "should 3 or 4 parameters!", TYPE_NONE, napi_generic_failure);
PARAM_CHECK_RETURN(env, JsUtil::GetValue(env, argv[0], ctxt->text), "text verification failed",
TYPE_NONE, napi_generic_failure);
PARAM_CHECK_RETURN(env, JsUtil::GetValue(env, argv[1], ctxt->start), "start verification failed",
TYPE_NONE, napi_generic_failure);
PARAM_CHECK_RETURN(env, JsUtil::GetValue(env, argv[2], ctxt->end), "end verification failed",
TYPE_NONE, napi_generic_failure);
PARAM_CHECK_RETURN(env, argc > 2, "at least three paramsters is required", TYPE_NONE, napi_generic_failure);
PARAM_CHECK_RETURN(env, JsUtil::GetValue(env, argv[0], ctxt->text),
"param text type must be string", TYPE_NONE, napi_generic_failure);
PARAM_CHECK_RETURN(env, JsUtil::GetValue(env, argv[1], ctxt->start),
"param start type must be number", TYPE_NONE, napi_generic_failure);
PARAM_CHECK_RETURN(env, JsUtil::GetValue(env, argv[2], ctxt->end),
"param end type must be number", TYPE_NONE, napi_generic_failure);
return napi_ok;
};
auto exec = [ctxt](AsyncCall::Context *ctx) {
@ -662,9 +653,9 @@ napi_value JsGetInputMethodController::UpdateAttribute(napi_env env, napi_callba
{
auto ctxt = std::make_shared<UpdateAttributeContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
PARAM_CHECK_RETURN(env, argc > 0, "should 1 or 2 parameters!", TYPE_NONE, napi_generic_failure);
PARAM_CHECK_RETURN(env, argc > 0, "at least one paramster is required", TYPE_NONE, napi_generic_failure);
bool ret = JsGetInputMethodController::GetValue(env, argv[0], ctxt->attribute);
PARAM_CHECK_RETURN(env, ret, "paramters of updateAttribute verification failed",
PARAM_CHECK_RETURN(env, ret, "param attribute type must be InputAttribute",
TYPE_NONE, napi_generic_failure);
ctxt->configuration.SetTextInputType(static_cast<TextInputType>(ctxt->attribute.inputPattern));
ctxt->configuration.SetEnterKeyType(static_cast<EnterKeyType>(ctxt->attribute.enterKeyType));

View File

@ -195,8 +195,6 @@ private:
static napi_value CreateSendFunctionKey(napi_env env, int32_t functionKey);
void RegisterListener(napi_value callback, std::string type, std::shared_ptr<JSCallbackObject> callbackObj);
void UnRegisterListener(napi_value callback, std::string type);
static bool ParseAttachInput(
napi_env env, size_t argc, napi_value *argv, const std::shared_ptr<AttachContext> &ctxt);
static bool GetValue(napi_env env, napi_value in, CursorInfo &out);
static bool GetValue(napi_env env, napi_value in, InputAttribute &out);
static bool GetValue(napi_env env, napi_value in, TextConfig &out);

View File

@ -164,7 +164,8 @@ napi_status JsGetInputMethodSetting::GetInputMethodProperty(
{
napi_valuetype valueType = napi_undefined;
napi_typeof(env, argv, &valueType);
PARAM_CHECK_RETURN(env, valueType == napi_object, "inputMethodProperty", TYPE_OBJECT, napi_invalid_arg);
PARAM_CHECK_RETURN(env, valueType == napi_object, "param inputMethodProperty type must be InputMethodProperty",
TYPE_NONE, napi_invalid_arg);
napi_value result = nullptr;
napi_get_named_property(env, argv, "name", &result);
JsUtils::GetValue(env, result, ctxt->property.name);
@ -183,7 +184,7 @@ napi_status JsGetInputMethodSetting::GetInputMethodProperty(
JsUtils::GetValue(env, result, ctxt->property.id);
}
PARAM_CHECK_RETURN(env, (!ctxt->property.name.empty() && !ctxt->property.id.empty()),
"name and id should not empty", TYPE_NONE, napi_invalid_arg);
"name and id must be string and cannot empty", TYPE_NONE, napi_invalid_arg);
IMSA_HILOGD("methodId:%{public}s, packageName:%{public}s", ctxt->property.id.c_str(), ctxt->property.name.c_str());
return napi_ok;
}
@ -221,11 +222,11 @@ napi_value JsGetInputMethodSetting::GetInputMethods(napi_env env, napi_callback_
IMSA_HILOGD("run in GetInputMethods");
auto ctxt = std::make_shared<ListInputContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
PARAM_CHECK_RETURN(env, argc > 0, "should has one parameter.", TYPE_NONE, napi_invalid_arg);
PARAM_CHECK_RETURN(env, argc > 0, "at least one paramster is required", TYPE_NONE, napi_invalid_arg);
bool enable = false;
// 0 means first param index
napi_status status = JsUtils::GetValue(env, argv[0], enable);
PARAM_CHECK_RETURN(env, status == napi_ok, "enable", TYPE_NUMBER, napi_invalid_arg);
PARAM_CHECK_RETURN(env, status == napi_ok, "param enable type must be boolean", TYPE_NONE, napi_invalid_arg);
ctxt->inputMethodStatus = enable ? InputMethodStatus::ENABLE : InputMethodStatus::DISABLE;
return napi_ok;
};
@ -259,8 +260,8 @@ napi_value JsGetInputMethodSetting::GetInputMethodsSync(napi_env env, napi_callb
bool enable = false;
// 0 means first param index
PARAM_CHECK_RETURN(env, argc >= 1, "At least 1 param", TYPE_NONE, JsUtil::Const::Null(env));
PARAM_CHECK_RETURN(env, JsUtils::GetValue(env, argv[0], enable) == napi_ok, "Failed to get param, should be bool",
PARAM_CHECK_RETURN(env, argc >= 1, "at least one paramster is required", TYPE_NONE, JsUtil::Const::Null(env));
PARAM_CHECK_RETURN(env, JsUtils::GetValue(env, argv[0], enable) == napi_ok, "param enable type must be boolean",
TYPE_NONE, JsUtil::Const::Null(env));
std::vector<Property> properties;
@ -365,10 +366,11 @@ napi_value JsGetInputMethodSetting::ListInputMethodSubtype(napi_env env, napi_ca
IMSA_HILOGD("run in ListInputMethodSubtype");
auto ctxt = std::make_shared<ListInputContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
PARAM_CHECK_RETURN(env, argc > 0, "should has one parameter.", TYPE_NONE, napi_invalid_arg);
PARAM_CHECK_RETURN(env, argc > 0, "at least one paramster is required", TYPE_NONE, napi_invalid_arg);
napi_valuetype valueType = napi_undefined;
napi_typeof(env, argv[0], &valueType);
PARAM_CHECK_RETURN(env, valueType == napi_object, "inputMethodProperty", TYPE_OBJECT, napi_invalid_arg);
PARAM_CHECK_RETURN(env, valueType == napi_object, "param inputMethodProperty type must be InputMethodProperty",
TYPE_NONE, napi_invalid_arg);
napi_status status = JsGetInputMethodSetting::GetInputMethodProperty(env, argv[0], ctxt);
return status;
};
@ -427,15 +429,16 @@ napi_value JsGetInputMethodSetting::IsPanelShown(napi_env env, napi_callback_inf
napi_value argv[1] = { nullptr };
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
// 1 means least param num
PARAM_CHECK_RETURN(env, argc >= 1, "should has 1 parameter!", TYPE_NONE, JsUtil::Const::Null(env));
PARAM_CHECK_RETURN(env, argc >= 1, "at least one paramster is required", TYPE_NONE, JsUtil::Const::Null(env));
// 0 means parameter of info<PanelInfo>
napi_valuetype valueType = napi_undefined;
napi_typeof(env, argv[0], &valueType);
PARAM_CHECK_RETURN(env, valueType == napi_object, "panelInfo", TYPE_OBJECT, JsUtil::Const::Null(env));
PARAM_CHECK_RETURN(env, valueType == napi_object, "param panelInfo type must be PanelInfo", TYPE_NONE,
JsUtil::Const::Null(env));
PanelInfo panelInfo;
napi_status status = JsUtils::GetValue(env, argv[0], panelInfo);
PARAM_CHECK_RETURN(env, status == napi_ok, "PanelInfo should contain PanelType and PanelFlag",
PARAM_CHECK_RETURN(env, status == napi_ok, "js param panelInfo covert failed",
TYPE_NONE, JsUtil::Const::Null(env));
bool isShown = false;

View File

@ -72,7 +72,7 @@ napi_status JsInputMethod::GetInputMethodProperty(
CHECK_RETURN(status == napi_ok, "get ctxt->methodId failed!", status);
}
PARAM_CHECK_RETURN(env, (!ctxt->packageName.empty() && !ctxt->methodId.empty()),
"packageName and methodId is empty", TYPE_NONE, napi_invalid_arg);
"param packageName and methodId is empty", TYPE_NONE, napi_invalid_arg);
IMSA_HILOGD("methodId:%{public}s, packageName:%{public}s", ctxt->methodId.c_str(), ctxt->packageName.c_str());
return napi_ok;
}
@ -233,11 +233,11 @@ napi_value JsInputMethod::SwitchInputMethod(napi_env env, napi_callback_info inf
{
auto ctxt = std::make_shared<SwitchInputMethodContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
PARAM_CHECK_RETURN(env, argc > 0, "at least 1 parameter", TYPE_NONE, napi_invalid_arg);
PARAM_CHECK_RETURN(env, argc > 0, "at least one paramster is required", TYPE_NONE, napi_invalid_arg);
napi_valuetype valueType = napi_undefined;
napi_typeof(env, argv[0], &valueType);
PARAM_CHECK_RETURN(env, valueType == napi_object || valueType == napi_string, "type must be object or string",
TYPE_NONE, napi_invalid_arg);
PARAM_CHECK_RETURN(env, valueType == napi_object || valueType == napi_string,
"when param is target/bundleName type must be InputMethodProperty/string", TYPE_NONE, napi_invalid_arg);
napi_status status = napi_generic_failure;
if (valueType == napi_object) {
ctxt->trigger = SwitchTrigger::CURRENT_IME;
@ -331,10 +331,11 @@ napi_value JsInputMethod::SwitchCurrentInputMethodSubtype(napi_env env, napi_cal
{
auto ctxt = std::make_shared<SwitchInputMethodContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
PARAM_CHECK_RETURN(env, argc > 0, "should has one parameter. ", TYPE_NONE, napi_invalid_arg);
PARAM_CHECK_RETURN(env, argc > 0, "at least one paramster is required", TYPE_NONE, napi_invalid_arg);
napi_valuetype valueType = napi_undefined;
napi_typeof(env, argv[0], &valueType);
PARAM_CHECK_RETURN(env, valueType == napi_object, "inputMethodSubtype: ", TYPE_OBJECT, napi_object_expected);
PARAM_CHECK_RETURN(env, valueType == napi_object, "param target type must be InputMethodSubtype",
TYPE_NONE, napi_invalid_arg);
napi_status status = GetInputMethodSubProperty(env, argv[0], ctxt);
return status;
};
@ -365,12 +366,14 @@ napi_value JsInputMethod::SwitchCurrentInputMethodAndSubtype(napi_env env, napi_
{
auto ctxt = std::make_shared<SwitchInputMethodContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
PARAM_CHECK_RETURN(env, argc > 1, "should has two parameter.", TYPE_NONE, napi_invalid_arg);
PARAM_CHECK_RETURN(env, argc > 1, "at least two paramsters is required", TYPE_NONE, napi_invalid_arg);
napi_valuetype valueType = napi_undefined;
napi_typeof(env, argv[0], &valueType);
PARAM_CHECK_RETURN(env, valueType == napi_object, "inputMethodProperty: ", TYPE_OBJECT, napi_object_expected);
PARAM_CHECK_RETURN(env, valueType == napi_object, "param inputMethodProperty type must be InputMethodProperty",
TYPE_NONE, napi_invalid_arg);
napi_typeof(env, argv[1], &valueType);
PARAM_CHECK_RETURN(env, valueType == napi_object, "inputMethodSubtype: ", TYPE_OBJECT, napi_object_expected);
PARAM_CHECK_RETURN(env, valueType == napi_object, "param inputMethodSubtype type must be InputMethodSubtype",
TYPE_NONE, napi_invalid_arg);
napi_status status = GetInputMethodSubProperty(env, argv[1], ctxt);
return status;
};

View File

@ -117,7 +117,6 @@ public:
static napi_value GetValue(napi_env env, const InputWindowInfo &in);
static napi_value GetJsPrivateCommand(napi_env env, const std::unordered_map<std::string, PrivateDataValue> &in);
static napi_status GetValue(napi_env env, const std::string &in, napi_value &out);
static napi_status GetValue(napi_env env, napi_value in, PanelFlag &out);
private:
static const std::string ToMessage(int32_t code);

View File

@ -189,12 +189,12 @@ napi_value JsKeyboardPanelManager::SendPrivateCommand(napi_env env, napi_callbac
{
auto ctxt = std::make_shared<SendPrivateCommandContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
PARAM_CHECK_RETURN(env, argc > 0, "should 1 parameter!", TYPE_NONE, napi_generic_failure);
PARAM_CHECK_RETURN(env, argc > 0, "at least one paramster is required", TYPE_NONE, napi_generic_failure);
CHECK_RETURN(JsUtils::GetValue(env, argv[0], ctxt->privateCommand) == napi_ok,
"GetValue privateCommand error", napi_generic_failure);
"param commandData covert failed, type must be Record<string, CommandDataType>", napi_generic_failure);
if (!TextConfig::IsPrivateCommandValid(ctxt->privateCommand)) {
PARAM_CHECK_RETURN(
env, false, "privateCommand size limit 32KB, count limit 5.", TYPE_NONE, napi_generic_failure);
env, false, "commandData size limit 32KB, count limit 5.", TYPE_NONE, napi_generic_failure);
}
ctxt->info = { std::chrono::system_clock::now(), ctxt->privateCommand };
privateCommandQueue_.Push(ctxt->info);

View File

@ -84,7 +84,7 @@ private:
struct UvEntry {
std::vector<std::shared_ptr<JSCallbackObject>> vecCopy;
std::string type;
bool shouldSysPanelShow;
bool shouldSysPanelShow = false;
std::string smartMenu;
std::unordered_map<std::string, PrivateDataValue> privateCommand;
explicit UvEntry(const std::vector<std::shared_ptr<JSCallbackObject>> &cbVec, const std::string &type)

View File

@ -45,6 +45,8 @@ ohos_shared_library("inputmethod_extension") {
"-Os",
]
include_dirs = [
"${inputmethod_path}/frameworks/js/napi/common",
"${inputmethod_path}/frameworks/js/napi/inputmethodclient",
"${inputmethod_path}/frameworks/kits/extension/include",
"${inputmethod_path}/frameworks/native/inputmethod_controller/include",
"${inputmethod_path}/interfaces/inner_api/inputmethod_controller/include",
@ -52,6 +54,7 @@ ohos_shared_library("inputmethod_extension") {
]
sources = [
"${inputmethod_path}/frameworks/js/napi/inputmethodclient/js_utils.cpp",
"${inputmethod_path}/frameworks/kits/extension/src/inputmethod_extension.cpp",
"${inputmethod_path}/frameworks/kits/extension/src/inputmethod_extension_context.cpp",
"${inputmethod_path}/frameworks/kits/extension/src/js_inputmethod_extension.cpp",
@ -62,6 +65,7 @@ ohos_shared_library("inputmethod_extension") {
deps = [
"${inputmethod_path}/common:inputmethod_common",
"${inputmethod_path}/frameworks/js/napi/common:inputmethod_js_common",
"${inputmethod_path}/interfaces/inner_api/inputmethod_ability:inputmethod_ability",
]

View File

@ -23,6 +23,8 @@
#include "js_extension_context.h"
#include "js_runtime.h"
#include "js_runtime_utils.h"
#include "js_util.h"
#include "js_utils.h"
#include "napi/native_api.h"
#include "napi_common_start_options.h"
#include "napi_common_util.h"
@ -32,6 +34,7 @@
namespace OHOS {
namespace AbilityRuntime {
using namespace OHOS::MiscServices;
namespace {
constexpr int32_t INDEX_ZERO = 0;
constexpr int32_t INDEX_ONE = 1;
@ -98,9 +101,12 @@ private:
// only support one or two or three params
if (argc != ARGC_ONE && argc != ARGC_TWO && argc != ARGC_THREE) {
IMSA_HILOGE("Not enough params");
JsUtils::ThrowException(env, IMFErrorCode::EXCEPTION_PARAMCHECK, "number of param should in [1,3]",
TYPE_NONE);
return CreateJsUndefined(env);
}
PARAM_CHECK_RETURN(env, JsUtil::GetType(env, argv[0]) == napi_object, "param want type must be Want",
TYPE_NONE, JsUtil::Const::Null(env));
decltype(argc) unwrapArgc = 0;
AAFwk::Want want;
OHOS::AppExecFwk::UnwrapWant(env, argv[INDEX_ZERO], want);

View File

@ -165,7 +165,7 @@ int32_t InputMethodPanel::MoveTo(int32_t x, int32_t y)
}
auto ret = window_->MoveTo(x, y);
IMSA_HILOGI("x/y: %{public}d/%{public}d, ret = %{public}d", x, y, ret);
return ret == WMError::WM_OK ? ErrorCode::NO_ERROR : ErrorCode::ERROR_OPERATE_PANEL;
return ret == WMError::WM_ERROR_INVALID_PARAM ? ErrorCode::ERROR_PARAMETER_CHECK_FAILED : ErrorCode::NO_ERROR;
}
int32_t InputMethodPanel::AdjustPanelRect(PanelFlag &panelFlag, const LayoutParams &layoutParams)
@ -298,20 +298,20 @@ int32_t InputMethodPanel::CalculatePanelRect(PanelFlag &panelFlag, PanelAdjustIn
keyboardLayoutParams_.PortraitPanelRect_.width_ = portraitDisplaySize.width;
keyboardLayoutParams_.PortraitPanelRect_.height_ =
layoutParams.portraitRect.height_ +
(porIterValue.top + porIterValue.bottom) * (densityDpi / DPI_CALCULATION_RATIO);
static_cast<uint32_t>((porIterValue.top + porIterValue.bottom) * (densityDpi / DPI_CALCULATION_RATIO));
if (keyboardLayoutParams_.PortraitPanelRect_.height_ >
portraitDisplaySize.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO) {
keyboardLayoutParams_.PortraitPanelRect_.height_ =
portraitDisplaySize.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO;
}
keyboardLayoutParams_.PortraitPanelRect_.posY_ = portraitDisplaySize.height -
keyboardLayoutParams_.PortraitPanelRect_.height_;
keyboardLayoutParams_.PortraitPanelRect_.posY_ = static_cast<int32_t>(portraitDisplaySize.height -
keyboardLayoutParams_.PortraitPanelRect_.height_);
keyboardLayoutParams_.PortraitPanelRect_.posX_ = NUMBER_ZERO;
//fixed Portraitkeyboard
keyboardLayoutParams_.PortraitKeyboardRect_.width_ = keyboardLayoutParams_.PortraitPanelRect_.width_ -
(porIterValue.left + porIterValue.right) * (densityDpi / DPI_CALCULATION_RATIO);
static_cast<uint32_t>((porIterValue.left + porIterValue.right) * (densityDpi / DPI_CALCULATION_RATIO));
keyboardLayoutParams_.PortraitKeyboardRect_.height_ = keyboardLayoutParams_.PortraitPanelRect_.height_ -
(porIterValue.top + porIterValue.bottom) * (densityDpi / DPI_CALCULATION_RATIO);
static_cast<uint32_t>((porIterValue.top + porIterValue.bottom) * (densityDpi / DPI_CALCULATION_RATIO));
keyboardLayoutParams_.PortraitKeyboardRect_.posY_ = keyboardLayoutParams_.PortraitPanelRect_.posY_ +
porIterValue.top * (densityDpi / DPI_CALCULATION_RATIO);
keyboardLayoutParams_.PortraitKeyboardRect_.posX_ = keyboardLayoutParams_.PortraitPanelRect_.posX_ +
@ -332,9 +332,9 @@ void InputMethodPanel::CalculateFaloatRect(const LayoutParams &layoutParams, Pan
keyboardLayoutParams_.PortraitKeyboardRect_.posX_ = layoutParams.portraitRect.posX_;
//portrait floating panel
keyboardLayoutParams_.PortraitPanelRect_.width_ = keyboardLayoutParams_.PortraitKeyboardRect_.width_ +
(porIterValue.left + porIterValue.right) * (densityDpi / DPI_CALCULATION_RATIO);
static_cast<uint32_t>((porIterValue.left + porIterValue.right) * (densityDpi / DPI_CALCULATION_RATIO));
keyboardLayoutParams_.PortraitPanelRect_.height_ = keyboardLayoutParams_.PortraitKeyboardRect_.height_ +
(porIterValue.top + porIterValue.bottom) * (densityDpi / DPI_CALCULATION_RATIO);
static_cast<uint32_t>((porIterValue.top + porIterValue.bottom) * (densityDpi / DPI_CALCULATION_RATIO));
keyboardLayoutParams_.PortraitPanelRect_.posY_ = keyboardLayoutParams_.PortraitKeyboardRect_.posY_ -
porIterValue.top * (densityDpi / DPI_CALCULATION_RATIO);
keyboardLayoutParams_.PortraitPanelRect_.posX_ = keyboardLayoutParams_.PortraitKeyboardRect_.posX_ -
@ -347,9 +347,9 @@ void InputMethodPanel::CalculateFaloatRect(const LayoutParams &layoutParams, Pan
keyboardLayoutParams_.LandscapeKeyboardRect_.posX_ = layoutParams.landscapeRect.posX_;
//landscape floating panel
keyboardLayoutParams_.LandscapePanelRect_.width_ = keyboardLayoutParams_.LandscapeKeyboardRect_.width_ +
(lanIterValue.left + lanIterValue.right) * (densityDpi / DPI_CALCULATION_RATIO);
static_cast<uint32_t>((lanIterValue.left + lanIterValue.right) * (densityDpi / DPI_CALCULATION_RATIO));
keyboardLayoutParams_.LandscapePanelRect_.height_ = keyboardLayoutParams_.LandscapeKeyboardRect_.height_ +
(lanIterValue.top + lanIterValue.bottom) * (densityDpi / DPI_CALCULATION_RATIO);
static_cast<uint32_t>((lanIterValue.top + lanIterValue.bottom) * (densityDpi / DPI_CALCULATION_RATIO));
keyboardLayoutParams_.LandscapePanelRect_.posY_ = keyboardLayoutParams_.LandscapeKeyboardRect_.posY_ -
lanIterValue.top * (densityDpi / DPI_CALCULATION_RATIO);
keyboardLayoutParams_.LandscapePanelRect_.posX_ = keyboardLayoutParams_.LandscapeKeyboardRect_.posX_ -
@ -374,14 +374,14 @@ int32_t InputMethodPanel::CalculateLandscapeRect(sptr<OHOS::Rosen::Display> &def
keyboardLayoutParams_.LandscapePanelRect_.height_ =
landscapeDisplaySize.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO;
}
keyboardLayoutParams_.LandscapePanelRect_.posY_ = landscapeDisplaySize.height -
keyboardLayoutParams_.LandscapePanelRect_.height_;
keyboardLayoutParams_.LandscapePanelRect_.posY_ = static_cast<int32_t>(landscapeDisplaySize.height -
keyboardLayoutParams_.LandscapePanelRect_.height_);
keyboardLayoutParams_.LandscapePanelRect_.posX_ = NUMBER_ZERO;
//Landscapekeyboard
keyboardLayoutParams_.LandscapeKeyboardRect_.width_ = keyboardLayoutParams_.LandscapePanelRect_.width_ -
(lanIterValue.left + lanIterValue.right) * (densityDpi / DPI_CALCULATION_RATIO);
static_cast<uint32_t>((lanIterValue.left + lanIterValue.right) * (densityDpi / DPI_CALCULATION_RATIO));
keyboardLayoutParams_.LandscapeKeyboardRect_.height_ = keyboardLayoutParams_.LandscapePanelRect_.height_ -
(lanIterValue.top + lanIterValue.bottom) * (densityDpi / DPI_CALCULATION_RATIO);
static_cast<uint32_t>((lanIterValue.top + lanIterValue.bottom) * (densityDpi / DPI_CALCULATION_RATIO));
keyboardLayoutParams_.LandscapeKeyboardRect_.posY_ = keyboardLayoutParams_.LandscapePanelRect_.posY_ +
lanIterValue.top * (densityDpi / DPI_CALCULATION_RATIO);
keyboardLayoutParams_.LandscapeKeyboardRect_.posX_ = keyboardLayoutParams_.LandscapePanelRect_.posX_ +
@ -398,7 +398,7 @@ int32_t InputMethodPanel::CalculateLandscapeRect(sptr<OHOS::Rosen::Display> &def
keyboardLayoutParams_.LandscapeKeyboardRect_.width_ =
keyboardLayoutParams_.LandscapeKeyboardRect_.width_ - cutoutArea.height_ * NUMBER_TWO;
keyboardLayoutParams_.LandscapeKeyboardRect_.posX_ =
keyboardLayoutParams_.LandscapeKeyboardRect_.posX_ + cutoutArea.height_;
keyboardLayoutParams_.LandscapeKeyboardRect_.posX_ + static_cast<int32_t>(cutoutArea.height_);
}
}
}
@ -804,7 +804,7 @@ bool InputMethodPanel::GetDisplaySize(bool isPortrait, WindowSize &size)
}
bool isDisplayPortrait = defaultDisplay->GetRotation() == Rosen::Rotation::ROTATION_0 ||
defaultDisplay->GetRotation() == Rosen::Rotation::ROTATION_180;
if (isPortrait ^ isDisplayPortrait) {
if (!isPortrait != isDisplayPortrait) {
size = {.width = defaultDisplay->GetHeight(), .height = defaultDisplay->GetWidth()};
} else {
size = {.width = defaultDisplay->GetWidth(), .height = defaultDisplay->GetHeight()};