From b2022db1cae9fada2db3b66372dbbcdb718fb65d Mon Sep 17 00:00:00 2001 From: openharmony_ci <120357966@qq.com> Date: Wed, 11 Oct 2023 10:55:38 +0000 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E9=80=80=20'Pull=20Request=20!2785=20?= =?UTF-8?q?:=20=E4=BF=AE=E6=94=B9js=5Finput=5Fmonitor=E4=B8=AD=E9=92=88?= =?UTF-8?q?=E5=AF=B9touchevent=E7=9A=84js=E8=BD=AC=E6=8D=A2=E5=87=BD?= =?UTF-8?q?=E6=95=B0'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/napi/input_monitor/BUILD.gn | 1 - .../input_monitor/include/js_input_monitor.h | 4 +- .../input_monitor/src/js_input_monitor.cpp | 108 ++++++++++-------- .../napi/touch_event/include/js_touch_event.h | 23 ---- .../napi/touch_event/src/js_touch_event.cpp | 24 ++++ 5 files changed, 87 insertions(+), 73 deletions(-) diff --git a/frameworks/napi/input_monitor/BUILD.gn b/frameworks/napi/input_monitor/BUILD.gn index 641bf4bba1..8e45d63255 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 f8a1158012..8578baa67e 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 8d2dc320a3..059335124a 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