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_OPER_FULLSCREEN_FAILED,
175 WM_ERROR_REPEAT_OPERATION,
176 WM_ERROR_INVALID_SESSION,
177 WM_ERROR_INVALID_CALLING,
178 WM_ERROR_SYSTEM_ABNORMALLY,
179
180 WM_ERROR_DEVICE_NOT_SUPPORT = 801, // the value do not change.It is defined on all system.
181
182 WM_ERROR_NEED_REPORT_BASE = 1000, // error code > 1000 means need report.
183 WM_ERROR_NULLPTR,
184 WM_ERROR_INVALID_TYPE,
185 WM_ERROR_INVALID_PARAM,
186 WM_ERROR_SAMGR,
187 WM_ERROR_IPC_FAILED,
188 WM_ERROR_NEED_REPORT_END,
189 WM_ERROR_START_ABILITY_FAILED,
190 WM_ERROR_PIP_DESTROY_FAILED,
191 WM_ERROR_PIP_STATE_ABNORMALLY,
192 WM_ERROR_PIP_CREATE_FAILED,
193 WM_ERROR_PIP_INTERNAL_ERROR,
194 WM_ERROR_PIP_REPEAT_OPERATION
195 };
196
197 /**
198 * @brief Enumerates error code of window only used for js api.
199 */
200 enum class WmErrorCode : int32_t {
201 WM_OK = 0,
202 WM_ERROR_NO_PERMISSION = 201,
203 WM_ERROR_NOT_SYSTEM_APP = 202,
204 WM_ERROR_INVALID_PARAM = 401,
205 WM_ERROR_DEVICE_NOT_SUPPORT = 801,
206
207 WM_ERROR_REPEAT_OPERATION = 1300001,
208 WM_ERROR_STATE_ABNORMALLY = 1300002,
209 WM_ERROR_SYSTEM_ABNORMALLY = 1300003,
210 WM_ERROR_INVALID_CALLING = 1300004,
211 WM_ERROR_STAGE_ABNORMALLY = 1300005,
212 WM_ERROR_CONTEXT_ABNORMALLY = 1300006,
213 WM_ERROR_START_ABILITY_FAILED = 1300007,
214 WM_ERROR_INVALID_DISPLAY = 1300008,
215 WM_ERROR_INVALID_PARENT = 1300009,
216 WM_ERROR_OPER_FULLSCREEN_FAILED = 1300010,
217 WM_ERROR_PIP_DESTROY_FAILED = 1300011,
218 WM_ERROR_PIP_STATE_ABNORMALLY = 1300012,
219 WM_ERROR_PIP_CREATE_FAILED = 1300013,
220 WM_ERROR_PIP_INTERNAL_ERROR = 1300014,
221 WM_ERROR_PIP_REPEAT_OPERATION = 1300015
222 };
223
224 /**
225 * @brief Enumerates setting flag of systemStatusBar.
226 */
227 enum class SystemBarSettingFlag : uint32_t {
228 DEFAULT_SETTING = 0,
229 COLOR_SETTING = 1,
230 ENABLE_SETTING = 1 << 1,
231 ALL_SETTING = 0b11
232 };
233
operator |(SystemBarSettingFlag lhs, SystemBarSettingFlag rhs)234 inline SystemBarSettingFlag operator|(SystemBarSettingFlag lhs, SystemBarSettingFlag rhs)
235 {
236 using T = std::underlying_type_t<SystemBarSettingFlag>;
237 return static_cast<SystemBarSettingFlag>(static_cast<T>(lhs) | static_cast<T>(rhs));
238 }
239
240 /**
241 * @brief Enumerates flag of window.
242 */
243 enum class WindowFlag : uint32_t {
244 WINDOW_FLAG_NEED_AVOID = 1,
245 WINDOW_FLAG_PARENT_LIMIT = 1 << 1,
246 WINDOW_FLAG_SHOW_WHEN_LOCKED = 1 << 2,
247 WINDOW_FLAG_FORBID_SPLIT_MOVE = 1 << 3,
248 WINDOW_FLAG_WATER_MARK = 1 << 4,
249 WINDOW_FLAG_IS_MODAL = 1 << 5,
250 WINDOW_FLAG_IS_APPLICATION_MODAL = 1 << 6,
251 WINDOW_FLAG_HANDWRITING = 1 << 7,
252 WINDOW_FLAG_IS_TOAST = 1 << 8,
253 WINDOW_FLAG_END = 1 << 9,
254 };
255
256 /**
257 * @brief Enumerates flag of multiWindowUIType.
258 */
259 enum class WindowUIType : uint8_t {
260 PHONE_WINDOW = 0,
261 PC_WINDOW,
262 PAD_WINDOW,
263 INVALID_WINDOW
264 };
265
266 /**
267 * @brief Used to map from WMError to WmErrorCode.
268 */
269 const std::map<WMError, WmErrorCode> WM_JS_TO_ERROR_CODE_MAP {
270 {WMError::WM_OK, WmErrorCode::WM_OK },
271 {WMError::WM_DO_NOTHING, WmErrorCode::WM_ERROR_STATE_ABNORMALLY },
272 {WMError::WM_ERROR_DESTROYED_OBJECT, WmErrorCode::WM_ERROR_STATE_ABNORMALLY },
273 {WMError::WM_ERROR_DEVICE_NOT_SUPPORT, WmErrorCode::WM_ERROR_DEVICE_NOT_SUPPORT },
274 {WMError::WM_ERROR_INVALID_OPERATION, WmErrorCode::WM_ERROR_STATE_ABNORMALLY },
275 {WMError::WM_ERROR_INVALID_PARAM, WmErrorCode::WM_ERROR_INVALID_PARAM },
276 {WMError::WM_ERROR_INVALID_PERMISSION, WmErrorCode::WM_ERROR_NO_PERMISSION },
277 {WMError::WM_ERROR_NOT_SYSTEM_APP, WmErrorCode::WM_ERROR_NOT_SYSTEM_APP },
278 {WMError::WM_ERROR_INVALID_TYPE, WmErrorCode::WM_ERROR_STATE_ABNORMALLY },
279 {WMError::WM_ERROR_INVALID_WINDOW, WmErrorCode::WM_ERROR_STATE_ABNORMALLY },
280 {WMError::WM_ERROR_INVALID_WINDOW_MODE_OR_SIZE, WmErrorCode::WM_ERROR_STATE_ABNORMALLY },
281 {WMError::WM_ERROR_IPC_FAILED, WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY },
282 {WMError::WM_ERROR_NO_MEM, WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY },
283 {WMError::WM_ERROR_NO_REMOTE_ANIMATION, WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY },
284 {WMError::WM_ERROR_INVALID_DISPLAY, WmErrorCode::WM_ERROR_INVALID_DISPLAY },
285 {WMError::WM_ERROR_INVALID_PARENT, WmErrorCode::WM_ERROR_INVALID_PARENT },
286 {WMError::WM_ERROR_OPER_FULLSCREEN_FAILED, WmErrorCode::WM_ERROR_OPER_FULLSCREEN_FAILED },
287 {WMError::WM_ERROR_REPEAT_OPERATION, WmErrorCode::WM_ERROR_REPEAT_OPERATION },
288 {WMError::WM_ERROR_NULLPTR, WmErrorCode::WM_ERROR_STATE_ABNORMALLY },
289 {WMError::WM_ERROR_SAMGR, WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY },
290 {WMError::WM_ERROR_START_ABILITY_FAILED, WmErrorCode::WM_ERROR_START_ABILITY_FAILED },
291 {WMError::WM_ERROR_SYSTEM_ABNORMALLY, WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY },
292 };
293
294 /**
295 * @brief Enumerates window size change reason.
296 */
297 enum class WindowSizeChangeReason : uint32_t {
298 UNDEFINED = 0,
299 MAXIMIZE,
300 RECOVER,
301 ROTATION,
302 DRAG,
303 DRAG_START,
304 DRAG_END,
305 RESIZE,
306 MOVE,
307 HIDE,
308 TRANSFORM,
309 CUSTOM_ANIMATION_SHOW,
310 FULL_TO_SPLIT,
311 SPLIT_TO_FULL,
312 FULL_TO_FLOATING,
313 FLOATING_TO_FULL,
314 PIP_START,
315 PIP_SHOW,
316 PIP_AUTO_START,
317 PIP_RATIO_CHANGE,
318 PIP_RESTORE,
319 END
320 };
321
322 /**
323 * @brief Enumerates window gravity.
324 */
325 enum class WindowGravity : uint32_t {
326 WINDOW_GRAVITY_FLOAT = 0,
327 WINDOW_GRAVITY_BOTTOM
328 };
329
330 /**
331 * @brief Enumerates window session type.
332 */
333 enum class WindowSessionType : uint32_t {
334 SCENE_SESSION = 0,
335 EXTENSION_SESSION = 1
336 };
337
338 /**
339 * @brief Enumerates window tag.
340 */
341 enum class WindowTag : uint32_t {
342 MAIN_WINDOW = 0,
343 SUB_WINDOW = 1,
344 SYSTEM_WINDOW = 2
345 };
346
347 /**
348 * @brief Enumerates drag event.
349 */
350 enum class DragEvent : uint32_t {
351 DRAG_EVENT_IN = 1,
352 DRAG_EVENT_OUT,
353 DRAG_EVENT_MOVE,
354 DRAG_EVENT_END
355 };
356
357 /**
358 * @brief Enumerates layout mode of window.
359 */
360 enum class WindowLayoutMode : uint32_t {
361 BASE = 0,
362 CASCADE = BASE,
363 TILE = 1,
364 END,
365 };
366
367 namespace {
368 constexpr uint32_t SYSTEM_COLOR_WHITE = 0xE5FFFFFF;
369 constexpr uint32_t SYSTEM_COLOR_BLACK = 0x66000000;
370 constexpr float UNDEFINED_BRIGHTNESS = -1.0f;
371 constexpr float MINIMUM_BRIGHTNESS = 0.0f;
372 constexpr float MAXIMUM_BRIGHTNESS = 1.0f;
373
374 constexpr uint32_t INVALID_WINDOW_ID = 0;
375 constexpr int32_t INVALID_PID = -1;
376 constexpr int32_t INVALID_UID = -1;
377 }
378
379 /**
380 * @struct PointInfo.
381 *
382 * @brief Point info.
383 */
384 struct PointInfo {
385 int32_t x;
386 int32_t y;
387 };
388
389 /**
390 * @class Transform
391 *
392 * @brief parameter of transform and rotate.
393 */
394 class Transform {
395 public:
Transform()396 Transform()
397 : pivotX_(0.5f), pivotY_(0.5f), scaleX_(1.f), scaleY_(1.f), scaleZ_(1.f), rotationX_(0.f),
398 rotationY_(0.f), rotationZ_(0.f), translateX_(0.f), translateY_(0.f), translateZ_(0.f)
399 {}
~Transform()400 ~Transform() {}
401
operator ==(const Transform& right) const402 bool operator==(const Transform& right) const
403 {
404 return NearZero(scaleX_ - right.scaleX_) &&
405 NearZero(scaleY_ - right.scaleY_) &&
406 NearZero(scaleZ_ - right.scaleZ_) &&
407 NearZero(pivotX_ - right.pivotX_) &&
408 NearZero(pivotY_ - right.pivotY_) &&
409 NearZero(translateX_ - right.translateX_) &&
410 NearZero(translateY_ - right.translateY_) &&
411 NearZero(translateZ_ - right.translateZ_) &&
412 NearZero(rotationX_ - right.rotationX_) &&
413 NearZero(rotationY_ - right.rotationY_) &&
414 NearZero(rotationZ_ - right.rotationZ_);
415 }
416
operator !=(const Transform& right) const417 bool operator!=(const Transform& right) const
418 {
419 return !(*this == right);
420 }
421
Identity()422 static const Transform& Identity()
423 {
424 static Transform I;
425 return I;
426 }
427
428 float pivotX_;
429 float pivotY_;
430 float scaleX_;
431 float scaleY_;
432 float scaleZ_;
433 float rotationX_;
434 float rotationY_;
435 float rotationZ_;
436 float translateX_;
437 float translateY_;
438 float translateZ_;
439
Unmarshalling(Parcel& parcel)440 void Unmarshalling(Parcel& parcel)
441 {
442 pivotX_ = parcel.ReadFloat();
443 pivotY_ = parcel.ReadFloat();
444 scaleX_ = parcel.ReadFloat();
445 scaleY_ = parcel.ReadFloat();
446 scaleZ_ = parcel.ReadFloat();
447 rotationX_ = parcel.ReadFloat();
448 rotationY_ = parcel.ReadFloat();
449 rotationZ_ = parcel.ReadFloat();
450 translateX_ = parcel.ReadFloat();
451 translateY_ = parcel.ReadFloat();
452 translateZ_ = parcel.ReadFloat();
453 }
454
Marshalling(Parcel& parcel) const455 bool Marshalling(Parcel& parcel) const
456 {
457 return parcel.WriteFloat(pivotX_) && parcel.WriteFloat(pivotY_) &&
458 parcel.WriteFloat(scaleX_) && parcel.WriteFloat(scaleY_) && parcel.WriteFloat(scaleZ_) &&
459 parcel.WriteFloat(rotationX_) && parcel.WriteFloat(rotationY_) && parcel.WriteFloat(rotationZ_) &&
460 parcel.WriteFloat(translateX_) && parcel.WriteFloat(translateY_) && parcel.WriteFloat(translateZ_);
461 }
462
463 private:
NearZero(float val)464 static inline bool NearZero(float val)
465 {
466 return -0.001f < val && val < 0.001f;
467 }
468 };
469
470 /**
471 * @struct SystemBarPropertyFlag
472 *
473 * @brief Flag of system bar
474 */
475 struct SystemBarPropertyFlag {
476 bool enableFlag = false;
477 bool backgroundColorFlag = false;
478 bool contentColorFlag = false;
479 bool enableAnimationFlag = false;
480 };
481
482 /**
483 * @struct Rect
484 *
485 * @brief Window Rect.
486 */
487 struct Rect {
488 int32_t posX_;
489 int32_t posY_;
490 uint32_t width_;
491 uint32_t height_;
492
operator ==OHOS::Rosen::WindowType::WindowState::WmErrorCode::SystemBarSettingFlag::WindowSessionType::WindowTag::Rect493 bool operator==(const Rect& a) const
494 {
495 return (posX_ == a.posX_ && posY_ == a.posY_ && width_ == a.width_ && height_ == a.height_);
496 }
497
operator !=OHOS::Rosen::WindowType::WindowState::WmErrorCode::SystemBarSettingFlag::WindowSessionType::WindowTag::Rect498 bool operator!=(const Rect& a) const
499 {
500 return !this->operator==(a);
501 }
502
IsInsideOfOHOS::Rosen::WindowType::WindowState::WmErrorCode::SystemBarSettingFlag::WindowSessionType::WindowTag::Rect503 bool IsInsideOf(const Rect& a) const
504 {
505 return (posX_ >= a.posX_ && posY_ >= a.posY_ &&
506 posX_ + width_ <= a.posX_ + a.width_ && posY_ + height_ <= a.posY_ + a.height_);
507 }
508
IsUninitializedRectOHOS::Rosen::WindowType::WindowState::WmErrorCode::SystemBarSettingFlag::WindowSessionType::WindowTag::Rect509 bool IsUninitializedRect() const
510 {
511 return (posX_ == 0 && posY_ == 0 && width_ == 0 && height_ == 0);
512 }
513 };
514
515 /**
516 * @struct SystemBarProperty
517 *
518 * @brief Property of system bar.
519 */
520 struct SystemBarProperty {
521 bool enable_;
522 uint32_t backgroundColor_;
523 uint32_t contentColor_;
524 bool enableAnimation_;
525 SystemBarSettingFlag settingFlag_;
SystemBarPropertyOHOS::Rosen::WindowType::WindowState::WmErrorCode::SystemBarSettingFlag::WindowSessionType::WindowTag::SystemBarProperty526 SystemBarProperty() : enable_(true), backgroundColor_(SYSTEM_COLOR_BLACK), contentColor_(SYSTEM_COLOR_WHITE),
527 enableAnimation_(false), settingFlag_(SystemBarSettingFlag::DEFAULT_SETTING) {}
SystemBarPropertyOHOS::Rosen::WindowType::WindowState::WmErrorCode::SystemBarSettingFlag::WindowSessionType::WindowTag::SystemBarProperty528 SystemBarProperty(bool enable, uint32_t background, uint32_t content, bool enableAnimation)
529 : enable_(enable), backgroundColor_(background), contentColor_(content), enableAnimation_(enableAnimation),
530 settingFlag_(SystemBarSettingFlag::DEFAULT_SETTING) {}
SystemBarPropertyOHOS::Rosen::WindowType::WindowState::WmErrorCode::SystemBarSettingFlag::WindowSessionType::WindowTag::SystemBarProperty531 SystemBarProperty(bool enable, uint32_t background, uint32_t content)
532 : enable_(enable), backgroundColor_(background), contentColor_(content), enableAnimation_(false),
533 settingFlag_(SystemBarSettingFlag::DEFAULT_SETTING) {}
SystemBarPropertyOHOS::Rosen::WindowType::WindowState::WmErrorCode::SystemBarSettingFlag::WindowSessionType::WindowTag::SystemBarProperty534 SystemBarProperty(bool enable, uint32_t background, uint32_t content,
535 bool enableAnimation, SystemBarSettingFlag settingFlag)
536 : enable_(enable), backgroundColor_(background), contentColor_(content), enableAnimation_(enableAnimation),
537 settingFlag_(settingFlag) {}
538
operator ==OHOS::Rosen::WindowType::WindowState::WmErrorCode::SystemBarSettingFlag::WindowSessionType::WindowTag::SystemBarProperty539 bool operator == (const SystemBarProperty& a) const
540 {
541 return (enable_ == a.enable_ && backgroundColor_ == a.backgroundColor_ && contentColor_ == a.contentColor_ &&
542 enableAnimation_ == a.enableAnimation_);
543 }
544 };
545
546 /**
547 * @brief Enumerates avoid area type.
548 */
549 enum class AvoidAreaType : uint32_t {
550 TYPE_SYSTEM, // area of SystemUI
551 TYPE_CUTOUT, // cutout of screen
552 TYPE_SYSTEM_GESTURE, // area for system gesture
553 TYPE_KEYBOARD, // area for soft input keyboard
554 TYPE_NAVIGATION_INDICATOR, // area for navigation indicator
555 };
556
557 /**
558 * @brief Enumerates color space.
559 */
560 enum class ColorSpace : uint32_t {
561 COLOR_SPACE_DEFAULT = 0, // Default color space.
562 COLOR_SPACE_WIDE_GAMUT, // Wide gamut color space. The specific wide color gamut depends on the screen.
563 };
564
565 /**
566 * @brief Enumerates occupied area type.
567 */
568 enum class OccupiedAreaType : uint32_t {
569 TYPE_INPUT, // area of input window
570 };
571
572 /**
573 * @brief Enumerates window maximize mode.
574 */
575 enum class MaximizeMode : uint32_t {
576 MODE_AVOID_SYSTEM_BAR,
577 MODE_FULL_FILL,
578 MODE_RECOVER
579 };
580
581 /**
582 * @brief Enumerates window animation.
583 */
584 enum class WindowAnimation : uint32_t {
585 NONE,
586 DEFAULT,
587 INPUTE,
588 CUSTOM
589 };
590
591 /**
592 * @class AvoidArea
593 *
594 * @brief Area needed to avoid.
595 */
596 class AvoidArea : virtual public RefBase {
597 public:
598 Rect topRect_ { 0, 0, 0, 0 };
599 Rect leftRect_ { 0, 0, 0, 0 };
600 Rect rightRect_ { 0, 0, 0, 0 };
601 Rect bottomRect_ { 0, 0, 0, 0 };
602
operator ==(const AvoidArea& a) const603 bool operator==(const AvoidArea& a) const
604 {
605 return (topRect_ == a.topRect_ && leftRect_ == a.leftRect_ &&
606 rightRect_ == a.rightRect_ && bottomRect_ == a.bottomRect_);
607 }
608
operator !=(const AvoidArea& a) const609 bool operator!=(const AvoidArea& a) const
610 {
611 return !this->operator==(a);
612 }
613
ReadParcel(Parcel& parcel, Rect& rect)614 static inline bool ReadParcel(Parcel& parcel, Rect& rect)
615 {
616 return parcel.ReadInt32(rect.posX_) && parcel.ReadInt32(rect.posY_) &&
617 parcel.ReadUint32(rect.width_) && parcel.ReadUint32(rect.height_);
618 }
619
WriteParcel(Parcel& parcel, const Rect& rect)620 static inline bool WriteParcel(Parcel& parcel, const Rect& rect)
621 {
622 return parcel.WriteInt32(rect.posX_) && parcel.WriteInt32(rect.posY_) &&
623 parcel.WriteUint32(rect.width_) && parcel.WriteUint32(rect.height_);
624 }
625
isEmptyAvoidArea() const626 bool isEmptyAvoidArea() const
627 {
628 return topRect_.IsUninitializedRect() && leftRect_.IsUninitializedRect() &&
629 rightRect_.IsUninitializedRect() && bottomRect_.IsUninitializedRect();
630 }
631 };
632
633 using OnCallback = std::function<void(int64_t, int64_t)>;
634
635 /**
636 * @struct VsyncCallback
637 *
638 * @brief Vsync callback
639 */
640 struct VsyncCallback {
641 OnCallback onCallback;
642 };
643
644 /**
645 * @brief Enumerates window update type.
646 */
647 enum class WindowUpdateType : int32_t {
648 WINDOW_UPDATE_ADDED = 1,
649 WINDOW_UPDATE_REMOVED,
650 WINDOW_UPDATE_FOCUSED,
651 WINDOW_UPDATE_BOUNDS,
652 WINDOW_UPDATE_ACTIVE,
653 WINDOW_UPDATE_PROPERTY
654 };
655
656 struct WindowLimits {
657 uint32_t maxWidth_ = INT32_MAX;
658 uint32_t maxHeight_ = INT32_MAX;
659 uint32_t minWidth_ = 1;
660 uint32_t minHeight_ = 1;
661 float maxRatio_ = FLT_MAX;
662 float minRatio_ = 0.0f;
663 float vpRatio_ = 1.0f;
664
WindowLimitsOHOS::Rosen::WindowType::WindowState::WmErrorCode::SystemBarSettingFlag::WindowSessionType::WindowTag::WindowLimits665 WindowLimits() {}
WindowLimitsOHOS::Rosen::WindowType::WindowState::WmErrorCode::SystemBarSettingFlag::WindowSessionType::WindowTag::WindowLimits666 WindowLimits(uint32_t maxWidth, uint32_t maxHeight, uint32_t minWidth, uint32_t minHeight, float maxRatio,
667 float minRatio) : maxWidth_(maxWidth), maxHeight_(maxHeight), minWidth_(minWidth), minHeight_(minHeight),
668 maxRatio_(maxRatio), minRatio_(minRatio) {}
WindowLimitsOHOS::Rosen::WindowType::WindowState::WmErrorCode::SystemBarSettingFlag::WindowSessionType::WindowTag::WindowLimits669 WindowLimits(uint32_t maxWidth, uint32_t maxHeight, uint32_t minWidth, uint32_t minHeight, float maxRatio,
670 float minRatio, float vpRatio) : maxWidth_(maxWidth), maxHeight_(maxHeight), minWidth_(minWidth),
671 minHeight_(minHeight), maxRatio_(maxRatio), minRatio_(minRatio), vpRatio_(vpRatio) {}
672
IsEmptyOHOS::Rosen::WindowType::WindowState::WmErrorCode::SystemBarSettingFlag::WindowSessionType::WindowTag::WindowLimits673 bool IsEmpty() const
674 {
675 return (maxHeight_ == 0 || minHeight_ == 0 || maxWidth_ == 0 || minWidth_ == 0);
676 }
677 };
678
679 /**
680 * @struct TitleButtonRect
681 *
682 * @brief An area of title buttons relative to the upper right corner of the window.
683 */
684 struct TitleButtonRect {
685 int32_t posX_;
686 int32_t posY_;
687 uint32_t width_;
688 uint32_t height_;
689
operator ==OHOS::Rosen::WindowType::WindowState::WmErrorCode::SystemBarSettingFlag::WindowSessionType::WindowTag::TitleButtonRect690 bool operator==(const TitleButtonRect& a) const
691 {
692 return (posX_ == a.posX_ && posY_ == a.posY_ && width_ == a.width_ && height_ == a.height_);
693 }
694
operator !=OHOS::Rosen::WindowType::WindowState::WmErrorCode::SystemBarSettingFlag::WindowSessionType::WindowTag::TitleButtonRect695 bool operator!=(const TitleButtonRect& a) const
696 {
697 return !this->operator==(a);
698 }
699
IsInsideOfOHOS::Rosen::WindowType::WindowState::WmErrorCode::SystemBarSettingFlag::WindowSessionType::WindowTag::TitleButtonRect700 bool IsInsideOf(const TitleButtonRect& a) const
701 {
702 return (posX_ >= a.posX_ && posY_ >= a.posY_ &&
703 posX_ + width_ <= a.posX_ + a.width_ && posY_ + height_ <= a.posY_ + a.height_);
704 }
705
IsUninitializedRectOHOS::Rosen::WindowType::WindowState::WmErrorCode::SystemBarSettingFlag::WindowSessionType::WindowTag::TitleButtonRect706 bool IsUninitializedRect() const
707 {
708 return (posX_ == 0 && posY_ == 0 && width_ == 0 && height_ == 0);
709 }
710 };
711
712 /*
713 * Config of keyboard animation
714 */
715 class KeyboardAnimationCurve : public Parcelable {
716 public:
717 KeyboardAnimationCurve() = default;
KeyboardAnimationCurve(const std::string& curveType, const std::vector<float>& curveParams, uint32_t duration)718 KeyboardAnimationCurve(const std::string& curveType, const std::vector<float>& curveParams, uint32_t duration)
719 : curveType_(curveType), duration_(duration)
720 {
721 curveParams_.assign(curveParams.begin(), curveParams.end());
722 }
723
724 virtual bool Marshalling(Parcel& parcel) const override
725 {
726 if (!parcel.WriteString(curveType_)) {
727 return false;
728 }
729
730 auto paramSize = curveParams_.size();
731 if (paramSize == 4) { // 4: param size
732 if (!parcel.WriteUint32(static_cast<uint32_t>(paramSize))) {
733 return false;
734 }
735 for (auto& param : curveParams_) {
736 if (!parcel.WriteFloat(param)) {
737 return false;
738 }
739 }
740 } else {
741 if (!parcel.WriteUint32(0)) {
742 return false;
743 }
744 }
745
746 if (!parcel.WriteUint32(duration_)) {
747 return false;
748 }
749 return true;
750 }
751
Unmarshalling(Parcel& parcel)752 static KeyboardAnimationCurve* Unmarshalling(Parcel& parcel)
753 {
754 KeyboardAnimationCurve* config = new KeyboardAnimationCurve;
755 uint32_t paramSize = 0;
756 if (!parcel.ReadString(config->curveType_) || !parcel.ReadUint32(paramSize)) {
757 delete config;
758 return nullptr;
759 }
760
761 if (paramSize == 4) { // 4: paramSize
762 for (uint32_t i = 0; i < paramSize; i++) {
763 float param = 0.0f;
764 if (!parcel.ReadFloat(param)) {
765 delete config;
766 return nullptr;
767 } else {
768 config->curveParams_.push_back(param);
769 }
770 }
771 }
772
773 if (!parcel.ReadUint32(config->duration_)) {
774 delete config;
775 return nullptr;
776 }
777 return config;
778 }
779
780 std::string curveType_ = "";
781 std::vector<float> curveParams_ = {};
782 uint32_t duration_ = 0;
783 };
784
785 struct KeyboardAnimationConfig {
786 KeyboardAnimationCurve curveIn;
787 KeyboardAnimationCurve curveOut;
788 };
789
790 enum class MaximizePresentation {
791 FOLLOW_APP_IMMERSIVE_SETTING = 0, // follow app set imersiveStateEnable
792 EXIT_IMMERSIVE = 1, // imersiveStateEnable will be set as false
793 ENTER_IMMERSIVE = 2, // imersiveStateEnable will be set as true
794 // imersiveStateEnable will be set as true, titleHoverShowEnabled and dockHoverShowEnabled will be set as false
795 ENTER_IMMERSIVE_DISABLE_TITLE_AND_DOCK_HOVER = 3,
796 };
797
798
799 enum class BackupAndRestoreType : int32_t {
800 NONE = 0, // no backup and restore
801 CONTINUATION = 1, // distribute
802 APP_RECOVERY = 2, // app recovery
803 RESOURCESCHEDULE_RECOVERY = 3, // app is killed due to resource schedule
804 };
805
806 enum class ExtensionWindowAttribute : int32_t {
807 SYSTEM_WINDOW = 0,
808 SUB_WINDOW = 1,
809 UNKNOWN = 2
810 };
811
812 struct SystemWindowOptions {
813 int32_t windowType = -1;
814 };
815
816 enum class ModalityType : uint8_t {
817 WINDOW_MODALITY,
818 APPLICATION_MODALITY,
819 };
820
821 struct SubWindowOptions {
822 std::string title;
823 bool decorEnabled = false;
824 bool isModal = false;
825 bool isTopmost = false;
826 ModalityType modalityType = ModalityType::WINDOW_MODALITY;
827 };
828
829 struct ExtensionWindowConfig {
830 std::string windowName;
831 ExtensionWindowAttribute windowAttribute = ExtensionWindowAttribute::UNKNOWN;
832 Rect windowRect;
833 SubWindowOptions subWindowOptions;
834 SystemWindowOptions systemWindowOptions;
835 };
836 }
837 }
838 #endif // OHOS_ROSEN_WM_COMMON_H
839