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