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_WM_COMMON_INNER_H
17 #define OHOS_ROSEN_WM_COMMON_INNER_H
18 
19 #include <cfloat>
20 #include <cinttypes>
21 #include <unordered_set>
22 #include "wm_common.h"
23 
24 namespace OHOS {
25 namespace Rosen {
26 class KeyboardAnimationCurve;
27 
28 enum class LifeCycleEvent : uint32_t {
29     CREATE_EVENT,
30     SHOW_EVENT,
31     HIDE_EVENT,
32     DESTROY_EVENT,
33 };
34 
35 enum class WindowStateChangeReason : uint32_t {
36     NORMAL,
37     KEYGUARD,
38     TOGGLING,
39 };
40 
41 enum class WindowUpdateReason : uint32_t {
42     NEED_SWITCH_CASCADE_BASE,
43     UPDATE_ALL = NEED_SWITCH_CASCADE_BASE,
44     UPDATE_MODE,
45     UPDATE_RECT,
46     UPDATE_FLAGS,
47     UPDATE_TYPE,
48     UPDATE_ASPECT_RATIO,
49     NEED_SWITCH_CASCADE_END,
50     UPDATE_OTHER_PROPS,
51     UPDATE_TRANSFORM,
52 };
53 
54 enum class AvoidPosType : uint32_t {
55     AVOID_POS_LEFT,
56     AVOID_POS_TOP,
57     AVOID_POS_RIGHT,
58     AVOID_POS_BOTTOM,
59     AVOID_POS_UNKNOWN
60 };
61 
62 enum class WindowRootNodeType : uint32_t {
63     APP_WINDOW_NODE,
64     ABOVE_WINDOW_NODE,
65     BELOW_WINDOW_NODE,
66 };
67 
68 enum class PropertyChangeAction : uint32_t {
69     ACTION_UPDATE_RECT = 1,
70     ACTION_UPDATE_MODE = 1 << 1,
71     ACTION_UPDATE_FLAGS = 1 << 2,
72     ACTION_UPDATE_OTHER_PROPS = 1 << 3,
73     ACTION_UPDATE_FOCUSABLE = 1 << 4,
74     ACTION_UPDATE_TOUCHABLE = 1 << 5,
75     ACTION_UPDATE_CALLING_WINDOW = 1 << 6,
76     ACTION_UPDATE_ORIENTATION = 1 << 7,
77     ACTION_UPDATE_TURN_SCREEN_ON = 1 << 8,
78     ACTION_UPDATE_KEEP_SCREEN_ON = 1 << 9,
79     ACTION_UPDATE_SET_BRIGHTNESS = 1 << 10,
80     ACTION_UPDATE_MODE_SUPPORT_INFO = 1 << 11,
81     ACTION_UPDATE_TOUCH_HOT_AREA = 1 << 12,
82     ACTION_UPDATE_TRANSFORM_PROPERTY = 1 << 13,
83     ACTION_UPDATE_ANIMATION_FLAG = 1 << 14,
84     ACTION_UPDATE_PRIVACY_MODE = 1 << 15,
85     ACTION_UPDATE_ASPECT_RATIO = 1 << 16,
86     ACTION_UPDATE_MAXIMIZE_STATE = 1 << 17,
87     ACTION_UPDATE_SYSTEM_PRIVACY_MODE = 1 << 18,
88     ACTION_UPDATE_SNAPSHOT_SKIP = 1 << 19,
89     ACTION_UPDATE_TEXTFIELD_AVOID_INFO = 1 << 20,
90 };
91 
92 struct ModeChangeHotZonesConfig {
93     bool isModeChangeHotZoneConfigured_;
94     uint32_t fullscreenRange_;
95     uint32_t primaryRange_;
96     uint32_t secondaryRange_;
97 };
98 
99 struct SystemConfig : public Parcelable {
100     bool isSystemDecorEnable_ = true;
101     uint32_t decorWindowModeSupportType_ = WindowModeSupport::WINDOW_MODE_SUPPORT_ALL;
102     bool isStretchable_ = false;
103     WindowMode defaultWindowMode_ = WindowMode::WINDOW_MODE_FULLSCREEN;
104     KeyboardAnimationCurve animationIn_;
105     KeyboardAnimationCurve animationOut_;
106     std::string uiType_;
107     bool supportTypeFloatWindow_ = false;
108 
MarshallingSystemConfig109     virtual bool Marshalling(Parcel& parcel) const override
110     {
111         if (!parcel.WriteBool(isSystemDecorEnable_) || !parcel.WriteBool(isStretchable_) ||
112             !parcel.WriteUint32(decorWindowModeSupportType_)) {
113             return false;
114         }
115 
116         if (!parcel.WriteUint32(static_cast<uint32_t>(defaultWindowMode_)) ||
117             !parcel.WriteParcelable(&animationIn_) || !parcel.WriteParcelable(&animationOut_)) {
118             return false;
119         }
120 
121         if (!parcel.WriteString(uiType_)) {
122             return false;
123         }
124 
125         if (!parcel.WriteBool(supportTypeFloatWindow_)) {
126             return false;
127         }
128 
129         return true;
130     }
131 
UnmarshallingSystemConfig132     static SystemConfig* Unmarshalling(Parcel& parcel)
133     {
134         SystemConfig* config = new SystemConfig();
135         config->isSystemDecorEnable_ = parcel.ReadBool();
136         config->isStretchable_ = parcel.ReadBool();
137         config->decorWindowModeSupportType_ = parcel.ReadUint32();
138         config->defaultWindowMode_ = static_cast<WindowMode>(parcel.ReadUint32());
139         sptr<KeyboardAnimationCurve> animationIn = parcel.ReadParcelable<KeyboardAnimationCurve>();
140         if (animationIn == nullptr) {
141             delete config;
142             return nullptr;
143         }
144         config->animationIn_ = *animationIn;
145         sptr<KeyboardAnimationCurve> animationOut = parcel.ReadParcelable<KeyboardAnimationCurve>();
146         if (animationOut == nullptr) {
147             delete config;
148             return nullptr;
149         }
150         config->animationOut_ = *animationOut;
151         config->uiType_ = parcel.ReadString();
152         config->supportTypeFloatWindow_ = parcel.ReadBool();
153         return config;
154     }
155 };
156 
157 struct ModeChangeHotZones {
158     Rect fullscreen_;
159     Rect primary_;
160     Rect secondary_;
161 };
162 
163 struct SplitRatioConfig {
164     // when divider reaches this position, the top/left window will hide. Valid range: (0, 0.5)
165     float exitSplitStartRatio;
166     // when divider reaches this position, the bottom/right window will hide. Valid range: (0.5, 1)
167     float exitSplitEndRatio;
168     std::vector<float> splitRatios;
169 };
170 
171 enum class DragType : uint32_t {
172     DRAG_UNDEFINED,
173     DRAG_LEFT_OR_RIGHT,
174     DRAG_BOTTOM_OR_TOP,
175     DRAG_LEFT_TOP_CORNER,
176     DRAG_RIGHT_TOP_CORNER,
177 };
178 
179 enum class TraceTaskId : int32_t {
180     STARTING_WINDOW = 0,
181     REMOTE_ANIMATION,
182     CONNECT_EXTENSION,
183     REMOTE_ANIMATION_HOME,
184     START_WINDOW_ANIMATION,
185 };
186 
187 enum class PersistentStorageType : uint32_t {
188     UKNOWN = 0,
189     ASPECT_RATIO,
190     MAXIMIZE_STATE,
191 };
192 
193 struct MoveDragProperty : public Parcelable {
194     int32_t startPointPosX_;
195     int32_t startPointPosY_;
196     int32_t startPointerId_;
197     int32_t targetDisplayId_;
198     int32_t sourceType_;
199     bool startDragFlag_;
200     bool startMoveFlag_;
201     bool pointEventStarted_;
202     DragType dragType_;
203     Rect startPointRect_;
204     Rect startRectExceptFrame_;
205     Rect startRectExceptCorner_;
206 
MoveDragPropertyMoveDragProperty207     MoveDragProperty() : startPointPosX_(0), startPointPosY_(0), startPointerId_(0), targetDisplayId_(0),
208         sourceType_(0), startDragFlag_(false), startMoveFlag_(false), pointEventStarted_(false),
209         dragType_(DragType::DRAG_UNDEFINED)
210     {
211         startPointRect_ = {0, 0, 0, 0};
212         startRectExceptFrame_ = {0, 0, 0, 0};
213         startRectExceptCorner_ = {0, 0, 0, 0};
214     }
215 
MoveDragPropertyMoveDragProperty216     MoveDragProperty(int32_t startPointPosX, int32_t startPointPosY, int32_t startPointerId, int32_t targetDisplayId,
217         int32_t sourceType, bool startDragFlag, bool startMoveFlag, bool pointEventStarted, DragType dragType,
218         Rect startPointRect, Rect startRectExceptFrame, Rect startRectExceptCorner)
219         : startPointPosX_(startPointPosX), startPointPosY_(startPointPosY), startPointerId_(startPointerId),
220         targetDisplayId_(targetDisplayId), sourceType_(sourceType), startDragFlag_(startDragFlag),
221         startMoveFlag_(startMoveFlag), pointEventStarted_(pointEventStarted), dragType_(dragType),
222         startPointRect_(startPointRect), startRectExceptFrame_(startRectExceptFrame),
223         startRectExceptCorner_(startRectExceptCorner) {}
224 
MarshallingMoveDragProperty225     virtual bool Marshalling(Parcel& parcel) const override
226     {
227         if (!parcel.WriteInt32(startPointPosX_) || !parcel.WriteInt32(startPointPosY_) ||
228             !parcel.WriteInt32(startPointerId_) || !parcel.WriteInt32(targetDisplayId_) ||
229             !parcel.WriteInt32(sourceType_) || !parcel.WriteBool(startDragFlag_) ||
230             !parcel.WriteBool(startMoveFlag_) || !parcel.WriteBool(pointEventStarted_) ||
231             !parcel.WriteUint32(static_cast<uint32_t>(dragType_))) {
232             return false;
233         }
234 
235         if (!parcel.WriteInt32(startPointRect_.posX_) || !parcel.WriteInt32(startPointRect_.posY_) ||
236             !parcel.WriteUint32(startPointRect_.width_) || !parcel.WriteUint32(startPointRect_.height_)) {
237             return false;
238         }
239 
240         if (!parcel.WriteInt32(startRectExceptFrame_.posX_) || !parcel.WriteInt32(startRectExceptFrame_.posY_) ||
241             !parcel.WriteUint32(startRectExceptFrame_.width_) || !parcel.WriteUint32(startRectExceptFrame_.height_)) {
242             return false;
243         }
244 
245         if (!parcel.WriteInt32(startRectExceptCorner_.posX_) || !parcel.WriteInt32(startRectExceptCorner_.posY_) ||
246             !parcel.WriteUint32(startRectExceptCorner_.width_) || !parcel.WriteUint32(startRectExceptCorner_.height_)) {
247             return false;
248         }
249 
250         return true;
251     }
252 
UnmarshallingMoveDragProperty253     static MoveDragProperty* Unmarshalling(Parcel& parcel)
254     {
255         MoveDragProperty* info = new MoveDragProperty();
256         info->startPointPosX_ = parcel.ReadInt32();
257         info->startPointPosY_ = parcel.ReadInt32();
258         info->startPointerId_ = parcel.ReadInt32();
259         info->targetDisplayId_ = parcel.ReadInt32();
260         info->sourceType_ = parcel.ReadInt32();
261         info->startDragFlag_ = parcel.ReadBool();
262         info->startMoveFlag_ = parcel.ReadBool();
263         info->pointEventStarted_ = parcel.ReadBool();
264         info->dragType_ = static_cast<DragType>(parcel.ReadUint32());
265         Rect startPointRect = { parcel.ReadInt32(), parcel.ReadInt32(),
266                                 parcel.ReadUint32(), parcel.ReadUint32() };
267         Rect startRectExceptFrame = { parcel.ReadInt32(), parcel.ReadInt32(),
268                                       parcel.ReadUint32(), parcel.ReadUint32() };
269         Rect startRectExceptCorner = { parcel.ReadInt32(), parcel.ReadInt32(),
270                                        parcel.ReadUint32(), parcel.ReadUint32() };
271         info->startPointRect_ = startPointRect;
272         info->startRectExceptFrame_ = startRectExceptFrame;
273         info->startRectExceptCorner_ = startRectExceptCorner;
274         return info;
275     }
276 
CopyFromMoveDragProperty277     void CopyFrom(const sptr<MoveDragProperty>& property)
278     {
279         startPointPosX_ = property->startPointPosX_;
280         startPointPosY_ = property->startPointPosY_;
281         startPointerId_ = property->startPointerId_;
282         targetDisplayId_ = property->targetDisplayId_;
283         sourceType_ = property->sourceType_;
284         startDragFlag_ = property->startDragFlag_;
285         startMoveFlag_ = property->startMoveFlag_;
286         pointEventStarted_ = property->pointEventStarted_;
287         dragType_ = property->dragType_;
288         startPointRect_ = property->startPointRect_;
289         startRectExceptFrame_ = property->startRectExceptFrame_;
290         startRectExceptCorner_ = property->startRectExceptCorner_;
291     }
292 };
293 
294 struct AbilityInfo {
295     std::string bundleName_ = "";
296     std::string abilityName_ = "";
297     int32_t missionId_ = -1;
298 };
299 
300 namespace {
301     constexpr float DEFAULT_SPLIT_RATIO = 0.5;
302     constexpr float DEFAULT_ASPECT_RATIO = 0.67;
303     constexpr float DISPLAY_ZOOM_OFF_SCALE = 1.0;
304     constexpr float DISPLAY_ZOOM_MIN_SCALE = 2.0;
305     constexpr float DISPLAY_ZOOM_MAX_SCALE = 8.0;
306     constexpr int32_t IVALID_DIALOG_WINDOW_ID = -1;
307     constexpr uint32_t DIVIDER_WIDTH = 8;
308     constexpr uint32_t WINDOW_TITLE_BAR_HEIGHT = 48;
309     constexpr uint32_t WINDOW_FRAME_WIDTH = 5;
310     constexpr uint32_t WINDOW_FRAME_CORNER_WIDTH = 16; // the frame width of corner
311     constexpr uint32_t HOTZONE_TOUCH = 24;
312     constexpr uint32_t HOTZONE_POINTER = 4;
313     constexpr uint32_t MIN_FLOATING_WIDTH = 320;
314     constexpr uint32_t MIN_FLOATING_HEIGHT = 240;
315     constexpr uint32_t MIN_VERTICAL_SPLIT_HEIGHT = 240;
316     constexpr uint32_t MIN_HORIZONTAL_SPLIT_WIDTH = 320;
317     constexpr unsigned int WMS_WATCHDOG_CHECK_INTERVAL = 6; // actual check interval is 3000ms(6 * 500)
318     const Rect INVALID_EMPTY_RECT = {0, 0, 0, 0};
319     const Rect DEFAULT_PLACE_HOLDER_RECT = {0, 0, 512, 512};
320     constexpr int32_t SNAPSHOT_TIMEOUT_MS = 300;
321     const std::unordered_set<WindowType> INPUT_WINDOW_TYPE_SKIPPED {
322         WindowType::WINDOW_TYPE_POINTER,
323         WindowType::WINDOW_TYPE_DRAGGING_EFFECT,
324     };
325 }
326 }
327 }
328 #endif // OHOS_ROSEN_WM_COMMON_INNER_H