diff --git a/frameworks/core/components_ng/manager/drag_drop/drag_drop_func_wrapper.cpp b/frameworks/core/components_ng/manager/drag_drop/drag_drop_func_wrapper.cpp index 8b7abbc64d2..81bffee692b 100644 --- a/frameworks/core/components_ng/manager/drag_drop/drag_drop_func_wrapper.cpp +++ b/frameworks/core/components_ng/manager/drag_drop/drag_drop_func_wrapper.cpp @@ -84,6 +84,7 @@ void GetShadowInfoArray( void PostStopDrag(std::shared_ptr dragAction, const RefPtr& container) { + CHECK_NULL_VOID(container); auto taskExecutor = container->GetTaskExecutor(); CHECK_NULL_VOID(taskExecutor); auto windowId = container->GetWindowId(); @@ -243,7 +244,10 @@ int32_t DragDropFuncWrapper::StartDragAction(std::shared_ptr dragData; EnvelopedDragData(dragAction, dragData); if (!dragData) { - manager->GetDragAction()->dragState = DragAdapterState::INIT; + { + std::lock_guard lock(dragAction->dragStateMutex); + manager->GetDragAction()->dragState = DragAdapterState::INIT; + } return -1; } OnDragCallback callback = [dragAction, manager](const OHOS::Ace::DragNotifyMsg& dragNotifyMsg) { diff --git a/frameworks/core/components_ng/manager/drag_drop/drag_drop_manager.cpp b/frameworks/core/components_ng/manager/drag_drop/drag_drop_manager.cpp index a0bd542d885..6ef517a2358 100644 --- a/frameworks/core/components_ng/manager/drag_drop/drag_drop_manager.cpp +++ b/frameworks/core/components_ng/manager/drag_drop/drag_drop_manager.cpp @@ -315,7 +315,7 @@ bool DragDropManager::CheckDragDropProxy(int64_t id) const } void DragDropManager::UpdateDragAllowDrop( - const RefPtr& dragFrameNode, const DragBehavior dragBehavior, const int32_t eventId) + const RefPtr& dragFrameNode, const DragBehavior dragBehavior, const int32_t eventId, bool isCapi) { if (!IsDropAllowed(dragFrameNode)) { UpdateDragStyle(DragCursorStyleCore::FORBIDDEN, eventId); @@ -326,7 +326,9 @@ void DragDropManager::UpdateDragAllowDrop( CHECK_NULL_VOID(dragFrameNode); const auto& dragFrameNodeAllowDrop = dragFrameNode->GetAllowDrop(); // special handling for no drag data present situation, always show as move - if (dragFrameNodeAllowDrop.empty() || summaryMap_.empty()) { + // For CAPI ,no ENABLE_DROP and DISABLE_DROP state, skip the judgment and consider it allowed to drop into. Continue + // to set dragBehavior. + if (!isCapi && (dragFrameNodeAllowDrop.empty() || summaryMap_.empty())) { UpdateDragStyle(DragCursorStyleCore::MOVE, eventId); return; } @@ -1102,7 +1104,7 @@ void DragDropManager::FireOnDragEvent( } else if (event->GetResult() == DragRet::DISABLE_DROP) { UpdateDragStyle(DragCursorStyleCore::FORBIDDEN, pointerEvent.pointerEventId); } else { - UpdateDragAllowDrop(frameNode, event->GetDragBehavior(), pointerEvent.pointerEventId); + UpdateDragAllowDrop(frameNode, event->GetDragBehavior(), pointerEvent.pointerEventId, event->IsCapi()); } } diff --git a/frameworks/core/components_ng/manager/drag_drop/drag_drop_manager.h b/frameworks/core/components_ng/manager/drag_drop/drag_drop_manager.h index fb861c31062..504cdb247e5 100644 --- a/frameworks/core/components_ng/manager/drag_drop/drag_drop_manager.h +++ b/frameworks/core/components_ng/manager/drag_drop/drag_drop_manager.h @@ -131,8 +131,8 @@ public: float GetWindowScale() const; void UpdateDragStyle( const DragCursorStyleCore& dragCursorStyleCore = DragCursorStyleCore::DEFAULT, const int32_t eventId = -1); - void UpdateDragAllowDrop( - const RefPtr& dragFrameNode, const DragBehavior dragBehavior, const int32_t eventId = -1); + void UpdateDragAllowDrop(const RefPtr& dragFrameNode, const DragBehavior dragBehavior, + const int32_t eventId = -1, bool isCapi = false); void RequireSummary(); void ClearSummary(); void SetSummaryMap(const std::map& summaryMap) diff --git a/frameworks/core/gestures/drag_event.h b/frameworks/core/gestures/drag_event.h index b42333db7e1..104da2c4755 100644 --- a/frameworks/core/gestures/drag_event.h +++ b/frameworks/core/gestures/drag_event.h @@ -287,6 +287,16 @@ public: pressedKeyCodes_ = pressedKeyCodes; } + void SetCapi(bool isCapi) + { + isCapi_ = isCapi; + } + + bool IsCapi() + { + return isCapi_; + } + private: RefPtr pasteData_; double screenX_ = 0.0; @@ -310,6 +320,7 @@ private: RefPtr dragInfo_; Velocity velocity_; std::vector pressedKeyCodes_; + bool isCapi_ = false; }; class NotifyDragEvent : public DragEvent { diff --git a/frameworks/core/interfaces/arkoala/arkoala_api.h b/frameworks/core/interfaces/arkoala/arkoala_api.h index 209f599db53..59ac4052caf 100644 --- a/frameworks/core/interfaces/arkoala/arkoala_api.h +++ b/frameworks/core/interfaces/arkoala/arkoala_api.h @@ -223,6 +223,7 @@ struct ArkUIMouseEvent { struct ArkUIDragEvent { void* unifiedData; void* unifiedDataSummary; + bool isSuitGetData; ArkUI_Int32 dragResult; ArkUI_Float64 touchPointX; ArkUI_Float64 touchPointY; diff --git a/frameworks/core/interfaces/native/node/drag_adapter_impl.cpp b/frameworks/core/interfaces/native/node/drag_adapter_impl.cpp index 59531c79055..5a598234ae9 100644 --- a/frameworks/core/interfaces/native/node/drag_adapter_impl.cpp +++ b/frameworks/core/interfaces/native/node/drag_adapter_impl.cpp @@ -33,6 +33,8 @@ namespace { static void DragActionConvert( ArkUIDragAction* dragAction, std::shared_ptr internalDragAction) { + CHECK_NULL_VOID(dragAction); + CHECK_NULL_VOID(internalDragAction); internalDragAction->pointer = dragAction->pointerId; internalDragAction->size = dragAction->size; internalDragAction->previewOption.isScaleEnabled = dragAction->dragPreviewOption.isScaleEnabled; diff --git a/frameworks/core/interfaces/native/node/node_drag_modifier.cpp b/frameworks/core/interfaces/native/node/node_drag_modifier.cpp index 562909c14f6..c8035e3037c 100644 --- a/frameworks/core/interfaces/native/node/node_drag_modifier.cpp +++ b/frameworks/core/interfaces/native/node/node_drag_modifier.cpp @@ -135,15 +135,18 @@ void SetOnDragDrop(ArkUINodeHandle node, void* extraParam) std::vector keepStr(summary.size()); SetDragEventProperty(info, event, strList, keepStr); + event.dragEvent.isSuitGetData = true; auto unifiedData = UdmfClient::GetInstance()->TransformUnifiedDataPtr(info->GetData()); event.dragEvent.unifiedData = unifiedData; + event.dragEvent.dragBehavior = static_cast(DragBehavior::UNKNOWN); PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode)); SendArkUIAsyncEvent(&event); info->UseCustomAnimation(event.dragEvent.useCustomDropAnimation); info->SetResult(static_cast(event.dragEvent.dragResult)); info->SetDragBehavior(static_cast(event.dragEvent.dragBehavior)); + info->SetCapi(true); }; ViewAbstract::SetOnDrop(frameNode, onDragDrop); } @@ -165,6 +168,7 @@ void SetOnDragStart(ArkUINodeHandle node, void* extraParam) std::vector keepStr(summary.size()); SetDragEventProperty(info, event, strList, keepStr); + event.dragEvent.isSuitGetData = false; PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode)); SendArkUIAsyncEvent(&event); @@ -197,13 +201,15 @@ void SetOnDragEnter(ArkUINodeHandle node, void* extraParam) SetDragEventProperty(info, event, strList, keepStr); auto unifiedData = UdmfClient::GetInstance()->TransformUnifiedDataPtr(info->GetData()); - + event.dragEvent.dragBehavior = static_cast(DragBehavior::UNKNOWN); event.dragEvent.unifiedData = unifiedData; + event.dragEvent.isSuitGetData = false; PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode)); SendArkUIAsyncEvent(&event); info->SetResult(static_cast(event.dragEvent.dragResult)); info->SetDragBehavior(static_cast(event.dragEvent.dragBehavior)); + info->SetCapi(true); }; ViewAbstract::SetOnDragEnter(frameNode, onDragEnter); } @@ -226,11 +232,15 @@ void SetOnDragMove(ArkUINodeHandle node, void* extraParam) SetDragEventProperty(info, event, strList, keepStr); auto unifiedData = UdmfClient::GetInstance()->TransformUnifiedDataPtr(info->GetData()); + event.dragEvent.dragBehavior = static_cast(DragBehavior::UNKNOWN); event.dragEvent.unifiedData = unifiedData; + event.dragEvent.isSuitGetData = false; + PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode)); SendArkUIAsyncEvent(&event); info->SetResult(static_cast(event.dragEvent.dragResult)); info->SetDragBehavior(static_cast(event.dragEvent.dragBehavior)); + info->SetCapi(true); }; ViewAbstract::SetOnDragMove(frameNode, onDragMove); } @@ -254,12 +264,15 @@ void SetOnDragLeave(ArkUINodeHandle node, void* extraParam) SetDragEventProperty(info, event, strList, keepStr); auto unifiedData = UdmfClient::GetInstance()->TransformUnifiedDataPtr(info->GetData()); - + event.dragEvent.dragBehavior = static_cast(DragBehavior::UNKNOWN); event.dragEvent.unifiedData = unifiedData; + event.dragEvent.isSuitGetData = false; + PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode)); SendArkUIAsyncEvent(&event); info->SetResult(static_cast(event.dragEvent.dragResult)); info->SetDragBehavior(static_cast(event.dragEvent.dragBehavior)); + info->SetCapi(true); }; ViewAbstract::SetOnDragLeave(frameNode, onDragLeave); } @@ -295,6 +308,7 @@ void SetOnDragEnd(ArkUINodeHandle node, void* extraParam) auto unifiedData = UdmfClient::GetInstance()->TransformUnifiedDataPtr(info->GetData()); event.dragEvent.unifiedData = unifiedData; + event.dragEvent.isSuitGetData = false; // Did NOT define pressCode, so will NOT pass presscode to UI. event.dragEvent.dragResult = static_cast(info->GetResult()); @@ -320,6 +334,8 @@ void SetOnPreDrag(ArkUINodeHandle node, void* extraParam) // Did NOT define pressCode, so will NOT pass presscode to UI. event.componentAsyncEvent.data[0].i32 = static_cast(preDragStatus); + event.dragEvent.isSuitGetData = false; + PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode)); SendArkUIAsyncEvent(&event); }; diff --git a/interfaces/native/event/drag_and_drop_impl.cpp b/interfaces/native/event/drag_and_drop_impl.cpp index 3faedf0ee9a..494f1337a06 100644 --- a/interfaces/native/event/drag_and_drop_impl.cpp +++ b/interfaces/native/event/drag_and_drop_impl.cpp @@ -70,9 +70,8 @@ int32_t OH_ArkUI_DragEvent_GetUdmfData(ArkUI_DragEvent* event, OH_UdmfData* data if (!event || !dragEvent || (dragEvent->unifiedData == nullptr) || !data) { return ARKUI_ERROR_CODE_PARAM_INVALID; } - auto rawData = reinterpret_cast(dragEvent->unifiedData); - auto raw = dynamic_cast(rawData); - if (raw) { + + if (!(dragEvent->isSuitGetData)) { return ARKUI_ERROR_CODE_PARAM_INVALID; } auto unifiedData = @@ -284,9 +283,6 @@ ArkUI_DragEvent* OH_ArkUI_DragAndDropInfo_GetDragEvent(ArkUI_DragAndDropInfo* dr return nullptr; } auto* dragAndDropInfos = reinterpret_cast(dragAndDropInfo); - if (!dragAndDropInfos) { - return nullptr; - } return reinterpret_cast(dragAndDropInfos->dragEvent); }