1 /*
2 * Copyright (c) 2023 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 #include "form_renderer_delegate_impl.h"
16
17 #include "form_renderer_hilog.h"
18
19 namespace OHOS {
20 namespace Ace {
OnSurfaceCreate(const std::shared_ptr<Rosen::RSSurfaceNode> & surfaceNode,const OHOS::AppExecFwk::FormJsInfo & formJsInfo,const AAFwk::Want & want)21 int32_t FormRendererDelegateImpl::OnSurfaceCreate(const std::shared_ptr<Rosen::RSSurfaceNode>& surfaceNode,
22 const OHOS::AppExecFwk::FormJsInfo& formJsInfo, const AAFwk::Want& want)
23 {
24 HILOG_DEBUG("%{public}s called.", __func__);
25 if (!surfaceNode) {
26 HILOG_ERROR("surface is invalid");
27 return ERR_NULL_OBJECT;
28 }
29 int64_t formId = formJsInfo.formId;
30 if (formId < 0) {
31 HILOG_ERROR("%{public}s error, the passed form id can't be negative.", __func__);
32 return ERR_INVALID_DATA;
33 }
34
35 if (!surfaceCreateEventHandler_) {
36 HILOG_ERROR("surfaceCreateEventHandler_ is null");
37 return ERR_INVALID_DATA;
38 }
39 surfaceCreateEventHandler_(surfaceNode, formJsInfo, want);
40 return ERR_OK;
41 }
42
OnActionEvent(const std::string & action)43 int32_t FormRendererDelegateImpl::OnActionEvent(const std::string& action)
44 {
45 HILOG_INFO("OnActionEvent %{public}zu", action.length());
46 if (!actionEventHandler_) {
47 HILOG_ERROR("actionEventHandler_ is null, %{public}zu", action.length());
48 return ERR_INVALID_DATA;
49 }
50
51 actionEventHandler_(action);
52 return ERR_OK;
53 }
54
OnError(const std::string & code,const std::string & msg)55 int32_t FormRendererDelegateImpl::OnError(const std::string& code, const std::string& msg)
56 {
57 HILOG_INFO("OnError code: %{public}s, msg: %{public}s", code.c_str(), msg.c_str());
58 if (!errorEventHandler_) {
59 HILOG_ERROR("errorEventHandler_ is null");
60 return ERR_INVALID_DATA;
61 }
62
63 errorEventHandler_(code, msg);
64 return ERR_OK;
65 }
66
OnSurfaceChange(float width,float height,float borderWidth)67 int32_t FormRendererDelegateImpl::OnSurfaceChange(float width, float height, float borderWidth)
68 {
69 HILOG_DEBUG("%{public}s called.", __func__);
70 if (!surfaceChangeEventHandler_) {
71 HILOG_ERROR("surfaceChangeEventHandler_ is null");
72 return ERR_INVALID_DATA;
73 }
74 surfaceChangeEventHandler_(width, height, borderWidth);
75 return ERR_OK;
76 }
77
OnSurfaceDetach(uint64_t surfaceId)78 int32_t FormRendererDelegateImpl::OnSurfaceDetach(uint64_t surfaceId)
79 {
80 HILOG_DEBUG("%{public}s called.", __func__);
81 if (!surfaceDetachEventHandler_) {
82 HILOG_ERROR("surfaceDetachEventHandler_ is null");
83 return ERR_INVALID_DATA;
84 }
85 surfaceDetachEventHandler_();
86 return ERR_OK;
87 }
88
OnFormLinkInfoUpdate(const std::vector<std::string> & formLinkInfos)89 int32_t FormRendererDelegateImpl::OnFormLinkInfoUpdate(const std::vector<std::string>& formLinkInfos)
90 {
91 HILOG_DEBUG("%{public}s called.", __func__);
92 if (!formLinkInfoUpdateHandler_) {
93 HILOG_ERROR("formLinkInfoUpdateHandler_ is null");
94 return ERR_INVALID_DATA;
95 }
96 formLinkInfoUpdateHandler_(formLinkInfos);
97 return ERR_OK;
98 }
99
OnGetRectRelativeToWindow(AccessibilityParentRectInfo & parentRectInfo)100 int32_t FormRendererDelegateImpl::OnGetRectRelativeToWindow(AccessibilityParentRectInfo& parentRectInfo)
101 {
102 HILOG_DEBUG("%{public}s called.", __func__);
103 if (!getRectRelativeToWindowHandler_) {
104 HILOG_ERROR("getRectRelativeToWindowHandler_ is null");
105 return ERR_INVALID_DATA;
106 }
107 getRectRelativeToWindowHandler_(parentRectInfo);
108 return ERR_OK;
109 }
110
OnCheckManagerDelegate(bool & checkFlag)111 int32_t FormRendererDelegateImpl::OnCheckManagerDelegate(bool &checkFlag)
112 {
113 if (!checkManagerDelegate_) {
114 HILOG_ERROR("checkManagerDelegate_ is null");
115 return ERR_INVALID_DATA;
116 }
117 checkManagerDelegate_(checkFlag);
118 return ERR_OK;
119 }
120
OnUpdateFormDone(const int64_t formId)121 int32_t FormRendererDelegateImpl::OnUpdateFormDone(const int64_t formId)
122 {
123 if (formId < 0) {
124 HILOG_ERROR("invalid formId");
125 return ERR_INVALID_DATA;
126 }
127
128 if (!updateFormEventHandler_) {
129 HILOG_ERROR("updateFormEventHandler_ is null");
130 return ERR_INVALID_DATA;
131 }
132 updateFormEventHandler_(formId);
133 return ERR_OK;
134 }
135
SetSurfaceCreateEventHandler(std::function<void (const std::shared_ptr<Rosen::RSSurfaceNode> &,const OHOS::AppExecFwk::FormJsInfo &,const AAFwk::Want &)> && listener)136 void FormRendererDelegateImpl::SetSurfaceCreateEventHandler(
137 std::function<void(const std::shared_ptr<Rosen::RSSurfaceNode>&, const OHOS::AppExecFwk::FormJsInfo&,
138 const AAFwk::Want&)>&& listener)
139 {
140 surfaceCreateEventHandler_ = std::move(listener);
141 }
142
SetActionEventHandler(std::function<void (const std::string &)> && listener)143 void FormRendererDelegateImpl::SetActionEventHandler(std::function<void(const std::string&)>&& listener)
144 {
145 HILOG_INFO("EventHandle - SetActionEventHandler");
146 actionEventHandler_ = std::move(listener);
147 }
148
SetErrorEventHandler(std::function<void (const std::string &,const std::string &)> && listener)149 void FormRendererDelegateImpl::SetErrorEventHandler(
150 std::function<void(const std::string&, const std::string&)>&& listener)
151 {
152 errorEventHandler_ = std::move(listener);
153 }
154
SetSurfaceChangeEventHandler(std::function<void (float width,float height,float borderWidth)> && listener)155 void FormRendererDelegateImpl::SetSurfaceChangeEventHandler(
156 std::function<void(float width, float height, float borderWidth)>&& listener)
157 {
158 surfaceChangeEventHandler_ = std::move(listener);
159 }
160
SetSurfaceDetachEventHandler(std::function<void ()> && listener)161 void FormRendererDelegateImpl::SetSurfaceDetachEventHandler(std::function<void()>&& listener)
162 {
163 surfaceDetachEventHandler_ = std::move(listener);
164 }
165
SetFormLinkInfoUpdateHandler(std::function<void (const std::vector<std::string> &)> && listener)166 void FormRendererDelegateImpl::SetFormLinkInfoUpdateHandler(
167 std::function<void(const std::vector<std::string>&)>&& listener)
168 {
169 formLinkInfoUpdateHandler_ = std::move(listener);
170 }
171
SetGetRectRelativeToWindowHandler(std::function<void (AccessibilityParentRectInfo & parentRectInfo)> && listener)172 void FormRendererDelegateImpl::SetGetRectRelativeToWindowHandler(
173 std::function<void(AccessibilityParentRectInfo& parentRectInfo)>&& listener)
174 {
175 getRectRelativeToWindowHandler_ = std::move(listener);
176 }
177
SetCheckManagerDelegate(std::function<void (bool &)> && listener)178 void FormRendererDelegateImpl::SetCheckManagerDelegate(std::function<void(bool&)>&& listener)
179 {
180 checkManagerDelegate_ = std::move(listener);
181 }
182
SetUpdateFormEventHandler(std::function<void (const int64_t)> && listener)183 void FormRendererDelegateImpl::SetUpdateFormEventHandler(std::function<void(const int64_t)>&& listener)
184 {
185 updateFormEventHandler_ = std::move(listener);
186 }
187 } // namespace Ace
188 } // namespace OHOS
189