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 #include "core/interfaces/native/node/column_modifier.h"
16
17 #include "core/components/common/layout/constants.h"
18 #include "core/components/common/properties/alignment.h"
19 #include "core/components_ng/base/frame_node.h"
20 #include "core/components_ng/base/view_abstract.h"
21 #include "core/components_ng/pattern/linear_layout/column_model_ng.h"
22 #include "core/pipeline/base/element_register.h"
23
24 namespace OHOS::Ace::NG {
25 constexpr FlexAlign DEFAULT_JUSTIFY_CONTENT = FlexAlign::FLEX_START;
26 const int32_t ERROR_INT_CODE = -1;
27
SetColumnJustifyContent(ArkUINodeHandle node,int32_t flexAlign)28 void SetColumnJustifyContent(ArkUINodeHandle node, int32_t flexAlign)
29 {
30 auto* frameNode = reinterpret_cast<FrameNode*>(node);
31 CHECK_NULL_VOID(frameNode);
32 ColumnModelNG::SetJustifyContent(frameNode, static_cast<FlexAlign>(flexAlign));
33 }
34
ResetColumnJustifyContent(ArkUINodeHandle node)35 void ResetColumnJustifyContent(ArkUINodeHandle node)
36 {
37 auto* frameNode = reinterpret_cast<FrameNode*>(node);
38 CHECK_NULL_VOID(frameNode);
39 ColumnModelNG::SetJustifyContent(frameNode, DEFAULT_JUSTIFY_CONTENT);
40 }
41
SetColumnAlignItems(ArkUINodeHandle node,int32_t value)42 void SetColumnAlignItems(ArkUINodeHandle node, int32_t value)
43 {
44 auto* frameNode = reinterpret_cast<FrameNode*>(node);
45 CHECK_NULL_VOID(frameNode);
46 if ((value == static_cast<int32_t>(FlexAlign::FLEX_START)) ||
47 (value == static_cast<int32_t>(FlexAlign::FLEX_END)) || (value == static_cast<int32_t>(FlexAlign::CENTER)) ||
48 (value == static_cast<int32_t>(FlexAlign::STRETCH))) {
49 ColumnModelNG::SetAlignItems(frameNode, static_cast<FlexAlign>(value));
50 } else if (Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TEN)) {
51 ColumnModelNG::SetAlignItems(frameNode, FlexAlign::CENTER);
52 }
53 FlexAlign value_flexAlign = static_cast<FlexAlign>(value);
54 ColumnModelNG::SetAlignItems(frameNode, value_flexAlign);
55 }
56
ResetColumnAlignItems(ArkUINodeHandle node)57 void ResetColumnAlignItems(ArkUINodeHandle node)
58 {
59 auto* frameNode = reinterpret_cast<FrameNode*>(node);
60 CHECK_NULL_VOID(frameNode);
61 ColumnModelNG::SetAlignItems(frameNode, FlexAlign::CENTER);
62 }
63
GetColumnJustifyContent(ArkUINodeHandle node)64 ArkUI_Int32 GetColumnJustifyContent(ArkUINodeHandle node)
65 {
66 auto* frameNode = reinterpret_cast<FrameNode*>(node);
67 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
68 return static_cast<ArkUI_Int32>(ColumnModelNG::GetJustifyContent(frameNode));
69 }
70
GetColumnAlignItems(ArkUINodeHandle node)71 ArkUI_Int32 GetColumnAlignItems(ArkUINodeHandle node)
72 {
73 auto* frameNode = reinterpret_cast<FrameNode*>(node);
74 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
75 return static_cast<ArkUI_Int32>(ColumnModelNG::GetAlignItems(frameNode));
76 }
77
SetColumnSpace(ArkUINodeHandle node,ArkUI_Float32 value,ArkUI_Int32 unit)78 void SetColumnSpace(ArkUINodeHandle node, ArkUI_Float32 value, ArkUI_Int32 unit)
79 {
80 auto* frameNode = reinterpret_cast<FrameNode*>(node);
81 CHECK_NULL_VOID(frameNode);
82 const auto space = CalcDimension(value, static_cast<OHOS::Ace::DimensionUnit>(unit));
83 ColumnModelNG::SetSpace(frameNode, space);
84 }
85
ResetColumnSpace(ArkUINodeHandle node)86 void ResetColumnSpace(ArkUINodeHandle node)
87 {
88 auto* frameNode = reinterpret_cast<FrameNode*>(node);
89 CHECK_NULL_VOID(frameNode);
90 const auto space = CalcDimension(0.0, DimensionUnit::PX);
91 ColumnModelNG::SetSpace(frameNode, space);
92 }
93
SetColumnReverse(ArkUINodeHandle node,ArkUI_Bool value)94 void SetColumnReverse(ArkUINodeHandle node, ArkUI_Bool value)
95 {
96 auto* frameNode = reinterpret_cast<FrameNode*>(node);
97 CHECK_NULL_VOID(frameNode);
98 ColumnModelNG::SetIsReverse(frameNode, value);
99 }
100
ResetColumnReverse(ArkUINodeHandle node)101 void ResetColumnReverse(ArkUINodeHandle node)
102 {
103 auto* frameNode = reinterpret_cast<FrameNode*>(node);
104 CHECK_NULL_VOID(frameNode);
105 ColumnModelNG::SetIsReverse(frameNode, false);
106 }
107
108 namespace NodeModifier {
GetColumnModifier()109 const ArkUIColumnModifier* GetColumnModifier()
110 {
111 static const ArkUIColumnModifier modifier = {
112 SetColumnJustifyContent,
113 ResetColumnJustifyContent,
114 SetColumnAlignItems,
115 ResetColumnAlignItems,
116 GetColumnJustifyContent,
117 GetColumnAlignItems,
118 SetColumnSpace,
119 ResetColumnSpace,
120 SetColumnReverse,
121 ResetColumnReverse,
122 };
123 return &modifier;
124 }
125
GetCJUIColumnModifier()126 const CJUIColumnModifier* GetCJUIColumnModifier()
127 {
128 static const CJUIColumnModifier modifier = {
129 SetColumnJustifyContent,
130 ResetColumnJustifyContent,
131 SetColumnAlignItems,
132 ResetColumnAlignItems,
133 GetColumnJustifyContent,
134 GetColumnAlignItems,
135 SetColumnSpace,
136 ResetColumnSpace,
137 };
138 return &modifier;
139 }
140 }
141 }
142