From 180a52f533a00df0c6a68a7846d0bd98852f3530 Mon Sep 17 00:00:00 2001 From: Zhang Jinyu Date: Wed, 31 Jul 2024 18:01:56 +0800 Subject: [PATCH] Add new interface GetDropOperation Signed-off-by: Zhang Jinyu --- interfaces/native/drag_and_drop.h | 17 +++++++++++-- .../native/event/drag_and_drop_impl.cpp | 15 +++++++++++ interfaces/native/libace.ndk.json | 4 +++ .../interfaces/drag_and_drop_test.cpp | 25 +++++++++++++++++++ 4 files changed, 59 insertions(+), 2 deletions(-) diff --git a/interfaces/native/drag_and_drop.h b/interfaces/native/drag_and_drop.h index 6329091e085..0b9fba71d77 100644 --- a/interfaces/native/drag_and_drop.h +++ b/interfaces/native/drag_and_drop.h @@ -221,17 +221,30 @@ ArkUI_PreviewDragStatus OH_ArkUI_NodeEvent_GetPreviewDragStatus(ArkUI_NodeEvent* int32_t OH_ArkUI_DragEvent_DisableDefaultDropAnimation(ArkUI_DragEvent* event, bool disable); /** - * @brief Sets the data processing mode. + * @brief Obtains the drop operation from a drag event. * * @param event Indicates the pointer to an ArkUI_DragEvent object. - * @param dropOperation Indicates the data processing mode. + * @param operation Indicates the drop operation which the data receiver set. * @return Returns the result code. * Returns {@link ARKUI_ERROR_CODE_NO_ERROR} if the operation is successful. * Returns {@link ARKUI_ERROR_CODE_PARAM_INVALID} if a parameter error occurs. + * Possible causes: 1. The given parameters are null or the given event is not a valid DragEvent. * @since 12 */ int32_t OH_ArkUI_DragEvent_SetSuggestedDropOperation(ArkUI_DragEvent* event, ArkUI_DropOperation dropOperation); +/** + * @brief Obtains the drop operation from a drag event. + * + * @param event Indicates the pointer to an ArkUI_DragEvent object. + * @param operation Indicates the drop operation which the data receiver set. + * @return Returns the result code. + * Returns {@link ARKUI_ERROR_CODE_NO_ERROR} if the operations successful. + * Returns {@link ARKUI_ERROR_CODE_PARAM_INVALID} if a parameter error occurs. + * @since 12 + */ +int32_t OH_ArkUI_DragEvent_GetDropOperation(ArkUI_DragEvent* event, ArkUI_DropOperation* operation); + /** * @brief Sets the result for a drag event. * diff --git a/interfaces/native/event/drag_and_drop_impl.cpp b/interfaces/native/event/drag_and_drop_impl.cpp index 6ef24b7c1cd..77cb2d0874d 100644 --- a/interfaces/native/event/drag_and_drop_impl.cpp +++ b/interfaces/native/event/drag_and_drop_impl.cpp @@ -562,6 +562,21 @@ int32_t OH_ArkUI_DragEvent_SetSuggestedDropOperation(ArkUI_DragEvent* event, Ark return ARKUI_ERROR_CODE_NO_ERROR; } +int32_t OH_ArkUI_DragEvent_GetDropOperation(ArkUI_DragEvent* event, ArkUI_DropOperation* operation) +{ + if (!event || !operation) { + return ARKUI_ERROR_CODE_PARAM_INVALID; + } + auto* dragEvent = reinterpret_cast(event); + if (dragEvent->dragBehavior >= static_cast(ArkUI_DropOperation::ARKUI_DROP_OPERATION_COPY) && + dragEvent->dragBehavior <= static_cast(ArkUI_DropOperation::ARKUI_DROP_OPERATION_MOVE)) { + *operation = static_cast(dragEvent->dragBehavior); + } else { + *operation = ARKUI_DROP_OPERATION_COPY; + } + return ARKUI_ERROR_CODE_NO_ERROR; +} + float OH_ArkUI_DragEvent_GetPreviewTouchPointX(ArkUI_DragEvent* event) { if (!event) { diff --git a/interfaces/native/libace.ndk.json b/interfaces/native/libace.ndk.json index 28294f0de18..3d644c29dab 100644 --- a/interfaces/native/libace.ndk.json +++ b/interfaces/native/libace.ndk.json @@ -1779,6 +1779,10 @@ "first_introduced": "12", "name": "OH_ArkUI_DragEvent_SetSuggestedDropOperation" }, + { + "first_introduced": "12", + "name": "OH_ArkUI_DragEvent_GetDropOperation" + }, { "first_introduced": "12", "name": "OH_ArkUI_DragEvent_SetDragResult" diff --git a/test/unittest/interfaces/drag_and_drop_test.cpp b/test/unittest/interfaces/drag_and_drop_test.cpp index c8aa18c48bd..c27c7d28d25 100644 --- a/test/unittest/interfaces/drag_and_drop_test.cpp +++ b/test/unittest/interfaces/drag_and_drop_test.cpp @@ -627,4 +627,29 @@ HWTEST_F(DragAndDropTest, DragAndDropTest020, TestSize.Level1) ret = OHOS::Ace::NodeModel::ConvertToNodeEventType(ON_DRAG_END); EXPECT_EQ(ret, static_cast(NODE_ON_DRAG_END)); } + +/** + * @tc.name: DragAndDropTest0021 + * @tc.desc: test OH_ArkUI_DragEvent_GetDropOperation. + * @tc.type: FUNC + */ +HWTEST_F(DragAndDropTest, DragAndDropTest021, TestSize.Level1) +{ + /** + *@tc.steps : step1.create and set property. + */ + ArkUIDragEvent dragEvent; + dragEvent.dragBehavior = ArkUI_DropOperation::ARKUI_DROP_OPERATION_MOVE; + auto* drag_Event = reinterpret_cast(&dragEvent); + ArkUI_DropOperation operation; + auto ret = OH_ArkUI_DragEvent_GetDropOperation(drag_Event, &operation); + + /** + * @tc.expected: Return expected results. + */ + EXPECT_EQ(ret, ARKUI_ERROR_CODE_NO_ERROR); + EXPECT_EQ(operation, ArkUI_DropOperation::ARKUI_DROP_OPERATION_MOVE); + EXPECT_EQ(OH_ArkUI_DragEvent_GetDropOperation(nullptr, &operation), ARKUI_ERROR_CODE_PARAM_INVALID); + EXPECT_EQ(OH_ArkUI_DragEvent_GetDropOperation(drag_Event, nullptr), ARKUI_ERROR_CODE_PARAM_INVALID); +} } // namespace OHOS::Ace \ No newline at end of file