From 0d97cf0f83e0f82479024a7f11f33d9083b1a521 Mon Sep 17 00:00:00 2001 From: wangzhihao Date: Wed, 27 Aug 2025 16:28:20 +0800 Subject: [PATCH] =?UTF-8?q?capi=E7=BC=A9=E6=94=BE=E5=BD=92=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangzhihao --- .../drag_drop/drag_drop_func_wrapper.cpp | 13 +++++++---- ...rag_drop_func_wrapper_test_ng_coverage.cpp | 23 +++++++++++++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) 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 4e3d030fb73..81e5d7c97b4 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 @@ -67,18 +67,21 @@ static bool CheckInternalDragging(const RefPtr& container) void GetShadowInfoArray( std::shared_ptr dragAction, std::vector& shadowInfos) { - auto minScaleWidth = NG::DragDropFuncWrapper::GetScaleWidth(dragAction->instanceId); for (auto& pixelMap : dragAction->pixelMapList) { double scale = 1.0; + int32_t width = 0; + int32_t height = 0; if (Referenced::RawPtr(pixelMap)) { - if (pixelMap->GetWidth() > minScaleWidth && dragAction->previewOption.isScaleEnabled) { - scale = minScaleWidth / pixelMap->GetWidth(); + width = pixelMap->GetWidth(); + height = pixelMap->GetHeight(); + if (width > 0 && height > 0 && dragAction->previewOption.isScaleEnabled) { + auto scaleData = DragDropManager::GetScaleInfo(width, height, false); + CHECK_NULL_VOID(scaleData); + scale = scaleData->scale; } auto pixelMapScale = dragAction->windowScale * scale; pixelMap->Scale(pixelMapScale, pixelMapScale, AceAntiAliasingOption::HIGH); } - int32_t width = pixelMap->GetWidth(); - int32_t height = pixelMap->GetHeight(); double x = dragAction->touchPointX; double y = dragAction->touchPointY; if (!dragAction->hasTouchPoint) { diff --git a/test/unittest/core/manager/drag_drop/drag_drop_func_wrapper_test_ng_coverage.cpp b/test/unittest/core/manager/drag_drop/drag_drop_func_wrapper_test_ng_coverage.cpp index 47cfa7c6eed..489d8fb16ae 100644 --- a/test/unittest/core/manager/drag_drop/drag_drop_func_wrapper_test_ng_coverage.cpp +++ b/test/unittest/core/manager/drag_drop/drag_drop_func_wrapper_test_ng_coverage.cpp @@ -18,6 +18,7 @@ #include "gtest/gtest.h" #define private public +#include "test/mock/base/mock_pixel_map.h" #include "test/mock/core/common/mock_theme_manager.h" #include "test/mock/core/render/mock_render_context.h" #include "test/mock/base/mock_drag_window.h" @@ -1917,4 +1918,26 @@ HWTEST_F(DragDropFuncWrapperTestNgCoverage, UpdateDragDropInitiatingStatus003, T DragDropGlobalController::GetInstance().UpdateDragDropInitiatingStatus(frameNode, DragDropInitiatingStatus::MOVING); EXPECT_EQ(DragDropGlobalController::GetInstance().currentDragNode_, frameNode); } + +/** + * @tc.name: Test DragDropFuncWrapperTestNgCoverage044 + * @tc.desc: Test StartDragAction func + * @tc.type: FUNC + * @tc.author: + */ +HWTEST_F(DragDropFuncWrapperTestNgCoverage, DragDropFuncWrapperTestNgCoverage044, TestSize.Level1) +{ + auto dragAction = std::make_shared(); + auto container = Container::Current(); + AceEngine& aceEngine = AceEngine::Get(); + aceEngine.AddContainer(0, container); + dragAction->instanceId = 0; + RefPtr mockPixelMap = AceType::MakeRefPtr(); + ASSERT_NE(mockPixelMap, nullptr); + dragAction->pixelMapList.push_back(mockPixelMap); + EXPECT_CALL(*mockPixelMap, GetWidth()).Times(1).WillOnce(testing::Return(10.0f)); + EXPECT_CALL(*mockPixelMap, GetHeight()).Times(1).WillOnce(testing::Return(10.0f)); + int32_t ret = DragDropFuncWrapper::StartDragAction(dragAction); + EXPECT_EQ(ret, -1); +} } // namespace OHOS::Ace::NG -- Gitee