diff --git a/frameworks/core/pipeline_ng/pipeline_context.cpp b/frameworks/core/pipeline_ng/pipeline_context.cpp index e1d3f0f650fbf774e8cb582dc70047e24f6f5823..510d9cd45bd8f1bafcf9dd4e0d35ad92d928e77d 100644 --- a/frameworks/core/pipeline_ng/pipeline_context.cpp +++ b/frameworks/core/pipeline_ng/pipeline_context.cpp @@ -2738,6 +2738,7 @@ void PipelineContext::OnTouchEvent( historyPointsById_.erase(scalePoint.id); } if (scalePoint.type == TouchType::DOWN) { + CompensateTouchMoveEventBeforeDown(); // Set focus state inactive while touch down event received SetIsFocusActive(false, FocusActiveReason::POINTER_EVENT); TouchRestrict touchRestrict { TouchRestrict::NONE }; @@ -2890,6 +2891,23 @@ void PipelineContext::OnTouchEvent( RequestFrame(); } +void PipelineContext::CompensateTouchMoveEventBeforeDown() +{ + if (touchEvents_.empty()) { + return; + } + std::unordered_map historyPointsById; + for (auto iter = touchEvents_.rbegin(); iter != touchEvents_.rend(); ++iter) { + auto scalePoint = (*iter).CreateScalePoint(GetViewScale()); + historyPointsById.emplace(scalePoint.id, scalePoint); + historyPointsById[scalePoint.id].history.insert(historyPointsById[scalePoint.id].history.begin(), scalePoint); + } + for (const auto& item : historyPointsById) { + eventManager_->DispatchTouchEvent(item.second); + } + touchEvents_.clear(); +} + bool PipelineContext::CompensateTouchMoveEventFromUnhandledEvents(const TouchEvent& event) { std::vector history; diff --git a/frameworks/core/pipeline_ng/pipeline_context.h b/frameworks/core/pipeline_ng/pipeline_context.h index 36a8642e5b53f6208b7715cedfadfbb0b4cf0b63..b187cab64d97925ffe364d51ce4bdeda6a044502 100644 --- a/frameworks/core/pipeline_ng/pipeline_context.h +++ b/frameworks/core/pipeline_ng/pipeline_context.h @@ -1266,6 +1266,7 @@ private: void CompensateTouchMoveEvent(const TouchEvent& event); bool CompensateTouchMoveEventFromUnhandledEvents(const TouchEvent& event); + void CompensateTouchMoveEventBeforeDown(); void DispatchMouseToTouchEvent(const MouseEvent& event, const RefPtr& node); diff --git a/test/unittest/core/pipeline/pipeline_context_test_ng_two.cpp b/test/unittest/core/pipeline/pipeline_context_test_ng_two.cpp index 5a9faef270bd89929c23687ac619c07da82b31b2..ac7da190e61b62a76401aee56788163ade9cbbc1 100644 --- a/test/unittest/core/pipeline/pipeline_context_test_ng_two.cpp +++ b/test/unittest/core/pipeline/pipeline_context_test_ng_two.cpp @@ -421,5 +421,36 @@ HWTEST_F(PipelineContextTestNg, PipelineContextTestNg140, TestSize.Level1) ASSERT_NE(context_->textFieldManager_, nullptr); } +/** + * @tc.name: PipelineContextTestNg303 + * @tc.desc: Test the function OnMouseMoveEventForAxisEvent. + * @tc.type: FUNC + */ +HWTEST_F(PipelineContextTestNg, PipelineContextTestNg303, TestSize.Level1) +{ + /** + * @tc.steps1: initialize parameters. + * @tc.expected: initialize pipeline, touch event. + */ + ASSERT_NE(context_, nullptr); + context_->SetEventManager(AceType::MakeRefPtr()); + TouchEvent touchEventOne; + touchEventOne.id = 0; + touchEventOne.type = TouchType::MOVE; + TouchEvent touchEventTwo; + touchEventTwo.id = 1; + touchEventTwo.type = TouchType::MOVE; + + /** + * @tc.steps2: Call the function CompensateTouchMoveEventBeforeDown. + * @tc.expected: Test if this function is available and the events is consumed. + */ + context_->CompensateTouchMoveEventBeforeDown(); + context_->touchEvents_.push_back(touchEventOne); + context_->touchEvents_.push_back(touchEventTwo); + context_->CompensateTouchMoveEventBeforeDown(); + EXPECT_TRUE(context_->touchEvents_.empty()); +} + } // namespace NG } // namespace OHOS::Ace \ No newline at end of file