dts:sdk、doc及提示信息不完整

Signed-off-by: h30051954 <hemenghao2@huawei.com>
This commit is contained in:
h30051954 2024-05-20 16:38:04 +08:00
parent 685e8cb4ac
commit 9f22cf9459
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 ctxt = std::make_shared<PanelContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status { 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; napi_valuetype valueType = napi_undefined;
// 0 means parameter of ctx<BaseContext> // 0 means parameter of ctx<BaseContext>
napi_typeof(env, argv[0], &valueType); 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); napi_status status = GetContext(env, argv[0], ctxt->context);
if (status != napi_ok) { if (status != napi_ok) {
return status; return status;
} }
// 1 means parameter of info<PanelInfo> // 1 means parameter of info<PanelInfo>
napi_typeof(env, argv[1], &valueType); 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); 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; return status;
}; };
@ -427,15 +429,17 @@ napi_value JsInputMethodEngineSetting::DestroyPanel(napi_env env, napi_callback_
{ {
auto ctxt = std::make_shared<PanelContext>(); auto ctxt = std::make_shared<PanelContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status { 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_valuetype valueType = napi_undefined;
napi_typeof(env, argv[0], &valueType); 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; bool isPanel = false;
napi_value constructor = JsPanel::Init(env); napi_value constructor = JsPanel::Init(env);
CHECK_RETURN(constructor != nullptr, "Failed to get panel constructor.", napi_invalid_arg); CHECK_RETURN(constructor != nullptr, "Failed to get panel constructor.", napi_invalid_arg);
napi_status status = napi_instanceof(env, argv[0], constructor, &isPanel); 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; JsPanel *jsPanel = nullptr;
status = napi_unwrap(env, argv[0], (void **)(&jsPanel)); status = napi_unwrap(env, argv[0], (void **)(&jsPanel));
CHECK_RETURN((status == napi_ok) && (jsPanel != nullptr), "Can not unwrap to JsPanel!", status); CHECK_RETURN((status == napi_ok) && (jsPanel != nullptr), "Can not unwrap to JsPanel!", status);

View File

@ -108,10 +108,10 @@ napi_value JsPanel::SetUiContent(napi_env env, napi_callback_info info)
auto ctxt = std::make_shared<PanelContentContext>(env, 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 { auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
napi_status status = napi_generic_failure; 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> // 0 means the first param path<std::string>
status = JsUtils::GetValue(env, argv[0], ctxt->path); PARAM_CHECK_RETURN(env, JsUtils::GetValue(env, argv[0], ctxt->path) == napi_ok,
CHECK_RETURN(status == napi_ok, "get path failed!", status); "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 type of argv[1] is object, we will get value of 'storage' from it.
if (argc >= 2) { if (argc >= 2) {
napi_valuetype valueType = napi_undefined; napi_valuetype valueType = napi_undefined;
@ -137,6 +137,7 @@ napi_value JsPanel::SetUiContent(napi_env env, napi_callback_info info)
auto code = ctxt->inputMethodPanel->SetUiContent(ctxt->path, env, ctxt->contentStorage); auto code = ctxt->inputMethodPanel->SetUiContent(ctxt->path, env, ctxt->contentStorage);
if (code == ErrorCode::ERROR_PARAMETER_CHECK_FAILED) { if (code == ErrorCode::ERROR_PARAMETER_CHECK_FAILED) {
ctxt->SetErrorCode(code); ctxt->SetErrorCode(code);
ctxt->SetErrorMessage("path should be a path to specific page.");
return napi_generic_failure; return napi_generic_failure;
} }
return napi_ok; return napi_ok;
@ -152,13 +153,13 @@ napi_value JsPanel::Resize(napi_env env, napi_callback_info info)
auto ctxt = std::make_shared<PanelContentContext>(env, 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 { auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
napi_status status = napi_generic_failure; 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> // 0 means the first param width<uint32_t>
status = JsUtils::GetValue(env, argv[0], ctxt->width); PARAM_CHECK_RETURN(env, JsUtils::GetValue(env, argv[0], ctxt->width) == napi_ok,
CHECK_RETURN(status == napi_ok, "get width failed!", status); "param width type must be number", TYPE_NONE, status);
// 1 means the second param height<uint32_t> // 1 means the second param height<uint32_t>
status = JsUtils::GetValue(env, argv[1], ctxt->height); PARAM_CHECK_RETURN(env, JsUtils::GetValue(env, argv[1], ctxt->height) == napi_ok,
CHECK_RETURN(status == napi_ok, "get height failed!", status); "param height type must be number", TYPE_NONE, status);
return napi_ok; return napi_ok;
}; };
@ -183,24 +184,24 @@ napi_value JsPanel::MoveTo(napi_env env, napi_callback_info info)
auto ctxt = std::make_shared<PanelContentContext>(env, 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 { auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
napi_status status = napi_generic_failure; 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> // 0 means the first param x<int32_t>
status = JsUtils::GetValue(env, argv[0], ctxt->x); PARAM_CHECK_RETURN(env, JsUtils::GetValue(env, argv[0], ctxt->x) == napi_ok, "param x type must be number",
CHECK_RETURN(status == napi_ok, "get x failed!", status); TYPE_NONE, status);
// 1 means the second param y<int32_t> // 1 means the second param y<int32_t>
status = JsUtils::GetValue(env, argv[1], ctxt->y); PARAM_CHECK_RETURN(env, JsUtils::GetValue(env, argv[1], ctxt->y) == napi_ok, "param y type must be number",
CHECK_RETURN(status == napi_ok, "get y failed!", status); TYPE_NONE, status);
return napi_ok; return napi_ok;
}; };
auto exec = [ctxt](AsyncCall::Context *ctx) { auto exec = [ctxt](AsyncCall::Context *ctx) {
CHECK_RETURN_VOID(ctxt->inputMethodPanel != nullptr, "inputMethodPanel_ is nullptr."); CHECK_RETURN_VOID(ctxt->inputMethodPanel != nullptr, "inputMethodPanel_ is nullptr.");
auto code = ctxt->inputMethodPanel->MoveTo(ctxt->x, ctxt->y); auto code = ctxt->inputMethodPanel->MoveTo(ctxt->x, ctxt->y);
if (code == ErrorCode::NO_ERROR) { if (code == ErrorCode::ERROR_PARAMETER_CHECK_FAILED) {
ctxt->SetState(napi_ok); ctxt->SetErrorCode(code);
return; return;
} }
ctxt->SetErrorCode(code); ctxt->SetState(napi_ok);
}; };
ctxt->SetAction(std::move(input)); ctxt->SetAction(std::move(input));
// 3 means JsAPI:moveTo has 3 params at most. // 3 means JsAPI:moveTo has 3 params at most.
@ -248,12 +249,14 @@ napi_value JsPanel::ChangeFlag(napi_env env, napi_callback_info info)
napi_value argv[ARGC_MAX] = { nullptr }; napi_value argv[ARGC_MAX] = { nullptr };
napi_value thisVar = nullptr; napi_value thisVar = nullptr;
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &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; int32_t panelFlag = 0;
// 0 means the first param flag<PanelFlag> // 0 means the first param flag<PanelFlag>
napi_status status = JsUtils::GetValue(env, argv[0], 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); 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)); auto ret = inputMethodPanel->ChangePanelFlag(PanelFlag(panelFlag));
CHECK_RETURN(ret == ErrorCode::NO_ERROR, "ChangePanelFlag failed!", nullptr); CHECK_RETURN(ret == ErrorCode::NO_ERROR, "ChangePanelFlag failed!", nullptr);
InputMethodAbility::GetInstance()->NotifyKeyboardHeight(inputMethodPanel); InputMethodAbility::GetInstance()->NotifyKeyboardHeight(inputMethodPanel);
@ -266,14 +269,11 @@ napi_value JsPanel::SetPrivacyMode(napi_env env, napi_callback_info info)
napi_value argv[ARGC_MAX] = { nullptr }; napi_value argv[ARGC_MAX] = { nullptr };
napi_value thisVar = nullptr; napi_value thisVar = nullptr;
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &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; bool isPrivacyMode = false;
// 0 means the first param isPrivacyMode<boolean> // 0 means the first param isPrivacyMode<boolean>
napi_status status = JsUtils::GetValue(env, argv[0], isPrivacyMode); napi_status status = JsUtils::GetValue(env, argv[0], isPrivacyMode);
if (status != napi_ok) { PARAM_CHECK_RETURN(env, status == napi_ok, "param isPrivacyMode type must be boolean", TYPE_NONE, nullptr);
JsUtils::ThrowException(env, JsUtils::Convert(ErrorCode::ERROR_PARAMETER_CHECK_FAILED), " param check failed!",
TYPE_BOOLEAN);
}
CHECK_RETURN(status == napi_ok, "get isPrivacyMode failed!", nullptr); CHECK_RETURN(status == napi_ok, "get isPrivacyMode failed!", nullptr);
auto inputMethodPanel = UnwrapPanel(env, thisVar); auto inputMethodPanel = UnwrapPanel(env, thisVar);
auto ret = inputMethodPanel->SetPrivacyMode(isPrivacyMode); auto ret = inputMethodPanel->SetPrivacyMode(isPrivacyMode);
@ -323,15 +323,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)); NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr));
std::string type; std::string type;
// 1 means least param num. // 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( 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), 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 // if the second param is not napi_function/napi_null/napi_undefined, return
auto paramType = JsUtil::GetType(env, argv[1]); auto paramType = JsUtil::GetType(env, argv[1]);
PARAM_CHECK_RETURN(env, (paramType == napi_function || paramType == napi_null || paramType == napi_undefined), 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 // if the second param is napi_function, delete it, else delete all
argv[1] = paramType == napi_function ? argv[1] : nullptr; argv[1] = paramType == napi_function ? argv[1] : nullptr;
@ -350,20 +350,20 @@ napi_value JsPanel::AdjustPanelRect(napi_env env, napi_callback_info info)
auto ctxt = std::make_shared<PanelContentContext>(env, 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 { auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
napi_status status = napi_generic_failure; 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 // 0 means the first param flag
PARAM_CHECK_RETURN(env, JsUtil::GetType(env, argv[0]) == napi_number, "flag", PARAM_CHECK_RETURN(env, JsUtil::GetType(env, argv[0]) == napi_number, "flag",
TYPE_NUMBER, napi_generic_failure); TYPE_NUMBER, napi_generic_failure);
int32_t panelFlag = 0; int32_t panelFlag = 0;
CHECK_RETURN(JsUtils::GetValue(env, argv[0], panelFlag) == napi_ok, 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); ctxt->panelFlag = PanelFlag(panelFlag);
PARAM_CHECK_RETURN(env, ctxt->panelFlag == 0 || ctxt->panelFlag == 1, 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 // 1 means the second param rect
PARAM_CHECK_RETURN(env, JsUtil::GetType(env, argv[1]) == napi_object, "rect", TYPE_OBJECT, PARAM_CHECK_RETURN(env, JsUtil::GetType(env, argv[1]) == napi_object, "param rect type must be PanelRect",
napi_generic_failure); TYPE_NONE, napi_generic_failure);
PARAM_CHECK_RETURN(env, JsPanelRect::Read(env, argv[1], ctxt->layoutParams), "js param: rect covert failed", PARAM_CHECK_RETURN(env, JsPanelRect::Read(env, argv[1], ctxt->layoutParams), "js param rect covert failed",
TYPE_NONE, napi_generic_failure); TYPE_NONE, napi_generic_failure);
return napi_ok; return napi_ok;
}; };

View File

@ -57,7 +57,10 @@ public:
private: private:
struct PanelContentContext : public AsyncCall::Context { struct PanelContentContext : public AsyncCall::Context {
LayoutParams layoutParams; LayoutParams layoutParams = {
{0, 0, 0, 0},
{0, 0, 0, 0}
};
PanelFlag panelFlag = PanelFlag::FLG_FIXED; PanelFlag panelFlag = PanelFlag::FLG_FIXED;
std::string path = ""; std::string path = "";
uint32_t width = 0; 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 ctxt = std::make_shared<MoveCursorContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status { 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); 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) { if (status == napi_ok) {
ctxt->info = { std::chrono::system_clock::now(), EditorEvent::MOVE_CURSOR }; ctxt->info = { std::chrono::system_clock::now(), EditorEvent::MOVE_CURSOR };
editorQueue_.Push(ctxt->info); 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)); NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
int32_t direction = 0; int32_t direction = 0;
// 1 means least param num. // 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, PARAM_CHECK_RETURN(env, JsUtil::GetType(env, argv[0]) == napi_number, "direction", TYPE_NUMBER,
HandleParamCheckFailure(env)); HandleParamCheckFailure(env));
PARAM_CHECK_RETURN(env, JsUtil::GetValue(env, argv[0], direction), 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, PARAM_CHECK_RETURN(env, direction >= 0, "direction should be no less than 0", TYPE_NONE,
HandleParamCheckFailure(env)); HandleParamCheckFailure(env));
IMSA_HILOGD("moveCursor , direction: %{public}d", direction); 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_status status = napi_generic_failure;
napi_value napiValue = nullptr; napi_value napiValue = nullptr;
status = napi_get_named_property(env, argv, "start", &napiValue); 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); status = JsUtils::GetValue(env, napiValue, ctxt->start);
CHECK_RETURN(status == napi_ok, "failed to get start value", status); CHECK_RETURN(status == napi_ok, "failed to get start value", status);
status = napi_get_named_property(env, argv, "end", &napiValue); 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); status = JsUtils::GetValue(env, napiValue, ctxt->end);
if (status != napi_ok) { if (status != napi_ok) {
IMSA_HILOGE("failed to get end value"); IMSA_HILOGE("failed to get end value");
@ -204,11 +209,12 @@ napi_status JsTextInputClientEngine::GetSelectMovement(
napi_status status = napi_generic_failure; napi_status status = napi_generic_failure;
napi_value napiValue = nullptr; napi_value napiValue = nullptr;
status = napi_get_named_property(env, argv, "direction", &napiValue); 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); status = JsUtils::GetValue(env, napiValue, ctxt->direction);
if (status != napi_ok) { if (status != napi_ok) {
IMSA_HILOGE("failed to get direction value"); 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; return status;
} }
@ -216,8 +222,10 @@ napi_value JsTextInputClientEngine::SendKeyFunction(napi_env env, napi_callback_
{ {
auto ctxt = std::make_shared<SendKeyFunctionContext>(); auto ctxt = std::make_shared<SendKeyFunctionContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status { 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);
return JsUtils::GetValue(env, argv[0], ctxt->action); 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 { auto output = [ctxt](napi_env env, napi_value *result) -> napi_status {
napi_status status = napi_get_boolean(env, ctxt->isSendKeyFunction, result); 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 ctxt = std::make_shared<SendPrivateCommandContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status { 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); napi_status status = JsUtils::GetValue(env, argv[0], ctxt->privateCommand);
CHECK_RETURN(status == napi_ok, "GetValue privateCommand error", status); CHECK_RETURN(status == napi_ok,
if (!TextConfig::IsPrivateCommandValid(ctxt->privateCommand)) { "param commandData covert failed, type must be Record<string, CommandDataType>", status);
JsUtils::ThrowException( PARAM_CHECK_RETURN(env, TextConfig::IsPrivateCommandValid(ctxt->privateCommand),
env, IMFErrorCode::EXCEPTION_PARAMCHECK, "privateCommand size limit 32KB, count limit 5.", TYPE_NONE); "commandData size limit 32KB, count limit 5.", TYPE_NONE, napi_generic_failure);
return napi_generic_failure;
}
ctxt->info = { std::chrono::system_clock::now(), ctxt->privateCommand }; ctxt->info = { std::chrono::system_clock::now(), ctxt->privateCommand };
privateCommandQueue_.Push(ctxt->info); privateCommandQueue_.Push(ctxt->info);
return status; 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)); NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
int32_t length = 0; int32_t length = 0;
// 1 means least param num. // 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, PARAM_CHECK_RETURN(env, JsUtil::GetType(env, argv[0]) == napi_number, "length", TYPE_NUMBER,
HandleParamCheckFailure(env)); 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)); TYPE_NONE, HandleParamCheckFailure(env));
PARAM_CHECK_RETURN(env, length >= 0, "length should no less than 0", 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); 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"); InputMethodSyncTrace tracer("JS_DeleteForward");
auto ctxt = std::make_shared<DeleteForwardContext>(); auto ctxt = std::make_shared<DeleteForwardContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status { 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); 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) { if (status == napi_ok) {
ctxt->info = { std::chrono::system_clock::now(), EditorEvent::DELETE_FORWARD }; ctxt->info = { std::chrono::system_clock::now(), EditorEvent::DELETE_FORWARD };
editorQueue_.Push(ctxt->info); 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)); NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
int32_t length = 0; int32_t length = 0;
// 1 means least param num. // 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, PARAM_CHECK_RETURN(env, JsUtil::GetType(env, argv[0]) == napi_number, "length", TYPE_NUMBER,
HandleParamCheckFailure(env)); 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)); TYPE_NONE, HandleParamCheckFailure(env));
PARAM_CHECK_RETURN(env, length >= 0, "length should no less than 0", 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); 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 ctxt = std::make_shared<DeleteBackwardContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status { 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); auto status = JsUtils::GetValue(env, argv[0], ctxt->length);
if (status == napi_ok) { if (status == napi_ok) {
ctxt->info = { std::chrono::system_clock::now(), EditorEvent::DELETE_BACKWARD }; 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"); InputMethodSyncTrace tracer("JS_InsertText");
auto ctxt = std::make_shared<InsertTextContext>(); auto ctxt = std::make_shared<InsertTextContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status { 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); auto status = JsUtils::GetValue(env, argv[0], ctxt->text);
if (status == napi_ok) { if (status == napi_ok) {
ctxt->info = { std::chrono::system_clock::now(), EditorEvent::INSERT_TEXT }; 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)); NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
std::string text; std::string text;
// 1 means least param num. // 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, PARAM_CHECK_RETURN(env, JsUtil::GetType(env, argv[0]) == napi_string, "text", TYPE_STRING,
HandleParamCheckFailure(env)); 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)); TYPE_NONE, HandleParamCheckFailure(env));
IMSA_HILOGD("insert text , text: %{public}s", text.c_str()); IMSA_HILOGD("insert text , text: %{public}s", text.c_str());
int32_t ret = InputMethodAbility::GetInstance()->InsertText(text); 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)); NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
int32_t length = 0; int32_t length = 0;
// 1 means least param num. // 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, PARAM_CHECK_RETURN(env, JsUtil::GetType(env, argv[0]) == napi_number, "length", TYPE_NUMBER,
HandleParamCheckFailure(env)); 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)); TYPE_NONE, HandleParamCheckFailure(env));
PARAM_CHECK_RETURN(env, length >= 0, "length should no less than 0", 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); 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"); InputMethodSyncTrace tracer("JS_GetForward");
auto ctxt = std::make_shared<GetForwardContext>(); auto ctxt = std::make_shared<GetForwardContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status { 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); auto status = JsUtils::GetValue(env, argv[0], ctxt->length);
if (status == napi_ok) { if (status == napi_ok) {
ctxt->info = { std::chrono::system_clock::now(), EditorEvent::GET_FORWARD }; 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)); NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
int32_t length = 0; int32_t length = 0;
// 1 means least param num. // 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, PARAM_CHECK_RETURN(env, JsUtil::GetType(env, argv[0]) == napi_number, "length", TYPE_NUMBER,
HandleParamCheckFailure(env)); 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)); TYPE_NONE, HandleParamCheckFailure(env));
PARAM_CHECK_RETURN(env, length >= 0, "length should no less than 0", 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); 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 ctxt = std::make_shared<GetBackwardContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status { 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); auto status = JsUtils::GetValue(env, argv[0], ctxt->length);
if (status == napi_ok) { if (status == napi_ok) {
ctxt->info = { std::chrono::system_clock::now(), EditorEvent::GET_BACKWARD }; 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"); IMSA_HILOGD("run in");
auto ctxt = std::make_shared<SelectContext>(); auto ctxt = std::make_shared<SelectContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status { 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_valuetype valueType = napi_undefined;
napi_typeof(env, argv[0], &valueType); 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); auto status = GetSelectRange(env, argv[0], ctxt);
if (status == napi_ok) { if (status == napi_ok) {
ctxt->info = { std::chrono::system_clock::now(), EditorEvent::SELECT_BY_RANGE }; 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; size_t argc = 1;
napi_value argv[1] = { nullptr }; napi_value argv[1] = { nullptr };
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, 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, argc >= 1, "at least one paramster is required", TYPE_NONE, HandleParamCheckFailure(env));
PARAM_CHECK_RETURN(env, JsUtil::GetType(env, argv[0]) == napi_object, "range", TYPE_OBJECT, PARAM_CHECK_RETURN(env, JsUtil::GetType(env, argv[0]) == napi_object, "param range type must be Range", TYPE_NONE,
HandleParamCheckFailure(env)); HandleParamCheckFailure(env));
auto ctxt = std::make_shared<SelectContext>(); auto ctxt = std::make_shared<SelectContext>();
auto status = GetSelectRange(env, argv[0], ctxt); auto status = GetSelectRange(env, argv[0], ctxt);
@ -716,14 +734,14 @@ napi_value JsTextInputClientEngine::SelectByMovementSync(napi_env env, napi_call
size_t argc = 1; size_t argc = 1;
napi_value argv[1] = { nullptr }; napi_value argv[1] = { nullptr };
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, 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, argc >= 1, "at least one paramster is required", TYPE_NONE, HandleParamCheckFailure(env));
PARAM_CHECK_RETURN(env, JsUtil::GetType(env, argv[0]) == napi_object, "direction", TYPE_OBJECT, PARAM_CHECK_RETURN(env, JsUtil::GetType(env, argv[0]) == napi_object, "param movement type must be Movement",
HandleParamCheckFailure(env)); TYPE_NONE, HandleParamCheckFailure(env));
auto ctxt = std::make_shared<SelectContext>(); auto ctxt = std::make_shared<SelectContext>();
auto status = GetSelectMovement(env, argv[0], ctxt); auto status = GetSelectMovement(env, argv[0], ctxt);
if (status != napi_ok) { if (status != napi_ok) {
editorQueue_.Pop(); 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); TYPE_NONE);
return JsUtil::Const::Null(env); return JsUtil::Const::Null(env);
} }
@ -741,10 +759,11 @@ napi_value JsTextInputClientEngine::SelectByMovement(napi_env env, napi_callback
IMSA_HILOGD("run in"); IMSA_HILOGD("run in");
auto ctxt = std::make_shared<SelectContext>(); auto ctxt = std::make_shared<SelectContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status { 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_valuetype valueType = napi_undefined;
napi_typeof(env, argv[0], &valueType); 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); auto status = GetSelectMovement(env, argv[0], ctxt);
if (status == napi_ok) { if (status == napi_ok) {
ctxt->info = { std::chrono::system_clock::now(), EditorEvent::SELECT_BY_MOVEMENT }; 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 ctxt = std::make_shared<SendExtendActionContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status { 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); auto status = JsUtils::GetValue(env, argv[0], ctxt->action);
if (status == napi_ok) { if (status == napi_ok) {
ctxt->info = { std::chrono::system_clock::now(), EditorEvent::SEND_EXTEND_ACTION }; ctxt->info = { std::chrono::system_clock::now(), EditorEvent::SEND_EXTEND_ACTION };
editorQueue_.Push(ctxt->info); editorQueue_.Push(ctxt->info);
} else {
ctxt->SetErrorMessage("action must be number and should in ExtendAction");
} }
return status; return status;
}; };
@ -985,12 +1006,13 @@ napi_status JsTextInputClientEngine::GetPreviewTextParam(
napi_env env, size_t argc, napi_value *argv, std::string &text, Range &range) napi_env env, size_t argc, napi_value *argv, std::string &text, Range &range)
{ {
// 2 means JsAPI:setPreviewText needs 2 params at least. // 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, 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", 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); 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), 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; return napi_ok;
} }

View File

@ -339,11 +339,11 @@ napi_value JsGetInputMethodController::Subscribe(napi_env env, napi_callback_inf
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data)); NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data));
std::string type; std::string type;
// 2 means least param num. // 2 means least param num.
PARAM_CHECK_RETURN(env, argc >= 2, "At least 2 params", TYPE_NONE, nullptr); 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", PARAM_CHECK_RETURN(env, JsUtil::GetValue(env, argv[0], type), "js param type covert failed, must be string",
TYPE_NONE, nullptr); TYPE_NONE, nullptr);
PARAM_CHECK_RETURN(env, EventChecker::IsValidEventType(EventSubscribeModule::INPUT_METHOD_CONTROLLER, type), 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); PARAM_CHECK_RETURN(env, JsUtil::GetType(env, argv[1]) == napi_function, "callback", TYPE_FUNCTION, nullptr);
IMSA_HILOGD("Subscribe type:%{public}s.", type.c_str()); IMSA_HILOGD("Subscribe type:%{public}s.", type.c_str());
if (TEXT_EVENT_TYPE.find(type) != TEXT_EVENT_TYPE.end()) { if (TEXT_EVENT_TYPE.find(type) != TEXT_EVENT_TYPE.end()) {
@ -490,9 +490,9 @@ bool JsGetInputMethodController::GetValue(napi_env env, napi_value in, TextConfi
{ {
napi_value attributeResult = nullptr; napi_value attributeResult = nullptr;
napi_status status = JsUtils::GetValue(env, in, "inputAttribute", attributeResult); 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); 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; napi_value cursorInfoResult = nullptr;
status = JsUtils::GetValue(env, in, "cursorInfo", cursorInfoResult); status = JsUtils::GetValue(env, in, "cursorInfo", cursorInfoResult);
@ -514,25 +514,15 @@ bool JsGetInputMethodController::GetValue(napi_env env, napi_value in, TextConfi
return ret; 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) napi_value JsGetInputMethodController::Attach(napi_env env, napi_callback_info info)
{ {
auto ctxt = std::make_shared<AttachContext>(); auto ctxt = std::make_shared<AttachContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status { 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); PARAM_CHECK_RETURN(env, argc > 1, "at least two paramsters is required", TYPE_NONE, napi_generic_failure);
bool ret = ParseAttachInput(env, argc, argv, ctxt); PARAM_CHECK_RETURN(env, JsUtil::GetValue(env, argv[0], ctxt->showKeyboard),
PARAM_CHECK_RETURN(env, ret, "attach verification failed. shoule contain showKeyboard and textConfig", "js param showKeyboard covert failed, type must be boolean", TYPE_NONE, napi_generic_failure);
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; return napi_ok;
}; };
auto exec = [ctxt, env](AsyncCall::Context *ctx) { auto exec = [ctxt, env](AsyncCall::Context *ctx) {
@ -571,11 +561,10 @@ napi_value JsGetInputMethodController::SetCallingWindow(napi_env env, napi_callb
{ {
auto ctxt = std::make_shared<SetCallingWindowContext>(); auto ctxt = std::make_shared<SetCallingWindowContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status { 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 // 0 means the first parameter: windowId
napi_status status = JsUtils::GetValue(env, argv[0], ctxt->windID); napi_status status = JsUtils::GetValue(env, argv[0], ctxt->windID);
PARAM_CHECK_RETURN(env, status == napi_ok, "windID verification failed. shoule be number", PARAM_CHECK_RETURN(env, status == napi_ok, "param windowId type must be number", TYPE_NONE, status);
TYPE_NONE, status);
return status; return status;
}; };
auto exec = [ctxt](AsyncCall::Context *ctx) { auto exec = [ctxt](AsyncCall::Context *ctx) {
@ -602,11 +591,13 @@ napi_value JsGetInputMethodController::UpdateCursor(napi_env env, napi_callback_
{ {
auto ctxt = std::make_shared<UpdateCursorContext>(); auto ctxt = std::make_shared<UpdateCursorContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status { 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 // 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); bool ret = JsGetInputMethodController::GetValue(env, argv[0], ctxt->cursorInfo);
PARAM_CHECK_RETURN(env, ret, "cursorInfo verification failed. should contain 4 number", TYPE_NONE, PARAM_CHECK_RETURN(env, ret, "param cursorInfo covert failed, must contain four numbers",
napi_generic_failure); TYPE_NONE, napi_generic_failure);
return napi_ok; return napi_ok;
}; };
auto exec = [ctxt](AsyncCall::Context *ctx) { auto exec = [ctxt](AsyncCall::Context *ctx) {
@ -625,13 +616,13 @@ napi_value JsGetInputMethodController::ChangeSelection(napi_env env, napi_callba
{ {
std::shared_ptr<ChangeSelectionContext> ctxt = std::make_shared<ChangeSelectionContext>(); 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 { 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, argc > 2, "at least three paramsters is required", TYPE_NONE, napi_generic_failure);
PARAM_CHECK_RETURN(env, JsUtil::GetValue(env, argv[0], ctxt->text), "text verification failed", PARAM_CHECK_RETURN(env, JsUtil::GetValue(env, argv[0], ctxt->text),
TYPE_NONE, napi_generic_failure); "param text type must be string", TYPE_NONE, napi_generic_failure);
PARAM_CHECK_RETURN(env, JsUtil::GetValue(env, argv[1], ctxt->start), "start verification failed", PARAM_CHECK_RETURN(env, JsUtil::GetValue(env, argv[1], ctxt->start),
TYPE_NONE, napi_generic_failure); "param start type must be number", TYPE_NONE, napi_generic_failure);
PARAM_CHECK_RETURN(env, JsUtil::GetValue(env, argv[2], ctxt->end), "end verification failed", PARAM_CHECK_RETURN(env, JsUtil::GetValue(env, argv[2], ctxt->end),
TYPE_NONE, napi_generic_failure); "param end type must be number", TYPE_NONE, napi_generic_failure);
return napi_ok; return napi_ok;
}; };
auto exec = [ctxt](AsyncCall::Context *ctx) { auto exec = [ctxt](AsyncCall::Context *ctx) {
@ -656,9 +647,9 @@ napi_value JsGetInputMethodController::UpdateAttribute(napi_env env, napi_callba
{ {
auto ctxt = std::make_shared<UpdateAttributeContext>(); auto ctxt = std::make_shared<UpdateAttributeContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status { 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); 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); TYPE_NONE, napi_generic_failure);
ctxt->configuration.SetTextInputType(static_cast<TextInputType>(ctxt->attribute.inputPattern)); ctxt->configuration.SetTextInputType(static_cast<TextInputType>(ctxt->attribute.inputPattern));
ctxt->configuration.SetEnterKeyType(static_cast<EnterKeyType>(ctxt->attribute.enterKeyType)); ctxt->configuration.SetEnterKeyType(static_cast<EnterKeyType>(ctxt->attribute.enterKeyType));

View File

@ -194,8 +194,6 @@ private:
static napi_value CreateSendFunctionKey(napi_env env, int32_t functionKey); static napi_value CreateSendFunctionKey(napi_env env, int32_t functionKey);
void RegisterListener(napi_value callback, std::string type, std::shared_ptr<JSCallbackObject> callbackObj); void RegisterListener(napi_value callback, std::string type, std::shared_ptr<JSCallbackObject> callbackObj);
void UnRegisterListener(napi_value callback, std::string type); 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, CursorInfo &out);
static bool GetValue(napi_env env, napi_value in, InputAttribute &out); static bool GetValue(napi_env env, napi_value in, InputAttribute &out);
static bool GetValue(napi_env env, napi_value in, TextConfig &out); static bool GetValue(napi_env env, napi_value in, TextConfig &out);

View File

@ -158,7 +158,8 @@ napi_status JsGetInputMethodSetting::GetInputMethodProperty(
{ {
napi_valuetype valueType = napi_undefined; napi_valuetype valueType = napi_undefined;
napi_typeof(env, argv, &valueType); 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_value result = nullptr;
napi_get_named_property(env, argv, "name", &result); napi_get_named_property(env, argv, "name", &result);
JsUtils::GetValue(env, result, ctxt->property.name); JsUtils::GetValue(env, result, ctxt->property.name);
@ -177,7 +178,7 @@ napi_status JsGetInputMethodSetting::GetInputMethodProperty(
JsUtils::GetValue(env, result, ctxt->property.id); JsUtils::GetValue(env, result, ctxt->property.id);
} }
PARAM_CHECK_RETURN(env, (!ctxt->property.name.empty() && !ctxt->property.id.empty()), 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()); IMSA_HILOGD("methodId:%{public}s, packageName:%{public}s", ctxt->property.id.c_str(), ctxt->property.name.c_str());
return napi_ok; return napi_ok;
} }
@ -215,11 +216,11 @@ napi_value JsGetInputMethodSetting::GetInputMethods(napi_env env, napi_callback_
IMSA_HILOGD("run in GetInputMethods"); IMSA_HILOGD("run in GetInputMethods");
auto ctxt = std::make_shared<ListInputContext>(); auto ctxt = std::make_shared<ListInputContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status { 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; bool enable = false;
// 0 means first param index // 0 means first param index
napi_status status = JsUtils::GetValue(env, argv[0], enable); 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; ctxt->inputMethodStatus = enable ? InputMethodStatus::ENABLE : InputMethodStatus::DISABLE;
return napi_ok; return napi_ok;
}; };
@ -253,8 +254,8 @@ napi_value JsGetInputMethodSetting::GetInputMethodsSync(napi_env env, napi_callb
bool enable = false; bool enable = false;
// 0 means first param index // 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, 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, "Failed to get param, should be bool", PARAM_CHECK_RETURN(env, JsUtils::GetValue(env, argv[0], enable) == napi_ok, "param enable type must be boolean",
TYPE_NONE, JsUtil::Const::Null(env)); TYPE_NONE, JsUtil::Const::Null(env));
std::vector<Property> properties; std::vector<Property> properties;
@ -359,10 +360,11 @@ napi_value JsGetInputMethodSetting::ListInputMethodSubtype(napi_env env, napi_ca
IMSA_HILOGD("run in ListInputMethodSubtype"); IMSA_HILOGD("run in ListInputMethodSubtype");
auto ctxt = std::make_shared<ListInputContext>(); auto ctxt = std::make_shared<ListInputContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status { 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_valuetype valueType = napi_undefined;
napi_typeof(env, argv[0], &valueType); 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); napi_status status = JsGetInputMethodSetting::GetInputMethodProperty(env, argv[0], ctxt);
return status; return status;
}; };
@ -421,15 +423,16 @@ napi_value JsGetInputMethodSetting::IsPanelShown(napi_env env, napi_callback_inf
napi_value argv[1] = { nullptr }; napi_value argv[1] = { nullptr };
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
// 1 means least param num // 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> // 0 means parameter of info<PanelInfo>
napi_valuetype valueType = napi_undefined; napi_valuetype valueType = napi_undefined;
napi_typeof(env, argv[0], &valueType); 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; PanelInfo panelInfo;
napi_status status = JsUtils::GetValue(env, argv[0], 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)); TYPE_NONE, JsUtil::Const::Null(env));
bool isShown = false; bool isShown = false;

View File

@ -72,7 +72,7 @@ napi_status JsInputMethod::GetInputMethodProperty(
CHECK_RETURN(status == napi_ok, "get ctxt->methodId failed!", status); CHECK_RETURN(status == napi_ok, "get ctxt->methodId failed!", status);
} }
PARAM_CHECK_RETURN(env, (!ctxt->packageName.empty() && !ctxt->methodId.empty()), 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()); IMSA_HILOGD("methodId:%{public}s, packageName:%{public}s", ctxt->methodId.c_str(), ctxt->packageName.c_str());
return napi_ok; 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 ctxt = std::make_shared<SwitchInputMethodContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status { 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_valuetype valueType = napi_undefined;
napi_typeof(env, argv[0], &valueType); napi_typeof(env, argv[0], &valueType);
PARAM_CHECK_RETURN(env, valueType == napi_object || valueType == napi_string, "type must be object or string", PARAM_CHECK_RETURN(env, valueType == napi_object || valueType == napi_string,
TYPE_NONE, napi_invalid_arg); "when param is target/bundleName type must be InputMethodProperty/string", TYPE_NONE, napi_invalid_arg);
napi_status status = napi_generic_failure; napi_status status = napi_generic_failure;
if (valueType == napi_object) { if (valueType == napi_object) {
ctxt->trigger = SwitchTrigger::CURRENT_IME; 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 ctxt = std::make_shared<SwitchInputMethodContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status { 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_valuetype valueType = napi_undefined;
napi_typeof(env, argv[0], &valueType); 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); napi_status status = GetInputMethodSubProperty(env, argv[0], ctxt);
return status; return status;
}; };
@ -365,12 +366,14 @@ napi_value JsInputMethod::SwitchCurrentInputMethodAndSubtype(napi_env env, napi_
{ {
auto ctxt = std::make_shared<SwitchInputMethodContext>(); auto ctxt = std::make_shared<SwitchInputMethodContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status { 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_valuetype valueType = napi_undefined;
napi_typeof(env, argv[0], &valueType); 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); 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); napi_status status = GetInputMethodSubProperty(env, argv[1], ctxt);
return status; return status;
}; };

View File

@ -117,7 +117,6 @@ public:
static napi_value GetValue(napi_env env, const InputWindowInfo &in); 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_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, const std::string &in, napi_value &out);
static napi_status GetValue(napi_env env, napi_value in, PanelFlag &out);
private: private:
static const std::string ToMessage(int32_t code); 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 ctxt = std::make_shared<SendPrivateCommandContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status { 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, 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)) { if (!TextConfig::IsPrivateCommandValid(ctxt->privateCommand)) {
PARAM_CHECK_RETURN( 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 }; ctxt->info = { std::chrono::system_clock::now(), ctxt->privateCommand };
privateCommandQueue_.Push(ctxt->info); privateCommandQueue_.Push(ctxt->info);

View File

@ -84,7 +84,7 @@ private:
struct UvEntry { struct UvEntry {
std::vector<std::shared_ptr<JSCallbackObject>> vecCopy; std::vector<std::shared_ptr<JSCallbackObject>> vecCopy;
std::string type; std::string type;
bool shouldSysPanelShow; bool shouldSysPanelShow = false;
std::string smartMenu; std::string smartMenu;
std::unordered_map<std::string, PrivateDataValue> privateCommand; std::unordered_map<std::string, PrivateDataValue> privateCommand;
explicit UvEntry(const std::vector<std::shared_ptr<JSCallbackObject>> &cbVec, const std::string &type) 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", "-Os",
] ]
include_dirs = [ include_dirs = [
"${inputmethod_path}/frameworks/js/napi/common",
"${inputmethod_path}/frameworks/js/napi/inputmethodclient",
"${inputmethod_path}/frameworks/kits/extension/include", "${inputmethod_path}/frameworks/kits/extension/include",
"${inputmethod_path}/frameworks/native/inputmethod_controller/include", "${inputmethod_path}/frameworks/native/inputmethod_controller/include",
"${inputmethod_path}/interfaces/inner_api/inputmethod_controller/include", "${inputmethod_path}/interfaces/inner_api/inputmethod_controller/include",
@ -52,6 +54,7 @@ ohos_shared_library("inputmethod_extension") {
] ]
sources = [ 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.cpp",
"${inputmethod_path}/frameworks/kits/extension/src/inputmethod_extension_context.cpp", "${inputmethod_path}/frameworks/kits/extension/src/inputmethod_extension_context.cpp",
"${inputmethod_path}/frameworks/kits/extension/src/js_inputmethod_extension.cpp", "${inputmethod_path}/frameworks/kits/extension/src/js_inputmethod_extension.cpp",
@ -62,6 +65,7 @@ ohos_shared_library("inputmethod_extension") {
deps = [ deps = [
"${inputmethod_path}/common:inputmethod_common", "${inputmethod_path}/common:inputmethod_common",
"${inputmethod_path}/frameworks/js/napi/common:inputmethod_js_common",
"${inputmethod_path}/interfaces/inner_api/inputmethod_ability:inputmethod_ability", "${inputmethod_path}/interfaces/inner_api/inputmethod_ability:inputmethod_ability",
] ]

View File

@ -23,6 +23,8 @@
#include "js_extension_context.h" #include "js_extension_context.h"
#include "js_runtime.h" #include "js_runtime.h"
#include "js_runtime_utils.h" #include "js_runtime_utils.h"
#include "js_util.h"
#include "js_utils.h"
#include "napi/native_api.h" #include "napi/native_api.h"
#include "napi_common_start_options.h" #include "napi_common_start_options.h"
#include "napi_common_util.h" #include "napi_common_util.h"
@ -32,6 +34,7 @@
namespace OHOS { namespace OHOS {
namespace AbilityRuntime { namespace AbilityRuntime {
using namespace OHOS::MiscServices;
namespace { namespace {
constexpr int32_t INDEX_ZERO = 0; constexpr int32_t INDEX_ZERO = 0;
constexpr int32_t INDEX_ONE = 1; constexpr int32_t INDEX_ONE = 1;
@ -98,9 +101,12 @@ private:
// only support one or two or three params // only support one or two or three params
if (argc != ARGC_ONE && argc != ARGC_TWO && argc != ARGC_THREE) { if (argc != ARGC_ONE && argc != ARGC_TWO && argc != ARGC_THREE) {
IMSA_HILOGE("Not enough params"); IMSA_HILOGE("Not enough params");
JsUtils::ThrowException(env, IMFErrorCode::EXCEPTION_PARAMCHECK, "number of param should in [1,3]",
TYPE_NONE);
return CreateJsUndefined(env); 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; decltype(argc) unwrapArgc = 0;
AAFwk::Want want; AAFwk::Want want;
OHOS::AppExecFwk::UnwrapWant(env, argv[INDEX_ZERO], 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); auto ret = window_->MoveTo(x, y);
IMSA_HILOGI("x/y: %{public}d/%{public}d, ret = %{public}d", x, y, ret); 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) 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_.width_ = portraitDisplaySize.width;
keyboardLayoutParams_.PortraitPanelRect_.height_ = keyboardLayoutParams_.PortraitPanelRect_.height_ =
layoutParams.portraitRect.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_ > if (keyboardLayoutParams_.PortraitPanelRect_.height_ >
portraitDisplaySize.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO) { portraitDisplaySize.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO) {
keyboardLayoutParams_.PortraitPanelRect_.height_ = keyboardLayoutParams_.PortraitPanelRect_.height_ =
portraitDisplaySize.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO; portraitDisplaySize.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO;
} }
keyboardLayoutParams_.PortraitPanelRect_.posY_ = portraitDisplaySize.height - keyboardLayoutParams_.PortraitPanelRect_.posY_ = static_cast<int32_t>(portraitDisplaySize.height -
keyboardLayoutParams_.PortraitPanelRect_.height_; keyboardLayoutParams_.PortraitPanelRect_.height_);
keyboardLayoutParams_.PortraitPanelRect_.posX_ = NUMBER_ZERO; keyboardLayoutParams_.PortraitPanelRect_.posX_ = NUMBER_ZERO;
//fixed Portraitkeyboard //fixed Portraitkeyboard
keyboardLayoutParams_.PortraitKeyboardRect_.width_ = keyboardLayoutParams_.PortraitPanelRect_.width_ - 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_ - 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_ + keyboardLayoutParams_.PortraitKeyboardRect_.posY_ = keyboardLayoutParams_.PortraitPanelRect_.posY_ +
porIterValue.top * (densityDpi / DPI_CALCULATION_RATIO); porIterValue.top * (densityDpi / DPI_CALCULATION_RATIO);
keyboardLayoutParams_.PortraitKeyboardRect_.posX_ = keyboardLayoutParams_.PortraitPanelRect_.posX_ + keyboardLayoutParams_.PortraitKeyboardRect_.posX_ = keyboardLayoutParams_.PortraitPanelRect_.posX_ +
@ -332,9 +332,9 @@ void InputMethodPanel::CalculateFaloatRect(const LayoutParams &layoutParams, Pan
keyboardLayoutParams_.PortraitKeyboardRect_.posX_ = layoutParams.portraitRect.posX_; keyboardLayoutParams_.PortraitKeyboardRect_.posX_ = layoutParams.portraitRect.posX_;
//portrait floating panel //portrait floating panel
keyboardLayoutParams_.PortraitPanelRect_.width_ = keyboardLayoutParams_.PortraitKeyboardRect_.width_ + 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_ + 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_ - keyboardLayoutParams_.PortraitPanelRect_.posY_ = keyboardLayoutParams_.PortraitKeyboardRect_.posY_ -
porIterValue.top * (densityDpi / DPI_CALCULATION_RATIO); porIterValue.top * (densityDpi / DPI_CALCULATION_RATIO);
keyboardLayoutParams_.PortraitPanelRect_.posX_ = keyboardLayoutParams_.PortraitKeyboardRect_.posX_ - keyboardLayoutParams_.PortraitPanelRect_.posX_ = keyboardLayoutParams_.PortraitKeyboardRect_.posX_ -
@ -347,9 +347,9 @@ void InputMethodPanel::CalculateFaloatRect(const LayoutParams &layoutParams, Pan
keyboardLayoutParams_.LandscapeKeyboardRect_.posX_ = layoutParams.landscapeRect.posX_; keyboardLayoutParams_.LandscapeKeyboardRect_.posX_ = layoutParams.landscapeRect.posX_;
//landscape floating panel //landscape floating panel
keyboardLayoutParams_.LandscapePanelRect_.width_ = keyboardLayoutParams_.LandscapeKeyboardRect_.width_ + 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_ + 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_ - keyboardLayoutParams_.LandscapePanelRect_.posY_ = keyboardLayoutParams_.LandscapeKeyboardRect_.posY_ -
lanIterValue.top * (densityDpi / DPI_CALCULATION_RATIO); lanIterValue.top * (densityDpi / DPI_CALCULATION_RATIO);
keyboardLayoutParams_.LandscapePanelRect_.posX_ = keyboardLayoutParams_.LandscapeKeyboardRect_.posX_ - keyboardLayoutParams_.LandscapePanelRect_.posX_ = keyboardLayoutParams_.LandscapeKeyboardRect_.posX_ -
@ -374,14 +374,14 @@ int32_t InputMethodPanel::CalculateLandscapeRect(sptr<OHOS::Rosen::Display> &def
keyboardLayoutParams_.LandscapePanelRect_.height_ = keyboardLayoutParams_.LandscapePanelRect_.height_ =
landscapeDisplaySize.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO; landscapeDisplaySize.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO;
} }
keyboardLayoutParams_.LandscapePanelRect_.posY_ = landscapeDisplaySize.height - keyboardLayoutParams_.LandscapePanelRect_.posY_ = static_cast<int32_t>(landscapeDisplaySize.height -
keyboardLayoutParams_.LandscapePanelRect_.height_; keyboardLayoutParams_.LandscapePanelRect_.height_);
keyboardLayoutParams_.LandscapePanelRect_.posX_ = NUMBER_ZERO; keyboardLayoutParams_.LandscapePanelRect_.posX_ = NUMBER_ZERO;
//Landscapekeyboard //Landscapekeyboard
keyboardLayoutParams_.LandscapeKeyboardRect_.width_ = keyboardLayoutParams_.LandscapePanelRect_.width_ - 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_ - 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_ + keyboardLayoutParams_.LandscapeKeyboardRect_.posY_ = keyboardLayoutParams_.LandscapePanelRect_.posY_ +
lanIterValue.top * (densityDpi / DPI_CALCULATION_RATIO); lanIterValue.top * (densityDpi / DPI_CALCULATION_RATIO);
keyboardLayoutParams_.LandscapeKeyboardRect_.posX_ = keyboardLayoutParams_.LandscapePanelRect_.posX_ + 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_ =
keyboardLayoutParams_.LandscapeKeyboardRect_.width_ - cutoutArea.height_ * NUMBER_TWO; keyboardLayoutParams_.LandscapeKeyboardRect_.width_ - cutoutArea.height_ * NUMBER_TWO;
keyboardLayoutParams_.LandscapeKeyboardRect_.posX_ = keyboardLayoutParams_.LandscapeKeyboardRect_.posX_ =
keyboardLayoutParams_.LandscapeKeyboardRect_.posX_ + cutoutArea.height_; keyboardLayoutParams_.LandscapeKeyboardRect_.posX_ + static_cast<int32_t>(cutoutArea.height_);
} }
} }
} }
@ -803,7 +803,7 @@ bool InputMethodPanel::GetDisplaySize(bool isPortrait, WindowSize &size)
} }
bool isDisplayPortrait = defaultDisplay->GetRotation() == Rosen::Rotation::ROTATION_0 || bool isDisplayPortrait = defaultDisplay->GetRotation() == Rosen::Rotation::ROTATION_0 ||
defaultDisplay->GetRotation() == Rosen::Rotation::ROTATION_180; defaultDisplay->GetRotation() == Rosen::Rotation::ROTATION_180;
if (isPortrait ^ isDisplayPortrait) { if (!isPortrait != isDisplayPortrait) {
size = {.width = defaultDisplay->GetHeight(), .height = defaultDisplay->GetWidth()}; size = {.width = defaultDisplay->GetHeight(), .height = defaultDisplay->GetWidth()};
} else { } else {
size = {.width = defaultDisplay->GetWidth(), .height = defaultDisplay->GetHeight()}; size = {.width = defaultDisplay->GetWidth(), .height = defaultDisplay->GetHeight()};