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 16import type { AsyncCallback } from './@ohos.base'; 17import type { Callback } from './@ohos.base'; 18 19/** 20 * Accessibility 21 * 22 * @namespace accessibility 23 * @syscap SystemCapability.BarrierFree.Accessibility.Core 24 * @since 7 25 */ 26declare namespace accessibility { 27 /** 28 * The type of the Ability app. 29 * 30 *{ 'audible' | 'generic' | 'haptic' | 'spoken' | 'visual' } 31 * @syscap SystemCapability.BarrierFree.Accessibility.Core 32 * @since 7 33 */ 34 /** 35 * The type of the Ability app. 36 * 37 * { 'audible' | 'generic' | 'haptic' | 'spoken' | 'visual' | 'all' } 38 * @syscap SystemCapability.BarrierFree.Accessibility.Core 39 * @since 9 40 */ 41 type AbilityType = 'audible' | 'generic' | 'haptic' | 'spoken' | 'visual' | 'all'; 42 43 /** 44 * The action that the ability can execute. 45 * 46 * @syscap SystemCapability.BarrierFree.Accessibility.Core 47 * @since 7 48 */ 49 type Action = 'accessibilityFocus' | 'clearAccessibilityFocus' | 'focus' | 'clearFocus' | 'clearSelection' | 50 'click' | 'longClick' | 'cut' | 'copy' | 'paste' | 'select' | 'setText' | 'delete' | 51 'scrollForward' | 'scrollBackward' | 'setSelection'; 52 53 /** 54 * The type of the accessibility event. 55 * windowsChange/windowContentChange/windowStateChange/announcement/notificationChange/textTraversedAtMove 56 * 57 * @syscap SystemCapability.BarrierFree.Accessibility.Core 58 * @since 7 59 */ 60 type EventType = 'accessibilityFocus' | 'accessibilityFocusClear' | 61 'click' | 'longClick' | 'focus' | 'select' | 'hoverEnter' | 'hoverExit' | 62 'textUpdate' | 'textSelectionUpdate' | 'scroll'; 63 64 /** 65 * The change type of the windowsChange event. 66 * It's used when received the {@code windowsChange} event. 67 * 68 * @syscap SystemCapability.BarrierFree.Accessibility.Core 69 * @since 7 70 */ 71 type WindowUpdateType = 'add' | 'remove' | 'bounds' | 'active' | 'focus'; 72 73 /** 74 * The type of the ability state. 75 * 76 * @syscap SystemCapability.BarrierFree.Accessibility.Core 77 * @since 7 78 */ 79 type AbilityState = 'enable' | 'disable' | 'install'; 80 81 /** 82 * The ability that accessibility subsystem support. 83 * touchExplorer: Describes the capability to talkback. 84 * magnification: Describes the capability to request to control the display magnification. 85 * gesturesSimulation: Describes the capability to request to simulate the gesture. 86 * windowContent: Describes the capability to search for the content of the active window. 87 * filterKeyEvents: Describes the capability to request to filter key events. 88 * fingerprintGesture: Describes the capability to request to fingerprint gesture. 89 * 90 * @syscap SystemCapability.BarrierFree.Accessibility.Core 91 * @since 7 92 */ 93 type Capability = 'retrieve' | 'touchGuide' | 'keyEventObserver' | 'zoom' | 'gesture'; 94 95 /** 96 * The granularity of text move. 97 * 98 * @syscap SystemCapability.BarrierFree.Accessibility.Core 99 * @since 7 100 */ 101 type TextMoveUnit = 'char' | 'word' | 'line' | 'page' | 'paragraph'; 102 103 /** 104 * Checks whether accessibility ability is enabled. 105 * 106 * @param { AsyncCallback<boolean> } callback Asynchronous callback interface. 107 * @syscap SystemCapability.BarrierFree.Accessibility.Core 108 * @since 7 109 * @deprecated since 10 110 * @useinstead ohos.accessibility#isOpenAccessibilitySync 111 */ 112 function isOpenAccessibility(callback: AsyncCallback<boolean>): void; 113 114 /** 115 * Checks whether accessibility ability is enabled. 116 * 117 * @returns { Promise<boolean> } Returns {@code true} if the accessibility is enabled; returns {@code false} otherwise. 118 * @syscap SystemCapability.BarrierFree.Accessibility.Core 119 * @since 7 120 * @deprecated since 10 121 * @useinstead ohos.accessibility#isOpenAccessibilitySync 122 */ 123 function isOpenAccessibility(): Promise<boolean>; 124 125 /** 126 * Checks whether accessibility ability is enabled. 127 * 128 * @returns { boolean } Returns true if the accessibility is enabled; returns false otherwise. 129 * @syscap SystemCapability.BarrierFree.Accessibility.Core 130 * @since 10 131 */ 132 function isOpenAccessibilitySync(): boolean; 133 134 /** 135 * Checks touch browser ability (which is used by talkback) is enabled. 136 * 137 * @param { AsyncCallback<boolean> } callback Asynchronous callback interface. 138 * @syscap SystemCapability.BarrierFree.Accessibility.Vision 139 * @since 7 140 * @deprecated since 10 141 * @useinstead ohos.accessibility#isOpenTouchGuideSync 142 */ 143 function isOpenTouchGuide(callback: AsyncCallback<boolean>): void; 144 145 /** 146 * Checks touch browser ability (which is used by talkback) is enabled. 147 * 148 * @returns { Promise<boolean> } Returns {@code true} if the touch browser is enabled; returns {@code false} otherwise. 149 * @syscap SystemCapability.BarrierFree.Accessibility.Vision 150 * @since 7 151 * @deprecated since 10 152 * @useinstead ohos.accessibility#isOpenTouchGuideSync 153 */ 154 function isOpenTouchGuide(): Promise<boolean>; 155 156 /** 157 * Checks touch browser ability (which is used by talkback) is enabled. 158 * 159 * @returns { boolean } Returns true if the touch browser is enabled; returns false otherwise. 160 * @syscap SystemCapability.BarrierFree.Accessibility.Vision 161 * @since 10 162 */ 163 function isOpenTouchGuideSync(): boolean; 164 165 /** 166 * Queries the list of accessibility abilities. 167 * 168 * @param { AbilityType } abilityType The type of the accessibility ability. {@code AbilityType} eg.spoken 169 * @param { AbilityState } stateType The state of the accessibility ability. {@code AbilityState} eg.installed 170 * @param { AsyncCallback<Array<AccessibilityAbilityInfo>> } callback 171 * @syscap SystemCapability.BarrierFree.Accessibility.Core 172 * @since 7 173 * @deprecated since 9 174 * @useinstead ohos.accessibility#getAccessibilityExtensionList 175 */ 176 function getAbilityLists( 177 abilityType: AbilityType, 178 stateType: AbilityState, 179 callback: AsyncCallback<Array<AccessibilityAbilityInfo>> 180 ): void; 181 182 /** 183 * Queries the list of accessibility abilities. 184 * 185 * @param { AbilityType } abilityType The type of the accessibility ability. {@code AbilityType} eg.spoken 186 * @param { AbilityState } stateType The state of the accessibility ability. {@code AbilityState} eg.installed 187 * @returns { Promise<Array<AccessibilityAbilityInfo>> } Returns the list of abilityInfos. 188 * @syscap SystemCapability.BarrierFree.Accessibility.Core 189 * @since 7 190 * @deprecated since 9 191 * @useinstead ohos.accessibility#getAccessibilityExtensionList 192 */ 193 function getAbilityLists(abilityType: AbilityType, stateType: AbilityState): Promise<Array<AccessibilityAbilityInfo>>; 194 195 /** 196 * Queries the list of accessibility abilities. 197 * 198 * @param { AbilityType } abilityType The type of the accessibility ability. {@code AbilityType} eg.spoken 199 * @param { AbilityState } stateType The state of the accessibility ability. {@code AbilityState} eg.installed 200 * @returns { Promise<Array<AccessibilityAbilityInfo>> } Returns the list of abilityInfos. 201 * @throws { BusinessError } 401 - Input parameter error. 202 * @syscap SystemCapability.BarrierFree.Accessibility.Core 203 * @since 9 204 */ 205 function getAccessibilityExtensionList( 206 abilityType: AbilityType, 207 stateType: AbilityState 208 ): Promise<Array<AccessibilityAbilityInfo>>; 209 210 /** 211 * Queries the list of accessibility abilities. 212 * 213 * @param { AbilityType } abilityType The type of the accessibility ability. {@code AbilityType} eg.spoken 214 * @param { AbilityState } stateType The state of the accessibility ability. {@code AbilityState} eg.installed 215 * @param { AsyncCallback<Array<AccessibilityAbilityInfo>> } callback 216 * @throws { BusinessError } 401 - Input parameter error. 217 * @syscap SystemCapability.BarrierFree.Accessibility.Core 218 * @since 9 219 */ 220 function getAccessibilityExtensionList( 221 abilityType: AbilityType, 222 stateType: AbilityState, 223 callback: AsyncCallback<Array<AccessibilityAbilityInfo>> 224 ): void; 225 226 /** 227 * Send accessibility Event. 228 * 229 * @param { EventInfo } event The object of the accessibility {@code EventInfo} . 230 * @param { AsyncCallback<void> } callback Asynchronous callback interface. 231 * @syscap SystemCapability.BarrierFree.Accessibility.Core 232 * @since 7 233 * @deprecated since 9 234 * @useinstead ohos.accessibility#sendAccessibilityEvent 235 */ 236 function sendEvent(event: EventInfo, callback: AsyncCallback<void>): void; 237 238 /** 239 * Send accessibility Event. 240 * 241 * @param { EventInfo } event The object of the accessibility {@code EventInfo} . 242 * @returns { Promise<void> } Returns {@code true} if success ; returns {@code false} otherwise. 243 * @syscap SystemCapability.BarrierFree.Accessibility.Core 244 * @since 7 245 * @deprecated since 9 246 * @useinstead ohos.accessibility#sendAccessibilityEvent 247 */ 248 function sendEvent(event: EventInfo): Promise<void>; 249 250 /** 251 * Send accessibility event. 252 * 253 * @param { EventInfo } event The object of the accessibility {@code EventInfo} . 254 * @param { AsyncCallback<void> } callback Asynchronous callback interface. 255 * @throws { BusinessError } 401 - Input parameter error. 256 * @syscap SystemCapability.BarrierFree.Accessibility.Core 257 * @since 9 258 */ 259 function sendAccessibilityEvent(event: EventInfo, callback: AsyncCallback<void>): void; 260 261 /** 262 * Send accessibility event. 263 * 264 * @param { EventInfo } event The object of the accessibility {@code EventInfo} . 265 * @returns { Promise<void> } Returns {@code true} if success ; returns {@code false} otherwise. 266 * @throws { BusinessError } 401 - Input parameter error. 267 * @syscap SystemCapability.BarrierFree.Accessibility.Core 268 * @since 9 269 */ 270 function sendAccessibilityEvent(event: EventInfo): Promise<void>; 271 272 /** 273 * Register the observe of the accessibility state changed. 274 * 275 * @param { 'accessibilityStateChange' } type state event type. 276 * @param { Callback<boolean> } callback Asynchronous callback interface. 277 * @throws { BusinessError } 401 - Input parameter error. 278 * @syscap SystemCapability.BarrierFree.Accessibility.Core 279 * @since 7 280 */ 281 function on(type: 'accessibilityStateChange', callback: Callback<boolean>): void; 282 283 /** 284 * Register the observe of the touchGuide state changed. 285 * 286 * @param { 'touchGuideStateChange' } type state event type. 287 * @param { Callback<boolean> } callback Asynchronous callback interface. 288 * @throws { BusinessError } 401 - Input parameter error. 289 * @syscap SystemCapability.BarrierFree.Accessibility.Vision 290 * @since 7 291 */ 292 function on(type: 'touchGuideStateChange', callback: Callback<boolean>): void; 293 294 /** 295 * Unregister the observe of the accessibility state changed. 296 * 297 * @param { 'accessibilityStateChange' } type state event type 298 * @param { Callback<boolean> } callback Asynchronous callback interface. 299 * @throws { BusinessError } 401 - Input parameter error. 300 * @syscap SystemCapability.BarrierFree.Accessibility.Core 301 * @since 7 302 */ 303 function off(type: 'accessibilityStateChange', callback?: Callback<boolean>): void; 304 305 /** 306 * Unregister the observe of the touchGuide state changed. 307 * 308 * @param { 'touchGuideStateChange' } type state event type 309 * @param { Callback<boolean> } callback Asynchronous callback interface. 310 * @throws { BusinessError } 401 - Input parameter error. 311 * @syscap SystemCapability.BarrierFree.Accessibility.Core 312 * @since 7 313 */ 314 function off(type: 'touchGuideStateChange', callback?: Callback<boolean>): void; 315 316 /** 317 * Get the captions manager. 318 * 319 * @returns { CaptionsManager } Returns the captions manager. 320 * @syscap SystemCapability.BarrierFree.Accessibility.Hearing 321 * @since 8 322 */ 323 function getCaptionsManager(): CaptionsManager; 324 325 /** 326 * Indicates the captions manager. 327 * 328 * @typedef CaptionsManager 329 * @syscap SystemCapability.BarrierFree.Accessibility.Hearing 330 * @since 8 331 */ 332 interface CaptionsManager { 333 /** 334 * Indicates whether captions are enabled. 335 * 336 * @syscap SystemCapability.BarrierFree.Accessibility.Hearing 337 * @since 8 338 */ 339 enabled: boolean; 340 /** 341 * Indicates the style of captions. 342 * 343 * @syscap SystemCapability.BarrierFree.Accessibility.Hearing 344 * @since 8 345 */ 346 style: CaptionsStyle; 347 348 /** 349 * Register the observe of the enable state. 350 * 351 * @param { 'enableChange' } type 352 * @param { Callback<boolean> } callback 353 * @throws { BusinessError } 401 - Input parameter error. 354 * @syscap SystemCapability.BarrierFree.Accessibility.Hearing 355 * @since 8 356 */ 357 on(type: 'enableChange', callback: Callback<boolean>): void; 358 359 /** 360 * Register the observer of the style. 361 * 362 * @param { 'styleChange' } type 363 * @param { Callback<CaptionsStyle> } callback 364 * @throws { BusinessError } 401 - Input parameter error. 365 * @syscap SystemCapability.BarrierFree.Accessibility.Hearing 366 * @since 8 367 */ 368 on(type: 'styleChange', callback: Callback<CaptionsStyle>): void; 369 370 /** 371 * Unregister the observe of the enable state. 372 * 373 * @param { 'enableChange' } type 374 * @param { Callback<boolean> } callback 375 * @throws { BusinessError } 401 - Input parameter error. 376 * @syscap SystemCapability.BarrierFree.Accessibility.Hearing 377 * @since 8 378 */ 379 off(type: 'enableChange', callback?: Callback<boolean>): void; 380 381 /** 382 * Unregister the observer of the style. 383 * 384 * @param { 'styleChange' } type 385 * @param { Callback<CaptionsStyle> } callback 386 * @throws { BusinessError } 401 - Input parameter error. 387 * @syscap SystemCapability.BarrierFree.Accessibility.Hearing 388 * @since 8 389 */ 390 off(type: 'styleChange', callback?: Callback<CaptionsStyle>): void; 391 } 392 393 /** 394 * Indicates the edge type of the captions font. 395 * 396 * @syscap SystemCapability.BarrierFree.Accessibility.Hearing 397 * @since 8 398 */ 399 type CaptionsFontEdgeType = 'none' | 'raised' | 'depressed' | 'uniform' | 'dropShadow'; 400 /** 401 * Indicates the font family of captions. 402 * 403 * @syscap SystemCapability.BarrierFree.Accessibility.Hearing 404 * @since 8 405 */ 406 type CaptionsFontFamily = 'default' | 'monospacedSerif' | 'serif' | 407 'monospacedSansSerif' | 'sansSerif' | 'casual' | 'cursive' | 'smallCapitals'; 408 /** 409 * Indicates the style of captions. 410 * 411 * @typedef CaptionsStyle 412 * @syscap SystemCapability.BarrierFree.Accessibility.Hearing 413 * @since 8 414 */ 415 interface CaptionsStyle { 416 /** 417 * Indicates the font family of captions. 418 * 419 * @syscap SystemCapability.BarrierFree.Accessibility.Hearing 420 * @since 8 421 */ 422 fontFamily: CaptionsFontFamily; 423 /** 424 * Indicates the font scaling of captions. 425 * 426 * @syscap SystemCapability.BarrierFree.Accessibility.Hearing 427 * @since 8 428 */ 429 fontScale: number; 430 /** 431 * Indicates the font color of captions. 432 * 433 * @syscap SystemCapability.BarrierFree.Accessibility.Hearing 434 * @since 8 435 */ 436 fontColor: number | string; 437 /** 438 * Indicates the edge type of the captions font. 439 * 440 * @syscap SystemCapability.BarrierFree.Accessibility.Hearing 441 * @since 8 442 */ 443 fontEdgeType: CaptionsFontEdgeType; 444 /** 445 * Indicates the background color of captions. 446 * 447 * @syscap SystemCapability.BarrierFree.Accessibility.Hearing 448 * @since 8 449 */ 450 backgroundColor: number | string; 451 /** 452 * Indicates the window color of captions. 453 * 454 * @syscap SystemCapability.BarrierFree.Accessibility.Hearing 455 * @since 8 456 */ 457 windowColor: number | string; 458 } 459 460 /** 461 * Indicates the info of accessibility. 462 * 463 * @typedef AccessibilityAbilityInfo 464 * @syscap SystemCapability.BarrierFree.Accessibility.Core 465 * @since 7 466 */ 467 interface AccessibilityAbilityInfo { 468 /** 469 * The ability id. 470 * 471 * @syscap SystemCapability.BarrierFree.Accessibility.Core 472 * @since 7 473 */ 474 readonly id: string; 475 476 /* The ability name. 477 * @since 7 478 */ 479 readonly name: string; 480 481 /* The bundle name of the ability. 482 * @since 7 483 */ 484 readonly bundleName: string; 485 486 /* The target bundle name for the observation. 487 * @since 9 488 */ 489 readonly targetBundleNames: Array<string>; 490 491 /** 492 * The type of the ability. 493 * 494 * @syscap SystemCapability.BarrierFree.Accessibility.Core 495 * @since 7 496 */ 497 readonly abilityTypes: Array<AbilityType>; 498 499 /** 500 * The capabilities of the ability. 501 * 502 * @syscap SystemCapability.BarrierFree.Accessibility.Core 503 * @since 7 504 */ 505 readonly capabilities: Array<Capability>; 506 507 /** 508 * The description of the ability. 509 * 510 * @syscap SystemCapability.BarrierFree.Accessibility.Core 511 * @since 7 512 */ 513 readonly description: string; 514 515 /** 516 * The events which the accessibility ability wants to observe. 517 * 518 * @syscap SystemCapability.BarrierFree.Accessibility.Core 519 * @since 7 520 */ 521 readonly eventTypes: Array<EventType>; 522 } 523 524 /** 525 * Indicates the info of events. 526 * 527 * @syscap SystemCapability.BarrierFree.Accessibility.Core 528 * @since 7 529 */ 530 class EventInfo { 531 constructor(jsonObject); 532 /** 533 * The type of an accessibility event. 534 * 535 * @syscap SystemCapability.BarrierFree.Accessibility.Core 536 * @since 7 537 */ 538 type: EventType; 539 540 /** 541 * The type of the window change event. 542 * 543 * @syscap SystemCapability.BarrierFree.Accessibility.Core 544 * @since 7 545 */ 546 windowUpdateType?: WindowUpdateType; 547 548 /** 549 * The bundle name of the target application. 550 * 551 * @syscap SystemCapability.BarrierFree.Accessibility.Core 552 * @since 7 553 */ 554 bundleName: string; 555 556 /** 557 * The type of the event source component,such as button, chart. 558 * 559 * @syscap SystemCapability.BarrierFree.Accessibility.Core 560 * @since 7 561 */ 562 componentType?: string; 563 564 /** 565 * The page id of the event source. 566 * 567 * @syscap SystemCapability.BarrierFree.Accessibility.Core 568 * @since 7 569 */ 570 pageId?: number; 571 572 /** 573 * The accessibility event description. 574 * 575 * @syscap SystemCapability.BarrierFree.Accessibility.Core 576 * @since 7 577 */ 578 description?: string; 579 580 /** 581 * The action that triggers the accessibility event, for example, clicking or focusing a view. 582 * 583 * @syscap SystemCapability.BarrierFree.Accessibility.Core 584 * @since 7 585 */ 586 triggerAction: Action; 587 588 /** 589 * The movement step used for reading texts. 590 * 591 * @syscap SystemCapability.BarrierFree.Accessibility.Core 592 * @since 7 593 */ 594 textMoveUnit?: TextMoveUnit; 595 596 /** 597 * The content list. 598 * 599 * @syscap SystemCapability.BarrierFree.Accessibility.Core 600 * @since 7 601 */ 602 contents?: Array<string>; 603 604 /** 605 * The content changed before. 606 * 607 * @syscap SystemCapability.BarrierFree.Accessibility.Core 608 * @since 7 609 */ 610 lastContent?: string; 611 612 /** 613 * The start index of listed items on the screen. 614 * 615 * @syscap SystemCapability.BarrierFree.Accessibility.Core 616 * @since 7 617 */ 618 beginIndex?: number; 619 620 /** 621 * The index of the current item on the screen. 622 * 623 * @syscap SystemCapability.BarrierFree.Accessibility.Core 624 * @since 7 625 */ 626 currentIndex?: number; 627 628 /** 629 * The end index of listed items on the screen. 630 * 631 * @syscap SystemCapability.BarrierFree.Accessibility.Core 632 * @since 7 633 */ 634 endIndex?: number; 635 636 /** 637 * The total of the items, talkback used it when scroll. 638 * 639 * @syscap SystemCapability.BarrierFree.Accessibility.Core 640 * @since 7 641 */ 642 itemCount?: number; 643 } 644} 645export default accessibility; 646