• 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_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 SetSearchDefaultFocusByWindowIdResult(const std::vector<AccessibilityElementInfo> &infos,
57         const int32_t requestId) override;
58 
59     /**
60      * @brief Save the elements information searched in ACE side
61      * @param infos The elements 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 SetSearchElementInfoByTextResult(const std::vector<AccessibilityElementInfo> &infos,
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 SetFindFocusedElementInfoResult(const AccessibilityElementInfo &info,
73         const int32_t requestId) override;
74 
75     /**
76      * @brief Save the element information searched in ACE side
77      * @param info The element info searched by accessibility id.
78      * @param requestId The request id from AA, it is used to match with request and response.
79      */
80     virtual void SetFocusMoveSearchResult(const AccessibilityElementInfo &info, const int32_t requestId) override;
81 
82     /**
83      * @brief Save the result of action executed in ACE.
84      * @param succeeded True: The action is executed successfully; otherwise is false.
85      * @param requestId The request id from AA, it is used to match with request and response.
86      */
87     virtual void SetExecuteActionResult(const bool succeeded, const int32_t requestId) override;
88 
89    /**
90      * @brief Set the result of cursor position to AA.
91      * @param cursorPosition The cursorPosition to be returned.
92      * @param requestId The request id from AA, it is used to match with request and response.
93      */
94     virtual void SetCursorPositionResult(const int32_t cursorPosition, const int32_t requestId) override;
95 
96     /**
97      * @brief Set the search element info by specific property result.
98      * @param infos The element infos searched by specific property.
99      * @param treeInfos The element infos searched by specific property.
100      * @param requestId The request id from AA, it is used to match with request and response.
101      */
102     virtual void SetSearchElementInfoBySpecificPropertyResult(const std::list<AccessibilityElementInfo> &infos,
103         const std::list<AccessibilityElementInfo> &treeInfos, const int32_t requestId) override;
104 
105 private:
106     ffrt::promise<void> promise_;
107     std::atomic<bool> promiseFlag_ = false;
108     bool executeActionResult_ = false;
109     AccessibilityElementInfo accessibilityInfoResult_ = {};
110     std::vector<AccessibilityElementInfo> elementInfosResult_;
111     std::vector<AccessibilityElementInfo> treeInfosResult_;
112     int32_t CursorPosition_ = 0 ;
113     friend class AccessibleAbilityChannelClient;
114 };
115 } // namespace Accessibility
116 } // namespace OHOS
117 #endif // ACCESSIBILITY_ELEMENT_OPERATOR_CALLBACK_IMPL_H