• 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 #include "accessibility_event_info.h"
17 
18 #include <cinttypes>
19 
20 #include "hilog_wrapper.h"
21 
22 namespace OHOS {
23 namespace Accessibility {
24 namespace {
25     static std::set<std::string> EXTRA_EVENTINFO_SET = {
26         "addText",
27         "removeText"
28     };
29 }
30 
SetSource(const int64_t componentId)31 void AccessibilityMemo::SetSource(const int64_t componentId)
32 {
33     HILOG_DEBUG("componentId[%{public}" PRId64 "]", componentId);
34     componentId_ = componentId;
35     elementId_ = componentId;
36 }
37 
GetViewId() const38 int64_t AccessibilityMemo::GetViewId() const
39 {
40     HILOG_DEBUG("componentId_[%{public}" PRId64 "]", componentId_);
41     return componentId_;
42 }
43 
GetAccessibilityId() const44 int64_t AccessibilityMemo::GetAccessibilityId() const
45 {
46     HILOG_DEBUG("called] elementId_[%{public}" PRId64 "]", elementId_);
47     return elementId_;
48 }
49 
SetWindowId(const int32_t windowId)50 void AccessibilityMemo::SetWindowId(const int32_t windowId)
51 {
52     HILOG_DEBUG("windowId[%{public}d]", windowId);
53     windowId_ = windowId;
54 }
55 
GetWindowId() const56 int32_t AccessibilityMemo::GetWindowId() const
57 {
58     HILOG_DEBUG("windowId_[%{public}d]", windowId_);
59     return windowId_;
60 }
61 
GetCurrentIndex() const62 int32_t AccessibilityMemo::GetCurrentIndex() const
63 {
64     HILOG_DEBUG("currentIndex_[%{public}d]", currentIndex_);
65     return currentIndex_;
66 }
67 
SetCurrentIndex(const int32_t index)68 void AccessibilityMemo::SetCurrentIndex(const int32_t index)
69 {
70     currentIndex_ = index;
71     HILOG_DEBUG("currentIndex_[%{public}d]", currentIndex_);
72 }
73 
GetBeginIndex() const74 int32_t AccessibilityMemo::GetBeginIndex() const
75 {
76     HILOG_DEBUG("beginIndex_[%{public}d]", beginIndex_);
77     return beginIndex_;
78 }
79 
SetBeginIndex(const int32_t index)80 void AccessibilityMemo::SetBeginIndex(const int32_t index)
81 {
82     beginIndex_ = index;
83     HILOG_DEBUG("beginIndex_[%{public}d]", beginIndex_);
84 }
85 
GetEndIndex() const86 int32_t AccessibilityMemo::GetEndIndex() const
87 {
88     HILOG_DEBUG("endIndex_[%{public}d]", endIndex_);
89     return endIndex_;
90 }
91 
SetEndIndex(const int32_t index)92 void AccessibilityMemo::SetEndIndex(const int32_t index)
93 {
94     endIndex_ = index;
95     HILOG_DEBUG("endIndex_[%{public}d]", endIndex_);
96 }
97 
GetComponentType() const98 const std::string &AccessibilityMemo::GetComponentType() const
99 {
100     HILOG_DEBUG("componentType_[%{public}s]", componentType_.c_str());
101     return componentType_;
102 }
103 
SetComponentType(const std::string & className)104 void AccessibilityMemo::SetComponentType(const std::string &className)
105 {
106     componentType_ = className;
107     HILOG_DEBUG("componentType_[%{public}s]", componentType_.c_str());
108 }
109 
GetBeforeText() const110 const std::string &AccessibilityMemo::GetBeforeText() const
111 {
112     HILOG_DEBUG("beforeText_[%{private}s]", beforeText_.c_str());
113     return beforeText_;
114 }
115 
SetBeforeText(const std::string & beforeText)116 void AccessibilityMemo::SetBeforeText(const std::string &beforeText)
117 {
118     beforeText_ = beforeText;
119     HILOG_DEBUG("beforeText_[%{private}s]", beforeText_.c_str());
120 }
121 
AddContent(const std::string & content)122 void AccessibilityMemo::AddContent(const std::string &content)
123 {
124     contents_.push_back(content);
125     HILOG_DEBUG("content[%{private}s]", content.c_str());
126 }
127 
GetContentList() const128 const std::vector<std::string> &AccessibilityMemo::GetContentList() const
129 {
130     return contents_;
131 }
132 
GetLatestContent() const133 const std::string &AccessibilityMemo::GetLatestContent() const
134 {
135     HILOG_DEBUG("latestContent_[%{private}s]", latestContent_.c_str());
136     return latestContent_;
137 }
138 
SetLatestContent(const std::string & content)139 void AccessibilityMemo::SetLatestContent(const std::string &content)
140 {
141     latestContent_ = content;
142     HILOG_DEBUG("latestContent_[%{private}s]", latestContent_.c_str());
143 }
144 
GetDescription() const145 const std::string &AccessibilityMemo::GetDescription() const
146 {
147     HILOG_DEBUG("description_[%{public}s]", description_.c_str());
148     return description_;
149 }
150 
SetDescription(const std::string & contentDescription)151 void AccessibilityMemo::SetDescription(const std::string &contentDescription)
152 {
153     description_ = contentDescription;
154     HILOG_DEBUG("description_[%{public}s]", description_.c_str());
155 }
156 
SetItemCounts(const int32_t itemCounts)157 void AccessibilityMemo::SetItemCounts(const int32_t itemCounts)
158 {
159     itemCounts_ = itemCounts;
160     HILOG_DEBUG("itemCounts_[%{public}d]", itemCounts_);
161 }
162 
GetItemCounts() const163 int32_t AccessibilityMemo::GetItemCounts() const
164 {
165     HILOG_DEBUG("itemCounts_[%{public}d]", itemCounts_);
166     return itemCounts_;
167 }
168 
ExtraEventInfo(const std::map<std::string,std::string> extraEventValueStr)169 ExtraEventInfo::ExtraEventInfo(const std::map<std::string, std::string> extraEventValueStr)
170 {
171     extraEventValueStr_ = extraEventValueStr;
172 }
173 
SetExtraEventInfo(const std::string keyStr,const std::string valueStr)174 RetError ExtraEventInfo::SetExtraEventInfo(const std::string keyStr, const std::string valueStr)
175 {
176     auto extraElementInfoIter = EXTRA_EVENTINFO_SET.find(keyStr);
177     if (extraElementInfoIter != EXTRA_EVENTINFO_SET.end()) {
178         extraEventValueStr_[keyStr] = valueStr;
179         HILOG_DEBUG("SetExtraEventInfo: size is extraEventValueStr : [%{public}zu]",
180             extraEventValueStr_.size());
181     } else {
182         return RET_ERR_FAILED;
183     }
184     return RET_OK;
185 }
186 
GetExtraEventInfoValueStr() const187 const std::map<std::string, std::string> &ExtraEventInfo::GetExtraEventInfoValueStr() const
188 {
189     return extraEventValueStr_;
190 }
191 
SetExtraEvent(const ExtraEventInfo & extraEventInfo)192 void AccessibilityEventInfo::SetExtraEvent(const ExtraEventInfo &extraEventInfo)
193 {
194     extraEventInfo_ = extraEventInfo;
195 }
196 
GetExtraEvent() const197 const ExtraEventInfo &AccessibilityEventInfo::GetExtraEvent() const
198 {
199     return extraEventInfo_;
200 }
201 
GetEventType() const202 EventType AccessibilityEventInfo::GetEventType() const
203 {
204     HILOG_DEBUG("eventType_[%{public}d]", eventType_);
205     return eventType_;
206 }
207 
GetWindowContentChangeTypes() const208 WindowsContentChangeTypes AccessibilityEventInfo::GetWindowContentChangeTypes() const
209 {
210     HILOG_DEBUG("windowType_[%{public}d]", windowContentChangeTypes_);
211     return windowContentChangeTypes_;
212 }
213 
SetWindowContentChangeTypes(const WindowsContentChangeTypes changeTypes)214 void AccessibilityEventInfo::SetWindowContentChangeTypes(const WindowsContentChangeTypes changeTypes)
215 {
216     windowContentChangeTypes_ = changeTypes;
217     HILOG_DEBUG("windowType_[%{public}d]", windowContentChangeTypes_);
218 }
219 
GetWindowChangeTypes() const220 WindowUpdateType AccessibilityEventInfo::GetWindowChangeTypes() const
221 {
222     HILOG_DEBUG("windowType_[%{public}d]", windowChangeTypes_);
223     return windowChangeTypes_;
224 }
225 
SetWindowChangeTypes(const WindowUpdateType changeTypes)226 void AccessibilityEventInfo::SetWindowChangeTypes(const WindowUpdateType changeTypes)
227 {
228     windowChangeTypes_ = changeTypes;
229     HILOG_DEBUG("windowType_[%{public}d]", windowChangeTypes_);
230 }
231 
SetEventType(const EventType eventType)232 void AccessibilityEventInfo::SetEventType(const EventType eventType)
233 {
234     eventType_ = EventType(eventType);
235     HILOG_DEBUG("eventType_[%{public}d]", eventType_);
236 }
237 
GetTimeStamp() const238 int64_t AccessibilityEventInfo::GetTimeStamp() const
239 {
240     HILOG_DEBUG("timeStamp:%{public}" PRId64 "", timeStamp_);
241     return timeStamp_;
242 }
243 
SetTimeStamp(int64_t timeStamp)244 void AccessibilityEventInfo::SetTimeStamp(int64_t timeStamp)
245 {
246     timeStamp_ = timeStamp;
247     HILOG_DEBUG("timeStamp:%{public}" PRId64 "", timeStamp_);
248 }
249 
GetResourceId() const250 uint32_t AccessibilityEventInfo::GetResourceId() const
251 {
252     HILOG_DEBUG("GetResourceId [%{public}d]", resourceId_);
253     return resourceId_;
254 }
255 
SetResourceId(const uint32_t & resourceId)256 void AccessibilityEventInfo::SetResourceId(const uint32_t &resourceId)
257 {
258     resourceId_ = resourceId;
259     HILOG_DEBUG("SetResourceId [%{public}d]", resourceId_);
260 }
261 
GetResourceBundleName() const262 const std::string &AccessibilityEventInfo::GetResourceBundleName() const
263 {
264     HILOG_DEBUG("GetResourceBundleName [%{public}s]", resourceBundleName_.c_str());
265     return resourceBundleName_;
266 }
267 
SetResourceBundleName(const std::string & bundleName)268 void AccessibilityEventInfo::SetResourceBundleName(const std::string &bundleName)
269 {
270     resourceBundleName_ = bundleName;
271     HILOG_DEBUG("SetResourceBundleName [%{public}s]", resourceBundleName_.c_str());
272 }
273 
GetResourceModuleName() const274 const std::string &AccessibilityEventInfo::GetResourceModuleName() const
275 {
276     HILOG_DEBUG("GetResourceModuleName [%{public}s]", resourceModuleName_.c_str());
277     return resourceModuleName_;
278 }
279 
SetResourceModuleName(const std::string & moduleName)280 void AccessibilityEventInfo::SetResourceModuleName(const std::string &moduleName)
281 {
282     resourceModuleName_ = moduleName;
283     HILOG_DEBUG("SetResourceModuleName [%{public}s]", resourceModuleName_.c_str());
284 }
285 
GetBundleName() const286 const std::string &AccessibilityEventInfo::GetBundleName() const
287 {
288     HILOG_DEBUG("bundleName_[%{public}s]", bundleName_.c_str());
289     return bundleName_;
290 }
291 
SetBundleName(const std::string & bundleName)292 void AccessibilityEventInfo::SetBundleName(const std::string &bundleName)
293 {
294     HILOG_DEBUG("previous bundleName[%{public}s] new bundleName[%{public}s]", bundleName_.c_str(), bundleName.c_str());
295     bundleName_ = bundleName;
296 }
297 
GetNotificationContent() const298 const std::string &AccessibilityEventInfo::GetNotificationContent() const
299 {
300     HILOG_DEBUG("notificationContent_[%{public}s]", notificationContent_.c_str());
301     return notificationContent_;
302 }
303 
SetNotificationContent(const std::string & notificationContent)304 void AccessibilityEventInfo::SetNotificationContent(const std::string &notificationContent)
305 {
306     notificationContent_ = notificationContent;
307     HILOG_DEBUG("notificationContent_[%{public}s]", notificationContent_.c_str());
308 }
309 
GetTextAnnouncedForAccessibility() const310 const std::string &AccessibilityEventInfo::GetTextAnnouncedForAccessibility() const
311 {
312     HILOG_DEBUG("textAnnouncedForAccessibility_[%{public}s]", textAnnouncedForAccessibility_.c_str());
313     return textAnnouncedForAccessibility_;
314 }
315 
SetTextAnnouncedForAccessibility(const std::string & textAnnouncedForAccessibility)316 void AccessibilityEventInfo::SetTextAnnouncedForAccessibility(const std::string &textAnnouncedForAccessibility)
317 {
318     textAnnouncedForAccessibility_ = textAnnouncedForAccessibility;
319     HILOG_DEBUG("textAnnouncedForAccessibility_[%{public}s]", textAnnouncedForAccessibility_.c_str());
320 }
321 
GetInspectorKey() const322 const std::string &AccessibilityEventInfo::GetInspectorKey() const
323 {
324     HILOG_DEBUG("inspectorKey_[%{public}s]", inspectorKey_.c_str());
325     return inspectorKey_;
326 }
327 
SetInspectorKey(const std::string & inspectorKey)328 void AccessibilityEventInfo::SetInspectorKey(const std::string &inspectorKey)
329 {
330     inspectorKey_ = inspectorKey;
331     HILOG_DEBUG("inspectorKey_[%{public}s]", inspectorKey_.c_str());
332 }
333 
SetTextMovementStep(const TextMoveUnit granularity)334 void AccessibilityEventInfo::SetTextMovementStep(const TextMoveUnit granularity)
335 {
336     textMoveStep_ = granularity;
337     HILOG_DEBUG("textMoveStep_[%{public}d]", textMoveStep_);
338 }
339 
GetTextMovementStep() const340 TextMoveUnit AccessibilityEventInfo::GetTextMovementStep() const
341 {
342     HILOG_DEBUG("textMoveStep_[%{public}d]", textMoveStep_);
343     return textMoveStep_;
344 }
345 
SetTriggerAction(const ActionType action)346 void AccessibilityEventInfo::SetTriggerAction(const ActionType action)
347 {
348     triggerAction_ = action;
349     HILOG_DEBUG("triggerAction_[%{public}d]", triggerAction_);
350 }
351 
GetTriggerAction() const352 ActionType AccessibilityEventInfo::GetTriggerAction() const
353 {
354     HILOG_DEBUG("triggerAction_[%{public}d]", triggerAction_);
355     return triggerAction_;
356 }
357 
AccessibilityEventInfo(int32_t windowId,WindowUpdateType windowChangeTypes)358 AccessibilityEventInfo::AccessibilityEventInfo(int32_t windowId, WindowUpdateType windowChangeTypes)
359     : eventType_(TYPE_WINDOW_UPDATE), windowChangeTypes_(windowChangeTypes)
360 {
361     HILOG_DEBUG();
362     SetWindowId(windowId);
363 }
364 
AccessibilityEventInfo(EventType eventType)365 AccessibilityEventInfo::AccessibilityEventInfo(EventType eventType) : eventType_(eventType)
366 {
367     HILOG_DEBUG("eventType_[%{public}d]", eventType_);
368 }
369 
SetNotificationInfo(const NotificationCategory category)370 void AccessibilityEventInfo::SetNotificationInfo(const NotificationCategory category)
371 {
372     category_ = category;
373     HILOG_DEBUG("category_[%{public}d]", category_);
374 }
375 
SetGestureType(const GestureType gestureType)376 void AccessibilityEventInfo::SetGestureType(const GestureType gestureType)
377 {
378     gestureType_ = gestureType;
379     HILOG_DEBUG("gestureType_[%{public}d]", gestureType_);
380 }
381 
GetGestureType() const382 GestureType AccessibilityEventInfo::GetGestureType() const
383 {
384     HILOG_DEBUG("gestureType_[%{public}d]", gestureType_);
385     return gestureType_;
386 }
387 
GetNotificationInfo() const388 NotificationCategory AccessibilityEventInfo::GetNotificationInfo() const
389 {
390     HILOG_DEBUG("category_[%{public}d]", category_);
391     return category_;
392 }
393 
SetPageId(const int32_t pageId)394 void AccessibilityEventInfo::SetPageId(const int32_t pageId)
395 {
396     HILOG_DEBUG("pageId[%{public}d]", pageId);
397     pageId_ = pageId;
398 }
399 
GetPageId() const400 int32_t AccessibilityEventInfo::GetPageId() const
401 {
402     HILOG_DEBUG("pageId_[%{public}d]", pageId_);
403     return pageId_;
404 }
405 
SetElementInfo(const AccessibilityElementInfo & elementInfo)406 void AccessibilityEventInfo::SetElementInfo(const AccessibilityElementInfo &elementInfo)
407 {
408     HILOG_DEBUG("set elementInfo");
409     elementInfo_ = elementInfo;
410 }
411 
GetElementInfo() const412 const AccessibilityElementInfo &AccessibilityEventInfo::GetElementInfo() const
413 {
414     HILOG_DEBUG("get elementInfo");
415     return elementInfo_;
416 }
417 
SetRequestFocusElementId(const int32_t requestFocusElementId)418 void AccessibilityEventInfo::SetRequestFocusElementId(const int32_t requestFocusElementId)
419 {
420     HILOG_DEBUG("requestFocusElementId[%{public}d]", requestFocusElementId);
421     requestFocusElementId_ = requestFocusElementId;
422 }
423 
GetRequestFocusElementId() const424 int32_t AccessibilityEventInfo::GetRequestFocusElementId() const
425 {
426     HILOG_DEBUG("requestFocusElementId_[%{public}d]", requestFocusElementId_);
427     return requestFocusElementId_;
428 }
429 
SetElementMainWindowId(const int32_t windowId)430 void AccessibilityEventInfo::SetElementMainWindowId(const int32_t windowId)
431 {
432     HILOG_DEBUG("mainWindowId[%{public}d]", windowId);
433     elementInfo_.SetMainWindowId(windowId);
434 }
435 } // namespace Accessibility
436 } // namespace OHOS