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 Gets the bundle name of the event source, that is, the bundle name of the target application. 340 * @return Returns the bundle name of the event source. 341 * @since 3 342 * @sysCap Accessibility 343 */ 344 const std::string &GetBundleName() const; 345 346 /** 347 * @brief Set the bundle name of the event source, that is, the bundle name of the target application. 348 * @param bundleName The bundle name of the event source. 349 * @since 3 350 * @sysCap Accessibility 351 */ 352 void SetBundleName(const std::string &bundleName); 353 354 /** 355 * @brief Get the notification content of the event source. 356 * @return Return the notification content of the event source. 357 * @since 3 358 * @sysCap Accessibility 359 */ 360 const std::string &GetNotificationContent() const; 361 362 /** 363 * @brief Set the notification content of the event source. 364 * @param notificationContent The notification content of the event source. 365 * @since 3 366 * @sysCap Accessibility 367 */ 368 void SetNotificationContent(const std::string ¬ificationContent); 369 370 /** 371 * @brief Set the move granularity of the text 372 * @param granularity The move granularity of the text. Refer to "AccessibilityElementInfo.TextMoveUnit" 373 * @since 3 374 * @sysCap Accessibility 375 */ 376 void SetTextMovementStep(const TextMoveUnit granularity); 377 378 /** 379 * @brief Get the move granularity of the text 380 * @return The move granularity of the text. Refer to "AccessibilityElementInfo.TextMoveUnit" 381 * @since 3 382 * @sysCap Accessibility 383 */ 384 TextMoveUnit GetTextMovementStep() const; 385 386 /** 387 * @brief Sets the action that triggers the accessibility event. 388 * @param action The operation of the event. Refer to "AccessibilityElementInfo.ActionType" 389 * @since 3 390 * @sysCap Accessibility 391 */ 392 void SetTriggerAction(const ActionType action); 393 394 /** 395 * @brief Gets the action that triggers the accessibility event. 396 * @return The operation of the event. Refer to "AccessibilityElementInfo.ActionType" 397 * @since 3 398 * @sysCap Accessibility 399 */ 400 ActionType GetTriggerAction() const; 401 402 /** 403 * @brief Set the information of accessibility event of [TYPE_NOTIFICATION_UPDATE_EVENT] 404 * @param category Refer to [NotificationCategory], It maybe changed from APP 405 * @since 3 406 * @sysCap Accessibility 407 */ 408 void SetNotificationInfo(const NotificationCategory category); 409 410 /** 411 * @brief Get the information of accessibility event of [TYPE_NOTIFICATION_UPDATE_EVENT] 412 * @return Refer to [NotificationCategory], It maybe changed from APP 413 * @since 3 414 * @sysCap Accessibility 415 */ 416 NotificationCategory GetNotificationInfo() const; 417 418 /** 419 * @brief Set the customize gesture type of accessibility event of [TYPE_GESTURE_EVENT] 420 * @param category Refer to [GestureType], It maybe changed from APP 421 * @since 3 422 * @sysCap Accessibility 423 */ 424 void SetGestureType(const GestureType gestureType); 425 426 /** 427 * @brief Get the customize gesture type of accessibility event of [TYPE_GESTURE_EVENT] 428 * @return Refer to [GestureType], It maybe changed from APP 429 * @since 3 430 * @sysCap Accessibility 431 */ 432 GestureType GetGestureType() const; 433 434 /** 435 * @brief Set the page ID associated with the accessibility event. 436 * @param pageId The page ID associated with the accessibility event. 437 * @since 3 438 * @sysCap Accessibility 439 */ 440 void SetPageId(const int32_t pageId); 441 442 /** 443 * @brief Gets the page ID associated with the accessibility event. 444 * @return The page ID associated with the accessibility event. 445 * @since 3 446 * @sysCap Accessibility 447 */ 448 int32_t GetPageId() const; 449 450 /** 451 * @brief Set the element info associated with the accessibility event. 452 * @param elementInfo The element info associated with the accessibility event. 453 * @since 12 454 * @sysCap Accessibility 455 */ 456 void SetElementInfo(const AccessibilityElementInfo &elementInfo); 457 458 /** 459 * @brief Get the element info pointer associated with the accessibility event. 460 * @return The element info associated with the accessibility event. 461 * @since 12 462 * @sysCap Accessibility 463 */ 464 const AccessibilityElementInfo &GetElementInfo() const; 465 466 /** 467 * @brief Get the text to announce. 468 * @return Return the text to announce. 469 * @since 12 470 * @sysCap Accessibility 471 */ 472 const std::string &GetTextAnnouncedForAccessibility() const; 473 474 /** 475 * @brief Set the text to announce of the event. 476 * @param textAnnouncedForAccessibility The text to announce. 477 * @since 12 478 * @sysCap Accessibility 479 */ 480 void SetTextAnnouncedForAccessibility(const std::string &textAnnouncedForAccessibility); 481 482 /** 483 * @brief Get the inspectorKey. 484 * @return Return the inspectorKey. 485 * @since 12 486 * @sysCap Accessibility 487 */ 488 const std::string &GetInspectorKey() const; 489 490 /** 491 * @brief Set the inspectorKey of the event. 492 * @param inspectorKey The inspectorKey. 493 * @since 12 494 * @sysCap Accessibility 495 */ 496 void SetInspectorKey(const std::string &inspectorKey); 497 498 /** 499 * @brief Set the request focus elementId. 500 * @param requestFocusElementId The elementId to focus. 501 * @since 12 502 * @sysCap Accessibility 503 */ 504 void SetRequestFocusElementId(const int32_t requestFocusElementId); 505 506 /** 507 * @brief Gets the request focus elementId. 508 * @return The elementId to focus. 509 * @since 12 510 * @sysCap Accessibility 511 */ 512 int32_t GetRequestFocusElementId() const; 513 514 void SetElementMainWindowId(const int32_t windowId); 515 516 protected: 517 EventType eventType_ = TYPE_VIEW_INVALID; 518 std::string bundleName_ = ""; 519 ActionType triggerAction_ = ACCESSIBILITY_ACTION_INVALID; 520 int64_t timeStamp_ = 0; 521 TextMoveUnit textMoveStep_ = STEP_CHARACTER; 522 WindowsContentChangeTypes windowContentChangeTypes_ = CONTENT_CHANGE_TYPE_INVALID; 523 WindowUpdateType windowChangeTypes_ = WINDOW_UPDATE_INVALID; 524 GestureType gestureType_ = GESTURE_INVALID; 525 NotificationCategory category_ = CATEGORY_INVALID; 526 int32_t pageId_ = 0; 527 std::string notificationContent_ = ""; 528 AccessibilityElementInfo elementInfo_ {}; 529 std::string textAnnouncedForAccessibility_ = ""; 530 std::string inspectorKey_ = ""; 531 int32_t requestFocusElementId_ = 0; 532 }; 533 } // namespace Accessibility 534 } // namespace OHOS 535 #endif // ACCESSIBILITY_EVENT_INFO_H 536