1 /* 2 * Copyright (c) 2023-2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_ROSEN_WM_COMMON_H 17 #define OHOS_ROSEN_WM_COMMON_H 18 19 #include <parcel.h> 20 #include <map> 21 #include <float.h> 22 23 namespace OHOS { 24 namespace Rosen { 25 using DisplayId = uint64_t; 26 27 /** 28 * @brief Enumerates type of window 29 */ 30 enum class WindowType : uint32_t { 31 APP_WINDOW_BASE = 1, 32 APP_MAIN_WINDOW_BASE = APP_WINDOW_BASE, 33 WINDOW_TYPE_APP_MAIN_WINDOW = APP_MAIN_WINDOW_BASE, 34 APP_MAIN_WINDOW_END, 35 36 APP_SUB_WINDOW_BASE = 1000, 37 WINDOW_TYPE_MEDIA = APP_SUB_WINDOW_BASE, 38 WINDOW_TYPE_APP_SUB_WINDOW, 39 WINDOW_TYPE_APP_COMPONENT, 40 APP_SUB_WINDOW_END, 41 APP_WINDOW_END = APP_SUB_WINDOW_END, 42 43 SYSTEM_WINDOW_BASE = 2000, 44 BELOW_APP_SYSTEM_WINDOW_BASE = SYSTEM_WINDOW_BASE, 45 WINDOW_TYPE_WALLPAPER = SYSTEM_WINDOW_BASE, 46 WINDOW_TYPE_DESKTOP, 47 BELOW_APP_SYSTEM_WINDOW_END, 48 49 ABOVE_APP_SYSTEM_WINDOW_BASE = 2100, 50 WINDOW_TYPE_APP_LAUNCHING = ABOVE_APP_SYSTEM_WINDOW_BASE, 51 WINDOW_TYPE_DOCK_SLICE, 52 WINDOW_TYPE_INCOMING_CALL, 53 WINDOW_TYPE_SEARCHING_BAR, 54 WINDOW_TYPE_SYSTEM_ALARM_WINDOW, 55 WINDOW_TYPE_INPUT_METHOD_FLOAT, 56 WINDOW_TYPE_FLOAT, 57 WINDOW_TYPE_TOAST, 58 WINDOW_TYPE_STATUS_BAR, 59 WINDOW_TYPE_PANEL, 60 WINDOW_TYPE_KEYGUARD, 61 WINDOW_TYPE_VOLUME_OVERLAY, 62 WINDOW_TYPE_NAVIGATION_BAR, 63 WINDOW_TYPE_DRAGGING_EFFECT, 64 WINDOW_TYPE_POINTER, 65 WINDOW_TYPE_LAUNCHER_RECENT, 66 WINDOW_TYPE_LAUNCHER_DOCK, 67 WINDOW_TYPE_BOOT_ANIMATION, 68 WINDOW_TYPE_FREEZE_DISPLAY, 69 WINDOW_TYPE_VOICE_INTERACTION, 70 WINDOW_TYPE_FLOAT_CAMERA, 71 WINDOW_TYPE_PLACEHOLDER, 72 WINDOW_TYPE_DIALOG, 73 WINDOW_TYPE_SCREENSHOT, 74 WINDOW_TYPE_GLOBAL_SEARCH, 75 WINDOW_TYPE_SYSTEM_TOAST, 76 WINDOW_TYPE_SYSTEM_FLOAT, 77 WINDOW_TYPE_PIP, 78 WINDOW_TYPE_THEME_EDITOR, 79 WINDOW_TYPE_NAVIGATION_INDICATOR, 80 WINDOW_TYPE_HANDWRITE, 81 WINDOW_TYPE_SCENE_BOARD, 82 WINDOW_TYPE_KEYBOARD_PANEL, 83 ABOVE_APP_SYSTEM_WINDOW_END, 84 85 SYSTEM_SUB_WINDOW_BASE = 2500, 86 WINDOW_TYPE_SYSTEM_SUB_WINDOW = SYSTEM_SUB_WINDOW_BASE, 87 SYSTEM_SUB_WINDOW_END, 88 89 SYSTEM_WINDOW_END = SYSTEM_SUB_WINDOW_END, 90 91 WINDOW_TYPE_UI_EXTENSION = 3000 92 }; 93 94 /** 95 * @brief Enumerates state of window. 96 */ 97 enum class WindowState : uint32_t { 98 STATE_INITIAL, 99 STATE_CREATED, 100 STATE_SHOWN, 101 STATE_HIDDEN, 102 STATE_FROZEN, 103 STATE_UNFROZEN, 104 STATE_DESTROYED, 105 STATE_BOTTOM = STATE_DESTROYED // Add state type after STATE_DESTROYED is not allowed. 106 }; 107 108 /** 109 * @brief Enumerates blur style of window. 110 */ 111 enum class WindowBlurStyle : uint32_t { 112 WINDOW_BLUR_OFF = 0, 113 WINDOW_BLUR_THIN, 114 WINDOW_BLUR_REGULAR, 115 WINDOW_BLUR_THICK 116 }; 117 118 /** 119 * @brief Enumerates mode supported of window. 120 */ 121 enum WindowModeSupport : uint32_t { 122 WINDOW_MODE_SUPPORT_FULLSCREEN = 1 << 0, 123 WINDOW_MODE_SUPPORT_FLOATING = 1 << 1, 124 WINDOW_MODE_SUPPORT_SPLIT_PRIMARY = 1 << 2, 125 WINDOW_MODE_SUPPORT_SPLIT_SECONDARY = 1 << 3, 126 WINDOW_MODE_SUPPORT_PIP = 1 << 4, 127 WINDOW_MODE_SUPPORT_ALL = WINDOW_MODE_SUPPORT_FLOATING | 128 WINDOW_MODE_SUPPORT_FULLSCREEN | 129 WINDOW_MODE_SUPPORT_SPLIT_PRIMARY | 130 WINDOW_MODE_SUPPORT_SPLIT_SECONDARY | 131 WINDOW_MODE_SUPPORT_PIP 132 }; 133 134 /** 135 * @brief Enumerates mode of window. 136 */ 137 enum class WindowMode : uint32_t { 138 WINDOW_MODE_UNDEFINED = 0, 139 WINDOW_MODE_FULLSCREEN = 1, 140 WINDOW_MODE_SPLIT_PRIMARY = 100, 141 WINDOW_MODE_SPLIT_SECONDARY, 142 WINDOW_MODE_FLOATING, 143 WINDOW_MODE_PIP 144 }; 145 146 /** 147 * @brief Enumerates status of window. 148 */ 149 enum class WindowStatus : uint32_t { 150 WINDOW_STATUS_UNDEFINED = 0, 151 WINDOW_STATUS_FULLSCREEN = 1, 152 WINDOW_STATUS_MAXIMIZE, 153 WINDOW_STATUS_MINIMIZE, 154 WINDOW_STATUS_FLOATING, 155 WINDOW_STATUS_SPLITSCREEN 156 }; 157 158 /** 159 * @brief Enumerates error code of window. 160 */ 161 enum class WMError : int32_t { 162 WM_OK = 0, 163 WM_DO_NOTHING, 164 WM_ERROR_NO_MEM, 165 WM_ERROR_DESTROYED_OBJECT, 166 WM_ERROR_INVALID_WINDOW, 167 WM_ERROR_INVALID_WINDOW_MODE_OR_SIZE, 168 WM_ERROR_INVALID_OPERATION, 169 WM_ERROR_INVALID_PERMISSION, 170 WM_ERROR_NOT_SYSTEM_APP, 171 WM_ERROR_NO_REMOTE_ANIMATION, 172 WM_ERROR_INVALID_DISPLAY, 173 WM_ERROR_INVALID_PARENT, 174 WM_ERROR_INVALID_OP_IN_CUR_STATUS, 175 WM_ERROR_REPEAT_OPERATION, 176 WM_ERROR_INVALID_SESSION, 177 WM_ERROR_INVALID_CALLING, 178 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_INVALID_OP_IN_CUR_STATUS = 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 234 /** 235 * @brief Enumerates flag of window. 236 */ 237 enum class WindowFlag : uint32_t { 238 WINDOW_FLAG_NEED_AVOID = 1, 239 WINDOW_FLAG_PARENT_LIMIT = 1 << 1, 240 WINDOW_FLAG_SHOW_WHEN_LOCKED = 1 << 2, 241 WINDOW_FLAG_FORBID_SPLIT_MOVE = 1 << 3, 242 WINDOW_FLAG_WATER_MARK = 1 << 4, 243 WINDOW_FLAG_IS_MODAL = 1 << 5, 244 WINDOW_FLAG_HANDWRITING = 1 << 6, 245 WINDOW_FLAG_IS_TOAST = 1 << 7, 246 WINDOW_FLAG_IS_APPLICATION_MODAL = 1 << 8, 247 WINDOW_FLAG_END = 1 << 9, 248 }; 249 250 /** 251 * @brief Used to map from WMError to WmErrorCode. 252 */ 253 const std::map<WMError, WmErrorCode> WM_JS_TO_ERROR_CODE_MAP { 254 {WMError::WM_OK, WmErrorCode::WM_OK }, 255 {WMError::WM_DO_NOTHING, WmErrorCode::WM_ERROR_STATE_ABNORMALLY }, 256 {WMError::WM_ERROR_DESTROYED_OBJECT, WmErrorCode::WM_ERROR_STATE_ABNORMALLY }, 257 {WMError::WM_ERROR_DEVICE_NOT_SUPPORT, WmErrorCode::WM_ERROR_DEVICE_NOT_SUPPORT }, 258 {WMError::WM_ERROR_INVALID_OPERATION, WmErrorCode::WM_ERROR_STATE_ABNORMALLY }, 259 {WMError::WM_ERROR_INVALID_PARAM, WmErrorCode::WM_ERROR_INVALID_PARAM }, 260 {WMError::WM_ERROR_INVALID_PERMISSION, WmErrorCode::WM_ERROR_NO_PERMISSION }, 261 {WMError::WM_ERROR_NOT_SYSTEM_APP, WmErrorCode::WM_ERROR_NOT_SYSTEM_APP }, 262 {WMError::WM_ERROR_INVALID_TYPE, WmErrorCode::WM_ERROR_STATE_ABNORMALLY }, 263 {WMError::WM_ERROR_INVALID_WINDOW, WmErrorCode::WM_ERROR_STATE_ABNORMALLY }, 264 {WMError::WM_ERROR_INVALID_WINDOW_MODE_OR_SIZE, WmErrorCode::WM_ERROR_STATE_ABNORMALLY }, 265 {WMError::WM_ERROR_IPC_FAILED, WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY }, 266 {WMError::WM_ERROR_NO_MEM, WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY }, 267 {WMError::WM_ERROR_NO_REMOTE_ANIMATION, WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY }, 268 {WMError::WM_ERROR_INVALID_DISPLAY, WmErrorCode::WM_ERROR_INVALID_DISPLAY }, 269 {WMError::WM_ERROR_INVALID_PARENT, WmErrorCode::WM_ERROR_INVALID_PARENT }, 270 {WMError::WM_ERROR_INVALID_OP_IN_CUR_STATUS, WmErrorCode::WM_ERROR_INVALID_OP_IN_CUR_STATUS }, 271 {WMError::WM_ERROR_REPEAT_OPERATION, WmErrorCode::WM_ERROR_REPEAT_OPERATION }, 272 {WMError::WM_ERROR_NULLPTR, WmErrorCode::WM_ERROR_STATE_ABNORMALLY }, 273 {WMError::WM_ERROR_SAMGR, WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY }, 274 {WMError::WM_ERROR_START_ABILITY_FAILED, WmErrorCode::WM_ERROR_START_ABILITY_FAILED }, 275 {WMError::WM_ERROR_SYSTEM_ABNORMALLY, WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY }, 276 }; 277 278 /** 279 * @brief Enumerates window size change reason. 280 */ 281 enum class WindowSizeChangeReason : uint32_t { 282 UNDEFINED = 0, 283 MAXIMIZE, 284 RECOVER, 285 ROTATION, 286 DRAG, 287 DRAG_START, 288 DRAG_END, 289 RESIZE, 290 MOVE, 291 HIDE, 292 TRANSFORM, 293 CUSTOM_ANIMATION_SHOW, 294 FULL_TO_SPLIT, 295 SPLIT_TO_FULL, 296 FULL_TO_FLOATING, 297 FLOATING_TO_FULL, 298 PIP_START, 299 PIP_SHOW, 300 PIP_AUTO_START, 301 PIP_RATIO_CHANGE, 302 PIP_RESTORE, 303 UPDATE_DPI_SYNC, 304 DRAG_MOVE, 305 END 306 }; 307 308 /** 309 * @brief Enumerates window gravity. 310 */ 311 enum class WindowGravity : uint32_t { 312 WINDOW_GRAVITY_FLOAT = 0, 313 WINDOW_GRAVITY_BOTTOM 314 }; 315 316 /** 317 * @brief Enumerates window session type. 318 */ 319 enum class WindowSessionType : uint32_t { 320 SCENE_SESSION = 0, 321 EXTENSION_SESSION = 1 322 }; 323 324 /** 325 * @brief Enumerates window tag. 326 */ 327 enum class WindowTag : uint32_t { 328 MAIN_WINDOW = 0, 329 SUB_WINDOW = 1, 330 SYSTEM_WINDOW = 2 331 }; 332 333 /** 334 * @brief Enumerates drag event. 335 */ 336 enum class DragEvent : uint32_t { 337 DRAG_EVENT_IN = 1, 338 DRAG_EVENT_OUT, 339 DRAG_EVENT_MOVE, 340 DRAG_EVENT_END 341 }; 342 343 /** 344 * @brief Enumerates layout mode of window. 345 */ 346 enum class WindowLayoutMode : uint32_t { 347 BASE = 0, 348 CASCADE = BASE, 349 TILE = 1, 350 END, 351 }; 352 353 namespace { 354 constexpr uint32_t SYSTEM_COLOR_WHITE = 0xE5FFFFFF; 355 constexpr uint32_t SYSTEM_COLOR_BLACK = 0x66000000; 356 constexpr float UNDEFINED_BRIGHTNESS = -1.0f; 357 constexpr float MINIMUM_BRIGHTNESS = 0.0f; 358 constexpr float MAXIMUM_BRIGHTNESS = 1.0f; 359 360 constexpr uint32_t INVALID_WINDOW_ID = 0; 361 constexpr int32_t INVALID_PID = -1; 362 constexpr int32_t INVALID_UID = -1; 363 } 364 365 /** 366 * @struct PointInfo. 367 * 368 * @brief Point info. 369 */ 370 struct PointInfo { 371 int32_t x; 372 int32_t y; 373 }; 374 375 /** 376 * @class Transform 377 * 378 * @brief parameter of transform and rotate. 379 */ 380 class Transform { 381 public: Transform()382 Transform() 383 : pivotX_(0.5f), pivotY_(0.5f), scaleX_(1.f), scaleY_(1.f), scaleZ_(1.f), rotationX_(0.f), 384 rotationY_(0.f), rotationZ_(0.f), translateX_(0.f), translateY_(0.f), translateZ_(0.f) 385 {} ~Transform()386 ~Transform() {} 387 388 bool operator==(const Transform& right) const 389 { 390 return NearZero(scaleX_ - right.scaleX_) && 391 NearZero(scaleY_ - right.scaleY_) && 392 NearZero(scaleZ_ - right.scaleZ_) && 393 NearZero(pivotX_ - right.pivotX_) && 394 NearZero(pivotY_ - right.pivotY_) && 395 NearZero(translateX_ - right.translateX_) && 396 NearZero(translateY_ - right.translateY_) && 397 NearZero(translateZ_ - right.translateZ_) && 398 NearZero(rotationX_ - right.rotationX_) && 399 NearZero(rotationY_ - right.rotationY_) && 400 NearZero(rotationZ_ - right.rotationZ_); 401 } 402 403 bool operator!=(const Transform& right) const 404 { 405 return !(*this == right); 406 } 407 Identity()408 static const Transform& Identity() 409 { 410 static Transform I; 411 return I; 412 } 413 414 float pivotX_; 415 float pivotY_; 416 float scaleX_; 417 float scaleY_; 418 float scaleZ_; 419 float rotationX_; 420 float rotationY_; 421 float rotationZ_; 422 float translateX_; 423 float translateY_; 424 float translateZ_; 425 Unmarshalling(Parcel & parcel)426 void Unmarshalling(Parcel& parcel) 427 { 428 pivotX_ = parcel.ReadFloat(); 429 pivotY_ = parcel.ReadFloat(); 430 scaleX_ = parcel.ReadFloat(); 431 scaleY_ = parcel.ReadFloat(); 432 scaleZ_ = parcel.ReadFloat(); 433 rotationX_ = parcel.ReadFloat(); 434 rotationY_ = parcel.ReadFloat(); 435 rotationZ_ = parcel.ReadFloat(); 436 translateX_ = parcel.ReadFloat(); 437 translateY_ = parcel.ReadFloat(); 438 translateZ_ = parcel.ReadFloat(); 439 } 440 Marshalling(Parcel & parcel)441 bool Marshalling(Parcel& parcel) const 442 { 443 return parcel.WriteFloat(pivotX_) && parcel.WriteFloat(pivotY_) && 444 parcel.WriteFloat(scaleX_) && parcel.WriteFloat(scaleY_) && parcel.WriteFloat(scaleZ_) && 445 parcel.WriteFloat(rotationX_) && parcel.WriteFloat(rotationY_) && parcel.WriteFloat(rotationZ_) && 446 parcel.WriteFloat(translateX_) && parcel.WriteFloat(translateY_) && parcel.WriteFloat(translateZ_); 447 } 448 449 private: NearZero(float val)450 static inline bool NearZero(float val) 451 { 452 return -0.001f < val && val < 0.001f; 453 } 454 }; 455 456 /** 457 * @struct SystemBarPropertyFlag 458 * 459 * @brief Flag of system bar 460 */ 461 struct SystemBarPropertyFlag { 462 bool enableFlag = false; 463 bool backgroundColorFlag = false; 464 bool contentColorFlag = false; 465 bool enableAnimationFlag = false; 466 }; 467 468 /** 469 * @struct Rect 470 * 471 * @brief Window Rect. 472 */ 473 struct Rect { 474 int32_t posX_; 475 int32_t posY_; 476 uint32_t width_; 477 uint32_t height_; 478 479 bool operator==(const Rect& a) const 480 { 481 return (posX_ == a.posX_ && posY_ == a.posY_ && width_ == a.width_ && height_ == a.height_); 482 } 483 484 bool operator!=(const Rect& a) const 485 { 486 return !this->operator==(a); 487 } 488 IsInsideOfRect489 bool IsInsideOf(const Rect& a) const 490 { 491 return (posX_ >= a.posX_ && posY_ >= a.posY_ && 492 posX_ + width_ <= a.posX_ + a.width_ && posY_ + height_ <= a.posY_ + a.height_); 493 } 494 IsUninitializedRectRect495 bool IsUninitializedRect() const 496 { 497 return (posX_ == 0 && posY_ == 0 && width_ == 0 && height_ == 0); 498 } 499 IsUninitializedSizeRect500 bool IsUninitializedSize() const 501 { 502 return width_ == 0 && height_ == 0; 503 } 504 }; 505 506 /** 507 * @struct SystemBarProperty 508 * 509 * @brief Property of system bar. 510 */ 511 struct SystemBarProperty { 512 bool enable_; 513 uint32_t backgroundColor_; 514 uint32_t contentColor_; 515 bool enableAnimation_; 516 SystemBarSettingFlag settingFlag_; SystemBarPropertySystemBarProperty517 SystemBarProperty() : enable_(true), backgroundColor_(SYSTEM_COLOR_BLACK), contentColor_(SYSTEM_COLOR_WHITE), 518 enableAnimation_(false), settingFlag_(SystemBarSettingFlag::DEFAULT_SETTING) {} SystemBarPropertySystemBarProperty519 SystemBarProperty(bool enable, uint32_t background, uint32_t content, bool enableAnimation) 520 : enable_(enable), backgroundColor_(background), contentColor_(content), enableAnimation_(enableAnimation), 521 settingFlag_(SystemBarSettingFlag::DEFAULT_SETTING) {} SystemBarPropertySystemBarProperty522 SystemBarProperty(bool enable, uint32_t background, uint32_t content) 523 : enable_(enable), backgroundColor_(background), contentColor_(content), enableAnimation_(false), 524 settingFlag_(SystemBarSettingFlag::DEFAULT_SETTING) {} SystemBarPropertySystemBarProperty525 SystemBarProperty(bool enable, uint32_t background, uint32_t content, 526 bool enableAnimation, SystemBarSettingFlag settingFlag) 527 : enable_(enable), backgroundColor_(background), contentColor_(content), enableAnimation_(enableAnimation), 528 settingFlag_(settingFlag) {} 529 530 bool operator == (const SystemBarProperty& a) const 531 { 532 return (enable_ == a.enable_ && backgroundColor_ == a.backgroundColor_ && contentColor_ == a.contentColor_ && 533 enableAnimation_ == a.enableAnimation_); 534 } 535 }; 536 537 /** 538 * @brief Enumerates avoid area type. 539 */ 540 enum class AvoidAreaType : uint32_t { 541 TYPE_SYSTEM, // area of SystemUI 542 TYPE_CUTOUT, // cutout of screen 543 TYPE_SYSTEM_GESTURE, // area for system gesture 544 TYPE_KEYBOARD, // area for soft input keyboard 545 TYPE_NAVIGATION_INDICATOR, // area for navigation indicator 546 }; 547 548 /** 549 * @brief Enumerates color space. 550 */ 551 enum class ColorSpace : uint32_t { 552 COLOR_SPACE_DEFAULT = 0, // Default color space. 553 COLOR_SPACE_WIDE_GAMUT, // Wide gamut color space. The specific wide color gamut depends on the screen. 554 }; 555 556 /** 557 * @brief Enumerates occupied area type. 558 */ 559 enum class OccupiedAreaType : uint32_t { 560 TYPE_INPUT, // area of input window 561 }; 562 563 /** 564 * @brief Enumerates window maximize mode. 565 */ 566 enum class MaximizeMode : uint32_t { 567 MODE_AVOID_SYSTEM_BAR, 568 MODE_FULL_FILL, 569 MODE_RECOVER 570 }; 571 572 /** 573 * @brief Enumerates window animation. 574 */ 575 enum class WindowAnimation : uint32_t { 576 NONE, 577 DEFAULT, 578 INPUTE, 579 CUSTOM 580 }; 581 582 /** 583 * @class AvoidArea 584 * 585 * @brief Area needed to avoid. 586 */ 587 class AvoidArea : virtual public RefBase { 588 public: 589 Rect topRect_ { 0, 0, 0, 0 }; 590 Rect leftRect_ { 0, 0, 0, 0 }; 591 Rect rightRect_ { 0, 0, 0, 0 }; 592 Rect bottomRect_ { 0, 0, 0, 0 }; 593 594 bool operator==(const AvoidArea& a) const 595 { 596 return (topRect_ == a.topRect_ && leftRect_ == a.leftRect_ && 597 rightRect_ == a.rightRect_ && bottomRect_ == a.bottomRect_); 598 } 599 600 bool operator!=(const AvoidArea& a) const 601 { 602 return !this->operator==(a); 603 } 604 ReadParcel(Parcel & parcel,Rect & rect)605 static inline bool ReadParcel(Parcel& parcel, Rect& rect) 606 { 607 return parcel.ReadInt32(rect.posX_) && parcel.ReadInt32(rect.posY_) && 608 parcel.ReadUint32(rect.width_) && parcel.ReadUint32(rect.height_); 609 } 610 WriteParcel(Parcel & parcel,const Rect & rect)611 static inline bool WriteParcel(Parcel& parcel, const Rect& rect) 612 { 613 return parcel.WriteInt32(rect.posX_) && parcel.WriteInt32(rect.posY_) && 614 parcel.WriteUint32(rect.width_) && parcel.WriteUint32(rect.height_); 615 } 616 isEmptyAvoidArea()617 bool isEmptyAvoidArea() const 618 { 619 return topRect_.IsUninitializedRect() && leftRect_.IsUninitializedRect() && 620 rightRect_.IsUninitializedRect() && bottomRect_.IsUninitializedRect(); 621 } 622 }; 623 624 using OnCallback = std::function<void(int64_t, int64_t)>; 625 626 /** 627 * @struct VsyncCallback 628 * 629 * @brief Vsync callback 630 */ 631 struct VsyncCallback { 632 OnCallback onCallback; 633 }; 634 635 /** 636 * @brief Enumerates window update type. 637 */ 638 enum class WindowUpdateType : int32_t { 639 WINDOW_UPDATE_ADDED = 1, 640 WINDOW_UPDATE_REMOVED, 641 WINDOW_UPDATE_FOCUSED, 642 WINDOW_UPDATE_BOUNDS, 643 WINDOW_UPDATE_ACTIVE, 644 WINDOW_UPDATE_PROPERTY 645 }; 646 647 struct WindowLimits { 648 uint32_t maxWidth_ = static_cast<uint32_t>(INT32_MAX); // The width and height are no larger than INT32_MAX. 649 uint32_t maxHeight_ = static_cast<uint32_t>(INT32_MAX); 650 uint32_t minWidth_ = 1; // The width and height of the window cannot be less than or equal to 0. 651 uint32_t minHeight_ = 1; 652 float maxRatio_ = FLT_MAX; 653 float minRatio_ = 0.0f; 654 float vpRatio_ = 1.0f; 655 WindowLimitsWindowLimits656 WindowLimits() {} WindowLimitsWindowLimits657 WindowLimits(uint32_t maxWidth, uint32_t maxHeight, uint32_t minWidth, uint32_t minHeight, float maxRatio, 658 float minRatio) : maxWidth_(maxWidth), maxHeight_(maxHeight), minWidth_(minWidth), minHeight_(minHeight), 659 maxRatio_(maxRatio), minRatio_(minRatio) {} WindowLimitsWindowLimits660 WindowLimits(uint32_t maxWidth, uint32_t maxHeight, uint32_t minWidth, uint32_t minHeight, float maxRatio, 661 float minRatio, float vpRatio) : maxWidth_(maxWidth), maxHeight_(maxHeight), minWidth_(minWidth), 662 minHeight_(minHeight), maxRatio_(maxRatio), minRatio_(minRatio), vpRatio_(vpRatio) {} 663 IsEmptyWindowLimits664 bool IsEmpty() const 665 { 666 return (maxHeight_ == 0 || minHeight_ == 0 || maxWidth_ == 0 || minWidth_ == 0); 667 } 668 }; 669 670 /** 671 * @struct TitleButtonRect 672 * 673 * @brief An area of title buttons relative to the upper right corner of the window. 674 */ 675 struct TitleButtonRect { 676 int32_t posX_; 677 int32_t posY_; 678 uint32_t width_; 679 uint32_t height_; 680 681 bool operator==(const TitleButtonRect& a) const 682 { 683 return (posX_ == a.posX_ && posY_ == a.posY_ && width_ == a.width_ && height_ == a.height_); 684 } 685 686 bool operator!=(const TitleButtonRect& a) const 687 { 688 return !this->operator==(a); 689 } 690 IsInsideOfTitleButtonRect691 bool IsInsideOf(const TitleButtonRect& a) const 692 { 693 return (posX_ >= a.posX_ && posY_ >= a.posY_ && 694 posX_ + width_ <= a.posX_ + a.width_ && posY_ + height_ <= a.posY_ + a.height_); 695 } 696 IsUninitializedRectTitleButtonRect697 bool IsUninitializedRect() const 698 { 699 return (posX_ == 0 && posY_ == 0 && width_ == 0 && height_ == 0); 700 } 701 }; 702 703 /* 704 * Config of keyboard animation 705 */ 706 class KeyboardAnimationCurve : public Parcelable { 707 public: 708 KeyboardAnimationCurve() = default; KeyboardAnimationCurve(const std::string & curveType,const std::vector<float> & curveParams,uint32_t duration)709 KeyboardAnimationCurve(const std::string& curveType, const std::vector<float>& curveParams, uint32_t duration) 710 : curveType_(curveType), duration_(duration) 711 { 712 curveParams_.assign(curveParams.begin(), curveParams.end()); 713 } 714 Marshalling(Parcel & parcel)715 virtual bool Marshalling(Parcel& parcel) const override 716 { 717 if (!parcel.WriteString(curveType_)) { 718 return false; 719 } 720 721 auto paramSize = curveParams_.size(); 722 if (paramSize == 4) { // 4: param size 723 if (!parcel.WriteUint32(static_cast<uint32_t>(paramSize))) { 724 return false; 725 } 726 for (auto& param : curveParams_) { 727 if (!parcel.WriteFloat(param)) { 728 return false; 729 } 730 } 731 } else { 732 if (!parcel.WriteUint32(0)) { 733 return false; 734 } 735 } 736 737 if (!parcel.WriteUint32(duration_)) { 738 return false; 739 } 740 return true; 741 } 742 Unmarshalling(Parcel & parcel)743 static KeyboardAnimationCurve* Unmarshalling(Parcel& parcel) 744 { 745 KeyboardAnimationCurve* config = new KeyboardAnimationCurve; 746 uint32_t paramSize = 0; 747 if (!parcel.ReadString(config->curveType_) || !parcel.ReadUint32(paramSize)) { 748 delete config; 749 return nullptr; 750 } 751 752 if (paramSize == 4) { // 4: paramSize 753 for (uint32_t i = 0; i < paramSize; i++) { 754 float param = 0.0f; 755 if (!parcel.ReadFloat(param)) { 756 delete config; 757 return nullptr; 758 } else { 759 config->curveParams_.push_back(param); 760 } 761 } 762 } 763 764 if (!parcel.ReadUint32(config->duration_)) { 765 delete config; 766 return nullptr; 767 } 768 return config; 769 } 770 771 std::string curveType_ = ""; 772 std::vector<float> curveParams_ = {}; 773 uint32_t duration_ = 0; 774 }; 775 776 struct KeyboardAnimationConfig { 777 KeyboardAnimationCurve curveIn; 778 KeyboardAnimationCurve curveOut; 779 }; 780 781 enum class MaximizePresentation { 782 FOLLOW_APP_IMMERSIVE_SETTING = 0, // follow app set immersiveStateEnable 783 EXIT_IMMERSIVE = 1, // immersiveStateEnable will be set as false 784 ENTER_IMMERSIVE = 2, // immersiveStateEnable will be set as true 785 // immersiveStateEnable will be set as true, titleHoverShowEnabled and dockHoverShowEnabled will be set as false 786 ENTER_IMMERSIVE_DISABLE_TITLE_AND_DOCK_HOVER = 3, 787 }; 788 789 enum class ModalityType : uint8_t { 790 WINDOW_MODALITY, 791 APPLICATION_MODALITY, 792 }; 793 794 struct SubWindowOptions { 795 std::string title; 796 bool decorEnabled = false; 797 bool isModal = false; 798 bool isTopmost = false; 799 ModalityType modalityType = ModalityType::WINDOW_MODALITY; 800 }; 801 802 enum class ExtensionWindowAttribute : int32_t { 803 SYSTEM_WINDOW = 0, 804 SUB_WINDOW = 1, 805 UNKNOWN = 2 806 }; 807 808 struct SystemWindowOptions { 809 int32_t windowType = -1; 810 }; 811 812 struct ExtensionWindowConfig { 813 std::string windowName; 814 ExtensionWindowAttribute windowAttribute = ExtensionWindowAttribute::UNKNOWN; 815 Rect windowRect; 816 SubWindowOptions subWindowOptions; 817 SystemWindowOptions systemWindowOptions; 818 }; 819 820 enum class BackupAndRestoreType : int32_t { 821 NONE = 0, // no backup and restore 822 CONTINUATION = 1, // distribute 823 APP_RECOVERY = 2, // app recovery 824 RESOURCESCHEDULE_RECOVERY = 3, // app is killed due to resource schedule 825 }; 826 } 827 } 828 #endif // OHOS_ROSEN_WM_COMMON_H 829