diff --git a/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp b/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp index e1225ffe5469dd81a63bee5312a07a72e3c924da..a0c8edfd56662357189220fa01c6754ffb3bd60b 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp @@ -492,38 +492,10 @@ void ParseLocationPropsEdgesResObj(EdgesParam& edges, const RefPtr& resObj, EdgesParam& edges) { - CalcDimension result; - ResourceParseUtils::ParseResDimensionVpNG(resObj, result); - edges.SetTop(result); - }; - edges.AddResource("edges.top", topResObj, std::move(updateFunc)); - } - if (leftResObj) { - auto&& updateFunc = [](const RefPtr& resObj, EdgesParam& edges) { - CalcDimension result; - ResourceParseUtils::ParseResDimensionVpNG(resObj, result); - edges.SetLeft(result); - }; - edges.AddResource("edges.left", leftResObj, std::move(updateFunc)); - } - if (bottomResObj) { - auto&& updateFunc = [](const RefPtr& resObj, EdgesParam& edges) { - CalcDimension result; - ResourceParseUtils::ParseResDimensionVpNG(resObj, result); - edges.SetBottom(result); - }; - edges.AddResource("edges.bottom", bottomResObj, std::move(updateFunc)); - } - if (rightResObj) { - auto&& updateFunc = [](const RefPtr& resObj, EdgesParam& edges) { - CalcDimension result; - ResourceParseUtils::ParseResDimensionVpNG(resObj, result); - edges.SetRight(result); - }; - edges.AddResource("edges.right", rightResObj, std::move(updateFunc)); - } + NG::ViewAbstractModelNG::RegisterLocationPropsEdgesResObj("edges.top", edges, topResObj); + NG::ViewAbstractModelNG::RegisterLocationPropsEdgesResObj("edges.left", edges, leftResObj); + NG::ViewAbstractModelNG::RegisterLocationPropsEdgesResObj("edges.bottom", edges, bottomResObj); + NG::ViewAbstractModelNG::RegisterLocationPropsEdgesResObj("edges.right", edges, rightResObj); } void ParseAllBorderRadiusesResObj(NG::BorderRadiusProperty& borderRadius, const RefPtr& topLeftResObj, @@ -534,38 +506,10 @@ void ParseAllBorderRadiusesResObj(NG::BorderRadiusProperty& borderRadius, const return; } borderRadius.resMap_.clear(); - if (topLeftResObj) { - auto&& updateFunc = [](const RefPtr& resObj, NG::BorderRadiusProperty& borderRadius) { - CalcDimension result; - ResourceParseUtils::ParseResDimensionVp(resObj, result); - borderRadius.radiusTopLeft = result; - }; - borderRadius.AddResource("borderRadius.topLeft", topLeftResObj, std::move(updateFunc)); - } - if (topRightResObj) { - auto&& updateFunc = [](const RefPtr& resObj, NG::BorderRadiusProperty& borderRadius) { - CalcDimension result; - ResourceParseUtils::ParseResDimensionVp(resObj, result); - borderRadius.radiusTopRight = result; - }; - borderRadius.AddResource("borderRadius.topRight", topRightResObj, std::move(updateFunc)); - } - if (bottomLeftResObj) { - auto&& updateFunc = [](const RefPtr& resObj, NG::BorderRadiusProperty& borderRadius) { - CalcDimension result; - ResourceParseUtils::ParseResDimensionVp(resObj, result); - borderRadius.radiusBottomLeft = result; - }; - borderRadius.AddResource("borderRadius.bottomLeft", bottomLeftResObj, std::move(updateFunc)); - } - if (bottomRightResObj) { - auto&& updateFunc = [](const RefPtr& resObj, NG::BorderRadiusProperty& borderRadius) { - CalcDimension result; - ResourceParseUtils::ParseResDimensionVp(resObj, result); - borderRadius.radiusBottomRight = result; - }; - borderRadius.AddResource("borderRadius.bottomRight", bottomRightResObj, std::move(updateFunc)); - } + NG::ViewAbstractModelNG::RegisterRadiusesResObj("borderRadius.topLeft", borderRadius, topLeftResObj); + NG::ViewAbstractModelNG::RegisterRadiusesResObj("borderRadius.topRight", borderRadius, topRightResObj); + NG::ViewAbstractModelNG::RegisterRadiusesResObj("borderRadius.bottomLeft", borderRadius, bottomLeftResObj); + NG::ViewAbstractModelNG::RegisterRadiusesResObj("borderRadius.bottomRight", borderRadius, bottomRightResObj); } bool ParseLocationPropsEdges(const JSRef& edgesObj, EdgesParam& edges) @@ -1221,42 +1165,10 @@ void ParseEdgeWidthsResObjFunc(NG::BorderWidthProperty& borderWidth, RefPtr& resObj, NG::BorderWidthProperty& borderWidth) { - CalcDimension result; - ResourceParseUtils::ParseResDimensionVp(resObj, result); - borderWidth.leftDimen = result; - borderWidth.multiValued = true; - }; - borderWidth.AddResource("borderWidth.left", leftResObj, std::move(updateFunc)); - } - if (rightResObj) { - auto&& updateFunc = [](const RefPtr& resObj, NG::BorderWidthProperty& borderWidth) { - CalcDimension result; - ResourceParseUtils::ParseResDimensionVp(resObj, result); - borderWidth.rightDimen = result; - borderWidth.multiValued = true; - }; - borderWidth.AddResource("borderWidth.right", rightResObj, std::move(updateFunc)); - } - if (topResObj) { - auto&& updateFunc = [](const RefPtr& resObj, NG::BorderWidthProperty& borderWidth) { - CalcDimension result; - ResourceParseUtils::ParseResDimensionVp(resObj, result); - borderWidth.topDimen = result; - borderWidth.multiValued = true; - }; - borderWidth.AddResource("borderWidth.top", topResObj, std::move(updateFunc)); - } - if (bottomResObj) { - auto&& updateFunc = [](const RefPtr& resObj, NG::BorderWidthProperty& borderWidth) { - CalcDimension result; - ResourceParseUtils::ParseResDimensionVp(resObj, result); - borderWidth.bottomDimen = result; - borderWidth.multiValued = true; - }; - borderWidth.AddResource("borderWidth.bottom", bottomResObj, std::move(updateFunc)); - } + NG::ViewAbstractModelNG::RegisterEdgesWidthResObj("borderWidth.left", borderWidth, leftResObj); + NG::ViewAbstractModelNG::RegisterEdgesWidthResObj("borderWidth.right", borderWidth, rightResObj); + NG::ViewAbstractModelNG::RegisterEdgesWidthResObj("borderWidth.top", borderWidth, topResObj); + NG::ViewAbstractModelNG::RegisterEdgesWidthResObj("borderWidth.bottom", borderWidth, bottomResObj); } void ParseEdgeWidthsForDashParamsResObj(NG::BorderWidthProperty& borderWidth, RefPtr topResObj, @@ -1590,14 +1502,6 @@ std::function ParseTransitionCallback(const JSRef& jsFunc, c return finishCallback; } -NG::CalcLength ConvertCalcLength(CalcDimension& target) -{ - NG::CalcLength targetLength = (target.Unit() == DimensionUnit::CALC) ? - NG::CalcLength(target.IsNonNegative() ? target.CalcValue() : CalcDimension().CalcValue()) : - NG::CalcLength(target.IsNonNegative() ? target : CalcDimension()); - return targetLength; -} - void SetConstraintSize(const RefPtr& minWidthResObj, const RefPtr& maxWidthResObj, const RefPtr& minHeightResObj, const RefPtr& maxHeightResObj) { @@ -4253,50 +4157,18 @@ void JSViewAbstract::GetEdgeMarginsResObj(NG::MarginProperty& margins, const Com return; } margins.resMap_.clear(); - if (commonCalcDimension.topResObj) { - auto&& updateFunc = [](const RefPtr& resObj, NG::MarginProperty& margins) { - CalcDimension result; - ResourceParseUtils::ParseResDimensionVpNG(resObj, result); - NG::CalcLength resultLength; - resultLength = (result.Unit() == DimensionUnit::CALC) ? NG::CalcLength(result.CalcValue()) : - NG::CalcLength(result); - margins.top = resultLength; - }; - margins.AddResource("margin.top", commonCalcDimension.topResObj, std::move(updateFunc)); - } - if (commonCalcDimension.bottomResObj) { - auto&& updateFunc = [](const RefPtr& resObj, NG::MarginProperty& margins) { - CalcDimension result; - ResourceParseUtils::ParseResDimensionVpNG(resObj, result); - NG::CalcLength resultLength; - resultLength = (result.Unit() == DimensionUnit::CALC) ? NG::CalcLength(result.CalcValue()) : - NG::CalcLength(result); - margins.bottom = resultLength; - }; - margins.AddResource("margin.bottom", commonCalcDimension.bottomResObj, std::move(updateFunc)); - } - if (commonCalcDimension.leftResObj) { - auto&& updateFunc = [](const RefPtr& resObj, NG::MarginProperty& margins) { - CalcDimension result; - ResourceParseUtils::ParseResDimensionVpNG(resObj, result); - NG::CalcLength resultLength; - resultLength = (result.Unit() == DimensionUnit::CALC) ? NG::CalcLength(result.CalcValue()) : - NG::CalcLength(result); - margins.left = resultLength; - }; - margins.AddResource("margin.left", commonCalcDimension.leftResObj, std::move(updateFunc)); - } - if (commonCalcDimension.rightResObj) { - auto&& updateFunc = [](const RefPtr& resObj, NG::MarginProperty& margins) { - CalcDimension result; - ResourceParseUtils::ParseResDimensionVpNG(resObj, result); - NG::CalcLength resultLength; - resultLength = (result.Unit() == DimensionUnit::CALC) ? NG::CalcLength(result.CalcValue()) : - NG::CalcLength(result); - margins.right = resultLength; - }; - margins.AddResource("margin.right", commonCalcDimension.rightResObj, std::move(updateFunc)); - } + NG::ViewAbstractModelNG::RegisterEdgeMarginsResObj("margin.top", margins, commonCalcDimension.topResObj); + NG::ViewAbstractModelNG::RegisterEdgeMarginsResObj("margin.bottom", margins, commonCalcDimension.bottomResObj); + NG::ViewAbstractModelNG::RegisterEdgeMarginsResObj("margin.left", margins, commonCalcDimension.leftResObj); + NG::ViewAbstractModelNG::RegisterEdgeMarginsResObj("margin.right", margins, commonCalcDimension.rightResObj); +} + +NG::CalcLength ConvertCalcLength(CalcDimension& target) +{ + NG::CalcLength targetLength = (target.Unit() == DimensionUnit::CALC) ? + NG::CalcLength(target.IsNonNegative() ? target.CalcValue() : CalcDimension().CalcValue()) : + NG::CalcLength(target.IsNonNegative() ? target : CalcDimension()); + return targetLength; } NG::PaddingProperty JSViewAbstract::GetEdgePaddingsOrSafeAreaPaddings(const CommonCalcDimension& commonCalcDimension) @@ -5312,38 +5184,11 @@ NG::BorderColorProperty JSViewAbstract::GetLocalizedBorderColor(const CommonColo if (!SystemProperties::ConfigChangePerform()) { return borderColors; } - if (commonColor.leftResObj) { - auto&& updateFunc = [](const RefPtr& resObj, NG::BorderColorProperty& borderColors) { - Color result; - ResourceParseUtils::ParseResColor(resObj, result); - borderColors.startColor = result; - }; - borderColors.AddResource("borderColor.start", commonColor.leftResObj, std::move(updateFunc)); - } - if (commonColor.rightResObj) { - auto&& updateFunc = [](const RefPtr& resObj, NG::BorderColorProperty& borderColors) { - Color result; - ResourceParseUtils::ParseResColor(resObj, result); - borderColors.endColor = result; - }; - borderColors.AddResource("borderColor.end", commonColor.rightResObj, std::move(updateFunc)); - } - if (commonColor.topResObj) { - auto&& updateFunc = [](const RefPtr& resObj, NG::BorderColorProperty& borderColors) { - Color result; - ResourceParseUtils::ParseResColor(resObj, result); - borderColors.topColor = result; - }; - borderColors.AddResource("borderColor.top", commonColor.topResObj, std::move(updateFunc)); - } - if (commonColor.bottomResObj) { - auto&& updateFunc = [](const RefPtr& resObj, NG::BorderColorProperty& borderColors) { - Color result; - ResourceParseUtils::ParseResColor(resObj, result); - borderColors.bottomColor = result; - }; - borderColors.AddResource("borderColor.bottom", commonColor.bottomResObj, std::move(updateFunc)); - } + NG::ViewAbstractModelNG::RegisterLocalizedBorderColor("borderColor.start", borderColors, commonColor.leftResObj); + NG::ViewAbstractModelNG::RegisterLocalizedBorderColor("borderColor.end", borderColors, commonColor.rightResObj); + NG::ViewAbstractModelNG::RegisterLocalizedBorderColor("borderColor.top", borderColors, commonColor.topResObj); + NG::ViewAbstractModelNG::RegisterLocalizedBorderColor( + "borderColor.bottom", borderColors, commonColor.bottomResObj); borderColors.multiValued = true; return borderColors; } diff --git a/frameworks/core/components_ng/base/view_abstract_model_ng.cpp b/frameworks/core/components_ng/base/view_abstract_model_ng.cpp index 3b48fc6a96adae4f2c5be9a2fd1ddc6d4d32b768..797f0599b4677263274f210192c938619101da3b 100644 --- a/frameworks/core/components_ng/base/view_abstract_model_ng.cpp +++ b/frameworks/core/components_ng/base/view_abstract_model_ng.cpp @@ -1535,6 +1535,120 @@ void ViewAbstractModelNG::ParseOptionsDimension(const RefPtr& fra return; } +void ViewAbstractModelNG::RegisterRadiusesResObj( + const std::string& key, NG::BorderRadiusProperty& borderRadius, const RefPtr& resObj) +{ + if (!resObj) { + return; + } + auto updateFunc = [key](const RefPtr& resObj, NG::BorderRadiusProperty& borderRadius) { + CalcDimension result; + ResourceParseUtils::ParseResDimensionVp(resObj, result); + if (key == "borderRadius.topLeft") { + borderRadius.radiusTopLeft = result; + } else if (key == "borderRadius.topRight") { + borderRadius.radiusTopRight = result; + } else if (key == "borderRadius.bottomLeft") { + borderRadius.radiusBottomLeft = result; + } else if (key == "borderRadius.bottomRight") { + borderRadius.radiusBottomRight = result; + } + }; + borderRadius.AddResource(key, resObj, std::move(updateFunc)); +} + +void ViewAbstractModelNG::RegisterLocationPropsEdgesResObj( + const std::string& key, EdgesParam& edges, const RefPtr& resObj) +{ + if (!resObj) { + return; + } + auto updateFunc = [key](const RefPtr& resObj, EdgesParam& edges) { + CalcDimension result; + ResourceParseUtils::ParseResDimensionVpNG(resObj, result); + if (key == "edges.top") { + edges.SetTop(result); + } else if (key == "edges.left") { + edges.SetLeft(result); + } else if (key == "edges.bottom") { + edges.SetBottom(result); + } else if (key == "edges.right") { + edges.SetRight(result); + } + }; + edges.AddResource(key, resObj, std::move(updateFunc)); +} + +void ViewAbstractModelNG::RegisterEdgesWidthResObj( + const std::string& key, NG::BorderWidthProperty& borderWidth, const RefPtr& resObj) +{ + if (!resObj) { + return; + } + auto updateFunc = [key](const RefPtr& resObj, NG::BorderWidthProperty& borderWidth) { + CalcDimension result; + ResourceParseUtils::ParseResDimensionVp(resObj, result); + if (key == "borderWidth.left") { + borderWidth.leftDimen = result; + } else if (key == "borderWidth.right") { + borderWidth.rightDimen = result; + } else if (key == "borderWidth.top") { + borderWidth.topDimen = result; + } else if (key == "borderWidth.bottom") { + borderWidth.bottomDimen = result; + } + borderWidth.multiValued = true; + }; + borderWidth.AddResource(key, resObj, std::move(updateFunc)); +} + +void ViewAbstractModelNG::RegisterEdgeMarginsResObj( + const std::string& key, NG::MarginProperty& margins, const RefPtr& resObj) +{ + if (!resObj) { + return; + } + auto updateFunc = [key](const RefPtr& resObj, NG::MarginProperty& margins) { + CalcDimension result; + ResourceParseUtils::ParseResDimensionVpNG(resObj, result); + NG::CalcLength resultLength; + resultLength = + (result.Unit() == DimensionUnit::CALC) ? NG::CalcLength(result.CalcValue()) : NG::CalcLength(result); + if (key == "margin.top") { + margins.top = resultLength; + } else if (key == "margin.bottom") { + margins.bottom = resultLength; + } else if (key == "margin.left") { + margins.left = resultLength; + } else if (key == "margin.right") { + margins.right = resultLength; + } + }; + margins.AddResource(key, resObj, std::move(updateFunc)); +} + +void ViewAbstractModelNG::RegisterLocalizedBorderColor( + const std::string& key, NG::BorderColorProperty& borderColors, const RefPtr& resObj) +{ + if (!resObj) { + return; + } + auto updateFunc = [key](const RefPtr& resObj, NG::BorderColorProperty& borderColors) { + Color result; + ResourceParseUtils::ParseResColor(resObj, result); + if (key == "borderColor.start") { + borderColors.startColor = result; + } else if (key == "borderColor.end") { + borderColors.endColor = result; + } else if (key == "borderColor.top") { + borderColors.topColor = result; + } else if (key == "borderColor.bottom") { + borderColors.bottomColor = result; + } + }; + borderColors.AddResource(key, resObj, std::move(updateFunc)); +} + void ViewAbstractModelNG::CreateWithDimensionResourceObj( const RefPtr& frameNode, const RefPtr& dimensionResObj, const PopupOptionsType& type) { diff --git a/frameworks/core/components_ng/base/view_abstract_model_ng.h b/frameworks/core/components_ng/base/view_abstract_model_ng.h index 73423db36e8fbc539bbc4bf099523dcee5d217c1..35b92c53179db4728dab1eeee0d837cb9952adbf 100644 --- a/frameworks/core/components_ng/base/view_abstract_model_ng.h +++ b/frameworks/core/components_ng/base/view_abstract_model_ng.h @@ -1916,6 +1916,16 @@ public: static void SetAccessibilityUseSamePage(FrameNode* frameNode, const std::string& pageMode); static void SetAccessibilityScrollTriggerable(FrameNode* frameNode, bool triggerable, bool resetValue); static void SetAccessibilityFocusDrawLevel(FrameNode* frameNode, int32_t drawLevel); + static void RegisterRadiusesResObj( + const std::string& key, NG::BorderRadiusProperty& borderRadius, const RefPtr& resObj); + static void RegisterLocationPropsEdgesResObj( + const std::string& key, EdgesParam& edges, const RefPtr& resObj); + static void RegisterEdgesWidthResObj( + const std::string& key, NG::BorderWidthProperty& borderWidth, const RefPtr& resObj); + static void RegisterEdgeMarginsResObj( + const std::string& key, NG::MarginProperty& margins, const RefPtr& resObj); + static void RegisterLocalizedBorderColor( + const std::string& key, NG::BorderColorProperty& borderColors, const RefPtr& resObj); static void SetKeyboardShortcut(FrameNode* frameNode, const std::string& value, const std::vector& keys, std::function&& onKeyboardShortcutAction) { diff --git a/frameworks/core/interfaces/native/node/node_common_modifier.cpp b/frameworks/core/interfaces/native/node/node_common_modifier.cpp index 706c39b50eaeb2d36a0c1c6ac70974cc325cc647..bd7ddd6373702b76d90576c73d67d1d79399db7b 100644 --- a/frameworks/core/interfaces/native/node/node_common_modifier.cpp +++ b/frameworks/core/interfaces/native/node/node_common_modifier.cpp @@ -1113,39 +1113,12 @@ void ParseAllBorderRadiusesResObj(NG::BorderRadiusProperty& borderRadius, const const RefPtr& bottomRightResObj) { borderRadius.resMap_.clear(); - if (topLeftResObj != nullptr) { - auto&& updateFunc = [](const RefPtr& resObj, NG::BorderRadiusProperty& borderRadius) { - CalcDimension result; - ResourceParseUtils::ParseResDimensionVp(resObj, result); - borderRadius.radiusTopLeft = result; - }; - borderRadius.AddResource("borderRadius.topLeft", topLeftResObj, std::move(updateFunc)); - } - if (topRightResObj != nullptr) { - auto&& updateFunc = [](const RefPtr& resObj, NG::BorderRadiusProperty& borderRadius) { - CalcDimension result; - ResourceParseUtils::ParseResDimensionVp(resObj, result); - borderRadius.radiusTopRight = result; - }; - borderRadius.AddResource("borderRadius.topRight", topRightResObj, std::move(updateFunc)); - } - if (bottomLeftResObj != nullptr) { - auto&& updateFunc = [](const RefPtr& resObj, NG::BorderRadiusProperty& borderRadius) { - CalcDimension result; - ResourceParseUtils::ParseResDimensionVp(resObj, result); - borderRadius.radiusBottomLeft = result; - }; - borderRadius.AddResource("borderRadius.bottomLeft", bottomLeftResObj, std::move(updateFunc)); - } - if (bottomRightResObj != nullptr) { - auto&& updateFunc = [](const RefPtr& resObj, NG::BorderRadiusProperty& borderRadius) { - CalcDimension result; - ResourceParseUtils::ParseResDimensionVp(resObj, result); - borderRadius.radiusBottomRight = result; - }; - borderRadius.AddResource("borderRadius.bottomRight", bottomRightResObj, std::move(updateFunc)); - } + ViewAbstractModelNG::RegisterRadiusesResObj("borderRadius.topLeft", borderRadius, topLeftResObj); + ViewAbstractModelNG::RegisterRadiusesResObj("borderRadius.topRight", borderRadius, topRightResObj); + ViewAbstractModelNG::RegisterRadiusesResObj("borderRadius.bottomLeft", borderRadius, bottomLeftResObj); + ViewAbstractModelNG::RegisterRadiusesResObj("borderRadius.bottomRight", borderRadius, bottomRightResObj); } + /** * @param values radius values * value[0] : radius value for TopLeft,value[1] : radius value for TopRight @@ -1189,38 +1162,10 @@ void ParseEdgeWidthsResObjFunc(NG::BorderWidthProperty& borderWidth, RefPtr rightResObj, RefPtr bottomResObj, RefPtr leftResObj) { borderWidth.resMap_.clear(); - if (leftResObj != nullptr) { - auto&& updateFunc = [](const RefPtr& resObj, NG::BorderWidthProperty& borderWidth) { - CalcDimension result; - ResourceParseUtils::ParseResDimensionVp(resObj, result); - borderWidth.leftDimen = result; - }; - borderWidth.AddResource("borderWidth.left", leftResObj, std::move(updateFunc)); - } - if (rightResObj != nullptr) { - auto&& updateFunc = [](const RefPtr& resObj, NG::BorderWidthProperty& borderWidth) { - CalcDimension result; - ResourceParseUtils::ParseResDimensionVp(resObj, result); - borderWidth.rightDimen = result; - }; - borderWidth.AddResource("borderWidth.right", rightResObj, std::move(updateFunc)); - } - if (topResObj != nullptr) { - auto&& updateFunc = [](const RefPtr& resObj, NG::BorderWidthProperty& borderWidth) { - CalcDimension result; - ResourceParseUtils::ParseResDimensionVp(resObj, result); - borderWidth.topDimen = result; - }; - borderWidth.AddResource("borderWidth.top", topResObj, std::move(updateFunc)); - } - if (bottomResObj != nullptr) { - auto&& updateFunc = [](const RefPtr& resObj, NG::BorderWidthProperty& borderWidth) { - CalcDimension result; - ResourceParseUtils::ParseResDimensionVp(resObj, result); - borderWidth.bottomDimen = result; - }; - borderWidth.AddResource("borderWidth.bottom", bottomResObj, std::move(updateFunc)); - } + ViewAbstractModelNG::RegisterEdgesWidthResObj("borderWidth.left", borderWidth, leftResObj); + ViewAbstractModelNG::RegisterEdgesWidthResObj("borderWidth.right", borderWidth, rightResObj); + ViewAbstractModelNG::RegisterEdgesWidthResObj("borderWidth.top", borderWidth, topResObj); + ViewAbstractModelNG::RegisterEdgesWidthResObj("borderWidth.bottom", borderWidth, bottomResObj); } void CheckDimensionUnit(CalcDimension& checkDimension, bool notPercent, bool notNegative) @@ -1528,38 +1473,10 @@ void ParseLocationPropsEdgesResObj(OHOS::Ace::EdgesParam& edges, RefPtr leftResObj, RefPtr bottomResObj, RefPtr rightResObj) { edges.resMap_.clear(); - if (topResObj != nullptr) { - auto&& updateFunc = [](const RefPtr& resObj, EdgesParam& edges) { - CalcDimension result; - ResourceParseUtils::ParseResDimensionVpNG(resObj, result); - edges.SetTop(result); - }; - edges.AddResource("edges.top", topResObj, std::move(updateFunc)); - } - if (leftResObj != nullptr) { - auto&& updateFunc = [](const RefPtr& resObj, EdgesParam& edges) { - CalcDimension result; - ResourceParseUtils::ParseResDimensionVpNG(resObj, result); - edges.SetLeft(result); - }; - edges.AddResource("edges.left", leftResObj, std::move(updateFunc)); - } - if (bottomResObj != nullptr) { - auto&& updateFunc = [](const RefPtr& resObj, EdgesParam& edges) { - CalcDimension result; - ResourceParseUtils::ParseResDimensionVpNG(resObj, result); - edges.SetBottom(result); - }; - edges.AddResource("edges.bottom", bottomResObj, std::move(updateFunc)); - } - if (rightResObj != nullptr) { - auto&& updateFunc = [](const RefPtr& resObj, EdgesParam& edges) { - CalcDimension result; - ResourceParseUtils::ParseResDimensionVpNG(resObj, result); - edges.SetRight(result); - }; - edges.AddResource("edges.right", rightResObj, std::move(updateFunc)); - } + ViewAbstractModelNG::RegisterLocationPropsEdgesResObj("edges.top", edges, topResObj); + ViewAbstractModelNG::RegisterLocationPropsEdgesResObj("edges.left", edges, leftResObj); + ViewAbstractModelNG::RegisterLocationPropsEdgesResObj("edges.bottom", edges, bottomResObj); + ViewAbstractModelNG::RegisterLocationPropsEdgesResObj("edges.right", edges, rightResObj); } void SetPositionEdges(ArkUINodeHandle node, const int32_t useEdges, const ArkUIStringAndFloat* options, void* rawPtr) @@ -2648,38 +2565,10 @@ void ParseLocalizedBorderColor(NG::BorderColorProperty& borderColors, RefPtr startResObj, RefPtr bottomResObj, RefPtr endResObj) { borderColors.resMap_.clear(); - if (startResObj != nullptr) { - auto&& updateFunc = [](const RefPtr& resObj, NG::BorderColorProperty& borderColors) { - Color result; - ResourceParseUtils::ParseResColor(resObj, result); - borderColors.startColor = result; - }; - borderColors.AddResource("borderColor.start", startResObj, std::move(updateFunc)); - } - if (endResObj != nullptr) { - auto&& updateFunc = [](const RefPtr& resObj, NG::BorderColorProperty& borderColors) { - Color result; - ResourceParseUtils::ParseResColor(resObj, result); - borderColors.endColor = result; - }; - borderColors.AddResource("borderColor.end", endResObj, std::move(updateFunc)); - } - if (topResObj != nullptr) { - auto&& updateFunc = [](const RefPtr& resObj, NG::BorderColorProperty& borderColors) { - Color result; - ResourceParseUtils::ParseResColor(resObj, result); - borderColors.topColor = result; - }; - borderColors.AddResource("borderColor.top", topResObj, std::move(updateFunc)); - } - if (bottomResObj != nullptr) { - auto&& updateFunc = [](const RefPtr& resObj, NG::BorderColorProperty& borderColors) { - Color result; - ResourceParseUtils::ParseResColor(resObj, result); - borderColors.bottomColor = result; - }; - borderColors.AddResource("borderColor.bottom", bottomResObj, std::move(updateFunc)); - } + ViewAbstractModelNG::RegisterLocalizedBorderColor("borderColor.start", borderColors, startResObj); + ViewAbstractModelNG::RegisterLocalizedBorderColor("borderColor.end", borderColors, endResObj); + ViewAbstractModelNG::RegisterLocalizedBorderColor("borderColor.top", borderColors, topResObj); + ViewAbstractModelNG::RegisterLocalizedBorderColor("borderColor.bottom", borderColors, bottomResObj); } /** @@ -3550,56 +3439,6 @@ void ResetOffset(ArkUINodeHandle node) ViewAbstract::SetOffset(frameNode, { xVal, yVal }); } -NG::CalcLength ConvertCalcLength(CalcDimension& target) -{ - NG::CalcLength targetLength = (target.Unit() == DimensionUnit::CALC) ? - NG::CalcLength(target.IsNonNegative() ? target.CalcValue() : CalcDimension().CalcValue()) : - NG::CalcLength(target.IsNonNegative() ? target : CalcDimension()); - return targetLength; -} - -void GetEdgePaddingsOrSafeAreaPaddings(NG::PaddingProperty& paddings, RefPtr topResObj, - RefPtr rightResObj, RefPtr bottomResObj, RefPtr leftResObj) -{ - paddings.resMap_.clear(); - if (topResObj != nullptr) { - auto&& updateFunc = [](const RefPtr& resObj, NG::PaddingProperty& paddings) { - CalcDimension result; - ResourceParseUtils::ParseResDimensionVpNG(resObj, result); - NG::CalcLength resultLength = ConvertCalcLength(result); - paddings.top = resultLength; - }; - paddings.AddResource("top", topResObj, std::move(updateFunc)); - } - if (rightResObj != nullptr) { - auto&& updateFunc = [](const RefPtr& resObj, NG::PaddingProperty& paddings) { - CalcDimension result; - ResourceParseUtils::ParseResDimensionVpNG(resObj, result); - NG::CalcLength resultLength = ConvertCalcLength(result); - paddings.right = resultLength; - }; - paddings.AddResource("right", rightResObj, std::move(updateFunc)); - } - if (bottomResObj != nullptr) { - auto&& updateFunc = [](const RefPtr& resObj, NG::PaddingProperty& paddings) { - CalcDimension result; - ResourceParseUtils::ParseResDimensionVpNG(resObj, result); - NG::CalcLength resultLength = ConvertCalcLength(result); - paddings.bottom = resultLength; - }; - paddings.AddResource("bottom", bottomResObj, std::move(updateFunc)); - } - if (leftResObj != nullptr) { - auto&& updateFunc = [](const RefPtr& resObj, NG::PaddingProperty& paddings) { - CalcDimension result; - ResourceParseUtils::ParseResDimensionVpNG(resObj, result); - NG::CalcLength resultLength = ConvertCalcLength(result); - paddings.left = resultLength; - }; - paddings.AddResource("left", leftResObj, std::move(updateFunc)); - } -} - void SetPadding(ArkUINodeHandle node, const struct ArkUISizeType* top, const struct ArkUISizeType* right, const struct ArkUISizeType* bottom, const struct ArkUISizeType* left, void* rawPtr) { @@ -3637,7 +3476,10 @@ void SetPadding(ArkUINodeHandle node, const struct ArkUISizeType* top, const str paddings.right = std::optional(rightDimen); if (SystemProperties::ConfigChangePerform() && rawPtr) { auto objs = *(reinterpret_cast>*>(rawPtr)); - GetEdgePaddingsOrSafeAreaPaddings(paddings, objs[NUM_0], objs[NUM_1], objs[NUM_2], objs[NUM_3]); + ViewAbstractModelNG::RegisterEdgeMarginsResObj("margin.top", paddings, objs[NUM_0]); + ViewAbstractModelNG::RegisterEdgeMarginsResObj("margin.right", paddings, objs[NUM_1]); + ViewAbstractModelNG::RegisterEdgeMarginsResObj("margin.bottom", paddings, objs[NUM_2]); + ViewAbstractModelNG::RegisterEdgeMarginsResObj("margin.left", paddings, objs[NUM_3]); } ViewAbstract::SetPadding(frameNode, paddings); } @@ -3698,7 +3540,10 @@ void SetSafeAreaPadding( } if (SystemProperties::ConfigChangePerform() && rawPtr) { auto objs = *(reinterpret_cast>*>(rawPtr)); - GetEdgePaddingsOrSafeAreaPaddings(paddings, objs[NUM_0], objs[NUM_1], objs[NUM_2], objs[NUM_3]); + ViewAbstractModelNG::RegisterEdgeMarginsResObj("margin.top", paddings, objs[NUM_0]); + ViewAbstractModelNG::RegisterEdgeMarginsResObj("margin.right", paddings, objs[NUM_1]); + ViewAbstractModelNG::RegisterEdgeMarginsResObj("margin.bottom", paddings, objs[NUM_2]); + ViewAbstractModelNG::RegisterEdgeMarginsResObj("margin.left", paddings, objs[NUM_3]); } ViewAbstract::SetSafeAreaPadding(frameNode, paddings); } @@ -4132,7 +3977,10 @@ void SetMargin(ArkUINodeHandle node, const struct ArkUISizeType* top, const stru paddings.right = std::optional(rightDimen); if (SystemProperties::ConfigChangePerform() && rawPtr) { auto objs = *(reinterpret_cast>*>(rawPtr)); - GetEdgePaddingsOrSafeAreaPaddings(paddings, objs[NUM_0], objs[NUM_1], objs[NUM_2], objs[NUM_3]); + ViewAbstractModelNG::RegisterEdgeMarginsResObj("margin.top", paddings, objs[NUM_0]); + ViewAbstractModelNG::RegisterEdgeMarginsResObj("margin.bottom", paddings, objs[NUM_2]); + ViewAbstractModelNG::RegisterEdgeMarginsResObj("margin.left", paddings, objs[NUM_3]); + ViewAbstractModelNG::RegisterEdgeMarginsResObj("margin.right", paddings, objs[NUM_1]); } ViewAbstract::SetMargin(frameNode, paddings); } diff --git a/test/unittest/core/base/view_abstract_test_ng_new.cpp b/test/unittest/core/base/view_abstract_test_ng_new.cpp index a4c6ed5826ff3f899fcfd0dcea3c7f43c20f5a59..b6a8f6d2b12cf466f0af0cb43b6eef2d5039b95f 100644 --- a/test/unittest/core/base/view_abstract_test_ng_new.cpp +++ b/test/unittest/core/base/view_abstract_test_ng_new.cpp @@ -2189,4 +2189,139 @@ HWTEST_F(ViewAbstractTestNg, CheckPositionOrOffsetLocalizedEdges002, TestSize.Le EXPECT_FALSE(edges.left.has_value()); EXPECT_FALSE(edges.right.has_value()); } + +/** + * @tc.name: RegisterRadiusesResObj + * @tc.desc: Test RegisterRadiusesResObj + * @tc.type: FUNC + */ +HWTEST_F(ViewAbstractTestNg, RegisterRadiusesResObj, TestSize.Level1) +{ + std::string bundleName = "com.example.test"; + std::string moduleName = "entry"; + RefPtr resObj = AceType::MakeRefPtr(bundleName, moduleName, 0); + NG::BorderRadiusProperty borderRadius; + ViewAbstractModelNG::RegisterRadiusesResObj("borderRadius.topLeft", borderRadius, resObj); + borderRadius.ReloadResources(); + EXPECT_EQ(borderRadius.resMap_.size(), 1); + ViewAbstractModelNG::RegisterRadiusesResObj("borderRadius.topRight", borderRadius, resObj); + borderRadius.ReloadResources(); + EXPECT_EQ(borderRadius.resMap_.size(), 2); + ViewAbstractModelNG::RegisterRadiusesResObj("borderRadius.bottomLeft", borderRadius, resObj); + borderRadius.ReloadResources(); + EXPECT_EQ(borderRadius.resMap_.size(), 3); + ViewAbstractModelNG::RegisterRadiusesResObj("borderRadius.bottomRight", borderRadius, resObj); + borderRadius.ReloadResources(); + EXPECT_EQ(borderRadius.resMap_.size(), 4); + ViewAbstractModelNG::RegisterRadiusesResObj("", borderRadius, nullptr); + EXPECT_EQ(borderRadius.resMap_.size(), 4); +} + +/** + * @tc.name: RegisterLocationPropsEdgesResObj + * @tc.desc: Test RegisterLocationPropsEdgesResObj + * @tc.type: FUNC + */ +HWTEST_F(ViewAbstractTestNg, RegisterLocationPropsEdgesResObj, TestSize.Level1) +{ + std::string bundleName = "com.example.test"; + std::string moduleName = "entry"; + RefPtr resObj = AceType::MakeRefPtr(bundleName, moduleName, 0); + EdgesParam edges; + ViewAbstractModelNG::RegisterLocationPropsEdgesResObj("edges.top", edges, resObj); + edges.ReloadResources(); + EXPECT_EQ(edges.resMap_.size(), 1); + ViewAbstractModelNG::RegisterLocationPropsEdgesResObj("edges.left", edges, resObj); + edges.ReloadResources(); + EXPECT_EQ(edges.resMap_.size(), 2); + ViewAbstractModelNG::RegisterLocationPropsEdgesResObj("edges.bottom", edges, resObj); + edges.ReloadResources(); + EXPECT_EQ(edges.resMap_.size(), 3); + ViewAbstractModelNG::RegisterLocationPropsEdgesResObj("edges.right", edges, resObj); + edges.ReloadResources(); + EXPECT_EQ(edges.resMap_.size(), 4); + ViewAbstractModelNG::RegisterLocationPropsEdgesResObj("", edges, nullptr); + EXPECT_EQ(edges.resMap_.size(), 4); +} + +/** + * @tc.name: RegisterEdgesWidthResObj + * @tc.desc: Test RegisterEdgesWidthResObj + * @tc.type: FUNC + */ +HWTEST_F(ViewAbstractTestNg, RegisterEdgesWidthResObj, TestSize.Level1) +{ + std::string bundleName = "com.example.test"; + std::string moduleName = "entry"; + RefPtr resObj = AceType::MakeRefPtr(bundleName, moduleName, 0); + NG::BorderWidthProperty borderWidth; + ViewAbstractModelNG::RegisterEdgesWidthResObj("borderWidth.top", borderWidth, resObj); + borderWidth.ReloadResources(); + EXPECT_EQ(borderWidth.resMap_.size(), 1); + ViewAbstractModelNG::RegisterEdgesWidthResObj("borderWidth.left", borderWidth, resObj); + borderWidth.ReloadResources(); + EXPECT_EQ(borderWidth.resMap_.size(), 2); + ViewAbstractModelNG::RegisterEdgesWidthResObj("borderWidth.bottom", borderWidth, resObj); + borderWidth.ReloadResources(); + EXPECT_EQ(borderWidth.resMap_.size(), 3); + ViewAbstractModelNG::RegisterEdgesWidthResObj("borderWidth.right", borderWidth, resObj); + borderWidth.ReloadResources(); + EXPECT_EQ(borderWidth.resMap_.size(), 4); + ViewAbstractModelNG::RegisterEdgesWidthResObj("", borderWidth, nullptr); + EXPECT_EQ(borderWidth.resMap_.size(), 4); +} + +/** + * @tc.name: RegisterEdgeMarginsResObj + * @tc.desc: Test RegisterEdgeMarginsResObj + * @tc.type: FUNC + */ +HWTEST_F(ViewAbstractTestNg, RegisterEdgeMarginsResObj, TestSize.Level1) +{ + std::string bundleName = "com.example.test"; + std::string moduleName = "entry"; + RefPtr resObj = AceType::MakeRefPtr(bundleName, moduleName, 0); + NG::MarginProperty margins; + ViewAbstractModelNG::RegisterEdgeMarginsResObj("margin.top", margins, resObj); + margins.ReloadResources(); + EXPECT_EQ(margins.resMap_.size(), 1); + ViewAbstractModelNG::RegisterEdgeMarginsResObj("margin.left", margins, resObj); + margins.ReloadResources(); + EXPECT_EQ(margins.resMap_.size(), 2); + ViewAbstractModelNG::RegisterEdgeMarginsResObj("margin.bottom", margins, resObj); + margins.ReloadResources(); + EXPECT_EQ(margins.resMap_.size(), 3); + ViewAbstractModelNG::RegisterEdgeMarginsResObj("margin.right", margins, resObj); + margins.ReloadResources(); + EXPECT_EQ(margins.resMap_.size(), 4); + ViewAbstractModelNG::RegisterEdgeMarginsResObj("", margins, nullptr); + EXPECT_EQ(margins.resMap_.size(), 4); +} + +/** + * @tc.name: RegisterLocalizedBorderColor + * @tc.desc: Test RegisterLocalizedBorderColor + * @tc.type: FUNC + */ +HWTEST_F(ViewAbstractTestNg, RegisterLocalizedBorderColor, TestSize.Level1) +{ + std::string bundleName = "com.example.test"; + std::string moduleName = "entry"; + RefPtr resObj = AceType::MakeRefPtr(bundleName, moduleName, 0); + NG::BorderColorProperty borderColors; + ViewAbstractModelNG::RegisterLocalizedBorderColor("borderColor.top", borderColors, resObj); + borderColors.ReloadResources(); + EXPECT_EQ(borderColors.resMap_.size(), 1); + ViewAbstractModelNG::RegisterLocalizedBorderColor("borderColor.start", borderColors, resObj); + borderColors.ReloadResources(); + EXPECT_EQ(borderColors.resMap_.size(), 2); + ViewAbstractModelNG::RegisterLocalizedBorderColor("borderColor.bottom", borderColors, resObj); + borderColors.ReloadResources(); + EXPECT_EQ(borderColors.resMap_.size(), 3); + ViewAbstractModelNG::RegisterLocalizedBorderColor("borderColor.end", borderColors, resObj); + borderColors.ReloadResources(); + EXPECT_EQ(borderColors.resMap_.size(), 4); + ViewAbstractModelNG::RegisterLocalizedBorderColor("", borderColors, nullptr); + EXPECT_EQ(borderColors.resMap_.size(), 4); +} } // namespace OHOS::Ace::NG \ No newline at end of file