1 /*
2 * Copyright (c) 2023-2024 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 "bridge/declarative_frontend/jsview/models/form_model_impl.h"
16
17 #include "bridge/declarative_frontend/view_stack_processor.h"
18 #include "core/components/form/form_component.h"
19
20 namespace OHOS::Ace::Framework {
Create(const RequestFormInfo & info)21 void FormModelImpl::Create(const RequestFormInfo& info)
22 {
23 RefPtr<FormComponent> form = AceType::MakeRefPtr<OHOS::Ace::FormComponent>();
24 form->SetFormRequestInfo(info);
25 form->SetInspectorTag("FormComponent");
26 ViewStackProcessor::GetInstance()->Push(form, false);
27 auto boxComponent = ViewStackProcessor::GetInstance()->GetBoxComponent();
28 boxComponent->SetMouseAnimationType(HoverAnimationType::SCALE);
29 }
30
SetSize(const Dimension & width,const Dimension & height)31 void FormModelImpl::SetSize(const Dimension& width, const Dimension& height)
32 {
33 auto form = AceType::DynamicCast<FormComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
34 if (form) {
35 form->SetCardSize(width.IsValid() ? width : 0.0_vp, height.IsValid() ? height : 0.0_vp);
36 }
37 }
38
SetDimension(int32_t value)39 void FormModelImpl::SetDimension(int32_t value)
40 {
41 auto form = AceType::DynamicCast<FormComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
42 if (form) {
43 form->SetDimension(value);
44 }
45 }
46
AllowUpdate(bool value)47 void FormModelImpl::AllowUpdate(bool value)
48 {
49 auto form = AceType::DynamicCast<FormComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
50 if (form) {
51 form->SetAllowUpdate(value);
52 }
53 }
54
SetVisible(VisibleType visible)55 void FormModelImpl::SetVisible(VisibleType visible) {}
56
SetVisibility(VisibleType visible)57 void FormModelImpl::SetVisibility(VisibleType visible)
58 {
59 auto component = ViewStackProcessor::GetInstance()->GetDisplayComponent();
60 auto display = AceType::DynamicCast<DisplayComponent>(component);
61 display->SetVisible(visible);
62 }
63
SetModuleName(const std::string & value)64 void FormModelImpl::SetModuleName(const std::string& value)
65 {
66 auto form = AceType::DynamicCast<FormComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
67 if (form) {
68 form->SetModuleName(value);
69 }
70 }
71
SetOnAcquired(std::function<void (const std::string &)> && onAcquired)72 void FormModelImpl::SetOnAcquired(std::function<void(const std::string&)>&& onAcquired)
73 {
74 auto form = AceType::DynamicCast<FormComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
75 auto onAppearId = EventMarker(std::move(onAcquired));
76 if (form) {
77 form->SetOnAcquireFormEventId(onAppearId);
78 }
79 }
80
SetOnError(std::function<void (const std::string &)> && onError)81 void FormModelImpl::SetOnError(std::function<void(const std::string&)>&& onError)
82 {
83 auto form = AceType::DynamicCast<FormComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
84 auto onErrorId = EventMarker(std::move(onError));
85 if (form) {
86 form->SetOnErrorEventId(onErrorId);
87 }
88 }
89
SetOnUninstall(std::function<void (const std::string &)> && onUninstall)90 void FormModelImpl::SetOnUninstall(std::function<void(const std::string&)>&& onUninstall)
91 {
92 auto form = AceType::DynamicCast<FormComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
93 auto onUninstallId = EventMarker(std::move(onUninstall));
94 if (form) {
95 form->SetOnUninstallEventId(onUninstallId);
96 }
97 }
98
SetOnRouter(std::function<void (const std::string &)> && onRouter)99 void FormModelImpl::SetOnRouter(std::function<void(const std::string&)>&& onRouter)
100 {
101 auto form = AceType::DynamicCast<FormComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
102 auto onRouterId = EventMarker(std::move(onRouter));
103 if (form) {
104 form->SetOnRouterEventId(onRouterId);
105 }
106 }
107
SetOnLoad(std::function<void (const std::string &)> && onLoad)108 void FormModelImpl::SetOnLoad(std::function<void(const std::string&)>&& onLoad)
109 {
110 LOGE("Not support onLoad in old pipeline");
111 }
112
SetObscured(const std::vector<ObscuredReasons> & reasons)113 void FormModelImpl::SetObscured(const std::vector<ObscuredReasons>& reasons)
114 {
115 LOGE("Not support SetObscured in old pipeline");
116 }
117
RequestPublishFormWithSnapshot(const AAFwk::Want & want,const std::string & formBindingDataStr,int64_t & formId,std::string & errMsg)118 int32_t FormModelImpl::RequestPublishFormWithSnapshot(const AAFwk::Want& want,
119 const std::string& formBindingDataStr, int64_t& formId, std::string &errMsg)
120 {
121 LOGE("Not support RequestPublishFormWithSnapshot in old pipeline");
122 return 0;
123 }
124 } // namespace OHOS::Ace::Framework
125