From bcca47058bdf10d6ab62dc69ae1fdcfe9f679f9f Mon Sep 17 00:00:00 2001 From: firminly Date: Sun, 5 May 2024 21:49:57 +0800 Subject: [PATCH] NDK C-API support interrupter gesture event Signed-off-by: liyi0309 Change-Id: I652dbe59707f4caa7d7acb88aab96ea0eb790a46 --- .../arkts_native_common_bridge.cpp | 20 ++--- .../core/components_ng/event/gesture_info.h | 11 +++ .../components_ng/gestures/gesture_info.h | 6 ++ .../gestures/long_press_gesture.cpp | 1 + .../gestures/recognizers/gesture_recognizer.h | 8 ++ .../core/interfaces/arkoala/arkoala_api.h | 20 +++-- .../native/node/node_gesture_modifier.cpp | 71 +++++++++++++++-- interfaces/native/libace.ndk.json | 16 ++++ interfaces/native/native_gesture.h | 10 +++ interfaces/native/node/gesture_impl.cpp | 78 ++++++++++++++++--- interfaces/native/node/gesture_impl.h | 3 + interfaces/native/node/native_impl.cpp | 2 +- 12 files changed, 211 insertions(+), 35 deletions(-) diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.cpp b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.cpp index c08176a6c3d..2bab3f3a22e 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.cpp +++ b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.cpp @@ -6103,7 +6103,7 @@ ArkUINativeModuleValue CommonBridge::AddTapGesture(ArkUIRuntimeCallInfo* runtime int32_t fingers = DEFAULT_TAP_FINGER; int32_t count = DEFAULT_TAP_COUNT; GetTapGestureValue(runtimeCallInfo, fingers, count, NUM_4); - auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createTapGesture(count, fingers); + auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createTapGesture(count, fingers, nullptr); SetGestureTag(runtimeCallInfo, NUM_3, gesture); SetOnGestureEvent(runtimeCallInfo, GestureEventAction::ACTION, NUM_6, gesture); GetArkUINodeModifiers()->getGestureModifier()->addGestureToNode(nativeNode, gesture, priority, mask); @@ -6125,7 +6125,7 @@ ArkUINativeModuleValue CommonBridge::AddLongPressGesture(ArkUIRuntimeCallInfo* r bool repeat = false; int32_t duration = DEFAULT_LONG_PRESS_DURATION; GetLongPressGestureValue(runtimeCallInfo, fingers, repeat, duration, NUM_4); - auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createLongPressGesture(fingers, repeat, duration); + auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createLongPressGesture(fingers, repeat, duration, nullptr); SetGestureTag(runtimeCallInfo, NUM_3, gesture); SetOnGestureEvent(runtimeCallInfo, GestureEventAction::ACTION, NUM_7, gesture); SetOnGestureEvent(runtimeCallInfo, GestureEventAction::END, NUM_8, gesture); @@ -6149,7 +6149,7 @@ ArkUINativeModuleValue CommonBridge::AddPanGesture(ArkUIRuntimeCallInfo* runtime int32_t direction = PanDirection::ALL; double distance = DEFAULT_PAN_DISTANCE.ConvertToPx(); GetPanGestureValue(runtimeCallInfo, fingers, direction, distance, NUM_4); - auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createPanGesture(fingers, direction, distance); + auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createPanGesture(fingers, direction, distance, nullptr); SetGestureTag(runtimeCallInfo, NUM_3, gesture); SetOnGestureEvent(runtimeCallInfo, GestureEventAction::START, NUM_7, gesture); SetOnGestureEvent(runtimeCallInfo, GestureEventAction::UPDATE, NUM_8, gesture); @@ -6196,7 +6196,7 @@ ArkUINativeModuleValue CommonBridge::AddPinchGesture(ArkUIRuntimeCallInfo* runti int32_t fingers = DEFAULT_PINCH_FINGER; double distance = DEFAULT_PINCH_DISTANCE; GetPinchGestureValue(runtimeCallInfo, fingers, distance, NUM_4); - auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createPinchGesture(fingers, distance); + auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createPinchGesture(fingers, distance, nullptr); SetGestureTag(runtimeCallInfo, NUM_3, gesture); SetOnGestureEvent(runtimeCallInfo, GestureEventAction::START, NUM_6, gesture); SetOnGestureEvent(runtimeCallInfo, GestureEventAction::UPDATE, NUM_7, gesture); @@ -6220,7 +6220,7 @@ ArkUINativeModuleValue CommonBridge::AddRotationGesture(ArkUIRuntimeCallInfo* ru int32_t fingers = DEFAULT_ROTATION_FINGER; double angle = DEFAULT_ROTATION_ANGLE; GetRotationGestureValue(runtimeCallInfo, fingers, angle, NUM_4); - auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createRotationGesture(fingers, angle); + auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createRotationGesture(fingers, angle, nullptr); SetGestureTag(runtimeCallInfo, NUM_3, gesture); SetOnGestureEvent(runtimeCallInfo, GestureEventAction::START, NUM_6, gesture); SetOnGestureEvent(runtimeCallInfo, GestureEventAction::UPDATE, NUM_7, gesture); @@ -6249,7 +6249,7 @@ ArkUINativeModuleValue CommonBridge::AddTapGestureToGroup(ArkUIRuntimeCallInfo* int32_t fingers = DEFAULT_TAP_FINGER; int32_t count = DEFAULT_TAP_COUNT; GetTapGestureValue(runtimeCallInfo, fingers, count, NUM_1); - auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createTapGesture(count, fingers); + auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createTapGesture(count, fingers, nullptr); SetGestureTag(runtimeCallInfo, NUM_0, gesture); SetOnGestureEvent(runtimeCallInfo, GestureEventAction::ACTION, NUM_3, gesture); auto* group = GetGestureGroup(runtimeCallInfo, NUM_4); @@ -6265,7 +6265,7 @@ ArkUINativeModuleValue CommonBridge::AddLongPressGestureToGroup(ArkUIRuntimeCall bool repeat = false; int32_t duration = DEFAULT_LONG_PRESS_DURATION; GetLongPressGestureValue(runtimeCallInfo, fingers, repeat, duration, NUM_1); - auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createLongPressGesture(fingers, repeat, duration); + auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createLongPressGesture(fingers, repeat, duration, nullptr); SetGestureTag(runtimeCallInfo, NUM_0, gesture); SetOnGestureEvent(runtimeCallInfo, GestureEventAction::ACTION, NUM_4, gesture); SetOnGestureEvent(runtimeCallInfo, GestureEventAction::END, NUM_5, gesture); @@ -6283,7 +6283,7 @@ ArkUINativeModuleValue CommonBridge::AddPanGestureToGroup(ArkUIRuntimeCallInfo* int32_t direction = PanDirection::ALL; double distance = DEFAULT_PAN_DISTANCE.ConvertToPx(); GetPanGestureValue(runtimeCallInfo, fingers, direction, distance, NUM_1); - auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createPanGesture(fingers, direction, distance); + auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createPanGesture(fingers, direction, distance, nullptr); SetGestureTag(runtimeCallInfo, NUM_0, gesture); SetOnGestureEvent(runtimeCallInfo, GestureEventAction::START, NUM_4, gesture); SetOnGestureEvent(runtimeCallInfo, GestureEventAction::UPDATE, NUM_5, gesture); @@ -6318,7 +6318,7 @@ ArkUINativeModuleValue CommonBridge::AddPinchGestureToGroup(ArkUIRuntimeCallInfo int32_t fingers = DEFAULT_PINCH_FINGER; double distance = DEFAULT_PINCH_DISTANCE; GetPinchGestureValue(runtimeCallInfo, fingers, distance, NUM_1); - auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createPinchGesture(fingers, distance); + auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createPinchGesture(fingers, distance, nullptr); SetGestureTag(runtimeCallInfo, NUM_0, gesture); SetOnGestureEvent(runtimeCallInfo, GestureEventAction::START, NUM_3, gesture); SetOnGestureEvent(runtimeCallInfo, GestureEventAction::UPDATE, NUM_4, gesture); @@ -6336,7 +6336,7 @@ ArkUINativeModuleValue CommonBridge::AddRotationGestureToGroup(ArkUIRuntimeCallI int32_t fingers = DEFAULT_ROTATION_FINGER; double angle = DEFAULT_ROTATION_ANGLE; GetRotationGestureValue(runtimeCallInfo, fingers, angle, NUM_1); - auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createRotationGesture(fingers, angle); + auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createRotationGesture(fingers, angle, nullptr); SetGestureTag(runtimeCallInfo, NUM_0, gesture); SetOnGestureEvent(runtimeCallInfo, GestureEventAction::START, NUM_3, gesture); SetOnGestureEvent(runtimeCallInfo, GestureEventAction::UPDATE, NUM_4, gesture); diff --git a/frameworks/core/components_ng/event/gesture_info.h b/frameworks/core/components_ng/event/gesture_info.h index 31fa3d34cf3..ad135383194 100644 --- a/frameworks/core/components_ng/event/gesture_info.h +++ b/frameworks/core/components_ng/event/gesture_info.h @@ -78,11 +78,22 @@ public: isSystemGesture_ = isSystemGesture; } + void SetUserData(void* userData) + { + userData_ = userData; + } + + void* GetUserData() + { + return userData_; + } + private: std::optional tag_; GestureTypeName type_ = GestureTypeName::UNKNOWN; InputEventType inputEventType_ = InputEventType::TOUCH_SCREEN; bool isSystemGesture_ = false; + void* userData_; }; } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/gestures/gesture_info.h b/frameworks/core/components_ng/gestures/gesture_info.h index cfc229ce984..3e94646ee5e 100644 --- a/frameworks/core/components_ng/gestures/gesture_info.h +++ b/frameworks/core/components_ng/gestures/gesture_info.h @@ -196,6 +196,11 @@ public: buff += sizeof(int32_t); return buff; } + + void SetUserData(void* userData) + { + userData_ = userData; + } virtual RefPtr CreateRecognizer() = 0; @@ -209,6 +214,7 @@ protected: std::unique_ptr onActionEndId_; std::unique_ptr onActionCancelId_; RefPtr gestureInfo_; + void* userData_; }; } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/gestures/long_press_gesture.cpp b/frameworks/core/components_ng/gestures/long_press_gesture.cpp index bf627b74a8f..a4b13186a28 100644 --- a/frameworks/core/components_ng/gestures/long_press_gesture.cpp +++ b/frameworks/core/components_ng/gestures/long_press_gesture.cpp @@ -38,6 +38,7 @@ RefPtr LongPressGesture::CreateRecognizer() if (onActionCancelId_) { longPressRecognizer->SetOnActionCancel(*onActionCancelId_); } + longPressRecognizer->SetUserData(userData_); return longPressRecognizer; } diff --git a/frameworks/core/components_ng/gestures/recognizers/gesture_recognizer.h b/frameworks/core/components_ng/gestures/recognizers/gesture_recognizer.h index 8d592c2aae6..9e2315a6de1 100644 --- a/frameworks/core/components_ng/gestures/recognizers/gesture_recognizer.h +++ b/frameworks/core/components_ng/gestures/recognizers/gesture_recognizer.h @@ -307,6 +307,14 @@ public: bool IsInAttachedNode(const TouchEvent& event); + + void SetUserData(void* userData) + { + if (gestureInfo_) { + gestureInfo_->SetUserData(userData); + } + } + protected: void Adjudicate(const RefPtr& recognizer, GestureDisposal disposal) { diff --git a/frameworks/core/interfaces/arkoala/arkoala_api.h b/frameworks/core/interfaces/arkoala/arkoala_api.h index 0491fd9eb90..67b7903eff4 100644 --- a/frameworks/core/interfaces/arkoala/arkoala_api.h +++ b/frameworks/core/interfaces/arkoala/arkoala_api.h @@ -2118,13 +2118,20 @@ struct ArkUITabsControllerModifier { struct ArkUIGesture; +struct ArkUIGestureInterruptInfo { + bool isSystemGesture; + ArkUI_Int32 systemRecognizerType; + ArkUIAPIEventGestureAsyncEvent* event = nullptr; + void* userData = nullptr; +}; + struct ArkUIGestureModifier { - ArkUIGesture* (*createTapGesture)(ArkUI_Int32 count, ArkUI_Int32 fingers); - ArkUIGesture* (*createLongPressGesture)(ArkUI_Int32 fingers, bool repeat, ArkUI_Int32 duration); - ArkUIGesture* (*createPanGesture)(ArkUI_Int32 fingers, ArkUI_Int32 direction, ArkUI_Float64 distance); - ArkUIGesture* (*createPinchGesture)(ArkUI_Int32 fingers, ArkUI_Float64 distance); - ArkUIGesture* (*createRotationGesture)(ArkUI_Int32 fingers, ArkUI_Float64 angle); - ArkUIGesture* (*createSwipeGesture)(ArkUI_Int32 fingers, ArkUI_Int32 directions, ArkUI_Float64 speed); + ArkUIGesture* (*createTapGesture)(ArkUI_Int32 count, ArkUI_Int32 fingers, void* userData); + ArkUIGesture* (*createLongPressGesture)(ArkUI_Int32 fingers, bool repeat, ArkUI_Int32 duration, void* userData); + ArkUIGesture* (*createPanGesture)(ArkUI_Int32 fingers, ArkUI_Int32 direction, ArkUI_Float64 distance, void* userData); + ArkUIGesture* (*createPinchGesture)(ArkUI_Int32 fingers, ArkUI_Float64 distance, void* userData); + ArkUIGesture* (*createRotationGesture)(ArkUI_Int32 fingers, ArkUI_Float64 angle, void* userData); + ArkUIGesture* (*createSwipeGesture)(ArkUI_Int32 fingers, ArkUI_Int32 directions, ArkUI_Float64 speed, void* userData); ArkUIGesture* (*createSwipeGestureByModifier)(ArkUI_Int32 fingers, ArkUI_Int32 direction, ArkUI_Float64 speed); ArkUIGesture* (*createGestureGroup)(ArkUI_Int32 mode); void (*addGestureToGestureGroup)(ArkUIGesture* group, ArkUIGesture* child); @@ -2136,6 +2143,7 @@ struct ArkUIGestureModifier { void (*removeGestureFromNode)(ArkUINodeHandle node, ArkUIGesture* recognizer); void (*removeGestureFromNodeByTag)(ArkUINodeHandle node, ArkUI_CharPtr gestureTag); void (*clearGestures)(ArkUINodeHandle node); + void (*setGestureInterrupterToNode)(ArkUINodeHandle node, ArkUI_Int32 (*interrupter)(ArkUIGestureInterruptInfo* interrupterInfo)); }; struct ArkUISliderModifier { diff --git a/frameworks/core/interfaces/native/node/node_gesture_modifier.cpp b/frameworks/core/interfaces/native/node/node_gesture_modifier.cpp index c8d2bfb51a3..1bb8f2bf286 100644 --- a/frameworks/core/interfaces/native/node/node_gesture_modifier.cpp +++ b/frameworks/core/interfaces/native/node/node_gesture_modifier.cpp @@ -23,12 +23,15 @@ #include "core/components_ng/gestures/swipe_gesture.h" #include "core/components_ng/base/frame_node.h" #include "core/interfaces/native/node/touch_event_convertor.h" +#include "core/components_ng/base/view_abstract.h" +#include "core/components_ng/base/view_abstract_model_ng.h" +#include "core/interfaces/arkoala/arkoala_api.h" namespace OHOS::Ace::NG { namespace { constexpr int32_t MAX_POINTS = 10; } -ArkUIGesture* createPanGesture(ArkUI_Int32 fingers, ArkUI_Int32 direction, ArkUI_Float64 distance) +ArkUIGesture* createPanGesture(ArkUI_Int32 fingers, ArkUI_Int32 direction, ArkUI_Float64 distance, void* userData) { PanDirection panDirection; switch (direction) { @@ -61,39 +64,44 @@ ArkUIGesture* createPanGesture(ArkUI_Int32 fingers, ArkUI_Int32 direction, ArkUI break; } auto panGestureObject = AceType::MakeRefPtr(fingers, panDirection, distance); + panGestureObject->SetUserData(userData); panGestureObject->IncRefCount(); return reinterpret_cast(AceType::RawPtr(panGestureObject)); } -ArkUIGesture* createTapGesture(ArkUI_Int32 count, ArkUI_Int32 fingers) +ArkUIGesture* createTapGesture(ArkUI_Int32 count, ArkUI_Int32 fingers, void* userData) { auto tapGestureObject = AceType::MakeRefPtr(count, fingers); + tapGestureObject->SetUserData(userData); tapGestureObject->IncRefCount(); return reinterpret_cast(AceType::RawPtr(tapGestureObject)); } -ArkUIGesture* createLongPressGesture(ArkUI_Int32 fingers, bool repeat, ArkUI_Int32 duration) +ArkUIGesture* createLongPressGesture(ArkUI_Int32 fingers, bool repeat, ArkUI_Int32 duration, void* userData) { auto longPressGestureObject = AceType::MakeRefPtr(fingers, repeat, duration); + longPressGestureObject->SetUserData(userData); longPressGestureObject->IncRefCount(); return reinterpret_cast(AceType::RawPtr(longPressGestureObject)); } -ArkUIGesture* createPinchGesture(ArkUI_Int32 fingers, ArkUI_Float64 distance) +ArkUIGesture* createPinchGesture(ArkUI_Int32 fingers, ArkUI_Float64 distance, void* userData) { auto pinchGestureObject = AceType::MakeRefPtr(fingers, distance); + pinchGestureObject->SetUserData(userData); pinchGestureObject->IncRefCount(); return reinterpret_cast(AceType::RawPtr(pinchGestureObject)); } -ArkUIGesture* createRotationGesture(ArkUI_Int32 fingers, ArkUI_Float64 angle) +ArkUIGesture* createRotationGesture(ArkUI_Int32 fingers, ArkUI_Float64 angle, void* userData) { auto rotationGestureObject = AceType::MakeRefPtr(fingers, angle); + rotationGestureObject->SetUserData(userData); rotationGestureObject->IncRefCount(); return reinterpret_cast(AceType::RawPtr(rotationGestureObject)); } -ArkUIGesture* createSwipeGesture(ArkUI_Int32 fingers, ArkUI_Int32 directions, ArkUI_Float64 speed) +ArkUIGesture* createSwipeGesture(ArkUI_Int32 fingers, ArkUI_Int32 directions, ArkUI_Float64 speed, void* userData) { SwipeDirection swipeDirection{SwipeDirection::NONE}; if (static_cast(directions) & ArkUI_GESTURE_DIRECTION_HORIZONTAL) { @@ -103,6 +111,7 @@ ArkUIGesture* createSwipeGesture(ArkUI_Int32 fingers, ArkUI_Int32 directions, Ar swipeDirection.type += SwipeDirection::VERTICAL; } auto swipeGestureObject = AceType::MakeRefPtr(fingers, swipeDirection, speed); + swipeGestureObject->SetUserData(userData); swipeGestureObject->IncRefCount(); return reinterpret_cast(AceType::RawPtr(swipeGestureObject)); } @@ -241,6 +250,38 @@ void GetGestureEvent(ArkUIAPIEventGestureAsyncEvent& ret, GestureEvent& info) ret.pinchCenterY = info.GetPinchCenter().GetY(); } +ArkUIAPIEventGestureAsyncEvent getBaseGestureEvent(const std::shared_ptr& info) +{ + ArkUIAPIEventGestureAsyncEvent ret; + ArkUITouchEvent rawInputEvent; + rawInputEvent.sourceType = static_cast(info->GetSourceDevice()); + rawInputEvent.timeStamp = info->GetTimeStamp().time_since_epoch().count(); + rawInputEvent.actionTouchPoint.tiltX = info->GetTiltX().value_or(0.0f); + rawInputEvent.actionTouchPoint.tiltY = info->GetTiltY().value_or(0.0f); + rawInputEvent.actionTouchPoint.toolType = static_cast(info->GetSourceTool()); + rawInputEvent.actionTouchPoint.pressure = info->GetForce(); + double density = PipelineBase::GetCurrentDensity(); + std::array points; + auto fingerList = info->GetFingerList(); + auto fingureIterator = std::begin(fingerList); + for (size_t i = 0; i < fingerList.size(); i++) { + points[i].id = fingureIterator->fingerId_; + points[i].windowX = NearEqual(density, 0.0) ? 0.0f : + fingureIterator->globalLocation_.GetX() / density; + points[i].windowY = NearEqual(density, 0.0) ? 0.0f : + fingureIterator->globalLocation_.GetY() / density; + points[i].nodeX = NearEqual(density, 0.0) ? 0.0f : + fingureIterator->localLocation_.GetX() / density; + points[i].nodeY = NearEqual(density, 0.0) ? 0.0f : + fingureIterator->localLocation_.GetY() / density; + fingureIterator++; + } + rawInputEvent.touchPointes = &(points[0]); + rawInputEvent.touchPointSize = fingerList.size(); + ret.rawPointerEvent = &rawInputEvent; + return ret; +} + void setCancelActionFunc(Gesture* gestureRef, void* extraParam) { auto onActionCancel = [extraParam]() { @@ -357,6 +398,23 @@ void clearGestures(ArkUINodeHandle node) gestureHub->ClearModifierGesture(); } +void setGestureInterrupterToNode(ArkUINodeHandle node, ArkUI_Int32 (*interrupter)(ArkUIGestureInterruptInfo* interrupterInfo)) +{ + auto* frameNode = reinterpret_cast(node); + auto onGestureJudgeBegin = [interrupter]( + const RefPtr& gestureInfo, const std::shared_ptr& info)-> GestureJudgeResult { + auto gestureEvent = getBaseGestureEvent(info); + ArkUIGestureInterruptInfo interruptInfo; + interruptInfo.isSystemGesture = gestureInfo->IsSystemGesture(); + interruptInfo.systemRecognizerType = static_cast(gestureInfo->GetType()); + interruptInfo.event = &gestureEvent; + interruptInfo.userData = gestureInfo->GetUserData(); + auto result = interrupter(&interruptInfo); + return static_cast(result); + }; + ViewAbstract::SetOnGestureJudgeBegin(frameNode, std::move(onGestureJudgeBegin)); +} + namespace NodeModifier { const ArkUIGestureModifier* GetGestureModifier() { @@ -377,6 +435,7 @@ const ArkUIGestureModifier* GetGestureModifier() removeGestureFromNode, removeGestureFromNodeByTag, clearGestures, + setGestureInterrupterToNode, }; return &modifier; } diff --git a/interfaces/native/libace.ndk.json b/interfaces/native/libace.ndk.json index cf0a31e2e61..0278395024e 100644 --- a/interfaces/native/libace.ndk.json +++ b/interfaces/native/libace.ndk.json @@ -1038,5 +1038,21 @@ { "first_introduced": "12", "name": "OH_ArkUI_DrawableDescriptor_GetAnimationIteration" + }, + { + "first_introduced": "12", + "name": "OH_ArkUI_GestureInterruptInfo_GetSystemFlag" + }, + { + "first_introduced": "12", + "name": "OH_ArkUI_GestureInterruptInfo_GetRecognizer" + }, + { + "first_introduced": "12", + "name": "OH_ArkUI_GestureInterruptInfo_GetGestureEvent" + }, + { + "first_introduced": "12", + "name": "OH_ArkUI_GestureInterruptInfo_GetSystemRecognizerType" } ] diff --git a/interfaces/native/native_gesture.h b/interfaces/native/native_gesture.h index 05a4d5608f7..9fbd02cf0da 100644 --- a/interfaces/native/native_gesture.h +++ b/interfaces/native/native_gesture.h @@ -250,6 +250,16 @@ ArkUI_GestureRecognizer* OH_ArkUI_GestureInterruptInfo_GetRecognizer(const ArkUI */ ArkUI_GestureEvent* OH_ArkUI_GestureInterruptInfo_GetGestureEvent(const ArkUI_GestureInterruptInfo* event); +/** +* @brief Obtains the type of the system gesture to trigger. +* +* @param event Indicates the pointer to the gesture interruption information. +* @return Returns the type of the system gesture to trigger. If the gesture to trigger is not a system gesture, +* -1 is returned. +* @since 12 +*/ +int32_t OH_ArkUI_GestureInterruptInfo_GetSystemRecognizerType(const ArkUI_GestureInterruptInfo* event); + /** * @brief Obtains the gesture event type. * diff --git a/interfaces/native/node/gesture_impl.cpp b/interfaces/native/node/gesture_impl.cpp index c882cd623b3..4a2868567a5 100644 --- a/interfaces/native/node/gesture_impl.cpp +++ b/interfaces/native/node/gesture_impl.cpp @@ -42,6 +42,10 @@ struct ArkUI_GestureEvent { ArkUIAPIEventGestureAsyncEvent eventData; }; +struct ArkUI_GestureInterruptInfo { + ArkUIGestureInterruptInfo interruptData; +}; + #endif @@ -137,6 +141,35 @@ float OH_ArkUI_PinchGesture_GetCenterY(const ArkUI_GestureEvent* event) return event->eventData.pinchCenterY; } +bool OH_ArkUI_GestureInterruptInfo_GetSystemFlag(const ArkUI_GestureInterruptInfo* event) +{ + return event->interruptData.isSystemGesture; +} + +ArkUI_GestureRecognizer* OH_ArkUI_GestureInterruptInfo_GetRecognizer(const ArkUI_GestureInterruptInfo* event) +{ + return reinterpret_cast(event->interruptData.userData); +} + +ArkUI_GestureEvent* OH_ArkUI_GestureInterruptInfo_GetGestureEvent(const ArkUI_GestureInterruptInfo* event) +{ + ArkUI_GestureEvent* gestureEvent = reinterpret_cast(event->interruptData.event); + ArkUI_UIInputEvent uiEvent; + uiEvent.inputType = ARKUI_UIINPUTEVENT_TYPE_TOUCH; + uiEvent.eventTypeId = C_TOUCH_EVENT_ID; + uiEvent.inputEvent = gestureEvent->eventData.rawPointerEvent; + gestureEvent->eventData.rawPointerEvent = &uiEvent; + return gestureEvent; +} + +int32_t OH_ArkUI_GestureInterruptInfo_GetSystemRecognizerType(const ArkUI_GestureInterruptInfo* event) +{ + if (event->interruptData.isSystemGesture) { + return event->interruptData.systemRecognizerType; + } + return -1; +} + namespace OHOS::Ace::GestureModel { constexpr int32_t DEFAULT_PAN_FINGERS = 1; @@ -151,17 +184,21 @@ struct GestureInnerData { ArkUI_GestureRecognizer* CreateTapGesture(int32_t count, int32_t fingers) { + auto* ndkGesture = new ArkUI_GestureRecognizer{ TAP_GESTURE, nullptr, nullptr }; auto* gesture = OHOS::Ace::NodeModel::GetFullImpl()->getNodeModifiers()->getGestureModifier()->createTapGesture( - count, fingers); - return new ArkUI_GestureRecognizer{ TAP_GESTURE, gesture, nullptr }; + count, fingers, ndkGesture); + ndkGesture->gesture = gesture; + return ndkGesture; } ArkUI_GestureRecognizer* CreateLongPressGesture(int32_t fingers, bool repeatResult, int32_t duration) { + auto* ndkGesture = new ArkUI_GestureRecognizer{ LONG_PRESS_GESTURE, nullptr, nullptr }; auto* gesture = OHOS::Ace::NodeModel::GetFullImpl()->getNodeModifiers()->getGestureModifier()->createLongPressGesture(fingers, - repeatResult, duration); - return new ArkUI_GestureRecognizer{ LONG_PRESS_GESTURE, gesture, nullptr }; + repeatResult, duration, ndkGesture); + ndkGesture->gesture = gesture; + return ndkGesture; } ArkUI_GestureRecognizer* CreatePinchGesture(int32_t fingers, double distance) @@ -171,18 +208,22 @@ ArkUI_GestureRecognizer* CreatePinchGesture(int32_t fingers, double distance) } double distanceNum = OHOS::Ace::NodeModel::GetFullImpl()->getBasicAPI()->convertLengthMetricsUnit( distance, static_cast(ARKUI_LENGTH_METRIC_UNIT_PX), static_cast(ARKUI_LENGTH_METRIC_UNIT_VP)); + auto* ndkGesture = new ArkUI_GestureRecognizer{ PINCH_GESTURE, nullptr, nullptr }; auto* gesture = OHOS::Ace::NodeModel::GetFullImpl()->getNodeModifiers()->getGestureModifier()->createPinchGesture(fingers, - distanceNum); - return new ArkUI_GestureRecognizer{ PINCH_GESTURE, gesture, nullptr }; + distanceNum, ndkGesture); + ndkGesture->gesture = gesture; + return ndkGesture; } ArkUI_GestureRecognizer* CreateRotationGesture(int32_t fingers, double angle) { + auto* ndkGesture = new ArkUI_GestureRecognizer{ ROTATION_GESTURE, nullptr, nullptr }; auto* gesture = OHOS::Ace::NodeModel::GetFullImpl()->getNodeModifiers()->getGestureModifier()->createRotationGesture(fingers, - angle); - return new ArkUI_GestureRecognizer{ ROTATION_GESTURE, gesture, nullptr }; + angle, ndkGesture); + ndkGesture->gesture = gesture; + return ndkGesture; } ArkUI_GestureRecognizer* CreateSwipeGesture(int32_t fingers, ArkUI_GestureDirectionMask directions, double speed) @@ -192,10 +233,12 @@ ArkUI_GestureRecognizer* CreateSwipeGesture(int32_t fingers, ArkUI_GestureDirect } double speedNum = OHOS::Ace::NodeModel::GetFullImpl()->getBasicAPI()->convertLengthMetricsUnit( speed, static_cast(ARKUI_LENGTH_METRIC_UNIT_PX), static_cast(ARKUI_LENGTH_METRIC_UNIT_VP)); + auto* ndkGesture = new ArkUI_GestureRecognizer{ SWIPE_GESTURE, nullptr, nullptr }; auto* gesture = OHOS::Ace::NodeModel::GetFullImpl()->getNodeModifiers()->getGestureModifier()->createSwipeGesture(fingers, - directions, speedNum); - return new ArkUI_GestureRecognizer{ SWIPE_GESTURE, gesture, nullptr }; + directions, speedNum, ndkGesture); + ndkGesture->gesture = gesture; + return ndkGesture; } ArkUI_GestureRecognizer* CreatePanGesture(int32_t fingersNum, ArkUI_GestureDirectionMask mask, double distanceNum) @@ -206,9 +249,11 @@ ArkUI_GestureRecognizer* CreatePanGesture(int32_t fingersNum, ArkUI_GestureDirec } else { fingers = fingersNum; } + auto* ndkGesture = new ArkUI_GestureRecognizer{ PAN_GESTURE, nullptr, nullptr }; auto* gesture = OHOS::Ace::NodeModel::GetFullImpl()->getNodeModifiers()->getGestureModifier()->createPanGesture( - fingers, mask, distanceNum); - return new ArkUI_GestureRecognizer{ PAN_GESTURE, gesture, nullptr }; + fingers, mask, distanceNum, ndkGesture); + ndkGesture->gesture = gesture; + return ndkGesture; } void DisposeGesture(ArkUI_GestureRecognizer* recognizer) @@ -286,4 +331,13 @@ void HandleGestureEvent(ArkUINodeEvent* event) delete event; } +int32_t SetGestureInterrupterToNode( + ArkUI_NodeHandle node, ArkUI_GestureInterruptResult (*interrupter)(ArkUI_GestureInterruptInfo* info)) +{ + auto callback = reinterpret_cast(interrupter); + OHOS::Ace::NodeModel::GetFullImpl()->getNodeModifiers()->getGestureModifier()->setGestureInterrupterToNode( + node->uiNodeHandle, callback); + return 0; +} + }; // namespace OHOS::Ace::GestureModel \ No newline at end of file diff --git a/interfaces/native/node/gesture_impl.h b/interfaces/native/node/gesture_impl.h index bb94ba03a5e..10f8723e443 100644 --- a/interfaces/native/node/gesture_impl.h +++ b/interfaces/native/node/gesture_impl.h @@ -55,5 +55,8 @@ int32_t RemoveChildGesture(ArkUI_GestureRecognizer* group, ArkUI_GestureRecogniz void HandleGestureEvent(ArkUINodeEvent* event); +int32_t SetGestureInterrupterToNode( + ArkUI_NodeHandle node, ArkUI_GestureInterruptResult (*interrupter)(ArkUI_GestureInterruptInfo* info)); + }; // namespace OHOS::Ace::GestureModel #endif \ No newline at end of file diff --git a/interfaces/native/node/native_impl.cpp b/interfaces/native/node/native_impl.cpp index 194a631177d..d00d1740801 100644 --- a/interfaces/native/node/native_impl.cpp +++ b/interfaces/native/node/native_impl.cpp @@ -127,7 +127,7 @@ ArkUI_NativeGestureAPI_1 gestureImpl_1 = { OHOS::Ace::GestureModel::SetGestureEventTarget, OHOS::Ace::GestureModel::AddGestureToNode, OHOS::Ace::GestureModel::RemoveGestureFromNode, - nullptr, + OHOS::Ace::GestureModel::SetGestureInterrupterToNode, OHOS::Ace::GestureModel::GetGestureType, }; -- Gitee