mirror of
https://github.com/openharmony/miscservices_inputmethod.git
synced 2026-07-18 17:24:37 -04:00
@@ -35,6 +35,7 @@ namespace MiscServices {
|
||||
virtual ~JsInputMethodEngineListener() = default;
|
||||
void RegisterListenerWithType(NativeEngine& engine, std::string type, NativeValue* value);
|
||||
void UnregisterListenerWithType(std::string type, NativeValue* value);
|
||||
void UnregisterAllListenerWithType(std::string type);
|
||||
void OnKeyboardStatus(bool isShow);
|
||||
void OnInputStart();
|
||||
void OnInputStop(std::string imeId);
|
||||
|
||||
@@ -35,6 +35,7 @@ namespace MiscServices {
|
||||
virtual ~JsKeyboardDelegateListener() = default;
|
||||
void RegisterListenerWithType(NativeEngine& engine, std::string type, NativeValue* value);
|
||||
void UnregisterListenerWithType(std::string type, NativeValue* value);
|
||||
void UnregisterAllListenerWithType(std::string type);
|
||||
bool OnKeyEvent(int32_t keyCode, int32_t keyStatus);
|
||||
void OnCursorUpdate(int32_t positionX, int32_t positionY, int height);
|
||||
void OnSelectionChange(int32_t oldBegin, int32_t oldEnd, int32_t newBegin, int32_t newEnd);
|
||||
|
||||
@@ -94,13 +94,17 @@ namespace MiscServices {
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(mtx_);
|
||||
NativeValue* value = info.argv[1];
|
||||
if (!value->IsCallable()) {
|
||||
IMSA_HILOGI("JsInputMethodEngine::OnUnregisterWindowManagerCallback info->argv[1] is not callable");
|
||||
return engine.CreateUndefined();
|
||||
if (info.argc == 1) {
|
||||
imeListener_->UnregisterAllListenerWithType(cbType);
|
||||
} else {
|
||||
std::lock_guard<std::mutex> lock(mtx_);
|
||||
NativeValue* value = info.argv[1];
|
||||
if (!value->IsCallable()) {
|
||||
IMSA_HILOGI("JsInputMethodEngine::OnUnregisterWindowManagerCallback info->argv[1] is not callable");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
imeListener_->UnregisterListenerWithType(cbType, value);
|
||||
}
|
||||
imeListener_->UnregisterListenerWithType(cbType, value);
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,24 @@ namespace MiscServices {
|
||||
return;
|
||||
}
|
||||
|
||||
void JsInputMethodEngineListener::UnregisterAllListenerWithType(std::string type)
|
||||
{
|
||||
IMSA_HILOGI("JsInputMethodEngineListener::UnregisterAllListenerWithType");
|
||||
// should do type check
|
||||
if (jsCbMap_.empty() || jsCbMap_.find(type) == jsCbMap_.end()) {
|
||||
IMSA_HILOGI("methodName %{public}s not registerted!", type.c_str());
|
||||
return;
|
||||
}
|
||||
for (auto it = jsCbMap_[type].begin(); it != jsCbMap_[type].end();) {
|
||||
jsCbMap_[type].erase(it);
|
||||
}
|
||||
// one type with multi jscallback, erase type when there is no callback in one type
|
||||
if (jsCbMap_[type].empty()) {
|
||||
jsCbMap_.erase(type);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void JsInputMethodEngineListener::UnregisterListenerWithType(std::string type, NativeValue* value)
|
||||
{
|
||||
IMSA_HILOGI("JsInputMethodEngineListener::UnregisterListenerWithType");
|
||||
|
||||
@@ -95,12 +95,17 @@ namespace MiscServices {
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(mtx_);
|
||||
NativeValue* value = info.argv[1];
|
||||
if (!value->IsCallable()) {
|
||||
IMSA_HILOGI("JsKeyboardDelegate::OnUnregisterWindowManagerCallback info->argv[1] is not callable");
|
||||
return engine.CreateUndefined();
|
||||
|
||||
if (info.argc == 1) {
|
||||
kdListener_->UnregisterAllListenerWithType(cbType);
|
||||
} else {
|
||||
NativeValue* value = info.argv[1];
|
||||
if (!value->IsCallable()) {
|
||||
IMSA_HILOGI("JsKeyboardDelegate::OnUnregisterWindowManagerCallback info->argv[1] is not callable");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
kdListener_->UnregisterListenerWithType(cbType, value);
|
||||
}
|
||||
kdListener_->UnregisterListenerWithType(cbType, value);
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,23 @@ namespace MiscServices {
|
||||
static_cast<uint32_t>(jsCbMap_.size()), type.c_str(), static_cast<uint32_t>(jsCbMap_[type].size()));
|
||||
return;
|
||||
}
|
||||
void JsKeyboardDelegateListener::UnregisterAllListenerWithType(std::string type)
|
||||
{
|
||||
IMSA_HILOGI("JsKeyboardDelegateListener::UnregisterAllListenerWithType");
|
||||
// should do type check
|
||||
if (jsCbMap_.empty() || jsCbMap_.find(type) == jsCbMap_.end()) {
|
||||
IMSA_HILOGI("methodName %{public}s not registerted!", type.c_str());
|
||||
return;
|
||||
}
|
||||
for (auto it = jsCbMap_[type].begin(); it != jsCbMap_[type].end();) {
|
||||
jsCbMap_[type].erase(it);
|
||||
}
|
||||
// one type with multi jscallback, erase type when there is no callback in one type
|
||||
if (jsCbMap_[type].empty()) {
|
||||
jsCbMap_.erase(type);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void JsKeyboardDelegateListener::UnregisterListenerWithType(std::string type, NativeValue* value)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user