• 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 #include "core/interfaces/native/node/button_modifier.h"
16 
17 #include <unordered_map>
18 
19 #include "bridge/common/utils/utils.h"
20 #include "core/components/button/button_theme.h"
21 #include "core/components/common/layout/constants.h"
22 #include "core/components/common/properties/text_style.h"
23 #include "core/components_ng/base/frame_node.h"
24 #include "core/components_ng/base/view_abstract.h"
25 #include "core/components_ng/pattern/button/button_model_ng.h"
26 #include "core/components_ng/pattern/button/button_request_data.h"
27 #include "core/pipeline/base/element_register.h"
28 #include "frameworks/core/components/button/button_theme.h"
29 
30 namespace OHOS::Ace::NG {
31 namespace {
32 constexpr int32_t DEFAULT_BUTTON_TYPE = (int32_t)ButtonType::CAPSULE;
33 constexpr bool DEFAULT_STATE_EFFECT = true;
34 constexpr Ace::FontWeight DEFAULT_FONT_WEIGHT = Ace::FontWeight::NORMAL;
35 constexpr Ace::FontStyle DEFAULT_FONT_STYLE = Ace::FontStyle::NORMAL;
36 constexpr uint32_t INDEX_STRING_FONT_WEIGHT_0 = 0;
37 constexpr uint32_t INDEX_STRING_FONT_FAMILY_1 = 1;
38 constexpr uint32_t INDEX_VALUE_TEXT_OVERFLOW_0 = 0;
39 constexpr uint32_t INDEX_VALUE_MAX_LINES_1 = 1;
40 constexpr uint32_t INDEX_VALUE_ADAPT_HEIGHT_2 = 2;
41 constexpr uint32_t INDEX_VALUE_FONT_STYLE_3 = 3;
42 constexpr uint32_t INDEX_DIMENSION_MIN_FONT_SIZE_0 = 0;
43 constexpr uint32_t INDEX_DIMENSION_MAX_FONT_SIZE_1 = 1;
44 constexpr uint32_t INDEX_DIMENSION_FONT_SIZE_2 = 2;
45 constexpr uint32_t INDEX_STRING_ARRAY_COUNT = 0;
46 constexpr uint32_t INDEX_VALUE_ARRAY_COUNT = 1;
47 constexpr uint32_t INDEX_DIMENSION_ARRAY_COUNT = 2;
48 constexpr uint32_t INDEX_INVALID_FONT_FAMILY_0 = 0;
49 const std::string DEFAULT_FONT_FAMILY = "HarmonyOS Sans";
50 constexpr int32_t OFFSET_1 = 1;
51 constexpr int32_t OFFSET_2 = 2;
52 constexpr int32_t OFFSET_3 = 3;
53 constexpr int32_t BORDERRADIUS_SIZE = 12; // BorderRaius arry size
54 const std::vector<TextOverflow> TEXT_OVERFLOWS = { TextOverflow::NONE, TextOverflow::CLIP, TextOverflow::ELLIPSIS,
55     TextOverflow::MARQUEE };
56 const std::vector<Ace::FontStyle> FONT_STYLES = { Ace::FontStyle::NORMAL, Ace::FontStyle::ITALIC };
57 const std::vector<TextHeightAdaptivePolicy> HEIGHT_ADAPTIVE_POLICY = { TextHeightAdaptivePolicy::MAX_LINES_FIRST,
58     TextHeightAdaptivePolicy::MIN_FONT_SIZE_FIRST, TextHeightAdaptivePolicy::LAYOUT_CONSTRAINT_FIRST };
59 const std::string NONE_FONT_FAMILY = "NoneFontFamily";
60 
61 const std::unordered_map<int, DimensionUnit> DIMENSION_UNIT_MAP = {
62     { -2, DimensionUnit::INVALID },
63     { -1, DimensionUnit::NONE },
64     { 0, DimensionUnit::PX },
65     { 1, DimensionUnit::VP },
66     { 2, DimensionUnit::FP },
67     { 3, DimensionUnit::PERCENT },
68     { 4, DimensionUnit::LPX },
69     { 5, DimensionUnit::AUTO },
70     { 6, DimensionUnit::CALC },
71 };
72 
73 const std::vector<FontWeight> BUTTON_FONT_WEIGHTS = {
74     FontWeight::W100,
75     FontWeight::W200,
76     FontWeight::W300,
77     FontWeight::W400,
78     FontWeight::W500,
79     FontWeight::W600,
80     FontWeight::W700,
81     FontWeight::W800,
82     FontWeight::W900,
83     FontWeight::BOLD,
84     FontWeight::BOLDER,
85     FontWeight::LIGHTER,
86     FontWeight::MEDIUM,
87     FontWeight::NORMAL,
88     FontWeight::REGULAR,
89 };
90 } // namespace
91 
SetOptionalBorderRadius(std::optional<Dimension> & optioalDimension,const double * values,int32_t valuesSize,int32_t & offset)92 void SetOptionalBorderRadius(
93     std::optional<Dimension>& optioalDimension, const double* values, int32_t valuesSize, int32_t& offset)
94 {
95     bool hasValue = static_cast<bool>(values[offset]);
96     if (hasValue) {
97         optioalDimension =
98             Dimension(values[offset + OFFSET_1], static_cast<OHOS::Ace::DimensionUnit>(values[offset + OFFSET_2]));
99     }
100     offset = offset + OFFSET_3;
101 }
102 
SetButtonType(NodeHandle node,int type)103 void SetButtonType(NodeHandle node, int type)
104 {
105     auto* frameNode = reinterpret_cast<FrameNode*>(node);
106     CHECK_NULL_VOID(frameNode);
107     if ((ButtonType)type == ButtonType::CAPSULE || (ButtonType)type == ButtonType::CIRCLE ||
108         (ButtonType)type == ButtonType::ARC || (ButtonType)type == ButtonType::NORMAL) {
109         ButtonModelNG::SetType(frameNode, type);
110     }
111 }
112 
ResetButtonType(NodeHandle node)113 void ResetButtonType(NodeHandle node)
114 {
115     auto* frameNode = reinterpret_cast<FrameNode*>(node);
116     CHECK_NULL_VOID(frameNode);
117     ButtonModelNG::SetType(frameNode, DEFAULT_BUTTON_TYPE);
118     return;
119 }
120 
SetButtonStateEffect(NodeHandle node,bool stateEffect)121 void SetButtonStateEffect(NodeHandle node, bool stateEffect)
122 {
123     auto* frameNode = reinterpret_cast<FrameNode*>(node);
124     CHECK_NULL_VOID(frameNode);
125     ButtonModelNG::SetStateEffect(frameNode, stateEffect);
126 }
127 
ResetButtonStateEffect(NodeHandle node)128 void ResetButtonStateEffect(NodeHandle node)
129 {
130     auto* frameNode = reinterpret_cast<FrameNode*>(node);
131     CHECK_NULL_VOID(frameNode);
132     ButtonModelNG::SetStateEffect(frameNode, DEFAULT_STATE_EFFECT);
133 }
134 
SetButtonFontColor(NodeHandle node,uint32_t fontColor)135 void SetButtonFontColor(NodeHandle node, uint32_t fontColor)
136 {
137     auto* frameNode = reinterpret_cast<FrameNode*>(node);
138     CHECK_NULL_VOID(frameNode);
139     ButtonModelNG::SetFontColor(frameNode, Color(fontColor));
140 }
141 
ResetButtonFontColor(NodeHandle node)142 void ResetButtonFontColor(NodeHandle node)
143 {
144     auto* frameNode = reinterpret_cast<FrameNode*>(node);
145     CHECK_NULL_VOID(frameNode);
146     auto pipeline = PipelineBase::GetCurrentContext();
147     CHECK_NULL_VOID(pipeline);
148     auto buttonTheme = pipeline->GetTheme<ButtonTheme>();
149     CHECK_NULL_VOID(buttonTheme);
150     Color textColor = buttonTheme->GetTextStyle().GetTextColor();
151     ButtonModelNG::SetFontColor(frameNode, textColor);
152 }
153 
ResetButtonFontSizeInternal(NodeHandle node)154 void ResetButtonFontSizeInternal(NodeHandle node)
155 {
156     auto* frameNode = reinterpret_cast<FrameNode*>(node);
157     CHECK_NULL_VOID(frameNode);
158     auto pipeline = PipelineBase::GetCurrentContext();
159     CHECK_NULL_VOID(pipeline);
160     auto buttonTheme = pipeline->GetTheme<ButtonTheme>();
161     CHECK_NULL_VOID(buttonTheme);
162     CalcDimension fontSize = buttonTheme->GetTextStyle().GetFontSize();
163     ButtonModelNG::SetFontSize(frameNode, fontSize);
164 }
165 
SetButtonFontSize(NodeHandle node,double fontSizeValue,int fontSizeUnit)166 void SetButtonFontSize(NodeHandle node, double fontSizeValue, int fontSizeUnit)
167 {
168     auto* frameNode = reinterpret_cast<FrameNode*>(node);
169     CHECK_NULL_VOID(frameNode);
170     if (LessNotEqual(fontSizeValue, 0.0)) {
171         ResetButtonFontSizeInternal(node);
172     } else {
173         ButtonModelNG::SetFontSize(frameNode, CalcDimension(fontSizeValue, (DimensionUnit)fontSizeUnit));
174     }
175 }
176 
ResetButtonFontSize(NodeHandle node)177 void ResetButtonFontSize(NodeHandle node)
178 {
179     ResetButtonFontSizeInternal(node);
180 }
181 
SetButtonFontWeight(NodeHandle node,const char * fontWeight)182 void SetButtonFontWeight(NodeHandle node, const char* fontWeight)
183 {
184     auto* frameNode = reinterpret_cast<FrameNode*>(node);
185     CHECK_NULL_VOID(frameNode);
186     std::string fontWeightStr = fontWeight;
187     ButtonModelNG::SetFontWeight(frameNode, Framework::ConvertStrToFontWeight(fontWeightStr));
188 }
189 
ResetButtonFontWeight(NodeHandle node)190 void ResetButtonFontWeight(NodeHandle node)
191 {
192     auto* frameNode = reinterpret_cast<FrameNode*>(node);
193     CHECK_NULL_VOID(frameNode);
194     ButtonModelNG::SetFontWeight(frameNode, DEFAULT_FONT_WEIGHT);
195 }
196 
SetButtonFontStyle(NodeHandle node,int32_t fontStyle)197 void SetButtonFontStyle(NodeHandle node, int32_t fontStyle)
198 {
199     auto* frameNode = reinterpret_cast<FrameNode*>(node);
200     CHECK_NULL_VOID(frameNode);
201     if (fontStyle < 0 || fontStyle >= static_cast<int32_t>(FONT_STYLES.size())) {
202         ButtonModelNG::SetFontStyle(frameNode, DEFAULT_FONT_STYLE);
203     } else {
204         ButtonModelNG::SetFontStyle(frameNode, FONT_STYLES[fontStyle]);
205     }
206 }
207 
ResetButtonFontStyle(NodeHandle node)208 void ResetButtonFontStyle(NodeHandle node)
209 {
210     auto* frameNode = reinterpret_cast<FrameNode*>(node);
211     CHECK_NULL_VOID(frameNode);
212     ButtonModelNG::SetFontStyle(frameNode, DEFAULT_FONT_STYLE);
213 }
214 
SetButtonFontFamily(NodeHandle node,const char * fontFamily)215 void SetButtonFontFamily(NodeHandle node, const char* fontFamily)
216 {
217     auto* frameNode = reinterpret_cast<FrameNode*>(node);
218     CHECK_NULL_VOID(frameNode);
219     std::string familiesStr = fontFamily;
220     std::vector<std::string> fontFamilyResult = Framework::ConvertStrToFontFamilies(familiesStr);
221     ButtonModelNG::SetFontFamily(frameNode, fontFamilyResult);
222 }
223 
ResetButtonFontFamily(NodeHandle node)224 void ResetButtonFontFamily(NodeHandle node)
225 {
226     auto* frameNode = reinterpret_cast<FrameNode*>(node);
227     CHECK_NULL_VOID(frameNode);
228     std::string familiesStr = DEFAULT_FONT_FAMILY;
229     std::vector<std::string> fontFamilyResult = Framework::ConvertStrToFontFamilies(familiesStr);
230     ButtonModelNG::SetFontFamily(frameNode, fontFamilyResult);
231 }
232 
ButtonCompleteParameters(ButtonParameters & buttonParameters)233 void ButtonCompleteParameters(ButtonParameters& buttonParameters)
234 {
235     auto pipeline = PipelineBase::GetCurrentContext();
236     CHECK_NULL_VOID(pipeline);
237     auto buttonTheme = pipeline->GetTheme<ButtonTheme>();
238     if (!buttonTheme) {
239         return;
240     }
241     auto textStyle = buttonTheme->GetTextStyle();
242     if (!buttonParameters.textOverflow.has_value()) {
243         buttonParameters.textOverflow = TextOverflow::CLIP;
244     }
245     if (!buttonParameters.maxLines.has_value()) {
246         buttonParameters.maxLines = buttonTheme->GetTextMaxLines();
247     }
248     if (!buttonParameters.fontSize.has_value()) {
249         buttonParameters.fontSize = textStyle.GetFontSize();
250     }
251     if (!buttonParameters.fontWeight.has_value()) {
252         buttonParameters.fontWeight = textStyle.GetFontWeight();
253     }
254     if (!buttonParameters.fontStyle.has_value()) {
255         buttonParameters.fontStyle = textStyle.GetFontStyle();
256     }
257     if (!buttonParameters.heightAdaptivePolicy.has_value()) {
258         buttonParameters.heightAdaptivePolicy = TextHeightAdaptivePolicy::MAX_LINES_FIRST;
259     }
260 }
261 
SetButtonDimension(const double * dimensionArray,uint32_t offset,const size_t dataCount,std::optional<CalcDimension> & optDimension)262 bool SetButtonDimension(
263     const double* dimensionArray, uint32_t offset, const size_t dataCount, std::optional<CalcDimension>& optDimension)
264 {
265     CHECK_NULL_RETURN(dimensionArray, false);
266     auto hasValue = dimensionArray[offset];
267     if (!static_cast<bool>(hasValue)) {
268         return false;
269     }
270     uint32_t valueIndex = offset + 1;
271     uint32_t unitIndex = offset + 2;
272     if (unitIndex >= dataCount) {
273         return false;
274     }
275     auto value = dimensionArray[valueIndex];
276     auto unit = dimensionArray[unitIndex];
277     DimensionUnit unitValue = static_cast<DimensionUnit>(unit);
278     CalcDimension dimensionValue = CalcDimension(value, unitValue);
279     optDimension = dimensionValue;
280     return true;
281 }
282 
SetButtonDimensionParameters(const double * dimensionArray,const size_t dataCount,ButtonParameters & buttonParameters)283 void SetButtonDimensionParameters(
284     const double* dimensionArray, const size_t dataCount, ButtonParameters& buttonParameters)
285 {
286     CHECK_NULL_VOID(dimensionArray);
287     uint32_t step = 3;
288     uint32_t minFontSizeIndex = INDEX_DIMENSION_MIN_FONT_SIZE_0;
289     std::optional<CalcDimension> minFontSizeOptional = std::nullopt;
290     if (SetButtonDimension(dimensionArray, minFontSizeIndex, dataCount, minFontSizeOptional)) {
291         buttonParameters.minFontSize = minFontSizeOptional;
292     }
293     uint32_t maxFontSizeIndex = INDEX_DIMENSION_MAX_FONT_SIZE_1 * step;
294     std::optional<CalcDimension> maxFontSizeOptional = std::nullopt;
295     if (SetButtonDimension(dimensionArray, maxFontSizeIndex, dataCount, maxFontSizeOptional)) {
296         buttonParameters.maxFontSize = maxFontSizeOptional;
297     }
298     uint32_t fontSizeIndex = INDEX_DIMENSION_FONT_SIZE_2 * step;
299     std::optional<CalcDimension> fontSizeOptional = std::nullopt;
300     if (SetButtonDimension(dimensionArray, fontSizeIndex, dataCount, fontSizeOptional)) {
301         buttonParameters.fontSize = fontSizeOptional;
302     }
303 }
304 
SetButtonValue(const int32_t * valueArray,uint32_t index,const size_t dataCount,int32_t & result)305 bool SetButtonValue(const int32_t* valueArray, uint32_t index, const size_t dataCount, int32_t& result)
306 {
307     CHECK_NULL_RETURN(valueArray, false);
308     uint32_t step = 2;
309     auto hasValueIndex = index * step;
310     auto valueIndex = hasValueIndex + 1;
311     if (valueIndex >= dataCount) {
312         return false;
313     }
314     if (static_cast<bool>(valueArray[hasValueIndex])) {
315         result = valueArray[valueIndex];
316         return true;
317     }
318     return false;
319 }
320 
SetButtonValueParameters(const int32_t * valueArray,const size_t dataCount,ButtonParameters & buttonParameters)321 void SetButtonValueParameters(const int32_t* valueArray, const size_t dataCount, ButtonParameters& buttonParameters)
322 {
323     CHECK_NULL_VOID(valueArray);
324     int32_t result = 0;
325     buttonParameters.textOverflow = TextOverflow::ELLIPSIS;
326     if (SetButtonValue(valueArray, INDEX_VALUE_TEXT_OVERFLOW_0, dataCount, result) && result >= 0 &&
327         result < static_cast<int32_t>(TEXT_OVERFLOWS.size())) {
328         buttonParameters.textOverflow = TEXT_OVERFLOWS[result];
329     }
330     buttonParameters.maxLines = std::nullopt;
331     if (SetButtonValue(valueArray, INDEX_VALUE_MAX_LINES_1, dataCount, result) && result >= 0) {
332         buttonParameters.maxLines = Positive(result) ? result : 1;
333     }
334     buttonParameters.heightAdaptivePolicy = std::nullopt;
335     if (SetButtonValue(valueArray, INDEX_VALUE_ADAPT_HEIGHT_2, dataCount, result) && result >= 0 &&
336         result < static_cast<int32_t>(HEIGHT_ADAPTIVE_POLICY.size())) {
337         buttonParameters.heightAdaptivePolicy = HEIGHT_ADAPTIVE_POLICY[result];
338     }
339     buttonParameters.fontStyle = std::nullopt;
340     if (SetButtonValue(valueArray, INDEX_VALUE_FONT_STYLE_3, dataCount, result) && result >= 0 &&
341         result < static_cast<int32_t>(FONT_STYLES.size())) {
342         buttonParameters.fontStyle = FONT_STYLES[result];
343     }
344 }
345 
SetButtonStringParameters(const char ** stringParameters,const size_t dataCount,ButtonParameters & buttonParameters)346 void SetButtonStringParameters(
347     const char** stringParameters, const size_t dataCount, ButtonParameters& buttonParameters)
348 {
349     CHECK_NULL_VOID(stringParameters);
350     buttonParameters.fontWeight = std::nullopt;
351     if (INDEX_STRING_FONT_WEIGHT_0 < dataCount && stringParameters[INDEX_STRING_FONT_WEIGHT_0] != nullptr) {
352         std::string fontWeightStr = stringParameters[INDEX_STRING_FONT_WEIGHT_0];
353         buttonParameters.fontWeight = Framework::ConvertStrToFontWeight(fontWeightStr);
354     }
355     buttonParameters.fontFamily = std::nullopt;
356     if (INDEX_STRING_FONT_FAMILY_1 < dataCount && stringParameters[INDEX_STRING_FONT_FAMILY_1] != nullptr) {
357         std::string familiesStr = stringParameters[INDEX_STRING_FONT_FAMILY_1];
358         std::vector<std::string> fontFamilyResult = Framework::ConvertStrToFontFamilies(familiesStr);
359         if (fontFamilyResult.size() == 1 &&
360             fontFamilyResult[INDEX_INVALID_FONT_FAMILY_0].compare(NONE_FONT_FAMILY) == 0) {
361             return;
362         }
363         buttonParameters.fontFamily = fontFamilyResult;
364     }
365 }
366 
SetButtonLabelStyle(NodeHandle node,const char ** stringParameters,const int32_t * valueArray,const double * dimensionArray,const size_t * dataCountArray)367 void SetButtonLabelStyle(NodeHandle node, const char** stringParameters, const int32_t* valueArray,
368     const double* dimensionArray, const size_t* dataCountArray)
369 {
370     auto* frameNode = reinterpret_cast<FrameNode*>(node);
371     CHECK_NULL_VOID(frameNode);
372     ButtonParameters buttonParameters;
373     SetButtonStringParameters(stringParameters, dataCountArray[INDEX_STRING_ARRAY_COUNT], buttonParameters);
374     SetButtonValueParameters(valueArray, dataCountArray[INDEX_VALUE_ARRAY_COUNT], buttonParameters);
375     SetButtonDimensionParameters(dimensionArray, dataCountArray[INDEX_DIMENSION_ARRAY_COUNT], buttonParameters);
376     ButtonCompleteParameters(buttonParameters);
377     ButtonModelNG::SetLableStyle(frameNode, buttonParameters);
378 }
379 
ResetButtonLabelStyle(NodeHandle node)380 void ResetButtonLabelStyle(NodeHandle node)
381 {
382     return;
383 }
384 
SetButtonBackgroundColor(NodeHandle node,uint32_t color)385 void SetButtonBackgroundColor(NodeHandle node, uint32_t color)
386 {
387     auto* frameNode = reinterpret_cast<FrameNode*>(node);
388     CHECK_NULL_VOID(frameNode);
389     ButtonModelNG::BackgroundColor(frameNode, Color(color), true);
390 }
391 
ResetButtonBackgroundColor(NodeHandle node)392 void ResetButtonBackgroundColor(NodeHandle node)
393 {
394     auto* frameNode = reinterpret_cast<FrameNode*>(node);
395     CHECK_NULL_VOID(frameNode);
396     Color backgroundColor;
397     auto pipeline = PipelineBase::GetCurrentContext();
398     CHECK_NULL_VOID(pipeline);
399     auto buttonTheme = pipeline->GetTheme<ButtonTheme>();
400     CHECK_NULL_VOID(buttonTheme);
401     backgroundColor = buttonTheme->GetBgColor();
402     ButtonModelNG::BackgroundColor(frameNode, backgroundColor, false);
403 }
404 
405 /**
406  * @param src source borderRadius
407  * @param options option value
408  * values[offset + 0], option[offset + 1], option[offset + 2]: borderRadius topLeft(hasValue, value, unit)
409  * values[offset + 3], option[offset + 4], option[offset + 5]: borderRadius topRight(hasValue, value, unit)
410  * values[offset + 6], option[offset + 7], option[offset + 8]: borderRadius bottomLeft(hasValue, value, unit)
411  * values[offset + 9], option[offset + 10], option[offset + 11]: borderRadius bottomRight(hasValue, value, unit)
412  * @param optionsLength options valuesSize
413  */
SetButtonBorderRadius(NodeHandle node,const double * values,int32_t valuesSize)414 void SetButtonBorderRadius(NodeHandle node, const double* values, int32_t valuesSize)
415 {
416     if ((values == nullptr) || (valuesSize != BORDERRADIUS_SIZE)) {
417         return;
418     }
419     auto* frameNode = reinterpret_cast<FrameNode*>(node);
420     CHECK_NULL_VOID(frameNode);
421     int32_t offset = 0;
422     std::optional<Dimension> radiusTopLeft;
423     std::optional<Dimension> radiusTopRight;
424     std::optional<Dimension> radiusBottomLeft;
425     std::optional<Dimension> radiusBottomRight;
426 
427     SetOptionalBorderRadius(radiusTopLeft, values, valuesSize, offset);
428     SetOptionalBorderRadius(radiusTopRight, values, valuesSize, offset);
429     SetOptionalBorderRadius(radiusBottomLeft, values, valuesSize, offset);
430     SetOptionalBorderRadius(radiusBottomRight, values, valuesSize, offset);
431     ButtonModelNG::SetBorderRadius(frameNode, radiusTopLeft, radiusTopRight, radiusBottomLeft, radiusBottomRight);
432 }
433 
ResetButtonBorderRadius(NodeHandle node)434 void ResetButtonBorderRadius(NodeHandle node)
435 {
436     auto* frameNode = reinterpret_cast<FrameNode*>(node);
437     CHECK_NULL_VOID(frameNode);
438     OHOS::Ace::Dimension reset;
439     ButtonModelNG::SetBorderRadius(frameNode, reset);
440 }
441 
SetButtonSize(NodeHandle node,const char * widthValue,int32_t widthUnit,const char * heightValue,int32_t heightUnit)442 void SetButtonSize(
443     NodeHandle node, const char* widthValue, int32_t widthUnit, const char* heightValue, int32_t heightUnit)
444 {
445     auto* frameNode = reinterpret_cast<FrameNode*>(node);
446     CHECK_NULL_VOID(frameNode);
447     std::string widthValueStr = std::string(widthValue);
448     std::string heightValueStr = std::string(heightValue);
449     std::optional<CalcDimension> widthInfo;
450     std::optional<CalcDimension> heightInfo;
451     if (widthValueStr != "undefined") {
452         widthInfo = CalcDimension(StringUtils::StringToDouble(widthValueStr), (DimensionUnit)widthUnit);
453     }
454     if (heightValueStr != "undefined") {
455         heightInfo = CalcDimension(StringUtils::StringToDouble(heightValueStr), (DimensionUnit)heightUnit);
456     }
457     ButtonModelNG::SetSize(frameNode, widthInfo, heightInfo);
458 }
459 
ResetButtonSize(NodeHandle node)460 void ResetButtonSize(NodeHandle node)
461 {
462     auto* frameNode = reinterpret_cast<FrameNode*>(node);
463     CHECK_NULL_VOID(frameNode);
464     CalcDimension value(0.0, DimensionUnit::VP);
465     ButtonModelNG::SetSize(frameNode, value, value);
466 }
467 
GetButtonModifier()468 ArkUIButtonModifierAPI GetButtonModifier()
469 {
470     static const ArkUIButtonModifierAPI modifier = { SetButtonType, ResetButtonType, SetButtonStateEffect,
471         ResetButtonStateEffect, SetButtonFontColor, ResetButtonFontColor, SetButtonFontSize, ResetButtonFontSize,
472         SetButtonFontWeight, ResetButtonFontWeight, SetButtonFontStyle, ResetButtonFontStyle, SetButtonFontFamily,
473         ResetButtonFontFamily, SetButtonLabelStyle, ResetButtonLabelStyle, SetButtonBackgroundColor,
474         ResetButtonBackgroundColor, SetButtonBorderRadius, ResetButtonBorderRadius, SetButtonSize, ResetButtonSize };
475 
476     return modifier;
477 }
478 } // namespace OHOS::Ace::NG