• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 
16 #ifndef ACCESSIBILITY_EVENT_INFO_H
17 #define ACCESSIBILITY_EVENT_INFO_H
18 
19 #include <vector>
20 #include "accessibility_def.h"
21 
22 namespace OHOS {
23 namespace Accessibility {
24 /*
25 * The class supply the content information about the event.
26 * The SetXxx() API is almost supplied to ACE to set the information.
27 * Parts of SetXxx() API is called by AAMS, such as: SetConnectId().
28 * The GetXxx() API is almost supplied to AA to get the information.
29 */
30 class AccessibilityMemo {
31 public:
32     /**
33      * @brief Construct
34      * @since 3
35      * @sysCap Accessibility
36      */
AccessibilityMemo()37     AccessibilityMemo() {}
38 
39     /**
40      * @brief Set the component of the event related.
41      * @param componentId The id of component.
42      * @since 3
43      * @sysCap Accessibility
44      */
45     void SetSource(const int64_t componentId);
46 
47     /**
48      * @brief Gets the view(component) ID associated with the accessibility event.
49      * @return The view(component) ID associated with the accessibility event.
50      * @since 3
51      * @sysCap Accessibility
52      */
53     int64_t GetViewId() const;
54 
55     /**
56      * @brief Gets the accessibility ID of the component.
57      * @return The accessibility ID of the component.
58      * @since 3
59      * @sysCap Accessibility
60      */
61     int64_t GetAccessibilityId() const;
62 
63     /**
64      * @brief Set the window ID associated with the accessibility event.
65      * @param windowId The window ID associated with the accessibility event.
66      * @since 3
67      * @sysCap Accessibility
68      */
69     void SetWindowId(const int32_t windowId);
70 
71     /**
72      * @brief Gets the window ID associated with the accessibility event.
73      * @return The window ID associated with the accessibility event.
74      * @since 3
75      * @sysCap Accessibility
76      */
77 
78     int32_t GetWindowId() const;
79 
80     /**
81      * @brief Gets the current index of listed items or text position associated with the current event.
82      * @return The current index of listed items or text position associated with the current event.
83      * @since 3
84      * @sysCap Accessibility
85      */
86     int32_t GetCurrentIndex() const;
87 
88     /**
89      * @brief Sets the current index of listed items or text position associated with the current event.
90      * @param index The current index of listed items or text position associated with the current event.
91      * @since 3
92      * @sysCap Accessibility
93      */
94     void SetCurrentIndex(const int32_t index);
95 
96     /**
97      * @brief Gets the start index of listed items on the screen.
98      * @return The start index of listed items. It is unique value for the listed items.
99      * @since 3
100      * @sysCap Accessibility
101      */
102     int32_t GetBeginIndex() const;
103 
104     /**
105      * @brief Sets the start index of listed items on the screen.
106      * @param index The start index of listed items. It is unique value for the listed items.
107      * @since 3
108      * @sysCap Accessibility
109      */
110     void SetBeginIndex(const int32_t index);
111 
112     /**
113      * @brief Gets the number items on the screen.
114      * @return The number of items.
115      * @since 3
116      * @sysCap Accessibility
117      */
118     int32_t GetItemCounts() const;
119 
120     /**
121      * @brief Sets the number items on the screen.
122      * @param ItemCounts The number of items.
123      * @since 3
124      * @sysCap Accessibility
125      */
126     void SetItemCounts(const int32_t itemCounts);
127 
128     /**
129      * @brief Gets the end index of listed items on the screen.
130      * @return The end index of listed items on the screen.
131      * @since 3
132      * @sysCap Accessibility
133      */
134     int32_t GetEndIndex() const;
135 
136     /**
137      * @brief Sets the end index of listed items on the screen.
138      * @param index The end index of listed items on the screen.
139      * @since 3
140      * @sysCap Accessibility
141      */
142     void SetEndIndex(const int32_t index);
143 
144     /**
145      * @brief Gets the class(component type) name.
146      * @return The class(component type) name.
147      * @since 3
148      * @sysCap Accessibility
149      */
150     const std::string &GetComponentType() const;
151 
152     /**
153      * @brief Sets the class(component type) name.
154      * @param className The class(component type) name.
155      * @since 3
156      * @sysCap Accessibility
157      */
158     void SetComponentType(const std::string &className);
159 
160     /**
161      * @brief Gets the before text changed of the component.
162      * @return The before text changed of the component.
163      * @since 3
164      * @sysCap Accessibility
165      */
166     const std::string &GetBeforeText() const;
167 
168     /**
169      * @brief Set the before text changed of the component.
170      * @param beforeText The before text changed of the component.
171      * @since 3
172      * @sysCap Accessibility
173      */
174     void SetBeforeText(const std::string &beforeText);
175 
176     /**
177      * @brief Adds an text to the content list.
178      * @param content Indicates the text to add.
179      * @since 3
180      * @sysCap Accessibility
181      */
182     void AddContent(const std::string &content);
183 
184     /**
185      * @brief Get the content list in the event.
186      * @return The content list in the event.
187      * @since 3
188      * @sysCap Accessibility
189      */
190     const std::vector<std::string> &GetContentList() const;
191 
192     /**
193      * @brief Gets the last content of the component(The text of changed after).
194      * @return The last content of the component(The text of changed after).
195      * @since 3
196      * @sysCap Accessibility
197      */
198     const std::string &GetLatestContent() const;
199 
200     /**
201      * @brief Sets the last content of the component.
202      * @param content The last content of component.
203      * @since 3
204      * @sysCap Accessibility
205      */
206     void SetLatestContent(const std::string &content);
207 
208     /**
209      * @brief Gets the accessibility event description.
210      * @return The accessibility event description
211      * @since 3
212      * @sysCap Accessibility
213      */
214     const std::string &GetDescription() const;
215 
216     /**
217      * @brief Sets the accessibility event description.
218      * @param contentDescription The accessibility event description
219      * @since 3
220      * @sysCap Accessibility
221      */
222     void SetDescription(const std::string &contentDescription);
223 
224 protected:
225     int64_t componentId_ = 0;
226     int32_t windowId_ = 0;
227     int32_t currentIndex_ = 0;
228     int32_t beginIndex_ = 0;
229     int32_t endIndex_ = 0;
230     std::vector<std::string> contents_ {};
231     std::string componentType_ = "";
232     std::string description_ = "";
233     std::string beforeText_ = "";
234     std::string latestContent_ = "";
235     int64_t elementId_ = 0;
236     int32_t itemCounts_ = 0;
237 };
238 
239 /*
240 * The class define the event types and supply the api to
241 * get/set the property of event. and it triggered by UI
242 * changed and sent to AA. According to the event property,
243 * AA can get event properties, such as: action triggered
244 * the event and the source.
245 */
246 class AccessibilityEventInfo : public AccessibilityMemo {
247 public:
248     /**
249      * @brief Construct
250      * @since 3
251      * @sysCap Accessibility
252      */
AccessibilityEventInfo()253     AccessibilityEventInfo() {}
254 
255     /**
256      * @brief Construct
257      * @param eventType the type of event info
258      * @since 3
259      * @sysCap Accessibility
260      */
261     AccessibilityEventInfo(EventType eventType);
262 
263     /**
264      * @brief Construct
265      * @param windowId The id of window
266      * @param windowChangeTypes the window change type
267      * @since 3
268      * @sysCap Accessibility
269      */
270     AccessibilityEventInfo(int32_t windowId, WindowUpdateType windowChangeTypes);
271 
272     /**
273      * @brief Get the type of the accessibility event.
274      * @return The type of the accessibility event.
275      * @since 3
276      * @sysCap Accessibility
277      */
278     EventType GetEventType() const;
279 
280     /**
281      * @brief Get the window content changed types
282      * @return The window content changed types. Refer to "WindowsContentChangeTypes"
283      * @since 3
284      * * @sysCap Accessibility
285      */
286     WindowsContentChangeTypes GetWindowContentChangeTypes() const;
287 
288     /**
289      * @brief Set the window content changed types
290      * @param changeTypes The window content changed types. Refer to "WindowsContentChangeTypes"
291      * @since 3
292      * @sysCap Accessibility
293      */
294     void SetWindowContentChangeTypes(const WindowsContentChangeTypes changeTypes);
295 
296     /**
297      * @brief Get the window changed types
298      * @return The window changed types.refer to WindowUpdateType
299      * @since 3
300      * @sysCap Accessibility
301      */
302     WindowUpdateType GetWindowChangeTypes() const;
303 
304     /**
305      * @brief Set the window changed types
306      * @param changeTypes The window changed types.refer to WindowUpdateType
307      * @since 3
308      * @sysCap Accessibility
309      */
310     void SetWindowChangeTypes(const WindowUpdateType changeTypes);
311 
312     /**
313      * @brief Sets the type of an accessibility event.
314      * @note It is same to setAccessibilityEventType​(int32_t accessibilityEventType)
315      * @param eventType The type of an accessibility event. Refer to "EventType"
316      * @since 3
317      * @sysCap Accessibility
318      */
319     void SetEventType(const EventType eventType);
320 
321     /**
322      * @brief AA get the time of accessibility event is sent from ASAC.
323      * @return The time of accessibility event is sent from ASAC
324      * @since 3
325      * @sysCap Accessibility
326      */
327     int64_t GetTimeStamp() const;
328 
329     /**
330      * @brief ASAC set the time of accessibility is sent to AA
331      * @param timeStamp The time of accessibility event is sent from ASAC
332      * @since 3
333      * @sysCap Accessibility
334      */
335     void SetTimeStamp(int64_t timeStamp);  // Remained:for send event timestamp
336 
337     /**
338      * @brief Gets the bundle name of the event source, that is, the bundle name of the target application.
339      * @return Returns the bundle name of the event source.
340      * @since 3
341      * @sysCap Accessibility
342      */
343     const std::string &GetBundleName() const;
344 
345     /**
346      * @brief Set the bundle name of the event source, that is, the bundle name of the target application.
347      * @param bundleName The bundle name of the event source.
348      * @since 3
349      * @sysCap Accessibility
350      */
351     void SetBundleName(const std::string &bundleName);
352 
353     /**
354      * @brief Get the notification content of the event source.
355      * @return Return the notification content of the event source.
356      * @since 3
357      * @sysCap Accessibility
358      */
359     const std::string &GetNotificationContent() const;
360 
361     /**
362      * @brief Set the notification content of the event source.
363      * @param notificationContent The notification content of the event source.
364      * @since 3
365      * @sysCap Accessibility
366      */
367     void SetNotificationContent(const std::string &notificationContent);
368 
369     /**
370      * @brief Set the move granularity of the text
371      * @param granularity The move granularity of the text. Refer to "AccessibilityElementInfo.TextMoveUnit"
372      * @since 3
373      * @sysCap Accessibility
374      */
375     void SetTextMovementStep(const TextMoveUnit granularity);
376 
377     /**
378      * @brief Get the move granularity of the text
379      * @return The move granularity of the text. Refer to "AccessibilityElementInfo.TextMoveUnit"
380      * @since 3
381      * @sysCap Accessibility
382      */
383     TextMoveUnit GetTextMovementStep() const;
384 
385     /**
386      * @brief Sets the action that triggers the accessibility event.
387      * @param action The operation of the event. Refer to "AccessibilityElementInfo.ActionType"
388      * @since 3
389      * @sysCap Accessibility
390      */
391     void SetTriggerAction(const ActionType action);
392 
393     /**
394      * @brief Gets the action that triggers the accessibility event.
395      * @return The operation of the event. Refer to "AccessibilityElementInfo.ActionType"
396      * @since 3
397      * @sysCap Accessibility
398      */
399     ActionType GetTriggerAction() const;
400 
401     /**
402      * @brief Set the information of accessibility event of [TYPE_NOTIFICATION_UPDATE_EVENT]
403      * @param category Refer to [NotificationCategory], It maybe changed from APP
404      * @since 3
405      * @sysCap Accessibility
406      */
407     void SetNotificationInfo(const NotificationCategory category);
408 
409     /**
410      * @brief Get the information of accessibility event of [TYPE_NOTIFICATION_UPDATE_EVENT]
411      * @return Refer to [NotificationCategory], It maybe changed from APP
412      * @since 3
413      * @sysCap Accessibility
414      */
415     NotificationCategory GetNotificationInfo() const;
416 
417     /**
418      * @brief Set the customize gesture type of accessibility event of [TYPE_GESTURE_EVENT]
419      * @param category Refer to [GestureType], It maybe changed from APP
420      * @since 3
421      * @sysCap Accessibility
422      */
423     void SetGestureType(const GestureType gestureType);
424 
425     /**
426      * @brief Get the customize gesture type of accessibility event of [TYPE_GESTURE_EVENT]
427      * @return Refer to [GestureType], It maybe changed from APP
428      * @since 3
429      * @sysCap Accessibility
430      */
431     GestureType GetGestureType() const;
432 
433     /**
434      * @brief Set the page ID associated with the accessibility event.
435      * @param pageId The page ID associated with the accessibility event.
436      * @since 3
437      * @sysCap Accessibility
438      */
439     void SetPageId(const int32_t pageId);
440 
441     /**
442      * @brief Gets the page ID associated with the accessibility event.
443      * @return The page ID associated with the accessibility event.
444      * @since 3
445      * @sysCap Accessibility
446      */
447     int32_t GetPageId() const;
448 
449 protected:
450     EventType eventType_ = TYPE_VIEW_INVALID;
451     std::string bundleName_ = "";
452     ActionType triggerAction_ = ACCESSIBILITY_ACTION_INVALID;
453     int64_t timeStamp_ = 0;
454     TextMoveUnit textMoveStep_ = STEP_CHARACTER;
455     WindowsContentChangeTypes windowContentChangeTypes_ = CONTENT_CHANGE_TYPE_INVALID;
456     WindowUpdateType windowChangeTypes_ = WINDOW_UPDATE_INVALID;
457     GestureType gestureType_ = GESTURE_INVALID;
458     NotificationCategory category_ = CATEGORY_INVALID;
459     int32_t pageId_ = 0;
460     std::string notificationContent_ = "";
461 };
462 } // namespace Accessibility
463 } // namespace OHOS
464 #endif // ACCESSIBILITY_EVENT_INFO_H
465