• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022-2024 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 
16 #ifndef ACCESSIBILITY_EVENT_INFO_H
17 #define ACCESSIBILITY_EVENT_INFO_H
18 
19 #include <vector>
20 #include "accessibility_def.h"
21 #include "accessibility_element_info.h"
22 
23 namespace OHOS {
24 namespace Accessibility {
25 /*
26 * The class supply the content information about the event.
27 * The SetXxx() API is almost supplied to ACE to set the information.
28 * Parts of SetXxx() API is called by AAMS, such as: SetConnectId().
29 * The GetXxx() API is almost supplied to AA to get the information.
30 */
31 class AccessibilityMemo {
32 public:
33     /**
34      * @brief Construct
35      * @since 3
36      * @sysCap Accessibility
37      */
AccessibilityMemo()38     AccessibilityMemo() {}
39 
40     /**
41      * @brief Set the component of the event related.
42      * @param componentId The id of component.
43      * @since 3
44      * @sysCap Accessibility
45      */
46     void SetSource(const int64_t componentId);
47 
48     /**
49      * @brief Gets the view(component) ID associated with the accessibility event.
50      * @return The view(component) ID associated with the accessibility event.
51      * @since 3
52      * @sysCap Accessibility
53      */
54     int64_t GetViewId() const;
55 
56     /**
57      * @brief Gets the accessibility ID of the component.
58      * @return The accessibility ID of the component.
59      * @since 3
60      * @sysCap Accessibility
61      */
62     int64_t GetAccessibilityId() const;
63 
64     /**
65      * @brief Set the window ID associated with the accessibility event.
66      * @param windowId The window ID associated with the accessibility event.
67      * @since 3
68      * @sysCap Accessibility
69      */
70     void SetWindowId(const int32_t windowId);
71 
72     /**
73      * @brief Gets the window ID associated with the accessibility event.
74      * @return The window ID associated with the accessibility event.
75      * @since 3
76      * @sysCap Accessibility
77      */
78 
79     int32_t GetWindowId() const;
80 
81     /**
82      * @brief Gets the current index of listed items or text position associated with the current event.
83      * @return The current index of listed items or text position associated with the current event.
84      * @since 3
85      * @sysCap Accessibility
86      */
87     int32_t GetCurrentIndex() const;
88 
89     /**
90      * @brief Sets the current index of listed items or text position associated with the current event.
91      * @param index The current index of listed items or text position associated with the current event.
92      * @since 3
93      * @sysCap Accessibility
94      */
95     void SetCurrentIndex(const int32_t index);
96 
97     /**
98      * @brief Gets the start index of listed items on the screen.
99      * @return The start index of listed items. It is unique value for the listed items.
100      * @since 3
101      * @sysCap Accessibility
102      */
103     int32_t GetBeginIndex() const;
104 
105     /**
106      * @brief Sets the start index of listed items on the screen.
107      * @param index The start index of listed items. It is unique value for the listed items.
108      * @since 3
109      * @sysCap Accessibility
110      */
111     void SetBeginIndex(const int32_t index);
112 
113     /**
114      * @brief Gets the number items on the screen.
115      * @return The number of items.
116      * @since 3
117      * @sysCap Accessibility
118      */
119     int32_t GetItemCounts() const;
120 
121     /**
122      * @brief Sets the number items on the screen.
123      * @param ItemCounts The number of items.
124      * @since 3
125      * @sysCap Accessibility
126      */
127     void SetItemCounts(const int32_t itemCounts);
128 
129     /**
130      * @brief Gets the end index of listed items on the screen.
131      * @return The end index of listed items on the screen.
132      * @since 3
133      * @sysCap Accessibility
134      */
135     int32_t GetEndIndex() const;
136 
137     /**
138      * @brief Sets the end index of listed items on the screen.
139      * @param index The end index of listed items on the screen.
140      * @since 3
141      * @sysCap Accessibility
142      */
143     void SetEndIndex(const int32_t index);
144 
145     /**
146      * @brief Gets the class(component type) name.
147      * @return The class(component type) name.
148      * @since 3
149      * @sysCap Accessibility
150      */
151     const std::string &GetComponentType() const;
152 
153     /**
154      * @brief Sets the class(component type) name.
155      * @param className The class(component type) name.
156      * @since 3
157      * @sysCap Accessibility
158      */
159     void SetComponentType(const std::string &className);
160 
161     /**
162      * @brief Gets the before text changed of the component.
163      * @return The before text changed of the component.
164      * @since 3
165      * @sysCap Accessibility
166      */
167     const std::string &GetBeforeText() const;
168 
169     /**
170      * @brief Set the before text changed of the component.
171      * @param beforeText The before text changed of the component.
172      * @since 3
173      * @sysCap Accessibility
174      */
175     void SetBeforeText(const std::string &beforeText);
176 
177     /**
178      * @brief Adds an text to the content list.
179      * @param content Indicates the text to add.
180      * @since 3
181      * @sysCap Accessibility
182      */
183     void AddContent(const std::string &content);
184 
185     /**
186      * @brief Get the content list in the event.
187      * @return The content list in the event.
188      * @since 3
189      * @sysCap Accessibility
190      */
191     const std::vector<std::string> &GetContentList() const;
192 
193     /**
194      * @brief Gets the last content of the component(The text of changed after).
195      * @return The last content of the component(The text of changed after).
196      * @since 3
197      * @sysCap Accessibility
198      */
199     const std::string &GetLatestContent() const;
200 
201     /**
202      * @brief Sets the last content of the component.
203      * @param content The last content of component.
204      * @since 3
205      * @sysCap Accessibility
206      */
207     void SetLatestContent(const std::string &content);
208 
209     /**
210      * @brief Gets the accessibility event description.
211      * @return The accessibility event description
212      * @since 3
213      * @sysCap Accessibility
214      */
215     const std::string &GetDescription() const;
216 
217     /**
218      * @brief Sets the accessibility event description.
219      * @param contentDescription The accessibility event description
220      * @since 3
221      * @sysCap Accessibility
222      */
223     void SetDescription(const std::string &contentDescription);
224 
225 protected:
226     int64_t componentId_ = 0;
227     int32_t windowId_ = 0;
228     int32_t currentIndex_ = 0;
229     int32_t beginIndex_ = 0;
230     int32_t endIndex_ = 0;
231     std::vector<std::string> contents_ {};
232     std::string componentType_ = "";
233     std::string description_ = "";
234     std::string beforeText_ = "";
235     std::string latestContent_ = "";
236     int64_t elementId_ = 0;
237     int32_t itemCounts_ = 0;
238 };
239 
240 /*
241 * The class define the event types and supply the api to
242 * get/set the property of event. and it triggered by UI
243 * changed and sent to AA. According to the event property,
244 * AA can get event properties, such as: action triggered
245 * the event and the source.
246 */
247 class AccessibilityEventInfo : public AccessibilityMemo {
248 public:
249     /**
250      * @brief Construct
251      * @since 3
252      * @sysCap Accessibility
253      */
AccessibilityEventInfo()254     AccessibilityEventInfo() {}
255 
256     /**
257      * @brief Construct
258      * @param eventType the type of event info
259      * @since 3
260      * @sysCap Accessibility
261      */
262     AccessibilityEventInfo(EventType eventType);
263 
264     /**
265      * @brief Construct
266      * @param windowId The id of window
267      * @param windowChangeTypes the window change type
268      * @since 3
269      * @sysCap Accessibility
270      */
271     AccessibilityEventInfo(int32_t windowId, WindowUpdateType windowChangeTypes);
272 
273     /**
274      * @brief Get the type of the accessibility event.
275      * @return The type of the accessibility event.
276      * @since 3
277      * @sysCap Accessibility
278      */
279     EventType GetEventType() const;
280 
281     /**
282      * @brief Get the window content changed types
283      * @return The window content changed types. Refer to "WindowsContentChangeTypes"
284      * @since 3
285      * * @sysCap Accessibility
286      */
287     WindowsContentChangeTypes GetWindowContentChangeTypes() const;
288 
289     /**
290      * @brief Set the window content changed types
291      * @param changeTypes The window content changed types. Refer to "WindowsContentChangeTypes"
292      * @since 3
293      * @sysCap Accessibility
294      */
295     void SetWindowContentChangeTypes(const WindowsContentChangeTypes changeTypes);
296 
297     /**
298      * @brief Get the window changed types
299      * @return The window changed types.refer to WindowUpdateType
300      * @since 3
301      * @sysCap Accessibility
302      */
303     WindowUpdateType GetWindowChangeTypes() const;
304 
305     /**
306      * @brief Set the window changed types
307      * @param changeTypes The window changed types.refer to WindowUpdateType
308      * @since 3
309      * @sysCap Accessibility
310      */
311     void SetWindowChangeTypes(const WindowUpdateType changeTypes);
312 
313     /**
314      * @brief Sets the type of an accessibility event.
315      * @note It is same to setAccessibilityEventType​(int32_t accessibilityEventType)
316      * @param eventType The type of an accessibility event. Refer to "EventType"
317      * @since 3
318      * @sysCap Accessibility
319      */
320     void SetEventType(const EventType eventType);
321 
322     /**
323      * @brief AA get the time of accessibility event is sent from ASAC.
324      * @return The time of accessibility event is sent from ASAC
325      * @since 3
326      * @sysCap Accessibility
327      */
328     int64_t GetTimeStamp() const;
329 
330     /**
331      * @brief ASAC set the time of accessibility is sent to AA
332      * @param timeStamp The time of accessibility event is sent from ASAC
333      * @since 3
334      * @sysCap Accessibility
335      */
336     void SetTimeStamp(int64_t timeStamp);  // Remained:for send event timestamp
337 
338     /**
339      * @brief AA get the resourceId of event is sent from ASAC.
340      * @return The resourceId of event is sent from ASAC
341      * @since 16
342      * @sysCap Accessibility
343      */
344     uint32_t GetResourceId() const;
345 
346     /**
347      * @brief ASAC set the resourceId of is sent to AA
348      * @param resourceId The resourceId of event is sent from ASAC
349      * @since 16
350      * @sysCap Accessibility
351      */
352     void SetResourceId(const uint32_t &resourceId);
353 
354      /**
355      * @brief AA get the moduleName of event is sent from ASAC.
356      * @return The moduleName of event is sent from ASAC
357      * @since 16
358      * @sysCap Accessibility
359      */
360     const std::string &GetResourceModuleName() const;
361 
362     /**
363      * @brief ASAC set the moduleName of is sent to AA
364      * @param moduleName The moduleName of event is sent from ASAC
365      * @since 16
366      * @sysCap Accessibility
367      */
368     void SetResourceModuleName(const std::string &moduleName);
369 
370      /**
371      * @brief AA get the bundleName of event is sent from ASAC.
372      * @return The bundleName of event is sent from ASAC
373      * @since 16
374      * @sysCap Accessibility
375      */
376     const std::string &GetResourceBundleName() const;
377 
378     /**
379      * @brief ASAC set the bundleName of is sent to AA
380      * @param bundleName The bundleName of event is sent from ASAC
381      * @since 16
382      * @sysCap Accessibility
383      */
384     void SetResourceBundleName(const std::string &bundleName);
385 
386     /**
387      * @brief AA get the resourceParams of event is send from ASAC.
388      * @return The resourceParams of event is send from ASAC
389      * @since 16
390      * @sysCap Accessibility
391      */
392     const std::vector<std::tuple<int32_t, std::string>> &GetResourceParams() const;
393 
394     /**
395      * @brief ASAC set the resourceParams of is send to ASAC.
396      * @return resourceParams The resourceParams of event is send from ASAC
397      * @since 16
398      * @sysCap Accessibility
399      */
400     void SetResourceParams(const std::vector<std::tuple<int32_t, std::string>> &resourceParams);
401 
402     /**
403      * @brief Gets the bundle name of the event source, that is, the bundle name of the target application.
404      * @return Returns the bundle name of the event source.
405      * @since 16
406      * @sysCap Accessibility
407      */
408     const std::string &GetBundleName() const;
409 
410     /**
411      * @brief Set the bundle name of the event source, that is, the bundle name of the target application.
412      * @param bundleName The bundle name of the event source.
413      * @since 3
414      * @sysCap Accessibility
415      */
416     void SetBundleName(const std::string &bundleName);
417 
418     /**
419      * @brief Get the notification content of the event source.
420      * @return Return the notification content of the event source.
421      * @since 3
422      * @sysCap Accessibility
423      */
424     const std::string &GetNotificationContent() const;
425 
426     /**
427      * @brief Set the notification content of the event source.
428      * @param notificationContent The notification content of the event source.
429      * @since 3
430      * @sysCap Accessibility
431      */
432     void SetNotificationContent(const std::string &notificationContent);
433 
434     /**
435      * @brief Set the move granularity of the text
436      * @param granularity The move granularity of the text. Refer to "AccessibilityElementInfo.TextMoveUnit"
437      * @since 3
438      * @sysCap Accessibility
439      */
440     void SetTextMovementStep(const TextMoveUnit granularity);
441 
442     /**
443      * @brief Get the move granularity of the text
444      * @return The move granularity of the text. Refer to "AccessibilityElementInfo.TextMoveUnit"
445      * @since 3
446      * @sysCap Accessibility
447      */
448     TextMoveUnit GetTextMovementStep() const;
449 
450     /**
451      * @brief Sets the action that triggers the accessibility event.
452      * @param action The operation of the event. Refer to "AccessibilityElementInfo.ActionType"
453      * @since 3
454      * @sysCap Accessibility
455      */
456     void SetTriggerAction(const ActionType action);
457 
458     /**
459      * @brief Gets the action that triggers the accessibility event.
460      * @return The operation of the event. Refer to "AccessibilityElementInfo.ActionType"
461      * @since 3
462      * @sysCap Accessibility
463      */
464     ActionType GetTriggerAction() const;
465 
466     /**
467      * @brief Set the information of accessibility event of [TYPE_NOTIFICATION_UPDATE_EVENT]
468      * @param category Refer to [NotificationCategory], It maybe changed from APP
469      * @since 3
470      * @sysCap Accessibility
471      */
472     void SetNotificationInfo(const NotificationCategory category);
473 
474     /**
475      * @brief Get the information of accessibility event of [TYPE_NOTIFICATION_UPDATE_EVENT]
476      * @return Refer to [NotificationCategory], It maybe changed from APP
477      * @since 3
478      * @sysCap Accessibility
479      */
480     NotificationCategory GetNotificationInfo() const;
481 
482     /**
483      * @brief Set the customize gesture type of accessibility event of [TYPE_GESTURE_EVENT]
484      * @param category Refer to [GestureType], It maybe changed from APP
485      * @since 3
486      * @sysCap Accessibility
487      */
488     void SetGestureType(const GestureType gestureType);
489 
490     /**
491      * @brief Get the customize gesture type of accessibility event of [TYPE_GESTURE_EVENT]
492      * @return Refer to [GestureType], It maybe changed from APP
493      * @since 3
494      * @sysCap Accessibility
495      */
496     GestureType GetGestureType() const;
497 
498     /**
499      * @brief Set the page ID associated with the accessibility event.
500      * @param pageId The page ID associated with the accessibility event.
501      * @since 3
502      * @sysCap Accessibility
503      */
504     void SetPageId(const int32_t pageId);
505 
506     /**
507      * @brief Gets the page ID associated with the accessibility event.
508      * @return The page ID associated with the accessibility event.
509      * @since 3
510      * @sysCap Accessibility
511      */
512     int32_t GetPageId() const;
513 
514     /**
515      * @brief Set the element info associated with the accessibility event.
516      * @param elementInfo The element info associated with the accessibility event.
517      * @since 12
518      * @sysCap Accessibility
519      */
520     void SetElementInfo(const AccessibilityElementInfo &elementInfo);
521 
522     /**
523      * @brief Get the element info pointer associated with the accessibility event.
524      * @return The element info associated with the accessibility event.
525      * @since 12
526      * @sysCap Accessibility
527      */
528     const AccessibilityElementInfo &GetElementInfo() const;
529 
530     /**
531      * @brief Get the text to announce.
532      * @return Return the text to announce.
533      * @since 12
534      * @sysCap Accessibility
535      */
536     const std::string &GetTextAnnouncedForAccessibility() const;
537 
538     /**
539      * @brief Set the text to announce of the event.
540      * @param textAnnouncedForAccessibility The text to announce.
541      * @since 12
542      * @sysCap Accessibility
543      */
544     void SetTextAnnouncedForAccessibility(const std::string &textAnnouncedForAccessibility);
545 
546     /**
547      * @brief Get the inspectorKey.
548      * @return Return the inspectorKey.
549      * @since 12
550      * @sysCap Accessibility
551      */
552     const std::string &GetInspectorKey() const;
553 
554     /**
555      * @brief Set the inspectorKey of the event.
556      * @param inspectorKey The inspectorKey.
557      * @since 12
558      * @sysCap Accessibility
559      */
560     void SetInspectorKey(const std::string &inspectorKey);
561 
562     /**
563      * @brief Set the request focus elementId.
564      * @param requestFocusElementId The elementId to focus.
565      * @since 12
566      * @sysCap Accessibility
567      */
568     void SetRequestFocusElementId(const int32_t requestFocusElementId);
569 
570     /**
571      * @brief Gets the request focus elementId.
572      * @return The elementId to focus.
573      * @since 12
574      * @sysCap Accessibility
575      */
576     int32_t GetRequestFocusElementId() const;
577 
578     void SetElementMainWindowId(const int32_t windowId);
579 
580 protected:
581     EventType eventType_ = TYPE_VIEW_INVALID;
582     std::string bundleName_ = "";
583     ActionType triggerAction_ = ACCESSIBILITY_ACTION_INVALID;
584     int64_t timeStamp_ = 0;
585     TextMoveUnit textMoveStep_ = STEP_CHARACTER;
586     WindowsContentChangeTypes windowContentChangeTypes_ = CONTENT_CHANGE_TYPE_INVALID;
587     WindowUpdateType windowChangeTypes_ = WINDOW_UPDATE_INVALID;
588     GestureType gestureType_ = GESTURE_INVALID;
589     NotificationCategory category_ = CATEGORY_INVALID;
590     int32_t pageId_ = 0;
591     std::string notificationContent_ = "";
592     AccessibilityElementInfo elementInfo_ {};
593     std::string textAnnouncedForAccessibility_ = "";
594     std::string inspectorKey_ = "";
595     int32_t requestFocusElementId_ = -1;
596     uint32_t resourceId_ = 0;
597     std::string resourceModuleName_ = "";
598     std::string resourceBundleName_ = "";
599     std::vector<std::tuple<int32_t, std::string>> resourceParams_ {};
600 };
601 } // namespace Accessibility
602 } // namespace OHOS
603 #endif // ACCESSIBILITY_EVENT_INFO_H
604