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/components_ng/pattern/security_component/security_component_model_ng.h"
17
18 #include "core/components/common/properties/text_style.h"
19 #include "core/components_ng/pattern/button/button_layout_property.h"
20 #include "core/components_ng/pattern/button/button_pattern.h"
21 #include "core/components_ng/pattern/image/image_model_ng.h"
22 #include "core/components_ng/pattern/image/image_pattern.h"
23 #include "core/components_ng/pattern/security_component/save_button/save_button_common.h"
24 #include "core/components_ng/pattern/security_component/save_button/save_button_model_ng.h"
25 #ifdef SECURITY_COMPONENT_ENABLE
26 #include "core/components_ng/pattern/security_component/security_component_handler.h"
27 #endif
28 #include "core/components_ng/pattern/security_component/security_component_log.h"
29 #include "core/components_ng/pattern/security_component/security_component_pattern.h"
30 #include "core/components_ng/pattern/security_component/security_component_theme.h"
31 #include "core/components_ng/pattern/text/text_pattern.h"
32 #include "core/components_v2/inspector/inspector_constants.h"
33 #include "core/pipeline_ng/pipeline_context.h"
34
35 namespace OHOS::Ace::NG {
36 const static uint8_t DEFAULT_TRANSPARENCY_THRESHOLD = 0x1A;
37 const static uint8_t FULL_TRANSPARENCY_VALUE = 0xFF;
38 const static std::set<uint32_t> RELEASE_ATTRIBUTE_LIST = {
39 0x0C000000,
40 };
41 const static double DEFAULT_ICON_FONT_SIZE = 24;
GetSecCompChildNode(const FrameNode * parent,const std::string & tag)42 static inline RefPtr<FrameNode> GetSecCompChildNode(const FrameNode* parent, const std::string& tag)
43 {
44 CHECK_NULL_RETURN(parent, nullptr);
45 for (const auto& child : parent->GetChildren()) {
46 auto node = AceType::DynamicCast<FrameNode, UINode>(child);
47 CHECK_NULL_RETURN(node, nullptr);
48 if (node->GetTag() == tag) {
49 return node;
50 }
51 }
52 return nullptr;
53 }
54
GetTheme()55 RefPtr<SecurityComponentTheme> SecurityComponentModelNG::GetTheme()
56 {
57 auto pipeline = PipelineContext::GetCurrentContextSafely();
58 CHECK_NULL_RETURN(pipeline, nullptr);
59 return pipeline->GetTheme<SecurityComponentTheme>();
60 }
61
InitLayoutProperty(RefPtr<FrameNode> & node,int32_t text,int32_t icon,uint32_t symbolIcon,int32_t backgroundType)62 void SecurityComponentModelNG::InitLayoutProperty(RefPtr<FrameNode>& node, int32_t text, int32_t icon,
63 uint32_t symbolIcon, int32_t backgroundType)
64 {
65 auto property = node->GetLayoutProperty<SecurityComponentLayoutProperty>();
66 CHECK_NULL_VOID(property);
67 auto secCompTheme = GetTheme();
68 CHECK_NULL_VOID(secCompTheme);
69 property->UpdateSecurityComponentDescription(text);
70 property->UpdateIconStyle(icon);
71 property->UpdateSymbolIconStyle(symbolIcon);
72 property->UpdateBackgroundType(backgroundType);
73
74 if (backgroundType == BUTTON_TYPE_NULL) {
75 property->UpdateBackgroundLeftPadding(secCompTheme->GetPaddingWithoutBg());
76 property->UpdateBackgroundRightPadding(secCompTheme->GetPaddingWithoutBg());
77 property->UpdateBackgroundTopPadding(secCompTheme->GetPaddingWithoutBg());
78 property->UpdateBackgroundBottomPadding(secCompTheme->GetPaddingWithoutBg());
79 }
80
81 property->UpdateTextIconLayoutDirection(SecurityComponentLayoutDirection::HORIZONTAL);
82 bool hasCustomPermission = false;
83 #ifdef SECURITY_COMPONENT_ENABLE
84 hasCustomPermission = SecurityComponentHandler::HasCustomPermissionForSecComp();
85 #endif
86 property->UpdateHasCustomPermissionForSecComp(hasCustomPermission);
87 }
88
InitChildNode(FrameNode * frameNode,const SecurityComponentElementStyle & style,GetIconResourceFuncType getIconResource,GetTextResourceFuncType getTextResource)89 void SecurityComponentModelNG::InitChildNode(FrameNode* frameNode, const SecurityComponentElementStyle& style,
90 GetIconResourceFuncType getIconResource, GetTextResourceFuncType getTextResource)
91 {
92 bool isButtonVisible = (style.backgroundType != BUTTON_TYPE_NULL);
93 auto buttonNode = FrameNode::CreateFrameNode(
94 V2::BUTTON_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
95 AceType::MakeRefPtr<ButtonPattern>());
96 buttonNode->SetInternal();
97
98 if (isButtonVisible) {
99 SetDefaultBackgroundButton(buttonNode, style.backgroundType);
100 } else {
101 SetInvisibleBackgroundButton(buttonNode);
102 }
103 frameNode->AddChild(buttonNode);
104
105 if (style.symbolIcon && style.symbolIcon != static_cast<uint32_t>(SecurityComponentIconStyle::ICON_NULL)) {
106 auto symbolIcon = FrameNode::CreateFrameNode(
107 V2::SYMBOL_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
108 SetDefaultSymbolIconStyle(symbolIcon, style.symbolIcon, isButtonVisible);
109 frameNode->AddChild(symbolIcon);
110 } else if (style.icon != static_cast<int32_t>(SecurityComponentIconStyle::ICON_NULL)) {
111 auto imageIcon = FrameNode::CreateFrameNode(
112 V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>());
113 imageIcon->SetInternal();
114 InternalResource::ResourceId iconId;
115 if (getIconResource(style.icon, iconId)) {
116 SetDefaultIconStyle(imageIcon, iconId, isButtonVisible);
117 }
118 frameNode->AddChild(imageIcon);
119 }
120
121 if (style.text != static_cast<int32_t>(SecurityComponentDescription::TEXT_NULL)) {
122 auto textNode = FrameNode::CreateFrameNode(
123 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
124 textNode->SetInternal();
125 std::string textStr = "";
126 getTextResource(style.text, textStr);
127 SetDefaultTextStyle(textNode, textStr, isButtonVisible);
128 frameNode->AddChild(textNode);
129 }
130 auto refPtr = AceType::Claim(frameNode);
131 InitLayoutProperty(refPtr, style.text, style.icon, style.symbolIcon, style.backgroundType);
132 }
133
InitSecurityComponent(FrameNode * frameNode,const SecurityComponentElementStyle & style,bool isArkuiComponent,GetIconResourceFuncType getIconResource,GetTextResourceFuncType getTextResource)134 bool SecurityComponentModelNG::InitSecurityComponent(FrameNode* frameNode,
135 const SecurityComponentElementStyle& style, bool isArkuiComponent,
136 GetIconResourceFuncType getIconResource, GetTextResourceFuncType getTextResource)
137 {
138 CHECK_NULL_RETURN(frameNode, false);
139 if (frameNode->GetChildren().empty()) {
140 InitChildNode(frameNode, style, getIconResource, getTextResource);
141 }
142 auto property = frameNode->GetLayoutProperty<SecurityComponentLayoutProperty>();
143 CHECK_NULL_RETURN(property, false);
144 property->UpdatePropertyChangeFlag(PROPERTY_UPDATE_MEASURE);
145 property->UpdateIsArkuiComponent(isArkuiComponent);
146 property->UpdateTextStyle(style.text);
147 auto pipeline = AceType::DynamicCast<PipelineContext>(PipelineBase::GetCurrentContextSafelyWithCheck());
148 CHECK_NULL_RETURN(pipeline, false);
149 pipeline->AddWindowStateChangedCallback(frameNode->GetId());
150 return true;
151 }
152
CreateNode(const std::string & tag,int32_t nodeId,SecurityComponentElementStyle & style,const std::function<RefPtr<Pattern> (void)> & patternCreator,bool isArkuiComponent)153 RefPtr<FrameNode> SecurityComponentModelNG::CreateNode(const std::string& tag, int32_t nodeId,
154 SecurityComponentElementStyle& style, const std::function<RefPtr<Pattern>(void)>& patternCreator,
155 bool isArkuiComponent)
156 {
157 ACE_LAYOUT_SCOPED_TRACE("Create[%s][self:%d]", tag.c_str(), nodeId);
158 auto frameNode = InitChild(tag, nodeId, style, patternCreator);
159 CHECK_NULL_RETURN(frameNode, nullptr);
160 auto property = frameNode->GetLayoutProperty<SecurityComponentLayoutProperty>();
161 CHECK_NULL_RETURN(property, nullptr);
162 property->UpdatePropertyChangeFlag(PROPERTY_UPDATE_MEASURE);
163 property->UpdateIsArkuiComponent(isArkuiComponent);
164 property->UpdateTextStyle(style.text);
165 auto pipeline = AceType::DynamicCast<PipelineContext>(PipelineBase::GetCurrentContextSafelyWithCheck());
166 CHECK_NULL_RETURN(pipeline, nullptr);
167 pipeline->AddWindowStateChangedCallback(nodeId);
168 return frameNode;
169 }
170
InitChild(const std::string & tag,int32_t nodeId,SecurityComponentElementStyle & style,const std::function<RefPtr<Pattern> (void)> & patternCreator)171 RefPtr<FrameNode> SecurityComponentModelNG::InitChild(const std::string& tag, int32_t nodeId,
172 SecurityComponentElementStyle& style, const std::function<RefPtr<Pattern>(void)>& patternCreator)
173 {
174 auto frameNode = FrameNode::GetOrCreateFrameNode(tag, nodeId, patternCreator);
175 CHECK_NULL_RETURN(frameNode, nullptr);
176 if (frameNode->GetChildren().empty()) {
177 bool isButtonVisible = (style.backgroundType != BUTTON_TYPE_NULL);
178 auto buttonNode = FrameNode::CreateFrameNode(
179 V2::BUTTON_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
180 AceType::MakeRefPtr<ButtonPattern>());
181 buttonNode->SetInternal();
182
183 if (isButtonVisible) {
184 SetDefaultBackgroundButton(buttonNode, style.backgroundType);
185 } else {
186 SetInvisibleBackgroundButton(buttonNode);
187 }
188 frameNode->AddChild(buttonNode);
189 if (style.symbolIcon && style.symbolIcon != static_cast<uint32_t>(SecurityComponentIconStyle::ICON_NULL)) {
190 if (style.icon != static_cast<int32_t>(SecurityComponentIconStyle::ICON_NULL)) {
191 SC_LOG_ERROR("Image icon and symbol icon cannot be set at same time.");
192 return nullptr;
193 }
194 auto symbolIcon = FrameNode::CreateFrameNode(
195 V2::SYMBOL_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
196 SetDefaultSymbolIconStyle(symbolIcon, style.symbolIcon, isButtonVisible);
197 frameNode->AddChild(symbolIcon);
198 } else if (style.icon != static_cast<int32_t>(SecurityComponentIconStyle::ICON_NULL)) {
199 auto imageIcon = FrameNode::CreateFrameNode(
200 V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>());
201 imageIcon->SetInternal();
202 InternalResource::ResourceId iconId;
203 if (GetIconResource(style.icon, iconId)) {
204 SetDefaultIconStyle(imageIcon, iconId, isButtonVisible);
205 }
206 frameNode->AddChild(imageIcon);
207 }
208
209 if (style.text != static_cast<int32_t>(SecurityComponentDescription::TEXT_NULL)) {
210 auto textNode = FrameNode::CreateFrameNode(
211 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
212 CHECK_NULL_RETURN(textNode, nullptr);
213 textNode->SetInternal();
214 std::string textStr = "";
215 GetTextResource(style.text, textStr);
216 SetDefaultTextStyle(textNode, textStr, isButtonVisible);
217 frameNode->AddChild(textNode);
218 }
219 InitLayoutProperty(frameNode, style.text, style.icon, style.symbolIcon, style.backgroundType);
220 }
221 return frameNode;
222 }
223
CreateCommon(const std::string & tag,int32_t text,int32_t icon,int32_t backgroundType,const std::function<RefPtr<Pattern> (void)> & patternCreator,bool isArkuiComponent)224 void SecurityComponentModelNG::CreateCommon(const std::string& tag, int32_t text, int32_t icon,
225 int32_t backgroundType, const std::function<RefPtr<Pattern>(void)>& patternCreator, bool isArkuiComponent)
226 {
227 auto stack = ViewStackProcessor::GetInstance();
228 auto nodeId = stack->ClaimNodeId();
229 SecurityComponentElementStyle style = {
230 .text = text,
231 .icon = icon,
232 .backgroundType = backgroundType
233 };
234 auto frameNode = CreateNode(tag, nodeId, style, patternCreator, isArkuiComponent);
235 CHECK_NULL_VOID(frameNode);
236 stack->Push(frameNode);
237 }
238
SetDefaultTextStyle(const RefPtr<FrameNode> & textNode,const std::string & text,bool isButtonVisible)239 void SecurityComponentModelNG::SetDefaultTextStyle(const RefPtr<FrameNode>& textNode, const std::string& text,
240 bool isButtonVisible)
241 {
242 auto secCompTheme = GetTheme();
243 CHECK_NULL_VOID(secCompTheme);
244 auto textLayoutProperty = textNode->GetLayoutProperty<TextLayoutProperty>();
245 CHECK_NULL_VOID(textLayoutProperty);
246 textLayoutProperty->UpdateContent(text);
247 textLayoutProperty->UpdateMaxLines(secCompTheme->GetDefaultTextMaxLines());
248 textLayoutProperty->UpdateFontSize(secCompTheme->GetFontSize());
249 textLayoutProperty->UpdateItalicFontStyle(Ace::FontStyle::NORMAL);
250 textLayoutProperty->UpdateFontWeight(FontWeight::MEDIUM);
251 textLayoutProperty->UpdateHeightAdaptivePolicy(TextHeightAdaptivePolicy::MAX_LINES_FIRST);
252
253 if (isButtonVisible) {
254 textLayoutProperty->UpdateTextColor(secCompTheme->GetFontColor());
255 } else {
256 textLayoutProperty->UpdateTextColor(secCompTheme->GetFontColorNoBg());
257 }
258 }
259
SetDefaultIconStyle(const RefPtr<FrameNode> & imageNode,InternalResource::ResourceId id,bool isButtonVisible)260 void SecurityComponentModelNG::SetDefaultIconStyle(const RefPtr<FrameNode>& imageNode, InternalResource::ResourceId id,
261 bool isButtonVisible)
262 {
263 auto secCompTheme = GetTheme();
264 CHECK_NULL_VOID(secCompTheme);
265 ImageSourceInfo imageSourceInfo;
266 imageSourceInfo.SetResourceId(id);
267 if (isButtonVisible) {
268 imageSourceInfo.SetFillColor(secCompTheme->GetIconColor());
269 } else {
270 imageSourceInfo.SetFillColor(secCompTheme->GetIconColorNoBg());
271 }
272
273 auto iconProp = imageNode->GetLayoutProperty<ImageLayoutProperty>();
274 CHECK_NULL_VOID(iconProp);
275 iconProp->UpdateImageSourceInfo(imageSourceInfo);
276 iconProp->UpdateUserDefinedIdealSize(
277 CalcSize(NG::CalcLength(secCompTheme->GetIconSize()), std::nullopt));
278 // default follow text direction
279 ImageModelNG::SetMatchTextDirection(Referenced::RawPtr(imageNode), true);
280 }
281
SetDefaultSymbolIconStyle(const RefPtr<FrameNode> & symbolNode,uint32_t symbolId,bool isButtonVisible)282 void SecurityComponentModelNG::SetDefaultSymbolIconStyle(
283 const RefPtr<FrameNode> &symbolNode, uint32_t symbolId, bool isButtonVisible)
284 {
285 CHECK_NULL_VOID(symbolNode);
286 auto secCompTheme = GetTheme();
287 CHECK_NULL_VOID(secCompTheme);
288 auto iconProp = symbolNode->GetLayoutProperty<TextLayoutProperty>();
289 CHECK_NULL_VOID(iconProp);
290 SymbolSourceInfo symbolSourceInfo(symbolId);
291 if (isButtonVisible) {
292 iconProp->UpdateSymbolColorList({secCompTheme->GetDefaultSymbolIconColor()});
293 } else {
294 iconProp->UpdateSymbolColorList({secCompTheme->GetIconColorNoBg()});
295 }
296 iconProp->UpdateSymbolSourceInfo(symbolSourceInfo);
297 iconProp->UpdateFontSize(Dimension(DEFAULT_ICON_FONT_SIZE, DimensionUnit::VP));
298 symbolNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
299 symbolNode->MarkModifyDone();
300 }
SetDefaultBackgroundButton(const RefPtr<FrameNode> & buttonNode,int32_t type)301 void SecurityComponentModelNG::SetDefaultBackgroundButton(const RefPtr<FrameNode>& buttonNode,
302 int32_t type)
303 {
304 auto buttonLayoutProperty = buttonNode->GetLayoutProperty<ButtonLayoutProperty>();
305 CHECK_NULL_VOID(buttonLayoutProperty);
306 const auto& renderContext = buttonNode->GetRenderContext();
307 CHECK_NULL_VOID(renderContext);
308 auto secCompTheme = GetTheme();
309 CHECK_NULL_VOID(secCompTheme);
310
311 BorderColorProperty borderColor;
312 borderColor.SetColor(secCompTheme->GetBorderColor());
313 renderContext->UpdateBorderColor(borderColor);
314 BorderWidthProperty widthProp;
315 widthProp.SetBorderWidth(secCompTheme->GetBorderWidth());
316 buttonLayoutProperty->UpdateBorderWidth(widthProp);
317 BorderStyleProperty style;
318 style.SetBorderStyle(BorderStyle::NONE);
319 renderContext->UpdateBorderStyle(style);
320 auto buttonRadius = secCompTheme->GetBorderRadius();
321 if (type == static_cast<int32_t>(ButtonType::ROUNDED_RECTANGLE)) {
322 buttonRadius = secCompTheme->GetDefaultBorderRadius();
323 }
324 buttonLayoutProperty->UpdateBorderRadius(BorderRadiusProperty(buttonRadius));
325 renderContext->UpdateBackgroundColor(secCompTheme->GetBackgroundColor());
326 buttonLayoutProperty->UpdateType(static_cast<ButtonType>(type));
327 }
328
SetInvisibleBackgroundButton(const RefPtr<FrameNode> & buttonNode)329 void SecurityComponentModelNG::SetInvisibleBackgroundButton(const RefPtr<FrameNode>& buttonNode)
330 {
331 auto buttonLayoutProperty = buttonNode->GetLayoutProperty<ButtonLayoutProperty>();
332 CHECK_NULL_VOID(buttonLayoutProperty);
333 const auto& renderContext = buttonNode->GetRenderContext();
334 CHECK_NULL_VOID(renderContext);
335 renderContext->UpdateBackgroundColor(Color::TRANSPARENT);
336 buttonLayoutProperty->UpdateType(ButtonType::NORMAL);
337 }
338
339 template<typename T>
GetChildLayoutProprty(const std::string & tag)340 RefPtr<T> GetChildLayoutProprty(const std::string& tag)
341 {
342 auto node = GetCurSecCompChildNode(tag);
343 CHECK_NULL_RETURN(node, nullptr);
344 return node->GetLayoutProperty<T>();
345 }
346
IsBackgroundVisible()347 bool SecurityComponentModelNG::IsBackgroundVisible()
348 {
349 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
350 CHECK_NULL_RETURN(frameNode, false);
351 auto prop = frameNode->GetLayoutProperty<SecurityComponentLayoutProperty>();
352 if (prop) {
353 return (prop->GetBackgroundType() != BUTTON_TYPE_NULL);
354 }
355 return false;
356 }
357
IsBackgroundVisible(FrameNode * frameNode)358 bool SecurityComponentModelNG::IsBackgroundVisible(FrameNode* frameNode)
359 {
360 CHECK_NULL_RETURN(frameNode, false);
361 auto prop = frameNode->GetLayoutProperty<SecurityComponentLayoutProperty>();
362 if (prop) {
363 return (prop->GetBackgroundType() != BUTTON_TYPE_NULL);
364 }
365 return false;
366 }
367
IsArkuiComponent()368 bool SecurityComponentModelNG::IsArkuiComponent()
369 {
370 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
371 CHECK_NULL_RETURN(frameNode, false);
372 auto prop = frameNode->GetLayoutProperty<SecurityComponentLayoutProperty>();
373 if (prop && prop->GetIsArkuiComponent().has_value()) {
374 return prop->GetIsArkuiComponent().value();
375 }
376 return false;
377 }
378
NotifyFontColorSet()379 void SecurityComponentModelNG::NotifyFontColorSet()
380 {
381 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
382 CHECK_NULL_VOID(frameNode);
383 auto prop = frameNode->GetLayoutProperty<SecurityComponentLayoutProperty>();
384 CHECK_NULL_VOID(prop);
385 prop->UpdateIsFontColorSet(true);
386 }
387
IsArkuiComponent(FrameNode * frameNode)388 bool SecurityComponentModelNG::IsArkuiComponent(FrameNode* frameNode)
389 {
390 CHECK_NULL_RETURN(frameNode, false);
391 auto prop = frameNode->GetLayoutProperty<SecurityComponentLayoutProperty>();
392 if (prop && prop->GetIsArkuiComponent().has_value()) {
393 return prop->GetIsArkuiComponent().value();
394 }
395 return false;
396 }
397
IsInReleaseList(uint32_t value)398 bool SecurityComponentModelNG::IsInReleaseList(uint32_t value)
399 {
400 return (RELEASE_ATTRIBUTE_LIST.find(value) != RELEASE_ATTRIBUTE_LIST.end());
401 }
402
IsBelowThreshold(const Color & value)403 bool SecurityComponentModelNG::IsBelowThreshold(const Color& value)
404 {
405 return value.GetAlpha() < DEFAULT_TRANSPARENCY_THRESHOLD;
406 }
407
SetIconSize(const Dimension & value)408 void SecurityComponentModelNG::SetIconSize(const Dimension& value)
409 {
410 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, IconSize, value);
411 }
412
SetIconSize(const NG::CalcSize & value)413 void SecurityComponentModelNG::SetIconSize(const NG::CalcSize& value)
414 {
415 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, IconCalcSize, value);
416 }
417
SetIconBorderRadius(const Dimension & value)418 void SecurityComponentModelNG::SetIconBorderRadius(const Dimension& value)
419 {
420 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
421 CHECK_NULL_VOID(frameNode);
422 auto prop = frameNode->GetLayoutProperty<SecurityComponentLayoutProperty>();
423 CHECK_NULL_VOID(prop);
424 auto hasPermission = prop->GetHasCustomPermissionForSecComp();
425 if (hasPermission.value_or(false)) {
426 NG::BorderRadiusProperty borderRadius = BorderRadiusProperty(value);
427 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, IconBorderRadius, borderRadius);
428 }
429 }
430
SetIconBorderRadius(const std::optional<Dimension> & topLeft,const std::optional<Dimension> & topRight,const std::optional<Dimension> & bottomLeft,const std::optional<Dimension> & bottomRight)431 void SecurityComponentModelNG::SetIconBorderRadius(const std::optional<Dimension>& topLeft,
432 const std::optional<Dimension>& topRight, const std::optional<Dimension>& bottomLeft,
433 const std::optional<Dimension>& bottomRight)
434 {
435 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
436 CHECK_NULL_VOID(frameNode);
437 auto prop = frameNode->GetLayoutProperty<SecurityComponentLayoutProperty>();
438 CHECK_NULL_VOID(prop);
439 auto hasPermission = prop->GetHasCustomPermissionForSecComp();
440 if (hasPermission.value_or(false)) {
441 NG::BorderRadiusProperty borderRadius;
442 borderRadius.radiusTopLeft = topLeft;
443 borderRadius.radiusTopRight = topRight;
444 borderRadius.radiusBottomLeft = bottomLeft;
445 borderRadius.radiusBottomRight = bottomRight;
446 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, IconBorderRadius, borderRadius);
447 }
448 }
449
SetIcon(const ImageSourceInfo & value)450 void SecurityComponentModelNG::SetIcon(const ImageSourceInfo& value)
451 {
452 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
453 CHECK_NULL_VOID(frameNode);
454 auto prop = frameNode->GetLayoutProperty<SecurityComponentLayoutProperty>();
455 CHECK_NULL_VOID(prop);
456 auto hasPermission = prop->GetHasCustomPermissionForSecComp();
457 if (hasPermission.value_or(false)) {
458 auto secCompTheme = GetTheme();
459 CHECK_NULL_VOID(secCompTheme);
460 bool isButtonVisible = false;
461 if (prop) {
462 isButtonVisible = (prop->GetBackgroundType() != BUTTON_TYPE_NULL);
463 }
464 RefPtr<FrameNode> iconNode = GetSecCompChildNode(frameNode, V2::IMAGE_ETS_TAG);
465 if (iconNode == nullptr) {
466 iconNode = FrameNode::CreateFrameNode(
467 V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>());
468 iconNode->SetInternal();
469 InternalResource::ResourceId iconId;
470 int32_t iconStyle = static_cast<int32_t>(SaveButtonIconStyle::ICON_FULL_FILLED);
471 if (SaveButtonModelNG::GetInstance()->GetIconResource(iconStyle, iconId)) {
472 SetDefaultIconStyle(iconNode, iconId, isButtonVisible);
473 }
474 CHECK_NULL_VOID(iconNode);
475 frameNode->AddChild(iconNode);
476
477 prop->UpdateIconStyle(iconStyle);
478 }
479
480 ImageSourceInfo imageSourceInfo = value;
481 if (isButtonVisible) {
482 imageSourceInfo.SetFillColor(secCompTheme->GetIconColor());
483 } else {
484 imageSourceInfo.SetFillColor(secCompTheme->GetIconColorNoBg());
485 }
486 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, ImageSourceInfo, imageSourceInfo);
487 }
488 }
489
SetText(const std::string & value)490 void SecurityComponentModelNG::SetText(const std::string& value)
491 {
492 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
493 CHECK_NULL_VOID(frameNode);
494 auto prop = frameNode->GetLayoutProperty<SecurityComponentLayoutProperty>();
495 CHECK_NULL_VOID(prop);
496 auto hasPermission = prop->GetHasCustomPermissionForSecComp();
497 if (hasPermission.value_or(false)) {
498 RefPtr<FrameNode> textNode = GetSecCompChildNode(frameNode, V2::TEXT_ETS_TAG);
499 if (textNode == nullptr) {
500 textNode = FrameNode::CreateFrameNode(
501 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
502 CHECK_NULL_VOID(textNode);
503 textNode->SetInternal();
504 std::string textStr = value;
505 bool isButtonVisible = false;
506 if (prop) {
507 isButtonVisible = (prop->GetBackgroundType() != BUTTON_TYPE_NULL);
508 }
509 SetDefaultTextStyle(textNode, textStr, isButtonVisible);
510 CHECK_NULL_VOID(textNode);
511 frameNode->AddChild(textNode);
512
513 prop->UpdateSecurityComponentDescription(static_cast<int32_t>(SaveButtonSaveDescription::DOWNLOAD));
514 }
515 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, TextContent, value);
516 }
517 }
518
SetIconSize(FrameNode * frameNode,const std::optional<Dimension> & value)519 void SecurityComponentModelNG::SetIconSize(FrameNode* frameNode, const std::optional<Dimension>& value)
520 {
521 CHECK_NULL_VOID(frameNode);
522 if (value) {
523 ACE_UPDATE_NODE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, IconSize, value.value(), frameNode);
524 } else {
525 ACE_RESET_NODE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, IconSize, frameNode);
526 }
527 }
528
SetIconColor(const Color & value)529 void SecurityComponentModelNG::SetIconColor(const Color& value)
530 {
531 ACE_UPDATE_PAINT_PROPERTY(SecurityComponentPaintProperty, IconColor, value);
532 }
533
SetIconColor(FrameNode * frameNode,const std::optional<Color> & value)534 void SecurityComponentModelNG::SetIconColor(FrameNode* frameNode, const std::optional<Color>& value)
535 {
536 CHECK_NULL_VOID(frameNode);
537 if (value) {
538 ACE_UPDATE_NODE_PAINT_PROPERTY(SecurityComponentPaintProperty, IconColor, value.value(), frameNode);
539 } else {
540 ACE_RESET_NODE_PAINT_PROPERTY(SecurityComponentPaintProperty, IconColor, frameNode);
541 }
542 }
543
SetSymbolIconSize(const Dimension & value)544 void SecurityComponentModelNG::SetSymbolIconSize(const Dimension& value)
545 {
546 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, SymbolIconSize, value);
547 }
548
SetSymbolIconColor(const std::vector<Color> & value)549 void SecurityComponentModelNG::SetSymbolIconColor(const std::vector<Color>& value)
550 {
551 ACE_UPDATE_PAINT_PROPERTY(SecurityComponentPaintProperty, SymbolIconColor, value);
552 }
553
SetFontSize(const Dimension & value)554 void SecurityComponentModelNG::SetFontSize(const Dimension& value)
555 {
556 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, FontSize, value);
557 }
558
SetFontSize(FrameNode * frameNode,const std::optional<Dimension> & value)559 void SecurityComponentModelNG::SetFontSize(FrameNode* frameNode, const std::optional<Dimension>& value)
560 {
561 CHECK_NULL_VOID(frameNode);
562 if (value) {
563 ACE_UPDATE_NODE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, FontSize, value.value(), frameNode);
564 } else {
565 ACE_RESET_NODE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, FontSize, frameNode);
566 }
567 }
568
SetFontStyle(const Ace::FontStyle & value)569 void SecurityComponentModelNG::SetFontStyle(const Ace::FontStyle& value)
570 {
571 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, FontStyle, value);
572 }
573
SetFontStyle(FrameNode * frameNode,const std::optional<Ace::FontStyle> & value)574 void SecurityComponentModelNG::SetFontStyle(FrameNode* frameNode, const std::optional<Ace::FontStyle>& value)
575 {
576 CHECK_NULL_VOID(frameNode);
577 if (value) {
578 ACE_UPDATE_NODE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, FontStyle, value.value(), frameNode);
579 } else {
580 ACE_RESET_NODE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, FontStyle, frameNode);
581 }
582 }
583
SetFontWeight(const FontWeight & value)584 void SecurityComponentModelNG::SetFontWeight(const FontWeight& value)
585 {
586 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, FontWeight, value);
587 }
588
SetFontWeight(FrameNode * frameNode,const std::optional<FontWeight> & value)589 void SecurityComponentModelNG::SetFontWeight(FrameNode* frameNode, const std::optional<FontWeight>& value)
590 {
591 CHECK_NULL_VOID(frameNode);
592 if (value) {
593 ACE_UPDATE_NODE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, FontWeight, value.value(), frameNode);
594 } else {
595 ACE_RESET_NODE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, FontWeight, frameNode);
596 }
597 }
598
SetFontFamily(const std::vector<std::string> & fontFamilies)599 void SecurityComponentModelNG::SetFontFamily(const std::vector<std::string>& fontFamilies)
600 {
601 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, FontFamily, fontFamilies);
602 }
603
SetFontFamily(FrameNode * frameNode,const std::optional<std::vector<std::string>> & fontFamilies)604 void SecurityComponentModelNG::SetFontFamily(FrameNode* frameNode,
605 const std::optional<std::vector<std::string>>& fontFamilies)
606 {
607 CHECK_NULL_VOID(frameNode);
608 if (fontFamilies) {
609 ACE_UPDATE_NODE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, FontFamily, fontFamilies.value(), frameNode);
610 } else {
611 ACE_RESET_NODE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, FontFamily, frameNode);
612 }
613 }
614
SetFontColor(const Color & value)615 void SecurityComponentModelNG::SetFontColor(const Color& value)
616 {
617 ACE_UPDATE_PAINT_PROPERTY(SecurityComponentPaintProperty, FontColor, value);
618 NotifyFontColorSet();
619 }
620
SetStateEffect(const bool & value)621 void SecurityComponentModelNG::SetStateEffect(const bool& value)
622 {
623 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
624 CHECK_NULL_VOID(frameNode);
625 auto prop = frameNode->GetLayoutProperty<SecurityComponentLayoutProperty>();
626 CHECK_NULL_VOID(prop);
627 auto hasPermission = prop->GetHasCustomPermissionForSecComp();
628 if (hasPermission.value_or(false)) {
629 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, StateEffect, value);
630 }
631 }
632
SetTipPosition(const TipPosition & value)633 void SecurityComponentModelNG::SetTipPosition(const TipPosition& value)
634 {
635 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
636 CHECK_NULL_VOID(frameNode);
637 auto prop = frameNode->GetLayoutProperty<SecurityComponentLayoutProperty>();
638 CHECK_NULL_VOID(prop);
639 auto hasPermission = prop->GetHasCustomPermissionForSecComp();
640 if (hasPermission.value_or(false)) {
641 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, TipPosition, value);
642 }
643 }
644
SetFontColor(FrameNode * frameNode,const std::optional<Color> & value)645 void SecurityComponentModelNG::SetFontColor(FrameNode* frameNode, const std::optional<Color>& value)
646 {
647 CHECK_NULL_VOID(frameNode);
648 if (value) {
649 ACE_UPDATE_NODE_PAINT_PROPERTY(SecurityComponentPaintProperty, FontColor, value.value(), frameNode);
650 } else {
651 ACE_RESET_NODE_PAINT_PROPERTY(SecurityComponentPaintProperty, FontColor, frameNode);
652 }
653 }
654
SetBackgroundColor(const Color & value)655 void SecurityComponentModelNG::SetBackgroundColor(const Color& value)
656 {
657 if (!IsBackgroundVisible()) {
658 SC_LOG_WARN("background is not exist");
659 return;
660 }
661
662 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
663 CHECK_NULL_VOID(frameNode);
664 auto prop = frameNode->GetLayoutProperty<SecurityComponentLayoutProperty>();
665 CHECK_NULL_VOID(prop);
666 bool res = prop->GetHasCustomPermissionForSecComp().value_or(false);
667 #ifdef SECURITY_COMPONENT_ENABLE
668 res |= SecurityComponentHandler::IsSystemAppCalling();
669 #endif
670 Color resColor = value;
671 if (!res && !IsInReleaseList(resColor.GetValue()) && !IsArkuiComponent() && IsBelowThreshold(value)) {
672 resColor = value.ChangeAlpha(FULL_TRANSPARENCY_VALUE);
673 }
674 ACE_UPDATE_PAINT_PROPERTY(SecurityComponentPaintProperty, BackgroundColor, resColor);
675 }
676
SetBackgroundColor(FrameNode * frameNode,const std::optional<Color> & valueOpt)677 void SecurityComponentModelNG::SetBackgroundColor(FrameNode* frameNode, const std::optional<Color>& valueOpt)
678 {
679 CHECK_NULL_VOID(frameNode);
680 if (!IsBackgroundVisible(frameNode)) {
681 SC_LOG_WARN("background is not exist");
682 return;
683 }
684
685 if (!valueOpt.has_value()) {
686 ACE_RESET_NODE_PAINT_PROPERTY(SecurityComponentPaintProperty, BackgroundColor, frameNode);
687 return;
688 }
689
690 bool res = false;
691 #ifdef SECURITY_COMPONENT_ENABLE
692 res = SecurityComponentHandler::IsSystemAppCalling();
693 #endif
694 const Color value = valueOpt.value();
695 Color resColor = value;
696 if (!res && !IsInReleaseList(resColor.GetValue()) && !IsArkuiComponent(frameNode) && IsBelowThreshold(value)) {
697 resColor = value.ChangeAlpha(FULL_TRANSPARENCY_VALUE);
698 }
699 ACE_UPDATE_NODE_PAINT_PROPERTY(SecurityComponentPaintProperty, BackgroundColor, resColor, frameNode);
700 }
701
SetBackgroundBorderWidth(const Dimension & value)702 void SecurityComponentModelNG::SetBackgroundBorderWidth(const Dimension& value)
703 {
704 if (!IsBackgroundVisible()) {
705 SC_LOG_WARN("background is not exist");
706 return;
707 }
708
709 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, BackgroundBorderWidth, value);
710 }
711
SetBackgroundBorderWidth(FrameNode * frameNode,const std::optional<Dimension> & value)712 void SecurityComponentModelNG::SetBackgroundBorderWidth(FrameNode* frameNode, const std::optional<Dimension>& value)
713 {
714 CHECK_NULL_VOID(frameNode);
715 if (!IsBackgroundVisible(frameNode)) {
716 SC_LOG_WARN("background is not exist");
717 return;
718 }
719
720 if (value) {
721 ACE_UPDATE_NODE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, BackgroundBorderWidth, value.value(),
722 frameNode);
723 } else {
724 ACE_RESET_NODE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, BackgroundBorderWidth, frameNode);
725 }
726 }
727
SetBackgroundBorderColor(const Color & value)728 void SecurityComponentModelNG::SetBackgroundBorderColor(const Color& value)
729 {
730 if (!IsBackgroundVisible()) {
731 SC_LOG_WARN("background is not exist");
732 return;
733 }
734 ACE_UPDATE_PAINT_PROPERTY(SecurityComponentPaintProperty, BackgroundBorderColor, value);
735 }
736
SetBackgroundBorderColor(FrameNode * frameNode,const std::optional<Color> & value)737 void SecurityComponentModelNG::SetBackgroundBorderColor(FrameNode* frameNode, const std::optional<Color>& value)
738 {
739 CHECK_NULL_VOID(frameNode);
740 if (!IsBackgroundVisible(frameNode)) {
741 SC_LOG_WARN("background is not exist");
742 return;
743 }
744 if (value) {
745 ACE_UPDATE_NODE_PAINT_PROPERTY(SecurityComponentPaintProperty, BackgroundBorderColor, value.value(),
746 frameNode);
747 } else {
748 ACE_RESET_NODE_PAINT_PROPERTY(SecurityComponentPaintProperty, BackgroundBorderColor, frameNode);
749 }
750 }
751
SetBackgroundBorderStyle(const BorderStyle & value)752 void SecurityComponentModelNG::SetBackgroundBorderStyle(const BorderStyle& value)
753 {
754 if (!IsBackgroundVisible()) {
755 SC_LOG_WARN("background is not exist");
756 return;
757 }
758 ACE_UPDATE_PAINT_PROPERTY(SecurityComponentPaintProperty, BackgroundBorderStyle, value);
759 }
760
SetBackgroundBorderStyle(FrameNode * frameNode,const std::optional<BorderStyle> & value)761 void SecurityComponentModelNG::SetBackgroundBorderStyle(FrameNode* frameNode, const std::optional<BorderStyle>& value)
762 {
763 CHECK_NULL_VOID(frameNode);
764 if (!IsBackgroundVisible(frameNode)) {
765 SC_LOG_WARN("background is not exist");
766 return;
767 }
768 BorderStyle borderStyle = value.value_or(BorderStyle::NONE);
769 ACE_UPDATE_NODE_PAINT_PROPERTY(SecurityComponentPaintProperty, BackgroundBorderStyle, borderStyle, frameNode);
770 }
771
SetBackgroundBorderRadius(const Dimension & value)772 void SecurityComponentModelNG::SetBackgroundBorderRadius(const Dimension& value)
773 {
774 if (!IsBackgroundVisible()) {
775 SC_LOG_WARN("background is not exist");
776 return;
777 }
778
779 NG::BorderRadiusProperty borderRadius = BorderRadiusProperty(value);
780 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, BackgroundBorderRadius, borderRadius);
781 }
782
SetBackgroundBorderRadius(FrameNode * frameNode,const std::optional<Dimension> & value)783 void SecurityComponentModelNG::SetBackgroundBorderRadius(FrameNode* frameNode, const std::optional<Dimension>& value)
784 {
785 CHECK_NULL_VOID(frameNode);
786 if (!IsBackgroundVisible(frameNode)) {
787 SC_LOG_WARN("background is not exist");
788 return;
789 }
790
791 if (value) {
792 NG::BorderRadiusProperty borderRadius = BorderRadiusProperty(value.value());
793 ACE_UPDATE_NODE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, BackgroundBorderRadius, borderRadius,
794 frameNode);
795 } else {
796 ACE_RESET_NODE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, BackgroundBorderRadius, frameNode);
797 }
798 }
799
SetBackgroundBorderRadius(const std::optional<Dimension> & topLeft,const std::optional<Dimension> & topRight,const std::optional<Dimension> & bottomLeft,const std::optional<Dimension> & bottomRight)800 void SecurityComponentModelNG::SetBackgroundBorderRadius(const std::optional<Dimension>& topLeft,
801 const std::optional<Dimension>& topRight, const std::optional<Dimension>& bottomLeft,
802 const std::optional<Dimension>& bottomRight)
803 {
804 if (!IsBackgroundVisible()) {
805 SC_LOG_WARN("Can not set background padding without background");
806 return;
807 }
808 NG::BorderRadiusProperty borderRadius;
809 borderRadius.radiusTopLeft = topLeft;
810 borderRadius.radiusTopRight = topRight;
811 borderRadius.radiusBottomLeft = bottomLeft;
812 borderRadius.radiusBottomRight = bottomRight;
813 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, BackgroundBorderRadius, borderRadius);
814 }
815
SetBackgroundPadding(const std::optional<Dimension> & left,const std::optional<Dimension> & right,const std::optional<Dimension> & top,const std::optional<Dimension> & bottom)816 void SecurityComponentModelNG::SetBackgroundPadding(const std::optional<Dimension>& left,
817 const std::optional<Dimension>& right, const std::optional<Dimension>& top,
818 const std::optional<Dimension>& bottom)
819 {
820 if (!IsBackgroundVisible()) {
821 SC_LOG_WARN("Can not set background padding without background");
822 return;
823 }
824
825 auto secCompTheme = GetTheme();
826 CHECK_NULL_VOID(secCompTheme);
827 if (left.has_value()) {
828 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty,
829 BackgroundLeftPadding, left.value());
830 }
831
832 if (right.has_value()) {
833 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty,
834 BackgroundRightPadding, right.value());
835 }
836 if (top.has_value()) {
837 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty,
838 BackgroundTopPadding, top.value());
839 }
840
841 if (bottom.has_value()) {
842 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty,
843 BackgroundBottomPadding, bottom.value());
844 }
845 }
846
SetBackgroundPadding(FrameNode * frameNode,const std::optional<Dimension> & left,const std::optional<Dimension> & right,const std::optional<Dimension> & top,const std::optional<Dimension> & bottom)847 void SecurityComponentModelNG::SetBackgroundPadding(
848 FrameNode* frameNode,
849 const std::optional<Dimension>& left, const std::optional<Dimension>& right,
850 const std::optional<Dimension>& top, const std::optional<Dimension>& bottom)
851 {
852 if (!IsBackgroundVisible(frameNode)) {
853 SC_LOG_WARN("Can not set background padding without background");
854 return;
855 }
856
857 auto secCompTheme = GetTheme();
858 CHECK_NULL_VOID(secCompTheme);
859 if (left.has_value()) {
860 ACE_UPDATE_NODE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty,
861 BackgroundLeftPadding, left.value(), frameNode);
862 } else {
863 ACE_RESET_NODE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty,
864 BackgroundLeftPadding, frameNode);
865 }
866
867 if (right.has_value()) {
868 ACE_UPDATE_NODE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty,
869 BackgroundRightPadding, right.value(), frameNode);
870 } else {
871 ACE_RESET_NODE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty,
872 BackgroundRightPadding, frameNode);
873 }
874 if (top.has_value()) {
875 ACE_UPDATE_NODE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty,
876 BackgroundTopPadding, top.value(), frameNode);
877 } else {
878 ACE_RESET_NODE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty,
879 BackgroundTopPadding, frameNode);
880 }
881
882 if (bottom.has_value()) {
883 ACE_UPDATE_NODE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty,
884 BackgroundBottomPadding, bottom.value(), frameNode);
885 } else {
886 ACE_RESET_NODE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty,
887 BackgroundBottomPadding, frameNode);
888 }
889 }
890
SetBackgroundPadding(const std::optional<Dimension> & padding)891 void SecurityComponentModelNG::SetBackgroundPadding(const std::optional<Dimension>& padding)
892 {
893 SetBackgroundPadding(padding, padding, padding, padding);
894 }
895
SetTextIconSpace(const Dimension & value)896 void SecurityComponentModelNG::SetTextIconSpace(const Dimension& value)
897 {
898 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, TextIconSpace, value);
899 }
900
SetTextIconSpace(FrameNode * frameNode,const std::optional<Dimension> & value)901 void SecurityComponentModelNG::SetTextIconSpace(FrameNode* frameNode, const std::optional<Dimension>& value)
902 {
903 CHECK_NULL_VOID(frameNode);
904 auto refPtr = AceType::Claim(frameNode);
905 if ((GetSecCompChildNode(refPtr, V2::TEXT_ETS_TAG) == nullptr) ||
906 (GetSecCompChildNode(refPtr, V2::IMAGE_ETS_TAG) == nullptr)) {
907 SC_LOG_WARN("Can not set text icon padding without text and icon");
908 return;
909 }
910 if (value) {
911 ACE_UPDATE_NODE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, TextIconSpace, value.value(), frameNode);
912 } else {
913 ACE_RESET_NODE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, TextIconSpace, frameNode);
914 }
915 }
916
SetTextIconLayoutDirection(const SecurityComponentLayoutDirection & value)917 void SecurityComponentModelNG::SetTextIconLayoutDirection(const SecurityComponentLayoutDirection& value)
918 {
919 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, TextIconLayoutDirection, value);
920 }
921
SetTextIconLayoutDirection(FrameNode * frameNode,const std::optional<SecurityComponentLayoutDirection> & value)922 void SecurityComponentModelNG::SetTextIconLayoutDirection(FrameNode* frameNode,
923 const std::optional<SecurityComponentLayoutDirection>& value)
924 {
925 CHECK_NULL_VOID(frameNode);
926 auto layoutDirection = value.value_or(SecurityComponentLayoutDirection::HORIZONTAL);
927 ACE_UPDATE_NODE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, TextIconLayoutDirection, layoutDirection,
928 frameNode);
929 }
930
SetAlign(const Alignment alignment)931 void SecurityComponentModelNG::SetAlign(const Alignment alignment)
932 {
933 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, Alignment, alignment);
934 }
935
SetMaxFontScale(const float value)936 void SecurityComponentModelNG::SetMaxFontScale(const float value)
937 {
938 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, MaxFontScale, value);
939 }
940
SetMinFontScale(const float value)941 void SecurityComponentModelNG::SetMinFontScale(const float value)
942 {
943 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, MinFontScale, value);
944 }
945
SetMaxLines(const int32_t value)946 void SecurityComponentModelNG::SetMaxLines(const int32_t value)
947 {
948 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, MaxLines, value);
949 }
950
SetAdaptMaxFontSize(const Dimension & value)951 void SecurityComponentModelNG::SetAdaptMaxFontSize(const Dimension& value)
952 {
953 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, AdaptMaxFontSize, value);
954 }
955
SetAdaptMinFontSize(const Dimension & value)956 void SecurityComponentModelNG::SetAdaptMinFontSize(const Dimension& value)
957 {
958 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, AdaptMinFontSize, value);
959 }
960
SetHeightAdaptivePolicy(TextHeightAdaptivePolicy value)961 void SecurityComponentModelNG::SetHeightAdaptivePolicy(TextHeightAdaptivePolicy value)
962 {
963 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, HeightAdaptivePolicy, value);
964 }
965 } // namespace OHOS::Ace::NG
966