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