From 2f7df10565193552d0d16a4cfc1563c0b9bf50c0 Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Tue, 15 Jul 2025 21:40:12 +0800 Subject: [PATCH 1/2] Synchronous branch Signed-off-by: li-yaoyao777 --- BUILD.gn | 30 +- bundle.json | 40 + .../ani/input_consumer/src/input_consumer.cpp | 618 ------------ .../ets/@ohos.multimodalInput.pointer.ets | 399 -------- frameworks/ani/pointer/include/ani_utils.h | 497 ---------- frameworks/ani/pointer/src/pointer.cpp | 164 ---- frameworks/ets/gesture_event/BUILD.gn | 90 ++ .../ohos.multimodalInput.gestureEvent.taihe | 74 ++ .../gesture_event/src/ani_constructor.cpp} | 29 +- ...ohos.multimodalInput.gestureEvent.impl.cpp | 29 + frameworks/ets/input_consumer/BUILD.gn | 96 ++ .../ohos.multimodalInput.inputConsumer.taihe | 80 ++ .../inputConsumer_hotkeyOptions_impl.h} | 95 +- .../include/inputConsumer_keyOptions_impl.h | 36 + .../include/inputConsumer_keyPressed_impl.h | 49 + .../input_consumer/src/ani_constructor.cpp | 29 + .../src/inputConsumer_hotkeyOptions_impl.cpp | 44 + .../src/inputConsumer_keyOptions_impl.cpp | 66 ++ .../src/inputConsumer_keyPressed_impl.cpp | 134 +++ ...hos.multimodalInput.inputConsumer.impl.cpp | 904 ++++++++++++++++++ frameworks/ets/input_device/BUILD.gn | 91 ++ .../ohos.multimodalInput.inputDevice.taihe | 96 ++ .../ets/input_device/src/ani_constructor.cpp | 30 + .../ohos.multimodalInput.inputDevice.impl.cpp | 29 + frameworks/ets/input_event/BUILD.gn | 48 + .../idl/ohos.multimodalInput.inputEvent.taihe | 24 + .../ets/input_event/src/ani_constructor.cpp | 29 + .../ohos.multimodalInput.inputEvent.impl.cpp | 29 + frameworks/ets/input_event_client/BUILD.gn | 92 ++ ...hos.multimodalInput.inputEventClient.taihe | 24 + .../src/ani_constructor.cpp | 30 + ....multimodalInput.inputEventClient.impl.cpp | 29 + frameworks/ets/input_monitor/BUILD.gn | 94 ++ .../ohos.multimodalInput.inputMonitor.taihe | 25 + .../ets/input_monitor/src/ani_constructor.cpp | 30 + ...ohos.multimodalInput.inputMonitor.impl.cpp | 29 + frameworks/ets/intention_code/BUILD.gn | 89 ++ .../ohos.multimodalInput.intentionCode.taihe | 36 + .../intention_code/src/ani_constructor.cpp | 29 + ...hos.multimodalInput.intentionCode.impl.cpp | 29 + .../input_consumer => ets/key_code}/BUILD.gn | 107 ++- .../idl/ohos.multimodalInput.keyCode.taihe | 369 +++++++ .../ohos.multimodalInput.keyCode.impl.h | 386 ++++++++ .../ets/key_code/src/ani_constructor.cpp | 29 + .../src/ohos.multimodalInput.keyCode.impl.cpp | 388 ++++++++ frameworks/ets/key_event/BUILD.gn | 95 ++ .../idl/ohos.multimodalInput.keyEvent.taihe | 49 + .../ets/key_event/src/ani_constructor.cpp | 29 + .../ohos.multimodalInput.keyEvent.impl.cpp | 29 + frameworks/ets/mouse_event/BUILD.gn | 93 ++ .../idl/ohos.multimodalInput.mouseEvent.taihe | 86 ++ .../ets/mouse_event/src/ani_constructor.cpp | 29 + .../ohos.multimodalInput.mouseEvent.impl.cpp | 29 + frameworks/{ani => ets}/pointer/BUILD.gn | 111 ++- .../idl/ohos.multimodalInput.pointer.taihe | 92 ++ .../ohos.multimodalInput.pointer.impl.h | 90 ++ .../ets/pointer/src/ani_constructor.cpp | 30 + .../src/ohos.multimodalInput.pointer.impl.cpp | 138 +++ frameworks/ets/short_key/BUILD.gn | 89 ++ .../idl/ohos.multimodalInput.shortKey.taihe} | 35 +- .../ets/short_key/src/ani_constructor.cpp | 29 + .../ohos.multimodalInput.shortKey.impl.cpp | 29 + frameworks/ets/touch_event/BUILD.gn | 90 ++ .../idl/ohos.multimodalInput.touchEvent.taihe | 81 ++ .../ets/touch_event/src/ani_constructor.cpp | 29 + .../ohos.multimodalInput.touchEvent.impl.cpp | 29 + 66 files changed, 5127 insertions(+), 1878 deletions(-) delete mode 100644 frameworks/ani/input_consumer/src/input_consumer.cpp delete mode 100644 frameworks/ani/pointer/ets/@ohos.multimodalInput.pointer.ets delete mode 100644 frameworks/ani/pointer/include/ani_utils.h delete mode 100644 frameworks/ani/pointer/src/pointer.cpp create mode 100644 frameworks/ets/gesture_event/BUILD.gn create mode 100644 frameworks/ets/gesture_event/idl/ohos.multimodalInput.gestureEvent.taihe rename frameworks/{ani/input_consumer/ets/@ohos.multimodalInput.inputConsumer.ets => ets/gesture_event/src/ani_constructor.cpp} (50%) create mode 100644 frameworks/ets/gesture_event/src/ohos.multimodalInput.gestureEvent.impl.cpp create mode 100644 frameworks/ets/input_consumer/BUILD.gn create mode 100644 frameworks/ets/input_consumer/idl/ohos.multimodalInput.inputConsumer.taihe rename frameworks/{ani/input_consumer/include/input_consumer.h => ets/input_consumer/include/inputConsumer_hotkeyOptions_impl.h} (31%) create mode 100644 frameworks/ets/input_consumer/include/inputConsumer_keyOptions_impl.h create mode 100644 frameworks/ets/input_consumer/include/inputConsumer_keyPressed_impl.h create mode 100644 frameworks/ets/input_consumer/src/ani_constructor.cpp create mode 100644 frameworks/ets/input_consumer/src/inputConsumer_hotkeyOptions_impl.cpp create mode 100644 frameworks/ets/input_consumer/src/inputConsumer_keyOptions_impl.cpp create mode 100644 frameworks/ets/input_consumer/src/inputConsumer_keyPressed_impl.cpp create mode 100644 frameworks/ets/input_consumer/src/ohos.multimodalInput.inputConsumer.impl.cpp create mode 100644 frameworks/ets/input_device/BUILD.gn create mode 100644 frameworks/ets/input_device/idl/ohos.multimodalInput.inputDevice.taihe create mode 100644 frameworks/ets/input_device/src/ani_constructor.cpp create mode 100644 frameworks/ets/input_device/src/ohos.multimodalInput.inputDevice.impl.cpp create mode 100644 frameworks/ets/input_event/BUILD.gn create mode 100644 frameworks/ets/input_event/idl/ohos.multimodalInput.inputEvent.taihe create mode 100644 frameworks/ets/input_event/src/ani_constructor.cpp create mode 100644 frameworks/ets/input_event/src/ohos.multimodalInput.inputEvent.impl.cpp create mode 100644 frameworks/ets/input_event_client/BUILD.gn create mode 100644 frameworks/ets/input_event_client/idl/ohos.multimodalInput.inputEventClient.taihe create mode 100644 frameworks/ets/input_event_client/src/ani_constructor.cpp create mode 100644 frameworks/ets/input_event_client/src/ohos.multimodalInput.inputEventClient.impl.cpp create mode 100644 frameworks/ets/input_monitor/BUILD.gn create mode 100644 frameworks/ets/input_monitor/idl/ohos.multimodalInput.inputMonitor.taihe create mode 100644 frameworks/ets/input_monitor/src/ani_constructor.cpp create mode 100644 frameworks/ets/input_monitor/src/ohos.multimodalInput.inputMonitor.impl.cpp create mode 100644 frameworks/ets/intention_code/BUILD.gn create mode 100644 frameworks/ets/intention_code/idl/ohos.multimodalInput.intentionCode.taihe create mode 100644 frameworks/ets/intention_code/src/ani_constructor.cpp create mode 100644 frameworks/ets/intention_code/src/ohos.multimodalInput.intentionCode.impl.cpp rename frameworks/{ani/input_consumer => ets/key_code}/BUILD.gn (43%) create mode 100644 frameworks/ets/key_code/idl/ohos.multimodalInput.keyCode.taihe create mode 100644 frameworks/ets/key_code/include/ohos.multimodalInput.keyCode.impl.h create mode 100644 frameworks/ets/key_code/src/ani_constructor.cpp create mode 100644 frameworks/ets/key_code/src/ohos.multimodalInput.keyCode.impl.cpp create mode 100644 frameworks/ets/key_event/BUILD.gn create mode 100644 frameworks/ets/key_event/idl/ohos.multimodalInput.keyEvent.taihe create mode 100644 frameworks/ets/key_event/src/ani_constructor.cpp create mode 100644 frameworks/ets/key_event/src/ohos.multimodalInput.keyEvent.impl.cpp create mode 100644 frameworks/ets/mouse_event/BUILD.gn create mode 100644 frameworks/ets/mouse_event/idl/ohos.multimodalInput.mouseEvent.taihe create mode 100644 frameworks/ets/mouse_event/src/ani_constructor.cpp create mode 100644 frameworks/ets/mouse_event/src/ohos.multimodalInput.mouseEvent.impl.cpp rename frameworks/{ani => ets}/pointer/BUILD.gn (45%) create mode 100644 frameworks/ets/pointer/idl/ohos.multimodalInput.pointer.taihe create mode 100644 frameworks/ets/pointer/include/ohos.multimodalInput.pointer.impl.h create mode 100644 frameworks/ets/pointer/src/ani_constructor.cpp create mode 100644 frameworks/ets/pointer/src/ohos.multimodalInput.pointer.impl.cpp create mode 100644 frameworks/ets/short_key/BUILD.gn rename frameworks/{ani/pointer/include/pointer.h => ets/short_key/idl/ohos.multimodalInput.shortKey.taihe} (59%) create mode 100644 frameworks/ets/short_key/src/ani_constructor.cpp create mode 100644 frameworks/ets/short_key/src/ohos.multimodalInput.shortKey.impl.cpp create mode 100644 frameworks/ets/touch_event/BUILD.gn create mode 100644 frameworks/ets/touch_event/idl/ohos.multimodalInput.touchEvent.taihe create mode 100644 frameworks/ets/touch_event/src/ani_constructor.cpp create mode 100644 frameworks/ets/touch_event/src/ohos.multimodalInput.touchEvent.impl.cpp diff --git a/BUILD.gn b/BUILD.gn index 0db7e286bc..028c2514df 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -123,13 +123,11 @@ group("input_jsapi_group") { } if (input_feature_mouse) { deps += [ - "frameworks/ani/pointer:ani_pointer_package", "frameworks/napi/pointer:pointer", ] } if (input_feature_keyboard) { deps += [ - "frameworks/ani/input_consumer:input_consumer_package", "frameworks/napi/input_consumer:inputconsumer", "frameworks/napi/input_event_client:inputeventclient", ] @@ -147,6 +145,34 @@ group("input_jsapi_group") { } } +group("input_ets_group") { + deps = [ + "frameworks/ets/input_event:ets_inputEvent_package", + "frameworks/ets/intention_code:ets_intentionCode_package", + "frameworks/ets/input_monitor:ets_inputMonitor_package", + "frameworks/ets/key_code:ets_keyCode_package", + "frameworks/ets/key_event:ets_keyEvent_package", + "frameworks/ets/mouse_event:ets_mouseEvent_package", + "frameworks/ets/touch_event:ets_touchEvent_package", + "frameworks/ets/gesture_event:ets_gestureEvent_package" + ] + if (input_feature_keyboard) { + deps += [ + "frameworks/ets/input_consumer:ets_inputConsumer_package", + "frameworks/ets/input_event_client:ets_inputEventClient_package" + ] + } + if (input_feature_input_device) { + deps += [ "frameworks/ets/input_device:ets_inputDevice_package" ] + } + if (input_feature_mouse) { + deps += [ "frameworks/ets/pointer:ets_pointer_package" ] + } + if (input_feature_short_key) { + deps += [ "frameworks/ets/short_key:ets_shortKey_package" ] + } +} + group("mmi_tests") { testonly = true deps = [ diff --git a/bundle.json b/bundle.json index cc8eacd88c..76bc50fe08 100644 --- a/bundle.json +++ b/bundle.json @@ -121,6 +121,7 @@ "fwk_group": [ "//foundation/multimodalinput/input:multimodalinput_mmi_frameworks", "//foundation/multimodalinput/input:input_jsapi_group", + "//foundation/multimodalinput/input:input_ets_group", "//foundation/multimodalinput/input/frameworks/native/input:oh_input_manager" ], "service_group": [ @@ -172,6 +173,45 @@ }, { "name": "//foundation/multimodalinput/input/libudev:mmi_libudev" + }, + { + "name": "//foundation/multimodalinput/input/frameworks/ets/input_consumer:input_consumer_taihe" + }, + { + "name": "//foundation/multimodalinput/input/frameworks/ets/input_event:input_event_taihe" + }, + { + "name": "//foundation/multimodalinput/input/frameworks/ets/input_monitor:input_monitor_taihe" + }, + { + "name": "//foundation/multimodalinput/input/frameworks/ets/intention_code:intention_code_taihe" + }, + { + "name": "//foundation/multimodalinput/input/frameworks/ets/gesture_event:gesture_event_taihe" + }, + { + "name": "//foundation/multimodalinput/input/frameworks/ets/mouse_event:mouse_event_taihe" + }, + { + "name": "//foundation/multimodalinput/input/frameworks/ets/key_code:key_code_taihe" + }, + { + "name": "//foundation/multimodalinput/input/frameworks/ets/key_event:key_event_taihe" + }, + { + "name": "//foundation/multimodalinput/input/frameworks/ets/short_key:short_key_taihe" + }, + { + "name": "//foundation/multimodalinput/input/frameworks/ets/touch_event:touch_event_taihe" + }, + { + "name": "//foundation/multimodalinput/input/frameworks/ets/input_event_client:input_event_client_taihe" + }, + { + "name": "//foundation/multimodalinput/input/frameworks/ets/input_device:input_device_taihe" + }, + { + "name": "//foundation/multimodalinput/input/frameworks/ets/pointer:pointer_taihe" } ], "test": [ diff --git a/frameworks/ani/input_consumer/src/input_consumer.cpp b/frameworks/ani/input_consumer/src/input_consumer.cpp deleted file mode 100644 index 1e4fa3b165..0000000000 --- a/frameworks/ani/input_consumer/src/input_consumer.cpp +++ /dev/null @@ -1,618 +0,0 @@ - /* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "input_consumer.h" -#include - -#include "define_multimodal.h" -#include "napi_constants.h" -#include "mmi_log.h" -#include "input_manager.h" - - -#undef MMI_LOG_TAG -#define MMI_LOG_TAG "AniInputConsumer" - -using namespace OHOS::MMI; - -namespace { -constexpr int32_t ANI_SCOPE_SIZE = 16; -constexpr int32_t MILLISECOND_FACTOR = 1000; -constexpr size_t PRE_KEYS_SIZE { 4 }; -const double INT32_MAX_D = static_cast(std::numeric_limits::max()); -} // namespace - -static Callbacks callbacks = {}; -static std::mutex sCallBacksMutex; - -KeyEventMonitorInfo::~KeyEventMonitorInfo() -{ - if (env == nullptr) { - return; - } - if (callback != nullptr) { - env->GlobalReference_Delete(callback); - } - if (keyOptionsObj != nullptr) { - env->GlobalReference_Delete(keyOptionsObj); - } - callback = nullptr; - keyOptionsObj = nullptr; -} - -static ani_error CreateAniError(ani_env *env, std::string &&errMsg) -{ - static const char *errorClsName = "Lescompat/Error;"; - ani_class cls {}; - if (ANI_OK != env->FindClass(errorClsName, &cls)) { - MMI_HILOGE("%{public}s: Not found namespace %{public}s.", __func__, errorClsName); - return nullptr; - } - ani_method ctor; - if (ANI_OK != env->Class_FindMethod(cls, "", "Lstd/core/String;:V", &ctor)) { - MMI_HILOGE("%{public}s: Not found in %{public}s.", __func__, errorClsName); - return nullptr; - } - ani_string error_msg; - env->String_NewUTF8(errMsg.c_str(), 17U, &error_msg); - ani_object errorObject; - env->Object_New(cls, ctor, &errorObject, error_msg); - return static_cast(errorObject); -} - -static std::optional GetIsRepeat(ani_env *env, ani_object keyOptionsObj) -{ - ani_ref aniRef; - if (ANI_OK != env->Object_GetPropertyByName_Ref(keyOptionsObj, "isRepeat", &aniRef)) { - MMI_HILOGE("%{public}s: Object_GetPropertyByName_Ref isRepeat failed.", __func__); - return std::nullopt; - } - - ani_boolean isUndefined; - if (ANI_OK != env->Reference_IsUndefined(aniRef, &isUndefined)) { - MMI_HILOGE("%{public}s: Object_GetFieldByName_Ref isRepeat failed.", __func__); - return std::nullopt; - } - - if (isUndefined) { - MMI_HILOGE("%{public}s: Param 'isRepeat' is undefined.", __func__); - return std::nullopt; - } - - ani_boolean isRepeat; - auto ret = env->Object_CallMethodByName_Boolean(static_cast(aniRef), "unboxed", nullptr, &isRepeat); - if (ret != ANI_OK) { - MMI_HILOGE("%{public}s: Object_CallMethodByName_Boolean failed.", __func__); - return std::nullopt; - } - return static_cast(isRepeat); -} - -static std::string AniStringToString(ani_env *env, ani_string aniStr) -{ - ani_size strSize; - env->String_GetUTF8Size(aniStr, &strSize); - - std::vector buffer(strSize + 1); - char* utf8Buffer = buffer.data(); - - ani_size bytes_written = 0; - env->String_GetUTF8(aniStr, utf8Buffer, strSize + 1, &bytes_written); - - utf8Buffer[bytes_written] = '\0'; - std::string content = std::string(utf8Buffer); - return content; -} - -static bool GetPreKeys(ani_env *env, ani_object keyOptionsObj, std::set &preKeys) -{ - CALL_DEBUG_ENTER; - ani_ref ref; - if (ANI_OK != env->Object_GetPropertyByName_Ref(keyOptionsObj, "preKeys", &ref)) { - MMI_HILOGE("Object_GetPropertyByName_Ref Failed"); - return false; - } - ani_object arrayObj = static_cast(ref); - ani_double length; - if (ANI_OK != env->Object_GetPropertyByName_Double(arrayObj, "length", &length)) { - MMI_HILOGE("Object_GetPropertyByName_Double length Failed"); - return false; - } - for (int i = 0; i < int(length); i++) { - ani_ref intArrayRef; - if (ANI_OK != env->Object_CallMethodByName_Ref(arrayObj, "$_get", "I:Lstd/core/Object;", &intArrayRef, - (ani_int)i)) { - MMI_HILOGE("Object_GetPropertyByName_Ref Failed"); - return false; - } - ani_double doubleEntry; - if (ANI_OK != env->Object_CallMethodByName_Double(static_cast(intArrayRef), "unboxed", nullptr, - &doubleEntry)) { - MMI_HILOGE("Object_CallMethodByName_Double unbox Failed"); - return false; - } - if (doubleEntry > INT32_MAX_D || doubleEntry < 0) { - ani_error error = CreateAniError(env, "preKeys must be between 0 and INT32_MAX"); - env->ThrowError(error); - MMI_HILOGE("preKey:%{public}f is less 0 or greater than INT32_MAX, can not process", doubleEntry); - return false; - } - if (!preKeys.insert(static_cast(doubleEntry)).second) { - MMI_HILOGE("Params insert value failed"); - return false; - } - } - return true; -} - -static std::string GenerateEventType(std::shared_ptr &keyOptionPtr) -{ - CALL_DEBUG_ENTER; - std::string eventType; - for (const auto &preKey : keyOptionPtr->GetPreKeys()) { - eventType = eventType + std::to_string(preKey) + ","; - } - eventType = eventType + std::to_string(keyOptionPtr->GetFinalKey()) + "," + - std::to_string(keyOptionPtr->IsFinalKeyDown()) + "," + - std::to_string(keyOptionPtr->GetFinalKeyDownDuration()) + "," + - std::to_string(keyOptionPtr->IsRepeat()); - return eventType; -} - -static std::shared_ptr ParseKeyOptions(ani_env *env, ani_object keyOptionsObj) -{ - CALL_DEBUG_ENTER; - std::shared_ptr keyOptionPtr = std::make_shared(); - - std::set preKeys; - if (!GetPreKeys(env, keyOptionsObj, preKeys) || preKeys.size() > PRE_KEYS_SIZE) { - MMI_HILOGE("PreKeys is invalid"); - ani_error error = CreateAniError(env, "PreKeys is invalid"); - env->ThrowError(error); - return nullptr; - } - keyOptionPtr->SetPreKeys(preKeys); - - ani_double finalKey; - if (ANI_OK != env->Object_GetPropertyByName_Double(keyOptionsObj, "finalKey", &finalKey)) { - MMI_HILOGE("Object_GetPropertyByName_Double finalKey Failed"); - return nullptr; - } - if (finalKey > INT32_MAX_D || finalKey < 0) { - MMI_HILOGE("finalKey:%{private}f is less 0 or greater than INT32_MAX, can not process", finalKey); - ani_error error = CreateAniError(env, "finalKey must be between 0 and INT32_MAX"); - env->ThrowError(error); - return nullptr; - } - keyOptionPtr->SetFinalKey(static_cast(finalKey)); - - ani_boolean isFinalKeyDown; - if (ANI_OK != env->Object_GetPropertyByName_Boolean(keyOptionsObj, "isFinalKeyDown", &isFinalKeyDown)) { - MMI_HILOGE("Object_GetPropertyByName_Boolean isFinalKeyDown Failed"); - return nullptr; - } - keyOptionPtr->SetFinalKeyDown(static_cast(isFinalKeyDown)); - - ani_double finalKeyDownDuration; - if (ANI_OK != env->Object_GetPropertyByName_Double(keyOptionsObj, "finalKeyDownDuration", &finalKeyDownDuration)) { - MMI_HILOGE("Object_GetPropertyByName_Double finalKeyDownDuration Failed"); - return nullptr; - } - if (finalKeyDownDuration > INT32_MAX_D || finalKeyDownDuration < 0) { - MMI_HILOGE("finalKeyDownDuration:%{public}f is less 0 or greater INT32_MAX", finalKeyDownDuration); - ani_error error = CreateAniError(env, "finalKeyDownDuration must be between 0 and INT32_MAX"); - env->ThrowError(error); - return nullptr; - } - keyOptionPtr->SetFinalKeyDownDuration(static_cast(finalKeyDownDuration)); - - bool isRepeat = true; - auto isRepeatOpt = GetIsRepeat(env, keyOptionsObj); - if (isRepeatOpt.has_value()) { - isRepeat = isRepeatOpt.value(); - } - keyOptionPtr->SetRepeat(isRepeat); - - return keyOptionPtr; -} - -static bool IsMatchKeyAction(bool isFinalKeydown, int32_t keyAction) -{ - CALL_DEBUG_ENTER; - MMI_HILOGD("isFinalKeydown:%{public}d, keyAction:%{public}d", isFinalKeydown, keyAction); - if (isFinalKeydown && keyAction == KeyEvent::KEY_ACTION_DOWN) { - return true; - } - if (!isFinalKeydown && keyAction == KeyEvent::KEY_ACTION_UP) { - return true; - } - MMI_HILOGE("isFinalKeydown not matched with keyAction"); - return false; -} - -static bool MatchCombinationKey(KeyOption &combinationKeyOption, KeyEvent &keyEvent) -{ - CALL_DEBUG_ENTER; - std::vector items = keyEvent.GetKeyItems(); - int32_t infoFinalKey = combinationKeyOption.GetFinalKey(); - int32_t keyEventFinalKey = keyEvent.GetKeyCode(); - bool isFinalKeydown = combinationKeyOption.IsFinalKeyDown(); - MMI_HILOGD("InfoFinalKey:%{public}d,keyEventFinalKey:%{public}d,isFinalKeydown:%{public}d", - infoFinalKey, keyEventFinalKey, isFinalKeydown); - if (infoFinalKey != keyEventFinalKey || items.size() > PRE_KEYS_SIZE || - !IsMatchKeyAction(isFinalKeydown, keyEvent.GetKeyAction())) { - MMI_HILOGD("key Param invalid"); - return false; - } - - std::set preKeys = combinationKeyOption.GetPreKeys(); - int32_t infoSize = std::count_if(preKeys.begin(), preKeys.end(), [](int32_t preKey) { return preKey >= 0; }); - int32_t count = 0; - for (const auto &item : items) { - if (item.GetKeyCode() == keyEventFinalKey) { - continue; - } - auto iter = find(preKeys.begin(), preKeys.end(), item.GetKeyCode()); - if (iter == preKeys.end()) { - MMI_HILOGW("No keyCode in preKeys"); - return false; - } - count++; - } - MMI_HILOGD("kevEventSize:%{public}d, infoSize:%{public}d", count, infoSize); - std::optional keyItem = keyEvent.GetKeyItem(); - if (!keyItem) { - MMI_HILOGE("The keyItem is nullopt"); - return false; - } - auto downTime = keyItem->GetDownTime(); - auto upTime = keyEvent.GetActionTime(); - auto curDurationTime = combinationKeyOption.GetFinalKeyDownDuration(); - if (curDurationTime > 0 && (upTime - downTime >= (static_cast(curDurationTime) * MILLISECOND_FACTOR))) { - MMI_HILOGE("Skip, upTime - downTime >= duration"); - return false; - } - return count == infoSize; -} - -static bool SendEventToMainThread(const std::function func) -{ - CALL_DEBUG_ENTER; - if (func == nullptr) { - MMI_HILOGE("%{public}s: func == nullptr", __func__); - return false; - } - auto runner = OHOS::AppExecFwk::EventRunner::GetMainEventRunner(); - if (!runner) { - MMI_HILOGE("%{public}s: runner == nullptr", __func__); - return false; - } - auto handler = std::make_shared(runner); - handler->PostTask(func, "", 0, OHOS::AppExecFwk::EventQueue::Priority::HIGH, {}); - MMI_HILOGD("%{public}s: PostTask success", __func__); - return true; -} - -static ani_boolean IsInstanceOf(ani_env *env, const std::string &cls_name, ani_object obj) -{ - ani_class cls; - if (ANI_OK != env->FindClass(cls_name.c_str(), &cls)) { - MMI_HILOGE("%{public}s: FindClass failed", __func__); - return ANI_FALSE; - } - - ani_boolean ret; - env->Object_InstanceOf(obj, cls, &ret); - return ret; -} - -static void EmitAsyncCallbackWork(std::shared_ptr reportEvent) -{ - CALL_DEBUG_ENTER; - CHKPV(reportEvent); - auto task = [reportEvent]() { - MMI_HILOGD("%{public}s: Begin to call task", __func__); - ani_size nrRefs = ANI_SCOPE_SIZE; - AniLocalScopeGuard aniLocalScopeGuard(reportEvent->env, nrRefs); - if (!aniLocalScopeGuard.IsStatusOK()) { - MMI_HILOGE("%{public}s: CreateLocalScope failed", __func__); - return; - } - auto fnObj = reinterpret_cast(reportEvent->callback); - std::vector args = {reportEvent->keyOptionsObj}; - ani_ref result; - MMI_HILOGD("%{public}s: Begin to call FunctionalObject_Call", __func__); - if (fnObj == nullptr || args.size() == 0) { - MMI_HILOGE("%{public}s: fnObj == nullptr", __func__); - return; - } - if (IsInstanceOf(reportEvent->env, "Lstd/core/Function1;", fnObj) == 0) { - MMI_HILOGE("%{public}s: fnObj is not instance Of function ", __func__); - return; - } - const std::string className = "L@ohos/multimodalInput/inputConsumer/inputConsumer/KeyOptions;"; - if (IsInstanceOf(reportEvent->env, className, static_cast(reportEvent->keyOptionsObj)) == 0) { - MMI_HILOGE("%{public}s: keyOptionsObj is not instance Of KeyOptions class", __func__); - return; - } - - if (ANI_OK != reportEvent->env->FunctionalObject_Call(fnObj, 1, args.data(), &result)) { - MMI_HILOGE("%{public}s: FunctionalObject_Call failed", __func__); - return; - } - MMI_HILOGD("%{public}s: FunctionalObject_Call success", __func__); - }; - if (!SendEventToMainThread(task)) { - MMI_HILOGE("%{public}s: failed to send event", __func__); - } -} - -static void SubKeyEventCallback(std::shared_ptr keyEvent) -{ - CALL_DEBUG_ENTER; - CHKPV(keyEvent); - std::lock_guard guard(sCallBacksMutex); - auto iter = callbacks.begin(); - while (iter != callbacks.end()) { - auto &list = iter->second; - ++iter; - MMI_HILOGD("list size:%{public}zu", list.size()); - auto infoIter = list.begin(); - while (infoIter != list.end()) { - auto monitorInfo = *infoIter; - if (MatchCombinationKey(*(monitorInfo->keyOption), *keyEvent)) { - MMI_HILOGD("MatchCombinationKey success"); - EmitAsyncCallbackWork(monitorInfo); - } - ++infoIter; - } - } -} - -static int32_t GetPreSubscribeId(const std::shared_ptr &event) -{ - CHKPR(event, ERROR_NULL_POINTER); - std::lock_guard guard(sCallBacksMutex); - auto it = callbacks.find(event->eventType); - if (it == callbacks.end() || it->second.empty()) { - MMI_HILOGE("The callbacks is empty"); - return JS_CALLBACK_EVENT_FAILED; - } - CHKPR(it->second.front(), ERROR_NULL_POINTER); - return it->second.front()->subscribeId; -} - -static bool CheckCallbackEqual(ani_env *env, ani_ref fnRef, ani_env *iterEnv, ani_ref iterFn) -{ - if (env != iterEnv) { - MMI_HILOGD("%{public}s: not the same env", __func__); - return false; - } - ani_boolean isEquals = false; - if (ANI_OK != env->Reference_StrictEquals(fnRef, iterFn, &isEquals)) { - MMI_HILOGD("%{public}s: check observer equal failed!", __func__); - return false; - } - return isEquals; -} - -static int32_t AddEventCallback(std::shared_ptr event) -{ - CALL_DEBUG_ENTER; - std::lock_guard guard(sCallBacksMutex); - CHKPR(event, ERROR_NULL_POINTER); - if (callbacks.find(event->eventType) == callbacks.end()) { - MMI_HILOGD("No callback in %{public}s", event->eventType.c_str()); - callbacks[event->eventType] = {}; - } - - auto it = callbacks.find(event->eventType); - for (const auto &iter: it->second) { - if (CheckCallbackEqual(event->env, event->callback, iter->env, iter->callback)) { - MMI_HILOGE("Callback already exist"); - return JS_CALLBACK_EVENT_FAILED; - } - } - it->second.push_back(event); - return JS_CALLBACK_EVENT_SUCCESS; -} - -static int32_t SubscribeKey(ani_env *env, std::shared_ptr &event) -{ - CALL_DEBUG_ENTER; - std::string subKeyNames = ""; - auto keyOptionsPtr = ParseKeyOptions(env, static_cast(event->keyOptionsObj)); - if (keyOptionsPtr == nullptr) { - MMI_HILOGE("keyOptionsPtr is nullptr"); - return ERROR_CODE; - } - event->keyOption = keyOptionsPtr; - event->eventType = GenerateEventType(keyOptionsPtr); - - int32_t preSubscribeId = GetPreSubscribeId(event); - if (preSubscribeId >= 0) { - event->subscribeId = preSubscribeId; - return AddEventCallback(event); - } - - MMI_HILOGD("EventType:%{private}s, eventName:%{public}s", event->eventType.c_str(), event->name.c_str()); - int32_t subscribeId = -1; - subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(event->keyOption, SubKeyEventCallback); - if (subscribeId < 0) { - MMI_HILOGE("SubscribeId invalid:%{public}d", subscribeId); - return subscribeId; - } - MMI_HILOGD("SubscribeId:%{public}d", subscribeId); - event->subscribeId = subscribeId; - return AddEventCallback(event); -} - -static void On([[maybe_unused]] ani_env *env, ani_string strObj, ani_object keyOptionsObj, ani_object callback) -{ - CALL_DEBUG_ENTER; - std::shared_ptr event = std::make_shared(); - event->env = env; - if (ANI_OK != env->GlobalReference_Create(callback, &event->callback)) { - MMI_HILOGE("Create global reference 'callback' failed"); - return; - } - if (ANI_OK != env->GlobalReference_Create(keyOptionsObj, &event->keyOptionsObj)) { - MMI_HILOGE("Create global reference 'keyOptionsObj' failed"); - return; - } - - std::string keyType = AniStringToString(env, strObj); - event->name = keyType; - - if (keyType == HOTKEY_SUBSCRIBE_TYPE) { - MMI_HILOGD("%{public}s: Enter Hotkey.", __func__); - } else if (keyType == SUBSCRIBE_TYPE) { - int32_t ret = SubscribeKey(env, event); - MMI_HILOGD("%{public}s: Call SubscribeKey end ret = %{public}d", __func__, ret); - } else { - MMI_HILOGE("Type is not key or hotkey"); - ani_error error = CreateAniError(env, "Type must be key or hotkeyChange"); - env->ThrowError(error); - } -} - -static int32_t DelEventCallbackRef(ani_env *env, std::list> &info, - ani_ref handler, int32_t &subscribeId) -{ - CALL_DEBUG_ENTER; - for (auto iter = info.begin(); iter != info.end();) { - if (*iter == nullptr) { - info.erase(iter++); - continue; - } - if (handler != nullptr) { - if (!CheckCallbackEqual(env, handler, (*iter)->env, (*iter)->callback)) { - ++iter; - continue; - } - std::shared_ptr monitorInfo = *iter; - info.erase(iter++); - if (info.empty()) { - subscribeId = monitorInfo->subscribeId; - } - MMI_HILOGD("Callback has deleted, size:%{public}zu", info.size()); - return JS_CALLBACK_EVENT_SUCCESS; - } - std::shared_ptr monitorInfo = *iter; - info.erase(iter++); - if (info.empty()) { - subscribeId = monitorInfo->subscribeId; - } - MMI_HILOGD("Callback has deleted, size:%{public}zu", info.size()); - } - MMI_HILOGD("Callback size:%{public}zu", info.size()); - return JS_CALLBACK_EVENT_SUCCESS; -} - -static int32_t DelEventCallback(std::shared_ptr &event, int32_t &subscribeId) -{ - CALL_DEBUG_ENTER; - std::lock_guard guard(sCallBacksMutex); - CHKPR(event, ERROR_NULL_POINTER); - if (callbacks.count(event->eventType) <= 0) { - MMI_HILOGE("Callback doesn't exists, eventType:%{private}s", event->eventType.c_str()); - return JS_CALLBACK_EVENT_FAILED; - } - auto &info = callbacks[event->eventType]; - MMI_HILOGD("EventType:%{public}s, keyEventMonitorInfos:%{public}zu", event->eventType.c_str(), info.size()); - - return DelEventCallbackRef(event->env, info, event->callback, subscribeId); -} - -static void Off([[maybe_unused]] ani_env *env, ani_string strObj, ani_object keyOptionsObj, ani_object callback) -{ - CALL_DEBUG_ENTER; - std::shared_ptr event = std::make_shared(); - event->env = env; - if (ANI_OK != env->GlobalReference_Create(keyOptionsObj, &event->keyOptionsObj)) { - MMI_HILOGE("Call GlobalReference_Create failed"); - return; - } - - ani_boolean isUndefined; - if (ANI_OK != env->Reference_IsUndefined(callback, &isUndefined)) { - MMI_HILOGE("Call Reference_IsUndefined failed"); - return; - } - if (isUndefined) { - MMI_HILOGD("%{public}s: callback is undefined", __func__); - event->callback = nullptr; - } else { - if (ANI_OK != env->GlobalReference_Create(callback, &event->callback)) { - MMI_HILOGE("%{public}s: Create global reference 'callback' failed", __func__); - return; - } - } - - std::string keyType = AniStringToString(env, strObj); - event->name = keyType; - int32_t subscribeId = -1; - if (keyType == HOTKEY_SUBSCRIBE_TYPE) { - MMI_HILOGD("%{public}s: Enter Hotkey.", __func__); - } else if (keyType == SUBSCRIBE_TYPE) { - std::string subKeyNames = ""; - auto keyOptionsPtr = ParseKeyOptions(env, static_cast(event->keyOptionsObj)); - if (keyOptionsPtr == nullptr) { - MMI_HILOGE("%{public}s: ParseKeyOptions failed", __func__); - return; - } - event->keyOption = keyOptionsPtr; - event->eventType = GenerateEventType(keyOptionsPtr); - if (DelEventCallback(event, subscribeId) < 0) { - MMI_HILOGE("DelEventCallback failed"); - return; - } - MMI_HILOGI("Unsubscribe key event(%{public}d)", subscribeId); - InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId); - } else { - MMI_HILOGE("Type is not key or hotkey"); - ani_error error = CreateAniError(env, "Type must be key or hotkeyChange"); - env->ThrowError(error); - } -} - -ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) -{ - ani_env *env; - if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) { - MMI_HILOGE("%{public}s: Unsupported ANI_VERSION_1", __func__); - return ANI_ERROR; - } - - static const char *name = "L@ohos/multimodalInput/inputConsumer/inputConsumer;"; - ani_namespace ns; - if (ANI_OK != env->FindNamespace(name, &ns)) { - MMI_HILOGE("%{public}s: Not found %{public}s", __func__, name); - return ANI_NOT_FOUND; - } - - std::array methods = { - ani_native_function {"on", nullptr, reinterpret_cast(On)}, - ani_native_function {"off", nullptr, reinterpret_cast(Off)}, - }; - - if (ANI_OK != env->Namespace_BindNativeFunctions(ns, methods.data(), methods.size())) { - MMI_HILOGE("%{public}s:Cannot bind native methods to '%{public}s'", __func__, name); - return ANI_ERROR; - }; - - *result = ANI_VERSION_1; - return ANI_OK; -} \ No newline at end of file diff --git a/frameworks/ani/pointer/ets/@ohos.multimodalInput.pointer.ets b/frameworks/ani/pointer/ets/@ohos.multimodalInput.pointer.ets deleted file mode 100644 index 7e20f0bfea..0000000000 --- a/frameworks/ani/pointer/ets/@ohos.multimodalInput.pointer.ets +++ /dev/null @@ -1,399 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog' -import { AsyncCallback } from "@ohos.base" -import { BusinessError } from "@ohos.base" - -export namespace pointer { - loadLibrary("ani_pointer"); - - export native function setPointerStyleInner(windowId: number, pointerStyle: PointerStyle): int; - - export enum PointerStyle { - DEFAULT, - EAST, - WEST, - SOUTH, - NORTH, - - /** - * East-west arrow - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @since 9 - */ - WEST_EAST, - - /** - * North-south arrow - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @since 9 - */ - NORTH_SOUTH, - - /** - * North-east arrow - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @since 9 - */ - NORTH_EAST, - - /** - * North-west arrow - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @since 9 - */ - NORTH_WEST, - - /** - * South-east arrow - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @since 9 - */ - SOUTH_EAST, - - /** - * South-west arrow - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @since 9 - */ - SOUTH_WEST, - - /** - * Northeast and southwest adjustment - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @since 9 - */ - NORTH_EAST_SOUTH_WEST, - - /** - * Northwest and southeast adjustment - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @since 9 - */ - NORTH_WEST_SOUTH_EAST, - - /** - * Cross (accurate selection) - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @since 9 - */ - CROSS, - - /** - * Copy - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @since 9 - */ - CURSOR_COPY, - - /** - * Forbid - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @since 9 - */ - CURSOR_FORBID, - - /** - * Sucker - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @since 9 - */ - COLOR_SUCKER, - - /** - * Grabbing hand - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @since 9 - */ - HAND_GRABBING, - - /** - * Opening hand - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @since 9 - */ - HAND_OPEN, - - /** - * Hand-shaped pointer - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @since 9 - */ - HAND_POINTING, - - /** - * Help - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @since 9 - */ - HELP, - - /** - * Move - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @since 9 - */ - MOVE, - - /** - * Left and right resizing - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @since 9 - */ - RESIZE_LEFT_RIGHT, - - /** - * Up and down resizing - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @since 9 - */ - RESIZE_UP_DOWN, - - /** - * Screenshot crosshair - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @since 9 - */ - SCREENSHOT_CHOOSE, - - /** - * Screenshot - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @since 9 - */ - SCREENSHOT_CURSOR, - - /** - * Text selection - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @since 9 - */ - TEXT_CURSOR, - - /** - * Zoom in - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @since 9 - */ - ZOOM_IN, - - /** - * Zoom out - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @since 9 - */ - ZOOM_OUT, - - /** - * Scrolling east - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @since 9 - */ - MIDDLE_BTN_EAST, - - /** - * Scrolling west - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @since 9 - */ - MIDDLE_BTN_WEST, - - /** - * Scrolling south - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @since 9 - */ - MIDDLE_BTN_SOUTH, - - /** - * Scrolling north - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @since 9 - */ - MIDDLE_BTN_NORTH, - - /** - * Scrolling north and south - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @since 9 - */ - MIDDLE_BTN_NORTH_SOUTH, - - /** - * Scrolling northeast - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @since 9 - */ - MIDDLE_BTN_NORTH_EAST, - - /** - * Scrolling northwest - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @since 9 - */ - MIDDLE_BTN_NORTH_WEST, - - /** - * Scrolling southeast - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @since 9 - */ - MIDDLE_BTN_SOUTH_EAST, - - /** - * Scrolling southwest - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @since 9 - */ - MIDDLE_BTN_SOUTH_WEST, - - /** - * Moving as a cone in four directions - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @since 9 - */ - MIDDLE_BTN_NORTH_SOUTH_WEST_EAST, - - /** - * Horizontal text selection - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @since 10 - */ - HORIZONTAL_TEXT_CURSOR, - - /** - * Precise selection - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @since 10 - */ - CURSOR_CROSS, - - /** - * Cursor with circle style - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @since 10 - */ - CURSOR_CIRCLE, - - /** - * Loading state with dynamic cursor - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @since 10 - */ - /** - * Loading state with dynamic cursor - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @atomicservice - * @since 12 - */ - LOADING, - - /** - * Running state with dynamic cursor - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @since 10 - */ - /** - * Running state with dynamic cursor - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @atomicservice - * @since 12 - */ - RUNNING, - - /** - * Scrolling east and west - * - * @syscap SystemCapability.MultimodalInput.Input.Pointer - * @since 16 - */ - MIDDLE_BTN_EAST_WEST - } - - export function setPointerStyle(windowId: number, pointerStyle: PointerStyle, callback: AsyncCallback): void { - let p1 = taskpool.execute(setPointerStyleInner, windowId, pointerStyle); - p1.then((data: NullishType) => { - let ret = data as int; - hilog.info(0x0000, 'pointer', "setPointerStyleInner callback then. ret is " + ret); - let err : BusinessError - callback(err, undefined); - }).catch((error: NullishType) => { - let err = error as BusinessError; - hilog.info(0x0000, 'pointer', "setPointerStyleInner err is " + err); - callback(err, undefined); - }); - } - - export function setPointerStyle(windowId: number, pointerStyle: PointerStyle): Promise { - let p = new Promise((resolve: (v: undefined) => void, - reject: (error: Object) => void) : void => { - let p1 = taskpool.execute(setPointerStyleInner, windowId, pointerStyle); - p1.then((e :NullishType) : void=>{ - let r = e as int; - hilog.info(0x0000, 'pointer', "setPointerStyleInner Promise, ret is: " + r); - resolve(undefined); - }).catch((err: Error) : void => { - reject(err); - }); - }); - return p; - } - - export function setPointerStyleSync(windowId: number, pointerStyle: PointerStyle): void { - setPointerStyleInner(windowId, pointerStyle); - } -} \ No newline at end of file diff --git a/frameworks/ani/pointer/include/ani_utils.h b/frameworks/ani/pointer/include/ani_utils.h deleted file mode 100644 index 790c86f936..0000000000 --- a/frameworks/ani/pointer/include/ani_utils.h +++ /dev/null @@ -1,497 +0,0 @@ -/* -* Copyright (c) 2025 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -#ifndef ANI_UTILS_H -#define ANI_UTILS_H - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -class AniObjectUtils { -public: - // 创建一个ani_object对象,使用命名空间和类名 - static ani_object Create(ani_env *env, const char* nsName, const char* clsName, ...) - { - // 创建一个空的对象 - ani_object nullobj{}; - - // 查找命名空间 - ani_namespace ns; - if (ANI_OK != env->FindNamespace(nsName, &ns)) { - return nullobj; - } - - // 查找类 - ani_class cls; - if (ANI_OK != env->Namespace_FindClass(ns, clsName, &cls)) { - return nullobj; - } - - ani_method ctor; - if (ANI_OK != env->Class_FindMethod(cls, "", nullptr, &ctor)) { - return nullobj; - } - - ani_object obj; - va_list args; - va_start(args, clsName); - ani_status status = env->Object_New_V(cls, ctor, &obj, args); - va_end(args); - if (ANI_OK != status) { - return nullobj; - } - return obj; - } - - static ani_object Create(ani_env *env, const char* clsName, ...) - { - ani_object nullobj{}; - // 查找类 - ani_class cls; - if (ANI_OK != env->FindClass(clsName, &cls)) { - return nullobj; - } - ani_method ctor; - if (ANI_OK != env->Class_FindMethod(cls, "", nullptr, &ctor)) { - return nullobj; - } - - ani_object obj; - va_list args; - va_start(args, clsName); - ani_status status = env->Object_New_V(cls, ctor, &obj, args); - va_end(args); - if (ANI_OK != status) { - return nullobj; - } - return obj; - } - - static ani_object Create(ani_env *env, ani_class cls, ...) - { - ani_object nullobj{}; - - ani_method ctor; - if (ANI_OK != env->Class_FindMethod(cls, "", nullptr, &ctor)) { - return nullobj; - } - - ani_object obj; - va_list args; - va_start(args, cls); - ani_status status = env->Object_New_V(cls, ctor, &obj, args); - va_end(args); - if (ANI_OK != status) { - return nullobj; - } - return obj; - } - - static ani_object From(ani_env *env, bool value) - { - return Create(env, "Lstd/core/Boolean;", static_cast(value)); - } - - template - static ani_status Wrap(ani_env *env, ani_object object, T* nativePtr, const char* propName = "nativePtr") - { - return env->Object_SetFieldByName_Long(object, propName, reinterpret_cast(nativePtr)); - } - - template - static T* Unwrap(ani_env *env, ani_object object, const char* propName = "nativePtr") - { - ani_long nativePtr; - if (ANI_OK != env->Object_GetFieldByName_Long(object, propName, &nativePtr)) { - return nullptr; - } - if (nativePtr == 0) { - return nullptr; - } - return reinterpret_cast(nativePtr); - } -}; - -class AniStringUtils { -public: - static std::string ToStd(ani_env *env, ani_string ani_str) - { - ani_size strSize; - env->String_GetUTF8Size(ani_str, &strSize); - - std::vector buffer(strSize + 1); // +1 for null terminator - char* utf8_buffer = buffer.data(); - - ani_size bytes_written = 0; - env->String_GetUTF8(ani_str, utf8_buffer, strSize + 1, &bytes_written); - - utf8_buffer[bytes_written] = '\0'; - std::string content = std::string(utf8_buffer); - return content; - } - - static ani_string ToAni(ani_env* env, const std::string& str) - { - ani_string aniStr = nullptr; - if (ANI_OK != env->String_NewUTF8(str.data(), str.size(), &aniStr)) { - return nullptr; - } - return aniStr; - } -}; - -class UnionAccessor { -public: - UnionAccessor(ani_env *env, ani_object &obj) : env_(env), obj_(obj) - { - } - - bool IsInstanceOf(const std::string& cls_name) - { - ani_class cls; - env_->FindClass(cls_name.c_str(), &cls); - - ani_boolean ret; - env_->Object_InstanceOf(obj_, cls, &ret); - return ret; - } - - template - bool IsInstanceOfType(); - - template - bool TryConvert(T &value); - - template - bool TryConvertArray(std::vector &value); - -private: - ani_env *env_; - ani_object obj_; -}; - -template<> -bool UnionAccessor::IsInstanceOfType() -{ - return IsInstanceOf("Lstd/core/Boolean;"); -} - -template<> -bool UnionAccessor::IsInstanceOfType() -{ - return IsInstanceOf("Lstd/core/Int;"); -} - -template<> -bool UnionAccessor::IsInstanceOfType() -{ - return IsInstanceOf("Lstd/core/Double;"); -} - -template<> -bool UnionAccessor::IsInstanceOfType() -{ - return IsInstanceOf("Lstd/core/String;"); -} - -template<> -bool UnionAccessor::TryConvert(bool &value) -{ - if (!IsInstanceOfType()) { - return false; - } - - ani_boolean aniValue; - auto ret = env_->Object_CallMethodByName_Boolean(obj_, "unboxed", nullptr, &aniValue); - if (ret != ANI_OK) { - return false; - } - value = static_cast(aniValue); - return true; -} - -template<> -bool UnionAccessor::TryConvert(int &value) -{ - if (!IsInstanceOfType()) { - return false; - } - - ani_int aniValue; - auto ret = env_->Object_CallMethodByName_Int(obj_, "unboxed", nullptr, &aniValue); - if (ret != ANI_OK) { - return false; - } - value = static_cast(aniValue); - return true; -} - -template<> -bool UnionAccessor::TryConvert(double &value) -{ - if (!IsInstanceOfType()) { - return false; - } - - ani_double aniValue; - auto ret = env_->Object_CallMethodByName_Double(obj_, "unboxed", nullptr, &aniValue); - if (ret != ANI_OK) { - return false; - } - value = static_cast(aniValue); - return true; -} - -template<> -bool UnionAccessor::TryConvert(std::string &value) -{ - if (!IsInstanceOfType()) { - return false; - } - - value = AniStringUtils::ToStd(env_, static_cast(obj_)); - return true; -} - -template<> -bool UnionAccessor::TryConvertArray(std::vector &value) -{ - ani_double length; - if (ANI_OK != env_->Object_GetPropertyByName_Double(obj_, "length", &length)) { - return false; - } - for (int i = 0; i < int(length); i++) { - ani_ref ref; - if (ANI_OK != env_->Object_CallMethodByName_Ref(obj_, "$_get", "I:Lstd/core/Object;", &ref, (ani_int)i)) { - return false; - } - ani_boolean val; - if (ANI_OK != env_->Object_CallMethodByName_Boolean(static_cast(ref), "unboxed", nullptr, &val)) { - return false; - } - value.push_back(static_cast(val)); - } - return true; -} - -template<> -bool UnionAccessor::TryConvertArray(std::vector &value) -{ - ani_double length; - if (ANI_OK != env_->Object_GetPropertyByName_Double(obj_, "length", &length)) { - return false; - } - for (int i = 0; i < int(length); i++) { - ani_ref ref; - if (ANI_OK != env_->Object_CallMethodByName_Ref(obj_, "$_get", "I:Lstd/core/Object;", &ref, (ani_int)i)) { - return false; - } - ani_int intValue; - if (ANI_OK != env_->Object_CallMethodByName_Int(static_cast(ref), "unboxed", nullptr, &intValue)) { - return false; - } - value.push_back(static_cast(intValue)); - } - return true; -} - -template<> -bool UnionAccessor::TryConvertArray(std::vector &value) -{ - ani_double length; - if (ANI_OK != env_->Object_GetPropertyByName_Double(obj_, "length", &length)) { - return false; - } - for (int i = 0; i < int(length); i++) { - ani_ref ref; - if (ANI_OK != env_->Object_CallMethodByName_Ref(obj_, "$_get", "I:Lstd/core/Object;", &ref, (ani_int)i)) { - return false; - } - ani_double val; - if (ANI_OK != env_->Object_CallMethodByName_Double(static_cast(ref), "unboxed", nullptr, &val)) { - return false; - } - value.push_back(static_cast(val)); - } - return true; -} - -template<> -bool UnionAccessor::TryConvertArray(std::vector &value) -{ - ani_ref buffer; - if (ANI_OK != env_->Object_GetFieldByName_Ref(obj_, "buffer", &buffer)) { - return false; - } - void* data; - size_t length; - if (ANI_OK != env_->ArrayBuffer_GetInfo(static_cast(buffer), &data, &length)) { - return false; - } - - for (size_t i = 0; i < length; i++) { - value.push_back(static_cast(data)[i]); - } - return true; -} - -template<> -bool UnionAccessor::TryConvertArray(std::vector &value) -{ - ani_double length; - if (ANI_OK != env_->Object_GetPropertyByName_Double(obj_, "length", &length)) { - return false; - } - - for (int i = 0; i < int(length); i++) { - ani_ref ref; - if (ANI_OK != env_->Object_CallMethodByName_Ref(obj_, "$_get", "I:Lstd/core/Object;", &ref, (ani_int)i)) { - return false; - } - value.push_back(AniStringUtils::ToStd(env_, static_cast(ref))); - } - return true; -} - -class OptionalAccessor { -public: - OptionalAccessor(ani_env *env, ani_object &obj) : env_(env), obj_(obj) - { - } - - bool IsUndefined() - { - ani_boolean isUndefined; - env_->Reference_IsUndefined(obj_, &isUndefined); - return isUndefined; - } - - template - std::optional Convert(); - -private: - ani_env *env_; - ani_object obj_; -}; - -template<> -std::optional OptionalAccessor::Convert() -{ - if (IsUndefined()) { - return std::nullopt; - } - - ani_double aniValue; - auto ret = env_->Object_CallMethodByName_Double(obj_, "doubleValue", nullptr, &aniValue); - if (ret != ANI_OK) { - return std::nullopt; - } - auto value = static_cast(aniValue); - return value; -} - -template<> -std::optional OptionalAccessor::Convert() -{ - if (IsUndefined()) { - return std::nullopt; - } - - ani_size strSize; - env_->String_GetUTF8Size(static_cast(obj_), &strSize); - - std::vector buffer(strSize + 1); - char* utf8_buffer = buffer.data(); - - ani_size bytes_written = 0; - env_->String_GetUTF8(static_cast(obj_), utf8_buffer, strSize + 1, &bytes_written); - - utf8_buffer[bytes_written] = '\0'; - std::string content = std::string(utf8_buffer); - return content; -} - - -class EnumAccessor { -public: - EnumAccessor(ani_env *env, const char* className, ani_int index) : env_(env), className_(className), index_(index) - { - } - - ani_status ToInt(int32_t &value) - { - ani_status status = ANI_ERROR; - ani_enum_item item; - status = GetItem(item); - if (ANI_OK != status) { - return status; - } - - status = env_->EnumItem_GetValue_Int(item, &value); - if (ANI_OK != status) { - return status; - } - return ANI_OK; - } - - ani_status ToString(std::string &value) - { - ani_status status = ANI_ERROR; - ani_enum_item item; - status = GetItem(item); - if (ANI_OK != status) { - return status; - } - - ani_string strValue; - status = env_->EnumItem_GetValue_String(item, &strValue); - if (ANI_OK != status) { - return status; - } - value = AniStringUtils::ToStd(env_, strValue); - - return ANI_OK; - } - -private: - ani_status GetItem(ani_enum_item &item) - { - ani_status status = ANI_ERROR; - ani_enum enumType; - status = env_->FindEnum(className_.c_str(), &enumType); - if (ANI_OK != status) { - return status; - } - - status = env_->Enum_GetEnumItemByIndex(enumType, index_, &item); - if (ANI_OK != status) { - return status; - } - return ANI_OK; - } - -private: - ani_env *env_; - std::string className_; - ani_int index_; -}; -#endif diff --git a/frameworks/ani/pointer/src/pointer.cpp b/frameworks/ani/pointer/src/pointer.cpp deleted file mode 100644 index 6f538a5519..0000000000 --- a/frameworks/ani/pointer/src/pointer.cpp +++ /dev/null @@ -1,164 +0,0 @@ - /* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "pointer.h" -#include - -#include "define_multimodal.h" -#include "input_manager.h" -#include "mmi_log.h" - -#include -#include -#include - -#undef MMI_LOG_TAG -#define MMI_LOG_TAG "AniPointer" - -using namespace OHOS::MMI; - -namespace { -constexpr int32_t ANI_SCOPE_SIZE = 16; -constexpr int32_t MILLISECOND_FACTOR = 1000; -constexpr size_t EVENT_NAME_LEN { 64 }; -constexpr size_t PRE_KEYS_SIZE { 4 }; -constexpr size_t INPUT_PARAMETER_MIDDLE { 2 }; -constexpr size_t INPUT_PARAMETER_MAX { 3 }; -constexpr int32_t OCCUPIED_BY_SYSTEM = -3; -constexpr int32_t OCCUPIED_BY_OTHER = -4; -const double INT32_MAX_D = static_cast(std::numeric_limits::max()); -} // namespace - -enum AniErrorCode : int32_t { - COMMON_PARAMETER_ERROR = 401, - COMMON_USE_SYSAPI_ERROR = 202, -}; - -static void ThrowBusinessError(ani_env *env, int errCode, std::string&& errMsg) -{ - MMI_HILOGD("Begin ThrowBusinessError."); - static const char *errorClsName = "L@ohos/base/BusinessError;"; - ani_class cls {}; - if (ANI_OK != env->FindClass(errorClsName, &cls)) { - MMI_HILOGE("find class BusinessError %{public}s failed", errorClsName); - return; - } - ani_method ctor; - if (ANI_OK != env->Class_FindMethod(cls, "", ":V", &ctor)) { - MMI_HILOGE("find method BusinessError.constructor failed"); - return; - } - ani_object errorObject; - if (ANI_OK != env->Object_New(cls, ctor, &errorObject)) { - MMI_HILOGE("create BusinessError object failed"); - return; - } - ani_double aniErrCode = static_cast(errCode); - ani_string errMsgStr; - if (ANI_OK != env->String_NewUTF8(errMsg.c_str(), errMsg.size(), &errMsgStr)) { - MMI_HILOGE("convert errMsg to ani_string failed"); - return; - } - if (ANI_OK != env->Object_SetFieldByName_Double(errorObject, "code", aniErrCode)) { - MMI_HILOGE("set error code failed"); - return; - } - if (ANI_OK != env->Object_SetPropertyByName_Ref(errorObject, "message", errMsgStr)) { - MMI_HILOGE("set error message failed"); - return; - } - env->ThrowError(static_cast(errorObject)); - return; -} - -static int32_t ToInt32ECMAScript(double value) -{ - if (std::isnan(value) || std::isinf(value)) { - return 0; - } - - double truncated = std::trunc(value); - double modValue = std::fmod(truncated, 4294967296.0); - uint32_t uint32Val = static_cast(modValue); - return static_cast(uint32Val); -} - -static ani_int ParseEnumToInt(ani_env *env, ani_enum_item enumItem) -{ - ani_int intValue = -1; - if (ANI_OK != env->EnumItem_GetValue_Int(enumItem, &intValue)) { - MMI_HILOGE("%{public}s: EnumItem_GetValue_Int FAILD.", __func__); - return -1; - } - MMI_HILOGD("%{public}s: Enum Value: %{public}d.", __func__, intValue); - return intValue; -} - -static int SetPointerStyleInner(ani_env *env, ani_double windowid, ani_enum_item pointerStyle) -{ - int32_t windowID = ToInt32ECMAScript(static_cast(windowid)); - if (windowID < 0 && windowID != GLOBAL_WINDOW_ID) { - MMI_HILOGE("Invalid windowid"); - ThrowBusinessError(env, COMMON_PARAMETER_ERROR, "Windowid is invalid"); - return 0; - } - - int32_t pointerStyleID = ParseEnumToInt(env, pointerStyle); - if ((pointerStyleID < DEFAULT && pointerStyleID != DEVELOPER_DEFINED_ICON) || pointerStyleID > RUNNING) { - MMI_HILOGE("Undefined pointer style"); - ThrowBusinessError(env, COMMON_PARAMETER_ERROR, "Pointer style does not exist"); - return 0; - } - - PointerStyle style; - style.id = pointerStyleID; - int32_t errorCode = InputManager::GetInstance()->SetPointerStyle(windowid, style); - if (errorCode == COMMON_USE_SYSAPI_ERROR) { - MMI_HILOGE("The windowId is negative number and no system applications use system API"); - ThrowBusinessError(env, COMMON_USE_SYSAPI_ERROR, - "windowId is negative number and no system applications use system API"); - return 0; - } - MMI_HILOGD(" SetPointerStyleInner end."); - return 0; -} - -ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) -{ - ani_env *env; - if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) { - MMI_HILOGE("%{public}s: Unsupported ANI_VERSION_1", __func__); - return ANI_ERROR; - } - - static const char *name = "L@ohos/multimodalInput/pointer/pointer;"; - ani_namespace ns; - if (ANI_OK != env->FindNamespace(name, &ns)) { - MMI_HILOGE("%{public}s: Not found %{public}s", __func__, name); - return ANI_NOT_FOUND; - } - - std::array methods = { - ani_native_function {"setPointerStyleInner", nullptr, reinterpret_cast(SetPointerStyleInner)}, - }; - - if (ANI_OK != env->Namespace_BindNativeFunctions(ns, methods.data(), methods.size())) { - MMI_HILOGE("%{public}s:Cannot bind native methods to '%{public}s'", __func__, name); - return ANI_ERROR; - }; - - *result = ANI_VERSION_1; - return ANI_OK; -} \ No newline at end of file diff --git a/frameworks/ets/gesture_event/BUILD.gn b/frameworks/ets/gesture_event/BUILD.gn new file mode 100644 index 0000000000..0fc0bc98f6 --- /dev/null +++ b/frameworks/ets/gesture_event/BUILD.gn @@ -0,0 +1,90 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/components/ets_frontend/ets2abc_config.gni") +import("//build/ohos.gni") +import("//build/ohos/taihe_idl/taihe.gni") +import("//foundation/multimodalinput/input/multimodalinput_mini.gni") +copy_taihe_idl("gesture_event_taihe") { + sources = [ "idl/ohos.multimodalInput.gestureEvent.taihe" ] + deps = [ "${mmi_path}/frameworks/ets/touch_event:touch_event_taihe" ] +} +config("gestureEvent_config") { + visibility = [ ":*" ] + + include_dirs = [ + "${mmi_path}/util/common/include", + "${mmi_path}/util/network/include", + ] +} +subsystem_name = "multimodalinput" +part_name = "input" +taihe_generated_file_path_gestureEvent = "$taihe_file_path/out/$subsystem_name/$part_name/gestureEvent" +ohos_taihe("run_taihe") { + taihe_generated_file_path = "${taihe_generated_file_path_gestureEvent}" + deps = [ ":gesture_event_taihe" ] + outputs = [ + "$taihe_generated_file_path/src/ohos.multimodalInput.gestureEvent.ani.cpp", + "$taihe_generated_file_path/src/ohos.multimodalInput.gestureEvent.abi.c", + ] +} +taihe_shared_library("GestureEvent") { + taihe_generated_file_path = "${taihe_generated_file_path_gestureEvent}" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + sources = get_target_outputs(":run_taihe") + configs = [ + "${mmi_path}:coverage_flags", + ":gestureEvent_config", + ] + sources += [ + "src/ani_constructor.cpp", + "src/ohos.multimodalInput.gestureEvent.impl.cpp", + ] + deps = [ + ":run_taihe", + "${mmi_path}/frameworks/proxy:libmmi-client", + "${mmi_path}/util:libmmi-util", + ] + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + ] + branch_protector_ret = "pac_ret" + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } +} +generate_static_abc("gesture_event") { + base_url = "${taihe_generated_file_path_gestureEvent}" + files = [ "${taihe_generated_file_path_gestureEvent}/@ohos.multimodalInput.gestureEvent.ets" ] + is_boot_abc = "True" + device_dst_file = "/system/framework/gesture_event.abc" + dependencies = [ ":run_taihe" ] +} +ohos_prebuilt_etc("gesture_event_etc") { + source = "$target_out_dir/gesture_event.abc" + module_install_dir = "framework" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + deps = [ ":gesture_event" ] +} +group("ets_gestureEvent_package") { + deps = [ + ":gesture_event_etc", + ":GestureEvent", + ] +} \ No newline at end of file diff --git a/frameworks/ets/gesture_event/idl/ohos.multimodalInput.gestureEvent.taihe b/frameworks/ets/gesture_event/idl/ohos.multimodalInput.gestureEvent.taihe new file mode 100644 index 0000000000..d18dcf0806 --- /dev/null +++ b/frameworks/ets/gesture_event/idl/ohos.multimodalInput.gestureEvent.taihe @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@!namespace("@ohos.multimodalInput.gestureEvent") +from ohos.multimodalInput.touchEvent use Touch; +@!sts_inject(""" + loadLibrary("GestureEvent.z") +""") + +struct Pinch { + type: ActionType; + scale: f64; +} + +struct Rotate { + type: ActionType; + angle: f64; +} + +struct ThreeFingersSwipe { + type: ActionType; + x: i32; + y: i32; +} + +struct FourFingersSwipe { + type: ActionType; + x: i32; + y: i32; +} + +struct SwipeInward { + type: ActionType; + x: i32; + y: i32; +} + +struct ThreeFingersTap { + type: ActionType; +} + +struct TouchGestureEvent { + action: TouchGestureAction; + touches: Array; +} + +enum TouchGestureAction : i32 { + SWIPE_DOWN = 0, + SWIPE_UP, + SWIPE_LEFT, + SWIPE_RIGHT, + PINCH_CLOSED, + PINCH_OPENED, + GESTURE_END +} + +enum ActionType : i32 { + CANCEL = 0, + BEGIN = 1, + UPDATE = 2, + END = 3 +} \ No newline at end of file diff --git a/frameworks/ani/input_consumer/ets/@ohos.multimodalInput.inputConsumer.ets b/frameworks/ets/gesture_event/src/ani_constructor.cpp similarity index 50% rename from frameworks/ani/input_consumer/ets/@ohos.multimodalInput.inputConsumer.ets rename to frameworks/ets/gesture_event/src/ani_constructor.cpp index 6a179a1455..f8f030c08a 100644 --- a/frameworks/ani/input_consumer/ets/@ohos.multimodalInput.inputConsumer.ets +++ b/frameworks/ets/gesture_event/src/ani_constructor.cpp @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,19 +13,18 @@ * limitations under the License. */ -import { Callback } from '@ohos.base'; +#include "ohos.multimodalInput.gestureEvent.ani.hpp" -export namespace inputConsumer { - loadLibrary("input_consumer") - - export interface KeyOptions { - finalKey: number; - finalKeyDownDuration: number; - isFinalKeyDown: boolean; - preKeys: Array; - isRepeat?: boolean; +ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) +{ + ani_env *env; + if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) { + return ANI_ERROR; } - - export native function on(type: 'key', keyOptions: KeyOptions, callback: Callback): void; - export native function off(type: 'key', keyOptions: KeyOptions, callback?: Callback): void; -} + if (ANI_OK != ohos::multimodalInput::gestureEvent::ANIRegister(env)) { + std::cerr << "Error from ohos::multimodalInput::gestureEvent::ANIRegister" << std::endl; + return ANI_ERROR; + } + *result = ANI_VERSION_1; + return ANI_OK; +} \ No newline at end of file diff --git a/frameworks/ets/gesture_event/src/ohos.multimodalInput.gestureEvent.impl.cpp b/frameworks/ets/gesture_event/src/ohos.multimodalInput.gestureEvent.impl.cpp new file mode 100644 index 0000000000..4eee7593e6 --- /dev/null +++ b/frameworks/ets/gesture_event/src/ohos.multimodalInput.gestureEvent.impl.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +#include "ohos.multimodalInput.gestureEvent.proj.hpp" +#include "ohos.multimodalInput.gestureEvent.impl.hpp" +#include "taihe/runtime.hpp" +#include "stdexcept" + +using namespace taihe; +using namespace ohos::multimodalInput::gestureEvent; + +namespace { +} // namespace + +// Since these macros are auto-generate, lint will cause false positive. +// NOLINTBEGIN +// NOLINTEND \ No newline at end of file diff --git a/frameworks/ets/input_consumer/BUILD.gn b/frameworks/ets/input_consumer/BUILD.gn new file mode 100644 index 0000000000..6977509744 --- /dev/null +++ b/frameworks/ets/input_consumer/BUILD.gn @@ -0,0 +1,96 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/components/ets_frontend/ets2abc_config.gni") +import("//build/ohos.gni") +import("//build/ohos/taihe_idl/taihe.gni") +import("//foundation/multimodalinput/input/multimodalinput_mini.gni") +copy_taihe_idl("input_consumer_taihe") { + sources = [ "idl/ohos.multimodalInput.inputConsumer.taihe" ] + deps = [ "${mmi_path}/frameworks/ets/key_event:key_event_taihe" ] +} +config("inputConsumer_config") { + visibility = [ ":*" ] + + include_dirs = [ + "include", + "${mmi_path}/frameworks/ets/key_code/include" + ] +} +subsystem_name = "multimodalinput" +part_name = "input" +taihe_generated_file_path_inputConsumer = "$taihe_file_path/out/$subsystem_name/$part_name/inputConsumer" +ohos_taihe("run_taihe") { + taihe_generated_file_path = "${taihe_generated_file_path_inputConsumer}" + deps = [ ":input_consumer_taihe" ] + outputs = [ + "$taihe_generated_file_path/src/ohos.multimodalInput.inputConsumer.ani.cpp", + "$taihe_generated_file_path/src/ohos.multimodalInput.inputConsumer.abi.c", + ] +} +taihe_shared_library("InputConsumer") { + taihe_generated_file_path = "${taihe_generated_file_path_inputConsumer}" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + sources = get_target_outputs(":run_taihe") + configs = [ + "${mmi_path}:coverage_flags", + ":inputConsumer_config", + ] + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + ] + sources += [ + "src/ani_constructor.cpp", + "src/ohos.multimodalInput.inputConsumer.impl.cpp", + "src/inputConsumer_keyOptions_impl.cpp", + "src/inputConsumer_hotkeyOptions_impl.cpp", + "src/inputConsumer_keyPressed_impl.cpp", + "${mmi_path}/frameworks/ets/key_code/src/ohos.multimodalInput.keyCode.impl.cpp", + ] + deps = [ + ":run_taihe", + "${mmi_path}/frameworks/proxy:libmmi-client", + "${mmi_path}/util:libmmi-util", + ] + branch_protector_ret = "pac_ret" + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } +} +generate_static_abc("input_consumer") { + base_url = "${taihe_generated_file_path_inputConsumer}" + files = [ "${taihe_generated_file_path_inputConsumer}/@ohos.multimodalInput.inputConsumer.ets" ] + is_boot_abc = "True" + device_dst_file = "/system/framework/input_consumer.abc" + dependencies = [ ":run_taihe" ] +} +ohos_prebuilt_etc("input_consumer_etc") { + source = "$target_out_dir/input_consumer.abc" + module_install_dir = "framework" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + deps = [ ":input_consumer" ] +} +group("ets_inputConsumer_package") { + deps = [ + ":input_consumer_etc", + ":InputConsumer", + ] +} \ No newline at end of file diff --git a/frameworks/ets/input_consumer/idl/ohos.multimodalInput.inputConsumer.taihe b/frameworks/ets/input_consumer/idl/ohos.multimodalInput.inputConsumer.taihe new file mode 100644 index 0000000000..3e7fe827d5 --- /dev/null +++ b/frameworks/ets/input_consumer/idl/ohos.multimodalInput.inputConsumer.taihe @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@!namespace("@ohos.multimodalInput.inputConsumer", "inputConsumer") +from ohos.multimodalInput.keyEvent use KeyEvent; +@!sts_inject(""" +static { loadLibrary("InputConsumer.z") } +""") + +@!sts_inject_into_module("import * as ohos_multimodalInput_keyEvent from './@ohos.multimodalInput.keyEvent';") + +struct KeyOptions { + preKeys: Array; + finalKey: i32; + isFinalKeyDown: bool; + finalKeyDownDuration: i32; + isRepeat: Optional; +} + +struct HotkeyOptions { + preKeys: Array; + finalKey: i32; + isRepeat: Optional; +} + +struct KeyPressedConfig { + key: i32; + action: i32; + isRepeat: bool; +} + +struct InfraredFrequency { + max: i32; + min: i32; +} + +@!sts_inject(""" + function on(type: 'key', keyOptions: KeyOptions, callback: (info: KeyOptions) => void) { + return onKey(keyOptions, callback, callback); + } + function off(type: 'key', keyOptions: KeyOptions, callback?: (info: KeyOptions) => void) { + return offKey(keyOptions, callback); + } +""") +@!sts_inject(""" + function on(type: 'hotkeyChange', hotkeyOptions: HotkeyOptions, callback: (info: HotkeyOptions) => void) { + return onHotkeyChange(hotkeyOptions, callback, callback); + } + function off(type: 'hotkeyChange', hotkeyOptions: HotkeyOptions, callback?: (info: HotkeyOptions) => void) { + return offHotkeyChange(hotkeyOptions, callback); + } +""") +@!sts_inject(""" + function on(type: 'keyPressed', options: KeyPressedConfig, + callback: (info: ohos_multimodalInput_keyEvent.KeyEvent) => void) { + return onKeyPressed(options, callback, callback); + } + function off(type: 'keyPressed', callback?: (info: ohos_multimodalInput_keyEvent.KeyEvent) => void) { + return offKeyPressed(callback); + } +""") + +function onKey(keyOptions: KeyOptions, f: (info: KeyOptions) => void, opq: Opaque); +function offKey(keyOptions: KeyOptions, opq: Optional); +function onHotkeyChange(hotkeyOptions: HotkeyOptions, f: (info: HotkeyOptions) => void, opq: Opaque); +function offHotkeyChange(hotkeyOptions: HotkeyOptions, opq: Optional); +function onKeyPressed(options: KeyPressedConfig, f: (info: KeyEvent) => void, opq: Opaque); +function offKeyPressed(opq: Optional); \ No newline at end of file diff --git a/frameworks/ani/input_consumer/include/input_consumer.h b/frameworks/ets/input_consumer/include/inputConsumer_hotkeyOptions_impl.h similarity index 31% rename from frameworks/ani/input_consumer/include/input_consumer.h rename to frameworks/ets/input_consumer/include/inputConsumer_hotkeyOptions_impl.h index 2ec895ce4f..a91809c00e 100644 --- a/frameworks/ani/input_consumer/include/input_consumer.h +++ b/frameworks/ets/input_consumer/include/inputConsumer_hotkeyOptions_impl.h @@ -1,10 +1,10 @@ - /* +/* * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,75 +13,42 @@ * limitations under the License. */ -#ifndef ANI_INPUT_CONSUMER_H -#define ANI_INPUT_CONSUMER_H +#ifndef INPUT_CONSUMER_HOT_KEY_OPTIONS_IMPL_H +#define INPUT_CONSUMER_HOT_KEY_OPTIONS_IMPL_H -#include -#include -#include -#include -#include -#include +#include "ohos.multimodalInput.inputConsumer.proj.hpp" +#include "ohos.multimodalInput.inputConsumer.impl.hpp" +#include "taihe/runtime.hpp" +#include "stdexcept" -#include "key_option.h" - -#define SUCCESS_CODE 0 -#define ERROR_CODE (-1) -#define UNREGISTERED_CODE (-2) -#define PRE_KEY_MAX_COUNT 4 - -enum JS_CALLBACK_EVENT { - JS_CALLBACK_EVENT_FAILED = -1, - JS_CALLBACK_EVENT_SUCCESS = 1, - JS_CALLBACK_EVENT_EXIST = 2, - JS_CALLBACK_EVENT_NOT_EXIST = 3, -}; +#include "define_multimodal.h" +#include "input_manager.h" namespace OHOS { namespace MMI { - -struct KeyEventMonitorInfo { - ani_env* env = nullptr; - std::string eventType; - std::string name; - ani_ref callback = nullptr; - int32_t subscribeId = 0; - ani_ref keyOptionsObj = nullptr; - std::shared_ptr keyOption = nullptr; - ~KeyEventMonitorInfo(); +using namespace ohos::multimodalInput::inputConsumer; + +static const std::vector pressKeyCodes = { + KeyEvent::KEYCODE_ALT_LEFT, + KeyEvent::KEYCODE_ALT_RIGHT, + KeyEvent::KEYCODE_SHIFT_LEFT, + KeyEvent::KEYCODE_SHIFT_RIGHT, + KeyEvent::KEYCODE_CTRL_LEFT, + KeyEvent::KEYCODE_CTRL_RIGHT }; -class AniLocalScopeGuard { -public: - AniLocalScopeGuard(ani_env *env, size_t nrRefs) : env_(env) - { - status_ = env_->CreateLocalScope(nrRefs); - } - - ~AniLocalScopeGuard() - { - if (ANI_OK != status_) { - return; - } - env_->DestroyLocalScope(); - } - - bool IsStatusOK() - { - return ANI_OK == status_; - } - - ani_status GetStatus() - { - return status_; - } - -private: - ani_env *env_ = nullptr; - ani_status status_ = ANI_ERROR; +static const std::vector finalKeyCodes = { + KeyEvent::KEYCODE_ALT_LEFT, + KeyEvent::KEYCODE_ALT_RIGHT, + KeyEvent::KEYCODE_SHIFT_LEFT, + KeyEvent::KEYCODE_SHIFT_RIGHT, + KeyEvent::KEYCODE_CTRL_LEFT, + KeyEvent::KEYCODE_CTRL_RIGHT, + KeyEvent::KEYCODE_META_LEFT, + KeyEvent::KEYCODE_META_RIGHT }; -typedef std::map>> Callbacks; + +HotkeyOptions ConverTaiheHotkeyOptions(std::shared_ptr keyOption); } // namespace MMI } // namespace OHOS - -#endif // ANI_INPUT_CONSUMER_H +#endif // INPUT_CONSUMER_HOT_KEY_OPTIONS_IMPL_H \ No newline at end of file diff --git a/frameworks/ets/input_consumer/include/inputConsumer_keyOptions_impl.h b/frameworks/ets/input_consumer/include/inputConsumer_keyOptions_impl.h new file mode 100644 index 0000000000..4812936479 --- /dev/null +++ b/frameworks/ets/input_consumer/include/inputConsumer_keyOptions_impl.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef INPUT_CONSUMER_KEY_OPTIONS_IMPL_H +#define INPUT_CONSUMER_KEY_OPTIONS_IMPL_H + +#include "ohos.multimodalInput.inputConsumer.proj.hpp" +#include "ohos.multimodalInput.inputConsumer.impl.hpp" +#include "taihe/runtime.hpp" +#include "stdexcept" + +#include "define_multimodal.h" +#include "input_manager.h" + +namespace OHOS { +namespace MMI { +using namespace ohos::multimodalInput::inputConsumer; + +ohos::multimodalInput::keyEvent::KeyEvent TaiheInvalidKeyPressed(); +std::string GenerateKeyOptionKey(const std::shared_ptr& keyOption); +KeyOptions ConverTaiheKeyOptions(std::shared_ptr keyOption); +} // namespace MMI +} // namespace OHOS +#endif // INPUT_CONSUMER_KEY_OPTIONS_IMPL_H \ No newline at end of file diff --git a/frameworks/ets/input_consumer/include/inputConsumer_keyPressed_impl.h b/frameworks/ets/input_consumer/include/inputConsumer_keyPressed_impl.h new file mode 100644 index 0000000000..3ee7ea743b --- /dev/null +++ b/frameworks/ets/input_consumer/include/inputConsumer_keyPressed_impl.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef INPUT_CONSUMER_KEY_PRESSED_IMPL_H +#define INPUT_CONSUMER_KEY_PRESSED_IMPL_H + +#include "ohos.multimodalInput.inputConsumer.proj.hpp" +#include "ohos.multimodalInput.inputConsumer.impl.hpp" +#include "taihe/runtime.hpp" +#include "stdexcept" + +#include "define_multimodal.h" +#include "input_manager.h" +#include "ohos.multimodalInput.keyCode.impl.h" + +namespace OHOS { +namespace MMI { +using namespace ohos::multimodalInput::inputConsumer; + +enum EtsKeyAction { + ETS_KEY_ACTION_CANCEL, + ETS_KEY_ACTION_DOWN, + ETS_KEY_ACTION_UP, +}; + +const std::set allowedKeys_ { + KeyEvent::KEYCODE_VOLUME_DOWN, + KeyEvent::KEYCODE_VOLUME_UP, +}; + +EtsKeyAction KeyActionEtsKeyAction(int32_t action); +ohos::multimodalInput::keyEvent::Key KeyItemEtsKey(const KeyEvent::KeyItem &keyItem); +ohos::multimodalInput::keyEvent::Action ConverKeyAction(EtsKeyAction action); +ohos::multimodalInput::keyEvent::KeyEvent ConverTaiheKeyPressed(std::shared_ptr keyEvent); +} // namespace MMI +} // namespace OHOS +#endif // INPUT_CONSUMER_KEY_PRESSED_IMPL_H \ No newline at end of file diff --git a/frameworks/ets/input_consumer/src/ani_constructor.cpp b/frameworks/ets/input_consumer/src/ani_constructor.cpp new file mode 100644 index 0000000000..22bbf49dfd --- /dev/null +++ b/frameworks/ets/input_consumer/src/ani_constructor.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ohos.multimodalInput.inputConsumer.ani.hpp" +ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) +{ + ani_env *env; + if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) { + return ANI_ERROR; + } + if (ANI_OK != ohos::multimodalInput::inputConsumer::ANIRegister(env)) { + std::cerr << "Error from ohos::multimodalInput::inputConsumer::ANIRegister" << std::endl; + return ANI_ERROR; + } + *result = ANI_VERSION_1; + return ANI_OK; +} \ No newline at end of file diff --git a/frameworks/ets/input_consumer/src/inputConsumer_hotkeyOptions_impl.cpp b/frameworks/ets/input_consumer/src/inputConsumer_hotkeyOptions_impl.cpp new file mode 100644 index 0000000000..8123694c1e --- /dev/null +++ b/frameworks/ets/input_consumer/src/inputConsumer_hotkeyOptions_impl.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "inputConsumer_hotkeyOptions_impl.h" + +#undef MMI_LOG_TAG +#define MMI_LOG_TAG "inputConsumer_hotkeyOptions_impl" + +namespace OHOS { +namespace MMI { + +HotkeyOptions ConverTaiheHotkeyOptions(std::shared_ptr keyOption) +{ + if (keyOption == nullptr) { + MMI_HILOGE("keyOption invalid"); + return { + taihe::array(nullptr, 0), + 0, + taihe::optional(std::nullopt) + }; + } + std::set preKeysSet = keyOption->GetPreKeys(); + std::vector preKeysVec(preKeysSet.begin(), preKeysSet.end()); + bool isRepeatValue = keyOption->IsRepeat(); + return { + taihe::array(preKeysVec), + keyOption->GetFinalKey(), + taihe::optional(&isRepeatValue) + }; +} +} // namespace MMI +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/ets/input_consumer/src/inputConsumer_keyOptions_impl.cpp b/frameworks/ets/input_consumer/src/inputConsumer_keyOptions_impl.cpp new file mode 100644 index 0000000000..3809d945cb --- /dev/null +++ b/frameworks/ets/input_consumer/src/inputConsumer_keyOptions_impl.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "inputConsumer_keyOptions_impl.h" + +#undef MMI_LOG_TAG +#define MMI_LOG_TAG "inputConsumer_keyOptions_impl" + +namespace OHOS { +namespace MMI { + +std::string GenerateKeyOptionKey(const std::shared_ptr& keyOption) +{ + std::string subKeyNames; + const std::set& preKeys = keyOption->GetPreKeys(); + int32_t finalKey = keyOption->GetFinalKey(); + bool isFinalKeyDown = keyOption->IsFinalKeyDown(); + int32_t finalKeyDownDuration = keyOption->GetFinalKeyDownDuration(); + bool isRepeat = keyOption->IsRepeat(); + for (const auto& key : preKeys) { + subKeyNames.append(std::to_string(key)).append(","); + } + subKeyNames.append(std::to_string(finalKey)).append(","); + subKeyNames.append(std::to_string(isFinalKeyDown)).append(","); + subKeyNames.append(std::to_string(finalKeyDownDuration)).append(","); + subKeyNames.append(std::to_string(isRepeat)); + return subKeyNames; +} + +KeyOptions ConverTaiheKeyOptions(std::shared_ptr keyOption) +{ + if (keyOption == nullptr) { + MMI_HILOGE("keyOption invalid"); + return { + taihe::array({}), + 0, + false, + 0, + taihe::optional(std::nullopt) + }; + } + std::set preKeysSet = keyOption->GetPreKeys(); + std::vector preKeysVec(preKeysSet.begin(), preKeysSet.end()); + bool isRepeatValue = keyOption->IsRepeat(); + return { + taihe::array(preKeysVec), + keyOption->GetFinalKey(), + keyOption->IsFinalKeyDown(), + keyOption->GetFinalKeyDownDuration(), + taihe::optional(&isRepeatValue) + }; +} +} // namespace MMI +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/ets/input_consumer/src/inputConsumer_keyPressed_impl.cpp b/frameworks/ets/input_consumer/src/inputConsumer_keyPressed_impl.cpp new file mode 100644 index 0000000000..1a71cae4c5 --- /dev/null +++ b/frameworks/ets/input_consumer/src/inputConsumer_keyPressed_impl.cpp @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "inputConsumer_keyPressed_impl.h" + +#undef MMI_LOG_TAG +#define MMI_LOG_TAG "inputConsumer_keyPressed_impl" + +namespace OHOS { +namespace MMI { +using namespace ohos::multimodalInput::keyCode; + +ohos::multimodalInput::keyEvent::KeyEvent TaiheInvalidKeyPressed() +{ + return { + { + 0, + 0, + 0, + 0, + 0 + }, + ohos::multimodalInput::keyEvent::Action::key_t::CANCEL, + { + ohos::multimodalInput::keyCode::KeyCode::key_t::KEYCODE_UNKNOWN, + 0, + 0 + }, + 0, + ::taihe::array(nullptr, 0), + false, + false, + false, + false, + false, + false, + false, + false + }; +} + +EtsKeyAction KeyActionEtsKeyAction(int32_t action) +{ + static const std::map keyActionMap { + { KeyEvent::KEY_ACTION_CANCEL, ETS_KEY_ACTION_CANCEL }, + { KeyEvent::KEY_ACTION_DOWN, ETS_KEY_ACTION_DOWN }, + { KeyEvent::KEY_ACTION_UP, ETS_KEY_ACTION_UP }, + }; + if (auto iter = keyActionMap.find(action); iter != keyActionMap.cend()) { + return iter->second; + } else { + return ETS_KEY_ACTION_CANCEL; + } +} + +ohos::multimodalInput::keyEvent::Action ConverKeyAction(EtsKeyAction action) +{ + switch (action) { + case ETS_KEY_ACTION_CANCEL: + return ohos::multimodalInput::keyEvent::Action::key_t::CANCEL; + case ETS_KEY_ACTION_DOWN: + return ohos::multimodalInput::keyEvent::Action::key_t::DOWN; + case ETS_KEY_ACTION_UP: + return ohos::multimodalInput::keyEvent::Action::key_t::UP; + } +} + +ohos::multimodalInput::keyEvent::Key KeyItemEtsKey(const KeyEvent::KeyItem &keyItem) +{ + return { + ConvertEtsKeyCode(keyItem.GetKeyCode()), + keyItem.GetDownTime(), + keyItem.GetDeviceId() + }; +} + +ohos::multimodalInput::keyEvent::KeyEvent ConverTaiheKeyPressed(std::shared_ptr keyEvent) +{ + if (keyEvent == nullptr) { + MMI_HILOGE("keyEvent is nullptr"); + return TaiheInvalidKeyPressed(); + } + auto keyItem = keyEvent->GetKeyItem(); + if (!keyItem) { + MMI_HILOGE("No key item(No:%{public}d,KC:%{private}d)", keyEvent->GetId(), keyEvent->GetKeyCode()); + return TaiheInvalidKeyPressed(); + } + std::vector etsKey; + ohos::multimodalInput::keyEvent::Key keycode = { + ohos::multimodalInput::keyCode::KeyCode::key_t::KEYCODE_UNKNOWN, + 0, + 0 + }; + auto keyItems = keyEvent->GetKeyItems(); + for (const auto &keyItem : keyItems) { + keycode = KeyItemEtsKey(keyItem); + etsKey.push_back(keycode); + } + return { + { + keyEvent->GetId(), + keyEvent->GetDeviceId(), + keyEvent->GetActionTime(), + keyEvent->GetTargetDisplayId(), + keyEvent->GetTargetWindowId() + }, + ConverKeyAction(KeyActionEtsKeyAction(keyEvent->GetKeyAction())), + keycode, + keyItem->GetUnicode(), + ::taihe::array(etsKey), + keyEvent->GetKeyItem(KeyEvent::KEYCODE_CTRL_RIGHT).has_value(), + keyEvent->GetKeyItem(KeyEvent::KEYCODE_ALT_RIGHT).has_value(), + keyEvent->GetKeyItem(KeyEvent::KEYCODE_SHIFT_RIGHT).has_value(), + keyEvent->GetKeyItem(KeyEvent::KEYCODE_META_RIGHT).has_value(), + keyEvent->GetKeyItem(KeyEvent::KEYCODE_FN).has_value(), + keyEvent->GetFunctionKey(KeyEvent::CAPS_LOCK_FUNCTION_KEY), + keyEvent->GetFunctionKey(KeyEvent::NUM_LOCK_FUNCTION_KEY), + keyEvent->GetFunctionKey(KeyEvent::SCROLL_LOCK_FUNCTION_KEY) + }; +} +} // namespace MMI +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/ets/input_consumer/src/ohos.multimodalInput.inputConsumer.impl.cpp b/frameworks/ets/input_consumer/src/ohos.multimodalInput.inputConsumer.impl.cpp new file mode 100644 index 0000000000..bf61616d73 --- /dev/null +++ b/frameworks/ets/input_consumer/src/ohos.multimodalInput.inputConsumer.impl.cpp @@ -0,0 +1,904 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ohos.multimodalInput.inputConsumer.proj.hpp" +#include "ohos.multimodalInput.inputConsumer.impl.hpp" +#include "taihe/runtime.hpp" +#include "stdexcept" + +#include "inputConsumer_keyOptions_impl.h" +#include "inputConsumer_hotkeyOptions_impl.h" +#include "inputConsumer_keyPressed_impl.h" + +#undef MMI_LOG_TAG +#define MMI_LOG_TAG "ohos.multimodalInput.inputConsumer" + +using namespace taihe; +using namespace ohos::multimodalInput::inputConsumer; +using namespace OHOS::MMI; + +namespace { +static constexpr size_t PRE_KEYS_SIZE { 4 }; +static constexpr int32_t INVALID_SUBSCRIBER_ID { -1 }; +static constexpr int32_t OCCUPIED_BY_SYSTEM = -3; +static constexpr int32_t OCCUPIED_BY_OTHER = -4; +const int64_t MILLISECONDS_IN_SECOND = 1000; + +enum ETS_CALLBACK_EVENT { + ETS_CALLBACK_EVENT_FAILED = -1, + ETS_CALLBACK_EVENT_SUCCESS = 1, + ETS_CALLBACK_EVENT_EXIST = 2, + ETS_CALLBACK_EVENT_NOT_EXIST = 3, +}; + +enum EtsErrorCode : int32_t { + OTHER_ERROR = -1, + COMMON_PERMISSION_CHECK_ERROR = 201, + COMMON_USE_SYSAPI_ERROR = 202, + COMMON_PARAMETER_ERROR = 401, + INPUT_DEVICE_NOT_SUPPORTED = 801, + COMMON_DEVICE_NOT_EXIST = 3900001, + COMMON_KEYBOARD_DEVICE_NOT_EXIST = 3900002, + COMMON_NON_INPUT_APPLICATION = 3900003, + PRE_KEY_NOT_SUPPORTED = 4100001, + INPUT_OCCUPIED_BY_SYSTEM = 4200002, + INPUT_OCCUPIED_BY_OTHER = 4200003, + ERROR_WINDOW_ID_PERMISSION_DENIED = 26500001, +}; + +struct KeyMonitor { + int32_t subscriberId { -1 }; + KeyMonitorOption keyOption {}; +}; + +struct KeyEventMonitorInfo { + std::string eventType; + int32_t subscribeId{ 0 }; + std::shared_ptr keyOption{ nullptr }; + ~KeyEventMonitorInfo(); +}; +typedef std::map>> Callbacks; +static Callbacks hotkeyCallbacks = {}; +static Callbacks keyCallbacks = {}; + + +using callbackType = std::variant, taihe::callback, + taihe::callback>; +struct CallbackObject { + CallbackObject(callbackType cb, ani_ref ref) : callback(cb), ref(ref) + { + } + ~CallbackObject() + { + if (auto *env = taihe::get_env()) { + env->GlobalReference_Delete(ref); + } + } + callbackType callback; + ani_ref ref; +}; + +class GlobalRefGuard { + ani_env *env_ = nullptr; + ani_ref ref_ = nullptr; + +public: + GlobalRefGuard(ani_env *env, ani_object obj) : env_(env) + { + if (!env_) { + return; + } + if (ANI_OK != env_->GlobalReference_Create(obj, &ref_)) { + ref_ = nullptr; + } + } + explicit operator bool() const + { + return ref_ != nullptr; + } + ani_ref get() const + { + return ref_; + } + ~GlobalRefGuard() + { + if (env_ && ref_) { + env_->GlobalReference_Delete(ref_); + } + } + + GlobalRefGuard(const GlobalRefGuard &) = delete; + GlobalRefGuard &operator=(const GlobalRefGuard &) = delete; +}; + +std::map monitors_; +std::map>> jsCbMap_; +std::mutex g_mutex; +std::mutex sCallBacksMutex; +std::mutex jsCbMapMutex; +size_t g_baseId { 0 }; + +KeyEventMonitorInfo::~KeyEventMonitorInfo() {} + +int32_t RegisterListener(std::string const &type, callbackType &&cb, uintptr_t opq) +{ + std::lock_guard lock(jsCbMapMutex); + ani_object callbackObj = reinterpret_cast(opq); + ani_ref callbackRef; + ani_env *env = taihe::get_env(); + if (env == nullptr || ANI_OK != env->GlobalReference_Create(callbackObj, &callbackRef)) { + MMI_HILOGE("ani_env is nullptr or GlobalReference_Create failed"); + return ETS_CALLBACK_EVENT_FAILED; + } + auto &cbVec = jsCbMap_[type]; + bool isDuplicate = std::any_of(cbVec.begin(), cbVec.end(), + [env, callbackRef](std::shared_ptr &obj) { + ani_boolean isEqual = false; + return (ANI_OK == env->Reference_StrictEquals(callbackRef, obj->ref, &isEqual)) && isEqual; + }); + if (isDuplicate) { + env->GlobalReference_Delete(callbackRef); + MMI_HILOGD("callback already registered"); + return ETS_CALLBACK_EVENT_EXIST; + } + cbVec.emplace_back(std::make_shared(cb, callbackRef)); + MMI_HILOGI("register callback success, type: %{public}s", type.c_str()); + return ETS_CALLBACK_EVENT_SUCCESS; +} + +bool UnregisterListener(std::string const &type, taihe::optional_view opq) +{ + std::lock_guard lock(jsCbMapMutex); + const auto iter = jsCbMap_.find(type); + if (iter == jsCbMap_.end()) { + MMI_HILOGE("Already unRegistered!"); + return false; + } + if (!opq.has_value()) { + jsCbMap_.erase(iter); + MMI_HILOGE("callback is nullptr!"); + return false; + } + ani_env *env = taihe::get_env(); + if (env == nullptr) { + MMI_HILOGE("ani_env is nullptr!"); + return false; + } + GlobalRefGuard guard(env, reinterpret_cast(opq.value())); + if (!guard) { + MMI_HILOGE("GlobalRefGuard is false!"); + return false; + } + const auto pred = [env, targetRef = guard.get()](std::shared_ptr &obj) { + ani_boolean is_equal = false; + return (ANI_OK == env->Reference_StrictEquals(targetRef, obj->ref, &is_equal)) && is_equal; + }; + auto &callbacks = iter->second; + const auto it = std::find_if(callbacks.begin(), callbacks.end(), pred); + if (it != callbacks.end()) { + callbacks.erase(it); + } + if (callbacks.empty()) { + jsCbMap_.erase(iter); + } + MMI_HILOGI("Unregister callback success, type: %{public}s", type.c_str()); + return true; +} + +size_t GenerateId() +{ + return g_baseId++; +} + +void EmitKeyPerssedCallbackWork(size_t keyMonitorId, std::shared_ptr keyEvent) +{ + CALL_DEBUG_ENTER; + std::lock_guard lock(jsCbMapMutex); + auto &cbVec = jsCbMap_[std::to_string(keyMonitorId)]; + for (auto &cb : cbVec) { + auto &func = std::get>(cb->callback); + auto keyPresseds = ConverTaiheKeyPressed(keyEvent); + func(keyPresseds); + } +} + +void OnSubscribeKeyMonitor(size_t keyMonitorId, std::shared_ptr keyEvent) +{ + CALL_DEBUG_ENTER; + CHKPV(keyEvent); + std::lock_guard guard(g_mutex); + auto mIter = monitors_.find(keyMonitorId); + if (mIter == monitors_.end()) { + MMI_HILOGE("No key monitor with ID(%{public}zu)", keyMonitorId); + return; + } + EmitKeyPerssedCallbackWork(keyMonitorId, keyEvent); +} + +bool CheckKeyMonitorOption(const KeyMonitorOption &keyOption) +{ + return ((allowedKeys_.find(keyOption.GetKey()) != allowedKeys_.cend()) && + (keyOption.GetAction() == KeyEvent::KEY_ACTION_DOWN)); +} + + +bool ParseKeyMonitorOption(KeyPressedConfig const& options, KeyMonitor &keyMonitor) +{ + CALL_DEBUG_ENTER; + keyMonitor.keyOption.SetKey(options.key); + keyMonitor.keyOption.SetAction(options.action); + keyMonitor.keyOption.SetRepeat(options.isRepeat); + if (CheckKeyMonitorOption(keyMonitor.keyOption)) { + MMI_HILOGE("Input for KeyPressedConfig is invalid"); + taihe::set_business_error(COMMON_PARAMETER_ERROR, "Input for KeyPressedConfig is invalid"); + return false; + } + return true; +} + + +void SubscribeKeyMonitor(KeyPressedConfig const& options, + callback_view f, uintptr_t opq) +{ + std::lock_guard guard(g_mutex); + KeyMonitor keyMonitor {}; + if (!ParseKeyMonitorOption(options, keyMonitor)) { + MMI_HILOGE("Invalid KeyMonitorOption"); + return; + } + MMI_HILOGI("[ETS] Subscribe key monitor"); + auto keyMonitorId = GenerateId(); + auto result = RegisterListener(std::to_string(keyMonitorId), f, opq); + if (result == ETS_CALLBACK_EVENT_FAILED) { + MMI_HILOGE("Register listener failed"); + return; + } + if (result == ETS_CALLBACK_EVENT_EXIST) { + MMI_HILOGE("Callback already exist"); + return; + } + auto subscriberId = InputManager::GetInstance()->SubscribeKeyMonitor(keyMonitor.keyOption, + [keyMonitorId](std::shared_ptr keyEvent) { + OnSubscribeKeyMonitor(keyMonitorId, keyEvent); + }); + if (subscriberId < 0) { + if (subscriberId == -CAPABILITY_NOT_SUPPORTED) { + MMI_HILOGE("Capability not supported"); + taihe::set_business_error(INPUT_DEVICE_NOT_SUPPORTED, "Capability not supported."); + } else if (subscriberId == -PARAM_INPUT_INVALID) { + MMI_HILOGE("Input is invalid"); + taihe::set_business_error(COMMON_PARAMETER_ERROR, "Input is invalid"); + } else { + MMI_HILOGE("SubscribeKeyMonitor fail, error:%{public}d", subscriberId); + } + } + MMI_HILOGI("[ETS] Subscribe key monitor(ID:%{public}zu, subscriberId:%{public}d)", keyMonitorId, subscriberId); + if (result == ETS_CALLBACK_EVENT_SUCCESS) { + keyMonitor.subscriberId = subscriberId; + monitors_.emplace(keyMonitorId, keyMonitor); + } +} + +void UnsubscribeKeyMonitor(taihe::optional_view opq) +{ + std::lock_guard guard(g_mutex); + for (auto iter = monitors_.begin(); iter != monitors_.end(); ++iter) { + if (!UnregisterListener(std::to_string(iter->first), opq)) { + MMI_HILOGE("UnregisterListener fail"); + return; + } + MMI_HILOGI("[NAPI] Unsubscribe key monitor(ID:%{public}zu, subscriberId:%{public}d)", + iter->first, iter->second.subscriberId); + auto ret = InputManager::GetInstance()->UnsubscribeKeyMonitor(iter->second.subscriberId); + if (ret == -CAPABILITY_NOT_SUPPORTED) { + MMI_HILOGE("Capability not supported"); + taihe::set_business_error(INPUT_DEVICE_NOT_SUPPORTED, "Capability not supported."); + } else if (ret == -PARAM_INPUT_INVALID) { + MMI_HILOGE("Input is invalid"); + taihe::set_business_error(COMMON_PARAMETER_ERROR, "Input is invalid"); + } else if (ret != RET_OK) { + MMI_HILOGE("UnsubscribeKeyMonitor fail, error:%{public}d", ret); + } + monitors_.erase(iter); + return; + } + + auto ret = InputManager::GetInstance()->UnsubscribeKeyMonitor(INVALID_SUBSCRIBER_ID); + if (ret == -CAPABILITY_NOT_SUPPORTED) { + MMI_HILOGE("Capability not supported"); + taihe::set_business_error(INPUT_DEVICE_NOT_SUPPORTED, "Capability not supported."); + } else { + MMI_HILOGE("Input is invalid"); + taihe::set_business_error(COMMON_PARAMETER_ERROR, "Input is invalid"); + } +} + +void UnsubscribeKeyMonitors() +{ + std::lock_guard guard(g_mutex); + if (monitors_.empty()) { + auto ret = InputManager::GetInstance()->UnsubscribeKeyMonitor(INVALID_SUBSCRIBER_ID); + if (ret == -CAPABILITY_NOT_SUPPORTED) { + MMI_HILOGE("Capability not supported"); + taihe::set_business_error(INPUT_DEVICE_NOT_SUPPORTED, "Capability not supported."); + } + return; + } + for (auto &[monitorId, monitor] : monitors_) { + MMI_HILOGI("[NAPI] Unsubscribe key monitor(ID:%{public}zu, subscriberId:%{public}d)", + monitorId, monitor.subscriberId); + auto ret = InputManager::GetInstance()->UnsubscribeKeyMonitor(monitor.subscriberId); + if (ret != RET_OK) { + MMI_HILOGE("UnsubscribeKeyMonitor fail, error:%{public}d", ret); + } + } + monitors_.clear(); +} + +int32_t GetPreSubscribeId(Callbacks &callbacks, std::shared_ptr event) +{ + CHKPR(event, ERROR_NULL_POINTER); + std::lock_guard guard(sCallBacksMutex); + auto it = callbacks.find(event->eventType); + if (it == callbacks.end() || it->second.empty()) { + MMI_HILOGE("The callbacks is empty"); + return ETS_CALLBACK_EVENT_FAILED; + } + CHKPR(it->second.front(), ERROR_NULL_POINTER); + return it->second.front()->subscribeId; +} + +int32_t GetPreKeys(std::vector &preKeys, std::set ¶ms) +{ + CALL_DEBUG_ENTER; + std::size_t arrayLength = preKeys.size(); + for (std::size_t i = 0; i < arrayLength; i++) { + MMI_HILOGD("Get int array number:%{public}d", preKeys[i]); + if (!params.insert(preKeys[i]).second) { + MMI_HILOGE("Params insert value failed"); + return RET_ERR; + } + } + return RET_OK; +} + +bool IsMatchKeyAction(bool isFinalKeydown, int32_t keyAction) +{ + CALL_DEBUG_ENTER; + MMI_HILOGD("isFinalKeydown:%{public}d, keyAction:%{public}d", isFinalKeydown, keyAction); + if (isFinalKeydown && keyAction == KeyEvent::KEY_ACTION_DOWN) { + return true; + } + if (!isFinalKeydown && keyAction == KeyEvent::KEY_ACTION_UP) { + return true; + } + MMI_HILOGE("isFinalKeydown not matched with keyAction"); + return false; +} + +bool MatchCombinationKeys(std::shared_ptr monitorInfo, std::shared_ptr keyEvent) +{ + CALL_DEBUG_ENTER; + CHKPF(monitorInfo); + CHKPF(keyEvent); + auto keyOption = monitorInfo->keyOption; + CHKPF(keyOption); + std::vector items = keyEvent->GetKeyItems(); + int32_t infoFinalKey = keyOption->GetFinalKey(); + int32_t keyEventFinalKey = keyEvent->GetKeyCode(); + bool isFinalKeydown = keyOption->IsFinalKeyDown(); + MMI_HILOGD("InfoFinalKey:%{private}d,keyEventFinalKey:%{private}d", infoFinalKey, keyEventFinalKey); + if (infoFinalKey != keyEventFinalKey || items.size() > PRE_KEYS_SIZE || + !IsMatchKeyAction(isFinalKeydown, keyEvent->GetKeyAction())) { + MMI_HILOGD("key Param invalid"); + return false; + } + std::set infoPreKeys = keyOption->GetPreKeys(); + int32_t infoSize = 0; + for (auto it = infoPreKeys.begin(); it != infoPreKeys.end(); ++it) { + if (*it >= 0) { + infoSize++; + } + } + int32_t count = 0; + for (const auto &item : items) { + if (item.GetKeyCode() == keyEventFinalKey) { + continue; + } + auto iter = find(infoPreKeys.begin(), infoPreKeys.end(), item.GetKeyCode()); + if (iter == infoPreKeys.end()) { + MMI_HILOGW("No keyCode in preKeys"); + return false; + } + count++; + } + MMI_HILOGD("kevEventSize:%{public}d, infoSize:%{public}d", count, infoSize); + std::optional keyItem = keyEvent->GetKeyItem(); + if (!keyItem) { + MMI_HILOGE("The keyItem is nullopt"); + return false; + } + auto downTime = keyItem->GetDownTime(); + auto upTime = keyEvent->GetActionTime(); + auto curDurationTime = keyOption->GetFinalKeyDownDuration(); + if (curDurationTime > 0 && (upTime - downTime >= + (static_cast(curDurationTime) * MILLISECONDS_IN_SECOND))) { + MMI_HILOGE("Skip, upTime - downTime >= duration"); + return false; + } + return count == infoSize; +} + +void EmitHotkeyCallbackWork(std::shared_ptr reportEvent) +{ + CALL_DEBUG_ENTER; + CHKPV(reportEvent); + std::lock_guard lock(jsCbMapMutex); + auto &cbVec = jsCbMap_[reportEvent->eventType]; + for (auto &cb : cbVec) { + auto &func = std::get>(cb->callback); + auto hotkeyOptions = ConverTaiheHotkeyOptions(reportEvent->keyOption); + func(hotkeyOptions); + } +} + +static void SubHotkeyEventCallback(std::shared_ptr keyEvent) +{ + CALL_DEBUG_ENTER; + CHKPV(keyEvent); + std::lock_guard guard(sCallBacksMutex); + auto iter = hotkeyCallbacks.begin(); + while (iter != hotkeyCallbacks.end()) { + auto &list = iter->second; + ++iter; + MMI_HILOGD("Callback list size:%{public}zu", list.size()); + auto infoIter = list.begin(); + while (infoIter != list.end()) { + auto monitorInfo = *infoIter; + if (MatchCombinationKeys(monitorInfo, keyEvent)) { + EmitHotkeyCallbackWork(monitorInfo); + MMI_HILOGD("need to async callback"); + } + ++infoIter; + } + } +} + +int32_t AddEventHotkeyCallback(Callbacks &callbacks, std::shared_ptr event, + callback_view f, uintptr_t opq) +{ + CALL_DEBUG_ENTER; + std::lock_guard guard(sCallBacksMutex); + CHKPR(event, RET_ERR); + auto result = RegisterListener(event->eventType, f, opq); + if (result == ETS_CALLBACK_EVENT_FAILED) { + MMI_HILOGE("Register listener failed"); + return RET_ERR; + } + if (result == ETS_CALLBACK_EVENT_EXIST) { + MMI_HILOGE("Callback already exist"); + return RET_ERR; + } + if (result == ETS_CALLBACK_EVENT_SUCCESS) { + hotkeyCallbacks[event->eventType].push_back(event); + } + return RET_OK; +} + +int32_t GetHotkeyEventInfo(HotkeyOptions const& hotkeyOptions, + std::shared_ptr event, std::shared_ptr keyOption) +{ + CALL_DEBUG_ENTER; + CHKPR(event, RET_ERR); + CHKPR(keyOption, RET_ERR); + if (hotkeyOptions.preKeys.empty()) { + taihe::set_business_error(COMMON_PARAMETER_ERROR, "PreKeys not found"); + return RET_ERR; + } + std::set preKeys; + std::vector etsPreKeys(hotkeyOptions.preKeys.begin(), hotkeyOptions.preKeys.end()); + if (GetPreKeys(etsPreKeys, preKeys) != RET_OK) { + MMI_HILOGE("Get preKeys failed"); + return RET_ERR; + } + if (preKeys.size() > PRE_KEYS_SIZE) { + MMI_HILOGE("PreKeys size invalid"); + taihe::set_business_error(COMMON_PARAMETER_ERROR, "PreKeys size invalid"); + return RET_ERR; + } + MMI_HILOGD("PreKeys size:%{public}zu", preKeys.size()); + keyOption->SetPreKeys(preKeys); + std::string subKeyNames = ""; + for (const auto &item : preKeys) { + auto it = std::find(pressKeyCodes.begin(), pressKeyCodes.end(), item); + if (it == pressKeyCodes.end()) { + MMI_HILOGE("PreKeys is not expect"); + taihe::set_business_error(COMMON_PARAMETER_ERROR, "PreKeys size invalid"); + return RET_ERR; + } + subKeyNames += std::to_string(item); + subKeyNames += ","; + MMI_HILOGD("PreKeys:%{private}d", item); + } + if (hotkeyOptions.finalKey < 0) { + MMI_HILOGE("FinalKey:%{private}d is less 0, can not process", hotkeyOptions.finalKey); + taihe::set_business_error(COMMON_PARAMETER_ERROR, "FinalKey must be greater than or equal to 0"); + return RET_ERR; + } + auto it = std::find(finalKeyCodes.begin(), finalKeyCodes.end(), hotkeyOptions.finalKey); + if (it != finalKeyCodes.end()) { + MMI_HILOGE("FinalKey is not expect"); + taihe::set_business_error(COMMON_PARAMETER_ERROR, "FinalKey is not expect"); + return RET_ERR; + } + subKeyNames += std::to_string(hotkeyOptions.finalKey); + subKeyNames += ","; + keyOption->SetFinalKey(hotkeyOptions.finalKey); + MMI_HILOGD("FinalKey:%{private}d", hotkeyOptions.finalKey); + + bool isFinalKeyDown = true; + subKeyNames += std::to_string(isFinalKeyDown); + subKeyNames += ","; + keyOption->SetFinalKeyDown(isFinalKeyDown); + MMI_HILOGD("IsFinalKeyDown:%{private}d,", (isFinalKeyDown == true ? 1 : 0)); + + int32_t finalKeyDownDuration = 0; + subKeyNames += std::to_string(finalKeyDownDuration); + subKeyNames += ","; + keyOption->SetFinalKeyDownDuration(finalKeyDownDuration); + + bool isRepeat = true; + if (!hotkeyOptions.isRepeat.has_value()) { + MMI_HILOGD("IsRepeat field is default"); + } else { + isRepeat = hotkeyOptions.isRepeat.value(); + } + subKeyNames += std::to_string(isRepeat); + keyOption->SetRepeat(isRepeat); + MMI_HILOGD("IsRepeat:%{public}s", (isRepeat ? "true" : "false")); + event->eventType = subKeyNames; + return RET_OK; +} + +void SubscribeHotkey(HotkeyOptions const& hotkeyOptions, callback_view f, uintptr_t opq) +{ + CALL_DEBUG_ENTER; + std::shared_ptr event = std::make_shared(); + CHKPV(event); + auto keyOption = std::make_shared(); + CHKPV(keyOption); + if (GetHotkeyEventInfo(hotkeyOptions, event, keyOption) != RET_OK) { + MMI_HILOGE("GetHotkeyEventInfo failed"); + return; + } + event->keyOption = keyOption; + int32_t preSubscribeId = GetPreSubscribeId(hotkeyCallbacks, event); + if (preSubscribeId < 0) { + MMI_HILOGD("EventType:%{private}s", event->eventType.c_str()); + int32_t subscribeId = InputManager::GetInstance()->SubscribeHotkey(keyOption, SubHotkeyEventCallback); + if (subscribeId == ERROR_UNSUPPORT) { + MMI_HILOGE("SubscribeId invalid:%{public}d", subscribeId); + taihe::set_business_error(INPUT_DEVICE_NOT_SUPPORTED, "Hotkey occupied by other"); + return; + } + if (subscribeId == OCCUPIED_BY_SYSTEM) { + MMI_HILOGE("SubscribeId invalid:%{public}d", subscribeId); + taihe::set_business_error(INPUT_OCCUPIED_BY_SYSTEM, "Hotkey occupied by system"); + return; + } + if (subscribeId == OCCUPIED_BY_OTHER) { + MMI_HILOGE("SubscribeId invalid:%{public}d", subscribeId); + taihe::set_business_error(INPUT_OCCUPIED_BY_OTHER, "Hotkey occupied by other"); + return; + } + MMI_HILOGD("SubscribeId:%{public}d", subscribeId); + event->subscribeId = subscribeId; + } else { + event->subscribeId = preSubscribeId; + } + if (AddEventHotkeyCallback(hotkeyCallbacks, event, f, opq) != RET_OK) { + MMI_HILOGE("AddEventHotkeyCallback failed"); + taihe::set_business_error(COMMON_PARAMETER_ERROR, "AddEventHotkeyCallback failed"); + } +} + +int32_t DelEventCallbackRef(std::list> &info, std::string const &type, + optional_view opq, int32_t &subscribeId) +{ + CALL_DEBUG_ENTER; + for (auto iter = info.begin(); iter != info.end();) { + if (*iter == nullptr) { + info.erase(iter++); + continue; + } + if (opq.has_value()) { + if (UnregisterListener(type, opq)) { + std::shared_ptr monitorInfo = *iter; + info.erase(iter++); + if (info.empty()) { + subscribeId = monitorInfo->subscribeId; + } + MMI_HILOGD("Callback has deleted, size:%{public}zu", info.size()); + return ETS_CALLBACK_EVENT_SUCCESS; + } + ++iter; + continue; + } + std::shared_ptr monitorInfo = *iter; + info.erase(iter++); + if (info.empty()) { + subscribeId = monitorInfo->subscribeId; + } + MMI_HILOGD("Callback has deleted, size:%{public}zu", info.size()); + } + MMI_HILOGD("Callback size:%{public}zu", info.size()); + return ETS_CALLBACK_EVENT_SUCCESS; +} + +int32_t DelEventCallback(Callbacks &callbacks, std::shared_ptr event, + optional_view opq, int32_t &subscribeId) +{ + CALL_DEBUG_ENTER; + std::lock_guard guard(sCallBacksMutex); + CHKPR(event, ERROR_NULL_POINTER); + if (callbacks.count(event->eventType) <= 0) { + MMI_HILOGE("Callback doesn't exists"); + return ETS_CALLBACK_EVENT_FAILED; + } + auto &info = callbacks[event->eventType]; + MMI_HILOGD("EventType:%{private}s, keyEventMonitorInfos:%{public}zu", event->eventType.c_str(), info.size()); + return DelEventCallbackRef(info, event->eventType, opq, subscribeId); +} + +void UnsubscribeHotkey(HotkeyOptions const& hotkeyOptions, optional_view opq) +{ + CALL_DEBUG_ENTER; + std::shared_ptr event = std::make_shared(); + CHKPV(event); + auto keyOption = std::make_shared(); + CHKPV(keyOption); + int32_t subscribeId = -1; + if (GetHotkeyEventInfo(hotkeyOptions, event, keyOption) != RET_OK) { + MMI_HILOGE("GetHotkeyEventInfo failed"); + return; + } + if (DelEventCallback(hotkeyCallbacks, event, opq, subscribeId) < 0) { + MMI_HILOGE("DelEventCallback failed"); + return; + } + MMI_HILOGI("Unsubscribe hot key(%{public}d)", subscribeId); + InputManager::GetInstance()->UnsubscribeHotkey(subscribeId); +} + +void EmitKeyCallbackWork(std::shared_ptr reportEvent) +{ + CALL_DEBUG_ENTER; + CHKPV(reportEvent); + std::lock_guard lock(jsCbMapMutex); + auto &cbVec = jsCbMap_[reportEvent->eventType]; + for (auto &cb : cbVec) { + auto &func = std::get>(cb->callback); + auto keyOptions = ConverTaiheKeyOptions(reportEvent->keyOption); + func(keyOptions); + } +} + +static void SubKeyEventCallback(std::shared_ptr keyEvent, const std::string& keyOptionKey) +{ + CALL_DEBUG_ENTER; + CHKPV(keyEvent); + std::lock_guard guard(sCallBacksMutex); + auto iter = keyCallbacks.find(keyOptionKey); + if (iter != keyCallbacks.end()) { + auto &list = iter->second; + MMI_HILOGD("list size:%{public}zu", list.size()); + for (auto monitorInfo : list) { + if (MatchCombinationKeys(monitorInfo, keyEvent)) { + EmitKeyCallbackWork(monitorInfo); + } + } + } else { + MMI_HILOGE("No Matches found for SubKeyEventCallback"); + } +} + +int32_t AddEventKeyCallback(Callbacks &callbacks, std::shared_ptr event, + callback_view f, uintptr_t opq) +{ + CALL_DEBUG_ENTER; + std::lock_guard guard(sCallBacksMutex); + CHKPR(event, RET_ERR); + auto result = RegisterListener(event->eventType, f, opq); + if (result == ETS_CALLBACK_EVENT_FAILED) { + MMI_HILOGE("Register listener failed"); + return RET_ERR; + } + if (result == ETS_CALLBACK_EVENT_SUCCESS) { + keyCallbacks[event->eventType].push_back(event); + } + return RET_OK; +} + +int32_t GetEventInfoAPI9(KeyOptions const& keyOptions, std::shared_ptr event, + std::shared_ptr keyOption) +{ + CALL_DEBUG_ENTER; + CHKPR(event, RET_ERR); + CHKPR(keyOption, RET_ERR); + if (keyOptions.preKeys.empty()) { + taihe::set_business_error(COMMON_PARAMETER_ERROR, "preKeys not found"); + return RET_ERR; + } + std::set preKeys; + std::vector etsPreKeys(keyOptions.preKeys.begin(), keyOptions.preKeys.end()); + if (GetPreKeys(etsPreKeys, preKeys) != RET_OK) { + MMI_HILOGE("Get preKeys failed"); + return RET_ERR; + } + if (preKeys.size() > PRE_KEYS_SIZE) { + MMI_HILOGE("PreKeys size invalid"); + taihe::set_business_error(COMMON_PARAMETER_ERROR, "PreKeys size invalid"); + return RET_ERR; + } + MMI_HILOGD("PreKeys size:%{public}zu", preKeys.size()); + keyOption->SetPreKeys(preKeys); + std::string subKeyNames = ""; + for (const auto &item : preKeys) { + subKeyNames += std::to_string(item); + subKeyNames += ","; + MMI_HILOGD("preKeys:%{private}d", item); + } + + if (keyOptions.finalKey < 0) { + MMI_HILOGE("finalKey:%{private}d is less 0, can not process", keyOptions.finalKey); + taihe::set_business_error(COMMON_PARAMETER_ERROR, "finalKey must be greater than or equal to 0"); + return RET_ERR; + } + subKeyNames += std::to_string(keyOptions.finalKey); + subKeyNames += ","; + keyOption->SetFinalKey(keyOptions.finalKey); + MMI_HILOGD("FinalKey:%{private}d", keyOptions.finalKey); + + subKeyNames += std::to_string(keyOptions.isFinalKeyDown); + subKeyNames += ","; + keyOption->SetFinalKeyDown(keyOptions.isFinalKeyDown); + MMI_HILOGD("IsFinalKeyDown:%{private}d,map_key:%{private}s", + (keyOptions.isFinalKeyDown == true ? 1 : 0), subKeyNames.c_str()); + + if (keyOptions.finalKeyDownDuration < 0) { + MMI_HILOGE("finalKeyDownDuration:%{public}d is less 0, can not process", keyOptions.finalKeyDownDuration); + taihe::set_business_error(COMMON_PARAMETER_ERROR, "finalKeyDownDuration must be greater than or equal to 0"); + return RET_ERR; + } + subKeyNames += std::to_string(keyOptions.finalKeyDownDuration); + subKeyNames += ","; + keyOption->SetFinalKeyDownDuration(keyOptions.finalKeyDownDuration); + MMI_HILOGD("FinalKeyDownDuration:%{public}d", keyOptions.finalKeyDownDuration); + + bool isRepeat = true; + if (!keyOptions.isRepeat.has_value()) { + MMI_HILOGD("IsRepeat field is default"); + } else { + isRepeat = keyOptions.isRepeat.value(); + } + subKeyNames += std::to_string(isRepeat); + keyOption->SetRepeat(isRepeat); + MMI_HILOGD("IsRepeat:%{public}s", (isRepeat ? "true" : "false")); + event->eventType = subKeyNames; + return RET_OK; +} + +void SubscribeKey(KeyOptions const& keyOptions, callback_view f, uintptr_t opq) +{ + CALL_DEBUG_ENTER; + std::shared_ptr event = std::make_shared(); + CHKPV(event); + auto keyOption = std::make_shared(); + CHKPV(keyOption); + if (GetEventInfoAPI9(keyOptions, event, keyOption) != RET_OK) { + MMI_HILOGE("GetEventInfoAPI9 failed"); + return; + } + event->keyOption = keyOption; + int32_t preSubscribeId = GetPreSubscribeId(keyCallbacks, event); + if (preSubscribeId < 0) { + MMI_HILOGD("EventType:%{private}s", event->eventType.c_str()); + int32_t subscribeId = -1; + subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, + [keyOption](std::shared_ptr keyEvent) { + std::string keyOptionKey = GenerateKeyOptionKey(keyOption); + SubKeyEventCallback(keyEvent, keyOptionKey); + }); + if (subscribeId < 0) { + MMI_HILOGE("SubscribeId invalid:%{public}d", subscribeId); + return; + } + MMI_HILOGD("SubscribeId:%{public}d", subscribeId); + event->subscribeId = subscribeId; + } else { + event->subscribeId = preSubscribeId; + } + if (AddEventKeyCallback(keyCallbacks, event, f, opq) != RET_OK) { + MMI_HILOGE("AddEventKeyCallback failed"); + taihe::set_business_error(COMMON_PARAMETER_ERROR, "AddEventKeyCallback failed"); + } +} + +void UnsubscribeKey(KeyOptions const& keyOptions, optional_view opq) +{ + CALL_DEBUG_ENTER; + std::shared_ptr event = std::make_shared(); + CHKPV(event); + auto keyOption = std::make_shared(); + CHKPV(keyOption); + int32_t subscribeId = -1; + if (GetEventInfoAPI9(keyOptions, event, keyOption) != RET_OK) { + MMI_HILOGE("GetEventInfoAPI9 failed"); + return; + } + if (DelEventCallback(keyCallbacks, event, opq, subscribeId) < 0) { + MMI_HILOGE("DelEventCallback failed"); + return; + } + MMI_HILOGI("Unsubscribe key event(%{public}d)", subscribeId); + InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId); +} + +void onKey(KeyOptions const& keyOptions, callback_view f, uintptr_t opq) +{ + SubscribeKey(keyOptions, f, opq); +} + +void offKey(KeyOptions const& keyOptions, optional_view opq) +{ + UnsubscribeKey(keyOptions, opq); +} + +void onHotkeyChange(HotkeyOptions const& hotkeyOptions, callback_view f, uintptr_t opq) +{ + SubscribeHotkey(hotkeyOptions, f, opq); +} + +void offHotkeyChange(HotkeyOptions const& hotkeyOptions, optional_view opq) +{ + UnsubscribeHotkey(hotkeyOptions, opq); +} + +void onKeyPressed(KeyPressedConfig const& options, + callback_view f, uintptr_t opq) +{ + SubscribeKeyMonitor(options, f, opq); +} + +void offKeyPressed(optional_view opq) +{ + if (opq.has_value()) { + MMI_HILOGI("[ETS] Unsubscribe key monitor"); + UnsubscribeKeyMonitor(opq); + } else { + UnsubscribeKeyMonitors(); + } +} +} // namespace + +// Since these macros are auto-generate, lint will cause false positive. +// NOLINTBEGIN +TH_EXPORT_CPP_API_onKey(onKey); +TH_EXPORT_CPP_API_offKey(offKey); +TH_EXPORT_CPP_API_onHotkeyChange(onHotkeyChange); +TH_EXPORT_CPP_API_offHotkeyChange(offHotkeyChange); +TH_EXPORT_CPP_API_onKeyPressed(onKeyPressed); +TH_EXPORT_CPP_API_offKeyPressed(offKeyPressed); +// NOLINTEND \ No newline at end of file diff --git a/frameworks/ets/input_device/BUILD.gn b/frameworks/ets/input_device/BUILD.gn new file mode 100644 index 0000000000..2992e60576 --- /dev/null +++ b/frameworks/ets/input_device/BUILD.gn @@ -0,0 +1,91 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/components/ets_frontend/ets2abc_config.gni") +import("//build/ohos.gni") +import("//build/ohos/taihe_idl/taihe.gni") +import("//foundation/multimodalinput/input/multimodalinput_mini.gni") +copy_taihe_idl("input_device_taihe") { + sources = [ "idl/ohos.multimodalInput.inputDevice.taihe" ] +} +config("inputDevice_config") { + visibility = [ ":*" ] + + include_dirs = [ + "${mmi_path}/util/common/include", + "${mmi_path}/util/network/include", + "${mmi_path}/frameworks/proxy/event_handler/include", + "${mmi_path}/frameworks/proxy/moudle_loader/include", + ] +} +subsystem_name = "multimodalinput" +part_name = "input" +taihe_generated_file_path_inputDevice = "$taihe_file_path/out/$subsystem_name/$part_name/inputDevice" +ohos_taihe("run_taihe") { + taihe_generated_file_path = "${taihe_generated_file_path_inputDevice}" + deps = [ ":input_device_taihe" ] + outputs = [ + "$taihe_generated_file_path/src/ohos.multimodalInput.inputDevice.ani.cpp", + "$taihe_generated_file_path/src/ohos.multimodalInput.inputDevice.abi.c", + ] +} +taihe_shared_library("InputDevice") { + taihe_generated_file_path = "${taihe_generated_file_path_inputDevice}" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + sources = get_target_outputs(":run_taihe") + configs = [ + "${mmi_path}:coverage_flags", + ":inputDevice_config", + ] + sources += [ + "src/ani_constructor.cpp", + "src/ohos.multimodalInput.inputDevice.impl.cpp", + ] + deps = [ + ":run_taihe", + "${mmi_path}/frameworks/proxy:libmmi-client", + "${mmi_path}/util:libmmi-util", + ] + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + ] + branch_protector_ret = "pac_ret" + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } +} +generate_static_abc("input_device") { + base_url = "${taihe_generated_file_path_inputDevice}" + files = [ "${taihe_generated_file_path_inputDevice}/@ohos.multimodalInput.inputDevice.ets" ] + is_boot_abc = "True" + device_dst_file = "/system/framework/input_device.abc" + dependencies = [ ":run_taihe" ] +} +ohos_prebuilt_etc("input_device_etc") { + source = "$target_out_dir/input_device.abc" + module_install_dir = "framework" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + deps = [ ":input_device" ] +} +group("ets_inputDevice_package") { + deps = [ + ":input_device_etc", + ":InputDevice", + ] +} \ No newline at end of file diff --git a/frameworks/ets/input_device/idl/ohos.multimodalInput.inputDevice.taihe b/frameworks/ets/input_device/idl/ohos.multimodalInput.inputDevice.taihe new file mode 100644 index 0000000000..9ba237e076 --- /dev/null +++ b/frameworks/ets/input_device/idl/ohos.multimodalInput.inputDevice.taihe @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@!namespace("@ohos.multimodalInput.inputDevice", "inputDevice") +@!sts_inject(""" +static { loadLibrary("InputDevice.z") } +""") + +enum changedType: String { + ADD = "add", + REMOVE = "remove" +} +union ChangedType { + type : changedType; +} + +enum sourceType : String { + KEYBOARD = "keyboard", + MOUSE = "mouse", + TOUCHPAD = "touchpad", + TOUCHSCREEN = "touchscreen", + JOYSTICK = "joystick", + TRACKBALL = "trackball" +} +union SourceType { + type : sourceType; +} + +enum axisType: String { + TOUCHMAJOR = "touchmajor", + TOUCHMINOR = "touchminor", + ORIENTATION = "orientation", + X = "x", + Y = "y", + PRESSURE = "pressure", + TOOLMINOR = "toolminor", + TOOLMAJOR = "toolmajor", + AXIS_NULL = "null" +} +union AxisType { + type : axisType; +} + +enum KeyboardType : i32 { + NONE = 0, + UNKNOWN = 1, + ALPHABETIC_KEYBOARD = 2, + DIGITAL_KEYBOARD = 3, + HANDWRITING_PEN = 4, + REMOTE_CONTROL = 5, + MAX = 6 +} + +enum FunctionKey : i32 { + CAPS_LOCK = 1 +} + +struct DeviceListener { + type: ChangedType; + deviceId: i32; +} + +struct AxisRange { + source: SourceType; + axis: AxisType; + max: i32; + min: i32; + fuzz: i32; + flat: i32; + resolution: i32; +} + +struct InputDeviceData { + id: i32; + name: String; + sources: Array; + axisRanges: Array; + bus: i32; + product: i32; + vendor: i32; + version: i32; + phys: String; + uniq: String; +} \ No newline at end of file diff --git a/frameworks/ets/input_device/src/ani_constructor.cpp b/frameworks/ets/input_device/src/ani_constructor.cpp new file mode 100644 index 0000000000..e9dc0cb7fc --- /dev/null +++ b/frameworks/ets/input_device/src/ani_constructor.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ohos.multimodalInput.inputDevice.ani.hpp" + +ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) +{ + ani_env *env; + if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) { + return ANI_ERROR; + } + if (ANI_OK != ohos::multimodalInput::inputDevice::ANIRegister(env)) { + std::cerr << "Error from ohos::multimodalInput::inputDevice::ANIRegister" << std::endl; + return ANI_ERROR; + } + *result = ANI_VERSION_1; + return ANI_OK; +} \ No newline at end of file diff --git a/frameworks/ets/input_device/src/ohos.multimodalInput.inputDevice.impl.cpp b/frameworks/ets/input_device/src/ohos.multimodalInput.inputDevice.impl.cpp new file mode 100644 index 0000000000..7abfd2b660 --- /dev/null +++ b/frameworks/ets/input_device/src/ohos.multimodalInput.inputDevice.impl.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ohos.multimodalInput.inputDevice.proj.hpp" +#include "ohos.multimodalInput.inputDevice.impl.hpp" +#include "taihe/runtime.hpp" +#include "stdexcept" + +using namespace taihe; +using namespace ohos::multimodalInput::inputDevice; + +namespace { +} // namespace + +// Since these macros are auto-generate, lint will cause false positive. +// NOLINTBEGIN +// NOLINTEND \ No newline at end of file diff --git a/frameworks/ets/input_event/BUILD.gn b/frameworks/ets/input_event/BUILD.gn new file mode 100644 index 0000000000..d5452f765d --- /dev/null +++ b/frameworks/ets/input_event/BUILD.gn @@ -0,0 +1,48 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/components/ets_frontend/ets2abc_config.gni") +import("//build/ohos.gni") +import("//build/ohos/taihe_idl/taihe.gni") +import("//foundation/multimodalinput/input/multimodalinput_mini.gni") +copy_taihe_idl("input_event_taihe") { + sources = [ "idl/ohos.multimodalInput.inputEvent.taihe" ] +} +subsystem_name = "multimodalinput" +part_name = "input" +taihe_generated_file_path_inputEvent = "$taihe_file_path/out/$subsystem_name/$part_name/inputEvent" +ohos_taihe("run_taihe") { + taihe_generated_file_path = "${taihe_generated_file_path_inputEvent}" + deps = [ ":input_event_taihe" ] + outputs = [ + "$taihe_generated_file_path/src/ohos.multimodalInput.inputEvent.ani.cpp", + "$taihe_generated_file_path/src/ohos.multimodalInput.inputEvent.abi.c", + ] +} +generate_static_abc("input_event") { + base_url = "${taihe_generated_file_path_inputEvent}" + files = [ "${taihe_generated_file_path_inputEvent}/@ohos.multimodalInput.inputEvent.ets" ] + is_boot_abc = "True" + device_dst_file = "/system/framework/input_event.abc" + dependencies = [ ":run_taihe" ] +} +ohos_prebuilt_etc("input_event_etc") { + source = "$target_out_dir/input_event.abc" + module_install_dir = "framework" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + deps = [ ":input_event" ] +} +group("ets_inputEvent_package") { + deps = [ + ":input_event_etc", + ] +} \ No newline at end of file diff --git a/frameworks/ets/input_event/idl/ohos.multimodalInput.inputEvent.taihe b/frameworks/ets/input_event/idl/ohos.multimodalInput.inputEvent.taihe new file mode 100644 index 0000000000..29ffa17523 --- /dev/null +++ b/frameworks/ets/input_event/idl/ohos.multimodalInput.inputEvent.taihe @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@!namespace("@ohos.multimodalInput.inputEvent") + +struct InputEvent { + id: i32; + deviceId: i32; + actionTime: i64; + screenId: i32; + windowId: i32; +} \ No newline at end of file diff --git a/frameworks/ets/input_event/src/ani_constructor.cpp b/frameworks/ets/input_event/src/ani_constructor.cpp new file mode 100644 index 0000000000..39e9cd1ceb --- /dev/null +++ b/frameworks/ets/input_event/src/ani_constructor.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ohos.multimodalInput.inputEvent.ani.hpp" +ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) +{ + ani_env *env; + if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) { + return ANI_ERROR; + } + if (ANI_OK != ohos::multimodalInput::inputEvent::ANIRegister(env)) { + std::cerr << "Error from ohos::multimodalInput::inputEvent::ANIRegister" << std::endl; + return ANI_ERROR; + } + *result = ANI_VERSION_1; + return ANI_OK; +} \ No newline at end of file diff --git a/frameworks/ets/input_event/src/ohos.multimodalInput.inputEvent.impl.cpp b/frameworks/ets/input_event/src/ohos.multimodalInput.inputEvent.impl.cpp new file mode 100644 index 0000000000..8d66c31abb --- /dev/null +++ b/frameworks/ets/input_event/src/ohos.multimodalInput.inputEvent.impl.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ohos.multimodalInput.inputEvent.proj.hpp" +#include "ohos.multimodalInput.inputEvent.impl.hpp" +#include "taihe/runtime.hpp" +#include "stdexcept" + +using namespace taihe; +using namespace ohos::multimodalInput::inputEvent; + +namespace { +} // namespace + +// Since these macros are auto-generate, lint will cause false positive. +// NOLINTBEGIN +// NOLINTEND \ No newline at end of file diff --git a/frameworks/ets/input_event_client/BUILD.gn b/frameworks/ets/input_event_client/BUILD.gn new file mode 100644 index 0000000000..d7cca9bf15 --- /dev/null +++ b/frameworks/ets/input_event_client/BUILD.gn @@ -0,0 +1,92 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/components/ets_frontend/ets2abc_config.gni") +import("//build/ohos.gni") +import("//build/ohos/taihe_idl/taihe.gni") +import("//foundation/multimodalinput/input/multimodalinput_mini.gni") +copy_taihe_idl("input_event_client_taihe") { + sources = [ "idl/ohos.multimodalInput.inputEventClient.taihe" ] + deps = [ "${mmi_path}/frameworks/ets/touch_event:touch_event_taihe" ] +} +config("inputEventClient_config") { + visibility = [ ":*" ] + + include_dirs = [ + "${mmi_path}/util/common/include", + "${mmi_path}/tools/event_inject/include", + "${mmi_path}/interfaces/kits/c/input", + "${mmi_path}/interfaces/native/innerkits/proxy/include", + ] +} +subsystem_name = "multimodalinput" +part_name = "input" +taihe_generated_file_path_inputEventClient = "$taihe_file_path/out/$subsystem_name/$part_name/inputEventClient" +ohos_taihe("run_taihe") { + taihe_generated_file_path = "${taihe_generated_file_path_inputEventClient}" + deps = [ ":input_event_client_taihe" ] + outputs = [ + "$taihe_generated_file_path/src/ohos.multimodalInput.inputEventClient.ani.cpp", + "$taihe_generated_file_path/src/ohos.multimodalInput.inputEventClient.abi.c", + ] +} +taihe_shared_library("InputEventClient") { + taihe_generated_file_path = "${taihe_generated_file_path_inputEventClient}" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + sources = get_target_outputs(":run_taihe") + configs = [ + "${mmi_path}:coverage_flags", + ":inputEventClient_config", + ] + sources += [ + "src/ani_constructor.cpp", + "src/ohos.multimodalInput.inputEventClient.impl.cpp", + ] + deps = [ + ":run_taihe", + "${mmi_path}/frameworks/proxy:libmmi-client", + "${mmi_path}/util:libmmi-util", + ] + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + ] + branch_protector_ret = "pac_ret" + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } +} +generate_static_abc("input_event_client") { + base_url = "${taihe_generated_file_path_inputEventClient}" + files = [ "${taihe_generated_file_path_inputEventClient}/@ohos.multimodalInput.inputEventClient.ets" ] + is_boot_abc = "True" + device_dst_file = "/system/framework/input_event_client.abc" + dependencies = [ ":run_taihe" ] +} +ohos_prebuilt_etc("input_event_client_etc") { + source = "$target_out_dir/input_event_client.abc" + module_install_dir = "framework" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + deps = [ ":input_event_client" ] +} +group("ets_inputEventClient_package") { + deps = [ + ":input_event_client_etc", + ":InputEventClient", + ] +} \ No newline at end of file diff --git a/frameworks/ets/input_event_client/idl/ohos.multimodalInput.inputEventClient.taihe b/frameworks/ets/input_event_client/idl/ohos.multimodalInput.inputEventClient.taihe new file mode 100644 index 0000000000..495a7e7bec --- /dev/null +++ b/frameworks/ets/input_event_client/idl/ohos.multimodalInput.inputEventClient.taihe @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@!namespace("@ohos.multimodalInput.inputEventClient", "inputEventClient") +from ohos.multimodalInput.touchEvent use TouchEvent; +@!sts_inject(""" +static { loadLibrary("InputEventClient.z") } +""") + +struct TouchEventData { + touchEvent: TouchEvent; +} diff --git a/frameworks/ets/input_event_client/src/ani_constructor.cpp b/frameworks/ets/input_event_client/src/ani_constructor.cpp new file mode 100644 index 0000000000..bfd603e00a --- /dev/null +++ b/frameworks/ets/input_event_client/src/ani_constructor.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ohos.multimodalInput.inputEventClient.ani.hpp" + +ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) +{ + ani_env *env; + if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) { + return ANI_ERROR; + } + if (ANI_OK != ohos::multimodalInput::inputEventClient::ANIRegister(env)) { + std::cerr << "Error from ohos::multimodalInput::inputEventClient::ANIRegister" << std::endl; + return ANI_ERROR; + } + *result = ANI_VERSION_1; + return ANI_OK; +} \ No newline at end of file diff --git a/frameworks/ets/input_event_client/src/ohos.multimodalInput.inputEventClient.impl.cpp b/frameworks/ets/input_event_client/src/ohos.multimodalInput.inputEventClient.impl.cpp new file mode 100644 index 0000000000..43b394ed24 --- /dev/null +++ b/frameworks/ets/input_event_client/src/ohos.multimodalInput.inputEventClient.impl.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ohos.multimodalInput.inputEventClient.proj.hpp" +#include "ohos.multimodalInput.inputEventClient.impl.hpp" +#include "taihe/runtime.hpp" +#include "stdexcept" + +using namespace taihe; +using namespace ohos::multimodalInput::inputEventClient; + +namespace { +} // namespace + +// Since these macros are auto-generate, lint will cause false positive. +// NOLINTBEGIN +// NOLINTEND \ No newline at end of file diff --git a/frameworks/ets/input_monitor/BUILD.gn b/frameworks/ets/input_monitor/BUILD.gn new file mode 100644 index 0000000000..884d730897 --- /dev/null +++ b/frameworks/ets/input_monitor/BUILD.gn @@ -0,0 +1,94 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/components/ets_frontend/ets2abc_config.gni") +import("//build/ohos.gni") +import("//build/ohos/taihe_idl/taihe.gni") +import("//foundation/multimodalinput/input/multimodalinput_mini.gni") +copy_taihe_idl("input_monitor_taihe") { + sources = [ "idl/ohos.multimodalInput.inputMonitor.taihe" ] + deps = [ + "${mmi_path}/frameworks/ets/mouse_event:mouse_event_taihe", + "${mmi_path}/frameworks/ets/touch_event:touch_event_taihe", + ] +} +config("inputMonitor_config") { + visibility = [ ":*" ] + + include_dirs = [ + "${mmi_path}/interfaces/native/innerkits/proxy/include", + "${mmi_path}/service/permission_helper/include", + "${mmi_path}/util/common/include", + ] +} +subsystem_name = "multimodalinput" +part_name = "input" +taihe_generated_file_path_inputMonitor = "$taihe_file_path/out/$subsystem_name/$part_name/inputMonitor" +ohos_taihe("run_taihe") { + taihe_generated_file_path = "${taihe_generated_file_path_inputMonitor}" + deps = [ ":input_monitor_taihe" ] + outputs = [ + "$taihe_generated_file_path/src/ohos.multimodalInput.inputMonitor.ani.cpp", + "$taihe_generated_file_path/src/ohos.multimodalInput.inputMonitor.abi.c", + ] +} +taihe_shared_library("InputMonitor") { + taihe_generated_file_path = "${taihe_generated_file_path_inputMonitor}" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + sources = get_target_outputs(":run_taihe") + configs = [ + "${mmi_path}:coverage_flags", + ":inputMonitor_config", + ] + sources += [ + "src/ani_constructor.cpp", + "src/ohos.multimodalInput.inputMonitor.impl.cpp", + ] + deps = [ + ":run_taihe", + "${mmi_path}/frameworks/proxy:libmmi-client", + "${mmi_path}/util:libmmi-util", + ] + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + ] + branch_protector_ret = "pac_ret" + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } +} +generate_static_abc("input_monitor") { + base_url = "${taihe_generated_file_path_inputMonitor}" + files = [ "${taihe_generated_file_path_inputMonitor}/@ohos.multimodalInput.inputMonitor.ets" ] + is_boot_abc = "True" + device_dst_file = "/system/framework/input_monitor.abc" + dependencies = [ ":run_taihe" ] +} +ohos_prebuilt_etc("input_monitor_etc") { + source = "$target_out_dir/input_monitor.abc" + module_install_dir = "framework" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + deps = [ ":input_monitor" ] +} +group("ets_inputMonitor_package") { + deps = [ + ":input_monitor_etc", + ":InputMonitor", + ] +}1111 \ No newline at end of file diff --git a/frameworks/ets/input_monitor/idl/ohos.multimodalInput.inputMonitor.taihe b/frameworks/ets/input_monitor/idl/ohos.multimodalInput.inputMonitor.taihe new file mode 100644 index 0000000000..b99983d27f --- /dev/null +++ b/frameworks/ets/input_monitor/idl/ohos.multimodalInput.inputMonitor.taihe @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@!namespace("@ohos.multimodalInput.inputMonitor", "inputMonitor") +from ohos.multimodalInput.touchEvent use TouchEvent; +from ohos.multimodalInput.mouseEvent use MouseEvent; +@!sts_inject(""" +static { loadLibrary("InputMonitor.z") } +""") + +struct TouchEventReceiver { + filter: (touchEvent: TouchEvent) => bool; +} \ No newline at end of file diff --git a/frameworks/ets/input_monitor/src/ani_constructor.cpp b/frameworks/ets/input_monitor/src/ani_constructor.cpp new file mode 100644 index 0000000000..632c0caf23 --- /dev/null +++ b/frameworks/ets/input_monitor/src/ani_constructor.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ohos.multimodalInput.inputMonitor.ani.hpp" + +ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) +{ + ani_env *env; + if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) { + return ANI_ERROR; + } + if (ANI_OK != ohos::multimodalInput::inputMonitor::ANIRegister(env)) { + std::cerr << "Error from ohos::multimodalInput::inputMonitor::ANIRegister" << std::endl; + return ANI_ERROR; + } + *result = ANI_VERSION_1; + return ANI_OK; +} \ No newline at end of file diff --git a/frameworks/ets/input_monitor/src/ohos.multimodalInput.inputMonitor.impl.cpp b/frameworks/ets/input_monitor/src/ohos.multimodalInput.inputMonitor.impl.cpp new file mode 100644 index 0000000000..da8107822f --- /dev/null +++ b/frameworks/ets/input_monitor/src/ohos.multimodalInput.inputMonitor.impl.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ohos.multimodalInput.inputMonitor.proj.hpp" +#include "ohos.multimodalInput.inputMonitor.impl.hpp" +#include "taihe/runtime.hpp" +#include "stdexcept" + +using namespace taihe; +using namespace ohos::multimodalInput::inputMonitor; + +namespace { +} // namespace + +// Since these macros are auto-generate, lint will cause false positive. +// NOLINTBEGIN +// NOLINTEND \ No newline at end of file diff --git a/frameworks/ets/intention_code/BUILD.gn b/frameworks/ets/intention_code/BUILD.gn new file mode 100644 index 0000000000..97a5ef2a30 --- /dev/null +++ b/frameworks/ets/intention_code/BUILD.gn @@ -0,0 +1,89 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/components/ets_frontend/ets2abc_config.gni") +import("//build/ohos.gni") +import("//build/ohos/taihe_idl/taihe.gni") +import("//foundation/multimodalinput/input/multimodalinput_mini.gni") +copy_taihe_idl("intention_code_taihe") { + sources = [ "idl/ohos.multimodalInput.intentionCode.taihe" ] +} +config("intentionCode_config") { + visibility = [ ":*" ] + + include_dirs = [ + "${mmi_path}/util/common/include", + "${mmi_path}/util/network/include", + ] +} +subsystem_name = "multimodalinput" +part_name = "input" +taihe_generated_file_path_intentionCode = "$taihe_file_path/out/$subsystem_name/$part_name/intentionCode" +ohos_taihe("run_taihe") { + taihe_generated_file_path = "${taihe_generated_file_path_intentionCode}" + deps = [ ":intention_code_taihe" ] + outputs = [ + "$taihe_generated_file_path/src/ohos.multimodalInput.intentionCode.ani.cpp", + "$taihe_generated_file_path/src/ohos.multimodalInput.intentionCode.abi.c", + ] +} +taihe_shared_library("IntentionCode") { + taihe_generated_file_path = "${taihe_generated_file_path_intentionCode}" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + sources = get_target_outputs(":run_taihe") + configs = [ + "${mmi_path}:coverage_flags", + ":intentionCode_config", + ] + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + ] + sources += [ + "src/ani_constructor.cpp", + "src/ohos.multimodalInput.intentionCode.impl.cpp", + ] + deps = [ + ":run_taihe", + "${mmi_path}/frameworks/proxy:libmmi-client", + "${mmi_path}/util:libmmi-util", + ] + branch_protector_ret = "pac_ret" + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } +} +generate_static_abc("intention_code") { + base_url = "${taihe_generated_file_path_intentionCode}" + files = [ "${taihe_generated_file_path_intentionCode}/@ohos.multimodalInput.intentionCode.ets" ] + is_boot_abc = "True" + device_dst_file = "/system/framework/intention_code.abc" + dependencies = [ ":run_taihe" ] +} +ohos_prebuilt_etc("intention_code_etc") { + source = "$target_out_dir/intention_code.abc" + module_install_dir = "framework" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + deps = [ ":intention_code" ] +} +group("ets_intentionCode_package") { + deps = [ + ":intention_code_etc", + ":IntentionCode", + ] +} \ No newline at end of file diff --git a/frameworks/ets/intention_code/idl/ohos.multimodalInput.intentionCode.taihe b/frameworks/ets/intention_code/idl/ohos.multimodalInput.intentionCode.taihe new file mode 100644 index 0000000000..ad64a072d2 --- /dev/null +++ b/frameworks/ets/intention_code/idl/ohos.multimodalInput.intentionCode.taihe @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@!namespace("@ohos.multimodalInput.intentionCode") +@!sts_inject(""" + loadLibrary("IntentionCode.z") +""") + +enum IntentionCode : i32 { + INTENTION_UNKNOWN = -1, + INTENTION_UP = 1, + INTENTION_DOWN = 2, + INTENTION_LEFT = 3, + INTENTION_RIGHT = 4, + INTENTION_SELECT = 5, + INTENTION_ESCAPE = 6, + INTENTION_BACK = 7, + INTENTION_FORWARD = 8, + INTENTION_MENU = 9, + INTENTION_PAGE_UP = 11, + INTENTION_PAGE_DOWN = 12, + INTENTION_ZOOM_OUT = 13, + INTENTION_ZOOM_IN = 14 +} \ No newline at end of file diff --git a/frameworks/ets/intention_code/src/ani_constructor.cpp b/frameworks/ets/intention_code/src/ani_constructor.cpp new file mode 100644 index 0000000000..45f23be42b --- /dev/null +++ b/frameworks/ets/intention_code/src/ani_constructor.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ohos.multimodalInput.intentionCode.ani.hpp" +ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) +{ + ani_env *env; + if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) { + return ANI_ERROR; + } + if (ANI_OK != ohos::multimodalInput::intentionCode::ANIRegister(env)) { + std::cerr << "Error from ohos::multimodalInput::intentionCode::ANIRegister" << std::endl; + return ANI_ERROR; + } + *result = ANI_VERSION_1; + return ANI_OK; +} \ No newline at end of file diff --git a/frameworks/ets/intention_code/src/ohos.multimodalInput.intentionCode.impl.cpp b/frameworks/ets/intention_code/src/ohos.multimodalInput.intentionCode.impl.cpp new file mode 100644 index 0000000000..e9f3d9a7db --- /dev/null +++ b/frameworks/ets/intention_code/src/ohos.multimodalInput.intentionCode.impl.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ohos.multimodalInput.intentionCode.proj.hpp" +#include "ohos.multimodalInput.intentionCode.impl.hpp" +#include "taihe/runtime.hpp" +#include "stdexcept" + +using namespace taihe; +using namespace ohos::multimodalInput::intentionCode; + +namespace { +} // namespace + +// Since these macros are auto-generate, lint will cause false positive. +// NOLINTBEGIN +// NOLINTEND \ No newline at end of file diff --git a/frameworks/ani/input_consumer/BUILD.gn b/frameworks/ets/key_code/BUILD.gn similarity index 43% rename from frameworks/ani/input_consumer/BUILD.gn rename to frameworks/ets/key_code/BUILD.gn index ca555c3cea..5a5b656db0 100644 --- a/frameworks/ani/input_consumer/BUILD.gn +++ b/frameworks/ets/key_code/BUILD.gn @@ -2,9 +2,7 @@ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# +# http://www.apache.org/licenses/LICENSE-2.0 # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -13,26 +11,13 @@ import("//build/config/components/ets_frontend/ets2abc_config.gni") import("//build/ohos.gni") -import("../../../multimodalinput_mini.gni") - -ohos_shared_library("input_consumer") { - branch_protector_ret = "pac_ret" - sanitize = { - integer_overflow = true - ubsan = true - boundary_sanitize = true - cfi = true - cfi_cross_dso = true - debug = false - } - - configs = [ "${mmi_path}:coverage_flags" ] - - cflags_cc = [ - "-Wno-unused-function", - "-Wno-unused-const-variable", - ] - sources = [ "src/input_consumer.cpp" ] +import("//build/ohos/taihe_idl/taihe.gni") +import("//foundation/multimodalinput/input/multimodalinput_mini.gni") +copy_taihe_idl("key_code_taihe") { + sources = [ "idl/ohos.multimodalInput.keyCode.taihe" ] +} +config("keyCode_config") { + visibility = [ ":*" ] include_dirs = [ "include", @@ -40,45 +25,67 @@ ohos_shared_library("input_consumer") { "${mmi_path}/tools/event_inject/include", "${mmi_path}/interfaces/native/innerkits/proxy/include", ] - +} +subsystem_name = "multimodalinput" +part_name = "input" +taihe_generated_file_path_keyCode = "$taihe_file_path/out/$subsystem_name/$part_name/keyCode" +ohos_taihe("run_taihe") { + taihe_generated_file_path = "${taihe_generated_file_path_keyCode}" + deps = [ ":key_code_taihe" ] + outputs = [ + "$taihe_generated_file_path/src/ohos.multimodalInput.keyCode.ani.cpp", + "$taihe_generated_file_path/src/ohos.multimodalInput.keyCode.abi.c", + ] +} +taihe_shared_library("KeyCode") { + taihe_generated_file_path = "${taihe_generated_file_path_keyCode}" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + sources = get_target_outputs(":run_taihe") + configs = [ + "${mmi_path}:coverage_flags", + ":keyCode_config", + ] + sources += [ + "src/ani_constructor.cpp", + "src/ohos.multimodalInput.keyCode.impl.cpp", + ] deps = [ + ":run_taihe", "${mmi_path}/frameworks/proxy:libmmi-client", "${mmi_path}/util:libmmi-util", ] - external_deps = [ "c_utils:utils", - "eventhandler:libeventhandler", "hilog:libhilog", - "ipc:ipc_core", - "runtime_core:ani", ] - - subsystem_name = "multimodalinput" - part_name = "input" - output_extension = "so" + branch_protector_ret = "pac_ret" + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } } - -generate_static_abc("input_consumer_abc") { - base_url = "./ets" - files = [ "./ets/@ohos.multimodalInput.inputConsumer.ets" ] - dst_file = "$target_out_dir/input_consumer.abc" - out_puts = [ "$target_out_dir/input_consumer.abc" ] +generate_static_abc("key_code") { + base_url = "${taihe_generated_file_path_keyCode}" + files = [ "${taihe_generated_file_path_keyCode}/@ohos.multimodalInput.keyCode.ets" ] is_boot_abc = "True" - device_dst_file = "/system/framework/input_consumer.abc" + device_dst_file = "/system/framework/key_code.abc" + dependencies = [ ":run_taihe" ] } - -ohos_prebuilt_etc("input_consumer_abc_etc") { - source = "$target_out_dir/input_consumer.abc" +ohos_prebuilt_etc("key_code_etc") { + source = "$target_out_dir/key_code.abc" module_install_dir = "framework" - subsystem_name = "multimodalinput" - part_name = "input" - deps = [ ":input_consumer_abc" ] + part_name = "$part_name" + subsystem_name = "$subsystem_name" + deps = [ ":key_code" ] } - -group("input_consumer_package") { +group("ets_keyCode_package") { deps = [ - ":input_consumer", - ":input_consumer_abc_etc", + ":key_code_etc", + ":KeyCode", ] -} +} \ No newline at end of file diff --git a/frameworks/ets/key_code/idl/ohos.multimodalInput.keyCode.taihe b/frameworks/ets/key_code/idl/ohos.multimodalInput.keyCode.taihe new file mode 100644 index 0000000000..973dbd78ca --- /dev/null +++ b/frameworks/ets/key_code/idl/ohos.multimodalInput.keyCode.taihe @@ -0,0 +1,369 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@!namespace("@ohos.multimodalInput.keyCode") +@!sts_inject(""" + loadLibrary("KeyCode.z") +""") + +enum KeyCode : i32 { + KEYCODE_FN = 0, + KEYCODE_UNKNOWN = -1, + KEYCODE_HOME = 1, + KEYCODE_BACK = 2, + KEYCODE_SEARCH = 9, + KEYCODE_MEDIA_PLAY_PAUSE = 10, + KEYCODE_MEDIA_STOP = 11, + KEYCODE_MEDIA_NEXT = 12, + KEYCODE_MEDIA_PREVIOUS = 13, + KEYCODE_MEDIA_REWIND = 14, + KEYCODE_MEDIA_FAST_FORWARD = 15, + KEYCODE_VOLUME_UP = 16, + KEYCODE_VOLUME_DOWN = 17, + KEYCODE_POWER = 18, + KEYCODE_CAMERA = 19, + KEYCODE_VOLUME_MUTE = 22, + KEYCODE_MUTE = 23, + KEYCODE_BRIGHTNESS_UP = 40, + KEYCODE_BRIGHTNESS_DOWN = 41, + KEYCODE_0 = 2000, + KEYCODE_1 = 2001, + KEYCODE_2 = 2002, + KEYCODE_3 = 2003, + KEYCODE_4 = 2004, + KEYCODE_5 = 2005, + KEYCODE_6 = 2006, + KEYCODE_7 = 2007, + KEYCODE_8 = 2008, + KEYCODE_9 = 2009, + KEYCODE_STAR = 2010, + KEYCODE_POUND = 2011, + KEYCODE_DPAD_UP = 2012, + KEYCODE_DPAD_DOWN = 2013, + KEYCODE_DPAD_LEFT = 2014, + KEYCODE_DPAD_RIGHT = 2015, + KEYCODE_DPAD_CENTER = 2016, + KEYCODE_A = 2017, + KEYCODE_B = 2018, + KEYCODE_C = 2019, + KEYCODE_D = 2020, + KEYCODE_E = 2021, + KEYCODE_F = 2022, + KEYCODE_G = 2023, + KEYCODE_H = 2024, + KEYCODE_I = 2025, + KEYCODE_J = 2026, + KEYCODE_K = 2027, + KEYCODE_L = 2028, + KEYCODE_M = 2029, + KEYCODE_N = 2030, + KEYCODE_O = 2031, + KEYCODE_P = 2032, + KEYCODE_Q = 2033, + KEYCODE_R = 2034, + KEYCODE_S = 2035, + KEYCODE_T = 2036, + KEYCODE_U = 2037, + KEYCODE_V = 2038, + KEYCODE_W = 2039, + KEYCODE_X = 2040, + KEYCODE_Y = 2041, + KEYCODE_Z = 2042, + KEYCODE_COMMA = 2043, + KEYCODE_PERIOD = 2044, + KEYCODE_ALT_LEFT = 2045, + KEYCODE_ALT_RIGHT = 2046, + KEYCODE_SHIFT_LEFT = 2047, + KEYCODE_SHIFT_RIGHT = 2048, + KEYCODE_TAB = 2049, + KEYCODE_SPACE = 2050, + KEYCODE_SYM = 2051, + KEYCODE_EXPLORER = 2052, + KEYCODE_ENVELOPE = 2053, + KEYCODE_ENTER = 2054, + KEYCODE_DEL = 2055, + KEYCODE_GRAVE = 2056, + KEYCODE_MINUS = 2057, + KEYCODE_EQUALS = 2058, + KEYCODE_LEFT_BRACKET = 2059, + KEYCODE_RIGHT_BRACKET = 2060, + KEYCODE_BACKSLASH = 2061, + KEYCODE_SEMICOLON = 2062, + KEYCODE_APOSTROPHE = 2063, + KEYCODE_SLASH = 2064, + KEYCODE_AT = 2065, + KEYCODE_PLUS = 2066, + KEYCODE_MENU = 2067, + KEYCODE_PAGE_UP = 2068, + KEYCODE_PAGE_DOWN = 2069, + KEYCODE_ESCAPE = 2070, + KEYCODE_FORWARD_DEL = 2071, + KEYCODE_CTRL_LEFT = 2072, + KEYCODE_CTRL_RIGHT = 2073, + KEYCODE_CAPS_LOCK = 2074, + KEYCODE_SCROLL_LOCK = 2075, + KEYCODE_META_LEFT = 2076, + KEYCODE_META_RIGHT = 2077, + KEYCODE_FUNCTION = 2078, + KEYCODE_SYSRQ = 2079, + KEYCODE_BREAK = 2080, + KEYCODE_MOVE_HOME = 2081, + KEYCODE_MOVE_END = 2082, + KEYCODE_INSERT = 2083, + KEYCODE_FORWARD = 2084, + KEYCODE_MEDIA_PLAY = 2085, + KEYCODE_MEDIA_PAUSE = 2086, + KEYCODE_MEDIA_CLOSE = 2087, + KEYCODE_MEDIA_EJECT = 2088, + KEYCODE_MEDIA_RECORD = 2089, + KEYCODE_F1 = 2090, + KEYCODE_F2 = 2091, + KEYCODE_F3 = 2092, + KEYCODE_F4 = 2093, + KEYCODE_F5 = 2094, + KEYCODE_F6 = 2095, + KEYCODE_F7 = 2096, + KEYCODE_F8 = 2097, + KEYCODE_F9 = 2098, + KEYCODE_F10 = 2099, + KEYCODE_F11 = 2100, + KEYCODE_F12 = 2101, + KEYCODE_NUM_LOCK = 2102, + KEYCODE_NUMPAD_0 = 2103, + KEYCODE_NUMPAD_1 = 2104, + KEYCODE_NUMPAD_2 = 2105, + KEYCODE_NUMPAD_3 = 2106, + KEYCODE_NUMPAD_4 = 2107, + KEYCODE_NUMPAD_5 = 2108, + KEYCODE_NUMPAD_6 = 2109, + KEYCODE_NUMPAD_7 = 2110, + KEYCODE_NUMPAD_8 = 2111, + KEYCODE_NUMPAD_9 = 2112, + KEYCODE_NUMPAD_DIVIDE = 2113, + KEYCODE_NUMPAD_MULTIPLY = 2114, + KEYCODE_NUMPAD_SUBTRACT = 2115, + KEYCODE_NUMPAD_ADD = 2116, + KEYCODE_NUMPAD_DOT = 2117, + KEYCODE_NUMPAD_COMMA = 2118, + KEYCODE_NUMPAD_ENTER = 2119, + KEYCODE_NUMPAD_EQUALS = 2120, + KEYCODE_NUMPAD_LEFT_PAREN = 2121, + KEYCODE_NUMPAD_RIGHT_PAREN = 2122, + KEYCODE_VIRTUAL_MULTITASK = 2210, + KEYCODE_BUTTON_A = 2301, + KEYCODE_BUTTON_B = 2302, + KEYCODE_BUTTON_X = 2304, + KEYCODE_BUTTON_Y = 2305, + KEYCODE_BUTTON_L1 = 2307, + KEYCODE_BUTTON_R1 = 2308, + KEYCODE_BUTTON_L2 = 2309, + KEYCODE_BUTTON_R2 = 2310, + KEYCODE_BUTTON_SELECT = 2311, + KEYCODE_BUTTON_START = 2312, + KEYCODE_BUTTON_MODE = 2313, + KEYCODE_BUTTON_THUMBL = 2314, + KEYCODE_BUTTON_THUMBR = 2315, + KEYCODE_SLEEP = 2600, + KEYCODE_ZENKAKU_HANKAKU = 2601, + KEYCODE_102ND = 2602, + KEYCODE_RO = 2603, + KEYCODE_KATAKANA = 2604, + KEYCODE_HIRAGANA = 2605, + KEYCODE_HENKAN = 2606, + KEYCODE_KATAKANA_HIRAGANA = 2607, + KEYCODE_MUHENKAN = 2608, + KEYCODE_LINEFEED = 2609, + KEYCODE_MACRO = 2610, + KEYCODE_NUMPAD_PLUSMINUS = 2611, + KEYCODE_SCALE = 2612, + KEYCODE_HANGUEL = 2613, + KEYCODE_HANJA = 2614, + KEYCODE_YEN = 2615, + KEYCODE_STOP = 2616, + KEYCODE_AGAIN = 2617, + KEYCODE_PROPS = 2618, + KEYCODE_UNDO = 2619, + KEYCODE_COPY = 2620, + KEYCODE_OPEN = 2621, + KEYCODE_PASTE = 2622, + KEYCODE_FIND = 2623, + KEYCODE_CUT = 2624, + KEYCODE_HELP = 2625, + KEYCODE_CALC = 2626, + KEYCODE_FILE = 2627, + KEYCODE_BOOKMARKS = 2628, + KEYCODE_NEXT = 2629, + KEYCODE_PLAYPAUSE = 2630, + KEYCODE_PREVIOUS = 2631, + KEYCODE_STOPCD = 2632, + KEYCODE_CONFIG = 2634, + KEYCODE_REFRESH = 2635, + KEYCODE_EXIT = 2636, + KEYCODE_EDIT = 2637, + KEYCODE_SCROLLUP = 2638, + KEYCODE_SCROLLDOWN = 2639, + KEYCODE_NEW = 2640, + KEYCODE_REDO = 2641, + KEYCODE_CLOSE = 2642, + KEYCODE_PLAY = 2643, + KEYCODE_BASSBOOST = 2644, + KEYCODE_PRINT = 2645, + KEYCODE_CHAT = 2646, + KEYCODE_FINANCE = 2647, + KEYCODE_CANCEL = 2648, + KEYCODE_KBDILLUM_TOGGLE = 2649, + KEYCODE_KBDILLUM_DOWN = 2650, + KEYCODE_KBDILLUM_UP = 2651, + KEYCODE_SEND = 2652, + KEYCODE_REPLY = 2653, + KEYCODE_FORWARDMAIL = 2654, + KEYCODE_SAVE = 2655, + KEYCODE_DOCUMENTS = 2656, + KEYCODE_VIDEO_NEXT = 2657, + KEYCODE_VIDEO_PREV = 2658, + KEYCODE_BRIGHTNESS_CYCLE = 2659, + KEYCODE_BRIGHTNESS_ZERO = 2660, + KEYCODE_DISPLAY_OFF = 2661, + KEYCODE_BTN_MISC = 2662, + KEYCODE_GOTO = 2663, + KEYCODE_INFO = 2664, + KEYCODE_PROGRAM = 2665, + KEYCODE_PVR = 2666, + KEYCODE_SUBTITLE = 2667, + KEYCODE_FULL_SCREEN = 2668, + KEYCODE_KEYBOARD = 2669, + KEYCODE_ASPECT_RATIO = 2670, + KEYCODE_PC = 2671, + KEYCODE_TV = 2672, + KEYCODE_TV2 = 2673, + KEYCODE_VCR = 2674, + KEYCODE_VCR2 = 2675, + KEYCODE_SAT = 2676, + KEYCODE_CD = 2677, + KEYCODE_TAPE = 2678, + KEYCODE_TUNER = 2679, + KEYCODE_PLAYER = 2680, + KEYCODE_DVD = 2681, + KEYCODE_AUDIO = 2682, + KEYCODE_VIDEO = 2683, + KEYCODE_MEMO = 2684, + KEYCODE_CALENDAR = 2685, + KEYCODE_RED = 2686, + KEYCODE_GREEN = 2687, + KEYCODE_YELLOW = 2688, + KEYCODE_BLUE = 2689, + KEYCODE_CHANNELUP = 2690, + KEYCODE_CHANNELDOWN = 2691, + KEYCODE_LAST = 2692, + KEYCODE_RESTART = 2693, + KEYCODE_SLOW = 2694, + KEYCODE_SHUFFLE = 2695, + KEYCODE_VIDEOPHONE = 2696, + KEYCODE_GAMES = 2697, + KEYCODE_ZOOMIN = 2698, + KEYCODE_ZOOMOUT = 2699, + KEYCODE_ZOOMRESET = 2700, + KEYCODE_WORDPROCESSOR = 2701, + KEYCODE_EDITOR = 2702, + KEYCODE_SPREADSHEET = 2703, + KEYCODE_GRAPHICSEDITOR = 2704, + KEYCODE_PRESENTATION = 2705, + KEYCODE_DATABASE = 2706, + KEYCODE_NEWS = 2707, + KEYCODE_VOICEMAIL = 2708, + KEYCODE_ADDRESSBOOK = 2709, + KEYCODE_MESSENGER = 2710, + KEYCODE_BRIGHTNESS_TOGGLE = 2711, + KEYCODE_SPELLCHECK = 2712, + KEYCODE_COFFEE = 2713, + KEYCODE_MEDIA_REPEAT = 2714, + KEYCODE_IMAGES = 2715, + KEYCODE_BUTTONCONFIG = 2716, + KEYCODE_TASKMANAGER = 2717, + KEYCODE_JOURNAL = 2718, + KEYCODE_CONTROLPANEL = 2719, + KEYCODE_APPSELECT = 2720, + KEYCODE_SCREENSAVER = 2721, + KEYCODE_ASSISTANT = 2722, + KEYCODE_KBD_LAYOUT_NEXT = 2723, + KEYCODE_BRIGHTNESS_MIN = 2724, + KEYCODE_BRIGHTNESS_MAX = 2725, + KEYCODE_KBDINPUTASSIST_PREV = 2726, + KEYCODE_KBDINPUTASSIST_NEXT = 2727, + KEYCODE_KBDINPUTASSIST_PREVGROUP = 2728, + KEYCODE_KBDINPUTASSIST_NEXTGROUP = 2729, + KEYCODE_KBDINPUTASSIST_ACCEPT = 2730, + KEYCODE_KBDINPUTASSIST_CANCEL = 2731, + KEYCODE_FRONT = 2800, + KEYCODE_SETUP = 2801, + KEYCODE_WAKEUP = 2802, + KEYCODE_SENDFILE = 2803, + KEYCODE_DELETEFILE = 2804, + KEYCODE_XFER = 2805, + KEYCODE_PROG1 = 2806, + KEYCODE_PROG2 = 2807, + KEYCODE_MSDOS = 2808, + KEYCODE_SCREENLOCK = 2809, + KEYCODE_DIRECTION_ROTATE_DISPLAY = 2810, + KEYCODE_CYCLEWINDOWS = 2811, + KEYCODE_COMPUTER = 2812, + KEYCODE_EJECTCLOSECD = 2813, + KEYCODE_ISO = 2814, + KEYCODE_MOVE = 2815, + KEYCODE_F13 = 2816, + KEYCODE_F14 = 2817, + KEYCODE_F15 = 2818, + KEYCODE_F16 = 2819, + KEYCODE_F17 = 2820, + KEYCODE_F18 = 2821, + KEYCODE_F19 = 2822, + KEYCODE_F20 = 2823, + KEYCODE_F21 = 2824, + KEYCODE_F22 = 2825, + KEYCODE_F23 = 2826, + KEYCODE_F24 = 2827, + KEYCODE_PROG3 = 2828, + KEYCODE_PROG4 = 2829, + KEYCODE_DASHBOARD = 2830, + KEYCODE_SUSPEND = 2831, + KEYCODE_HP = 2832, + KEYCODE_SOUND = 2833, + KEYCODE_QUESTION = 2834, + KEYCODE_CONNECT = 2836, + KEYCODE_SPORT = 2837, + KEYCODE_SHOP = 2838, + KEYCODE_ALTERASE = 2839, + KEYCODE_SWITCHVIDEOMODE = 2841, + KEYCODE_BATTERY = 2842, + KEYCODE_BLUETOOTH = 2843, + KEYCODE_WLAN = 2844, + KEYCODE_UWB = 2845, + KEYCODE_WWAN_WIMAX = 2846, + KEYCODE_RFKILL = 2847, + KEYCODE_CHANNEL = 3001, + KEYCODE_BTN_0 = 3100, + KEYCODE_BTN_1 = 3101, + KEYCODE_BTN_2 = 3102, + KEYCODE_BTN_3 = 3103, + KEYCODE_BTN_4 = 3104, + KEYCODE_BTN_5 = 3105, + KEYCODE_BTN_6 = 3106, + KEYCODE_BTN_7 = 3107, + KEYCODE_BTN_8 = 3108, + KEYCODE_BTN_9 = 3109, + KEYCODE_DAGGER_CLICK = 3211, + KEYCODE_DAGGER_DOUBLE_CLICK = 3212, + KEYCODE_DAGGER_LONG_PRESS = 3213 +} \ No newline at end of file diff --git a/frameworks/ets/key_code/include/ohos.multimodalInput.keyCode.impl.h b/frameworks/ets/key_code/include/ohos.multimodalInput.keyCode.impl.h new file mode 100644 index 0000000000..0e1a21307e --- /dev/null +++ b/frameworks/ets/key_code/include/ohos.multimodalInput.keyCode.impl.h @@ -0,0 +1,386 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_MULTIMODALINPUT_KEY_CODE_IMPL_H +#define OHOS_MULTIMODALINPUT_KEY_CODE_IMPL_H + +#include "define_multimodal.h" +#include "input_manager.h" +#include "ohos.multimodalInput.keyCode.proj.hpp" +#include "ohos.multimodalInput.keyCode.impl.hpp" +#include "taihe/runtime.hpp" +#include "stdexcept" + +#include + +namespace OHOS { +namespace MMI { +using namespace ohos::multimodalInput::keyCode; + +enum KeyCodeEts { + KEYCODE_FN_ETS = 0, + KEYCODE_UNKNOWN_ETS = -1, + KEYCODE_HOME_ETS = 1, + KEYCODE_BACK_ETS = 2, + KEYCODE_SEARCH_ETS = 9, + KEYCODE_MEDIA_PLAY_PAUSE_ETS = 10, + KEYCODE_MEDIA_STOP_ETS = 11, + KEYCODE_MEDIA_NEXT_ETS = 12, + KEYCODE_MEDIA_PREVIOUS_ETS = 13, + KEYCODE_MEDIA_REWIND_ETS = 14, + KEYCODE_MEDIA_FAST_FORWARD_ETS = 15, + KEYCODE_VOLUME_UP_ETS = 16, + KEYCODE_VOLUME_DOWN_ETS = 17, + KEYCODE_POWER_ETS = 18, + KEYCODE_CAMERA_ETS = 19, + KEYCODE_VOLUME_MUTE_ETS = 22, + KEYCODE_MUTE_ETS = 23, + KEYCODE_BRIGHTNESS_UP_ETS = 40, + KEYCODE_BRIGHTNESS_DOWN_ETS = 41, + KEYCODE_0_ETS = 2000, + KEYCODE_1_ETS = 2001, + KEYCODE_2_ETS = 2002, + KEYCODE_3_ETS = 2003, + KEYCODE_4_ETS = 2004, + KEYCODE_5_ETS = 2005, + KEYCODE_6_ETS = 2006, + KEYCODE_7_ETS = 2007, + KEYCODE_8_ETS = 2008, + KEYCODE_9_ETS = 2009, + KEYCODE_STAR_ETS = 2010, + KEYCODE_POUND_ETS = 2011, + KEYCODE_DPAD_UP_ETS = 2012, + KEYCODE_DPAD_DOWN_ETS = 2013, + KEYCODE_DPAD_LEFT_ETS = 2014, + KEYCODE_DPAD_RIGHT_ETS = 2015, + KEYCODE_DPAD_CENTER_ETS = 2016, + KEYCODE_A_ETS = 2017, + KEYCODE_B_ETS = 2018, + KEYCODE_C_ETS = 2019, + KEYCODE_D_ETS = 2020, + KEYCODE_E_ETS = 2021, + KEYCODE_F_ETS = 2022, + KEYCODE_G_ETS = 2023, + KEYCODE_H_ETS = 2024, + KEYCODE_I_ETS = 2025, + KEYCODE_J_ETS = 2026, + KEYCODE_K_ETS = 2027, + KEYCODE_L_ETS = 2028, + KEYCODE_M_ETS = 2029, + KEYCODE_N_ETS = 2030, + KEYCODE_O_ETS = 2031, + KEYCODE_P_ETS = 2032, + KEYCODE_Q_ETS = 2033, + KEYCODE_R_ETS = 2034, + KEYCODE_S_ETS = 2035, + KEYCODE_T_ETS = 2036, + KEYCODE_U_ETS = 2037, + KEYCODE_V_ETS = 2038, + KEYCODE_W_ETS = 2039, + KEYCODE_X_ETS = 2040, + KEYCODE_Y_ETS = 2041, + KEYCODE_Z_ETS = 2042, + KEYCODE_COMMA_ETS = 2043, + KEYCODE_PERIOD_ETS = 2044, + KEYCODE_ALT_LEFT_ETS = 2045, + KEYCODE_ALT_RIGHT_ETS = 2046, + KEYCODE_SHIFT_LEFT_ETS = 2047, + KEYCODE_SHIFT_RIGHT_ETS = 2048, + KEYCODE_TAB_ETS = 2049, + KEYCODE_SPACE_ETS = 2050, + KEYCODE_SYM_ETS = 2051, + KEYCODE_EXPLORER_ETS = 2052, + KEYCODE_ENVELOPE_ETS = 2053, + KEYCODE_ENTER_ETS = 2054, + KEYCODE_DEL_ETS = 2055, + KEYCODE_GRAVE_ETS = 2056, + KEYCODE_MINUS_ETS = 2057, + KEYCODE_EQUALS_ETS = 2058, + KEYCODE_LEFT_BRACKET_ETS = 2059, + KEYCODE_RIGHT_BRACKET_ETS = 2060, + KEYCODE_BACKSLASH_ETS = 2061, + KEYCODE_SEMICOLON_ETS = 2062, + KEYCODE_APOSTROPHE_ETS = 2063, + KEYCODE_SLASH_ETS = 2064, + KEYCODE_AT_ETS = 2065, + KEYCODE_PLUS_ETS = 2066, + KEYCODE_MENU_ETS = 2067, + KEYCODE_PAGE_UP_ETS = 2068, + KEYCODE_PAGE_DOWN_ETS = 2069, + KEYCODE_ESCAPE_ETS = 2070, + KEYCODE_FORWARD_DEL_ETS = 2071, + KEYCODE_CTRL_LEFT_ETS = 2072, + KEYCODE_CTRL_RIGHT_ETS = 2073, + KEYCODE_CAPS_LOCK_ETS = 2074, + KEYCODE_SCROLL_LOCK_ETS = 2075, + KEYCODE_META_LEFT_ETS = 2076, + KEYCODE_META_RIGHT_ETS = 2077, + KEYCODE_FUNCTION_ETS = 2078, + KEYCODE_SYSRQ_ETS = 2079, + KEYCODE_BREAK_ETS = 2080, + KEYCODE_MOVE_HOME_ETS = 2081, + KEYCODE_MOVE_END_ETS = 2082, + KEYCODE_INSERT_ETS = 2083, + KEYCODE_FORWARD_ETS = 2084, + KEYCODE_MEDIA_PLAY_ETS = 2085, + KEYCODE_MEDIA_PAUSE_ETS = 2086, + KEYCODE_MEDIA_CLOSE_ETS = 2087, + KEYCODE_MEDIA_EJECT_ETS = 2088, + KEYCODE_MEDIA_RECORD_ETS = 2089, + KEYCODE_F1_ETS = 2090, + KEYCODE_F2_ETS = 2091, + KEYCODE_F3_ETS = 2092, + KEYCODE_F4_ETS = 2093, + KEYCODE_F5_ETS = 2094, + KEYCODE_F6_ETS = 2095, + KEYCODE_F7_ETS = 2096, + KEYCODE_F8_ETS = 2097, + KEYCODE_F9_ETS = 2098, + KEYCODE_F10_ETS = 2099, + KEYCODE_F11_ETS = 2100, + KEYCODE_F12_ETS = 2101, + KEYCODE_NUM_LOCK_ETS = 2102, + KEYCODE_NUMPAD_0_ETS = 2103, + KEYCODE_NUMPAD_1_ETS = 2104, + KEYCODE_NUMPAD_2_ETS = 2105, + KEYCODE_NUMPAD_3_ETS = 2106, + KEYCODE_NUMPAD_4_ETS = 2107, + KEYCODE_NUMPAD_5_ETS = 2108, + KEYCODE_NUMPAD_6_ETS = 2109, + KEYCODE_NUMPAD_7_ETS = 2110, + KEYCODE_NUMPAD_8_ETS = 2111, + KEYCODE_NUMPAD_9_ETS = 2112, + KEYCODE_NUMPAD_DIVIDE_ETS = 2113, + KEYCODE_NUMPAD_MULTIPLY_ETS = 2114, + KEYCODE_NUMPAD_SUBTRACT_ETS = 2115, + KEYCODE_NUMPAD_ADD_ETS = 2116, + KEYCODE_NUMPAD_DOT_ETS = 2117, + KEYCODE_NUMPAD_COMMA_ETS = 2118, + KEYCODE_NUMPAD_ENTER_ETS = 2119, + KEYCODE_NUMPAD_EQUALS_ETS = 2120, + KEYCODE_NUMPAD_LEFT_PAREN_ETS = 2121, + KEYCODE_NUMPAD_RIGHT_PAREN_ETS = 2122, + KEYCODE_VIRTUAL_MULTITASK_ETS = 2210, + KEYCODE_BUTTON_A_ETS = 2301, + KEYCODE_BUTTON_B_ETS = 2302, + KEYCODE_BUTTON_X_ETS = 2304, + KEYCODE_BUTTON_Y_ETS = 2305, + KEYCODE_BUTTON_L1_ETS = 2307, + KEYCODE_BUTTON_R1_ETS = 2308, + KEYCODE_BUTTON_L2_ETS = 2309, + KEYCODE_BUTTON_R2_ETS = 2310, + KEYCODE_BUTTON_SELECT_ETS = 2311, + KEYCODE_BUTTON_START_ETS = 2312, + KEYCODE_BUTTON_MODE_ETS = 2313, + KEYCODE_BUTTON_THUMBL_ETS = 2314, + KEYCODE_BUTTON_THUMBR_ETS = 2315, + KEYCODE_SLEEP_ETS = 2600, + KEYCODE_ZENKAKU_HANKAKU_ETS = 2601, + KEYCODE_102ND_ETS = 2602, + KEYCODE_RO_ETS = 2603, + KEYCODE_KATAKANA_ETS = 2604, + KEYCODE_HIRAGANA_ETS = 2605, + KEYCODE_HENKAN_ETS = 2606, + KEYCODE_KATAKANA_HIRAGANA_ETS = 2607, + KEYCODE_MUHENKAN_ETS = 2608, + KEYCODE_LINEFEED_ETS = 2609, + KEYCODE_MACRO_ETS = 2610, + KEYCODE_NUMPAD_PLUSMINUS_ETS = 2611, + KEYCODE_SCALE_ETS = 2612, + KEYCODE_HANGUEL_ETS = 2613, + KEYCODE_HANJA_ETS = 2614, + KEYCODE_YEN_ETS = 2615, + KEYCODE_STOP_ETS = 2616, + KEYCODE_AGAIN_ETS = 2617, + KEYCODE_PROPS_ETS = 2618, + KEYCODE_UNDO_ETS = 2619, + KEYCODE_COPY_ETS = 2620, + KEYCODE_OPEN_ETS = 2621, + KEYCODE_PASTE_ETS = 2622, + KEYCODE_FIND_ETS = 2623, + KEYCODE_CUT_ETS = 2624, + KEYCODE_HELP_ETS = 2625, + KEYCODE_CALC_ETS = 2626, + KEYCODE_FILE_ETS = 2627, + KEYCODE_BOOKMARKS_ETS = 2628, + KEYCODE_NEXT_ETS = 2629, + KEYCODE_PLAYPAUSE_ETS = 2630, + KEYCODE_PREVIOUS_ETS = 2631, + KEYCODE_STOPCD_ETS = 2632, + KEYCODE_CONFIG_ETS = 2634, + KEYCODE_REFRESH_ETS = 2635, + KEYCODE_EXIT_ETS = 2636, + KEYCODE_EDIT_ETS = 2637, + KEYCODE_SCROLLUP_ETS = 2638, + KEYCODE_SCROLLDOWN_ETS = 2639, + KEYCODE_NEW_ETS = 2640, + KEYCODE_REDO_ETS = 2641, + KEYCODE_CLOSE_ETS = 2642, + KEYCODE_PLAY_ETS = 2643, + KEYCODE_BASSBOOST_ETS = 2644, + KEYCODE_PRINT_ETS = 2645, + KEYCODE_CHAT_ETS = 2646, + KEYCODE_FINANCE_ETS = 2647, + KEYCODE_CANCEL_ETS = 2648, + KEYCODE_KBDILLUM_TOGGLE_ETS = 2649, + KEYCODE_KBDILLUM_DOWN_ETS = 2650, + KEYCODE_KBDILLUM_UP_ETS = 2651, + KEYCODE_SEND_ETS = 2652, + KEYCODE_REPLY_ETS = 2653, + KEYCODE_FORWARDMAIL_ETS = 2654, + KEYCODE_SAVE_ETS = 2655, + KEYCODE_DOCUMENTS_ETS = 2656, + KEYCODE_VIDEO_NEXT_ETS = 2657, + KEYCODE_VIDEO_PREV_ETS = 2658, + KEYCODE_BRIGHTNESS_CYCLE_ETS = 2659, + KEYCODE_BRIGHTNESS_ZERO_ETS = 2660, + KEYCODE_DISPLAY_OFF_ETS = 2661, + KEYCODE_BTN_MISC_ETS = 2662, + KEYCODE_GOTO_ETS = 2663, + KEYCODE_INFO_ETS = 2664, + KEYCODE_PROGRAM_ETS = 2665, + KEYCODE_PVR_ETS = 2666, + KEYCODE_SUBTITLE_ETS = 2667, + KEYCODE_FULL_SCREEN_ETS = 2668, + KEYCODE_KEYBOARD_ETS = 2669, + KEYCODE_ASPECT_RATIO_ETS = 2670, + KEYCODE_PC_ETS = 2671, + KEYCODE_TV_ETS = 2672, + KEYCODE_TV2_ETS = 2673, + KEYCODE_VCR_ETS = 2674, + KEYCODE_VCR2_ETS = 2675, + KEYCODE_SAT_ETS = 2676, + KEYCODE_CD_ETS = 2677, + KEYCODE_TAPE_ETS = 2678, + KEYCODE_TUNER_ETS = 2679, + KEYCODE_PLAYER_ETS = 2680, + KEYCODE_DVD_ETS = 2681, + KEYCODE_AUDIO_ETS = 2682, + KEYCODE_VIDEO_ETS = 2683, + KEYCODE_MEMO_ETS = 2684, + KEYCODE_CALENDAR_ETS = 2685, + KEYCODE_RED_ETS = 2686, + KEYCODE_GREEN_ETS = 2687, + KEYCODE_YELLOW_ETS = 2688, + KEYCODE_BLUE_ETS = 2689, + KEYCODE_CHANNELUP_ETS = 2690, + KEYCODE_CHANNELDOWN_ETS = 2691, + KEYCODE_LAST_ETS = 2692, + KEYCODE_RESTART_ETS = 2693, + KEYCODE_SLOW_ETS = 2694, + KEYCODE_SHUFFLE_ETS = 2695, + KEYCODE_VIDEOPHONE_ETS = 2696, + KEYCODE_GAMES_ETS = 2697, + KEYCODE_ZOOMIN_ETS = 2698, + KEYCODE_ZOOMOUT_ETS = 2699, + KEYCODE_ZOOMRESET_ETS = 2700, + KEYCODE_WORDPROCESSOR_ETS = 2701, + KEYCODE_EDITOR_ETS = 2702, + KEYCODE_SPREADSHEET_ETS = 2703, + KEYCODE_GRAPHICSEDITOR_ETS = 2704, + KEYCODE_PRESENTATION_ETS = 2705, + KEYCODE_DATABASE_ETS = 2706, + KEYCODE_NEWS_ETS = 2707, + KEYCODE_VOICEMAIL_ETS = 2708, + KEYCODE_ADDRESSBOOK_ETS = 2709, + KEYCODE_MESSENGER_ETS = 2710, + KEYCODE_BRIGHTNESS_TOGGLE_ETS = 2711, + KEYCODE_SPELLCHECK_ETS = 2712, + KEYCODE_COFFEE_ETS = 2713, + KEYCODE_MEDIA_REPEAT_ETS = 2714, + KEYCODE_IMAGES_ETS = 2715, + KEYCODE_BUTTONCONFIG_ETS = 2716, + KEYCODE_TASKMANAGER_ETS = 2717, + KEYCODE_JOURNAL_ETS = 2718, + KEYCODE_CONTROLPANEL_ETS = 2719, + KEYCODE_APPSELECT_ETS = 2720, + KEYCODE_SCREENSAVER_ETS = 2721, + KEYCODE_ASSISTANT_ETS = 2722, + KEYCODE_KBD_LAYOUT_NEXT_ETS = 2723, + KEYCODE_BRIGHTNESS_MIN_ETS = 2724, + KEYCODE_BRIGHTNESS_MAX_ETS = 2725, + KEYCODE_KBDINPUTASSIST_PREV_ETS = 2726, + KEYCODE_KBDINPUTASSIST_NEXT_ETS = 2727, + KEYCODE_KBDINPUTASSIST_PREVGROUP_ETS = 2728, + KEYCODE_KBDINPUTASSIST_NEXTGROUP_ETS = 2729, + KEYCODE_KBDINPUTASSIST_ACCEPT_ETS = 2730, + KEYCODE_KBDINPUTASSIST_CANCEL_ETS = 2731, + KEYCODE_FRONT_ETS = 2800, + KEYCODE_SETUP_ETS = 2801, + KEYCODE_WAKEUP_ETS = 2802, + KEYCODE_SENDFILE_ETS = 2803, + KEYCODE_DELETEFILE_ETS = 2804, + KEYCODE_XFER_ETS = 2805, + KEYCODE_PROG1_ETS = 2806, + KEYCODE_PROG2_ETS = 2807, + KEYCODE_MSDOS_ETS = 2808, + KEYCODE_SCREENLOCK_ETS = 2809, + KEYCODE_DIRECTION_ROTATE_DISPLAY_ETS = 2810, + KEYCODE_CYCLEWINDOWS_ETS = 2811, + KEYCODE_COMPUTER_ETS = 2812, + KEYCODE_EJECTCLOSECD_ETS = 2813, + KEYCODE_ISO_ETS = 2814, + KEYCODE_MOVE_ETS = 2815, + KEYCODE_F13_ETS = 2816, + KEYCODE_F14_ETS = 2817, + KEYCODE_F15_ETS = 2818, + KEYCODE_F16_ETS = 2819, + KEYCODE_F17_ETS = 2820, + KEYCODE_F18_ETS = 2821, + KEYCODE_F19_ETS = 2822, + KEYCODE_F20_ETS = 2823, + KEYCODE_F21_ETS = 2824, + KEYCODE_F22_ETS = 2825, + KEYCODE_F23_ETS = 2826, + KEYCODE_F24_ETS = 2827, + KEYCODE_PROG3_ETS = 2828, + KEYCODE_PROG4_ETS = 2829, + KEYCODE_DASHBOARD_ETS = 2830, + KEYCODE_SUSPEND_ETS = 2831, + KEYCODE_HP_ETS = 2832, + KEYCODE_SOUND_ETS = 2833, + KEYCODE_QUESTION_ETS = 2834, + KEYCODE_CONNECT_ETS = 2836, + KEYCODE_SPORT_ETS = 2837, + KEYCODE_SHOP_ETS = 2838, + KEYCODE_ALTERASE_ETS = 2839, + KEYCODE_SWITCHVIDEOMODE_ETS = 2841, + KEYCODE_BATTERY_ETS = 2842, + KEYCODE_BLUETOOTH_ETS = 2843, + KEYCODE_WLAN_ETS = 2844, + KEYCODE_UWB_ETS = 2845, + KEYCODE_WWAN_WIMAX_ETS = 2846, + KEYCODE_RFKILL_ETS = 2847, + KEYCODE_CHANNEL_ETS = 3001, + KEYCODE_BTN_0_ETS = 3100, + KEYCODE_BTN_1_ETS = 3101, + KEYCODE_BTN_2_ETS = 3102, + KEYCODE_BTN_3_ETS = 3103, + KEYCODE_BTN_4_ETS = 3104, + KEYCODE_BTN_5_ETS = 3105, + KEYCODE_BTN_6_ETS = 3106, + KEYCODE_BTN_7_ETS = 3107, + KEYCODE_BTN_8_ETS = 3108, + KEYCODE_BTN_9_ETS = 3109, + KEYCODE_DAGGER_CLICK_ETS = 3211, + KEYCODE_DAGGER_DOUBLE_CLICK_ETS = 3212, + KEYCODE_DAGGER_LONG_PRESS_ETS = 3213 +}; + +KeyCode ConvertEtsKeyCode(int32_t keyCode); + +} // namespace MMI +} // namespace OHOS +#endif // OHOS_MULTIMODALINPUT_KEY_CODE_IMPL_H diff --git a/frameworks/ets/key_code/src/ani_constructor.cpp b/frameworks/ets/key_code/src/ani_constructor.cpp new file mode 100644 index 0000000000..bed80b9d8c --- /dev/null +++ b/frameworks/ets/key_code/src/ani_constructor.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ohos.multimodalInput.keyCode.ani.hpp" +ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) +{ + ani_env *env; + if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) { + return ANI_ERROR; + } + if (ANI_OK != ohos::multimodalInput::keyCode::ANIRegister(env)) { + std::cerr << "Error from ohos::multimodalInput::keyCode::ANIRegister" << std::endl; + return ANI_ERROR; + } + *result = ANI_VERSION_1; + return ANI_OK; +} \ No newline at end of file diff --git a/frameworks/ets/key_code/src/ohos.multimodalInput.keyCode.impl.cpp b/frameworks/ets/key_code/src/ohos.multimodalInput.keyCode.impl.cpp new file mode 100644 index 0000000000..fdcbf988aa --- /dev/null +++ b/frameworks/ets/key_code/src/ohos.multimodalInput.keyCode.impl.cpp @@ -0,0 +1,388 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ohos.multimodalInput.keyCode.impl.h" + +#undef MMI_LOG_TAG +#define MMI_LOG_TAG "ohos.multimodalInput.keyCode.impl" + +namespace OHOS { +namespace MMI { + +const static std::map KEY_CODE_TRANSFORMATION = { + { KEYCODE_FN_ETS, KeyCode::key_t::KEYCODE_FN }, + { KEYCODE_UNKNOWN_ETS, KeyCode::key_t::KEYCODE_UNKNOWN }, + { KEYCODE_HOME_ETS, KeyCode::key_t::KEYCODE_HOME }, + { KEYCODE_BACK_ETS, KeyCode::key_t::KEYCODE_BACK }, + { KEYCODE_SEARCH_ETS, KeyCode::key_t::KEYCODE_SEARCH }, + { KEYCODE_MEDIA_PLAY_PAUSE_ETS, KeyCode::key_t::KEYCODE_MEDIA_PLAY_PAUSE }, + { KEYCODE_MEDIA_STOP_ETS, KeyCode::key_t::KEYCODE_MEDIA_STOP }, + { KEYCODE_MEDIA_NEXT_ETS, KeyCode::key_t::KEYCODE_MEDIA_NEXT }, + { KEYCODE_MEDIA_PREVIOUS_ETS, KeyCode::key_t::KEYCODE_MEDIA_PREVIOUS }, + { KEYCODE_MEDIA_REWIND_ETS, KeyCode::key_t::KEYCODE_MEDIA_REWIND }, + { KEYCODE_MEDIA_FAST_FORWARD_ETS, KeyCode::key_t::KEYCODE_MEDIA_FAST_FORWARD }, + { KEYCODE_VOLUME_UP_ETS, KeyCode::key_t::KEYCODE_VOLUME_UP }, + { KEYCODE_VOLUME_DOWN_ETS, KeyCode::key_t::KEYCODE_VOLUME_DOWN }, + { KEYCODE_POWER_ETS, KeyCode::key_t::KEYCODE_POWER }, + { KEYCODE_CAMERA_ETS, KeyCode::key_t::KEYCODE_CAMERA }, + { KEYCODE_VOLUME_MUTE_ETS, KeyCode::key_t::KEYCODE_VOLUME_MUTE }, + { KEYCODE_MUTE_ETS, KeyCode::key_t::KEYCODE_MUTE }, + { KEYCODE_BRIGHTNESS_UP_ETS, KeyCode::key_t::KEYCODE_BRIGHTNESS_UP }, + { KEYCODE_BRIGHTNESS_DOWN_ETS, KeyCode::key_t::KEYCODE_BRIGHTNESS_DOWN }, + { KEYCODE_0_ETS, KeyCode::key_t::KEYCODE_0 }, + { KEYCODE_1_ETS, KeyCode::key_t::KEYCODE_1 }, + { KEYCODE_2_ETS, KeyCode::key_t::KEYCODE_2 }, + { KEYCODE_3_ETS, KeyCode::key_t::KEYCODE_3 }, + { KEYCODE_4_ETS, KeyCode::key_t::KEYCODE_4 }, + { KEYCODE_5_ETS, KeyCode::key_t::KEYCODE_5 }, + { KEYCODE_6_ETS, KeyCode::key_t::KEYCODE_6 }, + { KEYCODE_7_ETS, KeyCode::key_t::KEYCODE_7 }, + { KEYCODE_8_ETS, KeyCode::key_t::KEYCODE_8 }, + { KEYCODE_9_ETS, KeyCode::key_t::KEYCODE_9 }, + { KEYCODE_STAR_ETS, KeyCode::key_t::KEYCODE_STAR }, + { KEYCODE_POUND_ETS, KeyCode::key_t::KEYCODE_POUND }, + { KEYCODE_DPAD_UP_ETS, KeyCode::key_t::KEYCODE_DPAD_UP }, + { KEYCODE_DPAD_LEFT_ETS, KeyCode::key_t::KEYCODE_DPAD_LEFT }, + { KEYCODE_DPAD_RIGHT_ETS, KeyCode::key_t::KEYCODE_DPAD_RIGHT }, + { KEYCODE_DPAD_CENTER_ETS, KeyCode::key_t::KEYCODE_DPAD_CENTER }, + { KEYCODE_A_ETS, KeyCode::key_t::KEYCODE_A }, + { KEYCODE_B_ETS, KeyCode::key_t::KEYCODE_B }, + { KEYCODE_C_ETS, KeyCode::key_t::KEYCODE_C }, + { KEYCODE_D_ETS, KeyCode::key_t::KEYCODE_D }, + { KEYCODE_E_ETS, KeyCode::key_t::KEYCODE_E }, + { KEYCODE_F_ETS, KeyCode::key_t::KEYCODE_F }, + { KEYCODE_G_ETS, KeyCode::key_t::KEYCODE_G }, + { KEYCODE_H_ETS, KeyCode::key_t::KEYCODE_H }, + { KEYCODE_I_ETS, KeyCode::key_t::KEYCODE_I }, + { KEYCODE_J_ETS, KeyCode::key_t::KEYCODE_J }, + { KEYCODE_K_ETS, KeyCode::key_t::KEYCODE_K }, + { KEYCODE_L_ETS, KeyCode::key_t::KEYCODE_L }, + { KEYCODE_M_ETS, KeyCode::key_t::KEYCODE_M }, + { KEYCODE_N_ETS, KeyCode::key_t::KEYCODE_N }, + { KEYCODE_O_ETS, KeyCode::key_t::KEYCODE_O }, + { KEYCODE_P_ETS, KeyCode::key_t::KEYCODE_P }, + { KEYCODE_Q_ETS, KeyCode::key_t::KEYCODE_Q }, + { KEYCODE_R_ETS, KeyCode::key_t::KEYCODE_R }, + { KEYCODE_S_ETS, KeyCode::key_t::KEYCODE_S }, + { KEYCODE_T_ETS, KeyCode::key_t::KEYCODE_T }, + { KEYCODE_U_ETS, KeyCode::key_t::KEYCODE_U }, + { KEYCODE_V_ETS, KeyCode::key_t::KEYCODE_V }, + { KEYCODE_W_ETS, KeyCode::key_t::KEYCODE_W }, + { KEYCODE_X_ETS, KeyCode::key_t::KEYCODE_X }, + { KEYCODE_Y_ETS, KeyCode::key_t::KEYCODE_Y }, + { KEYCODE_Z_ETS, KeyCode::key_t::KEYCODE_Z }, + { KEYCODE_COMMA_ETS, KeyCode::key_t::KEYCODE_COMMA }, + { KEYCODE_PERIOD_ETS, KeyCode::key_t::KEYCODE_PERIOD }, + { KEYCODE_ALT_LEFT_ETS, KeyCode::key_t::KEYCODE_ALT_LEFT }, + { KEYCODE_ALT_RIGHT_ETS, KeyCode::key_t::KEYCODE_ALT_RIGHT }, + { KEYCODE_SHIFT_LEFT_ETS, KeyCode::key_t::KEYCODE_SHIFT_LEFT }, + { KEYCODE_SHIFT_RIGHT_ETS, KeyCode::key_t::KEYCODE_SHIFT_RIGHT }, + { KEYCODE_TAB_ETS, KeyCode::key_t::KEYCODE_TAB }, + { KEYCODE_SPACE_ETS, KeyCode::key_t::KEYCODE_SPACE }, + { KEYCODE_SYM_ETS, KeyCode::key_t::KEYCODE_SYM }, + { KEYCODE_EXPLORER_ETS, KeyCode::key_t::KEYCODE_EXPLORER }, + { KEYCODE_ENVELOPE_ETS, KeyCode::key_t::KEYCODE_ENVELOPE }, + { KEYCODE_ENTER_ETS, KeyCode::key_t::KEYCODE_ENTER }, + { KEYCODE_DEL_ETS, KeyCode::key_t::KEYCODE_DEL }, + { KEYCODE_GRAVE_ETS, KeyCode::key_t::KEYCODE_GRAVE }, + { KEYCODE_MINUS_ETS, KeyCode::key_t::KEYCODE_MINUS }, + { KEYCODE_EQUALS_ETS, KeyCode::key_t::KEYCODE_EQUALS }, + { KEYCODE_LEFT_BRACKET_ETS, KeyCode::key_t::KEYCODE_LEFT_BRACKET }, + { KEYCODE_RIGHT_BRACKET_ETS, KeyCode::key_t::KEYCODE_RIGHT_BRACKET }, + { KEYCODE_BACKSLASH_ETS, KeyCode::key_t::KEYCODE_BACKSLASH }, + { KEYCODE_SEMICOLON_ETS, KeyCode::key_t::KEYCODE_SEMICOLON }, + { KEYCODE_APOSTROPHE_ETS, KeyCode::key_t::KEYCODE_APOSTROPHE }, + { KEYCODE_SLASH_ETS, KeyCode::key_t::KEYCODE_SLASH }, + { KEYCODE_AT_ETS, KeyCode::key_t::KEYCODE_AT }, + { KEYCODE_PLUS_ETS, KeyCode::key_t::KEYCODE_PLUS }, + { KEYCODE_MENU_ETS, KeyCode::key_t::KEYCODE_MENU }, + { KEYCODE_PAGE_UP_ETS, KeyCode::key_t::KEYCODE_PAGE_UP }, + { KEYCODE_PAGE_DOWN_ETS, KeyCode::key_t::KEYCODE_PAGE_DOWN }, + { KEYCODE_ESCAPE_ETS, KeyCode::key_t::KEYCODE_ESCAPE }, + { KEYCODE_FORWARD_DEL_ETS, KeyCode::key_t::KEYCODE_FORWARD_DEL }, + { KEYCODE_CTRL_LEFT_ETS, KeyCode::key_t::KEYCODE_CTRL_LEFT }, + { KEYCODE_CTRL_RIGHT_ETS, KeyCode::key_t::KEYCODE_CTRL_RIGHT }, + { KEYCODE_CAPS_LOCK_ETS, KeyCode::key_t::KEYCODE_CAPS_LOCK }, + { KEYCODE_SCROLL_LOCK_ETS, KeyCode::key_t::KEYCODE_SCROLL_LOCK }, + { KEYCODE_META_LEFT_ETS, KeyCode::key_t::KEYCODE_META_LEFT }, + { KEYCODE_META_RIGHT_ETS, KeyCode::key_t::KEYCODE_META_RIGHT }, + { KEYCODE_FUNCTION_ETS, KeyCode::key_t::KEYCODE_FUNCTION }, + { KEYCODE_SYSRQ_ETS, KeyCode::key_t::KEYCODE_SYSRQ }, + { KEYCODE_BREAK_ETS, KeyCode::key_t::KEYCODE_BREAK }, + { KEYCODE_MOVE_HOME_ETS, KeyCode::key_t::KEYCODE_MOVE_HOME }, + { KEYCODE_MOVE_END_ETS, KeyCode::key_t::KEYCODE_MOVE_END }, + { KEYCODE_INSERT_ETS, KeyCode::key_t::KEYCODE_INSERT }, + { KEYCODE_FORWARD_ETS, KeyCode::key_t::KEYCODE_FORWARD }, + { KEYCODE_MEDIA_PLAY_ETS, KeyCode::key_t::KEYCODE_MEDIA_PLAY }, + { KEYCODE_MEDIA_PAUSE_ETS, KeyCode::key_t::KEYCODE_MEDIA_PAUSE }, + { KEYCODE_MEDIA_CLOSE_ETS, KeyCode::key_t::KEYCODE_MEDIA_CLOSE }, + { KEYCODE_MEDIA_EJECT_ETS, KeyCode::key_t::KEYCODE_MEDIA_EJECT }, + { KEYCODE_MEDIA_RECORD_ETS, KeyCode::key_t::KEYCODE_MEDIA_RECORD }, + { KEYCODE_F1_ETS, KeyCode::key_t::KEYCODE_F1 }, + { KEYCODE_F2_ETS, KeyCode::key_t::KEYCODE_F2 }, + { KEYCODE_F3_ETS, KeyCode::key_t::KEYCODE_F3 }, + { KEYCODE_F4_ETS, KeyCode::key_t::KEYCODE_F4 }, + { KEYCODE_F5_ETS, KeyCode::key_t::KEYCODE_F5 }, + { KEYCODE_F6_ETS, KeyCode::key_t::KEYCODE_F6 }, + { KEYCODE_F7_ETS, KeyCode::key_t::KEYCODE_F7 }, + { KEYCODE_F8_ETS, KeyCode::key_t::KEYCODE_F8 }, + { KEYCODE_F9_ETS, KeyCode::key_t::KEYCODE_F9 }, + { KEYCODE_F10_ETS, KeyCode::key_t::KEYCODE_F10 }, + { KEYCODE_F11_ETS, KeyCode::key_t::KEYCODE_F11 }, + { KEYCODE_F12_ETS, KeyCode::key_t::KEYCODE_F12 }, + { KEYCODE_NUM_LOCK_ETS, KeyCode::key_t::KEYCODE_NUM_LOCK }, + { KEYCODE_NUMPAD_0_ETS, KeyCode::key_t::KEYCODE_NUMPAD_0 }, + { KEYCODE_NUMPAD_1_ETS, KeyCode::key_t::KEYCODE_NUMPAD_1 }, + { KEYCODE_NUMPAD_2_ETS, KeyCode::key_t::KEYCODE_NUMPAD_2 }, + { KEYCODE_NUMPAD_3_ETS, KeyCode::key_t::KEYCODE_NUMPAD_3 }, + { KEYCODE_NUMPAD_4_ETS, KeyCode::key_t::KEYCODE_NUMPAD_4 }, + { KEYCODE_NUMPAD_5_ETS, KeyCode::key_t::KEYCODE_NUMPAD_5 }, + { KEYCODE_NUMPAD_6_ETS, KeyCode::key_t::KEYCODE_NUMPAD_6 }, + { KEYCODE_NUMPAD_7_ETS, KeyCode::key_t::KEYCODE_NUMPAD_7 }, + { KEYCODE_NUMPAD_8_ETS, KeyCode::key_t::KEYCODE_NUMPAD_8 }, + { KEYCODE_NUMPAD_9_ETS, KeyCode::key_t::KEYCODE_NUMPAD_9 }, + { KEYCODE_NUMPAD_DIVIDE_ETS, KeyCode::key_t::KEYCODE_NUMPAD_DIVIDE }, + { KEYCODE_NUMPAD_MULTIPLY_ETS, KeyCode::key_t::KEYCODE_NUMPAD_MULTIPLY }, + { KEYCODE_NUMPAD_SUBTRACT_ETS, KeyCode::key_t::KEYCODE_NUMPAD_SUBTRACT }, + { KEYCODE_NUMPAD_ADD_ETS, KeyCode::key_t::KEYCODE_NUMPAD_ADD }, + { KEYCODE_NUMPAD_DOT_ETS, KeyCode::key_t::KEYCODE_NUMPAD_DOT }, + { KEYCODE_NUMPAD_COMMA_ETS, KeyCode::key_t::KEYCODE_NUMPAD_COMMA }, + { KEYCODE_NUMPAD_ENTER_ETS, KeyCode::key_t::KEYCODE_NUMPAD_ENTER }, + { KEYCODE_NUMPAD_EQUALS_ETS, KeyCode::key_t::KEYCODE_NUMPAD_EQUALS }, + { KEYCODE_NUMPAD_LEFT_PAREN_ETS, KeyCode::key_t::KEYCODE_NUMPAD_LEFT_PAREN }, + { KEYCODE_NUMPAD_RIGHT_PAREN_ETS, KeyCode::key_t::KEYCODE_NUMPAD_RIGHT_PAREN }, + { KEYCODE_VIRTUAL_MULTITASK_ETS, KeyCode::key_t::KEYCODE_VIRTUAL_MULTITASK }, + { KEYCODE_BUTTON_A_ETS, KeyCode::key_t::KEYCODE_BUTTON_A }, + { KEYCODE_BUTTON_B_ETS, KeyCode::key_t::KEYCODE_BUTTON_B }, + { KEYCODE_BUTTON_X_ETS, KeyCode::key_t::KEYCODE_BUTTON_X }, + { KEYCODE_BUTTON_Y_ETS, KeyCode::key_t::KEYCODE_BUTTON_Y }, + { KEYCODE_BUTTON_L1_ETS, KeyCode::key_t::KEYCODE_BUTTON_L1 }, + { KEYCODE_BUTTON_R1_ETS, KeyCode::key_t::KEYCODE_BUTTON_R1 }, + { KEYCODE_BUTTON_L2_ETS, KeyCode::key_t::KEYCODE_BUTTON_L2 }, + { KEYCODE_BUTTON_R2_ETS, KeyCode::key_t::KEYCODE_BUTTON_R2 }, + { KEYCODE_BUTTON_SELECT_ETS, KeyCode::key_t::KEYCODE_BUTTON_SELECT }, + { KEYCODE_BUTTON_START_ETS, KeyCode::key_t::KEYCODE_BUTTON_START }, + { KEYCODE_BUTTON_MODE_ETS, KeyCode::key_t::KEYCODE_BUTTON_MODE }, + { KEYCODE_BUTTON_THUMBL_ETS, KeyCode::key_t::KEYCODE_BUTTON_THUMBL }, + { KEYCODE_BUTTON_THUMBR_ETS, KeyCode::key_t::KEYCODE_BUTTON_THUMBR }, + { KEYCODE_SLEEP_ETS, KeyCode::key_t::KEYCODE_SLEEP }, + { KEYCODE_ZENKAKU_HANKAKU_ETS, KeyCode::key_t::KEYCODE_ZENKAKU_HANKAKU }, + { KEYCODE_102ND_ETS, KeyCode::key_t::KEYCODE_102ND }, + { KEYCODE_RO_ETS, KeyCode::key_t::KEYCODE_RO }, + { KEYCODE_KATAKANA_ETS, KeyCode::key_t::KEYCODE_KATAKANA }, + { KEYCODE_HIRAGANA_ETS, KeyCode::key_t::KEYCODE_HIRAGANA }, + { KEYCODE_HENKAN_ETS, KeyCode::key_t::KEYCODE_HENKAN }, + { KEYCODE_KATAKANA_HIRAGANA_ETS, KeyCode::key_t::KEYCODE_KATAKANA_HIRAGANA }, + { KEYCODE_MUHENKAN_ETS, KeyCode::key_t::KEYCODE_MUHENKAN }, + { KEYCODE_LINEFEED_ETS, KeyCode::key_t::KEYCODE_LINEFEED }, + { KEYCODE_MACRO_ETS, KeyCode::key_t::KEYCODE_MACRO }, + { KEYCODE_NUMPAD_PLUSMINUS_ETS, KeyCode::key_t::KEYCODE_NUMPAD_PLUSMINUS }, + { KEYCODE_SCALE_ETS, KeyCode::key_t::KEYCODE_SCALE }, + { KEYCODE_HANGUEL_ETS, KeyCode::key_t::KEYCODE_HANGUEL }, + { KEYCODE_HANJA_ETS, KeyCode::key_t::KEYCODE_HANJA }, + { KEYCODE_YEN_ETS, KeyCode::key_t::KEYCODE_YEN }, + { KEYCODE_STOP_ETS, KeyCode::key_t::KEYCODE_STOP }, + { KEYCODE_AGAIN_ETS, KeyCode::key_t::KEYCODE_AGAIN }, + { KEYCODE_PROPS_ETS, KeyCode::key_t::KEYCODE_PROPS }, + { KEYCODE_UNDO_ETS, KeyCode::key_t::KEYCODE_UNDO }, + { KEYCODE_COPY_ETS, KeyCode::key_t::KEYCODE_COPY }, + { KEYCODE_OPEN_ETS, KeyCode::key_t::KEYCODE_OPEN }, + { KEYCODE_PASTE_ETS, KeyCode::key_t::KEYCODE_PASTE }, + { KEYCODE_FIND_ETS, KeyCode::key_t::KEYCODE_FIND }, + { KEYCODE_CUT_ETS, KeyCode::key_t::KEYCODE_CUT }, + { KEYCODE_HELP_ETS, KeyCode::key_t::KEYCODE_HELP }, + { KEYCODE_CALC_ETS, KeyCode::key_t::KEYCODE_CALC }, + { KEYCODE_FILE_ETS, KeyCode::key_t::KEYCODE_FILE }, + { KEYCODE_BOOKMARKS_ETS, KeyCode::key_t::KEYCODE_BOOKMARKS }, + { KEYCODE_NEXT_ETS, KeyCode::key_t::KEYCODE_NEXT }, + { KEYCODE_PLAYPAUSE_ETS, KeyCode::key_t::KEYCODE_PLAYPAUSE }, + { KEYCODE_PREVIOUS_ETS, KeyCode::key_t::KEYCODE_PREVIOUS }, + { KEYCODE_STOPCD_ETS, KeyCode::key_t::KEYCODE_STOPCD }, + { KEYCODE_CONFIG_ETS, KeyCode::key_t::KEYCODE_CONFIG }, + { KEYCODE_REFRESH_ETS, KeyCode::key_t::KEYCODE_REFRESH }, + { KEYCODE_EXIT_ETS, KeyCode::key_t::KEYCODE_EXIT }, + { KEYCODE_EDIT_ETS, KeyCode::key_t::KEYCODE_EDIT }, + { KEYCODE_SCROLLUP_ETS, KeyCode::key_t::KEYCODE_SCROLLUP }, + { KEYCODE_SCROLLDOWN_ETS, KeyCode::key_t::KEYCODE_SCROLLDOWN }, + { KEYCODE_NEW_ETS, KeyCode::key_t::KEYCODE_NEW }, + { KEYCODE_REDO_ETS, KeyCode::key_t::KEYCODE_REDO }, + { KEYCODE_CLOSE_ETS, KeyCode::key_t::KEYCODE_CLOSE }, + { KEYCODE_PLAY_ETS, KeyCode::key_t::KEYCODE_PLAY }, + { KEYCODE_BASSBOOST_ETS, KeyCode::key_t::KEYCODE_BASSBOOST }, + { KEYCODE_PRINT_ETS, KeyCode::key_t::KEYCODE_PRINT }, + { KEYCODE_CHAT_ETS, KeyCode::key_t::KEYCODE_CHAT }, + { KEYCODE_FINANCE_ETS, KeyCode::key_t::KEYCODE_FINANCE }, + { KEYCODE_CANCEL_ETS, KeyCode::key_t::KEYCODE_CANCEL }, + { KEYCODE_KBDILLUM_TOGGLE_ETS, KeyCode::key_t::KEYCODE_KBDILLUM_TOGGLE }, + { KEYCODE_KBDILLUM_DOWN_ETS, KeyCode::key_t::KEYCODE_KBDILLUM_DOWN }, + { KEYCODE_KBDILLUM_UP_ETS, KeyCode::key_t::KEYCODE_KBDILLUM_UP }, + { KEYCODE_SEND_ETS, KeyCode::key_t::KEYCODE_SEND }, + { KEYCODE_REPLY_ETS, KeyCode::key_t::KEYCODE_REPLY }, + { KEYCODE_FORWARDMAIL_ETS, KeyCode::key_t::KEYCODE_FORWARDMAIL }, + { KEYCODE_SAVE_ETS, KeyCode::key_t::KEYCODE_SAVE }, + { KEYCODE_DOCUMENTS_ETS, KeyCode::key_t::KEYCODE_DOCUMENTS }, + { KEYCODE_VIDEO_NEXT_ETS, KeyCode::key_t::KEYCODE_VIDEO_NEXT }, + { KEYCODE_VIDEO_PREV_ETS, KeyCode::key_t::KEYCODE_VIDEO_PREV }, + { KEYCODE_BRIGHTNESS_CYCLE_ETS, KeyCode::key_t::KEYCODE_BRIGHTNESS_CYCLE }, + { KEYCODE_BRIGHTNESS_ZERO_ETS, KeyCode::key_t::KEYCODE_BRIGHTNESS_ZERO }, + { KEYCODE_DISPLAY_OFF_ETS, KeyCode::key_t::KEYCODE_DISPLAY_OFF }, + { KEYCODE_BTN_MISC_ETS, KeyCode::key_t::KEYCODE_BTN_MISC }, + { KEYCODE_GOTO_ETS, KeyCode::key_t::KEYCODE_GOTO }, + { KEYCODE_INFO_ETS, KeyCode::key_t::KEYCODE_INFO }, + { KEYCODE_PROGRAM_ETS, KeyCode::key_t::KEYCODE_PROGRAM }, + { KEYCODE_PVR_ETS, KeyCode::key_t::KEYCODE_PVR }, + { KEYCODE_SUBTITLE_ETS, KeyCode::key_t::KEYCODE_SUBTITLE }, + { KEYCODE_FULL_SCREEN_ETS, KeyCode::key_t::KEYCODE_FULL_SCREEN }, + { KEYCODE_KEYBOARD_ETS, KeyCode::key_t::KEYCODE_KEYBOARD }, + { KEYCODE_ASPECT_RATIO_ETS, KeyCode::key_t::KEYCODE_ASPECT_RATIO }, + { KEYCODE_PC_ETS, KeyCode::key_t::KEYCODE_PC }, + { KEYCODE_TV_ETS, KeyCode::key_t::KEYCODE_TV }, + { KEYCODE_TV2_ETS, KeyCode::key_t::KEYCODE_TV2 }, + { KEYCODE_VCR_ETS, KeyCode::key_t::KEYCODE_VCR }, + { KEYCODE_VCR2_ETS, KeyCode::key_t::KEYCODE_VCR2 }, + { KEYCODE_SAT_ETS, KeyCode::key_t::KEYCODE_SAT }, + { KEYCODE_CD_ETS, KeyCode::key_t::KEYCODE_CD }, + { KEYCODE_TAPE_ETS, KeyCode::key_t::KEYCODE_TAPE }, + { KEYCODE_TUNER_ETS, KeyCode::key_t::KEYCODE_TUNER }, + { KEYCODE_PLAYER_ETS, KeyCode::key_t::KEYCODE_PLAYER }, + { KEYCODE_DVD_ETS, KeyCode::key_t::KEYCODE_DVD }, + { KEYCODE_AUDIO_ETS, KeyCode::key_t::KEYCODE_AUDIO }, + { KEYCODE_VIDEO_ETS, KeyCode::key_t::KEYCODE_VIDEO }, + { KEYCODE_MEMO_ETS, KeyCode::key_t::KEYCODE_MEMO }, + { KEYCODE_CALENDAR_ETS, KeyCode::key_t::KEYCODE_CALENDAR }, + { KEYCODE_RED_ETS, KeyCode::key_t::KEYCODE_RED }, + { KEYCODE_GREEN_ETS, KeyCode::key_t::KEYCODE_GREEN }, + { KEYCODE_YELLOW_ETS, KeyCode::key_t::KEYCODE_YELLOW }, + { KEYCODE_BLUE_ETS, KeyCode::key_t::KEYCODE_BLUE }, + { KEYCODE_CHANNELUP_ETS, KeyCode::key_t::KEYCODE_CHANNELUP }, + { KEYCODE_CHANNELDOWN_ETS, KeyCode::key_t::KEYCODE_CHANNELDOWN }, + { KEYCODE_LAST_ETS, KeyCode::key_t::KEYCODE_LAST }, + { KEYCODE_RESTART_ETS, KeyCode::key_t::KEYCODE_RESTART }, + { KEYCODE_SLOW_ETS, KeyCode::key_t::KEYCODE_SLOW }, + { KEYCODE_SHUFFLE_ETS, KeyCode::key_t::KEYCODE_SHUFFLE }, + { KEYCODE_VIDEOPHONE_ETS, KeyCode::key_t::KEYCODE_VIDEOPHONE }, + { KEYCODE_GAMES_ETS, KeyCode::key_t::KEYCODE_GAMES }, + { KEYCODE_ZOOMIN_ETS, KeyCode::key_t::KEYCODE_ZOOMIN }, + { KEYCODE_ZOOMOUT_ETS, KeyCode::key_t::KEYCODE_ZOOMOUT }, + { KEYCODE_ZOOMRESET_ETS, KeyCode::key_t::KEYCODE_ZOOMRESET }, + { KEYCODE_WORDPROCESSOR_ETS, KeyCode::key_t::KEYCODE_WORDPROCESSOR }, + { KEYCODE_EDITOR_ETS, KeyCode::key_t::KEYCODE_EDITOR }, + { KEYCODE_SPREADSHEET_ETS, KeyCode::key_t::KEYCODE_SPREADSHEET }, + { KEYCODE_GRAPHICSEDITOR_ETS, KeyCode::key_t::KEYCODE_GRAPHICSEDITOR }, + { KEYCODE_PRESENTATION_ETS, KeyCode::key_t::KEYCODE_PRESENTATION }, + { KEYCODE_DATABASE_ETS, KeyCode::key_t::KEYCODE_DATABASE }, + { KEYCODE_NEWS_ETS, KeyCode::key_t::KEYCODE_NEWS }, + { KEYCODE_VOICEMAIL_ETS, KeyCode::key_t::KEYCODE_VOICEMAIL }, + { KEYCODE_ADDRESSBOOK_ETS, KeyCode::key_t::KEYCODE_ADDRESSBOOK }, + { KEYCODE_MESSENGER_ETS, KeyCode::key_t::KEYCODE_MESSENGER }, + { KEYCODE_BRIGHTNESS_TOGGLE_ETS, KeyCode::key_t::KEYCODE_BRIGHTNESS_TOGGLE }, + { KEYCODE_SPELLCHECK_ETS, KeyCode::key_t::KEYCODE_SPELLCHECK }, + { KEYCODE_COFFEE_ETS, KeyCode::key_t::KEYCODE_COFFEE }, + { KEYCODE_MEDIA_REPEAT_ETS, KeyCode::key_t::KEYCODE_MEDIA_REPEAT }, + { KEYCODE_IMAGES_ETS, KeyCode::key_t::KEYCODE_IMAGES }, + { KEYCODE_BUTTONCONFIG_ETS, KeyCode::key_t::KEYCODE_BUTTONCONFIG }, + { KEYCODE_TASKMANAGER_ETS, KeyCode::key_t::KEYCODE_TASKMANAGER }, + { KEYCODE_JOURNAL_ETS, KeyCode::key_t::KEYCODE_JOURNAL }, + { KEYCODE_CONTROLPANEL_ETS, KeyCode::key_t::KEYCODE_CONTROLPANEL }, + { KEYCODE_APPSELECT_ETS, KeyCode::key_t::KEYCODE_APPSELECT }, + { KEYCODE_SCREENSAVER_ETS, KeyCode::key_t::KEYCODE_SCREENSAVER }, + { KEYCODE_ASSISTANT_ETS, KeyCode::key_t::KEYCODE_ASSISTANT }, + { KEYCODE_KBD_LAYOUT_NEXT_ETS, KeyCode::key_t::KEYCODE_KBD_LAYOUT_NEXT }, + { KEYCODE_BRIGHTNESS_MIN_ETS, KeyCode::key_t::KEYCODE_BRIGHTNESS_MIN }, + { KEYCODE_BRIGHTNESS_MAX_ETS, KeyCode::key_t::KEYCODE_BRIGHTNESS_MAX }, + { KEYCODE_KBDINPUTASSIST_PREV_ETS, KeyCode::key_t::KEYCODE_KBDINPUTASSIST_PREV }, + { KEYCODE_KBDINPUTASSIST_NEXT_ETS, KeyCode::key_t::KEYCODE_KBDINPUTASSIST_NEXT }, + { KEYCODE_KBDINPUTASSIST_PREVGROUP_ETS, KeyCode::key_t::KEYCODE_KBDINPUTASSIST_PREVGROUP }, + { KEYCODE_KBDINPUTASSIST_NEXTGROUP_ETS, KeyCode::key_t::KEYCODE_KBDINPUTASSIST_NEXTGROUP }, + { KEYCODE_KBDINPUTASSIST_ACCEPT_ETS, KeyCode::key_t::KEYCODE_KBDINPUTASSIST_ACCEPT }, + { KEYCODE_KBDINPUTASSIST_CANCEL_ETS, KeyCode::key_t::KEYCODE_KBDINPUTASSIST_CANCEL }, + { KEYCODE_FRONT_ETS, KeyCode::key_t::KEYCODE_FRONT }, + { KEYCODE_SETUP_ETS, KeyCode::key_t::KEYCODE_SETUP }, + { KEYCODE_WAKEUP_ETS, KeyCode::key_t::KEYCODE_WAKEUP }, + { KEYCODE_SENDFILE_ETS, KeyCode::key_t::KEYCODE_SENDFILE }, + { KEYCODE_DELETEFILE_ETS, KeyCode::key_t::KEYCODE_DELETEFILE }, + { KEYCODE_XFER_ETS, KeyCode::key_t::KEYCODE_XFER }, + { KEYCODE_PROG1_ETS, KeyCode::key_t::KEYCODE_PROG1 }, + { KEYCODE_PROG2_ETS, KeyCode::key_t::KEYCODE_PROG2 }, + { KEYCODE_MSDOS_ETS, KeyCode::key_t::KEYCODE_MSDOS }, + { KEYCODE_SCREENLOCK_ETS, KeyCode::key_t::KEYCODE_SCREENLOCK }, + { KEYCODE_DIRECTION_ROTATE_DISPLAY_ETS, KeyCode::key_t::KEYCODE_DIRECTION_ROTATE_DISPLAY }, + { KEYCODE_CYCLEWINDOWS_ETS, KeyCode::key_t::KEYCODE_CYCLEWINDOWS }, + { KEYCODE_COMPUTER_ETS, KeyCode::key_t::KEYCODE_COMPUTER }, + { KEYCODE_EJECTCLOSECD_ETS, KeyCode::key_t::KEYCODE_EJECTCLOSECD }, + { KEYCODE_ISO_ETS, KeyCode::key_t::KEYCODE_ISO }, + { KEYCODE_MOVE_ETS, KeyCode::key_t::KEYCODE_MOVE }, + { KEYCODE_F13_ETS, KeyCode::key_t::KEYCODE_F13 }, + { KEYCODE_F14_ETS, KeyCode::key_t::KEYCODE_F14 }, + { KEYCODE_F15_ETS, KeyCode::key_t::KEYCODE_F15 }, + { KEYCODE_F16_ETS, KeyCode::key_t::KEYCODE_F16 }, + { KEYCODE_F17_ETS, KeyCode::key_t::KEYCODE_F17 }, + { KEYCODE_F18_ETS, KeyCode::key_t::KEYCODE_F18 }, + { KEYCODE_F19_ETS, KeyCode::key_t::KEYCODE_F19 }, + { KEYCODE_F20_ETS, KeyCode::key_t::KEYCODE_F20 }, + { KEYCODE_F21_ETS, KeyCode::key_t::KEYCODE_F21 }, + { KEYCODE_F22_ETS, KeyCode::key_t::KEYCODE_F22 }, + { KEYCODE_F23_ETS, KeyCode::key_t::KEYCODE_F23 }, + { KEYCODE_F24_ETS, KeyCode::key_t::KEYCODE_F24 }, + { KEYCODE_PROG3_ETS, KeyCode::key_t::KEYCODE_PROG3 }, + { KEYCODE_PROG4_ETS, KeyCode::key_t::KEYCODE_PROG4 }, + { KEYCODE_DASHBOARD_ETS, KeyCode::key_t::KEYCODE_DASHBOARD }, + { KEYCODE_SUSPEND_ETS, KeyCode::key_t::KEYCODE_SUSPEND }, + { KEYCODE_HP_ETS, KeyCode::key_t::KEYCODE_HP }, + { KEYCODE_SOUND_ETS, KeyCode::key_t::KEYCODE_SOUND }, + { KEYCODE_QUESTION_ETS, KeyCode::key_t::KEYCODE_QUESTION }, + { KEYCODE_CONNECT_ETS, KeyCode::key_t::KEYCODE_CONNECT }, + { KEYCODE_SPORT_ETS, KeyCode::key_t::KEYCODE_SPORT }, + { KEYCODE_SHOP_ETS, KeyCode::key_t::KEYCODE_SHOP }, + { KEYCODE_ALTERASE_ETS, KeyCode::key_t::KEYCODE_ALTERASE }, + { KEYCODE_SWITCHVIDEOMODE_ETS, KeyCode::key_t::KEYCODE_SWITCHVIDEOMODE }, + { KEYCODE_BATTERY_ETS, KeyCode::key_t::KEYCODE_BATTERY }, + { KEYCODE_BLUETOOTH_ETS, KeyCode::key_t::KEYCODE_BLUETOOTH }, + { KEYCODE_WLAN_ETS, KeyCode::key_t::KEYCODE_WLAN }, + { KEYCODE_UWB_ETS, KeyCode::key_t::KEYCODE_UWB }, + { KEYCODE_WWAN_WIMAX_ETS, KeyCode::key_t::KEYCODE_WWAN_WIMAX }, + { KEYCODE_RFKILL_ETS, KeyCode::key_t::KEYCODE_RFKILL }, + { KEYCODE_CHANNEL_ETS, KeyCode::key_t::KEYCODE_CHANNEL }, + { KEYCODE_BTN_0_ETS, KeyCode::key_t::KEYCODE_BTN_0 }, + { KEYCODE_BTN_1_ETS, KeyCode::key_t::KEYCODE_BTN_1 }, + { KEYCODE_BTN_2_ETS, KeyCode::key_t::KEYCODE_BTN_2 }, + { KEYCODE_BTN_3_ETS, KeyCode::key_t::KEYCODE_BTN_3 }, + { KEYCODE_BTN_4_ETS, KeyCode::key_t::KEYCODE_BTN_4 }, + { KEYCODE_BTN_5_ETS, KeyCode::key_t::KEYCODE_BTN_5 }, + { KEYCODE_BTN_6_ETS, KeyCode::key_t::KEYCODE_BTN_6 }, + { KEYCODE_BTN_7_ETS, KeyCode::key_t::KEYCODE_BTN_7 }, + { KEYCODE_BTN_8_ETS, KeyCode::key_t::KEYCODE_BTN_8 }, + { KEYCODE_BTN_9_ETS, KeyCode::key_t::KEYCODE_BTN_9 }, + { KEYCODE_DAGGER_CLICK_ETS, KeyCode::key_t::KEYCODE_DAGGER_CLICK }, + { KEYCODE_DAGGER_DOUBLE_CLICK_ETS, KeyCode::key_t::KEYCODE_DAGGER_DOUBLE_CLICK }, + { KEYCODE_DAGGER_LONG_PRESS_ETS, KeyCode::key_t::KEYCODE_DAGGER_LONG_PRESS } +}; + +KeyCode ConvertEtsKeyCode(int32_t keyCode) +{ + auto iter = KEY_CODE_TRANSFORMATION.find(keyCode); + if (iter == KEY_CODE_TRANSFORMATION.end()) { + MMI_HILOGE("Find failed, keyCode:%{public}d", keyCode); + return KeyCode::key_t::KEYCODE_UNKNOWN; + } + return iter->second; +} + +} // namespace MMI +} // namespace OHOS + +// Since these macros are auto-generate, }, lint will cause false positive. +// NOLINTBEGIN +// NOLINTEND \ No newline at end of file diff --git a/frameworks/ets/key_event/BUILD.gn b/frameworks/ets/key_event/BUILD.gn new file mode 100644 index 0000000000..a6d3dc7ccb --- /dev/null +++ b/frameworks/ets/key_event/BUILD.gn @@ -0,0 +1,95 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/components/ets_frontend/ets2abc_config.gni") +import("//build/ohos.gni") +import("//build/ohos/taihe_idl/taihe.gni") +import("//foundation/multimodalinput/input/multimodalinput_mini.gni") +copy_taihe_idl("key_event_taihe") { + sources = [ "idl/ohos.multimodalInput.keyEvent.taihe" ] + deps = [ + "${mmi_path}/frameworks/ets/input_event:input_event_taihe", + "${mmi_path}/frameworks/ets/key_code:key_code_taihe", + ] +} +config("keyEvent_config") { + visibility = [ ":*" ] + + include_dirs = [ + "${mmi_path}/util/common/include", + "${mmi_path}/tools/event_inject/include", + "${mmi_path}/interfaces/kits/c/input", + "${mmi_path}/interfaces/native/innerkits/proxy/include", + ] +} +subsystem_name = "multimodalinput" +part_name = "input" +taihe_generated_file_path_keyEvent = "$taihe_file_path/out/$subsystem_name/$part_name/keyEvent" +ohos_taihe("run_taihe") { + taihe_generated_file_path = "${taihe_generated_file_path_keyEvent}" + deps = [ ":key_event_taihe" ] + outputs = [ + "$taihe_generated_file_path/src/ohos.multimodalInput.keyEvent.ani.cpp", + "$taihe_generated_file_path/src/ohos.multimodalInput.keyEvent.abi.c", + ] +} +taihe_shared_library("KeyEvent") { + taihe_generated_file_path = "${taihe_generated_file_path_keyEvent}" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + sources = get_target_outputs(":run_taihe") + configs = [ + "${mmi_path}:coverage_flags", + ":keyEvent_config", + ] + sources += [ + "src/ani_constructor.cpp", + "src/ohos.multimodalInput.keyEvent.impl.cpp", + ] + deps = [ + ":run_taihe", + "${mmi_path}/frameworks/proxy:libmmi-client", + "${mmi_path}/util:libmmi-util", + ] + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + ] + branch_protector_ret = "pac_ret" + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } +} +generate_static_abc("key_event") { + base_url = "${taihe_generated_file_path_keyEvent}" + files = [ "${taihe_generated_file_path_keyEvent}/@ohos.multimodalInput.keyEvent.ets" ] + is_boot_abc = "True" + device_dst_file = "/system/framework/key_event.abc" + dependencies = [ ":run_taihe" ] +} +ohos_prebuilt_etc("key_event_etc") { + source = "$target_out_dir/key_event.abc" + module_install_dir = "framework" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + deps = [ ":key_event" ] +} +group("ets_keyEvent_package") { + deps = [ + ":key_event_etc", + ":KeyEvent", + ] +} \ No newline at end of file diff --git a/frameworks/ets/key_event/idl/ohos.multimodalInput.keyEvent.taihe b/frameworks/ets/key_event/idl/ohos.multimodalInput.keyEvent.taihe new file mode 100644 index 0000000000..d4f2c0b523 --- /dev/null +++ b/frameworks/ets/key_event/idl/ohos.multimodalInput.keyEvent.taihe @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@!namespace("@ohos.multimodalInput.keyEvent") +from ohos.multimodalInput.inputEvent use InputEvent; +from ohos.multimodalInput.keyCode use KeyCode; +@!sts_inject(""" + loadLibrary("KeyEvent.z") +""") + +enum Action : i32 { + CANCEL = 0, + DOWN = 1, + UP = 2 +} + +struct Key { + code: KeyCode; + pressedTime: i64; + deviceId: i32; +} + +struct KeyEvent { + @extends base: InputEvent; + action: Action; + key: Key; + unicodeChar: i32; + keys: Array; + ctrlKey: bool; + altKey: bool; + shiftKey: bool; + logoKey: bool; + fnKey: bool; + capsLock: bool; + numLock: bool; + scrollLock: bool; +} \ No newline at end of file diff --git a/frameworks/ets/key_event/src/ani_constructor.cpp b/frameworks/ets/key_event/src/ani_constructor.cpp new file mode 100644 index 0000000000..de0a5c11be --- /dev/null +++ b/frameworks/ets/key_event/src/ani_constructor.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ohos.multimodalInput.keyEvent.ani.hpp" +ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) +{ + ani_env *env; + if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) { + return ANI_ERROR; + } + if (ANI_OK != ohos::multimodalInput::keyEvent::ANIRegister(env)) { + std::cerr << "Error from ohos::multimodalInput::keyEvent::ANIRegister" << std::endl; + return ANI_ERROR; + } + *result = ANI_VERSION_1; + return ANI_OK; +} \ No newline at end of file diff --git a/frameworks/ets/key_event/src/ohos.multimodalInput.keyEvent.impl.cpp b/frameworks/ets/key_event/src/ohos.multimodalInput.keyEvent.impl.cpp new file mode 100644 index 0000000000..8be68ba59d --- /dev/null +++ b/frameworks/ets/key_event/src/ohos.multimodalInput.keyEvent.impl.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ohos.multimodalInput.keyEvent.proj.hpp" +#include "ohos.multimodalInput.keyEvent.impl.hpp" +#include "taihe/runtime.hpp" +#include "stdexcept" + +using namespace taihe; +using namespace ohos::multimodalInput::keyEvent; + +namespace { +} // namespace + +// Since these macros are auto-generate, lint will cause false positive. +// NOLINTBEGIN +// NOLINTEND \ No newline at end of file diff --git a/frameworks/ets/mouse_event/BUILD.gn b/frameworks/ets/mouse_event/BUILD.gn new file mode 100644 index 0000000000..fe41b316f1 --- /dev/null +++ b/frameworks/ets/mouse_event/BUILD.gn @@ -0,0 +1,93 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/components/ets_frontend/ets2abc_config.gni") +import("//build/ohos.gni") +import("//build/ohos/taihe_idl/taihe.gni") +import("//foundation/multimodalinput/input/multimodalinput_mini.gni") +copy_taihe_idl("mouse_event_taihe") { + sources = [ "idl/ohos.multimodalInput.mouseEvent.taihe" ] + deps = [ + "${mmi_path}/frameworks/ets/input_event:input_event_taihe", + "${mmi_path}/frameworks/ets/key_code:key_code_taihe", + ] +} +config("mouseEvent_config") { + visibility = [ ":*" ] + + include_dirs = [ + "${mmi_path}/util/common/include", + "${mmi_path}/util/network/include", + ] +} +subsystem_name = "multimodalinput" +part_name = "input" +taihe_generated_file_path_mouseEvent = "$taihe_file_path/out/$subsystem_name/$part_name/mouseEvent" +ohos_taihe("run_taihe") { + taihe_generated_file_path = "${taihe_generated_file_path_mouseEvent}" + deps = [ ":mouse_event_taihe" ] + outputs = [ + "$taihe_generated_file_path/src/ohos.multimodalInput.mouseEvent.ani.cpp", + "$taihe_generated_file_path/src/ohos.multimodalInput.mouseEvent.abi.c", + ] +} +taihe_shared_library("MouseEvent") { + taihe_generated_file_path = "${taihe_generated_file_path_mouseEvent}" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + sources = get_target_outputs(":run_taihe") + configs = [ + "${mmi_path}:coverage_flags", + ":mouseEvent_config", + ] + sources += [ + "src/ani_constructor.cpp", + "src/ohos.multimodalInput.mouseEvent.impl.cpp", + ] + deps = [ + ":run_taihe", + "${mmi_path}/frameworks/proxy:libmmi-client", + "${mmi_path}/util:libmmi-util", + ] + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + ] + branch_protector_ret = "pac_ret" + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } +} +generate_static_abc("mouse_event") { + base_url = "${taihe_generated_file_path_mouseEvent}" + files = [ "${taihe_generated_file_path_mouseEvent}/@ohos.multimodalInput.mouseEvent.ets" ] + is_boot_abc = "True" + device_dst_file = "/system/framework/mouse_event.abc" + dependencies = [ ":run_taihe" ] +} +ohos_prebuilt_etc("mouse_event_etc") { + source = "$target_out_dir/mouse_event.abc" + module_install_dir = "framework" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + deps = [ ":mouse_event" ] +} +group("ets_mouseEvent_package") { + deps = [ + ":mouse_event_etc", + ":MouseEvent", + ] +} \ No newline at end of file diff --git a/frameworks/ets/mouse_event/idl/ohos.multimodalInput.mouseEvent.taihe b/frameworks/ets/mouse_event/idl/ohos.multimodalInput.mouseEvent.taihe new file mode 100644 index 0000000000..552f71172d --- /dev/null +++ b/frameworks/ets/mouse_event/idl/ohos.multimodalInput.mouseEvent.taihe @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@!namespace("@ohos.multimodalInput.mouseEvent") +from ohos.multimodalInput.inputEvent use InputEvent; +from ohos.multimodalInput.keyCode use KeyCode; +@!sts_inject(""" + loadLibrary("MouseEvent.z") +""") + +enum Action : i32 { + CANCEL = 0, + MOVE = 1, + BUTTON_DOWN = 2, + BUTTON_UP = 3, + AXIS_BEGIN = 4, + AXIS_UPDATE = 5, + AXIS_END = 6, + ACTION_DOWN = 7, + ACTION_UP = 8, +} + +enum Button : i32 { + LEFT = 0, + MIDDLE = 1, + RIGHT = 2, + SIDE = 3, + EXTRA = 4, + FORWARD = 5, + BACK = 6, + TASK = 7 +} + +enum Axis : i32 { + SCROLL_VERTICAL = 0, + SCROLL_HORIZONTAL = 1, + PINCH = 2 +} + +struct AxisValue { + axis: Axis; + value: i32; +} + +enum ToolType : i32 { + UNKNOWN = 0, + MOUSE = 1, + JOYSTICK = 2, + TOUCHPAD = 3, +} + +struct MouseEvent { + @extends base:InputEvent; + action: Action; + screenX: i32; + screenY: i32; + windowX: i32; + windowY: i32; + rawDeltaX: i32; + rawDeltaY: i32; + button: Button; + pressedButtons: Array