1/* 2* Copyright (c) 2021 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 16import { AsyncCallback, Callback } from './basic' ; 17import { Context } from './app/context'; 18/** 19 * Window manager. 20 * @syscap SystemCapability.WindowManager.WindowManager.Core 21 */ 22declare namespace window { 23 /** 24 * The type of a window. 25 * @syscap SystemCapability.WindowManager.WindowManager.Core 26 * @since 7 27 */ 28 enum WindowType { 29 /** 30 * App. 31 */ 32 TYPE_APP, 33 /** 34 * System alert. 35 */ 36 TYPE_SYSTEM_ALERT 37 } 38 39 /** 40 * Describes the type of avoid area 41 * @syscap SystemCapability.WindowManager.WindowManager.Core 42 * @since 7 43 */ 44 enum AvoidAreaType { 45 /** 46 * Default area of the system 47 */ 48 TYPE_SYSTEM, 49 50 /** 51 * Notch 52 */ 53 TYPE_CUTOUT 54 } 55 /** 56 * Describes the window mode of an application 57 * @systemapi Hide this for inner system use. 58 * @since 7 59 */ 60 enum WindowMode { 61 UNDEFINED = 1, 62 FULLSCREEN, 63 PRIMARY, 64 SECONDARY, 65 FLOATING 66 } 67 68 /** 69 * Properties of status bar and navigation bar, it couldn't update automatically 70 * @syscap SystemCapability.WindowManager.WindowManager.Core 71 * @since 6 72 */ 73 interface SystemBarProperties { 74 /** 75 * the color of the status bar. 76 * @since 6 77 */ 78 statusBarColor?: string; 79 80 /** 81 * the light icon of the status bar. 82 * @since 7 83 */ 84 isStatusBarLightIcon?: boolean; 85 86 /** 87 * the content color of the status bar 88 * @since 8 89 */ 90 statusBarContentColor?: string; 91 92 /** 93 * the color of the navigation bar. 94 * @since 6 95 */ 96 navigationBarColor?: string; 97 98 /** 99 * the light icon of the navigation bar. 100 * @since 7 101 */ 102 isNavigationBarLightIcon?: boolean; 103 104 /** 105 * the content color of the navigation bar 106 * @since 8 107 */ 108 navigationBarContentColor?: string; 109 } 110 111 /** 112 * system bar tint of region 113 * @syscap SystemCapability.WindowManager.WindowManager.Core 114 * @systemapi Hide this for inner system use. 115 * @since 8 116 */ 117 interface SystemBarRegionTint { 118 /** 119 * system bar type 120 */ 121 type: WindowType; 122 123 /** 124 * the visibility of system bar 125 */ 126 isEnable?: boolean; 127 128 /** 129 * the region of system bar 130 */ 131 region?: Rect; 132 133 /** 134 * the background color of the system bar. 135 */ 136 backgroundColor?: string; 137 138 /** 139 * the content color of the system bar. 140 */ 141 contentColor?: string 142 } 143 144 /** 145 * system bar tint state for systemui 146 * @syscap SystemCapability.WindowManager.WindowManager.Core 147 * @systemapi Hide this for inner system use. 148 * @since 8 149 */ 150 interface SystemBarTintState { 151 /** 152 * id of display 153 */ 154 displayId: number; 155 /** 156 * region tint of systembar 157 */ 158 regionTint: Array<SystemBarRegionTint>; 159 } 160 161 /** 162 * Rectangle 163 * @syscap SystemCapability.WindowManager.WindowManager.Core 164 * @since 7 165 */ 166 interface Rect { 167 left: number; 168 169 top: number; 170 171 width: number; 172 173 height: number; 174 } 175 176 /** 177 * avoid area 178 * @syscap SystemCapability.WindowManager.WindowManager.Core 179 * @since 7 180 */ 181 interface AvoidArea { 182 /** 183 * Rectangle on the left of the screen 184 */ 185 leftRect: Rect; 186 187 /** 188 * Rectangle on the top of the screen 189 */ 190 topRect: Rect; 191 192 /** 193 * Rectangle on the right of the screen 194 */ 195 rightRect: Rect; 196 197 /** 198 * Rectangle on the bottom of the screen 199 */ 200 bottomRect: Rect; 201 } 202 203 /** 204 * window size 205 * @syscap SystemCapability.WindowManager.WindowManager.Core 206 * @since 7 207 */ 208 interface Size { 209 /** 210 * the width of the window. 211 */ 212 width: number; 213 214 /** 215 * the height of the window. 216 */ 217 height: number; 218 } 219 220 /** 221 * Properties of window, it couldn't update automatically 222 * @syscap SystemCapability.WindowManager.WindowManager.Core 223 * @since 6 224 */ 225 interface WindowProperties { 226 /** 227 * the position and size of the window 228 * @since 7 229 */ 230 windowRect: Rect; 231 232 /** 233 * window type 234 * @since 7 235 */ 236 type: WindowType; 237 238 /** 239 * Whether the window is displayed in full screen mode. The default value is false. 240 * @since 6 241 */ 242 isFullScreen: boolean 243 244 /** 245 * Whether the window layout is in full screen mode(whether the window is immersive). The default value is false. 246 * @since 7 247 */ 248 isLayoutFullScreen: boolean 249 250 /** 251 * Whether the window can gain focus. The default value is true 252 * @since 7 253 */ 254 focusable: boolean 255 256 /** 257 * Whether the window is touchable. The default value is false 258 * @since 7 259 */ 260 touchable: boolean 261 262 /** 263 * Brightness value of window. 264 * @since 6 265 */ 266 brightness: number 267 268 /** 269 * The dimbehind value of window. 270 * @since 7 271 */ 272 dimBehindValue: number 273 274 /** 275 * Whether keep screen on. 276 * @since 6 277 */ 278 isKeepScreenOn: boolean 279 280 /** 281 * Whether make window in privacy mode or not. 282 * @since 7 283 */ 284 isPrivacyMode: boolean 285 286 /** 287 * Whether is round corner or not. 288 * @since 7 289 */ 290 isRoundCorner: boolean 291 292 /** 293 * Whether is transparent or not. 294 * @since 7 295 */ 296 isTransparent: boolean 297 } 298 299 /** 300 * Type of allowing the specified of color space. 301 * @since 8 302 */ 303 enum ColorSpace { 304 /** 305 * Default color space. 306 */ 307 DEFAULT, 308 /** 309 * Wide gamut color space. The specific wide color gamut depends on thr screen. 310 */ 311 WIDE_GAMUT, 312 } 313 314 /** 315 * Create a sub window with a specific id and type, only support 7. 316 * @param id Indicates window id. 317 * @param type Indicates window type. 318 * @since 7 319 */ 320 function create(id: string, type: WindowType, callback: AsyncCallback<Window>): void; 321 322 /** 323 * Create a sub window with a specific id and type, only support 7. 324 * @param id Indicates window id. 325 * @param type Indicates window type. 326 * @since 7 327 */ 328 function create(id: string, type: WindowType): Promise<Window>; 329 330 /** 331 * Create a system or float window with a specific id and type. 332 * @param ctx Indicates the context on which the window depends 333 * @param id Indicates window id. 334 * @param type Indicates window type. 335 * @since 8 336 */ 337 function create(ctx: Context, id: string, type: WindowType): Promise<Window>; 338 339 /** 340 * Create a system or float window with a specific id and type. 341 * @param ctx Indicates the context on which the window depends 342 * @param id Indicates window id. 343 * @param type Indicates window type. 344 * @since 8 345 */ 346 function create(ctx: Context, id: string, type: WindowType, callback: AsyncCallback<Window>): void; 347 348 /** 349 * Find the window by id. 350 * @param id Indicates window id. 351 * @since 7 352 */ 353 function find(id: string, callback: AsyncCallback<Window>): void; 354 355 /** 356 * Find the window by id. 357 * @param id Indicates window id. 358 * @since 7 359 */ 360 function find(id: string): Promise<Window>; 361 362 /** 363 * Get the final show window. 364 * @param id Indicates window id. 365 * @since 6 366 */ 367 function getTopWindow(callback: AsyncCallback<Window>): void; 368 369 /** 370 * Get the final show window. 371 * @since 6 372 */ 373 function getTopWindow(): Promise<Window>; 374 375 /** 376 * Get the final show window. 377 * @param ctx Indicates the context on which the window depends 378 * @since 8 379 */ 380 function getTopWindow(ctx: Context): Promise<Window>; 381 382 /** 383 * Get the final show window. 384 * @param ctx Indicates the context on which the window depends 385 * @since 8 386 */ 387 function getTopWindow(ctx: Context, callback: AsyncCallback<Window>): void; 388 389 /** 390 * register the callback of systemBarTintChange 391 * @param type: 'systemBarTintChange' 392 * @systemapi Hide this for inner system use. 393 * @since 8 394 */ 395 function on(type: 'systemBarTintChange', callback: Callback<SystemBarTintState>): void; 396 397 /** 398 * unregister the callback of systemBarTintChange 399 * @param type: 'systemBarTintChange' 400 * @systemapi Hide this for inner system use. 401 * @since 8 402 */ 403 function off(type: 'systemBarTintChange', callback?: Callback<SystemBarTintState>): void; 404 405 interface Window { 406 /** 407 * hide window. 408 * @systemapi Hide this for inner system use. 409 * @since 7 410 */ 411 hide (callback: AsyncCallback<void>): void; 412 413 /** 414 * hide window. 415 * @systemapi Hide this for inner system use. 416 * @since 7 417 */ 418 hide(): Promise<void>; 419 420 /** 421 * show window. 422 * @since 7 423 */ 424 show(callback: AsyncCallback<void>): void; 425 426 /** 427 * show window. 428 * @since 7 429 */ 430 show(): Promise<void>; 431 432 /** 433 * Destroy the window. 434 * @since 7 435 */ 436 destroy(callback: AsyncCallback<void>): void; 437 438 /** 439 * Destroy the window. 440 * @since 7 441 */ 442 destroy(): Promise<void>; 443 444 /** 445 * Set the position of a window. 446 * @param x Indicate the X-coordinate of the window. 447 * @param y Indicate the Y-coordinate of the window. 448 * @syscap SystemCapability.WindowManager.WindowManager.Core 449 * @since 7 450 */ 451 moveTo(x: number, y: number): Promise<void>; 452 453 /** 454 * Set the position of a window. 455 * @param x Indicate the X-coordinate of the window. 456 * @param y Indicate the Y-coordinate of the window. 457 * @syscap SystemCapability.WindowManager.WindowManager.Core 458 * @since 7 459 */ 460 moveTo(x: number, y: number, callback: AsyncCallback<void>): void; 461 462 /** 463 * Set the size of a window . 464 * @param width Indicates the width of the window. 465 * @param height Indicates the height of the window. 466 * @syscap SystemCapability.WindowManager.WindowManager.Core 467 * @since 7 468 */ 469 resetSize(width: number, height: number): Promise<void>; 470 471 /** 472 * Set the size of a window . 473 * @param width Indicates the width of the window. 474 * @param height Indicates the height of the window. 475 * @syscap SystemCapability.WindowManager.WindowManager.Core 476 * @since 7 477 */ 478 resetSize(width: number, height: number, callback: AsyncCallback<void>): void; 479 480 /** 481 * Set the type of a window. 482 * @param type Indicate the type of a window. 483 * @syscap SystemCapability.WindowManager.WindowManager.Core 484 * @systemapi Hide this for inner system use. 485 * @since 7 486 */ 487 setWindowType(type: WindowType): Promise<void>; 488 489 /** 490 * Set the type of a window. 491 * @param type Indicate the type of a window. 492 * @syscap SystemCapability.WindowManager.WindowManager.Core 493 * @systemapi Hide this for inner system use. 494 * @since 7 495 */ 496 setWindowType(type: WindowType, callback: AsyncCallback<void>): void; 497 498 /** 499 * get the properties of current window 500 * @syscap SystemCapability.WindowManager.WindowManager.Core 501 * @since 6 502 */ 503 getProperties(callback: AsyncCallback<WindowProperties>): void; 504 505 /** 506 * get the properties of current window 507 * @syscap SystemCapability.WindowManager.WindowManager.Core 508 * @since 6 509 */ 510 getProperties(): Promise<WindowProperties>; 511 512 /** 513 * get the avoid area 514 * @param type Type of the area 515 * @since 7 516 */ 517 getAvoidArea(type: AvoidAreaType, callback: AsyncCallback<AvoidArea>): void; 518 519 /** 520 * get the avoid area 521 * @param type Type of the area 522 * @since 7 523 */ 524 getAvoidArea(type: AvoidAreaType): Promise<AvoidArea>; 525 526 /** 527 * set the flag of the window is shown full screen 528 * @param isFullScreen the flag of the window is shown full screen 529 * @syscap SystemCapability.WindowManager.WindowManager.Core 530 * @since 6 531 */ 532 setFullScreen(isFullScreen: boolean, callback: AsyncCallback<void>): void; 533 534 /** 535 * set the flag of the window is shown full screen 536 * @param isFullScreen the flag of the window is shown full screen 537 * @syscap SystemCapability.WindowManager.WindowManager.Core 538 * @since 6 539 */ 540 setFullScreen(isFullScreen: boolean): Promise<void>; 541 542 /** 543 * set the property of the window can layout in full screen 544 * @param isLayoutFullScreen the window can layout in full screen 545 * @syscap SystemCapability.WindowManager.WindowManager.Core 546 * @since 7 547 */ 548 setLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback<void>): void; 549 550 /** 551 * set the property of the window can layout in full screen 552 * @param isLayoutFullScreen the window can layout in full screen 553 * @syscap SystemCapability.WindowManager.WindowManager.Core 554 * @since 7 555 */ 556 setLayoutFullScreen(isLayoutFullScreen: boolean): Promise<void>; 557 558 /** 559 * set the system bar to have visible. 560 * @param names the set of system bar 561 * @syscap SystemCapability.WindowManager.WindowManager.Core 562 * @since 7 563 */ 564 setSystemBarEnable(names: Array<'status'|'navigation'>, callback: AsyncCallback<void>): void; 565 566 /** 567 * set the system bar to have visible. 568 * @param names the set of system bar 569 * @syscap SystemCapability.WindowManager.WindowManager.Core 570 * @since 7 571 */ 572 setSystemBarEnable(names: Array<'status'|'navigation'>): Promise<void>; 573 574 /** 575 * set the background color of statusbar 576 * @param color the background color of statusbar 577 * @syscap SystemCapability.WindowManager.WindowManager.Core 578 * @since 6 579 */ 580 setSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback<void>): void; 581 582 /** 583 * set the background color of statusbar 584 * @param color the background color of statusbar 585 * @syscap SystemCapability.WindowManager.WindowManager.Core 586 * @since 6 587 */ 588 setSystemBarProperties(systemBarProperties: SystemBarProperties): Promise<void>; 589 590 /** 591 * Loads content 592 * @param path path of the page to which the content will be loaded 593 * @syscap SystemCapability.WindowManager.WindowManager.Core 594 * @since 7 595 */ 596 loadContent(path: string, callback: AsyncCallback<void>): void; 597 598 /** 599 * Loads content 600 * @param path path of the page to which the content will be loaded 601 * @syscap SystemCapability.WindowManager.WindowManager.Core 602 * @since 7 603 */ 604 loadContent(path: string): Promise<void>; 605 606 /** 607 * Checks whether the window is displayed 608 * @syscap SystemCapability.WindowManager.WindowManager.Core 609 * @since 7 610 */ 611 isShowing(callback: AsyncCallback<boolean>): void; 612 613 /** 614 * Checks whether the window is displayed 615 * @syscap SystemCapability.WindowManager.WindowManager.Core 616 * @since 7 617 */ 618 isShowing(): Promise<boolean>; 619 620 /** 621 * register the callback of windowSizeChange 622 * @param type: 'windowSizeChange' 623 * @syscap SystemCapability.WindowManager.WindowManager.Core 624 * @since 7 625 */ 626 on(type: 'windowSizeChange', callback: Callback<Size>): void; 627 628 /** 629 * unregister the callback of windowSizeChange 630 * @param type: 'windowSizeChange' 631 * @syscap SystemCapability.WindowManager.WindowManager.Core 632 * @since 7 633 */ 634 off(type: 'windowSizeChange', callback?: Callback<Size>): void; 635 636 /** 637 * register the callback of systemAvoidAreaChange 638 * @param type: 'systemAvoidAreaChange' 639 * @syscap SystemCapability.WindowManager.WindowManager.Core 640 * @since 7 641 */ 642 on(type: 'systemAvoidAreaChange', callback: Callback<AvoidArea>): void; 643 644 /** 645 * unregister the callback of systemAvoidAreaChange 646 * @param type: 'systemAvoidAreaChange' 647 * @syscap SystemCapability.WindowManager.WindowManager.Core 648 * @since 7 649 */ 650 off(type: 'systemAvoidAreaChange', callback?: Callback<AvoidArea>): void; 651 652 /** 653 * register the callback of keyboardHeightChange 654 * @param type: 'keyboardHeightChange' 655 * @syscap SystemCapability.WindowManager.WindowManager.Core 656 * @since 7 657 */ 658 on(type: 'keyboardHeightChange', callback: Callback<number>): void; 659 660 /** 661 * unregister the callback of keyboardHeightChange 662 * @param type: 'keyboardHeightChange' 663 * @syscap SystemCapability.WindowManager.WindowManager.Core 664 * @since 7 665 */ 666 off(type: 'keyboardHeightChange', callback?: Callback<number>): void; 667 668 /** 669 * Whether the window supports thr wide gamut setting. 670 * @since 8 671 */ 672 isSupportWideGamut(): Promise<boolean>; 673 674 /** 675 * Whether the window supports thr wide gamut setting. 676 * @since 8 677 */ 678 isSupportWideGamut(callback: AsyncCallback<boolean>): void; 679 680 /** 681 * Sets the specified color space. 682 * @param colorSpace the specified color space. 683 * @since 8 684 */ 685 setColorSpace(colorSpace:ColorSpace): Promise<void>; 686 687 /** 688 * Sets the specified color space. 689 * @param colorSpace the specified color space. 690 * @since 8 691 */ 692 setColorSpace(colorSpace:ColorSpace, callback: AsyncCallback<void>): void; 693 694 /** 695 * Obtains thr set color space. 696 * @since 8 697 */ 698 getColorSpace(): Promise<ColorSpace>; 699 700 /** 701 * Obtains thr set color space. 702 * @since 8 703 */ 704 getColorSpace(callback: AsyncCallback<ColorSpace>): void; 705 706 /** 707 * Sets the background color of window. 708 * @param color the specified color. 709 * @syscap SystemCapability.WindowManager.WindowManager.Core 710 * @since 6 711 */ 712 setBackgroundColor(color: string): Promise<void>; 713 714 /** 715 * Sets the background color of window. 716 * @param color the specified color. 717 * @syscap SystemCapability.WindowManager.WindowManager.Core 718 * @since 6 719 */ 720 setBackgroundColor(color: string, callback: AsyncCallback<void>): void; 721 722 /** 723 * Sets the brightness of window. 724 * @param brightness the specified brightness value. 725 * @syscap SystemCapability.WindowManager.WindowManager.Core 726 * @since 6 727 */ 728 setBrightness(brightness: number): Promise<void>; 729 730 /** 731 * Sets the brightness of window. 732 * @param brightness the specified brightness value. 733 * @syscap SystemCapability.WindowManager.WindowManager.Core 734 * @since 6 735 */ 736 setBrightness(brightness: number, callback: AsyncCallback<void>): void; 737 738 /** 739 * Sets the dimBehind of window. 740 * @param dimBehindValue the specified dimBehind. 741 * @syscap SystemCapability.WindowManager.WindowManager.Core 742 * @since 7 743 */ 744 setDimBehind(dimBehindValue: number, callback: AsyncCallback<void>): void; 745 746 /** 747 * Sets the dimBehind of window. 748 * @param dimBehind the specified dimBehind. 749 * @syscap SystemCapability.WindowManager.WindowManager.Core 750 * @since 7 751 */ 752 setDimBehind(dimBehindValue: number): Promise<void>; 753 754 /** 755 * Sets whether focusable or not. 756 * @param isFocusable can be focus if true, or can not be focus if false. 757 * @syscap SystemCapability.WindowManager.WindowManager.Core 758 * @since 7 759 */ 760 setFocusable(isFocusable: boolean): Promise<void>; 761 762 /** 763 * Sets whether focusable or not. 764 * @param isFocusable can be focus if true, or can not be focus if false. 765 * @syscap SystemCapability.WindowManager.WindowManager.Core 766 * @since 7 767 */ 768 setFocusable(isFocusable: boolean, callback: AsyncCallback<void>): void; 769 770 /** 771 * Sets whether keep screen on or not. 772 * @param isKeepScreenOn keep screen on if true, or not if false. 773 * @syscap SystemCapability.WindowManager.WindowManager.Core 774 * @since 6 775 */ 776 setKeepScreenOn(isKeepScreenOn: boolean): Promise<void>; 777 778 /** 779 * Sets whether keep screen on or not. 780 * @param isKeepScreenOn keep screen on if true, or not if false. 781 * @syscap SystemCapability.WindowManager.WindowManager.Core 782 * @since 6 783 */ 784 setKeepScreenOn(isKeepScreenOn: boolean, callback: AsyncCallback<void>): void; 785 786 /** 787 * Sets whether outside can be touch or not. 788 * @param touchable outside can be touch if true, or not if false. 789 * @syscap SystemCapability.WindowManager.WindowManager.Core 790 * @since 7 791 */ 792 setOutsideTouchable(touchable: boolean): Promise<void>; 793 794 /** 795 * Sets whether outside can be touch or not. 796 * @param touchable outside can be touch if true, or not if false. 797 * @syscap SystemCapability.WindowManager.WindowManager.Core 798 * @since 7 799 */ 800 setOutsideTouchable(touchable: boolean, callback: AsyncCallback<void>): void; 801 802 /** 803 * Sets whether is private mode or not. 804 * @param isPrivacyMode in private mode if true, or not if false. 805 * @syscap SystemCapability.WindowManager.WindowManager.Core 806 * @since 7 807 */ 808 setPrivacyMode(isPrivacyMode: boolean): Promise<void>; 809 810 /** 811 * Sets whether is private mode or not. 812 * @param isPrivacyMode in private mode if true, or not if false. 813 * @syscap SystemCapability.WindowManager.WindowManager.Core 814 * @since 7 815 */ 816 setPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback<void>): void; 817 818 /** 819 * Sets whether is touchable or not. 820 * @param isTouchable is touchable if true, or not if false. 821 * @syscap SystemCapability.WindowManager.WindowManager.Core 822 * @since 7 823 */ 824 setTouchable(isTouchable: boolean): Promise<void>; 825 826 /** 827 * Sets whether is touchable or not. 828 * @param isTouchable is touchable if true, or not if false. 829 * @syscap SystemCapability.WindowManager.WindowManager.Core 830 * @since 7 831 */ 832 setTouchable(isTouchable: boolean, callback: AsyncCallback<void>): void; 833 } 834} 835 836export default window; 837