From c8e4ddcb69365848b87ff1aebcd9b09232fc0b59 Mon Sep 17 00:00:00 2001 From: b30058220 Date: Sat, 6 Jul 2024 10:29:47 +0000 Subject: [PATCH] add GetDisplayX and GetDisplayY Signed-off-by: b30058220 Change-Id: Icb6824d44d78c147a1ac1cbde4c63e7163e6922d --- .../core/components_ng/event/event_hub.cpp | 1 - .../components_ng/event/gesture_event_hub.cpp | 2 ++ .../manager/drag_drop/drag_drop_manager.cpp | 9 ++++++-- .../manager/drag_drop/drag_drop_manager.h | 2 +- frameworks/core/event/pointer_event.h | 10 +++++++++ frameworks/core/gestures/drag_event.h | 22 +++++++++++++++++++ .../manager/drag_drop_manager_test_ng.cpp | 2 +- 7 files changed, 43 insertions(+), 5 deletions(-) diff --git a/frameworks/core/components_ng/event/event_hub.cpp b/frameworks/core/components_ng/event/event_hub.cpp index 42645ab464c..78fe36c8ed0 100644 --- a/frameworks/core/components_ng/event/event_hub.cpp +++ b/frameworks/core/components_ng/event/event_hub.cpp @@ -274,7 +274,6 @@ bool EventHub::IsFireOnDrop(const RefPtr& info) || info->GetResult() == DragRet::DRAG_DEFAULT || info->GetResult() == DragRet::ENABLE_DROP || info->GetResult() == DragRet::DISABLE_DROP; - return true; } void EventHub::HandleInternalOnDrop(const RefPtr& info, const std::string& extraParams) diff --git a/frameworks/core/components_ng/event/gesture_event_hub.cpp b/frameworks/core/components_ng/event/gesture_event_hub.cpp index 4d02d1c30c1..c6f56c55046 100644 --- a/frameworks/core/components_ng/event/gesture_event_hub.cpp +++ b/frameworks/core/components_ng/event/gesture_event_hub.cpp @@ -729,6 +729,8 @@ void GestureEventHub::HandleOnDragStart(const GestureEvent& info) } event->SetScreenX(info.GetScreenLocation().GetX()); event->SetScreenY(info.GetScreenLocation().GetY()); + event->SetDisplayX(info.GetScreenLocation().GetX()); + event->SetDisplayY(info.GetScreenLocation().GetY()); event->SetSourceTool(info.GetSourceTool()); auto frameTag = frameNode->GetTag(); 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 ec48efaf7b0..b97e2b419f2 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 @@ -870,7 +870,7 @@ void DragDropManager::OnDragDrop(RefPtr& event, const RefP auto point = pointerEvent.GetPoint(); auto eventHub = dragFrameNode->GetEventHub(); CHECK_NULL_VOID(eventHub); - UpdateDragEvent(event, point); + UpdateDragEvent(event, pointerEvent); auto extraParams = eventHub->GetDragExtraParams(extraInfo_, point, DragEventType::DROP); eventHub->FireCustomerOnDragFunc(DragFuncType::DRAG_DROP, event, extraParams); eventHub->HandleInternalOnDrop(event, extraParams); @@ -1026,6 +1026,8 @@ void DragDropManager::FireOnDragEvent( event->SetY((double)point.GetY()); event->SetScreenX((double)point.GetScreenX()); event->SetScreenY((double)point.GetScreenY()); + event->SetDisplayX((double)pointerEvent.GetDisplayX()); + event->SetDisplayY((double)pointerEvent.GetDisplayY()); event->SetVelocity(velocityTracker_.GetVelocity()); event->SetSummary(summaryMap_); event->SetPreviewRect(GetDragWindowRect(point)); @@ -1388,12 +1390,15 @@ void DragDropManager::UpdateNotifyDragEvent( } } -void DragDropManager::UpdateDragEvent(RefPtr& event, const Point& point) +void DragDropManager::UpdateDragEvent(RefPtr& event, const OHOS::Ace::PointerEvent& pointerEvent) { + auto point = pointerEvent.GetPoint(); event->SetX(point.GetX()); event->SetY(point.GetY()); event->SetScreenX(point.GetScreenX()); event->SetScreenY(point.GetScreenY()); + event->SetDisplayX((double)pointerEvent.GetDisplayX()); + event->SetDisplayY((double)pointerEvent.GetDisplayY()); event->SetVelocity(velocityTracker_.GetVelocity()); event->SetSummary(summaryMap_); event->SetPreviewRect(GetDragWindowRect(point)); 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 2c94a812a48..7f30d7e49a8 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 @@ -141,7 +141,7 @@ public: void HideDragPreviewOverlay(); void HideDragPreviewWindow(int32_t containerId); bool IsMSDPDragging() const; - void UpdateDragEvent(RefPtr& event, const Point& point); + void UpdateDragEvent(RefPtr& event, const OHOS::Ace::PointerEvent& pointerEvent); void UpdateNotifyDragEvent( RefPtr& notifyEvent, const Point& point, const DragEventType dragEventType); bool CheckDragDropProxy(int64_t id) const; diff --git a/frameworks/core/event/pointer_event.h b/frameworks/core/event/pointer_event.h index d781f99b5ca..7915604acc7 100644 --- a/frameworks/core/event/pointer_event.h +++ b/frameworks/core/event/pointer_event.h @@ -89,6 +89,16 @@ struct PointerEvent final { return Point(x, y, x, y); } } + + int32_t GetDisplayX() const + { + return displayX; + } + + int32_t GetDisplayY() const + { + return displayY; + } }; } // namespace OHOS::Ace #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_EVENT_POINTER_EVENT_H \ No newline at end of file diff --git a/frameworks/core/gestures/drag_event.h b/frameworks/core/gestures/drag_event.h index 1d4b545b8a4..b42333db7e1 100644 --- a/frameworks/core/gestures/drag_event.h +++ b/frameworks/core/gestures/drag_event.h @@ -130,6 +130,26 @@ public: y_ = y; } + double GetDisplayX() const + { + return displayX_; + } + + double GetDisplayY() const + { + return displayY_; + } + + void SetDisplayX(double x) + { + displayX_ = x; + } + + void SetDisplayY(double y) + { + displayY_ = y; + } + void SetDescription(const std::string& description) { description_ = description; @@ -273,6 +293,8 @@ private: double screenY_ = 0.0; double x_ = 0.0; double y_ = 0.0; + double displayX_ = 0.0; + double displayY_ = 0.0; std::string description_; RefPtr pixelMap_; std::map summary_; diff --git a/test/unittest/core/manager/drag_drop_manager_test_ng.cpp b/test/unittest/core/manager/drag_drop_manager_test_ng.cpp index 0bb8a27607d..e710809c2d6 100644 --- a/test/unittest/core/manager/drag_drop_manager_test_ng.cpp +++ b/test/unittest/core/manager/drag_drop_manager_test_ng.cpp @@ -992,7 +992,7 @@ HWTEST_F(DragDropManagerTestNg, DragDropManagerTest017, TestSize.Level1) * @tc.steps: step3. call UpdateDragEvent. * @tc.expected: pipeline is not null. */ - dragDropManager->UpdateDragEvent(event, Point(1.0f, 1.0f)); + dragDropManager->UpdateDragEvent(event, PointerEvent(1, 1)); auto pipeline = PipelineContext::GetCurrentContext(); ASSERT_NE(pipeline, nullptr); }