diff --git a/frameworks/core/common/event_manager.cpp b/frameworks/core/common/event_manager.cpp index 68b59d87ce6010d5cef8ffb56dd1b1bf391ae401..6506b38fb6ab128382322ea651a3031ed67a2338 100644 --- a/frameworks/core/common/event_manager.cpp +++ b/frameworks/core/common/event_manager.cpp @@ -1050,6 +1050,7 @@ void EventManager::CleanHoverStatusForDragBegin() if (!AceApplicationInfo::GetInstance().GreatOrEqualTargetAPIVersion(PlatformVersion::VERSION_TWELVE)) { return; } + isDragCancelPending_ = true; TAG_LOGD(AceLogTag::ACE_DRAG, "Clean mouse status for drag begin."); MouseEvent falsifyEvent = lastMouseEvent_; TouchTestResult testResult; @@ -1063,6 +1064,7 @@ void EventManager::CleanHoverStatusForDragBegin() } mouseTestResults_.clear(); pressMouseTestResultsMap_[{ lastMouseEvent_.id, lastMouseEvent_.button }].clear(); + isDragCancelPending_ = false; } void EventManager::RegisterDragTouchEventListener( @@ -1623,7 +1625,8 @@ bool EventManager::DispatchMouseEventInLessAPI13(const MouseEvent& event) void EventManager::DispatchMouseEventToPressResults(const MouseEvent& event, const MouseTestResult& targetResults, MouseTestResult& handledResults, bool& isStopPropagation) { - for (const auto& mouseTarget : targetResults) { + auto targetPressResults = targetResults; + for (const auto& mouseTarget : targetPressResults) { if (!mouseTarget) { continue; } diff --git a/frameworks/core/components_ng/manager/post_event/post_event_manager.cpp b/frameworks/core/components_ng/manager/post_event/post_event_manager.cpp index 61e2fd7925c5333a53a2eab0e6433cc24bf8afaf..d5122a00b53be45876c2093c9f994c13b7047901 100644 --- a/frameworks/core/components_ng/manager/post_event/post_event_manager.cpp +++ b/frameworks/core/components_ng/manager/post_event/post_event_manager.cpp @@ -101,7 +101,11 @@ bool PostEventManager::PostMouseEvent(const RefPtr& uiNode, MouseEve CHECK_NULL_RETURN(pipelineContext, false); mouseEvent.passThrough = true; passThroughResult_ = false; - pipelineContext->OnMouseEvent(mouseEvent, frameNode); + auto eventManager = pipelineContext->GetEventManager(); + CHECK_NULL_RETURN(eventManager, false); + if (!eventManager->IsDragCancelPending()) { + pipelineContext->OnMouseEvent(mouseEvent, frameNode); + } mouseEvent.passThrough = false; targetNode_.Reset(); return passThroughResult_; diff --git a/test/unittest/core/manager/post_event_manager_test_ng.cpp b/test/unittest/core/manager/post_event_manager_test_ng.cpp index e3c8f747307624cf765e08534317e0ed0571bbf7..52d34d0965ca0f7e214e4bbc7a6ab99599220c04 100644 --- a/test/unittest/core/manager/post_event_manager_test_ng.cpp +++ b/test/unittest/core/manager/post_event_manager_test_ng.cpp @@ -1112,4 +1112,37 @@ HWTEST_F(PostEventManagerTestNg, ClearPostInputActionsTest001, TestSize.Level1) postEventManager_->ClearPostInputActions(UInode, touchUpEvent.id); EXPECT_TRUE(postEventManager_->postInputEventAction_.empty()); } + +/** + * @tc.name: PostMouseEventTest002 + * @tc.desc: test PostMouseEvent func. + * @tc.type: FUNC + */ +HWTEST_F(PostEventManagerTestNg, PostMouseEventTest002, TestSize.Level1) +{ + /** + * @tc.steps: step1. construct a FrameNode and set gesture. + */ + Init(); + + /** + * @tc.steps: step2. test PostMouseEvent. + */ + auto frameNode = AceType::MakeRefPtr(ROOT_TAG, -1, AceType::MakeRefPtr(), true); + auto uiNode = AceType::DynamicCast(frameNode); + MouseEvent mouseEvent; + mouseEvent.touchEventId = 1; + auto pipelineContext = PipelineContext::GetCurrentContextSafelyWithCheck(); + ASSERT_NE(pipelineContext, nullptr); + pipelineContext->eventManager_ = AceType::MakeRefPtr(); + ASSERT_NE(pipelineContext->eventManager_, nullptr); + pipelineContext->eventManager_->isDragCancelPending_ = false; + postEventManager_->passThroughResult_ = true; + postEventManager_->PostMouseEvent(uiNode, std::move(mouseEvent)); + pipelineContext->eventManager_->isDragCancelPending_ = true; + MouseEvent mouseEventEx; + mouseEventEx.touchEventId = 2; + postEventManager_->PostMouseEvent(uiNode, std::move(mouseEventEx)); + EXPECT_FALSE(postEventManager_->passThroughResult_); +} } // namespace OHOS::Ace::NG