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 23 namespace OHOS { 24 namespace Rosen { 25 using DisplayId = uint64_t; 26 /** 27 * @brief Enumerates type of window. 28 */ 29 enum class WindowType : uint32_t { 30 APP_WINDOW_BASE = 1, 31 APP_MAIN_WINDOW_BASE = APP_WINDOW_BASE, 32 WINDOW_TYPE_APP_MAIN_WINDOW = APP_MAIN_WINDOW_BASE, 33 APP_MAIN_WINDOW_END, 34 35 APP_SUB_WINDOW_BASE = 1000, 36 WINDOW_TYPE_MEDIA = APP_SUB_WINDOW_BASE, 37 WINDOW_TYPE_APP_SUB_WINDOW, 38 WINDOW_TYPE_APP_COMPONENT, 39 APP_SUB_WINDOW_END, 40 APP_WINDOW_END = APP_SUB_WINDOW_END, 41 42 SYSTEM_WINDOW_BASE = 2000, 43 BELOW_APP_SYSTEM_WINDOW_BASE = SYSTEM_WINDOW_BASE, 44 WINDOW_TYPE_WALLPAPER = SYSTEM_WINDOW_BASE, 45 WINDOW_TYPE_DESKTOP, 46 BELOW_APP_SYSTEM_WINDOW_END, 47 48 ABOVE_APP_SYSTEM_WINDOW_BASE = 2100, 49 WINDOW_TYPE_APP_LAUNCHING = ABOVE_APP_SYSTEM_WINDOW_BASE, 50 WINDOW_TYPE_DOCK_SLICE, 51 WINDOW_TYPE_INCOMING_CALL, 52 WINDOW_TYPE_SEARCHING_BAR, 53 WINDOW_TYPE_SYSTEM_ALARM_WINDOW, 54 WINDOW_TYPE_INPUT_METHOD_FLOAT, 55 WINDOW_TYPE_FLOAT, 56 WINDOW_TYPE_TOAST, 57 WINDOW_TYPE_STATUS_BAR, 58 WINDOW_TYPE_PANEL, 59 WINDOW_TYPE_KEYGUARD, 60 WINDOW_TYPE_VOLUME_OVERLAY, 61 WINDOW_TYPE_NAVIGATION_BAR, 62 WINDOW_TYPE_DRAGGING_EFFECT, 63 WINDOW_TYPE_POINTER, 64 WINDOW_TYPE_LAUNCHER_RECENT, 65 WINDOW_TYPE_LAUNCHER_DOCK, 66 WINDOW_TYPE_BOOT_ANIMATION, 67 WINDOW_TYPE_FREEZE_DISPLAY, 68 WINDOW_TYPE_VOICE_INTERACTION, 69 WINDOW_TYPE_FLOAT_CAMERA, 70 WINDOW_TYPE_PLACEHOLDER, 71 WINDOW_TYPE_DIALOG, 72 WINDOW_TYPE_SCREENSHOT, 73 WINDOW_TYPE_INPUT_METHOD_STATUS_BAR, 74 WINDOW_TYPE_GLOBAL_SEARCH, 75 WINDOW_TYPE_NEGATIVE_SCREEN, 76 WINDOW_TYPE_SYSTEM_TOAST, 77 WINDOW_TYPE_SYSTEM_FLOAT, 78 WINDOW_TYPE_PIP, 79 WINDOW_TYPE_THEME_EDITOR, 80 WINDOW_TYPE_NAVIGATION_INDICATOR, 81 ABOVE_APP_SYSTEM_WINDOW_END, 82 83 SYSTEM_SUB_WINDOW_BASE = 2500, 84 WINDOW_TYPE_SYSTEM_SUB_WINDOW = SYSTEM_SUB_WINDOW_BASE, 85 SYSTEM_SUB_WINDOW_END, 86 87 SYSTEM_WINDOW_END = SYSTEM_SUB_WINDOW_END, 88 89 WINDOW_TYPE_UI_EXTENSION = 3000, 90 WINDOW_TYPE_SCENE_BOARD 91 }; 92 93 /** 94 * @brief Enumerates mode of window. 95 */ 96 enum class WindowMode : uint32_t { 97 WINDOW_MODE_UNDEFINED = 0, 98 WINDOW_MODE_FULLSCREEN = 1, 99 WINDOW_MODE_SPLIT_PRIMARY = 100, 100 WINDOW_MODE_SPLIT_SECONDARY, 101 WINDOW_MODE_FLOATING, 102 WINDOW_MODE_PIP 103 }; 104 105 /** 106 * @brief Enumerates mode supported of window. 107 */ 108 enum WindowModeSupport : uint32_t { 109 WINDOW_MODE_SUPPORT_FULLSCREEN = 1 << 0, 110 WINDOW_MODE_SUPPORT_FLOATING = 1 << 1, 111 WINDOW_MODE_SUPPORT_SPLIT_PRIMARY = 1 << 2, 112 WINDOW_MODE_SUPPORT_SPLIT_SECONDARY = 1 << 3, 113 WINDOW_MODE_SUPPORT_PIP = 1 << 4, 114 WINDOW_MODE_SUPPORT_ALL = WINDOW_MODE_SUPPORT_FULLSCREEN | 115 WINDOW_MODE_SUPPORT_SPLIT_PRIMARY | 116 WINDOW_MODE_SUPPORT_SPLIT_SECONDARY | 117 WINDOW_MODE_SUPPORT_FLOATING | 118 WINDOW_MODE_SUPPORT_PIP 119 }; 120 121 /** 122 * @brief Enumerates blur style of window. 123 */ 124 enum class WindowBlurStyle : uint32_t { 125 WINDOW_BLUR_OFF = 0, 126 WINDOW_BLUR_THIN, 127 WINDOW_BLUR_REGULAR, 128 WINDOW_BLUR_THICK 129 }; 130 131 /** 132 * @brief Enumerates state of window. 133 */ 134 enum class WindowState : uint32_t { 135 STATE_INITIAL, 136 STATE_CREATED, 137 STATE_SHOWN, 138 STATE_HIDDEN, 139 STATE_FROZEN, 140 STATE_UNFROZEN, 141 STATE_DESTROYED, 142 STATE_BOTTOM = STATE_DESTROYED, // Add state type after STATE_DESTROYED is not allowed 143 }; 144 145 /** 146 * @brief Enumerates error code of window. 147 */ 148 enum class WMError : int32_t { 149 WM_OK = 0, 150 WM_DO_NOTHING, 151 WM_ERROR_NO_MEM, 152 WM_ERROR_DESTROYED_OBJECT, 153 WM_ERROR_INVALID_WINDOW, 154 WM_ERROR_INVALID_WINDOW_MODE_OR_SIZE, 155 WM_ERROR_INVALID_OPERATION, 156 WM_ERROR_INVALID_PERMISSION, 157 WM_ERROR_NOT_SYSTEM_APP, 158 WM_ERROR_NO_REMOTE_ANIMATION, 159 WM_ERROR_INVALID_DISPLAY, 160 WM_ERROR_INVALID_PARENT, 161 WM_ERROR_OPER_FULLSCREEN_FAILED, 162 WM_ERROR_REPEAT_OPERATION, 163 WM_ERROR_INVALID_SESSION, 164 WM_ERROR_INVALID_CALLING, 165 166 WM_ERROR_DEVICE_NOT_SUPPORT = 801, // the value do not change.It is defined on all system 167 168 WM_ERROR_NEED_REPORT_BASE = 1000, // error code > 1000 means need report 169 WM_ERROR_NULLPTR, 170 WM_ERROR_INVALID_TYPE, 171 WM_ERROR_INVALID_PARAM, 172 WM_ERROR_SAMGR, 173 WM_ERROR_IPC_FAILED, 174 WM_ERROR_NEED_REPORT_END, 175 WM_ERROR_START_ABILITY_FAILED, 176 WM_ERROR_PIP_DESTROY_FAILED, 177 WM_ERROR_PIP_STATE_ABNORMALLY, 178 WM_ERROR_PIP_CREATE_FAILED, 179 WM_ERROR_PIP_INTERNAL_ERROR, 180 WM_ERROR_PIP_REPEAT_OPERATION, 181 }; 182 183 /** 184 * @brief Enumerates error code of window only used for js api. 185 */ 186 enum class WmErrorCode : int32_t { 187 WM_OK = 0, 188 WM_ERROR_NO_PERMISSION = 201, 189 WM_ERROR_NOT_SYSTEM_APP = 202, 190 WM_ERROR_INVALID_PARAM = 401, 191 WM_ERROR_DEVICE_NOT_SUPPORT = 801, 192 WM_ERROR_REPEAT_OPERATION = 1300001, 193 WM_ERROR_STATE_ABNORMALLY = 1300002, 194 WM_ERROR_SYSTEM_ABNORMALLY = 1300003, 195 WM_ERROR_INVALID_CALLING = 1300004, 196 WM_ERROR_STAGE_ABNORMALLY = 1300005, 197 WM_ERROR_CONTEXT_ABNORMALLY = 1300006, 198 WM_ERROR_START_ABILITY_FAILED = 1300007, 199 WM_ERROR_INVALID_DISPLAY = 1300008, 200 WM_ERROR_INVALID_PARENT = 1300009, 201 WM_ERROR_OPER_FULLSCREEN_FAILED = 1300010, 202 WM_ERROR_PIP_DESTROY_FAILED = 1300011, 203 WM_ERROR_PIP_STATE_ABNORMALLY = 1300012, 204 WM_ERROR_PIP_CREATE_FAILED = 1300013, 205 WM_ERROR_PIP_INTERNAL_ERROR = 1300014, 206 WM_ERROR_PIP_REPEAT_OPERATION = 1300015, 207 }; 208 209 /** 210 * @brief Enumerates status of window. 211 */ 212 enum class WindowStatus : uint32_t { 213 WINDOW_STATUS_UNDEFINED = 0, 214 WINDOW_STATUS_FULLSCREEN = 1, 215 WINDOW_STATUS_MAXMIZE, 216 WINDOW_STATUS_MINIMIZE, 217 WINDOW_STATUS_FLOATING, 218 WINDOW_STATUS_SPLITSCREEN 219 }; 220 221 222 /** 223 * @brief Used to map from WMError to WmErrorCode. 224 */ 225 const std::map<WMError, WmErrorCode> WM_JS_TO_ERROR_CODE_MAP { 226 {WMError::WM_OK, WmErrorCode::WM_OK }, 227 {WMError::WM_DO_NOTHING, WmErrorCode::WM_ERROR_STATE_ABNORMALLY }, 228 {WMError::WM_ERROR_DESTROYED_OBJECT, WmErrorCode::WM_ERROR_STATE_ABNORMALLY }, 229 {WMError::WM_ERROR_DEVICE_NOT_SUPPORT, WmErrorCode::WM_ERROR_DEVICE_NOT_SUPPORT }, 230 {WMError::WM_ERROR_INVALID_OPERATION, WmErrorCode::WM_ERROR_STATE_ABNORMALLY }, 231 {WMError::WM_ERROR_INVALID_PARAM, WmErrorCode::WM_ERROR_INVALID_PARAM }, 232 {WMError::WM_ERROR_INVALID_PERMISSION, WmErrorCode::WM_ERROR_NO_PERMISSION }, 233 {WMError::WM_ERROR_NOT_SYSTEM_APP, WmErrorCode::WM_ERROR_NOT_SYSTEM_APP }, 234 {WMError::WM_ERROR_INVALID_TYPE, WmErrorCode::WM_ERROR_STATE_ABNORMALLY }, 235 {WMError::WM_ERROR_INVALID_WINDOW, WmErrorCode::WM_ERROR_STATE_ABNORMALLY }, 236 {WMError::WM_ERROR_INVALID_WINDOW_MODE_OR_SIZE, WmErrorCode::WM_ERROR_STATE_ABNORMALLY }, 237 {WMError::WM_ERROR_IPC_FAILED, WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY }, 238 {WMError::WM_ERROR_NO_MEM, WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY }, 239 {WMError::WM_ERROR_NO_REMOTE_ANIMATION, WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY }, 240 {WMError::WM_ERROR_INVALID_DISPLAY, WmErrorCode::WM_ERROR_INVALID_DISPLAY }, 241 {WMError::WM_ERROR_INVALID_PARENT, WmErrorCode::WM_ERROR_INVALID_PARENT }, 242 {WMError::WM_ERROR_OPER_FULLSCREEN_FAILED, WmErrorCode::WM_ERROR_OPER_FULLSCREEN_FAILED }, 243 {WMError::WM_ERROR_REPEAT_OPERATION, WmErrorCode::WM_ERROR_REPEAT_OPERATION }, 244 {WMError::WM_ERROR_NULLPTR, WmErrorCode::WM_ERROR_STATE_ABNORMALLY }, 245 {WMError::WM_ERROR_SAMGR, WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY }, 246 {WMError::WM_ERROR_START_ABILITY_FAILED, WmErrorCode::WM_ERROR_START_ABILITY_FAILED }, 247 {WMError::WM_ERROR_PIP_DESTROY_FAILED, WmErrorCode::WM_ERROR_PIP_DESTROY_FAILED }, 248 {WMError::WM_ERROR_PIP_STATE_ABNORMALLY, WmErrorCode::WM_ERROR_PIP_STATE_ABNORMALLY }, 249 {WMError::WM_ERROR_PIP_CREATE_FAILED, WmErrorCode::WM_ERROR_PIP_CREATE_FAILED }, 250 {WMError::WM_ERROR_PIP_INTERNAL_ERROR, WmErrorCode::WM_ERROR_PIP_INTERNAL_ERROR }, 251 {WMError::WM_ERROR_PIP_REPEAT_OPERATION, WmErrorCode::WM_ERROR_PIP_REPEAT_OPERATION }, 252 {WMError::WM_ERROR_INVALID_CALLING, WmErrorCode::WM_ERROR_INVALID_CALLING }, 253 {WMError::WM_ERROR_INVALID_SESSION, WmErrorCode::WM_ERROR_STATE_ABNORMALLY }, 254 }; 255 256 /** 257 * @brief Enumerates flag of window. 258 */ 259 enum class WindowFlag : uint32_t { 260 WINDOW_FLAG_NEED_AVOID = 1, 261 WINDOW_FLAG_PARENT_LIMIT = 1 << 1, 262 WINDOW_FLAG_SHOW_WHEN_LOCKED = 1 << 2, 263 WINDOW_FLAG_FORBID_SPLIT_MOVE = 1 << 3, 264 WINDOW_FLAG_WATER_MARK = 1 << 4, 265 WINDOW_FLAG_END = 1 << 5, 266 }; 267 268 /** 269 * @brief Enumerates window size change reason. 270 */ 271 enum class WindowSizeChangeReason : uint32_t { 272 UNDEFINED = 0, 273 MAXIMIZE, 274 RECOVER, 275 ROTATION, 276 DRAG, 277 DRAG_START, 278 DRAG_END, 279 RESIZE, 280 MOVE, 281 HIDE, 282 TRANSFORM, 283 CUSTOM_ANIMATION_SHOW, 284 FULL_TO_SPLIT, 285 SPLIT_TO_FULL, 286 FULL_TO_FLOATING, 287 FLOATING_TO_FULL, 288 END, 289 }; 290 291 /** 292 * @brief Enumerates layout mode of window. 293 */ 294 enum class WindowLayoutMode : uint32_t { 295 BASE = 0, 296 CASCADE = BASE, 297 TILE = 1, 298 END, 299 }; 300 301 /** 302 * @brief Enumerates drag event. 303 */ 304 enum class DragEvent : uint32_t { 305 DRAG_EVENT_IN = 1, 306 DRAG_EVENT_OUT, 307 DRAG_EVENT_MOVE, 308 DRAG_EVENT_END, 309 }; 310 311 /** 312 * @brief Enumerates window tag. 313 */ 314 enum class WindowTag : uint32_t { 315 MAIN_WINDOW = 0, 316 SUB_WINDOW = 1, 317 SYSTEM_WINDOW = 2, 318 }; 319 320 /** 321 * @brief Enumerates window session type. 322 */ 323 enum class WindowSessionType : uint32_t { 324 SCENE_SESSION = 0, 325 EXTENSION_SESSION = 1, 326 }; 327 328 /** 329 * @brief Enumerates window gravity. 330 */ 331 enum class WindowGravity : uint32_t { 332 WINDOW_GRAVITY_FLOAT = 0, 333 WINDOW_GRAVITY_BOTTOM, 334 }; 335 336 /** 337 * @brief Enumerates window setuicontent type. 338 */ 339 enum class WindowSetUIContentType: uint32_t { 340 DEFAULT, 341 DISTRIBUTE, 342 BY_NAME, 343 BY_ABC, 344 }; 345 346 /** 347 * @struct PointInfo. 348 * 349 * @brief point Info. 350 */ 351 struct PointInfo { 352 int32_t x; 353 int32_t y; 354 }; 355 356 namespace { 357 constexpr uint32_t SYSTEM_COLOR_WHITE = 0xE5FFFFFF; 358 constexpr uint32_t SYSTEM_COLOR_BLACK = 0x66000000; 359 constexpr uint32_t INVALID_WINDOW_ID = 0; 360 constexpr float UNDEFINED_BRIGHTNESS = -1.0f; 361 constexpr float MINIMUM_BRIGHTNESS = 0.0f; 362 constexpr float MAXIMUM_BRIGHTNESS = 1.0f; 363 constexpr int32_t INVALID_PID = -1; 364 constexpr int32_t INVALID_UID = -1; 365 } 366 367 /** 368 * @class Transform 369 * 370 * @brief parameter of transform and rotate. 371 */ 372 class Transform { 373 public: Transform()374 Transform() 375 : pivotX_(0.5f), pivotY_(0.5f), scaleX_(1.f), scaleY_(1.f), scaleZ_(1.f), rotationX_(0.f), 376 rotationY_(0.f), rotationZ_(0.f), translateX_(0.f), translateY_(0.f), translateZ_(0.f) 377 {} ~Transform()378 ~Transform() {} 379 380 bool operator==(const Transform& right) const 381 { 382 return NearZero(pivotX_ - right.pivotX_) && 383 NearZero(pivotY_ - right.pivotY_) && 384 NearZero(scaleX_ - right.scaleX_) && 385 NearZero(scaleY_ - right.scaleY_) && 386 NearZero(scaleZ_ - right.scaleZ_) && 387 NearZero(rotationX_ - right.rotationX_) && 388 NearZero(rotationY_ - right.rotationY_) && 389 NearZero(rotationZ_ - right.rotationZ_) && 390 NearZero(translateX_ - right.translateX_) && 391 NearZero(translateY_ - right.translateY_) && 392 NearZero(translateZ_ - right.translateZ_); 393 } 394 395 bool operator!=(const Transform& right) const 396 { 397 return !(*this == right); 398 } 399 400 float pivotX_; 401 float pivotY_; 402 float scaleX_; 403 float scaleY_; 404 float scaleZ_; 405 float rotationX_; 406 float rotationY_; 407 float rotationZ_; 408 float translateX_; 409 float translateY_; 410 float translateZ_; 411 Identity()412 static const Transform& Identity() 413 { 414 static Transform I; 415 return I; 416 } 417 Marshalling(Parcel & parcel)418 bool Marshalling(Parcel& parcel) const 419 { 420 return parcel.WriteFloat(pivotX_) && parcel.WriteFloat(pivotY_) && 421 parcel.WriteFloat(scaleX_) && parcel.WriteFloat(scaleY_) && parcel.WriteFloat(scaleZ_) && 422 parcel.WriteFloat(rotationX_) && parcel.WriteFloat(rotationY_) && parcel.WriteFloat(rotationZ_) && 423 parcel.WriteFloat(translateX_) && parcel.WriteFloat(translateY_) && parcel.WriteFloat(translateZ_); 424 } 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 private: NearZero(float val)441 static inline bool NearZero(float val) 442 { 443 return val < 0.001f && val > -0.001f; 444 } 445 }; 446 447 /** 448 * @struct SystemBarProperty 449 * 450 * @brief Property of system bar 451 */ 452 struct SystemBarProperty { 453 bool enable_; 454 uint32_t backgroundColor_; 455 uint32_t contentColor_; SystemBarPropertySystemBarProperty456 SystemBarProperty() : enable_(true), backgroundColor_(SYSTEM_COLOR_BLACK), contentColor_(SYSTEM_COLOR_WHITE) {} SystemBarPropertySystemBarProperty457 SystemBarProperty(bool enable, uint32_t background, uint32_t content) 458 : enable_(enable), backgroundColor_(background), contentColor_(content) {} 459 bool operator == (const SystemBarProperty& a) const 460 { 461 return (enable_ == a.enable_ && backgroundColor_ == a.backgroundColor_ && contentColor_ == a.contentColor_); 462 } 463 }; 464 465 /** 466 * @struct Rect 467 * 468 * @brief Window Rect 469 */ 470 struct Rect { 471 int32_t posX_; 472 int32_t posY_; 473 uint32_t width_; 474 uint32_t height_; 475 476 bool operator==(const Rect& a) const 477 { 478 return (posX_ == a.posX_ && posY_ == a.posY_ && width_ == a.width_ && height_ == a.height_); 479 } 480 481 bool operator!=(const Rect& a) const 482 { 483 return !this->operator==(a); 484 } 485 IsUninitializedRectRect486 bool IsUninitializedRect() const 487 { 488 return (posX_ == 0 && posY_ == 0 && width_ == 0 && height_ == 0); 489 } 490 IsInsideOfRect491 bool IsInsideOf(const Rect& a) const 492 { 493 return (posX_ >= a.posX_ && posY_ >= a.posY_ && 494 posX_ + width_ <= a.posX_ + a.width_ && posY_ + height_ <= a.posY_ + a.height_); 495 } 496 }; 497 498 /** 499 * @brief Enumerates avoid area type. 500 */ 501 enum class AvoidAreaType : uint32_t { 502 TYPE_SYSTEM, // area of SystemUI 503 TYPE_CUTOUT, // cutout of screen 504 TYPE_SYSTEM_GESTURE, // area for system gesture 505 TYPE_KEYBOARD, // area for soft input keyboard 506 TYPE_NAVIGATION_INDICATOR, // area for navigation indicator 507 }; 508 509 /** 510 * @brief Enumerates occupied area type. 511 */ 512 enum class OccupiedAreaType : uint32_t { 513 TYPE_INPUT, // area of input window 514 }; 515 516 /** 517 * @brief Enumerates color space. 518 */ 519 enum class ColorSpace : uint32_t { 520 COLOR_SPACE_DEFAULT = 0, // Default color space. 521 COLOR_SPACE_WIDE_GAMUT, // Wide gamut color space. The specific wide color gamut depends on the screen. 522 }; 523 524 /** 525 * @brief Enumerates window animation. 526 */ 527 enum class WindowAnimation : uint32_t { 528 NONE, 529 DEFAULT, 530 INPUTE, 531 CUSTOM, 532 }; 533 534 /** 535 * @brief Enumerates window maximize mode. 536 */ 537 enum class MaximizeMode : uint32_t { 538 MODE_AVOID_SYSTEM_BAR, 539 MODE_FULL_FILL, 540 MODE_RECOVER, 541 }; 542 543 /** 544 * @class AvoidArea 545 * 546 * @brief Area needed to avoid. 547 */ 548 class AvoidArea : public Parcelable { 549 public: 550 Rect topRect_ { 0, 0, 0, 0 }; 551 Rect leftRect_ { 0, 0, 0, 0 }; 552 Rect rightRect_ { 0, 0, 0, 0 }; 553 Rect bottomRect_ { 0, 0, 0, 0 }; 554 555 bool operator==(const AvoidArea& a) const 556 { 557 return (leftRect_ == a.leftRect_ && topRect_ == a.topRect_ && 558 rightRect_ == a.rightRect_ && bottomRect_ == a.bottomRect_); 559 } 560 561 bool operator!=(const AvoidArea& a) const 562 { 563 return !this->operator==(a); 564 } 565 isEmptyAvoidArea()566 bool isEmptyAvoidArea() const 567 { 568 return topRect_.IsUninitializedRect() && leftRect_.IsUninitializedRect() && 569 rightRect_.IsUninitializedRect() && bottomRect_.IsUninitializedRect(); 570 } 571 WriteParcel(Parcel & parcel,const Rect & rect)572 static inline bool WriteParcel(Parcel& parcel, const Rect& rect) 573 { 574 return parcel.WriteInt32(rect.posX_) && parcel.WriteInt32(rect.posY_) && 575 parcel.WriteUint32(rect.width_) && parcel.WriteUint32(rect.height_); 576 } 577 ReadParcel(Parcel & parcel,Rect & rect)578 static inline bool ReadParcel(Parcel& parcel, Rect& rect) 579 { 580 return parcel.ReadInt32(rect.posX_) && parcel.ReadInt32(rect.posY_) && 581 parcel.ReadUint32(rect.width_) && parcel.ReadUint32(rect.height_); 582 } 583 Marshalling(Parcel & parcel)584 virtual bool Marshalling(Parcel& parcel) const override 585 { 586 return (WriteParcel(parcel, leftRect_) && WriteParcel(parcel, topRect_) && 587 WriteParcel(parcel, rightRect_) && WriteParcel(parcel, bottomRect_)); 588 } 589 Unmarshalling(Parcel & parcel)590 static AvoidArea* Unmarshalling(Parcel& parcel) 591 { 592 AvoidArea *avoidArea = new(std::nothrow) AvoidArea(); 593 if (avoidArea == nullptr) { 594 return nullptr; 595 } 596 if (ReadParcel(parcel, avoidArea->leftRect_) && ReadParcel(parcel, avoidArea->topRect_) && 597 ReadParcel(parcel, avoidArea->rightRect_) && ReadParcel(parcel, avoidArea->bottomRect_)) { 598 return avoidArea; 599 } 600 delete avoidArea; 601 return nullptr; 602 } 603 }; 604 605 /** 606 * @brief Enumerates window update type. 607 */ 608 enum class WindowUpdateType : int32_t { 609 WINDOW_UPDATE_ADDED = 1, 610 WINDOW_UPDATE_REMOVED, 611 WINDOW_UPDATE_FOCUSED, 612 WINDOW_UPDATE_BOUNDS, 613 WINDOW_UPDATE_ACTIVE, 614 WINDOW_UPDATE_PROPERTY, 615 }; 616 617 /** 618 * @brief Enumerates picture in picture window state. 619 */ 620 enum class PipWindowState : uint32_t { 621 STATE_UNDEFINED = 0, 622 STATE_STARTING = 1, 623 STATE_STARTED = 2, 624 STATE_STOPPING = 3, 625 STATE_STOPPED = 4, 626 }; 627 628 /** 629 * @brief Enumerates picture in picture template type. 630 */ 631 enum class PipTemplateType : uint32_t { 632 VIDEO_PLAY = 0, 633 VIDEO_CALL = 1, 634 VIDEO_MEETING = 2, 635 VIDEO_LIVE = 3, 636 }; 637 638 /** 639 * @brief Enumerates picture in picture state. 640 */ 641 enum class PipState : int32_t { 642 ABOUT_TO_START = 1, 643 STARTED = 2, 644 ABOUT_TO_STOP = 3, 645 STOPPED = 4, 646 ABOUT_TO_RESTORE = 5, 647 ERROR = 6, 648 }; 649 650 /** 651 * @brief Enumerates pip window rect update reason. 652 */ 653 enum class PiPRectUpdateReason : int32_t { 654 REASON_PIP_START_WINDOW, 655 REASON_PIP_MOVE, 656 REASON_PIP_VIDEO_RATIO_CHANGE, 657 REASON_PIP_SCALE_CHANGE, 658 REASON_PIP_DESTROY_WINDOW, 659 REASON_DISPLAY_ROTATION_CHANGE, 660 }; 661 662 /** 663 * @brief Enumerates picture in picture scale level. 664 */ 665 enum class PiPScaleLevel : int32_t { 666 PIP_SCALE_LEVEL_SMALLEST = 0, 667 PIP_SCALE_LEVEL_BIGGEST = 1, 668 COUNT = 2, 669 }; 670 671 /** 672 * @brief Enumerates picture in picture scale pivot. 673 */ 674 enum class PiPScalePivot : int32_t { 675 UNDEFINED = 0, 676 START, 677 MIDDLE, 678 END, 679 }; 680 681 /** 682 * @brief Structure of picture in picture rect info. 683 */ 684 struct PiPRectInfo { 685 PiPScalePivot xPivot_; 686 PiPScalePivot yPivot_; 687 uint32_t originWidth_; 688 uint32_t originHeight_; 689 PiPScaleLevel level_; 690 }; 691 692 using OnCallback = std::function<void(int64_t)>; 693 694 /** 695 * @struct VsyncCallback 696 * 697 * @brief Vsync callback 698 */ 699 struct VsyncCallback { 700 OnCallback onCallback; 701 }; 702 703 struct WindowLimits { 704 uint32_t maxWidth_; 705 uint32_t maxHeight_; 706 uint32_t minWidth_; 707 uint32_t minHeight_; 708 float maxRatio_; 709 float minRatio_; WindowLimitsWindowLimits710 WindowLimits() : maxWidth_(UINT32_MAX), maxHeight_(UINT32_MAX), minWidth_(0), minHeight_(0), maxRatio_(FLT_MAX), 711 minRatio_(0.0f) {} WindowLimitsWindowLimits712 WindowLimits(uint32_t maxWidth, uint32_t maxHeight, uint32_t minWidth, uint32_t minHeight, float maxRatio, 713 float minRatio) : maxWidth_(maxWidth), maxHeight_(maxHeight), minWidth_(minWidth), minHeight_(minHeight), 714 maxRatio_(maxRatio), minRatio_(minRatio) {} 715 IsEmptyWindowLimits716 bool IsEmpty() const 717 { 718 return (maxWidth_ == 0 || minWidth_ == 0 || maxHeight_ == 0 || minHeight_ == 0); 719 } 720 }; 721 722 /** 723 * @struct TitleButtonRect 724 * 725 * @brief An area of title buttons relative to the upper right corner of the window. 726 */ 727 struct TitleButtonRect { 728 int32_t posX_; 729 int32_t posY_; 730 uint32_t width_; 731 uint32_t height_; 732 733 bool operator==(const TitleButtonRect& a) const 734 { 735 return (posX_ == a.posX_ && posY_ == a.posY_ && width_ == a.width_ && height_ == a.height_); 736 } 737 738 bool operator!=(const TitleButtonRect& a) const 739 { 740 return !this->operator==(a); 741 } 742 IsUninitializedRectTitleButtonRect743 bool IsUninitializedRect() const 744 { 745 return (posX_ == 0 && posY_ == 0 && width_ == 0 && height_ == 0); 746 } 747 IsInsideOfTitleButtonRect748 bool IsInsideOf(const TitleButtonRect& a) const 749 { 750 return (posX_ >= a.posX_ && posY_ >= a.posY_ && 751 posX_ + width_ <= a.posX_ + a.width_ && posY_ + height_ <= a.posY_ + a.height_); 752 } 753 }; 754 755 /* 756 * Config of keyboard animation 757 */ 758 class KeyboardAnimationConfig : public Parcelable { 759 public: 760 std::string curveType_ = ""; 761 std::vector<float> curveParams_ = {}; 762 uint32_t durationIn_ = 0; 763 uint32_t durationOut_ = 0; 764 Marshalling(Parcel & parcel)765 virtual bool Marshalling(Parcel& parcel) const override 766 { 767 if (!parcel.WriteString(curveType_)) { 768 return false; 769 } 770 771 auto paramSize = curveParams_.size(); 772 if (paramSize == 4) { // 4: param size 773 if (!parcel.WriteUint32(static_cast<uint32_t>(paramSize))) { 774 return false; 775 } 776 for (auto& param : curveParams_) { 777 if (!parcel.WriteFloat(param)) { 778 return false; 779 } 780 } 781 } else { 782 if (!parcel.WriteUint32(0)) { 783 return false; 784 } 785 } 786 787 if (!parcel.WriteUint32(durationIn_) || !parcel.WriteUint32(durationOut_)) { 788 return false; 789 } 790 return true; 791 } 792 Unmarshalling(Parcel & parcel)793 static KeyboardAnimationConfig* Unmarshalling(Parcel& parcel) 794 { 795 KeyboardAnimationConfig* config = new KeyboardAnimationConfig; 796 config->curveType_ = parcel.ReadString(); 797 auto paramSize = parcel.ReadUint32(); 798 if (paramSize == 4) { // 4: param size 799 for (uint32_t i = 0; i < paramSize; i++) { 800 config->curveParams_.push_back(parcel.ReadFloat()); 801 } 802 } 803 config->durationIn_ = parcel.ReadUint32(); 804 config->durationOut_ = parcel.ReadUint32(); 805 return config; 806 } 807 }; 808 } 809 } 810 #endif // OHOS_ROSEN_WM_COMMON_H 811