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