• 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_ELEMENT_OPERATOR_STUB_H
17 #define ACCESSIBILITY_ELEMENT_OPERATOR_STUB_H
18 
19 #include <cstdint>
20 #include <list>
21 #include <mutex>
22 #include <string>
23 #include <vector>
24 
25 #include "accessibility_element_operator_interface.h"
26 #include "accessibility_element_operator_callback.h"
27 #include "accessibility_errorcode.h"
28 #include "iremote_object.h"
29 #include "iremote_stub.h"
30 #include "nocopyable.h"
31 
32 namespace OHOS {
33 namespace Accessibility {
34 /*
35 * The class define the interface for UI to implement.
36 * It is triggered by ABMS when AA to request the accessibility information.
37 */
38 class AccessibilityElementOperatorStub : public IRemoteStub<IAccessibilityElementOperator> {
39 public:
40     /**
41      * @brief construct function
42      * @param object The object of IPC
43      * @return
44      */
45     AccessibilityElementOperatorStub();
46 
47     /**
48      * @brief destruct function
49      * @param
50      * @return
51      */
52     virtual ~AccessibilityElementOperatorStub();
53 
54     /**
55      * @brief Receive the event from proxy by IPC mechanism.
56      * @param code The code is matched with the process function.
57      * @param data The data of process communication
58      * @param reply The response of IPC request
59      * @param option The option parameter of IPC,such as: async,sync
60      * @return
61      */
62     virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
63         MessageOption &option) override;
64 
65     /**
66      * @brief Make the node information by accessibility ID and set the result by callback.
67      * @param elementId: The unique id of the component ID.
68      * @param requestId Matched the request and response. It needn't cared by ACE, transfer it by callback only.
69      * @param callback  To transfer the node info to ASAC and it defined by ASAC.
70      * @param mode PREFETCH_PREDECESSORS: Need to make the parent node info also.
71      *              PREFETCH_SIBLINGS: Need to make the sister/brothers node info also.
72      *              PREFETCH_CHILDREN: Need to make the child node info also.
73      *              otherwise: Make the node information by elementId only.
74      * @return -
75      */
76     virtual void SearchElementInfoByAccessibilityId(const long elementId, const int requestId,
77         const sptr<IAccessibilityElementOperatorCallback> &callback, const int mode) override;
78 
79     /**
80      * @brief Make the child node information by accessibility ID and filtered by text and set the result by callback.
81      * @param elementId: The unique id of the component ID.
82      * @param requestId Matched the request and response. It needn't cared by ACE, transfer it by callback only.
83      * @param callback  To transfer the node info to ASAC and it defined by ASAC.
84      * @param text  Filter for the child components to matched with the text
85      * @return
86      */
87     virtual void SearchElementInfosByText(const long elementId, const std::string &text,
88         const int requestId, const sptr<IAccessibilityElementOperatorCallback> &callback) override;
89 
90     /**
91      * @brief Make the node information of the component focused by the focus type specified.
92      * @param elementId: The unique id of the component ID.
93      * @param requestId Matched the request and response. It needn't cared by ACE, transfer it by callback only.
94      * @param callback  To transfer the node info to ASAC and it defined by ASAC.
95      * @param focusType FOCUS_TYPE_ACCESSIBILITY: accessibility focus
96      *                  FOCUS_TYPE_INPUT: text input focus
97      * @return
98      */
99     virtual void FindFocusedElementInfo(const long elementId, const int focusType, const int requestId,
100         const sptr<IAccessibilityElementOperatorCallback> &callback) override;
101 
102     /**
103      * @brief Make the node info by current focus move direction.
104      * @param elementId: The unique id of the component ID.
105      * @param requestId Matched the request and response. It needn't cared by ACE, transfer it by callback only.
106      * @param callback  To transfer the node info to ASAC and it defined by ASAC.
107      * @param direction Refer to AccessibilityElementInfo.FocusMoveDirection(UP/DOWN/LEFT/RIGHT/FORWARD/BACKWARD)
108      * @return -
109      */
110     virtual void FocusMoveSearch(const long elementId, const int direction, const int requestId,
111         const sptr<IAccessibilityElementOperatorCallback> &callback) override;
112 
113     /**
114      * @brief To return the result of perform action.
115      * @param elementId: The unique id of the component ID.
116      * @param requestId Matched the request and response. It needn't cared by ACE, transfer it by callback only.
117      * @param callback  To transfer the node info to ASAC and it defined by ASAC.
118      * @param action Refer to [AccessibilityElementInfo.ActionType]
119      * @param actionArguments The parameter for action type. such as:
120      *      action: ACCESSIBILITY_ACTION_NEXT_HTML_ITEM,
121      *                  actionArguments(ACTION_ARGU_HTML_ELEMENT,HtmlItemType)
122      *      action: ACCESSIBILITY_ACTION_PREVIOUS_HTML_ITEM,
123      *                  actionArguments(ACTION_ARGU_HTML_ELEMENT,HtmlItemType)
124      *      action: ACCESSIBILITY_ACTION_NEXT_TEXT,
125      *                  actionArguments(ACTION_ARGU_MOVE_UNIT,MOVE_UNIT_XXX)
126      *      action: ACCESSIBILITY_ACTION_PREVIOUS_TEXT,
127      *                  actionArguments(ACTION_ARGU_MOVE_UNIT,MOVE_UNIT_XXX)
128      *      action: ACCESSIBILITY_ACTION_SET_SELECTION,
129      *                  actionArguments({ACTION_ARGU_SELECT_TEXT_START,"1"(start location)},
130      *                                  {ACTION_ARGU_SELECT_TEXT_END,"10"(end location)})
131      *      action: ACCESSIBILITY_ACTION_SET_TEXT,
132      *                  actionArguments(ACTION_ARGU_SET_TEXT,"the text of setted")
133      * @return
134      */
135     virtual void ExecuteAction(const long elementId, const int action,
136         const std::map<std::string, std::string> actionArguments,
137         int requestId, const sptr<IAccessibilityElementOperatorCallback> &callback) override;
138 
139     /**
140      * @brief The function is called while accessibility System check the id of window is not equal
141      * to the id of active window when sendAccessibility.
142      * @param -
143      * @return
144      */
145 
146     virtual void ClearFocus() override;
147 
148     /**
149      * @brief the low layser is notified by the function called while accessibility system execute
150      * the function of executeAction from AS to check the all low windows cared the outside event.
151      * Example: PopupWindow receive the OUTSIDE_EVENT to close itself.
152      * @param -
153      * @return
154      */
155     virtual void OutsideTouch() override;
156 
157     /**
158      * @brief Save the window id related with operator object
159      * @param windowId: The unique id of the window related with operator object.
160      * @return -
161      */
162     void SetWindowId(int windowId);
163 
164     /**
165      * @brief Get the window id related with operator object
166      * @param windowId: The unique id of the window related with operator object.
167      * @return -
168      */
169     int GetWindowId();
170 
171     /**
172      * Implement the function to set the result to AA when ACE complete the request.
173      */
174     class CallbackImpl : public AccessibilityElementOperatorCallback {
175     public:
176         enum CALL_API_NUM : uint32_t {
177             CALLBACK_BY_ACCESSIBILITY_ID = 0x00000001,
178             CALLBACK_BY_TEXT = 0x00000002,
179             CALLBACK_FIND_FOCUS = 0x00000004,
180             CALLBACK_BY_FOCUS_MOVE = 0x00000008,
181             CALLBACK_PERFORM_ACTION = 0x00000010,
182         };
183 
184         /**
185          * @brief construct function
186          * @param object The object of IPC
187          * @return
188          */
189         CallbackImpl();
190 
191         /**
192          * @brief construct function
193          * @param requestId The request id from AA, it is used to match with request and response.
194          * @param callNum The id is matched handle function of IPC.
195          * @return
196          */
197         CallbackImpl(const int requestId, CALL_API_NUM callNum);
198 
199         /**
200          * @brief Set the element information by accessibility id to AA.
201          * @param infos The element info searched by accessibility id.
202          * @param requestId The request id from AA, it is used to match with request and response.
203          * @return
204          */
205         virtual void SetSearchElementInfoByAccessibilityIdResult(const std::list<AccessibilityElementInfo> &infos,
206             const int requestId) override;
207 
208         /**
209          * @brief Set the element information matched with text to AA.
210          * @param infos The element information searched matched with text.
211          * @param requestId The request id from AA, it is used to match with request and response.
212          * @return
213          */
214         virtual void SetSearchElementInfoByTextResult(const std::list<AccessibilityElementInfo> &infos,
215             const int requestId) override;
216 
217         /**
218          * @brief Set the element information matched with focus type to AA.
219          * @param info The element information searched matched with focus type.
220          * @param requestId The request id from AA, it is used to match with request and response.
221          * @return
222          */
223         virtual void SetFindFocusedElementInfoResult(const AccessibilityElementInfo &info,
224             const int requestId) override;
225 
226         /**
227          * @brief Set the element information by focus direction to AA.
228          * @param info The element information searched by focus direction.
229          * @param requestId The request id from AA, it is used to match with request and response.
230          * @return
231          */
232         virtual void SetFocusMoveSearchResult(const AccessibilityElementInfo &info, const int requestId) override;
233 
234         /**
235          * @brief Set the result of action executed to AA.
236          * @param succeeded True: The action is executed successfully; otherwise is false.
237          * @param requestId The request id from AA, it is used to match with request and response.
238          * @return
239          */
240         virtual void SetExecuteActionResult(const bool succeeded, const int requestId) override;
241 
242         /**
243          * @brief Get the callback object of AA.
244          * @param
245          * @return The callback object of AA and the request id matched.
246          */
247         std::map<const int, const sptr<IAccessibilityElementOperatorCallback>> GetAACallbackList();
248 
249         /**
250          * @brief Remove the callback object of AA after send the result to AA.
251          * @param requestId The request id from AA, it is used to match with request and response.
252          * @return
253          */
254         void RemoveAACallbackList(int requestId);
255     private:
256         int requestId_ = 0;
257         CALL_API_NUM callNum_ = CALLBACK_BY_ACCESSIBILITY_ID;
258     };
259 private:
260     /**
261      * @brief Handle the IPC request for the function:SetSearchElementInfoByAccessibilityIdResult.
262      * @param data The data of process communication
263      * @param reply The response of IPC request
264      * @return NO_ERROR: successful; otherwise is failed.
265      */
266     ErrCode HandleSearchElementInfoByAccessibilityId(MessageParcel &data, MessageParcel &reply);
267 
268     /**
269      * @brief Handle the IPC request for the function:SetSearchElementInfoByTextResult.
270      * @param data The data of process communication
271      * @param reply The response of IPC request
272      * @return NO_ERROR: successful; otherwise is failed.
273      */
274     ErrCode HandleSearchElementInfosByText(MessageParcel &data, MessageParcel &reply);
275 
276     /**
277      * @brief Handle the IPC request for the function:SetFindFocusedElementInfoResult.
278      * @param data The data of process communication
279      * @param reply The response of IPC request
280      * @return NO_ERROR: successful; otherwise is failed.
281      */
282     ErrCode HandleFindFocusedElementInfo(MessageParcel &data, MessageParcel &reply);
283 
284     /**
285      * @brief Handle the IPC request for the function:SetFocusMoveSearchResult.
286      * @param data The data of process communication
287      * @param reply The response of IPC request
288      * @return NO_ERROR: successful; otherwise is failed.
289      */
290     ErrCode HandleFocusFind(MessageParcel &data, MessageParcel &reply);
291 
292     /**
293      * @brief Handle the IPC request for the function:SetExecuteActionResult.
294      * @param data The data of process communication
295      * @param reply The response of IPC request
296      * @return NO_ERROR: successful; otherwise is failed.
297      */
298     ErrCode HandleExecuteAction(MessageParcel &data, MessageParcel &reply);
299 
300     /**
301      * @brief Handle the IPC request for the function:ClearFocus.
302      * @param data The data of process communication
303      * @param reply The response of IPC request
304      * @return NO_ERROR: successful; otherwise is failed.
305      */
306     ErrCode HandleClearFocus(MessageParcel &data, MessageParcel &reply);
307 
308     /**
309      * @brief Handle the IPC request for the function:OutsideTouch.
310      * @param data The data of process communication
311      * @param reply The response of IPC request
312      * @return NO_ERROR: successful; otherwise is failed.
313      */
314     ErrCode HandleOutsideTouch(MessageParcel &data, MessageParcel &reply);
315 
316     using AccessibilityElementOperatorFunc =
317         ErrCode (AccessibilityElementOperatorStub::*)(MessageParcel &data, MessageParcel &reply);
318     std::map<uint32_t, AccessibilityElementOperatorFunc> memberFuncMap_;
319     static std::map<const int, const sptr<IAccessibilityElementOperatorCallback>>  aaCallbacks_;
320     static std::recursive_mutex mutex_;
321     int windowId_ = 0;
322     DISALLOW_COPY_AND_MOVE(AccessibilityElementOperatorStub);
323 };
324 } // namespace Accessibility
325 } // namespace OHOS
326 #endif