mirror of
https://github.com/openharmony/miscservices_inputmethod.git
synced 2026-07-20 23:45:31 -04:00
@@ -21,6 +21,7 @@
|
||||
#include "string_ex.h"
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
using namespace AbilityRuntime;
|
||||
constexpr size_t ARGC_ZERO = 0;
|
||||
|
||||
void JsInputMethodController::Finalizer(NativeEngine* engine, void* data, void* hint)
|
||||
@@ -31,7 +32,7 @@ namespace MiscServices {
|
||||
|
||||
NativeValue* JsInputMethodController::StopInput(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsInputMethodController* me = AbilityRuntime::CheckParamsAndGetThis<JsInputMethodController>(engine, info);
|
||||
JsInputMethodController* me = CheckParamsAndGetThis<JsInputMethodController>(engine, info);
|
||||
return (me != nullptr) ? me->OnStopInput(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
@@ -45,7 +46,7 @@ namespace MiscServices {
|
||||
|
||||
InputMethodController::GetInstance()->HideCurrentInput();
|
||||
|
||||
NativeValue* result = AbilityRuntime::CreateJsValue(engine, true);
|
||||
NativeValue* result = CreateJsValue(engine, true);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
using namespace AbilityRuntime;
|
||||
namespace {
|
||||
constexpr size_t ARGC_ZERO = 0;
|
||||
constexpr int32_t MAX_TYPE_NUM = 128;
|
||||
@@ -46,14 +47,14 @@ namespace MiscServices {
|
||||
static NativeValue* GetInputMethodSetting(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
IMSA_HILOGI("JsInputMethodRegistry::GetInputMethodSetting is called");
|
||||
JsInputMethodRegistry* me = AbilityRuntime::CheckParamsAndGetThis<JsInputMethodRegistry>(engine, info);
|
||||
JsInputMethodRegistry* me = CheckParamsAndGetThis<JsInputMethodRegistry>(engine, info);
|
||||
return (me != nullptr) ? me->OnGetInputMethodSetting(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
static NativeValue* GetInputMethodController(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
IMSA_HILOGI("JsInputMethodRegistry::GetInputMethodController is called");
|
||||
JsInputMethodRegistry* me = AbilityRuntime::CheckParamsAndGetThis<JsInputMethodRegistry>(engine, info);
|
||||
JsInputMethodRegistry* me = CheckParamsAndGetThis<JsInputMethodRegistry>(engine, info);
|
||||
return (me != nullptr) ? me->OnGetInputMethodController(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
@@ -90,7 +91,7 @@ namespace MiscServices {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeObject* object = AbilityRuntime::ConvertNativeValueTo<NativeObject>(exportObj);
|
||||
NativeObject* object = ConvertNativeValueTo<NativeObject>(exportObj);
|
||||
if (object == nullptr) {
|
||||
IMSA_HILOGI("object null");
|
||||
return nullptr;
|
||||
@@ -99,12 +100,10 @@ namespace MiscServices {
|
||||
std::unique_ptr<JsInputMethodRegistry> jsInputMethodRegistry = std::make_unique<JsInputMethodRegistry>(engine);
|
||||
object->SetNativePointer(jsInputMethodRegistry.release(), JsInputMethodRegistry::Finalizer, nullptr);
|
||||
|
||||
AbilityRuntime::BindNativeFunction(*engine, *object, "getInputMethodSetting",
|
||||
JsInputMethodRegistry::GetInputMethodSetting);
|
||||
AbilityRuntime::BindNativeFunction(*engine, *object, "getInputMethodController",
|
||||
JsInputMethodRegistry::GetInputMethodController);
|
||||
BindNativeFunction(*engine, *object, "getInputMethodSetting", JsInputMethodRegistry::GetInputMethodSetting);
|
||||
BindNativeFunction(*engine, *object, "getInputMethodController", JsInputMethodRegistry::GetInputMethodController);
|
||||
|
||||
object->SetProperty("MAX_TYPE_NUM", AbilityRuntime::CreateJsValue(*engine, static_cast<uint32_t>(MAX_TYPE_NUM)));
|
||||
object->SetProperty("MAX_TYPE_NUM", CreateJsValue(*engine, static_cast<uint32_t>(MAX_TYPE_NUM)));
|
||||
|
||||
return engine->CreateUndefined();
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "string_ex.h"
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
using namespace AbilityRuntime;
|
||||
constexpr size_t ARGC_ZERO = 0;
|
||||
|
||||
void JsInputMethodSetting::Finalizer(NativeEngine* engine, void* data, void* hint)
|
||||
@@ -31,13 +32,13 @@ namespace MiscServices {
|
||||
|
||||
NativeValue* JsInputMethodSetting::DisplayOptionalInputMethod(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsInputMethodSetting* me = AbilityRuntime::CheckParamsAndGetThis<JsInputMethodSetting>(engine, info);
|
||||
JsInputMethodSetting* me = CheckParamsAndGetThis<JsInputMethodSetting>(engine, info);
|
||||
return (me != nullptr) ? me->OnDisplayOptionalInputMethod(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue* JsInputMethodSetting::ListInputMethod(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsInputMethodSetting* me = AbilityRuntime::CheckParamsAndGetThis<JsInputMethodSetting>(engine, info);
|
||||
JsInputMethodSetting* me = CheckParamsAndGetThis<JsInputMethodSetting>(engine, info);
|
||||
return (me != nullptr) ? me->OnListInputMethod(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
@@ -68,16 +69,16 @@ namespace MiscServices {
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
NativeValue* arrayValue = engine.CreateArray(properties.size());
|
||||
NativeArray* array = AbilityRuntime::ConvertNativeValueTo<NativeArray>(arrayValue);
|
||||
NativeArray* array = ConvertNativeValueTo<NativeArray>(arrayValue);
|
||||
uint32_t index = 0;
|
||||
for (const auto &info : properties) {
|
||||
NativeValue* objValue = engine.CreateObject();
|
||||
NativeObject* object = AbilityRuntime::ConvertNativeValueTo<NativeObject>(objValue);
|
||||
NativeObject* object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
|
||||
IMSA_HILOGI("JsInputMethodSetting::ListInputMethod %{public}s/%{public}s", Str16ToStr8(info->mPackageName).c_str(), Str16ToStr8(info->mAbilityName).c_str());
|
||||
|
||||
object->SetProperty("packageName", AbilityRuntime::CreateJsValue(engine, Str16ToStr8(info->mPackageName)));
|
||||
object->SetProperty("methodId", AbilityRuntime::CreateJsValue(engine, Str16ToStr8(info->mAbilityName)));
|
||||
object->SetProperty("packageName", CreateJsValue(engine, Str16ToStr8(info->mPackageName)));
|
||||
object->SetProperty("methodId", CreateJsValue(engine, Str16ToStr8(info->mAbilityName)));
|
||||
array->SetElement(index++, objValue);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,11 +22,12 @@
|
||||
#include "js_input_method_controller.h"
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
using namespace AbilityRuntime;
|
||||
NativeValue* CreateInputMethodSetting(NativeEngine& engine)
|
||||
{
|
||||
IMSA_HILOGI("JsInputMethodUtils::CreateInputMethodSetting is called");
|
||||
NativeValue *objValue = engine.CreateObject();
|
||||
NativeObject *object = AbilityRuntime::ConvertNativeValueTo<NativeObject>(objValue);
|
||||
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
if (object == nullptr) {
|
||||
IMSA_HILOGI("JsInputMethodUtils::CreateInputMethodSetting Failed to get object");
|
||||
return nullptr;
|
||||
@@ -35,9 +36,8 @@ namespace OHOS {
|
||||
std::unique_ptr<JsInputMethodSetting> jsInputMethodSetting = std::make_unique<JsInputMethodSetting>();
|
||||
object->SetNativePointer(jsInputMethodSetting.release(), JsInputMethodSetting::Finalizer, nullptr);
|
||||
|
||||
AbilityRuntime::BindNativeFunction(engine, *object, "displayOptionalInputMethod",
|
||||
JsInputMethodSetting::DisplayOptionalInputMethod);
|
||||
AbilityRuntime::BindNativeFunction(engine, *object, "listInputMethod", JsInputMethodSetting::ListInputMethod);
|
||||
BindNativeFunction(engine, *object, "displayOptionalInputMethod", JsInputMethodSetting::DisplayOptionalInputMethod);
|
||||
BindNativeFunction(engine, *object, "listInputMethod", JsInputMethodSetting::ListInputMethod);
|
||||
return objValue;
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace OHOS {
|
||||
{
|
||||
IMSA_HILOGI("JsInputMethodUtils::CreateInputMethodController is called");
|
||||
NativeValue *objValue = engine.CreateObject();
|
||||
NativeObject *object = AbilityRuntime::ConvertNativeValueTo<NativeObject>(objValue);
|
||||
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
if (object == nullptr) {
|
||||
IMSA_HILOGI("JsInputMethodUtils::CreateInputMethodController Failed to get object");
|
||||
return nullptr;
|
||||
@@ -54,7 +54,7 @@ namespace OHOS {
|
||||
std::unique_ptr<JsInputMethodController> jsInputMethodController = std::make_unique<JsInputMethodController>();
|
||||
object->SetNativePointer(jsInputMethodController.release(), JsInputMethodController::Finalizer, nullptr);
|
||||
|
||||
AbilityRuntime::BindNativeFunction(engine, *object, "stopInput", JsInputMethodController::StopInput);
|
||||
BindNativeFunction(engine, *object, "stopInput", JsInputMethodController::StopInput);
|
||||
return objValue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,11 +25,7 @@ namespace OHOS {
|
||||
JsEditorAttribute() = default;
|
||||
~JsEditorAttribute() = default;
|
||||
static void Finalizer(NativeEngine* engine, void* data, void* hint);
|
||||
// static NativeValue* GetEnterKeyType(NativeEngine* engine, NativeCallbackInfo* info);
|
||||
// static NativeValue* GetInputPattern(NativeEngine* engine, NativeCallbackInfo* info);
|
||||
private:
|
||||
// NativeValue* OnGetEnterKeyType(NativeEngine& engine, NativeCallbackInfo& info);
|
||||
// NativeValue* OnGetInputPattern(NativeEngine& engine, NativeCallbackInfo& info);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,47 +29,5 @@ namespace MiscServices {
|
||||
IMSA_HILOGI("JsEditorAttribute::Finalizer is called");
|
||||
std::unique_ptr<JsEditorAttribute>(static_cast<JsEditorAttribute*>(data));
|
||||
}
|
||||
|
||||
// NativeValue* JsEditorAttribute::GetEnterKeyType(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
// {
|
||||
// JsEditorAttribute* me = AbilityRuntime::CheckParamsAndGetThis<JsEditorAttribute>(engine, info);
|
||||
// return (me != nullptr) ? me->OnGetEnterKeyType(*engine, *info) : nullptr;
|
||||
// }
|
||||
//
|
||||
// NativeValue* JsEditorAttribute::GetInputPattern(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
// {
|
||||
// JsEditorAttribute* me = AbilityRuntime::CheckParamsAndGetThis<JsEditorAttribute>(engine, info);
|
||||
// return (me != nullptr) ? me->OnGetInputPattern(*engine, *info) : nullptr;
|
||||
// }
|
||||
|
||||
// NativeValue* JsEditorAttribute::OnGetEnterKeyType(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
// {
|
||||
// IMSA_HILOGI("JsEditorAttribute::OnGetEnterKeyType is called!");
|
||||
// if (info.argc != ARGC_ZERO) {
|
||||
// IMSA_HILOGI("JsEditorAttribute::OnGetEnterKeyType has params!");
|
||||
// return engine.CreateUndefined();
|
||||
// }
|
||||
//
|
||||
// int32_t ret = InputMethodAbility::GetInstance()->GetEnterKeyType();
|
||||
//
|
||||
// NativeValue* result = AbilityRuntime::CreateJsValue(engine, ret);
|
||||
//
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
// NativeValue* JsEditorAttribute::OnGetInputPattern(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
// {
|
||||
// IMSA_HILOGI("JsEditorAttribute::OnGetInputPattern is called!");
|
||||
// if (info.argc != ARGC_ZERO) {
|
||||
// IMSA_HILOGI("JsEditorAttribute::OnGetInputPattern has params!");
|
||||
// return engine.CreateUndefined();
|
||||
// }
|
||||
//
|
||||
// int32_t ret = InputMethodAbility::GetInstance()->GetInputPattern();
|
||||
//
|
||||
// NativeValue* result = AbilityRuntime::CreateJsValue(engine, ret);
|
||||
//
|
||||
// return result;
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "global.h"
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
using namespace AbilityRuntime;
|
||||
constexpr size_t ARGC_TWO = 2;
|
||||
JsInputMethodEngine::JsInputMethodEngine(NativeEngine* engine)
|
||||
{
|
||||
@@ -40,13 +41,13 @@ namespace MiscServices {
|
||||
|
||||
NativeValue* JsInputMethodEngine::RegisterCallback(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsInputMethodEngine* me = AbilityRuntime::CheckParamsAndGetThis<JsInputMethodEngine>(engine, info);
|
||||
JsInputMethodEngine* me = CheckParamsAndGetThis<JsInputMethodEngine>(engine, info);
|
||||
return (me != nullptr) ? me->OnRegisterCallback(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue* JsInputMethodEngine::UnRegisterCallback(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsInputMethodEngine* me = AbilityRuntime::CheckParamsAndGetThis<JsInputMethodEngine>(engine, info);
|
||||
JsInputMethodEngine* me = CheckParamsAndGetThis<JsInputMethodEngine>(engine, info);
|
||||
return (me != nullptr) ? me->OnUnRegisterCallback(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
@@ -59,7 +60,7 @@ namespace MiscServices {
|
||||
}
|
||||
|
||||
std::string cbType;
|
||||
if (!AbilityRuntime::ConvertFromJsValue(engine, info.argv[0], cbType)) {
|
||||
if (!ConvertFromJsValue(engine, info.argv[0], cbType)) {
|
||||
IMSA_HILOGI("JsInputMethodEngine::OnRegisterCallback Failed to convert parameter to callbackType");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
@@ -78,7 +79,7 @@ namespace MiscServices {
|
||||
}
|
||||
|
||||
std::string cbType;
|
||||
if (!AbilityRuntime::ConvertFromJsValue(engine, info.argv[0], cbType)) {
|
||||
if (!ConvertFromJsValue(engine, info.argv[0], cbType)) {
|
||||
IMSA_HILOGI("JsInputMethodEngine::OnUnRegisterCallback Failed to convert parameter to callbackType");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
using namespace AbilityRuntime;
|
||||
void JsInputMethodEngineListener::RegisterListenerWithType(NativeEngine& engine,
|
||||
std::string type, NativeValue* value)
|
||||
{
|
||||
@@ -120,7 +121,7 @@ namespace MiscServices {
|
||||
for (auto iter = jsCbMap_[methodName].begin(); iter != jsCbMap_[methodName].end(); iter++) {
|
||||
NativeValue* nativeValue = engine_->CallFunction(engine_->CreateUndefined(), (*iter)->Get(), argv, argc);
|
||||
bool ret = false;
|
||||
if (AbilityRuntime::ConvertFromJsValue(*engine_, nativeValue, ret) && ret) {
|
||||
if (ConvertFromJsValue(*engine_, nativeValue, ret) && ret) {
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
@@ -133,7 +134,7 @@ namespace MiscServices {
|
||||
IMSA_HILOGI("JsInputMethodEngineListener::OnKeyboardStatus");
|
||||
|
||||
NativeValue* nativeValue = engine_->CreateObject();
|
||||
NativeObject* object = AbilityRuntime::ConvertNativeValueTo<NativeObject>(nativeValue);
|
||||
NativeObject* object = ConvertNativeValueTo<NativeObject>(nativeValue);
|
||||
if (object == nullptr) {
|
||||
IMSA_HILOGI("Failed to convert rect to jsObject");
|
||||
return;
|
||||
@@ -145,34 +146,19 @@ namespace MiscServices {
|
||||
} else {
|
||||
methodName = "keyboardHide";
|
||||
}
|
||||
CallJsMethod(methodName, argv, AbilityRuntime::ArraySize(argv));
|
||||
CallJsMethod(methodName, argv, ArraySize(argv));
|
||||
}
|
||||
|
||||
void JsInputMethodEngineListener::OnInputStart()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
IMSA_HILOGI("JsInputMethodEngineListener::OnInputStart");
|
||||
// NativeValue *nativeValuekb = engine_->CreateObject();
|
||||
// NativeObject *objectkb = AbilityRuntime::ConvertNativeValueTo<NativeObject>(nativeValuekb);
|
||||
// if (objectkb == nullptr) {
|
||||
// IMSA_HILOGI("JsInputMethodEngineListener::OnInputStart Failed to get object");
|
||||
// return;
|
||||
// }
|
||||
|
||||
NativeValue *nativeValuekb = CreateKeyboardController(*engine_);
|
||||
// objectkb->SetProperty("kbController", CreateKeyboardController(*engine_));
|
||||
|
||||
// NativeValue *nativeValuetx = engine_->CreateObject();
|
||||
// NativeObject *objecttx = AbilityRuntime::ConvertNativeValueTo<NativeObject>(nativeValuetx);
|
||||
// if (objecttx == nullptr) {
|
||||
// IMSA_HILOGI("JsInputMethodEngineListener::OnInputStart Failed to get object");
|
||||
// return;
|
||||
// }
|
||||
// objecttx->SetProperty("textInputClient", CreateTextInputClient(*engine_));
|
||||
NativeValue *nativeValuetx = CreateTextInputClient(*engine_);
|
||||
NativeValue* argv[] = {nativeValuekb, nativeValuetx};
|
||||
std::string methodName = "inputStart";
|
||||
CallJsMethod(methodName, argv, AbilityRuntime::ArraySize(argv));
|
||||
CallJsMethod(methodName, argv, ArraySize(argv));
|
||||
}
|
||||
|
||||
void JsInputMethodEngineListener::OnInputStop(std::string imeId)
|
||||
@@ -181,16 +167,16 @@ namespace MiscServices {
|
||||
IMSA_HILOGI("JsInputMethodEngineListener::OnInputStop");
|
||||
|
||||
NativeValue* nativeValue = engine_->CreateObject();
|
||||
NativeObject* object = AbilityRuntime::ConvertNativeValueTo<NativeObject>(nativeValue);
|
||||
NativeObject* object = ConvertNativeValueTo<NativeObject>(nativeValue);
|
||||
if (object == nullptr) {
|
||||
IMSA_HILOGI("Failed to convert rect to jsObject");
|
||||
return;
|
||||
}
|
||||
object->SetProperty("imeId", AbilityRuntime::CreateJsValue(*engine_, imeId));
|
||||
object->SetProperty("imeId", CreateJsValue(*engine_, imeId));
|
||||
|
||||
NativeValue* argv[] = {nativeValue};
|
||||
std::string methodName = "inputStop";
|
||||
CallJsMethod(methodName, argv, AbilityRuntime::ArraySize(argv));
|
||||
CallJsMethod(methodName, argv, ArraySize(argv));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
using namespace AbilityRuntime;
|
||||
namespace {
|
||||
constexpr size_t ARGC_ZERO = 0;
|
||||
constexpr size_t ARGC_ONE = 1;
|
||||
@@ -46,19 +47,19 @@ namespace MiscServices {
|
||||
|
||||
static NativeValue* GetInputMethodEngine(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsInputMethodEngineRegistry* me = AbilityRuntime::CheckParamsAndGetThis<JsInputMethodEngineRegistry>(engine, info);
|
||||
JsInputMethodEngineRegistry* me = CheckParamsAndGetThis<JsInputMethodEngineRegistry>(engine, info);
|
||||
return (me != nullptr) ? me->OnGetInputMethodEngine(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
static NativeValue* GetKeyboardDelegate(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsInputMethodEngineRegistry* me = AbilityRuntime::CheckParamsAndGetThis<JsInputMethodEngineRegistry>(engine, info);
|
||||
JsInputMethodEngineRegistry* me = CheckParamsAndGetThis<JsInputMethodEngineRegistry>(engine, info);
|
||||
return (me != nullptr) ? me->OnGetKeyboardDelegate(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
static NativeValue* MoveCursor(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsInputMethodEngineRegistry* me = AbilityRuntime::CheckParamsAndGetThis<JsInputMethodEngineRegistry>(engine, info);
|
||||
JsInputMethodEngineRegistry* me = CheckParamsAndGetThis<JsInputMethodEngineRegistry>(engine, info);
|
||||
return (me != nullptr) ? me->OnMoveCursor(*engine, *info) : nullptr;
|
||||
}
|
||||
private:
|
||||
@@ -96,14 +97,14 @@ namespace MiscServices {
|
||||
nativeString = info.argv[ARGC_ZERO];
|
||||
|
||||
int32_t number;
|
||||
if (!AbilityRuntime::ConvertFromJsValue(engine, nativeString, number)) {
|
||||
if (!ConvertFromJsValue(engine, nativeString, number)) {
|
||||
IMSA_HILOGI("JsInputMethodEngineRegistry::OnMoveCursor Failed to convert parameter to string");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
InputMethodAbility::GetInstance()->MoveCursor(number);
|
||||
|
||||
NativeValue* result = AbilityRuntime::CreateJsValue(engine, true);
|
||||
NativeValue* result = CreateJsValue(engine, true);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -118,7 +119,7 @@ namespace MiscServices {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeObject* object = AbilityRuntime::ConvertNativeValueTo<NativeObject>(exportObj);
|
||||
NativeObject* object = ConvertNativeValueTo<NativeObject>(exportObj);
|
||||
if (object == nullptr) {
|
||||
IMSA_HILOGI("object null");
|
||||
return nullptr;
|
||||
@@ -127,50 +128,46 @@ namespace MiscServices {
|
||||
std::unique_ptr<JsInputMethodEngineRegistry> jsInputMethodEngineRegistry = std::make_unique<JsInputMethodEngineRegistry>(engine);
|
||||
object->SetNativePointer(jsInputMethodEngineRegistry.release(), JsInputMethodEngineRegistry::Finalizer, nullptr);
|
||||
|
||||
AbilityRuntime::BindNativeFunction(*engine, *object, "getInputMethodEngine", JsInputMethodEngineRegistry::GetInputMethodEngine);
|
||||
AbilityRuntime::BindNativeFunction(*engine, *object, "createKeyboardDelegate", JsInputMethodEngineRegistry::GetKeyboardDelegate);
|
||||
BindNativeFunction(*engine, *object, "getInputMethodEngine", JsInputMethodEngineRegistry::GetInputMethodEngine);
|
||||
BindNativeFunction(*engine, *object, "createKeyboardDelegate", JsInputMethodEngineRegistry::GetKeyboardDelegate);
|
||||
|
||||
object->SetProperty("ENTER_KEY_TYPE_UNSPECIFIED", AbilityRuntime::CreateJsValue(*engine, static_cast<uint32_t>(EnterKeyType::UNSPECIFIED)));
|
||||
object->SetProperty("ENTER_KEY_TYPE_GO", AbilityRuntime::CreateJsValue(*engine, static_cast<uint32_t>(EnterKeyType::GO)));
|
||||
object->SetProperty("ENTER_KEY_TYPE_SEARCH", AbilityRuntime::CreateJsValue(*engine, static_cast<uint32_t>(EnterKeyType::SEARCH)));
|
||||
object->SetProperty("ENTER_KEY_TYPE_SEND", AbilityRuntime::CreateJsValue(*engine, static_cast<uint32_t>(EnterKeyType::SEND)));
|
||||
object->SetProperty("ENTER_KEY_TYPE_NEXT", AbilityRuntime::CreateJsValue(*engine, static_cast<uint32_t>(EnterKeyType::NEXT)));
|
||||
object->SetProperty("ENTER_KEY_TYPE_DONE", AbilityRuntime::CreateJsValue(*engine, static_cast<uint32_t>(EnterKeyType::DONE)));
|
||||
object->SetProperty("ENTER_KEY_TYPE_PREVIOUS", AbilityRuntime::CreateJsValue(*engine, static_cast<uint32_t>(EnterKeyType::PREVIOUS)));
|
||||
object->SetProperty("ENTER_KEY_TYPE_UNSPECIFIED", CreateJsValue(*engine, static_cast<uint32_t>(EnterKeyType::UNSPECIFIED)));
|
||||
object->SetProperty("ENTER_KEY_TYPE_GO", CreateJsValue(*engine, static_cast<uint32_t>(EnterKeyType::GO)));
|
||||
object->SetProperty("ENTER_KEY_TYPE_SEARCH", CreateJsValue(*engine, static_cast<uint32_t>(EnterKeyType::SEARCH)));
|
||||
object->SetProperty("ENTER_KEY_TYPE_SEND", CreateJsValue(*engine, static_cast<uint32_t>(EnterKeyType::SEND)));
|
||||
object->SetProperty("ENTER_KEY_TYPE_NEXT", CreateJsValue(*engine, static_cast<uint32_t>(EnterKeyType::NEXT)));
|
||||
object->SetProperty("ENTER_KEY_TYPE_DONE", CreateJsValue(*engine, static_cast<uint32_t>(EnterKeyType::DONE)));
|
||||
object->SetProperty("ENTER_KEY_TYPE_PREVIOUS", CreateJsValue(*engine, static_cast<uint32_t>(EnterKeyType::PREVIOUS)));
|
||||
|
||||
object->SetProperty("PATTERN_NULL", AbilityRuntime::CreateJsValue(*engine, static_cast<int32_t>(TextInputType::NONE)));
|
||||
object->SetProperty("PATTERN_TEXT", AbilityRuntime::CreateJsValue(*engine, static_cast<uint32_t>(TextInputType::TEXT)));
|
||||
object->SetProperty("PATTERN_NUMBER", AbilityRuntime::CreateJsValue(*engine, static_cast<uint32_t>(TextInputType::NUMBER)));
|
||||
object->SetProperty("PATTERN_PHONE", AbilityRuntime::CreateJsValue(*engine, static_cast<uint32_t>(TextInputType::PHONE)));
|
||||
object->SetProperty("PATTERN_DATETIME", AbilityRuntime::CreateJsValue(*engine, static_cast<uint32_t>(TextInputType::DATETIME)));
|
||||
object->SetProperty("PATTERN_EMAIL", AbilityRuntime::CreateJsValue(*engine, static_cast<uint32_t>(TextInputType::EMAIL_ADDRESS)));
|
||||
object->SetProperty("PATTERN_URI", AbilityRuntime::CreateJsValue(*engine, static_cast<uint32_t>(TextInputType::URL)));
|
||||
object->SetProperty("PATTERN_PASSWORD", AbilityRuntime::CreateJsValue(*engine, static_cast<uint32_t>(TextInputType::VISIBLE_PASSWORD)));
|
||||
object->SetProperty("PATTERN_NULL", CreateJsValue(*engine, static_cast<int32_t>(TextInputType::NONE)));
|
||||
object->SetProperty("PATTERN_TEXT", CreateJsValue(*engine, static_cast<uint32_t>(TextInputType::TEXT)));
|
||||
object->SetProperty("PATTERN_NUMBER", CreateJsValue(*engine, static_cast<uint32_t>(TextInputType::NUMBER)));
|
||||
object->SetProperty("PATTERN_PHONE", CreateJsValue(*engine, static_cast<uint32_t>(TextInputType::PHONE)));
|
||||
object->SetProperty("PATTERN_DATETIME", CreateJsValue(*engine, static_cast<uint32_t>(TextInputType::DATETIME)));
|
||||
object->SetProperty("PATTERN_EMAIL", CreateJsValue(*engine, static_cast<uint32_t>(TextInputType::EMAIL_ADDRESS)));
|
||||
object->SetProperty("PATTERN_URI", CreateJsValue(*engine, static_cast<uint32_t>(TextInputType::URL)));
|
||||
object->SetProperty("PATTERN_PASSWORD", CreateJsValue(*engine, static_cast<uint32_t>(TextInputType::VISIBLE_PASSWORD)));
|
||||
|
||||
object->SetProperty("FLAG_SELECTING", CreateJsValue(*engine, static_cast<uint32_t>(2)));
|
||||
object->SetProperty("FLAG_SINGLE_LINE", CreateJsValue(*engine, static_cast<uint32_t>(1)));
|
||||
|
||||
object->SetProperty("FLAG_SELECTING", AbilityRuntime::CreateJsValue(*engine, static_cast<uint32_t>(2)));
|
||||
object->SetProperty("FLAG_SINGLE_LINE", AbilityRuntime::CreateJsValue(*engine, static_cast<uint32_t>(1)));
|
||||
object->SetProperty("DISPLAY_MODE_PART", CreateJsValue(*engine, static_cast<uint32_t>(0)));
|
||||
object->SetProperty("DISPLAY_MODE_FULL", CreateJsValue(*engine, static_cast<uint32_t>(1)));
|
||||
|
||||
object->SetProperty("DISPLAY_MODE_PART", AbilityRuntime::CreateJsValue(*engine, static_cast<uint32_t>(0)));
|
||||
object->SetProperty("DISPLAY_MODE_FULL", AbilityRuntime::CreateJsValue(*engine, static_cast<uint32_t>(1)));
|
||||
object->SetProperty("OPTION_ASCII", CreateJsValue(*engine, static_cast<uint32_t>(20)));
|
||||
object->SetProperty("OPTION_NONE", CreateJsValue(*engine, static_cast<uint32_t>(0)));
|
||||
object->SetProperty("OPTION_AUTO_CAP_CHARACTERS", CreateJsValue(*engine, static_cast<uint32_t>(2)));
|
||||
object->SetProperty("OPTION_AUTO_CAP_SENTENCES", CreateJsValue(*engine, static_cast<uint32_t>(8)));
|
||||
object->SetProperty("OPTION_AUTO_WORDS", CreateJsValue(*engine, static_cast<uint32_t>(4)));
|
||||
object->SetProperty("OPTION_MULTI_LINE", CreateJsValue(*engine, static_cast<uint32_t>(1)));
|
||||
object->SetProperty("OPTION_NO_FULLSCREEN", CreateJsValue(*engine, static_cast<uint32_t>(10)));
|
||||
|
||||
object->SetProperty("OPTION_ASCII", AbilityRuntime::CreateJsValue(*engine, static_cast<uint32_t>(20)));
|
||||
object->SetProperty("OPTION_NONE", AbilityRuntime::CreateJsValue(*engine, static_cast<uint32_t>(0)));
|
||||
object->SetProperty("OPTION_AUTO_CAP_CHARACTERS", AbilityRuntime::CreateJsValue(*engine, static_cast<uint32_t>(2)));
|
||||
object->SetProperty("OPTION_AUTO_CAP_SENTENCES", AbilityRuntime::CreateJsValue(*engine, static_cast<uint32_t>(8)));
|
||||
object->SetProperty("OPTION_AUTO_WORDS", AbilityRuntime::CreateJsValue(*engine, static_cast<uint32_t>(4)));
|
||||
object->SetProperty("OPTION_MULTI_LINE", AbilityRuntime::CreateJsValue(*engine, static_cast<uint32_t>(1)));
|
||||
object->SetProperty("OPTION_NO_FULLSCREEN", AbilityRuntime::CreateJsValue(*engine, static_cast<uint32_t>(10)));
|
||||
BindNativeFunction(*engine, *object, "MoveCursor", JsInputMethodEngineRegistry::MoveCursor);
|
||||
|
||||
|
||||
|
||||
AbilityRuntime::BindNativeFunction(*engine, *object, "MoveCursor", JsInputMethodEngineRegistry::MoveCursor);
|
||||
|
||||
object->SetProperty("FUNCTION_KEY_CONFIRM", AbilityRuntime::CreateJsValue(*engine, static_cast<uint32_t>(1)));
|
||||
object->SetProperty("CURSOR_UP", AbilityRuntime::CreateJsValue(*engine, static_cast<uint32_t>(1)));
|
||||
object->SetProperty("CURSOR_DOWN", AbilityRuntime::CreateJsValue(*engine, static_cast<uint32_t>(2)));
|
||||
object->SetProperty("CURSOR_LEFT", AbilityRuntime::CreateJsValue(*engine, static_cast<uint32_t>(3)));
|
||||
object->SetProperty("CURSOR_RIGHT", AbilityRuntime::CreateJsValue(*engine, static_cast<uint32_t>(4)));
|
||||
object->SetProperty("CURSOR_UP", CreateJsValue(*engine, static_cast<uint32_t>(1)));
|
||||
object->SetProperty("CURSOR_DOWN", CreateJsValue(*engine, static_cast<uint32_t>(2)));
|
||||
object->SetProperty("CURSOR_LEFT", CreateJsValue(*engine, static_cast<uint32_t>(3)));
|
||||
object->SetProperty("CURSOR_RIGHT", CreateJsValue(*engine, static_cast<uint32_t>(4)));
|
||||
return engine->CreateUndefined();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,11 +26,12 @@
|
||||
#include "js_editor_attribute.h"
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
using namespace AbilityRuntime;
|
||||
NativeValue* CreateInputMethodEngine(NativeEngine &engine)
|
||||
{
|
||||
IMSA_HILOGI("JsInputMethodEngineUtils::CreateInputMethodEngine is called");
|
||||
NativeValue *objValue = engine.CreateObject();
|
||||
NativeObject *object = AbilityRuntime::ConvertNativeValueTo<NativeObject>(objValue);
|
||||
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
if (object == nullptr) {
|
||||
IMSA_HILOGI("JsInputMethodEngineUtils::CreateInputMethodEngine Failed to get object");
|
||||
return nullptr;
|
||||
@@ -39,8 +40,8 @@ namespace OHOS {
|
||||
std::unique_ptr<JsInputMethodEngine> jsInputMethodEngine = std::make_unique<JsInputMethodEngine>(&engine);
|
||||
object->SetNativePointer(jsInputMethodEngine.release(), JsInputMethodEngine::Finalizer, nullptr);
|
||||
|
||||
AbilityRuntime::BindNativeFunction(engine, *object, "on", JsInputMethodEngine::RegisterCallback);
|
||||
AbilityRuntime::BindNativeFunction(engine, *object, "off", JsInputMethodEngine::UnRegisterCallback);
|
||||
BindNativeFunction(engine, *object, "on", JsInputMethodEngine::RegisterCallback);
|
||||
BindNativeFunction(engine, *object, "off", JsInputMethodEngine::UnRegisterCallback);
|
||||
return objValue;
|
||||
}
|
||||
|
||||
@@ -48,7 +49,7 @@ namespace OHOS {
|
||||
{
|
||||
IMSA_HILOGI("JsInputMethodEngineUtils::CreateKeyboardController is called");
|
||||
NativeValue *objValue = engine.CreateObject();
|
||||
NativeObject *object = AbilityRuntime::ConvertNativeValueTo<NativeObject>(objValue);
|
||||
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
if (object == nullptr) {
|
||||
IMSA_HILOGI("CreateKeyboardController Failed to get object");
|
||||
return nullptr;
|
||||
@@ -57,7 +58,7 @@ namespace OHOS {
|
||||
std::unique_ptr<JsKeyboardController> jsKeyboardController = std::make_unique<JsKeyboardController>();
|
||||
object->SetNativePointer(jsKeyboardController.release(), JsKeyboardController::Finalizer, nullptr);
|
||||
|
||||
AbilityRuntime::BindNativeFunction(engine, *object, "hideKeyboard", JsKeyboardController::HideKeyboardSelf);
|
||||
BindNativeFunction(engine, *object, "hideKeyboard", JsKeyboardController::HideKeyboardSelf);
|
||||
|
||||
return objValue;
|
||||
}
|
||||
@@ -66,7 +67,7 @@ namespace OHOS {
|
||||
{
|
||||
IMSA_HILOGI("JsInputMethodEngineUtils::CreateTextInputClient is called");
|
||||
NativeValue *objValue = engine.CreateObject();
|
||||
NativeObject *object = AbilityRuntime::ConvertNativeValueTo<NativeObject>(objValue);
|
||||
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
if (object == nullptr) {
|
||||
IMSA_HILOGI("CreateTextInputClient Failed to get object");
|
||||
return nullptr;
|
||||
@@ -75,13 +76,13 @@ namespace OHOS {
|
||||
std::unique_ptr<JsTextInputClient> jsTextInputClient = std::make_unique<JsTextInputClient>();
|
||||
object->SetNativePointer(jsTextInputClient.release(), JsTextInputClient::Finalizer, nullptr);
|
||||
|
||||
AbilityRuntime::BindNativeFunction(engine, *object, "insertText", JsTextInputClient::InsertText);
|
||||
AbilityRuntime::BindNativeFunction(engine, *object, "deleteForward", JsTextInputClient::DeleteForward);
|
||||
AbilityRuntime::BindNativeFunction(engine, *object, "deleteBackward", JsTextInputClient::DeleteBackward);
|
||||
AbilityRuntime::BindNativeFunction(engine, *object, "sendKeyFunction", JsTextInputClient::SendFunctionKey);
|
||||
AbilityRuntime::BindNativeFunction(engine, *object, "getForward", JsTextInputClient::GetForward);
|
||||
AbilityRuntime::BindNativeFunction(engine, *object, "getBackward", JsTextInputClient::GetBackward);
|
||||
AbilityRuntime::BindNativeFunction(engine, *object, "getEditorAttribute", JsTextInputClient::GetEditorAttribute);
|
||||
BindNativeFunction(engine, *object, "insertText", JsTextInputClient::InsertText);
|
||||
BindNativeFunction(engine, *object, "deleteForward", JsTextInputClient::DeleteForward);
|
||||
BindNativeFunction(engine, *object, "deleteBackward", JsTextInputClient::DeleteBackward);
|
||||
BindNativeFunction(engine, *object, "sendKeyFunction", JsTextInputClient::SendFunctionKey);
|
||||
BindNativeFunction(engine, *object, "getForward", JsTextInputClient::GetForward);
|
||||
BindNativeFunction(engine, *object, "getBackward", JsTextInputClient::GetBackward);
|
||||
BindNativeFunction(engine, *object, "getEditorAttribute", JsTextInputClient::GetEditorAttribute);
|
||||
return objValue;
|
||||
}
|
||||
|
||||
@@ -89,7 +90,7 @@ namespace OHOS {
|
||||
{
|
||||
IMSA_HILOGI("JsInputMethodEngineUtils::CreateKeyboardDelegate is called");
|
||||
NativeValue *objValue = engine.CreateObject();
|
||||
NativeObject *object = AbilityRuntime::ConvertNativeValueTo<NativeObject>(objValue);
|
||||
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
if (object == nullptr) {
|
||||
IMSA_HILOGI("CreateKeyboardDelegate Failed to get object");
|
||||
return nullptr;
|
||||
@@ -98,8 +99,8 @@ namespace OHOS {
|
||||
std::unique_ptr<JsKeyboardDelegate> jsKeyboardDelegate = std::make_unique<JsKeyboardDelegate>(&engine);
|
||||
object->SetNativePointer(jsKeyboardDelegate.release(), JsKeyboardDelegate::Finalizer, nullptr);
|
||||
|
||||
AbilityRuntime::BindNativeFunction(engine, *object, "on", JsKeyboardDelegate::RegisterCallback);
|
||||
AbilityRuntime::BindNativeFunction(engine, *object, "off", JsKeyboardDelegate::UnRegisterCallback);
|
||||
BindNativeFunction(engine, *object, "on", JsKeyboardDelegate::RegisterCallback);
|
||||
BindNativeFunction(engine, *object, "off", JsKeyboardDelegate::UnRegisterCallback);
|
||||
return objValue;
|
||||
}
|
||||
|
||||
@@ -107,7 +108,7 @@ namespace OHOS {
|
||||
{
|
||||
IMSA_HILOGI("JsInputMethodEngineUtils::CreateEditorAttribute is called");
|
||||
NativeValue *objValue = engine.CreateObject();
|
||||
NativeObject *object = AbilityRuntime::ConvertNativeValueTo<NativeObject>(objValue);
|
||||
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
if (object == nullptr) {
|
||||
IMSA_HILOGI("CreateEditorAttribute Failed to get object");
|
||||
return nullptr;
|
||||
@@ -116,8 +117,8 @@ namespace OHOS {
|
||||
std::unique_ptr<JsEditorAttribute> jsEditorAttribute = std::make_unique<JsEditorAttribute>();
|
||||
object->SetNativePointer(jsEditorAttribute.release(), JsEditorAttribute::Finalizer, nullptr);
|
||||
|
||||
object->SetProperty("enterKeyType", AbilityRuntime::CreateJsValue(engine, InputMethodAbility::GetInstance()->GetEnterKeyType()));
|
||||
object->SetProperty("inputPattern", AbilityRuntime::CreateJsValue(engine, InputMethodAbility::GetInstance()->GetInputPattern()));
|
||||
object->SetProperty("enterKeyType", CreateJsValue(engine, InputMethodAbility::GetInstance()->GetEnterKeyType()));
|
||||
object->SetProperty("inputPattern", CreateJsValue(engine, InputMethodAbility::GetInstance()->GetInputPattern()));
|
||||
|
||||
return objValue;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "input_method_ability.h"
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
using namespace AbilityRuntime;
|
||||
constexpr size_t ARGC_ZERO = 0;
|
||||
void JsKeyboardController::Finalizer(NativeEngine* engine, void* data, void* hint)
|
||||
{
|
||||
@@ -31,7 +32,7 @@ namespace MiscServices {
|
||||
|
||||
NativeValue* JsKeyboardController::HideKeyboardSelf(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsKeyboardController* me = AbilityRuntime::CheckParamsAndGetThis<JsKeyboardController>(engine, info);
|
||||
JsKeyboardController* me = CheckParamsAndGetThis<JsKeyboardController>(engine, info);
|
||||
return (me != nullptr) ? me->OnHideKeyboardSelf(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "global.h"
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
using namespace AbilityRuntime;
|
||||
constexpr size_t ARGC_TWO = 2;
|
||||
JsKeyboardDelegate::JsKeyboardDelegate(NativeEngine* engine)
|
||||
{
|
||||
@@ -50,13 +51,13 @@ namespace MiscServices {
|
||||
|
||||
NativeValue* JsKeyboardDelegate::RegisterCallback(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsKeyboardDelegate* me = AbilityRuntime::CheckParamsAndGetThis<JsKeyboardDelegate>(engine, info);
|
||||
JsKeyboardDelegate* me = CheckParamsAndGetThis<JsKeyboardDelegate>(engine, info);
|
||||
return (me != nullptr) ? me->OnRegisterCallback(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue* JsKeyboardDelegate::UnRegisterCallback(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsKeyboardDelegate* me = AbilityRuntime::CheckParamsAndGetThis<JsKeyboardDelegate>(engine, info);
|
||||
JsKeyboardDelegate* me = CheckParamsAndGetThis<JsKeyboardDelegate>(engine, info);
|
||||
return (me != nullptr) ? me->OnUnRegisterCallback(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
@@ -69,7 +70,7 @@ namespace MiscServices {
|
||||
}
|
||||
|
||||
std::string cbType;
|
||||
if (!AbilityRuntime::ConvertFromJsValue(engine, info.argv[0], cbType)) {
|
||||
if (!ConvertFromJsValue(engine, info.argv[0], cbType)) {
|
||||
IMSA_HILOGI("JsKeyboardDelegate::OnRegisterCallback Failed to convert parameter to callbackType");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
@@ -88,7 +89,7 @@ namespace MiscServices {
|
||||
}
|
||||
|
||||
std::string cbType;
|
||||
if (!AbilityRuntime::ConvertFromJsValue(engine, info.argv[0], cbType)) {
|
||||
if (!ConvertFromJsValue(engine, info.argv[0], cbType)) {
|
||||
IMSA_HILOGI("JsKeyboardDelegate::OnUnRegisterCallback Failed to convert parameter to callbackType");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
void JsKeyboardDelegateListener::RegisterListenerWithType(NativeEngine& engine,
|
||||
std::string type, NativeValue* value)
|
||||
using namespace AbilityRuntime;
|
||||
void JsKeyboardDelegateListener::RegisterListenerWithType(NativeEngine& engine, std::string type, NativeValue* value)
|
||||
{
|
||||
// should do type check
|
||||
if (IfCallbackRegistered(type, value)) {
|
||||
@@ -120,7 +120,7 @@ namespace MiscServices {
|
||||
for (auto iter = jsCbMap_[methodName].begin(); iter != jsCbMap_[methodName].end(); iter++) {
|
||||
NativeValue* nativeValue = engine_->CallFunction(engine_->CreateUndefined(), (*iter)->Get(), argv, argc);
|
||||
bool ret = false;
|
||||
if (AbilityRuntime::ConvertFromJsValue(*engine_, nativeValue, ret) && ret) {
|
||||
if (ConvertFromJsValue(*engine_, nativeValue, ret) && ret) {
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
@@ -133,7 +133,7 @@ namespace MiscServices {
|
||||
IMSA_HILOGI("JsKeyboardDelegateListener::OnKeyEvent");
|
||||
|
||||
NativeValue* nativeValue = engine_->CreateObject();
|
||||
NativeObject* object = AbilityRuntime::ConvertNativeValueTo<NativeObject>(nativeValue);
|
||||
NativeObject* object = ConvertNativeValueTo<NativeObject>(nativeValue);
|
||||
if (object == nullptr) {
|
||||
IMSA_HILOGI("Failed to convert rect to jsObject");
|
||||
return false;
|
||||
@@ -145,9 +145,9 @@ namespace MiscServices {
|
||||
} else {
|
||||
methodName = "keyUp";
|
||||
}
|
||||
object->SetProperty("keyCode", AbilityRuntime::CreateJsValue(*engine_, static_cast<uint32_t>(keyCode)));
|
||||
object->SetProperty("keyAction", AbilityRuntime::CreateJsValue(*engine_, static_cast<uint32_t>(keyStatus)));
|
||||
return CallJsMethodReturnBool(methodName, argv, AbilityRuntime::ArraySize(argv));
|
||||
object->SetProperty("keyCode", CreateJsValue(*engine_, static_cast<uint32_t>(keyCode)));
|
||||
object->SetProperty("keyAction", CreateJsValue(*engine_, static_cast<uint32_t>(keyStatus)));
|
||||
return CallJsMethodReturnBool(methodName, argv, ArraySize(argv));
|
||||
}
|
||||
|
||||
void JsKeyboardDelegateListener::OnCursorUpdate(int32_t positionX, int32_t positionY, int height)
|
||||
@@ -156,32 +156,31 @@ namespace MiscServices {
|
||||
IMSA_HILOGI("JsKeyboardDelegateListener::OnCursorUpdate");
|
||||
|
||||
auto task = [this, positionX, positionY, height] () {
|
||||
NativeValue* nativeXValue = AbilityRuntime::CreateJsValue(*engine_, static_cast<uint32_t>(positionX));
|
||||
NativeValue* nativeYValue = AbilityRuntime::CreateJsValue(*engine_, static_cast<uint32_t>(positionY));
|
||||
NativeValue* nativeHValue = AbilityRuntime::CreateJsValue(*engine_, static_cast<uint32_t>(height));
|
||||
NativeValue* nativeXValue = CreateJsValue(*engine_, static_cast<uint32_t>(positionX));
|
||||
NativeValue* nativeYValue = CreateJsValue(*engine_, static_cast<uint32_t>(positionY));
|
||||
NativeValue* nativeHValue = CreateJsValue(*engine_, static_cast<uint32_t>(height));
|
||||
|
||||
NativeValue* argv[] = {nativeXValue, nativeYValue, nativeHValue};
|
||||
std::string methodName = "cursorContextChange";
|
||||
CallJsMethod(methodName, argv, AbilityRuntime::ArraySize(argv));
|
||||
CallJsMethod(methodName, argv, ArraySize(argv));
|
||||
};
|
||||
mainHandler_->PostTask(task);
|
||||
}
|
||||
|
||||
void JsKeyboardDelegateListener::OnSelectionChange(int32_t oldBegin, int32_t oldEnd,
|
||||
int32_t newBegin, int32_t newEnd)
|
||||
void JsKeyboardDelegateListener::OnSelectionChange(int32_t oldBegin, int32_t oldEnd, int32_t newBegin, int32_t newEnd)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
IMSA_HILOGI("JsKeyboardDelegateListener::OnSelectionChange");
|
||||
|
||||
auto task = [this, oldBegin, oldEnd, newBegin, newEnd] () {
|
||||
NativeValue* nativeOBValue = AbilityRuntime::CreateJsValue(*engine_, static_cast<uint32_t>(oldBegin));
|
||||
NativeValue* nativeOEValue = AbilityRuntime::CreateJsValue(*engine_, static_cast<uint32_t>(oldEnd));
|
||||
NativeValue* nativeNBHValue = AbilityRuntime::CreateJsValue(*engine_, static_cast<uint32_t>(newBegin));
|
||||
NativeValue* nativeNEValue = AbilityRuntime::CreateJsValue(*engine_, static_cast<uint32_t>(newEnd));
|
||||
NativeValue* nativeOBValue = CreateJsValue(*engine_, static_cast<uint32_t>(oldBegin));
|
||||
NativeValue* nativeOEValue = CreateJsValue(*engine_, static_cast<uint32_t>(oldEnd));
|
||||
NativeValue* nativeNBHValue = CreateJsValue(*engine_, static_cast<uint32_t>(newBegin));
|
||||
NativeValue* nativeNEValue = CreateJsValue(*engine_, static_cast<uint32_t>(newEnd));
|
||||
|
||||
NativeValue* argv[] = {nativeOBValue, nativeOEValue, nativeNBHValue, nativeNEValue};
|
||||
std::string methodName = "selectionChange";
|
||||
CallJsMethod(methodName, argv, AbilityRuntime::ArraySize(argv));
|
||||
CallJsMethod(methodName, argv, ArraySize(argv));
|
||||
};
|
||||
|
||||
mainHandler_->PostTask(task);
|
||||
@@ -192,11 +191,11 @@ namespace MiscServices {
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
IMSA_HILOGI("JsKeyboardDelegateListener::OnTextChange");
|
||||
auto task = [this, text] () {
|
||||
NativeValue* nativeValue = AbilityRuntime::CreateJsValue(*engine_, text);
|
||||
NativeValue* nativeValue = CreateJsValue(*engine_, text);
|
||||
|
||||
NativeValue* argv[] = {nativeValue};
|
||||
std::string methodName = "textChange";
|
||||
CallJsMethod(methodName, argv, AbilityRuntime::ArraySize(argv));
|
||||
CallJsMethod(methodName, argv, ArraySize(argv));
|
||||
};
|
||||
|
||||
mainHandler_->PostTask(task);
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "js_input_method_engine_utils.h"
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
using namespace AbilityRuntime;
|
||||
constexpr size_t ARGC_ZERO = 0;
|
||||
constexpr size_t ARGC_ONE = 1;
|
||||
|
||||
@@ -34,43 +35,43 @@ namespace MiscServices {
|
||||
|
||||
NativeValue* JsTextInputClient::InsertText(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsTextInputClient* me = AbilityRuntime::CheckParamsAndGetThis<JsTextInputClient>(engine, info);
|
||||
JsTextInputClient* me = CheckParamsAndGetThis<JsTextInputClient>(engine, info);
|
||||
return (me != nullptr) ? me->OnInsertText(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue* JsTextInputClient::DeleteForward(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsTextInputClient* me = AbilityRuntime::CheckParamsAndGetThis<JsTextInputClient>(engine, info);
|
||||
JsTextInputClient* me = CheckParamsAndGetThis<JsTextInputClient>(engine, info);
|
||||
return (me != nullptr) ? me->OnDeleteForward(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue* JsTextInputClient::DeleteBackward(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsTextInputClient* me = AbilityRuntime::CheckParamsAndGetThis<JsTextInputClient>(engine, info);
|
||||
JsTextInputClient* me = CheckParamsAndGetThis<JsTextInputClient>(engine, info);
|
||||
return (me != nullptr) ? me->OnDeleteBackward(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue* JsTextInputClient::SendFunctionKey(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsTextInputClient* me = AbilityRuntime::CheckParamsAndGetThis<JsTextInputClient>(engine, info);
|
||||
JsTextInputClient* me = CheckParamsAndGetThis<JsTextInputClient>(engine, info);
|
||||
return (me != nullptr) ? me->OnSendFunctionKey(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue* JsTextInputClient::GetForward(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsTextInputClient* me = AbilityRuntime::CheckParamsAndGetThis<JsTextInputClient>(engine, info);
|
||||
JsTextInputClient* me = CheckParamsAndGetThis<JsTextInputClient>(engine, info);
|
||||
return (me != nullptr) ? me->OnGetForward(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue* JsTextInputClient::GetBackward(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsTextInputClient* me = AbilityRuntime::CheckParamsAndGetThis<JsTextInputClient>(engine, info);
|
||||
JsTextInputClient* me = CheckParamsAndGetThis<JsTextInputClient>(engine, info);
|
||||
return (me != nullptr) ? me->OnGetBackward(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue* JsTextInputClient::GetEditorAttribute(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsTextInputClient* me = AbilityRuntime::CheckParamsAndGetThis<JsTextInputClient>(engine, info);
|
||||
JsTextInputClient* me = CheckParamsAndGetThis<JsTextInputClient>(engine, info);
|
||||
return (me != nullptr) ? me->OnGetEditorAttribute(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
@@ -86,14 +87,14 @@ namespace MiscServices {
|
||||
nativeString = info.argv[ARGC_ZERO];
|
||||
|
||||
std::string textString;
|
||||
if (!AbilityRuntime::ConvertFromJsValue(engine, nativeString, textString)) {
|
||||
if (!ConvertFromJsValue(engine, nativeString, textString)) {
|
||||
IMSA_HILOGI("JsTextInputClient::OnInsertText Failed to convert parameter to string");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
bool ret = InputMethodAbility::GetInstance()->InsertText(textString);
|
||||
|
||||
NativeValue* result = AbilityRuntime::CreateJsValue(engine, ret);
|
||||
NativeValue* result = CreateJsValue(engine, ret);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -110,14 +111,14 @@ namespace MiscServices {
|
||||
nativeString = info.argv[ARGC_ZERO];
|
||||
|
||||
int32_t number;
|
||||
if (!AbilityRuntime::ConvertFromJsValue(engine, nativeString, number)) {
|
||||
if (!ConvertFromJsValue(engine, nativeString, number)) {
|
||||
IMSA_HILOGI("JsTextInputClient::OnDeleteForward Failed to convert parameter to string");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
InputMethodAbility::GetInstance()->DeleteForward(number);
|
||||
|
||||
NativeValue* result = AbilityRuntime::CreateJsValue(engine, true);
|
||||
NativeValue* result = CreateJsValue(engine, true);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -134,14 +135,14 @@ namespace MiscServices {
|
||||
nativeString = info.argv[ARGC_ZERO];
|
||||
|
||||
int32_t number;
|
||||
if (!AbilityRuntime::ConvertFromJsValue(engine, nativeString, number)) {
|
||||
if (!ConvertFromJsValue(engine, nativeString, number)) {
|
||||
IMSA_HILOGI("JsTextInputClient::OnDeleteBackward Failed to convert parameter to string");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
InputMethodAbility::GetInstance()->DeleteBackward(number);
|
||||
|
||||
NativeValue* result = AbilityRuntime::CreateJsValue(engine, true);
|
||||
NativeValue* result = CreateJsValue(engine, true);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -158,14 +159,14 @@ namespace MiscServices {
|
||||
nativeString = info.argv[ARGC_ZERO];
|
||||
|
||||
int32_t number;
|
||||
if (!AbilityRuntime::ConvertFromJsValue(engine, nativeString, number)) {
|
||||
if (!ConvertFromJsValue(engine, nativeString, number)) {
|
||||
IMSA_HILOGI("JsTextInputClient::OnSendFunctionKey Failed to convert parameter to string");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
InputMethodAbility::GetInstance()->SendFunctionKey(number);
|
||||
|
||||
NativeValue* result = AbilityRuntime::CreateJsValue(engine, true);
|
||||
NativeValue* result = CreateJsValue(engine, true);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -182,14 +183,14 @@ namespace MiscServices {
|
||||
nativeString = info.argv[ARGC_ZERO];
|
||||
|
||||
int32_t number;
|
||||
if (!AbilityRuntime::ConvertFromJsValue(engine, nativeString, number)) {
|
||||
if (!ConvertFromJsValue(engine, nativeString, number)) {
|
||||
IMSA_HILOGI("JsTextInputClient::OnGetForward Failed to convert parameter to string");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
std::string ret = Str16ToStr8(InputMethodAbility::GetInstance()->GetTextBeforeCursor(number));
|
||||
|
||||
NativeValue* result = AbilityRuntime::CreateJsValue(engine, ret);
|
||||
NativeValue* result = CreateJsValue(engine, ret);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -206,14 +207,14 @@ namespace MiscServices {
|
||||
nativeString = info.argv[ARGC_ZERO];
|
||||
|
||||
int32_t number;
|
||||
if (!AbilityRuntime::ConvertFromJsValue(engine, nativeString, number)) {
|
||||
if (!ConvertFromJsValue(engine, nativeString, number)) {
|
||||
IMSA_HILOGI("JsTextInputClient::OnGetBackward Failed to convert parameter to string");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
std::string ret = Str16ToStr8(InputMethodAbility::GetInstance()->GetTextAfterCursor(number));
|
||||
|
||||
NativeValue* result = AbilityRuntime::CreateJsValue(engine, ret);
|
||||
NativeValue* result = CreateJsValue(engine, ret);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user