From 194d36b2d7c1270d0ae7bf02833c998fe8f8bfb8 Mon Sep 17 00:00:00 2001 From: rsyys Date: Thu, 21 Aug 2025 16:08:30 +0800 Subject: [PATCH 1/2] fix: double click focus Signed-off-by: rsyys --- window_scene/session/host/include/session.h | 4 ++ .../session/host/src/scb_system_session.cpp | 7 ++- window_scene/session/host/src/session.cpp | 36 +++++++++-- .../include/scene_input_manager.h | 3 +- .../include/scene_session_dirty_manager.h | 4 +- .../include/scene_session_manager.h | 2 + .../src/scene_input_manager.cpp | 6 ++ .../src/scene_session_manager.cpp | 63 +++++++++++++++++++ window_scene/test/unittest/session_test3.cpp | 16 +++++ 9 files changed, 132 insertions(+), 9 deletions(-) diff --git a/window_scene/session/host/include/session.h b/window_scene/session/host/include/session.h index e5d8b434d1..5e13951a05 100644 --- a/window_scene/session/host/include/session.h +++ b/window_scene/session/host/include/session.h @@ -67,6 +67,8 @@ using NotifyBufferAvailableChangeFunc = std::function; using NotifyRequestFocusStatusNotifyManagerFunc = std::function; +using CheckPointerEventDispatchFocusFunc = + std::function using NotifyBackPressedFunc = std::function; using NotifySessionFocusableChangeFunc = std::function; using NotifySessionTouchableChangeFunc = std::function; @@ -391,6 +393,7 @@ public: void SetSessionPropertyChangeNotifyManagerListener(const NotifySessionPropertyChangeNotifyManagerFunc& func); void SetDisplayIdChangedNotifyManagerListener(const NotifyDisplayIdChangedNotifyManagerFunc& func); void SetRequestFocusStatusNotifyManagerListener(const NotifyRequestFocusStatusNotifyManagerFunc& func); + void SetCheckPointerEventDispatchFocusListener(const CheckPointerEventDispatchFocusFunc& func); void SetNotifyUIRequestFocusFunc(const NotifyUIRequestFocusFunc& func); void SetNotifyUILostFocusFunc(const NotifyUILostFocusFunc& func); void SetGetStateFromManagerListener(const GetStateFromManagerFunc& func); @@ -841,6 +844,7 @@ protected: NotifyDisplayIdChangedNotifyManagerFunc displayIdChangedNotifyManagerFunc_; NotifySessionStateChangeNotifyManagerFunc sessionStateChangeNotifyManagerFunc_; NotifyRequestFocusStatusNotifyManagerFunc requestFocusStatusNotifyManagerFunc_; + CheckPointerEventDispatchFocusFunc checkPointerEventDispatchFocusFunc_; NotifyUIRequestFocusFunc requestFocusFunc_; NotifyUILostFocusFunc lostFocusFunc_; GetStateFromManagerFunc getStateFromManagerFunc_; diff --git a/window_scene/session/host/src/scb_system_session.cpp b/window_scene/session/host/src/scb_system_session.cpp index 3f5867318b..630b01aad3 100644 --- a/window_scene/session/host/src/scb_system_session.cpp +++ b/window_scene/session/host/src/scb_system_session.cpp @@ -70,9 +70,12 @@ WSError SCBSystemSession::ProcessPointDownSession(int32_t posX, int32_t posY) { const auto id = GetPersistentId(); const auto type = GetWindowType(); - TLOGD(WmsLogTag::WMS_INPUT_KEY_FLOW, "id: %{public}d, type: %{public}d", id, type); + TLOGI(WmsLogTag::WMS_INPUT_KEY_FLOW, "SCBSystemSession id: %{public}d, type: %{public}d", id, type); auto ret = SceneSession::ProcessPointDownSession(posX, posY); - PresentFocusIfPointDown(); + if (CheckPointerEventDispatchFocus(posX, posY)) { + TLOGI(WmsLogTag::WMS_INPUT_KEY_FLOW, "SCBSystemSession check success ,id: %{public}d, type: %{public}d", id, type); + PresentFocusIfPointDown(); + } return ret; } diff --git a/window_scene/session/host/src/session.cpp b/window_scene/session/host/src/session.cpp index 6ffc701025..65a8cf752f 100644 --- a/window_scene/session/host/src/session.cpp +++ b/window_scene/session/host/src/session.cpp @@ -2444,6 +2444,16 @@ WSError Session::HandleSubWindowClick(int32_t action, int32_t sourceType, bool i return WSError::WS_OK; } +bool Session::CheckPointerEventDispatchFocus(int32_t x, int32_t y) { + TLOGI(WmsLogTag::WMS_EVENT, "in"); + if (checkPointerEventDispatchFocusFunc_) { + TLOGI(WmsLogTag::WMS_EVENT, "cllback checkPointerEventDispatchFocusFunc_"); + checkPointerEventDispatchFocusFunc_(GetPersistentId(), x, y , GetDisplayId()); + return true; + } + return true; +} + WSError Session::HandlePointerEventForFocus(const std::shared_ptr& pointerEvent, bool isExecuteDelayRaise) { @@ -2451,16 +2461,29 @@ WSError Session::HandlePointerEventForFocus(const std::shared_ptrGetId(), pointerEvent->DumpPointerAction(), persistentId_); auto pointerAction = pointerEvent->GetPointerAction(); auto sourceType = pointerEvent->GetSourceType(); bool isHoverDown = pointerAction == MMI::PointerEvent::POINTER_ACTION_HOVER_ENTER && sourceType == MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN; bool isPointDown = (pointerAction == MMI::PointerEvent::POINTER_ACTION_DOWN) || - (pointerAction == MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN) || isHoverDown; + (pointerAction == MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN); + bool isDown = isPointDown || isHoverDown; + + if (isPointDown && IsSystemSession() && !(systemConfig_.IsPcWindow() || systemConfig_.IsFreeMultiWindowMode())) { + MMI::PointerEvent::PointerItem pointerItem; + if (pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), pointerItem)) { + TLOGI(WmsLogTag::WMS_EVENT, "before CheckPointerEventDispatchFocus"); + if (!CheckPointerEventDispatchFocus(pointerItem.GetDisplayX(), pointerItem.GetDisplayY())) { + TLOGI(WmsLogTag::WMS_EVENT, "abort click persistentId:%{public}d ", persistentId_); + return WSError::WS_DO_NOTHING + } + } + } + if (GetWindowType() == WindowType::WINDOW_TYPE_APP_MAIN_WINDOW) { - if (CheckDialogOnForeground() && isPointDown) { + if (CheckDialogOnForeground() && isDown) { HandlePointDownDialog(); return WSError::WS_ERROR_INVALID_PERMISSION; } @@ -2471,7 +2494,7 @@ WSError Session::HandlePointerEventForFocus(const std::shared_ptrCheckDialogOnForeground() && isPointDown) { + if (parentSession && parentSession->CheckDialogOnForeground() && isDown) { parentSession->HandlePointDownDialog(); if (!IsTopDialog()) { TLOGI(WmsLogTag::WMS_DIALOG, "There is at least one active dialog upon this dialog, id: %{public}d", @@ -3077,6 +3100,11 @@ void Session::SetRequestFocusStatusNotifyManagerListener(const NotifyRequestFocu requestFocusStatusNotifyManagerFunc_ = func; } +void Session::SetCheckPointerEventDispatchFocusListener(const CheckPointerEventDispatchFocusFunc& func) +{ + checkPointerEventDispatchFocusFunc_ = func; +} + void Session::SetNotifyUIRequestFocusFunc(const NotifyUIRequestFocusFunc& func) { std::unique_lock lock(uiRequestFocusMutex_); diff --git a/window_scene/session_manager/include/scene_input_manager.h b/window_scene/session_manager/include/scene_input_manager.h index dad9fd87b2..466f6948ad 100644 --- a/window_scene/session_manager/include/scene_input_manager.h +++ b/window_scene/session_manager/include/scene_input_manager.h @@ -48,7 +48,8 @@ public: void ResetSessionDirty(); std::pair, std::vector>> GetFullWindowInfoList(); - + std::pair> + GetWindowInfo(const sptr& sceneSession, const WindowAction& action); /* * Multi User */ diff --git a/window_scene/session_manager/include/scene_session_dirty_manager.h b/window_scene/session_manager/include/scene_session_dirty_manager.h index 7ff5f35fb6..d147f89cea 100644 --- a/window_scene/session_manager/include/scene_session_dirty_manager.h +++ b/window_scene/session_manager/include/scene_session_dirty_manager.h @@ -71,12 +71,12 @@ public: std::vector>& constrainedModalUIExtInfoMap); bool GetLastConstrainedModalUIExtInfo(const sptr& sceneSession, SecSurfaceInfo& constrainedModalUIExtInfo); + std::pair> + GetWindowInfo(const sptr& sceneSession, const WindowAction& action) const; private: std::vector FullSceneSessionInfoUpdate() const; bool IsFilterSession(const sptr& sceneSession) const; - std::pair> - GetWindowInfo(const sptr& sceneSession, const WindowAction& action) const; SingleHandData GetSingleHandData(const sptr& sceneSession) const; void CalNotRotateTransform(const sptr& sceneSession, Matrix3f& transform, bool useUIExtension = false) const; diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index 902af226c8..cc6b69d0bc 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -954,6 +954,8 @@ private: bool MissionChanged(const sptr& prevSession, const sptr& currSession); std::string GetAllSessionFocusInfo(); void RegisterRequestFocusStatusNotifyManagerFunc(const sptr& sceneSession); + void RegisterCheckPointerEventDispatchFocusFunc(const sptr& sceneSession); + bool CheckPointerEventDispatchFocus(int32_t persistentId, int32_t x, int32_t y, DisplayId displayId); void ProcessUpdateLastFocusedAppId(const std::vector>& zOrderList); WSError ProcessModalTopmostRequestFocusImmediately(const sptr& sceneSession); WSError ProcessSubWindowRequestFocusImmediately(const sptr& sceneSession); diff --git a/window_scene/session_manager/src/scene_input_manager.cpp b/window_scene/session_manager/src/scene_input_manager.cpp index 47d60a919e..b6ee60a445 100644 --- a/window_scene/session_manager/src/scene_input_manager.cpp +++ b/window_scene/session_manager/src/scene_input_manager.cpp @@ -229,6 +229,12 @@ auto SceneInputManager::GetFullWindowInfoList() -> return sceneSessionDirty_->GetFullWindowInfoList(); } +auto SceneInputManager::GetWindowInfo(const sptr& sceneSession, const WindowAction& action) -> + std::pair> +{ + return sceneSessionDirty_->GetWindowInfo(sceneSession, action); +} + std::vector SceneInputManager::ConstructScreenInfos( std::map& screensProperties) { diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index 1a104d886f..e2008b68d5 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -8524,6 +8524,69 @@ void SceneSessionManager::RegisterRequestFocusStatusNotifyManagerFunc(const sptr TLOGD(WmsLogTag::DEFAULT, "success"); } +bool SceneSessionManager::CheckPointerEventDispatchFocus(int32_t persistentId, int32_t x, int32_t y, DisplayId displayId) +{ + TLOGI(WmsLogTag::WMS_FOCUS, "id: %{public}d, ", persistentId); + TLOGI(WmsLogTag::WMS_FOCUS, "id: %{public}d, x: %{public}d, y: %{public}d", + session->GetPersistentId(), x, y); + bool shouldAbort = false; + auto func = [this, persistentId, x, y, displayId](sptr session) { + if (session == nullptr) { + return false; + } + TLOGNI(WmsLogTag::WMS_FOCUS, "CheckPointerEventDispatchFocus , id: %{public}d, IsVisibleForeground: %{public}d, GetSystemTouchable: %{public}d, GetZOrder: %{public}d", + session->GetPersistentId(), session->IsVisibleForeground(), session->GetSystemTouchable(), session->GetZOrder()); + if (session->GetPersistentId() == persistentId) { + return true; + } + if (session->GetDisplayId() != displayGroupId) { + return false; + } + if (!session->IsVisibleForeground() || !session->GetSystemTouchable() ) { + return false; + } + auto [windowInfo, pixelMap] = SceneInputManager::GetInstance().GetWindowInfo(session, WindowAction::WINDOW_ADD); + bool isInRectArea = x >= windowInfo.area.x && x <= windowInfo.area.x + windowInfo.area.width && + y >= windowInfo.area.y && y <= windowInfo.area.y + windowInfo.area.height; + TLOGNI(WmsLogTag::WMS_FOCUS, "CheckPointerEventDispatchFocus, check in area id: %{public}d,isInRectArea: %{public}d, posX: %{public}d, posY: %{public}d, width: %{public}d, height: %{public}d, w: %{public}d, h: %{public}d", + session->GetPersistentId(), isInRectArea, windowInfo.area.x, windowInfo.area.y, windowInfo.area.width, windowInfo.area.height,windowInfo.area.x + windowInfo.area.width, windowInfo.area.y + windowInfo.area.height ); + if (!isInRectArea) { + TLOGNE(WmsLogTag::WMS_FOCUS, "CheckPointerEventDispatchFocus, not in area id: %{public}d", session->GetPersistentId()); + return false; + } + if (windowInfo.defaultHotAreas.empty()) { + TLOGNI(WmsLogTag::WMS_FOCUS, "CheckPointerEventDispatchFocus, defaultHotAreas is empty, id: %{public}d", session->GetPersistentId()); + shouldAbort = true; + return true; + } + for (const auto& area : windowInfo.defaultHotAreas) { + TLOGNI(WmsLogTag::WMS_FOCUS, "CheckPointerEventDispatchFocus, check in defaultHotAreas id: %{public}d, posX: %{public}d, posY: %{public}d, width: %{public}d, height: %{public}d, w: %{public}d, h: %{public}d", + session->GetPersistentId(), area.x, area.y, area.width, area.height,area.x + area.width, area.y + area.height ); + if ( x >= area.x && x <= area.x + area.width && y >= area.y && y <= area.y + area.height) { + TLOGNI(WmsLogTag::WMS_FOCUS, "CheckPointerEventDispatchFocus, point is in touchHotArea, id: %{public}d", session->GetPersistentId()); + shouldAbort = true; + return true; + } + } + return false; + }; + TraverseSessionTree(func, true); + return true; +} + +void SceneSessionManager::RegisterCheckPointerEventDispatchFocusFunc(const sptr& sceneSession) +{ + if (sceneSession == nullptr) { + TLOGE(WmsLogTag::DEFAULT, "session is nullptr"); + return; + } + sceneSession->SetCheckPointerEventDispatchFocusListener( + [this](int32_t persistentId, int32_t x, int32_t y, DisplayId displayId) { + return CheckPointerEventDispatchFocus(persistentId, x, y, displayId); + }); + TLOGD(WmsLogTag::DEFAULT, "success"); +} + void SceneSessionManager::RegisterGetStateFromManagerFunc(sptr& sceneSession) { GetStateFromManagerFunc func = [this](const ManagerState key) { diff --git a/window_scene/test/unittest/session_test3.cpp b/window_scene/test/unittest/session_test3.cpp index aa0ec8283b..27a0072cb4 100644 --- a/window_scene/test/unittest/session_test3.cpp +++ b/window_scene/test/unittest/session_test3.cpp @@ -734,6 +734,22 @@ HWTEST_F(WindowSessionTest3, PresentFocusIfNeed02, TestSize.Level1) EXPECT_EQ(hasNotifyManagerToRequestFocus, true); } +/** + * @tc.name: CheckPointerEventDispatchFocus + * @tc.desc: CheckPointerEventDispatchFocus Test + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionTest3, CheckPointerEventDispatchFocus, TestSize.Level1) +{ + ASSERT_NE(session_, nullptr); + EXPECT_EQ(false, session_->CheckPointerEventDispatchFocus(0, 0)); + session_->SetCheckPointerEventDispatchFocusListener( + [&hasCheck](int32_t persistentId, int32_t x, int32_t y, DisplayId displayId) { + return true; + }); + EXPECT_EQ(true, session_->CheckPointerEventDispatchFocus(0, 0)); +} + /** * @tc.name: UpdateFocus03 * @tc.desc: UpdateFocus Test -- Gitee From 0f36c03422c36782ae6fd288a5a6322f725b8abb Mon Sep 17 00:00:00 2001 From: rsyys Date: Thu, 28 Aug 2025 17:20:56 +0800 Subject: [PATCH 2/2] fix: double click Signed-off-by: rsyys --- window_scene/session/host/include/session.h | 3 +- window_scene/session/host/src/session.cpp | 6 +-- .../include/scene_input_manager.h | 2 +- .../include/scene_session_dirty_manager.h | 3 +- .../src/scene_input_manager.cpp | 2 +- .../src/scene_session_manager.cpp | 10 ++-- .../scene_input_manager_test.cpp | 19 ++++++++ .../unittest/scene_session_manager_test11.cpp | 48 +++++++++++++++++++ window_scene/test/unittest/session_test3.cpp | 30 +++++++++++- 9 files changed, 110 insertions(+), 13 deletions(-) diff --git a/window_scene/session/host/include/session.h b/window_scene/session/host/include/session.h index 5e13951a05..a2cfaedd5f 100644 --- a/window_scene/session/host/include/session.h +++ b/window_scene/session/host/include/session.h @@ -68,7 +68,7 @@ using NotifySessionStateChangeNotifyManagerFunc = std::function; using CheckPointerEventDispatchFocusFunc = - std::function + std::function; using NotifyBackPressedFunc = std::function; using NotifySessionFocusableChangeFunc = std::function; using NotifySessionTouchableChangeFunc = std::function; @@ -497,6 +497,7 @@ public: WSError HandlePointerEventForFocus(const std::shared_ptr& pointerEvent, bool isExecuteDelayRaise = false); bool HasParentSessionWithToken(const sptr& token); + bool CheckPointerEventDispatchFocus(int32_t x, int32_t y); /* * Multi Window diff --git a/window_scene/session/host/src/session.cpp b/window_scene/session/host/src/session.cpp index 65a8cf752f..7a121eabb2 100644 --- a/window_scene/session/host/src/session.cpp +++ b/window_scene/session/host/src/session.cpp @@ -2444,7 +2444,8 @@ WSError Session::HandleSubWindowClick(int32_t action, int32_t sourceType, bool i return WSError::WS_OK; } -bool Session::CheckPointerEventDispatchFocus(int32_t x, int32_t y) { +bool Session::CheckPointerEventDispatchFocus(int32_t x, int32_t y) +{ TLOGI(WmsLogTag::WMS_EVENT, "in"); if (checkPointerEventDispatchFocusFunc_) { TLOGI(WmsLogTag::WMS_EVENT, "cllback checkPointerEventDispatchFocusFunc_"); @@ -2477,11 +2478,10 @@ WSError Session::HandlePointerEventForFocus(const std::shared_ptr, std::vector>> GetFullWindowInfoList(); std::pair> - GetWindowInfo(const sptr& sceneSession, const WindowAction& action); + GetWindowInfo(const sptr& sceneSession); /* * Multi User */ diff --git a/window_scene/session_manager/include/scene_session_dirty_manager.h b/window_scene/session_manager/include/scene_session_dirty_manager.h index d147f89cea..7b9b29281b 100644 --- a/window_scene/session_manager/include/scene_session_dirty_manager.h +++ b/window_scene/session_manager/include/scene_session_dirty_manager.h @@ -72,7 +72,8 @@ public: bool GetLastConstrainedModalUIExtInfo(const sptr& sceneSession, SecSurfaceInfo& constrainedModalUIExtInfo); std::pair> - GetWindowInfo(const sptr& sceneSession, const WindowAction& action) const; + GetWindowInfo(const sptr& sceneSession, + const WindowAction& action = WindowAction::WINDOW_ADD) const; private: std::vector FullSceneSessionInfoUpdate() const; diff --git a/window_scene/session_manager/src/scene_input_manager.cpp b/window_scene/session_manager/src/scene_input_manager.cpp index b6ee60a445..d4bd8b9d77 100644 --- a/window_scene/session_manager/src/scene_input_manager.cpp +++ b/window_scene/session_manager/src/scene_input_manager.cpp @@ -229,7 +229,7 @@ auto SceneInputManager::GetFullWindowInfoList() -> return sceneSessionDirty_->GetFullWindowInfoList(); } -auto SceneInputManager::GetWindowInfo(const sptr& sceneSession, const WindowAction& action) -> +auto SceneInputManager::GetWindowInfo(const sptr& sceneSession) -> std::pair> { return sceneSessionDirty_->GetWindowInfo(sceneSession, action); diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index e2008b68d5..e9a284079a 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -8539,15 +8539,15 @@ bool SceneSessionManager::CheckPointerEventDispatchFocus(int32_t persistentId, i if (session->GetPersistentId() == persistentId) { return true; } - if (session->GetDisplayId() != displayGroupId) { + if (session->GetDisplayId() != displayId) { return false; } if (!session->IsVisibleForeground() || !session->GetSystemTouchable() ) { return false; } - auto [windowInfo, pixelMap] = SceneInputManager::GetInstance().GetWindowInfo(session, WindowAction::WINDOW_ADD); - bool isInRectArea = x >= windowInfo.area.x && x <= windowInfo.area.x + windowInfo.area.width && - y >= windowInfo.area.y && y <= windowInfo.area.y + windowInfo.area.height; + auto [windowInfo, pixelMap] = SceneInputManager::GetInstance().GetWindowInfo(session); + bool isInRectArea = x >= windowInfo.area.x && x <= windowInfo.area.x + windowInfo.area.width && + y >= windowInfo.area.y && y <= windowInfo.area.y + windowInfo.area.height; TLOGNI(WmsLogTag::WMS_FOCUS, "CheckPointerEventDispatchFocus, check in area id: %{public}d,isInRectArea: %{public}d, posX: %{public}d, posY: %{public}d, width: %{public}d, height: %{public}d, w: %{public}d, h: %{public}d", session->GetPersistentId(), isInRectArea, windowInfo.area.x, windowInfo.area.y, windowInfo.area.width, windowInfo.area.height,windowInfo.area.x + windowInfo.area.width, windowInfo.area.y + windowInfo.area.height ); if (!isInRectArea) { @@ -8562,7 +8562,7 @@ bool SceneSessionManager::CheckPointerEventDispatchFocus(int32_t persistentId, i for (const auto& area : windowInfo.defaultHotAreas) { TLOGNI(WmsLogTag::WMS_FOCUS, "CheckPointerEventDispatchFocus, check in defaultHotAreas id: %{public}d, posX: %{public}d, posY: %{public}d, width: %{public}d, height: %{public}d, w: %{public}d, h: %{public}d", session->GetPersistentId(), area.x, area.y, area.width, area.height,area.x + area.width, area.y + area.height ); - if ( x >= area.x && x <= area.x + area.width && y >= area.y && y <= area.y + area.height) { + if (x >= area.x && x <= area.x + area.width && y >= area.y && y <= area.y + area.height) { TLOGNI(WmsLogTag::WMS_FOCUS, "CheckPointerEventDispatchFocus, point is in touchHotArea, id: %{public}d", session->GetPersistentId()); shouldAbort = true; return true; diff --git a/window_scene/test/unittest/event_distribution/scene_input_manager_test.cpp b/window_scene/test/unittest/event_distribution/scene_input_manager_test.cpp index 3b4eda9c3a..5a0894203f 100644 --- a/window_scene/test/unittest/event_distribution/scene_input_manager_test.cpp +++ b/window_scene/test/unittest/event_distribution/scene_input_manager_test.cpp @@ -960,6 +960,25 @@ HWTEST_F(SceneInputManagerTest, CheckNeedUpdateFordDisplayInfos, TestSize.Level1 ASSERT_TRUE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); ASSERT_FALSE(SceneInputManager::GetInstance().CheckNeedUpdate(screenInfos, displayInfos, windowInfoList)); } + +/** + * @tc.name: GetWindowInfo + * @tc.desc: GetWindowInfo + * @tc.type: FUNC + */ +HWTEST_F(SceneInputManagerTest, GetWindowInfo, TestSize.Level1) +{ + SessionInfo info; + info.abilityName_ = "GetWindowInfo"; + info.bundleName_ = "GetWindowInfo"; + session = sptr::MakeSptr(info, nullptr); + sptr windowSessionProperty = session->GetSessionProperty(); + session->SetSessionProperty(windowSessionProperty); + windowSessionProperty->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); + std::pair> ret; + ret = SceneInputManager::GetInstance().GetWindowInfo(session); + EXPECT_EQ(ret.first.id, session->GetWindowId()); +} } // namespace } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/window_scene/test/unittest/scene_session_manager_test11.cpp b/window_scene/test/unittest/scene_session_manager_test11.cpp index 0c206a3af4..6df1a35d9e 100755 --- a/window_scene/test/unittest/scene_session_manager_test11.cpp +++ b/window_scene/test/unittest/scene_session_manager_test11.cpp @@ -1695,6 +1695,54 @@ HWTEST_F(SceneSessionManagerTest11, ConfigSupportCreateFloatWindow, TestSize.Lev usleep(WAIT_SYNC_IN_NS); EXPECT_TRUE(ssm_->systemConfig_.supportCreateFloatWindow_); } + +/** + * @tc.name: CheckPointerEventDispatchFocus + * @tc.desc: test function : CheckPointerEventDispatchFocus + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest11, CheckPointerEventDispatchFocus, TestSize.Level0) +{ + ASSERT_NE(nullptr, ssm_); + + SessionInfo info; + auto session1 = sptr::MakeSptr(info, nullptr); + session1->property_->SetPersistentId(1); + session1->SetZOrder(100); + + auto session2 = sptr::MakeSptr(info, nullptr); + session2->property_->SetPersistentId(2); + session2->UpdateVisibilityInner(true); + session2->SetSessionState(SessionState::STATE_FOREGROUND); + session2->forceTouchable_ = true; + session2->systemTouchable_ = true; + session2->property_->SetTouchable(true); + + auto session3 = sptr::MakeSptr(info, nullptr); + session3->property_->SetPersistentId(3); + session3->SetZOrder(102); + + auto session4 = sptr::MakeSptr(info, nullptr); + session4->property_->SetPersistentId(4); + session4->SetZOrder(103); + session4->UpdateVisibilityInner(true); + session4->SetSessionState(SessionState::STATE_FOREGROUND); + + auto session5 = sptr::MakeSptr(info, nullptr); + session5->SetScreenId(1000); + session5->property_->SetPersistentId(5); + session5->SetZOrder(104); + + { + std::unique_lock lock(ssm_->sceneSessionMapMutex_); + auto& sessionMap = ssm_->sceneSessionMap_; + sessionMap.clear(); + sessionMap.emplace(1, session1); + sessionMap.emplace(2, session2); + sessionMap.emplace(3, session3); + sessionMap.emplace(4, nullptr); + } +} } // namespace } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/window_scene/test/unittest/session_test3.cpp b/window_scene/test/unittest/session_test3.cpp index 27a0072cb4..bd69d0e51b 100644 --- a/window_scene/test/unittest/session_test3.cpp +++ b/window_scene/test/unittest/session_test3.cpp @@ -505,6 +505,34 @@ HWTEST_F(WindowSessionTest3, HandlePointerEventForFocus_Hover, TestSize.Level1) EXPECT_EQ(ret, WSError::WS_OK); } +/** + * @tc.name: HandlePointerEventForFocus_CheckDispatch + * @tc.desc: HandlePointerEventForFocus + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionTest3, HandlePointerEventForFocus_CheckDispatch, TestSize.Level1) +{ + ASSERT_NE(session_, nullptr); + SessionInfo info; + info.abilityName_ = "HandlePointerEventForFocus"; + info.moduleName_ = "HandlePointerEventForFocus"; + info.bundleName_ = "HandlePointerEventForFocus"; + // info.windowType_ = static_cast(WindowType::APP_MAIN_WINDOW_END); + sptr session = sptr::MakeSptr(info); + session->sessionInfo_.isSystem_ = true; + std::shared_ptr pointerEvent = MMI::PointerEvent::Create(); + pointerEvent->pointerAction_ = MMI::PointerEvent::POINTER_ACTION_DOWN; + // session_->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW); + session->SetCheckPointerEventDispatchFocusListener( + [](int32_t persistentId, int32_t x, int32_t y, DisplayId displayId) { + return false; + }); + + // sceneSession->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW; + WSError ret = session_->HandlePointerEventForFocus(pointerEvent); + EXPECT_EQ(ret, WSError::WS_DO_NOTHING); +} + /** * @tc.name: TransferFocusStateEvent03 * @tc.desc: TransferFocusStateEvent Test @@ -744,7 +772,7 @@ HWTEST_F(WindowSessionTest3, CheckPointerEventDispatchFocus, TestSize.Level1) ASSERT_NE(session_, nullptr); EXPECT_EQ(false, session_->CheckPointerEventDispatchFocus(0, 0)); session_->SetCheckPointerEventDispatchFocusListener( - [&hasCheck](int32_t persistentId, int32_t x, int32_t y, DisplayId displayId) { + [](int32_t persistentId, int32_t x, int32_t y, DisplayId displayId) { return true; }); EXPECT_EQ(true, session_->CheckPointerEventDispatchFocus(0, 0)); -- Gitee