From 002563211f82475836438b04363959beed63fe37 Mon Sep 17 00:00:00 2001 From: lmxxf Date: Fri, 8 Aug 2025 20:19:54 +0800 Subject: [PATCH] =?UTF-8?q?bugfix:=20=E7=AA=97=E5=8F=A3=E5=A4=B1=E7=84=A6?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E5=8F=91=E9=80=81=E8=A7=A6=E6=91=B8=E5=8F=96?= =?UTF-8?q?=E6=B6=88=E4=BA=8B=E4=BB=B6=E6=9D=A5=E6=B8=85=E7=90=86=E6=89=80?= =?UTF-8?q?=E6=9C=89=E6=8C=89=E4=B8=8B=E7=8A=B6=E6=80=81=E7=9A=84=E6=8E=A7?= =?UTF-8?q?=E4=BB=B6=20Signed-off-by:=20lmxxff=20=20Chan?= =?UTF-8?q?ge-Id:=20I803d66edc9ac216aabb990b8a256fe3605bff753?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I86fb7d56d6bcc4b0df6e63b8351e6373ea321974 --- .../core/pipeline_ng/pipeline_context.cpp | 36 +++++++++++++++++++ .../core/pipeline_ng/pipeline_context.h | 2 ++ 2 files changed, 38 insertions(+) diff --git a/frameworks/core/pipeline_ng/pipeline_context.cpp b/frameworks/core/pipeline_ng/pipeline_context.cpp index deafafe0570..8cb8ded8473 100755 --- a/frameworks/core/pipeline_ng/pipeline_context.cpp +++ b/frameworks/core/pipeline_ng/pipeline_context.cpp @@ -1845,6 +1845,11 @@ void PipelineContext::FlushWindowFocusChangedCallback(bool isFocus) ++iter; } } + + // 当窗口失焦时,发送触摸取消事件来清理所有按下状态的控件 + if (!isFocus) { + SendTouchCancelEventOnWindowUnfocused(); + } } void PipelineContext::AddWindowSizeChangeCallback(int32_t nodeId) @@ -2084,4 +2089,35 @@ void PipelineContext::SetCloseButtonStatus(bool isEnabled) CHECK_NULL_VOID(containerPattern); containerPattern->SetCloseButtonStatus(isEnabled); } + +void PipelineContext::SendTouchCancelEventOnWindowUnfocused() +{ + CHECK_RUN_ON(UI); + + // 遍历所有活跃的触摸事件,发送取消事件 + if (!touchEvents_.empty()) { + std::vector cancelEvents; + for (const auto& touchEvent : touchEvents_) { + // 创建取消事件 + TouchEvent cancelEvent = touchEvent; + cancelEvent.type = TouchType::CANCEL; + cancelEvents.push_back(cancelEvent); + } + + // 清空当前触摸事件列表 + touchEvents_.clear(); + + // 发送所有取消事件 + for (const auto& cancelEvent : cancelEvents) { + auto scalePoint = cancelEvent.CreateScalePoint(GetViewScale()); + eventManager_->DispatchTouchEvent(scalePoint); + } + + // 清理插件管道上下文 + touchPluginPipelineContext_.clear(); + + LOGI("Sent touch cancel events on window unfocused, count: %zu", cancelEvents.size()); + } +} + } // namespace OHOS::Ace::NG diff --git a/frameworks/core/pipeline_ng/pipeline_context.h b/frameworks/core/pipeline_ng/pipeline_context.h index 74462f4ffc0..2f9fccc1477 100644 --- a/frameworks/core/pipeline_ng/pipeline_context.h +++ b/frameworks/core/pipeline_ng/pipeline_context.h @@ -535,6 +535,8 @@ private: std::list delayedTasks_; ACE_DISALLOW_COPY_AND_MOVE(PipelineContext); + + void SendTouchCancelEventOnWindowUnfocused(); }; } // namespace OHOS::Ace::NG -- Gitee