diff --git a/frameworks/napi/input_monitor/BUILD.gn b/frameworks/napi/input_monitor/BUILD.gn index 641bf4bba1fd2b14a8bf80a4664edc8339f04b9a..8e45d6325519d58eafe2ad02122aec55417c36f1 100644 --- a/frameworks/napi/input_monitor/BUILD.gn +++ b/frameworks/napi/input_monitor/BUILD.gn @@ -20,7 +20,6 @@ config("inputmonitor_config") { "${mmi_path}/frameworks/napi/input_monitor/include", "${mmi_path}/util/common/include", "${mmi_path}/interfaces/native/innerkits/proxy/include", - "${mmi_path}/frameworks/napi/touch_event/include", ] defines = input_default_defines diff --git a/frameworks/napi/input_monitor/include/js_input_monitor.h b/frameworks/napi/input_monitor/include/js_input_monitor.h index f8a115801218218ab0d78a4a8ddad2e6335bc44f..8578baa67eb120f163e82d1c40eb456dd026a852 100644 --- a/frameworks/napi/input_monitor/include/js_input_monitor.h +++ b/frameworks/napi/input_monitor/include/js_input_monitor.h @@ -28,7 +28,6 @@ #include "util_napi.h" #include "i_input_event_consumer.h" -#include "js_touch_event.h" namespace OHOS { namespace MMI { @@ -82,8 +81,7 @@ public: private: void SetCallback(napi_value callback); int32_t TransformPointerEvent(const std::shared_ptr pointerEvent, napi_value result); - int32_t GetAction(int32_t action) const; - int32_t GetSourceType(int32_t sourceType) const; + std::string GetAction(int32_t action) const; int32_t GetPinchAction(int32_t action) const; int32_t GetSwipeAction(int32_t action) const; int32_t GetJsPointerItem(const PointerEvent::PointerItem &item, napi_value value) const; diff --git a/frameworks/napi/input_monitor/src/js_input_monitor.cpp b/frameworks/napi/input_monitor/src/js_input_monitor.cpp index 8d2dc320a31e462226bd8d11d3ad7bed294e9a86..059335124ac0fb0d5b451912513cb97c91cd74dd 100644 --- a/frameworks/napi/input_monitor/src/js_input_monitor.cpp +++ b/frameworks/napi/input_monitor/src/js_input_monitor.cpp @@ -259,74 +259,62 @@ int32_t JsInputMonitor::IsMatch(napi_env jsEnv) return RET_ERR; } -int32_t JsInputMonitor::GetAction(int32_t action) const +std::string JsInputMonitor::GetAction(int32_t action) const { switch (action) { case PointerEvent::POINTER_ACTION_CANCEL: { - return static_cast(JsTouchEvent::Action::CANCEL); + return "cancel"; } case PointerEvent::POINTER_ACTION_DOWN: { - return static_cast(JsTouchEvent::Action::DOWN); + return "down"; } case PointerEvent::POINTER_ACTION_MOVE: { - return static_cast(JsTouchEvent::Action::MOVE); + return "move"; } case PointerEvent::POINTER_ACTION_UP: { - return static_cast(JsTouchEvent::Action::UP); + return "up"; } default: { - return RET_ERR; - } - } -} - -int32_t JsInputMonitor::GetSourceType(int32_t sourceType) const -{ - switch (sourceType) { - case PointerEvent::SOURCE_TYPE_TOUCHSCREEN: { - return static_cast(JsTouchEvent::SourceType::TOUCH_SCREEN); - } - case PointerEvent::SOURCE_TYPE_TOUCHPAD: { - return static_cast(JsTouchEvent::SourceType::TOUCH_PAD); - } - default: { - return RET_ERR; + return ""; } } } int32_t JsInputMonitor::GetJsPointerItem(const PointerEvent::PointerItem &item, napi_value value) const { - CHKRR(SetNameProperty(jsEnv_, value, "id", item.GetPointerId()), "Set id", RET_ERR); - CHKRR(SetNameProperty(jsEnv_, value, "pressedTime", item.GetDownTime()), "Set pressedTime", RET_ERR); - CHKRR(SetNameProperty(jsEnv_, value, "screenX", item.GetDisplayX()), "Set screenX", RET_ERR); - CHKRR(SetNameProperty(jsEnv_, value, "screenY", item.GetDisplayY()), "Set screenY", RET_ERR); - CHKRR(SetNameProperty(jsEnv_, value, "windowX", item.GetWindowX()), "Set windowX", RET_ERR); - CHKRR(SetNameProperty(jsEnv_, value, "windowY", item.GetWindowY()), "Set windowY", RET_ERR); - CHKRR(SetNameProperty(jsEnv_, value, "pressure", item.GetPressure()), "Set pressure", RET_ERR); - CHKRR(SetNameProperty(jsEnv_, value, "width", item.GetWidth()), "Set width", RET_ERR); - CHKRR(SetNameProperty(jsEnv_, value, "height", item.GetHeight()), "Set height", RET_ERR); - CHKRR(SetNameProperty(jsEnv_, value, "tiltX", item.GetTiltX()), "Set tiltX", RET_ERR); - CHKRR(SetNameProperty(jsEnv_, value, "tiltY", item.GetTiltY()), "Set tiltY", RET_ERR); - CHKRR(SetNameProperty(jsEnv_, value, "toolX", item.GetToolDisplayX()), "Set toolX", RET_ERR); - CHKRR(SetNameProperty(jsEnv_, value, "toolY", item.GetToolDisplayY()), "Set toolY", RET_ERR); - CHKRR(SetNameProperty(jsEnv_, value, "toolWidth", item.GetToolWidth()), "Set toolWidth", RET_ERR); - CHKRR(SetNameProperty(jsEnv_, value, "toolHeight", item.GetToolHeight()), "Set toolHeight", RET_ERR); - CHKRR(SetNameProperty(jsEnv_, value, "rawX", item.GetRawDx()), "Set rawX", RET_ERR); - CHKRR(SetNameProperty(jsEnv_, value, "rawY", item.GetRawDy()), "Set rawY", RET_ERR); - CHKRR(SetNameProperty(jsEnv_, value, "toolType", item.GetToolType()), "Set toolType", RET_ERR); + if (SetNameProperty(jsEnv_, value, "globalX", item.GetDisplayX()) != napi_ok) { + MMI_HILOGE("Set globalX property failed"); + return RET_ERR; + } + if (SetNameProperty(jsEnv_, value, "globalY", item.GetDisplayY()) != napi_ok) { + MMI_HILOGE("Set globalY property failed"); + return RET_ERR; + } + if (SetNameProperty(jsEnv_, value, "localX", 0) != napi_ok) { + MMI_HILOGE("Set localX property failed"); + return RET_ERR; + } + if (SetNameProperty(jsEnv_, value, "localY", 0) != napi_ok) { + MMI_HILOGE("Set localY property failed"); + return RET_ERR; + } + int32_t touchArea = (item.GetWidth() + item.GetHeight()) / 2; + if (SetNameProperty(jsEnv_, value, "size", touchArea) != napi_ok) { + MMI_HILOGE("Set size property failed"); + return RET_ERR; + } + if (SetNameProperty(jsEnv_, value, "force", item.GetPressure()) != napi_ok) { + MMI_HILOGE("Set force property failed"); + return RET_ERR; + } return RET_OK; } int32_t JsInputMonitor::TransformPointerEvent(const std::shared_ptr pointerEvent, napi_value result) { CHKPR(pointerEvent, ERROR_NULL_POINTER); - if (SetNameProperty(jsEnv_, result, "action", GetAction(pointerEvent->GetPointerAction())) != napi_ok) { - MMI_HILOGE("Set action property failed"); - return RET_ERR; - } - if (SetNameProperty(jsEnv_, result, "sourceType", GetSourceType(pointerEvent->GetSourceType())) != napi_ok) { - MMI_HILOGE("Set sourceType property failed"); + if (SetNameProperty(jsEnv_, result, "type", GetAction(pointerEvent->GetPointerAction())) != napi_ok) { + MMI_HILOGE("Set type property failed"); return RET_ERR; } napi_value pointers = nullptr; @@ -345,6 +333,8 @@ int32_t JsInputMonitor::TransformPointerEvent(const std::shared_ptrGetPointerId(); for (const auto &it : pointerItems) { napi_value element = nullptr; status = napi_create_object(jsEnv_, &element); @@ -352,6 +342,25 @@ int32_t JsInputMonitor::TransformPointerEvent(const std::shared_ptrGetActionTime()) != napi_ok) { + MMI_HILOGE("Set timestamp property failed"); + return RET_ERR; + } + if (SetNameProperty(jsEnv_, result, "deviceId", it.GetDeviceId()) != napi_ok) { + MMI_HILOGE("Set deviceId property failed"); + return RET_ERR; + } + } if (GetJsPointerItem(it, element) != RET_OK) { MMI_HILOGE("Transform pointerItem failed"); return RET_ERR; @@ -363,7 +372,14 @@ int32_t JsInputMonitor::TransformPointerEvent(const std::shared_ptr