• 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 class ExtraEventInfo {
241 public:
242     /**
243      * @brief Construct
244      */
ExtraEventInfo()245     ExtraEventInfo() {}
246 
247     /**
248      * @brief Construct
249      * @param extraEventValueStr The map of extraEvent.
250      * @sysCap Accessibility
251      */
252     ExtraEventInfo(const std::map<std::string, std::string> extraEventValueStr);
253 
254     /**
255      * @brief Copy the ExtraEventInfo
256      * @param keyStr The key of extraEventValueStr.
257      * @param valueStr The val of extraEventValueStr.
258      * @sysCap Accessibility
259      */
260     RetError SetExtraEventInfo(const std::string keyStr, const std::string valueStr);
261 
262     /**
263      * @brief Gets the map of extraEventValueStr.
264      * @return The extraEventValueStr map.
265      * @sysCap Accessibility
266      */
267     const std::map<std::string, std::string> &GetExtraEventInfoValueStr() const;
268 
269 protected:
270     std::map<std::string, std::string> extraEventValueStr_ = {};
271 };
272 
273 /*
274 * The class define the event types and supply the api to
275 * get/set the property of event. and it triggered by UI
276 * changed and sent to AA. According to the event property,
277 * AA can get event properties, such as: action triggered
278 * the event and the source.
279 */
280 class AccessibilityEventInfo : public AccessibilityMemo {
281 public:
282     /**
283      * @brief Construct
284      * @since 3
285      * @sysCap Accessibility
286      */
AccessibilityEventInfo()287     AccessibilityEventInfo() {}
288 
289     /**
290      * @brief Construct
291      * @param eventType the type of event info
292      * @since 3
293      * @sysCap Accessibility
294      */
295     AccessibilityEventInfo(EventType eventType);
296 
297     /**
298      * @brief Construct
299      * @param windowId The id of window
300      * @param windowChangeTypes the window change type
301      * @since 3
302      * @sysCap Accessibility
303      */
304     AccessibilityEventInfo(int32_t windowId, WindowUpdateType windowChangeTypes);
305 
306     /**
307      * @brief Get the type of the accessibility event.
308      * @return The type of the accessibility event.
309      * @since 3
310      * @sysCap Accessibility
311      */
312     EventType GetEventType() const;
313 
314     /**
315      * @brief Get the window content changed types
316      * @return The window content changed types. Refer to "WindowsContentChangeTypes"
317      * @since 3
318      * * @sysCap Accessibility
319      */
320     WindowsContentChangeTypes GetWindowContentChangeTypes() const;
321 
322     /**
323      * @brief Set the window content changed types
324      * @param changeTypes The window content changed types. Refer to "WindowsContentChangeTypes"
325      * @since 3
326      * @sysCap Accessibility
327      */
328     void SetWindowContentChangeTypes(const WindowsContentChangeTypes changeTypes);
329 
330     /**
331      * @brief Get the window changed types
332      * @return The window changed types.refer to WindowUpdateType
333      * @since 3
334      * @sysCap Accessibility
335      */
336     WindowUpdateType GetWindowChangeTypes() const;
337 
338     /**
339      * @brief Set the window changed types
340      * @param changeTypes The window changed types.refer to WindowUpdateType
341      * @since 3
342      * @sysCap Accessibility
343      */
344     void SetWindowChangeTypes(const WindowUpdateType changeTypes);
345 
346     /**
347      * @brief Sets the type of an accessibility event.
348      * @note It is same to setAccessibilityEventType​(int32_t accessibilityEventType)
349      * @param eventType The type of an accessibility event. Refer to "EventType"
350      * @since 3
351      * @sysCap Accessibility
352      */
353     void SetEventType(const EventType eventType);
354 
355     /**
356      * @brief AA get the time of accessibility event is sent from ASAC.
357      * @return The time of accessibility event is sent from ASAC
358      * @since 3
359      * @sysCap Accessibility
360      */
361     int64_t GetTimeStamp() const;
362 
363     /**
364      * @brief ASAC set the time of accessibility is sent to AA
365      * @param timeStamp The time of accessibility event is sent from ASAC
366      * @since 3
367      * @sysCap Accessibility
368      */
369     void SetTimeStamp(int64_t timeStamp);  // Remained:for send event timestamp
370 
371     /**
372      * @brief AA get the resourceId of event is sent from ASAC.
373      * @return The resourceId of event is sent from ASAC
374      * @since 3
375      * @sysCap Accessibility
376      */
377     uint32_t GetResourceId() const;
378 
379     /**
380      * @brief ASAC set the resourceId of is sent to AA
381      * @param resourceId The resourceId of event is sent from ASAC
382      * @since 3
383      * @sysCap Accessibility
384      */
385     void SetResourceId(const uint32_t &resourceId);
386 
387      /**
388      * @brief AA get the moduleName of event is sent from ASAC.
389      * @return The moduleName of event is sent from ASAC
390      * @since 3
391      * @sysCap Accessibility
392      */
393     const std::string &GetResourceModuleName() const;
394 
395     /**
396      * @brief ASAC set the moduleName of is sent to AA
397      * @param moduleName The moduleName of event is sent from ASAC
398      * @since 3
399      * @sysCap Accessibility
400      */
401     void SetResourceModuleName(const std::string &moduleName);
402 
403      /**
404      * @brief AA get the bundleName of event is sent from ASAC.
405      * @return The bundleName of event is sent from ASAC
406      * @since 3
407      * @sysCap Accessibility
408      */
409     const std::string &GetResourceBundleName() const;
410 
411     /**
412      * @brief ASAC set the bundleName of is sent to AA
413      * @param bundleName The bundleName of event is sent from ASAC
414      * @since 3
415      * @sysCap Accessibility
416      */
417     void SetResourceBundleName(const std::string &bundleName);
418 
419     /**
420      * @brief Gets the bundle name of the event source, that is, the bundle name of the target application.
421      * @return Returns the bundle name of the event source.
422      * @since 3
423      * @sysCap Accessibility
424      */
425     const std::string &GetBundleName() const;
426 
427     /**
428      * @brief Set the bundle name of the event source, that is, the bundle name of the target application.
429      * @param bundleName The bundle name of the event source.
430      * @since 3
431      * @sysCap Accessibility
432      */
433     void SetBundleName(const std::string &bundleName);
434 
435     /**
436      * @brief Get the notification content of the event source.
437      * @return Return the notification content of the event source.
438      * @since 3
439      * @sysCap Accessibility
440      */
441     const std::string &GetNotificationContent() const;
442 
443     /**
444      * @brief Set the notification content of the event source.
445      * @param notificationContent The notification content of the event source.
446      * @since 3
447      * @sysCap Accessibility
448      */
449     void SetNotificationContent(const std::string &notificationContent);
450 
451     /**
452      * @brief Set the move granularity of the text
453      * @param granularity The move granularity of the text. Refer to "AccessibilityElementInfo.TextMoveUnit"
454      * @since 3
455      * @sysCap Accessibility
456      */
457     void SetTextMovementStep(const TextMoveUnit granularity);
458 
459     /**
460      * @brief Get the move granularity of the text
461      * @return The move granularity of the text. Refer to "AccessibilityElementInfo.TextMoveUnit"
462      * @since 3
463      * @sysCap Accessibility
464      */
465     TextMoveUnit GetTextMovementStep() const;
466 
467     /**
468      * @brief Sets the action that triggers the accessibility event.
469      * @param action The operation of the event. Refer to "AccessibilityElementInfo.ActionType"
470      * @since 3
471      * @sysCap Accessibility
472      */
473     void SetTriggerAction(const ActionType action);
474 
475     /**
476      * @brief Gets the action that triggers the accessibility event.
477      * @return The operation of the event. Refer to "AccessibilityElementInfo.ActionType"
478      * @since 3
479      * @sysCap Accessibility
480      */
481     ActionType GetTriggerAction() const;
482 
483     /**
484      * @brief Set the information of accessibility event of [TYPE_NOTIFICATION_UPDATE_EVENT]
485      * @param category Refer to [NotificationCategory], It maybe changed from APP
486      * @since 3
487      * @sysCap Accessibility
488      */
489     void SetNotificationInfo(const NotificationCategory category);
490 
491     /**
492      * @brief Get the information of accessibility event of [TYPE_NOTIFICATION_UPDATE_EVENT]
493      * @return Refer to [NotificationCategory], It maybe changed from APP
494      * @since 3
495      * @sysCap Accessibility
496      */
497     NotificationCategory GetNotificationInfo() const;
498 
499     /**
500      * @brief Set the customize gesture type of accessibility event of [TYPE_GESTURE_EVENT]
501      * @param category Refer to [GestureType], It maybe changed from APP
502      * @since 3
503      * @sysCap Accessibility
504      */
505     void SetGestureType(const GestureType gestureType);
506 
507     /**
508      * @brief Get the customize gesture type of accessibility event of [TYPE_GESTURE_EVENT]
509      * @return Refer to [GestureType], It maybe changed from APP
510      * @since 3
511      * @sysCap Accessibility
512      */
513     GestureType GetGestureType() const;
514 
515     /**
516      * @brief Set the page ID associated with the accessibility event.
517      * @param pageId The page ID associated with the accessibility event.
518      * @since 3
519      * @sysCap Accessibility
520      */
521     void SetPageId(const int32_t pageId);
522 
523     /**
524      * @brief Gets the page ID associated with the accessibility event.
525      * @return The page ID associated with the accessibility event.
526      * @since 3
527      * @sysCap Accessibility
528      */
529     int32_t GetPageId() const;
530 
531     /**
532      * @brief Set the element info associated with the accessibility event.
533      * @param elementInfo The element info associated with the accessibility event.
534      * @since 12
535      * @sysCap Accessibility
536      */
537     void SetElementInfo(const AccessibilityElementInfo &elementInfo);
538 
539     /**
540      * @brief Get the element info pointer associated with the accessibility event.
541      * @return The element info associated with the accessibility event.
542      * @since 12
543      * @sysCap Accessibility
544      */
545     const AccessibilityElementInfo &GetElementInfo() const;
546 
547     /**
548      * @brief Get the text to announce.
549      * @return Return the text to announce.
550      * @since 12
551      * @sysCap Accessibility
552      */
553     const std::string &GetTextAnnouncedForAccessibility() const;
554 
555     /**
556      * @brief Set the text to announce of the event.
557      * @param textAnnouncedForAccessibility The text to announce.
558      * @since 12
559      * @sysCap Accessibility
560      */
561     void SetTextAnnouncedForAccessibility(const std::string &textAnnouncedForAccessibility);
562 
563     /**
564      * @brief Get the inspectorKey.
565      * @return Return the inspectorKey.
566      * @since 12
567      * @sysCap Accessibility
568      */
569     const std::string &GetInspectorKey() const;
570 
571     /**
572      * @brief Set the inspectorKey of the event.
573      * @param inspectorKey The inspectorKey.
574      * @since 12
575      * @sysCap Accessibility
576      */
577     void SetInspectorKey(const std::string &inspectorKey);
578 
579     /**
580      * @brief Set the request focus elementId.
581      * @param requestFocusElementId The elementId to focus.
582      * @since 12
583      * @sysCap Accessibility
584      */
585     void SetRequestFocusElementId(const int32_t requestFocusElementId);
586 
587     /**
588      * @brief Gets the request focus elementId.
589      * @return The elementId to focus.
590      * @since 12
591      * @sysCap Accessibility
592      */
593     int32_t GetRequestFocusElementId() const;
594 
595     void SetElementMainWindowId(const int32_t windowId);
596 
597     void SetExtraEvent(const ExtraEventInfo &extraEventInfo);
598 
599     const ExtraEventInfo &GetExtraEvent() const;
600 
601 protected:
602     EventType eventType_ = TYPE_VIEW_INVALID;
603     std::string bundleName_ = "";
604     ActionType triggerAction_ = ACCESSIBILITY_ACTION_INVALID;
605     int64_t timeStamp_ = 0;
606     TextMoveUnit textMoveStep_ = STEP_CHARACTER;
607     WindowsContentChangeTypes windowContentChangeTypes_ = CONTENT_CHANGE_TYPE_INVALID;
608     WindowUpdateType windowChangeTypes_ = WINDOW_UPDATE_INVALID;
609     GestureType gestureType_ = GESTURE_INVALID;
610     NotificationCategory category_ = CATEGORY_INVALID;
611     int32_t pageId_ = 0;
612     std::string notificationContent_ = "";
613     AccessibilityElementInfo elementInfo_ {};
614     ExtraEventInfo extraEventInfo_ {};
615     std::string textAnnouncedForAccessibility_ = "";
616     std::string inspectorKey_ = "";
617     int32_t requestFocusElementId_ = -1;
618     uint32_t resourceId_ = 1;
619     std::string resourceModuleName_ = "";
620     std::string resourceBundleName_ = "";
621 };
622 } // namespace Accessibility
623 } // namespace OHOS
624 #endif // ACCESSIBILITY_EVENT_INFO_H
625