!37032 onItemDrag适配新的窗口类型

Merge pull request !37032 from tomkl123/20240704_on_item_drag
This commit is contained in:
openharmony_ci 2024-07-05 17:50:21 +00:00 committed by Gitee
commit a9cd2d4ac5
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
7 changed files with 52 additions and 27 deletions

View File

@ -243,6 +243,32 @@ RefPtr<DragWindow> DragWindow::CreateDragWindow(
return window;
}
RefPtr<DragWindow> DragWindow::CreateDragWindow(
const std::string& windowName, int32_t parentWindowId, int32_t x, int32_t y, uint32_t width, uint32_t height)
{
int32_t halfWidth = static_cast<int32_t>(width) / 2;
int32_t halfHeight = static_cast<int32_t>(height) / 2;
OHOS::sptr<OHOS::Rosen::WindowOption> option = new OHOS::Rosen::WindowOption();
option->SetWindowRect({ x - halfWidth, y - halfHeight, width, height });
option->SetHitOffset(halfWidth, halfHeight);
option->SetWindowType(OHOS::Rosen::WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
option->SetWindowMode(OHOS::Rosen::WindowMode::WINDOW_MODE_FLOATING);
option->SetParentId(parentWindowId);
option->SetFocusable(false);
OHOS::sptr<OHOS::Rosen::Window> dragWindow = OHOS::Rosen::Window::Create(windowName, option);
CHECK_NULL_RETURN(dragWindow, nullptr);
OHOS::Rosen::WMError ret = dragWindow->Show();
if (ret != OHOS::Rosen::WMError::WM_OK) {
TAG_LOGE(AceLogTag::ACE_DRAG, "DragWindow CreateDragWindow, drag window Show() failed, ret: %d", ret);
}
auto window = AceType::MakeRefPtr<DragWindowOhos>(dragWindow);
window->SetSize(width, height);
return window;
}
RefPtr<DragWindow> DragWindow::CreateTextDragWindow(
const std::string& windowName, int32_t x, int32_t y, uint32_t width, uint32_t height)
{

View File

@ -46,6 +46,8 @@ class ACE_EXPORT DragWindow : public AceType {
public:
static RefPtr<DragWindow> CreateDragWindow(
const std::string& windowName, int32_t x, int32_t y, uint32_t width, uint32_t height);
static RefPtr<DragWindow> CreateDragWindow(
const std::string& windowName, int32_t parentWindowId, int32_t x, int32_t y, uint32_t width, uint32_t height);
static RefPtr<DragWindow> CreateTextDragWindow(
const std::string& windowName, int32_t x, int32_t y, uint32_t width, uint32_t height);

View File

@ -61,8 +61,6 @@ RefPtr<DragDropProxy> DragDropManager::CreateAndShowDragWindow(
SetIsDragged(true);
isDragCancel_ = false;
#if !defined(PREVIEW)
auto windowScale = GetWindowScale();
pixelMap->Scale(windowScale, windowScale, AceAntiAliasingOption::HIGH);
CreateDragWindow(info, pixelMap->GetWidth(), pixelMap->GetHeight());
CHECK_NULL_RETURN(dragWindow_, nullptr);
dragWindow_->DrawPixelMap(pixelMap);
@ -106,17 +104,15 @@ RefPtr<DragDropProxy> DragDropManager::CreateTextDragDropProxy()
void DragDropManager::CreateDragWindow(const GestureEvent& info, uint32_t width, uint32_t height)
{
#if !defined(PREVIEW)
auto pipeline = PipelineContext::GetCurrentContext();
CHECK_NULL_VOID(pipeline);
auto rect = pipeline->GetDisplayWindowRectInfo();
auto windowScale = GetWindowScale();
int32_t windowX = static_cast<int32_t>(info.GetGlobalPoint().GetX() * windowScale);
int32_t windowY = static_cast<int32_t>(info.GetGlobalPoint().GetY() * windowScale);
dragWindow_ = DragWindow::CreateDragWindow("APP_DRAG_WINDOW",
windowX + rect.Left(), windowY + rect.Top(), width, height);
if (dragWindow_) {
dragWindow_->SetOffset(rect.Left(), rect.Top());
} else {
// The window manager currently does not support creating child windows within child windows,
// so the main window is used here
auto container = Container::GetContainer(CONTAINER_ID_DIVIDE_SIZE);
CHECK_NULL_VOID(container);
int32_t windowX = static_cast<int32_t>(info.GetGlobalPoint().GetX());
int32_t windowY = static_cast<int32_t>(info.GetGlobalPoint().GetY());
dragWindow_ = DragWindow::CreateDragWindow(
"APP_DRAG_WINDOW", container->GetWindowId(), windowX, windowY, width, height);
if (!dragWindow_) {
TAG_LOGW(AceLogTag::ACE_DRAG, "Create drag window failed!");
}
#endif
@ -1068,14 +1064,11 @@ void DragDropManager::OnItemDragMove(float globalX, float globalY, int32_t dragg
auto container = Container::Current();
CHECK_NULL_VOID(container);
auto windowScale = GetWindowScale();
auto windowX = globalX * windowScale;
auto windowY = globalY * windowScale;
UpdateDragWindowPosition(static_cast<int32_t>(windowX), static_cast<int32_t>(windowY));
UpdateDragWindowPosition(static_cast<int32_t>(globalX), static_cast<int32_t>(globalY));
OHOS::Ace::ItemDragInfo itemDragInfo;
itemDragInfo.SetX(pipeline->ConvertPxToVp(Dimension(windowX, DimensionUnit::PX)));
itemDragInfo.SetY(pipeline->ConvertPxToVp(Dimension(windowY, DimensionUnit::PX)));
itemDragInfo.SetX(pipeline->ConvertPxToVp(Dimension(globalX, DimensionUnit::PX)));
itemDragInfo.SetY(pipeline->ConvertPxToVp(Dimension(globalY, DimensionUnit::PX)));
// use -1 for grid item not in eventGrid
auto getDraggedIndex = [draggedGrid = draggedGridFrameNode_, draggedIndex, dragType](
@ -1129,13 +1122,10 @@ void DragDropManager::OnItemDragEnd(float globalX, float globalY, int32_t dragge
dragDropState_ = DragDropMgrState::IDLE;
auto pipeline = PipelineContext::GetCurrentContext();
CHECK_NULL_VOID(pipeline);
auto windowScale = GetWindowScale();
auto windowX = globalX * windowScale;
auto windowY = globalY * windowScale;
OHOS::Ace::ItemDragInfo itemDragInfo;
itemDragInfo.SetX(pipeline->ConvertPxToVp(Dimension(windowX, DimensionUnit::PX)));
itemDragInfo.SetY(pipeline->ConvertPxToVp(Dimension(windowY, DimensionUnit::PX)));
itemDragInfo.SetX(pipeline->ConvertPxToVp(Dimension(globalX, DimensionUnit::PX)));
itemDragInfo.SetY(pipeline->ConvertPxToVp(Dimension(globalY, DimensionUnit::PX)));
auto dragFrameNode = FindDragFrameNodeByPosition(globalX, globalY);
if (!dragFrameNode) {

View File

@ -24,6 +24,13 @@ RefPtr<DragWindow> DragWindow::CreateDragWindow(
return dragWindow;
}
RefPtr<DragWindow> DragWindow::CreateDragWindow(const std::string& /* windowName */, int32_t /* parentWindowId */,
int32_t /* x */, int32_t /* y */, uint32_t /* width */, uint32_t /* height */)
{
static RefPtr<DragWindow> dragWindow = AceType::MakeRefPtr<MockDragWindow>();
return dragWindow;
}
RefPtr<DragWindow> DragWindow::CreateTextDragWindow(
const std::string& /* windowName */, int32_t /* x */, int32_t /* y */, uint32_t /* width */, uint32_t /* height */)
{

View File

@ -23,7 +23,7 @@ void DragDropManagerTestNg::SetUpTestCase()
{
MockPipelineContext::SetUp();
MockContainer::SetUp();
MOCK_DRAG_WINDOW = DragWindow::CreateDragWindow("", 0, 0, 0, 0);
MOCK_DRAG_WINDOW = DragWindow::CreateDragWindow("", 0, 0, 0, 0, 0);
}
void DragDropManagerTestNg::TearDownTestCase()

View File

@ -41,7 +41,7 @@ void GridTestNg::SetUpTestSuite()
auto themeConstants = CreateThemeConstants(THEME_PATTERN_GRID);
auto gridItemTheme = GridItemTheme::Builder().Build(themeConstants);
EXPECT_CALL(*themeManager, GetTheme(GridItemTheme::TypeId())).WillRepeatedly(Return(gridItemTheme));
RefPtr<DragWindow> dragWindow = DragWindow::CreateDragWindow("", 0, 0, 0, 0);
RefPtr<DragWindow> dragWindow = DragWindow::CreateDragWindow("", 0, 0, 0, 0, 0);
EXPECT_CALL(*(AceType::DynamicCast<MockDragWindow>(dragWindow)), DrawFrameNode(_)).Times(AnyNumber());
EXPECT_CALL(*(AceType::DynamicCast<MockDragWindow>(dragWindow)), MoveTo(_, _)).Times(AnyNumber());
EXPECT_CALL(*(AceType::DynamicCast<MockDragWindow>(dragWindow)), Destroy()).Times(AnyNumber());

View File

@ -888,7 +888,7 @@ HWTEST_F(ListCommonTestNg, EventHub001, TestSize.Level1)
/**
* @tc.steps: step1. EXPECT_CALL DrawFrameNode, HandleOnItemDragStart will trigger it
*/
auto mockDragWindow = MockDragWindow::CreateDragWindow("", 0, 0, 0, 0);
auto mockDragWindow = MockDragWindow::CreateDragWindow("", 0, 0, 0, 0, 0);
EXPECT_CALL(*(AceType::DynamicCast<MockDragWindow>(mockDragWindow)), DrawFrameNode(_)).Times(2);
EXPECT_CALL(*(AceType::DynamicCast<MockDragWindow>(mockDragWindow)), MoveTo).Times(AnyNumber());
EXPECT_CALL(*(AceType::DynamicCast<MockDragWindow>(mockDragWindow)), Destroy).Times(AnyNumber());