1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_ROSEN_WINDOW_SCENE_KEYBOARD_SESSION_H 17 #define OHOS_ROSEN_WINDOW_SCENE_KEYBOARD_SESSION_H 18 19 #include "session/host/include/system_session.h" 20 #include <transaction/rs_interfaces.h> 21 #include <transaction/rs_transaction.h> 22 #include "transaction/rs_sync_transaction_controller.h" 23 24 namespace OHOS::Rosen { 25 using OnGetSceneSessionCallback = std::function<sptr<SceneSession>(uint32_t callingSessionId)>; 26 using OnGetFocusedSessionIdCallback = std::function<int32_t()>; 27 using OnCallingSessionIdChangeCallback = std::function<void(uint32_t callingSessionId)>; 28 29 class KeyboardSession : public SystemSession { 30 public: 31 // callback for notify SceneSessionManager 32 struct KeyboardSessionCallback : public RefBase { 33 OnGetSceneSessionCallback onGetSceneSession_; 34 OnGetFocusedSessionIdCallback onGetFocusedSessionId_; 35 OnCallingSessionIdChangeCallback onCallingSessionIdChange_; 36 }; 37 KeyboardSession(const SessionInfo& info, const sptr<SpecificSessionCallback>& specificCallback, 38 const sptr<KeyboardSessionCallback>& keyboardCallback); 39 ~KeyboardSession(); 40 41 WSError Show(sptr<WindowSessionProperty> property) override; 42 WSError Hide() override; 43 WSError Disconnect(bool isFromClient = false, const std::string& identityToken = "") override; 44 WSError NotifyClientToUpdateRect(const std::string& updateReason, 45 std::shared_ptr<RSTransaction> rsTransaction) override; 46 47 void BindKeyboardPanelSession(sptr<SceneSession> panelSession) override; 48 sptr<SceneSession> GetKeyboardPanelSession() const override; 49 SessionGravity GetKeyboardGravity() const override; 50 void OnKeyboardPanelUpdated() override; 51 void OnCallingSessionUpdated() override; 52 void OpenKeyboardSyncTransaction() override; 53 void CloseKeyboardSyncTransaction(const WSRect& keyboardPanelRect, bool isKeyboardShow, bool isRotating) override; 54 bool IsVisibleForeground() const override; 55 uint32_t GetCallingSessionId() override; 56 57 private: 58 sptr<SceneSession> GetSceneSession(uint32_t persistentId); 59 int32_t GetFocusedSessionId(); 60 61 WSError SetKeyboardSessionGravity(SessionGravity gravity); 62 void SetCallingSessionId(uint32_t callingSessionId) override; 63 64 int32_t GetStatusBarHeight(); 65 void NotifyOccupiedAreaChangeInfo(const sptr<SceneSession>& callingSession, const WSRect& rect, 66 const WSRect& occupiedArea, const std::shared_ptr<RSTransaction>& rsTransaction = nullptr); 67 void RaiseCallingSession(const WSRect& keyboardPanelRect, bool needCheckVisible, 68 const std::shared_ptr<RSTransaction>& rsTransaction = nullptr); 69 void RestoreCallingSession(const std::shared_ptr<RSTransaction>& rsTransaction = nullptr); 70 void UpdateKeyboardAvoidArea(); 71 void UseFocusIdIfCallingSessionIdInvalid(); 72 void UpdateCallingSessionIdAndPosition(uint32_t newCallingSessionId); 73 void RelayoutKeyBoard(); 74 void NotifyKeyboardPanelInfoChange(WSRect rect, bool isKeyboardPanelShow); 75 bool CheckIfNeedRaiseCallingSession(sptr<SceneSession> callingSession, bool isCallingSessionFloating); 76 WSError AdjustKeyboardLayout(const KeyboardLayoutParams& params) override; 77 std::shared_ptr<RSTransaction> GetRSTransaction(); 78 std::string GetSessionScreenName(); 79 void MoveAndResizeKeyboard(const KeyboardLayoutParams& params, const sptr<WindowSessionProperty>& sessionProperty, 80 bool isShow); 81 82 sptr<KeyboardSessionCallback> keyboardCallback_ = nullptr; 83 bool isKeyboardSyncTransactionOpen_ = false; 84 }; 85 } // namespace OHOS::Rosen 86 #endif // OHOS_ROSEN_WINDOW_SCENE_KEYBOARD_SESSION_H