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 22 namespace OHOS { 23 namespace Rosen { 24 using DisplayId = uint64_t; 25 /** 26 * @brief Enumerates type of window. 27 */ 28 enum class WindowType : uint32_t { 29 APP_WINDOW_BASE = 1, 30 APP_MAIN_WINDOW_BASE = APP_WINDOW_BASE, 31 WINDOW_TYPE_APP_MAIN_WINDOW = APP_MAIN_WINDOW_BASE, 32 APP_MAIN_WINDOW_END, 33 34 APP_SUB_WINDOW_BASE = 1000, 35 WINDOW_TYPE_MEDIA = APP_SUB_WINDOW_BASE, 36 WINDOW_TYPE_APP_SUB_WINDOW, 37 WINDOW_TYPE_APP_COMPONENT, 38 APP_SUB_WINDOW_END, 39 APP_WINDOW_END = APP_SUB_WINDOW_END, 40 41 SYSTEM_WINDOW_BASE = 2000, 42 BELOW_APP_SYSTEM_WINDOW_BASE = SYSTEM_WINDOW_BASE, 43 WINDOW_TYPE_WALLPAPER = SYSTEM_WINDOW_BASE, 44 WINDOW_TYPE_DESKTOP, 45 BELOW_APP_SYSTEM_WINDOW_END, 46 47 ABOVE_APP_SYSTEM_WINDOW_BASE = 2100, 48 WINDOW_TYPE_APP_LAUNCHING = ABOVE_APP_SYSTEM_WINDOW_BASE, 49 WINDOW_TYPE_DOCK_SLICE, 50 WINDOW_TYPE_INCOMING_CALL, 51 WINDOW_TYPE_SEARCHING_BAR, 52 WINDOW_TYPE_SYSTEM_ALARM_WINDOW, 53 WINDOW_TYPE_INPUT_METHOD_FLOAT, 54 WINDOW_TYPE_FLOAT, 55 WINDOW_TYPE_TOAST, 56 WINDOW_TYPE_STATUS_BAR, 57 WINDOW_TYPE_PANEL, 58 WINDOW_TYPE_KEYGUARD, 59 WINDOW_TYPE_VOLUME_OVERLAY, 60 WINDOW_TYPE_NAVIGATION_BAR, 61 WINDOW_TYPE_DRAGGING_EFFECT, 62 WINDOW_TYPE_POINTER, 63 WINDOW_TYPE_LAUNCHER_RECENT, 64 WINDOW_TYPE_LAUNCHER_DOCK, 65 WINDOW_TYPE_BOOT_ANIMATION, 66 WINDOW_TYPE_FREEZE_DISPLAY, 67 WINDOW_TYPE_VOICE_INTERACTION, 68 WINDOW_TYPE_FLOAT_CAMERA, 69 WINDOW_TYPE_PLACEHOLDER, 70 WINDOW_TYPE_DIALOG, 71 WINDOW_TYPE_SCREENSHOT, 72 WINDOW_TYPE_INPUT_METHOD_STATUS_BAR, 73 ABOVE_APP_SYSTEM_WINDOW_END, 74 75 SYSTEM_SUB_WINDOW_BASE = 2500, 76 WINDOW_TYPE_SYSTEM_SUB_WINDOW = SYSTEM_SUB_WINDOW_BASE, 77 SYSTEM_SUB_WINDOW_END, 78 79 SYSTEM_WINDOW_END = SYSTEM_SUB_WINDOW_END, 80 81 WINDOW_TYPE_UI_EXTENSION = 3000, 82 WINDOW_TYPE_SCENE_BOARD 83 }; 84 85 /** 86 * @brief Enumerates mode of window. 87 */ 88 enum class WindowMode : uint32_t { 89 WINDOW_MODE_UNDEFINED = 0, 90 WINDOW_MODE_FULLSCREEN = 1, 91 WINDOW_MODE_SPLIT_PRIMARY = 100, 92 WINDOW_MODE_SPLIT_SECONDARY, 93 WINDOW_MODE_FLOATING, 94 WINDOW_MODE_PIP 95 }; 96 97 /** 98 * @brief Enumerates mode supported of window. 99 */ 100 enum WindowModeSupport : uint32_t { 101 WINDOW_MODE_SUPPORT_FULLSCREEN = 1 << 0, 102 WINDOW_MODE_SUPPORT_FLOATING = 1 << 1, 103 WINDOW_MODE_SUPPORT_SPLIT_PRIMARY = 1 << 2, 104 WINDOW_MODE_SUPPORT_SPLIT_SECONDARY = 1 << 3, 105 WINDOW_MODE_SUPPORT_PIP = 1 << 4, 106 WINDOW_MODE_SUPPORT_ALL = WINDOW_MODE_SUPPORT_FULLSCREEN | 107 WINDOW_MODE_SUPPORT_SPLIT_PRIMARY | 108 WINDOW_MODE_SUPPORT_SPLIT_SECONDARY | 109 WINDOW_MODE_SUPPORT_FLOATING | 110 WINDOW_MODE_SUPPORT_PIP 111 }; 112 113 /** 114 * @brief Enumerates blur style of window. 115 */ 116 enum class WindowBlurStyle : uint32_t { 117 WINDOW_BLUR_OFF = 0, 118 WINDOW_BLUR_THIN, 119 WINDOW_BLUR_REGULAR, 120 WINDOW_BLUR_THICK 121 }; 122 123 /** 124 * @brief Enumerates state of window. 125 */ 126 enum class WindowState : uint32_t { 127 STATE_INITIAL, 128 STATE_CREATED, 129 STATE_SHOWN, 130 STATE_HIDDEN, 131 STATE_FROZEN, 132 STATE_UNFROZEN, 133 STATE_DESTROYED, 134 STATE_BOTTOM = STATE_DESTROYED, // Add state type after STATE_DESTROYED is not allowed 135 }; 136 137 /** 138 * @brief Enumerates error code of window. 139 */ 140 enum class WMError : int32_t { 141 WM_OK = 0, 142 WM_DO_NOTHING, 143 WM_ERROR_NO_MEM, 144 WM_ERROR_DESTROYED_OBJECT, 145 WM_ERROR_INVALID_WINDOW, 146 WM_ERROR_INVALID_WINDOW_MODE_OR_SIZE, 147 WM_ERROR_INVALID_OPERATION, 148 WM_ERROR_INVALID_PERMISSION, 149 WM_ERROR_NOT_SYSTEM_APP, 150 WM_ERROR_NO_REMOTE_ANIMATION, 151 WM_ERROR_INVALID_DISPLAY, 152 WM_ERROR_INVALID_PARENT, 153 WM_ERROR_OPER_FULLSCREEN_FAILED, 154 WM_ERROR_REPEAT_OPERATION, 155 WM_ERROR_INVALID_SESSION, 156 157 WM_ERROR_DEVICE_NOT_SUPPORT = 801, // the value do not change.It is defined on all system 158 159 WM_ERROR_NEED_REPORT_BASE = 1000, // error code > 1000 means need report 160 WM_ERROR_NULLPTR, 161 WM_ERROR_INVALID_TYPE, 162 WM_ERROR_INVALID_PARAM, 163 WM_ERROR_SAMGR, 164 WM_ERROR_IPC_FAILED, 165 WM_ERROR_NEED_REPORT_END, 166 WM_ERROR_START_ABILITY_FAILED, 167 }; 168 169 /** 170 * @brief Enumerates error code of window only used for js api. 171 */ 172 enum class WmErrorCode : int32_t { 173 WM_OK = 0, 174 WM_ERROR_NO_PERMISSION = 201, 175 WM_ERROR_NOT_SYSTEM_APP = 202, 176 WM_ERROR_INVALID_PARAM = 401, 177 WM_ERROR_DEVICE_NOT_SUPPORT = 801, 178 WM_ERROR_REPEAT_OPERATION = 1300001, 179 WM_ERROR_STATE_ABNORMALLY = 1300002, 180 WM_ERROR_SYSTEM_ABNORMALLY = 1300003, 181 WM_ERROR_INVALID_CALLING = 1300004, 182 WM_ERROR_STAGE_ABNORMALLY = 1300005, 183 WM_ERROR_CONTEXT_ABNORMALLY = 1300006, 184 WM_ERROR_START_ABILITY_FAILED = 1300007, 185 WM_ERROR_INVALID_DISPLAY = 1300008, 186 WM_ERROR_INVALID_PARENT = 1300009, 187 WM_ERROR_OPER_FULLSCREEN_FAILED = 1300010, 188 }; 189 190 /** 191 * @brief Used to map from WMError to WmErrorCode. 192 */ 193 const std::map<WMError, WmErrorCode> WM_JS_TO_ERROR_CODE_MAP { 194 {WMError::WM_OK, WmErrorCode::WM_OK }, 195 {WMError::WM_DO_NOTHING, WmErrorCode::WM_ERROR_STATE_ABNORMALLY }, 196 {WMError::WM_ERROR_DESTROYED_OBJECT, WmErrorCode::WM_ERROR_STATE_ABNORMALLY }, 197 {WMError::WM_ERROR_DEVICE_NOT_SUPPORT, WmErrorCode::WM_ERROR_DEVICE_NOT_SUPPORT }, 198 {WMError::WM_ERROR_INVALID_OPERATION, WmErrorCode::WM_ERROR_STATE_ABNORMALLY }, 199 {WMError::WM_ERROR_INVALID_PARAM, WmErrorCode::WM_ERROR_INVALID_PARAM }, 200 {WMError::WM_ERROR_INVALID_PERMISSION, WmErrorCode::WM_ERROR_NO_PERMISSION }, 201 {WMError::WM_ERROR_NOT_SYSTEM_APP, WmErrorCode::WM_ERROR_NOT_SYSTEM_APP }, 202 {WMError::WM_ERROR_INVALID_TYPE, WmErrorCode::WM_ERROR_STATE_ABNORMALLY }, 203 {WMError::WM_ERROR_INVALID_WINDOW, WmErrorCode::WM_ERROR_STATE_ABNORMALLY }, 204 {WMError::WM_ERROR_INVALID_WINDOW_MODE_OR_SIZE, WmErrorCode::WM_ERROR_STATE_ABNORMALLY }, 205 {WMError::WM_ERROR_IPC_FAILED, WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY }, 206 {WMError::WM_ERROR_NO_MEM, WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY }, 207 {WMError::WM_ERROR_NO_REMOTE_ANIMATION, WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY }, 208 {WMError::WM_ERROR_INVALID_DISPLAY, WmErrorCode::WM_ERROR_INVALID_DISPLAY }, 209 {WMError::WM_ERROR_INVALID_PARENT, WmErrorCode::WM_ERROR_INVALID_PARENT }, 210 {WMError::WM_ERROR_OPER_FULLSCREEN_FAILED, WmErrorCode::WM_ERROR_OPER_FULLSCREEN_FAILED }, 211 {WMError::WM_ERROR_REPEAT_OPERATION, WmErrorCode::WM_ERROR_REPEAT_OPERATION }, 212 {WMError::WM_ERROR_NULLPTR, WmErrorCode::WM_ERROR_STATE_ABNORMALLY }, 213 {WMError::WM_ERROR_SAMGR, WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY }, 214 {WMError::WM_ERROR_START_ABILITY_FAILED, WmErrorCode::WM_ERROR_START_ABILITY_FAILED }, 215 }; 216 217 /** 218 * @brief Enumerates flag of window. 219 */ 220 enum class WindowFlag : uint32_t { 221 WINDOW_FLAG_NEED_AVOID = 1, 222 WINDOW_FLAG_PARENT_LIMIT = 1 << 1, 223 WINDOW_FLAG_SHOW_WHEN_LOCKED = 1 << 2, 224 WINDOW_FLAG_FORBID_SPLIT_MOVE = 1 << 3, 225 WINDOW_FLAG_WATER_MARK = 1 << 4, 226 WINDOW_FLAG_END = 1 << 5, 227 }; 228 229 /** 230 * @brief Enumerates window size change reason. 231 */ 232 enum class WindowSizeChangeReason : uint32_t { 233 UNDEFINED = 0, 234 MAXIMIZE, 235 RECOVER, 236 ROTATION, 237 DRAG, 238 DRAG_START, 239 DRAG_END, 240 RESIZE, 241 MOVE, 242 HIDE, 243 TRANSFORM, 244 CUSTOM_ANIMATION_SHOW, 245 FULL_TO_SPLIT, 246 SPLIT_TO_FULL, 247 END, 248 }; 249 250 /** 251 * @brief Enumerates layout mode of window. 252 */ 253 enum class WindowLayoutMode : uint32_t { 254 BASE = 0, 255 CASCADE = BASE, 256 TILE = 1, 257 END, 258 }; 259 260 /** 261 * @brief Enumerates drag event. 262 */ 263 enum class DragEvent : uint32_t { 264 DRAG_EVENT_IN = 1, 265 DRAG_EVENT_OUT, 266 DRAG_EVENT_MOVE, 267 DRAG_EVENT_END, 268 }; 269 270 /** 271 * @brief Enumerates window tag. 272 */ 273 enum class WindowTag : uint32_t { 274 MAIN_WINDOW = 0, 275 SUB_WINDOW = 1, 276 SYSTEM_WINDOW = 2, 277 }; 278 279 /** 280 * @brief Enumerates window session type. 281 */ 282 enum class WindowSessionType : uint32_t { 283 SCENE_SESSION = 0, 284 EXTENSION_SESSION = 1, 285 }; 286 287 /** 288 * @brief Enumerates window gravity. 289 */ 290 enum class WindowGravity : uint32_t { 291 WINDOW_GRAVITY_FLOAT = 0, 292 WINDOW_GRAVITY_BOTTOM, 293 }; 294 295 /** 296 * @struct PointInfo. 297 * 298 * @brief point Info. 299 */ 300 struct PointInfo { 301 int32_t x; 302 int32_t y; 303 }; 304 305 namespace { 306 constexpr uint32_t SYSTEM_COLOR_WHITE = 0xE5FFFFFF; 307 constexpr uint32_t SYSTEM_COLOR_BLACK = 0x66000000; 308 constexpr uint32_t INVALID_WINDOW_ID = 0; 309 constexpr float UNDEFINED_BRIGHTNESS = -1.0f; 310 constexpr float MINIMUM_BRIGHTNESS = 0.0f; 311 constexpr float MAXIMUM_BRIGHTNESS = 1.0f; 312 constexpr int32_t INVALID_PID = -1; 313 constexpr int32_t INVALID_UID = -1; 314 } 315 316 /** 317 * @class Transform 318 * 319 * @brief parameter of transform and rotate. 320 */ 321 class Transform { 322 public: Transform()323 Transform() 324 : pivotX_(0.5f), pivotY_(0.5f), scaleX_(1.f), scaleY_(1.f), scaleZ_(1.f), rotationX_(0.f), 325 rotationY_(0.f), rotationZ_(0.f), translateX_(0.f), translateY_(0.f), translateZ_(0.f) 326 {} ~Transform()327 ~Transform() {} 328 329 bool operator==(const Transform& right) const 330 { 331 return NearZero(pivotX_ - right.pivotX_) && 332 NearZero(pivotY_ - right.pivotY_) && 333 NearZero(scaleX_ - right.scaleX_) && 334 NearZero(scaleY_ - right.scaleY_) && 335 NearZero(scaleZ_ - right.scaleZ_) && 336 NearZero(rotationX_ - right.rotationX_) && 337 NearZero(rotationY_ - right.rotationY_) && 338 NearZero(rotationZ_ - right.rotationZ_) && 339 NearZero(translateX_ - right.translateX_) && 340 NearZero(translateY_ - right.translateY_) && 341 NearZero(translateZ_ - right.translateZ_); 342 } 343 344 bool operator!=(const Transform& right) const 345 { 346 return !(*this == right); 347 } 348 349 float pivotX_; 350 float pivotY_; 351 float scaleX_; 352 float scaleY_; 353 float scaleZ_; 354 float rotationX_; 355 float rotationY_; 356 float rotationZ_; 357 float translateX_; 358 float translateY_; 359 float translateZ_; 360 Identity()361 static const Transform& Identity() 362 { 363 static Transform I; 364 return I; 365 } 366 Marshalling(Parcel & parcel)367 bool Marshalling(Parcel& parcel) const 368 { 369 return parcel.WriteFloat(pivotX_) && parcel.WriteFloat(pivotY_) && 370 parcel.WriteFloat(scaleX_) && parcel.WriteFloat(scaleY_) && parcel.WriteFloat(scaleZ_) && 371 parcel.WriteFloat(rotationX_) && parcel.WriteFloat(rotationY_) && parcel.WriteFloat(rotationZ_) && 372 parcel.WriteFloat(translateX_) && parcel.WriteFloat(translateY_) && parcel.WriteFloat(translateZ_); 373 } 374 Unmarshalling(Parcel & parcel)375 void Unmarshalling(Parcel& parcel) 376 { 377 pivotX_ = parcel.ReadFloat(); 378 pivotY_ = parcel.ReadFloat(); 379 scaleX_ = parcel.ReadFloat(); 380 scaleY_ = parcel.ReadFloat(); 381 scaleZ_ = parcel.ReadFloat(); 382 rotationX_ = parcel.ReadFloat(); 383 rotationY_ = parcel.ReadFloat(); 384 rotationZ_ = parcel.ReadFloat(); 385 translateX_ = parcel.ReadFloat(); 386 translateY_ = parcel.ReadFloat(); 387 translateZ_ = parcel.ReadFloat(); 388 } 389 private: NearZero(float val)390 static inline bool NearZero(float val) 391 { 392 return val < 0.001f && val > -0.001f; 393 } 394 }; 395 396 /** 397 * @struct SystemBarProperty 398 * 399 * @brief Property of system bar 400 */ 401 struct SystemBarProperty { 402 bool enable_; 403 uint32_t backgroundColor_; 404 uint32_t contentColor_; SystemBarPropertySystemBarProperty405 SystemBarProperty() : enable_(true), backgroundColor_(SYSTEM_COLOR_BLACK), contentColor_(SYSTEM_COLOR_WHITE) {} SystemBarPropertySystemBarProperty406 SystemBarProperty(bool enable, uint32_t background, uint32_t content) 407 : enable_(enable), backgroundColor_(background), contentColor_(content) {} 408 bool operator == (const SystemBarProperty& a) const 409 { 410 return (enable_ == a.enable_ && backgroundColor_ == a.backgroundColor_ && contentColor_ == a.contentColor_); 411 } 412 }; 413 414 /** 415 * @struct Rect 416 * 417 * @brief Window Rect 418 */ 419 struct Rect { 420 int32_t posX_; 421 int32_t posY_; 422 uint32_t width_; 423 uint32_t height_; 424 425 bool operator==(const Rect& a) const 426 { 427 return (posX_ == a.posX_ && posY_ == a.posY_ && width_ == a.width_ && height_ == a.height_); 428 } 429 430 bool operator!=(const Rect& a) const 431 { 432 return !this->operator==(a); 433 } 434 IsUninitializedRectRect435 bool IsUninitializedRect() const 436 { 437 return (posX_ == 0 && posY_ == 0 && width_ == 0 && height_ == 0); 438 } 439 IsInsideOfRect440 bool IsInsideOf(const Rect& a) const 441 { 442 return (posX_ >= a.posX_ && posY_ >= a.posY_ && 443 posX_ + width_ <= a.posX_ + a.width_ && posY_ + height_ <= a.posY_ + a.height_); 444 } 445 }; 446 447 /** 448 * @brief Enumerates avoid area type. 449 */ 450 enum class AvoidAreaType : uint32_t { 451 TYPE_SYSTEM, // area of SystemUI 452 TYPE_CUTOUT, // cutout of screen 453 TYPE_SYSTEM_GESTURE, // area for system gesture 454 TYPE_KEYBOARD, // area for soft input keyboard 455 }; 456 457 /** 458 * @brief Enumerates occupied area type. 459 */ 460 enum class OccupiedAreaType : uint32_t { 461 TYPE_INPUT, // area of input window 462 }; 463 464 /** 465 * @brief Enumerates color space. 466 */ 467 enum class ColorSpace : uint32_t { 468 COLOR_SPACE_DEFAULT = 0, // Default color space. 469 COLOR_SPACE_WIDE_GAMUT, // Wide gamut color space. The specific wide color gamut depends on the screen. 470 }; 471 472 /** 473 * @brief Enumerates window animation. 474 */ 475 enum class WindowAnimation : uint32_t { 476 NONE, 477 DEFAULT, 478 INPUTE, 479 CUSTOM, 480 }; 481 482 /** 483 * @brief Enumerates window maximize mode. 484 */ 485 enum class MaximizeMode : uint32_t { 486 MODE_AVOID_SYSTEM_BAR, 487 MODE_FULL_FILL, 488 MODE_RECOVER, 489 }; 490 491 /** 492 * @class AvoidArea 493 * 494 * @brief Area needed to avoid. 495 */ 496 class AvoidArea : public Parcelable { 497 public: 498 Rect topRect_ { 0, 0, 0, 0 }; 499 Rect leftRect_ { 0, 0, 0, 0 }; 500 Rect rightRect_ { 0, 0, 0, 0 }; 501 Rect bottomRect_ { 0, 0, 0, 0 }; 502 503 bool operator==(const AvoidArea& a) const 504 { 505 return (leftRect_ == a.leftRect_ && topRect_ == a.topRect_ && 506 rightRect_ == a.rightRect_ && bottomRect_ == a.bottomRect_); 507 } 508 509 bool operator!=(const AvoidArea& a) const 510 { 511 return !this->operator==(a); 512 } 513 isEmptyAvoidArea()514 bool isEmptyAvoidArea() const 515 { 516 return topRect_.IsUninitializedRect() && leftRect_.IsUninitializedRect() && 517 rightRect_.IsUninitializedRect() && bottomRect_.IsUninitializedRect(); 518 } 519 WriteParcel(Parcel & parcel,const Rect & rect)520 static inline bool WriteParcel(Parcel& parcel, const Rect& rect) 521 { 522 return parcel.WriteInt32(rect.posX_) && parcel.WriteInt32(rect.posY_) && 523 parcel.WriteUint32(rect.width_) && parcel.WriteUint32(rect.height_); 524 } 525 ReadParcel(Parcel & parcel,Rect & rect)526 static inline bool ReadParcel(Parcel& parcel, Rect& rect) 527 { 528 return parcel.ReadInt32(rect.posX_) && parcel.ReadInt32(rect.posY_) && 529 parcel.ReadUint32(rect.width_) && parcel.ReadUint32(rect.height_); 530 } 531 Marshalling(Parcel & parcel)532 virtual bool Marshalling(Parcel& parcel) const override 533 { 534 return (WriteParcel(parcel, leftRect_) && WriteParcel(parcel, topRect_) && 535 WriteParcel(parcel, rightRect_) && WriteParcel(parcel, bottomRect_)); 536 } 537 Unmarshalling(Parcel & parcel)538 static AvoidArea* Unmarshalling(Parcel& parcel) 539 { 540 AvoidArea *avoidArea = new(std::nothrow) AvoidArea(); 541 if (avoidArea == nullptr) { 542 return nullptr; 543 } 544 if (ReadParcel(parcel, avoidArea->leftRect_) && ReadParcel(parcel, avoidArea->topRect_) && 545 ReadParcel(parcel, avoidArea->rightRect_) && ReadParcel(parcel, avoidArea->bottomRect_)) { 546 return avoidArea; 547 } 548 delete avoidArea; 549 return nullptr; 550 } 551 }; 552 553 /** 554 * @brief Enumerates window update type. 555 */ 556 enum class WindowUpdateType : int32_t { 557 WINDOW_UPDATE_ADDED = 1, 558 WINDOW_UPDATE_REMOVED, 559 WINDOW_UPDATE_FOCUSED, 560 WINDOW_UPDATE_BOUNDS, 561 WINDOW_UPDATE_ACTIVE, 562 WINDOW_UPDATE_PROPERTY, 563 }; 564 565 using OnCallback = std::function<void(int64_t)>; 566 567 /** 568 * @struct VsyncCallback 569 * 570 * @brief Vsync callback 571 */ 572 struct VsyncCallback { 573 OnCallback onCallback; 574 }; 575 576 /* 577 * Config of keyboard animation 578 */ 579 class KeyboardAnimationConfig : public Parcelable { 580 public: 581 std::string curveType_ = ""; 582 std::vector<float> curveParams_ = {}; 583 uint32_t durationIn_ = 0; 584 uint32_t durationOut_ = 0; 585 Marshalling(Parcel & parcel)586 virtual bool Marshalling(Parcel& parcel) const override 587 { 588 if (!parcel.WriteString(curveType_)) { 589 return false; 590 } 591 592 auto paramSize = curveParams_.size(); 593 if (paramSize == 4) { // 4: param size 594 if (!parcel.WriteUint32(static_cast<uint32_t>(paramSize))) { 595 return false; 596 } 597 for (auto& param : curveParams_) { 598 if (!parcel.WriteFloat(param)) { 599 return false; 600 } 601 } 602 } else { 603 if (!parcel.WriteUint32(0)) { 604 return false; 605 } 606 } 607 608 if (!parcel.WriteUint32(durationIn_) || !parcel.WriteUint32(durationOut_)) { 609 return false; 610 } 611 return true; 612 } 613 Unmarshalling(Parcel & parcel)614 static KeyboardAnimationConfig* Unmarshalling(Parcel& parcel) 615 { 616 KeyboardAnimationConfig* config = new KeyboardAnimationConfig; 617 config->curveType_ = parcel.ReadString(); 618 auto paramSize = parcel.ReadUint32(); 619 if (paramSize == 4) { // 4: param size 620 for (uint32_t i = 0; i < paramSize; i++) { 621 config->curveParams_.push_back(parcel.ReadFloat()); 622 } 623 } 624 config->durationIn_ = parcel.ReadUint32(); 625 config->durationOut_ = parcel.ReadUint32(); 626 return config; 627 } 628 }; 629 } 630 } 631 #endif // OHOS_ROSEN_WM_COMMON_H 632