• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 struct WindowLimits {
33     uint32_t maxWidth_;
34     uint32_t maxHeight_;
35     uint32_t minWidth_;
36     uint32_t minHeight_;
37     float maxRatio_;
38     float minRatio_;
WindowLimitsWindowLimits39     WindowLimits() : maxWidth_(UINT32_MAX), maxHeight_(UINT32_MAX), minWidth_(0), minHeight_(0), maxRatio_(FLT_MAX),
40         minRatio_(0.0f) {}
WindowLimitsWindowLimits41     WindowLimits(uint32_t maxWidth, uint32_t maxHeight, uint32_t minWidth, uint32_t minHeight, float maxRatio,
42         float minRatio) : maxWidth_(maxWidth), maxHeight_(maxHeight), minWidth_(minWidth), minHeight_(minHeight),
43         maxRatio_(maxRatio), minRatio_(minRatio) {}
44 
IsEmptyWindowLimits45     bool IsEmpty() const
46     {
47         return (maxWidth_ == 0 || minWidth_ == 0 || maxHeight_ == 0 || minHeight_ == 0);
48     }
49 };
50 
51 class WindowSessionProperty : public Parcelable {
52 public:
53     WindowSessionProperty() = default;
54     ~WindowSessionProperty() = default;
55     explicit WindowSessionProperty(const sptr<WindowSessionProperty>& property);
56     void CopyFrom(const sptr<WindowSessionProperty>& property);
57     void SetWindowName(const std::string& name);
58     void SetSessionInfo(const SessionInfo& info);
59     void SetRequestRect(const struct Rect& rect);
60     void SetWindowRect(const struct Rect& rect);
61     void SetFocusable(bool isFocusable);
62     void SetTouchable(bool isTouchable);
63     void SetDragEnabled(bool dragEnabled);
64     void SetRaiseEnabled(bool raiseEnabled);
65     void SetSystemCalling(bool isSystemCalling);
66     void SetTurnScreenOn(bool turnScreenOn);
67     void SetKeepScreenOn(bool keepScreenOn);
68     void SetBrightness(float brightness);
69     void SetRequestedOrientation(Orientation orientation);
70     void SetPrivacyMode(bool isPrivate);
71     void SetSystemPrivacyMode(bool isSystemPrivate);
72     void SetDisplayId(uint64_t displayId);
73     void SetWindowType(WindowType type);
74     void SetParentId(int32_t parentId);
75     void SetPersistentId(int32_t persistentId);
76     void SetParentPersistentId(int32_t persistentId);
77     void SetAccessTokenId(uint32_t accessTokenId);
78     void SetTokenState(bool hasToken);
79     void SetMaximizeMode(MaximizeMode mode);
80     void SetWindowMode(WindowMode mode);
81     void SetWindowLimits(const WindowLimits& windowLimits);
82     void SetSystemBarProperty(WindowType type, const SystemBarProperty& property);
83     void SetSessionGravity(SessionGravity gravity_, uint32_t percent);
84     void SetDecorEnable(bool isDecorEnable);
85     void SetAnimationFlag(uint32_t animationFlag);
86     void SetTransform(const Transform& trans);
87     void SetWindowFlags(uint32_t flags);
88     void AddWindowFlag(WindowFlag flag);
89     void SetModeSupportInfo(uint32_t modeSupportInfo);
90     void SetFloatingWindowAppType(bool isAppType);
91     void SetTouchHotAreas(const std::vector<Rect>& rects);
92 
93     const std::string& GetWindowName() const;
94     const SessionInfo& GetSessionInfo() const;
95     Rect GetWindowRect() const;
96     Rect GetRequestRect() const;
97     WindowType GetWindowType() const;
98     bool GetFocusable() const;
99     bool GetTouchable() const;
100     bool GetDragEnabled() const;
101     bool GetRaiseEnabled() const;
102     bool GetSystemCalling() const;
103     bool IsTurnScreenOn() const;
104     bool IsKeepScreenOn() const;
105     float GetBrightness() const;
106     Orientation GetRequestedOrientation() const;
107     bool GetPrivacyMode() const;
108     bool GetSystemPrivacyMode() const;
109     int32_t GetParentId() const;
110     uint32_t GetWindowFlags() const;
111     uint64_t GetDisplayId() const;
112     int32_t GetPersistentId() const;
113     int32_t GetParentPersistentId() const;
114     uint32_t GetAccessTokenId() const;
115     bool GetTokenState() const;
116     MaximizeMode GetMaximizeMode() const;
117     WindowMode GetWindowMode() const;
118     WindowLimits GetWindowLimits() const;
119     uint32_t GetModeSupportInfo() const;
120     std::unordered_map<WindowType, SystemBarProperty> GetSystemBarProperty() const;
121     void GetSessionGravity(SessionGravity& gravity, uint32_t& percent);
122     bool IsDecorEnable();
123     uint32_t GetAnimationFlag() const;
124     const Transform& GetTransform() const;
125     bool IsFloatingWindowAppType() const;
126     void GetTouchHotAreas(std::vector<Rect>& rects) const;
127 
128     bool MarshallingWindowLimits(Parcel& parcel) const;
129     static void UnmarshallingWindowLimits(Parcel& parcel, WindowSessionProperty* property);
130     bool MarshallingSystemBarMap(Parcel& parcel) const;
131     static void UnMarshallingSystemBarMap(Parcel& parcel, WindowSessionProperty* property);
132     bool Marshalling(Parcel& parcel) const override;
133     static WindowSessionProperty* Unmarshalling(Parcel& parcel);
134 
135 private:
136     bool MarshallingTouchHotAreas(Parcel& parcel) const;
137     static void UnmarshallingTouchHotAreas(Parcel& parcel, WindowSessionProperty* property);
138     std::string windowName_;
139     SessionInfo sessionInfo_;
140     Rect requestRect_ { 0, 0, 0, 0 }; // window rect requested by the client (without decoration size)
141     Rect windowRect_ { 0, 0, 0, 0 }; // actual window rect
142     WindowType type_ { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW }; // type main window
143     bool focusable_ { true };
144     bool touchable_ { true };
145     bool dragEnabled_ = { true };
146     bool raiseEnabled_ = { true };
147     bool isSystemCalling_ = { false };
148     bool tokenState_ { false };
149     bool turnScreenOn_ = false;
150     bool keepScreenOn_ = false;
151     float brightness_ = UNDEFINED_BRIGHTNESS;
152     Orientation requestedOrientation_ = Orientation::UNSPECIFIED;
153     bool isPrivacyMode_ { false };
154     bool isSystemPrivacyMode_ { false };
155     uint64_t displayId_ = 0;
156     int32_t parentId_ = INVALID_SESSION_ID; // parentId of sceneSession, which is low 32 bite of parentPersistentId_
157     uint32_t flags_ = 0;
158     int32_t persistentId_ = INVALID_SESSION_ID;
159     int32_t parentPersistentId_ = INVALID_SESSION_ID;
160     uint32_t accessTokenId_ = INVALID_SESSION_ID;
161     MaximizeMode maximizeMode_ = MaximizeMode::MODE_RECOVER;
162     WindowMode windowMode_ = WindowMode::WINDOW_MODE_FULLSCREEN;
163     WindowLimits limits_;
164     SessionGravity sessionGravity_ = SessionGravity::SESSION_GRAVITY_BOTTOM;
165     uint32_t sessionGravitySizePercent_ = 0;
166     uint32_t modeSupportInfo_ {WindowModeSupport::WINDOW_MODE_SUPPORT_ALL};
167     std::unordered_map<WindowType, SystemBarProperty> sysBarPropMap_ {
168         { WindowType::WINDOW_TYPE_STATUS_BAR,     SystemBarProperty(true, 0x00FFFFFF, 0xFF000000) },
169     };
170     bool isDecorEnable_ = false;
171     uint32_t animationFlag_ { static_cast<uint32_t>(WindowAnimation::DEFAULT) };
172     // Transform info
173     Transform trans_;
174     bool isFloatingWindowAppType_ = false;
175     std::vector<Rect> touchHotAreas_;  // coordinates relative to window.
176 };
177 
178 struct SystemSessionConfig : public Parcelable {
179     bool isSystemDecorEnable_ = true;
180     uint32_t decorModeSupportInfo_ = WindowModeSupport::WINDOW_MODE_SUPPORT_ALL;
181     bool isStretchable_ = false;
182     WindowMode defaultWindowMode_ = WindowMode::WINDOW_MODE_FULLSCREEN;
183     KeyboardAnimationConfig keyboardAnimationConfig_;
184     uint32_t maxFloatingWindowSize_ = UINT32_MAX;
185     uint32_t miniWidthOfMainWindow_ = 0;
186     uint32_t miniHeightOfMainWindow_ = 0;
187     uint32_t miniWidthOfSubWindow_ = 0;
188     uint32_t miniHeightOfSubWindow_ = 0;
189 
MarshallingSystemSessionConfig190     virtual bool Marshalling(Parcel& parcel) const override
191     {
192         if (!parcel.WriteBool(isSystemDecorEnable_) || !parcel.WriteBool(isStretchable_) ||
193             !parcel.WriteUint32(decorModeSupportInfo_)) {
194             return false;
195         }
196 
197         if (!parcel.WriteUint32(static_cast<uint32_t>(defaultWindowMode_)) ||
198             !parcel.WriteParcelable(&keyboardAnimationConfig_) ||
199             !parcel.WriteUint32(maxFloatingWindowSize_)) {
200             return false;
201         }
202 
203         if (!parcel.WriteUint32(miniWidthOfMainWindow_) || !parcel.WriteUint32(miniHeightOfMainWindow_) ||
204             !parcel.WriteUint32(miniWidthOfSubWindow_) || !parcel.WriteUint32(miniHeightOfSubWindow_)) {
205             return false;
206         }
207 
208         return true;
209     }
210 
UnmarshallingSystemSessionConfig211     static SystemSessionConfig* Unmarshalling(Parcel& parcel)
212     {
213         SystemSessionConfig* config = new (std::nothrow) SystemSessionConfig();
214         if (config == nullptr) {
215             return nullptr;
216         }
217         config->isSystemDecorEnable_ = parcel.ReadBool();
218         config->isStretchable_ = parcel.ReadBool();
219         config->decorModeSupportInfo_ = parcel.ReadUint32();
220         config->defaultWindowMode_ = static_cast<WindowMode>(parcel.ReadUint32());
221         sptr<KeyboardAnimationConfig> keyboardConfig = parcel.ReadParcelable<KeyboardAnimationConfig>();
222         config->keyboardAnimationConfig_ = *keyboardConfig;
223         config->maxFloatingWindowSize_ = parcel.ReadUint32();
224         config->miniWidthOfMainWindow_ = parcel.ReadUint32();
225         config->miniHeightOfMainWindow_ = parcel.ReadUint32();
226         config->miniWidthOfSubWindow_ = parcel.ReadUint32();
227         config->miniHeightOfSubWindow_ = parcel.ReadUint32();
228         return config;
229     }
230 };
231 } // namespace Rosen
232 } // namespace OHOS
233 #endif // OHOS_ROSEN_WINDOW_PROPERTY_H
234