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
30namespace OHOS {
31namespace Rosen {
32class WindowProperty : public Parcelable {
33public:
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 SetModeSupportInfo(uint32_t modeSupportInfo);
74    void SetRequestModeSupportInfo(uint32_t requestModeSupportInfo);
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 GetModeSupportInfo() const;
126    uint32_t GetRequestModeSupportInfo() 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;
156private:
157    bool MapMarshalling(Parcel& parcel) const;
158    static void MapUnmarshalling(Parcel& parcel, WindowProperty* property);
159    bool MarshallingTouchHotAreas(Parcel& parcel) const;
160    static void UnmarshallingTouchHotAreas(Parcel& parcel, WindowProperty* property);
161    bool MarshallingTransform(Parcel& parcel) const;
162    static void UnmarshallingTransform(Parcel& parcel, WindowProperty* property);
163    bool MarshallingWindowSizeLimits(Parcel& parcel) const;
164    static void UnmarshallingWindowSizeLimits(Parcel& parcel, WindowProperty* property);
165    void HandleComputeTransform(const Transform& trans);
166
167    std::string windowName_;
168    AbilityInfo abilityInfo_;
169    Rect requestRect_ { 0, 0, 0, 0 }; // window rect requested by the client (without decoration size)
170    Rect windowRect_ { 0, 0, 0, 0 }; // actual window rect
171    bool decoStatus_ { false }; // window has been decorated or not
172    WindowType type_ { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW };
173    WindowMode mode_ { WindowMode::WINDOW_MODE_UNDEFINED };
174    WindowMode lastMode_ { WindowMode::WINDOW_MODE_UNDEFINED };
175    uint32_t flags_ { 0 };
176    bool isFullScreen_ { true };
177    bool focusable_ { true };
178    bool touchable_ { true };
179    bool isPrivacyMode_ { false };
180    bool isSystemPrivacyMode_ { false };
181    bool isTransparent_ { false };
182    bool tokenState_ { false };
183    float alpha_ { 1.0f };
184    float brightness_ = UNDEFINED_BRIGHTNESS;
185    bool turnScreenOn_ = false;
186    bool keepScreenOn_ = false;
187    uint32_t callingWindow_ = INVALID_WINDOW_ID;
188    DisplayId displayId_ { 0 };
189    uint32_t windowId_ = INVALID_WINDOW_ID;
190    uint32_t parentId_ = INVALID_WINDOW_ID;
191    PointInfo hitOffset_ { 0, 0 };
192    uint32_t animationFlag_ { static_cast<uint32_t>(WindowAnimation::DEFAULT) };
193    // modeSupportInfo_ means supported modes in runtime, which can be changed
194    uint32_t modeSupportInfo_ {WindowModeSupport::WINDOW_MODE_SUPPORT_ALL};
195    // requestModeSupportInfo_ is configured in abilityInfo, usually can't be changed
196    uint32_t requestModeSupportInfo_ {WindowModeSupport::WINDOW_MODE_SUPPORT_ALL};
197    WindowSizeChangeReason windowSizeChangeReason_ = WindowSizeChangeReason::UNDEFINED;
198    std::unordered_map<WindowType, SystemBarProperty> sysBarPropMap_ {
199        { WindowType::WINDOW_TYPE_STATUS_BAR,     SystemBarProperty() },
200        { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SystemBarProperty() },
201    };
202    bool isDecorEnable_ { true };
203    Rect originRect_ = { 0, 0, 0, 0 };
204    bool isStretchable_ {false};
205    DragType dragType_ = DragType::DRAG_UNDEFINED;
206    std::vector<Rect> touchHotAreas_;  // coordinates relative to window.
207    uint32_t accessTokenId_ { 0 };
208    // Transform info
209    Transform trans_;
210    bool recomputeTransformMat_ { false };
211    TransformHelper::Matrix4 transformMat_ = TransformHelper::Matrix4::Identity;
212    TransformHelper::Matrix4 worldTransformMat_ = TransformHelper::Matrix4::Identity;
213    // Display Zoom transform info
214    Transform zoomTrans_; // Compared with original window rect, including class member trans_
215    bool reCalcuZoomTransformMat_ {true};
216    // if scale of trans_ is less than 1.0, zoomTrans_ may be an identity matrix
217    bool isDisplayZoomOn_ {false};
218    bool isAnimateWindow_ {false};
219    float aspectRatio_ {0.0};
220    WindowGravity windowGravity_ = WindowGravity::WINDOW_GRAVITY_BOTTOM;
221    uint32_t windowGravitySizePercent_ = 0;
222    bool isSnapshotSkip_ = false;
223
224    DEFINE_VAR_DEFAULT_FUNC_GET_SET(Orientation, RequestedOrientation, requestedOrientation, Orientation::UNSPECIFIED);
225    DEFINE_VAR_DEFAULT_FUNC_GET_SET(uint32_t, ApiCompatibleVersion, apiCompatibleVersion, 0u);
226    WindowLimits sizeLimits_;
227    WindowLimits updatedSizeLimits_;
228    MaximizeMode maximizeMode_ { MaximizeMode::MODE_RECOVER };
229
230    double textFieldPositionY_ = 0.0;
231    double textFieldHeight_ = 0.0;
232};
233}
234}
235#endif // OHOS_ROSEN_WINDOW_PROPERTY_H
236