1 /* 2 * Copyright (c) 2021-2022 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_WINDOW_OPTION_H 17 #define OHOS_ROSEN_WINDOW_OPTION_H 18 #include <refbase.h> 19 #include <string> 20 #include <unordered_map> 21 22 #include "dm_common.h" 23 #include "wm_common.h" 24 25 namespace OHOS { 26 namespace Rosen { 27 /** 28 * @class WindowOption 29 * WindowOption is used to create a window. 30 */ 31 class WindowOption : public RefBase { 32 public: 33 /** 34 * @brief Default construct of WindowOption. 35 */ 36 WindowOption(); 37 38 /** 39 * @brief Deconstruct of WindowOption. 40 */ 41 virtual ~WindowOption() = default; 42 43 /** 44 * @brief Set window rect. 45 * 46 * @param rect The rect of window to set window position and size. 47 */ 48 void SetWindowRect(const struct Rect& rect); 49 50 /** 51 * @brief Set window type. 52 * 53 * @param type The type of window. 54 */ 55 void SetWindowType(WindowType type); 56 57 /** 58 * @brief Set window mode. 59 * 60 * @param mode The mode of window. 61 */ 62 void SetWindowMode(WindowMode mode); 63 64 /** 65 * @brief Set window focusable. 66 * 67 * @param isFocusable True means the window can be focused, otherwise not. 68 */ 69 void SetFocusable(bool isFocusable); 70 71 /** 72 * @brief Set window touchable. 73 * 74 * @param isTouchable True means the window can be touched, otherwise not. 75 */ 76 void SetTouchable(bool isTouchable); 77 78 /** 79 * @brief Set display id. 80 * 81 * @param displayId The display id of window. 82 */ 83 void SetDisplayId(DisplayId displayId); 84 85 /** 86 * @brief Set parent id. 87 * 88 * @param parentId The parent window id. 89 */ 90 void SetParentId(uint32_t parentId); 91 92 /** 93 * @brief Set window name. 94 * 95 * @param windowName The window name. 96 */ 97 void SetWindowName(const std::string& windowName); 98 99 /** 100 * @brief Set bundle name. 101 * 102 * @param bundleName The bundle name. 103 */ 104 void SetBundleName(const std::string bundleName); 105 106 /** 107 * @brief Add window flag. 108 * 109 * @param flag The flag value added. 110 */ 111 void AddWindowFlag(WindowFlag flag); 112 113 /** 114 * @brief Remove winodw flag. 115 * 116 * @param flag The flag value removed. 117 */ 118 void RemoveWindowFlag(WindowFlag flag); 119 120 /** 121 * @brief Set window flags. 122 * 123 * @param flags The flag value. 124 */ 125 void SetWindowFlags(uint32_t flags); 126 127 /** 128 * @brief Set system bar property. 129 * 130 * @param type The system bar window type. 131 * @param property The system bar property. 132 */ 133 void SetSystemBarProperty(WindowType type, const SystemBarProperty& property); 134 135 /** 136 * @brief Set hit offset. 137 * 138 * @param x The position x of hit offset. 139 * @param y The position y of hit offset. 140 */ 141 void SetHitOffset(int32_t x, int32_t y); 142 143 /** 144 * @brief Set window tag. 145 * 146 * @param windowTag The tag of window. 147 */ 148 void SetWindowTag(WindowTag windowTag); 149 150 /** 151 * @brief Set window session type. 152 * 153 * @param sessionType The session type of window. 154 */ 155 void SetWindowSessionType(WindowSessionType sessionType); 156 157 /** 158 * @brief Set keep screen on. 159 * 160 * @param keepScreenOn The window keep screen on or not. 161 */ 162 void SetKeepScreenOn(bool keepScreenOn); 163 164 /** 165 * @brief Is keep screen on. 166 * 167 * @return Return true means the window would keep screen on, otherwise not. 168 */ 169 bool IsKeepScreenOn() const; 170 171 /** 172 * @brief Set view keep screen on. 173 * 174 * @param keepScreenOn The view keep screen on or not. 175 */ 176 void SetViewKeepScreenOn(bool keepScreenOn); 177 178 /** 179 * @brief Is view keep screen on. 180 * 181 * @return Return true means the view would keep screen on, otherwise not. 182 */ 183 bool IsViewKeepScreenOn() const; 184 185 /** 186 * @brief Set screen on. 187 * 188 * @param turnScreenOn mark the window to turn the screen on or not. 189 */ 190 void SetTurnScreenOn(bool turnScreenOn); 191 192 /** 193 * @brief Is turned screen on. 194 * 195 * @return The window is marked to turn the screen on or not. 196 */ 197 bool IsTurnScreenOn() const; 198 199 /** 200 * @brief Set window brightness. 201 * 202 * @param brightness The brightness of screen. the value is between 0.0 ~ 1.0. 203 */ 204 void SetBrightness(float brightness); 205 206 /** 207 * @brief Set window requested orientation. 208 * 209 * @param orientation The requested orientation of window. 210 */ 211 void SetRequestedOrientation(Orientation orientation); 212 213 /** 214 * @brief Set window calling window id. 215 * 216 * @param windowId The window id of calling window. 217 */ 218 void SetCallingWindow(uint32_t windowId); 219 220 /** 221 * @brief Set window main handler available. 222 * 223 * @param isMainHandlerAvailable is window main handler available. 224 */ 225 void SetMainHandlerAvailable(bool isMainHandlerAvailable); 226 227 /** 228 * @brief Set subwindow title. 229 * 230 * @param subWindowTitle the subwindow title. 231 */ 232 void SetSubWindowTitle(const std::string& subWindowTitle); 233 234 /** 235 * @brief Set is subwindow support maximize. 236 * 237 * @param maximizeSupported true means support default not support. 238 */ 239 void SetSubWindowMaximizeSupported(bool maximizeSupported); 240 241 /** 242 * @brief Set subwindow decor enable. 243 * 244 * @param subWindowDecorEnable the subwindow decor enable. 245 */ 246 void SetSubWindowDecorEnable(bool subWindowDecorEnable); 247 248 /** 249 * @brief Set only sceneboard supported. 250 * 251 * @param onlySupportSceneBoard only sceneboard supported. 252 */ 253 void SetOnlySupportSceneBoard(bool onlySupportSceneBoard); 254 255 /** 256 * @brief Set whether this window is the first level sub window of UIExtension. 257 * 258 * @param isUIExtFirstSubWindow whether is the first sub window of UIExtension. 259 */ 260 void SetIsUIExtFirstSubWindow(bool isUIExtFirstSubWindow); 261 262 /** 263 * @brief Set UIExtension usage. 264 * 265 * @param uiExtensionUsage UIExtension usage. 266 */ 267 void SetUIExtensionUsage(uint32_t uiExtensionUsage); 268 269 /** 270 * @brief Set Dialog Decor Enable Or Not. 271 * 272 * @param decorEnable true means enable, default disabled. 273 */ 274 void SetDialogDecorEnable(bool decorEnable); 275 276 /** 277 * @brief Set Dialog title. 278 * 279 * @param dialogTitle true means enable, default disabled. 280 */ 281 void SetDialogTitle(const std::string& dialogTitle); 282 283 /** 284 * @brief Set window topmost. 285 * 286 * @param isTopmost true means enable, default disabled. 287 */ 288 void SetWindowTopmost(bool isTopmost); 289 290 /** 291 * @brief Set sub window zLevel 292 * 293 * @param zLevel zLevel of sub window to specify the hierarchical relationship among sub windows 294 */ 295 void SetSubWindowZLevel(int32_t zLevel); 296 297 /** 298 * @brief Set zIndex of specific window. 299 * 300 * @param zIndex zIndex of specific window 301 */ 302 void SetZIndex(int32_t zIndex); 303 304 /** 305 * @brief Set sub window outline enabled 306 * 307 * @param outlineEnabled whether show sub window outline 308 */ 309 void SetSubWindowOutlineEnabled(bool outlineEnabled); 310 311 /** 312 * @brief Get sub window outline enabled 313 * 314 */ 315 bool IsSubWindowOutlineEnabled() const; 316 317 /** 318 * @brief Set real parent id of UIExtension 319 * 320 * @param realParentId real parent id of UIExtension 321 */ 322 void SetRealParentId(int32_t realParentId); 323 324 /** 325 * @brief Set parent window type of UIExtension 326 * 327 * @param parentWindowType Parent window type of UIExtension 328 */ 329 void SetParentWindowType(WindowType parentWindowType); 330 331 /** 332 * @brief Get window rect. 333 * 334 * @return The rect of window. 335 */ 336 Rect GetWindowRect() const; 337 338 /** 339 * @brief Get window type. 340 * 341 * @return The type of window. 342 */ 343 WindowType GetWindowType() const; 344 345 /** 346 * @brief Get window mode. 347 * 348 * @return The mode of window. 349 */ 350 WindowMode GetWindowMode() const; 351 352 /** 353 * @brief Get window focusable. 354 * 355 * @return Return true means the window is focusable, otherwise not. 356 */ 357 bool GetFocusable() const; 358 359 /** 360 * @brief Get window touchable. 361 * 362 * @return Return true means the window is touchable, otherwise not. 363 */ 364 bool GetTouchable() const; 365 366 /** 367 * @brief Get display id. 368 * 369 * @return Return diplay id. 370 */ 371 DisplayId GetDisplayId() const; 372 373 /** 374 * @brief Get parent id. 375 * 376 * @return Return parent window id. 377 */ 378 uint32_t GetParentId() const; 379 380 /** 381 * @brief Get window name. 382 * 383 * @return Return the window name. 384 */ 385 const std::string& GetWindowName() const; 386 387 /** 388 * @brief Get bundle name. 389 * 390 * @return Return the bundle name. 391 */ 392 const std::string GetBundleName() const; 393 394 /** 395 * @brief Get window flags. 396 * 397 * @return Return the window flags. 398 */ 399 uint32_t GetWindowFlags() const; 400 401 /** 402 * @brief Get system bar property. 403 * 404 * @return Return system bar property map. 405 */ 406 const std::unordered_map<WindowType, SystemBarProperty>& GetSystemBarProperty() const; 407 408 /** 409 * @brief Get window hit offset. 410 * 411 * @return Return hit offset value as PointInfo. 412 */ 413 const PointInfo& GetHitOffset() const; 414 415 /** 416 * @brief Get window tag. 417 * 418 * @return Return window tag. 419 */ 420 WindowTag GetWindowTag() const; 421 422 /** 423 * @brief Get window session type. 424 * 425 * @return Return window session type. 426 */ 427 WindowSessionType GetWindowSessionType() const; 428 429 /** 430 * @brief Get window brightness. 431 * 432 * @return Return screen brightness. 433 */ 434 float GetBrightness() const; 435 436 /** 437 * @brief Get window request orientation. 438 * 439 * @return Return window requested orientation. 440 */ 441 Orientation GetRequestedOrientation() const; 442 443 /** 444 * @brief Get calling window id. 445 * 446 * @return Return the calling window id of window. 447 */ 448 uint32_t GetCallingWindow() const; 449 450 /** 451 * @brief Get main handler available 452 * 453 * @return Return true means the main handler available, otherwise not. 454 */ 455 bool GetMainHandlerAvailable() const; 456 457 /** 458 * @brief Get subwindow title 459 * 460 * @return Return the subwindow title 461 */ 462 std::string GetSubWindowTitle() const; 463 464 /** 465 * @brief Get subwindow decor enable 466 * 467 * @return Return ture means the subwindow decor enabled, otherwise not. 468 */ 469 bool GetSubWindowDecorEnable() const; 470 471 /** 472 * @brief Get only sceneboard supported 473 * 474 * @return Return ture means only sceneboard supported, otherwise not. 475 */ 476 bool GetOnlySupportSceneBoard() const; 477 478 /** 479 * @brief Get whether this window is the first level sub window of UIExtension. 480 * 481 * @return true - is the first sub window of UIExtension, false - is not the first sub window of UIExtension 482 */ 483 bool GetIsUIExtFirstSubWindow() const; 484 485 /** 486 * @brief Get UIExtension usage. 487 * 488 * @param Return UIExtension usage. 489 */ 490 uint32_t GetUIExtensionUsage() const; 491 492 /** 493 * @brief Get dialog decor enable 494 * 495 * @return true means the dialog decor is enabled, otherwise not. 496 */ 497 bool GetDialogDecorEnable() const; 498 499 /** 500 * @brief Get dialog title 501 * 502 * @return Return the dialog title 503 */ 504 std::string GetDialogTitle() const; 505 506 /** 507 * @brief Get window topmost 508 * 509 * @return true means the window is topmost, otherwise not. 510 */ 511 bool GetWindowTopmost() const; 512 513 /** 514 * @brief Get sub window zLevel 515 * 516 * @return Return zLevel of sub window 517 */ 518 int32_t GetSubWindowZLevel() const; 519 520 /** 521 * @brief Get zIndex of specific window. 522 * 523 * @return Return zIndex of specific window 524 */ 525 int32_t GetZIndex() const; 526 527 /** 528 * @brief Get subwindow maximizeSupported 529 * 530 * @return true means subwindow support maximize, otherwise not. 531 */ 532 bool GetSubWindowMaximizeSupported() const; 533 534 /** 535 * @brief Get the real parent id of UIExtension 536 * 537 * @return Return the real parent id of UIExtension 538 */ 539 int32_t GetRealParentId() const; 540 541 /* 542 * @brief Get the parent window type of UIExtension 543 * 544 * @return Parent window type of UIExtension 545 */ 546 virtual WindowType GetParentWindowType() const; 547 548 /** 549 * @brief Set whether this window is a sub window of any level of UIExtension. 550 * 551 * @param isUIExtAnySubWindow true - is any sub window of UIExtension, 552 * false - is not any sub window of UIExtension. 553 */ 554 void SetIsUIExtAnySubWindow(bool isUIExtAnySubWindow); 555 556 /** 557 * @brief Get whether this window is a sub window of any level of UIExtension. 558 * 559 * @return true - is a sub window of any level of UIExtension, 560 * false - is not a sub window of any level of UIExtension. 561 */ 562 bool GetIsUIExtAnySubWindow() const; 563 564 /** 565 * @brief Set whether this window is a system keyboard 566 * 567 * @param isSystemKeyboard true means the window is a system keyboard. 568 */ 569 void SetIsSystemKeyboard(bool isSystemKeyboard); 570 571 /** 572 * @brief Check whether this window is a system keyboard. 573 * 574 * @return true - this window is a system keyboard, false - this window is not a system keyboard. 575 */ 576 bool IsSystemKeyboard() const; 577 578 /** 579 * @brief Set density of UIExtension. 580 * 581 * @param density Density of UIExtension. 582 */ 583 void SetDensity(float density); 584 585 /** 586 * @brief Get density of UIExtension. 587 * 588 * @return Density of UIExtension. 589 */ 590 float GetDensity() const; 591 592 /** 593 * @brief Set DPI follow-up mode of UIExtension. 594 * 595 * @param isDensityFollowHost DPI follow-up mode of UIExtension. 596 */ 597 void SetIsDensityFollowHost(bool isDensityFollowHost); 598 599 /** 600 * @brief Get DPI follow-up mode of UIExtension. 601 * 602 * @return true - DPI follows host, false - DPI follows UIExtensionAbility. 603 */ 604 bool GetIsDensityFollowHost() const; 605 606 /** 607 * @brief Set default density for subwindow or system window. 608 * 609 * @param defaultDensityEnabled Whether default density enabled. 610 */ 611 void SetDefaultDensityEnabled(bool defaultDensityEnabled); 612 613 /** 614 * @brief Check whether default density enabled. 615 * 616 * @return true - default density is enabled. 617 */ 618 bool IsDefaultDensityEnabled() const; 619 620 /** 621 * @brief Set whether this modal UIExt is a constrained modal UIExtension. 622 * 623 * @param isConstrainedModal true - is a constrained modal UIExtension, 624 * false - is not a constrained modal UIExtension, 625 */ 626 void SetConstrainedModal(bool isConstrainedModal); 627 628 /** 629 * @brief Get whether this modal UIExt is a constrained modal UIExtension. 630 * 631 * @return true - is a constrained modal UIExtension, 632 * false - is not a constrained modal UIExtension, 633 */ 634 bool IsConstrainedModal() const; 635 636 private: 637 Rect windowRect_ { 0, 0, 0, 0 }; 638 WindowType type_ { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW }; 639 WindowMode mode_ { WindowMode::WINDOW_MODE_UNDEFINED }; 640 bool focusable_ { true }; 641 bool touchable_ { true }; 642 DisplayId displayId_ { DISPLAY_ID_INVALID }; 643 uint32_t parentId_ = INVALID_WINDOW_ID; 644 std::string windowName_ { "" }; 645 std::string bundleName_ { "" }; 646 uint32_t flags_ { 0 }; 647 PointInfo hitOffset_ { 0, 0 }; 648 WindowTag windowTag_; 649 WindowSessionType sessionType_ { WindowSessionType::SCENE_SESSION }; 650 bool keepScreenOn_ = false; 651 bool viewKeepScreenOn_ = false; 652 bool turnScreenOn_ = false; 653 bool isMainHandlerAvailable_ = true; 654 float brightness_ = UNDEFINED_BRIGHTNESS; 655 uint32_t callingWindow_ = INVALID_WINDOW_ID; 656 std::unordered_map<WindowType, SystemBarProperty> sysBarPropMap_ { 657 { WindowType::WINDOW_TYPE_STATUS_BAR, SystemBarProperty() }, 658 { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SystemBarProperty() }, 659 }; 660 Orientation requestedOrientation_ { Orientation::UNSPECIFIED }; 661 std::string subWindowTitle_ = { "" }; 662 bool subWindowDecorEnable_ = false; 663 bool subWindowMaximizeSupported_ = false; 664 bool subWindowOutlineEnabled_ = false; 665 bool onlySupportSceneBoard_ = false; 666 bool dialogDecorEnable_ = false; 667 std::string dialogTitle_ = { "" }; 668 bool isTopmost_ = false; 669 int32_t zLevel_ = 0; 670 int32_t zIndex_ = SPECIFIC_ZINDEX_INVALID; 671 bool isSystemKeyboard_ = false; 672 bool defaultDensityEnabled_ = false; 673 674 /* 675 * UIExtension 676 */ 677 int32_t realParentId_ = INVALID_WINDOW_ID; 678 uint32_t uiExtensionUsage_ = static_cast<uint32_t>(UIExtensionUsage::EMBEDDED); 679 bool isUIExtFirstSubWindow_ = false; 680 bool isUIExtAnySubWindow_ = false; 681 WindowType parentWindowType_ = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW; 682 float density_ = 1.0f; 683 bool isDensityFollowHost_ = false; 684 bool isConstrainedModal_ = false; 685 }; 686 } // namespace Rosen 687 } // namespace OHOS 688 #endif // OHOS_ROSEN_WINDOW_OPTION_H 689