• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2025 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/counter_modifier.h"
16 
17 #include "core/components_ng/pattern/counter/counter_model_ng.h"
18 
19 namespace OHOS::Ace::NG {
SetEnableInc(ArkUINodeHandle node,ArkUI_Bool enableInc)20 void SetEnableInc(ArkUINodeHandle node, ArkUI_Bool enableInc)
21 {
22     auto* frameNode = reinterpret_cast<FrameNode*>(node);
23     CHECK_NULL_VOID(frameNode);
24     CounterModelNG::SetEnableInc(frameNode, enableInc);
25 }
ResetEnableInc(ArkUINodeHandle node)26 void ResetEnableInc(ArkUINodeHandle node)
27 {
28     auto* frameNode = reinterpret_cast<FrameNode*>(node);
29     CHECK_NULL_VOID(frameNode);
30     CounterModelNG::SetEnableInc(frameNode, true);
31 }
SetEnableDec(ArkUINodeHandle node,ArkUI_Bool enableDec)32 void SetEnableDec(ArkUINodeHandle node, ArkUI_Bool enableDec)
33 {
34     auto* frameNode = reinterpret_cast<FrameNode*>(node);
35     CHECK_NULL_VOID(frameNode);
36     CounterModelNG::SetEnableDec(frameNode, enableDec);
37 }
ResetEnableDec(ArkUINodeHandle node)38 void ResetEnableDec(ArkUINodeHandle node)
39 {
40     auto* frameNode = reinterpret_cast<FrameNode*>(node);
41     CHECK_NULL_VOID(frameNode);
42     CounterModelNG::SetEnableDec(frameNode, true);
43 }
44 
SetCounterHeight(ArkUINodeHandle node,ArkUI_Float32 value,ArkUI_Int32 unit)45 void SetCounterHeight(ArkUINodeHandle node, ArkUI_Float32 value, ArkUI_Int32 unit)
46 {
47     auto* frameNode = reinterpret_cast<FrameNode*>(node);
48     CHECK_NULL_VOID(frameNode);
49     Dimension height = Dimension(value, static_cast<OHOS::Ace::DimensionUnit>(unit));
50     CounterModelNG::SetHeight(frameNode, height);
51 }
52 
SetCounterHeightRes(ArkUINodeHandle node,ArkUI_Float32 value,ArkUI_Int32 unit,void * heightRawPtr)53 void SetCounterHeightRes(ArkUINodeHandle node, ArkUI_Float32 value, ArkUI_Int32 unit, void* heightRawPtr)
54 {
55     auto* frameNode = reinterpret_cast<FrameNode*>(node);
56     CHECK_NULL_VOID(frameNode);
57     Dimension height = Dimension(value, static_cast<OHOS::Ace::DimensionUnit>(unit));
58     CounterModelNG::SetHeight(frameNode, height);
59     if (SystemProperties::ConfigChangePerform()) {
60         if (heightRawPtr) {
61             auto* fontWeight = reinterpret_cast<ResourceObject*>(heightRawPtr);
62             auto heightResObj = AceType::Claim(fontWeight);
63             CounterModelNG::CreateWithResourceObj(frameNode, JsCounterResourceType::Height, heightResObj);
64         } else {
65             CounterModelNG::CreateWithResourceObj(frameNode, JsCounterResourceType::Height, nullptr);
66         }
67     }
68 }
69 
ResetCounterHeight(ArkUINodeHandle node)70 void ResetCounterHeight(ArkUINodeHandle node)
71 {
72     if (SystemProperties::ConfigChangePerform()) {
73         auto* frameNode = reinterpret_cast<FrameNode*>(node);
74         CHECK_NULL_VOID(frameNode);
75         CounterModelNG::CreateWithResourceObj(frameNode, JsCounterResourceType::Height, nullptr);
76     }
77 }
78 
SetCounterWidth(ArkUINodeHandle node,ArkUI_Float32 value,ArkUI_Int32 unit)79 void SetCounterWidth(ArkUINodeHandle node, ArkUI_Float32 value, ArkUI_Int32 unit)
80 {
81     auto* frameNode = reinterpret_cast<FrameNode*>(node);
82     CHECK_NULL_VOID(frameNode);
83     Dimension width = Dimension(value, static_cast<OHOS::Ace::DimensionUnit>(unit));
84     CounterModelNG::SetWidth(frameNode, width);
85 }
86 
SetCounterWidthRes(ArkUINodeHandle node,ArkUI_Float32 value,ArkUI_Int32 unit,void * widthRawPtr)87 void SetCounterWidthRes(ArkUINodeHandle node, ArkUI_Float32 value, ArkUI_Int32 unit, void* widthRawPtr)
88 {
89     auto* frameNode = reinterpret_cast<FrameNode*>(node);
90     CHECK_NULL_VOID(frameNode);
91     Dimension width = Dimension(value, static_cast<OHOS::Ace::DimensionUnit>(unit));
92     CounterModelNG::SetWidth(frameNode, width);
93     if (SystemProperties::ConfigChangePerform()) {
94         if (widthRawPtr) {
95             auto* fontWeight = reinterpret_cast<ResourceObject*>(widthRawPtr);
96             auto widthResObj = AceType::Claim(fontWeight);
97             CounterModelNG::CreateWithResourceObj(frameNode, JsCounterResourceType::Width, widthResObj);
98         } else {
99             CounterModelNG::CreateWithResourceObj(frameNode, JsCounterResourceType::Width, nullptr);
100         }
101     }
102 }
103 
ResetCounterWidth(ArkUINodeHandle node)104 void ResetCounterWidth(ArkUINodeHandle node)
105 {
106     if (SystemProperties::ConfigChangePerform()) {
107         auto* frameNode = reinterpret_cast<FrameNode*>(node);
108         CHECK_NULL_VOID(frameNode);
109         CounterModelNG::CreateWithResourceObj(frameNode, JsCounterResourceType::Width, nullptr);
110     }
111 }
112 
SetCounterBackgroundColor(ArkUINodeHandle node,ArkUI_Uint32 color)113 void SetCounterBackgroundColor(ArkUINodeHandle node, ArkUI_Uint32 color)
114 {
115     auto* frameNode = reinterpret_cast<FrameNode*>(node);
116     CHECK_NULL_VOID(frameNode);
117     CounterModelNG::SetBackgroundColor(frameNode, Color(color));
118 }
119 
SetCounterBackgroundColorWithColorSpace(ArkUINodeHandle node,ArkUI_Uint32 color,ArkUI_Int32 colorSpace)120 void SetCounterBackgroundColorWithColorSpace(ArkUINodeHandle node, ArkUI_Uint32 color, ArkUI_Int32 colorSpace)
121 {
122     auto* frameNode = reinterpret_cast<FrameNode*>(node);
123     CHECK_NULL_VOID(frameNode);
124     Color backgroundColor { color };
125     if (ColorSpace::DISPLAY_P3 == colorSpace) {
126         backgroundColor.SetColorSpace(ColorSpace::DISPLAY_P3);
127     } else {
128         backgroundColor.SetColorSpace(ColorSpace::SRGB);
129     }
130     CounterModelNG::SetBackgroundColor(frameNode, backgroundColor);
131 }
132 
SetCounterBackgroundColorRes(ArkUINodeHandle node,ArkUI_Uint32 color,ArkUI_Int32 colorSpace,void * colorRawPtr)133 void SetCounterBackgroundColorRes(ArkUINodeHandle node, ArkUI_Uint32 color, ArkUI_Int32 colorSpace, void* colorRawPtr)
134 {
135     auto* frameNode = reinterpret_cast<FrameNode*>(node);
136     Color backgroundColor { color };
137     if (ColorSpace::DISPLAY_P3 == colorSpace) {
138         backgroundColor.SetColorSpace(ColorSpace::DISPLAY_P3);
139     } else {
140         backgroundColor.SetColorSpace(ColorSpace::SRGB);
141     }
142     CounterModelNG::SetBackgroundColor(frameNode, backgroundColor);
143 
144     if (SystemProperties::ConfigChangePerform()) {
145         if (colorRawPtr) {
146             auto* colorResObj = reinterpret_cast<ResourceObject*>(colorRawPtr);
147             CounterModelNG::CreateWithResourceObj(
148                 frameNode, JsCounterResourceType::BackgroundColor, AceType::Claim(colorResObj));
149         } else {
150             CounterModelNG::CreateWithResourceObj(frameNode, JsCounterResourceType::BackgroundColor, nullptr);
151         }
152     }
153 }
154 
ResetCounterBackgroundColor(ArkUINodeHandle node)155 void ResetCounterBackgroundColor(ArkUINodeHandle node)
156 {
157     auto* frameNode = reinterpret_cast<FrameNode*>(node);
158     CHECK_NULL_VOID(frameNode);
159     CounterModelNG::ResetBackgroundColor(frameNode);
160     if (SystemProperties::ConfigChangePerform()) {
161         CounterModelNG::CreateWithResourceObj(
162             frameNode, JsCounterResourceType::BackgroundColor, nullptr);
163     }
164 }
165 
SetCounterOnInc(ArkUINodeHandle node,void * callback)166 void SetCounterOnInc(ArkUINodeHandle node, void* callback)
167 {
168     auto* frameNode = reinterpret_cast<FrameNode*>(node);
169     CHECK_NULL_VOID(frameNode);
170     if (callback) {
171         auto onInc = reinterpret_cast<CounterModel::CounterEventFunc*>(callback);
172         CounterModelNG::SetOnInc(frameNode, std::move(*onInc));
173     } else {
174         CounterModelNG::SetOnInc(frameNode, nullptr);
175     }
176 }
177 
ResetCounterOnInc(ArkUINodeHandle node)178 void ResetCounterOnInc(ArkUINodeHandle node)
179 {
180     auto* frameNode = reinterpret_cast<FrameNode*>(node);
181     CHECK_NULL_VOID(frameNode);
182     CounterModelNG::SetOnInc(frameNode, nullptr);
183 }
184 
SetCounterOnDec(ArkUINodeHandle node,void * callback)185 void SetCounterOnDec(ArkUINodeHandle node, void* callback)
186 {
187     auto* frameNode = reinterpret_cast<FrameNode*>(node);
188     CHECK_NULL_VOID(frameNode);
189     if (callback) {
190         auto onDec = reinterpret_cast<CounterModel::CounterEventFunc*>(callback);
191         CounterModelNG::SetOnDec(frameNode, std::move(*onDec));
192     } else {
193         CounterModelNG::SetOnDec(frameNode, nullptr);
194     }
195 }
196 
ResetCounterOnDec(ArkUINodeHandle node)197 void ResetCounterOnDec(ArkUINodeHandle node)
198 {
199     auto* frameNode = reinterpret_cast<FrameNode*>(node);
200     CHECK_NULL_VOID(frameNode);
201     CounterModelNG::SetOnDec(frameNode, nullptr);
202 }
203 
204 namespace NodeModifier {
GetCounterModifier()205 const ArkUICounterModifier* GetCounterModifier()
206 {
207     CHECK_INITIALIZED_FIELDS_BEGIN(); // don't move this line
208     static const ArkUICounterModifier modifier = {
209         .setEnableInc = SetEnableInc,
210         .resetEnableInc = ResetEnableInc,
211         .setEnableDec = SetEnableDec,
212         .resetEnableDec = ResetEnableDec,
213         .setCounterHeight = SetCounterHeight,
214         .setCounterHeightRes = SetCounterHeightRes,
215         .resetCounterHeight = ResetCounterHeight,
216         .setCounterWidth = SetCounterWidth,
217         .setCounterWidthRes = SetCounterWidthRes,
218         .resetCounterWidth = ResetCounterWidth,
219         .setCounterBackgroundColor = SetCounterBackgroundColor,
220         .setCounterBackgroundColorWithColorSpace = SetCounterBackgroundColorWithColorSpace,
221         .setCounterBackgroundColorRes = SetCounterBackgroundColorRes,
222         .resetCounterBackgroundColor = ResetCounterBackgroundColor,
223         .setCounterOnInc = SetCounterOnInc,
224         .resetCounterOnInc = ResetCounterOnInc,
225         .setCounterOnDec = SetCounterOnDec,
226         .resetCounterOnDec = ResetCounterOnDec,
227     };
228     CHECK_INITIALIZED_FIELDS_END(modifier, 0, 0, 0); // don't move this line
229 
230     return &modifier;
231 }
232 
GetCJUICounterModifier()233 const CJUICounterModifier* GetCJUICounterModifier()
234 {
235     CHECK_INITIALIZED_FIELDS_BEGIN(); // don't move this line
236     static const CJUICounterModifier modifier = {
237         .setEnableInc = SetEnableInc,
238         .resetEnableInc = ResetEnableInc,
239         .setEnableDec = SetEnableDec,
240         .resetEnableDec = ResetEnableDec,
241         .setCounterHeight = SetCounterHeight,
242         .setCounterHeightRes = SetCounterHeightRes,
243         .resetCounterHeight = ResetCounterHeight,
244         .setCounterWidth = SetCounterWidth,
245         .setCounterWidthRes = SetCounterWidthRes,
246         .resetCounterWidth = ResetCounterWidth,
247         .setCounterBackgroundColor = SetCounterBackgroundColor,
248         .setCounterBackgroundColorWithColorSpace = SetCounterBackgroundColorWithColorSpace,
249         .setCounterBackgroundColorRes = SetCounterBackgroundColorRes,
250         .resetCounterBackgroundColor = ResetCounterBackgroundColor,
251     };
252     CHECK_INITIALIZED_FIELDS_END(modifier, 0, 0, 0); // don't move this line
253 
254     return &modifier;
255 }
256 } // namespace NodeModifier
257 } // namespace OHOS::Ace::NG
258