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 { AsyncCallback } from "../basic"; 17import ExtensionContext from "./ExtensionContext"; 18import accessibility from "../@ohos.accessibility"; 19import { GesturePath } from "../@ohos.accessibility.GesturePath"; 20 21/** 22 * The accessibility extension context. Used to configure, query information, and inject gestures. 23 * 24 * @since 9 25 * @syscap SystemCapability.BarrierFree.Accessibility.Core 26 */ 27export default class AccessibilityExtensionContext extends ExtensionContext { 28 /** 29 * Set the name of the bundle name that is interested in sending the event. 30 * @param targetNames 31 * @throws { BusinessError } 401 - Input parameter error. 32 */ 33 setTargetBundleName(targetNames: Array<string>): Promise<void>; 34 setTargetBundleName(targetNames: Array<string>, callback: AsyncCallback<void>): void; 35 36 /** 37 * Get focus element. 38 * @param isAccessibilityFocus Indicates whether the acquired element has an accessibility focus. 39 * @throws { BusinessError } 9300003 - Do not have accessibility right for this operation. 40 */ 41 getFocusElement(isAccessibilityFocus?: boolean): Promise<AccessibilityElement>; 42 getFocusElement(callback: AsyncCallback<AccessibilityElement>): void; 43 getFocusElement(isAccessibilityFocus: boolean, callback: AsyncCallback<AccessibilityElement>): void; 44 45 /** 46 * Get window root element. 47 * @param windowId Indicates the window ID. 48 * @throws { BusinessError } 9300003 - Do not have accessibility right for this operation. 49 */ 50 getWindowRootElement(windowId?: number): Promise<AccessibilityElement>; 51 getWindowRootElement(callback: AsyncCallback<AccessibilityElement>): void; 52 getWindowRootElement(windowId: number, callback: AsyncCallback<AccessibilityElement>): void; 53 54 /** 55 * Get window list. 56 * @param displayId Indicates the display ID. 57 * @throws { BusinessError } 9300003 - Do not have accessibility right for this operation. 58 */ 59 getWindows(displayId?: number): Promise<Array<AccessibilityElement>>; 60 getWindows(callback: AsyncCallback<Array<AccessibilityElement>>): void; 61 getWindows(displayId: number, callback: AsyncCallback<Array<AccessibilityElement>>): void; 62 63 /** 64 * Inject gesture path events. 65 * @param gesturePath Indicates the gesture path. 66 * @throws { BusinessError } 401 - Input parameter error. 67 * @throws { BusinessError } 9300003 - Do not have accessibility right for this operation. 68 */ 69 injectGesture(gesturePath: GesturePath): Promise<void>; 70 injectGesture(gesturePath: GesturePath, callback: AsyncCallback<void>): void; 71} 72 73/** 74 * Indicates an accessibility element. 75 * 76 * Supports querying element attributes, requesting execution actions, and finding child elements by condition. 77 * @since 9 78 * @syscap SystemCapability.BarrierFree.Accessibility.Core 79 */ 80declare interface AccessibilityElement { 81 /** 82 * Get a list of attribute names. 83 */ 84 attributeNames<T extends keyof ElementAttributeValues>(): Promise<Array<T>>; 85 attributeNames<T extends keyof ElementAttributeValues>(callback: AsyncCallback<Array<T>>): void; 86 87 /** 88 * Get the value of an attribute. 89 * @param attributeName Indicates the attribute name. 90 * @throws { BusinessError } 401 - Input parameter error. 91 * @throws { BusinessError } 9300004 - This property does not exist. 92 */ 93 attributeValue<T extends keyof ElementAttributeValues>(attributeName: T): Promise<ElementAttributeValues[T]>; 94 attributeValue<T extends keyof ElementAttributeValues>(attributeName: T, 95 callback: AsyncCallback<ElementAttributeValues[T]>): void; 96 97 /** 98 * Get a list of supported actions. 99 */ 100 actionNames(): Promise<Array<string>>; 101 actionNames(callback: AsyncCallback<Array<string>>): void; 102 103 /** 104 * Perform the specified action. 105 * @param actionName Indicates the action name. 106 * @param parameters Indicates the parameters needed to execute the action. 107 * @throws { BusinessError } 401 - Input parameter error. 108 * @throws { BusinessError } 9300005 - This action is not supported. 109 */ 110 performAction(actionName: string, parameters?: object): Promise<void>; 111 performAction(actionName: string, callback: AsyncCallback<void>): void; 112 performAction(actionName: string, parameters: object, callback: AsyncCallback<void>): void; 113 114 /** 115 * Find elements that match the condition. 116 * @param type The type of query condition is content. 117 * @param condition Indicates the specific content to be queried. 118 * @throws { BusinessError } 401 - Input parameter error. 119 */ 120 findElement(type: 'content', condition: string): Promise<Array<AccessibilityElement>>; 121 findElement(type: 'content', condition: string, callback: AsyncCallback<Array<AccessibilityElement>>): void 122 123 /** 124 * Find elements that match the condition. 125 * @param type The type of query condition is focus type. 126 * @param condition Indicates the type of focus to query. 127 * @throws { BusinessError } 401 - Input parameter error. 128 */ 129 findElement(type: 'focusType', condition: FocusType): Promise<AccessibilityElement>; 130 findElement(type: 'focusType', condition: FocusType, callback: AsyncCallback<AccessibilityElement>): void 131 132 /** 133 * Find elements that match the condition. 134 * @param type The type of query condition is focus direction. 135 * @param condition Indicates the direction of search focus to query. 136 * @throws { BusinessError } 401 - Input parameter error. 137 */ 138 findElement(type: 'focusDirection', condition: FocusDirection): Promise<AccessibilityElement>; 139 findElement(type: 'focusDirection', condition: FocusDirection, callback: AsyncCallback<AccessibilityElement>): void 140} 141 142/** 143 * Indicates the possible attributes of the element and the type of the attribute value. 144 * @since 9 145 * @syscap SystemCapability.BarrierFree.Accessibility.Core 146 */ 147type ElementAttributeValues = { 148 /** 149 * Indicates accessibility focus state. 150 */ 151 'accessibilityFocused': boolean; 152 /** 153 * Indicates the bundle name to which it belongs. 154 */ 155 'bundleName': string; 156 /** 157 * Indicates whether the element is checkable. 158 */ 159 'checkable': boolean; 160 /** 161 * Indicates whether the element is checked. 162 */ 163 'checked': boolean; 164 /** 165 * Indicates all child elements. 166 */ 167 'children': Array<AccessibilityElement>; 168 /** 169 * Indicates whether the element is clickable. 170 */ 171 'clickable': boolean; 172 /** 173 * Indicates the component ID to which the element belongs. 174 */ 175 'componentId': number; 176 /** 177 * Indicates the component type to which the element belongs. 178 */ 179 'componentType': string; 180 /** 181 * Indicates the content. 182 */ 183 'contents': Array<string>; 184 /** 185 * Indicates the index of the current item. 186 */ 187 'currentIndex': number; 188 /** 189 * Indicates the description of the element. 190 */ 191 'description': string; 192 /** 193 * Indicates whether the element is editable. 194 */ 195 'editable': boolean; 196 /** 197 * Indicates the list index of the last item displayed on the screen. 198 */ 199 'endIndex': number; 200 /** 201 * Indicates the string of error state. 202 */ 203 'error': string; 204 /** 205 * Indicates whether the element is focusable. 206 */ 207 'focusable': boolean; 208 /** 209 * Indicates the hint text. 210 */ 211 'hintText': string; 212 /** 213 * Indicates the type of input text. 214 */ 215 'inputType': number; 216 /** 217 * Indicates the inspector key. 218 */ 219 'inspectorKey': string 220 /** 221 * Indicates whether the element is active or not. 222 */ 223 'isActive': boolean; 224 /** 225 * Indicates whether the element is enable or not. 226 */ 227 'isEnable': boolean; 228 /** 229 * Indicates whether the element is hint state or not. 230 */ 231 'isHint': boolean; 232 /** 233 * Indicates whether the element is focused or not. 234 */ 235 'isFocused': boolean; 236 /** 237 * Indicates whether the element is password or not. 238 */ 239 'isPassword': boolean; 240 /** 241 * Indicates whether the element is visible or not. 242 */ 243 'isVisible': boolean; 244 /** 245 * Indicates the total count of the items. 246 */ 247 'itemCount': number; 248 /** 249 * Indicates the last content. 250 */ 251 'lastContent': string; 252 /** 253 * Indicates the display layer of the element. 254 */ 255 'layer': number; 256 /** 257 * Indicates whether the element is long clickable. 258 */ 259 'longClickable': boolean; 260 /** 261 * Indicates the page id. 262 */ 263 'pageId': number; 264 /** 265 * Indicates the parent of the element. 266 */ 267 'parent': AccessibilityElement; 268 /** 269 * Indicates whether the element supports multiple lines of text. 270 */ 271 'pluralLineSupported': boolean; 272 /** 273 * Indicates the area of the element. 274 */ 275 'rect': Rect; 276 /** 277 * Indicates the resource name of the element. 278 */ 279 'resourceName': string; 280 /** 281 * Indicates the root element of the window element. 282 */ 283 'rootElement': AccessibilityElement; 284 /** 285 * Indicates the display area of the element. 286 */ 287 'screenRect': Rect; 288 /** 289 * Indicates whether the element is scrollable. 290 */ 291 'scrollable': boolean; 292 /** 293 * Indicates whether the element is selected. 294 */ 295 'selected': boolean; 296 /** 297 * Indicates the list index of the first item displayed on the screen. 298 */ 299 'startIndex': number; 300 /** 301 * Indicates the text of the element. 302 */ 303 'text': string; 304 /** 305 * Indicates the maximum length limit of the element text. 306 */ 307 'textLengthLimit': number; 308 /** 309 * Indicates the unit of movement of the element text as it is read. 310 */ 311 'textMoveUnit': accessibility.TextMoveUnit; 312 /** 313 * Indicates the action that triggered the element event. 314 */ 315 'triggerAction': accessibility.Action; 316 /** 317 * Indicates the window type of the element. 318 */ 319 'type': WindowType; 320 /** 321 * Indicates the maximum value. 322 */ 323 'valueMax': number; 324 /** 325 * Indicates the minimum value. 326 */ 327 'valueMin': number; 328 /** 329 * Indicates the current value. 330 */ 331 'valueNow': number; 332 /** 333 * Indicates the window id. 334 */ 335 'windowId': number; 336} 337 338/** 339* Indicates the direction of the search focus. 340 * @since 9 341 * @syscap SystemCapability.BarrierFree.Accessibility.Core 342 */ 343type FocusDirection = 'up' | 'down' | 'left' | 'right' | 'forward' | 'backward'; 344 345/** 346 * Indicates the type of the focus. 347 * @since 9 348 * @syscap SystemCapability.BarrierFree.Accessibility.Core 349 */ 350type FocusType = 'accessibility' | 'normal'; 351 352/** 353 * Indicates the type of the window. 354 * @since 9 355 * @syscap SystemCapability.BarrierFree.Accessibility.Core 356 */ 357type WindowType = 'application' | 'system'; 358 359/** 360 * Indicates rectangle. 361 * @since 9 362 * @syscap SystemCapability.BarrierFree.Accessibility.Core 363 */ 364interface Rect { 365 left: number; 366 top: number; 367 width: number; 368 height: number; 369}