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_H
17 #define OHOS_ROSEN_WM_COMMON_H
18 
19 #include <parcel.h>
20 #include <map>
21 #include <float.h>
22 #include <sstream>
23 #include <string>
24 
25 namespace OHOS {
26 namespace Rosen {
27 using DisplayId = uint64_t;
28 /**
29  * @brief Enumerates type of window.
30  */
31 enum class WindowType : uint32_t {
32     APP_WINDOW_BASE = 1,
33     APP_MAIN_WINDOW_BASE = APP_WINDOW_BASE,
34     WINDOW_TYPE_APP_MAIN_WINDOW = APP_MAIN_WINDOW_BASE,
35     APP_MAIN_WINDOW_END,
36 
37     APP_SUB_WINDOW_BASE = 1000,
38     WINDOW_TYPE_MEDIA = APP_SUB_WINDOW_BASE,
39     WINDOW_TYPE_APP_SUB_WINDOW,
40     WINDOW_TYPE_APP_COMPONENT,
41     APP_SUB_WINDOW_END,
42     APP_WINDOW_END = APP_SUB_WINDOW_END,
43 
44     SYSTEM_WINDOW_BASE = 2000,
45     BELOW_APP_SYSTEM_WINDOW_BASE = SYSTEM_WINDOW_BASE,
46     WINDOW_TYPE_WALLPAPER = SYSTEM_WINDOW_BASE,
47     WINDOW_TYPE_DESKTOP,
48     BELOW_APP_SYSTEM_WINDOW_END,
49 
50     ABOVE_APP_SYSTEM_WINDOW_BASE = 2100,
51     WINDOW_TYPE_APP_LAUNCHING = ABOVE_APP_SYSTEM_WINDOW_BASE,
52     WINDOW_TYPE_DOCK_SLICE,
53     WINDOW_TYPE_INCOMING_CALL,
54     WINDOW_TYPE_SEARCHING_BAR,
55     WINDOW_TYPE_SYSTEM_ALARM_WINDOW,
56     WINDOW_TYPE_INPUT_METHOD_FLOAT,
57     WINDOW_TYPE_FLOAT,
58     WINDOW_TYPE_TOAST,
59     WINDOW_TYPE_STATUS_BAR,
60     WINDOW_TYPE_PANEL,
61     WINDOW_TYPE_KEYGUARD,
62     WINDOW_TYPE_VOLUME_OVERLAY,
63     WINDOW_TYPE_NAVIGATION_BAR,
64     WINDOW_TYPE_DRAGGING_EFFECT,
65     WINDOW_TYPE_POINTER,
66     WINDOW_TYPE_LAUNCHER_RECENT,
67     WINDOW_TYPE_LAUNCHER_DOCK,
68     WINDOW_TYPE_BOOT_ANIMATION,
69     WINDOW_TYPE_FREEZE_DISPLAY,
70     WINDOW_TYPE_VOICE_INTERACTION,
71     WINDOW_TYPE_FLOAT_CAMERA,
72     WINDOW_TYPE_PLACEHOLDER,
73     WINDOW_TYPE_DIALOG,
74     WINDOW_TYPE_SCREENSHOT,
75     WINDOW_TYPE_INPUT_METHOD_STATUS_BAR,
76     WINDOW_TYPE_GLOBAL_SEARCH,
77     WINDOW_TYPE_NEGATIVE_SCREEN,
78     WINDOW_TYPE_SYSTEM_TOAST,
79     WINDOW_TYPE_SYSTEM_FLOAT,
80     WINDOW_TYPE_PIP,
81     WINDOW_TYPE_THEME_EDITOR,
82     WINDOW_TYPE_NAVIGATION_INDICATOR,
83     WINDOW_TYPE_HANDWRITE,
84     WINDOW_TYPE_SCENE_BOARD,
85     WINDOW_TYPE_KEYBOARD_PANEL,
86     WINDOW_TYPE_SCB_DEFAULT,
87     WINDOW_TYPE_TRANSPARENT_VIEW,
88     ABOVE_APP_SYSTEM_WINDOW_END,
89 
90     SYSTEM_SUB_WINDOW_BASE = 2500,
91     WINDOW_TYPE_SYSTEM_SUB_WINDOW = SYSTEM_SUB_WINDOW_BASE,
92     SYSTEM_SUB_WINDOW_END,
93 
94     SYSTEM_WINDOW_END = SYSTEM_SUB_WINDOW_END,
95 
96     WINDOW_TYPE_UI_EXTENSION = 3000
97 };
98 
99 /**
100  * @struct HookInfo.
101  *
102  * @brief hook diaplayinfo deepending on the window size.
103  */
104 struct HookInfo {
105     uint32_t width_;
106     uint32_t height_;
107     float_t density_;
108     uint32_t rotation_;
109     bool enableHookRotation_;
110 };
111 
112 /**
113  * @brief Enumerates mode of window.
114  */
115 enum class WindowMode : uint32_t {
116     WINDOW_MODE_UNDEFINED = 0,
117     WINDOW_MODE_FULLSCREEN = 1,
118     WINDOW_MODE_SPLIT_PRIMARY = 100,
119     WINDOW_MODE_SPLIT_SECONDARY,
120     WINDOW_MODE_FLOATING,
121     WINDOW_MODE_PIP
122 };
123 
124 /**
125  * @brief Enumerates modeType of window.
126  */
127 enum class WindowModeType : uint8_t {
128     WINDOW_MODE_SPLIT_FLOATING = 0,
129     WINDOW_MODE_SPLIT = 1,
130     WINDOW_MODE_FLOATING = 2,
131     WINDOW_MODE_FULLSCREEN = 3,
132     WINDOW_MODE_FULLSCREEN_FLOATING = 4,
133     WINDOW_MODE_OTHER = 5
134 };
135 
136 /**
137  * @brief Enumerates modal of sub session.
138  */
139 enum class SubWindowModalType : uint32_t {
140     BEGIN = 0,
141     TYPE_UNDEFINED = BEGIN,
142     TYPE_NORMAL,
143     TYPE_DIALOG,
144     TYPE_WINDOW_MODALITY,
145     TYPE_TOAST,
146     TYPE_APPLICATION_MODALITY,
147     END = TYPE_APPLICATION_MODALITY,
148 };
149 
150 /**
151  * @brief Enumerates mode supported of window.
152  */
153 enum WindowModeSupport : uint32_t {
154     WINDOW_MODE_SUPPORT_FULLSCREEN = 1 << 0,
155     WINDOW_MODE_SUPPORT_FLOATING = 1 << 1,
156     WINDOW_MODE_SUPPORT_SPLIT_PRIMARY = 1 << 2,
157     WINDOW_MODE_SUPPORT_SPLIT_SECONDARY = 1 << 3,
158     WINDOW_MODE_SUPPORT_PIP = 1 << 4,
159     WINDOW_MODE_SUPPORT_ALL = WINDOW_MODE_SUPPORT_FULLSCREEN |
160                               WINDOW_MODE_SUPPORT_SPLIT_PRIMARY |
161                               WINDOW_MODE_SUPPORT_SPLIT_SECONDARY |
162                               WINDOW_MODE_SUPPORT_FLOATING |
163                               WINDOW_MODE_SUPPORT_PIP
164 };
165 
166 /**
167  * @brief Enumerates blur style of window.
168  */
169 enum class WindowBlurStyle : uint32_t {
170     WINDOW_BLUR_OFF = 0,
171     WINDOW_BLUR_THIN,
172     WINDOW_BLUR_REGULAR,
173     WINDOW_BLUR_THICK
174 };
175 
176 /**
177  * @brief Enumerates state of window.
178  */
179 enum class WindowState : uint32_t {
180     STATE_INITIAL,
181     STATE_CREATED,
182     STATE_SHOWN,
183     STATE_HIDDEN,
184     STATE_FROZEN,
185     STATE_UNFROZEN,
186     STATE_DESTROYED,
187     STATE_BOTTOM = STATE_DESTROYED, // Add state type after STATE_DESTROYED is not allowed
188 };
189 
190 /**
191  * @brief Enumerates error code of window.
192  */
193 enum class WMError : int32_t {
194     WM_OK = 0,
195     WM_DO_NOTHING,
196     WM_ERROR_NO_MEM,
197     WM_ERROR_DESTROYED_OBJECT,
198     WM_ERROR_INVALID_WINDOW,
199     WM_ERROR_INVALID_WINDOW_MODE_OR_SIZE,
200     WM_ERROR_INVALID_OPERATION,
201     WM_ERROR_INVALID_PERMISSION,
202     WM_ERROR_NOT_SYSTEM_APP,
203     WM_ERROR_NO_REMOTE_ANIMATION,
204     WM_ERROR_INVALID_DISPLAY,
205     WM_ERROR_INVALID_PARENT,
206     WM_ERROR_INVALID_OP_IN_CUR_STATUS,
207     WM_ERROR_REPEAT_OPERATION,
208     WM_ERROR_INVALID_SESSION,
209     WM_ERROR_INVALID_CALLING,
210     WM_ERROR_SYSTEM_ABNORMALLY,
211 
212     WM_ERROR_DEVICE_NOT_SUPPORT = 801, // the value do not change.It is defined on all system
213 
214     WM_ERROR_NEED_REPORT_BASE = 1000, // error code > 1000 means need report
215     WM_ERROR_NULLPTR,
216     WM_ERROR_INVALID_TYPE,
217     WM_ERROR_INVALID_PARAM,
218     WM_ERROR_SAMGR,
219     WM_ERROR_IPC_FAILED,
220     WM_ERROR_NEED_REPORT_END,
221     WM_ERROR_START_ABILITY_FAILED,
222     WM_ERROR_PIP_DESTROY_FAILED,
223     WM_ERROR_PIP_STATE_ABNORMALLY,
224     WM_ERROR_PIP_CREATE_FAILED,
225     WM_ERROR_PIP_INTERNAL_ERROR,
226     WM_ERROR_PIP_REPEAT_OPERATION,
227 };
228 
229 /**
230  * @brief Enumerates error code of window only used for js api.
231  */
232 enum class WmErrorCode : int32_t {
233     WM_OK = 0,
234     WM_ERROR_NO_PERMISSION = 201,
235     WM_ERROR_NOT_SYSTEM_APP = 202,
236     WM_ERROR_INVALID_PARAM = 401,
237     WM_ERROR_DEVICE_NOT_SUPPORT = 801,
238     WM_ERROR_REPEAT_OPERATION = 1300001,
239     WM_ERROR_STATE_ABNORMALLY = 1300002,
240     WM_ERROR_SYSTEM_ABNORMALLY = 1300003,
241     WM_ERROR_INVALID_CALLING = 1300004,
242     WM_ERROR_STAGE_ABNORMALLY = 1300005,
243     WM_ERROR_CONTEXT_ABNORMALLY = 1300006,
244     WM_ERROR_START_ABILITY_FAILED = 1300007,
245     WM_ERROR_INVALID_DISPLAY = 1300008,
246     WM_ERROR_INVALID_PARENT = 1300009,
247     WM_ERROR_INVALID_OP_IN_CUR_STATUS = 1300010,
248     WM_ERROR_PIP_DESTROY_FAILED = 1300011,
249     WM_ERROR_PIP_STATE_ABNORMALLY = 1300012,
250     WM_ERROR_PIP_CREATE_FAILED = 1300013,
251     WM_ERROR_PIP_INTERNAL_ERROR = 1300014,
252     WM_ERROR_PIP_REPEAT_OPERATION = 1300015,
253 };
254 
255 /**
256  * @brief Enumerates status of window.
257  */
258 enum class WindowStatus : uint32_t {
259     WINDOW_STATUS_UNDEFINED = 0,
260     WINDOW_STATUS_FULLSCREEN = 1,
261     WINDOW_STATUS_MAXIMIZE,
262     WINDOW_STATUS_MINIMIZE,
263     WINDOW_STATUS_FLOATING,
264     WINDOW_STATUS_SPLITSCREEN
265 };
266 
267 /**
268  * @brief Enumerates setting flag of systemStatusBar
269  */
270 enum class SystemBarSettingFlag : uint32_t {
271     DEFAULT_SETTING = 0,
272     COLOR_SETTING = 1,
273     ENABLE_SETTING = 1 << 1,
274     ALL_SETTING = COLOR_SETTING | ENABLE_SETTING,
275     FOLLOW_SETTING = 1 << 2
276 };
277 
278 /**
279  * @brief Enumerates flag of ControlAppType.
280  */
281 enum class ControlAppType : uint8_t {
282     CONTROL_APP_TYPE_BEGIN = 0,
283     APP_LOCK = 1,
284     CONTROL_APP_TYPE_END,
285 };
286 
287 /**
288  * @brief Used to map from WMError to WmErrorCode.
289  */
290 const std::map<WMError, WmErrorCode> WM_JS_TO_ERROR_CODE_MAP {
291     {WMError::WM_OK,                                   WmErrorCode::WM_OK                             },
292     {WMError::WM_DO_NOTHING,                           WmErrorCode::WM_ERROR_STATE_ABNORMALLY         },
293     {WMError::WM_ERROR_DESTROYED_OBJECT,               WmErrorCode::WM_ERROR_STATE_ABNORMALLY         },
294     {WMError::WM_ERROR_DEVICE_NOT_SUPPORT,             WmErrorCode::WM_ERROR_DEVICE_NOT_SUPPORT       },
295     {WMError::WM_ERROR_INVALID_OPERATION,              WmErrorCode::WM_ERROR_STATE_ABNORMALLY         },
296     {WMError::WM_ERROR_INVALID_PARAM,                  WmErrorCode::WM_ERROR_INVALID_PARAM            },
297     {WMError::WM_ERROR_INVALID_PERMISSION,             WmErrorCode::WM_ERROR_NO_PERMISSION            },
298     {WMError::WM_ERROR_NOT_SYSTEM_APP,                 WmErrorCode::WM_ERROR_NOT_SYSTEM_APP           },
299     {WMError::WM_ERROR_INVALID_TYPE,                   WmErrorCode::WM_ERROR_STATE_ABNORMALLY         },
300     {WMError::WM_ERROR_INVALID_WINDOW,                 WmErrorCode::WM_ERROR_STATE_ABNORMALLY         },
301     {WMError::WM_ERROR_INVALID_WINDOW_MODE_OR_SIZE,    WmErrorCode::WM_ERROR_STATE_ABNORMALLY         },
302     {WMError::WM_ERROR_IPC_FAILED,                     WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY        },
303     {WMError::WM_ERROR_NO_MEM,                         WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY        },
304     {WMError::WM_ERROR_NO_REMOTE_ANIMATION,            WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY        },
305     {WMError::WM_ERROR_INVALID_DISPLAY,                WmErrorCode::WM_ERROR_INVALID_DISPLAY          },
306     {WMError::WM_ERROR_INVALID_PARENT,                 WmErrorCode::WM_ERROR_INVALID_PARENT           },
307     {WMError::WM_ERROR_INVALID_OP_IN_CUR_STATUS,       WmErrorCode::WM_ERROR_INVALID_OP_IN_CUR_STATUS },
308     {WMError::WM_ERROR_REPEAT_OPERATION,               WmErrorCode::WM_ERROR_REPEAT_OPERATION         },
309     {WMError::WM_ERROR_NULLPTR,                        WmErrorCode::WM_ERROR_STATE_ABNORMALLY         },
310     {WMError::WM_ERROR_SAMGR,                          WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY        },
311     {WMError::WM_ERROR_START_ABILITY_FAILED,           WmErrorCode::WM_ERROR_START_ABILITY_FAILED     },
312     {WMError::WM_ERROR_PIP_DESTROY_FAILED,             WmErrorCode::WM_ERROR_PIP_DESTROY_FAILED       },
313     {WMError::WM_ERROR_PIP_STATE_ABNORMALLY,           WmErrorCode::WM_ERROR_PIP_STATE_ABNORMALLY     },
314     {WMError::WM_ERROR_PIP_CREATE_FAILED,              WmErrorCode::WM_ERROR_PIP_CREATE_FAILED        },
315     {WMError::WM_ERROR_PIP_INTERNAL_ERROR,             WmErrorCode::WM_ERROR_PIP_INTERNAL_ERROR       },
316     {WMError::WM_ERROR_PIP_REPEAT_OPERATION,           WmErrorCode::WM_ERROR_PIP_REPEAT_OPERATION     },
317     {WMError::WM_ERROR_INVALID_CALLING,                WmErrorCode::WM_ERROR_INVALID_CALLING          },
318     {WMError::WM_ERROR_INVALID_SESSION,                WmErrorCode::WM_ERROR_STATE_ABNORMALLY         },
319     {WMError::WM_ERROR_SYSTEM_ABNORMALLY,              WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY        },
320 };
321 
322 /**
323  * @brief Enumerates flag of window.
324  */
325 enum class WindowFlag : uint32_t {
326     WINDOW_FLAG_NEED_AVOID = 1,
327     WINDOW_FLAG_PARENT_LIMIT = 1 << 1,
328     WINDOW_FLAG_SHOW_WHEN_LOCKED = 1 << 2,
329     WINDOW_FLAG_FORBID_SPLIT_MOVE = 1 << 3,
330     WINDOW_FLAG_WATER_MARK = 1 << 4,
331     WINDOW_FLAG_IS_MODAL = 1 << 5,
332     WINDOW_FLAG_HANDWRITING = 1 << 6,
333     WINDOW_FLAG_IS_TOAST = 1 << 7,
334     WINDOW_FLAG_IS_APPLICATION_MODAL = 1 << 8,
335     WINDOW_FLAG_END = 1 << 9,
336 };
337 
338 /**
339  * @brief Flag of uiextension window.
340  */
341 union ExtensionWindowFlags {
342     uint32_t bitData;
343     struct {
344         // Each flag should be false default, true when active
345         bool hideNonSecureWindowsFlag : 1;
346         bool waterMarkFlag : 1;
347         bool privacyModeFlag : 1;
348     };
ExtensionWindowFlags()349     ExtensionWindowFlags() : bitData(0) {}
ExtensionWindowFlags(uint32_t bits)350     ExtensionWindowFlags(uint32_t bits) : bitData(bits) {}
~ExtensionWindowFlags()351     ~ExtensionWindowFlags() {}
SetAllActive()352     void SetAllActive()
353     {
354         hideNonSecureWindowsFlag = true;
355         waterMarkFlag = true;
356         privacyModeFlag = true;
357     }
358 };
359 
360 /**
361  * @brief Enumerates window size change reason.
362  */
363 enum class WindowSizeChangeReason : uint32_t {
364     UNDEFINED = 0,
365     MAXIMIZE,
366     RECOVER,
367     ROTATION,
368     DRAG,
369     DRAG_START,
370     DRAG_END,
371     RESIZE,
372     MOVE,
373     HIDE,
374     TRANSFORM,
375     CUSTOM_ANIMATION_SHOW,
376     FULL_TO_SPLIT,
377     SPLIT_TO_FULL,
378     FULL_TO_FLOATING,
379     FLOATING_TO_FULL,
380     PIP_START,
381     PIP_SHOW,
382     PIP_AUTO_START,
383     PIP_RATIO_CHANGE,
384     PIP_RESTORE,
385     UPDATE_DPI_SYNC,
386     DRAG_MOVE,
387     END,
388 };
389 
IsMoveToOrDragMove(WindowSizeChangeReason reason)390 inline bool IsMoveToOrDragMove(WindowSizeChangeReason reason)
391 {
392     return reason == WindowSizeChangeReason::MOVE || reason == WindowSizeChangeReason::DRAG_MOVE;
393 }
394 
395 /**
396  * @brief Enumerates layout mode of window.
397  */
398 enum class WindowLayoutMode : uint32_t {
399     BASE = 0,
400     CASCADE = BASE,
401     TILE = 1,
402     END,
403 };
404 
405 /**
406  * @brief Enumerates drag event.
407  */
408 enum class DragEvent : uint32_t {
409     DRAG_EVENT_IN  = 1,
410     DRAG_EVENT_OUT,
411     DRAG_EVENT_MOVE,
412     DRAG_EVENT_END,
413 };
414 
415 /**
416  * @brief Enumerates drag resize type.
417  */
418 enum class DragResizeType : uint32_t {
419     RESIZE_TYPE_UNDEFINED = 0,
420     RESIZE_EACH_FRAME = 1,
421     RESIZE_WHEN_DRAG_END = 2,
422 };
423 
424 /**
425  * @brief Enumerates window tag.
426  */
427 enum class WindowTag : uint32_t {
428     MAIN_WINDOW = 0,
429     SUB_WINDOW = 1,
430     SYSTEM_WINDOW = 2,
431 };
432 
433 /**
434  * @brief Enumerates window session type.
435  */
436 enum class WindowSessionType : uint32_t {
437     SCENE_SESSION = 0,
438     EXTENSION_SESSION = 1,
439 };
440 
441 /**
442  * @brief Enumerates window gravity.
443  */
444 enum class WindowGravity : uint32_t {
445     WINDOW_GRAVITY_FLOAT = 0,
446     WINDOW_GRAVITY_BOTTOM,
447     WINDOW_GRAVITY_DEFAULT,
448 };
449 
450 /**
451  * @brief Enumerates window setuicontent type.
452  */
453 enum class WindowSetUIContentType: uint32_t {
454     DEFAULT,
455     RESTORE,
456     BY_NAME,
457     BY_ABC,
458 };
459 
460 /**
461  * @brief Enumerates restore type.
462  */
463 enum class BackupAndRestoreType : int32_t {
464     NONE = 0,                       // no backup and restore
465     CONTINUATION = 1,               // distribute
466     APP_RECOVERY = 2,               // app recovery
467     RESOURCESCHEDULE_RECOVERY = 3,  // app is killed due to resource schedule
468 };
469 
470 /**
471  * @brief Enumerates window Style type.
472  */
473 enum class WindowStyleType : uint8_t {
474     WINDOW_STYLE_DEFAULT = 0,
475     WINDOW_STYLE_FREE_MULTI_WINDOW = 1,
476 };
477 
478 /**
479  * @brief Disable Gesture Back Type
480  */
481 enum class GestureBackType : uint8_t {
482     GESTURE_SIDE = 0,
483     GESTURE_SWIPE_UP = 1,
484     GESTURE_ALL = 2,
485 };
486 
487 /**
488  * @struct PointInfo.
489  *
490  * @brief point Info.
491  */
492 struct PointInfo {
493     int32_t x;
494     int32_t y;
495 };
496 
497 /**
498  * @struct MainWindowInfo.
499  *
500  * @brief topN main window info.
501  */
502 struct MainWindowInfo : public Parcelable {
MarshallingMainWindowInfo503     virtual bool Marshalling(Parcel& parcel) const override
504     {
505         if (!parcel.WriteInt32(pid_)) {
506             return false;
507         }
508 
509         if (!parcel.WriteString(bundleName_)) {
510             return false;
511         }
512 
513         if (!parcel.WriteInt32(persistentId_)) {
514             return false;
515         }
516 
517         if (!parcel.WriteInt32(bundleType_)) {
518             return false;
519         }
520         return true;
521     }
522 
UnmarshallingMainWindowInfo523     static MainWindowInfo* Unmarshalling(Parcel& parcel)
524     {
525         MainWindowInfo* mainWindowInfo = new MainWindowInfo;
526         mainWindowInfo->pid_ = parcel.ReadInt32();
527         mainWindowInfo->bundleName_ = parcel.ReadString();
528         mainWindowInfo->persistentId_ = parcel.ReadInt32();
529         mainWindowInfo->bundleType_ = parcel.ReadInt32();
530         return mainWindowInfo;
531     }
532 
533     int32_t pid_ = 0;
534     std::string bundleName_ = "";
535     int32_t persistentId_ = 0;
536     int32_t bundleType_ = 0;
537 };
538 
539 /**
540  * @struct MainWindowState.
541  *
542  * @brief Main window state info.
543  */
544 struct MainWindowState : public Parcelable {
MarshallingMainWindowState545     bool Marshalling(Parcel& parcel) const override
546     {
547         if (!parcel.WriteInt32(state_)) {
548             return false;
549         }
550         if (!parcel.WriteBool(isVisible_)) {
551             return false;
552         }
553         if (!parcel.WriteBool(isForegroundInteractive_)) {
554             return false;
555         }
556         if (!parcel.WriteBool(isPcOrPadEnableActivation_)) {
557             return false;
558         }
559         return true;
560     }
561 
UnmarshallingMainWindowState562     static MainWindowState* Unmarshalling(Parcel& parcel)
563     {
564         MainWindowState* mainWindowState = new MainWindowState();
565         if (!mainWindowState) {
566             return nullptr;
567         }
568         if (!parcel.ReadInt32(mainWindowState->state_) ||
569             !parcel.ReadBool(mainWindowState->isVisible_) ||
570             !parcel.ReadBool(mainWindowState->isForegroundInteractive_) ||
571             !parcel.ReadBool(mainWindowState->isPcOrPadEnableActivation_)) {
572             delete mainWindowState;
573             return nullptr;
574         }
575         return mainWindowState;
576     }
577 
578     int32_t state_ = 0;
579     bool isVisible_ = false;
580     bool isForegroundInteractive_ = false;
581     bool isPcOrPadEnableActivation_ = false;
582 };
583 
584 namespace {
585     constexpr uint32_t SYSTEM_COLOR_WHITE = 0xE5FFFFFF;
586     constexpr uint32_t SYSTEM_COLOR_BLACK = 0x66000000;
587     constexpr uint32_t INVALID_WINDOW_ID = 0;
588     constexpr float UNDEFINED_BRIGHTNESS = -1.0f;
589     constexpr float MINIMUM_BRIGHTNESS = 0.0f;
590     constexpr float MAXIMUM_BRIGHTNESS = 1.0f;
591     constexpr int32_t INVALID_PID = -1;
592     constexpr int32_t INVALID_UID = -1;
593     constexpr int32_t INVALID_USER_ID = -1;
594     constexpr int32_t SYSTEM_USERID = 0;
595     constexpr int32_t BASE_USER_RANGE = 200000;
596     constexpr int32_t DEFAULT_SCREEN_ID = 0;
597 }
598 
GetUserIdByUid(int32_t uid)599 inline int32_t GetUserIdByUid(int32_t uid)
600 {
601     return uid / BASE_USER_RANGE;
602 }
603 
604 /**
605  * @class Transform
606  *
607  * @brief parameter of transform and rotate.
608  */
609 class Transform {
610 public:
Transform()611     Transform()
612         : pivotX_(0.5f), pivotY_(0.5f), scaleX_(1.f), scaleY_(1.f), scaleZ_(1.f), rotationX_(0.f),
613           rotationY_(0.f), rotationZ_(0.f), translateX_(0.f), translateY_(0.f), translateZ_(0.f)
614     {}
~Transform()615     ~Transform() {}
616 
617     bool operator==(const Transform& right) const
618     {
619         return NearZero(pivotX_ - right.pivotX_) &&
620             NearZero(pivotY_ - right.pivotY_) &&
621             NearZero(scaleX_ - right.scaleX_) &&
622             NearZero(scaleY_ - right.scaleY_) &&
623             NearZero(scaleZ_ - right.scaleZ_) &&
624             NearZero(rotationX_ - right.rotationX_) &&
625             NearZero(rotationY_ - right.rotationY_) &&
626             NearZero(rotationZ_ - right.rotationZ_) &&
627             NearZero(translateX_ - right.translateX_) &&
628             NearZero(translateY_ - right.translateY_) &&
629             NearZero(translateZ_ - right.translateZ_);
630     }
631 
632     bool operator!=(const Transform& right) const
633     {
634         return !(*this == right);
635     }
636 
637     float pivotX_;
638     float pivotY_;
639     float scaleX_;
640     float scaleY_;
641     float scaleZ_;
642     float rotationX_;
643     float rotationY_;
644     float rotationZ_;
645     float translateX_;
646     float translateY_;
647     float translateZ_;
648 
Identity()649     static const Transform& Identity()
650     {
651         static Transform I;
652         return I;
653     }
654 
Marshalling(Parcel & parcel)655     bool Marshalling(Parcel& parcel) const
656     {
657         return parcel.WriteFloat(pivotX_) && parcel.WriteFloat(pivotY_) &&
658                parcel.WriteFloat(scaleX_) && parcel.WriteFloat(scaleY_) && parcel.WriteFloat(scaleZ_) &&
659                parcel.WriteFloat(rotationX_) && parcel.WriteFloat(rotationY_) && parcel.WriteFloat(rotationZ_) &&
660                parcel.WriteFloat(translateX_) && parcel.WriteFloat(translateY_) && parcel.WriteFloat(translateZ_);
661     }
662 
Unmarshalling(Parcel & parcel)663     void Unmarshalling(Parcel& parcel)
664     {
665         pivotX_ = parcel.ReadFloat();
666         pivotY_ = parcel.ReadFloat();
667         scaleX_ = parcel.ReadFloat();
668         scaleY_ = parcel.ReadFloat();
669         scaleZ_ = parcel.ReadFloat();
670         rotationX_ = parcel.ReadFloat();
671         rotationY_ = parcel.ReadFloat();
672         rotationZ_ = parcel.ReadFloat();
673         translateX_ = parcel.ReadFloat();
674         translateY_ = parcel.ReadFloat();
675         translateZ_ = parcel.ReadFloat();
676     }
677 private:
NearZero(float val)678     static inline bool NearZero(float val)
679     {
680         return val < 0.001f && val > -0.001f;
681     }
682 };
683 
684 /**
685  * @struct SystemBarProperty
686  *
687  * @brief Property of system bar
688  */
689 struct SystemBarProperty {
690     bool enable_;
691     uint32_t backgroundColor_;
692     uint32_t contentColor_;
693     bool enableAnimation_;
694     SystemBarSettingFlag settingFlag_;
SystemBarPropertySystemBarProperty695     SystemBarProperty() : enable_(true), backgroundColor_(SYSTEM_COLOR_BLACK), contentColor_(SYSTEM_COLOR_WHITE),
696                           enableAnimation_(false), settingFlag_(SystemBarSettingFlag::DEFAULT_SETTING) {}
SystemBarPropertySystemBarProperty697     SystemBarProperty(bool enable, uint32_t background, uint32_t content)
698         : enable_(enable), backgroundColor_(background), contentColor_(content), enableAnimation_(false),
699           settingFlag_(SystemBarSettingFlag::DEFAULT_SETTING) {}
SystemBarPropertySystemBarProperty700     SystemBarProperty(bool enable, uint32_t background, uint32_t content, bool enableAnimation)
701         : enable_(enable), backgroundColor_(background), contentColor_(content), enableAnimation_(enableAnimation),
702           settingFlag_(SystemBarSettingFlag::DEFAULT_SETTING) {}
SystemBarPropertySystemBarProperty703     SystemBarProperty(bool enable, uint32_t background, uint32_t content,
704                       bool enableAnimation, SystemBarSettingFlag settingFlag)
705         : enable_(enable), backgroundColor_(background), contentColor_(content), enableAnimation_(enableAnimation),
706           settingFlag_(settingFlag) {}
707     bool operator == (const SystemBarProperty& a) const
708     {
709         return (enable_ == a.enable_ && backgroundColor_ == a.backgroundColor_ && contentColor_ == a.contentColor_ &&
710             enableAnimation_ == a.enableAnimation_);
711     }
712 };
713 
714 /**
715  * @struct SystemBarPropertyFlag
716  *
717  * @brief Flag of system bar
718  */
719 struct SystemBarPropertyFlag {
720     bool enableFlag = false;
721     bool backgroundColorFlag = false;
722     bool contentColorFlag = false;
723     bool enableAnimationFlag = false;
724 };
725 
726 /**
727  * @struct Rect
728  *
729  * @brief Window Rect
730  */
731 struct Rect {
732     int32_t posX_;
733     int32_t posY_;
734     uint32_t width_;
735     uint32_t height_;
736 
737     bool operator==(const Rect& a) const
738     {
739         return (posX_ == a.posX_ && posY_ == a.posY_ && width_ == a.width_ && height_ == a.height_);
740     }
741 
742     bool operator!=(const Rect& a) const
743     {
744         return !this->operator==(a);
745     }
746 
IsUninitializedRectRect747     bool IsUninitializedRect() const
748     {
749         return (posX_ == 0 && posY_ == 0 && width_ == 0 && height_ == 0);
750     }
751 
IsUninitializedSizeRect752     bool IsUninitializedSize() const
753     {
754         return width_ == 0 && height_ == 0;
755     }
756 
IsInsideOfRect757     bool IsInsideOf(const Rect& a) const
758     {
759         return (posX_ >= a.posX_ && posY_ >= a.posY_ &&
760             posX_ + width_ <= a.posX_ + a.width_ && posY_ + height_ <= a.posY_ + a.height_);
761     }
762 
ToStringRect763     inline std::string ToString() const
764     {
765         std::stringstream ss;
766         ss << "[" << posX_ << " " << posY_ << " " << width_ << " " << height_ << "]";
767         return ss.str();
768     }
769 };
770 
771 /**
772  * @brief UIExtension usage
773  */
774 enum class UIExtensionUsage : uint32_t {
775     MODAL = 0,
776     EMBEDDED,
777     CONSTRAINED_EMBEDDED,
778     UIEXTENSION_USAGE_END
779 };
780 
781 /**
782  * @brief UIExtension info for event
783  */
784 struct ExtensionWindowEventInfo {
785     int32_t persistentId = 0;
786     int32_t pid = -1;
787     Rect windowRect { 0, 0, 0, 0 }; // Calculated from global rect and UIExtension windowRect
788     Rect uiExtRect { 0, 0, 0, 0 };  // Transferred from arkUI
789     bool hasUpdatedRect = false;
790 };
791 
792 /**
793  * @brief UIExtension info from ability
794  */
795 struct ExtensionWindowAbilityInfo {
796     int32_t persistentId  { 0 };
797     int32_t parentId { 0 };
798     UIExtensionUsage usage { UIExtensionUsage::UIEXTENSION_USAGE_END };
799 };
800 
801 /**
802  * @struct KeyboardPanelInfo
803  *
804  * @brief Info of keyboard panel
805  */
806 struct KeyboardPanelInfo : public Parcelable {
807     Rect rect_ = {0, 0, 0, 0};
808     WindowGravity gravity_ = WindowGravity::WINDOW_GRAVITY_BOTTOM;
809     bool isShowing_ = false;
810 
MarshallingKeyboardPanelInfo811     bool Marshalling(Parcel& parcel) const
812     {
813         return parcel.WriteInt32(rect_.posX_) && parcel.WriteInt32(rect_.posY_) &&
814                parcel.WriteUint32(rect_.width_) && parcel.WriteUint32(rect_.height_) &&
815                parcel.WriteUint32(static_cast<uint32_t>(gravity_)) &&
816                parcel.WriteBool(isShowing_);
817     }
818 
UnmarshallingKeyboardPanelInfo819     static KeyboardPanelInfo* Unmarshalling(Parcel& parcel)
820     {
821         KeyboardPanelInfo* keyboardPanelInfo = new(std::nothrow)KeyboardPanelInfo;
822         if (keyboardPanelInfo == nullptr) {
823             return nullptr;
824         }
825         bool res = parcel.ReadInt32(keyboardPanelInfo->rect_.posX_) &&
826             parcel.ReadInt32(keyboardPanelInfo->rect_.posY_) && parcel.ReadUint32(keyboardPanelInfo->rect_.width_) &&
827             parcel.ReadUint32(keyboardPanelInfo->rect_.height_);
828         if (!res) {
829             delete keyboardPanelInfo;
830             return nullptr;
831         }
832         keyboardPanelInfo->gravity_ = static_cast<WindowGravity>(parcel.ReadUint32());
833         keyboardPanelInfo->isShowing_ = parcel.ReadBool();
834 
835         return keyboardPanelInfo;
836     }
837 };
838 
839 /**
840  * @brief Enumerates avoid area type.
841  */
842 enum class AvoidAreaType : uint32_t {
843     TYPE_SYSTEM,           // area of SystemUI
844     TYPE_CUTOUT,           // cutout of screen
845     TYPE_SYSTEM_GESTURE,   // area for system gesture
846     TYPE_KEYBOARD,         // area for soft input keyboard
847     TYPE_NAVIGATION_INDICATOR, // area for navigation indicator
848 };
849 
850 /**
851  * @brief Enumerates occupied area type.
852  */
853 enum class OccupiedAreaType : uint32_t {
854     TYPE_INPUT, // area of input window
855 };
856 
857 /**
858  * @brief Enumerates color space.
859  */
860 enum class ColorSpace : uint32_t {
861     COLOR_SPACE_DEFAULT = 0, // Default color space.
862     COLOR_SPACE_WIDE_GAMUT,  // Wide gamut color space. The specific wide color gamut depends on the screen.
863 };
864 
865 /**
866  * @brief Enumerates window animation.
867  */
868 enum class WindowAnimation : uint32_t {
869     NONE,
870     DEFAULT,
871     INPUTE,
872     CUSTOM,
873 };
874 
875 /**
876  * @brief Enumerates window maximize mode.
877  */
878 enum class MaximizeMode : uint32_t {
879     MODE_AVOID_SYSTEM_BAR,
880     MODE_FULL_FILL,
881     MODE_RECOVER,
882 };
883 
884 /**
885  * @class AvoidArea
886  *
887  * @brief Area needed to avoid.
888  */
889 class AvoidArea : public Parcelable {
890 public:
891     Rect topRect_ { 0, 0, 0, 0 };
892     Rect leftRect_ { 0, 0, 0, 0 };
893     Rect rightRect_ { 0, 0, 0, 0 };
894     Rect bottomRect_ { 0, 0, 0, 0 };
895 
896     bool operator==(const AvoidArea& a) const
897     {
898         return (leftRect_ == a.leftRect_ && topRect_ == a.topRect_ &&
899             rightRect_ == a.rightRect_ && bottomRect_ == a.bottomRect_);
900     }
901 
902     bool operator!=(const AvoidArea& a) const
903     {
904         return !this->operator==(a);
905     }
906 
isEmptyAvoidArea()907     bool isEmptyAvoidArea() const
908     {
909         return topRect_.IsUninitializedRect() && leftRect_.IsUninitializedRect() &&
910             rightRect_.IsUninitializedRect() && bottomRect_.IsUninitializedRect();
911     }
912 
WriteParcel(Parcel & parcel,const Rect & rect)913     static inline bool WriteParcel(Parcel& parcel, const Rect& rect)
914     {
915         return parcel.WriteInt32(rect.posX_) && parcel.WriteInt32(rect.posY_) &&
916             parcel.WriteUint32(rect.width_) && parcel.WriteUint32(rect.height_);
917     }
918 
ReadParcel(Parcel & parcel,Rect & rect)919     static inline bool ReadParcel(Parcel& parcel, Rect& rect)
920     {
921         return parcel.ReadInt32(rect.posX_) && parcel.ReadInt32(rect.posY_) &&
922             parcel.ReadUint32(rect.width_) && parcel.ReadUint32(rect.height_);
923     }
924 
Marshalling(Parcel & parcel)925     virtual bool Marshalling(Parcel& parcel) const override
926     {
927         return (WriteParcel(parcel, leftRect_) && WriteParcel(parcel, topRect_) &&
928             WriteParcel(parcel, rightRect_) && WriteParcel(parcel, bottomRect_));
929     }
930 
Unmarshalling(Parcel & parcel)931     static AvoidArea* Unmarshalling(Parcel& parcel)
932     {
933         AvoidArea *avoidArea = new(std::nothrow) AvoidArea();
934         if (avoidArea == nullptr) {
935             return nullptr;
936         }
937         if (ReadParcel(parcel, avoidArea->leftRect_) && ReadParcel(parcel, avoidArea->topRect_) &&
938             ReadParcel(parcel, avoidArea->rightRect_) && ReadParcel(parcel, avoidArea->bottomRect_)) {
939             return avoidArea;
940         }
941         delete avoidArea;
942         return nullptr;
943     }
944 
ToString()945     std::string ToString() const
946     {
947         std::stringstream ss;
948         if (isEmptyAvoidArea()) {
949             ss << "empty";
950             return ss.str();
951         }
952         if (!topRect_.IsUninitializedRect()) {
953             ss << "top " << topRect_.ToString() << " ";
954         }
955         if (!bottomRect_.IsUninitializedRect()) {
956             ss << "bottom " << bottomRect_.ToString() << " ";
957         }
958         if (!leftRect_.IsUninitializedRect()) {
959             ss << "left " << leftRect_.ToString() << " ";
960         }
961         if (!rightRect_.IsUninitializedRect()) {
962             ss << "right " << rightRect_.ToString() << " ";
963         }
964         return ss.str();
965     }
966 };
967 
968 /**
969  * @brief Enumerates window update type.
970  */
971 enum class WindowUpdateType : int32_t {
972     WINDOW_UPDATE_ADDED = 1,
973     WINDOW_UPDATE_REMOVED,
974     WINDOW_UPDATE_FOCUSED,
975     WINDOW_UPDATE_BOUNDS,
976     WINDOW_UPDATE_ACTIVE,
977     WINDOW_UPDATE_PROPERTY,
978     WINDOW_UPDATE_ALL,
979 };
980 
981 /**
982  * @brief Enumerates picture in picture window state.
983  */
984 enum class PiPWindowState : uint32_t {
985     STATE_UNDEFINED = 0,
986     STATE_STARTING = 1,
987     STATE_STARTED = 2,
988     STATE_STOPPING = 3,
989     STATE_STOPPED = 4,
990     STATE_RESTORING = 5,
991 };
992 
993 /**
994  * @brief Enumerates picture in picture template type.
995  */
996 enum class PiPTemplateType : uint32_t {
997     VIDEO_PLAY = 0,
998     VIDEO_CALL = 1,
999     VIDEO_MEETING = 2,
1000     VIDEO_LIVE = 3,
1001     END,
1002 };
1003 
1004 /**
1005  * @brief Enumerates picture in picture control group.
1006  */
1007 enum class PiPControlGroup : uint32_t {
1008     VIDEO_PLAY_START = 100,
1009     VIDEO_PREVIOUS_NEXT = 101,
1010     FAST_FORWARD_BACKWARD = 102,
1011     VIDEO_PLAY_END,
1012 
1013     VIDEO_CALL_START = 200,
1014     VIDEO_CALL_MICROPHONE_SWITCH = 201,
1015     VIDEO_CALL_HANG_UP_BUTTON = 202,
1016     VIDEO_CALL_CAMERA_SWITCH = 203,
1017     VIDEO_CALL_MUTE_SWITCH = 204,
1018     VIDEO_CALL_END,
1019 
1020     VIDEO_MEETING_START = 300,
1021     VIDEO_MEETING_HANG_UP_BUTTON = 301,
1022     VIDEO_MEETING_CAMERA_SWITCH = 302,
1023     VIDEO_MEETING_MUTE_SWITCH = 303,
1024     VIDEO_MEETING_MICROPHONE_SWITCH = 304,
1025     VIDEO_MEETING_END,
1026 
1027     VIDEO_LIVE_START = 400,
1028     VIDEO_PLAY_PAUSE = 401,
1029     VIDEO_LIVE_MUTE_SWITCH = 402,
1030     VIDEO_LIVE_END,
1031     END,
1032 };
1033 
1034 /**
1035  * @brief Enumerates picture in picture state.
1036  */
1037 enum class PiPState : int32_t {
1038     ABOUT_TO_START = 1,
1039     STARTED = 2,
1040     ABOUT_TO_STOP = 3,
1041     STOPPED = 4,
1042     ABOUT_TO_RESTORE = 5,
1043     ERROR = 6,
1044 };
1045 
1046 /**
1047  * @brief Enumerates picture in picture control status.
1048  */
1049 enum class PiPControlStatus : int32_t {
1050     PLAY = 1,
1051     PAUSE = 0,
1052     OPEN = 1,
1053     CLOSE = 0,
1054     ENABLED = -2,
1055     DISABLED = -3,
1056 };
1057 
1058 /**
1059  * @brief Enumerates picture in picture control type.
1060  */
1061 enum class PiPControlType : uint32_t {
1062     VIDEO_PLAY_PAUSE = 0,
1063     VIDEO_PREVIOUS = 1,
1064     VIDEO_NEXT = 2,
1065     FAST_FORWARD = 3,
1066     FAST_BACKWARD = 4,
1067     HANG_UP_BUTTON = 5,
1068     MICROPHONE_SWITCH = 6,
1069     CAMERA_SWITCH = 7,
1070     MUTE_SWITCH = 8,
1071     END,
1072 };
1073 
1074 struct PiPControlStatusInfo {
1075     PiPControlType controlType;
1076     PiPControlStatus status;
1077 };
1078 
1079 struct PiPControlEnableInfo {
1080     PiPControlType controlType;
1081     PiPControlStatus enabled;
1082 };
1083 
1084 struct PiPTemplateInfo {
1085     uint32_t pipTemplateType;
1086     uint32_t priority;
1087     std::vector<uint32_t> controlGroup;
1088     std::vector<PiPControlStatusInfo> pipControlStatusInfoList;
1089     std::vector<PiPControlEnableInfo> pipControlEnableInfoList;
1090 };
1091 
1092 using OnCallback = std::function<void(int64_t, int64_t)>;
1093 
1094 /**
1095  * @struct VsyncCallback
1096  *
1097  * @brief Vsync callback
1098  */
1099 struct VsyncCallback {
1100     OnCallback onCallback;
1101 };
1102 
1103 struct WindowLimits {
1104     uint32_t maxWidth_ = static_cast<uint32_t>(INT32_MAX); // The width and height are no larger than INT32_MAX.
1105     uint32_t maxHeight_ = static_cast<uint32_t>(INT32_MAX);
1106     uint32_t minWidth_ = 1; // The width and height of the window cannot be less than or equal to 0.
1107     uint32_t minHeight_ = 1;
1108     float maxRatio_ = FLT_MAX;
1109     float minRatio_ = 0.0f;
1110     float vpRatio_ = 1.0f;
1111 
WindowLimitsWindowLimits1112     WindowLimits() {}
WindowLimitsWindowLimits1113     WindowLimits(uint32_t maxWidth, uint32_t maxHeight, uint32_t minWidth, uint32_t minHeight, float maxRatio,
1114         float minRatio) : maxWidth_(maxWidth), maxHeight_(maxHeight), minWidth_(minWidth), minHeight_(minHeight),
1115         maxRatio_(maxRatio), minRatio_(minRatio) {}
WindowLimitsWindowLimits1116     WindowLimits(uint32_t maxWidth, uint32_t maxHeight, uint32_t minWidth, uint32_t minHeight, float maxRatio,
1117         float minRatio, float vpRatio) : maxWidth_(maxWidth), maxHeight_(maxHeight), minWidth_(minWidth),
1118         minHeight_(minHeight), maxRatio_(maxRatio), minRatio_(minRatio), vpRatio_(vpRatio) {}
1119 
IsEmptyWindowLimits1120     bool IsEmpty() const
1121     {
1122         return (maxWidth_ == 0 || minWidth_ == 0 || maxHeight_ == 0 || minHeight_ == 0);
1123     }
1124 };
1125 
1126 /**
1127  * @struct TitleButtonRect
1128  *
1129  * @brief An area of title buttons relative to the upper right corner of the window.
1130  */
1131 struct TitleButtonRect {
1132     int32_t posX_;
1133     int32_t posY_;
1134     uint32_t width_;
1135     uint32_t height_;
1136 
1137     bool operator==(const TitleButtonRect& a) const
1138     {
1139         return (posX_ == a.posX_ && posY_ == a.posY_ && width_ == a.width_ && height_ == a.height_);
1140     }
1141 
1142     bool operator!=(const TitleButtonRect& a) const
1143     {
1144         return !this->operator==(a);
1145     }
1146 
IsUninitializedRectTitleButtonRect1147     bool IsUninitializedRect() const
1148     {
1149         return (posX_ == 0 && posY_ == 0 && width_ == 0 && height_ == 0);
1150     }
1151 
IsInsideOfTitleButtonRect1152     bool IsInsideOf(const TitleButtonRect& a) const
1153     {
1154         return (posX_ >= a.posX_ && posY_ >= a.posY_ &&
1155             posX_ + width_ <= a.posX_ + a.width_ && posY_ + height_ <= a.posY_ + a.height_);
1156     }
1157 };
1158 
1159 /*
1160  * Config of keyboard animation
1161  */
1162 class KeyboardAnimationCurve : public Parcelable {
1163 public:
1164     KeyboardAnimationCurve() = default;
KeyboardAnimationCurve(const std::string & curveType,const std::vector<float> & curveParams,uint32_t duration)1165     KeyboardAnimationCurve(const std::string& curveType, const std::vector<float>& curveParams, uint32_t duration)
1166         : curveType_(curveType), duration_(duration)
1167     {
1168         curveParams_.assign(curveParams.begin(), curveParams.end());
1169     }
1170 
Marshalling(Parcel & parcel)1171     virtual bool Marshalling(Parcel& parcel) const override
1172     {
1173         if (!parcel.WriteString(curveType_)) {
1174             return false;
1175         }
1176 
1177         auto paramSize = curveParams_.size();
1178         if (paramSize == 4) { // 4: param size
1179             if (!parcel.WriteUint32(static_cast<uint32_t>(paramSize))) {
1180                 return false;
1181             }
1182             for (auto& param : curveParams_) {
1183                 if (!parcel.WriteFloat(param)) {
1184                     return false;
1185                 }
1186             }
1187         } else {
1188             if (!parcel.WriteUint32(0)) {
1189                 return false;
1190             }
1191         }
1192 
1193         if (!parcel.WriteUint32(duration_)) {
1194             return false;
1195         }
1196         return true;
1197     }
1198 
Unmarshalling(Parcel & parcel)1199     static KeyboardAnimationCurve* Unmarshalling(Parcel& parcel)
1200     {
1201         KeyboardAnimationCurve* config = new KeyboardAnimationCurve;
1202         uint32_t paramSize = 0;
1203         if (!parcel.ReadString(config->curveType_) || !parcel.ReadUint32(paramSize)) {
1204             delete config;
1205             return nullptr;
1206         }
1207 
1208         if (paramSize == 4) { // 4: paramSize
1209             for (uint32_t i = 0; i < paramSize; i++) {
1210                 float param = 0.0f;
1211                 if (!parcel.ReadFloat(param)) {
1212                     delete config;
1213                     return nullptr;
1214                 } else {
1215                     config->curveParams_.push_back(param);
1216                 }
1217             }
1218         }
1219 
1220         if (!parcel.ReadUint32(config->duration_)) {
1221             delete config;
1222             return nullptr;
1223         }
1224         return config;
1225     }
1226 
1227     std::string curveType_ = "";
1228     std::vector<float> curveParams_ = {};
1229     uint32_t duration_ = 0;
1230 };
1231 
1232 struct KeyboardAnimationConfig {
1233     KeyboardAnimationCurve curveIn;
1234     KeyboardAnimationCurve curveOut;
1235 };
1236 
1237 enum class CaseType {
1238     CASE_WINDOW_MANAGER = 0,
1239     CASE_WINDOW,
1240     CASE_STAGE
1241 };
1242 
1243 enum class MaximizePresentation {
1244     FOLLOW_APP_IMMERSIVE_SETTING = 0,  // follow app set immersiveStateEnable
1245     EXIT_IMMERSIVE = 1,                // immersiveStateEnable will be set as false
1246     ENTER_IMMERSIVE = 2,               // immersiveStateEnable will be set as true
1247     // immersiveStateEnable will be set as true, titleHoverShowEnabled and dockHoverShowEnabled will be set as false
1248     ENTER_IMMERSIVE_DISABLE_TITLE_AND_DOCK_HOVER = 3,
1249 };
1250 
1251 enum ForceHideState : uint32_t {
1252     NOT_HIDDEN = 0,
1253     HIDDEN_WHEN_FOCUSED,
1254     HIDDEN_WHEN_UNFOCUSED
1255 };
1256 
1257 enum class ModalityType : uint8_t {
1258     WINDOW_MODALITY,
1259     APPLICATION_MODALITY,
1260 };
1261 
1262 struct SubWindowOptions {
1263     std::string title;
1264     bool decorEnabled = false;
1265     bool isModal = false;
1266     bool isTopmost = false;
1267     ModalityType modalityType = ModalityType::WINDOW_MODALITY;
1268 };
1269 
1270 enum class ExtensionWindowAttribute : int32_t {
1271     SYSTEM_WINDOW = 0,
1272     SUB_WINDOW = 1,
1273     UNKNOWN = 2
1274 };
1275 
1276 struct SystemWindowOptions {
1277     int32_t windowType = -1;
1278 };
1279 
1280 struct ExtensionWindowConfig {
1281     std::string windowName;
1282     ExtensionWindowAttribute windowAttribute = ExtensionWindowAttribute::UNKNOWN;
1283     Rect windowRect;
1284     SubWindowOptions subWindowOptions;
1285     SystemWindowOptions systemWindowOptions;
1286 };
1287 
1288 /**
1289  * @class KeyboardLayoutParams
1290  *
1291  * @brief Keyboard need adjust layout
1292  */
1293 class KeyboardLayoutParams : public Parcelable {
1294 public:
1295     WindowGravity gravity_ = WindowGravity::WINDOW_GRAVITY_BOTTOM;
1296     Rect LandscapeKeyboardRect_ { 0, 0, 0, 0 };
1297     Rect PortraitKeyboardRect_ { 0, 0, 0, 0 };
1298     Rect LandscapePanelRect_ { 0, 0, 0, 0 };
1299     Rect PortraitPanelRect_ { 0, 0, 0, 0 };
1300 
1301     bool operator==(const KeyboardLayoutParams& params) const
1302     {
1303         return (gravity_ == params.gravity_ && LandscapeKeyboardRect_ == params.LandscapeKeyboardRect_ &&
1304             PortraitKeyboardRect_ == params.PortraitKeyboardRect_ &&
1305             LandscapePanelRect_ == params.LandscapePanelRect_ &&
1306             PortraitPanelRect_ == params.PortraitPanelRect_);
1307     }
1308 
1309     bool operator!=(const KeyboardLayoutParams& params) const
1310     {
1311         return !this->operator==(params);
1312     }
1313 
isEmpty()1314     bool isEmpty() const
1315     {
1316         return LandscapeKeyboardRect_.IsUninitializedRect() && PortraitKeyboardRect_.IsUninitializedRect() &&
1317             LandscapePanelRect_.IsUninitializedRect() && PortraitPanelRect_.IsUninitializedRect();
1318     }
1319 
WriteParcel(Parcel & parcel,const Rect & rect)1320     static inline bool WriteParcel(Parcel& parcel, const Rect& rect)
1321     {
1322         return parcel.WriteInt32(rect.posX_) && parcel.WriteInt32(rect.posY_) &&
1323             parcel.WriteUint32(rect.width_) && parcel.WriteUint32(rect.height_);
1324     }
1325 
ReadParcel(Parcel & parcel,Rect & rect)1326     static inline bool ReadParcel(Parcel& parcel, Rect& rect)
1327     {
1328         return parcel.ReadInt32(rect.posX_) && parcel.ReadInt32(rect.posY_) &&
1329             parcel.ReadUint32(rect.width_) && parcel.ReadUint32(rect.height_);
1330     }
1331 
Marshalling(Parcel & parcel)1332     virtual bool Marshalling(Parcel& parcel) const override
1333     {
1334         return (parcel.WriteUint32(static_cast<uint32_t>(gravity_)) &&
1335             WriteParcel(parcel, LandscapeKeyboardRect_) &&
1336             WriteParcel(parcel, PortraitKeyboardRect_) &&
1337             WriteParcel(parcel, LandscapePanelRect_) &&
1338             WriteParcel(parcel, PortraitPanelRect_));
1339     }
1340 
Unmarshalling(Parcel & parcel)1341     static KeyboardLayoutParams* Unmarshalling(Parcel& parcel)
1342     {
1343         KeyboardLayoutParams *params = new(std::nothrow) KeyboardLayoutParams();
1344         if (params == nullptr) {
1345             return nullptr;
1346         }
1347         params->gravity_ = static_cast<WindowGravity>(parcel.ReadUint32());
1348         if (ReadParcel(parcel, params->LandscapeKeyboardRect_) &&
1349             ReadParcel(parcel, params->PortraitKeyboardRect_) &&
1350             ReadParcel(parcel, params->LandscapePanelRect_) &&
1351             ReadParcel(parcel, params->PortraitPanelRect_)) {
1352             return params;
1353         }
1354         delete params;
1355         return nullptr;
1356     }
1357 };
1358 }
1359 }
1360 #endif // OHOS_ROSEN_WM_COMMON_H
1361