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 
16 #ifndef FOUNDATION_ACE_INTERFACE_INNERKITS_FORM_RENDERER_DELEGATE_IMPL_H
17 #define FOUNDATION_ACE_INTERFACE_INNERKITS_FORM_RENDERER_DELEGATE_IMPL_H
18 
19 #include "form_renderer_delegate_stub.h"
20 
21 namespace OHOS {
22 namespace Ace {
23 /**
24  * @class FormRendererDelegate
25  * FormRendererDelegate interface is used to form renderer delegate.
26  */
27 class ACE_EXPORT FormRendererDelegateImpl : public FormRendererDelegateStub {
28 public:
29     FormRendererDelegateImpl() = default;
30     ~FormRendererDelegateImpl() override = default;
31     /**
32      * @brief OnSurfaceCreate.
33      * @param surfaceNode The surfaceNode.
34      * @param formJsInfo The formJsInfo.
35      * @param want The want.
36      */
37     int32_t OnSurfaceCreate(const std::shared_ptr<Rosen::RSSurfaceNode>& surfaceNode,
38         const OHOS::AppExecFwk::FormJsInfo& formJsInfo, const AAFwk::Want& want) override;
39     /**
40      * @brief OnActionEvent.
41      * @param action The action.
42      */
43     int32_t OnActionEvent(const std::string& action) override;
44     /**
45      * @brief OnError.
46      * @param code The code.
47      * @param msg The msg.
48      */
49     int32_t OnError(const std::string& code, const std::string& msg) override;
50     /**
51      * @brief OnSurfaceChange.
52      * @param width
53      * @param height
54      */
55     int32_t OnSurfaceChange(float width, float height, float borderWidth = 0.0) override;
56     /**
57      * @brief OnSurfaceDetach.
58      * @param surfaceId The surfaceNode ID.
59      */
60     int32_t OnSurfaceDetach(uint64_t surfaceId) override;
61 
62     int32_t OnFormLinkInfoUpdate(const std::vector<std::string>& formLinkInfos) override;
63 
64     int32_t OnGetRectRelativeToWindow(int32_t &top, int32_t &left) override;
65 
66     void SetSurfaceCreateEventHandler(std::function<void(const std::shared_ptr<Rosen::RSSurfaceNode>&,
67             const OHOS::AppExecFwk::FormJsInfo&, const AAFwk::Want&)>&& listener);
68     void SetActionEventHandler(std::function<void(const std::string&)>&& listener);
69     void SetErrorEventHandler(std::function<void(const std::string&, const std::string&)>&& listener);
70     void SetSurfaceChangeEventHandler(std::function<void(float width, float height, float borderWidth)>&& listener);
71     void SetSurfaceDetachEventHandler(std::function<void()>&& listener);
72     void SetFormLinkInfoUpdateHandler(std::function<void(const std::vector<std::string>&)>&& listener);
73     void SetGetRectRelativeToWindowHandler(std::function<void(int32_t&, int32_t&)>&& listener);
74 private:
75     std::function<void(
76         const std::shared_ptr<Rosen::RSSurfaceNode>&, const OHOS::AppExecFwk::FormJsInfo&, const AAFwk::Want&)>
77         surfaceCreateEventHandler_;
78     std::function<void(const std::string&)> actionEventHandler_;
79     std::function<void(const std::string&, const std::string&)> errorEventHandler_;
80     std::function<void(float width, float height, float borderWidth)> surfaceChangeEventHandler_;
81     std::function<void()> surfaceDetachEventHandler_;
82     std::function<void(const std::vector<std::string>&)> formLinkInfoUpdateHandler_;
83     std::function<void(int32_t&, int32_t&)> getRectRelativeToWindowHandler_;
84 };
85 } // namespace Ace
86 } // namespace OHOS
87 #endif // FOUNDATION_ACE_INTERFACE_INNERKITS_FORM_RENDERER_DELEGATE_IMPL_H
88