mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2024-11-27 17:21:11 +00:00
onItemDrag适配appSubWindow
Signed-off-by: tomkl123 <wangyansong11@huawei.com>
This commit is contained in:
parent
651bc21b83
commit
50f529227c
@ -221,51 +221,36 @@ void DrawPixelMapInner(RSCanvas* canvas, const RefPtr<PixelMap>& pixmap, int32_t
|
||||
RefPtr<DragWindow> DragWindow::CreateDragWindow(
|
||||
const std::string& windowName, 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_DRAGGING_EFFECT);
|
||||
option->SetWindowMode(OHOS::Rosen::WindowMode::WINDOW_MODE_FLOATING);
|
||||
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;
|
||||
return CreateDragWindow({ windowName, x, y, width, height });
|
||||
}
|
||||
|
||||
RefPtr<DragWindow> DragWindow::CreateDragWindow(
|
||||
const std::string& windowName, int32_t parentWindowId, int32_t x, int32_t y, uint32_t width, uint32_t height)
|
||||
RefPtr<DragWindow> DragWindow::CreateDragWindow(const DragWindowParams& params)
|
||||
{
|
||||
int32_t halfWidth = static_cast<int32_t>(width) / 2;
|
||||
int32_t halfHeight = static_cast<int32_t>(height) / 2;
|
||||
int32_t halfWidth = static_cast<int32_t>(params.width) / 2;
|
||||
int32_t halfHeight = static_cast<int32_t>(params.height) / 2;
|
||||
|
||||
OHOS::sptr<OHOS::Rosen::WindowOption> option = new OHOS::Rosen::WindowOption();
|
||||
option->SetWindowRect({ x - halfWidth, y - halfHeight, width, height });
|
||||
option->SetWindowRect({ params.x - halfWidth, params.y - halfHeight, params.width, params.height });
|
||||
option->SetHitOffset(halfWidth, halfHeight);
|
||||
option->SetWindowType(OHOS::Rosen::WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
|
||||
if (params.parentWindowId == -1) {
|
||||
option->SetWindowType(OHOS::Rosen::WindowType::WINDOW_TYPE_DRAGGING_EFFECT);
|
||||
} else {
|
||||
option->SetParentId(params.parentWindowId);
|
||||
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);
|
||||
OHOS::sptr<OHOS::Rosen::Window> dragWindow = OHOS::Rosen::Window::Create(params.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);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto window = AceType::MakeRefPtr<DragWindowOhos>(dragWindow);
|
||||
window->SetSize(width, height);
|
||||
window->SetSize(params.width, params.height);
|
||||
return window;
|
||||
}
|
||||
|
||||
|
@ -44,10 +44,18 @@ class ACE_EXPORT DragWindow : public AceType {
|
||||
DECLARE_ACE_TYPE(DragWindow, AceType);
|
||||
|
||||
public:
|
||||
struct DragWindowParams {
|
||||
std::string windowName;
|
||||
int32_t x = 0;
|
||||
int32_t y = 0;
|
||||
uint32_t width = 0;
|
||||
uint32_t height = 0;
|
||||
int32_t parentWindowId = -1;
|
||||
};
|
||||
|
||||
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> CreateDragWindow(const DragWindowParams& params);
|
||||
|
||||
static RefPtr<DragWindow> CreateTextDragWindow(
|
||||
const std::string& windowName, int32_t x, int32_t y, uint32_t width, uint32_t height);
|
||||
|
@ -61,6 +61,10 @@ RefPtr<DragDropProxy> DragDropManager::CreateAndShowDragWindow(
|
||||
SetIsDragged(true);
|
||||
isDragCancel_ = false;
|
||||
#if !defined(PREVIEW)
|
||||
if (GetWindowId() == -1) {
|
||||
const float windowScale = GetWindowScale();
|
||||
pixelMap->Scale(windowScale, windowScale, AceAntiAliasingOption::HIGH);
|
||||
}
|
||||
CreateDragWindow(info, pixelMap->GetWidth(), pixelMap->GetHeight());
|
||||
CHECK_NULL_RETURN(dragWindow_, nullptr);
|
||||
dragWindow_->DrawPixelMap(pixelMap);
|
||||
@ -104,20 +108,57 @@ RefPtr<DragDropProxy> DragDropManager::CreateTextDragDropProxy()
|
||||
void DragDropManager::CreateDragWindow(const GestureEvent& info, uint32_t width, uint32_t height)
|
||||
{
|
||||
#if !defined(PREVIEW)
|
||||
// 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());
|
||||
const int32_t windowId = GetWindowId();
|
||||
auto pipeline = PipelineContext::GetCurrentContext();
|
||||
CHECK_NULL_VOID(pipeline);
|
||||
float windowScale = GetWindowScale();
|
||||
Rect rect = Rect(0, 0, 0, 0);
|
||||
if (!isDragWindowSubWindow_ || NearEqual(windowScale, 1.0f)) {
|
||||
rect = pipeline->GetDisplayWindowRectInfo();
|
||||
}
|
||||
if (isDragWindowShow_) {
|
||||
windowScale = 1.0f;
|
||||
}
|
||||
const int32_t windowY = static_cast<int32_t>(info.GetGlobalPoint().GetY() * windowScale);
|
||||
const int32_t windowX = static_cast<int32_t>(info.GetGlobalPoint().GetX() * windowScale);
|
||||
dragWindow_ = DragWindow::CreateDragWindow(
|
||||
"APP_DRAG_WINDOW", container->GetWindowId(), windowX, windowY, width, height);
|
||||
if (!dragWindow_) {
|
||||
{ "APP_DRAG_WINDOW", windowX + rect.Left(), windowY + rect.Top(), width, height, windowId });
|
||||
if (dragWindow_) {
|
||||
dragWindow_->SetOffset(rect.Left(), rect.Top());
|
||||
} else {
|
||||
TAG_LOGW(AceLogTag::ACE_DRAG, "Create drag window failed!");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t DragDropManager::GetWindowId()
|
||||
{
|
||||
auto windowId = -1;
|
||||
auto container = Container::Current();
|
||||
CHECK_NULL_RETURN(container, windowId);
|
||||
|
||||
if (!container->IsSceneBoardEnabled()) {
|
||||
isDragWindowSubWindow_ = false;
|
||||
return windowId;
|
||||
}
|
||||
|
||||
if (!container->IsMainWindow()) {
|
||||
// The window manager currently does not support creating child windows within child windows,
|
||||
// so the main window is used here
|
||||
container = Container::GetContainer(CONTAINER_ID_DIVIDE_SIZE);
|
||||
CHECK_NULL_RETURN(container, windowId);
|
||||
if (!container->IsMainWindow()) {
|
||||
isDragWindowSubWindow_ = false;
|
||||
return windowId;
|
||||
}
|
||||
}
|
||||
|
||||
windowId = container->GetWindowId();
|
||||
isDragWindowSubWindow_ = true;
|
||||
|
||||
return windowId;
|
||||
}
|
||||
|
||||
RefPtr<FrameNode> DragDropManager::CreateDragRootNode(const RefPtr<UINode>& customNode)
|
||||
{
|
||||
auto pipeline = PipelineContext::GetCurrentContext();
|
||||
@ -1069,11 +1110,14 @@ void DragDropManager::OnItemDragMove(float globalX, float globalY, int32_t dragg
|
||||
auto container = Container::Current();
|
||||
CHECK_NULL_VOID(container);
|
||||
|
||||
UpdateDragWindowPosition(static_cast<int32_t>(globalX), static_cast<int32_t>(globalY));
|
||||
const float windowScale = isDragWindowSubWindow_ ? 1.0f : GetWindowScale();
|
||||
const float windowX = globalX * windowScale;
|
||||
const float windowY = globalY * windowScale;
|
||||
UpdateDragWindowPosition(static_cast<int32_t>(windowX), static_cast<int32_t>(windowY));
|
||||
|
||||
OHOS::Ace::ItemDragInfo itemDragInfo;
|
||||
itemDragInfo.SetX(pipeline->ConvertPxToVp(Dimension(globalX, DimensionUnit::PX)));
|
||||
itemDragInfo.SetY(pipeline->ConvertPxToVp(Dimension(globalY, DimensionUnit::PX)));
|
||||
itemDragInfo.SetX(pipeline->ConvertPxToVp(Dimension(windowX, DimensionUnit::PX)));
|
||||
itemDragInfo.SetY(pipeline->ConvertPxToVp(Dimension(windowY, DimensionUnit::PX)));
|
||||
|
||||
// use -1 for grid item not in eventGrid
|
||||
auto getDraggedIndex = [draggedGrid = draggedGridFrameNode_, draggedIndex, dragType](
|
||||
@ -1127,10 +1171,13 @@ void DragDropManager::OnItemDragEnd(float globalX, float globalY, int32_t dragge
|
||||
dragDropState_ = DragDropMgrState::IDLE;
|
||||
auto pipeline = PipelineContext::GetCurrentContext();
|
||||
CHECK_NULL_VOID(pipeline);
|
||||
const float windowScale = isDragWindowSubWindow_ ? 1.0f : GetWindowScale();
|
||||
const float windowX = globalX * windowScale;
|
||||
const float windowY = globalY * windowScale;
|
||||
|
||||
OHOS::Ace::ItemDragInfo itemDragInfo;
|
||||
itemDragInfo.SetX(pipeline->ConvertPxToVp(Dimension(globalX, DimensionUnit::PX)));
|
||||
itemDragInfo.SetY(pipeline->ConvertPxToVp(Dimension(globalY, DimensionUnit::PX)));
|
||||
itemDragInfo.SetX(pipeline->ConvertPxToVp(Dimension(windowX, DimensionUnit::PX)));
|
||||
itemDragInfo.SetY(pipeline->ConvertPxToVp(Dimension(windowY, DimensionUnit::PX)));
|
||||
|
||||
auto dragFrameNode = FindDragFrameNodeByPosition(globalX, globalY);
|
||||
if (!dragFrameNode) {
|
||||
|
@ -481,6 +481,7 @@ private:
|
||||
bool ReachMoveLimit(const PointerEvent& pointerEvent, const Point& point);
|
||||
bool IsUIExtensionShowPlaceholder(const RefPtr<NG::UINode>& node);
|
||||
bool IsUIExtensionComponent(const RefPtr<NG::UINode>& node);
|
||||
int32_t GetWindowId();
|
||||
|
||||
std::map<int32_t, WeakPtr<FrameNode>> dragFrameNodes_;
|
||||
std::map<int32_t, WeakPtr<FrameNode>> gridDragFrameNodes_;
|
||||
@ -519,6 +520,7 @@ private:
|
||||
bool isDragWindowShow_ = false;
|
||||
bool hasNotifiedTransformation_ = false;
|
||||
bool isPullMoveReceivedForCurrentDrag_ = false;
|
||||
bool isDragWindowSubWindow_ = false;
|
||||
VelocityTracker velocityTracker_;
|
||||
DragDropMgrState dragDropState_ = DragDropMgrState::IDLE;
|
||||
PreDragStatus preDragStatus_ = PreDragStatus::ACTION_DETECTING_STATUS;
|
||||
|
@ -24,8 +24,7 @@ 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 */)
|
||||
RefPtr<DragWindow> DragWindow::CreateDragWindow(const DragWindowParams& /* params */)
|
||||
{
|
||||
static RefPtr<DragWindow> dragWindow = AceType::MakeRefPtr<MockDragWindow>();
|
||||
return dragWindow;
|
||||
|
@ -23,7 +23,7 @@ void DragDropManagerTestNg::SetUpTestCase()
|
||||
{
|
||||
MockPipelineContext::SetUp();
|
||||
MockContainer::SetUp();
|
||||
MOCK_DRAG_WINDOW = DragWindow::CreateDragWindow("", 0, 0, 0, 0, 0);
|
||||
MOCK_DRAG_WINDOW = DragWindow::CreateDragWindow({"", 0, 0, 0, 0, 0});
|
||||
}
|
||||
|
||||
void DragDropManagerTestNg::TearDownTestCase()
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "grid_test_ng.h"
|
||||
|
||||
#include "test/mock/base/mock_drag_window.h"
|
||||
#include "test/mock/core/common/mock_container.h"
|
||||
#include "test/mock/core/common/mock_theme_manager.h"
|
||||
#include "test/mock/core/pipeline/mock_pipeline_context.h"
|
||||
|
||||
@ -41,10 +42,12 @@ 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, 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());
|
||||
auto container = Container::GetContainer(CONTAINER_ID_DIVIDE_SIZE);
|
||||
EXPECT_CALL(*(AceType::DynamicCast<MockContainer>(container)), GetWindowId()).Times(AnyNumber());
|
||||
EXPECT_CALL(*MockPipelineContext::pipeline_, FlushUITasks).Times(AnyNumber());
|
||||
|
||||
#ifndef TEST_IRREGULAR_GRID
|
||||
|
@ -15,6 +15,7 @@
|
||||
|
||||
#include "list_test_ng.h"
|
||||
#include "test/mock/base/mock_drag_window.h"
|
||||
#include "test/mock/core/common/mock_container.h"
|
||||
#include "core/components/common/properties/shadow_config.h"
|
||||
#include "core/components_ng/pattern/button/button_layout_property.h"
|
||||
#include "core/components_ng/pattern/button/button_model_ng.h"
|
||||
@ -989,10 +990,12 @@ HWTEST_F(ListCommonTestNg, EventHub001, TestSize.Level1)
|
||||
/**
|
||||
* @tc.steps: step1. EXPECT_CALL DrawFrameNode, HandleOnItemDragStart will trigger it
|
||||
*/
|
||||
auto mockDragWindow = MockDragWindow::CreateDragWindow("", 0, 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());
|
||||
auto container = Container::GetContainer(CONTAINER_ID_DIVIDE_SIZE);
|
||||
EXPECT_CALL(*(AceType::DynamicCast<MockContainer>(container)), GetWindowId()).Times(AnyNumber());
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Run List GetDragExtraParams func.
|
||||
|
Loading…
Reference in New Issue
Block a user