1 /* 2 * Copyright (c) 2023 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_SESSION_PROPERTY_H 17 #define OHOS_ROSEN_WINDOW_SESSION_PROPERTY_H 18 19 #include <refbase.h> 20 #include <string> 21 #include <unordered_map> 22 #include <parcel.h> 23 #include "interfaces/include/ws_common.h" 24 #include "interfaces/include/ws_common_inner.h" 25 #include "wm_common.h" 26 #include "dm_common.h" 27 #include <cfloat> 28 29 namespace OHOS { 30 namespace Rosen { 31 32 class WindowSessionProperty : public Parcelable { 33 public: 34 WindowSessionProperty() = default; 35 ~WindowSessionProperty() = default; 36 explicit WindowSessionProperty(const sptr<WindowSessionProperty>& property); 37 void CopyFrom(const sptr<WindowSessionProperty>& property); 38 void SetWindowName(const std::string& name); 39 void SetSessionInfo(const SessionInfo& info); 40 void SetRequestRect(const struct Rect& rect); 41 void SetWindowRect(const struct Rect& rect); 42 void SetFocusable(bool isFocusable); 43 void SetTouchable(bool isTouchable); 44 void SetDragEnabled(bool dragEnabled); 45 void SetHideNonSystemFloatingWindows(bool hide); 46 void SetForceHide(bool hide); 47 void SetRaiseEnabled(bool raiseEnabled); 48 void SetSystemCalling(bool isSystemCalling); 49 void SetTurnScreenOn(bool turnScreenOn); 50 void SetKeepScreenOn(bool keepScreenOn); 51 void SetRequestedOrientation(Orientation orientation); 52 void SetPrivacyMode(bool isPrivate); 53 void SetSystemPrivacyMode(bool isSystemPrivate); 54 void SetBrightness(float brightness); 55 void SetDisplayId(uint64_t displayId); 56 void SetWindowType(WindowType type); 57 void SetParentId(int32_t parentId); 58 void SetPersistentId(int32_t persistentId); 59 void SetParentPersistentId(int32_t persistentId); 60 void SetAccessTokenId(uint32_t accessTokenId); 61 void SetTokenState(bool hasToken); 62 void SetMaximizeMode(MaximizeMode mode); 63 void SetWindowMode(WindowMode mode); 64 void SetWindowLimits(const WindowLimits& windowLimits); 65 void SetSystemBarProperty(WindowType type, const SystemBarProperty& property); 66 void SetSessionGravity(SessionGravity gravity_, uint32_t percent); 67 void SetDecorEnable(bool isDecorEnable); 68 void SetAnimationFlag(uint32_t animationFlag); 69 void SetTransform(const Transform& trans); 70 void SetWindowFlags(uint32_t flags); 71 void AddWindowFlag(WindowFlag flag); 72 void SetModeSupportInfo(uint32_t modeSupportInfo); 73 void SetFloatingWindowAppType(bool isAppType); 74 void SetTouchHotAreas(const std::vector<Rect>& rects); 75 void KeepKeyboardOnFocus(bool keepKeyboardFlag); 76 void SetIsNeedUpdateWindowMode(bool isNeedUpdateWindowMode); 77 void SetCallingWindow(uint32_t windowId); 78 79 bool GetIsNeedUpdateWindowMode() const; 80 const std::string& GetWindowName() const; 81 const SessionInfo& GetSessionInfo() const; 82 Rect GetWindowRect() const; 83 Rect GetRequestRect() const; 84 WindowType GetWindowType() const; 85 bool GetFocusable() const; 86 bool GetTouchable() const; 87 bool GetDragEnabled() const; 88 bool GetHideNonSystemFloatingWindows() const; 89 bool GetForceHide() const; 90 bool GetRaiseEnabled() const; 91 bool GetSystemCalling() const; 92 bool IsTurnScreenOn() const; 93 bool IsKeepScreenOn() const; 94 Orientation GetRequestedOrientation() const; 95 bool GetPrivacyMode() const; 96 bool GetSystemPrivacyMode() const; 97 float GetBrightness() const; 98 int32_t GetParentId() const; 99 uint32_t GetWindowFlags() const; 100 uint64_t GetDisplayId() const; 101 int32_t GetPersistentId() const; 102 int32_t GetParentPersistentId() const; 103 uint32_t GetAccessTokenId() const; 104 bool GetTokenState() const; 105 MaximizeMode GetMaximizeMode() const; 106 WindowMode GetWindowMode() const; 107 WindowLimits GetWindowLimits() const; 108 uint32_t GetModeSupportInfo() const; 109 std::unordered_map<WindowType, SystemBarProperty> GetSystemBarProperty() const; 110 void GetSessionGravity(SessionGravity& gravity, uint32_t& percent); 111 bool IsDecorEnable(); 112 uint32_t GetAnimationFlag() const; 113 const Transform& GetTransform() const; 114 bool IsFloatingWindowAppType() const; 115 void GetTouchHotAreas(std::vector<Rect>& rects) const; 116 bool GetKeepKeyboardFlag() const; 117 uint32_t GetCallingWindow() const; 118 119 bool MarshallingWindowLimits(Parcel& parcel) const; 120 static void UnmarshallingWindowLimits(Parcel& parcel, WindowSessionProperty* property); 121 bool MarshallingSystemBarMap(Parcel& parcel) const; 122 static void UnMarshallingSystemBarMap(Parcel& parcel, WindowSessionProperty* property); 123 bool Marshalling(Parcel& parcel) const override; 124 static WindowSessionProperty* Unmarshalling(Parcel& parcel); 125 126 void SetTextFieldPositionY(double textFieldPositionY); 127 void SetTextFieldHeight(double textFieldHeight); 128 129 WindowState GetWindowState() const; 130 void SetWindowState(WindowState state); 131 132 double GetTextFieldPositionY() const; 133 double GetTextFieldHeight() const; 134 135 void SetSessionPropertyChangeCallback(std::function<void()>&& callback); 136 bool IsLayoutFullScreen() const; 137 void SetIsLayoutFullScreen(bool isLayoutFullScreen); 138 139 private: 140 bool MarshallingTouchHotAreas(Parcel& parcel) const; 141 static void UnmarshallingTouchHotAreas(Parcel& parcel, WindowSessionProperty* property); 142 std::string windowName_; 143 SessionInfo sessionInfo_; 144 Rect requestRect_ { 0, 0, 0, 0 }; // window rect requested by the client (without decoration size) 145 Rect windowRect_ { 0, 0, 0, 0 }; // actual window rect 146 WindowType type_ { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW }; // type main window 147 bool focusable_ { true }; 148 bool touchable_ { true }; 149 bool dragEnabled_ = { true }; 150 bool raiseEnabled_ = { true }; 151 bool isSystemCalling_ = { false }; 152 bool tokenState_ { false }; 153 bool turnScreenOn_ = false; 154 bool keepScreenOn_ = false; 155 Orientation requestedOrientation_ = Orientation::UNSPECIFIED; 156 bool isPrivacyMode_ { false }; 157 bool isSystemPrivacyMode_ { false }; 158 float brightness_ = UNDEFINED_BRIGHTNESS; 159 uint64_t displayId_ = 0; 160 int32_t parentId_ = INVALID_SESSION_ID; // parentId of sceneSession, which is low 32 bite of parentPersistentId_ 161 uint32_t flags_ = 0; 162 int32_t persistentId_ = INVALID_SESSION_ID; 163 int32_t parentPersistentId_ = INVALID_SESSION_ID; 164 uint32_t accessTokenId_ = INVALID_SESSION_ID; 165 MaximizeMode maximizeMode_ = MaximizeMode::MODE_RECOVER; 166 WindowMode windowMode_ = WindowMode::WINDOW_MODE_FULLSCREEN; 167 WindowState windowState_ = WindowState::STATE_INITIAL; 168 WindowLimits limits_; 169 SessionGravity sessionGravity_ = SessionGravity::SESSION_GRAVITY_DEFAULT; 170 uint32_t sessionGravitySizePercent_ = 0; 171 uint32_t modeSupportInfo_ {WindowModeSupport::WINDOW_MODE_SUPPORT_ALL}; 172 std::unordered_map<WindowType, SystemBarProperty> sysBarPropMap_ { 173 { WindowType::WINDOW_TYPE_STATUS_BAR, SystemBarProperty(true, 0x00FFFFFF, 0xFF000000) }, 174 { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SystemBarProperty(true, 0x00FFFFFF, 0xFF000000) }, 175 { WindowType::WINDOW_TYPE_NAVIGATION_INDICATOR, SystemBarProperty(true, 0x00FFFFFF, 0xFF000000) }, 176 }; 177 bool isDecorEnable_ = false; 178 uint32_t animationFlag_ { static_cast<uint32_t>(WindowAnimation::DEFAULT) }; 179 // Transform info 180 Transform trans_; 181 bool isFloatingWindowAppType_ = false; 182 std::vector<Rect> touchHotAreas_; // coordinates relative to window. 183 bool hideNonSystemFloatingWindows_ = false; 184 bool forceHide_ = false; 185 bool keepKeyboardFlag_ = false; 186 uint32_t callingWindowId_ = INVALID_WINDOW_ID; 187 188 double textFieldPositionY_ = 0.0; 189 double textFieldHeight_ = 0.0; 190 bool isNeedUpdateWindowMode_ = false; 191 std::function<void()> touchHotAreasChangeCallback_; 192 bool isLayoutFullScreen_ = false; 193 }; 194 195 struct SystemSessionConfig : public Parcelable { 196 bool isSystemDecorEnable_ = true; 197 uint32_t decorModeSupportInfo_ = WindowModeSupport::WINDOW_MODE_SUPPORT_ALL; 198 bool isStretchable_ = false; 199 WindowMode defaultWindowMode_ = WindowMode::WINDOW_MODE_FULLSCREEN; 200 KeyboardAnimationConfig keyboardAnimationConfig_; 201 uint32_t maxFloatingWindowSize_ = UINT32_MAX; 202 uint32_t miniWidthOfMainWindow_ = 0; 203 uint32_t miniHeightOfMainWindow_ = 0; 204 uint32_t miniWidthOfSubWindow_ = 0; 205 uint32_t miniHeightOfSubWindow_ = 0; 206 bool backgroundswitch = false; 207 MarshallingSystemSessionConfig208 virtual bool Marshalling(Parcel& parcel) const override 209 { 210 if (!parcel.WriteBool(isSystemDecorEnable_) || !parcel.WriteBool(isStretchable_) || 211 !parcel.WriteUint32(decorModeSupportInfo_)) { 212 return false; 213 } 214 215 if (!parcel.WriteUint32(static_cast<uint32_t>(defaultWindowMode_)) || 216 !parcel.WriteParcelable(&keyboardAnimationConfig_) || 217 !parcel.WriteUint32(maxFloatingWindowSize_)) { 218 return false; 219 } 220 221 if (!parcel.WriteUint32(miniWidthOfMainWindow_) || !parcel.WriteUint32(miniHeightOfMainWindow_) || 222 !parcel.WriteUint32(miniWidthOfSubWindow_) || !parcel.WriteUint32(miniHeightOfSubWindow_)) { 223 return false; 224 } 225 226 if (!parcel.WriteBool(backgroundswitch)) { 227 return false; 228 } 229 return true; 230 } 231 UnmarshallingSystemSessionConfig232 static SystemSessionConfig* Unmarshalling(Parcel& parcel) 233 { 234 SystemSessionConfig* config = new (std::nothrow) SystemSessionConfig(); 235 if (config == nullptr) { 236 return nullptr; 237 } 238 config->isSystemDecorEnable_ = parcel.ReadBool(); 239 config->isStretchable_ = parcel.ReadBool(); 240 config->decorModeSupportInfo_ = parcel.ReadUint32(); 241 config->defaultWindowMode_ = static_cast<WindowMode>(parcel.ReadUint32()); 242 sptr<KeyboardAnimationConfig> keyboardConfig = parcel.ReadParcelable<KeyboardAnimationConfig>(); 243 config->keyboardAnimationConfig_ = *keyboardConfig; 244 config->maxFloatingWindowSize_ = parcel.ReadUint32(); 245 config->miniWidthOfMainWindow_ = parcel.ReadUint32(); 246 config->miniHeightOfMainWindow_ = parcel.ReadUint32(); 247 config->miniWidthOfSubWindow_ = parcel.ReadUint32(); 248 config->miniHeightOfSubWindow_ = parcel.ReadUint32(); 249 config->backgroundswitch = parcel.ReadBool(); 250 return config; 251 } 252 }; 253 } // namespace Rosen 254 } // namespace OHOS 255 #endif // OHOS_ROSEN_WINDOW_PROPERTY_H 256