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 ACCESSIBLE_ABILITY_CLIENT_H 17 #define ACCESSIBLE_ABILITY_CLIENT_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 "accessible_ability_listener.h" 26 #include "iremote_object.h" 27 28 namespace OHOS { 29 namespace Accessibility { 30 class AccessibleAbilityClient : public virtual RefBase { 31 public: 32 /** 33 * @brief Destruct 34 */ 35 virtual ~AccessibleAbilityClient() = default; 36 37 /** 38 * @brief Gets an instance of AccessibleAbilityClient. 39 * @return Return an instance of AccessibleAbilityClient. 40 */ 41 static sptr<AccessibleAbilityClient> GetInstance(); 42 43 /** 44 * @brief Gets remote object. 45 * @return Remote object. 46 */ 47 virtual sptr<IRemoteObject> GetRemoteObject() = 0; 48 49 /** 50 * @brief Obtains elementInfo of focus. 51 * @param focusType The type of focus. It contains FOCUS_TYPE_INPUT and FOCUS_TYPE_ACCESSIBILITY. 52 * @param elementInfo The accessibilityElementInfo of focus. 53 * @return Return RET_OK if obtains elementInfo successfully, otherwise refer to the RetError for the failure. 54 */ 55 virtual RetError GetFocus(const int32_t focusType, AccessibilityElementInfo &elementInfo) = 0; 56 57 /** 58 * @brief Obtains elementInfo of focus. 59 * @param sourceInfo The source info to get focus. 60 * @param focusType The type of focus. It contains FOCUS_TYPE_INPUT and FOCUS_TYPE_ACCESSIBILITY. 61 * @param elementInfo The accessibilityElementInfo of focus. 62 * @return Return RET_OK if obtains elementInfo successfully, otherwise refer to the RetError for the failure. 63 */ 64 virtual RetError GetFocusByElementInfo(const AccessibilityElementInfo &sourceInfo, const int32_t focusType, 65 AccessibilityElementInfo &elementInfo) = 0; 66 67 /** 68 * @brief Sends simulate gestures to the screen. 69 * @param gesturePath The gesture which need to send. 70 * @return Return RET_OK if the gesture sends successfully, otherwise refer to the RetError for the failure. 71 */ 72 virtual RetError InjectGesture(const std::shared_ptr<AccessibilityGestureInjectPath> &gesturePath) = 0; 73 74 /** 75 * @brief Obtains elementInfo of the accessible root node. 76 * @param elementInfo The elementInfo of the accessible root node. 77 * @return Return RET_OK if obtains elementInfo successfully, otherwise refer to the RetError for the failure. 78 */ 79 virtual RetError GetRoot(AccessibilityElementInfo &elementInfo) = 0; 80 81 /** 82 * @brief Obtains elementInfo of the accessible root node. 83 * @param windowInfo The source window info to get root. 84 * @param elementInfo The elementInfo of the accessible root node. 85 * @return Return RET_OK if obtains elementInfo successfully, otherwise refer to the RetError for the failure. 86 */ 87 virtual RetError GetRootByWindow(const AccessibilityWindowInfo &windowInfo, 88 AccessibilityElementInfo &elementInfo) = 0; 89 90 /** 91 * @brief Get the window information related with the event 92 * @param windowId The window id. 93 * @param windowInfo The window information. 94 * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure. 95 */ 96 virtual RetError GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) = 0; 97 98 /** 99 * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users. 100 * @param windows The information of windows. 101 * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure. 102 */ 103 virtual RetError GetWindows(std::vector<AccessibilityWindowInfo> &windows) = 0; 104 105 /** 106 * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users. 107 * @param displayId the id of display 108 * @param windows The information of windows. 109 * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure. 110 */ 111 virtual RetError GetWindows(const uint64_t displayId, std::vector<AccessibilityWindowInfo> &windows) = 0; 112 113 /** 114 * @brief Gets the next focused node in the specified direction of the currently focused node. 115 * @param elementInfo The source info to get next info. 116 * @param direction Indicates the direction to obtain the next focused node. Refer to FocusMoveDirection 117 * @param nextElementInfo The info of next element. 118 * @return Return RET_OK if gets next elementInfo successfully, otherwise refer to the RetError for the failure. 119 */ 120 virtual RetError GetNext(const AccessibilityElementInfo &elementInfo, const FocusMoveDirection direction, 121 AccessibilityElementInfo &nextElementInfo) = 0; 122 123 /** 124 * @brief Get the child node information by child index. 125 * @param index The index of the child. 126 * @param parent The parent info to get child. 127 * @param child The element info of child. 128 * @return Return RET_OK if gets child elementInfo successfully, otherwise refer to the RetError for the failure. 129 */ 130 virtual RetError GetChildElementInfo(const int32_t index, const AccessibilityElementInfo &parent, 131 AccessibilityElementInfo &child) = 0; 132 133 /** 134 * @brief Get the children node information 135 * @param parent The parent info to get children. 136 * @param children The element info of children. 137 * @return Return RET_OK if gets children elementInfo successfully, otherwise refer to the RetError for the failure. 138 */ 139 virtual RetError GetChildren(const AccessibilityElementInfo &parent, 140 std::vector<AccessibilityElementInfo> &children) = 0; 141 142 /** 143 * @brief Searches for node information based on the specified content. 144 * @param elementInfo The source info. 145 * @param text specified content 146 * @param elementInfos The element infos of specified content. 147 * @return Return RET_OK if gets elementInfos successfully, otherwise refer to the RetError for the failure. 148 */ 149 virtual RetError GetByContent(const AccessibilityElementInfo &elementInfo, const std::string &text, 150 std::vector<AccessibilityElementInfo> &elementInfos) = 0; 151 152 /** 153 * @brief Get the node information related with the event 154 * @param eventInfo The source info to get source. 155 * @param elementInfo The element info of source. 156 * @return Return RET_OK if gets elementInfos successfully, otherwise refer to the RetError for the failure. 157 */ 158 virtual RetError GetSource(const AccessibilityEventInfo &eventInfo, AccessibilityElementInfo &elementInfo) = 0; 159 160 /** 161 * @brief Get Parent node information 162 * @param child The child element info to get parent. 163 * @param parent The parent element info. 164 * @return Return RET_OK if gets info successfully, otherwise refer to the RetError for the failure. 165 */ 166 virtual RetError GetParentElementInfo(const AccessibilityElementInfo &child, AccessibilityElementInfo &parent) = 0; 167 168 /** 169 * @brief Executes a specified action. 170 * @param elementInfo The source info to execute action. 171 * @param action: the action type 172 * @param actionArguments: The parameter for action type. such as: 173 * action: ACCESSIBILITY_ACTION_NEXT_HTML_ITEM, 174 * actionArguments(ACTION_ARGU_HTML_ELEMENT,HtmlItemType) 175 * action: ACCESSIBILITY_ACTION_PREVIOUS_HTML_ITEM, 176 * actionArguments(ACTION_ARGU_HTML_ELEMENT,HtmlItemType) 177 * action: ACCESSIBILITY_ACTION_NEXT_TEXT, 178 * actionArguments(ACTION_ARGU_MOVE_UNIT,MOVE_UNIT_XXX) 179 * action: ACCESSIBILITY_ACTION_PREVIOUS_TEXT, 180 * actionArguments(ACTION_ARGU_MOVE_UNIT,MOVE_UNIT_XXX) 181 * action: ACCESSIBILITY_ACTION_SET_SELECTION, 182 * actionArguments({ACTION_ARGU_SELECT_TEXT_START,"1"(start location)}, 183 * {ACTION_ARGU_SELECT_TEXT_END,"10"(end location)}) 184 * action: ACCESSIBILITY_ACTION_SET_TEXT, 185 * actionArguments(ACTION_ARGU_SET_TEXT,"the text of setted") 186 * @return Return RET_OK if performs action succeed, otherwise refer to the RetError for the failure. 187 */ 188 virtual RetError ExecuteAction(const AccessibilityElementInfo &elementInfo, const ActionType action, 189 const std::map<std::string, std::string> &actionArguments) = 0; 190 191 /** 192 * @brief Register ability listener. 193 * @param listener The listener to add. 194 * @return Return RET_OK if registers listener successfully, otherwise refer to the RetError for the failure. 195 */ 196 virtual RetError RegisterAbilityListener(const std::shared_ptr<AccessibleAbilityListener> &listener) = 0; 197 198 /** 199 * @brief Set target bundle names. 200 * @param targetBundleNames The target bundle name 201 * @return Return RET_OK if sets target bundle names successfully, otherwise refer to the RetError for the failure. 202 */ 203 virtual RetError SetTargetBundleName(const std::vector<std::string> &targetBundleNames) = 0; 204 205 /** 206 * @brief Set cache mode. 207 * The mode is used for functions: GetRoot, GetRootByWindow, GetChildElementInfo, 208 * GetChildren, GetSource, GetParentElementInfo. 209 * @param cacheMode The cache mode. It includes: 210 * PREFETCH_PREDECESSORS: cache the parent node info also. 211 * PREFETCH_SIBLINGS: cache the sister/brothers node info also. 212 * PREFETCH_CHILDREN: cache the child node info also. 213 * otherwise: no cache. 214 * @return Return RET_OK if sets cache mode successfully, otherwise refer to the RetError for the failure. 215 */ 216 virtual RetError SetCacheMode(const int32_t cacheMode) = 0; 217 }; 218 } // namespace Accessibility 219 } // namespace OHOS 220 #endif // ACCESSIBLE_ABILITY_CLIENT_H