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