diff --git a/frameworks/core/components_ng/event/gesture_info.h b/frameworks/core/components_ng/event/gesture_info.h index ed683f02607..663bff390e9 100644 --- a/frameworks/core/components_ng/event/gesture_info.h +++ b/frameworks/core/components_ng/event/gesture_info.h @@ -101,6 +101,16 @@ public: return userData_; } + void SetDisposeTag(bool tag) + { + disposeTag_ = tag; + } + + bool GetDisposeTag() + { + return disposeTag_; + } + private: std::optional tag_; GestureTypeName type_ = GestureTypeName::UNKNOWN; @@ -109,6 +119,7 @@ private: InputEventType inputEventType_ = InputEventType::TOUCH_SCREEN; bool isSystemGesture_ = false; void* userData_ = nullptr; + bool disposeTag_ = false; }; } // 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 3dad12e3944..199b002ba5e 100644 --- a/frameworks/core/components_ng/gestures/gesture_info.h +++ b/frameworks/core/components_ng/gestures/gesture_info.h @@ -204,6 +204,13 @@ public: virtual RefPtr CreateRecognizer() = 0; + void SetDisposeTag(bool tag) + { + if (gestureInfo_) { + gestureInfo_->SetDisposeTag(tag); + } + } + protected: int32_t fingers_ = 1; GesturePriority priority_ = GesturePriority::Low; diff --git a/frameworks/core/components_ng/gestures/long_press_gesture.cpp b/frameworks/core/components_ng/gestures/long_press_gesture.cpp index a4b13186a28..1cd598d11c6 100644 --- a/frameworks/core/components_ng/gestures/long_press_gesture.cpp +++ b/frameworks/core/components_ng/gestures/long_press_gesture.cpp @@ -38,6 +38,9 @@ RefPtr LongPressGesture::CreateRecognizer() if (onActionCancelId_) { longPressRecognizer->SetOnActionCancel(*onActionCancelId_); } + if (gestureInfo_) { + gestureInfo_->SetDisposeTag(false); + } longPressRecognizer->SetUserData(userData_); return longPressRecognizer; 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 1240f7181d3..91e466f9061 100644 --- a/frameworks/core/components_ng/gestures/recognizers/long_press_recognizer.cpp +++ b/frameworks/core/components_ng/gestures/recognizers/long_press_recognizer.cpp @@ -344,7 +344,7 @@ double LongPressRecognizer::ConvertPxToVp(double offset) const void LongPressRecognizer::SendCallbackMsg( const std::unique_ptr& callback, bool isRepeat, bool isOnAction) { - if (callback && *callback) { + if (callback && *callback && !gestureInfo_->GetDisposeTag()) { GestureEvent info; info.SetTimeStamp(time_); info.SetRepeat(isRepeat); diff --git a/frameworks/core/interfaces/native/node/node_gesture_modifier.cpp b/frameworks/core/interfaces/native/node/node_gesture_modifier.cpp index a2328034660..3dbc3bc04a0 100644 --- a/frameworks/core/interfaces/native/node/node_gesture_modifier.cpp +++ b/frameworks/core/interfaces/native/node/node_gesture_modifier.cpp @@ -166,6 +166,7 @@ void removeGestureFromGestureGroup(ArkUIGesture* group, ArkUIGesture* child) void dispose(ArkUIGesture* recognizer) { Gesture* gestureRef = reinterpret_cast(recognizer); + gestureRef->SetDisposeTag(true); gestureRef->DecRefCount(); } @@ -268,12 +269,12 @@ void GetBaseGestureEvent(ArkUIAPIEventGestureAsyncEvent* ret, ArkUITouchEvent& r void setCancelActionFunc(Gesture* gestureRef, void* extraParam) { auto onActionCancel = [extraParam]() { - ArkUINodeEvent *eventData = new ArkUINodeEvent(); - eventData->kind = GESTURE_ASYNC_EVENT; - eventData->nodeId = 0; - eventData->extraParam = reinterpret_cast(extraParam); - eventData->gestureAsyncEvent.subKind = ON_ACTION_CANCEL; - SendArkUIAsyncEvent(eventData); + ArkUINodeEvent eventData; + eventData.kind = GESTURE_ASYNC_EVENT; + eventData.nodeId = 0; + eventData.extraParam = reinterpret_cast(extraParam); + eventData.gestureAsyncEvent.subKind = ON_ACTION_CANCEL; + SendArkUIAsyncEvent(&eventData); }; gestureRef->SetOnActionCancelId(onActionCancel); } @@ -283,50 +284,50 @@ void registerGestureEvent(ArkUIGesture* gesture, ArkUI_Uint32 actionTypeMask, vo Gesture* gestureRef = reinterpret_cast(gesture); if (actionTypeMask & ARKUI_GESTURE_EVENT_ACTION_ACCEPT) { auto onActionAccept = [extraParam](GestureEvent& info) { - ArkUINodeEvent *eventData = new ArkUINodeEvent(); - eventData->kind = GESTURE_ASYNC_EVENT; - eventData->nodeId = 0; - eventData->extraParam = reinterpret_cast(extraParam); - eventData->gestureAsyncEvent.subKind = ON_ACTION_START; - GetGestureEvent(eventData->gestureAsyncEvent, info); + ArkUINodeEvent eventData; + eventData.kind = GESTURE_ASYNC_EVENT; + eventData.nodeId = 0; + eventData.extraParam = reinterpret_cast(extraParam); + eventData.gestureAsyncEvent.subKind = ON_ACTION_START; + GetGestureEvent(eventData.gestureAsyncEvent, info); ArkUITouchEvent rawInputEvent; std::array points; ConvertIMMEventToTouchEvent(info, rawInputEvent, points); - eventData->gestureAsyncEvent.rawPointerEvent = &rawInputEvent; - SendArkUIAsyncEvent(eventData); + eventData.gestureAsyncEvent.rawPointerEvent = &rawInputEvent; + SendArkUIAsyncEvent(&eventData); }; gestureRef->SetOnActionId(onActionAccept); gestureRef->SetOnActionStartId(onActionAccept); } if (actionTypeMask & ARKUI_GESTURE_EVENT_ACTION_UPDATE) { auto onActionUpdate = [extraParam](GestureEvent& info) { - ArkUINodeEvent *eventData = new ArkUINodeEvent(); - eventData->kind = GESTURE_ASYNC_EVENT; - eventData->nodeId = 0; - eventData->extraParam = reinterpret_cast(extraParam); - eventData->gestureAsyncEvent.subKind = ON_ACTION_UPDATE; - GetGestureEvent(eventData->gestureAsyncEvent, info); + ArkUINodeEvent eventData; + eventData.kind = GESTURE_ASYNC_EVENT; + eventData.nodeId = 0; + eventData.extraParam = reinterpret_cast(extraParam); + eventData.gestureAsyncEvent.subKind = ON_ACTION_UPDATE; + GetGestureEvent(eventData.gestureAsyncEvent, info); ArkUITouchEvent rawInputEvent; std::array points; ConvertIMMEventToTouchEvent(info, rawInputEvent, points); - eventData->gestureAsyncEvent.rawPointerEvent = &rawInputEvent; - SendArkUIAsyncEvent(eventData); + eventData.gestureAsyncEvent.rawPointerEvent = &rawInputEvent; + SendArkUIAsyncEvent(&eventData); }; gestureRef->SetOnActionUpdateId(onActionUpdate); } if (actionTypeMask & ARKUI_GESTURE_EVENT_ACTION_END) { auto onActionEnd = [extraParam](GestureEvent& info) { - ArkUINodeEvent *eventData = new ArkUINodeEvent(); - eventData->kind = GESTURE_ASYNC_EVENT; - eventData->nodeId = 0; - eventData->extraParam = reinterpret_cast(extraParam); - eventData->gestureAsyncEvent.subKind = ON_ACTION_END; - GetGestureEvent(eventData->gestureAsyncEvent, info); + ArkUINodeEvent eventData; + eventData.kind = GESTURE_ASYNC_EVENT; + eventData.nodeId = 0; + eventData.extraParam = reinterpret_cast(extraParam); + eventData.gestureAsyncEvent.subKind = ON_ACTION_END; + GetGestureEvent(eventData.gestureAsyncEvent, info); ArkUITouchEvent rawInputEvent; std::array points; ConvertIMMEventToTouchEvent(info, rawInputEvent, points); - eventData->gestureAsyncEvent.rawPointerEvent = &rawInputEvent; - SendArkUIAsyncEvent(eventData); + eventData.gestureAsyncEvent.rawPointerEvent = &rawInputEvent; + SendArkUIAsyncEvent(&eventData); }; gestureRef->SetOnActionEndId(onActionEnd); } diff --git a/interfaces/native/node/gesture_impl.cpp b/interfaces/native/node/gesture_impl.cpp index a1356683d7f..3b854310f58 100644 --- a/interfaces/native/node/gesture_impl.cpp +++ b/interfaces/native/node/gesture_impl.cpp @@ -258,7 +258,9 @@ void DisposeGesture(ArkUI_GestureRecognizer* recognizer) { OHOS::Ace::NodeModel::GetFullImpl()->getNodeModifiers()->getGestureModifier()->dispose(recognizer->gesture); delete reinterpret_cast(recognizer->extraData); + recognizer->extraData = nullptr; delete recognizer; + recognizer = nullptr; } int32_t SetGestureEventTarget(ArkUI_GestureRecognizer* recognizer, ArkUI_GestureEventActionTypeMask mask, @@ -268,6 +270,7 @@ int32_t SetGestureEventTarget(ArkUI_GestureRecognizer* recognizer, ArkUI_Gesture // 把回调函数和上下文都封装到内部结构体中。 if (recognizer->extraData) { delete reinterpret_cast(recognizer->extraData); + recognizer->extraData = nullptr; } recognizer->extraData = new GestureInnerData { targetReceiver, extraParam }; OHOS::Ace::NodeModel::GetFullImpl()->getNodeModifiers()->getGestureModifier()->registerGestureEvent( @@ -318,15 +321,23 @@ int32_t RemoveChildGesture(ArkUI_GestureRecognizer* group, ArkUI_GestureRecogniz void HandleGestureEvent(ArkUINodeEvent* event) { + if (event == nullptr) { + return; + } auto* extraData = reinterpret_cast(event->extraParam); + if (extraData == nullptr) { + return; + } ArkUI_GestureEvent* gestureEvent = reinterpret_cast(&event->gestureAsyncEvent); + if (gestureEvent == nullptr || extraData->targetReceiver == nullptr) { + return; + } ArkUI_UIInputEvent uiEvent; uiEvent.inputType = ARKUI_UIINPUTEVENT_TYPE_TOUCH; uiEvent.eventTypeId = C_TOUCH_EVENT_ID; uiEvent.inputEvent = gestureEvent->eventData.rawPointerEvent; gestureEvent->eventData.rawPointerEvent = &uiEvent; extraData->targetReceiver(gestureEvent, extraData->extraParam); - delete event; } int32_t SetGestureInterrupterToNode( diff --git a/interfaces/native/node/style_modifier.cpp b/interfaces/native/node/style_modifier.cpp index 8a8338cab11..655ef2bec60 100644 --- a/interfaces/native/node/style_modifier.cpp +++ b/interfaces/native/node/style_modifier.cpp @@ -4089,7 +4089,9 @@ void ResetPlaceholderColor(ArkUI_NodeHandle node) int32_t SetTextInputPlaceholderFont(ArkUI_NodeHandle node, const ArkUI_AttributeItem* item) { - // already check in entry point. + if (item == nullptr) { + return ERROR_CODE_PARAM_INVALID; + } auto* fullImpl = GetFullImpl(); struct ArkUIResourceLength size = { 16.0, GetDefaultUnit(node, UNIT_FP) }; int weight = ARKUI_FONT_WEIGHT_NORMAL; @@ -5593,6 +5595,9 @@ int32_t SetListScrollToIndex(ArkUI_NodeHandle node, const ArkUI_AttributeItem* i int32_t SetTextAreaPlaceholderFont(ArkUI_NodeHandle node, const ArkUI_AttributeItem* item) { + if (item == nullptr) { + return ERROR_CODE_PARAM_INVALID; + } auto* fullImpl = GetFullImpl(); struct ArkUIResourceLength size = { 16.0, GetDefaultUnit(node, UNIT_FP) }; int weight = ARKUI_FONT_WEIGHT_NORMAL; @@ -5813,7 +5818,7 @@ void ResetTextAreaSelectionMenuHidden(ArkUI_NodeHandle node) // button int32_t SetButtonLabel(ArkUI_NodeHandle node, const ArkUI_AttributeItem* item) { - if (item->string == nullptr) { + if (item == nullptr || item->string == nullptr) { return ERROR_CODE_PARAM_INVALID; } auto* fullImpl = GetFullImpl(); @@ -5970,7 +5975,7 @@ int32_t SetXComponentId(ArkUI_NodeHandle node, const ArkUI_AttributeItem* item) { // already check in entry point. auto* fullImpl = GetFullImpl(); - if (!item->string) { + if (item == nullptr || !item->string) { return ERROR_CODE_PARAM_INVALID; } fullImpl->getNodeModifiers()->getXComponentModifier()->setXComponentId(node->uiNodeHandle, item->string);