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