• 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 "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 
SetSurfaceCreateEventHandler(std::function<void (const std::shared_ptr<Rosen::RSSurfaceNode> &,const OHOS::AppExecFwk::FormJsInfo &,const AAFwk::Want &)> && listener)121 void FormRendererDelegateImpl::SetSurfaceCreateEventHandler(
122     std::function<void(const std::shared_ptr<Rosen::RSSurfaceNode>&, const OHOS::AppExecFwk::FormJsInfo&,
123         const AAFwk::Want&)>&& listener)
124 {
125     surfaceCreateEventHandler_ = std::move(listener);
126 }
127 
SetActionEventHandler(std::function<void (const std::string &)> && listener)128 void FormRendererDelegateImpl::SetActionEventHandler(std::function<void(const std::string&)>&& listener)
129 {
130     HILOG_INFO("EventHandle - SetActionEventHandler");
131     actionEventHandler_ = std::move(listener);
132 }
133 
SetErrorEventHandler(std::function<void (const std::string &,const std::string &)> && listener)134 void FormRendererDelegateImpl::SetErrorEventHandler(
135     std::function<void(const std::string&, const std::string&)>&& listener)
136 {
137     errorEventHandler_ = std::move(listener);
138 }
139 
SetSurfaceChangeEventHandler(std::function<void (float width,float height,float borderWidth)> && listener)140 void FormRendererDelegateImpl::SetSurfaceChangeEventHandler(
141     std::function<void(float width, float height, float borderWidth)>&& listener)
142 {
143     surfaceChangeEventHandler_ = std::move(listener);
144 }
145 
SetSurfaceDetachEventHandler(std::function<void ()> && listener)146 void FormRendererDelegateImpl::SetSurfaceDetachEventHandler(std::function<void()>&& listener)
147 {
148     surfaceDetachEventHandler_ = std::move(listener);
149 }
150 
SetFormLinkInfoUpdateHandler(std::function<void (const std::vector<std::string> &)> && listener)151 void FormRendererDelegateImpl::SetFormLinkInfoUpdateHandler(
152     std::function<void(const std::vector<std::string>&)>&& listener)
153 {
154     formLinkInfoUpdateHandler_ = std::move(listener);
155 }
156 
SetGetRectRelativeToWindowHandler(std::function<void (AccessibilityParentRectInfo & parentRectInfo)> && listener)157 void FormRendererDelegateImpl::SetGetRectRelativeToWindowHandler(
158     std::function<void(AccessibilityParentRectInfo& parentRectInfo)>&& 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