diff --git a/window_scene/session/host/include/scene_session.h b/window_scene/session/host/include/scene_session.h index e7b5d262b07188ee23cd3be09145586652cf0e8e..389092e7d28d14cf1dc435835bbf9d5b2edfe65d 100644 --- a/window_scene/session/host/include/scene_session.h +++ b/window_scene/session/host/include/scene_session.h @@ -115,6 +115,8 @@ using NotifySetSupportedWindowModesFunc = std::function&& supportedWindowModes)>; using GetStatusBarAvoidHeightFunc = std::function; using NotifySetWindowCornerRadiusFunc = std::function; +using GetKeyboardOccupiedAreaWithRotationCallback = + std::function>& avoidAreas)>; struct UIExtensionTokenInfo { bool canShowOnLockScreen { false }; @@ -148,6 +150,7 @@ public: PiPStateChangeCallback onPiPStateChange_; UpdateGestureBackEnabledCallback onUpdateGestureBackEnabled_; NotifyAvoidAreaChangeCallback onNotifyAvoidAreaChange_; + GetKeyboardOccupiedAreaWithRotationCallback onKeyboardRotationChange_; }; // func for change window scene pattern property @@ -642,6 +645,7 @@ public: void ActivateKeyboardAvoidArea(bool active, bool recalculateAvoid); bool IsKeyboardAvoidAreaActive() const; virtual void SetKeyboardViewModeChangeListener(const NotifyKeyboarViewModeChangeFunc& func) {}; + void GetKeyboardOccupiedAreaWithRotation(int32_t persistentId, uint32_t rotation, std::vector>& avoidAreas); /* * Window Focus diff --git a/window_scene/session/host/src/scene_session.cpp b/window_scene/session/host/src/scene_session.cpp index 4c747993e78be98d61accf2d9faab7ff62ea7652..304d63124effcd47ea2d0c82a9439a7f819d154c 100644 --- a/window_scene/session/host/src/scene_session.cpp +++ b/window_scene/session/host/src/scene_session.cpp @@ -2135,6 +2135,16 @@ void SceneSession::GetKeyboardAvoidArea(WSRect& rect, AvoidArea& avoidArea) return; } +void SceneSession::GetKeyboardOccupiedAreaWithRotation(int32_t persistentId, uint32_t rotation, std::vector>& avoidAreas) +{ + TLOGI(WmsLogTag::WMS_KEYBOARD, "GetKeyboardOccupiedAreaWithRotation begin"); + if (specificCallback_ != nullptr && specificCallback_->onKeyboardRotationChange_) { + specificCallback_->onKeyboardRotationChange_(persistentId, rotation, avoidAreas); + } else { + TLOGE(WmsLogTag::WMS_KEYBOARD, "Fail to get keyboard occupied area, specificCallback_ is nullptr"); + } +} + void SceneSession::GetCutoutAvoidArea(WSRect& rect, AvoidArea& avoidArea) { auto display = DisplayManager::GetInstance().GetDisplayById(GetSessionProperty()->GetDisplayId()); diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index df718ec7f62bef689e62698811f2c695871e446e..b8a445e91678eca154b8bee00ec1eeee14624fc0 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -432,6 +432,7 @@ public: */ void RequestInputMethodCloseKeyboard(int32_t persistentId); void RegisterNotifyRootSceneOccupiedAreaChangeFunc(NotifyRootSceneOccupiedAreaChangeFunc&& func); + void GetKeyboardOccupiedAreaWithRotation(int32_t persistentId, uint32_t rotation, std::vector>& avoidAreas); /* * UIExtension @@ -1128,6 +1129,7 @@ private: void UpdateKeyboardAvoidAreaActive(bool systemKeyboardAvoidAreaActive); NotifyRootSceneOccupiedAreaChangeFunc onNotifyOccupiedAreaChangeForRootFunc_; + /* * Specific Window */ diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index c667744be6916239caeae5217b392f18f06d9468..18ab30e55de3c3cb7d3e7ed95f41a809ea1dbe02 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -1576,6 +1576,10 @@ sptr SceneSessionManager::CreateSpecificS specificCb->onUpdateGestureBackEnabled_ = [this](int32_t persistentId) { this->UpdateGestureBackEnabled(persistentId); }; + specificCb->onKeyboardRotationChange_ = [this](int32_t persistentId, uint32_t rotation, + std::vector>& avoidAreas) { + this->GetKeyboardOccupiedAreaWithRotation(persistentId, rotation, avoidAreas); + }; return specificCb; } @@ -9431,6 +9435,44 @@ void SceneSessionManager::UpdateAvoidArea(int32_t persistentId) }, "UpdateAvoidArea:PID:" + std::to_string(persistentId)); } +void SceneSessionManager::GetKeyboardOccupiedAreaWithRotation(int32_t persistentId, uint32_t rotation, std::vector>& avoidAreas) +{ + auto sceneSession = GetSceneSession(persistentId); + if (sceneSession == nullptr) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "sceneSession is nullptr,id: %{public}d", persistentId); + return; + } + + auto sceneSessionProperty = sceneSession->GetSessionProperty(); + auto keyboardSession = GetKeyboardSession(sceneSessionProperty->GetDisplayId(), false); + if (keyboardSession == nullptr) { + TLOGE(WmsLogTag::WMS_KEYBOARD, "keyboardSession is nullptr,id: %{public}d", persistentId); + return; + } + + auto keyboardSessionProperty = keyboardSession->GetSessionProperty(); + + std::pair keyboardOccupiedArea = {true, {0, 0, 0, 0}}; + const KeyboardLayoutParams keyboardLayoutParams = keyboardSessionProperty->GetKeyboardLayoutParams(); + Rect nextRect; + if (rotation == 0 || rotation == 180 || rotation == 360) { + nextRect = keyboardLayoutParams.PortraitPanelRect_; + } else if (rotation == 90 || rotation == 270) { + nextRect = keyboardLayoutParams.LandscapePanelRect_; + } else { + TLOGE(WmsLogTag::WMS_KEYBOARD, "Rotation is invalid,id: %{public}d, rotation: %{public}u", persistentId, rotation); + return; + } + keyboardOccupiedArea.second = {nextRect.posX_, nextRect.posY_, static_cast(nextRect.width_), static_cast(nextRect.height_)}; + + SessionState keyboardState = keyboardSession->GetSessionState(); + if (!(keyboardState == SessionState::STATE_ACTIVE || keyboardState == SessionState::STATE_FOREGROUND) || + keyboardLayoutParams.gravity_ == WindowGravity::WINDOW_GRAVITY_FLOAT) { + keyboardOccupiedArea.first = false; + } + avoidAreas.emplace_back(keyboardOccupiedArea); +} + void SceneSessionManager::UpdateGestureBackEnabled(int32_t persistentId) { auto task = [this, persistentId, where = __func__] {