diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.cpp b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.cpp index daee9662de2..37c8df39b6c 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.cpp +++ b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.cpp @@ -7382,7 +7382,7 @@ ArkUINativeModuleValue CommonBridge::SetFocusBox(ArkUIRuntimeCallInfo* runtimeCa int32_t hasValue = 0; CalcDimension margin; if (!marginArg->IsUndefined() && !marginArg->IsNull()) { - if (ArkTSUtils::ParseJsDimensionVpNG(vm, marginArg, margin, true)) { + if (ArkTSUtils::ParseJsDimensionFpNG(vm, marginArg, margin, false)) { hasValue = 1; } else if (ArkTSUtils::ParseJsLengthMetrics(vm, marginArg, margin)) { hasValue = 1; @@ -7391,7 +7391,7 @@ ArkUINativeModuleValue CommonBridge::SetFocusBox(ArkUIRuntimeCallInfo* runtimeCa hasValue = hasValue << 1; CalcDimension width; if (!widthArg->IsUndefined() && !widthArg->IsNull()) { - if (ArkTSUtils::ParseJsDimensionVpNG(vm, widthArg, width, true) && GreatOrEqual(width.Value(), 0.0f)) { + if (ArkTSUtils::ParseJsDimensionFpNG(vm, widthArg, width, false) && GreatOrEqual(width.Value(), 0.0f)) { hasValue += 1; } else if (ArkTSUtils::ParseJsLengthMetrics(vm, widthArg, width) && GreatOrEqual(width.Value(), 0.0f)) { hasValue += 1; @@ -7402,8 +7402,9 @@ ArkUINativeModuleValue CommonBridge::SetFocusBox(ArkUIRuntimeCallInfo* runtimeCa if (!colorArg->IsUndefined() && !colorArg->IsNull() && ParseColorMetricsToColor(vm, colorArg, strokeColor)) { hasValue += 1; } - GetArkUINodeModifiers()->getCommonModifier()->setFocusBoxStyle( - nativeNode, margin.Value(), width.Value(), strokeColor.GetValue(), hasValue); + GetArkUINodeModifiers()->getCommonModifier()->setFocusBoxStyle(nativeNode, margin.Value(), + static_cast(margin.Unit()), width.Value(), static_cast(width.Unit()), strokeColor.GetValue(), + hasValue); return panda::JSValueRef::Undefined(vm); } diff --git a/frameworks/core/interfaces/arkoala/arkoala_api.h b/frameworks/core/interfaces/arkoala/arkoala_api.h index 50736410470..38c6aee9a5b 100644 --- a/frameworks/core/interfaces/arkoala/arkoala_api.h +++ b/frameworks/core/interfaces/arkoala/arkoala_api.h @@ -1726,8 +1726,8 @@ struct ArkUICommonModifier { void (*setDragPreview)(ArkUINodeHandle node, ArkUIDragPreview dragPreview); void (*resetDragPreview)(ArkUINodeHandle node); ArkUI_Int32 (*getNodeUniqueId)(ArkUINodeHandle node); - void (*setFocusBoxStyle)(ArkUINodeHandle node, ArkUI_Float32 valueMargin, ArkUI_Float32 valueStrokeWidth, - ArkUI_Uint32 valueColor, ArkUI_Uint32 hasValue); + void (*setFocusBoxStyle)(ArkUINodeHandle node, ArkUI_Float32 valueMargin, ArkUI_Int32 marginUnit, + ArkUI_Float32 valueStrokeWidth, ArkUI_Int32 widthUnit, ArkUI_Uint32 valueColor, ArkUI_Uint32 hasValue); void (*resetFocusBoxStyle)(ArkUINodeHandle node); }; diff --git a/frameworks/core/interfaces/native/node/node_common_modifier.cpp b/frameworks/core/interfaces/native/node/node_common_modifier.cpp index 8e11c4b301d..bcc1cdee9ea 100644 --- a/frameworks/core/interfaces/native/node/node_common_modifier.cpp +++ b/frameworks/core/interfaces/native/node/node_common_modifier.cpp @@ -6065,23 +6065,31 @@ ArkUI_Int32 GetNodeUniqueId(ArkUINodeHandle node) return frameNode->GetId(); } -void SetFocusBoxStyle(ArkUINodeHandle node, ArkUI_Float32 valueMargin, ArkUI_Float32 valueStrokeWidth, - ArkUI_Uint32 valueColor, ArkUI_Uint32 hasValue) +void SetFocusBoxStyle(ArkUINodeHandle node, ArkUI_Float32 valueMargin, ArkUI_Int32 marginUnit, + ArkUI_Float32 valueStrokeWidth, ArkUI_Int32 widthUnit, ArkUI_Uint32 valueColor, ArkUI_Uint32 hasValue) { CHECK_NULL_VOID(node); auto* frameNode = reinterpret_cast(node); + auto marginUnitEnum = static_cast(marginUnit); + auto widthUnitEnum = static_cast(widthUnit); NG::FocusBoxStyle style; - if ((hasValue >> 2) & 1) { // margin - CalcDimension margin; - margin.SetValue(valueMargin); + if ((hasValue >> 2) & 1) { // 2: margin + CalcDimension margin = CalcDimension(valueMargin, DimensionUnit::FP); + if (marginUnitEnum >= OHOS::Ace::DimensionUnit::PX && marginUnitEnum <= OHOS::Ace::DimensionUnit::CALC && + marginUnitEnum != OHOS::Ace::DimensionUnit::PERCENT) { + margin.SetUnit(marginUnitEnum); + } style.margin = margin; } - if ((hasValue >> 1) & 1) { // strokeWidth - CalcDimension strokeWidth; - strokeWidth.SetValue(valueStrokeWidth); + if ((hasValue >> 1) & 1) { // 1: strokeWidth + CalcDimension strokeWidth = CalcDimension(valueStrokeWidth, DimensionUnit::FP); + if (widthUnitEnum >= OHOS::Ace::DimensionUnit::PX && widthUnitEnum <= OHOS::Ace::DimensionUnit::CALC && + widthUnitEnum != OHOS::Ace::DimensionUnit::PERCENT) { + strokeWidth.SetUnit(widthUnitEnum); + } style.strokeWidth = strokeWidth; } - if ((hasValue >> 0) & 1) { // strokeColor + if ((hasValue >> 0) & 1) { // 0: strokeColor Color strokeColor(valueColor); style.strokeColor = strokeColor; } diff --git a/interfaces/native/native_node.h b/interfaces/native/native_node.h index 18987c4c19d..cbd1741b73b 100644 --- a/interfaces/native/native_node.h +++ b/interfaces/native/native_node.h @@ -1647,7 +1647,21 @@ typedef enum { * */ NODE_UNIQUE_ID = 95, - + + /** + * @brief Set the current component system focus box style. + * + * Format of the {@link ArkUI_AttributeItem} parameter for setting the attribute: \n + * .value[0].f32: The distance between the focus box and the edge of the component. \n + * Positive numbers represent the outer side, negative numbers represent the inner side. \n + * Percentage is not supported. \n + * .value[1].f32: Focus box width. Negative numbers and percentages are not supported. \n + * .value[2].u32: Focus box color. \n + * \n + * + */ + NODE_FOCUS_BOX = 96, + /** * @brief Defines the text content attribute, which can be set, reset, and obtained as required through APIs. * diff --git a/interfaces/native/node/style_modifier.cpp b/interfaces/native/node/style_modifier.cpp index a2bf476d714..10f70ceeab8 100644 --- a/interfaces/native/node/style_modifier.cpp +++ b/interfaces/native/node/style_modifier.cpp @@ -3718,6 +3718,24 @@ int32_t SetTransition(ArkUI_NodeHandle node, const ArkUI_AttributeItem* item) return ERROR_CODE_NO_ERROR; } +int32_t SetFocusBox(ArkUI_NodeHandle node, const ArkUI_AttributeItem* item) +{ + if (item->size != NUM_3) { + return ERROR_CODE_PARAM_INVALID; + } + auto* fullImpl = GetFullImpl(); + int32_t unit = GetDefaultUnit(node, UNIT_FP); + fullImpl->getNodeModifiers()->getCommonModifier()->setFocusBoxStyle( + node->uiNodeHandle, item->value[0].f32, unit, item->value[1].f32, unit, item->value[2].u32, NUM_7); + return ERROR_CODE_NO_ERROR; +} + +void ResetFocusBox(ArkUI_NodeHandle node) +{ + auto* fullImpl = GetFullImpl(); + fullImpl->getNodeModifiers()->getCommonModifier()->resetFocusBoxStyle(node->uiNodeHandle); +} + const ArkUI_AttributeItem* GetTransition(ArkUI_NodeHandle node) { g_attributeItem.object = node->transitionOption; @@ -12605,6 +12623,7 @@ int32_t SetCommonAttribute(ArkUI_NodeHandle node, int32_t subTypeId, const ArkUI SetAreaChangeRatio, SetTransition, nullptr, + SetFocusBox, }; if (static_cast(subTypeId) >= sizeof(setters) / sizeof(Setter*)) { TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "common node attribute: %{public}d NOT IMPLEMENT", subTypeId); @@ -12823,6 +12842,7 @@ void ResetCommonAttribute(ArkUI_NodeHandle node, int32_t subTypeId) ResetAreaChangeRatio, nullptr, nullptr, + ResetFocusBox, }; if (static_cast(subTypeId) >= sizeof(resetters) / sizeof(Resetter*)) { TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "common node attribute: %{public}d NOT IMPLEMENT", subTypeId);