1 /*
2  * Copyright (c) 2021 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_FRAMEWORKS_CORE_COMPONENTS_FORM_FORM_ELEMENT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_FORM_FORM_ELEMENT_H
18 
19 #include "core/pipeline/base/render_element.h"
20 #include "core/components/form/form_component.h"
21 #include "core/components/form/sub_container.h"
22 #include "core/components/form/resource/form_manager_delegate.h"
23 #include "core/pipeline/base/composed_element.h"
24 
25 namespace OHOS::Ace {
26 
27 class FormElement : public RenderElement {
28     DECLARE_ACE_TYPE(FormElement, RenderElement);
29 
30 public:
31     using EventCallback = std::function<void(const std::string&)>;
32 
33     FormElement() = default;
34     ~FormElement() override;
35 
36     void Prepare(const WeakPtr<Element>& parent) override;
37     void Update()  override;
38     void PerformBuild() override;
39 
40     RefPtr<RenderNode> CreateRenderNode() override;
41 
GetSubContainer()42     const RefPtr<SubContainer> GetSubContainer() const
43     {
44         return subContainer_;
45     }
46 
47     void HandleOnAcquireEvent(int64_t);
48     void HandleOnErrorEvent(const std::string code, const std::string msg);
49     void HandleOnRouterEvent(const std::unique_ptr<JsonValue>& action);
50     void HandleOnUninstallEvent(int64_t formId);
51     void OnActionEvent(const std::string& action) const;
52 
ISAllowUpdate()53     bool ISAllowUpdate() const
54     {
55         return cardInfo_.allowUpdate;
56     }
57 
58 private:
59     void CreateCardContainer();
60     void InitEvent(const RefPtr<FormComponent>& component);
61     void UpdateInner(const RequestFormInfo& info);
62 
63 private:
64     RefPtr<SubContainer> subContainer_;
65     RefPtr<FormManagerDelegate> formManagerBridge_;
66 
67     EventCallback onAcquireEvent_;
68     EventCallback onErrorEvent_;
69     EventCallback onUninstallEvent_;
70     EventCallback onRouterEvent_;
71     RequestFormInfo cardInfo_;
72 };
73 
74 } // namespace OHOS::Ace
75 
76 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_FORM_FORM_ELEMENT_H
77