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