• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 
16 #include "interfaces/inner_api/ace_kit/include/ui/view/layout/box_layout_algorithm.h"
17 
18 #include "interfaces/inner_api/ace_kit/src/view/frame_node_impl.h"
19 
20 #include "core/components_ng/layout/box_layout_algorithm.h"
21 
22 namespace OHOS::Ace::Kit {
23 
Measure(const Kit::LayoutConstraintInfo & contentConstraint)24 void BoxLayoutAlgorithm::Measure(const Kit::LayoutConstraintInfo& contentConstraint)
25 {
26     auto frameNode = host_.Upgrade();
27     if (frameNode) {
28         frameNode->MeasureChildren();
29         BoxLayoutAlgorithm::PerformMeasureSelf(AceType::RawPtr(frameNode));
30     }
31 }
32 
Layout()33 void BoxLayoutAlgorithm::Layout()
34 {
35     auto frameNode = host_.Upgrade();
36     if (frameNode) {
37         BoxLayoutAlgorithm::PerformLayout(AceType::RawPtr(frameNode));
38         frameNode->LayoutChildren();
39     }
40 }
41 
MeasureContent(const NG::LayoutConstraintT<float> & contentConstraint)42 std::optional<NG::SizeF> BoxLayoutAlgorithm::MeasureContent(const NG::LayoutConstraintT<float>& contentConstraint)
43 {
44     auto frameNode = DynamicCast<FrameNodeImpl>(host_.Upgrade());
45     if (frameNode) {
46         return NG::BoxLayoutAlgorithm::PerformMeasureContent(contentConstraint, frameNode->GetLayoutWrapper());
47     }
48     return std::nullopt;
49 }
50 
PerformMeasureSelf(FrameNode * frameNode)51 void BoxLayoutAlgorithm::PerformMeasureSelf(FrameNode* frameNode)
52 {
53     auto* frameNodeImpl = reinterpret_cast<FrameNodeImpl*>(frameNode);
54     CHECK_NULL_VOID(frameNodeImpl);
55     auto* layoutWrapper = frameNodeImpl->GetLayoutWrapper();
56     NG::BoxLayoutAlgorithm::PerformMeasureSelf(layoutWrapper);
57 }
58 
PerformLayout(FrameNode * frameNode)59 void BoxLayoutAlgorithm::PerformLayout(FrameNode* frameNode)
60 {
61     auto* frameNodeImpl = reinterpret_cast<FrameNodeImpl*>(frameNode);
62     CHECK_NULL_VOID(frameNodeImpl);
63     auto* layoutWrapper = frameNodeImpl->GetLayoutWrapper();
64     NG::BoxLayoutAlgorithm::PerformLayout(layoutWrapper);
65 }
66 
PerformMeasureSelfWithChildList(FrameNode * frameNode)67 void BoxLayoutAlgorithm::PerformMeasureSelfWithChildList(FrameNode* frameNode)
68 {
69     auto* frameNodeImpl = reinterpret_cast<FrameNodeImpl*>(frameNode);
70     CHECK_NULL_VOID(frameNodeImpl);
71     auto* layoutWrapper = frameNodeImpl->GetLayoutWrapper();
72     CHECK_NULL_VOID(layoutWrapper);
73     NG::BoxLayoutAlgorithm::PerformMeasureSelfWithChildList(
74         layoutWrapper, layoutWrapper->GetAllChildrenWithBuild());
75 }
76 } // namespace OHOS::Ace::Kit
77