1 /*
2  * Copyright (c) 2022 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 "frameworks/bridge/declarative_frontend/jsview/models/ability_component_model_impl.h"
17 
18 #include "frameworks/base/utils/utils.h"
19 #include "frameworks/bridge/declarative_frontend/view_stack_processor.h"
20 #include "frameworks/core/event/ace_event_handler.h"
21 
22 namespace OHOS::Ace::Framework {
Create(const std::string & bundleName,const std::string & abilityName)23 void AbilityComponentModelImpl::Create(const std::string& bundleName, const std::string& abilityName)
24 {
25     auto abilityComponent = AceType::MakeRefPtr<OHOS::Ace::V2::AbilityComponent>();
26     ViewStackProcessor::GetInstance()->ClaimElementId(abilityComponent);
27     ViewStackProcessor::GetInstance()->Push(abilityComponent);
28 }
29 
GetComponent()30 RefPtr<OHOS::Ace::V2::AbilityComponent> AbilityComponentModelImpl::GetComponent()
31 {
32     auto* stack = ViewStackProcessor::GetInstance();
33     if (!stack) {
34         return nullptr;
35     }
36     auto component = AceType::DynamicCast<OHOS::Ace::V2::AbilityComponent>(stack->GetMainComponent());
37     return component;
38 }
39 
SetWant(const std::string & want)40 void AbilityComponentModelImpl::SetWant(const std::string& want)
41 {
42     auto component = GetComponent();
43     CHECK_NULL_VOID(component);
44 
45     component->SetWant(want);
46 }
47 
SetWidth(Dimension value)48 void AbilityComponentModelImpl::SetWidth(Dimension value)
49 {
50     auto component = GetComponent();
51     CHECK_NULL_VOID(component);
52 
53     component->SetWidth(value);
54 }
55 
SetHeight(Dimension value)56 void AbilityComponentModelImpl::SetHeight(Dimension value)
57 {
58     auto component = GetComponent();
59     CHECK_NULL_VOID(component);
60 
61     component->SetHeight(value);
62 }
63 
SetOnConnect(std::function<void ()> && onConnect)64 void AbilityComponentModelImpl::SetOnConnect(std::function<void()>&& onConnect)
65 {
66     auto component = GetComponent();
67     CHECK_NULL_VOID(component);
68     component->SetOnConnected(std::move(onConnect));
69 }
70 
SetOnDisConnect(std::function<void ()> && onDisConnect)71 void AbilityComponentModelImpl::SetOnDisConnect(std::function<void()>&& onDisConnect)
72 {
73     auto component = GetComponent();
74     CHECK_NULL_VOID(component);
75     component->SetOnDisconnected(std::move(onDisConnect));
76 }
77 
78 } // namespace OHOS::Ace::Framework
79