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_EXTENSION_CONTEXT_H 17 #define ACCESSIBILITY_EXTENSION_CONTEXT_H 18 19 #include <map> 20 #include <memory> 21 #include "accessibility_element_info.h" 22 #include "accessibility_event_info.h" 23 #include "accessibility_gesture_inject_path.h" 24 #include "accessibility_window_info.h" 25 #include "extension_context.h" 26 27 namespace OHOS { 28 namespace Accessibility { 29 class AccessibilityExtensionContext : public AbilityRuntime::ExtensionContext { 30 public: 31 AccessibilityExtensionContext() = default; 32 virtual ~AccessibilityExtensionContext() = default; 33 34 /** 35 * @brief Obtains elementInfo of focus. 36 * @param focusType The type of focus. It contains FOCUS_TYPE_INPUT and FOCUS_TYPE_ACCESSIBILITY. 37 * @param elementInfo The accessibilityElementInfo of focus. 38 * @return Return RET_OK if obtains elementInfo successfully, otherwise refer to the RetError for the failure. 39 */ 40 RetError GetFocus(const int32_t focusType, AccessibilityElementInfo &elementInfo); 41 42 /** 43 * @brief Obtains elementInfo of focus. 44 * @param sourceInfo 45 * @param focusType The type of focus. It contains FOCUS_TYPE_INPUT and FOCUS_TYPE_ACCESSIBILITY. 46 * @param elementInfo The accessibilityElementInfo of focus. 47 * @return Return RET_OK if obtains elementInfo successfully, otherwise refer to the RetError for the failure. 48 */ 49 RetError GetFocusByElementInfo(const AccessibilityElementInfo &sourceInfo, const int32_t focusType, 50 AccessibilityElementInfo &elementInfo); 51 52 /** 53 * @brief Sends simulate gestures to the screen. 54 * @param gesturePath The gesture which need to send. 55 * @return Return RET_OK if the gesture sends successfully, otherwise refer to the RetError for the failure. 56 */ 57 RetError InjectGesture(const std::shared_ptr<AccessibilityGestureInjectPath> &gesturePath); 58 59 /** 60 * @brief Obtains elementInfo of the accessible root node. 61 * @param elementInfo The elementInfo of the accessible root node. 62 * @return Return RET_OK if obtains elementInfo successfully, otherwise refer to the RetError for the failure. 63 */ 64 RetError GetRoot(AccessibilityElementInfo &elementInfo); 65 66 /** 67 * @brief Obtains elementInfo of the accessible root node. 68 * @param windowInfo The source window info to get root. 69 * @param elementInfo The elementInfo of the accessible root node. 70 * @return Return RET_OK if obtains elementInfo successfully, otherwise refer to the RetError for the failure. 71 */ 72 RetError GetRootByWindow(const AccessibilityWindowInfo &windowInfo, 73 AccessibilityElementInfo &elementInfo); 74 75 /** 76 * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users. 77 * @param windows The information of windows. 78 * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure. 79 */ 80 RetError GetWindows(std::vector<AccessibilityWindowInfo> &windows); 81 82 /** 83 * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users. 84 * @param displayId the id of display 85 * @param windows The information of windows. 86 * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure. 87 */ 88 RetError GetWindows(const uint64_t displayId, std::vector<AccessibilityWindowInfo> &windows); 89 90 /** 91 * @brief Gets the next focused node in the specified direction of the currently focused node. 92 * @param elementInfo 93 * @param direction Indicates the direction to obtain the next focused node. Refer to FocusMoveDirection 94 * @param nextElementInfo The info of next element. 95 * @return Return RET_OK if gets next elementInfo successfully, otherwise refer to the RetError for the failure. 96 */ 97 RetError GetNext(const AccessibilityElementInfo &elementInfo, const FocusMoveDirection direction, 98 AccessibilityElementInfo &nextElementInfo); 99 100 /** 101 * @brief Get the child node information by childId 102 * @param index 103 * @param parent 104 * @param child The element info of child 105 * @return Return RET_OK if gets child elementInfo successfully, otherwise refer to the RetError for the failure. 106 */ 107 RetError GetChildElementInfo(const int32_t index, const AccessibilityElementInfo &parent, 108 AccessibilityElementInfo &child); 109 110 /** 111 * @brief Searches for node information based on the specified content. 112 * @param elementInfo 113 * @param text specified content 114 * @param elementInfos 115 * @return Return RET_OK if gets elementInfos successfully, otherwise refer to the RetError for the failure. 116 */ 117 RetError GetByContent(const AccessibilityElementInfo &elementInfo, const std::string &text, 118 std::vector<AccessibilityElementInfo> &elementInfos); 119 120 /** 121 * @brief Get Parent node information 122 * @param child 123 * @param parent 124 * @return Return RET_OK if gets info successfully, otherwise refer to the RetError for the failure. 125 */ 126 RetError GetParentElementInfo(const AccessibilityElementInfo &child, AccessibilityElementInfo &parent); 127 128 /** 129 * @brief Executes a specified action. 130 * @param elementInfo 131 * @param action: the action type 132 * @param actionArguments: The parameter for action type. such as: 133 * action: ACCESSIBILITY_ACTION_NEXT_HTML_ITEM, 134 * actionArguments(ACTION_ARGU_HTML_ELEMENT,HtmlItemType) 135 * action: ACCESSIBILITY_ACTION_PREVIOUS_HTML_ITEM, 136 * actionArguments(ACTION_ARGU_HTML_ELEMENT,HtmlItemType) 137 * action: ACCESSIBILITY_ACTION_NEXT_TEXT, 138 * actionArguments(ACTION_ARGU_MOVE_UNIT,MOVE_UNIT_XXX) 139 * action: ACCESSIBILITY_ACTION_PREVIOUS_TEXT, 140 * actionArguments(ACTION_ARGU_MOVE_UNIT,MOVE_UNIT_XXX) 141 * action: ACCESSIBILITY_ACTION_SET_SELECTION, 142 * actionArguments({ACTION_ARGU_SELECT_TEXT_START,"1"(start location)}, 143 * {ACTION_ARGU_SELECT_TEXT_END,"10"(end location)}) 144 * action: ACCESSIBILITY_ACTION_SET_TEXT, 145 * actionArguments(ACTION_ARGU_SET_TEXT,"the text of setted") 146 * @return Return RET_OK if performs action succeed, otherwise refer to the RetError for the failure. 147 */ 148 RetError ExecuteAction(const AccessibilityElementInfo &elementInfo, const ActionType action, 149 const std::map<std::string, std::string> &actionArguments); 150 151 /** 152 * @brief Set target bundle names. 153 * @param targetBundleNames The target bundle name 154 * @return Return RET_OK if sets target bundle names successfully, otherwise refer to the RetError for the failure. 155 */ 156 RetError SetTargetBundleName(const std::vector<std::string> &targetBundleNames); 157 }; 158 } // namespace Accessibility 159 } // namespace OHOS 160 #endif // ACCESSIBILITY_EXTENSION_CONTEXT_H