• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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     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 
91     const std::string& GetWindowName() const;
92     const AbilityInfo& GetAbilityInfo() const;
93     Rect GetRequestRect() const;
94     Rect GetWindowRect() const;
95     bool GetDecoStatus() const;
96     Rect GetWindowHotZoneRect() const;
97     WindowType GetWindowType() const;
98     WindowMode GetWindowMode() const;
99     WindowMode GetLastWindowMode() const;
100     bool GetFullScreen() const;
101     bool GetFocusable() const;
102     bool GetTouchable() const;
103     uint32_t GetCallingWindow() const;
104     bool GetPrivacyMode() const;
105     bool GetSystemPrivacyMode() const;
106     bool GetTransparent() const;
107     bool GetTokenState() const;
108     float GetAlpha() const;
109     float GetBrightness() const;
110     bool IsTurnScreenOn() const;
111     bool IsKeepScreenOn() const;
112     DisplayId GetDisplayId() const;
113     uint32_t GetWindowId() const;
114     uint32_t GetParentId() const;
115     uint32_t GetWindowFlags() const;
116     const std::unordered_map<WindowType, SystemBarProperty>& GetSystemBarProperty() const;
117     bool GetDecorEnable() const;
118     const PointInfo& GetHitOffset() const;
119     uint32_t GetAnimationFlag() const;
120     uint32_t GetModeSupportInfo() const;
121     uint32_t GetRequestModeSupportInfo() const;
122     DragType GetDragType() const;
123     bool GetStretchable() const;
124     const Rect& GetOriginRect() const;
125     void GetTouchHotAreas(std::vector<Rect>& rects) const;
126     uint32_t GetAccessTokenId() const;
127     const Transform& GetTransform() const;
128     const Transform& GetZoomTransform() const;
129     bool IsDisplayZoomOn() const;
130     bool IsAnimateWindow() const;
131     WindowSizeLimits GetSizeLimits() const;
132     WindowSizeLimits GetUpdatedSizeLimits() const;
133     const TransformHelper::Matrix4& GetTransformMat() const;
134     const TransformHelper::Matrix4& GetWorldTransformMat() const;
135 
136     virtual bool Marshalling(Parcel& parcel) const override;
137     static WindowProperty* Unmarshalling(Parcel& parcel);
138 
139     bool Write(Parcel& parcel, PropertyChangeAction action);
140     void Read(Parcel& parcel, PropertyChangeAction action);
141 private:
142     bool MapMarshalling(Parcel& parcel) const;
143     static void MapUnmarshalling(Parcel& parcel, WindowProperty* property);
144     bool MarshallingTouchHotAreas(Parcel& parcel) const;
145     static void UnmarshallingTouchHotAreas(Parcel& parcel, WindowProperty* property);
146     bool MarshallingTransform(Parcel& parcel) const;
147     static void UnmarshallingTransform(Parcel& parcel, WindowProperty* property);
148     bool MarshallingWindowSizeLimits(Parcel& parcel) const;
149     static void UnmarshallingWindowSizeLimits(Parcel& parcel, WindowProperty* property);
150     void HandleComputeTransform(const Transform& trans);
151 
152     std::string windowName_;
153     AbilityInfo abilityInfo_;
154     Rect requestRect_ { 0, 0, 0, 0 }; // window rect requested by the client (without decoration size)
155     Rect windowRect_ { 0, 0, 0, 0 }; // actual window rect
156     bool decoStatus_ { false }; // window has been decorated or not
157     WindowType type_ { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW };
158     WindowMode mode_ { WindowMode::WINDOW_MODE_UNDEFINED };
159     WindowMode lastMode_ { WindowMode::WINDOW_MODE_UNDEFINED };
160     uint32_t flags_ { 0 };
161     bool isFullScreen_ { true };
162     bool focusable_ { true };
163     bool touchable_ { true };
164     bool isPrivacyMode_ { false };
165     bool isSystemPrivacyMode_ { false };
166     bool isTransparent_ { false };
167     bool tokenState_ { false };
168     float alpha_ { 1.0f };
169     float brightness_ = UNDEFINED_BRIGHTNESS;
170     bool turnScreenOn_ = false;
171     bool keepScreenOn_ = false;
172     uint32_t callingWindow_ = INVALID_WINDOW_ID;
173     DisplayId displayId_ { 0 };
174     uint32_t windowId_ = INVALID_WINDOW_ID;
175     uint32_t parentId_ = INVALID_WINDOW_ID;
176     PointInfo hitOffset_ { 0, 0 };
177     uint32_t animationFlag_ { static_cast<uint32_t>(WindowAnimation::DEFAULT) };
178     // modeSupportInfo_ means supported modes in runtime, which can be changed
179     uint32_t modeSupportInfo_ {WindowModeSupport::WINDOW_MODE_SUPPORT_ALL};
180     // requestModeSupportInfo_ is configured in abilityInfo, usually can't be changed
181     uint32_t requestModeSupportInfo_ {WindowModeSupport::WINDOW_MODE_SUPPORT_ALL};
182     WindowSizeChangeReason windowSizeChangeReason_ = WindowSizeChangeReason::UNDEFINED;
183     std::unordered_map<WindowType, SystemBarProperty> sysBarPropMap_ {
184         { WindowType::WINDOW_TYPE_STATUS_BAR,     SystemBarProperty() },
185         { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SystemBarProperty() },
186     };
187     bool isDecorEnable_ { false };
188     Rect originRect_ = { 0, 0, 0, 0 };
189     bool isStretchable_ {false};
190     DragType dragType_ = DragType::DRAG_UNDEFINED;
191     std::vector<Rect> touchHotAreas_;  // coordinates relative to window.
192     uint32_t accessTokenId_ { 0 };
193     // Transform info
194     Transform trans_;
195     bool recomputeTransformMat_ { false };
196     TransformHelper::Matrix4 transformMat_ = TransformHelper::Matrix4::Identity;
197     TransformHelper::Matrix4 worldTransformMat_ = TransformHelper::Matrix4::Identity;
198     // Display Zoom transform info
199     Transform zoomTrans_; // Compared with original window rect, including class member trans_
200     bool reCalcuZoomTransformMat_ {true};
201     // if scale of trans_ is less than 1.0, zoomTrans_ may be an identity matrix
202     bool isDisplayZoomOn_ {false};
203     bool isAnimateWindow_ {false};
204 
205     DEFINE_VAR_DEFAULT_FUNC_GET_SET(Orientation, RequestedOrientation, requestedOrientation, Orientation::UNSPECIFIED);
206     WindowSizeLimits sizeLimits_;
207     WindowSizeLimits updatedSizeLimits_;
208 };
209 }
210 }
211 #endif // OHOS_ROSEN_WINDOW_PROPERTY_H
212