• 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 <parcel.h>
20 #include <map>
21 #include <float.h>
22 
23 namespace OHOS {
24 namespace Rosen {
25 using DisplayId = uint64_t;
26 
27 /**
28  * @brief Enumerates type of window
29  */
30 enum class WindowType : uint32_t {
31     APP_WINDOW_BASE = 1,
32     APP_MAIN_WINDOW_BASE = APP_WINDOW_BASE,
33     WINDOW_TYPE_APP_MAIN_WINDOW = APP_MAIN_WINDOW_BASE,
34     APP_MAIN_WINDOW_END,
35 
36     APP_SUB_WINDOW_BASE = 1000,
37     WINDOW_TYPE_MEDIA = APP_SUB_WINDOW_BASE,
38     WINDOW_TYPE_APP_SUB_WINDOW,
39     WINDOW_TYPE_APP_COMPONENT,
40     APP_SUB_WINDOW_END,
41     APP_WINDOW_END = APP_SUB_WINDOW_END,
42 
43     SYSTEM_WINDOW_BASE = 2000,
44     BELOW_APP_SYSTEM_WINDOW_BASE = SYSTEM_WINDOW_BASE,
45     WINDOW_TYPE_WALLPAPER = SYSTEM_WINDOW_BASE,
46     WINDOW_TYPE_DESKTOP,
47     BELOW_APP_SYSTEM_WINDOW_END,
48 
49     ABOVE_APP_SYSTEM_WINDOW_BASE = 2100,
50     WINDOW_TYPE_APP_LAUNCHING = ABOVE_APP_SYSTEM_WINDOW_BASE,
51     WINDOW_TYPE_DOCK_SLICE,
52     WINDOW_TYPE_INCOMING_CALL,
53     WINDOW_TYPE_SEARCHING_BAR,
54     WINDOW_TYPE_SYSTEM_ALARM_WINDOW,
55     WINDOW_TYPE_INPUT_METHOD_FLOAT,
56     WINDOW_TYPE_FLOAT,
57     WINDOW_TYPE_TOAST,
58     WINDOW_TYPE_STATUS_BAR,
59     WINDOW_TYPE_PANEL,
60     WINDOW_TYPE_KEYGUARD,
61     WINDOW_TYPE_VOLUME_OVERLAY,
62     WINDOW_TYPE_NAVIGATION_BAR,
63     WINDOW_TYPE_DRAGGING_EFFECT,
64     WINDOW_TYPE_POINTER,
65     WINDOW_TYPE_LAUNCHER_RECENT,
66     WINDOW_TYPE_LAUNCHER_DOCK,
67     WINDOW_TYPE_BOOT_ANIMATION,
68     WINDOW_TYPE_FREEZE_DISPLAY,
69     WINDOW_TYPE_VOICE_INTERACTION,
70     WINDOW_TYPE_FLOAT_CAMERA,
71     WINDOW_TYPE_PLACEHOLDER,
72     WINDOW_TYPE_DIALOG,
73     WINDOW_TYPE_SCREENSHOT,
74     WINDOW_TYPE_GLOBAL_SEARCH,
75     WINDOW_TYPE_SYSTEM_TOAST,
76     WINDOW_TYPE_SYSTEM_FLOAT,
77     WINDOW_TYPE_PIP,
78     WINDOW_TYPE_THEME_EDITOR,
79     WINDOW_TYPE_NAVIGATION_INDICATOR,
80     WINDOW_TYPE_HANDWRITE,
81     WINDOW_TYPE_SCENE_BOARD,
82     WINDOW_TYPE_KEYBOARD_PANEL,
83     ABOVE_APP_SYSTEM_WINDOW_END,
84 
85     SYSTEM_SUB_WINDOW_BASE = 2500,
86     WINDOW_TYPE_SYSTEM_SUB_WINDOW = SYSTEM_SUB_WINDOW_BASE,
87     SYSTEM_SUB_WINDOW_END,
88 
89     SYSTEM_WINDOW_END = SYSTEM_SUB_WINDOW_END,
90 
91     WINDOW_TYPE_UI_EXTENSION = 3000
92 };
93 
94 /**
95  * @brief Enumerates state of window.
96  */
97 enum class WindowState : uint32_t {
98     STATE_INITIAL,
99     STATE_CREATED,
100     STATE_SHOWN,
101     STATE_HIDDEN,
102     STATE_FROZEN,
103     STATE_UNFROZEN,
104     STATE_DESTROYED,
105     STATE_BOTTOM = STATE_DESTROYED // Add state type after STATE_DESTROYED is not allowed.
106 };
107 
108 /**
109  * @brief Enumerates blur style of window.
110  */
111 enum class WindowBlurStyle : uint32_t {
112     WINDOW_BLUR_OFF = 0,
113     WINDOW_BLUR_THIN,
114     WINDOW_BLUR_REGULAR,
115     WINDOW_BLUR_THICK
116 };
117 
118 /**
119  * @brief Enumerates mode supported of window.
120  */
121 enum WindowModeSupport : uint32_t {
122     WINDOW_MODE_SUPPORT_FULLSCREEN = 1 << 0,
123     WINDOW_MODE_SUPPORT_FLOATING = 1 << 1,
124     WINDOW_MODE_SUPPORT_SPLIT_PRIMARY = 1 << 2,
125     WINDOW_MODE_SUPPORT_SPLIT_SECONDARY = 1 << 3,
126     WINDOW_MODE_SUPPORT_PIP = 1 << 4,
127     WINDOW_MODE_SUPPORT_ALL = WINDOW_MODE_SUPPORT_FLOATING |
128                               WINDOW_MODE_SUPPORT_FULLSCREEN |
129                               WINDOW_MODE_SUPPORT_SPLIT_PRIMARY |
130                               WINDOW_MODE_SUPPORT_SPLIT_SECONDARY |
131                               WINDOW_MODE_SUPPORT_PIP
132 };
133 
134 /**
135  * @brief Enumerates mode of window.
136  */
137 enum class WindowMode : uint32_t {
138     WINDOW_MODE_UNDEFINED = 0,
139     WINDOW_MODE_FULLSCREEN = 1,
140     WINDOW_MODE_SPLIT_PRIMARY = 100,
141     WINDOW_MODE_SPLIT_SECONDARY,
142     WINDOW_MODE_FLOATING,
143     WINDOW_MODE_PIP
144 };
145 
146 /**
147  * @brief Enumerates status of window.
148  */
149 enum class WindowStatus : uint32_t {
150     WINDOW_STATUS_UNDEFINED = 0,
151     WINDOW_STATUS_FULLSCREEN = 1,
152     WINDOW_STATUS_MAXIMIZE,
153     WINDOW_STATUS_MINIMIZE,
154     WINDOW_STATUS_FLOATING,
155     WINDOW_STATUS_SPLITSCREEN
156 };
157 
158 /**
159  * @brief Enumerates error code of window.
160  */
161 enum class WMError : int32_t {
162     WM_OK = 0,
163     WM_DO_NOTHING,
164     WM_ERROR_NO_MEM,
165     WM_ERROR_DESTROYED_OBJECT,
166     WM_ERROR_INVALID_WINDOW,
167     WM_ERROR_INVALID_WINDOW_MODE_OR_SIZE,
168     WM_ERROR_INVALID_OPERATION,
169     WM_ERROR_INVALID_PERMISSION,
170     WM_ERROR_NOT_SYSTEM_APP,
171     WM_ERROR_NO_REMOTE_ANIMATION,
172     WM_ERROR_INVALID_DISPLAY,
173     WM_ERROR_INVALID_PARENT,
174     WM_ERROR_INVALID_OP_IN_CUR_STATUS,
175     WM_ERROR_REPEAT_OPERATION,
176     WM_ERROR_INVALID_SESSION,
177     WM_ERROR_INVALID_CALLING,
178 
179     WM_ERROR_DEVICE_NOT_SUPPORT = 801, // the value do not change.It is defined on all system.
180 
181     WM_ERROR_NEED_REPORT_BASE = 1000, // error code > 1000 means need report.
182     WM_ERROR_NULLPTR,
183     WM_ERROR_INVALID_TYPE,
184     WM_ERROR_INVALID_PARAM,
185     WM_ERROR_SAMGR,
186     WM_ERROR_IPC_FAILED,
187     WM_ERROR_NEED_REPORT_END,
188     WM_ERROR_START_ABILITY_FAILED,
189     WM_ERROR_PIP_DESTROY_FAILED,
190     WM_ERROR_PIP_STATE_ABNORMALLY,
191     WM_ERROR_PIP_CREATE_FAILED,
192     WM_ERROR_PIP_INTERNAL_ERROR,
193     WM_ERROR_PIP_REPEAT_OPERATION
194 };
195 
196 /**
197  * @brief Enumerates error code of window only used for js api.
198  */
199 enum class WmErrorCode : int32_t {
200     WM_OK = 0,
201     WM_ERROR_NO_PERMISSION = 201,
202     WM_ERROR_NOT_SYSTEM_APP = 202,
203     WM_ERROR_INVALID_PARAM = 401,
204     WM_ERROR_DEVICE_NOT_SUPPORT = 801,
205 
206     WM_ERROR_REPEAT_OPERATION = 1300001,
207     WM_ERROR_STATE_ABNORMALLY = 1300002,
208     WM_ERROR_SYSTEM_ABNORMALLY = 1300003,
209     WM_ERROR_INVALID_CALLING = 1300004,
210     WM_ERROR_STAGE_ABNORMALLY = 1300005,
211     WM_ERROR_CONTEXT_ABNORMALLY = 1300006,
212     WM_ERROR_START_ABILITY_FAILED = 1300007,
213     WM_ERROR_INVALID_DISPLAY = 1300008,
214     WM_ERROR_INVALID_PARENT = 1300009,
215     WM_ERROR_INVALID_OP_IN_CUR_STATUS = 1300010,
216     WM_ERROR_PIP_DESTROY_FAILED = 1300011,
217     WM_ERROR_PIP_STATE_ABNORMALLY = 1300012,
218     WM_ERROR_PIP_CREATE_FAILED = 1300013,
219     WM_ERROR_PIP_INTERNAL_ERROR = 1300014,
220     WM_ERROR_PIP_REPEAT_OPERATION = 1300015
221 };
222 
223 /**
224  * @brief Enumerates setting flag of systemStatusBar.
225  */
226 enum class SystemBarSettingFlag : uint32_t {
227     DEFAULT_SETTING = 0,
228     COLOR_SETTING = 1,
229     ENABLE_SETTING = 1 << 1,
230     ALL_SETTING = 0b11
231 };
232 
233 /**
234  * @brief Enumerates flag of window.
235  */
236 enum class WindowFlag : uint32_t {
237     WINDOW_FLAG_NEED_AVOID = 1,
238     WINDOW_FLAG_PARENT_LIMIT = 1 << 1,
239     WINDOW_FLAG_SHOW_WHEN_LOCKED = 1 << 2,
240     WINDOW_FLAG_FORBID_SPLIT_MOVE = 1 << 3,
241     WINDOW_FLAG_WATER_MARK = 1 << 4,
242     WINDOW_FLAG_IS_MODAL = 1 << 5,
243     WINDOW_FLAG_HANDWRITING = 1 << 6,
244     WINDOW_FLAG_IS_TOAST = 1 << 7,
245     WINDOW_FLAG_END = 1 << 8,
246 };
247 
248 /**
249  * @brief Used to map from WMError to WmErrorCode.
250  */
251 const std::map<WMError, WmErrorCode> WM_JS_TO_ERROR_CODE_MAP {
252     {WMError::WM_OK,                                   WmErrorCode::WM_OK                             },
253     {WMError::WM_DO_NOTHING,                           WmErrorCode::WM_ERROR_STATE_ABNORMALLY         },
254     {WMError::WM_ERROR_DESTROYED_OBJECT,               WmErrorCode::WM_ERROR_STATE_ABNORMALLY         },
255     {WMError::WM_ERROR_DEVICE_NOT_SUPPORT,             WmErrorCode::WM_ERROR_DEVICE_NOT_SUPPORT       },
256     {WMError::WM_ERROR_INVALID_OPERATION,              WmErrorCode::WM_ERROR_STATE_ABNORMALLY         },
257     {WMError::WM_ERROR_INVALID_PARAM,                  WmErrorCode::WM_ERROR_INVALID_PARAM            },
258     {WMError::WM_ERROR_INVALID_PERMISSION,             WmErrorCode::WM_ERROR_NO_PERMISSION            },
259     {WMError::WM_ERROR_NOT_SYSTEM_APP,                 WmErrorCode::WM_ERROR_NOT_SYSTEM_APP           },
260     {WMError::WM_ERROR_INVALID_TYPE,                   WmErrorCode::WM_ERROR_STATE_ABNORMALLY         },
261     {WMError::WM_ERROR_INVALID_WINDOW,                 WmErrorCode::WM_ERROR_STATE_ABNORMALLY         },
262     {WMError::WM_ERROR_INVALID_WINDOW_MODE_OR_SIZE,    WmErrorCode::WM_ERROR_STATE_ABNORMALLY         },
263     {WMError::WM_ERROR_IPC_FAILED,                     WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY        },
264     {WMError::WM_ERROR_NO_MEM,                         WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY        },
265     {WMError::WM_ERROR_NO_REMOTE_ANIMATION,            WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY        },
266     {WMError::WM_ERROR_INVALID_DISPLAY,                WmErrorCode::WM_ERROR_INVALID_DISPLAY          },
267     {WMError::WM_ERROR_INVALID_PARENT,                 WmErrorCode::WM_ERROR_INVALID_PARENT           },
268     {WMError::WM_ERROR_INVALID_OP_IN_CUR_STATUS,       WmErrorCode::WM_ERROR_INVALID_OP_IN_CUR_STATUS },
269     {WMError::WM_ERROR_REPEAT_OPERATION,               WmErrorCode::WM_ERROR_REPEAT_OPERATION         },
270     {WMError::WM_ERROR_NULLPTR,                        WmErrorCode::WM_ERROR_STATE_ABNORMALLY         },
271     {WMError::WM_ERROR_SAMGR,                          WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY        },
272     {WMError::WM_ERROR_START_ABILITY_FAILED,           WmErrorCode::WM_ERROR_START_ABILITY_FAILED     },
273 };
274 
275 /**
276  * @brief Enumerates window size change reason.
277  */
278 enum class WindowSizeChangeReason : uint32_t {
279     UNDEFINED = 0,
280     MAXIMIZE,
281     RECOVER,
282     ROTATION,
283     DRAG,
284     DRAG_START,
285     DRAG_END,
286     RESIZE,
287     MOVE,
288     HIDE,
289     TRANSFORM,
290     CUSTOM_ANIMATION_SHOW,
291     FULL_TO_SPLIT,
292     SPLIT_TO_FULL,
293     FULL_TO_FLOATING,
294     FLOATING_TO_FULL,
295     PIP_START,
296     PIP_SHOW,
297     PIP_AUTO_START,
298     PIP_RATIO_CHANGE,
299     PIP_RESTORE,
300     END
301 };
302 
303 /**
304  * @brief Enumerates window gravity.
305  */
306 enum class WindowGravity : uint32_t {
307     WINDOW_GRAVITY_FLOAT = 0,
308     WINDOW_GRAVITY_BOTTOM
309 };
310 
311 /**
312  * @brief Enumerates window session type.
313  */
314 enum class WindowSessionType : uint32_t {
315     SCENE_SESSION = 0,
316     EXTENSION_SESSION = 1
317 };
318 
319 /**
320  * @brief Enumerates window tag.
321  */
322 enum class WindowTag : uint32_t {
323     MAIN_WINDOW = 0,
324     SUB_WINDOW = 1,
325     SYSTEM_WINDOW = 2
326 };
327 
328 /**
329  * @brief Enumerates drag event.
330  */
331 enum class DragEvent : uint32_t {
332     DRAG_EVENT_IN  = 1,
333     DRAG_EVENT_OUT,
334     DRAG_EVENT_MOVE,
335     DRAG_EVENT_END
336 };
337 
338 /**
339  * @brief Enumerates layout mode of window.
340  */
341 enum class WindowLayoutMode : uint32_t {
342     BASE = 0,
343     CASCADE = BASE,
344     TILE = 1,
345     END,
346 };
347 
348 namespace {
349     constexpr uint32_t SYSTEM_COLOR_WHITE = 0xE5FFFFFF;
350     constexpr uint32_t SYSTEM_COLOR_BLACK = 0x66000000;
351     constexpr float UNDEFINED_BRIGHTNESS = -1.0f;
352     constexpr float MINIMUM_BRIGHTNESS = 0.0f;
353     constexpr float MAXIMUM_BRIGHTNESS = 1.0f;
354 
355     constexpr uint32_t INVALID_WINDOW_ID = 0;
356     constexpr int32_t INVALID_PID = -1;
357     constexpr int32_t INVALID_UID = -1;
358 }
359 
360 /**
361  * @struct PointInfo.
362  *
363  * @brief Point info.
364  */
365 struct PointInfo {
366     int32_t x;
367     int32_t y;
368 };
369 
370 /**
371  * @class Transform
372  *
373  * @brief parameter of transform and rotate.
374  */
375 class Transform {
376 public:
Transform()377     Transform()
378         : pivotX_(0.5f), pivotY_(0.5f), scaleX_(1.f), scaleY_(1.f), scaleZ_(1.f), rotationX_(0.f),
379           rotationY_(0.f), rotationZ_(0.f), translateX_(0.f), translateY_(0.f), translateZ_(0.f)
380     {}
~Transform()381     ~Transform() {}
382 
383     bool operator==(const Transform& right) const
384     {
385         return NearZero(scaleX_ - right.scaleX_) &&
386             NearZero(scaleY_ - right.scaleY_) &&
387             NearZero(scaleZ_ - right.scaleZ_) &&
388             NearZero(pivotX_ - right.pivotX_) &&
389             NearZero(pivotY_ - right.pivotY_) &&
390             NearZero(translateX_ - right.translateX_) &&
391             NearZero(translateY_ - right.translateY_) &&
392             NearZero(translateZ_ - right.translateZ_) &&
393             NearZero(rotationX_ - right.rotationX_) &&
394             NearZero(rotationY_ - right.rotationY_) &&
395             NearZero(rotationZ_ - right.rotationZ_);
396     }
397 
398     bool operator!=(const Transform& right) const
399     {
400         return !(*this == right);
401     }
402 
Identity()403     static const Transform& Identity()
404     {
405         static Transform I;
406         return I;
407     }
408 
409     float pivotX_;
410     float pivotY_;
411     float scaleX_;
412     float scaleY_;
413     float scaleZ_;
414     float rotationX_;
415     float rotationY_;
416     float rotationZ_;
417     float translateX_;
418     float translateY_;
419     float translateZ_;
420 
Unmarshalling(Parcel & parcel)421     void Unmarshalling(Parcel& parcel)
422     {
423         pivotX_ = parcel.ReadFloat();
424         pivotY_ = parcel.ReadFloat();
425         scaleX_ = parcel.ReadFloat();
426         scaleY_ = parcel.ReadFloat();
427         scaleZ_ = parcel.ReadFloat();
428         rotationX_ = parcel.ReadFloat();
429         rotationY_ = parcel.ReadFloat();
430         rotationZ_ = parcel.ReadFloat();
431         translateX_ = parcel.ReadFloat();
432         translateY_ = parcel.ReadFloat();
433         translateZ_ = parcel.ReadFloat();
434     }
435 
Marshalling(Parcel & parcel)436     bool Marshalling(Parcel& parcel) const
437     {
438         return parcel.WriteFloat(pivotX_) && parcel.WriteFloat(pivotY_) &&
439                parcel.WriteFloat(scaleX_) && parcel.WriteFloat(scaleY_) && parcel.WriteFloat(scaleZ_) &&
440                parcel.WriteFloat(rotationX_) && parcel.WriteFloat(rotationY_) && parcel.WriteFloat(rotationZ_) &&
441                parcel.WriteFloat(translateX_) && parcel.WriteFloat(translateY_) && parcel.WriteFloat(translateZ_);
442     }
443 
444 private:
NearZero(float val)445     static inline bool NearZero(float val)
446     {
447         return -0.001f < val && val < 0.001f;
448     }
449 };
450 
451 /**
452  * @struct SystemBarPropertyFlag
453  *
454  * @brief Flag of system bar
455  */
456 struct SystemBarPropertyFlag {
457     bool enableFlag = false;
458     bool backgroundColorFlag = false;
459     bool contentColorFlag = false;
460     bool enableAnimationFlag = false;
461 };
462 
463 /**
464  * @struct Rect
465  *
466  * @brief Window Rect.
467  */
468 struct Rect {
469     int32_t posX_;
470     int32_t posY_;
471     uint32_t width_;
472     uint32_t height_;
473 
474     bool operator==(const Rect& a) const
475     {
476         return (posX_ == a.posX_ && posY_ == a.posY_ && width_ == a.width_ && height_ == a.height_);
477     }
478 
479     bool operator!=(const Rect& a) const
480     {
481         return !this->operator==(a);
482     }
483 
IsInsideOfRect484     bool IsInsideOf(const Rect& a) const
485     {
486         return (posX_ >= a.posX_ && posY_ >= a.posY_ &&
487             posX_ + width_ <= a.posX_ + a.width_ && posY_ + height_ <= a.posY_ + a.height_);
488     }
489 
IsUninitializedRectRect490     bool IsUninitializedRect() const
491     {
492         return (posX_ == 0 && posY_ == 0 && width_ == 0 && height_ == 0);
493     }
494 
IsUninitializedSizeRect495     bool IsUninitializedSize() const
496     {
497         return width_ == 0 && height_ == 0;
498     }
499 };
500 
501 /**
502  * @struct SystemBarProperty
503  *
504  * @brief Property of system bar.
505  */
506 struct SystemBarProperty {
507     bool enable_;
508     uint32_t backgroundColor_;
509     uint32_t contentColor_;
510     bool enableAnimation_;
511     SystemBarSettingFlag settingFlag_;
SystemBarPropertySystemBarProperty512     SystemBarProperty() : enable_(true), backgroundColor_(SYSTEM_COLOR_BLACK), contentColor_(SYSTEM_COLOR_WHITE),
513                           enableAnimation_(false), settingFlag_(SystemBarSettingFlag::DEFAULT_SETTING) {}
SystemBarPropertySystemBarProperty514     SystemBarProperty(bool enable, uint32_t background, uint32_t content, bool enableAnimation)
515         : enable_(enable), backgroundColor_(background), contentColor_(content), enableAnimation_(enableAnimation),
516           settingFlag_(SystemBarSettingFlag::DEFAULT_SETTING) {}
SystemBarPropertySystemBarProperty517     SystemBarProperty(bool enable, uint32_t background, uint32_t content)
518         : enable_(enable), backgroundColor_(background), contentColor_(content), enableAnimation_(false),
519           settingFlag_(SystemBarSettingFlag::DEFAULT_SETTING) {}
SystemBarPropertySystemBarProperty520     SystemBarProperty(bool enable, uint32_t background, uint32_t content,
521                       bool enableAnimation, SystemBarSettingFlag settingFlag)
522         : enable_(enable), backgroundColor_(background), contentColor_(content), enableAnimation_(enableAnimation),
523           settingFlag_(settingFlag) {}
524 
525     bool operator == (const SystemBarProperty& a) const
526     {
527         return (enable_ == a.enable_ && backgroundColor_ == a.backgroundColor_ && contentColor_ == a.contentColor_ &&
528             enableAnimation_ == a.enableAnimation_);
529     }
530 };
531 
532 /**
533  * @brief Enumerates avoid area type.
534  */
535 enum class AvoidAreaType : uint32_t {
536     TYPE_SYSTEM,               // area of SystemUI
537     TYPE_CUTOUT,               // cutout of screen
538     TYPE_SYSTEM_GESTURE,       // area for system gesture
539     TYPE_KEYBOARD,             // area for soft input keyboard
540     TYPE_NAVIGATION_INDICATOR, // area for navigation indicator
541 };
542 
543 /**
544  * @brief Enumerates color space.
545  */
546 enum class ColorSpace : uint32_t {
547     COLOR_SPACE_DEFAULT = 0, // Default color space.
548     COLOR_SPACE_WIDE_GAMUT,  // Wide gamut color space. The specific wide color gamut depends on the screen.
549 };
550 
551 /**
552  * @brief Enumerates occupied area type.
553  */
554 enum class OccupiedAreaType : uint32_t {
555     TYPE_INPUT, // area of input window
556 };
557 
558 /**
559  * @brief Enumerates window maximize mode.
560  */
561 enum class MaximizeMode : uint32_t {
562     MODE_AVOID_SYSTEM_BAR,
563     MODE_FULL_FILL,
564     MODE_RECOVER
565 };
566 
567 /**
568  * @brief Enumerates window animation.
569  */
570 enum class WindowAnimation : uint32_t {
571     NONE,
572     DEFAULT,
573     INPUTE,
574     CUSTOM
575 };
576 
577 /**
578  * @class AvoidArea
579  *
580  * @brief Area needed to avoid.
581  */
582 class AvoidArea : virtual public RefBase {
583 public:
584     Rect topRect_ { 0, 0, 0, 0 };
585     Rect leftRect_ { 0, 0, 0, 0 };
586     Rect rightRect_ { 0, 0, 0, 0 };
587     Rect bottomRect_ { 0, 0, 0, 0 };
588 
589     bool operator==(const AvoidArea& a) const
590     {
591         return (topRect_ == a.topRect_ && leftRect_ == a.leftRect_ &&
592             rightRect_ == a.rightRect_ && bottomRect_ == a.bottomRect_);
593     }
594 
595     bool operator!=(const AvoidArea& a) const
596     {
597         return !this->operator==(a);
598     }
599 
ReadParcel(Parcel & parcel,Rect & rect)600     static inline bool ReadParcel(Parcel& parcel, Rect& rect)
601     {
602         return parcel.ReadInt32(rect.posX_) && parcel.ReadInt32(rect.posY_) &&
603             parcel.ReadUint32(rect.width_) && parcel.ReadUint32(rect.height_);
604     }
605 
WriteParcel(Parcel & parcel,const Rect & rect)606     static inline bool WriteParcel(Parcel& parcel, const Rect& rect)
607     {
608         return parcel.WriteInt32(rect.posX_) && parcel.WriteInt32(rect.posY_) &&
609             parcel.WriteUint32(rect.width_) && parcel.WriteUint32(rect.height_);
610     }
611 
isEmptyAvoidArea()612     bool isEmptyAvoidArea() const
613     {
614         return topRect_.IsUninitializedRect() && leftRect_.IsUninitializedRect() &&
615             rightRect_.IsUninitializedRect() && bottomRect_.IsUninitializedRect();
616     }
617 };
618 
619 using OnCallback = std::function<void(int64_t, int64_t)>;
620 
621 /**
622  * @struct VsyncCallback
623  *
624  * @brief Vsync callback
625  */
626 struct VsyncCallback {
627     OnCallback onCallback;
628 };
629 
630 /**
631  * @brief Enumerates window update type.
632  */
633 enum class WindowUpdateType : int32_t {
634     WINDOW_UPDATE_ADDED = 1,
635     WINDOW_UPDATE_REMOVED,
636     WINDOW_UPDATE_FOCUSED,
637     WINDOW_UPDATE_BOUNDS,
638     WINDOW_UPDATE_ACTIVE,
639     WINDOW_UPDATE_PROPERTY
640 };
641 
642 struct WindowLimits {
643     uint32_t maxWidth_ = UINT32_MAX;
644     uint32_t maxHeight_ = UINT32_MAX;
645     uint32_t minWidth_ = 0;
646     uint32_t minHeight_ = 0;
647     float maxRatio_ = FLT_MAX;
648     float minRatio_ = 0.0f;
649     float vpRatio_ = 1.0f;
650 
WindowLimitsWindowLimits651     WindowLimits() {}
WindowLimitsWindowLimits652     WindowLimits(uint32_t maxWidth, uint32_t maxHeight, uint32_t minWidth, uint32_t minHeight, float maxRatio,
653         float minRatio) : maxWidth_(maxWidth), maxHeight_(maxHeight), minWidth_(minWidth), minHeight_(minHeight),
654         maxRatio_(maxRatio), minRatio_(minRatio) {}
WindowLimitsWindowLimits655     WindowLimits(uint32_t maxWidth, uint32_t maxHeight, uint32_t minWidth, uint32_t minHeight, float maxRatio,
656         float minRatio, float vpRatio) : maxWidth_(maxWidth), maxHeight_(maxHeight), minWidth_(minWidth),
657         minHeight_(minHeight), maxRatio_(maxRatio), minRatio_(minRatio), vpRatio_(vpRatio) {}
658 
IsEmptyWindowLimits659     bool IsEmpty() const
660     {
661         return (maxHeight_ == 0 || minHeight_ == 0 || maxWidth_ == 0 || minWidth_ == 0);
662     }
663 };
664 
665 /**
666  * @struct TitleButtonRect
667  *
668  * @brief An area of title buttons relative to the upper right corner of the window.
669  */
670 struct TitleButtonRect {
671     int32_t posX_;
672     int32_t posY_;
673     uint32_t width_;
674     uint32_t height_;
675 
676     bool operator==(const TitleButtonRect& a) const
677     {
678         return (posX_ == a.posX_ && posY_ == a.posY_ && width_ == a.width_ && height_ == a.height_);
679     }
680 
681     bool operator!=(const TitleButtonRect& a) const
682     {
683         return !this->operator==(a);
684     }
685 
IsInsideOfTitleButtonRect686     bool IsInsideOf(const TitleButtonRect& a) const
687     {
688         return (posX_ >= a.posX_ && posY_ >= a.posY_ &&
689             posX_ + width_ <= a.posX_ + a.width_ && posY_ + height_ <= a.posY_ + a.height_);
690     }
691 
IsUninitializedRectTitleButtonRect692     bool IsUninitializedRect() const
693     {
694         return (posX_ == 0 && posY_ == 0 && width_ == 0 && height_ == 0);
695     }
696 };
697 
698 /*
699  * Config of keyboard animation
700  */
701 class KeyboardAnimationCurve : public Parcelable {
702 public:
703     KeyboardAnimationCurve() = default;
KeyboardAnimationCurve(const std::string & curveType,const std::vector<float> & curveParams,uint32_t duration)704     KeyboardAnimationCurve(const std::string& curveType, const std::vector<float>& curveParams, uint32_t duration)
705         : curveType_(curveType), duration_(duration)
706     {
707         curveParams_.assign(curveParams.begin(), curveParams.end());
708     }
709 
Marshalling(Parcel & parcel)710     virtual bool Marshalling(Parcel& parcel) const override
711     {
712         if (!parcel.WriteString(curveType_)) {
713             return false;
714         }
715 
716         auto paramSize = curveParams_.size();
717         if (paramSize == 4) { // 4: param size
718             if (!parcel.WriteUint32(static_cast<uint32_t>(paramSize))) {
719                 return false;
720             }
721             for (auto& param : curveParams_) {
722                 if (!parcel.WriteFloat(param)) {
723                     return false;
724                 }
725             }
726         } else {
727             if (!parcel.WriteUint32(0)) {
728                 return false;
729             }
730         }
731 
732         if (!parcel.WriteUint32(duration_)) {
733             return false;
734         }
735         return true;
736     }
737 
Unmarshalling(Parcel & parcel)738     static KeyboardAnimationCurve* Unmarshalling(Parcel& parcel)
739     {
740         KeyboardAnimationCurve* config = new KeyboardAnimationCurve;
741         uint32_t paramSize = 0;
742         if (!parcel.ReadString(config->curveType_) || !parcel.ReadUint32(paramSize)) {
743             delete config;
744             return nullptr;
745         }
746 
747         if (paramSize == 4) { // 4: paramSize
748             for (uint32_t i = 0; i < paramSize; i++) {
749                 float param = 0.0f;
750                 if (!parcel.ReadFloat(param)) {
751                     delete config;
752                     return nullptr;
753                 } else {
754                     config->curveParams_.push_back(param);
755                 }
756             }
757         }
758 
759         if (!parcel.ReadUint32(config->duration_)) {
760             delete config;
761             return nullptr;
762         }
763         return config;
764     }
765 
766     std::string curveType_ = "";
767     std::vector<float> curveParams_ = {};
768     uint32_t duration_ = 0;
769 };
770 
771 struct KeyboardAnimationConfig {
772     KeyboardAnimationCurve curveIn;
773     KeyboardAnimationCurve curveOut;
774 };
775 
776 enum class MaximizePresentation {
777     FOLLOW_APP_IMMERSIVE_SETTING = 0,   // follow app set imersiveStateEnable
778     EXIT_IMMERSIVE = 1,        // imersiveStateEnable will be set as false
779     ENTER_IMMERSIVE = 2,        // imersiveStateEnable will be set as true
780 };
781 }
782 }
783 #endif // OHOS_ROSEN_WM_COMMON_H
784