• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 } from './basic';
17import { Callback } from './basic';
18
19/**
20 * Accessibility
21 * @name Accessibility
22 * @since 7
23 * @syscap SystemCapability.BarrierFree.Accessibility.Core
24 * @import basic,abilityInfo
25 */
26declare namespace accessibility {
27
28  /**
29   * The type of the Ability app.
30   * @syscap SystemCapability.BarrierFree.Accessibility.Core
31   * @since 7
32   */
33  type AbilityType = 'audible' | 'generic' | 'haptic' | 'spoken' | 'visual';
34
35  /**
36   * The action that the ability can execute.
37   * @syscap SystemCapability.BarrierFree.Accessibility.Core
38   * @since 7
39   */
40  type Action = 'accessibilityFocus' | 'clearAccessibilityFocus' | 'focus' | 'clearFocus' | 'clearSelection' |
41    'click' | 'longClick' | 'cut' | 'copy' | 'paste' | 'select' | 'setText' | 'delete' |
42    'scrollForward' | 'scrollBackward' | 'setSelection';
43
44  /**
45   * The type of the accessibility event.
46   * @note windowsChange
47   * @note windowContentChange
48   * @note windowStateChange
49   * @note announcement
50   * @note notificationChange
51   * @note textTraversedAtMove
52   * @syscap SystemCapability.BarrierFree.Accessibility.Core
53   * @since 7
54   */
55  type EventType = 'accessibilityFocus' | 'accessibilityFocusClear' |
56    'click' | 'longClick' | 'focus' | 'select' | 'hoverEnter' | 'hoverExit' |
57    'textUpdate' | 'textSelectionUpdate' | 'scroll';
58
59  /**
60   * The change type of the windowsChange event.
61   * @note It's used when received the {@code windowsChange} event.
62   * @syscap SystemCapability.BarrierFree.Accessibility.Core
63   * @since 7
64   */
65  type WindowUpdateType = 'add' | 'remove' | 'bounds' | 'active' | 'focus';
66
67  /**
68   * The type of the ability state.
69   * @syscap SystemCapability.BarrierFree.Accessibility.Core
70   * @since 7
71   */
72  type AbilityState = 'enable' | 'disable' | 'install';
73
74  /**
75   * The ability that accessibility subsystem support.
76   * @note touchExplorer: Describes the capability to talkback.
77   * magnification: Describes the capability to request to control the display magnification.
78   * gesturesSimulation: Describes the capability to request to simulate the gesture.
79   * windowContent: Describes the capability to search for the content of the active window.
80   * filterKeyEvents: Describes the capability to request to filter key events.
81   * fingerprintGesture: Describes the capability to request to fingerprint gesture.
82   * @syscap SystemCapability.BarrierFree.Accessibility.Core
83   * @since 7
84   */
85  type Capability = 'retrieve' | 'touchGuide' | 'keyEventObserver' | 'zoom' | 'gesture';
86
87  /**
88   * The granularity of text move.
89   * @note The granularity of text move.
90   * @syscap SystemCapability.BarrierFree.Accessibility.Core
91   * @since 7
92   */
93  type TextMoveUnit = 'char' | 'word' | 'line' | 'page' | 'paragraph';
94
95  /**
96   * Checks whether accessibility ability is enabled.
97   * @since 7
98   * @param callback Asynchronous callback interface.
99   * @syscap SystemCapability.BarrierFree.Accessibility.Core
100   * @return Returns {@code true} if the accessibility is enabled; returns {@code false} otherwise.
101  */
102  function isOpenAccessibility(callback: AsyncCallback<boolean>): void;
103  function isOpenAccessibility(): Promise<boolean>;
104
105  /**
106   * Checks touch browser ability (which is used by talkback) is enabled.
107   * @since 7
108   * @param callback Asynchronous callback interface.
109   * @syscap SystemCapability.BarrierFree.Accessibility.Vision
110   * @return Returns {@code true} if the touch browser is enabled; returns {@code false} otherwise.
111  */
112  function isOpenTouchGuide(callback: AsyncCallback<boolean>): void;
113  function isOpenTouchGuide(): Promise<boolean>;
114
115  /**
116   * Queries the list of accessibility abilities.
117   * @since 7
118   * @param abilityType The type of the accessibility ability. {@code AbilityType} eg.spoken
119   * @param stateType The state of the accessibility ability.  {@code AbilityState} eg.installed
120   * @syscap SystemCapability.BarrierFree.Accessibility.Core
121   * @return Returns the list of abilityInfos.
122  */
123  function getAbilityLists(abilityType: AbilityType, stateType: AbilityState,
124    callback: AsyncCallback<Array<AccessibilityAbilityInfo>>): void;
125  function getAbilityLists(abilityType: AbilityType,
126    stateType: AbilityState): Promise<Array<AccessibilityAbilityInfo>>;
127
128  /**
129   * Send accessibility Event.
130   * @since 7
131   * @param event The object of the accessibility {@code EventInfo} .
132   * @param callback Asynchronous callback interface.
133   * @syscap SystemCapability.BarrierFree.Accessibility.Core
134   * @return Returns {@code true} if success ; returns {@code false} otherwise.
135   */
136  function sendEvent(event: EventInfo, callback: AsyncCallback<void>): void;
137  function sendEvent(event: EventInfo): Promise<void>;
138
139  /**
140   * Register the observe of the accessibility state changed.
141   * @since 7
142   * @param type state event type.
143   * @param callback Asynchronous callback interface.
144   * @syscap SystemCapability.BarrierFree.Accessibility.Core
145   * @return Returns {@code true} if the register is success ; returns {@code false} otherwise.
146   */
147  function on(type: 'accessibilityStateChange', callback: Callback<boolean>): void;
148
149  /**
150   * Register the observe of the touchGuide state changed.
151   * @since 7
152   * @param type state event type.
153   * @param callback Asynchronous callback interface.
154   * @syscap SystemCapability.BarrierFree.Accessibility.Vision
155   * @return Returns {@code true} if the register is success ; returns {@code false} otherwise.
156   */
157  function on(type: 'touchGuideStateChange', callback: Callback<boolean>): void;
158
159  /**
160   * Deregister the observe of the accessibility state changed.
161   * @since 7
162   * @param type state event type
163   * @param callback Asynchronous callback interface.
164   * @syscap SystemCapability.BarrierFree.Accessibility.Core
165   * @return Returns {@code true} if the deregister is success ; returns {@code false} otherwise.
166   */
167  function off(type: 'accessibilityStateChange', callback?: Callback<boolean>): void;
168
169  /**
170   * Deregister the observe of the touchGuide state changed.
171   * @since 7
172   * @param type state event type
173   * @param callback Asynchronous callback interface.
174   * @return Returns {@code true} if the deregister is success ; returns {@code false} otherwise.
175   */
176   function off(type: 'touchGuideStateChange', callback?: Callback<boolean>): void;
177
178  /**
179   * Get the captions manager.
180   * @syscap SystemCapability.BarrierFree.Accessibility.Hearing
181   * @since 8
182   * @return Returns the captions manager.
183   */
184   function getCaptionsManager(): CaptionsManager;
185
186   /**
187    * Indicates the captions manager.
188    * @syscap SystemCapability.BarrierFree.Accessibility.Hearing
189    * @since 8
190    */
191   interface CaptionsManager {
192     /**
193      * Indicates whether captions are enabled.
194      */
195     enabled: boolean;
196     /**
197      * Indicates the style of captions.
198      */
199     style: CaptionsStyle;
200
201     /**
202      * Register the observe of the enable state.
203      */
204     on(type: 'enableChange', callback: Callback<boolean>): void;
205     /**
206      * Register the observer of the style.
207      */
208     on(type: 'styleChange', callback: Callback<CaptionsStyle>): void;
209     /**
210      * Deregister the observe of the enable state.
211      */
212     off(type: 'enableChange', callback?: Callback<boolean>): void;
213     /**
214      * Deregister the observer of the style.
215      */
216     off(type: 'styleChange', callback?: Callback<CaptionsStyle>): void;
217   }
218
219   /**
220    * Indicates the edge type of the captions font.
221    * @syscap SystemCapability.BarrierFree.Accessibility.Hearing
222    * @since 8
223    */
224   type CaptionsFontEdgeType = 'none' | 'raised' | 'depressed' | 'uniform' | 'dropShadow';
225   /**
226    * Indicates the font family of captions.
227    * @syscap SystemCapability.BarrierFree.Accessibility.Hearing
228    * @since 8
229    */
230   type CaptionsFontFamily = 'default' | 'monospacedSerif' | 'serif' |
231     'monospacedSansSerif' | 'sansSerif' | 'casual' | 'cursive' | 'smallCapitals';
232   /**
233    * Indicates the style of captions.
234    * @syscap SystemCapability.BarrierFree.Accessibility.Hearing
235    * @since 8
236    */
237   interface CaptionsStyle {
238     /**
239      * Indicates the font family of captions.
240      */
241     fontFamily: CaptionsFontFamily;
242     /**
243      * Indicates the font scaling of captions.
244      */
245     fontScale: number;
246     /**
247      * Indicates the font color of captions.
248      */
249     fontColor: number | string;
250     /**
251      * Indicates the edge type of the captions font.
252      */
253     fontEdgeType: CaptionsFontEdgeType;
254     /**
255      * Indicates the background color of captions.
256      */
257     backgroundColor: number | string;
258     /**
259      * Indicates the window color of captions.
260      */
261     windowColor: number | string;
262   }
263
264   /**
265    * Indicates the info of accessibility.
266    * @syscap SystemCapability.BarrierFree.Accessibility.Core
267    * @since 7
268    */
269  interface AccessibilityAbilityInfo {
270    /**
271     * The ability id.
272     * @since 7
273     */
274    readonly id: string;
275
276    /* The ability name.
277     * @since 7
278     */
279    readonly name: string;
280
281    /* The bundle name of the ability.
282     * @since 7
283     */
284    readonly bundleName: string;
285
286    /**
287     * The type of the ability.
288     * @since 7
289     */
290    readonly abilityTypes: Array<AbilityType>;
291
292    /**
293     * The capabilities of the ability.
294     * @since 7
295     */
296    readonly capabilities: Array<Capability>;
297
298    /**
299     * The description of the ability.
300     * @since 7
301     */
302    readonly description: string;
303
304    /**
305     * The events which the accessibility ability wants to observe.
306     * @since 7
307     */
308    readonly eventTypes: Array<EventType>;
309
310  }
311
312  /**
313    * Indicates the info of events.
314    * @syscap SystemCapability.BarrierFree.Accessibility.Core
315    * @since 7
316    */
317  class EventInfo {
318    constructor(jsonObject);
319    /**
320     * The type of an accessibility event.
321     * @since 7
322     */
323    type: EventType;
324
325    /**
326     * The type of the window change event.
327     * @since 7
328     */
329    windowUpdateType?: WindowUpdateType;
330
331    /**
332     * The bundle name of the target application.
333     * @since 7
334     */
335    bundleName: string;
336
337    /**
338     * The type of the event source component,such as button, chart.
339     * @since 7
340     */
341    componentType?: string;
342
343    /** The page id of the event source.
344     * @since 7
345     */
346    pageId ?: number;
347
348    /**
349     * The accessibility event description.
350     * @since 7
351     */
352    description?: string;
353
354    /**
355     * The action that triggers the accessibility event, for example, clicking or focusing a view.
356     * @since 7
357     */
358    triggerAction: Action;
359
360    /**
361     * The movement step used for reading texts.
362     * @since 7
363     */
364    textMoveUnit?: TextMoveUnit;
365
366    /**
367     * The content list.
368     * @note
369     * @since 7
370     */
371    contents?: Array<string>;
372
373    /**
374     * The content changed before.
375     * @since 7
376     */
377    lastContent?: string;
378
379    /**
380     * The start index of listed items on the screen.
381     * @since 7
382     */
383    beginIndex?: number;
384
385    /**
386     * The index of the current item on the screen.
387     * @since 7
388     */
389    currentIndex?: number;
390
391    /**
392     * The end index of listed items on the screen.
393     * @since 7
394     */
395    endIndex?: number;
396
397    /**
398     * The total of the items.
399     * @note talkback used it when scroll.
400     * @since 7
401     */
402    itemCount?: number;
403  }
404}
405export default accessibility;