• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #include "core/interfaces/native/node/form_component_modifier.h"
17 
18 #include "core/components_ng/pattern/form/form_model_ng.h"
19 
20 namespace OHOS::Ace::NG {
21 const int32_t DEFAULT_VISIBILITY = 0;
22 const int32_t DEFAULT_FORM_DIM = 1;
23 const bool DEFAULT_ALLOW_UPDATE = true;
SetFormVisibility(ArkUINodeHandle node,ArkUI_Int32 visible)24 void SetFormVisibility(ArkUINodeHandle node, ArkUI_Int32 visible)
25 {
26     auto* frameNode = reinterpret_cast<FrameNode*>(node);
27     CHECK_NULL_VOID(frameNode);
28     VisibleType visibility = static_cast<VisibleType>(visible);
29     FormModelNG::SetVisibility(frameNode, visibility);
30 }
31 
AllowUpdate(ArkUINodeHandle node,ArkUI_Bool value)32 void AllowUpdate(ArkUINodeHandle node, ArkUI_Bool value)
33 {
34     auto* frameNode = reinterpret_cast<FrameNode*>(node);
35     CHECK_NULL_VOID(frameNode);
36     FormModelNG::AllowUpdate(frameNode, value);
37 }
38 
SetDimension(ArkUINodeHandle node,ArkUI_Int32 dimension)39 void SetDimension(ArkUINodeHandle node, ArkUI_Int32 dimension)
40 {
41     auto* frameNode = reinterpret_cast<FrameNode*>(node);
42     CHECK_NULL_VOID(frameNode);
43     FormModelNG::SetDimension(frameNode, dimension);
44 }
45 
SetModuleName(ArkUINodeHandle node,const char * value)46 void SetModuleName(ArkUINodeHandle node, const char* value)
47 {
48     auto* frameNode = reinterpret_cast<FrameNode*>(node);
49     CHECK_NULL_VOID(frameNode);
50     std::string moduleName(value);
51     FormModelNG::SetModuleName(frameNode, moduleName);
52 }
53 
SetFormSize(ArkUINodeHandle node,ArkUI_Float32 widthValue,ArkUI_Int32 widthUnit,ArkUI_Float32 heightValue,ArkUI_Int32 heightUnit)54 void SetFormSize(ArkUINodeHandle node, ArkUI_Float32 widthValue, ArkUI_Int32 widthUnit,
55     ArkUI_Float32 heightValue, ArkUI_Int32 heightUnit)
56 {
57     auto* frameNode = reinterpret_cast<FrameNode*>(node);
58     CHECK_NULL_VOID(frameNode);
59     FormModelNG::SetSize(frameNode,
60         Dimension(widthValue, static_cast<OHOS::Ace::DimensionUnit>(widthUnit)),
61         Dimension(heightValue, static_cast<OHOS::Ace::DimensionUnit>(heightUnit)));
62 }
63 
ResetFormVisibility(ArkUINodeHandle node)64 void ResetFormVisibility(ArkUINodeHandle node)
65 {
66     auto* frameNode = reinterpret_cast<FrameNode*>(node);
67     CHECK_NULL_VOID(frameNode);
68     VisibleType visibility = static_cast<VisibleType>(DEFAULT_VISIBILITY);
69     FormModelNG::SetVisibility(frameNode, visibility);
70 }
71 
DisallowUpdate(ArkUINodeHandle node)72 void DisallowUpdate(ArkUINodeHandle node)
73 {
74     auto* frameNode = reinterpret_cast<FrameNode*>(node);
75     CHECK_NULL_VOID(frameNode);
76     FormModelNG::AllowUpdate(frameNode, DEFAULT_ALLOW_UPDATE);
77 }
78 
ResetDimension(ArkUINodeHandle node)79 void ResetDimension(ArkUINodeHandle node)
80 {
81     auto* frameNode = reinterpret_cast<FrameNode*>(node);
82     CHECK_NULL_VOID(frameNode);
83     FormModelNG::SetDimension(frameNode, DEFAULT_FORM_DIM);
84 }
85 
ResetModuleName(ArkUINodeHandle node)86 void ResetModuleName(ArkUINodeHandle node) {}
87 
ResetFormSize(ArkUINodeHandle node)88 void ResetFormSize(ArkUINodeHandle node)
89 {
90     auto* frameNode = reinterpret_cast<FrameNode*>(node);
91     CHECK_NULL_VOID(frameNode);
92     Dimension width = 0.0_vp;
93     Dimension height = 0.0_vp;
94     FormModelNG::SetSize(frameNode, width, height);
95 }
96 
97 namespace NodeModifier {
GetFormComponentModifier()98 const ArkUIFormComponentModifier* GetFormComponentModifier()
99 {
100     CHECK_INITIALIZED_FIELDS_BEGIN(); // don't move this line
101     static const ArkUIFormComponentModifier modifier = {
102         .setFormVisibility = SetFormVisibility,
103         .allowUpdate = AllowUpdate,
104         .setDimension = SetDimension,
105         .setModuleName = SetModuleName,
106         .setFormSize = SetFormSize,
107         .resetFormVisibility = ResetFormVisibility,
108         .disallowUpdate = DisallowUpdate,
109         .resetDimension = ResetDimension,
110         .resetModuleName = ResetModuleName,
111         .resetFormSize = ResetFormSize,
112     };
113     CHECK_INITIALIZED_FIELDS_END(modifier, 0, 0, 0); // don't move this line
114 
115     return &modifier;
116 }
117 
GetCJUIFormComponentModifier()118 const CJUIFormComponentModifier* GetCJUIFormComponentModifier()
119 {
120     CHECK_INITIALIZED_FIELDS_BEGIN(); // don't move this line
121     static const CJUIFormComponentModifier modifier = {
122         .setFormVisibility = SetFormVisibility,
123         .allowUpdate = AllowUpdate,
124         .setDimension = SetDimension,
125         .setModuleName = SetModuleName,
126         .setFormSize = SetFormSize,
127         .resetFormVisibility = ResetFormVisibility,
128         .disallowUpdate = DisallowUpdate,
129         .resetDimension = ResetDimension,
130         .resetModuleName = ResetModuleName,
131         .resetFormSize = ResetFormSize,
132     };
133     CHECK_INITIALIZED_FIELDS_END(modifier, 0, 0, 0); // don't move this line
134 
135     return &modifier;
136 }
137 }
138 } // namespace OHOS::Ace::NG
139