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 SetTransparent(bool isTransparent); 56 void SetAlpha(float alpha); 57 void SetBrightness(float brightness); 58 void SetTurnScreenOn(bool turnScreenOn); 59 void SetKeepScreenOn(bool keepScreenOn); 60 void SetCallingWindow(uint32_t windowId); 61 void SetDisplayId(DisplayId displayId); 62 void SetWindowId(uint32_t windowId); 63 void SetParentId(uint32_t parentId); 64 void SetWindowFlags(uint32_t flags); 65 void AddWindowFlag(WindowFlag flag); 66 void SetSystemBarProperty(WindowType type, const SystemBarProperty& state); 67 void SetDecorEnable(bool decorEnable); 68 void SetHitOffset(const PointInfo& offset); 69 void SetAnimationFlag(uint32_t animationFlag); 70 void SetWindowSizeChangeReason(WindowSizeChangeReason reason); 71 void SetTokenState(bool hasToken); 72 void SetModeSupportInfo(uint32_t modeSupportInfo); 73 void SetRequestModeSupportInfo(uint32_t requestModeSupportInfo); 74 void SetDragType(DragType dragType); 75 void SetStretchable(bool stretchable); 76 void SetOriginRect(const Rect& rect); 77 void SetTouchHotAreas(const std::vector<Rect>& rects); 78 void SetAccessTokenId(uint32_t accessTokenId); 79 void SetSizeLimits(const WindowSizeLimits& sizeLimits); 80 void SetUpdatedSizeLimits(const WindowSizeLimits& sizeLimits); 81 WindowSizeChangeReason GetWindowSizeChangeReason() const; 82 void SetTransform(const Transform& trans); 83 void ComputeTransform(); 84 void SetZoomTransform(const Transform& trans); 85 void SetDisplayZoomState(bool isDisplayZoomOn); 86 void SetAnimateWindowFlag(bool isAnimateWindow); 87 void UpdatePointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent); 88 bool isNeedComputerTransform(); 89 void ClearTransformZAxisOffset(Transform& trans); 90 void SetAspectRatio(float ratio); 91 void SetWindowGravity(WindowGravity gravity, uint32_t percent); 92 void SetMaximizeMode(MaximizeMode maximizeMode); 93 void SetOnlySkipSnapshot(bool onlySkip); 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 GetTransparent() const; 111 bool GetTokenState() const; 112 float GetAlpha() const; 113 float GetBrightness() const; 114 bool IsTurnScreenOn() const; 115 bool IsKeepScreenOn() const; 116 DisplayId GetDisplayId() const; 117 uint32_t GetWindowId() const; 118 uint32_t GetParentId() const; 119 uint32_t GetWindowFlags() const; 120 const std::unordered_map<WindowType, SystemBarProperty>& GetSystemBarProperty() const; 121 bool GetDecorEnable() const; 122 const PointInfo& GetHitOffset() const; 123 uint32_t GetAnimationFlag() const; 124 uint32_t GetModeSupportInfo() const; 125 uint32_t GetRequestModeSupportInfo() const; 126 DragType GetDragType() const; 127 bool GetStretchable() const; 128 const Rect& GetOriginRect() const; 129 void GetTouchHotAreas(std::vector<Rect>& rects) const; 130 uint32_t GetAccessTokenId() const; 131 const Transform& GetTransform() const; 132 const Transform& GetZoomTransform() const; 133 bool IsDisplayZoomOn() const; 134 bool IsAnimateWindow() const; 135 WindowSizeLimits GetSizeLimits() const; 136 WindowSizeLimits GetUpdatedSizeLimits() const; 137 const TransformHelper::Matrix4& GetTransformMat() const; 138 const TransformHelper::Matrix4& GetWorldTransformMat() const; 139 float GetAspectRatio() const; 140 void GetWindowGravity(WindowGravity& gravity, uint32_t& percent) const; 141 MaximizeMode GetMaximizeMode() const; 142 bool GetOnlySkipSnapshot(); 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 private: 151 bool MapMarshalling(Parcel& parcel) const; 152 static void MapUnmarshalling(Parcel& parcel, WindowProperty* property); 153 bool MarshallingTouchHotAreas(Parcel& parcel) const; 154 static void UnmarshallingTouchHotAreas(Parcel& parcel, WindowProperty* property); 155 bool MarshallingTransform(Parcel& parcel) const; 156 static void UnmarshallingTransform(Parcel& parcel, WindowProperty* property); 157 bool MarshallingWindowSizeLimits(Parcel& parcel) const; 158 static void UnmarshallingWindowSizeLimits(Parcel& parcel, WindowProperty* property); 159 void HandleComputeTransform(const Transform& trans); 160 161 std::string windowName_; 162 AbilityInfo abilityInfo_; 163 Rect requestRect_ { 0, 0, 0, 0 }; // window rect requested by the client (without decoration size) 164 Rect windowRect_ { 0, 0, 0, 0 }; // actual window rect 165 bool decoStatus_ { false }; // window has been decorated or not 166 WindowType type_ { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW }; 167 WindowMode mode_ { WindowMode::WINDOW_MODE_UNDEFINED }; 168 WindowMode lastMode_ { WindowMode::WINDOW_MODE_UNDEFINED }; 169 uint32_t flags_ { 0 }; 170 bool isFullScreen_ { true }; 171 bool focusable_ { true }; 172 bool touchable_ { true }; 173 bool isPrivacyMode_ { false }; 174 bool isSystemPrivacyMode_ { false }; 175 bool isTransparent_ { false }; 176 bool tokenState_ { false }; 177 float alpha_ { 1.0f }; 178 float brightness_ = UNDEFINED_BRIGHTNESS; 179 bool turnScreenOn_ = false; 180 bool keepScreenOn_ = false; 181 uint32_t callingWindow_ = INVALID_WINDOW_ID; 182 DisplayId displayId_ { 0 }; 183 uint32_t windowId_ = INVALID_WINDOW_ID; 184 uint32_t parentId_ = INVALID_WINDOW_ID; 185 PointInfo hitOffset_ { 0, 0 }; 186 uint32_t animationFlag_ { static_cast<uint32_t>(WindowAnimation::DEFAULT) }; 187 // modeSupportInfo_ means supported modes in runtime, which can be changed 188 uint32_t modeSupportInfo_ {WindowModeSupport::WINDOW_MODE_SUPPORT_ALL}; 189 // requestModeSupportInfo_ is configured in abilityInfo, usually can't be changed 190 uint32_t requestModeSupportInfo_ {WindowModeSupport::WINDOW_MODE_SUPPORT_ALL}; 191 WindowSizeChangeReason windowSizeChangeReason_ = WindowSizeChangeReason::UNDEFINED; 192 std::unordered_map<WindowType, SystemBarProperty> sysBarPropMap_ { 193 { WindowType::WINDOW_TYPE_STATUS_BAR, SystemBarProperty() }, 194 { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SystemBarProperty() }, 195 }; 196 bool isDecorEnable_ { true }; 197 Rect originRect_ = { 0, 0, 0, 0 }; 198 bool isStretchable_ {false}; 199 DragType dragType_ = DragType::DRAG_UNDEFINED; 200 std::vector<Rect> touchHotAreas_; // coordinates relative to window. 201 uint32_t accessTokenId_ { 0 }; 202 // Transform info 203 Transform trans_; 204 bool recomputeTransformMat_ { false }; 205 TransformHelper::Matrix4 transformMat_ = TransformHelper::Matrix4::Identity; 206 TransformHelper::Matrix4 worldTransformMat_ = TransformHelper::Matrix4::Identity; 207 // Display Zoom transform info 208 Transform zoomTrans_; // Compared with original window rect, including class member trans_ 209 bool reCalcuZoomTransformMat_ {true}; 210 // if scale of trans_ is less than 1.0, zoomTrans_ may be an identity matrix 211 bool isDisplayZoomOn_ {false}; 212 bool isAnimateWindow_ {false}; 213 float aspectRatio_ {0.0}; 214 WindowGravity windowGravity_ = WindowGravity::WINDOW_GRAVITY_BOTTOM; 215 uint32_t windowGravitySizePercent_ = 0; 216 bool onlySkipSnapshot_ = false; 217 218 DEFINE_VAR_DEFAULT_FUNC_GET_SET(Orientation, RequestedOrientation, requestedOrientation, Orientation::UNSPECIFIED); 219 DEFINE_VAR_DEFAULT_FUNC_GET_SET(uint32_t, ApiCompatibleVersion, apiCompatibleVersion, 0u); 220 WindowSizeLimits sizeLimits_; 221 WindowSizeLimits updatedSizeLimits_; 222 MaximizeMode maximizeMode_ { MaximizeMode::MODE_RECOVER }; 223 }; 224 } 225 } 226 #endif // OHOS_ROSEN_WINDOW_PROPERTY_H 227