From 22596c102a29dd97958dc349250542820bbf2f7b Mon Sep 17 00:00:00 2001 From: huangxiaoxiao Date: Fri, 25 Jul 2025 19:15:46 +0800 Subject: [PATCH] tetxpicker api support color invert. Signed-off-by: huangxiaoxiao --- .../arkts_native_textpicker_bridge.cpp | 100 ++++--- .../jsview/js_textpicker.cpp | 7 +- .../pattern/picker/picker_type_define.h | 3 + .../text_picker/textpicker_model_ng.cpp | 138 ++++++--- .../pattern/text_picker/textpicker_model_ng.h | 2 + .../text_picker/textpicker_pattern.cpp | 52 ++-- .../pattern/text_picker/textpicker_pattern.h | 4 +- .../core/interfaces/arkoala/arkoala_api.h | 15 + .../native/node/node_textpicker_modifier.cpp | 107 ++++++- .../text_picker/text_picker_resource_test.cpp | 267 ++++++++++++++++++ 10 files changed, 573 insertions(+), 122 deletions(-) diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_textpicker_bridge.cpp b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_textpicker_bridge.cpp index 6210141a525..5e43eff9656 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_textpicker_bridge.cpp +++ b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_textpicker_bridge.cpp @@ -151,6 +151,48 @@ Color ParseTextColor(const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, in return textColor; } +void ParseSelectedBackgroundStyleRadius(const EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUI_Bool* isHasValue, + ArkUIPickerBackgroundStyleStruct& backgroundStyleStruct, RefPtr* radiusResObjs) +{ + ArkUI_Float32 value[VALUE_MAX_SIZE] = { + DEFAULT_TEXT_PICKER_SELECTED_BACKGROUND_BORDER_RADIUS, DEFAULT_TEXT_PICKER_SELECTED_BACKGROUND_BORDER_RADIUS, + DEFAULT_TEXT_PICKER_SELECTED_BACKGROUND_BORDER_RADIUS, DEFAULT_TEXT_PICKER_SELECTED_BACKGROUND_BORDER_RADIUS}; + ArkUI_Int32 unit[VALUE_MAX_SIZE] = {UNIT_VP, UNIT_VP, UNIT_VP, UNIT_VP}; + auto isRightToLeft = AceApplicationInfo::GetInstance().IsRightToLeft(); + CalcDimension calcDimension; + RefPtr tmpResObj; + for (int i = 0; i < VALUE_MAX_SIZE; i++) { + if (ArkTSUtils::ParseJsLengthMetrics(vm, runtimeCallInfo->GetCallArgRef(i + NUM_2), calcDimension, tmpResObj) && + !calcDimension.IsNegative()) { + isHasValue[i + COLOR_ARG_INDEX] = true; + value[i] = calcDimension.Value(); + unit[i] = static_cast(calcDimension.Unit()); + radiusResObjs[i] = tmpResObj; + } + if (ArkTSUtils::ParseJsDimensionVp(vm, runtimeCallInfo->GetCallArgRef(i + NUM_2), calcDimension, tmpResObj) && + !calcDimension.IsNegative()) { + isHasValue[i + COLOR_ARG_INDEX] = true; + value[i] = calcDimension.Value(); + unit[i] = static_cast(calcDimension.Unit()); + radiusResObjs[i] = tmpResObj; + } + } + if (isRightToLeft && (value[TOPLEFT] != value[BOTTOMLEFT] || value[TOPRIGHT] != value[BOTTOMRIGHT]) && + (unit[TOPLEFT] != unit[BOTTOMLEFT] || unit[TOPRIGHT] != unit[BOTTOMRIGHT])) { + std::swap(value[TOPLEFT], value[BOTTOMLEFT]); + std::swap(value[TOPRIGHT], value[BOTTOMRIGHT]); + std::swap(unit[TOPLEFT], unit[BOTTOMLEFT]); + std::swap(unit[TOPRIGHT], unit[BOTTOMRIGHT]); + std::swap(isHasValue[GETTOPLEFT], isHasValue[GETTOPRIGHT]); + std::swap(isHasValue[GETBOTTOMLEFT], isHasValue[GETBOTTOMRIGHT]); + std::swap(radiusResObjs[TOPLEFT], radiusResObjs[BOTTOMLEFT]); + std::swap(radiusResObjs[TOPRIGHT], radiusResObjs[BOTTOMRIGHT]); + } + backgroundStyleStruct.values = value; + backgroundStyleStruct.units = unit; + backgroundStyleStruct.length = VALUE_MAX_SIZE; +} + } // namespace ArkUINativeModuleValue TextPickerBridge::SetBackgroundColor(ArkUIRuntimeCallInfo* runtimeCallInfo) @@ -741,52 +783,36 @@ ArkUINativeModuleValue TextPickerBridge::SetTextPickerSelectedBackgroundStyle(Ar { EcmaVM* vm = runtimeCallInfo->GetVM(); CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr)); - Local nodeArg = runtimeCallInfo->GetCallArgRef(0); // framenode + Local nodeArg = runtimeCallInfo->GetCallArgRef(0); // frameNode Local colorArg = runtimeCallInfo->GetCallArgRef(1); // background color auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value()); CHECK_NULL_RETURN(nativeNode, panda::NativePointerRef::New(vm, nullptr)); - ArkUI_Bool getValue[GETVALUE_MAX_SIZE] = {false, false, false, false, false}; - ArkUI_Uint32 colorValue = DEFAULT_TEXT_PICKER_SELECTED_BACKGROUND_COLOR; + auto nodeInfo = ArkTSUtils::MakeNativeNodeInfo(nativeNode); + + ArkUI_Bool isHasValue[GETVALUE_MAX_SIZE] = {false, false, false, false, false}; + ArkUIPickerBackgroundStyleStruct backgroundStyleStruct; + backgroundStyleStruct.colorValue = DEFAULT_TEXT_PICKER_SELECTED_BACKGROUND_COLOR; Color color; - if (ArkTSUtils::ParseJsColorAlpha(vm, colorArg, color)) { - colorValue = color.GetValue(); - getValue[GETCOLOR] = true; - } - ArkUI_Float32 value[VALUE_MAX_SIZE] = {DEFAULT_TEXT_PICKER_SELECTED_BACKGROUND_BORDER_RADIUS, - DEFAULT_TEXT_PICKER_SELECTED_BACKGROUND_BORDER_RADIUS, DEFAULT_TEXT_PICKER_SELECTED_BACKGROUND_BORDER_RADIUS, - DEFAULT_TEXT_PICKER_SELECTED_BACKGROUND_BORDER_RADIUS}; - ArkUI_Int32 unit[VALUE_MAX_SIZE] = {UNIT_VP, UNIT_VP, UNIT_VP, UNIT_VP}; - auto isRightToLeft = AceApplicationInfo::GetInstance().IsRightToLeft(); - CalcDimension calcDimension; - for (int i = NUM_0; i < VALUE_MAX_SIZE; i++) { - if (ArkTSUtils::ParseJsLengthMetrics(vm, runtimeCallInfo->GetCallArgRef(i + NUM_2), calcDimension) && - !calcDimension.IsNegative()) { - getValue[i + NUM_1] = true; - value[i] = calcDimension.Value(); - unit[i] = static_cast(calcDimension.Unit()); - } - if (ArkTSUtils::ParseJsDimensionVp(vm, runtimeCallInfo->GetCallArgRef(i + NUM_2), calcDimension) && - !calcDimension.IsNegative()) { - getValue[i + NUM_1] = true; - value[i] = calcDimension.Value(); - unit[i] = static_cast(calcDimension.Unit()); - } - } - if (isRightToLeft && (value[TOPLEFT] != value[BOTTOMLEFT] || value[TOPRIGHT] != value[BOTTOMRIGHT]) && - (unit[TOPLEFT] != unit[BOTTOMLEFT] || unit[TOPRIGHT] != unit[BOTTOMRIGHT])) { - std::swap(value[TOPLEFT], value[BOTTOMLEFT]); - std::swap(value[TOPRIGHT], value[BOTTOMRIGHT]); - std::swap(unit[TOPLEFT], unit[BOTTOMLEFT]); - std::swap(unit[TOPRIGHT], unit[BOTTOMRIGHT]); - std::swap(getValue[GETTOPLEFT], getValue[GETTOPRIGHT]); - std::swap(getValue[GETBOTTOMLEFT], getValue[GETBOTTOMRIGHT]); + RefPtr colorResObj; + if (ArkTSUtils::ParseJsColorAlpha(vm, colorArg, color, colorResObj, nodeInfo)) { + isHasValue[GETCOLOR] = true; + backgroundStyleStruct.isColorSetByUser = true; + backgroundStyleStruct.colorValue = color.GetValue(); } + backgroundStyleStruct.colorRawPtr = AceType::RawPtr(colorResObj); + + RefPtr radiusResObjs[VALUE_MAX_SIZE] = {nullptr, nullptr, nullptr, nullptr}; + ParseSelectedBackgroundStyleRadius(vm, runtimeCallInfo, isHasValue, backgroundStyleStruct, radiusResObjs); + backgroundStyleStruct.topLeftRawPtr = AceType::RawPtr(radiusResObjs[TOPLEFT]); + backgroundStyleStruct.topRightRawPtr = AceType::RawPtr(radiusResObjs[TOPRIGHT]); + backgroundStyleStruct.bottomLeftRawPtr = AceType::RawPtr(radiusResObjs[BOTTOMLEFT]); + backgroundStyleStruct.bottomRightRawPtr = AceType::RawPtr(radiusResObjs[BOTTOMRIGHT]); + auto modifiers = GetArkUINodeModifiers(); CHECK_NULL_RETURN(modifiers, panda::NativePointerRef::New(vm, nullptr)); auto textPickerModifier = modifiers->getTextPickerModifier(); CHECK_NULL_RETURN(textPickerModifier, panda::NativePointerRef::New(vm, nullptr)); - textPickerModifier->setTextPickerSelectedBackgroundStyle(nativeNode, getValue, colorValue, value, unit, - VALUE_MAX_SIZE); + textPickerModifier->setTextPickerSelectedBackgroundStyleWithResObj(nativeNode, isHasValue, &backgroundStyleStruct); return panda::JSValueRef::Undefined(vm); } diff --git a/frameworks/bridge/declarative_frontend/jsview/js_textpicker.cpp b/frameworks/bridge/declarative_frontend/jsview/js_textpicker.cpp index a7786f8d5f6..57b47e3701f 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_textpicker.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_textpicker.cpp @@ -1125,16 +1125,19 @@ void JSTextPickerParser::ParsePickerBackgroundStyle(const JSRef& param auto borderRadius = paramObj->GetProperty("borderRadius"); if (!color->IsUndefined() && !color->IsNull()) { Color buttonBgColor; - if (ParseJsColor(color, buttonBgColor)) { + if (ParseJsColor(color, buttonBgColor, bgStyle.colorResObj)) { bgStyle.color = buttonBgColor; + bgStyle.textColorSetByUser = true; } } if (!borderRadius->IsUndefined() && !borderRadius->IsNull()) { CalcDimension calcDimension; NG::BorderRadiusProperty borderRadiusProperty; - if (ParseLengthMetricsToDimension(borderRadius, calcDimension)) { + if (ParseLengthMetricsToDimension(borderRadius, calcDimension, bgStyle.borderRadiusResObj)) { if (GreatOrEqual(calcDimension.Value(), 0.0f)) { bgStyle.borderRadius = NG::BorderRadiusProperty(calcDimension); + } else { + bgStyle.borderRadiusResObj = nullptr; } } else if (ParseBindSheetBorderRadiusProps(borderRadius, borderRadiusProperty)) { SetBorderRadiusWithCheck(bgStyle.borderRadius, borderRadiusProperty); diff --git a/frameworks/core/components_ng/pattern/picker/picker_type_define.h b/frameworks/core/components_ng/pattern/picker/picker_type_define.h index fc7725e3c82..d3be246311e 100644 --- a/frameworks/core/components_ng/pattern/picker/picker_type_define.h +++ b/frameworks/core/components_ng/pattern/picker/picker_type_define.h @@ -81,6 +81,9 @@ struct PickerTextProperties { struct PickerBackgroundStyle { std::optional color; std::optional borderRadius; + bool textColorSetByUser = false; + RefPtr colorResObj; + RefPtr borderRadiusResObj; }; // textpicker column kind diff --git a/frameworks/core/components_ng/pattern/text_picker/textpicker_model_ng.cpp b/frameworks/core/components_ng/pattern/text_picker/textpicker_model_ng.cpp index 5ffb01f7c43..cfe7ae8c911 100644 --- a/frameworks/core/components_ng/pattern/text_picker/textpicker_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/text_picker/textpicker_model_ng.cpp @@ -1616,6 +1616,10 @@ bool TextPickerModelNG::GetEnableHapticFeedback(FrameNode* frameNode) void TextPickerModelNG::SetSelectedBackgroundStyle(const NG::PickerBackgroundStyle& value) { + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + ParseBackgroundStyleColorResObj(frameNode, value); + ParseBackgroundStyleRadiusResObj(frameNode, value); if (value.color.has_value()) { ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedBackgroundColor, value.color.value()); @@ -1629,6 +1633,8 @@ void TextPickerModelNG::SetSelectedBackgroundStyle(const NG::PickerBackgroundSty void TextPickerModelNG::SetSelectedBackgroundStyle(FrameNode* frameNode, const NG::PickerBackgroundStyle& value) { CHECK_NULL_VOID(frameNode); + ParseBackgroundStyleColorResObj(frameNode, value); + ParseBackgroundStyleRadiusResObj(frameNode, value); if (value.color.has_value()) { ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedBackgroundColor, value.color.value(), frameNode); @@ -1784,7 +1790,8 @@ void TextPickerModelNG::ParseResTextStyle(const PickerTextStyle& textStyleOpt, c auto pickerPattern = frameNode->GetPattern(); CHECK_NULL_VOID(pickerPattern); - if (!textStyleOpt.textColorResObj && !textStyleOpt.fontSizeResObj && !textStyleOpt.fontFamilyResObj) { + if (!textStyleOpt.textColorResObj && !textStyleOpt.fontSizeResObj && !textStyleOpt.fontFamilyResObj && + !textStyleOpt.minFontSizeResObj && !textStyleOpt.maxFontSizeResObj) { pickerPattern->RemoveResObj(textStyleType); return; } @@ -1810,6 +1817,18 @@ void TextPickerModelNG::ParseResTextStyle(const PickerTextStyle& textStyleOpt, c textStyle.fontFamily = families; } + CalcDimension minFontSize; + if (textStyleOpt.minFontSizeResObj && + ResourceParseUtils::ParseResDimensionFp(textStyleOpt.minFontSizeResObj, minFontSize)) { + textStyle.minFontSize = minFontSize; + } + + CalcDimension maxFontSize; + if (textStyleOpt.maxFontSizeResObj && + ResourceParseUtils::ParseResDimensionFp(textStyleOpt.maxFontSizeResObj, maxFontSize)) { + textStyle.maxFontSize = maxFontSize; + } + updateTextStyleFunc(textStyle); }; RefPtr resObj = AceType::MakeRefPtr(); @@ -1873,49 +1892,11 @@ void TextPickerModelNG::ParseDefaultTextStyleResObj(const PickerTextStyle& textS auto pickerPattern = frameNode->GetPattern(); CHECK_NULL_VOID(pickerPattern); - if (!textStyleOpt.textColorResObj && !textStyleOpt.fontSizeResObj && !textStyleOpt.fontFamilyResObj && - !textStyleOpt.minFontSizeResObj && !textStyleOpt.maxFontSizeResObj) { - pickerPattern->RemoveResObj("TextPickerDefaultTextStyle"); - return; - } - - auto&& updateFunc = [textStyleOpt, frameNode](const RefPtr resObj) { - PickerTextStyle textStyle; - auto pickerPattern = frameNode->GetPattern(); - CHECK_NULL_VOID(pickerPattern); - Color color; - if (textStyleOpt.textColorResObj && - ResourceParseUtils::ParseResColor(textStyleOpt.textColorResObj, color)) { - textStyle.textColor = color; - } - - CalcDimension fontSize; - if (textStyleOpt.fontSizeResObj && - ResourceParseUtils::ParseResDimensionFp(textStyleOpt.fontSizeResObj, fontSize)) { - textStyle.fontSize = fontSize; - } - - std::vector families; - if (textStyleOpt.fontFamilyResObj && - ResourceParseUtils::ParseResFontFamilies(textStyleOpt.fontFamilyResObj, families)) { - textStyle.fontFamily = families; - } - - CalcDimension minFontSize; - if (textStyleOpt.minFontSizeResObj && - ResourceParseUtils::ParseResDimensionFp(textStyleOpt.minFontSizeResObj, minFontSize)) { - textStyle.minFontSize = minFontSize; - } - - CalcDimension maxFontSize; - if (textStyleOpt.maxFontSizeResObj && - ResourceParseUtils::ParseResDimensionFp(textStyleOpt.maxFontSizeResObj, maxFontSize)) { - textStyle.maxFontSize = maxFontSize; - } - pickerPattern->UpdateDefaultTextStyle(textStyle); - }; - RefPtr resObj = AceType::MakeRefPtr(); - pickerPattern->AddResObj("TextPickerDefaultTextStyle", resObj, std::move(updateFunc)); + ParseResTextStyle( + textStyleOpt, + "TextPickerDefaultTextStyle", + [pickerPattern](const PickerTextStyle& textStyle) { pickerPattern->UpdateDefaultTextStyle(textStyle); } + ); } void TextPickerModelNG::ParseSingleRangeResourceObj(const RefPtr& resultResObj, @@ -2101,4 +2082,73 @@ void TextPickerModelNG::TextPickerRemoveResObj(FrameNode* frameNode, const std:: pickerPattern->RemoveResObj(key); } +void TextPickerModelNG::ParseBackgroundStyleColorResObj(FrameNode* frameNode, const NG::PickerBackgroundStyle& value) +{ + if (!SystemProperties::ConfigChangePerform() || !frameNode) { + return; + } + + auto textPickerPattern = frameNode->GetPattern(); + CHECK_NULL_VOID(textPickerPattern); + textPickerPattern->RemoveResObj("TextPicker.BackgroundStyle.color"); + + auto&& updateColorFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr& resObj) { + auto node = weak.Upgrade(); + CHECK_NULL_VOID(node); + + NG::PickerBackgroundStyle& backgroundValue = const_cast(value); + Color color = backgroundValue.color.value(); + if (value.colorResObj && ResourceParseUtils::ParseResColor(backgroundValue.colorResObj, color)) { + ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedBackgroundColor, color, node); + } else if (!value.textColorSetByUser) { + auto context = node->GetContext(); + CHECK_NULL_VOID(context); + auto theme = context->GetTheme(); + if (theme) { + color = theme->GetSelectedBackgroundColor(); + ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedBackgroundColor, color, node); + } + } + }; + RefPtr resObj = AceType::MakeRefPtr(); + textPickerPattern->AddResObj("TextPicker.BackgroundStyle.color", resObj, std::move(updateColorFunc)); +} + +void TextPickerModelNG::ParseBackgroundStyleRadiusResObj(FrameNode* frameNode, const NG::PickerBackgroundStyle& value) +{ + if (!SystemProperties::ConfigChangePerform() || !frameNode) { + return; + } + + auto textPickerPattern = frameNode->GetPattern(); + CHECK_NULL_VOID(textPickerPattern); + textPickerPattern->RemoveResObj("TextPicker.BackgroundStyle.borderRadius"); + + if (!value.borderRadiusResObj && !value.borderRadius->HasResources()) { + return; + } + + auto&& updateRadiusFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr& resObj) { + auto node = weak.Upgrade(); + CHECK_NULL_VOID(node); + + NG::PickerBackgroundStyle& backgroundValue = const_cast(value); + if (backgroundValue.borderRadius->HasResources()) { + backgroundValue.borderRadius->ReloadResources(); + NG::BorderRadiusProperty& borderRadiusValue = backgroundValue.borderRadius.value(); + ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedBorderRadius, borderRadiusValue, node); + } else if (backgroundValue.borderRadiusResObj) { + CalcDimension calcDimension; + ResourceParseUtils::ParseResDimensionVpNG(backgroundValue.borderRadiusResObj, calcDimension); + if (GreatOrEqual(calcDimension.Value(), 0.0f)) { + NG::BorderRadiusProperty borderRadiusValue = NG::BorderRadiusProperty(calcDimension); + ACE_UPDATE_NODE_LAYOUT_PROPERTY( + TextPickerLayoutProperty, SelectedBorderRadius, borderRadiusValue, node); + } + } + }; + RefPtr resObj = AceType::MakeRefPtr(); + textPickerPattern->AddResObj("TextPicker.BackgroundStyle.borderRadius", resObj, std::move(updateRadiusFunc)); +} + } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/text_picker/textpicker_model_ng.h b/frameworks/core/components_ng/pattern/text_picker/textpicker_model_ng.h index a96408a2ccf..9e89e945240 100644 --- a/frameworks/core/components_ng/pattern/text_picker/textpicker_model_ng.h +++ b/frameworks/core/components_ng/pattern/text_picker/textpicker_model_ng.h @@ -179,6 +179,8 @@ private: static void ParseSelectedTextStyleResObj(const PickerTextStyle& textStyleOpt); static void ParseNormalTextStyleResObj(const PickerTextStyle& textStyleOpt); static void ParseDefaultTextStyleResObj(const PickerTextStyle& textStyleOpt); + static void ParseBackgroundStyleColorResObj(FrameNode* frameNode, const NG::PickerBackgroundStyle& value); + static void ParseBackgroundStyleRadiusResObj(FrameNode* frameNode, const NG::PickerBackgroundStyle& value); uint32_t maxCount_ = 0; std::vector kinds_; diff --git a/frameworks/core/components_ng/pattern/text_picker/textpicker_pattern.cpp b/frameworks/core/components_ng/pattern/text_picker/textpicker_pattern.cpp index 7dfa2778e65..cc610b3b464 100644 --- a/frameworks/core/components_ng/pattern/text_picker/textpicker_pattern.cpp +++ b/frameworks/core/components_ng/pattern/text_picker/textpicker_pattern.cpp @@ -1968,7 +1968,9 @@ void TextPickerPattern::UpdateTextStyleCommon( const TextStyle& defaultTextStyle, std::function updateTextColorFunc, std::function updateFontSizeFunc, - std::function&)> updateFontFamilyFunc + std::function&)> updateFontFamilyFunc, + std::function updateMinFontSizeFunc, + std::function updateMaxFontSizeFunc ) { auto host = GetHost(); @@ -1989,6 +1991,18 @@ void TextPickerPattern::UpdateTextStyleCommon( updateFontSizeFunc(ConvertFontScaleValue(fontSize)); updateFontFamilyFunc(textStyle.fontFamily.value_or(defaultTextStyle.GetFontFamilies())); + + Dimension minFontSize = Dimension(); + if (textStyle.minFontSize.has_value() && textStyle.minFontSize->IsValid()) { + minFontSize = ConvertFontScaleValue(textStyle.minFontSize.value()); + } + updateMinFontSizeFunc(minFontSize); + + Dimension maxFontSize = Dimension(); + if (textStyle.maxFontSize.has_value() && textStyle.maxFontSize->IsValid()) { + maxFontSize = ConvertFontScaleValue(textStyle.maxFontSize.value()); + } + updateMaxFontSizeFunc(maxFontSize); } if (host->GetRerenderable()) { @@ -2017,7 +2031,9 @@ void TextPickerPattern::UpdateDisappearTextStyle(const PickerTextStyle& textStyl defaultTextStyle, [&](const Color& color) { pickerProperty->UpdateDisappearColor(color); }, [&](const Dimension& fontSize) { pickerProperty->UpdateDisappearFontSize(fontSize); }, - [&](const std::vector& fontFamily) { pickerProperty->UpdateDisappearFontFamily(fontFamily); } + [&](const std::vector& fontFamily) { pickerProperty->UpdateDisappearFontFamily(fontFamily); }, + [&](const Dimension& minFontSize) { pickerProperty->UpdateDisappearMinFontSize(minFontSize); }, + [&](const Dimension& maxFontSize) { pickerProperty->UpdateDisappearMaxFontSize(maxFontSize); } ); } @@ -2042,7 +2058,9 @@ void TextPickerPattern::UpdateNormalTextStyle(const PickerTextStyle& textStyle) defaultTextStyle, [&](const Color& color) { pickerProperty->UpdateColor(color); }, [&](const Dimension& fontSize) { pickerProperty->UpdateFontSize(fontSize); }, - [&](const std::vector& fontFamily) { pickerProperty->UpdateFontFamily(fontFamily); } + [&](const std::vector& fontFamily) { pickerProperty->UpdateFontFamily(fontFamily); }, + [&](const Dimension& minFontSize) { pickerProperty->UpdateMinFontSize(minFontSize); }, + [&](const Dimension& maxFontSize) { pickerProperty->UpdateMaxFontSize(maxFontSize); } ); } @@ -2067,7 +2085,9 @@ void TextPickerPattern::UpdateSelectedTextStyle(const PickerTextStyle& textStyle defaultTextStyle, [&](const Color& color) { pickerProperty->UpdateSelectedColor(color); }, [&](const Dimension& fontSize) { pickerProperty->UpdateSelectedFontSize(fontSize); }, - [&](const std::vector& fontFamily) { pickerProperty->UpdateSelectedFontFamily(fontFamily); } + [&](const std::vector& fontFamily) { pickerProperty->UpdateSelectedFontFamily(fontFamily); }, + [&](const Dimension& minFontSize) { pickerProperty->UpdateSelectedMinFontSize(minFontSize); }, + [&](const Dimension& maxFontSize) { pickerProperty->UpdateSelectedMaxFontSize(maxFontSize); } ); } @@ -2092,28 +2112,10 @@ void TextPickerPattern::UpdateDefaultTextStyle(const PickerTextStyle& textStyle) defaultTextStyle, [&](const Color& color) { pickerProperty->UpdateDefaultColor(color); }, [&](const Dimension& fontSize) { pickerProperty->UpdateDefaultFontSize(fontSize); }, - [&](const std::vector& fontFamily) { pickerProperty->UpdateDefaultFontFamily(fontFamily); } + [&](const std::vector& fontFamily) { pickerProperty->UpdateDefaultFontFamily(fontFamily); }, + [&](const Dimension& minFontSize) { pickerProperty->UpdateDefaultMinFontSize(minFontSize); }, + [&](const Dimension& maxFontSize) { pickerProperty->UpdateDefaultMaxFontSize(maxFontSize); } ); - - if (pipelineContext->IsSystmColorChange()) { - if (textStyle.minFontSize.has_value() && textStyle.minFontSize->IsValid()) { - Dimension minFontSize = textStyle.minFontSize.value(); - pickerProperty->UpdateDefaultMinFontSize(ConvertFontScaleValue(minFontSize)); - } else { - pickerProperty->UpdateDefaultMinFontSize(Dimension()); - } - - if (textStyle.maxFontSize.has_value() && textStyle.maxFontSize->IsValid()) { - Dimension maxFontSize = textStyle.maxFontSize.value(); - pickerProperty->UpdateDefaultMaxFontSize(ConvertFontScaleValue(maxFontSize)); - } else { - pickerProperty->UpdateDefaultMaxFontSize(Dimension()); - } - } - - if (host->GetRerenderable()) { - host->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF); - } } void TextPickerPattern::ParseRangeResult(NG::TextCascadePickerOptions& option) diff --git a/frameworks/core/components_ng/pattern/text_picker/textpicker_pattern.h b/frameworks/core/components_ng/pattern/text_picker/textpicker_pattern.h index 3829351b35d..26a9ca62f72 100644 --- a/frameworks/core/components_ng/pattern/text_picker/textpicker_pattern.h +++ b/frameworks/core/components_ng/pattern/text_picker/textpicker_pattern.h @@ -634,7 +634,9 @@ private: const TextStyle& defaultTextStyle, std::function updateTextColorFunc, std::function updateFontSizeFunc, - std::function&)> updateFontFamilyFunc); + std::function&)> updateFontFamilyFunc, + std::function updateMinFontSizeFunc, + std::function updateMaxFontSizeFunc); void ParseRangeResult(NG::TextCascadePickerOptions& option); void GetRealSelectedIndex(const std::vector& rangeOptions, diff --git a/frameworks/core/interfaces/arkoala/arkoala_api.h b/frameworks/core/interfaces/arkoala/arkoala_api.h index 00feaafa8c5..ba8a50768c4 100644 --- a/frameworks/core/interfaces/arkoala/arkoala_api.h +++ b/frameworks/core/interfaces/arkoala/arkoala_api.h @@ -1043,6 +1043,19 @@ struct ArkUIPickerEdgeAlignStruct { void* dyRawPtr; }; +struct ArkUIPickerBackgroundStyleStruct { + ArkUI_Uint32 colorValue; + ArkUI_Float32* values; + ArkUI_Int32* units; + ArkUI_Int32 length; + ArkUI_Bool isColorSetByUser; + void* colorRawPtr; + void* topLeftRawPtr; + void* topRightRawPtr; + void* bottomLeftRawPtr; + void* bottomRightRawPtr; +}; + struct ArkUISliderShowStepOptions { uint32_t step; const char* text; @@ -6016,6 +6029,8 @@ struct ArkUITextPickerModifier { ArkUINodeHandle node, ArkUITextCascadePickerRangeContentArray arry, ArkUI_Int32 rangeType); void (*setTextPickerSelectedBackgroundStyle)(ArkUINodeHandle node, ArkUI_Bool* getValue, ArkUI_Uint32 color, ArkUI_Float32* value, ArkUI_Int32* unit, ArkUI_Int32 size); + void (*setTextPickerSelectedBackgroundStyleWithResObj)(ArkUINodeHandle node, ArkUI_Bool* isHasValue, + const struct ArkUIPickerBackgroundStyleStruct* backgroundStyleStruct); void (*getTextPickerSelectedBackgroundStyle)(ArkUINodeHandle node, ArkUINumberValue* result, ArkUI_Int32 size); void (*resetTextPickerSelectedBackgroundStyle)(ArkUINodeHandle node); }; diff --git a/frameworks/core/interfaces/native/node/node_textpicker_modifier.cpp b/frameworks/core/interfaces/native/node/node_textpicker_modifier.cpp index c4d6e5059f3..23145651af0 100644 --- a/frameworks/core/interfaces/native/node/node_textpicker_modifier.cpp +++ b/frameworks/core/interfaces/native/node/node_textpicker_modifier.cpp @@ -19,6 +19,7 @@ #include "core/components_ng/pattern/tabs/tabs_model.h" #include "core/pipeline_ng/pipeline_context.h" #include "core/components_ng/pattern/text_picker/textpicker_model_ng.h" +#include "core/common/resource/resource_parse_utils.h" namespace OHOS::Ace::NG { namespace { @@ -83,23 +84,33 @@ void InitTextPickerTextStyle(const char* fontInfo, uint32_t color, int32_t fontS textStyle.textColor = Color(color); } -void SetTextPickerTextStyleResObj(NG::PickerTextStyle& textStyle, void* fontSizeRawPtr, void* fontFamilyRawPtr, - void* textColorRawPtr) +void SetTextPickerTextStyleResObj(NG::PickerTextStyle& textStyle, + const struct ArkUIPickerTextStyleStruct* textStyleStruct) { - auto* fontSizePtr = reinterpret_cast(fontSizeRawPtr); + auto* fontSizePtr = reinterpret_cast(textStyleStruct->fontSizeRawPtr); if (fontSizePtr) { textStyle.fontSizeResObj = AceType::Claim(fontSizePtr); } - auto* fontFamilyPtr = reinterpret_cast(fontFamilyRawPtr); + auto* fontFamilyPtr = reinterpret_cast(textStyleStruct->fontFamilyRawPtr); if (fontFamilyPtr) { textStyle.fontFamilyResObj = AceType::Claim(fontFamilyPtr); } - auto* textColorPtr = reinterpret_cast(textColorRawPtr); + auto* textColorPtr = reinterpret_cast(textStyleStruct->textColorRawPtr); if (textColorPtr) { textStyle.textColorResObj = AceType::Claim(textColorPtr); } + + auto* minFontSizePtr = reinterpret_cast(textStyleStruct->minFontSizeRawPtr); + if (minFontSizePtr) { + textStyle.minFontSizeResObj = AceType::Claim(minFontSizePtr); + } + + auto* maxFontSizePtr = reinterpret_cast(textStyleStruct->maxFontSizeRawPtr); + if (maxFontSizePtr) { + textStyle.maxFontSizeResObj = AceType::Claim(maxFontSizePtr); + } } void SetTextPickerBackgroundColor(ArkUINodeHandle node, ArkUI_Uint32 color) @@ -254,8 +265,7 @@ void SetTextPickerTextStyleWithResObj(ArkUINodeHandle node, const struct ArkUIPi } else { textStyle.textOverflow = TEXT_OVERFLOWS[0]; } - SetTextPickerTextStyleResObj(textStyle, textStyleStruct->fontSizeRawPtr, textStyleStruct->fontFamilyRawPtr, - textStyleStruct->textColorRawPtr); + SetTextPickerTextStyleResObj(textStyle, textStyleStruct); TextPickerModelNG::SetNormalTextStyle(frameNode, theme, textStyle); } @@ -324,8 +334,7 @@ void SetTextPickerSelectedTextStyleWithResObj(ArkUINodeHandle node, } else { textStyle.textOverflow = TEXT_OVERFLOWS[0]; } - SetTextPickerTextStyleResObj(textStyle, textStyleStruct->fontSizeRawPtr, textStyleStruct->fontFamilyRawPtr, - textStyleStruct->textColorRawPtr); + SetTextPickerTextStyleResObj(textStyle, textStyleStruct); TextPickerModelNG::SetSelectedTextStyle(frameNode, theme, textStyle); } @@ -394,8 +403,7 @@ void SetTextPickerDisappearTextStyleWithResObj(ArkUINodeHandle node, } else { textStyle.textOverflow = TEXT_OVERFLOWS[0]; } - SetTextPickerTextStyleResObj(textStyle, textStyleStruct->fontSizeRawPtr, textStyleStruct->fontFamilyRawPtr, - textStyleStruct->textColorRawPtr); + SetTextPickerTextStyleResObj(textStyle, textStyleStruct); TextPickerModelNG::SetDisappearTextStyle(frameNode, theme, textStyle); } @@ -881,8 +889,7 @@ void SetTextPickerDefaultTextStyleWithResObj(ArkUINodeHandle node, } else { textStyle.textOverflow = TEXT_OVERFLOWS[0]; } - SetTextPickerTextStyleResObj(textStyle, textStyleStruct->fontSizeRawPtr, - textStyleStruct->fontFamilyRawPtr, textStyleStruct->textColorRawPtr); + SetTextPickerTextStyleResObj(textStyle, textStyleStruct); TextPickerModelNG::SetDefaultTextStyle(frameNode, theme, textStyle); } @@ -972,6 +979,79 @@ void SetTextPickerSelectedBackgroundStyle(ArkUINodeHandle node, ArkUI_Bool* getV TextPickerModelNG::SetSelectedBackgroundStyle(frameNode, pickerBgStyle); } +#define TEXT_PICKER_ADD_RADIUS_RESOURCE(radiusProp, propName, dimensionMember) \ + auto propName##Update = [](const RefPtr& obj, BorderRadiusProperty& prop) { \ + CalcDimension dim; \ + ResourceParseUtils::ParseResDimensionVp(obj, dim); \ + prop.dimensionMember = dim; \ + }; \ + const std::string resourceKey = std::string("borderRadius.") + #dimensionMember; \ + (radiusProp)->AddResource(resourceKey, propName##ResObj, std::move(propName##Update)) + +void AddRadiusResource(const struct ArkUIPickerBackgroundStyleStruct* backgroundStyleStruct, + PickerBackgroundStyle& pickerBgStyle) +{ + auto* topLeftResPtr = reinterpret_cast(backgroundStyleStruct->topLeftRawPtr); + auto topLeftResObj = AceType::Claim(topLeftResPtr); + auto* topRightResPtr = reinterpret_cast(backgroundStyleStruct->topRightRawPtr); + auto topRightResObj = AceType::Claim(topRightResPtr); + auto* bottomLeftResPtr = reinterpret_cast(backgroundStyleStruct->bottomLeftRawPtr); + auto bottomLeftResObj = AceType::Claim(bottomLeftResPtr); + auto* bottomRightResPtr = reinterpret_cast(backgroundStyleStruct->bottomRightRawPtr); + auto bottomRightResObj = AceType::Claim(bottomRightResPtr); + if (topLeftResObj) { + TEXT_PICKER_ADD_RADIUS_RESOURCE(pickerBgStyle.borderRadius, topLeft, radiusTopLeft); + } + if (topRightResObj) { + TEXT_PICKER_ADD_RADIUS_RESOURCE(pickerBgStyle.borderRadius, topRight, radiusTopRight); + } + if (bottomLeftResObj) { + TEXT_PICKER_ADD_RADIUS_RESOURCE(pickerBgStyle.borderRadius, bottomLeft, radiusBottomLeft); + } + if (bottomRightResObj) { + TEXT_PICKER_ADD_RADIUS_RESOURCE(pickerBgStyle.borderRadius, bottomRight, radiusBottomRight); + } +} + +void SetTextPickerSelectedBackgroundStyleWithResObj(ArkUINodeHandle node, ArkUI_Bool* isHasValue, + const struct ArkUIPickerBackgroundStyleStruct* backgroundStyleStruct) +{ + auto* frameNode = reinterpret_cast(node); + CHECK_NULL_VOID(frameNode); + auto pipeline = frameNode->GetContext(); + CHECK_NULL_VOID(pipeline); + auto theme = pipeline->GetTheme(); + CHECK_NULL_VOID(theme); + PickerBackgroundStyle pickerBgStyle; + pickerBgStyle.color = theme->GetSelectedBackgroundColor(); + pickerBgStyle.borderRadius = theme->GetSelectedBorderRadius(); + if (isHasValue[GETCOLOR]) { + pickerBgStyle.color = Color(backgroundStyleStruct->colorValue); + pickerBgStyle.textColorSetByUser = backgroundStyleStruct->isColorSetByUser; + auto* colorPtr = reinterpret_cast(backgroundStyleStruct->colorRawPtr); + pickerBgStyle.colorResObj = AceType::Claim(colorPtr); + } + if (isHasValue[GETTOPLEFT]) { + pickerBgStyle.borderRadius->radiusTopLeft = Dimension(backgroundStyleStruct->values[TOPLEFT], + static_cast(backgroundStyleStruct->units[TOPLEFT])); + } + if (isHasValue[GETTOPRIGHT]) { + pickerBgStyle.borderRadius->radiusTopRight = Dimension(backgroundStyleStruct->values[TOPRIGHT], + static_cast(backgroundStyleStruct->units[TOPRIGHT])); + } + if (isHasValue[GETBOTTOMLEFT]) { + pickerBgStyle.borderRadius->radiusBottomLeft = Dimension(backgroundStyleStruct->values[BOTTOMLEFT], + static_cast(backgroundStyleStruct->units[BOTTOMLEFT])); + } + if (isHasValue[GETBOTTOMRIGHT]) { + pickerBgStyle.borderRadius->radiusBottomRight = Dimension(backgroundStyleStruct->values[BOTTOMRIGHT], + static_cast(backgroundStyleStruct->units[BOTTOMRIGHT])); + } + + AddRadiusResource(backgroundStyleStruct, pickerBgStyle); + TextPickerModelNG::SetSelectedBackgroundStyle(frameNode, pickerBgStyle); +} + void GetTextPickerSelectedBackgroundStyle(ArkUINodeHandle node, ArkUINumberValue* result, ArkUI_Int32 size) { auto* frameNode = reinterpret_cast(node); @@ -1061,6 +1141,7 @@ const ArkUITextPickerModifier* GetTextPickerModifier() .setTextPickerIconRangeStr = SetTextPickerIconRangeStr, .setTextCascadePickRangeContent = SetTextCascadePickRangeContent, .setTextPickerSelectedBackgroundStyle = SetTextPickerSelectedBackgroundStyle, + .setTextPickerSelectedBackgroundStyleWithResObj = SetTextPickerSelectedBackgroundStyleWithResObj, .getTextPickerSelectedBackgroundStyle = GetTextPickerSelectedBackgroundStyle, .resetTextPickerSelectedBackgroundStyle = ResetTextPickerSelectedBackgroundStyle, }; diff --git a/test/unittest/core/pattern/text_picker/text_picker_resource_test.cpp b/test/unittest/core/pattern/text_picker/text_picker_resource_test.cpp index ab576dc1b4d..3f2956dd5c7 100644 --- a/test/unittest/core/pattern/text_picker/text_picker_resource_test.cpp +++ b/test/unittest/core/pattern/text_picker/text_picker_resource_test.cpp @@ -39,6 +39,8 @@ namespace OHOS::Ace::NG { namespace { constexpr uint32_t SELECTED_INDEX_1 = 1; constexpr double TEST_FONT_SIZE = 10.0; +constexpr double TEST_MIN_FONT_SIZE = 9.0; +constexpr double TEST_MAX_FONT_SIZE = 20.0; } // namespace class TextPickerResourceTest : public testing::Test { @@ -53,6 +55,7 @@ public: RefPtr dialogTheme_; RefPtr pickerThem_; RefPtr buttonTheme_; + RefPtr textTheme_; }; class TestNode : public UINode { @@ -92,6 +95,7 @@ void TextPickerResourceTest::SetUp() dialogTheme_ = AceType::MakeRefPtr(); pickerThem_ = MockThemeDefault::GetPickerTheme(); buttonTheme_ = AceType::MakeRefPtr(); + textTheme_ = AceType::MakeRefPtr(); auto themeManager = AceType::MakeRefPtr(); MockPipelineContext::GetCurrent()->SetThemeManager(themeManager); @@ -119,6 +123,8 @@ RefPtr TextPickerResourceTest::GetThemeByType(ThemeType type) return pickerThem_; } else if (type == ButtonTheme::TypeId()) { return buttonTheme_; + } else if (type == TextTheme::TypeId()) { + return textTheme_; } else { return nullptr; } @@ -496,4 +502,265 @@ HWTEST_F(TextPickerResourceTest, UpdateSelectedTextStyle001, TestSize.Level1) EXPECT_EQ(pickerProperty->GetSelectedFontSize().value(), Dimension(TEST_FONT_SIZE + 1)); } +/** + * @tc.name: SetDefaultTextStyle001 + * @tc.desc: Test SetDefaultTextStyle. + * @tc.type: FUNC + */ +HWTEST_F(TextPickerResourceTest, SetDefaultTextStyle001, TestSize.Level1) +{ + /** + * @tc.steps: step1. Create TextPicker. + */ + auto pipeline = MockPipelineContext::GetCurrent(); + auto theme = pipeline->GetTheme(); + + SystemProperties::SetDeviceType(DeviceType::PHONE); + SystemProperties::SetDeviceOrientation(static_cast(DeviceOrientation::LANDSCAPE)); + TextPickerModelNG::GetInstance()->Create(theme, TEXT); + std::vector oldRange = { { "", "Text1" }, { "", "Text2" }, { "", "Text3" } }; + TextPickerModelNG::GetInstance()->SetRange(oldRange); + TextPickerModelNG::GetInstance()->SetSelected(SELECTED_INDEX_1); + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + ASSERT_NE(frameNode, nullptr); + + auto pipelineContext = PipelineContext::GetCurrentContext(); + ASSERT_NE(pipelineContext, nullptr); + pipelineContext->SetIsSystemColorChange(true); + + /** + * @tc.steps: step2. Call SetDefaultTextStyle function. + */ + PickerTextStyle textStyle; + textStyle.textColor = Color::RED; + textStyle.fontSize = Dimension(TEST_FONT_SIZE); + auto textTheme = pipeline->GetTheme(); + TextPickerModelNG::GetInstance()->SetDefaultTextStyle(textTheme, textStyle); + + auto pickerProperty = frameNode->GetLayoutProperty(); + ASSERT_NE(pickerProperty, nullptr); + EXPECT_EQ(pickerProperty->GetDefaultColor().value(), Color::RED); + EXPECT_EQ(pickerProperty->GetDefaultFontSize().value(), Dimension(TEST_FONT_SIZE)); + + textStyle.textColor = Color::GREEN; + textStyle.fontSize = Dimension(TEST_FONT_SIZE + 1); + textStyle.minFontSize = Dimension(TEST_MIN_FONT_SIZE); + textStyle.maxFontSize = Dimension(TEST_MAX_FONT_SIZE); + auto pickerPattern = frameNode->GetPattern(); + ASSERT_NE(pickerPattern, nullptr); + pickerPattern->UpdateDefaultTextStyle(textStyle); + + EXPECT_EQ(pickerProperty->GetDefaultColor().value(), Color::GREEN); + EXPECT_EQ(pickerProperty->GetDefaultFontSize().value(), Dimension(TEST_FONT_SIZE + 1)); + EXPECT_EQ(pickerProperty->GetDefaultMinFontSize().value(), Dimension(TEST_MIN_FONT_SIZE)); + EXPECT_EQ(pickerProperty->GetDefaultMaxFontSize().value(), Dimension(TEST_MAX_FONT_SIZE)); +} + +/** + * @tc.name: SelectedBackgroundStyle001 + * @tc.desc: Test GetCanLoopFromLayoutProperty. + * @tc.type: FUNC + */ +HWTEST_F(TextPickerResourceTest, SelectedBackgroundStyle001, TestSize.Level1) +{ + /** + * @tc.steps: step1. Create TextPicker. + */ + auto pipeline = MockPipelineContext::GetCurrent(); + auto theme = pipeline->GetTheme(); + ASSERT_NE(theme, nullptr); + + SystemProperties::SetDeviceType(DeviceType::PHONE); + SystemProperties::SetDeviceOrientation(static_cast(DeviceOrientation::LANDSCAPE)); + TextPickerModelNG::GetInstance()->Create(theme, TEXT); + std::vector oldRange = { { "", "Text1" }, { "", "Text2" }, { "", "Text3" } }; + TextPickerModelNG::GetInstance()->SetRange(oldRange); + TextPickerModelNG::GetInstance()->SetSelected(SELECTED_INDEX_1); + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + ASSERT_NE(frameNode, nullptr); + + /** + * @tc.steps: step2. Set g_isConfigChangePerform to true. + */ + g_isConfigChangePerform = true; + auto pattern = frameNode->GetPattern(); + ASSERT_NE(pattern, nullptr); + pattern->resourceMgr_ = AceType::MakeRefPtr(); + ASSERT_NE(pattern->resourceMgr_, nullptr); + + NG::PickerBackgroundStyle pickerBgStyle; + pickerBgStyle.color = Color::RED; + pickerBgStyle.borderRadius = NG::BorderRadiusProperty(8.0_vp); + TextPickerModelNG::SetSelectedBackgroundStyle(frameNode, pickerBgStyle); + + NG::PickerBackgroundStyle result1; + NG::PickerBackgroundStyle result2; + auto layoutProperty = frameNode->GetLayoutProperty(); + result1.color = layoutProperty->GetSelectedBackgroundColorValue(); + result1.borderRadius = layoutProperty->GetSelectedBorderRadiusValue(); + result2.color = TextPickerModelNG::GetSelectedBackgroundStyle(frameNode).color; + result2.borderRadius = TextPickerModelNG::GetSelectedBackgroundStyle(frameNode).borderRadius; + EXPECT_EQ(pickerBgStyle.color, result1.color); + EXPECT_EQ(pickerBgStyle.borderRadius, result1.borderRadius); + EXPECT_EQ(pickerBgStyle.color, result2.color); + EXPECT_EQ(pickerBgStyle.borderRadius, result2.borderRadius); + + /** + * @tc.steps: step3. Call ParseBackgroundStyleColorResObj and ParseBackgroundStyleRadiusResObj + * to register the resourceObject callback function. + * @tc.expected: Dut to color is set by user, the value will not be changed. + */ + auto textPickerPattern = frameNode->GetPattern(); + ASSERT_NE(textPickerPattern, nullptr); + + pickerBgStyle.textColorSetByUser = true; + pickerBgStyle.colorResObj = AceType::MakeRefPtr(); + pickerBgStyle.borderRadiusResObj = AceType::MakeRefPtr(); + TextPickerModelNG::ParseBackgroundStyleColorResObj(frameNode, pickerBgStyle); + TextPickerModelNG::ParseBackgroundStyleRadiusResObj(frameNode, pickerBgStyle); + pattern->resourceMgr_->ReloadResources(); + result1.color = layoutProperty->GetSelectedBackgroundColorValue(); + result2.color = TextPickerModelNG::GetSelectedBackgroundStyle(frameNode).color; + EXPECT_EQ(pickerBgStyle.color, result1.color); + EXPECT_EQ(pickerBgStyle.color, result2.color); +} + +/** + * @tc.name: SelectedBackgroundStyle002 + * @tc.desc: Test GetCanLoopFromLayoutProperty. + * @tc.type: FUNC + */ +HWTEST_F(TextPickerResourceTest, SelectedBackgroundStyle002, TestSize.Level1) +{ + /** + * @tc.steps: step1. Create TextPicker. + */ + auto pipeline = MockPipelineContext::GetCurrent(); + auto theme = pipeline->GetTheme(); + ASSERT_NE(theme, nullptr); + + SystemProperties::SetDeviceType(DeviceType::PHONE); + SystemProperties::SetDeviceOrientation(static_cast(DeviceOrientation::LANDSCAPE)); + TextPickerModelNG::GetInstance()->Create(theme, TEXT); + std::vector oldRange = { { "", "Text1" }, { "", "Text2" }, { "", "Text3" } }; + TextPickerModelNG::GetInstance()->SetRange(oldRange); + TextPickerModelNG::GetInstance()->SetSelected(SELECTED_INDEX_1); + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + ASSERT_NE(frameNode, nullptr); + + /** + * @tc.steps: step2. Set g_isConfigChangePerform to true. + */ + g_isConfigChangePerform = true; + auto pattern = frameNode->GetPattern(); + ASSERT_NE(pattern, nullptr); + pattern->resourceMgr_ = AceType::MakeRefPtr(); + ASSERT_NE(pattern->resourceMgr_, nullptr); + + NG::PickerBackgroundStyle pickerBgStyle; + pickerBgStyle.color = Color::RED; + pickerBgStyle.borderRadius = NG::BorderRadiusProperty(8.0_vp); + TextPickerModelNG::GetInstance()->SetSelectedBackgroundStyle(pickerBgStyle); + + NG::PickerBackgroundStyle result1; + NG::PickerBackgroundStyle result2; + auto layoutProperty = frameNode->GetLayoutProperty(); + result1.color = layoutProperty->GetSelectedBackgroundColorValue(); + result1.borderRadius = layoutProperty->GetSelectedBorderRadiusValue(); + result2.color = TextPickerModelNG::GetSelectedBackgroundStyle(frameNode).color; + result2.borderRadius = TextPickerModelNG::GetSelectedBackgroundStyle(frameNode).borderRadius; + EXPECT_EQ(pickerBgStyle.color, result1.color); + EXPECT_EQ(pickerBgStyle.borderRadius, result1.borderRadius); + EXPECT_EQ(pickerBgStyle.color, result2.color); + EXPECT_EQ(pickerBgStyle.borderRadius, result2.borderRadius); + + /** + * @tc.steps: step3. Call ParseBackgroundStyleColorResObj and ParseBackgroundStyleRadiusResObj + * to register the resourceObject callback function. + * @tc.expected: Dut to color is set by user, the value will not be changed. + */ + auto textPickerPattern = frameNode->GetPattern(); + ASSERT_NE(textPickerPattern, nullptr); + pickerBgStyle.textColorSetByUser = true; + pickerBgStyle.colorResObj = AceType::MakeRefPtr(); + pickerBgStyle.borderRadiusResObj = AceType::MakeRefPtr(); + TextPickerModelNG::ParseBackgroundStyleColorResObj(frameNode, pickerBgStyle); + TextPickerModelNG::ParseBackgroundStyleRadiusResObj(frameNode, pickerBgStyle); + pattern->resourceMgr_->ReloadResources(); + result1.color = layoutProperty->GetSelectedBackgroundColorValue(); + result2.color = TextPickerModelNG::GetSelectedBackgroundStyle(frameNode).color; + EXPECT_EQ(pickerBgStyle.color, result1.color); + EXPECT_EQ(pickerBgStyle.color, result2.color); +} + +/** + * @tc.name: SelectedBackgroundStyle003 + * @tc.desc: Test GetCanLoopFromLayoutProperty. + * @tc.type: FUNC + */ +HWTEST_F(TextPickerResourceTest, SelectedBackgroundStyle003, TestSize.Level1) +{ + /** + * @tc.steps: step1. Create TextPicker. + */ + auto pipeline = MockPipelineContext::GetCurrent(); + auto theme = pipeline->GetTheme(); + ASSERT_NE(theme, nullptr); + + SystemProperties::SetDeviceType(DeviceType::PHONE); + SystemProperties::SetDeviceOrientation(static_cast(DeviceOrientation::LANDSCAPE)); + TextPickerModelNG::GetInstance()->Create(theme, TEXT); + std::vector oldRange = { { "", "Text1" }, { "", "Text2" }, { "", "Text3" } }; + TextPickerModelNG::GetInstance()->SetRange(oldRange); + TextPickerModelNG::GetInstance()->SetSelected(SELECTED_INDEX_1); + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + ASSERT_NE(frameNode, nullptr); + + /** + * @tc.steps: step2. Set g_isConfigChangePerform to true. + */ + g_isConfigChangePerform = true; + auto pattern = frameNode->GetPattern(); + ASSERT_NE(pattern, nullptr); + pattern->resourceMgr_ = AceType::MakeRefPtr(); + ASSERT_NE(pattern->resourceMgr_, nullptr); + + NG::PickerBackgroundStyle pickerBgStyle; + pickerBgStyle.color = Color::RED; + pickerBgStyle.borderRadius = NG::BorderRadiusProperty(8.0_vp); + TextPickerModelNG::GetInstance()->SetSelectedBackgroundStyle(pickerBgStyle); + + NG::PickerBackgroundStyle result1; + NG::PickerBackgroundStyle result2; + auto layoutProperty = frameNode->GetLayoutProperty(); + result1.color = layoutProperty->GetSelectedBackgroundColorValue(); + result1.borderRadius = layoutProperty->GetSelectedBorderRadiusValue(); + result2.color = TextPickerModelNG::GetSelectedBackgroundStyle(frameNode).color; + result2.borderRadius = TextPickerModelNG::GetSelectedBackgroundStyle(frameNode).borderRadius; + EXPECT_EQ(pickerBgStyle.color, result1.color); + EXPECT_EQ(pickerBgStyle.borderRadius, result1.borderRadius); + EXPECT_EQ(pickerBgStyle.color, result2.color); + EXPECT_EQ(pickerBgStyle.borderRadius, result2.borderRadius); + + /** + * @tc.steps: step3. Call ParseBackgroundStyleColorResObj and ParseBackgroundStyleRadiusResObj + * to register the resourceObject callback function. + * @tc.expected: Dut to color is not set by user, the value will not be changed. + */ + auto textPickerPattern = frameNode->GetPattern(); + ASSERT_NE(textPickerPattern, nullptr); + pickerBgStyle.textColorSetByUser = false; + pickerBgStyle.colorResObj = AceType::MakeRefPtr(); + pickerBgStyle.borderRadiusResObj = AceType::MakeRefPtr(); + TextPickerModelNG::ParseBackgroundStyleColorResObj(frameNode, pickerBgStyle); + TextPickerModelNG::ParseBackgroundStyleRadiusResObj(frameNode, pickerBgStyle); + pattern->resourceMgr_->ReloadResources(); + Color newColor = theme->GetSelectedBackgroundColor(); + result1.color = layoutProperty->GetSelectedBackgroundColorValue(); + result2.color = TextPickerModelNG::GetSelectedBackgroundStyle(frameNode).color; + EXPECT_EQ(newColor, result1.color); + EXPECT_EQ(newColor, result2.color); + EXPECT_NE(newColor, pickerBgStyle.color); +} + } // namespace OHOS::Ace::NG \ No newline at end of file -- Gitee