layoutFullScreen fix

Signed-off-by: wangziyi <zhouchengchao4@huawei.com>
This commit is contained in:
wangziyi 2024-11-04 21:40:46 +08:00
parent e849c3b85d
commit c9efb74931
4 changed files with 50 additions and 21 deletions

View File

@ -654,12 +654,12 @@ void JsSceneSession::ProcessAdjustKeyboardLayoutRegister()
void JsSceneSession::ProcessLayoutFullScreenChangeRegister()
{
auto sessionchangeCallback = sessionchangeCallback_.promote();
if (sessionchangeCallback == nullptr) {
TLOGE(WmsLogTag::WMS_LAYOUT, "sessionchangeCallback is nullptr");
auto session = weakSession_.promote();
if (session == nullptr) {
TLOGE(WmsLogTag::WMS_LAYOUT, "session is nullptr, id:%{public}d", persistentId_);
return;
}
sessionchangeCallback->onLayoutFullScreenChangeFunc_ = [weakThis = wptr(this)](bool isLayoutFullScreen) {
auto layoutFullScreenChangeCallback = [weakThis = wptr(this)](bool isLayoutFullScreen) {
auto jsSceneSession = weakThis.promote();
if (!jsSceneSession) {
TLOGE(WmsLogTag::WMS_LIFE, "ProcessLayoutFullScreenChangeRegister jsSceneSession is null");
@ -667,6 +667,7 @@ void JsSceneSession::ProcessLayoutFullScreenChangeRegister()
}
jsSceneSession->OnLayoutFullScreenChange(isLayoutFullScreen);
};
session->RegisterLayoutFullScreenChangeCallback(layoutFullScreenChangeCallback);
TLOGI(WmsLogTag::WMS_LAYOUT, "success");
}

View File

@ -128,7 +128,6 @@ public:
NotifyRaiseAboveTargetFunc onRaiseAboveTarget_;
NotifyTouchOutsideFunc OnTouchOutside_;
NotifyLandscapeMultiWindowSessionFunc onSetLandscapeMultiWindowFunc_;
NotifyLayoutFullScreenChangeFunc onLayoutFullScreenChangeFunc_;
NotifyDefaultDensityEnabledFunc onDefaultDensityEnabledFunc_;
NotifyRestoreMainWindowFunc onRestoreMainWindowFunc_;
NotifyTitleAndDockHoverShowChangeFunc onTitleAndDockHoverShowChangeFunc_;
@ -392,6 +391,11 @@ public:
*/
void RegisterIsCustomAnimationPlayingCallback(NotifyIsCustomAnimationPlayingCallback&& callback);
/**
* Window layoutFullScreen
*/
void RegisterLayoutFullScreenChangeCallback(NotifyLayoutFullScreenChangeFunc&& callback);
/**
* Window Visibility
*/
@ -799,6 +803,11 @@ private:
*/
NotifyIsCustomAnimationPlayingCallback onIsCustomAnimationPlaying_;
/**
* Window LayoutFullscreen
*/
NotifyLayoutFullScreenChangeFunc onLayoutFullScreenChangeFunc_;
/**
* Window Immersive
*/

View File

@ -4730,10 +4730,9 @@ WSError SceneSession::OnLayoutFullScreenChange(bool isLayoutFullScreen)
TLOGE(WmsLogTag::WMS_LAYOUT, "session is null");
return WSError::WS_ERROR_DESTROYED_OBJECT;
}
TLOGI(WmsLogTag::WMS_LAYOUT, "OnLayoutFullScreenChange, isLayoutFullScreen: %{public}d",
isLayoutFullScreen);
if (session->sessionChangeCallback_ && session->sessionChangeCallback_->onLayoutFullScreenChangeFunc_) {
session->sessionChangeCallback_->onLayoutFullScreenChangeFunc_(isLayoutFullScreen);
TLOGI(WmsLogTag::WMS_LAYOUT, "isLayoutFullScreen: %{public}d", isLayoutFullScreen);
if (session->onLayoutFullScreenChangeFunc_) {
session->onLayoutFullScreenChangeFunc_(isLayoutFullScreen);
}
return WSError::WS_OK;
};
@ -5006,6 +5005,19 @@ void SceneSession::RegisterIsCustomAnimationPlayingCallback(NotifyIsCustomAnimat
PostTask(task, __func__);
}
void SceneSession::RegisterLayoutFullScreenChangeCallback(NotifyLayoutFullScreenChangeFunc&& callback)
{
auto task = [weakThis = wptr(this), callback = std::move(callback)] {
auto session = weakThis.promote();
if (!session) {
TLOGNE(WmsLogTag::WMS_LAYOUT, "session is null");
return;
}
session->onLayoutFullScreenChangeFunc_ = std::move(callback);
};
PostTask(task, __func__);
}
WMError SceneSession::GetAppForceLandscapeConfig(AppForceLandscapeConfig& config)
{
if (forceSplitFunc_ == nullptr) {
@ -5322,7 +5334,6 @@ void SceneSession::UnregisterSessionChangeListeners()
session->sessionChangeCallback_->onRaiseAboveTarget_ = nullptr;
session->sessionChangeCallback_->OnTouchOutside_ = nullptr;
session->sessionChangeCallback_->onSetLandscapeMultiWindowFunc_ = nullptr;
session->sessionChangeCallback_->onLayoutFullScreenChangeFunc_ = nullptr;
session->sessionChangeCallback_->onRestoreMainWindowFunc_ = nullptr;
}
session->Session::UnregisterSessionChangeListeners();

View File

@ -401,21 +401,29 @@ HWTEST_F(SceneSessionTest5, OnLayoutFullScreenChange, Function | SmallTest | Lev
info.bundleName_ = "OnLayoutFullScreenChange";
sptr<SceneSession> session = sptr<SceneSession>::MakeSptr(info, nullptr);
EXPECT_NE(session, nullptr);
EXPECT_EQ(WSError::WS_OK, session->OnLayoutFullScreenChange(true));
sptr<SceneSession::SessionChangeCallback> sessionChangeCallback =
sptr<SceneSession::SessionChangeCallback>::MakeSptr();
session->RegisterSessionChangeCallback(sessionChangeCallback);
sessionChangeCallback->onLayoutFullScreenChangeFunc_ = nullptr;
EXPECT_EQ(WSError::WS_OK, session->OnLayoutFullScreenChange(true));
NotifyLayoutFullScreenChangeFunc func = [](bool isLayoutFullScreen) {
return;
};
NotifyLayoutFullScreenChangeFunc func = [](bool isLayoutFullScreen) {};
sessionChangeCallback->onLayoutFullScreenChangeFunc_ = func;
EXPECT_EQ(WSError::WS_OK, session->OnLayoutFullScreenChange(true));
}
/**
* @tc.name: RegisterLayoutFullScreenChangeCallback
* @tc.desc: test RegisterLayoutFullScreenChangeCallback
* @tc.type: FUNC
*/
HWTEST_F(SceneSessionTest3, RegisterLayoutFullScreenChangeCallback, Function | SmallTest | Level2)
{
SessionInfo info;
info.abilityName_ = "RegisterLayoutFullScreenChangeCallback";
info.bundleName_ = "RegisterLayoutFullScreenChangeCallback";
sptr<SceneSession> sceneSession = new SceneSession(info, nullptr);
sceneSession->onLayoutFullScreenChangeFunc_ = nullptr;
NotifyLayoutFullScreenChangeFunc func = [](bool isLayoutFullScreen) {};
sceneSession->RegisterLayoutFullScreenChangeCallback(std::move(func));
ASSERT_NE(sceneSession->onLayoutFullScreenChangeFunc_, nullptr);
}
/**
* @tc.name: OnDefaultDensityEnabled
* @tc.desc: OnDefaultDensityEnabled function