1 /* 2 * Copyright (c) 2021-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_PROPERTY_H 17 #define OHOS_ROSEN_WINDOW_PROPERTY_H 18 19 #include <refbase.h> 20 #include <string> 21 #include <unordered_map> 22 #include <parcel.h> 23 #include "class_var_definition.h" 24 #include "pointer_event.h" 25 #include "dm_common.h" 26 #include "wm_common.h" 27 #include "wm_common_inner.h" 28 #include "wm_math.h" 29 30 namespace OHOS { 31 namespace Rosen { 32 class WindowProperty : public Parcelable { 33 public: 34 WindowProperty() = default; 35 explicit WindowProperty(const sptr<WindowProperty>& property); 36 ~WindowProperty() = default; 37 38 void CopyFrom(const sptr<WindowProperty>& property); 39 40 void SetWindowName(const std::string& name); 41 void SetAbilityInfo(const AbilityInfo& info); 42 void SetRequestRect(const struct Rect& rect); 43 void SetWindowRect(const struct Rect& rect); 44 void SetDecoStatus(bool decoStatus); 45 void SetWindowHotZoneRect(const struct Rect& rect); 46 void SetWindowType(WindowType type); 47 void SetWindowMode(WindowMode mode); 48 void SetLastWindowMode(WindowMode mode); 49 void ResumeLastWindowMode(); 50 void SetFullScreen(bool isFullScreen); 51 void SetFocusable(bool isFocusable); 52 void SetTouchable(bool isTouchable); 53 void SetPrivacyMode(bool isPrivate); 54 void SetSystemPrivacyMode(bool isSystemPrivate); 55 void SetSnapshotSkip(bool isSkip); 56 void SetTransparent(bool isTransparent); 57 void SetAlpha(float alpha); 58 void SetBrightness(float brightness); 59 void SetTurnScreenOn(bool turnScreenOn); 60 void SetKeepScreenOn(bool keepScreenOn); 61 void SetCallingWindow(uint32_t windowId); 62 void SetDisplayId(DisplayId displayId); 63 void SetWindowId(uint32_t windowId); 64 void SetParentId(uint32_t parentId); 65 void SetWindowFlags(uint32_t flags); 66 void AddWindowFlag(WindowFlag flag); 67 void SetSystemBarProperty(WindowType type, const SystemBarProperty& state); 68 void SetDecorEnable(bool decorEnable); 69 void SetHitOffset(const PointInfo& offset); 70 void SetAnimationFlag(uint32_t animationFlag); 71 void SetWindowSizeChangeReason(WindowSizeChangeReason reason); 72 void SetTokenState(bool hasToken); 73 void SetWindowModeSupportType(uint32_t windowModeSupportType); 74 void SetRequestWindowModeSupportType(uint32_t requestWindowModeSupportType); 75 void SetDragType(DragType dragType); 76 void SetStretchable(bool stretchable); 77 void SetOriginRect(const Rect& rect); 78 void SetTouchHotAreas(const std::vector<Rect>& rects); 79 void SetAccessTokenId(uint32_t accessTokenId); 80 void SetSizeLimits(const WindowLimits& sizeLimits); 81 void SetUpdatedSizeLimits(const WindowLimits& sizeLimits); 82 WindowSizeChangeReason GetWindowSizeChangeReason() const; 83 void SetTransform(const Transform& trans); 84 void ComputeTransform(); 85 void SetZoomTransform(const Transform& trans); 86 void SetDisplayZoomState(bool isDisplayZoomOn); 87 void SetAnimateWindowFlag(bool isAnimateWindow); 88 void UpdatePointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent); 89 bool isNeedComputerTransform(); 90 void ClearTransformZAxisOffset(Transform& trans); 91 void SetAspectRatio(float ratio); 92 void SetWindowGravity(WindowGravity gravity, uint32_t percent); 93 void SetMaximizeMode(MaximizeMode maximizeMode); 94 95 const std::string& GetWindowName() const; 96 const AbilityInfo& GetAbilityInfo() const; 97 Rect GetRequestRect() const; 98 Rect GetWindowRect() const; 99 bool GetDecoStatus() const; 100 Rect GetWindowHotZoneRect() const; 101 WindowType GetWindowType() const; 102 WindowMode GetWindowMode() const; 103 WindowMode GetLastWindowMode() const; 104 bool GetFullScreen() const; 105 bool GetFocusable() const; 106 bool GetTouchable() const; 107 uint32_t GetCallingWindow() const; 108 bool GetPrivacyMode() const; 109 bool GetSystemPrivacyMode() const; 110 bool GetSnapshotSkip() const; 111 bool GetTransparent() const; 112 bool GetTokenState() const; 113 float GetAlpha() const; 114 float GetBrightness() const; 115 bool IsTurnScreenOn() const; 116 bool IsKeepScreenOn() const; 117 DisplayId GetDisplayId() const; 118 uint32_t GetWindowId() const; 119 uint32_t GetParentId() const; 120 uint32_t GetWindowFlags() const; 121 const std::unordered_map<WindowType, SystemBarProperty>& GetSystemBarProperty() const; 122 bool GetDecorEnable() const; 123 const PointInfo& GetHitOffset() const; 124 uint32_t GetAnimationFlag() const; 125 uint32_t GetWindowModeSupportType() const; 126 uint32_t GetRequestWindowModeSupportType() const; 127 DragType GetDragType() const; 128 bool GetStretchable() const; 129 const Rect& GetOriginRect() const; 130 void GetTouchHotAreas(std::vector<Rect>& rects) const; 131 uint32_t GetAccessTokenId() const; 132 const Transform& GetTransform() const; 133 const Transform& GetZoomTransform() const; 134 bool IsDisplayZoomOn() const; 135 bool IsAnimateWindow() const; 136 WindowLimits GetSizeLimits() const; 137 WindowLimits GetUpdatedSizeLimits() const; 138 const TransformHelper::Matrix4& GetTransformMat() const; 139 const TransformHelper::Matrix4& GetWorldTransformMat() const; 140 float GetAspectRatio() const; 141 void GetWindowGravity(WindowGravity& gravity, uint32_t& percent) const; 142 MaximizeMode GetMaximizeMode() const; 143 144 virtual bool Marshalling(Parcel& parcel) const override; 145 static WindowProperty* Unmarshalling(Parcel& parcel); 146 147 bool Write(Parcel& parcel, PropertyChangeAction action); 148 void Read(Parcel& parcel, PropertyChangeAction action); 149 bool isSystemCalling_ { false }; 150 151 void SetTextFieldPositionY(double textFieldPositionY); 152 void SetTextFieldHeight(double textFieldHeight); 153 154 double GetTextFieldPositionY() const; 155 double GetTextFieldHeight() const; 156 157 void SetFollowScreenChange(bool isFollowScreenChange); 158 bool GetFollowScreenChange() const; 159 160 private: 161 bool MapMarshalling(Parcel& parcel) const; 162 static void MapUnmarshalling(Parcel& parcel, WindowProperty* property); 163 bool MarshallingTouchHotAreas(Parcel& parcel) const; 164 static void UnmarshallingTouchHotAreas(Parcel& parcel, WindowProperty* property); 165 bool MarshallingTransform(Parcel& parcel) const; 166 static void UnmarshallingTransform(Parcel& parcel, WindowProperty* property); 167 bool MarshallingWindowSizeLimits(Parcel& parcel) const; 168 static void UnmarshallingWindowSizeLimits(Parcel& parcel, WindowProperty* property); 169 void HandleComputeTransform(const Transform& trans); 170 171 std::string windowName_; 172 AbilityInfo abilityInfo_; 173 Rect requestRect_ { 0, 0, 0, 0 }; // window rect requested by the client (without decoration size) 174 Rect windowRect_ { 0, 0, 0, 0 }; // actual window rect 175 bool decoStatus_ { false }; // window has been decorated or not 176 WindowType type_ { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW }; 177 WindowMode mode_ { WindowMode::WINDOW_MODE_UNDEFINED }; 178 WindowMode lastMode_ { WindowMode::WINDOW_MODE_UNDEFINED }; 179 uint32_t flags_ { 0 }; 180 bool isFullScreen_ { true }; 181 bool focusable_ { true }; 182 bool touchable_ { true }; 183 bool isPrivacyMode_ { false }; 184 bool isSystemPrivacyMode_ { false }; 185 bool isTransparent_ { false }; 186 bool tokenState_ { false }; 187 float alpha_ { 1.0f }; 188 float brightness_ = UNDEFINED_BRIGHTNESS; 189 bool turnScreenOn_ = false; 190 bool keepScreenOn_ = false; 191 bool isFollowScreenChange_ = false; 192 uint32_t callingWindow_ = INVALID_WINDOW_ID; 193 DisplayId displayId_ { 0 }; 194 uint32_t windowId_ = INVALID_WINDOW_ID; 195 uint32_t parentId_ = INVALID_WINDOW_ID; 196 PointInfo hitOffset_ { 0, 0 }; 197 uint32_t animationFlag_ { static_cast<uint32_t>(WindowAnimation::DEFAULT) }; 198 // windowModeSupportType_ means supported modes in runtime, which can be changed 199 uint32_t windowModeSupportType_ {WindowModeSupport::WINDOW_MODE_SUPPORT_ALL}; 200 // requestWindowModeSupportType_ is configured in abilityInfo, usually can't be changed 201 uint32_t requestWindowModeSupportType_ {WindowModeSupport::WINDOW_MODE_SUPPORT_ALL}; 202 WindowSizeChangeReason windowSizeChangeReason_ = WindowSizeChangeReason::UNDEFINED; 203 std::unordered_map<WindowType, SystemBarProperty> sysBarPropMap_ { 204 { WindowType::WINDOW_TYPE_STATUS_BAR, SystemBarProperty() }, 205 { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SystemBarProperty() }, 206 }; 207 bool isDecorEnable_ { true }; 208 Rect originRect_ = { 0, 0, 0, 0 }; 209 bool isStretchable_ {false}; 210 DragType dragType_ = DragType::DRAG_UNDEFINED; 211 std::vector<Rect> touchHotAreas_; // coordinates relative to window. 212 uint32_t accessTokenId_ { 0 }; 213 // Transform info 214 Transform trans_; 215 bool recomputeTransformMat_ { false }; 216 TransformHelper::Matrix4 transformMat_ = TransformHelper::Matrix4::Identity; 217 TransformHelper::Matrix4 worldTransformMat_ = TransformHelper::Matrix4::Identity; 218 // Display Zoom transform info 219 Transform zoomTrans_; // Compared with original window rect, including class member trans_ 220 bool reCalcuZoomTransformMat_ {true}; 221 // if scale of trans_ is less than 1.0, zoomTrans_ may be an identity matrix 222 bool isDisplayZoomOn_ {false}; 223 bool isAnimateWindow_ {false}; 224 float aspectRatio_ {0.0}; 225 WindowGravity windowGravity_ = WindowGravity::WINDOW_GRAVITY_BOTTOM; 226 uint32_t windowGravitySizePercent_ = 0; 227 bool isSnapshotSkip_ = false; 228 229 DEFINE_VAR_DEFAULT_FUNC_GET_SET(Orientation, RequestedOrientation, requestedOrientation, Orientation::UNSPECIFIED); 230 DEFINE_VAR_DEFAULT_FUNC_GET_SET(uint32_t, ApiCompatibleVersion, apiCompatibleVersion, 0u); 231 WindowLimits sizeLimits_; 232 WindowLimits updatedSizeLimits_; 233 MaximizeMode maximizeMode_ { MaximizeMode::MODE_RECOVER }; 234 235 double textFieldPositionY_ = 0.0; 236 double textFieldHeight_ = 0.0; 237 }; 238 } 239 } 240 #endif // OHOS_ROSEN_WINDOW_PROPERTY_H 241