• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <any>
20 #include <map>
21 #include <sstream>
22 #include <string>
23 #include <unordered_set>
24 #include <vector>
25 
26 #include <float.h>
27 
28 #include <parcel.h>
29 
30 #include "../dm/dm_common.h"
31 #include "securec.h"
32 #include "wm_math.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 int32_t DEFAULT_COLOR_MODE = -1;
42 constexpr int32_t MIN_COLOR_MODE = -1;
43 constexpr int32_t MAX_COLOR_MODE = 1;
44 constexpr int32_t LIGHT_COLOR_MODE = 0;
45 constexpr int32_t DARK_COLOR_MODE = 1;
46 constexpr uint32_t MIN_SPACING_BETWEEN_BUTTONS = 12;
47 constexpr uint32_t MAX_SPACING_BETWEEN_BUTTONS = 24;
48 constexpr uint32_t MIN_BUTTON_BACKGROUND_SIZE = 20;
49 constexpr uint32_t MAX_BUTTON_BACKGROUND_SIZE = 40;
50 constexpr uint32_t MIN_CLOSE_BUTTON_RIGHT_MARGIN = 8;
51 constexpr uint32_t MAX_CLOSE_BUTTON_RIGHT_MARGIN = 22;
52 constexpr int32_t API_VERSION_INVALID = -1;
53 /*
54  * PC Window Sidebar Blur
55  */
56 constexpr float SIDEBAR_BLUR_NUMBER_ZERO = 0.0f;
57 constexpr float SIDEBAR_DEFAULT_RADIUS_LIGHT = 57.0f;
58 constexpr float SIDEBAR_DEFAULT_RADIUS_DARK = 57.0f;
59 constexpr float SIDEBAR_DEFAULT_SATURATION_LIGHT = 2.0f;
60 constexpr float SIDEBAR_DEFAULT_SATURATION_DARK = 2.6f;
61 constexpr float SIDEBAR_DEFAULT_BRIGHTNESS_LIGHT = 1.0f;
62 constexpr float SIDEBAR_DEFAULT_BRIGHTNESS_DARK = 0.4f;
63 constexpr uint32_t SIDEBAR_DEFAULT_MASKCOLOR_LIGHT = 0xdbf1f1f1;
64 constexpr uint32_t SIDEBAR_DEFAULT_MASKCOLOR_DARK = 0xe61a1a1a;
65 constexpr uint32_t SIDEBAR_SNAPSHOT_MASKCOLOR_LIGHT = 0xffe5e5e5;
66 constexpr uint32_t SIDEBAR_SNAPSHOT_MASKCOLOR_DARK = 0xff414141;
67 }
68 
69 /**
70  * @brief Enumerates type of window.
71  */
72 enum class WindowType : uint32_t {
73     APP_WINDOW_BASE = 1,
74     APP_MAIN_WINDOW_BASE = APP_WINDOW_BASE,
75     WINDOW_TYPE_APP_MAIN_WINDOW = APP_MAIN_WINDOW_BASE,
76     APP_MAIN_WINDOW_END,
77 
78     APP_SUB_WINDOW_BASE = 1000,
79     WINDOW_TYPE_MEDIA = APP_SUB_WINDOW_BASE,
80     WINDOW_TYPE_APP_SUB_WINDOW,
81     WINDOW_TYPE_APP_COMPONENT,
82     APP_SUB_WINDOW_END,
83     APP_WINDOW_END = APP_SUB_WINDOW_END,
84 
85     SYSTEM_WINDOW_BASE = 2000,
86     BELOW_APP_SYSTEM_WINDOW_BASE = SYSTEM_WINDOW_BASE,
87     WINDOW_TYPE_WALLPAPER = SYSTEM_WINDOW_BASE,
88     WINDOW_TYPE_DESKTOP,
89     BELOW_APP_SYSTEM_WINDOW_END,
90 
91     ABOVE_APP_SYSTEM_WINDOW_BASE = 2100,
92     WINDOW_TYPE_APP_LAUNCHING = ABOVE_APP_SYSTEM_WINDOW_BASE,
93     WINDOW_TYPE_DOCK_SLICE,
94     WINDOW_TYPE_INCOMING_CALL,
95     WINDOW_TYPE_SEARCHING_BAR,
96     WINDOW_TYPE_SYSTEM_ALARM_WINDOW,
97     WINDOW_TYPE_INPUT_METHOD_FLOAT,
98     WINDOW_TYPE_FLOAT,
99     WINDOW_TYPE_TOAST,
100     WINDOW_TYPE_STATUS_BAR,
101     WINDOW_TYPE_PANEL,
102     WINDOW_TYPE_KEYGUARD,
103     WINDOW_TYPE_VOLUME_OVERLAY,
104     WINDOW_TYPE_NAVIGATION_BAR,
105     WINDOW_TYPE_DRAGGING_EFFECT,
106     WINDOW_TYPE_POINTER,
107     WINDOW_TYPE_LAUNCHER_RECENT,
108     WINDOW_TYPE_LAUNCHER_DOCK,
109     WINDOW_TYPE_BOOT_ANIMATION,
110     WINDOW_TYPE_FREEZE_DISPLAY,
111     WINDOW_TYPE_VOICE_INTERACTION,
112     WINDOW_TYPE_FLOAT_CAMERA,
113     WINDOW_TYPE_PLACEHOLDER,
114     WINDOW_TYPE_DIALOG,
115     WINDOW_TYPE_SCREENSHOT,
116     WINDOW_TYPE_INPUT_METHOD_STATUS_BAR,
117     WINDOW_TYPE_GLOBAL_SEARCH,
118     WINDOW_TYPE_NEGATIVE_SCREEN,
119     WINDOW_TYPE_SYSTEM_TOAST,
120     WINDOW_TYPE_SYSTEM_FLOAT,
121     WINDOW_TYPE_PIP,
122     WINDOW_TYPE_THEME_EDITOR,
123     WINDOW_TYPE_NAVIGATION_INDICATOR,
124     WINDOW_TYPE_HANDWRITE,
125     WINDOW_TYPE_SCENE_BOARD,
126     WINDOW_TYPE_KEYBOARD_PANEL,
127     WINDOW_TYPE_SCB_DEFAULT,
128     WINDOW_TYPE_TRANSPARENT_VIEW,
129     WINDOW_TYPE_WALLET_SWIPE_CARD,
130     WINDOW_TYPE_SCREEN_CONTROL,
131     WINDOW_TYPE_FLOAT_NAVIGATION,
132     ABOVE_APP_SYSTEM_WINDOW_END,
133 
134     SYSTEM_SUB_WINDOW_BASE = 2500,
135     WINDOW_TYPE_SYSTEM_SUB_WINDOW = SYSTEM_SUB_WINDOW_BASE,
136     SYSTEM_SUB_WINDOW_END,
137 
138     SYSTEM_WINDOW_END = SYSTEM_SUB_WINDOW_END,
139 
140     WINDOW_TYPE_UI_EXTENSION = 3000
141 };
142 
143 /**
144  * @struct HookInfo.
145  *
146  * @brief hook diaplayinfo deepending on the window size.
147  */
148 struct HookInfo {
149     uint32_t width_;
150     uint32_t height_;
151     float_t density_;
152     uint32_t rotation_;
153     bool enableHookRotation_;
154 };
155 
156 /**
157  * @brief Enumerates mode of window.
158  */
159 enum class WindowMode : uint32_t {
160     WINDOW_MODE_UNDEFINED = 0,
161     WINDOW_MODE_FULLSCREEN = 1,
162     WINDOW_MODE_SPLIT_PRIMARY = 100,
163     WINDOW_MODE_SPLIT_SECONDARY,
164     WINDOW_MODE_FLOATING,
165     WINDOW_MODE_PIP,
166     END = WINDOW_MODE_PIP,
167 };
168 
169 /**
170  * @brief Enumerates modeType of window.
171  */
172 enum class WindowModeType : uint8_t {
173     WINDOW_MODE_SPLIT_FLOATING = 0,
174     WINDOW_MODE_SPLIT = 1,
175     WINDOW_MODE_FLOATING = 2,
176     WINDOW_MODE_FULLSCREEN = 3,
177     WINDOW_MODE_FULLSCREEN_FLOATING = 4,
178     WINDOW_MODE_OTHER = 5
179 };
180 
181 /**
182  * @brief Enumerates modal of sub session.
183  */
184 enum class SubWindowModalType : uint32_t {
185     BEGIN = 0,
186     TYPE_UNDEFINED = BEGIN,
187     TYPE_NORMAL,
188     TYPE_DIALOG,
189     TYPE_WINDOW_MODALITY,
190     TYPE_TOAST,
191     TYPE_APPLICATION_MODALITY,
192     TYPE_TEXT_MENU,
193     END = TYPE_TEXT_MENU,
194 };
195 
196 /**
197  * @brief Enumerates mode supported of window.
198  */
199 enum WindowModeSupport : uint32_t {
200     WINDOW_MODE_SUPPORT_FULLSCREEN = 1 << 0,
201     WINDOW_MODE_SUPPORT_FLOATING = 1 << 1,
202     WINDOW_MODE_SUPPORT_SPLIT_PRIMARY = 1 << 2,
203     WINDOW_MODE_SUPPORT_SPLIT_SECONDARY = 1 << 3,
204     WINDOW_MODE_SUPPORT_PIP = 1 << 4,
205     WINDOW_MODE_SUPPORT_ALL = WINDOW_MODE_SUPPORT_FULLSCREEN |
206                               WINDOW_MODE_SUPPORT_SPLIT_PRIMARY |
207                               WINDOW_MODE_SUPPORT_SPLIT_SECONDARY |
208                               WINDOW_MODE_SUPPORT_FLOATING |
209                               WINDOW_MODE_SUPPORT_PIP
210 };
211 
212 /**
213  * @brief Enumerates blur style of window.
214  */
215 enum class WindowBlurStyle : uint32_t {
216     WINDOW_BLUR_OFF = 0,
217     WINDOW_BLUR_THIN,
218     WINDOW_BLUR_REGULAR,
219     WINDOW_BLUR_THICK
220 };
221 
222 /**
223  * @brief Enumerates cross axis state of window.
224  */
225 enum class CrossAxisState : uint32_t {
226     STATE_INVALID = 0,
227     STATE_CROSS,
228     STATE_NO_CROSS,
229     STATE_END,
230 };
231 
232 /**
233  * @brief Enumerates state of window.
234  */
235 enum class WindowState : uint32_t {
236     STATE_INITIAL,
237     STATE_CREATED,
238     STATE_SHOWN,
239     STATE_HIDDEN,
240     STATE_FROZEN,
241     STATE_UNFROZEN,
242     STATE_DESTROYED,
243     STATE_BOTTOM = STATE_DESTROYED, // Add state type after STATE_DESTROYED is not allowed
244 };
245 
246 /**
247  * @brief Enumerates error code of window.
248  */
249 enum class WMError : int32_t {
250     WM_OK = 0,
251     WM_DO_NOTHING,
252     WM_ERROR_NO_MEM,
253     WM_ERROR_DESTROYED_OBJECT,
254     WM_ERROR_INVALID_WINDOW,
255     WM_ERROR_INVALID_WINDOW_MODE_OR_SIZE,
256     WM_ERROR_INVALID_OPERATION,
257     WM_ERROR_INVALID_PERMISSION,
258     WM_ERROR_NOT_SYSTEM_APP,
259     WM_ERROR_NO_REMOTE_ANIMATION,
260     WM_ERROR_INVALID_DISPLAY,
261     WM_ERROR_INVALID_PARENT,
262     WM_ERROR_INVALID_OP_IN_CUR_STATUS,
263     WM_ERROR_REPEAT_OPERATION,
264     WM_ERROR_INVALID_SESSION,
265     WM_ERROR_INVALID_CALLING,
266     WM_ERROR_SYSTEM_ABNORMALLY,
267 
268     WM_ERROR_DEVICE_NOT_SUPPORT = 801, // the value do not change.It is defined on all system
269 
270     WM_ERROR_NEED_REPORT_BASE = 1000, // error code > 1000 means need report
271     WM_ERROR_NULLPTR,
272     WM_ERROR_INVALID_TYPE,
273     WM_ERROR_INVALID_PARAM,
274     WM_ERROR_SAMGR,
275     WM_ERROR_IPC_FAILED,
276     WM_ERROR_NEED_REPORT_END,
277     WM_ERROR_START_ABILITY_FAILED,
278     WM_ERROR_PIP_DESTROY_FAILED,
279     WM_ERROR_PIP_STATE_ABNORMALLY,
280     WM_ERROR_PIP_CREATE_FAILED,
281     WM_ERROR_PIP_INTERNAL_ERROR,
282     WM_ERROR_PIP_REPEAT_OPERATION,
283 };
284 
285 /**
286  * @brief Enumerates error code of window only used for js api.
287  */
288 enum class WmErrorCode : int32_t {
289     WM_OK = 0,
290     WM_ERROR_NO_PERMISSION = 201,
291     WM_ERROR_NOT_SYSTEM_APP = 202,
292     WM_ERROR_INVALID_PARAM = 401,
293     WM_ERROR_DEVICE_NOT_SUPPORT = 801,
294     WM_ERROR_REPEAT_OPERATION = 1300001,
295     WM_ERROR_STATE_ABNORMALLY = 1300002,
296     WM_ERROR_SYSTEM_ABNORMALLY = 1300003,
297     WM_ERROR_INVALID_CALLING = 1300004,
298     WM_ERROR_STAGE_ABNORMALLY = 1300005,
299     WM_ERROR_CONTEXT_ABNORMALLY = 1300006,
300     WM_ERROR_START_ABILITY_FAILED = 1300007,
301     WM_ERROR_INVALID_DISPLAY = 1300008,
302     WM_ERROR_INVALID_PARENT = 1300009,
303     WM_ERROR_INVALID_OP_IN_CUR_STATUS = 1300010,
304     WM_ERROR_PIP_DESTROY_FAILED = 1300011,
305     WM_ERROR_PIP_STATE_ABNORMALLY = 1300012,
306     WM_ERROR_PIP_CREATE_FAILED = 1300013,
307     WM_ERROR_PIP_INTERNAL_ERROR = 1300014,
308     WM_ERROR_PIP_REPEAT_OPERATION = 1300015,
309 };
310 
311 /**
312  * @brief Enumerates status of window.
313  */
314 enum class WindowStatus : uint32_t {
315     WINDOW_STATUS_UNDEFINED = 0,
316     WINDOW_STATUS_FULLSCREEN = 1,
317     WINDOW_STATUS_MAXIMIZE,
318     WINDOW_STATUS_MINIMIZE,
319     WINDOW_STATUS_FLOATING,
320     WINDOW_STATUS_SPLITSCREEN
321 };
322 
323 /**
324  * @brief Enumerates setting flag of systemStatusBar
325  */
326 enum class SystemBarSettingFlag : uint32_t {
327     DEFAULT_SETTING = 0,
328     COLOR_SETTING = 1,
329     ENABLE_SETTING = 1 << 1,
330     ALL_SETTING = COLOR_SETTING | ENABLE_SETTING,
331     FOLLOW_SETTING = 1 << 2
332 };
333 
334 inline SystemBarSettingFlag operator|(SystemBarSettingFlag lhs, SystemBarSettingFlag rhs)
335 {
336     using T = std::underlying_type_t<SystemBarSettingFlag>;
337     return static_cast<SystemBarSettingFlag>(static_cast<T>(lhs) | static_cast<T>(rhs));
338 }
339 
340 inline SystemBarSettingFlag& operator|=
341     (SystemBarSettingFlag& lhs, SystemBarSettingFlag rhs) { return lhs = lhs | rhs; }
342 
343 /**
344  * @brief Enumerates flag of ControlAppType.
345  */
346 enum class ControlAppType : uint8_t {
347     CONTROL_APP_TYPE_BEGIN = 0,
348     APP_LOCK = 1,
349     PARENT_CONTROL,
350     CONTROL_APP_TYPE_END,
351 };
352 
353 /**
354  * @brief Enumerates flag of multiWindowUIType.
355  */
356 enum class WindowUIType : uint8_t {
357     PHONE_WINDOW = 0,
358     PC_WINDOW,
359     PAD_WINDOW,
360     INVALID_WINDOW
361 };
362 
363 /**
364  * @brief Used to map from WMError to WmErrorCode.
365  */
366 extern const std::map<WMError, WmErrorCode> WM_JS_TO_ERROR_CODE_MAP;
367 
368 /**
369  * @brief Enumerates flag of window.
370  */
371 enum class WindowFlag : uint32_t {
372     WINDOW_FLAG_NEED_AVOID = 1,
373     WINDOW_FLAG_PARENT_LIMIT = 1 << 1,
374     WINDOW_FLAG_SHOW_WHEN_LOCKED = 1 << 2,
375     WINDOW_FLAG_FORBID_SPLIT_MOVE = 1 << 3,
376     WINDOW_FLAG_WATER_MARK = 1 << 4,
377     WINDOW_FLAG_IS_MODAL = 1 << 5,
378     WINDOW_FLAG_HANDWRITING = 1 << 6,
379     WINDOW_FLAG_IS_TOAST = 1 << 7,
380     WINDOW_FLAG_IS_APPLICATION_MODAL = 1 << 8,
381     WINDOW_FLAG_IS_TEXT_MENU = 1 << 9,
382     WINDOW_FLAG_END = 1 << 10,
383 };
384 
385 /**
386  * @brief Enumerates system and app sub window avoid area options
387  */
388 enum class AvoidAreaOption : uint32_t {
389     ENABLE_SYSTEM_WINDOW = 1,
390     ENABLE_APP_SUB_WINDOW = 1 << 1,
391 };
392 
393 /**
394  * @brief Flag of uiextension window.
395  */
396 union ExtensionWindowFlags {
397     uint32_t bitData;
398     struct {
399         // Each flag should be false default, true when active
400         bool hideNonSecureWindowsFlag : 1;
401         bool waterMarkFlag : 1;
402         bool privacyModeFlag : 1;
403     };
ExtensionWindowFlags()404     ExtensionWindowFlags() : bitData(0) {}
ExtensionWindowFlags(uint32_t bits)405     ExtensionWindowFlags(uint32_t bits) : bitData(bits) {}
~ExtensionWindowFlags()406     ~ExtensionWindowFlags() {}
SetAllActive()407     void SetAllActive()
408     {
409         hideNonSecureWindowsFlag = true;
410         waterMarkFlag = true;
411         privacyModeFlag = true;
412     }
413 };
414 
415 /**
416  * @brief Enumerates window size change reason.
417  */
418 enum class WindowSizeChangeReason : uint32_t {
419     UNDEFINED = 0,
420     MAXIMIZE,
421     RECOVER,
422     ROTATION,
423     DRAG,
424     DRAG_START,
425     DRAG_END,
426     RESIZE,
427     RESIZE_WITH_ANIMATION,
428     MOVE,
429     MOVE_WITH_ANIMATION,
430     HIDE,
431     TRANSFORM,
432     CUSTOM_ANIMATION_SHOW,
433     FULL_TO_SPLIT,
434     SPLIT_TO_FULL,
435     FULL_TO_FLOATING,
436     FLOATING_TO_FULL,
437     PIP_START,
438     PIP_SHOW,
439     PIP_AUTO_START,
440     PIP_RATIO_CHANGE,
441     PIP_RESTORE,
442     UPDATE_DPI_SYNC,
443     DRAG_MOVE,
444     AVOID_AREA_CHANGE,
445     MAXIMIZE_TO_SPLIT,
446     SPLIT_TO_MAXIMIZE,
447     END,
448 };
449 
IsMoveToOrDragMove(WindowSizeChangeReason reason)450 inline bool IsMoveToOrDragMove(WindowSizeChangeReason reason)
451 {
452     return reason == WindowSizeChangeReason::MOVE || reason == WindowSizeChangeReason::DRAG_MOVE;
453 }
454 
455 /**
456  * @brief Enumerates layout mode of window.
457  */
458 enum class WindowLayoutMode : uint32_t {
459     BASE = 0,
460     CASCADE = BASE,
461     TILE = 1,
462     END,
463 };
464 
465 /**
466  * @brief Enumerates drag event.
467  */
468 enum class DragEvent : uint32_t {
469     DRAG_EVENT_IN  = 1,
470     DRAG_EVENT_OUT,
471     DRAG_EVENT_MOVE,
472     DRAG_EVENT_END,
473 };
474 
475 /**
476  * @brief Enumerates drag resize type.
477  */
478 enum class DragResizeType : uint32_t {
479     RESIZE_TYPE_UNDEFINED = 0,
480     RESIZE_EACH_FRAME = 1,
481     RESIZE_WHEN_DRAG_END = 2,
482 };
483 
484 /**
485  * @brief Enumerates window tag.
486  */
487 enum class WindowTag : uint32_t {
488     MAIN_WINDOW = 0,
489     SUB_WINDOW = 1,
490     SYSTEM_WINDOW = 2,
491 };
492 
493 /**
494  * @brief Enumerates window session type.
495  */
496 enum class WindowSessionType : uint32_t {
497     SCENE_SESSION = 0,
498     EXTENSION_SESSION = 1,
499 };
500 
501 /**
502  * @brief Enumerates window gravity.
503  */
504 enum class WindowGravity : uint32_t {
505     WINDOW_GRAVITY_FLOAT = 0,
506     WINDOW_GRAVITY_BOTTOM,
507     WINDOW_GRAVITY_DEFAULT,
508 };
509 
510 /**
511  * @brief Enumerates window setuicontent type.
512  */
513 enum class WindowSetUIContentType : uint32_t {
514     DEFAULT,
515     RESTORE,
516     BY_NAME,
517     BY_ABC,
518 };
519 
520 /**
521  * @brief Enumerates restore type.
522  */
523 enum class BackupAndRestoreType : int32_t {
524     NONE = 0,                       // no backup and restore
525     CONTINUATION = 1,               // distribute
526     APP_RECOVERY = 2,               // app recovery
527     RESOURCESCHEDULE_RECOVERY = 3,  // app is killed due to resource schedule
528 };
529 
530 /**
531  * @brief Enumerates window Style type.
532  */
533 enum class WindowStyleType : uint8_t {
534     WINDOW_STYLE_DEFAULT = 0,
535     WINDOW_STYLE_FREE_MULTI_WINDOW = 1,
536 };
537 
538 /**
539  * @brief Disable Gesture Back Type
540  */
541 enum class GestureBackType : uint8_t {
542     GESTURE_SIDE = 0,
543     GESTURE_SWIPE_UP = 1,
544     GESTURE_ALL = 2,
545 };
546 
547 /**
548  * @struct PointInfo.
549  *
550  * @brief point Info.
551  */
552 struct PointInfo {
553     int32_t x;
554     int32_t y;
555 };
556 
557 /**
558  * @struct MainWindowInfo.
559  *
560  * @brief topN main window info.
561  */
562 struct MainWindowInfo : public Parcelable {
MarshallingMainWindowInfo563     virtual bool Marshalling(Parcel& parcel) const override
564     {
565         if (!parcel.WriteInt32(pid_)) {
566             return false;
567         }
568 
569         if (!parcel.WriteString(bundleName_)) {
570             return false;
571         }
572 
573         if (!parcel.WriteInt32(persistentId_)) {
574             return false;
575         }
576 
577         if (!parcel.WriteInt32(bundleType_)) {
578             return false;
579         }
580         return true;
581     }
582 
UnmarshallingMainWindowInfo583     static MainWindowInfo* Unmarshalling(Parcel& parcel)
584     {
585         MainWindowInfo* mainWindowInfo = new MainWindowInfo;
586         mainWindowInfo->pid_ = parcel.ReadInt32();
587         mainWindowInfo->bundleName_ = parcel.ReadString();
588         mainWindowInfo->persistentId_ = parcel.ReadInt32();
589         mainWindowInfo->bundleType_ = parcel.ReadInt32();
590         return mainWindowInfo;
591     }
592 
593     int32_t pid_ = 0;
594     std::string bundleName_ = "";
595     int32_t persistentId_ = 0;
596     int32_t bundleType_ = 0;
597 };
598 
599 /**
600  * @struct MainWindowState.
601  *
602  * @brief main window state info.
603  */
604 struct MainWindowState : public Parcelable {
MarshallingMainWindowState605     bool Marshalling(Parcel& parcel) const override
606     {
607         if (!parcel.WriteInt32(state_)) {
608             return false;
609         }
610         if (!parcel.WriteBool(isVisible_)) {
611             return false;
612         }
613         if (!parcel.WriteBool(isForegroundInteractive_)) {
614             return false;
615         }
616         if (!parcel.WriteBool(isPcOrPadEnableActivation_)) {
617             return false;
618         }
619         return true;
620     }
621 
UnmarshallingMainWindowState622     static MainWindowState* Unmarshalling(Parcel& parcel)
623     {
624         MainWindowState* mainWindowState = new MainWindowState();
625         if (!mainWindowState) {
626             return nullptr;
627         }
628         if (!parcel.ReadInt32(mainWindowState->state_) ||
629             !parcel.ReadBool(mainWindowState->isVisible_) ||
630             !parcel.ReadBool(mainWindowState->isForegroundInteractive_) ||
631             !parcel.ReadBool(mainWindowState->isPcOrPadEnableActivation_)) {
632             delete mainWindowState;
633             return nullptr;
634         }
635         return mainWindowState;
636     }
637 
638     int32_t state_ = 0;
639     bool isVisible_ = false;
640     bool isForegroundInteractive_ = false;
641     bool isPcOrPadEnableActivation_ = false;
642 };
643 
644 namespace {
645 constexpr uint32_t SYSTEM_COLOR_WHITE = 0xE5FFFFFF;
646 constexpr uint32_t SYSTEM_COLOR_BLACK = 0x66000000;
647 constexpr uint32_t INVALID_WINDOW_ID = 0;
648 constexpr float UNDEFINED_BRIGHTNESS = -1.0f;
649 constexpr float MINIMUM_BRIGHTNESS = 0.0f;
650 constexpr float MAXIMUM_BRIGHTNESS = 1.0f;
651 constexpr int32_t INVALID_PID = -1;
652 constexpr int32_t INVALID_UID = -1;
653 constexpr int32_t INVALID_USER_ID = -1;
654 constexpr int32_t SYSTEM_USERID = 0;
655 constexpr int32_t BASE_USER_RANGE = 200000;
656 constexpr int32_t DEFAULT_SCREEN_ID = 0;
657 constexpr int32_t FULL_CIRCLE_DEGREE = 360;
658 constexpr int32_t ONE_FOURTH_FULL_CIRCLE_DEGREE = 90;
659 constexpr float UNDEFINED_DENSITY = -1.0f;
660 constexpr float MINIMUM_CUSTOM_DENSITY = 0.5f;
661 constexpr float MAXIMUM_CUSTOM_DENSITY = 4.0f;
662 constexpr int32_t MINIMUM_Z_LEVEL = -10000;
663 constexpr int32_t MAXIMUM_Z_LEVEL = 10000;
664 constexpr int32_t NORMAL_SUB_WINDOW_Z_LEVEL = 0;
665 constexpr int32_t MODALITY_SUB_WINDOW_Z_LEVEL = 13000;
666 constexpr int32_t DIALOG_SUB_WINDOW_Z_LEVEL = 13000;
667 constexpr int32_t TEXT_MENU_SUB_WINDOW_Z_LEVEL = 13500;
668 constexpr int32_t TOAST_SUB_WINDOW_Z_LEVEL = 14000;
669 constexpr int32_t APPLICATION_MODALITY_SUB_WINDOW_Z_LEVEL = 20000;
670 constexpr int32_t TOPMOST_SUB_WINDOW_Z_LEVEL = 2000;
671 }
672 
GetUserIdByUid(int32_t uid)673 inline int32_t GetUserIdByUid(int32_t uid)
674 {
675     return uid / BASE_USER_RANGE;
676 }
677 
678 /**
679  * @class Transform
680  *
681  * @brief parameter of transform and rotate.
682  */
683 class Transform {
684 public:
Transform()685     Transform()
686         : pivotX_(0.5f), pivotY_(0.5f), scaleX_(1.f), scaleY_(1.f), scaleZ_(1.f), rotationX_(0.f),
687           rotationY_(0.f), rotationZ_(0.f), translateX_(0.f), translateY_(0.f), translateZ_(0.f)
688     {}
~Transform()689     ~Transform() {}
690 
691     bool operator==(const Transform& right) const
692     {
693         return NearZero(pivotX_ - right.pivotX_) &&
694             NearZero(pivotY_ - right.pivotY_) &&
695             NearZero(scaleX_ - right.scaleX_) &&
696             NearZero(scaleY_ - right.scaleY_) &&
697             NearZero(scaleZ_ - right.scaleZ_) &&
698             NearZero(rotationX_ - right.rotationX_) &&
699             NearZero(rotationY_ - right.rotationY_) &&
700             NearZero(rotationZ_ - right.rotationZ_) &&
701             NearZero(translateX_ - right.translateX_) &&
702             NearZero(translateY_ - right.translateY_) &&
703             NearZero(translateZ_ - right.translateZ_);
704     }
705 
706     bool operator!=(const Transform& right) const
707     {
708         return !(*this == right);
709     }
710 
711     float pivotX_;
712     float pivotY_;
713     float scaleX_;
714     float scaleY_;
715     float scaleZ_;
716     float rotationX_;
717     float rotationY_;
718     float rotationZ_;
719     float translateX_;
720     float translateY_;
721     float translateZ_;
722 
Identity()723     static const Transform& Identity()
724     {
725         static Transform I;
726         return I;
727     }
728 
Marshalling(Parcel & parcel)729     bool Marshalling(Parcel& parcel) const
730     {
731         return parcel.WriteFloat(pivotX_) && parcel.WriteFloat(pivotY_) &&
732                parcel.WriteFloat(scaleX_) && parcel.WriteFloat(scaleY_) && parcel.WriteFloat(scaleZ_) &&
733                parcel.WriteFloat(rotationX_) && parcel.WriteFloat(rotationY_) && parcel.WriteFloat(rotationZ_) &&
734                parcel.WriteFloat(translateX_) && parcel.WriteFloat(translateY_) && parcel.WriteFloat(translateZ_);
735     }
736 
Unmarshalling(Parcel & parcel)737     void Unmarshalling(Parcel& parcel)
738     {
739         pivotX_ = parcel.ReadFloat();
740         pivotY_ = parcel.ReadFloat();
741         scaleX_ = parcel.ReadFloat();
742         scaleY_ = parcel.ReadFloat();
743         scaleZ_ = parcel.ReadFloat();
744         rotationX_ = parcel.ReadFloat();
745         rotationY_ = parcel.ReadFloat();
746         rotationZ_ = parcel.ReadFloat();
747         translateX_ = parcel.ReadFloat();
748         translateY_ = parcel.ReadFloat();
749         translateZ_ = parcel.ReadFloat();
750     }
751 private:
NearZero(float val)752     static inline bool NearZero(float val)
753     {
754         return val < 0.001f && val > -0.001f;
755     }
756 };
757 
758 /**
759  * @struct SingleHandTransform
760  *
761  * @brief parameter of transform in single hand mode.
762  */
763 struct SingleHandTransform {
764     int32_t posX = 0;
765     int32_t posY = 0;
766     float scaleX = 1.0f;
767     float scaleY = 1.0f;
768 
769     bool operator==(const SingleHandTransform& right) const
770     {
771         return posX == right.posX && MathHelper::NearEqual(scaleX, right.scaleX) &&
772                posY == right.posY && MathHelper::NearEqual(scaleY, right.scaleY);
773     }
774 
775     bool operator!=(const SingleHandTransform& right) const
776     {
777         return !(*this == right);
778     }
779 
MarshallingSingleHandTransform780     bool Marshalling(Parcel& parcel) const
781     {
782         return parcel.WriteInt32(posX) && parcel.WriteInt32(posY) &&
783                parcel.WriteFloat(scaleX) && parcel.WriteFloat(scaleY);
784     }
785 
UnmarshallingSingleHandTransform786     void Unmarshalling(Parcel& parcel)
787     {
788         posX = parcel.ReadInt32();
789         posY = parcel.ReadInt32();
790         scaleX = parcel.ReadFloat();
791         scaleY = parcel.ReadFloat();
792     }
793 };
794 
795 /**
796  * @struct SystemBarProperty
797  *
798  * @brief Property of system bar
799  */
800 struct SystemBarProperty {
801     bool enable_;
802     uint32_t backgroundColor_;
803     uint32_t contentColor_;
804     bool enableAnimation_;
805     SystemBarSettingFlag settingFlag_;
SystemBarPropertySystemBarProperty806     SystemBarProperty() : enable_(true), backgroundColor_(SYSTEM_COLOR_BLACK), contentColor_(SYSTEM_COLOR_WHITE),
807                           enableAnimation_(false), settingFlag_(SystemBarSettingFlag::DEFAULT_SETTING) {}
SystemBarPropertySystemBarProperty808     SystemBarProperty(bool enable, uint32_t background, uint32_t content)
809         : enable_(enable), backgroundColor_(background), contentColor_(content), enableAnimation_(false),
810           settingFlag_(SystemBarSettingFlag::DEFAULT_SETTING) {}
SystemBarPropertySystemBarProperty811     SystemBarProperty(bool enable, uint32_t background, uint32_t content, bool enableAnimation)
812         : enable_(enable), backgroundColor_(background), contentColor_(content), enableAnimation_(enableAnimation),
813           settingFlag_(SystemBarSettingFlag::DEFAULT_SETTING) {}
SystemBarPropertySystemBarProperty814     SystemBarProperty(bool enable, uint32_t background, uint32_t content,
815                       bool enableAnimation, SystemBarSettingFlag settingFlag)
816         : enable_(enable), backgroundColor_(background), contentColor_(content), enableAnimation_(enableAnimation),
817           settingFlag_(settingFlag) {}
818     bool operator == (const SystemBarProperty& a) const
819     {
820         return (enable_ == a.enable_ && backgroundColor_ == a.backgroundColor_ && contentColor_ == a.contentColor_ &&
821             enableAnimation_ == a.enableAnimation_);
822     }
823 };
824 
825 /**
826  * @struct SystemBarPropertyFlag
827  *
828  * @brief Flag of system bar
829  */
830 struct SystemBarPropertyFlag {
831     bool enableFlag = false;
832     bool backgroundColorFlag = false;
833     bool contentColorFlag = false;
834     bool enableAnimationFlag = false;
835 };
836 
837 /**
838  * @struct Rect
839  *
840  * @brief Window Rect
841  */
842 struct Rect {
843     int32_t posX_;
844     int32_t posY_;
845     uint32_t width_;
846     uint32_t height_;
847 
848     bool operator==(const Rect& a) const
849     {
850         return (posX_ == a.posX_ && posY_ == a.posY_ && width_ == a.width_ && height_ == a.height_);
851     }
852 
853     bool operator!=(const Rect& a) const
854     {
855         return !this->operator==(a);
856     }
857 
IsUninitializedRectRect858     bool IsUninitializedRect() const
859     {
860         return (posX_ == 0 && posY_ == 0 && width_ == 0 && height_ == 0);
861     }
862 
IsUninitializedSizeRect863     bool IsUninitializedSize() const
864     {
865         return width_ == 0 && height_ == 0;
866     }
867 
IsInsideOfRect868     bool IsInsideOf(const Rect& a) const
869     {
870         return (posX_ >= a.posX_ && posY_ >= a.posY_ &&
871             posX_ + width_ <= a.posX_ + a.width_ && posY_ + height_ <= a.posY_ + a.height_);
872     }
873 
ToStringRect874     inline std::string ToString() const
875     {
876         std::ostringstream oss;
877         oss << "[" << posX_ << " " << posY_ << " " << width_ << " " << height_ << "]";
878         return oss.str();
879     }
880 
881     static const Rect EMPTY_RECT;
882 };
883 
884 inline constexpr Rect Rect::EMPTY_RECT { 0, 0, 0, 0 };
885 
886 /**
887  * @struct RectAnimationConfig
888  *
889  * @brief Window RectAnimationConfig
890  */
891 struct RectAnimationConfig {
892     uint32_t duration = 0; // Duartion of the animation, in milliseconds.
893     float x1 = 0.0f;       // X coordinate of the first point on the Bezier curve.
894     float y1 = 0.0f;       // Y coordinate of the first point on the Bezier curve.
895     float x2 = 0.0f;       // X coordinate of the second point on the Bezier curve.
896     float y2 = 0.0f;       // Y coordinate of the second point on the Bezier curve.
897 };
898 
899 /**
900  * @brief UIExtension usage
901  */
902 enum class UIExtensionUsage : uint32_t {
903     MODAL = 0,
904     EMBEDDED,
905     CONSTRAINED_EMBEDDED,
906     UIEXTENSION_USAGE_END
907 };
908 
909 /**
910  * @brief UIExtension info for event
911  */
912 struct ExtensionWindowEventInfo {
913     int32_t persistentId = 0;
914     int32_t pid = -1;
915     Rect windowRect { 0, 0, 0, 0 }; // Calculated from global rect and UIExtension windowRect
916     Rect uiExtRect { 0, 0, 0, 0 };  // Transferred from arkUI
917     bool hasUpdatedRect = false;
918     bool isConstrainedModal = false;
919 };
920 
921 /**
922  * @brief UIExtension info from ability
923  */
924 struct ExtensionWindowAbilityInfo {
925     int32_t persistentId  { 0 };
926     int32_t parentId { 0 };
927     UIExtensionUsage usage { UIExtensionUsage::UIEXTENSION_USAGE_END };
928 };
929 
930 /**
931  * @struct KeyboardPanelInfo
932  *
933  * @brief Info of keyboard panel
934  */
935 struct KeyboardPanelInfo : public Parcelable {
936     Rect rect_ = {0, 0, 0, 0};
937     Rect beginRect_ = {0, 0, 0, 0};
938     Rect endRect_ = {0, 0, 0, 0};
939     WindowGravity gravity_ = WindowGravity::WINDOW_GRAVITY_BOTTOM;
940     bool isShowing_ = false;
941 
MarshallingKeyboardPanelInfo942     bool Marshalling(Parcel& parcel) const
943     {
944         return parcel.WriteInt32(rect_.posX_) && parcel.WriteInt32(rect_.posY_) &&
945                parcel.WriteUint32(rect_.width_) && parcel.WriteUint32(rect_.height_) &&
946                parcel.WriteInt32(beginRect_.posX_) && parcel.WriteInt32(beginRect_.posY_) &&
947                parcel.WriteUint32(beginRect_.width_) && parcel.WriteUint32(beginRect_.height_) &&
948                parcel.WriteInt32(endRect_.posX_) && parcel.WriteInt32(endRect_.posY_) &&
949                parcel.WriteUint32(endRect_.width_) && parcel.WriteUint32(endRect_.height_) &&
950                parcel.WriteUint32(static_cast<uint32_t>(gravity_)) && parcel.WriteBool(isShowing_);
951     }
952 
UnmarshallingKeyboardPanelInfo953     static KeyboardPanelInfo* Unmarshalling(Parcel& parcel)
954     {
955         KeyboardPanelInfo* panelInfo = new KeyboardPanelInfo;
956         bool res = parcel.ReadInt32(panelInfo->rect_.posX_) && parcel.ReadInt32(panelInfo->rect_.posY_) &&
957             parcel.ReadUint32(panelInfo->rect_.width_) && parcel.ReadUint32(panelInfo->rect_.height_) &&
958             parcel.ReadInt32(panelInfo->beginRect_.posX_) && parcel.ReadInt32(panelInfo->beginRect_.posY_) &&
959             parcel.ReadUint32(panelInfo->beginRect_.width_) && parcel.ReadUint32(panelInfo->beginRect_.height_) &&
960             parcel.ReadInt32(panelInfo->endRect_.posX_) && parcel.ReadInt32(panelInfo->endRect_.posY_) &&
961             parcel.ReadUint32(panelInfo->endRect_.width_) && parcel.ReadUint32(panelInfo->endRect_.height_);
962         if (!res) {
963             delete panelInfo;
964             return nullptr;
965         }
966         panelInfo->gravity_ = static_cast<WindowGravity>(parcel.ReadUint32());
967         panelInfo->isShowing_ = parcel.ReadBool();
968 
969         return panelInfo;
970     }
971 };
972 
973 /**
974  * @struct CallingWindowInfo
975  *
976  * @brief Information of keyboard calling window.
977  */
978 struct CallingWindowInfo : public Parcelable {
979     int32_t windowId_ = 0;
980     int32_t callingPid_ = -1;
981     DisplayId displayId_ = 0;
982     int32_t userId_ = 0;
983 
CallingWindowInfoCallingWindowInfo984     CallingWindowInfo() {}
CallingWindowInfoCallingWindowInfo985     CallingWindowInfo(int32_t windowId, int32_t callingPid, DisplayId displayId, int32_t userId)
986         : windowId_(windowId), callingPid_(callingPid), displayId_(displayId), userId_(userId) {}
987 
MarshallingCallingWindowInfo988     bool Marshalling(Parcel& parcel) const
989     {
990         return parcel.WriteInt32(windowId_) && parcel.WriteInt32(callingPid_) &&
991                parcel.WriteUint64(displayId_) && parcel.WriteInt32(userId_);
992     }
993 
UnmarshallingCallingWindowInfo994     static CallingWindowInfo* Unmarshalling(Parcel& parcel)
995     {
996         CallingWindowInfo* callingWindowInfo = new CallingWindowInfo();
997         bool res = parcel.ReadInt32(callingWindowInfo->windowId_) && parcel.ReadInt32(callingWindowInfo->callingPid_) &&
998                    parcel.ReadUint64(callingWindowInfo->displayId_) && parcel.ReadInt32(callingWindowInfo->userId_);
999         if (!res) {
1000             delete callingWindowInfo;
1001             return nullptr;
1002         }
1003         return callingWindowInfo;
1004     }
1005 };
1006 
1007 /**
1008  * @brief Enumerates avoid area type.
1009  */
1010 enum class AvoidAreaType : uint32_t {
1011     TYPE_START = 0,
1012     TYPE_SYSTEM = TYPE_START,           // area of SystemUI
1013     TYPE_CUTOUT,                        // cutout of screen
1014     TYPE_SYSTEM_GESTURE,                // area for system gesture
1015     TYPE_KEYBOARD,                      // area for soft input keyboard
1016     TYPE_NAVIGATION_INDICATOR,          // area for navigation indicator
1017     TYPE_END,
1018 };
1019 
1020 /**
1021  * @brief Enumerates occupied area type.
1022  */
1023 enum class OccupiedAreaType : uint32_t {
1024     TYPE_INPUT, // area of input window
1025 };
1026 
1027 /**
1028  * @brief Enumerates color space.
1029  */
1030 enum class ColorSpace : uint32_t {
1031     COLOR_SPACE_DEFAULT = 0, // Default color space.
1032     COLOR_SPACE_WIDE_GAMUT,  // Wide gamut color space. The specific wide color gamut depends on the screen.
1033 };
1034 
1035 /**
1036  * @brief Enumerates window animation.
1037  */
1038 enum class WindowAnimation : uint32_t {
1039     NONE,
1040     DEFAULT,
1041     INPUTE,
1042     CUSTOM,
1043 };
1044 
1045 /**
1046  * @brief Enumerates window maximize mode.
1047  */
1048 enum class MaximizeMode : uint32_t {
1049     MODE_AVOID_SYSTEM_BAR,
1050     MODE_FULL_FILL,
1051     MODE_RECOVER,
1052     MODE_END,
1053 };
1054 
1055 /**
1056  * @class AvoidArea
1057  *
1058  * @brief Area needed to avoid.
1059  */
1060 class AvoidArea : public Parcelable {
1061 public:
1062     Rect topRect_ { 0, 0, 0, 0 };
1063     Rect leftRect_ { 0, 0, 0, 0 };
1064     Rect rightRect_ { 0, 0, 0, 0 };
1065     Rect bottomRect_ { 0, 0, 0, 0 };
1066 
1067     bool operator==(const AvoidArea& a) const
1068     {
1069         return (leftRect_ == a.leftRect_ && topRect_ == a.topRect_ &&
1070             rightRect_ == a.rightRect_ && bottomRect_ == a.bottomRect_);
1071     }
1072 
1073     bool operator!=(const AvoidArea& a) const
1074     {
1075         return !this->operator==(a);
1076     }
1077 
isEmptyAvoidArea()1078     bool isEmptyAvoidArea() const
1079     {
1080         return topRect_.IsUninitializedRect() && leftRect_.IsUninitializedRect() &&
1081             rightRect_.IsUninitializedRect() && bottomRect_.IsUninitializedRect();
1082     }
1083 
WriteParcel(Parcel & parcel,const Rect & rect)1084     static inline bool WriteParcel(Parcel& parcel, const Rect& rect)
1085     {
1086         return parcel.WriteInt32(rect.posX_) && parcel.WriteInt32(rect.posY_) &&
1087             parcel.WriteUint32(rect.width_) && parcel.WriteUint32(rect.height_);
1088     }
1089 
ReadParcel(Parcel & parcel,Rect & rect)1090     static inline bool ReadParcel(Parcel& parcel, Rect& rect)
1091     {
1092         return parcel.ReadInt32(rect.posX_) && parcel.ReadInt32(rect.posY_) &&
1093             parcel.ReadUint32(rect.width_) && parcel.ReadUint32(rect.height_);
1094     }
1095 
Marshalling(Parcel & parcel)1096     virtual bool Marshalling(Parcel& parcel) const override
1097     {
1098         return (WriteParcel(parcel, leftRect_) && WriteParcel(parcel, topRect_) &&
1099             WriteParcel(parcel, rightRect_) && WriteParcel(parcel, bottomRect_));
1100     }
1101 
Unmarshalling(Parcel & parcel)1102     static AvoidArea* Unmarshalling(Parcel& parcel)
1103     {
1104         AvoidArea *avoidArea = new(std::nothrow) AvoidArea();
1105         if (avoidArea == nullptr) {
1106             return nullptr;
1107         }
1108         if (ReadParcel(parcel, avoidArea->leftRect_) && ReadParcel(parcel, avoidArea->topRect_) &&
1109             ReadParcel(parcel, avoidArea->rightRect_) && ReadParcel(parcel, avoidArea->bottomRect_)) {
1110             return avoidArea;
1111         }
1112         delete avoidArea;
1113         return nullptr;
1114     }
1115 
ToString()1116     std::string ToString() const
1117     {
1118         std::stringstream ss;
1119         if (isEmptyAvoidArea()) {
1120             ss << "empty";
1121             return ss.str();
1122         }
1123         if (!topRect_.IsUninitializedRect()) {
1124             ss << "top " << topRect_.ToString() << " ";
1125         }
1126         if (!bottomRect_.IsUninitializedRect()) {
1127             ss << "bottom " << bottomRect_.ToString() << " ";
1128         }
1129         if (!leftRect_.IsUninitializedRect()) {
1130             ss << "left " << leftRect_.ToString() << " ";
1131         }
1132         if (!rightRect_.IsUninitializedRect()) {
1133             ss << "right " << rightRect_.ToString() << " ";
1134         }
1135         return ss.str();
1136     }
1137 };
1138 
1139 /**
1140  * @struct ExceptionInfo
1141  *
1142  * @brief Exception info.
1143  */
1144 struct ExceptionInfo : public Parcelable {
1145     /**
1146      * @brief Marshalling ExceptionInfo.
1147      *
1148      * @param parcel Package of ExceptionInfo.
1149      * @return True means marshall success, false means marshall failed.
1150      */
MarshallingExceptionInfo1151     bool Marshalling(Parcel& parcel) const override
1152     {
1153         return parcel.WriteBool(needRemoveSession) &&
1154                parcel.WriteBool(needClearCallerLink);
1155     }
1156 
1157     /**
1158      * @brief Unmarshalling ExceptionInfo.
1159      *
1160      * @param parcel Package of ExceptionInfo.
1161      * @return ExceptionInfo object.
1162      */
UnmarshallingExceptionInfo1163     static ExceptionInfo* Unmarshalling(Parcel& parcel)
1164     {
1165         auto info = new ExceptionInfo();
1166         if (!parcel.ReadBool(info->needRemoveSession) ||
1167             !parcel.ReadBool(info->needClearCallerLink)) {
1168             delete info;
1169             return nullptr;
1170         }
1171         return info;
1172     }
1173 
1174     bool needRemoveSession = false;
1175     bool needClearCallerLink = true;
1176 };
1177 
1178 /**
1179  * @brief Enumerates window update type.
1180  */
1181 enum class WindowUpdateType : int32_t {
1182     WINDOW_UPDATE_ADDED = 1,
1183     WINDOW_UPDATE_REMOVED,
1184     WINDOW_UPDATE_FOCUSED,
1185     WINDOW_UPDATE_BOUNDS,
1186     WINDOW_UPDATE_ACTIVE,
1187     WINDOW_UPDATE_PROPERTY,
1188     WINDOW_UPDATE_ALL,
1189 };
1190 
1191 /**
1192  * @brief Enumerates picture in picture window state.
1193  */
1194 enum class PiPWindowState : uint32_t {
1195     STATE_UNDEFINED = 0,
1196     STATE_STARTING = 1,
1197     STATE_STARTED = 2,
1198     STATE_STOPPING = 3,
1199     STATE_STOPPED = 4,
1200     STATE_RESTORING = 5,
1201 };
1202 
1203 /**
1204  * @brief Enumerates picture in picture template type.
1205  */
1206 enum class PiPTemplateType : uint32_t {
1207     VIDEO_PLAY = 0,
1208     VIDEO_CALL = 1,
1209     VIDEO_MEETING = 2,
1210     VIDEO_LIVE = 3,
1211     END,
1212 };
1213 
1214 /**
1215  * @brief Enumerates picture in picture control group.
1216  */
1217 enum class PiPControlGroup : uint32_t {
1218     VIDEO_PLAY_START = 100,
1219     VIDEO_PREVIOUS_NEXT = 101,
1220     FAST_FORWARD_BACKWARD = 102,
1221     VIDEO_PLAY_END,
1222 
1223     VIDEO_CALL_START = 200,
1224     VIDEO_CALL_MICROPHONE_SWITCH = 201,
1225     VIDEO_CALL_HANG_UP_BUTTON = 202,
1226     VIDEO_CALL_CAMERA_SWITCH = 203,
1227     VIDEO_CALL_MUTE_SWITCH = 204,
1228     VIDEO_CALL_END,
1229 
1230     VIDEO_MEETING_START = 300,
1231     VIDEO_MEETING_HANG_UP_BUTTON = 301,
1232     VIDEO_MEETING_CAMERA_SWITCH = 302,
1233     VIDEO_MEETING_MUTE_SWITCH = 303,
1234     VIDEO_MEETING_MICROPHONE_SWITCH = 304,
1235     VIDEO_MEETING_END,
1236 
1237     VIDEO_LIVE_START = 400,
1238     VIDEO_PLAY_PAUSE = 401,
1239     VIDEO_LIVE_MUTE_SWITCH = 402,
1240     VIDEO_LIVE_END,
1241     END,
1242 };
1243 
1244 /**
1245  * @brief Enumerates picture in picture state.
1246  */
1247 enum class PiPState : int32_t {
1248     ABOUT_TO_START = 1,
1249     STARTED = 2,
1250     ABOUT_TO_STOP = 3,
1251     STOPPED = 4,
1252     ABOUT_TO_RESTORE = 5,
1253     ERROR = 6,
1254 };
1255 
1256 /**
1257  * @brief Enumerates picture in picture control status.
1258  */
1259 enum class PiPControlStatus : int32_t {
1260     PLAY = 1,
1261     PAUSE = 0,
1262     OPEN = 1,
1263     CLOSE = 0,
1264     ENABLED = -2,
1265     DISABLED = -3,
1266 };
1267 
1268 /**
1269  * @brief Enumerates picture in picture control type.
1270  */
1271 enum class PiPControlType : uint32_t {
1272     VIDEO_PLAY_PAUSE = 0,
1273     VIDEO_PREVIOUS = 1,
1274     VIDEO_NEXT = 2,
1275     FAST_FORWARD = 3,
1276     FAST_BACKWARD = 4,
1277     HANG_UP_BUTTON = 5,
1278     MICROPHONE_SWITCH = 6,
1279     CAMERA_SWITCH = 7,
1280     MUTE_SWITCH = 8,
1281     END,
1282 };
1283 
1284 struct PiPControlStatusInfo {
1285     PiPControlType controlType;
1286     PiPControlStatus status;
1287 };
1288 
1289 struct PiPControlEnableInfo {
1290     PiPControlType controlType;
1291     PiPControlStatus enabled;
1292 };
1293 
1294 struct PiPTemplateInfo {
1295     uint32_t pipTemplateType;
1296     uint32_t priority;
1297     std::vector<uint32_t> controlGroup;
1298     std::vector<PiPControlStatusInfo> pipControlStatusInfoList;
1299     std::vector<PiPControlEnableInfo> pipControlEnableInfoList;
1300 };
1301 
1302 struct PiPWindowSize {
1303     uint32_t width;
1304     uint32_t height;
1305     double scale;
1306 };
1307 
1308 /**
1309  * @struct VsyncCallback
1310  *
1311  * @brief Vsync callback
1312  */
1313 struct VsyncCallback {
1314     OnCallback onCallback;
1315 };
1316 
1317 struct WindowLimits {
1318     uint32_t maxWidth_ = static_cast<uint32_t>(INT32_MAX); // The width and height are no larger than INT32_MAX.
1319     uint32_t maxHeight_ = static_cast<uint32_t>(INT32_MAX);
1320     uint32_t minWidth_ = 1; // The width and height of the window cannot be less than or equal to 0.
1321     uint32_t minHeight_ = 1;
1322     float maxRatio_ = FLT_MAX;
1323     float minRatio_ = 0.0f;
1324     float vpRatio_ = 1.0f;
1325 
WindowLimitsWindowLimits1326     WindowLimits() {}
WindowLimitsWindowLimits1327     WindowLimits(uint32_t maxWidth, uint32_t maxHeight, uint32_t minWidth, uint32_t minHeight, float maxRatio,
1328         float minRatio) : maxWidth_(maxWidth), maxHeight_(maxHeight), minWidth_(minWidth), minHeight_(minHeight),
1329         maxRatio_(maxRatio), minRatio_(minRatio) {}
WindowLimitsWindowLimits1330     WindowLimits(uint32_t maxWidth, uint32_t maxHeight, uint32_t minWidth, uint32_t minHeight, float maxRatio,
1331         float minRatio, float vpRatio) : maxWidth_(maxWidth), maxHeight_(maxHeight), minWidth_(minWidth),
1332         minHeight_(minHeight), maxRatio_(maxRatio), minRatio_(minRatio), vpRatio_(vpRatio) {}
1333 
IsEmptyWindowLimits1334     bool IsEmpty() const
1335     {
1336         return (maxWidth_ == 0 || minWidth_ == 0 || maxHeight_ == 0 || minHeight_ == 0);
1337     }
1338 };
1339 
1340 /**
1341  * @struct TitleButtonRect
1342  *
1343  * @brief An area of title buttons relative to the upper right corner of the window.
1344  */
1345 struct TitleButtonRect {
1346     int32_t posX_ = 0;
1347     int32_t posY_ = 0;
1348     uint32_t width_ = 0;
1349     uint32_t height_ = 0;
1350 
1351     bool operator==(const TitleButtonRect& a) const
1352     {
1353         return (posX_ == a.posX_ && posY_ == a.posY_ && width_ == a.width_ && height_ == a.height_);
1354     }
1355 
1356     bool operator!=(const TitleButtonRect& a) const
1357     {
1358         return !this->operator==(a);
1359     }
1360 
ResetRectTitleButtonRect1361     void ResetRect()
1362     {
1363         posX_ = 0;
1364         posY_ = 0;
1365         width_ = 0;
1366         height_ = 0;
1367     }
1368 
IsUninitializedRectTitleButtonRect1369     bool IsUninitializedRect() const
1370     {
1371         return (posX_ == 0 && posY_ == 0 && width_ == 0 && height_ == 0);
1372     }
1373 
IsInsideOfTitleButtonRect1374     bool IsInsideOf(const TitleButtonRect& a) const
1375     {
1376         return (posX_ >= a.posX_ && posY_ >= a.posY_ &&
1377             posX_ + width_ <= a.posX_ + a.width_ && posY_ + height_ <= a.posY_ + a.height_);
1378     }
1379 };
1380 
1381 /**
1382  * @brief WindowInfo filter Option
1383  */
1384 enum class WindowInfoFilterOption : WindowInfoFilterOptionDataType {
1385     ALL = 0,
1386     EXCLUDE_SYSTEM = 1,
1387     VISIBLE = 1 << 1,
1388     FOREGROUND = 1 << 2,
1389 };
1390 
1391 inline WindowInfoFilterOption operator|(WindowInfoFilterOption lhs, WindowInfoFilterOption rhs)
1392 {
1393     return static_cast<WindowInfoFilterOption>(static_cast<WindowInfoFilterOptionDataType>(lhs) |
1394         static_cast<WindowInfoFilterOptionDataType>(rhs));
1395 }
1396 
IsChosenWindowOption(WindowInfoFilterOption options,WindowInfoFilterOption option)1397 inline bool IsChosenWindowOption(WindowInfoFilterOption options, WindowInfoFilterOption option)
1398 {
1399     return (static_cast<WindowInfoFilterOptionDataType>(options) &
1400         static_cast<WindowInfoFilterOptionDataType>(option)) != 0;
1401 }
1402 
1403 /**
1404  * @brief WindowInfo Type Option
1405  */
1406 enum class WindowInfoTypeOption : WindowInfoTypeOptionDataType {
1407     WINDOW_UI_INFO = 1,
1408     WINDOW_DISPLAY_INFO = 1 << 1,
1409     WINDOW_LAYOUT_INFO = 1 << 2,
1410     WINDOW_META_INFO = 1 << 3,
1411     ALL = ~0,
1412 };
1413 
1414 inline WindowInfoTypeOption operator|(WindowInfoTypeOption lhs, WindowInfoTypeOption rhs)
1415 {
1416     return static_cast<WindowInfoTypeOption>(static_cast<WindowInfoTypeOptionDataType>(lhs) |
1417         static_cast<WindowInfoTypeOptionDataType>(rhs));
1418 }
1419 
IsChosenWindowOption(WindowInfoTypeOption options,WindowInfoTypeOption option)1420 inline bool IsChosenWindowOption(WindowInfoTypeOption options, WindowInfoTypeOption option)
1421 {
1422     return (static_cast<WindowInfoTypeOptionDataType>(options) &
1423         static_cast<WindowInfoTypeOptionDataType>(option)) != 0;
1424 }
1425 
1426 /**
1427  * @enum WindowVisibilityState
1428  *
1429  * @brief Visibility state of a window
1430  */
1431 enum WindowVisibilityState : uint32_t {
1432     START = 0,
1433     WINDOW_VISIBILITY_STATE_NO_OCCLUSION = START,
1434     WINDOW_VISIBILITY_STATE_PARTICALLY_OCCLUSION,
1435     WINDOW_VISIBILITY_STATE_TOTALLY_OCCUSION,
1436     WINDOW_LAYER_STATE_MAX,
1437     END = WINDOW_LAYER_STATE_MAX,
1438 };
1439 
1440 /**
1441  * @struct WindowUIInfo
1442  *
1443  * @brief Window UI info
1444  */
1445 struct WindowUIInfo : public Parcelable {
1446     WindowVisibilityState visibilityState = WINDOW_LAYER_STATE_MAX;
1447 
MarshallingWindowUIInfo1448     bool Marshalling(Parcel& parcel) const override
1449     {
1450         return parcel.WriteUint32(static_cast<uint32_t>(visibilityState));
1451     }
1452 
UnmarshallingWindowUIInfo1453     static WindowUIInfo* Unmarshalling(Parcel& parcel)
1454     {
1455         WindowUIInfo* windowUIInfo = new WindowUIInfo();
1456         uint32_t visibilityState = 0;
1457         if (!parcel.ReadUint32(visibilityState)) {
1458             delete windowUIInfo;
1459             return nullptr;
1460         }
1461         windowUIInfo->visibilityState = static_cast<WindowVisibilityState>(visibilityState);
1462         return windowUIInfo;
1463     }
1464 };
1465 
1466 /**
1467  * @struct WindowDisplayInfo
1468  *
1469  * @brief Window display info
1470  */
1471 struct WindowDisplayInfo : public Parcelable {
1472     DisplayId displayId = DISPLAY_ID_INVALID;
MarshallingWindowDisplayInfo1473     bool Marshalling(Parcel& parcel) const override
1474     {
1475         return parcel.WriteUint64(displayId);
1476     }
1477 
UnmarshallingWindowDisplayInfo1478     static WindowDisplayInfo* Unmarshalling(Parcel& parcel)
1479     {
1480         WindowDisplayInfo* windowDisplayInfo = new WindowDisplayInfo();
1481         if (!parcel.ReadUint64(windowDisplayInfo->displayId)) {
1482             delete windowDisplayInfo;
1483             return nullptr;
1484         }
1485         return windowDisplayInfo;
1486     }
1487 };
1488 
1489 /**
1490  * @struct WindowLayoutInfo
1491  *
1492  * @brief Layout info for all windows on the screen.
1493  */
1494 struct WindowLayoutInfo : public Parcelable {
1495     Rect rect = Rect::EMPTY_RECT;
1496 
MarshallingWindowLayoutInfo1497     bool Marshalling(Parcel& parcel) const override
1498     {
1499         return parcel.WriteInt32(rect.posX_) && parcel.WriteInt32(rect.posY_) && parcel.WriteUint32(rect.width_) &&
1500                parcel.WriteUint32(rect.height_);
1501     }
1502 
UnmarshallingWindowLayoutInfo1503     static WindowLayoutInfo* Unmarshalling(Parcel& parcel)
1504     {
1505         WindowLayoutInfo* windowLayoutInfo = new WindowLayoutInfo();
1506         if (!parcel.ReadInt32(windowLayoutInfo->rect.posX_) || !parcel.ReadInt32(windowLayoutInfo->rect.posY_) ||
1507             !parcel.ReadUint32(windowLayoutInfo->rect.width_) || !parcel.ReadUint32(windowLayoutInfo->rect.height_)) {
1508             delete windowLayoutInfo;
1509             return nullptr;
1510         }
1511         return windowLayoutInfo;
1512     }
1513 };
1514 
1515 /**
1516  * @struct WindowMetaInfo
1517  *
1518  * @brief Window meta info
1519  */
1520 struct WindowMetaInfo : public Parcelable {
1521     int32_t windowId = 0;
1522     std::string windowName;
1523     std::string bundleName;
1524     std::string abilityName;
1525     int32_t appIndex = 0;
1526 
MarshallingWindowMetaInfo1527     bool Marshalling(Parcel& parcel) const override
1528     {
1529         return parcel.WriteInt32(windowId) && parcel.WriteString(windowName) && parcel.WriteString(bundleName) &&
1530                parcel.WriteString(abilityName) && parcel.WriteInt32(appIndex);
1531     }
UnmarshallingWindowMetaInfo1532     static WindowMetaInfo* Unmarshalling(Parcel& parcel)
1533     {
1534         WindowMetaInfo* windowMetaInfo = new WindowMetaInfo();
1535         if (!parcel.ReadInt32(windowMetaInfo->windowId) || !parcel.ReadString(windowMetaInfo->windowName) ||
1536             !parcel.ReadString(windowMetaInfo->bundleName) || !parcel.ReadString(windowMetaInfo->abilityName) ||
1537             !parcel.ReadInt32(windowMetaInfo->appIndex)) {
1538             delete windowMetaInfo;
1539             return nullptr;
1540         }
1541         return windowMetaInfo;
1542     }
1543 };
1544 
1545 /**
1546  * @struct WindowInfo
1547  *
1548  * @brief Classified window info
1549  */
1550 struct WindowInfo : public Parcelable {
1551     WindowUIInfo windowUIInfo;
1552     WindowDisplayInfo windowDisplayInfo;
1553     WindowLayoutInfo windowLayoutInfo;
1554     WindowMetaInfo windowMetaInfo;
1555 
MarshallingWindowInfo1556     bool Marshalling(Parcel& parcel) const override
1557     {
1558         return parcel.WriteParcelable(&windowUIInfo) && parcel.WriteParcelable(&windowDisplayInfo) &&
1559                parcel.WriteParcelable(&windowLayoutInfo) && parcel.WriteParcelable(&windowMetaInfo);
1560     }
1561 
UnmarshallingWindowInfo1562     static WindowInfo* Unmarshalling(Parcel& parcel)
1563     {
1564         WindowInfo* windowInfo = new WindowInfo();
1565         sptr<WindowUIInfo> windowUIInfo = parcel.ReadParcelable<WindowUIInfo>();
1566         sptr<WindowDisplayInfo> windowDisplayInfo = parcel.ReadParcelable<WindowDisplayInfo>();
1567         sptr<WindowLayoutInfo> windowLayoutInfo = parcel.ReadParcelable<WindowLayoutInfo>();
1568         sptr<WindowMetaInfo> windowMetaInfo = parcel.ReadParcelable<WindowMetaInfo>();
1569         if (!windowUIInfo || !windowDisplayInfo || !windowLayoutInfo || !windowMetaInfo) {
1570             delete windowInfo;
1571             return nullptr;
1572         }
1573         windowInfo->windowUIInfo = *windowUIInfo;
1574         windowInfo->windowDisplayInfo = *windowDisplayInfo;
1575         windowInfo->windowLayoutInfo = *windowLayoutInfo;
1576         windowInfo->windowMetaInfo = *windowMetaInfo;
1577         return windowInfo;
1578     }
1579 };
1580 
1581 /**
1582  * @struct WindowInfoOption
1583  *
1584  * @brief Option of list window info
1585  */
1586 struct WindowInfoOption : public Parcelable {
1587     WindowInfoFilterOption windowInfoFilterOption = WindowInfoFilterOption::ALL;
1588     WindowInfoTypeOption windowInfoTypeOption = WindowInfoTypeOption::ALL;
1589     DisplayId displayId = DISPLAY_ID_INVALID;
1590     int32_t windowId = 0;
1591 
MarshallingWindowInfoOption1592     bool Marshalling(Parcel& parcel) const override
1593     {
1594         return parcel.WriteUint32(static_cast<uint32_t>(windowInfoFilterOption)) &&
1595                parcel.WriteUint32(static_cast<uint32_t>(windowInfoTypeOption)) &&
1596                parcel.WriteUint64(displayId) &&
1597                parcel.WriteInt32(windowId);
1598     }
1599 
UnmarshallingWindowInfoOption1600     static WindowInfoOption* Unmarshalling(Parcel& parcel)
1601     {
1602         WindowInfoOption* windowInfoOption = new WindowInfoOption();
1603         uint32_t windowInfoFilterOption;
1604         uint32_t windowInfoTypeOption;
1605         if (!parcel.ReadUint32(windowInfoFilterOption) || !parcel.ReadUint32(windowInfoTypeOption) ||
1606             !parcel.ReadUint64(windowInfoOption->displayId) || !parcel.ReadInt32(windowInfoOption->windowId)) {
1607             delete windowInfoOption;
1608             return nullptr;
1609         }
1610         windowInfoOption->windowInfoFilterOption = static_cast<WindowInfoFilterOption>(windowInfoFilterOption);
1611         windowInfoOption->windowInfoTypeOption = static_cast<WindowInfoTypeOption>(windowInfoTypeOption);
1612         return windowInfoOption;
1613     }
1614 };
1615 
1616 /**
1617  * Config of keyboard animation
1618  */
1619 class KeyboardAnimationCurve : public Parcelable {
1620 public:
1621     KeyboardAnimationCurve() = default;
KeyboardAnimationCurve(const std::string & curveType,const std::vector<float> & curveParams,uint32_t duration)1622     KeyboardAnimationCurve(const std::string& curveType, const std::vector<float>& curveParams, uint32_t duration)
1623         : curveType_(curveType), duration_(duration)
1624     {
1625         curveParams_.assign(curveParams.begin(), curveParams.end());
1626     }
1627 
Marshalling(Parcel & parcel)1628     virtual bool Marshalling(Parcel& parcel) const override
1629     {
1630         if (!parcel.WriteString(curveType_)) {
1631             return false;
1632         }
1633 
1634         auto paramSize = curveParams_.size();
1635         if (paramSize == 4) { // 4: param size
1636             if (!parcel.WriteUint32(static_cast<uint32_t>(paramSize))) {
1637                 return false;
1638             }
1639             for (auto& param : curveParams_) {
1640                 if (!parcel.WriteFloat(param)) {
1641                     return false;
1642                 }
1643             }
1644         } else {
1645             if (!parcel.WriteUint32(0)) {
1646                 return false;
1647             }
1648         }
1649 
1650         if (!parcel.WriteUint32(duration_)) {
1651             return false;
1652         }
1653         return true;
1654     }
1655 
Unmarshalling(Parcel & parcel)1656     static KeyboardAnimationCurve* Unmarshalling(Parcel& parcel)
1657     {
1658         KeyboardAnimationCurve* config = new KeyboardAnimationCurve;
1659         uint32_t paramSize = 0;
1660         if (!parcel.ReadString(config->curveType_) || !parcel.ReadUint32(paramSize)) {
1661             delete config;
1662             return nullptr;
1663         }
1664 
1665         if (paramSize == 4) { // 4: paramSize
1666             for (uint32_t i = 0; i < paramSize; i++) {
1667                 float param = 0.0f;
1668                 if (!parcel.ReadFloat(param)) {
1669                     delete config;
1670                     return nullptr;
1671                 } else {
1672                     config->curveParams_.push_back(param);
1673                 }
1674             }
1675         }
1676 
1677         if (!parcel.ReadUint32(config->duration_)) {
1678             delete config;
1679             return nullptr;
1680         }
1681         return config;
1682     }
1683 
1684     std::string curveType_ = "";
1685     std::vector<float> curveParams_ = {};
1686     uint32_t duration_ = 0;
1687 };
1688 
1689 struct KeyboardAnimationConfig {
1690     KeyboardAnimationCurve curveIn;
1691     KeyboardAnimationCurve curveOut;
1692 };
1693 
1694 struct MoveConfiguration {
1695     DisplayId displayId = DISPLAY_ID_INVALID;
1696     RectAnimationConfig rectAnimationConfig = { 0, 0.0f, 0.0f, 0.0f, 0.0f };
ToStringMoveConfiguration1697     std::string ToString() const
1698     {
1699         std::string str;
1700         constexpr int BUFFER_SIZE = 1024;
1701         char buffer[BUFFER_SIZE] = { 0 };
1702         if (snprintf_s(buffer, sizeof(buffer), sizeof(buffer) - 1,
1703             "[displayId: %llu, rectAnimationConfig: [%u, %f, %f, %f, %f]]", displayId, rectAnimationConfig.duration,
1704             rectAnimationConfig.x1, rectAnimationConfig.y1, rectAnimationConfig.x2, rectAnimationConfig.y2) > 0) {
1705             str.append(buffer);
1706         }
1707         return str;
1708     }
1709 };
1710 
1711 enum class CaseType {
1712     CASE_WINDOW_MANAGER = 0,
1713     CASE_WINDOW,
1714     CASE_STAGE
1715 };
1716 
1717 enum class MaximizePresentation {
1718     FOLLOW_APP_IMMERSIVE_SETTING = 0,  // follow app set immersiveStateEnable
1719     EXIT_IMMERSIVE = 1,                // immersiveStateEnable will be set as false
1720     ENTER_IMMERSIVE = 2,               // immersiveStateEnable will be set as true
1721     // immersiveStateEnable will be set as true, titleHoverShowEnabled and dockHoverShowEnabled will be set as false
1722     ENTER_IMMERSIVE_DISABLE_TITLE_AND_DOCK_HOVER = 3,
1723 };
1724 
1725 enum ForceHideState : uint32_t {
1726     NOT_HIDDEN = 0,
1727     HIDDEN_WHEN_FOCUSED,
1728     HIDDEN_WHEN_UNFOCUSED
1729 };
1730 
1731 enum class ExtensionWindowAttribute : int32_t {
1732     SYSTEM_WINDOW = 0,
1733     SUB_WINDOW = 1,
1734     UNKNOWN = 2
1735 };
1736 
1737 struct SystemWindowOptions {
1738     int32_t windowType = -1;
1739 };
1740 
1741 enum class ModalityType : uint8_t {
1742     WINDOW_MODALITY,
1743     APPLICATION_MODALITY,
1744 };
1745 
1746 struct SubWindowOptions {
1747     std::string title;
1748     bool decorEnabled = false;
1749     bool isModal = false;
1750     bool isTopmost = false;
1751     int32_t zLevel = 0;
1752     bool maximizeSupported = false;
1753     ModalityType modalityType = ModalityType::WINDOW_MODALITY;
1754 };
1755 
1756 struct DecorButtonStyle {
1757     int32_t  colorMode = DEFAULT_COLOR_MODE;
1758     uint32_t spacingBetweenButtons = DEFAULT_SPACING_BETWEEN_BUTTONS;
1759     uint32_t closeButtonRightMargin = DEFAULT_CLOSE_BUTTON_RIGHT_MARGIN;
1760     uint32_t buttonBackgroundSize = DEFAULT_BUTTON_BACKGROUND_SIZE;
1761 };
1762 
1763 struct ExtensionWindowConfig {
1764     std::string windowName;
1765     ExtensionWindowAttribute windowAttribute = ExtensionWindowAttribute::UNKNOWN;
1766     Rect windowRect;
1767     SubWindowOptions subWindowOptions;
1768     SystemWindowOptions systemWindowOptions;
1769 };
1770 
1771 template <typename T>
1772 struct SptrHash {
operatorSptrHash1773     std::size_t operator()(const sptr<T>& ptr) const
1774     {
1775         return std::hash<T*>{}(ptr.GetRefPtr());
1776     }
1777 };
1778 
1779 /**
1780  * @struct WindowDensityInfo
1781  *
1782  * @brief Currently available density
1783  */
1784 struct WindowDensityInfo {
1785     float systemDensity = UNDEFINED_DENSITY;
1786     float defaultDensity = UNDEFINED_DENSITY;
1787     float customDensity = UNDEFINED_DENSITY;
1788 
ToStringWindowDensityInfo1789     std::string ToString() const
1790     {
1791         std::string str;
1792         constexpr int BUFFER_SIZE = 64;
1793         char buffer[BUFFER_SIZE] = { 0 };
1794         if (snprintf_s(buffer, sizeof(buffer), sizeof(buffer) - 1,
1795             "[%f, %f, %f]", systemDensity, defaultDensity, customDensity) > 0) {
1796             str.append(buffer);
1797         }
1798         return str;
1799     }
1800 };
1801 
1802 /**
1803  * @struct KeyboardLayoutParams
1804  *
1805  * @brief Keyboard needs to adjust layout
1806  */
1807 struct KeyboardLayoutParams : public Parcelable {
1808     WindowGravity gravity_ = WindowGravity::WINDOW_GRAVITY_BOTTOM;
1809     int32_t landscapeAvoidHeight_ = -1;
1810     int32_t portraitAvoidHeight_ = -1;
1811     Rect LandscapeKeyboardRect_ { 0, 0, 0, 0 };
1812     Rect PortraitKeyboardRect_ { 0, 0, 0, 0 };
1813     Rect LandscapePanelRect_ { 0, 0, 0, 0 };
1814     Rect PortraitPanelRect_ { 0, 0, 0, 0 };
1815 
1816     bool operator==(const KeyboardLayoutParams& other) const
1817     {
1818         return (gravity_ == other.gravity_ &&
1819                 landscapeAvoidHeight_ == other.landscapeAvoidHeight_ &&
1820                 portraitAvoidHeight_ == other.portraitAvoidHeight_ &&
1821                 LandscapeKeyboardRect_ == other.LandscapeKeyboardRect_ &&
1822                 PortraitKeyboardRect_ == other.PortraitKeyboardRect_ &&
1823                 LandscapePanelRect_ == other.LandscapePanelRect_ &&
1824                 PortraitPanelRect_ == other.PortraitPanelRect_);
1825     }
1826 
1827     bool operator!=(const KeyboardLayoutParams& params) const
1828     {
1829         return !this->operator==(params);
1830     }
1831 
isEmptyKeyboardLayoutParams1832     bool isEmpty() const
1833     {
1834         return LandscapeKeyboardRect_.IsUninitializedRect() && PortraitKeyboardRect_.IsUninitializedRect() &&
1835                LandscapePanelRect_.IsUninitializedRect() && PortraitPanelRect_.IsUninitializedRect();
1836     }
1837 
WriteParcelKeyboardLayoutParams1838     static inline bool WriteParcel(Parcel& parcel, const Rect& rect)
1839     {
1840         return parcel.WriteInt32(rect.posX_) && parcel.WriteInt32(rect.posY_) &&
1841                parcel.WriteUint32(rect.width_) && parcel.WriteUint32(rect.height_);
1842     }
1843 
ReadParcelKeyboardLayoutParams1844     static inline bool ReadParcel(Parcel& parcel, Rect& rect)
1845     {
1846         return parcel.ReadInt32(rect.posX_) && parcel.ReadInt32(rect.posY_) &&
1847                parcel.ReadUint32(rect.width_) && parcel.ReadUint32(rect.height_);
1848     }
1849 
MarshallingKeyboardLayoutParams1850     virtual bool Marshalling(Parcel& parcel) const override
1851     {
1852         return (parcel.WriteUint32(static_cast<uint32_t>(gravity_)) &&
1853                 parcel.WriteInt32(landscapeAvoidHeight_) &&
1854                 parcel.WriteInt32(portraitAvoidHeight_) &&
1855                 WriteParcel(parcel, LandscapeKeyboardRect_) &&
1856                 WriteParcel(parcel, PortraitKeyboardRect_) &&
1857                 WriteParcel(parcel, LandscapePanelRect_) &&
1858                 WriteParcel(parcel, PortraitPanelRect_));
1859     }
1860 
UnmarshallingKeyboardLayoutParams1861     static KeyboardLayoutParams* Unmarshalling(Parcel& parcel)
1862     {
1863         KeyboardLayoutParams* params = new KeyboardLayoutParams();
1864         uint32_t gravity;
1865         if (parcel.ReadUint32(gravity) &&
1866             parcel.ReadInt32(params->landscapeAvoidHeight_) &&
1867             parcel.ReadInt32(params->portraitAvoidHeight_) &&
1868             ReadParcel(parcel, params->LandscapeKeyboardRect_) &&
1869             ReadParcel(parcel, params->PortraitKeyboardRect_) &&
1870             ReadParcel(parcel, params->LandscapePanelRect_) &&
1871             ReadParcel(parcel, params->PortraitPanelRect_)) {
1872             params->gravity_ = static_cast<WindowGravity>(gravity);
1873             return params;
1874         }
1875         delete params;
1876         return nullptr;
1877     }
1878 };
1879 
1880 /**
1881  * @struct KeyboardTouchHotAreas
1882  *
1883  * @brief Keyboard needs to set hotArea
1884  */
1885 struct KeyboardTouchHotAreas {
1886     std::vector<Rect> landscapeKeyboardHotAreas_;
1887     std::vector<Rect> portraitKeyboardHotAreas_;
1888     std::vector<Rect> landscapePanelHotAreas_;
1889     std::vector<Rect> portraitPanelHotAreas_;
1890 
isKeyboardEmptyKeyboardTouchHotAreas1891     bool isKeyboardEmpty() const
1892     {
1893         return (landscapeKeyboardHotAreas_.empty() || portraitKeyboardHotAreas_.empty());
1894     }
1895 
isPanelEmptyKeyboardTouchHotAreas1896     bool isPanelEmpty() const
1897     {
1898         return (landscapePanelHotAreas_.empty() || portraitPanelHotAreas_.empty());
1899     }
1900 };
1901 
1902 enum class KeyboardViewMode: uint32_t {
1903     NON_IMMERSIVE_MODE = 0,
1904     IMMERSIVE_MODE,
1905     LIGHT_IMMERSIVE_MODE,
1906     DARK_IMMERSIVE_MODE,
1907     VIEW_MODE_END,
1908 };
1909 
1910 /*
1911  * Multi User
1912  */
1913 enum class UserSwitchEventType: uint32_t {
1914     SWITCHING,
1915     SWITCHED,
1916 };
1917 
1918 /**
1919  * @brief Enumerates window focus change reason
1920  */
1921 enum class WindowFocusChangeReason : int32_t {
1922     /**
1923      * default focus change reason
1924      */
1925     DEFAULT = 0,
1926 
1927     /**
1928      * focus change for move up
1929      */
1930     MOVE_UP,
1931 
1932     /**
1933      * focus change for click
1934      */
1935     CLICK,
1936 
1937     /**
1938      * focus change for foreground
1939      */
1940     FOREGROUND,
1941 
1942     /**
1943      * focus change for background
1944      */
1945     BACKGROUND,
1946 
1947     /**
1948      * focus change for split screen.5
1949      */
1950     SPLIT_SCREEN,
1951 
1952     /**
1953      * focus change for full screen
1954      */
1955     FULL_SCREEN,
1956 
1957     /**
1958      * focus change for global search
1959      */
1960     SCB_SESSION_REQUEST,
1961 
1962     /**
1963      * focus change for floating scene
1964      */
1965     FLOATING_SCENE,
1966 
1967     /**
1968      * focus change for losing focus
1969      */
1970     SCB_SESSION_REQUEST_UNFOCUS,
1971 
1972     /**
1973      * focus change for client requerst.10
1974      */
1975     CLIENT_REQUEST,
1976 
1977     /**
1978      * focus change for wind
1979      */
1980     WIND,
1981 
1982     /**
1983      * focus change for app foreground
1984      */
1985     APP_FOREGROUND,
1986 
1987     /**
1988      * focus change for app background
1989      */
1990     APP_BACKGROUND,
1991 
1992     /**
1993      * focus change for recent,Multitasking
1994      */
1995     RECENT,
1996 
1997     /**
1998      * focus change for inner app.
1999      */
2000     SCB_START_APP,
2001 
2002     /**
2003      * focus for setting focuable.
2004      */
2005     FOCUSABLE,
2006 
2007     /**
2008      * select last focused app when requestSessionUnFocus.
2009      */
2010     LAST_FOCUSED_APP,
2011 
2012     /**
2013      * focus for zOrder pass through VOICE_INTERACTION.
2014      */
2015     VOICE_INTERACTION,
2016 
2017     /**
2018      * focus change for SA requerst.19
2019      */
2020     SA_REQUEST,
2021 
2022     /**
2023      * focus on previous window for system keyboard
2024      */
2025     SYSTEM_KEYBOARD,
2026 
2027     /**
2028      * focus change max.
2029      */
2030     MAX,
2031 };
2032 
2033 /**
2034  * @brief Windowinfokey
2035  */
2036 enum class WindowInfoKey : int32_t {
2037     WINDOW_ID,
2038     BUNDLE_NAME,
2039     ABILITY_NAME,
2040     APP_INDEX,
2041     VISIBILITY_STATE,
2042 };
2043 }
2044 }
2045 #endif // OHOS_ROSEN_WM_COMMON_H
2046