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_CALLBACK_IMPL_H
17 #define ACCESSIBILITY_ELEMENT_OPERATOR_CALLBACK_IMPL_H
18 
19 #include "accessibility_element_operator_callback_stub.h"
20 #include "ffrt_inner.h"
21 
22 namespace OHOS {
23 namespace Accessibility {
24 /*
25 * The class supply the api called by AA to get the accessibility info of UI.
26 * It call the API of AAMS and the request will be processed by
27 * UI and then set the result by callback(AA-->this class(with Callback)--> AAMS
28 * --> UI process and set Callback).
29 * It supply one instance for each thread to use this class.
30 */
31 class AccessibilityElementOperatorCallbackImpl : public AccessibilityElementOperatorCallbackStub {
32 public:
33     /**
34      * @brief construct function
35      */
36     AccessibilityElementOperatorCallbackImpl() = default;
37 
38     /**
39      * @brief deconstruct function
40      */
41     ~AccessibilityElementOperatorCallbackImpl() = default;
42 
43     /**
44      * @brief Save the elements information searched in ACE side
45      * @param infos The elements info searched by accessibility id.
46      * @param requestId The request id from AA, it is used to match with request and response.
47      */
48     virtual void SetSearchElementInfoByAccessibilityIdResult(const std::vector<AccessibilityElementInfo> &infos,
49         const int32_t requestId) override;
50 
51     /**
52      * @brief Save the elements information searched in ACE side
53      * @param infos The elements info searched by accessibility id.
54      * @param requestId The request id from AA, it is used to match with request and response.
55      */
56     virtual void SetSearchElementInfoByTextResult(const std::vector<AccessibilityElementInfo> &infos,
57         const int32_t requestId) override;
58 
59     /**
60      * @brief Save the element information searched in ACE side
61      * @param info The element info searched by accessibility id.
62      * @param requestId The request id from AA, it is used to match with request and response.
63      */
64     virtual void SetFindFocusedElementInfoResult(const AccessibilityElementInfo &info,
65         const int32_t requestId) override;
66 
67     /**
68      * @brief Save the element information searched in ACE side
69      * @param info The element info searched by accessibility id.
70      * @param requestId The request id from AA, it is used to match with request and response.
71      */
72     virtual void SetFocusMoveSearchResult(const AccessibilityElementInfo &info, const int32_t requestId) override;
73 
74     /**
75      * @brief Save the result of action executed in ACE.
76      * @param succeeded True: The action is executed successfully; otherwise is false.
77      * @param requestId The request id from AA, it is used to match with request and response.
78      */
79     virtual void SetExecuteActionResult(const bool succeeded, const int32_t requestId) override;
80 
81    /**
82      * @brief Set the result of cursor position to AA.
83      * @param cursorPosition The cursorPosition to be returned.
84      * @param requestId The request id from AA, it is used to match with request and response.
85      */
86     virtual void SetCursorPositionResult(const int32_t cursorPosition, const int32_t requestId) override;
87 
88 private:
89     ffrt::promise<void> promise_;
90     std::atomic<bool> promiseFlag_ = false;
91     bool executeActionResult_ = false;
92     AccessibilityElementInfo accessibilityInfoResult_ = {};
93     std::vector<AccessibilityElementInfo> elementInfosResult_;
94     int32_t CursorPosition_ = 0 ;
95     friend class AccessibleAbilityChannelClient;
96 };
97 } // namespace Accessibility
98 } // namespace OHOS
99 #endif // ACCESSIBILITY_ELEMENT_OPERATOR_CALLBACK_IMPL_H