diff --git a/adapter/ohos/entrance/mmi_event_convertor.cpp b/adapter/ohos/entrance/mmi_event_convertor.cpp index 5fac041735d1c3f5b854d35ca31002b62ef386de..552f83e8bc52983c194a512134830da2cf0b679f 100644 --- a/adapter/ohos/entrance/mmi_event_convertor.cpp +++ b/adapter/ohos/entrance/mmi_event_convertor.cpp @@ -27,6 +27,81 @@ constexpr int32_t ANGLE_90 = 90; constexpr int32_t ANGLE_180 = 180; constexpr int32_t ANGLE_270 = 270; constexpr double SIZE_DIVIDE = 2.0; + +TouchType ConvertTouchEventType(int32_t originAction) +{ + std::map actionMap = { + { OHOS::MMI::PointerEvent::POINTER_ACTION_CANCEL, TouchType::CANCEL }, + { OHOS::MMI::PointerEvent::POINTER_ACTION_DOWN, TouchType::DOWN }, + { OHOS::MMI::PointerEvent::POINTER_ACTION_MOVE, TouchType::MOVE }, + { OHOS::MMI::PointerEvent::POINTER_ACTION_UP, TouchType::UP }, + { OHOS::MMI::PointerEvent::POINTER_ACTION_PULL_DOWN, TouchType::PULL_DOWN }, + { OHOS::MMI::PointerEvent::POINTER_ACTION_PULL_MOVE, TouchType::PULL_MOVE }, + { OHOS::MMI::PointerEvent::POINTER_ACTION_PULL_UP, TouchType::PULL_UP }, + { OHOS::MMI::PointerEvent::POINTER_ACTION_PULL_IN_WINDOW, TouchType::PULL_IN_WINDOW }, + { OHOS::MMI::PointerEvent::POINTER_ACTION_PULL_OUT_WINDOW, TouchType::PULL_OUT_WINDOW }, + { OHOS::MMI::PointerEvent::POINTER_ACTION_HOVER_ENTER, TouchType::HOVER_ENTER }, + { OHOS::MMI::PointerEvent::POINTER_ACTION_HOVER_MOVE, TouchType::HOVER_MOVE }, + { OHOS::MMI::PointerEvent::POINTER_ACTION_HOVER_EXIT, TouchType::HOVER_EXIT }, + { OHOS::MMI::PointerEvent::POINTER_ACTION_HOVER_CANCEL, TouchType::HOVER_CANCEL }, + { OHOS::MMI::PointerEvent::POINTER_ACTION_PROXIMITY_IN, TouchType::PROXIMITY_IN }, + { OHOS::MMI::PointerEvent::POINTER_ACTION_PROXIMITY_OUT, TouchType::PROXIMITY_OUT }, + }; + auto typeIter = actionMap.find(originAction); + if (typeIter == actionMap.end()) { + return TouchType::UNKNOWN; + } + return typeIter->second; +} + +MouseAction ConvertMouseEventAction(int32_t originAction) +{ + switch (originAction) { + case OHOS::MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN: + return MouseAction::PRESS; + case OHOS::MMI::PointerEvent::POINTER_ACTION_BUTTON_UP: + return MouseAction::RELEASE; + case OHOS::MMI::PointerEvent::POINTER_ACTION_ENTER_WINDOW: + return MouseAction::WINDOW_ENTER; + case OHOS::MMI::PointerEvent::POINTER_ACTION_LEAVE_WINDOW: + return MouseAction::WINDOW_LEAVE; + case OHOS::MMI::PointerEvent::POINTER_ACTION_MOVE: + return MouseAction::MOVE; + case OHOS::MMI::PointerEvent::POINTER_ACTION_PULL_DOWN: + return MouseAction::PRESS; + case OHOS::MMI::PointerEvent::POINTER_ACTION_PULL_MOVE: + return MouseAction::MOVE; + case OHOS::MMI::PointerEvent::POINTER_ACTION_PULL_IN_WINDOW: + return MouseAction::WINDOW_ENTER; + case OHOS::MMI::PointerEvent::POINTER_ACTION_PULL_OUT_WINDOW: + return MouseAction::WINDOW_LEAVE; + case OHOS::MMI::PointerEvent::POINTER_ACTION_PULL_UP: + return MouseAction::RELEASE; + case OHOS::MMI::PointerEvent::POINTER_ACTION_CANCEL: + return MouseAction::CANCEL; + default: + return MouseAction::NONE; + } +} + +AxisAction ConvertAxisEventAction(int32_t originAction) +{ + switch (originAction) { + case OHOS::MMI::PointerEvent::POINTER_ACTION_AXIS_BEGIN: + case OHOS::MMI::PointerEvent::POINTER_ACTION_ROTATE_BEGIN: + return AxisAction::BEGIN; + case OHOS::MMI::PointerEvent::POINTER_ACTION_AXIS_UPDATE: + case OHOS::MMI::PointerEvent::POINTER_ACTION_ROTATE_UPDATE: + return AxisAction::UPDATE; + case OHOS::MMI::PointerEvent::POINTER_ACTION_AXIS_END: + case OHOS::MMI::PointerEvent::POINTER_ACTION_ROTATE_END: + return AxisAction::END; + case OHOS::MMI::PointerEvent::POINTER_ACTION_CANCEL: + return AxisAction::CANCEL; + default: + return AxisAction::NONE; + } +} } // namespace SourceTool GetSourceTool(int32_t orgToolType) @@ -256,79 +331,38 @@ TouchEvent ConvertTouchEvent(const std::shared_ptr& pointerEv void SetTouchEventType(int32_t orgAction, TouchEvent& event) { - std::map actionMap = { - { OHOS::MMI::PointerEvent::POINTER_ACTION_CANCEL, TouchType::CANCEL }, - { OHOS::MMI::PointerEvent::POINTER_ACTION_DOWN, TouchType::DOWN }, - { OHOS::MMI::PointerEvent::POINTER_ACTION_MOVE, TouchType::MOVE }, - { OHOS::MMI::PointerEvent::POINTER_ACTION_UP, TouchType::UP }, - { OHOS::MMI::PointerEvent::POINTER_ACTION_PULL_DOWN, TouchType::PULL_DOWN }, - { OHOS::MMI::PointerEvent::POINTER_ACTION_PULL_MOVE, TouchType::PULL_MOVE }, - { OHOS::MMI::PointerEvent::POINTER_ACTION_PULL_UP, TouchType::PULL_UP }, - { OHOS::MMI::PointerEvent::POINTER_ACTION_PULL_IN_WINDOW, TouchType::PULL_IN_WINDOW }, - { OHOS::MMI::PointerEvent::POINTER_ACTION_PULL_OUT_WINDOW, TouchType::PULL_OUT_WINDOW }, - { OHOS::MMI::PointerEvent::POINTER_ACTION_HOVER_ENTER, TouchType::HOVER_ENTER }, - { OHOS::MMI::PointerEvent::POINTER_ACTION_HOVER_MOVE, TouchType::HOVER_MOVE }, - { OHOS::MMI::PointerEvent::POINTER_ACTION_HOVER_EXIT, TouchType::HOVER_EXIT }, - { OHOS::MMI::PointerEvent::POINTER_ACTION_HOVER_CANCEL, TouchType::HOVER_CANCEL }, - { OHOS::MMI::PointerEvent::POINTER_ACTION_PROXIMITY_IN, TouchType::PROXIMITY_IN }, - { OHOS::MMI::PointerEvent::POINTER_ACTION_PROXIMITY_OUT, TouchType::PROXIMITY_OUT }, - }; - auto typeIter = actionMap.find(orgAction); - if (typeIter == actionMap.end()) { - TAG_LOGI(AceLogTag::ACE_INPUTKEYFLOW, "unknown touch type"); + auto touchType = ConvertTouchEventType(orgAction); + if (touchType == TouchType::UNKNOWN) { + TAG_LOGE(AceLogTag::ACE_INPUTKEYFLOW, "unknown touch type"); return; } - event.type = typeIter->second; - if (typeIter->second == TouchType::PULL_DOWN || typeIter->second == TouchType::PULL_MOVE || - typeIter->second == TouchType::PULL_UP || typeIter->second == TouchType::PULL_IN_WINDOW || - typeIter->second == TouchType::PULL_OUT_WINDOW) { - event.pullType = typeIter->second; + event.type = touchType; + if (touchType == TouchType::PULL_DOWN || touchType == TouchType::PULL_MOVE || touchType == TouchType::PULL_UP || + touchType == TouchType::PULL_IN_WINDOW || touchType == TouchType::PULL_OUT_WINDOW) { + event.pullType = touchType; } } void GetMouseEventAction(int32_t action, MouseEvent& events, bool isSceneBoardWindow) { + events.action = ConvertMouseEventAction(action); switch (action) { - case OHOS::MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN: - events.action = MouseAction::PRESS; - break; - case OHOS::MMI::PointerEvent::POINTER_ACTION_BUTTON_UP: - events.action = MouseAction::RELEASE; - break; - case OHOS::MMI::PointerEvent::POINTER_ACTION_ENTER_WINDOW: - events.action = MouseAction::WINDOW_ENTER; - break; - case OHOS::MMI::PointerEvent::POINTER_ACTION_LEAVE_WINDOW: - events.action = MouseAction::WINDOW_LEAVE; - break; - case OHOS::MMI::PointerEvent::POINTER_ACTION_MOVE: - events.action = MouseAction::MOVE; - break; case OHOS::MMI::PointerEvent::POINTER_ACTION_PULL_DOWN: - events.action = MouseAction::PRESS; events.pullAction = MouseAction::PULL_DOWN; break; case OHOS::MMI::PointerEvent::POINTER_ACTION_PULL_MOVE: - events.action = MouseAction::MOVE; events.pullAction = MouseAction::PULL_MOVE; break; case OHOS::MMI::PointerEvent::POINTER_ACTION_PULL_IN_WINDOW: - events.action = MouseAction::WINDOW_ENTER; events.pullAction = MouseAction::PULL_MOVE; return; case OHOS::MMI::PointerEvent::POINTER_ACTION_PULL_OUT_WINDOW: - events.action = MouseAction::WINDOW_LEAVE; events.pullAction = MouseAction::PULL_MOVE; return; case OHOS::MMI::PointerEvent::POINTER_ACTION_PULL_UP: - events.action = MouseAction::RELEASE; events.pullAction = MouseAction::PULL_UP; break; - case OHOS::MMI::PointerEvent::POINTER_ACTION_CANCEL: - events.action = MouseAction::CANCEL; - break; default: - events.action = MouseAction::NONE; break; } } @@ -412,26 +446,7 @@ void ConvertMouseEvent( void GetAxisEventAction(int32_t action, AxisEvent& event) { - switch (action) { - case OHOS::MMI::PointerEvent::POINTER_ACTION_AXIS_BEGIN: - case OHOS::MMI::PointerEvent::POINTER_ACTION_ROTATE_BEGIN: - event.action = AxisAction::BEGIN; - break; - case OHOS::MMI::PointerEvent::POINTER_ACTION_AXIS_UPDATE: - case OHOS::MMI::PointerEvent::POINTER_ACTION_ROTATE_UPDATE: - event.action = AxisAction::UPDATE; - break; - case OHOS::MMI::PointerEvent::POINTER_ACTION_AXIS_END: - case OHOS::MMI::PointerEvent::POINTER_ACTION_ROTATE_END: - event.action = AxisAction::END; - break; - case OHOS::MMI::PointerEvent::POINTER_ACTION_CANCEL: - event.action = AxisAction::CANCEL; - break; - default: - event.action = AxisAction::NONE; - break; - } + event.action = ConvertAxisEventAction(action); } void GetNonPointerAxisEventAction(int32_t action, NG::FocusAxisEvent& event) @@ -971,4 +986,25 @@ void CalculateWindowCoordinate(const NG::OffsetF& offsetF, const std::shared_ptr point->UpdatePointerItem(id, item); } } + +TouchType GetTouchTypeFromPointerEvent(const std::shared_ptr& pointerEvent) +{ + CHECK_NULL_RETURN(pointerEvent, TouchType::UNKNOWN); + auto pointerAction = pointerEvent->GetPointerAction(); + return ConvertTouchEventType(pointerAction); +} + +AxisAction GetAxisActionFromPointerEvent(const std::shared_ptr& pointerEvent) +{ + CHECK_NULL_RETURN(pointerEvent, AxisAction::NONE); + auto pointerAction = pointerEvent->GetPointerAction(); + return ConvertAxisEventAction(pointerAction); +} + +MouseAction GetMouseActionFromPointerEvent(const std::shared_ptr& pointerEvent) +{ + CHECK_NULL_RETURN(pointerEvent, MouseAction::NONE); + auto pointerAction = pointerEvent->GetPointerAction(); + return ConvertMouseEventAction(pointerAction); +} } // namespace OHOS::Ace::Platform diff --git a/adapter/ohos/entrance/mmi_event_convertor.h b/adapter/ohos/entrance/mmi_event_convertor.h index 10a8b88aaa3f7995c9bfa6f09214fa23b0ef19d6..f0678b2ee2f6d5edf7a094becdcbc36f902b587b 100644 --- a/adapter/ohos/entrance/mmi_event_convertor.h +++ b/adapter/ohos/entrance/mmi_event_convertor.h @@ -116,6 +116,12 @@ bool GetPointerEventToolType(const std::shared_ptr& pointerEv void SetClonedPointerEvent(const MMI::PointerEvent* pointerEvent, ArkUITouchEvent* arkUITouchEventCloned); void SetPostPointerEvent(const MMI::PointerEvent* pointerEvent, TouchEvent& touchEvent); + +TouchType GetTouchTypeFromPointerEvent(const std::shared_ptr& pointerEvent); + +AxisAction GetAxisActionFromPointerEvent(const std::shared_ptr& pointerEvent); + +MouseAction GetMouseActionFromPointerEvent(const std::shared_ptr& pointerEvent); } // namespace OHOS::Ace::Platform #endif // FOUNDATION_ACE_ADAPTER_OHOS_ENTRANCE_MMI_EVENT_CONVERTOR_H diff --git a/adapter/ohos/entrance/touch_event_convertor.cpp b/adapter/ohos/entrance/touch_event_convertor.cpp index 52dd3d86fefaa38502c49500db71d3dc1fa4e53f..592bfaadccb8686166972bc36da7607c64c9afe4 100644 --- a/adapter/ohos/entrance/touch_event_convertor.cpp +++ b/adapter/ohos/entrance/touch_event_convertor.cpp @@ -44,4 +44,19 @@ void SetPostPointerEvent(const MMI::PointerEvent* pointerEvent, TouchEvent& touc { Platform::SetPostPointerEvent(pointerEvent, touchEvent); } + +TouchType GetTouchEventType(const std::shared_ptr& pointerEvent) +{ + return Platform::GetTouchTypeFromPointerEvent(pointerEvent); +} + +AxisAction GetAxisEventType(const std::shared_ptr& pointerEvent) +{ + return Platform::GetAxisActionFromPointerEvent(pointerEvent); +} + +MouseAction GetMouseEventType(const std::shared_ptr& pointerEvent) +{ + return Platform::GetMouseActionFromPointerEvent(pointerEvent); +} } \ No newline at end of file diff --git a/adapter/preview/entrance/touch_event_convertor.cpp b/adapter/preview/entrance/touch_event_convertor.cpp index 50ae62cace5af7c59ee8dd5b496cc506bad73859..0cd22bee3c5967673ffbf3572b491585562b35ed 100644 --- a/adapter/preview/entrance/touch_event_convertor.cpp +++ b/adapter/preview/entrance/touch_event_convertor.cpp @@ -28,4 +28,19 @@ void ConvertToAxisEvent(AxisEvent& event, const std::shared_ptr& pointerEvent) +{ + return TouchType::UNKNOWN; +} + +AxisAction GetAxisEventType(const std::shared_ptr& pointerEvent) +{ + return AxisAction::NONE; +} + +MouseAction GetMouseEventType(const std::shared_ptr& pointerEvent) +{ + return MouseAction::NONE; +} } \ No newline at end of file diff --git a/frameworks/core/components_ng/gestures/base_gesture_event.h b/frameworks/core/components_ng/gestures/base_gesture_event.h index 902c8f7714cba1db228fe438b091e13ec7674171..62d366abf167a1c2053c6914a9d37619f31c48a0 100644 --- a/frameworks/core/components_ng/gestures/base_gesture_event.h +++ b/frameworks/core/components_ng/gestures/base_gesture_event.h @@ -17,6 +17,10 @@ #include "core/gestures/gesture_info.h" +namespace OHOS::MMI { +class PointerEvent; +} // namespace OHOS::MMI + namespace OHOS::Ace { class ACE_EXPORT BaseGestureEvent : public BaseEventInfo { @@ -36,8 +40,52 @@ public: fingerList_ = fingerList; } + InputEventType GetRawInputEventType() const + { + return rawInputEventType_; + } + + void SetRawInputEventType(InputEventType type) + { + rawInputEventType_ = type; + } + + std::shared_ptr GetRawInputEvent() const + { + return rawInputEvent_; + } + + void SetRawInputEvent(std::shared_ptr rawInputEvent) + { + rawInputEvent_ = rawInputEvent; + } + + int64_t GetRawInputDeviceId() const + { + return rawInputDeviceId_; + } + + void SetRawInputDeviceId(int64_t rawInputDeviceId) + { + rawInputDeviceId_ = rawInputDeviceId; + } + + void SetLastAction(int32_t action) + { + lastAction_.emplace(action); + } + + std::optional GetLastAction() const + { + return lastAction_; + } + protected: std::list fingerList_; + InputEventType rawInputEventType_ = InputEventType::TOUCH_SCREEN; + std::shared_ptr rawInputEvent_; + int64_t rawInputDeviceId_ = 0; + std::optional lastAction_; }; class ACE_EXPORT TapGestureEvent : public BaseGestureEvent { diff --git a/frameworks/core/components_ng/gestures/recognizers/click_recognizer.cpp b/frameworks/core/components_ng/gestures/recognizers/click_recognizer.cpp index 83267fa966917480082d5991df3f9abe14c556c3..1c29296e94407920fff88bdb083efe0b59a5eb27 100644 --- a/frameworks/core/components_ng/gestures/recognizers/click_recognizer.cpp +++ b/frameworks/core/components_ng/gestures/recognizers/click_recognizer.cpp @@ -620,6 +620,9 @@ GestureJudgeResult ClickRecognizer::TriggerGestureJudgeCallback() info->SetRollAngle(touchPoint.rollAngle.value()); } info->SetSourceTool(touchPoint.sourceTool); + info->SetRawInputEventType(inputEventType_); + info->SetRawInputEvent(lastPointEvent_); + info->SetRawInputDeviceId(deviceId_); if (sysJudge_) { return sysJudge_(gestureInfo_, info); } diff --git a/frameworks/core/components_ng/gestures/recognizers/long_press_recognizer.cpp b/frameworks/core/components_ng/gestures/recognizers/long_press_recognizer.cpp index e4e198a86616c900427cc46e9e0f7ca38573cc99..70422058a4c68602d8db72e92e3af9559dcfc4cd 100644 --- a/frameworks/core/components_ng/gestures/recognizers/long_press_recognizer.cpp +++ b/frameworks/core/components_ng/gestures/recognizers/long_press_recognizer.cpp @@ -123,6 +123,7 @@ void LongPressRecognizer::ThumbnailTimer(int32_t time) void LongPressRecognizer::HandleTouchDownEvent(const TouchEvent& event) { extraInfo_ = ""; + lastAction_ = static_cast(TouchType::DOWN); if (!firstInputTime_.has_value()) { firstInputTime_ = event.time; } @@ -188,6 +189,7 @@ void LongPressRecognizer::HandleTouchDownEvent(const TouchEvent& event) void LongPressRecognizer::HandleTouchUpEvent(const TouchEvent& event) { + lastAction_ = static_cast(TouchType::UP); auto context = PipelineContext::GetCurrentContextSafelyWithCheck(); CHECK_NULL_VOID(context); context->RemoveGestureTask(task_); @@ -229,6 +231,7 @@ void LongPressRecognizer::HandleTouchUpEvent(const TouchEvent& event) void LongPressRecognizer::HandleTouchMoveEvent(const TouchEvent& event) { lastTouchEvent_.pressedKeyCodes_ = event.pressedKeyCodes_; + lastAction_ = static_cast(TouchType::MOVE); if (static_cast(touchPoints_.size()) < fingers_) { return; } @@ -253,6 +256,7 @@ void LongPressRecognizer::HandleTouchCancelEvent(const TouchEvent& event) if (refereeState_ == RefereeState::FAIL) { return; } + lastAction_ = static_cast(TouchType::CANCEL); lastTouchEvent_ = event; if (touchPoints_.find(event.id) != touchPoints_.end()) { touchPoints_.erase(event.id); @@ -399,6 +403,7 @@ void LongPressRecognizer::SendCallbackMsg( } if (callback && *callback) { GestureEvent info; + info.SetLastAction(lastAction_); info.SetGestureTypeName(GestureTypeName::LONG_PRESS_GESTURE); info.SetTimeStamp(time_); info.SetRepeat(isRepeat); @@ -574,6 +579,10 @@ GestureJudgeResult LongPressRecognizer::TriggerGestureJudgeCallback() info->SetRollAngle(trackPoint.rollAngle.value()); } info->SetSourceTool(trackPoint.sourceTool); + info->SetRawInputEventType(inputEventType_); + info->SetRawInputEvent(lastPointEvent_); + info->SetRawInputDeviceId(deviceId_); + info->SetLastAction(lastAction_); if (gestureRecognizerJudgeFunc && gestureRecognizerJudgeFunc(info, Claim(this), responseLinkRecognizer_) == GestureJudgeResult::REJECT) { return GestureJudgeResult::REJECT; diff --git a/frameworks/core/components_ng/gestures/recognizers/long_press_recognizer.h b/frameworks/core/components_ng/gestures/recognizers/long_press_recognizer.h index 11793f350be73fad62c52d642bffba22ed02f8ff..7f2f1fd6ac5b0e6b4108a888a0a2b65e47a3821f 100644 --- a/frameworks/core/components_ng/gestures/recognizers/long_press_recognizer.h +++ b/frameworks/core/components_ng/gestures/recognizers/long_press_recognizer.h @@ -173,6 +173,7 @@ private: DelayedTask task_; OnAccessibilityEventFunc onAccessibilityEventFunc_ = nullptr; std::unique_ptr longPressRecorder_; + int32_t lastAction_ = 0; }; } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/gestures/recognizers/pan_recognizer.cpp b/frameworks/core/components_ng/gestures/recognizers/pan_recognizer.cpp index 0d1641baebbee1e87e0218a0d307e0fd2756cba1..1b8f498a7156b87e25b4ced1582580847f30eaae 100644 --- a/frameworks/core/components_ng/gestures/recognizers/pan_recognizer.cpp +++ b/frameworks/core/components_ng/gestures/recognizers/pan_recognizer.cpp @@ -228,6 +228,7 @@ void PanRecognizer::UpdateAxisPointInVelocityTracker(const AxisEvent& event, boo void PanRecognizer::HandleTouchDownEvent(const TouchEvent& event) { extraInfo_ = ""; + lastAction_ = static_cast(TouchType::DOWN); isTouchEventFinished_ = false; if (!firstInputTime_.has_value()) { firstInputTime_ = event.time; @@ -281,6 +282,7 @@ void PanRecognizer::HandleTouchDownEvent(const TouchEvent& event) void PanRecognizer::HandleTouchDownEvent(const AxisEvent& event) { extraInfo_ = ""; + lastAction_ = static_cast(AxisAction::BEGIN); isTouchEventFinished_ = false; if (!firstInputTime_.has_value()) { firstInputTime_ = event.time; @@ -327,6 +329,7 @@ void PanRecognizer::HandleTouchDownEvent(const AxisEvent& event) void PanRecognizer::HandleTouchUpEvent(const TouchEvent& event) { extraInfo_ = "currentFingers: " + std::to_string(currentFingers_) + " fingers: " + std::to_string(fingers_); + lastAction_ = static_cast(TouchType::UP); fingersId_.erase(event.id); if (currentFingers_ < fingers_) { if (isNeedResetVoluntarily_ && currentFingers_ == 1) { @@ -383,6 +386,7 @@ void PanRecognizer::HandleTouchUpEvent(const TouchEvent& event) void PanRecognizer::HandleTouchUpEvent(const AxisEvent& event) { isTouchEventFinished_ = false; + lastAction_ = static_cast(AxisAction::END); // if axisEvent received rotateEvent, no need to active Pan recognizer. if (event.isRotationEvent) { return; @@ -422,6 +426,7 @@ void PanRecognizer::HandleTouchUpEvent(const AxisEvent& event) void PanRecognizer::HandleTouchMoveEvent(const TouchEvent& event) { isTouchEventFinished_ = false; + lastAction_ = static_cast(TouchType::MOVE); if (static_cast(touchPoints_.size()) < fingers_) { return; } @@ -495,6 +500,7 @@ void PanRecognizer::UpdateAxisDeltaTransform(const AxisEvent& event) void PanRecognizer::HandleTouchMoveEvent(const AxisEvent& event) { isTouchEventFinished_ = false; + lastAction_ = static_cast(AxisAction::UPDATE); if (fingers_ != AXIS_PAN_FINGERS || event.isRotationEvent) { return; } @@ -571,6 +577,7 @@ bool PanRecognizer::HandlePanAccept() void PanRecognizer::HandleTouchCancelEvent(const TouchEvent& event) { + lastAction_ = static_cast(TouchType::CANCEL); if ((refereeState_ != RefereeState::SUCCEED) && (refereeState_ != RefereeState::FAIL)) { Adjudicate(AceType::Claim(this), GestureDisposal::REJECT); return; @@ -590,6 +597,7 @@ void PanRecognizer::HandleTouchCancelEvent(const TouchEvent& event) void PanRecognizer::HandleTouchCancelEvent(const AxisEvent& event) { isTouchEventFinished_ = false; + lastAction_ = static_cast(AxisAction::CANCEL); if ((refereeState_ != RefereeState::SUCCEED) && (refereeState_ != RefereeState::FAIL)) { Adjudicate(AceType::Claim(this), GestureDisposal::REJECT); return; @@ -799,6 +807,7 @@ GestureEvent PanRecognizer::GetGestureEventInfo() info.SetPointerEvent(lastPointEvent_); info.SetIsPostEventResult(isPostEventResult_); info.SetPostEventNodeId(lastTouchEvent_.postEventNodeId); + info.SetLastAction(lastAction_); return info; } @@ -874,6 +883,10 @@ GestureJudgeResult PanRecognizer::TriggerGestureJudgeCallback() } info->SetTarget(GetEventTarget().value_or(EventTarget())); info->SetForce(lastTouchEvent_.force); + info->SetRawInputEventType(inputEventType_); + info->SetRawInputEvent(lastPointEvent_); + info->SetRawInputDeviceId(deviceId_); + info->SetLastAction(lastAction_); if (lastTouchEvent_.tiltX.has_value()) { info->SetTiltX(lastTouchEvent_.tiltX.value()); } diff --git a/frameworks/core/components_ng/gestures/recognizers/pan_recognizer.h b/frameworks/core/components_ng/gestures/recognizers/pan_recognizer.h index 7997f9416a2ffc04de25d16e295fe83571871a1f..9fe026e6cae17cb6ed5f98451241a8ee10cc0873 100644 --- a/frameworks/core/components_ng/gestures/recognizers/pan_recognizer.h +++ b/frameworks/core/components_ng/gestures/recognizers/pan_recognizer.h @@ -200,6 +200,7 @@ private: OnPanDistanceFunc onChangeDistance_; // this callback will be triggered when pan end, but the enable state is false std::unique_ptr panEndOnDisableState_; + int32_t lastAction_ = 0; }; } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/gestures/recognizers/pinch_recognizer.cpp b/frameworks/core/components_ng/gestures/recognizers/pinch_recognizer.cpp index 63b5ceee1a56afe79b6aa6a60f3ebb10592b0b26..61ff834987b6c5e3668e82eb7e410ccc5796818b 100644 --- a/frameworks/core/components_ng/gestures/recognizers/pinch_recognizer.cpp +++ b/frameworks/core/components_ng/gestures/recognizers/pinch_recognizer.cpp @@ -162,6 +162,7 @@ void PinchRecognizer::HandleTouchUpEvent(const TouchEvent& event) return; } + touchPoints_[event.id] = event; extraInfo_ = "activeSize: " + std::to_string(static_cast(activeFingers_.size())); if (static_cast(activeFingers_.size()) < fingers_ && refereeState_ != RefereeState::SUCCEED) { extraInfo_ += "activeFinger size not satisify."; @@ -318,6 +319,7 @@ void PinchRecognizer::HandleTouchCancelEvent(const TouchEvent& event) if (!IsActiveFinger(event.id)) { return; } + touchPoints_[event.id] = event; if ((refereeState_ != RefereeState::SUCCEED) && (refereeState_ != RefereeState::FAIL)) { Adjudicate(AceType::Claim(this), GestureDisposal::REJECT); return; @@ -335,6 +337,7 @@ void PinchRecognizer::HandleTouchCancelEvent(const TouchEvent& event) void PinchRecognizer::HandleTouchCancelEvent(const AxisEvent& event) { + UpdateTouchPointWithAxisEvent(event); if ((refereeState_ != RefereeState::SUCCEED) && (refereeState_ != RefereeState::FAIL)) { Adjudicate(AceType::Claim(this), GestureDisposal::REJECT); return; @@ -504,6 +507,9 @@ GestureJudgeResult PinchRecognizer::TriggerGestureJudgeCallback() info->SetRollAngle(lastTouchEvent_.rollAngle.value()); } info->SetSourceTool(lastTouchEvent_.sourceTool); + info->SetRawInputEventType(inputEventType_); + info->SetRawInputEvent(lastPointEvent_); + info->SetRawInputDeviceId(deviceId_); if (gestureRecognizerJudgeFunc) { return gestureRecognizerJudgeFunc(info, Claim(this), responseLinkRecognizer_); } diff --git a/frameworks/core/components_ng/gestures/recognizers/rotation_recognizer.cpp b/frameworks/core/components_ng/gestures/recognizers/rotation_recognizer.cpp index 56bd78d7070cbd2a220561dca07819bc2002ff3b..e88aec4901949549f8f6b49ea54423ccaccfc146 100644 --- a/frameworks/core/components_ng/gestures/recognizers/rotation_recognizer.cpp +++ b/frameworks/core/components_ng/gestures/recognizers/rotation_recognizer.cpp @@ -139,6 +139,7 @@ void RotationRecognizer::HandleTouchUpEvent(const TouchEvent& event) if (!IsActiveFinger(event.id)) { return; } + touchPoints_[event.id] = event; if (static_cast(activeFingers_.size()) < DEFAULT_ROTATION_FINGERS && refereeState_ != RefereeState::SUCCEED) { extraInfo_ += "activeFinger size not satisify."; @@ -285,6 +286,7 @@ void RotationRecognizer::HandleTouchCancelEvent(const TouchEvent& event) if (!IsActiveFinger(event.id)) { return; } + touchPoints_[event.id] = event; if ((refereeState_ != RefereeState::SUCCEED) && (refereeState_ != RefereeState::FAIL)) { extraInfo_ += "receive cancel event."; Adjudicate(AceType::Claim(this), GestureDisposal::REJECT); @@ -304,6 +306,7 @@ void RotationRecognizer::HandleTouchCancelEvent(const TouchEvent& event) void RotationRecognizer::HandleTouchCancelEvent(const AxisEvent& event) { + UpdateTouchPointWithAxisEvent(event); if ((refereeState_ != RefereeState::SUCCEED) && (refereeState_ != RefereeState::FAIL)) { Adjudicate(AceType::Claim(this), GestureDisposal::REJECT); return; @@ -455,6 +458,9 @@ GestureJudgeResult RotationRecognizer::TriggerGestureJudgeCallback() info->SetRollAngle(touchPoint.rollAngle.value()); } info->SetSourceTool(touchPoint.sourceTool); + info->SetRawInputEventType(inputEventType_); + info->SetRawInputEvent(lastPointEvent_); + info->SetRawInputDeviceId(deviceId_); if (gestureRecognizerJudgeFunc) { return gestureRecognizerJudgeFunc(info, Claim(this), responseLinkRecognizer_); } diff --git a/frameworks/core/components_ng/gestures/recognizers/swipe_recognizer.cpp b/frameworks/core/components_ng/gestures/recognizers/swipe_recognizer.cpp index aabfbf964381803473322be8c650c8567959672f..b20bcbcb72fcd372742325c8c97507902101751b 100644 --- a/frameworks/core/components_ng/gestures/recognizers/swipe_recognizer.cpp +++ b/frameworks/core/components_ng/gestures/recognizers/swipe_recognizer.cpp @@ -497,6 +497,9 @@ GestureJudgeResult SwipeRecognizer::TriggerGestureJudgeCallback() if (prevAngle_) { info->SetAngle(prevAngle_.value()); } + info->SetRawInputEventType(inputEventType_); + info->SetRawInputEvent(lastPointEvent_); + info->SetRawInputDeviceId(deviceId_); if (gestureRecognizerJudgeFunc) { return gestureRecognizerJudgeFunc(info, Claim(this), responseLinkRecognizer_); } diff --git a/frameworks/core/gestures/gesture_event.h b/frameworks/core/gestures/gesture_event.h index cb6b9205623af8ee7b8ce509396b77d4b204a3f6..156a1798b0c40d2cbeb7534f9a19b2f52e1fea04 100644 --- a/frameworks/core/gestures/gesture_event.h +++ b/frameworks/core/gestures/gesture_event.h @@ -304,6 +304,16 @@ public: { return gestureType_; } + + void SetLastAction(int32_t action) + { + lastAction_.emplace(action); + } + + std::optional GetLastAction() const + { + return lastAction_; + } #ifdef SECURITY_COMPONENT_ENABLE void SetDisplayX(double displayX) { @@ -375,6 +385,7 @@ private: float inputXDeltaSlope_ = 0.0f; float inputYDeltaSlope_ = 0.0f; GestureTypeName gestureType_ = GestureTypeName::UNKNOWN; + std::optional lastAction_; }; using GestureEventFunc = std::function; diff --git a/frameworks/core/interfaces/native/node/node_gesture_modifier.cpp b/frameworks/core/interfaces/native/node/node_gesture_modifier.cpp index 2ee6fccbe5bd71d05fc7467826051f278924ea12..7981ca7193b8e4b7cf1067850836e6c04ba13773 100644 --- a/frameworks/core/interfaces/native/node/node_gesture_modifier.cpp +++ b/frameworks/core/interfaces/native/node/node_gesture_modifier.cpp @@ -267,7 +267,7 @@ void ConvertIMMEventToTouchEvent(GestureEvent& info, ArkUITouchEvent& touchEvent touchEvent.deviceId = info.GetDeviceId(); // modifierkeystates touchEvent.modifierKeyState = NodeModifier::CalculateModifierKeyState(info.GetPressedKeyCodes()); - touchEvent.action = static_cast(tempTouchEvent.type); + touchEvent.action = info.GetLastAction().value_or(static_cast(tempTouchEvent.type)); touchEvent.sourceType = static_cast(tempTouchEvent.sourceType); touchEvent.timeStamp = tempTouchEvent.time.time_since_epoch().count(); touchEvent.actionTouchPoint.pressure = tempTouchEvent.force; @@ -306,6 +306,22 @@ SourceTool ConvertCInputEventToolTypeToSourceTool(int32_t cInputEventToolType) } } +ArkUI_UIInputEvent_Type ConvertInputEventTypeToArkuiUIInputEventType(InputEventType type) +{ + switch (type) { + case InputEventType::TOUCH_SCREEN: + return ARKUI_UIINPUTEVENT_TYPE_TOUCH; + case InputEventType::MOUSE_BUTTON: + return ARKUI_UIINPUTEVENT_TYPE_MOUSE; + case InputEventType::AXIS: + return ARKUI_UIINPUTEVENT_TYPE_AXIS; + case InputEventType::KEYBOARD: + return ARKUI_UIINPUTEVENT_TYPE_KEY; + default: + return ARKUI_UIINPUTEVENT_TYPE_UNKNOWN; + } +} + void GetGestureEvent(ArkUIAPIEventGestureAsyncEvent& ret, GestureEvent& info) { ret.repeat = info.GetRepeat(); @@ -321,23 +337,24 @@ void GetGestureEvent(ArkUIAPIEventGestureAsyncEvent& ret, GestureEvent& info) ret.speed = info.GetSpeed(); ret.source = static_cast(info.GetSourceDevice()); ret.targetDisplayId = info.GetTargetDisplayId(); - switch (info.GetInputEventType()) { - case InputEventType::TOUCH_SCREEN : - ret.inputEventType = static_cast(ARKUI_UIINPUTEVENT_TYPE_TOUCH); - break; - case InputEventType::MOUSE_BUTTON: - ret.inputEventType = static_cast(ARKUI_UIINPUTEVENT_TYPE_MOUSE); - break; - case InputEventType::AXIS : - ret.inputEventType = static_cast(ARKUI_UIINPUTEVENT_TYPE_AXIS); - break; - case InputEventType::KEYBOARD: - ret.inputEventType = static_cast(ARKUI_UIINPUTEVENT_TYPE_KEY); - ret.deviceId = info.GetDeviceId(); - break; - default: - break; + ret.inputEventType = ConvertInputEventTypeToArkuiUIInputEventType(info.GetInputEventType()); +} + +int32_t GetPointerEventAction(InputEventType type, std::shared_ptr pointerEvent) +{ + if (type == InputEventType::AXIS) { + CHECK_NULL_RETURN(pointerEvent, static_cast(AxisAction::NONE)); + return static_cast(NG::GetAxisEventType(pointerEvent)); + } + if (type == InputEventType::MOUSE_BUTTON) { + CHECK_NULL_RETURN(pointerEvent, static_cast(MouseAction::NONE)); + return static_cast(NG::GetMouseEventType(pointerEvent)); + } + if (type == InputEventType::KEYBOARD) { + return static_cast(KeyAction::DOWN); } + CHECK_NULL_RETURN(pointerEvent, static_cast(TouchType::UNKNOWN)); + return static_cast(NG::GetTouchEventType(pointerEvent)); } void GetBaseGestureEvent(ArkUIAPIEventGestureAsyncEvent* ret, ArkUITouchEvent& rawInputEvent, @@ -345,6 +362,9 @@ void GetBaseGestureEvent(ArkUIAPIEventGestureAsyncEvent* ret, ArkUITouchEvent& r { rawInputEvent.sourceType = static_cast(info->GetSourceDevice()); rawInputEvent.timeStamp = info->GetTimeStamp().time_since_epoch().count(); + rawInputEvent.action = + info->GetLastAction().value_or(GetPointerEventAction(info->GetRawInputEventType(), info->GetRawInputEvent())); + rawInputEvent.deviceId = info->GetRawInputDeviceId(); rawInputEvent.actionTouchPoint.tiltX = info->GetTiltX().value_or(0.0f); rawInputEvent.actionTouchPoint.tiltY = info->GetTiltY().value_or(0.0f); rawInputEvent.actionTouchPoint.rollAngle = info->GetRollAngle().value_or(0.0f); @@ -441,7 +461,7 @@ void ConvertIMMEventToMouseEvent(GestureEvent& info, ArkUIMouseEvent& mouseEvent mouseEvent.deviceId = info.GetDeviceId(); // modifierkeystates mouseEvent.modifierKeyState = NodeModifier::CalculateModifierKeyState(info.GetPressedKeyCodes()); - mouseEvent.action = static_cast(tempMouseEvent.action); + mouseEvent.action = info.GetLastAction().value_or(static_cast(tempMouseEvent.action)); mouseEvent.sourceType = static_cast(tempMouseEvent.sourceType); mouseEvent.timeStamp = tempMouseEvent.time.time_since_epoch().count(); mouseEvent.actionTouchPoint.pressure = 0.0f; @@ -475,7 +495,7 @@ void ConvertIMMEventToAxisEvent(GestureEvent& info, ArkUIAxisEvent& axisEvent) axisEvent.deviceId = info.GetDeviceId(); // modifierkeystates axisEvent.modifierKeyState = NodeModifier::CalculateModifierKeyState(info.GetPressedKeyCodes()); - axisEvent.action = static_cast(tempAxisEvent.action); + axisEvent.action = info.GetLastAction().value_or(static_cast(tempAxisEvent.action)); axisEvent.sourceType = static_cast(tempAxisEvent.sourceType); axisEvent.timeStamp = tempAxisEvent.time.time_since_epoch().count(); axisEvent.horizontalAxis = tempAxisEvent.horizontalAxis; @@ -806,7 +826,8 @@ void setGestureInterrupterToNodeWithUserData( } interruptInfo.responseLinkRecognizer = othersRecognizer; interruptInfo.count = count; - ArkUI_UIInputEvent inputEvent { ARKUI_UIINPUTEVENT_TYPE_TOUCH, C_TOUCH_EVENT_ID, &rawInputEvent }; + ArkUI_UIInputEvent inputEvent { ConvertInputEventTypeToArkuiUIInputEventType(info->GetRawInputEventType()), + C_TOUCH_EVENT_ID, &rawInputEvent }; inputEvent.apiVersion = AceApplicationInfo::GetInstance().GetApiTargetVersion() % API_TARGET_VERSION_MASK; ArkUIGestureEvent arkUIGestureEvent { gestureEvent, nullptr }; interruptInfo.inputEvent = &inputEvent; diff --git a/frameworks/core/interfaces/native/node/touch_event_convertor.h b/frameworks/core/interfaces/native/node/touch_event_convertor.h index 72112d3f905ddc457a457a24092f0e5d7fe63355..2c8d24235ec5cc91110261da5e3784a5a230a497 100644 --- a/frameworks/core/interfaces/native/node/touch_event_convertor.h +++ b/frameworks/core/interfaces/native/node/touch_event_convertor.h @@ -26,5 +26,8 @@ namespace OHOS::Ace::NG { void ConvertToAxisEvent(AxisEvent& event, const std::shared_ptr& srcPointerEvent); void SetClonedPointerEvent(const MMI::PointerEvent* pointerEvent, ArkUITouchEvent* arkUITouchEventCloned); void SetPostPointerEvent(const MMI::PointerEvent* pointerEvent, TouchEvent& touchEvent); + TouchType GetTouchEventType(const std::shared_ptr& pointerEvent); + AxisAction GetAxisEventType(const std::shared_ptr& pointerEvent); + MouseAction GetMouseEventType(const std::shared_ptr& pointerEvent); } #endif \ No newline at end of file diff --git a/test/unittest/core/gestures/click_recognizer_test_ng.cpp b/test/unittest/core/gestures/click_recognizer_test_ng.cpp index 1cbb8e91beee0ba49f6a607868b4c762d9e3bbb0..b155e595c04b0ec44222216340a9e7ead8088a55 100644 --- a/test/unittest/core/gestures/click_recognizer_test_ng.cpp +++ b/test/unittest/core/gestures/click_recognizer_test_ng.cpp @@ -1963,4 +1963,30 @@ HWTEST_F(ClickRecognizerTestNg, ClickRecognizerTypeTest003, TestSize.Level1) clickRecognizer->HandleReports(info, GestureCallbackType::START); EXPECT_EQ(clickRecognizer->GetRecognizerType(), GestureTypeName::TAP_GESTURE); } + +/** + * @tc.name: TriggerGestureJudgeCallbackTest002 + * @tc.desc: Test TriggerGestureJudgeCallback + * @tc.type: FUNC + */ +HWTEST_F(ClickRecognizerTestNg, TriggerGestureJudgeCallbackTest002, TestSize.Level1) +{ + RefPtr clickRecognizer = AceType::MakeRefPtr(FINGER_NUMBER, COUNT); + RefPtr targetComponent = AceType::MakeRefPtr(); + clickRecognizer->inputEventType_ = InputEventType::KEYBOARD; + clickRecognizer->deviceId_ = 1; + + auto func = [](const std::shared_ptr& info, const RefPtr& current, + const std::list>& others) { + EXPECT_EQ(info->rawInputEventType_, InputEventType::KEYBOARD); + EXPECT_EQ(info->rawInputDeviceId_, 1); + return GestureJudgeResult::REJECT; + }; + TouchEvent touchEvent; + touchEvent.rollAngle = 0; + clickRecognizer->touchPoints_[0] = touchEvent; + clickRecognizer->targetComponent_ = targetComponent; + targetComponent->SetOnGestureRecognizerJudgeBegin(func); + clickRecognizer->TriggerGestureJudgeCallback(); +} } // namespace OHOS::Ace::NG \ No newline at end of file diff --git a/test/unittest/core/gestures/long_press_recognizer_test_ng.cpp b/test/unittest/core/gestures/long_press_recognizer_test_ng.cpp index 3e82af4817da267f46da2e41f49c1367d8fc030e..9780a7491c6321bcf1e3083e36b822ef93c29585 100644 --- a/test/unittest/core/gestures/long_press_recognizer_test_ng.cpp +++ b/test/unittest/core/gestures/long_press_recognizer_test_ng.cpp @@ -2094,4 +2094,33 @@ HWTEST_F(LongPressRecognizerTestNg, LongPressRecognizerTypeTest001, TestSize.Lev longPressRecognizer->HandleReports(info, GestureCallbackType::END); EXPECT_EQ(longPressRecognizer->GetRecognizerType(), GestureTypeName::LONG_PRESS_GESTURE); } + +/** + * @tc.name: TriggerGestureJudgeCallbackTest002 + * @tc.desc: Test TriggerGestureJudgeCallback + * @tc.type: FUNC + */ +HWTEST_F(LongPressRecognizerTestNg, TriggerGestureJudgeCallbackTest002, TestSize.Level1) +{ + RefPtr longPressRecognizer = + AceType::MakeRefPtr(LONG_PRESS_DURATION, FINGER_NUMBER, false); + RefPtr targetComponent = AceType::MakeRefPtr(); + longPressRecognizer->inputEventType_ = InputEventType::KEYBOARD; + longPressRecognizer->deviceId_ = 1; + longPressRecognizer->lastAction_ = 1; + + auto func = [](const std::shared_ptr& info, const RefPtr& current, + const std::list>& others) { + EXPECT_EQ(info->rawInputEventType_, InputEventType::KEYBOARD); + EXPECT_EQ(info->rawInputDeviceId_, 1); + EXPECT_EQ(info->lastAction_.value_or(0), 1); + return GestureJudgeResult::REJECT; + }; + TouchEvent touchEvent; + touchEvent.rollAngle = 0; + longPressRecognizer->touchPoints_[0] = touchEvent; + longPressRecognizer->targetComponent_ = targetComponent; + targetComponent->SetOnGestureRecognizerJudgeBegin(func); + longPressRecognizer->TriggerGestureJudgeCallback(); +} } // namespace OHOS::Ace::NG \ No newline at end of file