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 #include "accessibility_element_operator_callback_impl.h"
17 #include "hilog_wrapper.h"
18 
19 namespace OHOS {
20 namespace Accessibility {
SetFindFocusedElementInfoResult(const AccessibilityElementInfo & info,const int32_t requestId)21 void AccessibilityElementOperatorCallbackImpl::SetFindFocusedElementInfoResult(const AccessibilityElementInfo &info,
22     const int32_t requestId)
23 {
24     HILOG_DEBUG("Response [requestId:%{public}d]", requestId);
25     accessibilityInfoResult_ = info;
26     if (promiseFlag_ == false) {
27         promise_.set_value();
28         promiseFlag_ = true;
29     }
30 }
31 
SetSearchElementInfoByTextResult(const std::vector<AccessibilityElementInfo> & infos,const int32_t requestId)32 void AccessibilityElementOperatorCallbackImpl::SetSearchElementInfoByTextResult(
33     const std::vector<AccessibilityElementInfo> &infos, const int32_t requestId)
34 {
35     HILOG_DEBUG("Response [elementInfoSize:%{public}zu] [requestId:%{public}d]", infos.size(), requestId);
36     elementInfosResult_ = infos;
37     if (promiseFlag_ == false) {
38         promise_.set_value();
39         promiseFlag_ = true;
40     }
41 }
42 
SetSearchElementInfoByAccessibilityIdResult(const std::vector<AccessibilityElementInfo> & infos,const int32_t requestId)43 void AccessibilityElementOperatorCallbackImpl::SetSearchElementInfoByAccessibilityIdResult(
44     const std::vector<AccessibilityElementInfo> &infos, const int32_t requestId)
45 {
46     HILOG_DEBUG("Response[elementInfoSize:%{public}zu] [requestId:%{public}d]", infos.size(), requestId);
47     elementInfosResult_ = infos;
48     if (promiseFlag_ == false) {
49         promise_.set_value();
50         promiseFlag_ = true;
51     }
52 }
53 
SetFocusMoveSearchResult(const AccessibilityElementInfo & info,const int32_t requestId)54 void AccessibilityElementOperatorCallbackImpl::SetFocusMoveSearchResult(const AccessibilityElementInfo &info,
55     const int32_t requestId)
56 {
57     HILOG_DEBUG("Response [requestId:%{public}d]", requestId);
58     accessibilityInfoResult_ = info;
59     if (promiseFlag_ == false) {
60         promise_.set_value();
61         promiseFlag_ = true;
62     }
63 }
64 
SetExecuteActionResult(const bool succeeded,const int32_t requestId)65 void AccessibilityElementOperatorCallbackImpl::SetExecuteActionResult(const bool succeeded, const int32_t requestId)
66 {
67     HILOG_DEBUG("Response [requestId:%{public}d] result[%{public}d]", requestId, succeeded);
68     executeActionResult_ = succeeded;
69     if (promiseFlag_ == false) {
70         promise_.set_value();
71         promiseFlag_ = true;
72     }
73 }
74 
SetCursorPositionResult(const int32_t cursorPosition,const int32_t requestId)75 void AccessibilityElementOperatorCallbackImpl::SetCursorPositionResult(const int32_t cursorPosition,
76     const int32_t requestId)
77 {
78     HILOG_DEBUG("Response [requestId:%{public}d] cursorPosition[%{public}d]", requestId, cursorPosition);
79     CursorPosition_ = cursorPosition;
80     if (promiseFlag_ == false) {
81         promise_.set_value();
82         promiseFlag_ = true;
83     }
84 }
85 } // namespace Accessibility
86 } // namespace OHOS