• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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(Alignment alignment)24 void StackModelImpl::Create(Alignment alignment)
25 {
26     std::list<RefPtr<Component>> children;
27     RefPtr<StackComponent> component =
28         AceType::MakeRefPtr<StackComponent>(alignment, StackFit::KEEP, Overflow::OBSERVABLE, children);
29     ViewStackProcessor::GetInstance()->ClaimElementId(component);
30     ViewStackProcessor::GetInstance()->Push(component);
31     JSInteractableView::SetFocusNode(true);
32 }
33 
SetStackFit(StackFit fit)34 void StackModelImpl::SetStackFit(StackFit fit)
35 {
36     auto stack = AceType::DynamicCast<StackComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
37     if (stack) {
38         stack->SetStackFit(fit);
39     }
40 }
41 
SetOverflow(Overflow overflow)42 void StackModelImpl::SetOverflow(Overflow overflow)
43 {
44     auto stack = AceType::DynamicCast<StackComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
45     if (stack) {
46         stack->SetOverflow(overflow);
47     }
48 }
49 
SetAlignment(Alignment alignment)50 void StackModelImpl::SetAlignment(Alignment alignment)
51 {
52     auto stack = AceType::DynamicCast<StackComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
53     if (stack) {
54         stack->SetAlignment(alignment);
55     }
56 }
57 
SetHasWidth()58 void StackModelImpl::SetHasWidth()
59 {
60     auto stack = AceType::DynamicCast<StackComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
61     if (stack) {
62         if (stack->GetMainStackSize() == MainStackSize::MAX || stack->GetMainStackSize() == MainStackSize::MAX_Y) {
63             stack->SetMainStackSize(MainStackSize::MAX);
64         } else {
65             stack->SetMainStackSize(MainStackSize::MAX_X);
66         }
67     }
68 }
69 
SetHasHeight()70 void StackModelImpl::SetHasHeight()
71 {
72     auto stack = AceType::DynamicCast<StackComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
73     if (stack) {
74         if (stack->GetMainStackSize() == MainStackSize::MAX || stack->GetMainStackSize() == MainStackSize::MAX_X) {
75             stack->SetMainStackSize(MainStackSize::MAX);
76         } else {
77             stack->SetMainStackSize(MainStackSize::MAX_Y);
78         }
79     }
80 }
81 
82 } // namespace OHOS::Ace::Framework
83