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 "bridge/declarative_frontend/jsview/models/stack_model_impl.h"
17
18 #include "base/memory/referenced.h"
19 #include "frameworks/bridge/declarative_frontend/jsview/js_interactable_view.h"
20 #include "frameworks/bridge/declarative_frontend/view_stack_processor.h"
21
22 namespace OHOS::Ace::Framework {
23
Create()24 void StackModelImpl::Create()
25 {
26 Alignment alignment = Alignment::CENTER;
27 std::list<RefPtr<Component>> children;
28 RefPtr<StackComponent> component =
29 AceType::MakeRefPtr<StackComponent>(alignment, StackFit::KEEP, Overflow::OBSERVABLE, children);
30 ViewStackProcessor::GetInstance()->ClaimElementId(component);
31 ViewStackProcessor::GetInstance()->Push(component);
32 JSInteractableView::SetFocusNode(true);
33 }
34
Create(Alignment alignment)35 void StackModelImpl::Create(Alignment alignment)
36 {
37 std::list<RefPtr<Component>> children;
38 RefPtr<StackComponent> component =
39 AceType::MakeRefPtr<StackComponent>(alignment, StackFit::KEEP, Overflow::OBSERVABLE, children);
40 ViewStackProcessor::GetInstance()->ClaimElementId(component);
41 ViewStackProcessor::GetInstance()->Push(component);
42 JSInteractableView::SetFocusNode(true);
43 }
44
SetStackFit(StackFit fit)45 void StackModelImpl::SetStackFit(StackFit fit)
46 {
47 auto stack = AceType::DynamicCast<StackComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
48 if (stack) {
49 stack->SetStackFit(fit);
50 }
51 }
52
SetOverflow(Overflow overflow)53 void StackModelImpl::SetOverflow(Overflow overflow)
54 {
55 auto stack = AceType::DynamicCast<StackComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
56 if (stack) {
57 stack->SetOverflow(overflow);
58 }
59 }
60
SetAlignment(Alignment alignment)61 void StackModelImpl::SetAlignment(Alignment alignment)
62 {
63 auto stack = AceType::DynamicCast<StackComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
64 if (stack) {
65 stack->SetAlignment(alignment);
66 }
67 }
68
SetHasWidth()69 void StackModelImpl::SetHasWidth()
70 {
71 auto stack = AceType::DynamicCast<StackComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
72 if (stack) {
73 if (stack->GetMainStackSize() == MainStackSize::MAX || stack->GetMainStackSize() == MainStackSize::MAX_Y) {
74 stack->SetMainStackSize(MainStackSize::MAX);
75 } else {
76 stack->SetMainStackSize(MainStackSize::MAX_X);
77 }
78 }
79 }
80
SetHasHeight()81 void StackModelImpl::SetHasHeight()
82 {
83 auto stack = AceType::DynamicCast<StackComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
84 if (stack) {
85 if (stack->GetMainStackSize() == MainStackSize::MAX || stack->GetMainStackSize() == MainStackSize::MAX_X) {
86 stack->SetMainStackSize(MainStackSize::MAX);
87 } else {
88 stack->SetMainStackSize(MainStackSize::MAX_Y);
89 }
90 }
91 }
92
93 } // namespace OHOS::Ace::Framework
94