• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2024 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 <cmath>
20 #include <map>
21 #include <memory>
22 #include <sstream>
23 #include <string>
24 #include <unordered_set>
25 #include <variant>
26 
27 #include <float.h>
28 
29 #include <parcel.h>
30 #include "dm_common.h"
31 #include "securec.h"
32 #include "wm_animation_common.h"
33 #include "wm_type.h"
34 
35 namespace OHOS {
36 namespace Rosen {
37 namespace {
38 constexpr uint32_t DEFAULT_SPACING_BETWEEN_BUTTONS = 12;
39 constexpr uint32_t DEFAULT_BUTTON_BACKGROUND_SIZE = 28;
40 constexpr uint32_t DEFAULT_CLOSE_BUTTON_RIGHT_MARGIN = 20;
41 constexpr uint32_t DEFAULT_BUTTON_ICON_SIZE = 20;
42 constexpr uint32_t DEFAULT_BUTTON_BACKGROUND_CORNER_RADIUS = 4;
43 constexpr int32_t DEFAULT_COLOR_MODE = -1;
44 constexpr int32_t MIN_COLOR_MODE = -1;
45 constexpr int32_t MAX_COLOR_MODE = 1;
46 constexpr int32_t LIGHT_COLOR_MODE = 0;
47 constexpr int32_t DARK_COLOR_MODE = 1;
48 constexpr uint32_t MIN_SPACING_BETWEEN_BUTTONS = 8;
49 constexpr uint32_t MAX_SPACING_BETWEEN_BUTTONS = 24;
50 constexpr uint32_t MIN_BUTTON_BACKGROUND_SIZE = 20;
51 constexpr uint32_t MAX_BUTTON_BACKGROUND_SIZE = 40;
52 constexpr uint32_t MIN_CLOSE_BUTTON_RIGHT_MARGIN = 6;
53 constexpr uint32_t MAX_CLOSE_BUTTON_RIGHT_MARGIN = 22;
54 constexpr uint32_t MIN_BUTTON_ICON_SIZE = 16;
55 constexpr uint32_t MAX_BUTTON_ICON_SIZE = 24;
56 constexpr uint32_t MIN_BUTTON_BACKGROUND_CORNER_RADIUS = 4;
57 constexpr uint32_t MAX_BUTTON_BACKGROUND_CORNER_RADIUS = 8;
58 constexpr int32_t MINIMUM_Z_LEVEL = -10000;
59 constexpr int32_t MAXIMUM_Z_LEVEL = 10000;
60 constexpr int32_t SPECIFIC_ZINDEX_INVALID = -1;
61 constexpr double POS_ZERO = 0.001f;
62 }
63 
64 /**
65  * @brief Enumerates type of window
66  */
67 enum class WindowType : uint32_t {
68     APP_WINDOW_BASE = 1,
69     APP_MAIN_WINDOW_BASE = APP_WINDOW_BASE,
70     WINDOW_TYPE_APP_MAIN_WINDOW = APP_MAIN_WINDOW_BASE,
71     APP_MAIN_WINDOW_END,
72 
73     APP_SUB_WINDOW_BASE = 1000,
74     WINDOW_TYPE_MEDIA = APP_SUB_WINDOW_BASE,
75     WINDOW_TYPE_APP_SUB_WINDOW,
76     WINDOW_TYPE_APP_COMPONENT,
77     APP_SUB_WINDOW_END,
78     APP_WINDOW_END = APP_SUB_WINDOW_END,
79 
80     SYSTEM_WINDOW_BASE = 2000,
81     BELOW_APP_SYSTEM_WINDOW_BASE = SYSTEM_WINDOW_BASE,
82     WINDOW_TYPE_WALLPAPER = SYSTEM_WINDOW_BASE,
83     WINDOW_TYPE_DESKTOP,
84     BELOW_APP_SYSTEM_WINDOW_END,
85 
86     ABOVE_APP_SYSTEM_WINDOW_BASE = 2100,
87     WINDOW_TYPE_APP_LAUNCHING = ABOVE_APP_SYSTEM_WINDOW_BASE,
88     WINDOW_TYPE_DOCK_SLICE,
89     WINDOW_TYPE_INCOMING_CALL,
90     WINDOW_TYPE_SEARCHING_BAR,
91     WINDOW_TYPE_SYSTEM_ALARM_WINDOW,
92     WINDOW_TYPE_INPUT_METHOD_FLOAT,
93     WINDOW_TYPE_FLOAT,
94     WINDOW_TYPE_TOAST,
95     WINDOW_TYPE_STATUS_BAR,
96     WINDOW_TYPE_PANEL,
97     WINDOW_TYPE_KEYGUARD,
98     WINDOW_TYPE_VOLUME_OVERLAY,
99     WINDOW_TYPE_NAVIGATION_BAR,
100     WINDOW_TYPE_DRAGGING_EFFECT,
101     WINDOW_TYPE_POINTER,
102     WINDOW_TYPE_LAUNCHER_RECENT,
103     WINDOW_TYPE_LAUNCHER_DOCK,
104     WINDOW_TYPE_BOOT_ANIMATION,
105     WINDOW_TYPE_FREEZE_DISPLAY,
106     WINDOW_TYPE_VOICE_INTERACTION,
107     WINDOW_TYPE_FLOAT_CAMERA,
108     WINDOW_TYPE_PLACEHOLDER,
109     WINDOW_TYPE_DIALOG,
110     WINDOW_TYPE_SCREENSHOT,
111     WINDOW_TYPE_INPUT_METHOD_STATUS_BAR,
112     WINDOW_TYPE_GLOBAL_SEARCH,
113     WINDOW_TYPE_SYSTEM_TOAST,
114     WINDOW_TYPE_SYSTEM_FLOAT,
115     WINDOW_TYPE_PIP,
116     WINDOW_TYPE_THEME_EDITOR,
117     WINDOW_TYPE_NAVIGATION_INDICATOR,
118     WINDOW_TYPE_HANDWRITE,
119     WINDOW_TYPE_SCENE_BOARD,
120     WINDOW_TYPE_KEYBOARD_PANEL,
121     WINDOW_TYPE_WALLET_SWIPE_CARD,
122     WINDOW_TYPE_SCREEN_CONTROL,
123     WINDOW_TYPE_FLOAT_NAVIGATION,
124     WINDOW_TYPE_MUTISCREEN_COLLABORATION,
125     WINDOW_TYPE_DYNAMIC,
126     WINDOW_TYPE_MAGNIFICATION,
127     WINDOW_TYPE_MAGNIFICATION_MENU,
128     WINDOW_TYPE_SELECTION,
129     WINDOW_TYPE_FB,
130     ABOVE_APP_SYSTEM_WINDOW_END,
131 
132     SYSTEM_SUB_WINDOW_BASE = 2500,
133     WINDOW_TYPE_SYSTEM_SUB_WINDOW = SYSTEM_SUB_WINDOW_BASE,
134     SYSTEM_SUB_WINDOW_END,
135 
136     SYSTEM_WINDOW_END = SYSTEM_SUB_WINDOW_END,
137 
138     WINDOW_TYPE_UI_EXTENSION = 3000
139 };
140 
141 /**
142  * @brief Enumerates state of window.
143  */
144 enum class WindowState : uint32_t {
145     STATE_INITIAL,
146     STATE_CREATED,
147     STATE_SHOWN,
148     STATE_HIDDEN,
149     STATE_FROZEN,
150     STATE_UNFROZEN,
151     STATE_DESTROYED,
152     STATE_BOTTOM = STATE_DESTROYED // Add state type after STATE_DESTROYED is not allowed.
153 };
154 
155 /**
156  * @brief Enumerates blur style of window.
157  */
158 enum class WindowBlurStyle : uint32_t {
159     WINDOW_BLUR_OFF = 0,
160     WINDOW_BLUR_THIN,
161     WINDOW_BLUR_REGULAR,
162     WINDOW_BLUR_THICK
163 };
164 
165 /**
166  * @brief Enumerates mode supported of window.
167  */
168 enum WindowModeSupport : uint32_t {
169     WINDOW_MODE_SUPPORT_FULLSCREEN = 1 << 0,
170     WINDOW_MODE_SUPPORT_FLOATING = 1 << 1,
171     WINDOW_MODE_SUPPORT_SPLIT_PRIMARY = 1 << 2,
172     WINDOW_MODE_SUPPORT_SPLIT_SECONDARY = 1 << 3,
173     WINDOW_MODE_SUPPORT_PIP = 1 << 4,
174     WINDOW_MODE_SUPPORT_FB = 1 << 5,
175     WINDOW_MODE_SUPPORT_ALL = WINDOW_MODE_SUPPORT_FLOATING |
176                               WINDOW_MODE_SUPPORT_FULLSCREEN |
177                               WINDOW_MODE_SUPPORT_SPLIT_PRIMARY |
178                               WINDOW_MODE_SUPPORT_SPLIT_SECONDARY |
179                               WINDOW_MODE_SUPPORT_PIP |
180                               WINDOW_MODE_SUPPORT_FB
181 };
182 
183 /**
184  * @brief Enumerates mode of window.
185  */
186 enum class WindowMode : uint32_t {
187     WINDOW_MODE_UNDEFINED = 0,
188     WINDOW_MODE_FULLSCREEN = 1,
189     WINDOW_MODE_SPLIT_PRIMARY = 100,
190     WINDOW_MODE_SPLIT_SECONDARY,
191     WINDOW_MODE_FLOATING,
192     WINDOW_MODE_PIP,
193     WINDOW_MODE_FB,
194 };
195 
196 /**
197  * @brief Enumerates global mode of window.
198  */
199 enum class GlobalWindowMode : uint32_t {
200     UNKNOWN = 0,
201     FULLSCREEN = 1,
202     SPLIT = 1 << 1,
203     FLOAT = 1 << 2,
204     PIP = 1 << 3,
205     ALL = FULLSCREEN | SPLIT | FLOAT | PIP
206 };
207 
208 inline GlobalWindowMode operator|(GlobalWindowMode lhs, GlobalWindowMode rhs)
209 {
210     return static_cast<GlobalWindowMode>(static_cast<uint32_t>(lhs) | static_cast<uint32_t>(rhs));
211 }
212 
213 /**
214  * @brief Enumerates status of window.
215  */
216 enum class WindowStatus : uint32_t {
217     WINDOW_STATUS_UNDEFINED = 0,
218     WINDOW_STATUS_FULLSCREEN = 1,
219     WINDOW_STATUS_MAXIMIZE,
220     WINDOW_STATUS_MINIMIZE,
221     WINDOW_STATUS_FLOATING,
222     WINDOW_STATUS_SPLITSCREEN
223 };
224 
225 /**
226  * @brief Enumerates error code of window.
227  */
228 enum class WMError : int32_t {
229     WM_OK = 0,
230     WM_DO_NOTHING,
231     WM_ERROR_NO_MEM,
232     WM_ERROR_DESTROYED_OBJECT,
233     WM_ERROR_INVALID_WINDOW,
234     WM_ERROR_INVALID_WINDOW_MODE_OR_SIZE,
235     WM_ERROR_INVALID_OPERATION,
236     WM_ERROR_INVALID_PERMISSION,
237     WM_ERROR_NOT_SYSTEM_APP,
238     WM_ERROR_NO_REMOTE_ANIMATION,
239     WM_ERROR_INVALID_DISPLAY,
240     WM_ERROR_INVALID_PARENT,
241     WM_ERROR_INVALID_OP_IN_CUR_STATUS,
242     WM_ERROR_REPEAT_OPERATION,
243     WM_ERROR_INVALID_SESSION,
244     WM_ERROR_INVALID_CALLING,
245     WM_ERROR_SYSTEM_ABNORMALLY,
246 
247     WM_ERROR_DEVICE_NOT_SUPPORT = 801, // the value do not change.It is defined on all system.
248 
249     WM_ERROR_NEED_REPORT_BASE = 1000, // error code > 1000 means need report.
250     WM_ERROR_NULLPTR,
251     WM_ERROR_INVALID_TYPE,
252     WM_ERROR_INVALID_PARAM,
253     WM_ERROR_SAMGR,
254     WM_ERROR_IPC_FAILED,
255     WM_ERROR_NEED_REPORT_END,
256     WM_ERROR_START_ABILITY_FAILED,
257     WM_ERROR_PIP_DESTROY_FAILED,
258     WM_ERROR_PIP_STATE_ABNORMALLY,
259     WM_ERROR_PIP_CREATE_FAILED,
260     WM_ERROR_PIP_INTERNAL_ERROR,
261     WM_ERROR_PIP_REPEAT_OPERATION,
262     WM_ERROR_ILLEGAL_PARAM,
263     WM_ERROR_UI_EFFECT_ERROR,
264     WM_ERROR_TIMEOUT,
265     WM_ERROR_FB_PARAM_INVALID,
266     WM_ERROR_FB_CREATE_FAILED,
267     WM_ERROR_FB_REPEAT_CONTROLLER,
268     WM_ERROR_FB_REPEAT_OPERATION,
269     WM_ERROR_FB_INTERNAL_ERROR,
270     WM_ERROR_FB_STATE_ABNORMALLY,
271     WM_ERROR_FB_INVALID_STATE,
272     WM_ERROR_FB_RESTORE_MAIN_WINDOW_FAILED,
273     WM_ERROR_FB_UPDATE_TEMPLATE_TYPE_DENIED,
274     WM_ERROR_FB_UPDATE_STATIC_TEMPLATE_DENIED,
275 };
276 
277 /**
278  * @brief Enumerates error code of window only used for js api.
279  */
280 enum class WmErrorCode : int32_t {
281     WM_OK = 0,
282     WM_ERROR_NO_PERMISSION = 201,
283     WM_ERROR_NOT_SYSTEM_APP = 202,
284     WM_ERROR_INVALID_PARAM = 401,
285     WM_ERROR_DEVICE_NOT_SUPPORT = 801,
286 
287     WM_ERROR_REPEAT_OPERATION = 1300001,
288     WM_ERROR_STATE_ABNORMALLY = 1300002,
289     WM_ERROR_SYSTEM_ABNORMALLY = 1300003,
290     WM_ERROR_INVALID_CALLING = 1300004,
291     WM_ERROR_STAGE_ABNORMALLY = 1300005,
292     WM_ERROR_CONTEXT_ABNORMALLY = 1300006,
293     WM_ERROR_START_ABILITY_FAILED = 1300007,
294     WM_ERROR_INVALID_DISPLAY = 1300008,
295     WM_ERROR_INVALID_PARENT = 1300009,
296     WM_ERROR_INVALID_OP_IN_CUR_STATUS = 1300010,
297     WM_ERROR_PIP_DESTROY_FAILED = 1300011,
298     WM_ERROR_PIP_STATE_ABNORMALLY = 1300012,
299     WM_ERROR_PIP_CREATE_FAILED = 1300013,
300     WM_ERROR_PIP_INTERNAL_ERROR = 1300014,
301     WM_ERROR_PIP_REPEAT_OPERATION = 1300015,
302     WM_ERROR_ILLEGAL_PARAM = 1300016,
303     WM_ERROR_UI_EFFECT_ERROR = 1300017,
304     WM_ERROR_TIMEOUT = 1300018,
305     WM_ERROR_FB_PARAM_INVALID = 1300019,
306     WM_ERROR_FB_CREATE_FAILED = 1300020,
307     WM_ERROR_FB_REPEAT_CONTROLLER = 1300021,
308     WM_ERROR_FB_REPEAT_OPERATION = 1300022,
309     WM_ERROR_FB_INTERNAL_ERROR = 1300023,
310     WM_ERROR_FB_STATE_ABNORMALLY = 1300024,
311     WM_ERROR_FB_INVALID_STATE = 1300025,
312     WM_ERROR_FB_RESTORE_MAIN_WINDOW_FAILED = 1300026,
313     WM_ERROR_FB_UPDATE_TEMPLATE_TYPE_DENIED = 1300027,
314     WM_ERROR_FB_UPDATE_STATIC_TEMPLATE_DENIED = 1300028,
315 };
316 
317 /**
318  * @brief Enumerates setting flag of systemStatusBar.
319  */
320 enum class SystemBarSettingFlag : uint32_t {
321     DEFAULT_SETTING = 0,
322     COLOR_SETTING = 1,
323     ENABLE_SETTING = 1 << 1,
324     ALL_SETTING = 0b11
325 };
326 
327 inline SystemBarSettingFlag operator|(SystemBarSettingFlag lhs, SystemBarSettingFlag rhs)
328 {
329     using T = std::underlying_type_t<SystemBarSettingFlag>;
330     return static_cast<SystemBarSettingFlag>(static_cast<T>(lhs) | static_cast<T>(rhs));
331 }
332 
333 inline SystemBarSettingFlag& operator|=
334     (SystemBarSettingFlag& lhs, SystemBarSettingFlag rhs) { return lhs = lhs | rhs; }
335 
336 /**
337  * @brief Enumerates flag of window.
338  */
339 enum class WindowFlag : uint32_t {
340     WINDOW_FLAG_NEED_AVOID = 1,
341     WINDOW_FLAG_PARENT_LIMIT = 1 << 1,
342     WINDOW_FLAG_SHOW_WHEN_LOCKED = 1 << 2,
343     WINDOW_FLAG_FORBID_SPLIT_MOVE = 1 << 3,
344     WINDOW_FLAG_WATER_MARK = 1 << 4,
345     WINDOW_FLAG_IS_MODAL = 1 << 5,
346     WINDOW_FLAG_HANDWRITING = 1 << 6,
347     WINDOW_FLAG_IS_TOAST = 1 << 7,
348     WINDOW_FLAG_IS_APPLICATION_MODAL = 1 << 8,
349     WINDOW_FLAG_IS_TEXT_MENU = 1 << 9,
350     WINDOW_FLAG_END = 1 << 10,
351 };
352 
353 /**
354  * @brief Enumerates system and app sub window avoid area options
355  */
356 enum class AvoidAreaOption : uint32_t {
357     ENABLE_SYSTEM_WINDOW = 1,
358     ENABLE_APP_SUB_WINDOW = 1 << 1,
359 };
360 
361 /**
362  * @brief Enumerates flag of multiWindowUIType.
363  */
364 enum class WindowUIType : uint8_t {
365     PHONE_WINDOW = 0,
366     PC_WINDOW,
367     PAD_WINDOW,
368     INVALID_WINDOW
369 };
370 
371 /**
372  * @brief Used to map from WMError to WmErrorCode.
373  */
374 const std::map<WMError, WmErrorCode> WM_JS_TO_ERROR_CODE_MAP {
375     {WMError::WM_OK,                                   WmErrorCode::WM_OK                             },
376     {WMError::WM_DO_NOTHING,                           WmErrorCode::WM_ERROR_STATE_ABNORMALLY         },
377     {WMError::WM_ERROR_DESTROYED_OBJECT,               WmErrorCode::WM_ERROR_STATE_ABNORMALLY         },
378     {WMError::WM_ERROR_DEVICE_NOT_SUPPORT,             WmErrorCode::WM_ERROR_DEVICE_NOT_SUPPORT       },
379     {WMError::WM_ERROR_INVALID_OPERATION,              WmErrorCode::WM_ERROR_STATE_ABNORMALLY         },
380     {WMError::WM_ERROR_INVALID_PARAM,                  WmErrorCode::WM_ERROR_INVALID_PARAM            },
381     {WMError::WM_ERROR_INVALID_PERMISSION,             WmErrorCode::WM_ERROR_NO_PERMISSION            },
382     {WMError::WM_ERROR_NOT_SYSTEM_APP,                 WmErrorCode::WM_ERROR_NOT_SYSTEM_APP           },
383     {WMError::WM_ERROR_INVALID_TYPE,                   WmErrorCode::WM_ERROR_STATE_ABNORMALLY         },
384     {WMError::WM_ERROR_INVALID_WINDOW,                 WmErrorCode::WM_ERROR_STATE_ABNORMALLY         },
385     {WMError::WM_ERROR_INVALID_WINDOW_MODE_OR_SIZE,    WmErrorCode::WM_ERROR_STATE_ABNORMALLY         },
386     {WMError::WM_ERROR_IPC_FAILED,                     WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY        },
387     {WMError::WM_ERROR_NO_MEM,                         WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY        },
388     {WMError::WM_ERROR_NO_REMOTE_ANIMATION,            WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY        },
389     {WMError::WM_ERROR_INVALID_DISPLAY,                WmErrorCode::WM_ERROR_INVALID_DISPLAY          },
390     {WMError::WM_ERROR_INVALID_PARENT,                 WmErrorCode::WM_ERROR_INVALID_PARENT           },
391     {WMError::WM_ERROR_INVALID_OP_IN_CUR_STATUS,       WmErrorCode::WM_ERROR_INVALID_OP_IN_CUR_STATUS },
392     {WMError::WM_ERROR_REPEAT_OPERATION,               WmErrorCode::WM_ERROR_REPEAT_OPERATION         },
393     {WMError::WM_ERROR_NULLPTR,                        WmErrorCode::WM_ERROR_STATE_ABNORMALLY         },
394     {WMError::WM_ERROR_SAMGR,                          WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY        },
395     {WMError::WM_ERROR_START_ABILITY_FAILED,           WmErrorCode::WM_ERROR_START_ABILITY_FAILED     },
396     {WMError::WM_ERROR_SYSTEM_ABNORMALLY,              WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY        },
397     {WMError::WM_ERROR_TIMEOUT,                        WmErrorCode::WM_ERROR_TIMEOUT                  },
398     {WMError::WM_ERROR_ILLEGAL_PARAM,                  WmErrorCode::WM_ERROR_ILLEGAL_PARAM            },
399     {WMError::WM_ERROR_FB_PARAM_INVALID,               WmErrorCode::WM_ERROR_FB_PARAM_INVALID         },
400     {WMError::WM_ERROR_FB_CREATE_FAILED,               WmErrorCode::WM_ERROR_FB_CREATE_FAILED         },
401     {WMError::WM_ERROR_FB_REPEAT_CONTROLLER,           WmErrorCode::WM_ERROR_FB_REPEAT_CONTROLLER     },
402     {WMError::WM_ERROR_FB_REPEAT_OPERATION,            WmErrorCode::WM_ERROR_FB_REPEAT_OPERATION      },
403     {WMError::WM_ERROR_FB_INTERNAL_ERROR,              WmErrorCode::WM_ERROR_FB_INTERNAL_ERROR        },
404     {WMError::WM_ERROR_FB_STATE_ABNORMALLY,            WmErrorCode::WM_ERROR_FB_STATE_ABNORMALLY      },
405     {WMError::WM_ERROR_FB_INVALID_STATE,               WmErrorCode::WM_ERROR_FB_INVALID_STATE         },
406     {WMError::WM_ERROR_FB_RESTORE_MAIN_WINDOW_FAILED,  WmErrorCode::WM_ERROR_FB_RESTORE_MAIN_WINDOW_FAILED  },
407     {WMError::WM_ERROR_FB_UPDATE_TEMPLATE_TYPE_DENIED, WmErrorCode::WM_ERROR_FB_UPDATE_TEMPLATE_TYPE_DENIED  },
408     {WMError::WM_ERROR_FB_UPDATE_STATIC_TEMPLATE_DENIED,  WmErrorCode::WM_ERROR_FB_UPDATE_STATIC_TEMPLATE_DENIED  },
409     {WMError::WM_ERROR_UI_EFFECT_ERROR,                WmErrorCode::WM_ERROR_UI_EFFECT_ERROR          },
410 };
411 
412 /**
413  * @brief Enumerates window size change reason.
414  */
415 enum class WindowSizeChangeReason : uint32_t {
416     UNDEFINED = 0,
417     MAXIMIZE,
418     RECOVER,
419     ROTATION,
420     DRAG,
421     DRAG_START,
422     DRAG_END,
423     RESIZE,
424     RESIZE_WITH_ANIMATION,
425     MOVE,
426     MOVE_WITH_ANIMATION,
427     HIDE,
428     TRANSFORM,
429     CUSTOM_ANIMATION_SHOW,
430     FULL_TO_SPLIT,
431     SPLIT_TO_FULL,
432     FULL_TO_FLOATING,
433     FLOATING_TO_FULL,
434     PIP_START,
435     PIP_SHOW,
436     PIP_AUTO_START,
437     PIP_RATIO_CHANGE,
438     PIP_RESTORE,
439     UPDATE_DPI_SYNC,
440     DRAG_MOVE,
441     AVOID_AREA_CHANGE,
442     MAXIMIZE_TO_SPLIT,
443     SPLIT_TO_MAXIMIZE,
444     PAGE_ROTATION,
445     SPLIT_DRAG_START,
446     SPLIT_DRAG,
447     SPLIT_DRAG_END,
448     RESIZE_BY_LIMIT,
449     MAXIMIZE_IN_IMPLICT = 32,
450     RECOVER_IN_IMPLICIT = 33,
451     SCREEN_RELATIVE_POSITION_CHANGE,
452     SNAPSHOT_ROTATION = 37,
453     END
454 };
455 
456 /**
457  * @brief Enumerates window gravity.
458  */
459 enum class WindowGravity : uint32_t {
460     WINDOW_GRAVITY_FLOAT = 0,
461     WINDOW_GRAVITY_BOTTOM
462 };
463 
464 /**
465  * @brief Enumerates window session type.
466  */
467 enum class WindowSessionType : uint32_t {
468     SCENE_SESSION = 0,
469     EXTENSION_SESSION = 1
470 };
471 
472 /**
473  * @brief Enumerates window tag.
474  */
475 enum class WindowTag : uint32_t {
476     MAIN_WINDOW = 0,
477     SUB_WINDOW = 1,
478     SYSTEM_WINDOW = 2
479 };
480 
481 /**
482  * @brief Enumerates drag event.
483  */
484 enum class DragEvent : uint32_t {
485     DRAG_EVENT_IN  = 1,
486     DRAG_EVENT_OUT,
487     DRAG_EVENT_MOVE,
488     DRAG_EVENT_END
489 };
490 
491 /**
492  * @brief Enumerates drag resize type.
493  */
494 enum class DragResizeType : uint32_t {
495     RESIZE_TYPE_UNDEFINED = 0,
496     RESIZE_EACH_FRAME = 1,
497     RESIZE_WHEN_DRAG_END = 2,
498     RESIZE_KEY_FRAME = 3,
499     RESIZE_MAX_VALUE,  // invalid value begin, add new value above
500 };
501 
502 /**
503  * @struct KeyFramePolicy
504  *
505  * @brief info for drag key frame policy.
506  */
507 struct KeyFramePolicy : public Parcelable {
508     DragResizeType dragResizeType_ = DragResizeType::RESIZE_TYPE_UNDEFINED;
509     uint32_t interval_ = 1000;
510     uint32_t distance_ = 1000;
511     uint32_t animationDuration_ = 100;
512     uint32_t animationDelay_ = 100;
513     bool running_ = false;
514     bool stopping_ = false;
515 
enabledKeyFramePolicy516     bool enabled() const
517     {
518         return dragResizeType_ == DragResizeType::RESIZE_KEY_FRAME;
519     }
520 
MarshallingKeyFramePolicy521     bool Marshalling(Parcel& parcel) const override
522     {
523         return parcel.WriteUint32(static_cast<uint32_t>(dragResizeType_)) &&
524             parcel.WriteUint32(interval_) && parcel.WriteUint32(distance_) &&
525             parcel.WriteUint32(animationDuration_) && parcel.WriteUint32(animationDelay_) &&
526             parcel.WriteBool(running_) && parcel.WriteBool(stopping_);
527     }
528 
UnmarshallingKeyFramePolicy529     static KeyFramePolicy* Unmarshalling(Parcel& parcel)
530     {
531         KeyFramePolicy* keyFramePolicy = new KeyFramePolicy();
532         uint32_t dragResizeType;
533         if (!parcel.ReadUint32(dragResizeType) || !parcel.ReadUint32(keyFramePolicy->interval_) ||
534             !parcel.ReadUint32(keyFramePolicy->distance_) || !parcel.ReadUint32(keyFramePolicy->animationDuration_) ||
535             !parcel.ReadUint32(keyFramePolicy->animationDelay_) || !parcel.ReadBool(keyFramePolicy->running_) ||
536             !parcel.ReadBool(keyFramePolicy->stopping_)) {
537             delete keyFramePolicy;
538             return nullptr;
539         }
540         if (dragResizeType >= static_cast<uint32_t>(DragResizeType::RESIZE_MAX_VALUE)) {
541             delete keyFramePolicy;
542             return nullptr;
543         }
544         keyFramePolicy->dragResizeType_ = static_cast<DragResizeType>(dragResizeType);
545         return keyFramePolicy;
546     }
547 
ToStringKeyFramePolicy548     inline std::string ToString() const
549     {
550         std::ostringstream oss;
551         oss << "[" << static_cast<uint32_t>(dragResizeType_) << " " << interval_ << " " << distance_;
552         oss << " " << animationDuration_ << " " << animationDelay_ << "]";
553         return oss.str();
554     }
555 };
556 
557 /**
558  * @struct HookWindowInfo.
559  *
560  * @brief Configures window hook behavior based on window size ratios.
561  */
562 struct HookWindowInfo : public Parcelable {
563     bool enableHookWindow{ false };
564     float widthHookRatio{ 1.0f };
565 
566     static constexpr float DEFAULT_WINDOW_SIZE_HOOK_RATIO = 1.0f;
567 
MarshallingHookWindowInfo568     bool Marshalling(Parcel& parcel) const override
569     {
570         return WriteAllFields(parcel);
571     }
572 
UnmarshallingHookWindowInfo573     static HookWindowInfo* Unmarshalling(Parcel& parcel)
574     {
575         auto hookWindowInfo = std::make_unique<HookWindowInfo>();
576         if (!hookWindowInfo || !ReadAllFields(parcel, *hookWindowInfo)) {
577             return nullptr;
578         }
579         return hookWindowInfo.release();
580     }
581 
ToStringHookWindowInfo582     std::string ToString() const
583     {
584         constexpr int precision = 6; // Print float with precision of 6 decimal places.
585         std::ostringstream oss;
586         oss << std::boolalpha  // For true/false instead of 1/0
587             << "enableHookWindow: " << enableHookWindow
588             << ", widthHookRatio: " << std::fixed << std::setprecision(precision) << widthHookRatio;
589         return oss.str();
590     }
591 
592 private:
WriteAllFieldsHookWindowInfo593     bool WriteAllFields(Parcel& parcel) const
594     {
595         return parcel.WriteBool(enableHookWindow) &&
596                parcel.WriteFloat(widthHookRatio);
597     }
598 
ReadAllFieldsHookWindowInfo599     static bool ReadAllFields(Parcel& parcel, HookWindowInfo& info)
600     {
601         return parcel.ReadBool(info.enableHookWindow) &&
602                parcel.ReadFloat(info.widthHookRatio);
603     }
604 };
605 
606 /**
607  * @brief Enumerates layout mode of window.
608  */
609 enum class WindowLayoutMode : uint32_t {
610     BASE = 0,
611     CASCADE = BASE,
612     TILE = 1,
613     END,
614 };
615 
616 namespace {
617 constexpr uint32_t SYSTEM_COLOR_WHITE = 0xE5FFFFFF;
618 constexpr uint32_t SYSTEM_COLOR_BLACK = 0x66000000;
619 constexpr float UNDEFINED_BRIGHTNESS = -1.0f;
620 constexpr float MINIMUM_BRIGHTNESS = 0.0f;
621 constexpr float MAXIMUM_BRIGHTNESS = 1.0f;
622 
623 constexpr uint32_t INVALID_WINDOW_ID = 0;
624 constexpr int32_t INVALID_PID = -1;
625 constexpr int32_t INVALID_UID = -1;
626 
627 constexpr float UNDEFINED_DENSITY = -1.0f;
628 constexpr float MINIMUM_CUSTOM_DENSITY = 0.5f;
629 constexpr float MAXIMUM_CUSTOM_DENSITY = 4.0f;
630 }
631 
632 /**
633  * @struct PointInfo.
634  *
635  * @brief Point info.
636  */
637 struct PointInfo {
638     int32_t x;
639     int32_t y;
640 };
641 
642 /**
643  * @class Transform
644  *
645  * @brief parameter of transform and rotate.
646  */
647 class Transform {
648 public:
Transform()649     Transform()
650         : pivotX_(0.5f), pivotY_(0.5f), scaleX_(1.f), scaleY_(1.f), scaleZ_(1.f), rotationX_(0.f),
651           rotationY_(0.f), rotationZ_(0.f), translateX_(0.f), translateY_(0.f), translateZ_(0.f)
652     {}
~Transform()653     ~Transform() {}
654 
655     bool operator==(const Transform& right) const
656     {
657         return NearZero(scaleX_ - right.scaleX_) &&
658             NearZero(scaleY_ - right.scaleY_) &&
659             NearZero(scaleZ_ - right.scaleZ_) &&
660             NearZero(pivotX_ - right.pivotX_) &&
661             NearZero(pivotY_ - right.pivotY_) &&
662             NearZero(translateX_ - right.translateX_) &&
663             NearZero(translateY_ - right.translateY_) &&
664             NearZero(translateZ_ - right.translateZ_) &&
665             NearZero(rotationX_ - right.rotationX_) &&
666             NearZero(rotationY_ - right.rotationY_) &&
667             NearZero(rotationZ_ - right.rotationZ_);
668     }
669 
670     bool operator!=(const Transform& right) const
671     {
672         return !(*this == right);
673     }
674 
Identity()675     static const Transform& Identity()
676     {
677         static Transform I;
678         return I;
679     }
680 
681     float pivotX_;
682     float pivotY_;
683     float scaleX_;
684     float scaleY_;
685     float scaleZ_;
686     float rotationX_;
687     float rotationY_;
688     float rotationZ_;
689     float translateX_;
690     float translateY_;
691     float translateZ_;
692 
Unmarshalling(Parcel & parcel)693     void Unmarshalling(Parcel& parcel)
694     {
695         pivotX_ = parcel.ReadFloat();
696         pivotY_ = parcel.ReadFloat();
697         scaleX_ = parcel.ReadFloat();
698         scaleY_ = parcel.ReadFloat();
699         scaleZ_ = parcel.ReadFloat();
700         rotationX_ = parcel.ReadFloat();
701         rotationY_ = parcel.ReadFloat();
702         rotationZ_ = parcel.ReadFloat();
703         translateX_ = parcel.ReadFloat();
704         translateY_ = parcel.ReadFloat();
705         translateZ_ = parcel.ReadFloat();
706     }
707 
Marshalling(Parcel & parcel)708     bool Marshalling(Parcel& parcel) const
709     {
710         return parcel.WriteFloat(pivotX_) && parcel.WriteFloat(pivotY_) &&
711                parcel.WriteFloat(scaleX_) && parcel.WriteFloat(scaleY_) && parcel.WriteFloat(scaleZ_) &&
712                parcel.WriteFloat(rotationX_) && parcel.WriteFloat(rotationY_) && parcel.WriteFloat(rotationZ_) &&
713                parcel.WriteFloat(translateX_) && parcel.WriteFloat(translateY_) && parcel.WriteFloat(translateZ_);
714     }
715 
716 private:
NearZero(float val)717     static inline bool NearZero(float val)
718     {
719         return -0.001f < val && val < 0.001f;
720     }
721 };
722 
723 /**
724  * @struct RectAnimationConfig
725  *
726  * @brief Window RectAnimationConfig
727  */
728 struct RectAnimationConfig {
729     uint32_t duration = 0; // Duartion of the animation, in milliseconds.
730     float x1 = 0.0f;       // X coordinate of the first point on the Bezier curve.
731     float y1 = 0.0f;       // Y coordinate of the first point on the Bezier curve.
732     float x2 = 0.0f;       // X coordinate of the second point on the Bezier curve.
733     float y2 = 0.0f;       // Y coordinate of the second point on the Bezier curve.
734 };
735 
736 /**
737  * @struct SystemBarPropertyFlag
738  *
739  * @brief Flag of system bar
740  */
741 struct SystemBarPropertyFlag {
742     bool enableFlag = false;
743     bool backgroundColorFlag = false;
744     bool contentColorFlag = false;
745     bool enableAnimationFlag = false;
746 };
747 
748 /**
749  * @struct Rect
750  *
751  * @brief Window Rect.
752  */
753 struct Rect {
754     int32_t posX_;
755     int32_t posY_;
756     uint32_t width_;
757     uint32_t height_;
758 
759     bool operator==(const Rect& a) const
760     {
761         return (posX_ == a.posX_ && posY_ == a.posY_ && width_ == a.width_ && height_ == a.height_);
762     }
763 
764     bool operator!=(const Rect& a) const
765     {
766         return !this->operator==(a);
767     }
768 
IsInsideOfRect769     bool IsInsideOf(const Rect& a) const
770     {
771         return (posX_ >= a.posX_ && posY_ >= a.posY_ &&
772             posX_ + width_ <= a.posX_ + a.width_ && posY_ + height_ <= a.posY_ + a.height_);
773     }
774 
IsUninitializedRectRect775     bool IsUninitializedRect() const
776     {
777         return (posX_ == 0 && posY_ == 0 && width_ == 0 && height_ == 0);
778     }
779 
IsUninitializedSizeRect780     bool IsUninitializedSize() const
781     {
782         return width_ == 0 && height_ == 0;
783     }
784 
IsSamePositionRect785     bool IsSamePosition(int32_t x, int32_t y) const
786     {
787         return posX_ == x && posY_ == y;
788     }
789 
ToStringRect790     inline std::string ToString() const
791     {
792         std::ostringstream oss;
793         oss << "[" << posX_ << " " << posY_ << " " << width_ << " " << height_ << "]";
794         return oss.str();
795     }
796 
797     static const Rect EMPTY_RECT;
798 
799     /**
800      * @brief Checks whether the right-bottom corner of a rectangle stays within the valid range.
801      *
802      * @param x The x-coordinate of the left-top corner.
803      * @param y The y-coordinate of the left-top corner.
804      * @param width The rectangle's width.
805      * @param height The rectangle's height.
806      * @return true if right-bottom corner stays within int32_t range; false if overflow happens.
807      */
IsRightBottomValidRect808     static bool IsRightBottomValid(int32_t x, int32_t y, uint32_t width, uint32_t height)
809     {
810         int64_t right = static_cast<int64_t>(x) + static_cast<int64_t>(width);
811         int64_t bottom = static_cast<int64_t>(y) + static_cast<int64_t>(height);
812         return right <= INT32_MAX && bottom <= INT32_MAX;
813     }
814 };
815 
816 inline constexpr Rect Rect::EMPTY_RECT { 0, 0, 0, 0 };
817 
818 /**
819  * @struct SystemBarProperty
820  *
821  * @brief Property of system bar.
822  */
823 struct SystemBarProperty {
824     bool enable_;
825     uint32_t backgroundColor_;
826     uint32_t contentColor_;
827     bool enableAnimation_;
828     SystemBarSettingFlag settingFlag_;
SystemBarPropertySystemBarProperty829     SystemBarProperty() : enable_(true), backgroundColor_(SYSTEM_COLOR_BLACK), contentColor_(SYSTEM_COLOR_WHITE),
830                           enableAnimation_(false), settingFlag_(SystemBarSettingFlag::DEFAULT_SETTING) {}
SystemBarPropertySystemBarProperty831     SystemBarProperty(bool enable, uint32_t background, uint32_t content, bool enableAnimation)
832         : enable_(enable), backgroundColor_(background), contentColor_(content), enableAnimation_(enableAnimation),
833           settingFlag_(SystemBarSettingFlag::DEFAULT_SETTING) {}
SystemBarPropertySystemBarProperty834     SystemBarProperty(bool enable, uint32_t background, uint32_t content)
835         : enable_(enable), backgroundColor_(background), contentColor_(content), enableAnimation_(false),
836           settingFlag_(SystemBarSettingFlag::DEFAULT_SETTING) {}
SystemBarPropertySystemBarProperty837     SystemBarProperty(bool enable, uint32_t background, uint32_t content,
838                       bool enableAnimation, SystemBarSettingFlag settingFlag)
839         : enable_(enable), backgroundColor_(background), contentColor_(content), enableAnimation_(enableAnimation),
840           settingFlag_(settingFlag) {}
841 
842     bool operator == (const SystemBarProperty& a) const
843     {
844         return (enable_ == a.enable_ && backgroundColor_ == a.backgroundColor_ && contentColor_ == a.contentColor_ &&
845             enableAnimation_ == a.enableAnimation_);
846     }
847 };
848 
849 /**
850  * @struct WindowDensityInfo
851  *
852  * @brief Currently available density
853  */
854 struct WindowDensityInfo {
855     float systemDensity = UNDEFINED_DENSITY;
856     float defaultDensity = UNDEFINED_DENSITY;
857     float customDensity = UNDEFINED_DENSITY;
858 
ToStringWindowDensityInfo859     std::string ToString() const
860     {
861         std::string str;
862         constexpr int BUFFER_SIZE = 64;
863         char buffer[BUFFER_SIZE] = { 0 };
864         if (snprintf_s(buffer, sizeof(buffer), sizeof(buffer) - 1,
865             "[%f, %f, %f]", systemDensity, defaultDensity, customDensity) > 0) {
866             str.append(buffer);
867         }
868         return str;
869     }
870 };
871 
872 /**
873  * @struct WindowPropertyInfo
874  *
875  * @brief Currently available window property
876  */
877 struct WindowPropertyInfo {
878     Rect windowRect { 0, 0, 0, 0 };
879     Rect drawableRect { 0, 0, 0, 0 };
880     Rect globalDisplayRect { 0, 0, 0, 0 };
881     uint32_t apiCompatibleVersion = 0;
882     WindowType type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW;
883     bool isLayoutFullScreen = false;
884     bool isFullScreen = false;
885     bool isTouchable = false;
886     bool isFocusable = false;
887     std::string name;
888     bool isPrivacyMode = false;
889     bool isKeepScreenOn = false;
890     float brightness = 0.0f;
891     bool isTransparent = false;
892     bool isRoundCorner = false;
893     float dimBehindValue = 0.0f;
894     uint32_t id = INVALID_WINDOW_ID;
895     DisplayId displayId = DISPLAY_ID_INVALID;
896 };
897 
898 /**
899  * @brief Enumerates avoid area type.
900  */
901 enum class AvoidAreaType : uint32_t {
902     TYPE_START = 0,
903     TYPE_SYSTEM = TYPE_START,           // area of SystemUI
904     TYPE_CUTOUT,                        // cutout of screen
905     TYPE_SYSTEM_GESTURE,                // area for system gesture
906     TYPE_KEYBOARD,                      // area for soft input keyboard
907     TYPE_NAVIGATION_INDICATOR,          // area for navigation indicator
908     TYPE_END,
909 };
910 
911 /**
912  * @brief Enumerates color space.
913  */
914 enum class ColorSpace : uint32_t {
915     COLOR_SPACE_DEFAULT = 0, // Default color space.
916     COLOR_SPACE_WIDE_GAMUT,  // Wide gamut color space. The specific wide color gamut depends on the screen.
917 };
918 
919 /**
920  * @brief Enumerates occupied area type.
921  */
922 enum class OccupiedAreaType : uint32_t {
923     TYPE_INPUT, // area of input window
924 };
925 
926 /**
927  * @brief Enumerates window maximize mode.
928  */
929 enum class MaximizeMode : uint32_t {
930     MODE_AVOID_SYSTEM_BAR,
931     MODE_FULL_FILL,
932     MODE_RECOVER
933 };
934 
935 /**
936  * @brief Enumerates window animation.
937  */
938 enum class WindowAnimation : uint32_t {
939     NONE,
940     DEFAULT,
941     INPUTE,
942     CUSTOM
943 };
944 
945 /**
946  * @brief Enumerates window anchor.
947  */
948 enum class WindowAnchor : uint32_t {
949     TOP_START = 0,
950     TOP,
951     TOP_END,
952     START,
953     CENTER,
954     END,
955     BOTTOM_START,
956     BOTTOM,
957     BOTTOM_END,
958 };
959 
960 /**
961  * @struct WindowAnchorInfo
962  *
963  * @brief Window anchor info
964  */
965 struct WindowAnchorInfo : public Parcelable {
966     bool isAnchorEnabled_ = false;
967     WindowAnchor windowAnchor_ = WindowAnchor::TOP_START;
968     int32_t offsetX_ = 0;
969     int32_t offsetY_ = 0;
970 
WindowAnchorInfoWindowAnchorInfo971     WindowAnchorInfo() {}
WindowAnchorInfoWindowAnchorInfo972     WindowAnchorInfo(bool isAnchorEnabled) : isAnchorEnabled_(isAnchorEnabled) {}
WindowAnchorInfoWindowAnchorInfo973     WindowAnchorInfo(bool isAnchorEnabled, WindowAnchor windowAnchor, int32_t offsetX,
974         int32_t offsetY) : isAnchorEnabled_(isAnchorEnabled),  windowAnchor_(windowAnchor),
975         offsetX_(offsetX), offsetY_(offsetY) {}
976 
977     bool operator==(const WindowAnchorInfo& other) const
978     {
979         return isAnchorEnabled_ == other.isAnchorEnabled_ && windowAnchor_ == other.windowAnchor_ &&
980             offsetX_ == other.offsetX_ && offsetY_ == other.offsetY_;
981     }
982 
983     bool operator!=(const WindowAnchorInfo& other) const
984     {
985         return !(*this == other);
986     }
987 
MarshallingWindowAnchorInfo988     bool Marshalling(Parcel& parcel) const override
989     {
990         return parcel.WriteBool(isAnchorEnabled_) && parcel.WriteUint32(static_cast<uint32_t>(windowAnchor_)) &&
991             parcel.WriteInt32(offsetX_) && parcel.WriteInt32(offsetY_);
992     }
993 
UnmarshallingWindowAnchorInfo994     static WindowAnchorInfo* Unmarshalling(Parcel& parcel)
995     {
996         uint32_t windowAnchorMode = 0;
997         WindowAnchorInfo* windowAnchorInfo = new(std::nothrow) WindowAnchorInfo();
998         if (windowAnchorInfo == nullptr) {
999             return nullptr;
1000         }
1001         if (!parcel.ReadBool(windowAnchorInfo->isAnchorEnabled_) || !parcel.ReadUint32(windowAnchorMode) ||
1002             !parcel.ReadInt32(windowAnchorInfo->offsetX_) || !parcel.ReadInt32(windowAnchorInfo->offsetY_)) {
1003             delete windowAnchorInfo;
1004             return nullptr;
1005         }
1006         windowAnchorInfo->windowAnchor_ = static_cast<WindowAnchor>(windowAnchorMode);
1007         return windowAnchorInfo;
1008     }
1009 };
1010 
1011 struct DecorButtonStyle {
1012     int32_t  colorMode = DEFAULT_COLOR_MODE;
1013     uint32_t spacingBetweenButtons = DEFAULT_SPACING_BETWEEN_BUTTONS;
1014     uint32_t closeButtonRightMargin = DEFAULT_CLOSE_BUTTON_RIGHT_MARGIN;
1015     uint32_t buttonBackgroundSize = DEFAULT_BUTTON_BACKGROUND_SIZE;
1016     uint32_t buttonIconSize = DEFAULT_BUTTON_ICON_SIZE;
1017     uint32_t buttonBackgroundCornerRadius = DEFAULT_BUTTON_BACKGROUND_CORNER_RADIUS;
1018 };
1019 
1020 /**
1021  * @class AvoidArea
1022  *
1023  * @brief Area needed to avoid.
1024  */
1025 class AvoidArea : virtual public RefBase {
1026 public:
1027     Rect topRect_ { 0, 0, 0, 0 };
1028     Rect leftRect_ { 0, 0, 0, 0 };
1029     Rect rightRect_ { 0, 0, 0, 0 };
1030     Rect bottomRect_ { 0, 0, 0, 0 };
1031 
1032     bool operator==(const AvoidArea& a) const
1033     {
1034         return (topRect_ == a.topRect_ && leftRect_ == a.leftRect_ &&
1035             rightRect_ == a.rightRect_ && bottomRect_ == a.bottomRect_);
1036     }
1037 
1038     bool operator!=(const AvoidArea& a) const
1039     {
1040         return !this->operator==(a);
1041     }
1042 
ReadParcel(Parcel & parcel,Rect & rect)1043     static inline bool ReadParcel(Parcel& parcel, Rect& rect)
1044     {
1045         return parcel.ReadInt32(rect.posX_) && parcel.ReadInt32(rect.posY_) &&
1046             parcel.ReadUint32(rect.width_) && parcel.ReadUint32(rect.height_);
1047     }
1048 
WriteParcel(Parcel & parcel,const Rect & rect)1049     static inline bool WriteParcel(Parcel& parcel, const Rect& rect)
1050     {
1051         return parcel.WriteInt32(rect.posX_) && parcel.WriteInt32(rect.posY_) &&
1052             parcel.WriteUint32(rect.width_) && parcel.WriteUint32(rect.height_);
1053     }
1054 
isEmptyAvoidArea()1055     bool isEmptyAvoidArea() const
1056     {
1057         return topRect_.IsUninitializedRect() && leftRect_.IsUninitializedRect() &&
1058             rightRect_.IsUninitializedRect() && bottomRect_.IsUninitializedRect();
1059     }
1060 };
1061 
1062 /**
1063  * @struct VsyncCallback
1064  *
1065  * @brief Vsync callback
1066  */
1067 struct VsyncCallback {
1068     OnCallback onCallback;
1069 };
1070 
1071 /**
1072  * @brief Enumerates window update type.
1073  */
1074 enum class WindowUpdateType : int32_t {
1075     WINDOW_UPDATE_ADDED = 1,
1076     WINDOW_UPDATE_REMOVED,
1077     WINDOW_UPDATE_FOCUSED,
1078     WINDOW_UPDATE_BOUNDS,
1079     WINDOW_UPDATE_ACTIVE,
1080     WINDOW_UPDATE_PROPERTY
1081 };
1082 
1083 struct WindowLimits {
1084     uint32_t maxWidth_ = static_cast<uint32_t>(INT32_MAX); // The width and height are no larger than INT32_MAX.
1085     uint32_t maxHeight_ = static_cast<uint32_t>(INT32_MAX);
1086     uint32_t minWidth_ = 1; // The width and height of the window cannot be less than or equal to 0.
1087     uint32_t minHeight_ = 1;
1088     float maxRatio_ = FLT_MAX;
1089     float minRatio_ = 0.0f;
1090     float vpRatio_ = 1.0f;
1091 
WindowLimitsWindowLimits1092     WindowLimits() {}
WindowLimitsWindowLimits1093     WindowLimits(uint32_t maxWidth, uint32_t maxHeight, uint32_t minWidth, uint32_t minHeight, float maxRatio,
1094         float minRatio) : maxWidth_(maxWidth), maxHeight_(maxHeight), minWidth_(minWidth), minHeight_(minHeight),
1095         maxRatio_(maxRatio), minRatio_(minRatio) {}
WindowLimitsWindowLimits1096     WindowLimits(uint32_t maxWidth, uint32_t maxHeight, uint32_t minWidth, uint32_t minHeight, float maxRatio,
1097         float minRatio, float vpRatio) : maxWidth_(maxWidth), maxHeight_(maxHeight), minWidth_(minWidth),
1098         minHeight_(minHeight), maxRatio_(maxRatio), minRatio_(minRatio), vpRatio_(vpRatio) {}
1099 
IsEmptyWindowLimits1100     bool IsEmpty() const
1101     {
1102         return (maxHeight_ == 0 || minHeight_ == 0 || maxWidth_ == 0 || minWidth_ == 0);
1103     }
1104 
ToStringWindowLimits1105     std::string ToString() const
1106     {
1107         constexpr int precision = 6;
1108         std::ostringstream oss;
1109         oss << "[" << maxWidth_ << " " << maxHeight_ << " " << minWidth_ << " " << minHeight_
1110             << " " << std::fixed << std::setprecision(precision) << maxRatio_ << " " << minRatio_
1111             << " " << vpRatio_ << "]";
1112         return oss.str();
1113     }
1114 };
1115 
1116 /**
1117  * @struct TitleButtonRect
1118  *
1119  * @brief An area of title buttons relative to the upper right corner of the window.
1120  */
1121 struct TitleButtonRect {
1122     int32_t posX_ = 0;
1123     int32_t posY_ = 0;
1124     uint32_t width_ = 0;
1125     uint32_t height_ = 0;
1126 
1127     bool operator==(const TitleButtonRect& a) const
1128     {
1129         return (posX_ == a.posX_ && posY_ == a.posY_ && width_ == a.width_ && height_ == a.height_);
1130     }
1131 
1132     bool operator!=(const TitleButtonRect& a) const
1133     {
1134         return !this->operator==(a);
1135     }
1136 
ResetRectTitleButtonRect1137     void ResetRect()
1138     {
1139         posX_ = 0;
1140         posY_ = 0;
1141         width_ = 0;
1142         height_ = 0;
1143     }
1144 
IsInsideOfTitleButtonRect1145     bool IsInsideOf(const TitleButtonRect& a) const
1146     {
1147         return (posX_ >= a.posX_ && posY_ >= a.posY_ &&
1148             posX_ + width_ <= a.posX_ + a.width_ && posY_ + height_ <= a.posY_ + a.height_);
1149     }
1150 
IsUninitializedRectTitleButtonRect1151     bool IsUninitializedRect() const
1152     {
1153         return (posX_ == 0 && posY_ == 0 && width_ == 0 && height_ == 0);
1154     }
1155 };
1156 
1157 /**
1158  * @brief WindowInfo filter Option
1159  */
1160 enum class WindowInfoFilterOption : WindowInfoFilterOptionDataType {
1161     ALL = 0,
1162     EXCLUDE_SYSTEM = 1,
1163     VISIBLE = 1 << 1,
1164     FOREGROUND = 1 << 2,
1165 };
1166 
1167 inline WindowInfoFilterOption operator|(WindowInfoFilterOption lhs, WindowInfoFilterOption rhs)
1168 {
1169     return static_cast<WindowInfoFilterOption>(static_cast<WindowInfoFilterOptionDataType>(lhs) |
1170         static_cast<WindowInfoFilterOptionDataType>(rhs));
1171 }
1172 
IsChosenWindowOption(WindowInfoFilterOption options,WindowInfoFilterOption option)1173 inline bool IsChosenWindowOption(WindowInfoFilterOption options, WindowInfoFilterOption option)
1174 {
1175     return (static_cast<WindowInfoFilterOptionDataType>(options) &
1176         static_cast<WindowInfoFilterOptionDataType>(option)) != 0;
1177 }
1178 
1179 /**
1180  * @brief WindowInfo Type Option
1181  */
1182 enum class WindowInfoTypeOption : WindowInfoTypeOptionDataType {
1183     WINDOW_UI_INFO = 1,
1184     WINDOW_DISPLAY_INFO = 1 << 1,
1185     WINDOW_LAYOUT_INFO = 1 << 2,
1186     WINDOW_META_INFO = 1 << 3,
1187     ALL = ~0,
1188 };
1189 
1190 inline WindowInfoTypeOption operator|(WindowInfoTypeOption lhs, WindowInfoTypeOption rhs)
1191 {
1192     return static_cast<WindowInfoTypeOption>(static_cast<WindowInfoTypeOptionDataType>(lhs) |
1193         static_cast<WindowInfoTypeOptionDataType>(rhs));
1194 }
1195 
IsChosenWindowOption(WindowInfoTypeOption options,WindowInfoTypeOption option)1196 inline bool IsChosenWindowOption(WindowInfoTypeOption options, WindowInfoTypeOption option)
1197 {
1198     return (static_cast<WindowInfoTypeOptionDataType>(options) &
1199         static_cast<WindowInfoTypeOptionDataType>(option)) != 0;
1200 }
1201 
1202 /**
1203  * @enum WindowVisibilityState
1204  *
1205  * @brief Visibility state of a window
1206  */
1207 enum WindowVisibilityState : uint32_t {
1208     START = 0,
1209     WINDOW_VISIBILITY_STATE_NO_OCCLUSION = START,
1210     WINDOW_VISIBILITY_STATE_PARTICALLY_OCCLUSION,
1211     WINDOW_VISIBILITY_STATE_TOTALLY_OCCUSION,
1212     WINDOW_LAYER_STATE_MAX,
1213     END = WINDOW_LAYER_STATE_MAX,
1214 };
1215 
1216 /**
1217  * @struct WindowUIInfo
1218  *
1219  * @brief Window UI info
1220  */
1221 struct WindowUIInfo : public Parcelable {
1222     WindowVisibilityState visibilityState = WINDOW_LAYER_STATE_MAX;
1223 
MarshallingWindowUIInfo1224     bool Marshalling(Parcel& parcel) const override
1225     {
1226         return parcel.WriteUint32(static_cast<uint32_t>(visibilityState));
1227     }
1228 
UnmarshallingWindowUIInfo1229     static WindowUIInfo* Unmarshalling(Parcel& parcel)
1230     {
1231         WindowUIInfo* windowUIInfo = new WindowUIInfo();
1232         uint32_t visibilityState = 0;
1233         if (!parcel.ReadUint32(visibilityState)) {
1234             delete windowUIInfo;
1235             return nullptr;
1236         }
1237         windowUIInfo->visibilityState = static_cast<WindowVisibilityState>(visibilityState);
1238         return windowUIInfo;
1239     }
1240 };
1241 
1242 /**
1243  * @struct WindowDisplayInfo
1244  *
1245  * @brief Window display info
1246  */
1247 struct WindowDisplayInfo : public Parcelable {
1248     DisplayId displayId = DISPLAY_ID_INVALID;
MarshallingWindowDisplayInfo1249     bool Marshalling(Parcel& parcel) const override
1250     {
1251         return parcel.WriteUint64(displayId);
1252     }
1253 
UnmarshallingWindowDisplayInfo1254     static WindowDisplayInfo* Unmarshalling(Parcel& parcel)
1255     {
1256         WindowDisplayInfo* windowDisplayInfo = new WindowDisplayInfo();
1257         if (!parcel.ReadUint64(windowDisplayInfo->displayId)) {
1258             delete windowDisplayInfo;
1259             return nullptr;
1260         }
1261         return windowDisplayInfo;
1262     }
1263 };
1264 
1265 /**
1266  * @struct WindowLayoutInfo
1267  *
1268  * @brief Layout info for all windows on the screen.
1269  */
1270 struct WindowLayoutInfo : public Parcelable {
1271     Rect rect = Rect::EMPTY_RECT;
1272     uint32_t zOrder = 0;
1273 
MarshallingWindowLayoutInfo1274     bool Marshalling(Parcel& parcel) const override
1275     {
1276         return parcel.WriteInt32(rect.posX_) && parcel.WriteInt32(rect.posY_) && parcel.WriteUint32(rect.width_) &&
1277                parcel.WriteUint32(rect.height_) && parcel.WriteUint32(zOrder);
1278     }
1279 
UnmarshallingWindowLayoutInfo1280     static WindowLayoutInfo* Unmarshalling(Parcel& parcel)
1281     {
1282         WindowLayoutInfo* windowLayoutInfo = new WindowLayoutInfo();
1283         if (!parcel.ReadInt32(windowLayoutInfo->rect.posX_) || !parcel.ReadInt32(windowLayoutInfo->rect.posY_) ||
1284             !parcel.ReadUint32(windowLayoutInfo->rect.width_) || !parcel.ReadUint32(windowLayoutInfo->rect.height_) ||
1285             !parcel.ReadUint32(windowLayoutInfo->zOrder)) {
1286             delete windowLayoutInfo;
1287             return nullptr;
1288         }
1289         return windowLayoutInfo;
1290     }
1291 };
1292 
1293 /**
1294  * @struct WindowMetaInfo
1295  *
1296  * @brief Window meta info
1297  */
1298 struct WindowMetaInfo : public Parcelable {
1299     int32_t windowId = 0;
1300     std::string windowName;
1301     std::string bundleName;
1302     std::string abilityName;
1303     int32_t appIndex = 0;
1304     WindowType windowType = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW;
1305     uint32_t parentWindowId = INVALID_WINDOW_ID;
1306     uint64_t surfaceNodeId = 0;
1307     uint64_t leashWinSurfaceNodeId = 0;
1308     bool isPrivacyMode = false;
1309     WindowMode windowMode = WindowMode::WINDOW_MODE_UNDEFINED;
1310     bool isMidScene = false;
1311     bool isFocused = false;
1312 
MarshallingWindowMetaInfo1313     bool Marshalling(Parcel& parcel) const override
1314     {
1315         return parcel.WriteInt32(windowId) && parcel.WriteString(windowName) && parcel.WriteString(bundleName) &&
1316                parcel.WriteString(abilityName) && parcel.WriteInt32(appIndex) &&
1317                parcel.WriteUint32(static_cast<uint32_t>(windowType)) && parcel.WriteUint32(parentWindowId) &&
1318                parcel.WriteUint64(surfaceNodeId) && parcel.WriteUint64(leashWinSurfaceNodeId) &&
1319                parcel.WriteBool(isPrivacyMode) && parcel.WriteBool(isMidScene) &&
1320                parcel.WriteBool(isFocused) && parcel.WriteUint32(static_cast<uint32_t>(windowMode));
1321     }
1322 
UnmarshallingWindowMetaInfo1323     static WindowMetaInfo* Unmarshalling(Parcel& parcel)
1324     {
1325         uint32_t windowTypeValue = 1;
1326         uint32_t windowModeValue = 1;
1327         WindowMetaInfo* windowMetaInfo = new WindowMetaInfo();
1328         if (!parcel.ReadInt32(windowMetaInfo->windowId) || !parcel.ReadString(windowMetaInfo->windowName) ||
1329             !parcel.ReadString(windowMetaInfo->bundleName) || !parcel.ReadString(windowMetaInfo->abilityName) ||
1330             !parcel.ReadInt32(windowMetaInfo->appIndex) || !parcel.ReadUint32(windowTypeValue) ||
1331             !parcel.ReadUint32(windowMetaInfo->parentWindowId) || !parcel.ReadUint64(windowMetaInfo->surfaceNodeId) ||
1332             !parcel.ReadUint64(windowMetaInfo->leashWinSurfaceNodeId) ||
1333             !parcel.ReadBool(windowMetaInfo->isPrivacyMode) || !parcel.ReadBool(windowMetaInfo->isMidScene) ||
1334             !parcel.ReadBool(windowMetaInfo->isFocused) || !parcel.ReadUint32(windowModeValue)) {
1335             delete windowMetaInfo;
1336             return nullptr;
1337         }
1338         windowMetaInfo->windowType = static_cast<WindowType>(windowTypeValue);
1339         windowMetaInfo->windowMode = static_cast<WindowMode>(windowModeValue);
1340         return windowMetaInfo;
1341     }
1342 };
1343 
1344 /**
1345  * @struct WindowInfo
1346  *
1347  * @brief Classified window info
1348  */
1349 struct WindowInfo : public Parcelable {
1350     WindowUIInfo windowUIInfo;
1351     WindowDisplayInfo windowDisplayInfo;
1352     WindowLayoutInfo windowLayoutInfo;
1353     WindowMetaInfo windowMetaInfo;
1354 
MarshallingWindowInfo1355     bool Marshalling(Parcel& parcel) const override
1356     {
1357         return parcel.WriteParcelable(&windowUIInfo) && parcel.WriteParcelable(&windowDisplayInfo) &&
1358                parcel.WriteParcelable(&windowLayoutInfo) && parcel.WriteParcelable(&windowMetaInfo);
1359     }
1360 
UnmarshallingWindowInfo1361     static WindowInfo* Unmarshalling(Parcel& parcel)
1362     {
1363         WindowInfo* windowInfo = new WindowInfo();
1364         sptr<WindowUIInfo> windowUIInfo = parcel.ReadParcelable<WindowUIInfo>();
1365         sptr<WindowDisplayInfo> windowDisplayInfo = parcel.ReadParcelable<WindowDisplayInfo>();
1366         sptr<WindowLayoutInfo> windowLayoutInfo = parcel.ReadParcelable<WindowLayoutInfo>();
1367         sptr<WindowMetaInfo> windowMetaInfo = parcel.ReadParcelable<WindowMetaInfo>();
1368         if (!windowUIInfo || !windowDisplayInfo || !windowLayoutInfo || !windowMetaInfo) {
1369             delete windowInfo;
1370             return nullptr;
1371         }
1372         windowInfo->windowUIInfo = *windowUIInfo;
1373         windowInfo->windowDisplayInfo = *windowDisplayInfo;
1374         windowInfo->windowLayoutInfo = *windowLayoutInfo;
1375         windowInfo->windowMetaInfo = *windowMetaInfo;
1376         return windowInfo;
1377     }
1378 };
1379 
1380 /**
1381  * @struct WindowInfoOption
1382  *
1383  * @brief Option of list window info
1384  */
1385 struct WindowInfoOption : public Parcelable {
1386     WindowInfoFilterOption windowInfoFilterOption = WindowInfoFilterOption::ALL;
1387     WindowInfoTypeOption windowInfoTypeOption = WindowInfoTypeOption::ALL;
1388     DisplayId displayId = DISPLAY_ID_INVALID;
1389     int32_t windowId = 0;
1390 
MarshallingWindowInfoOption1391     bool Marshalling(Parcel& parcel) const override
1392     {
1393         return parcel.WriteUint32(static_cast<uint32_t>(windowInfoFilterOption)) &&
1394                parcel.WriteUint32(static_cast<uint32_t>(windowInfoTypeOption)) &&
1395                parcel.WriteUint64(displayId) &&
1396                parcel.WriteInt32(windowId);
1397     }
1398 
UnmarshallingWindowInfoOption1399     static WindowInfoOption* Unmarshalling(Parcel& parcel)
1400     {
1401         WindowInfoOption* windowInfoOption = new WindowInfoOption();
1402         uint32_t windowInfoFilterOption;
1403         uint32_t windowInfoTypeOption;
1404         if (!parcel.ReadUint32(windowInfoFilterOption) || !parcel.ReadUint32(windowInfoTypeOption) ||
1405             !parcel.ReadUint64(windowInfoOption->displayId) || !parcel.ReadInt32(windowInfoOption->windowId)) {
1406             delete windowInfoOption;
1407             return nullptr;
1408         }
1409         windowInfoOption->windowInfoFilterOption = static_cast<WindowInfoFilterOption>(windowInfoFilterOption);
1410         windowInfoOption->windowInfoTypeOption = static_cast<WindowInfoTypeOption>(windowInfoTypeOption);
1411         return windowInfoOption;
1412     }
1413 };
1414 
1415 /**
1416  * Config of keyboard animation
1417  */
1418 class KeyboardAnimationCurve : public Parcelable {
1419 public:
1420     KeyboardAnimationCurve() = default;
KeyboardAnimationCurve(const std::string & curveType,const std::vector<float> & curveParams,uint32_t duration)1421     KeyboardAnimationCurve(const std::string& curveType, const std::vector<float>& curveParams, uint32_t duration)
1422         : curveType_(curveType), duration_(duration)
1423     {
1424         curveParams_.assign(curveParams.begin(), curveParams.end());
1425     }
1426 
Marshalling(Parcel & parcel)1427     virtual bool Marshalling(Parcel& parcel) const override
1428     {
1429         if (!parcel.WriteString(curveType_)) {
1430             return false;
1431         }
1432 
1433         auto paramSize = curveParams_.size();
1434         if (paramSize == 4) { // 4: param size
1435             if (!parcel.WriteUint32(static_cast<uint32_t>(paramSize))) {
1436                 return false;
1437             }
1438             for (auto& param : curveParams_) {
1439                 if (!parcel.WriteFloat(param)) {
1440                     return false;
1441                 }
1442             }
1443         } else {
1444             if (!parcel.WriteUint32(0)) {
1445                 return false;
1446             }
1447         }
1448 
1449         if (!parcel.WriteUint32(duration_)) {
1450             return false;
1451         }
1452         return true;
1453     }
1454 
Unmarshalling(Parcel & parcel)1455     static KeyboardAnimationCurve* Unmarshalling(Parcel& parcel)
1456     {
1457         KeyboardAnimationCurve* config = new KeyboardAnimationCurve;
1458         uint32_t paramSize = 0;
1459         if (!parcel.ReadString(config->curveType_) || !parcel.ReadUint32(paramSize)) {
1460             delete config;
1461             return nullptr;
1462         }
1463 
1464         if (paramSize == 4) { // 4: paramSize
1465             for (uint32_t i = 0; i < paramSize; i++) {
1466                 float param = 0.0f;
1467                 if (!parcel.ReadFloat(param)) {
1468                     delete config;
1469                     return nullptr;
1470                 } else {
1471                     config->curveParams_.push_back(param);
1472                 }
1473             }
1474         }
1475 
1476         if (!parcel.ReadUint32(config->duration_)) {
1477             delete config;
1478             return nullptr;
1479         }
1480         return config;
1481     }
1482 
1483     std::string curveType_ = "";
1484     std::vector<float> curveParams_ = {};
1485     uint32_t duration_ = 0;
1486 };
1487 
1488 struct KeyboardAnimationConfig {
1489     KeyboardAnimationCurve curveIn;
1490     KeyboardAnimationCurve curveOut;
1491 };
1492 
1493 struct MoveConfiguration {
1494     DisplayId displayId = DISPLAY_ID_INVALID;
1495     RectAnimationConfig rectAnimationConfig = { 0, 0.0f, 0.0f, 0.0f, 0.0f };
ToStringMoveConfiguration1496     std::string ToString() const
1497     {
1498         std::string str;
1499         constexpr int BUFFER_SIZE = 1024;
1500         char buffer[BUFFER_SIZE] = { 0 };
1501         if (snprintf_s(buffer, sizeof(buffer), sizeof(buffer) - 1,
1502             "[displayId: %llu, rectAnimationConfig: [%u, %f, %f, %f, %f]]", displayId, rectAnimationConfig.duration,
1503             rectAnimationConfig.x1, rectAnimationConfig.y1, rectAnimationConfig.x2, rectAnimationConfig.y2) > 0) {
1504             str.append(buffer);
1505         }
1506         return str;
1507     }
1508 };
1509 
1510 enum class MaximizePresentation {
1511     FOLLOW_APP_IMMERSIVE_SETTING = 0,   // follow app set immersiveStateEnable
1512     EXIT_IMMERSIVE = 1,                 // immersiveStateEnable will be set as false
1513     ENTER_IMMERSIVE = 2,                // immersiveStateEnable will be set as true
1514     // immersiveStateEnable will be set as true, titleHoverShowEnabled and dockHoverShowEnabled will be set as false
1515     ENTER_IMMERSIVE_DISABLE_TITLE_AND_DOCK_HOVER = 3,
1516 };
1517 
1518 enum class ExtensionWindowAttribute : int32_t {
1519     SYSTEM_WINDOW = 0,
1520     SUB_WINDOW = 1,
1521     UNKNOWN = 2
1522 };
1523 
1524 struct SystemWindowOptions {
1525     int32_t windowType = -1;
1526 };
1527 
1528 enum class ModalityType : uint8_t {
1529     WINDOW_MODALITY,
1530     APPLICATION_MODALITY,
1531 };
1532 
1533 struct SubWindowOptions {
1534     std::string title;
1535     bool decorEnabled = false;
1536     bool isModal = false;
1537     bool isTopmost = false;
1538     bool maximizeSupported = false;
1539     ModalityType modalityType = ModalityType::WINDOW_MODALITY;
1540 };
1541 
1542 struct ExtensionWindowConfig {
1543     std::string windowName;
1544     ExtensionWindowAttribute windowAttribute = ExtensionWindowAttribute::UNKNOWN;
1545     Rect windowRect;
1546     SubWindowOptions subWindowOptions;
1547     SystemWindowOptions systemWindowOptions;
1548 };
1549 
1550 enum class BackupAndRestoreType : int32_t {
1551     NONE = 0,                       // no backup and restore
1552     CONTINUATION = 1,               // distribute
1553     APP_RECOVERY = 2,               // app recovery
1554     RESOURCESCHEDULE_RECOVERY = 3,  // app is killed due to resource schedule
1555 };
1556 
1557 /**
1558  * @brief Windowinfokey
1559  */
1560 enum class WindowInfoKey : int32_t {
1561     NONE = 0,
1562     WINDOW_ID = 1,
1563     BUNDLE_NAME = 1 << 1,
1564     ABILITY_NAME = 1 << 2,
1565     APP_INDEX = 1 << 3,
1566     VISIBILITY_STATE = 1 << 4,
1567     DISPLAY_ID = 1 << 5,
1568     WINDOW_RECT = 1 << 6,
1569     WINDOW_MODE = 1 << 7,
1570     FLOATING_SCALE = 1 << 8,
1571 };
1572 
1573 /*
1574  * @brief Enumerates rotation change type.
1575  */
1576 enum class RotationChangeType : uint32_t {
1577     /**
1578      * rotate will begin.
1579      */
1580     WINDOW_WILL_ROTATE = 0,
1581 
1582     /**
1583      * rotate end.
1584      */
1585     WINDOW_DID_ROTATE,
1586 };
1587 
1588 /**
1589  * @brief Enumerates rect type
1590  */
1591 enum class RectType : uint32_t {
1592     /**
1593      * the window rect of app relative to screen.
1594      */
1595     RELATIVE_TO_SCREEN = 0,
1596 
1597     /**
1598      * the window rect of app relative to parent window.
1599      */
1600     RELATIVE_TO_PARENT_WINDOW,
1601 };
1602 
1603 /**
1604  * @brief rotation change info to notify listener.
1605  */
1606 struct RotationChangeInfo {
1607     RotationChangeType type_;
1608     uint32_t orientation_;
1609     DisplayId displayId_;
1610     Rect displayRect_;
1611 };
1612 
1613 /**
1614  * @brief rotation change result return from listener.
1615  */
1616 struct RotationChangeResult {
1617     RectType rectType_;
1618     Rect windowRect_;
1619 };
1620 
1621 /**
1622  * @brief default zIndex for specific window.
1623  */
1624 enum DefaultSpecificZIndex {
1625     MUTISCREEN_COLLABORATION = 930,
1626     SUPER_PRIVACY_ANIMATION = 1100,
1627 };
1628 
1629 /**
1630  * @struct ShadowsInfo
1631  *
1632  * @brief window shadows info
1633  */
1634 struct ShadowsInfo : public Parcelable {
1635     float radius_ = 0.0f;
1636     std::string color_;
1637     float offsetX_ = 0.0f;
1638     float offsetY_ = 0.0f;
1639     bool hasRadiusValue_ = false;
1640     bool hasColorValue_ = false;
1641     bool hasOffsetXValue_ = false;
1642     bool hasOffsetYValue_ = false;
1643 
ShadowsInfoShadowsInfo1644     ShadowsInfo() {}
ShadowsInfoShadowsInfo1645     ShadowsInfo(float radius, std::string color, float offsetX, float offsetY, bool hasRadiusValue,
1646         bool hasColorValue, bool hasOffsetXValue, bool hasOffsetYValue) : radius_(radius), color_(color),
1647         offsetX_(offsetX), offsetY_(offsetY), hasRadiusValue_(hasRadiusValue), hasColorValue_(hasColorValue),
1648         hasOffsetXValue_(hasOffsetXValue), hasOffsetYValue_(hasOffsetYValue) {}
1649 
1650     bool operator==(const ShadowsInfo& other) const
1651     {
1652         return (NearEqual(radius_, other.radius_) && color_ == other.color_ &&
1653             NearEqual(offsetX_, other.offsetX_) && NearEqual(offsetY_, other.offsetY_));
1654     }
1655 
1656     bool operator!=(const ShadowsInfo& other) const
1657     {
1658         return !this->operator==(other);
1659     }
1660 
NearEqualShadowsInfo1661     static inline bool NearEqual(float left, float right) { return std::abs(left - right) < POS_ZERO; }
1662 
MarshallingShadowsInfo1663     bool Marshalling(Parcel& parcel) const override
1664     {
1665         if (!parcel.WriteBool(hasRadiusValue_)) {
1666             return false;
1667         }
1668 
1669         if (!parcel.WriteBool(hasColorValue_)) {
1670             return false;
1671         }
1672 
1673         if (!parcel.WriteBool(hasOffsetXValue_)) {
1674             return false;
1675         }
1676 
1677         if (!parcel.WriteBool(hasOffsetYValue_)) {
1678             return false;
1679         }
1680 
1681         if (hasRadiusValue_ && !parcel.WriteFloat(radius_)) {
1682             return false;
1683         }
1684 
1685         if (hasColorValue_ && !parcel.WriteString(color_)) {
1686             return false;
1687         }
1688 
1689         if (hasOffsetXValue_ && !parcel.WriteFloat(offsetX_)) {
1690             return false;
1691         }
1692 
1693         if (hasOffsetYValue_ && !parcel.WriteFloat(offsetY_)) {
1694             return false;
1695         }
1696         return true;
1697     }
1698 
UnmarshallingShadowsInfo1699     static ShadowsInfo* Unmarshalling(Parcel& parcel)
1700     {
1701         ShadowsInfo* shadowsInfo = new ShadowsInfo();
1702         if (!parcel.ReadBool(shadowsInfo->hasRadiusValue_)) {
1703             delete shadowsInfo;
1704             return nullptr;
1705         }
1706 
1707         if (!parcel.ReadBool(shadowsInfo->hasColorValue_)) {
1708             delete shadowsInfo;
1709             return nullptr;
1710         }
1711 
1712         if (!parcel.ReadBool(shadowsInfo->hasOffsetXValue_)) {
1713             delete shadowsInfo;
1714             return nullptr;
1715         }
1716 
1717         if (!parcel.ReadBool(shadowsInfo->hasOffsetYValue_)) {
1718             delete shadowsInfo;
1719             return nullptr;
1720         }
1721 
1722         if (shadowsInfo->hasRadiusValue_ && !parcel.ReadFloat(shadowsInfo->radius_)) {
1723             delete shadowsInfo;
1724             return nullptr;
1725         }
1726 
1727         if (shadowsInfo->hasColorValue_ && !parcel.ReadString(shadowsInfo->color_)) {
1728             delete shadowsInfo;
1729             return nullptr;
1730         }
1731 
1732         if (shadowsInfo->hasOffsetXValue_ && !parcel.ReadFloat(shadowsInfo->offsetX_)) {
1733             delete shadowsInfo;
1734             return nullptr;
1735         }
1736 
1737         if (shadowsInfo->hasOffsetYValue_ && !parcel.ReadFloat(shadowsInfo->offsetY_)) {
1738             delete shadowsInfo;
1739             return nullptr;
1740         }
1741         return shadowsInfo;
1742     }
1743 };
1744 
1745 /**
1746  * @brief Enumerates source of sub session.
1747  */
1748 enum class SubWindowSource : uint32_t {
1749     SUB_WINDOW_SOURCE_UNKNOWN = 0,
1750     SUB_WINDOW_SOURCE_ARKUI = 1,
1751 };
1752 
1753 /**
1754  * @brief Screenshot event type.
1755  */
1756 enum class ScreenshotEventType : int32_t {
1757     START = 0,
1758 
1759     /**
1760      * System screenshot.
1761      */
1762     SYSTEM_SCREENSHOT = START,
1763 
1764     /**
1765      * System screenshot abort.
1766      */
1767     SYSTEM_SCREENSHOT_ABORT = 1,
1768 
1769     /**
1770      * Scroll shot start.
1771      */
1772     SCROLL_SHOT_START = 2,
1773 
1774     /**
1775      * Scroll shot end.
1776      */
1777     SCROLL_SHOT_END = 3,
1778 
1779     /**
1780      * Scroll shot abort.
1781      */
1782     SCROLL_SHOT_ABORT = 4,
1783 
1784     END,
1785 };
1786 }
1787 }
1788 #endif // OHOS_ROSEN_WM_COMMON_H
1789