diff --git a/window_scene/session/host/include/scene_session.h b/window_scene/session/host/include/scene_session.h index f0f5d2c7e8c09a65f2c8d6157503692e60362c43..fb60840d3b6ccfbdcd8e5def0dcdba940a0659f9 100644 --- a/window_scene/session/host/include/scene_session.h +++ b/window_scene/session/host/include/scene_session.h @@ -838,6 +838,8 @@ public: void SetFollowParentRectFunc(NotifyFollowParentRectFunc&& func); WSError SetFollowParentWindowLayoutEnabled(bool isFollow) override; bool IsDelayFocusChange(); + virtual bool IsBlockingFocusFullScreenSystemPanel() const; + virtual bool IsAppMainWindowFullScreen(); /* * Window Property diff --git a/window_scene/session/host/src/scene_session.cpp b/window_scene/session/host/src/scene_session.cpp index 2a037c2232d96a454c0e6843cbfa83878a80fac4..774d4cdbb57e1c3a87b1b0400efd7eb0fde93d51 100644 --- a/window_scene/session/host/src/scene_session.cpp +++ b/window_scene/session/host/src/scene_session.cpp @@ -4970,6 +4970,49 @@ bool SceneSession::IsAppOrLowerSystemSession() const return IsAppSession(); } +/** @note @window.focus */ +bool SceneSession::IsBlockingFocusFullScreenSystemPanel() const +{ + bool blockingFocus = GetBlockingFocus(); + if (!blockingFocus) { + TLOGD(WmsLogTag::WMS_FOCUS, "not blocking focus window"); + return false; + } + if (!(systemConfig_.IsPhoneWindow() || systemConfig_.IsPadWindow())) { + TLOGD(WmsLogTag::WMS_FOCUS, "device type unmatched"); + return false; + } + WindowType windowType = GetWindowType(); + //Get height and width of current screen + uint64_t displayId = GetSessionProperty()->GetDisplayId(); + auto display = DisplayManager::GetInstance().GetDisplayById(displayId); + if (display == nullptr) { + TLOGE(WmsLogTag::WMS_FOCUS, "get display object failed of display: %{public}" PRIu64, displayId); + return false; + } + auto displayInfo = display->GetDisplayInfo(); + if (displayInfo == nullptr) { + TLOGE(WmsLogTag::WMS_FOCUS, "get display info failed of display: %{public}" PRIu64, displayId); + return false; + } + if ((windowType == WindowType::WINDOW_TYPE_PANEL || windowType == WindowType::WINDOW_TYPE_GLOBAL_SEARCH || + windowType == WindowType::WINDOW_TYPE_NEGATIVE_SCREEN) && + (GetSessionRect().height_ == displayInfo->GetHeight() && GetSessionRect().width_ == displayInfo->GetWidth())) { + return true; + } + TLOGD(WmsLogTag::WMS_FOCUS, "current session is not full-screen, " + "screen w: %{public}d, h: %{public}d, window w: %{public}d, h: %{public}d", + displayInfo->GetWidth(), displayInfo->GetHeight(), GetSessionRect().width_, GetSessionRect().height_); + return false; +} + +/** @note @window.focus */ +bool SceneSession::IsAppMainWindowFullScreen() +{ + auto mainSession = GetMainSession(); + return mainSession == nullptr ? false : (mainSession->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN); +} + /** @note @window.focus */ bool SceneSession::IsSystemSessionAboveApp() const { diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index 5a2f962d7427a8c8bf66e4674620e14892607b45..a987e693b3207774e70668d7187233dbc54527df 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -7635,14 +7635,16 @@ bool SceneSessionManager::CheckRequestFocusSubWindowImmediately(const sptr& focusedSession, const sptr& sceneSession, FocusChangeReason reason) { - if (focusedSession->GetWindowType() != WindowType::WINDOW_TYPE_GLOBAL_SEARCH && - focusedSession->GetWindowType() != WindowType::WINDOW_TYPE_NEGATIVE_SCREEN) { + if (reason != FocusChangeReason::CLICK) { return false; } - if (reason != FocusChangeReason::CLICK || !focusedSession->GetBlockingFocus()) { - return false; + if (focusedSession->IsBlockingFocusFullScreenSystemPanel()) { + return sceneSession->GetZOrder() < focusedSession->GetZOrder(); + } + if (focusedSession->IsAppMainWindowFullScreen()) { + return sceneSession->GetZOrder() < focusedSession->GetMainSession()->GetZOrder(); } - return sceneSession->GetZOrder() < focusedSession->GetZOrder(); + return false; } WSError SceneSessionManager::RequestFocusSpecificCheck(DisplayId displayId, const sptr& sceneSession, diff --git a/window_scene/test/mock/mock_scene_session.h b/window_scene/test/mock/mock_scene_session.h index b9654b628273c0acba6dfa70855e808477d97f73..7e99455cfb29e33ab6e492758fee5113612b10b2 100644 --- a/window_scene/test/mock/mock_scene_session.h +++ b/window_scene/test/mock/mock_scene_session.h @@ -30,6 +30,8 @@ public: MOCK_METHOD(void, UpdateCrossAxisOfLayout, (const WSRect& rect), (override)); MOCK_METHOD(void, UpdateCrossAxis, (), (override)); MOCK_METHOD(WSError, UpdateGlobalDisplayRect, (const WSRect& rect, SizeChangeReason reason), (override)); + MOCK_CONST_METHOD0(IsBlockingFocusFullScreenSystemPanel, bool()); + MOCK_METHOD(bool, IsAppMainWindowFullScreen, (), (override)); }; } } diff --git a/window_scene/test/unittest/scene_session_manager_test9.cpp b/window_scene/test/unittest/scene_session_manager_test9.cpp index d2cc830d8f33bf41af31f3efa405059b3357e550..6a391dff961be83aac4d74648d2c558ebdf3f3c2 100644 --- a/window_scene/test/unittest/scene_session_manager_test9.cpp +++ b/window_scene/test/unittest/scene_session_manager_test9.cpp @@ -18,10 +18,11 @@ #include "common/include/session_permission.h" #include "interfaces/include/ws_common.h" #include "iremote_object_mocker.h" -#include "session_manager/include/scene_session_manager.h" -#include "session_info.h" +#include "mock/mock_scene_session.h" #include "session/host/include/scene_session.h" +#include "session_info.h" #include "session_manager.h" +#include "session_manager/include/scene_session_manager.h" using namespace testing; using namespace testing::ext; @@ -1270,32 +1271,100 @@ HWTEST_F(SceneSessionManagerTest9, GetSessionRSVisible, TestSize.Level1) } /** - * @tc.name: CheckClickFocusIsDownThroughFullScreen - * @tc.desc: CheckClickFocusIsDownThroughFullScreen + * @tc.name: CheckClickFocusIsDownThroughFullScreen_FocusChangeReason + * @tc.desc: Test return value with click-reason and other reasons * @tc.type: FUNC */ -HWTEST_F(SceneSessionManagerTest9, CheckClickFocusIsDownThroughFullScreen, TestSize.Level1) +HWTEST_F(SceneSessionManagerTest9, CheckClickFocusIsDownThroughFullScreen_FocusChangeReason, TestSize.Level1) { ASSERT_NE(ssm_, nullptr); SessionInfo info; - info.abilityName_ = "test1"; - info.bundleName_ = "test2"; + info.abilityName_ = "CheckClickFocusIsDownThroughFullScreen_FocusChangeReason"; + info.bundleName_ = "CheckClickFocusIsDownThroughFullScreen_FocusChangeReason"; + + sptr sceneSession = sptr::MakeSptr(info, nullptr); + sceneSession->zOrder_ = 1; + + sptr focusedSession = sptr::MakeSptr(info, nullptr); + focusedSession->zOrder_ = 2; + EXPECT_CAll(*focusedSession, IsBlockingFocusFullScreenSystemPanel()).WillRepeatedly(Return(true)); - sptr focusedSession = sptr::MakeSptr(info, nullptr); - ASSERT_NE(focusedSession, nullptr); - sptr sceneSession = sptr::MakeSptr(info, nullptr); - ASSERT_NE(sceneSession, nullptr); bool ret = ssm_->CheckClickFocusIsDownThroughFullScreen(focusedSession, sceneSession, FocusChangeReason::DEFAULT); - ASSERT_EQ(ret, false); + EXPECT_EQ(ret, false); - focusedSession->property_->SetWindowType(WindowType::WINDOW_TYPE_GLOBAL_SEARCH); - ret = ssm_->CheckClickFocusIsDownThroughFullScreen(focusedSession, sceneSession, FocusChangeReason::DEFAULT); - ASSERT_EQ(ret, false); - sceneSession->SetZOrder(50); - focusedSession->SetZOrder(100); - focusedSession->blockingFocus_ = true; ret = ssm_->CheckClickFocusIsDownThroughFullScreen(focusedSession, sceneSession, FocusChangeReason::CLICK); - ASSERT_EQ(ret, true); + EXPECT_EQ(ret, true); +} + +/** + * @tc.name: CheckClickFocusIsDownThroughFullScreen_FullScreenCheck + * @tc.desc: Test return value with full-screen window and non-full-screen window + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest9, CheckClickFocusIsDownThroughFullScreen_FullScreenCheck, TestSize.Level1) +{ + ASSERT_NE(ssm_, nullptr); + SessionInfo info; + info.abilityName_ = "CheckClickFocusIsDownThroughFullScreen_FullScreenCheck"; + info.bundleName_ = "CheckClickFocusIsDownThroughFullScreen_FullScreenCheck"; + + sptr sceneSession = sptr::MakeSptr(info, nullptr); + sceneSession->zOrder_ = 1; + + sptr focusedSession = sptr::MakeSptr(info, nullptr); + focusedSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); + focusedSession->zOrder_ = 2; + + FocusChangeReason focusChangeReason = FocusChangeReason::CLICK; + + EXPECT_CALL(*focusedSession, IsBlockingFocusFullScreenSystemPanel()).WillRepeatedly(Return(false)); + EXPECT_CALL(*focusedSession, IsAppMainWindowFullScreen()).WillRepeatedly(Return(false)); + bool ret = ssm_->CheckClickFocusIsDownThroughFullScreen(focusedSession, sceneSession, reason); + EXPECT_EQ(ret, false); + + EXPECT_CALL(*focusedSession, IsBlockingFocusFullScreenSystemPanel()).WillRepeatedly(Return(true)); + ret = ssm_->CheckClickFocusIsDownThroughFullScreen(focusedSession, sceneSession, reason); + EXPECT_EQ(ret, true); + + EXPECT_CALL(*focusedSession, IsBlockingFocusFullScreenSystemPanel()).WillRepeatedly(Return(false)); + EXPECT_CALL(*focusedSession, IsAppMainWindowFullScreen()).WillRepeatedly(Return(true)); + ret = ssm_->CheckClickFocusIsDownThroughFullScreen(focusedSession, sceneSession, reason); + EXPECT_EQ(ret, true); +} + +/** + * @tc.name: CheckClickFocusIsDownThroughFullScreen_ZOrderCheck + * @tc.desc: Test return value with window-pairs of different zorder-relationships + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest9, CheckClickFocusIsDownThroughFullScreen_ZOrderCheck, TestSize.Level1) +{ + ASSERT_NE(ssm_, nullptr); + SessionInfo info; + info.abilityName_ = "CheckClickFocusIsDownThroughFullScreen_ZOrderCheck"; + info.bundleName_ = "CheckClickFocusIsDownThroughFullScreen_ZOrderCheck"; + + sptr sceneSession = sptr::MakeSptr(info, nullptr); + sptr focusedSession = sptr::MakeSptr(info, nullptr); + focusedSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); + EXPECT_CALL(*focusedSession, IsBlockingFocusFullScreenSystemPanel()).WillRepeatedly(Return(false)); + EXPECT_CALL(*focusedSession, IsAppMainWindowFullScreen()).WillRepeatedly(Return(false)); + + FocusChangeReason reason = FocusChangeReason::CLICK; + + focusedSession->zOrder_ = 0; + sceneSession->zOrder_ = 1; + + bool ret = ssm_->CheckClickFocusIsDownThroughFullScreen(focusedSession, sceneSession, reason); + EXPECT_EQ(ret, false); + + focusedSession->zOrder_ = 1; + ret = ssm_->CheckClickFocusIsDownThroughFullScreen(focusedSession, sceneSession, reason); + EXPECT_EQ(ret, false); + + focusedSession->zOrder_ = 2; + ret = ssm_->CheckClickFocusIsDownThroughFullScreen(focusedSession, sceneSession, reason); + EXPECT_EQ(ret, true); } /** diff --git a/window_scene/test/unittest/window_focus/window_focus_scene_session_test.cpp b/window_scene/test/unittest/window_focus/window_focus_scene_session_test.cpp index 22ef170514a25f14f29833f0582c347a8e08e352..d83ab2ab0349e002c4f63c9e660fa3dbd7a182de 100644 --- a/window_scene/test/unittest/window_focus/window_focus_scene_session_test.cpp +++ b/window_scene/test/unittest/window_focus/window_focus_scene_session_test.cpp @@ -143,6 +143,82 @@ HWTEST_F(WindowFocusSceneSessionTest, IsAppOrLowerSystemSession02, TestSize.Leve ASSERT_EQ(true, sceneSession->IsAppOrLowerSystemSession()); } +/** + * @tc.name: IsBlockingFocusFullScreenSystemPanel_SessionConfig + * @tc.desc: Check if the session blockingFocus and device type is qualified + * @tc.type: FUNC + */ +HWTEST_F(WindowFocusSceneSessionTest, IsBlockingFocusFullScreenSystemPanel_SessionConfig, TestSize.Level1) +{ + SessionInfo info; + info.abilityName_ = "IsBlockingFocusFullScreenSystemPanel_SessionConfig"; + info.bundleName_ = "IsBlockingFocusFullScreenSystemPanel_SessionConfig"; + sptr sceneSession = sptr::MakeSptr(info, nullptr); + + sceneSession->blockingFocus_ = false; + EXPECT_EQ(false, sceneSession->IsBlockingFocusFullScreenSystemPanel()); + + sceneSession->blockingFocus_ = true; + sceneSession->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW; + EXPECT_EQ(false, sceneSession->IsBlockingFocusFullScreenSystemPanel()); +} + +/** + * @tc.name: IsBlockingFocusFullScreenSystemPanel_RectCheck + * @tc.desc: Check if the height and width of the current session is full-screen + * @tc.type: FUNC + */ +HWTEST_F(WindowFocusSceneSessionTest, IsBlockingFocusFullScreenSystemPanel_RectCheck, TestSize.Level1) +{ + SessionInfo info; + info.abilityName_ = "IsBlockingFocusFullScreenSystemPanel_RectCheck"; + info.bundleName_ = "IsBlockingFocusFullScreenSystemPanel_RectCheck"; + sptr sceneSession = sptr::MakeSptr(info, nullptr); + + sceneSession->blockingFocus_ = true; + sceneSession->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW; + constexpr DisplayId DISPLAY_ID = 0; + sceneSession->GetSessionProperty()->SetDisplayId(DISPLAY_ID); + + const WSRect rect = {0, 0, 0, 0}; + sceneSession->SetSessionRect(rect); + sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); + EXPECT_EQ(false, sceneSession->IsBlockingFocusFullScreenSystemPanel()); + + sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_PANEL); + EXPECT_EQ(false, sceneSession->IsBlockingFocusFullScreenSystemPanel()); +} + +/** + * @tc.name: IsAppMainWindowFullScreen + * @tc.desc: Check if main session of the current session is full-screen + * @tc.type: FUNC + */ +HWTEST_F(WindowFocusSceneSessionTest, IsAppMainWindowFullScreen, TestSize.Level1) +{ + SessionInfo subSessionInfo; + subSessionInfo.abilityName_ = "IsAppMainWindowFullScreen_SubSession"; + subSessionInfo.bundleName_ = "IsAppMainWindowFullScreen_SubSession"; + sptr subSession = sptr::MakeSptr(subSessionInfo, nullptr); + + subSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW); + subSession->SetParentSession(nullptr); + EXPECT_EQ(false, subSession->IsAppMainWindowFullScreen()); + + SessionInfo mainSessionInfo; + mainSessionInfo.abilityName_ = "IsAppMainWindowFullScreen_MainSession"; + mainSessionInfo.bundleName_ = "IsAppMainWindowFullScreen_MainSession"; + sptr mainSession = sptr::MakeSptr(mainSessionInfo, nullptr); + + mainSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); + mainSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); + subSession->SetParentSession(mainSession); + EXPECT_EQ(false, subSession->IsAppMainWindowFullScreen()); + + mainSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN); + EXPECT_EQ(false, subSession->IsAppMainWindowFullScreen()); +} + /** * @tc.name: IsSystemSessionAboveApp * @tc.desc: IsSystemSessionAboveApp true