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 * @type { '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 * @type { '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 */ 175 function getAbilityLists( 176 abilityType: AbilityType, 177 stateType: AbilityState, 178 callback: AsyncCallback<Array<AccessibilityAbilityInfo>> 179 ): void; 180 181 /** 182 * Queries the list of accessibility abilities. 183 * 184 * @param { AbilityType } abilityType The type of the accessibility ability. {@code AbilityType} eg.spoken 185 * @param { AbilityState } stateType The state of the accessibility ability. {@code AbilityState} eg.installed 186 * @returns { Promise<Array<AccessibilityAbilityInfo>> } Returns the list of abilityInfos. 187 * @syscap SystemCapability.BarrierFree.Accessibility.Core 188 * @since 7 189 * @deprecated since 9 190 */ 191 function getAbilityLists(abilityType: AbilityType, stateType: AbilityState): Promise<Array<AccessibilityAbilityInfo>>; 192 193 /** 194 * Queries the list of accessibility abilities. 195 * 196 * @param { AbilityType } abilityType The type of the accessibility ability. {@code AbilityType} eg.spoken 197 * @param { AbilityState } stateType The state of the accessibility ability. {@code AbilityState} eg.installed 198 * @returns { Promise<Array<AccessibilityAbilityInfo>> } Returns the list of abilityInfos. 199 * @throws { BusinessError } 401 - Input parameter error. 200 * @syscap SystemCapability.BarrierFree.Accessibility.Core 201 * @since 9 202 */ 203 function getAccessibilityExtensionList( 204 abilityType: AbilityType, 205 stateType: AbilityState 206 ): Promise<Array<AccessibilityAbilityInfo>>; 207 208 /** 209 * Queries the list of accessibility abilities. 210 * 211 * @param { AbilityType } abilityType The type of the accessibility ability. {@code AbilityType} eg.spoken 212 * @param { AbilityState } stateType The state of the accessibility ability. {@code AbilityState} eg.installed 213 * @param { AsyncCallback<Array<AccessibilityAbilityInfo>> } callback 214 * @throws { BusinessError } 401 - Input parameter error. 215 * @syscap SystemCapability.BarrierFree.Accessibility.Core 216 * @since 9 217 */ 218 function getAccessibilityExtensionList( 219 abilityType: AbilityType, 220 stateType: AbilityState, 221 callback: AsyncCallback<Array<AccessibilityAbilityInfo>> 222 ): void; 223 224 /** 225 * Send accessibility Event. 226 * 227 * @param { EventInfo } event The object of the accessibility {@code EventInfo} . 228 * @param { AsyncCallback<void> } callback Asynchronous callback interface. 229 * @syscap SystemCapability.BarrierFree.Accessibility.Core 230 * @since 7 231 * @deprecated since 9 232 */ 233 function sendEvent(event: EventInfo, callback: AsyncCallback<void>): void; 234 235 /** 236 * Send accessibility Event. 237 * 238 * @param { EventInfo } event The object of the accessibility {@code EventInfo} . 239 * @returns { Promise<void> } Returns {@code true} if success ; returns {@code false} otherwise. 240 * @syscap SystemCapability.BarrierFree.Accessibility.Core 241 * @since 7 242 * @deprecated since 9 243 */ 244 function sendEvent(event: EventInfo): Promise<void>; 245 246 /** 247 * Send accessibility event. 248 * 249 * @param { EventInfo } event The object of the accessibility {@code EventInfo} . 250 * @param { AsyncCallback<void> } callback Asynchronous callback interface. 251 * @throws { BusinessError } 401 - Input parameter error. 252 * @syscap SystemCapability.BarrierFree.Accessibility.Core 253 * @since 9 254 */ 255 function sendAccessibilityEvent(event: EventInfo, callback: AsyncCallback<void>): void; 256 257 /** 258 * Send accessibility event. 259 * 260 * @param { EventInfo } event The object of the accessibility {@code EventInfo} . 261 * @returns { Promise<void> } Returns {@code true} if success ; returns {@code false} otherwise. 262 * @throws { BusinessError } 401 - Input parameter error. 263 * @syscap SystemCapability.BarrierFree.Accessibility.Core 264 * @since 9 265 */ 266 function sendAccessibilityEvent(event: EventInfo): Promise<void>; 267 268 /** 269 * Register the observe of the accessibility state changed. 270 * 271 * @param { 'accessibilityStateChange' } type state event type. 272 * @param { Callback<boolean> } callback Asynchronous callback interface. 273 * @throws { BusinessError } 401 - Input parameter error. 274 * @syscap SystemCapability.BarrierFree.Accessibility.Core 275 * @since 7 276 */ 277 function on(type: 'accessibilityStateChange', callback: Callback<boolean>): void; 278 279 /** 280 * Register the observe of the touchGuide state changed. 281 * 282 * @param { 'touchGuideStateChange' } type state event type. 283 * @param { Callback<boolean> } callback Asynchronous callback interface. 284 * @throws { BusinessError } 401 - Input parameter error. 285 * @syscap SystemCapability.BarrierFree.Accessibility.Vision 286 * @since 7 287 */ 288 function on(type: 'touchGuideStateChange', callback: Callback<boolean>): void; 289 290 /** 291 * Deregister the observe of the accessibility state changed. 292 * 293 * @param { 'accessibilityStateChange' } type state event type 294 * @param { Callback<boolean> } callback Asynchronous callback interface. 295 * @throws { BusinessError } 401 - Input parameter error. 296 * @syscap SystemCapability.BarrierFree.Accessibility.Core 297 * @since 7 298 */ 299 function off(type: 'accessibilityStateChange', callback?: Callback<boolean>): void; 300 301 /** 302 * Deregister the observe of the touchGuide state changed. 303 * 304 * @param { 'touchGuideStateChange' } type state event type 305 * @param { Callback<boolean> } callback Asynchronous callback interface. 306 * @throws { BusinessError } 401 - Input parameter error. 307 * @syscap SystemCapability.BarrierFree.Accessibility.Core 308 * @since 7 309 */ 310 function off(type: 'touchGuideStateChange', callback?: Callback<boolean>): void; 311 312 /** 313 * Get the captions manager. 314 * 315 * @returns { CaptionsManager } Returns the captions manager. 316 * @syscap SystemCapability.BarrierFree.Accessibility.Hearing 317 * @since 8 318 */ 319 function getCaptionsManager(): CaptionsManager; 320 321 /** 322 * Indicates the captions manager. 323 * 324 * @typedef CaptionsManager 325 * @syscap SystemCapability.BarrierFree.Accessibility.Hearing 326 * @since 8 327 */ 328 interface CaptionsManager { 329 /** 330 * Indicates whether captions are enabled. 331 * 332 * @syscap SystemCapability.BarrierFree.Accessibility.Hearing 333 * @since 8 334 */ 335 enabled: boolean; 336 /** 337 * Indicates the style of captions. 338 * 339 * @syscap SystemCapability.BarrierFree.Accessibility.Hearing 340 * @since 8 341 */ 342 style: CaptionsStyle; 343 344 /** 345 * Register the observe of the enable state. 346 * 347 * @param { 'enableChange' } type 348 * @param { Callback<boolean> } callback 349 * @throws { BusinessError } 401 - Input parameter error. 350 * @syscap SystemCapability.BarrierFree.Accessibility.Hearing 351 * @since 8 352 */ 353 on(type: 'enableChange', callback: Callback<boolean>): void; 354 355 /** 356 * Register the observer of the style. 357 * 358 * @param { 'styleChange' } type 359 * @param { Callback<CaptionsStyle> } callback 360 * @throws { BusinessError } 401 - Input parameter error. 361 * @syscap SystemCapability.BarrierFree.Accessibility.Hearing 362 * @since 8 363 */ 364 on(type: 'styleChange', callback: Callback<CaptionsStyle>): void; 365 366 /** 367 * Deregister the observe of the enable state. 368 * 369 * @param { 'enableChange' } type 370 * @param { Callback<boolean> } callback 371 * @throws { BusinessError } 401 - Input parameter error. 372 * @syscap SystemCapability.BarrierFree.Accessibility.Hearing 373 * @since 8 374 */ 375 off(type: 'enableChange', callback?: Callback<boolean>): void; 376 377 /** 378 * Deregister the observer of the style. 379 * 380 * @param { 'styleChange' } type 381 * @param { Callback<CaptionsStyle> } callback 382 * @throws { BusinessError } 401 - Input parameter error. 383 * @syscap SystemCapability.BarrierFree.Accessibility.Hearing 384 * @since 8 385 */ 386 off(type: 'styleChange', callback?: Callback<CaptionsStyle>): void; 387 } 388 389 /** 390 * Indicates the edge type of the captions font. 391 * 392 * @syscap SystemCapability.BarrierFree.Accessibility.Hearing 393 * @since 8 394 */ 395 type CaptionsFontEdgeType = 'none' | 'raised' | 'depressed' | 'uniform' | 'dropShadow'; 396 /** 397 * Indicates the font family of captions. 398 * 399 * @syscap SystemCapability.BarrierFree.Accessibility.Hearing 400 * @since 8 401 */ 402 type CaptionsFontFamily = 'default' | 'monospacedSerif' | 'serif' | 403 'monospacedSansSerif' | 'sansSerif' | 'casual' | 'cursive' | 'smallCapitals'; 404 /** 405 * Indicates the style of captions. 406 * 407 * @typedef CaptionsStyle 408 * @syscap SystemCapability.BarrierFree.Accessibility.Hearing 409 * @since 8 410 */ 411 interface CaptionsStyle { 412 /** 413 * Indicates the font family of captions. 414 * 415 * @syscap SystemCapability.BarrierFree.Accessibility.Hearing 416 * @since 8 417 */ 418 fontFamily: CaptionsFontFamily; 419 /** 420 * Indicates the font scaling of captions. 421 * 422 * @syscap SystemCapability.BarrierFree.Accessibility.Hearing 423 * @since 8 424 */ 425 fontScale: number; 426 /** 427 * Indicates the font color of captions. 428 * 429 * @syscap SystemCapability.BarrierFree.Accessibility.Hearing 430 * @since 8 431 */ 432 fontColor: number | string; 433 /** 434 * Indicates the edge type of the captions font. 435 * 436 * @syscap SystemCapability.BarrierFree.Accessibility.Hearing 437 * @since 8 438 */ 439 fontEdgeType: CaptionsFontEdgeType; 440 /** 441 * Indicates the background color of captions. 442 * 443 * @syscap SystemCapability.BarrierFree.Accessibility.Hearing 444 * @since 8 445 */ 446 backgroundColor: number | string; 447 /** 448 * Indicates the window color of captions. 449 * 450 * @syscap SystemCapability.BarrierFree.Accessibility.Hearing 451 * @since 8 452 */ 453 windowColor: number | string; 454 } 455 456 /** 457 * Indicates the info of accessibility. 458 * 459 * @typedef AccessibilityAbilityInfo 460 * @syscap SystemCapability.BarrierFree.Accessibility.Core 461 * @since 7 462 */ 463 interface AccessibilityAbilityInfo { 464 /** 465 * The ability id. 466 * 467 * @syscap SystemCapability.BarrierFree.Accessibility.Core 468 * @since 7 469 */ 470 readonly id: string; 471 472 /* The ability name. 473 * @since 7 474 */ 475 readonly name: string; 476 477 /* The bundle name of the ability. 478 * @since 7 479 */ 480 readonly bundleName: string; 481 482 /* The target bundle name for the observation. 483 * @since 9 484 */ 485 readonly targetBundleNames: Array<string>; 486 487 /** 488 * The type of the ability. 489 * 490 * @syscap SystemCapability.BarrierFree.Accessibility.Core 491 * @since 7 492 */ 493 readonly abilityTypes: Array<AbilityType>; 494 495 /** 496 * The capabilities of the ability. 497 * 498 * @syscap SystemCapability.BarrierFree.Accessibility.Core 499 * @since 7 500 */ 501 readonly capabilities: Array<Capability>; 502 503 /** 504 * The description of the ability. 505 * 506 * @syscap SystemCapability.BarrierFree.Accessibility.Core 507 * @since 7 508 */ 509 readonly description: string; 510 511 /** 512 * The events which the accessibility ability wants to observe. 513 * 514 * @syscap SystemCapability.BarrierFree.Accessibility.Core 515 * @since 7 516 */ 517 readonly eventTypes: Array<EventType>; 518 } 519 520 /** 521 * Indicates the info of events. 522 * 523 * @syscap SystemCapability.BarrierFree.Accessibility.Core 524 * @since 7 525 */ 526 class EventInfo { 527 constructor(jsonObject); 528 /** 529 * The type of an accessibility event. 530 * 531 * @syscap SystemCapability.BarrierFree.Accessibility.Core 532 * @since 7 533 */ 534 type: EventType; 535 536 /** 537 * The type of the window change event. 538 * 539 * @syscap SystemCapability.BarrierFree.Accessibility.Core 540 * @since 7 541 */ 542 windowUpdateType?: WindowUpdateType; 543 544 /** 545 * The bundle name of the target application. 546 * 547 * @syscap SystemCapability.BarrierFree.Accessibility.Core 548 * @since 7 549 */ 550 bundleName: string; 551 552 /** 553 * The type of the event source component,such as button, chart. 554 * 555 * @syscap SystemCapability.BarrierFree.Accessibility.Core 556 * @since 7 557 */ 558 componentType?: string; 559 560 /** 561 * The page id of the event source. 562 * 563 * @syscap SystemCapability.BarrierFree.Accessibility.Core 564 * @since 7 565 */ 566 pageId?: number; 567 568 /** 569 * The accessibility event description. 570 * 571 * @syscap SystemCapability.BarrierFree.Accessibility.Core 572 * @since 7 573 */ 574 description?: string; 575 576 /** 577 * The action that triggers the accessibility event, for example, clicking or focusing a view. 578 * 579 * @syscap SystemCapability.BarrierFree.Accessibility.Core 580 * @since 7 581 */ 582 triggerAction: Action; 583 584 /** 585 * The movement step used for reading texts. 586 * 587 * @syscap SystemCapability.BarrierFree.Accessibility.Core 588 * @since 7 589 */ 590 textMoveUnit?: TextMoveUnit; 591 592 /** 593 * The content list. 594 * 595 * @syscap SystemCapability.BarrierFree.Accessibility.Core 596 * @since 7 597 */ 598 contents?: Array<string>; 599 600 /** 601 * The content changed before. 602 * 603 * @syscap SystemCapability.BarrierFree.Accessibility.Core 604 * @since 7 605 */ 606 lastContent?: string; 607 608 /** 609 * The start index of listed items on the screen. 610 * 611 * @syscap SystemCapability.BarrierFree.Accessibility.Core 612 * @since 7 613 */ 614 beginIndex?: number; 615 616 /** 617 * The index of the current item on the screen. 618 * 619 * @syscap SystemCapability.BarrierFree.Accessibility.Core 620 * @since 7 621 */ 622 currentIndex?: number; 623 624 /** 625 * The end index of listed items on the screen. 626 * 627 * @syscap SystemCapability.BarrierFree.Accessibility.Core 628 * @since 7 629 */ 630 endIndex?: number; 631 632 /** 633 * The total of the items, talkback used it when scroll. 634 * 635 * @syscap SystemCapability.BarrierFree.Accessibility.Core 636 * @since 7 637 */ 638 itemCount?: number; 639 } 640} 641export default accessibility; 642