• 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(
23     const std::shared_ptr<Rosen::RSSurfaceNode>& surfaceNode,
24     const OHOS::AppExecFwk::FormJsInfo& formJsInfo,
25     const AAFwk::Want& want)
26 {
27     HILOG_DEBUG("%{public}s called.", __func__);
28     if (!surfaceNode) {
29         HILOG_ERROR("surface is invalid");
30         return ERR_NULL_OBJECT;
31     }
32     int64_t formId = formJsInfo.formId;
33     if (formId < 0) {
34         HILOG_ERROR("%{public}s error, the passed form id can't be negative.", __func__);
35         return ERR_INVALID_DATA;
36     }
37 
38     if (!surfaceCreateEventHandler_) {
39         HILOG_ERROR("surfaceCreateEventHandler_ is null");
40         return ERR_INVALID_DATA;
41     }
42     surfaceCreateEventHandler_(surfaceNode, formJsInfo, want);
43     return ERR_OK;
44 }
45 
OnActionEvent(const std::string & action)46 int32_t FormRendererDelegateImpl::OnActionEvent(const std::string& action)
47 {
48     HILOG_INFO("OnActionEvent %{public}s", action.c_str());
49     if (!actionEventHandler_) {
50         HILOG_ERROR("actionEventHandler_ is null,  %{public}s", action.c_str());
51         return ERR_INVALID_DATA;
52     }
53 
54     actionEventHandler_(action);
55     return ERR_OK;
56 }
57 
OnError(const std::string & code,const std::string & msg)58 int32_t FormRendererDelegateImpl::OnError(const std::string& code, const std::string& msg)
59 {
60     HILOG_INFO("OnError code: %{public}s, msg: %{public}s", code.c_str(), msg.c_str());
61     if (!errorEventHandler_) {
62         HILOG_ERROR("errorEventHandler_ is null");
63         return ERR_INVALID_DATA;
64     }
65 
66     errorEventHandler_(code, msg);
67     return ERR_OK;
68 }
69 
OnSurfaceChange(float width,float height)70 int32_t FormRendererDelegateImpl::OnSurfaceChange(float width, float height)
71 {
72     HILOG_DEBUG("%{public}s called.", __func__);
73     if (!surfaceChangeEventHandler_) {
74         HILOG_ERROR("surfaceChangeEventHandler_ is null");
75         return ERR_INVALID_DATA;
76     }
77     surfaceChangeEventHandler_(width, height);
78     return ERR_OK;
79 }
80 
SetSurfaceCreateEventHandler(std::function<void (const std::shared_ptr<Rosen::RSSurfaceNode> &,const OHOS::AppExecFwk::FormJsInfo &,const AAFwk::Want &)> && listener)81 void FormRendererDelegateImpl::SetSurfaceCreateEventHandler(
82     std::function<void(const std::shared_ptr<Rosen::RSSurfaceNode>&, const OHOS::AppExecFwk::FormJsInfo&,
83         const AAFwk::Want&)>&& listener)
84 {
85     surfaceCreateEventHandler_ = std::move(listener);
86 }
87 
SetActionEventHandler(std::function<void (const std::string &)> && listener)88 void FormRendererDelegateImpl::SetActionEventHandler(
89     std::function<void(const std::string&)>&& listener)
90 {
91     actionEventHandler_ = std::move(listener);
92 }
93 
SetErrorEventHandler(std::function<void (const std::string &,const std::string &)> && listener)94 void FormRendererDelegateImpl::SetErrorEventHandler(
95     std::function<void(const std::string&, const std::string&)>&& listener)
96 {
97     errorEventHandler_ = std::move(listener);
98 }
99 
SetSurfaceChangeEventHandler(std::function<void (float width,float height)> && listener)100 void FormRendererDelegateImpl::SetSurfaceChangeEventHandler(std::function<void(float width, float height)>&& listener)
101 {
102     surfaceChangeEventHandler_ = std::move(listener);
103 }
104 } // namespace Ace
105 } // namespace OHOS
106