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 <map>
20 #include <sstream>
21 #include <string>
22
23 #include <float.h>
24
25 #include <parcel.h>
26
27 #include "../dm/dm_common.h"
28 #include "securec.h"
29 #include "wm_math.h"
30
31 namespace OHOS {
32 namespace Rosen {
33 using DisplayId = uint64_t;
34 /**
35 * @brief Enumerates type of window.
36 */
37 enum class WindowType : uint32_t {
38 APP_WINDOW_BASE = 1,
39 APP_MAIN_WINDOW_BASE = APP_WINDOW_BASE,
40 WINDOW_TYPE_APP_MAIN_WINDOW = APP_MAIN_WINDOW_BASE,
41 APP_MAIN_WINDOW_END,
42
43 APP_SUB_WINDOW_BASE = 1000,
44 WINDOW_TYPE_MEDIA = APP_SUB_WINDOW_BASE,
45 WINDOW_TYPE_APP_SUB_WINDOW,
46 WINDOW_TYPE_APP_COMPONENT,
47 APP_SUB_WINDOW_END,
48 APP_WINDOW_END = APP_SUB_WINDOW_END,
49
50 SYSTEM_WINDOW_BASE = 2000,
51 BELOW_APP_SYSTEM_WINDOW_BASE = SYSTEM_WINDOW_BASE,
52 WINDOW_TYPE_WALLPAPER = SYSTEM_WINDOW_BASE,
53 WINDOW_TYPE_DESKTOP,
54 BELOW_APP_SYSTEM_WINDOW_END,
55
56 ABOVE_APP_SYSTEM_WINDOW_BASE = 2100,
57 WINDOW_TYPE_APP_LAUNCHING = ABOVE_APP_SYSTEM_WINDOW_BASE,
58 WINDOW_TYPE_DOCK_SLICE,
59 WINDOW_TYPE_INCOMING_CALL,
60 WINDOW_TYPE_SEARCHING_BAR,
61 WINDOW_TYPE_SYSTEM_ALARM_WINDOW,
62 WINDOW_TYPE_INPUT_METHOD_FLOAT,
63 WINDOW_TYPE_FLOAT,
64 WINDOW_TYPE_TOAST,
65 WINDOW_TYPE_STATUS_BAR,
66 WINDOW_TYPE_PANEL,
67 WINDOW_TYPE_KEYGUARD,
68 WINDOW_TYPE_VOLUME_OVERLAY,
69 WINDOW_TYPE_NAVIGATION_BAR,
70 WINDOW_TYPE_DRAGGING_EFFECT,
71 WINDOW_TYPE_POINTER,
72 WINDOW_TYPE_LAUNCHER_RECENT,
73 WINDOW_TYPE_LAUNCHER_DOCK,
74 WINDOW_TYPE_BOOT_ANIMATION,
75 WINDOW_TYPE_FREEZE_DISPLAY,
76 WINDOW_TYPE_VOICE_INTERACTION,
77 WINDOW_TYPE_FLOAT_CAMERA,
78 WINDOW_TYPE_PLACEHOLDER,
79 WINDOW_TYPE_DIALOG,
80 WINDOW_TYPE_SCREENSHOT,
81 WINDOW_TYPE_INPUT_METHOD_STATUS_BAR,
82 WINDOW_TYPE_GLOBAL_SEARCH,
83 WINDOW_TYPE_NEGATIVE_SCREEN,
84 WINDOW_TYPE_SYSTEM_TOAST,
85 WINDOW_TYPE_SYSTEM_FLOAT,
86 WINDOW_TYPE_PIP,
87 WINDOW_TYPE_THEME_EDITOR,
88 WINDOW_TYPE_NAVIGATION_INDICATOR,
89 WINDOW_TYPE_HANDWRITE,
90 WINDOW_TYPE_SCENE_BOARD,
91 WINDOW_TYPE_KEYBOARD_PANEL,
92 WINDOW_TYPE_SCB_DEFAULT,
93 WINDOW_TYPE_TRANSPARENT_VIEW,
94 WINDOW_TYPE_WALLET_SWIPE_CARD,
95 WINDOW_TYPE_SCREEN_CONTROL,
96 WINDOW_TYPE_FLOAT_NAVIGATION,
97 ABOVE_APP_SYSTEM_WINDOW_END,
98
99 SYSTEM_SUB_WINDOW_BASE = 2500,
100 WINDOW_TYPE_SYSTEM_SUB_WINDOW = SYSTEM_SUB_WINDOW_BASE,
101 SYSTEM_SUB_WINDOW_END,
102
103 SYSTEM_WINDOW_END = SYSTEM_SUB_WINDOW_END,
104
105 WINDOW_TYPE_UI_EXTENSION = 3000
106 };
107
108 /**
109 * @struct HookInfo.
110 *
111 * @brief hook diaplayinfo deepending on the window size.
112 */
113 struct HookInfo {
114 uint32_t width_;
115 uint32_t height_;
116 float_t density_;
117 uint32_t rotation_;
118 bool enableHookRotation_;
119 };
120
121 /**
122 * @brief Enumerates mode of window.
123 */
124 enum class WindowMode : uint32_t {
125 WINDOW_MODE_UNDEFINED = 0,
126 WINDOW_MODE_FULLSCREEN = 1,
127 WINDOW_MODE_SPLIT_PRIMARY = 100,
128 WINDOW_MODE_SPLIT_SECONDARY,
129 WINDOW_MODE_FLOATING,
130 WINDOW_MODE_PIP
131 };
132
133 /**
134 * @brief Enumerates modeType of window.
135 */
136 enum class WindowModeType : uint8_t {
137 WINDOW_MODE_SPLIT_FLOATING = 0,
138 WINDOW_MODE_SPLIT = 1,
139 WINDOW_MODE_FLOATING = 2,
140 WINDOW_MODE_FULLSCREEN = 3,
141 WINDOW_MODE_FULLSCREEN_FLOATING = 4,
142 WINDOW_MODE_OTHER = 5
143 };
144
145 /**
146 * @brief Enumerates modal of sub session.
147 */
148 enum class SubWindowModalType : uint32_t {
149 BEGIN = 0,
150 TYPE_UNDEFINED = BEGIN,
151 TYPE_NORMAL,
152 TYPE_DIALOG,
153 TYPE_WINDOW_MODALITY,
154 TYPE_TOAST,
155 TYPE_APPLICATION_MODALITY,
156 END = TYPE_APPLICATION_MODALITY,
157 };
158
159 /**
160 * @brief Enumerates mode supported of window.
161 */
162 enum WindowModeSupport : uint32_t {
163 WINDOW_MODE_SUPPORT_FULLSCREEN = 1 << 0,
164 WINDOW_MODE_SUPPORT_FLOATING = 1 << 1,
165 WINDOW_MODE_SUPPORT_SPLIT_PRIMARY = 1 << 2,
166 WINDOW_MODE_SUPPORT_SPLIT_SECONDARY = 1 << 3,
167 WINDOW_MODE_SUPPORT_PIP = 1 << 4,
168 WINDOW_MODE_SUPPORT_ALL = WINDOW_MODE_SUPPORT_FULLSCREEN |
169 WINDOW_MODE_SUPPORT_SPLIT_PRIMARY |
170 WINDOW_MODE_SUPPORT_SPLIT_SECONDARY |
171 WINDOW_MODE_SUPPORT_FLOATING |
172 WINDOW_MODE_SUPPORT_PIP
173 };
174
175 /**
176 * @brief Enumerates blur style of window.
177 */
178 enum class WindowBlurStyle : uint32_t {
179 WINDOW_BLUR_OFF = 0,
180 WINDOW_BLUR_THIN,
181 WINDOW_BLUR_REGULAR,
182 WINDOW_BLUR_THICK
183 };
184
185 /**
186 * @brief Enumerates cross axis state of window.
187 */
188 enum class CrossAxisState : uint32_t {
189 STATE_INVALID = 0,
190 STATE_CROSS,
191 STATE_NO_CROSS,
192 STATE_END,
193 };
194
195 /**
196 * @brief Enumerates state of window.
197 */
198 enum class WindowState : uint32_t {
199 STATE_INITIAL,
200 STATE_CREATED,
201 STATE_SHOWN,
202 STATE_HIDDEN,
203 STATE_FROZEN,
204 STATE_UNFROZEN,
205 STATE_DESTROYED,
206 STATE_BOTTOM = STATE_DESTROYED, // Add state type after STATE_DESTROYED is not allowed
207 };
208
209 /**
210 * @brief Enumerates error code of window.
211 */
212 enum class WMError : int32_t {
213 WM_OK = 0,
214 WM_DO_NOTHING,
215 WM_ERROR_NO_MEM,
216 WM_ERROR_DESTROYED_OBJECT,
217 WM_ERROR_INVALID_WINDOW,
218 WM_ERROR_INVALID_WINDOW_MODE_OR_SIZE,
219 WM_ERROR_INVALID_OPERATION,
220 WM_ERROR_INVALID_PERMISSION,
221 WM_ERROR_NOT_SYSTEM_APP,
222 WM_ERROR_NO_REMOTE_ANIMATION,
223 WM_ERROR_INVALID_DISPLAY,
224 WM_ERROR_INVALID_PARENT,
225 WM_ERROR_INVALID_OP_IN_CUR_STATUS,
226 WM_ERROR_REPEAT_OPERATION,
227 WM_ERROR_INVALID_SESSION,
228 WM_ERROR_INVALID_CALLING,
229 WM_ERROR_SYSTEM_ABNORMALLY,
230
231 WM_ERROR_DEVICE_NOT_SUPPORT = 801, // the value do not change.It is defined on all system
232
233 WM_ERROR_NEED_REPORT_BASE = 1000, // error code > 1000 means need report
234 WM_ERROR_NULLPTR,
235 WM_ERROR_INVALID_TYPE,
236 WM_ERROR_INVALID_PARAM,
237 WM_ERROR_SAMGR,
238 WM_ERROR_IPC_FAILED,
239 WM_ERROR_NEED_REPORT_END,
240 WM_ERROR_START_ABILITY_FAILED,
241 WM_ERROR_PIP_DESTROY_FAILED,
242 WM_ERROR_PIP_STATE_ABNORMALLY,
243 WM_ERROR_PIP_CREATE_FAILED,
244 WM_ERROR_PIP_INTERNAL_ERROR,
245 WM_ERROR_PIP_REPEAT_OPERATION,
246 };
247
248 /**
249 * @brief Enumerates error code of window only used for js api.
250 */
251 enum class WmErrorCode : int32_t {
252 WM_OK = 0,
253 WM_ERROR_NO_PERMISSION = 201,
254 WM_ERROR_NOT_SYSTEM_APP = 202,
255 WM_ERROR_INVALID_PARAM = 401,
256 WM_ERROR_DEVICE_NOT_SUPPORT = 801,
257 WM_ERROR_REPEAT_OPERATION = 1300001,
258 WM_ERROR_STATE_ABNORMALLY = 1300002,
259 WM_ERROR_SYSTEM_ABNORMALLY = 1300003,
260 WM_ERROR_INVALID_CALLING = 1300004,
261 WM_ERROR_STAGE_ABNORMALLY = 1300005,
262 WM_ERROR_CONTEXT_ABNORMALLY = 1300006,
263 WM_ERROR_START_ABILITY_FAILED = 1300007,
264 WM_ERROR_INVALID_DISPLAY = 1300008,
265 WM_ERROR_INVALID_PARENT = 1300009,
266 WM_ERROR_INVALID_OP_IN_CUR_STATUS = 1300010,
267 WM_ERROR_PIP_DESTROY_FAILED = 1300011,
268 WM_ERROR_PIP_STATE_ABNORMALLY = 1300012,
269 WM_ERROR_PIP_CREATE_FAILED = 1300013,
270 WM_ERROR_PIP_INTERNAL_ERROR = 1300014,
271 WM_ERROR_PIP_REPEAT_OPERATION = 1300015,
272 };
273
274 /**
275 * @brief Enumerates status of window.
276 */
277 enum class WindowStatus : uint32_t {
278 WINDOW_STATUS_UNDEFINED = 0,
279 WINDOW_STATUS_FULLSCREEN = 1,
280 WINDOW_STATUS_MAXIMIZE,
281 WINDOW_STATUS_MINIMIZE,
282 WINDOW_STATUS_FLOATING,
283 WINDOW_STATUS_SPLITSCREEN
284 };
285
286 /**
287 * @brief Enumerates setting flag of systemStatusBar
288 */
289 enum class SystemBarSettingFlag : uint32_t {
290 DEFAULT_SETTING = 0,
291 COLOR_SETTING = 1,
292 ENABLE_SETTING = 1 << 1,
293 ALL_SETTING = COLOR_SETTING | ENABLE_SETTING,
294 FOLLOW_SETTING = 1 << 2
295 };
296
297 /**
298 * @brief Enumerates flag of ControlAppType.
299 */
300 enum class ControlAppType : uint8_t {
301 CONTROL_APP_TYPE_BEGIN = 0,
302 APP_LOCK = 1,
303 PARENT_CONTROL,
304 CONTROL_APP_TYPE_END,
305 };
306
307 /**
308 * @brief Used to map from WMError to WmErrorCode.
309 */
310 const std::map<WMError, WmErrorCode> WM_JS_TO_ERROR_CODE_MAP {
311 {WMError::WM_OK, WmErrorCode::WM_OK },
312 {WMError::WM_DO_NOTHING, WmErrorCode::WM_ERROR_STATE_ABNORMALLY },
313 {WMError::WM_ERROR_DESTROYED_OBJECT, WmErrorCode::WM_ERROR_STATE_ABNORMALLY },
314 {WMError::WM_ERROR_DEVICE_NOT_SUPPORT, WmErrorCode::WM_ERROR_DEVICE_NOT_SUPPORT },
315 {WMError::WM_ERROR_INVALID_OPERATION, WmErrorCode::WM_ERROR_STATE_ABNORMALLY },
316 {WMError::WM_ERROR_INVALID_PARAM, WmErrorCode::WM_ERROR_INVALID_PARAM },
317 {WMError::WM_ERROR_INVALID_PERMISSION, WmErrorCode::WM_ERROR_NO_PERMISSION },
318 {WMError::WM_ERROR_NOT_SYSTEM_APP, WmErrorCode::WM_ERROR_NOT_SYSTEM_APP },
319 {WMError::WM_ERROR_INVALID_TYPE, WmErrorCode::WM_ERROR_STATE_ABNORMALLY },
320 {WMError::WM_ERROR_INVALID_WINDOW, WmErrorCode::WM_ERROR_STATE_ABNORMALLY },
321 {WMError::WM_ERROR_INVALID_WINDOW_MODE_OR_SIZE, WmErrorCode::WM_ERROR_STATE_ABNORMALLY },
322 {WMError::WM_ERROR_IPC_FAILED, WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY },
323 {WMError::WM_ERROR_NO_MEM, WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY },
324 {WMError::WM_ERROR_NO_REMOTE_ANIMATION, WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY },
325 {WMError::WM_ERROR_INVALID_DISPLAY, WmErrorCode::WM_ERROR_INVALID_DISPLAY },
326 {WMError::WM_ERROR_INVALID_PARENT, WmErrorCode::WM_ERROR_INVALID_PARENT },
327 {WMError::WM_ERROR_INVALID_OP_IN_CUR_STATUS, WmErrorCode::WM_ERROR_INVALID_OP_IN_CUR_STATUS },
328 {WMError::WM_ERROR_REPEAT_OPERATION, WmErrorCode::WM_ERROR_REPEAT_OPERATION },
329 {WMError::WM_ERROR_NULLPTR, WmErrorCode::WM_ERROR_STATE_ABNORMALLY },
330 {WMError::WM_ERROR_SAMGR, WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY },
331 {WMError::WM_ERROR_START_ABILITY_FAILED, WmErrorCode::WM_ERROR_START_ABILITY_FAILED },
332 {WMError::WM_ERROR_PIP_DESTROY_FAILED, WmErrorCode::WM_ERROR_PIP_DESTROY_FAILED },
333 {WMError::WM_ERROR_PIP_STATE_ABNORMALLY, WmErrorCode::WM_ERROR_PIP_STATE_ABNORMALLY },
334 {WMError::WM_ERROR_PIP_CREATE_FAILED, WmErrorCode::WM_ERROR_PIP_CREATE_FAILED },
335 {WMError::WM_ERROR_PIP_INTERNAL_ERROR, WmErrorCode::WM_ERROR_PIP_INTERNAL_ERROR },
336 {WMError::WM_ERROR_PIP_REPEAT_OPERATION, WmErrorCode::WM_ERROR_PIP_REPEAT_OPERATION },
337 {WMError::WM_ERROR_INVALID_CALLING, WmErrorCode::WM_ERROR_INVALID_CALLING },
338 {WMError::WM_ERROR_INVALID_SESSION, WmErrorCode::WM_ERROR_STATE_ABNORMALLY },
339 {WMError::WM_ERROR_SYSTEM_ABNORMALLY, WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY },
340 };
341
342 /**
343 * @brief Enumerates flag of window.
344 */
345 enum class WindowFlag : uint32_t {
346 WINDOW_FLAG_NEED_AVOID = 1,
347 WINDOW_FLAG_PARENT_LIMIT = 1 << 1,
348 WINDOW_FLAG_SHOW_WHEN_LOCKED = 1 << 2,
349 WINDOW_FLAG_FORBID_SPLIT_MOVE = 1 << 3,
350 WINDOW_FLAG_WATER_MARK = 1 << 4,
351 WINDOW_FLAG_IS_MODAL = 1 << 5,
352 WINDOW_FLAG_HANDWRITING = 1 << 6,
353 WINDOW_FLAG_IS_TOAST = 1 << 7,
354 WINDOW_FLAG_IS_APPLICATION_MODAL = 1 << 8,
355 WINDOW_FLAG_END = 1 << 9,
356 };
357
358 /**
359 * @brief Flag of uiextension window.
360 */
361 union ExtensionWindowFlags {
362 uint32_t bitData;
363 struct {
364 // Each flag should be false default, true when active
365 bool hideNonSecureWindowsFlag : 1;
366 bool waterMarkFlag : 1;
367 bool privacyModeFlag : 1;
368 };
ExtensionWindowFlags()369 ExtensionWindowFlags() : bitData(0) {}
ExtensionWindowFlags(uint32_t bits)370 ExtensionWindowFlags(uint32_t bits) : bitData(bits) {}
~ExtensionWindowFlags()371 ~ExtensionWindowFlags() {}
SetAllActive()372 void SetAllActive()
373 {
374 hideNonSecureWindowsFlag = true;
375 waterMarkFlag = true;
376 privacyModeFlag = true;
377 }
378 };
379
380 /**
381 * @brief Enumerates window size change reason.
382 */
383 enum class WindowSizeChangeReason : uint32_t {
384 UNDEFINED = 0,
385 MAXIMIZE,
386 RECOVER,
387 ROTATION,
388 DRAG,
389 DRAG_START,
390 DRAG_END,
391 RESIZE,
392 MOVE,
393 HIDE,
394 TRANSFORM,
395 CUSTOM_ANIMATION_SHOW,
396 FULL_TO_SPLIT,
397 SPLIT_TO_FULL,
398 FULL_TO_FLOATING,
399 FLOATING_TO_FULL,
400 PIP_START,
401 PIP_SHOW,
402 PIP_AUTO_START,
403 PIP_RATIO_CHANGE,
404 PIP_RESTORE,
405 UPDATE_DPI_SYNC,
406 DRAG_MOVE,
407 AVOID_AREA_CHANGE,
408 END,
409 };
410
IsMoveToOrDragMove(WindowSizeChangeReason reason)411 inline bool IsMoveToOrDragMove(WindowSizeChangeReason reason)
412 {
413 return reason == WindowSizeChangeReason::MOVE || reason == WindowSizeChangeReason::DRAG_MOVE;
414 }
415
416 /**
417 * @brief Enumerates layout mode of window.
418 */
419 enum class WindowLayoutMode : uint32_t {
420 BASE = 0,
421 CASCADE = BASE,
422 TILE = 1,
423 END,
424 };
425
426 /**
427 * @brief Enumerates drag event.
428 */
429 enum class DragEvent : uint32_t {
430 DRAG_EVENT_IN = 1,
431 DRAG_EVENT_OUT,
432 DRAG_EVENT_MOVE,
433 DRAG_EVENT_END,
434 };
435
436 /**
437 * @brief Enumerates drag resize type.
438 */
439 enum class DragResizeType : uint32_t {
440 RESIZE_TYPE_UNDEFINED = 0,
441 RESIZE_EACH_FRAME = 1,
442 RESIZE_WHEN_DRAG_END = 2,
443 };
444
445 /**
446 * @brief Enumerates window tag.
447 */
448 enum class WindowTag : uint32_t {
449 MAIN_WINDOW = 0,
450 SUB_WINDOW = 1,
451 SYSTEM_WINDOW = 2,
452 };
453
454 /**
455 * @brief Enumerates window session type.
456 */
457 enum class WindowSessionType : uint32_t {
458 SCENE_SESSION = 0,
459 EXTENSION_SESSION = 1,
460 };
461
462 /**
463 * @brief Enumerates window gravity.
464 */
465 enum class WindowGravity : uint32_t {
466 WINDOW_GRAVITY_FLOAT = 0,
467 WINDOW_GRAVITY_BOTTOM,
468 WINDOW_GRAVITY_DEFAULT,
469 };
470
471 /**
472 * @brief Enumerates window setuicontent type.
473 */
474 enum class WindowSetUIContentType: uint32_t {
475 DEFAULT,
476 RESTORE,
477 BY_NAME,
478 BY_ABC,
479 };
480
481 /**
482 * @brief Enumerates restore type.
483 */
484 enum class BackupAndRestoreType : int32_t {
485 NONE = 0, // no backup and restore
486 CONTINUATION = 1, // distribute
487 APP_RECOVERY = 2, // app recovery
488 RESOURCESCHEDULE_RECOVERY = 3, // app is killed due to resource schedule
489 };
490
491 /**
492 * @brief Enumerates window Style type.
493 */
494 enum class WindowStyleType : uint8_t {
495 WINDOW_STYLE_DEFAULT = 0,
496 WINDOW_STYLE_FREE_MULTI_WINDOW = 1,
497 };
498
499 /**
500 * @brief Disable Gesture Back Type
501 */
502 enum class GestureBackType : uint8_t {
503 GESTURE_SIDE = 0,
504 GESTURE_SWIPE_UP = 1,
505 GESTURE_ALL = 2,
506 };
507
508 /**
509 * @struct PointInfo.
510 *
511 * @brief point Info.
512 */
513 struct PointInfo {
514 int32_t x;
515 int32_t y;
516 };
517
518 /**
519 * @struct MainWindowInfo.
520 *
521 * @brief topN main window info.
522 */
523 struct MainWindowInfo : public Parcelable {
MarshallingMainWindowInfo524 virtual bool Marshalling(Parcel& parcel) const override
525 {
526 if (!parcel.WriteInt32(pid_)) {
527 return false;
528 }
529
530 if (!parcel.WriteString(bundleName_)) {
531 return false;
532 }
533
534 if (!parcel.WriteInt32(persistentId_)) {
535 return false;
536 }
537
538 if (!parcel.WriteInt32(bundleType_)) {
539 return false;
540 }
541 return true;
542 }
543
UnmarshallingMainWindowInfo544 static MainWindowInfo* Unmarshalling(Parcel& parcel)
545 {
546 MainWindowInfo* mainWindowInfo = new MainWindowInfo;
547 mainWindowInfo->pid_ = parcel.ReadInt32();
548 mainWindowInfo->bundleName_ = parcel.ReadString();
549 mainWindowInfo->persistentId_ = parcel.ReadInt32();
550 mainWindowInfo->bundleType_ = parcel.ReadInt32();
551 return mainWindowInfo;
552 }
553
554 int32_t pid_ = 0;
555 std::string bundleName_ = "";
556 int32_t persistentId_ = 0;
557 int32_t bundleType_ = 0;
558 };
559
560 /**
561 * @struct MainWindowState.
562 *
563 * @brief Main window state info.
564 */
565 struct MainWindowState : public Parcelable {
MarshallingMainWindowState566 bool Marshalling(Parcel& parcel) const override
567 {
568 if (!parcel.WriteInt32(state_)) {
569 return false;
570 }
571 if (!parcel.WriteBool(isVisible_)) {
572 return false;
573 }
574 if (!parcel.WriteBool(isForegroundInteractive_)) {
575 return false;
576 }
577 if (!parcel.WriteBool(isPcOrPadEnableActivation_)) {
578 return false;
579 }
580 return true;
581 }
582
UnmarshallingMainWindowState583 static MainWindowState* Unmarshalling(Parcel& parcel)
584 {
585 MainWindowState* mainWindowState = new MainWindowState();
586 if (!mainWindowState) {
587 return nullptr;
588 }
589 if (!parcel.ReadInt32(mainWindowState->state_) ||
590 !parcel.ReadBool(mainWindowState->isVisible_) ||
591 !parcel.ReadBool(mainWindowState->isForegroundInteractive_) ||
592 !parcel.ReadBool(mainWindowState->isPcOrPadEnableActivation_)) {
593 delete mainWindowState;
594 return nullptr;
595 }
596 return mainWindowState;
597 }
598
599 int32_t state_ = 0;
600 bool isVisible_ = false;
601 bool isForegroundInteractive_ = false;
602 bool isPcOrPadEnableActivation_ = false;
603 };
604
605 namespace {
606 constexpr uint32_t SYSTEM_COLOR_WHITE = 0xE5FFFFFF;
607 constexpr uint32_t SYSTEM_COLOR_BLACK = 0x66000000;
608 constexpr uint32_t INVALID_WINDOW_ID = 0;
609 constexpr float UNDEFINED_BRIGHTNESS = -1.0f;
610 constexpr float MINIMUM_BRIGHTNESS = 0.0f;
611 constexpr float MAXIMUM_BRIGHTNESS = 1.0f;
612 constexpr int32_t INVALID_PID = -1;
613 constexpr int32_t INVALID_UID = -1;
614 constexpr int32_t INVALID_USER_ID = -1;
615 constexpr int32_t SYSTEM_USERID = 0;
616 constexpr int32_t BASE_USER_RANGE = 200000;
617 constexpr int32_t DEFAULT_SCREEN_ID = 0;
618 constexpr float UNDEFINED_DENSITY = -1.0f;
619 constexpr float MINIMUM_CUSTOM_DENSITY = 0.5f;
620 constexpr float MAXIMUM_CUSTOM_DENSITY = 4.0f;
621 }
622
GetUserIdByUid(int32_t uid)623 inline int32_t GetUserIdByUid(int32_t uid)
624 {
625 return uid / BASE_USER_RANGE;
626 }
627
628 /**
629 * @class Transform
630 *
631 * @brief parameter of transform and rotate.
632 */
633 class Transform {
634 public:
Transform()635 Transform()
636 : pivotX_(0.5f), pivotY_(0.5f), scaleX_(1.f), scaleY_(1.f), scaleZ_(1.f), rotationX_(0.f),
637 rotationY_(0.f), rotationZ_(0.f), translateX_(0.f), translateY_(0.f), translateZ_(0.f)
638 {}
~Transform()639 ~Transform() {}
640
641 bool operator==(const Transform& right) const
642 {
643 return NearZero(pivotX_ - right.pivotX_) &&
644 NearZero(pivotY_ - right.pivotY_) &&
645 NearZero(scaleX_ - right.scaleX_) &&
646 NearZero(scaleY_ - right.scaleY_) &&
647 NearZero(scaleZ_ - right.scaleZ_) &&
648 NearZero(rotationX_ - right.rotationX_) &&
649 NearZero(rotationY_ - right.rotationY_) &&
650 NearZero(rotationZ_ - right.rotationZ_) &&
651 NearZero(translateX_ - right.translateX_) &&
652 NearZero(translateY_ - right.translateY_) &&
653 NearZero(translateZ_ - right.translateZ_);
654 }
655
656 bool operator!=(const Transform& right) const
657 {
658 return !(*this == right);
659 }
660
661 float pivotX_;
662 float pivotY_;
663 float scaleX_;
664 float scaleY_;
665 float scaleZ_;
666 float rotationX_;
667 float rotationY_;
668 float rotationZ_;
669 float translateX_;
670 float translateY_;
671 float translateZ_;
672
Identity()673 static const Transform& Identity()
674 {
675 static Transform I;
676 return I;
677 }
678
Marshalling(Parcel & parcel)679 bool Marshalling(Parcel& parcel) const
680 {
681 return parcel.WriteFloat(pivotX_) && parcel.WriteFloat(pivotY_) &&
682 parcel.WriteFloat(scaleX_) && parcel.WriteFloat(scaleY_) && parcel.WriteFloat(scaleZ_) &&
683 parcel.WriteFloat(rotationX_) && parcel.WriteFloat(rotationY_) && parcel.WriteFloat(rotationZ_) &&
684 parcel.WriteFloat(translateX_) && parcel.WriteFloat(translateY_) && parcel.WriteFloat(translateZ_);
685 }
686
Unmarshalling(Parcel & parcel)687 void Unmarshalling(Parcel& parcel)
688 {
689 pivotX_ = parcel.ReadFloat();
690 pivotY_ = parcel.ReadFloat();
691 scaleX_ = parcel.ReadFloat();
692 scaleY_ = parcel.ReadFloat();
693 scaleZ_ = parcel.ReadFloat();
694 rotationX_ = parcel.ReadFloat();
695 rotationY_ = parcel.ReadFloat();
696 rotationZ_ = parcel.ReadFloat();
697 translateX_ = parcel.ReadFloat();
698 translateY_ = parcel.ReadFloat();
699 translateZ_ = parcel.ReadFloat();
700 }
701 private:
NearZero(float val)702 static inline bool NearZero(float val)
703 {
704 return val < 0.001f && val > -0.001f;
705 }
706 };
707
708 /**
709 * @struct SingleHandTransform
710 *
711 * @brief parameter of transform in single hand mode.
712 */
713 struct SingleHandTransform {
714 int32_t posX = 0;
715 int32_t posY = 0;
716 float scaleX = 0;
717 float scaleY = 0;
718
719 bool operator==(const SingleHandTransform& right) const
720 {
721 return posX == right.posX && MathHelper::NearEqual(scaleX, right.scaleX) &&
722 posY == right.posY && MathHelper::NearEqual(scaleY, right.scaleY);
723 }
724
725 bool operator!=(const SingleHandTransform& right) const
726 {
727 return !(*this == right);
728 }
729
MarshallingSingleHandTransform730 bool Marshalling(Parcel& parcel) const
731 {
732 return parcel.WriteInt32(posX) && parcel.WriteInt32(posY) &&
733 parcel.WriteFloat(scaleX) && parcel.WriteFloat(scaleY);
734 }
735
UnmarshallingSingleHandTransform736 void Unmarshalling(Parcel& parcel)
737 {
738 posX = parcel.ReadInt32();
739 posY = parcel.ReadInt32();
740 scaleX = parcel.ReadFloat();
741 scaleY = parcel.ReadFloat();
742 }
743 };
744
745 /**
746 * @struct SystemBarProperty
747 *
748 * @brief Property of system bar
749 */
750 struct SystemBarProperty {
751 bool enable_;
752 uint32_t backgroundColor_;
753 uint32_t contentColor_;
754 bool enableAnimation_;
755 SystemBarSettingFlag settingFlag_;
SystemBarPropertySystemBarProperty756 SystemBarProperty() : enable_(true), backgroundColor_(SYSTEM_COLOR_BLACK), contentColor_(SYSTEM_COLOR_WHITE),
757 enableAnimation_(false), settingFlag_(SystemBarSettingFlag::DEFAULT_SETTING) {}
SystemBarPropertySystemBarProperty758 SystemBarProperty(bool enable, uint32_t background, uint32_t content)
759 : enable_(enable), backgroundColor_(background), contentColor_(content), enableAnimation_(false),
760 settingFlag_(SystemBarSettingFlag::DEFAULT_SETTING) {}
SystemBarPropertySystemBarProperty761 SystemBarProperty(bool enable, uint32_t background, uint32_t content, bool enableAnimation)
762 : enable_(enable), backgroundColor_(background), contentColor_(content), enableAnimation_(enableAnimation),
763 settingFlag_(SystemBarSettingFlag::DEFAULT_SETTING) {}
SystemBarPropertySystemBarProperty764 SystemBarProperty(bool enable, uint32_t background, uint32_t content,
765 bool enableAnimation, SystemBarSettingFlag settingFlag)
766 : enable_(enable), backgroundColor_(background), contentColor_(content), enableAnimation_(enableAnimation),
767 settingFlag_(settingFlag) {}
768 bool operator == (const SystemBarProperty& a) const
769 {
770 return (enable_ == a.enable_ && backgroundColor_ == a.backgroundColor_ && contentColor_ == a.contentColor_ &&
771 enableAnimation_ == a.enableAnimation_);
772 }
773 };
774
775 /**
776 * @struct SystemBarPropertyFlag
777 *
778 * @brief Flag of system bar
779 */
780 struct SystemBarPropertyFlag {
781 bool enableFlag = false;
782 bool backgroundColorFlag = false;
783 bool contentColorFlag = false;
784 bool enableAnimationFlag = false;
785 };
786
787 /**
788 * @struct Rect
789 *
790 * @brief Window Rect
791 */
792 struct Rect {
793 int32_t posX_;
794 int32_t posY_;
795 uint32_t width_;
796 uint32_t height_;
797
798 bool operator==(const Rect& a) const
799 {
800 return (posX_ == a.posX_ && posY_ == a.posY_ && width_ == a.width_ && height_ == a.height_);
801 }
802
803 bool operator!=(const Rect& a) const
804 {
805 return !this->operator==(a);
806 }
807
IsUninitializedRectRect808 bool IsUninitializedRect() const
809 {
810 return (posX_ == 0 && posY_ == 0 && width_ == 0 && height_ == 0);
811 }
812
IsUninitializedSizeRect813 bool IsUninitializedSize() const
814 {
815 return width_ == 0 && height_ == 0;
816 }
817
IsInsideOfRect818 bool IsInsideOf(const Rect& a) const
819 {
820 return (posX_ >= a.posX_ && posY_ >= a.posY_ &&
821 posX_ + width_ <= a.posX_ + a.width_ && posY_ + height_ <= a.posY_ + a.height_);
822 }
823
ToStringRect824 inline std::string ToString() const
825 {
826 std::stringstream ss;
827 ss << "[" << posX_ << " " << posY_ << " " << width_ << " " << height_ << "]";
828 return ss.str();
829 }
830 };
831
832 /**
833 * @brief UIExtension usage
834 */
835 enum class UIExtensionUsage : uint32_t {
836 MODAL = 0,
837 EMBEDDED,
838 CONSTRAINED_EMBEDDED,
839 UIEXTENSION_USAGE_END
840 };
841
842 /**
843 * @brief UIExtension info for event
844 */
845 struct ExtensionWindowEventInfo {
846 int32_t persistentId = 0;
847 int32_t pid = -1;
848 Rect windowRect { 0, 0, 0, 0 }; // Calculated from global rect and UIExtension windowRect
849 Rect uiExtRect { 0, 0, 0, 0 }; // Transferred from arkUI
850 bool hasUpdatedRect = false;
851 bool isConstrainedModal = false;
852 };
853
854 /**
855 * @brief UIExtension info from ability
856 */
857 struct ExtensionWindowAbilityInfo {
858 int32_t persistentId { 0 };
859 int32_t parentId { 0 };
860 UIExtensionUsage usage { UIExtensionUsage::UIEXTENSION_USAGE_END };
861 };
862
863 /**
864 * @struct KeyboardPanelInfo
865 *
866 * @brief Info of keyboard panel
867 */
868 struct KeyboardPanelInfo : public Parcelable {
869 Rect rect_ = {0, 0, 0, 0};
870 WindowGravity gravity_ = WindowGravity::WINDOW_GRAVITY_BOTTOM;
871 bool isShowing_ = false;
872
MarshallingKeyboardPanelInfo873 bool Marshalling(Parcel& parcel) const
874 {
875 return parcel.WriteInt32(rect_.posX_) && parcel.WriteInt32(rect_.posY_) &&
876 parcel.WriteUint32(rect_.width_) && parcel.WriteUint32(rect_.height_) &&
877 parcel.WriteUint32(static_cast<uint32_t>(gravity_)) &&
878 parcel.WriteBool(isShowing_);
879 }
880
UnmarshallingKeyboardPanelInfo881 static KeyboardPanelInfo* Unmarshalling(Parcel& parcel)
882 {
883 KeyboardPanelInfo* keyboardPanelInfo = new(std::nothrow)KeyboardPanelInfo;
884 if (keyboardPanelInfo == nullptr) {
885 return nullptr;
886 }
887 bool res = parcel.ReadInt32(keyboardPanelInfo->rect_.posX_) &&
888 parcel.ReadInt32(keyboardPanelInfo->rect_.posY_) && parcel.ReadUint32(keyboardPanelInfo->rect_.width_) &&
889 parcel.ReadUint32(keyboardPanelInfo->rect_.height_);
890 if (!res) {
891 delete keyboardPanelInfo;
892 return nullptr;
893 }
894 keyboardPanelInfo->gravity_ = static_cast<WindowGravity>(parcel.ReadUint32());
895 keyboardPanelInfo->isShowing_ = parcel.ReadBool();
896
897 return keyboardPanelInfo;
898 }
899 };
900
901 /**
902 * @brief Enumerates avoid area type.
903 */
904 enum class AvoidAreaType : uint32_t {
905 TYPE_SYSTEM, // area of SystemUI
906 TYPE_CUTOUT, // cutout of screen
907 TYPE_SYSTEM_GESTURE, // area for system gesture
908 TYPE_KEYBOARD, // area for soft input keyboard
909 TYPE_NAVIGATION_INDICATOR, // area for navigation indicator
910 };
911
912 /**
913 * @brief Enumerates occupied area type.
914 */
915 enum class OccupiedAreaType : uint32_t {
916 TYPE_INPUT, // area of input window
917 };
918
919 /**
920 * @brief Enumerates color space.
921 */
922 enum class ColorSpace : uint32_t {
923 COLOR_SPACE_DEFAULT = 0, // Default color space.
924 COLOR_SPACE_WIDE_GAMUT, // Wide gamut color space. The specific wide color gamut depends on the screen.
925 };
926
927 /**
928 * @brief Enumerates window animation.
929 */
930 enum class WindowAnimation : uint32_t {
931 NONE,
932 DEFAULT,
933 INPUTE,
934 CUSTOM,
935 };
936
937 /**
938 * @brief Enumerates window maximize mode.
939 */
940 enum class MaximizeMode : uint32_t {
941 MODE_AVOID_SYSTEM_BAR,
942 MODE_FULL_FILL,
943 MODE_RECOVER,
944 };
945
946 /**
947 * @class AvoidArea
948 *
949 * @brief Area needed to avoid.
950 */
951 class AvoidArea : public Parcelable {
952 public:
953 Rect topRect_ { 0, 0, 0, 0 };
954 Rect leftRect_ { 0, 0, 0, 0 };
955 Rect rightRect_ { 0, 0, 0, 0 };
956 Rect bottomRect_ { 0, 0, 0, 0 };
957
958 bool operator==(const AvoidArea& a) const
959 {
960 return (leftRect_ == a.leftRect_ && topRect_ == a.topRect_ &&
961 rightRect_ == a.rightRect_ && bottomRect_ == a.bottomRect_);
962 }
963
964 bool operator!=(const AvoidArea& a) const
965 {
966 return !this->operator==(a);
967 }
968
isEmptyAvoidArea()969 bool isEmptyAvoidArea() const
970 {
971 return topRect_.IsUninitializedRect() && leftRect_.IsUninitializedRect() &&
972 rightRect_.IsUninitializedRect() && bottomRect_.IsUninitializedRect();
973 }
974
WriteParcel(Parcel & parcel,const Rect & rect)975 static inline bool WriteParcel(Parcel& parcel, const Rect& rect)
976 {
977 return parcel.WriteInt32(rect.posX_) && parcel.WriteInt32(rect.posY_) &&
978 parcel.WriteUint32(rect.width_) && parcel.WriteUint32(rect.height_);
979 }
980
ReadParcel(Parcel & parcel,Rect & rect)981 static inline bool ReadParcel(Parcel& parcel, Rect& rect)
982 {
983 return parcel.ReadInt32(rect.posX_) && parcel.ReadInt32(rect.posY_) &&
984 parcel.ReadUint32(rect.width_) && parcel.ReadUint32(rect.height_);
985 }
986
Marshalling(Parcel & parcel)987 virtual bool Marshalling(Parcel& parcel) const override
988 {
989 return (WriteParcel(parcel, leftRect_) && WriteParcel(parcel, topRect_) &&
990 WriteParcel(parcel, rightRect_) && WriteParcel(parcel, bottomRect_));
991 }
992
Unmarshalling(Parcel & parcel)993 static AvoidArea* Unmarshalling(Parcel& parcel)
994 {
995 AvoidArea *avoidArea = new(std::nothrow) AvoidArea();
996 if (avoidArea == nullptr) {
997 return nullptr;
998 }
999 if (ReadParcel(parcel, avoidArea->leftRect_) && ReadParcel(parcel, avoidArea->topRect_) &&
1000 ReadParcel(parcel, avoidArea->rightRect_) && ReadParcel(parcel, avoidArea->bottomRect_)) {
1001 return avoidArea;
1002 }
1003 delete avoidArea;
1004 return nullptr;
1005 }
1006
ToString()1007 std::string ToString() const
1008 {
1009 std::stringstream ss;
1010 if (isEmptyAvoidArea()) {
1011 ss << "empty";
1012 return ss.str();
1013 }
1014 if (!topRect_.IsUninitializedRect()) {
1015 ss << "top " << topRect_.ToString() << " ";
1016 }
1017 if (!bottomRect_.IsUninitializedRect()) {
1018 ss << "bottom " << bottomRect_.ToString() << " ";
1019 }
1020 if (!leftRect_.IsUninitializedRect()) {
1021 ss << "left " << leftRect_.ToString() << " ";
1022 }
1023 if (!rightRect_.IsUninitializedRect()) {
1024 ss << "right " << rightRect_.ToString() << " ";
1025 }
1026 return ss.str();
1027 }
1028 };
1029
1030 /**
1031 * @brief Enumerates window update type.
1032 */
1033 enum class WindowUpdateType : int32_t {
1034 WINDOW_UPDATE_ADDED = 1,
1035 WINDOW_UPDATE_REMOVED,
1036 WINDOW_UPDATE_FOCUSED,
1037 WINDOW_UPDATE_BOUNDS,
1038 WINDOW_UPDATE_ACTIVE,
1039 WINDOW_UPDATE_PROPERTY,
1040 WINDOW_UPDATE_ALL,
1041 };
1042
1043 /**
1044 * @brief Enumerates picture in picture window state.
1045 */
1046 enum class PiPWindowState : uint32_t {
1047 STATE_UNDEFINED = 0,
1048 STATE_STARTING = 1,
1049 STATE_STARTED = 2,
1050 STATE_STOPPING = 3,
1051 STATE_STOPPED = 4,
1052 STATE_RESTORING = 5,
1053 };
1054
1055 /**
1056 * @brief Enumerates picture in picture template type.
1057 */
1058 enum class PiPTemplateType : uint32_t {
1059 VIDEO_PLAY = 0,
1060 VIDEO_CALL = 1,
1061 VIDEO_MEETING = 2,
1062 VIDEO_LIVE = 3,
1063 END,
1064 };
1065
1066 /**
1067 * @brief Enumerates picture in picture control group.
1068 */
1069 enum class PiPControlGroup : uint32_t {
1070 VIDEO_PLAY_START = 100,
1071 VIDEO_PREVIOUS_NEXT = 101,
1072 FAST_FORWARD_BACKWARD = 102,
1073 VIDEO_PLAY_END,
1074
1075 VIDEO_CALL_START = 200,
1076 VIDEO_CALL_MICROPHONE_SWITCH = 201,
1077 VIDEO_CALL_HANG_UP_BUTTON = 202,
1078 VIDEO_CALL_CAMERA_SWITCH = 203,
1079 VIDEO_CALL_MUTE_SWITCH = 204,
1080 VIDEO_CALL_END,
1081
1082 VIDEO_MEETING_START = 300,
1083 VIDEO_MEETING_HANG_UP_BUTTON = 301,
1084 VIDEO_MEETING_CAMERA_SWITCH = 302,
1085 VIDEO_MEETING_MUTE_SWITCH = 303,
1086 VIDEO_MEETING_MICROPHONE_SWITCH = 304,
1087 VIDEO_MEETING_END,
1088
1089 VIDEO_LIVE_START = 400,
1090 VIDEO_PLAY_PAUSE = 401,
1091 VIDEO_LIVE_MUTE_SWITCH = 402,
1092 VIDEO_LIVE_END,
1093 END,
1094 };
1095
1096 /**
1097 * @brief Enumerates picture in picture state.
1098 */
1099 enum class PiPState : int32_t {
1100 ABOUT_TO_START = 1,
1101 STARTED = 2,
1102 ABOUT_TO_STOP = 3,
1103 STOPPED = 4,
1104 ABOUT_TO_RESTORE = 5,
1105 ERROR = 6,
1106 };
1107
1108 /**
1109 * @brief Enumerates picture in picture control status.
1110 */
1111 enum class PiPControlStatus : int32_t {
1112 PLAY = 1,
1113 PAUSE = 0,
1114 OPEN = 1,
1115 CLOSE = 0,
1116 ENABLED = -2,
1117 DISABLED = -3,
1118 };
1119
1120 /**
1121 * @brief Enumerates picture in picture control type.
1122 */
1123 enum class PiPControlType : uint32_t {
1124 VIDEO_PLAY_PAUSE = 0,
1125 VIDEO_PREVIOUS = 1,
1126 VIDEO_NEXT = 2,
1127 FAST_FORWARD = 3,
1128 FAST_BACKWARD = 4,
1129 HANG_UP_BUTTON = 5,
1130 MICROPHONE_SWITCH = 6,
1131 CAMERA_SWITCH = 7,
1132 MUTE_SWITCH = 8,
1133 END,
1134 };
1135
1136 struct PiPControlStatusInfo {
1137 PiPControlType controlType;
1138 PiPControlStatus status;
1139 };
1140
1141 struct PiPControlEnableInfo {
1142 PiPControlType controlType;
1143 PiPControlStatus enabled;
1144 };
1145
1146 struct PiPTemplateInfo {
1147 uint32_t pipTemplateType;
1148 uint32_t priority;
1149 std::vector<uint32_t> controlGroup;
1150 std::vector<PiPControlStatusInfo> pipControlStatusInfoList;
1151 std::vector<PiPControlEnableInfo> pipControlEnableInfoList;
1152 };
1153
1154 struct PiPWindowSize {
1155 uint32_t width;
1156 uint32_t height;
1157 double scale;
1158 };
1159
1160 using OnCallback = std::function<void(int64_t, int64_t)>;
1161
1162 /**
1163 * @struct VsyncCallback
1164 *
1165 * @brief Vsync callback
1166 */
1167 struct VsyncCallback {
1168 OnCallback onCallback;
1169 };
1170
1171 struct WindowLimits {
1172 uint32_t maxWidth_ = static_cast<uint32_t>(INT32_MAX); // The width and height are no larger than INT32_MAX.
1173 uint32_t maxHeight_ = static_cast<uint32_t>(INT32_MAX);
1174 uint32_t minWidth_ = 1; // The width and height of the window cannot be less than or equal to 0.
1175 uint32_t minHeight_ = 1;
1176 float maxRatio_ = FLT_MAX;
1177 float minRatio_ = 0.0f;
1178 float vpRatio_ = 1.0f;
1179
WindowLimitsWindowLimits1180 WindowLimits() {}
WindowLimitsWindowLimits1181 WindowLimits(uint32_t maxWidth, uint32_t maxHeight, uint32_t minWidth, uint32_t minHeight, float maxRatio,
1182 float minRatio) : maxWidth_(maxWidth), maxHeight_(maxHeight), minWidth_(minWidth), minHeight_(minHeight),
1183 maxRatio_(maxRatio), minRatio_(minRatio) {}
WindowLimitsWindowLimits1184 WindowLimits(uint32_t maxWidth, uint32_t maxHeight, uint32_t minWidth, uint32_t minHeight, float maxRatio,
1185 float minRatio, float vpRatio) : maxWidth_(maxWidth), maxHeight_(maxHeight), minWidth_(minWidth),
1186 minHeight_(minHeight), maxRatio_(maxRatio), minRatio_(minRatio), vpRatio_(vpRatio) {}
1187
IsEmptyWindowLimits1188 bool IsEmpty() const
1189 {
1190 return (maxWidth_ == 0 || minWidth_ == 0 || maxHeight_ == 0 || minHeight_ == 0);
1191 }
1192 };
1193
1194 /**
1195 * @struct TitleButtonRect
1196 *
1197 * @brief An area of title buttons relative to the upper right corner of the window.
1198 */
1199 struct TitleButtonRect {
1200 int32_t posX_;
1201 int32_t posY_;
1202 uint32_t width_;
1203 uint32_t height_;
1204
1205 bool operator==(const TitleButtonRect& a) const
1206 {
1207 return (posX_ == a.posX_ && posY_ == a.posY_ && width_ == a.width_ && height_ == a.height_);
1208 }
1209
1210 bool operator!=(const TitleButtonRect& a) const
1211 {
1212 return !this->operator==(a);
1213 }
1214
IsUninitializedRectTitleButtonRect1215 bool IsUninitializedRect() const
1216 {
1217 return (posX_ == 0 && posY_ == 0 && width_ == 0 && height_ == 0);
1218 }
1219
IsInsideOfTitleButtonRect1220 bool IsInsideOf(const TitleButtonRect& a) const
1221 {
1222 return (posX_ >= a.posX_ && posY_ >= a.posY_ &&
1223 posX_ + width_ <= a.posX_ + a.width_ && posY_ + height_ <= a.posY_ + a.height_);
1224 }
1225 };
1226
1227 /**
1228 * @struct WindowLayoutInfo
1229 *
1230 * @brief Layout info for all windows on the screen.
1231 */
1232 struct WindowLayoutInfo : public Parcelable {
1233 Rect rect = { 0, 0, 0, 0 };
1234
MarshallingWindowLayoutInfo1235 bool Marshalling(Parcel& parcel) const override
1236 {
1237 return parcel.WriteInt32(rect.posX_) && parcel.WriteInt32(rect.posY_) &&
1238 parcel.WriteUint32(rect.width_) && parcel.WriteUint32(rect.height_);
1239 }
1240
UnmarshallingWindowLayoutInfo1241 static WindowLayoutInfo* Unmarshalling(Parcel& parcel)
1242 {
1243 WindowLayoutInfo* windowLayoutInfo = new WindowLayoutInfo;
1244 if (!parcel.ReadInt32(windowLayoutInfo->rect.posX_) ||
1245 !parcel.ReadInt32(windowLayoutInfo->rect.posY_) ||
1246 !parcel.ReadUint32(windowLayoutInfo->rect.width_) ||
1247 !parcel.ReadUint32(windowLayoutInfo->rect.height_)) {
1248 delete windowLayoutInfo;
1249 return nullptr;
1250 }
1251 return windowLayoutInfo;
1252 }
1253 };
1254
1255 /*
1256 * Config of keyboard animation
1257 */
1258 class KeyboardAnimationCurve : public Parcelable {
1259 public:
1260 KeyboardAnimationCurve() = default;
KeyboardAnimationCurve(const std::string & curveType,const std::vector<float> & curveParams,uint32_t duration)1261 KeyboardAnimationCurve(const std::string& curveType, const std::vector<float>& curveParams, uint32_t duration)
1262 : curveType_(curveType), duration_(duration)
1263 {
1264 curveParams_.assign(curveParams.begin(), curveParams.end());
1265 }
1266
Marshalling(Parcel & parcel)1267 virtual bool Marshalling(Parcel& parcel) const override
1268 {
1269 if (!parcel.WriteString(curveType_)) {
1270 return false;
1271 }
1272
1273 auto paramSize = curveParams_.size();
1274 if (paramSize == 4) { // 4: param size
1275 if (!parcel.WriteUint32(static_cast<uint32_t>(paramSize))) {
1276 return false;
1277 }
1278 for (auto& param : curveParams_) {
1279 if (!parcel.WriteFloat(param)) {
1280 return false;
1281 }
1282 }
1283 } else {
1284 if (!parcel.WriteUint32(0)) {
1285 return false;
1286 }
1287 }
1288
1289 if (!parcel.WriteUint32(duration_)) {
1290 return false;
1291 }
1292 return true;
1293 }
1294
Unmarshalling(Parcel & parcel)1295 static KeyboardAnimationCurve* Unmarshalling(Parcel& parcel)
1296 {
1297 KeyboardAnimationCurve* config = new KeyboardAnimationCurve;
1298 uint32_t paramSize = 0;
1299 if (!parcel.ReadString(config->curveType_) || !parcel.ReadUint32(paramSize)) {
1300 delete config;
1301 return nullptr;
1302 }
1303
1304 if (paramSize == 4) { // 4: paramSize
1305 for (uint32_t i = 0; i < paramSize; i++) {
1306 float param = 0.0f;
1307 if (!parcel.ReadFloat(param)) {
1308 delete config;
1309 return nullptr;
1310 } else {
1311 config->curveParams_.push_back(param);
1312 }
1313 }
1314 }
1315
1316 if (!parcel.ReadUint32(config->duration_)) {
1317 delete config;
1318 return nullptr;
1319 }
1320 return config;
1321 }
1322
1323 std::string curveType_ = "";
1324 std::vector<float> curveParams_ = {};
1325 uint32_t duration_ = 0;
1326 };
1327
1328 struct KeyboardAnimationConfig {
1329 KeyboardAnimationCurve curveIn;
1330 KeyboardAnimationCurve curveOut;
1331 };
1332
1333 struct MoveConfiguration {
1334 DisplayId displayId = DISPLAY_ID_INVALID;
ToStringMoveConfiguration1335 std::string ToString() const
1336 {
1337 std::string str;
1338 constexpr int BUFFER_SIZE = 23;
1339 char buffer[BUFFER_SIZE] = { 0 };
1340 if (snprintf_s(buffer, sizeof(buffer), sizeof(buffer) - 1, "[%llu]", displayId) > 0) {
1341 str.append(buffer);
1342 }
1343 return str;
1344 }
1345 };
1346
1347 enum class CaseType {
1348 CASE_WINDOW_MANAGER = 0,
1349 CASE_WINDOW,
1350 CASE_STAGE
1351 };
1352
1353 enum class MaximizePresentation {
1354 FOLLOW_APP_IMMERSIVE_SETTING = 0, // follow app set immersiveStateEnable
1355 EXIT_IMMERSIVE = 1, // immersiveStateEnable will be set as false
1356 ENTER_IMMERSIVE = 2, // immersiveStateEnable will be set as true
1357 // immersiveStateEnable will be set as true, titleHoverShowEnabled and dockHoverShowEnabled will be set as false
1358 ENTER_IMMERSIVE_DISABLE_TITLE_AND_DOCK_HOVER = 3,
1359 };
1360
1361 enum ForceHideState : uint32_t {
1362 NOT_HIDDEN = 0,
1363 HIDDEN_WHEN_FOCUSED,
1364 HIDDEN_WHEN_UNFOCUSED
1365 };
1366
1367 enum class ModalityType : uint8_t {
1368 WINDOW_MODALITY,
1369 APPLICATION_MODALITY,
1370 };
1371
1372 struct SubWindowOptions {
1373 std::string title;
1374 bool decorEnabled = false;
1375 bool isModal = false;
1376 bool isTopmost = false;
1377 ModalityType modalityType = ModalityType::WINDOW_MODALITY;
1378 };
1379
1380 enum class ExtensionWindowAttribute : int32_t {
1381 SYSTEM_WINDOW = 0,
1382 SUB_WINDOW = 1,
1383 UNKNOWN = 2
1384 };
1385
1386 struct SystemWindowOptions {
1387 int32_t windowType = -1;
1388 };
1389
1390 struct ExtensionWindowConfig {
1391 std::string windowName;
1392 ExtensionWindowAttribute windowAttribute = ExtensionWindowAttribute::UNKNOWN;
1393 Rect windowRect;
1394 SubWindowOptions subWindowOptions;
1395 SystemWindowOptions systemWindowOptions;
1396 };
1397
1398 /**
1399 * @struct WindowDensityInfo
1400 *
1401 * @brief Currently available density
1402 */
1403 struct WindowDensityInfo {
1404 float systemDensity = UNDEFINED_DENSITY;
1405 float defaultDensity = UNDEFINED_DENSITY;
1406 float customDensity = UNDEFINED_DENSITY;
1407
ToStringWindowDensityInfo1408 std::string ToString() const
1409 {
1410 std::string str;
1411 constexpr int BUFFER_SIZE = 64;
1412 char buffer[BUFFER_SIZE] = { 0 };
1413 if (snprintf_s(buffer, sizeof(buffer), sizeof(buffer) - 1,
1414 "[%f, %f, %f]", systemDensity, defaultDensity, customDensity) > 0) {
1415 str.append(buffer);
1416 }
1417 return str;
1418 }
1419 };
1420
1421 /**
1422 * @struct KeyboardLayoutParams
1423 *
1424 * @brief Keyboard needs to adjust layout
1425 */
1426 struct KeyboardLayoutParams : public Parcelable {
1427 public:
1428 WindowGravity gravity_ = WindowGravity::WINDOW_GRAVITY_BOTTOM;
1429 int32_t landscapeAvoidHeight_ = -1;
1430 int32_t portraitAvoidHeight_ = -1;
1431 Rect LandscapeKeyboardRect_ { 0, 0, 0, 0 };
1432 Rect PortraitKeyboardRect_ { 0, 0, 0, 0 };
1433 Rect LandscapePanelRect_ { 0, 0, 0, 0 };
1434 Rect PortraitPanelRect_ { 0, 0, 0, 0 };
1435
1436 bool operator==(const KeyboardLayoutParams& others) const
1437 {
1438 return (gravity_ == others.gravity_ &&
1439 landscapeAvoidHeight_ == others.landscapeAvoidHeight_ &&
1440 portraitAvoidHeight_ == others.portraitAvoidHeight_ &&
1441 LandscapeKeyboardRect_ == others.LandscapeKeyboardRect_ &&
1442 PortraitKeyboardRect_ == others.PortraitKeyboardRect_ &&
1443 LandscapePanelRect_ == others.LandscapePanelRect_ &&
1444 PortraitPanelRect_ == others.PortraitPanelRect_);
1445 }
1446
1447 bool operator!=(const KeyboardLayoutParams& params) const
1448 {
1449 return !this->operator==(params);
1450 }
1451
isEmptyKeyboardLayoutParams1452 bool isEmpty() const
1453 {
1454 return LandscapeKeyboardRect_.IsUninitializedRect() && PortraitKeyboardRect_.IsUninitializedRect() &&
1455 LandscapePanelRect_.IsUninitializedRect() && PortraitPanelRect_.IsUninitializedRect();
1456 }
1457
WriteParcelKeyboardLayoutParams1458 static inline bool WriteParcel(Parcel& parcel, const Rect& rect)
1459 {
1460 return parcel.WriteInt32(rect.posX_) && parcel.WriteInt32(rect.posY_) &&
1461 parcel.WriteUint32(rect.width_) && parcel.WriteUint32(rect.height_);
1462 }
1463
ReadParcelKeyboardLayoutParams1464 static inline bool ReadParcel(Parcel& parcel, Rect& rect)
1465 {
1466 return parcel.ReadInt32(rect.posX_) && parcel.ReadInt32(rect.posY_) &&
1467 parcel.ReadUint32(rect.width_) && parcel.ReadUint32(rect.height_);
1468 }
1469
MarshallingKeyboardLayoutParams1470 virtual bool Marshalling(Parcel& parcel) const override
1471 {
1472 return (parcel.WriteUint32(static_cast<uint32_t>(gravity_)) &&
1473 parcel.WriteInt32(landscapeAvoidHeight_) &&
1474 parcel.WriteInt32(portraitAvoidHeight_) &&
1475 WriteParcel(parcel, LandscapeKeyboardRect_) &&
1476 WriteParcel(parcel, PortraitKeyboardRect_) &&
1477 WriteParcel(parcel, LandscapePanelRect_) &&
1478 WriteParcel(parcel, PortraitPanelRect_));
1479 }
1480
UnmarshallingKeyboardLayoutParams1481 static KeyboardLayoutParams* Unmarshalling(Parcel& parcel)
1482 {
1483 KeyboardLayoutParams* params = new(std::nothrow) KeyboardLayoutParams();
1484 uint32_t gravity;
1485 if (parcel.ReadUint32(gravity) &&
1486 parcel.ReadInt32(params->landscapeAvoidHeight_) &&
1487 parcel.ReadInt32(params->portraitAvoidHeight_) &&
1488 ReadParcel(parcel, params->LandscapeKeyboardRect_) &&
1489 ReadParcel(parcel, params->PortraitKeyboardRect_) &&
1490 ReadParcel(parcel, params->LandscapePanelRect_) &&
1491 ReadParcel(parcel, params->PortraitPanelRect_)) {
1492 params->gravity_ = static_cast<WindowGravity>(gravity);
1493 return params;
1494 }
1495 delete params;
1496 return nullptr;
1497 }
1498 };
1499
1500 /**
1501 * @struct KeyboardTouchHotAreas
1502 *
1503 * @brief Keyboard needs to set hotArea
1504 */
1505 struct KeyboardTouchHotAreas {
1506 std::vector<Rect> landscapeKeyboardHotAreas_;
1507 std::vector<Rect> portraitKeyboardHotAreas_;
1508 std::vector<Rect> landscapePanelHotAreas_;
1509 std::vector<Rect> portraitPanelHotAreas_;
1510
isKeyboardEmptyKeyboardTouchHotAreas1511 bool isKeyboardEmpty() const
1512 {
1513 return (landscapeKeyboardHotAreas_.empty()) || (portraitKeyboardHotAreas_.empty());
1514 }
1515
isPanelEmptyKeyboardTouchHotAreas1516 bool isPanelEmpty() const
1517 {
1518 return (landscapePanelHotAreas_.empty()) || (portraitPanelHotAreas_.empty());
1519 }
1520 };
1521
1522 enum class KeyboardViewMode: uint32_t {
1523 NON_IMMERSIVE_MODE = 0,
1524 IMMERSIVE_MODE,
1525 LIGHT_IMMERSIVE_MODE,
1526 DARK_IMMERSIVE_MODE,
1527 VIEW_MODE_END,
1528 };
1529 }
1530 }
1531 #endif // OHOS_ROSEN_WM_COMMON_H
1532