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 #ifdef SECURITY_COMPONENT_ENABLE
24 #include "core/components_ng/pattern/security_component/security_component_handler.h"
25 #endif
26 #include "core/components_ng/pattern/security_component/security_component_log.h"
27 #include "core/components_ng/pattern/security_component/security_component_pattern.h"
28 #include "core/components_ng/pattern/security_component/security_component_theme.h"
29 #include "core/components_ng/pattern/text/text_pattern.h"
30 #include "core/components_v2/inspector/inspector_constants.h"
31 #include "core/pipeline_ng/pipeline_context.h"
32
33 namespace OHOS::Ace::NG {
34 const static uint8_t DEFAULT_TRANSPARENCY_THRESHOLD = 0x1A;
35 const static uint8_t FULL_TRANSPARENCY_VALUE = 0xFF;
36 const static std::set<uint32_t> RELEASE_ATTRIBUTE_LIST = {
37 0x0C000000,
38 };
39 const static double DEFAULT_ICON_FONT_SIZE = 24;
GetTheme()40 RefPtr<SecurityComponentTheme> SecurityComponentModelNG::GetTheme()
41 {
42 auto pipeline = PipelineContext::GetCurrentContextSafely();
43 CHECK_NULL_RETURN(pipeline, nullptr);
44 return pipeline->GetTheme<SecurityComponentTheme>();
45 }
46
InitLayoutProperty(RefPtr<FrameNode> & node,int32_t text,int32_t icon,uint32_t symbolIcon,int32_t backgroundType)47 void SecurityComponentModelNG::InitLayoutProperty(RefPtr<FrameNode>& node, int32_t text, int32_t icon,
48 uint32_t symbolIcon, int32_t backgroundType)
49 {
50 auto property = node->GetLayoutProperty<SecurityComponentLayoutProperty>();
51 CHECK_NULL_VOID(property);
52 auto secCompTheme = GetTheme();
53 CHECK_NULL_VOID(secCompTheme);
54 property->UpdateSecurityComponentDescription(text);
55 property->UpdateIconStyle(icon);
56 property->UpdateSymbolIconStyle(symbolIcon);
57 property->UpdateBackgroundType(backgroundType);
58
59 bool isNullSymbolIcon = !symbolIcon ||
60 symbolIcon == static_cast<uint32_t>(SecurityComponentIconStyle::ICON_NULL);
61 if ((text == static_cast<int32_t>(SecurityComponentDescription::TEXT_NULL)) ||
62 ((icon == static_cast<int32_t>(SecurityComponentIconStyle::ICON_NULL)) && isNullSymbolIcon)) {
63 property->UpdateTextIconSpace(Dimension(0.0));
64 }
65
66 if (backgroundType == BUTTON_TYPE_NULL) {
67 property->UpdateBackgroundLeftPadding(secCompTheme->GetPaddingWithoutBg());
68 property->UpdateBackgroundRightPadding(secCompTheme->GetPaddingWithoutBg());
69 property->UpdateBackgroundTopPadding(secCompTheme->GetPaddingWithoutBg());
70 property->UpdateBackgroundBottomPadding(secCompTheme->GetPaddingWithoutBg());
71 }
72
73 property->UpdateTextIconLayoutDirection(SecurityComponentLayoutDirection::HORIZONTAL);
74 }
75
CreateNode(const std::string & tag,int32_t nodeId,SecurityComponentElementStyle & style,const std::function<RefPtr<Pattern> (void)> & patternCreator,bool isArkuiComponent)76 RefPtr<FrameNode> SecurityComponentModelNG::CreateNode(const std::string& tag, int32_t nodeId,
77 SecurityComponentElementStyle& style, const std::function<RefPtr<Pattern>(void)>& patternCreator,
78 bool isArkuiComponent)
79 {
80 ACE_LAYOUT_SCOPED_TRACE("Create[%s][self:%d]", tag.c_str(), nodeId);
81 auto frameNode = InitChild(tag, nodeId, style, patternCreator);
82 CHECK_NULL_RETURN(frameNode, nullptr);
83 auto property = frameNode->GetLayoutProperty<SecurityComponentLayoutProperty>();
84 CHECK_NULL_RETURN(property, nullptr);
85 property->UpdatePropertyChangeFlag(PROPERTY_UPDATE_MEASURE);
86 property->UpdateIsArkuiComponent(isArkuiComponent);
87 property->UpdateTextStyle(style.text);
88 auto pipeline = AceType::DynamicCast<PipelineContext>(PipelineBase::GetCurrentContextSafelyWithCheck());
89 CHECK_NULL_RETURN(pipeline, nullptr);
90 pipeline->AddWindowStateChangedCallback(nodeId);
91 return frameNode;
92 }
93
InitChild(const std::string & tag,int32_t nodeId,SecurityComponentElementStyle & style,const std::function<RefPtr<Pattern> (void)> & patternCreator)94 RefPtr<FrameNode> SecurityComponentModelNG::InitChild(const std::string& tag, int32_t nodeId,
95 SecurityComponentElementStyle& style, const std::function<RefPtr<Pattern>(void)>& patternCreator)
96 {
97 auto frameNode = FrameNode::GetOrCreateFrameNode(tag, nodeId, patternCreator);
98 CHECK_NULL_RETURN(frameNode, nullptr);
99 if (frameNode->GetChildren().empty()) {
100 bool isButtonVisible = (style.backgroundType != BUTTON_TYPE_NULL);
101 auto buttonNode = FrameNode::CreateFrameNode(
102 V2::BUTTON_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
103 AceType::MakeRefPtr<ButtonPattern>());
104 buttonNode->SetInternal();
105
106 if (isButtonVisible) {
107 SetDefaultBackgroundButton(buttonNode, style.backgroundType);
108 } else {
109 SetInvisibleBackgroundButton(buttonNode);
110 }
111 frameNode->AddChild(buttonNode);
112 if (style.symbolIcon && style.symbolIcon != static_cast<uint32_t>(SecurityComponentIconStyle::ICON_NULL)) {
113 auto symbolIcon = FrameNode::CreateFrameNode(
114 V2::SYMBOL_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
115 SetDefaultSymbolIconStyle(symbolIcon, style.symbolIcon, isButtonVisible);
116 frameNode->AddChild(symbolIcon);
117 } else if (style.icon != static_cast<int32_t>(SecurityComponentIconStyle::ICON_NULL)) {
118 auto imageIcon = FrameNode::CreateFrameNode(
119 V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>());
120 imageIcon->SetInternal();
121 InternalResource::ResourceId iconId;
122 if (GetIconResource(style.icon, iconId)) {
123 SetDefaultIconStyle(imageIcon, iconId, isButtonVisible);
124 }
125 frameNode->AddChild(imageIcon);
126 }
127
128 if (style.text != static_cast<int32_t>(SecurityComponentDescription::TEXT_NULL)) {
129 auto textNode = FrameNode::CreateFrameNode(
130 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
131 CHECK_NULL_RETURN(textNode, nullptr);
132 textNode->SetInternal();
133 std::string textStr = "";
134 GetTextResource(style.text, textStr);
135 SetDefaultTextStyle(textNode, textStr, isButtonVisible);
136 frameNode->AddChild(textNode);
137 }
138 InitLayoutProperty(frameNode, style.text, style.icon, style.symbolIcon, style.backgroundType);
139 }
140 return frameNode;
141 }
142
CreateCommon(const std::string & tag,int32_t text,int32_t icon,int32_t backgroundType,const std::function<RefPtr<Pattern> (void)> & patternCreator,bool isArkuiComponent)143 void SecurityComponentModelNG::CreateCommon(const std::string& tag, int32_t text, int32_t icon,
144 int32_t backgroundType, const std::function<RefPtr<Pattern>(void)>& patternCreator, bool isArkuiComponent)
145 {
146 auto stack = ViewStackProcessor::GetInstance();
147 auto nodeId = stack->ClaimNodeId();
148 SecurityComponentElementStyle style = {
149 .text = text,
150 .icon = icon,
151 .backgroundType = backgroundType
152 };
153 auto frameNode = CreateNode(tag, nodeId, style, patternCreator, isArkuiComponent);
154 CHECK_NULL_VOID(frameNode);
155 stack->Push(frameNode);
156 }
157
SetDefaultTextStyle(const RefPtr<FrameNode> & textNode,const std::string & text,bool isButtonVisible)158 void SecurityComponentModelNG::SetDefaultTextStyle(const RefPtr<FrameNode>& textNode, const std::string& text,
159 bool isButtonVisible)
160 {
161 auto secCompTheme = GetTheme();
162 CHECK_NULL_VOID(secCompTheme);
163 auto textLayoutProperty = textNode->GetLayoutProperty<TextLayoutProperty>();
164 CHECK_NULL_VOID(textLayoutProperty);
165 textLayoutProperty->UpdateContent(text);
166 textLayoutProperty->UpdateMaxLines(secCompTheme->GetDefaultTextMaxLines());
167 textLayoutProperty->UpdateFontSize(secCompTheme->GetFontSize());
168 textLayoutProperty->UpdateItalicFontStyle(Ace::FontStyle::NORMAL);
169 textLayoutProperty->UpdateFontWeight(FontWeight::MEDIUM);
170 textLayoutProperty->UpdateHeightAdaptivePolicy(TextHeightAdaptivePolicy::MAX_LINES_FIRST);
171
172 if (isButtonVisible) {
173 textLayoutProperty->UpdateTextColor(secCompTheme->GetFontColor());
174 } else {
175 textLayoutProperty->UpdateTextColor(secCompTheme->GetFontColorNoBg());
176 }
177 }
178
SetDefaultIconStyle(const RefPtr<FrameNode> & imageNode,InternalResource::ResourceId id,bool isButtonVisible)179 void SecurityComponentModelNG::SetDefaultIconStyle(const RefPtr<FrameNode>& imageNode, InternalResource::ResourceId id,
180 bool isButtonVisible)
181 {
182 auto secCompTheme = GetTheme();
183 CHECK_NULL_VOID(secCompTheme);
184 ImageSourceInfo imageSourceInfo;
185 imageSourceInfo.SetResourceId(id);
186 if (isButtonVisible) {
187 imageSourceInfo.SetFillColor(secCompTheme->GetIconColor());
188 } else {
189 imageSourceInfo.SetFillColor(secCompTheme->GetIconColorNoBg());
190 }
191
192 auto iconProp = imageNode->GetLayoutProperty<ImageLayoutProperty>();
193 CHECK_NULL_VOID(iconProp);
194 iconProp->UpdateImageSourceInfo(imageSourceInfo);
195 iconProp->UpdateUserDefinedIdealSize(
196 CalcSize(NG::CalcLength(secCompTheme->GetIconSize()), NG::CalcLength(secCompTheme->GetIconSize())));
197 // default follow text direction
198 ImageModelNG::SetMatchTextDirection(Referenced::RawPtr(imageNode), true);
199 }
200
SetDefaultSymbolIconStyle(const RefPtr<FrameNode> & symbolNode,uint32_t symbolId,bool isButtonVisible)201 void SecurityComponentModelNG::SetDefaultSymbolIconStyle(
202 const RefPtr<FrameNode> &symbolNode, uint32_t symbolId, bool isButtonVisible)
203 {
204 CHECK_NULL_VOID(symbolNode);
205 auto secCompTheme = GetTheme();
206 CHECK_NULL_VOID(secCompTheme);
207 auto iconProp = symbolNode->GetLayoutProperty<TextLayoutProperty>();
208 CHECK_NULL_VOID(iconProp);
209 SymbolSourceInfo symbolSourceInfo(symbolId);
210 if (isButtonVisible) {
211 iconProp->UpdateSymbolColorList({secCompTheme->GetDefaultSymbolIconColor()});
212 } else {
213 iconProp->UpdateSymbolColorList({secCompTheme->GetIconColorNoBg()});
214 }
215 iconProp->UpdateSymbolSourceInfo(symbolSourceInfo);
216 iconProp->UpdateFontSize(Dimension(DEFAULT_ICON_FONT_SIZE, DimensionUnit::VP));
217 symbolNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
218 symbolNode->MarkModifyDone();
219 }
SetDefaultBackgroundButton(const RefPtr<FrameNode> & buttonNode,int32_t type)220 void SecurityComponentModelNG::SetDefaultBackgroundButton(const RefPtr<FrameNode>& buttonNode,
221 int32_t type)
222 {
223 auto buttonLayoutProperty = buttonNode->GetLayoutProperty<ButtonLayoutProperty>();
224 CHECK_NULL_VOID(buttonLayoutProperty);
225 const auto& renderContext = buttonNode->GetRenderContext();
226 CHECK_NULL_VOID(renderContext);
227 auto secCompTheme = GetTheme();
228 CHECK_NULL_VOID(secCompTheme);
229
230 BorderColorProperty borderColor;
231 borderColor.SetColor(secCompTheme->GetBorderColor());
232 renderContext->UpdateBorderColor(borderColor);
233 BorderWidthProperty widthProp;
234 widthProp.SetBorderWidth(secCompTheme->GetBorderWidth());
235 buttonLayoutProperty->UpdateBorderWidth(widthProp);
236 BorderStyleProperty style;
237 style.SetBorderStyle(BorderStyle::NONE);
238 renderContext->UpdateBorderStyle(style);
239 auto buttonRadius = secCompTheme->GetBorderRadius();
240 if (type == static_cast<int32_t>(ButtonType::ROUNDED_RECTANGLE)) {
241 buttonRadius = secCompTheme->GetDefaultBorderRadius();
242 }
243 buttonLayoutProperty->UpdateBorderRadius(BorderRadiusProperty(buttonRadius));
244 renderContext->UpdateBackgroundColor(secCompTheme->GetBackgroundColor());
245 buttonLayoutProperty->UpdateType(static_cast<ButtonType>(type));
246 }
247
SetInvisibleBackgroundButton(const RefPtr<FrameNode> & buttonNode)248 void SecurityComponentModelNG::SetInvisibleBackgroundButton(const RefPtr<FrameNode>& buttonNode)
249 {
250 auto buttonLayoutProperty = buttonNode->GetLayoutProperty<ButtonLayoutProperty>();
251 CHECK_NULL_VOID(buttonLayoutProperty);
252 const auto& renderContext = buttonNode->GetRenderContext();
253 CHECK_NULL_VOID(renderContext);
254 renderContext->UpdateBackgroundColor(Color::TRANSPARENT);
255 buttonLayoutProperty->UpdateType(ButtonType::NORMAL);
256 }
257
258 template<typename T>
GetChildLayoutProprty(const std::string & tag)259 RefPtr<T> GetChildLayoutProprty(const std::string& tag)
260 {
261 auto node = GetCurSecCompChildNode(tag);
262 CHECK_NULL_RETURN(node, nullptr);
263 return node->GetLayoutProperty<T>();
264 }
265
IsBackgroundVisible()266 bool SecurityComponentModelNG::IsBackgroundVisible()
267 {
268 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
269 CHECK_NULL_RETURN(frameNode, false);
270 auto prop = frameNode->GetLayoutProperty<SecurityComponentLayoutProperty>();
271 if (prop) {
272 return (prop->GetBackgroundType() != BUTTON_TYPE_NULL);
273 }
274 return false;
275 }
276
IsArkuiComponent()277 bool SecurityComponentModelNG::IsArkuiComponent()
278 {
279 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
280 CHECK_NULL_RETURN(frameNode, false);
281 auto prop = frameNode->GetLayoutProperty<SecurityComponentLayoutProperty>();
282 if (prop && prop->GetIsArkuiComponent().has_value()) {
283 return prop->GetIsArkuiComponent().value();
284 }
285 return false;
286 }
287
NotifyFontColorSet()288 void SecurityComponentModelNG::NotifyFontColorSet()
289 {
290 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
291 CHECK_NULL_VOID(frameNode);
292 auto prop = frameNode->GetLayoutProperty<SecurityComponentLayoutProperty>();
293 CHECK_NULL_VOID(prop);
294 prop->UpdateIsFontColorSet(true);
295 }
296
IsInReleaseList(uint32_t value)297 bool SecurityComponentModelNG::IsInReleaseList(uint32_t value)
298 {
299 return (RELEASE_ATTRIBUTE_LIST.find(value) != RELEASE_ATTRIBUTE_LIST.end());
300 }
301
IsBelowThreshold(const Color & value)302 bool SecurityComponentModelNG::IsBelowThreshold(const Color& value)
303 {
304 return value.GetAlpha() < DEFAULT_TRANSPARENCY_THRESHOLD;
305 }
306
SetIconSize(const Dimension & value)307 void SecurityComponentModelNG::SetIconSize(const Dimension& value)
308 {
309 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, IconSize, value);
310 }
311
SetIconColor(const Color & value)312 void SecurityComponentModelNG::SetIconColor(const Color& value)
313 {
314 ACE_UPDATE_PAINT_PROPERTY(SecurityComponentPaintProperty, IconColor, value);
315 }
316
SetSymbolIconSize(const Dimension & value)317 void SecurityComponentModelNG::SetSymbolIconSize(const Dimension& value)
318 {
319 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, SymbolIconSize, value);
320 }
321
SetSymbolIconColor(const std::vector<Color> & value)322 void SecurityComponentModelNG::SetSymbolIconColor(const std::vector<Color>& value)
323 {
324 ACE_UPDATE_PAINT_PROPERTY(SecurityComponentPaintProperty, SymbolIconColor, value);
325 }
326
SetFontSize(const Dimension & value)327 void SecurityComponentModelNG::SetFontSize(const Dimension& value)
328 {
329 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, FontSize, value);
330 }
331
SetFontStyle(const Ace::FontStyle & value)332 void SecurityComponentModelNG::SetFontStyle(const Ace::FontStyle& value)
333 {
334 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, FontStyle, value);
335 }
336
SetFontWeight(const FontWeight & value)337 void SecurityComponentModelNG::SetFontWeight(const FontWeight& value)
338 {
339 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, FontWeight, value);
340 }
341
SetFontFamily(const std::vector<std::string> & fontFamilies)342 void SecurityComponentModelNG::SetFontFamily(const std::vector<std::string>& fontFamilies)
343 {
344 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, FontFamily, fontFamilies);
345 }
346
SetFontColor(const Color & value)347 void SecurityComponentModelNG::SetFontColor(const Color& value)
348 {
349 ACE_UPDATE_PAINT_PROPERTY(SecurityComponentPaintProperty, FontColor, value);
350 NotifyFontColorSet();
351 }
352
SetBackgroundColor(const Color & value)353 void SecurityComponentModelNG::SetBackgroundColor(const Color& value)
354 {
355 if (!IsBackgroundVisible()) {
356 SC_LOG_WARN("background is not exist");
357 return;
358 }
359
360 bool res = false;
361 #ifdef SECURITY_COMPONENT_ENABLE
362 res = SecurityComponentHandler::IsSystemAppCalling();
363 #endif
364 Color resColor = value;
365 if (!res && !IsInReleaseList(resColor.GetValue()) && !IsArkuiComponent() && IsBelowThreshold(value)) {
366 resColor = value.ChangeAlpha(FULL_TRANSPARENCY_VALUE);
367 }
368 ACE_UPDATE_PAINT_PROPERTY(SecurityComponentPaintProperty, BackgroundColor, resColor);
369 }
370
SetBackgroundBorderWidth(const Dimension & value)371 void SecurityComponentModelNG::SetBackgroundBorderWidth(const Dimension& value)
372 {
373 if (!IsBackgroundVisible()) {
374 SC_LOG_WARN("background is not exist");
375 return;
376 }
377
378 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, BackgroundBorderWidth, value);
379 }
380
SetBackgroundBorderColor(const Color & value)381 void SecurityComponentModelNG::SetBackgroundBorderColor(const Color& value)
382 {
383 if (!IsBackgroundVisible()) {
384 SC_LOG_WARN("background is not exist");
385 return;
386 }
387 ACE_UPDATE_PAINT_PROPERTY(SecurityComponentPaintProperty, BackgroundBorderColor, value);
388 }
389
SetBackgroundBorderStyle(const BorderStyle & value)390 void SecurityComponentModelNG::SetBackgroundBorderStyle(const BorderStyle& value)
391 {
392 if (!IsBackgroundVisible()) {
393 SC_LOG_WARN("background is not exist");
394 return;
395 }
396 ACE_UPDATE_PAINT_PROPERTY(SecurityComponentPaintProperty, BackgroundBorderStyle, value);
397 }
398
SetBackgroundBorderRadius(const Dimension & value)399 void SecurityComponentModelNG::SetBackgroundBorderRadius(const Dimension& value)
400 {
401 if (!IsBackgroundVisible()) {
402 SC_LOG_WARN("background is not exist");
403 return;
404 }
405
406 NG::BorderRadiusProperty borderRadius = BorderRadiusProperty(value);
407 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, BackgroundBorderRadius, borderRadius);
408 }
409
SetBackgroundBorderRadius(const std::optional<Dimension> & topLeft,const std::optional<Dimension> & topRight,const std::optional<Dimension> & bottomLeft,const std::optional<Dimension> & bottomRight)410 void SecurityComponentModelNG::SetBackgroundBorderRadius(const std::optional<Dimension>& topLeft,
411 const std::optional<Dimension>& topRight, const std::optional<Dimension>& bottomLeft,
412 const std::optional<Dimension>& bottomRight)
413 {
414 if (!IsBackgroundVisible()) {
415 SC_LOG_WARN("Can not set background padding without background");
416 return;
417 }
418 NG::BorderRadiusProperty borderRadius;
419 borderRadius.radiusTopLeft = topLeft;
420 borderRadius.radiusTopRight = topRight;
421 borderRadius.radiusBottomLeft = bottomLeft;
422 borderRadius.radiusBottomRight = bottomRight;
423 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, BackgroundBorderRadius, borderRadius);
424 }
425
SetBackgroundPadding(const std::optional<Dimension> & left,const std::optional<Dimension> & right,const std::optional<Dimension> & top,const std::optional<Dimension> & bottom)426 void SecurityComponentModelNG::SetBackgroundPadding(const std::optional<Dimension>& left,
427 const std::optional<Dimension>& right, const std::optional<Dimension>& top,
428 const std::optional<Dimension>& bottom)
429 {
430 if (!IsBackgroundVisible()) {
431 SC_LOG_WARN("Can not set background padding without background");
432 return;
433 }
434
435 auto secCompTheme = GetTheme();
436 CHECK_NULL_VOID(secCompTheme);
437 if (left.has_value()) {
438 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty,
439 BackgroundLeftPadding, left.value());
440 }
441
442 if (right.has_value()) {
443 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty,
444 BackgroundRightPadding, right.value());
445 }
446 if (top.has_value()) {
447 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty,
448 BackgroundTopPadding, top.value());
449 }
450
451 if (bottom.has_value()) {
452 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty,
453 BackgroundBottomPadding, bottom.value());
454 }
455 }
456
SetBackgroundPadding(const std::optional<Dimension> & padding)457 void SecurityComponentModelNG::SetBackgroundPadding(const std::optional<Dimension>& padding)
458 {
459 SetBackgroundPadding(padding, padding, padding, padding);
460 }
461
SetTextIconSpace(const Dimension & value)462 void SecurityComponentModelNG::SetTextIconSpace(const Dimension& value)
463 {
464 if ((GetCurSecCompChildNode(V2::TEXT_ETS_TAG) == nullptr) ||
465 (GetCurSecCompChildNode(V2::IMAGE_ETS_TAG) == nullptr)) {
466 SC_LOG_WARN("Can not set text icon padding without text and icon");
467 return;
468 }
469 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, TextIconSpace, value);
470 }
471
SetTextIconLayoutDirection(const SecurityComponentLayoutDirection & value)472 void SecurityComponentModelNG::SetTextIconLayoutDirection(const SecurityComponentLayoutDirection& value)
473 {
474 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, TextIconLayoutDirection, value);
475 }
476
SetAlign(const Alignment alignment)477 void SecurityComponentModelNG::SetAlign(const Alignment alignment)
478 {
479 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, Alignment, alignment);
480 }
481
SetMaxFontScale(const float value)482 void SecurityComponentModelNG::SetMaxFontScale(const float value)
483 {
484 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, MaxFontScale, value);
485 }
486
SetMinFontScale(const float value)487 void SecurityComponentModelNG::SetMinFontScale(const float value)
488 {
489 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, MinFontScale, value);
490 }
491
SetMaxLines(const int32_t value)492 void SecurityComponentModelNG::SetMaxLines(const int32_t value)
493 {
494 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, MaxLines, value);
495 }
496
SetAdaptMaxFontSize(const Dimension & value)497 void SecurityComponentModelNG::SetAdaptMaxFontSize(const Dimension& value)
498 {
499 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, AdaptMaxFontSize, value);
500 }
501
SetAdaptMinFontSize(const Dimension & value)502 void SecurityComponentModelNG::SetAdaptMinFontSize(const Dimension& value)
503 {
504 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, AdaptMinFontSize, value);
505 }
506
SetHeightAdaptivePolicy(TextHeightAdaptivePolicy value)507 void SecurityComponentModelNG::SetHeightAdaptivePolicy(TextHeightAdaptivePolicy value)
508 {
509 ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, HeightAdaptivePolicy, value);
510 }
511 } // namespace OHOS::Ace::NG
512