diff --git a/frameworks/bridge/declarative_frontend/jsview/js_popups.cpp b/frameworks/bridge/declarative_frontend/jsview/js_popups.cpp index efa62cc749ee596f26c39effaca5cab20747df64..ecb4e9037997db855ef8e726117df5d6a739e9a4 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_popups.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_popups.cpp @@ -1956,8 +1956,17 @@ void JSViewAbstract::ParseModalStyle(const JSRef& paramObj, NG::ModalS ParseModalTransition(modalTransitionValue, modalStyle.modalTransition, NG::ModalTransition::DEFAULT); auto backgroundColor = paramObj->GetProperty("backgroundColor"); Color color; - if (ParseJsColor(backgroundColor, color)) { - modalStyle.backgroundColor = color; + if (SystemProperties::ConfigChangePerform()) { + // When the switch is turned on, the modal background color and its resource are parsed together. + RefPtr resObj; + if (ParseJsColor(backgroundColor, color, resObj)) { + modalStyle.SetBackgroundColorResObj(resObj); + modalStyle.backgroundColor = color; + } + } else { + if (ParseJsColor(backgroundColor, color)) { + modalStyle.backgroundColor = color; + } } } @@ -2120,7 +2129,7 @@ void JSViewAbstract::ParseSheetStyle( } std::vector detents; - if (ParseSheetDetents(sheetDetents, detents)) { + if (ParseSheetDetents(sheetDetents, detents, sheetStyle)) { sheetStyle.detents = detents; } BlurStyleOption styleOption; @@ -2163,6 +2172,15 @@ void JSViewAbstract::ParseSheetStyle( bool showClose = true; if (NG::SheetType::SHEET_CONTENT_COVER == sheetStyle.sheetType) { sheetStyle.showCloseIcon = false; + } else if (SystemProperties::ConfigChangePerform()) { + // When the switch is turned on, the sheet closeIcon and its resource are parsed together. + RefPtr resObj; + if (ParseJsBool(showCloseIcon, showClose, resObj)) { + sheetStyle.showCloseIcon = showClose; + sheetStyle.SetShowCloseResObj(resObj); + } else if (!isPartialUpdate) { + sheetStyle.showCloseIcon = true; + } } else { if (ParseJsBool(showCloseIcon, showClose)) { sheetStyle.showCloseIcon = showClose; @@ -2208,37 +2226,88 @@ void JSViewAbstract::ParseSheetStyle( } Color color; - if (ParseJsColor(backgroundColor, color)) { - sheetStyle.backgroundColor = color; + if (SystemProperties::ConfigChangePerform()) { + // When the switch is turned on, the sheet background color and its resource are parsed together. + RefPtr resObj; + if (ParseJsColor(backgroundColor, color, resObj)) { + sheetStyle.backgroundColor = color; + sheetStyle.SetBackgroundColorResObj(resObj); + } + } else { + if (ParseJsColor(backgroundColor, color)) { + sheetStyle.backgroundColor = color; + } } // parse maskColor Color parseMaskColor; - if (!maskColor->IsNull() && !maskColor->IsUndefined() && JSViewAbstract::ParseJsColor(maskColor, parseMaskColor)) { - sheetStyle.maskColor = std::move(parseMaskColor); + if (SystemProperties::ConfigChangePerform()) { + // When the switch is turned on, the sheet maskColor and its resource are parsed together. + RefPtr resObj; + if (!maskColor->IsNull() && !maskColor->IsUndefined() && + JSViewAbstract::ParseJsColor(maskColor, parseMaskColor, resObj)) { + sheetStyle.maskColor = std::move(parseMaskColor); + sheetStyle.SetMaskColorResObj(resObj); + } + } else { + if (!maskColor->IsNull() && !maskColor->IsUndefined() && + JSViewAbstract::ParseJsColor(maskColor, parseMaskColor)) { + sheetStyle.maskColor = std::move(parseMaskColor); + } } // Parse border width auto borderWidthValue = paramObj->GetProperty("borderWidth"); NG::BorderWidthProperty borderWidth; - if (ParseBorderWidthProps(borderWidthValue, borderWidth)) { - sheetStyle.borderWidth = borderWidth; - // Parse border color - auto colorValue = paramObj->GetProperty("borderColor"); - NG::BorderColorProperty borderColor; - if (ParseBorderColorProps(colorValue, borderColor)) { - sheetStyle.borderColor = borderColor; - } else { - sheetStyle.borderColor = - NG::BorderColorProperty({ Color::BLACK, Color::BLACK, Color::BLACK, Color::BLACK }); + if (SystemProperties::ConfigChangePerform()) { + // When the switch is turned on, the sheet borderWidth and its resource are parsed together. + RefPtr borderWidthResObj; + if (ParseBorderWidthProps(borderWidthValue, borderWidth, borderWidthResObj)) { + sheetStyle.borderWidth = borderWidth; + sheetStyle.SetBorderWidthResObj(borderWidthResObj); + + // When the switch is turned on, the sheet borderColor and its resource are parsed together, + // when borderWidth and borderColor are set at the same time. + auto colorValue = paramObj->GetProperty("borderColor"); + NG::BorderColorProperty borderColor; + RefPtr borderColorResObj; + if (ParseBorderColorProps(colorValue, borderColor, borderColorResObj)) { + sheetStyle.borderColor = borderColor; + } else { + sheetStyle.borderColor = + NG::BorderColorProperty({ Color::BLACK, Color::BLACK, Color::BLACK, Color::BLACK }); + } + sheetStyle.SetBorderColorResObj(borderColorResObj); + // Parse border style + auto styleValue = paramObj->GetProperty("borderStyle"); + NG::BorderStyleProperty borderStyle; + if (ParseBorderStyleProps(styleValue, borderStyle)) { + sheetStyle.borderStyle = borderStyle; + } else { + sheetStyle.borderStyle = NG::BorderStyleProperty( + { BorderStyle::SOLID, BorderStyle::SOLID, BorderStyle::SOLID, BorderStyle::SOLID }); + } } - // Parse border style - auto styleValue = paramObj->GetProperty("borderStyle"); - NG::BorderStyleProperty borderStyle; - if (ParseBorderStyleProps(styleValue, borderStyle)) { - sheetStyle.borderStyle = borderStyle; - } else { - sheetStyle.borderStyle = NG::BorderStyleProperty( - { BorderStyle::SOLID, BorderStyle::SOLID, BorderStyle::SOLID, BorderStyle::SOLID }); + } else { + if (ParseBorderWidthProps(borderWidthValue, borderWidth)) { + sheetStyle.borderWidth = borderWidth; + // Parse border color + auto colorValue = paramObj->GetProperty("borderColor"); + NG::BorderColorProperty borderColor; + if (ParseBorderColorProps(colorValue, borderColor)) { + sheetStyle.borderColor = borderColor; + } else { + sheetStyle.borderColor = + NG::BorderColorProperty({ Color::BLACK, Color::BLACK, Color::BLACK, Color::BLACK }); + } + // Parse border style + auto styleValue = paramObj->GetProperty("borderStyle"); + NG::BorderStyleProperty borderStyle; + if (ParseBorderStyleProps(styleValue, borderStyle)) { + sheetStyle.borderStyle = borderStyle; + } else { + sheetStyle.borderStyle = NG::BorderStyleProperty( + { BorderStyle::SOLID, BorderStyle::SOLID, BorderStyle::SOLID, BorderStyle::SOLID }); + } } } if (isPartialUpdate) { @@ -2283,17 +2352,41 @@ void JSViewAbstract::ParseSheetStyle( auto widthValue = paramObj->GetProperty("width"); CalcDimension width; - if (ParseJsDimensionVpNG(widthValue, width, true)) { - sheetStyle.width = width; + if (SystemProperties::ConfigChangePerform()) { + // When the switch is turned on, the sheet width and its resource are parsed together. + RefPtr resObj; + if (ParseJsDimensionVpNG(widthValue, width, resObj, true)) { + sheetStyle.SetSheetWidthResObj(resObj); + sheetStyle.width = width; + } + } else { + if (ParseJsDimensionVpNG(widthValue, width, true)) { + sheetStyle.width = width; + } } auto radiusValue = paramObj->GetProperty("radius"); - JSViewAbstract::ParseBindSheetBorderRadius(radiusValue, sheetStyle); + if (SystemProperties::ConfigChangePerform()) { + // When the switch is turned on, the sheet radius and its resource are parsed together. + RefPtr resObj; + JSViewAbstract::ParseBindSheetBorderRadius(radiusValue, sheetStyle, resObj); + sheetStyle.SetRadiusResObj(resObj); + } else { + JSViewAbstract::ParseBindSheetBorderRadius(radiusValue, sheetStyle); + } ParseDetentSelection(paramObj, sheetStyle); NG::SheetHeight sheetStruct; - bool parseResult = ParseSheetHeight(height, sheetStruct, isPartialUpdate); + bool parseResult; + if (SystemProperties::ConfigChangePerform()) { + // When the switch is turned on, the sheet height and its resource are parsed together. + RefPtr heightResObj; + parseResult = ParseSheetHeight(height, sheetStruct, isPartialUpdate, heightResObj); + sheetStyle.SetSheetHeightResObj(heightResObj); + } else { + parseResult = ParseSheetHeight(height, sheetStruct, isPartialUpdate); + } if (!parseResult) { TAG_LOGD(AceLogTag::ACE_SHEET, "parse sheet height in unnormal condition"); } @@ -2333,7 +2426,15 @@ void JSViewAbstract::ParseDetentSelection(const JSRef& paramObj, NG::S { auto detentSelection = paramObj->GetProperty("detentSelection"); NG::SheetHeight sheetStruct; - bool parseResult = ParseSheetHeight(detentSelection, sheetStruct, true); + bool parseResult; + if (SystemProperties::ConfigChangePerform()) { + // When the switch is turned on, the sheet detentSelection and its resource are parsed together. + RefPtr resObj; + parseResult = ParseSheetHeight(detentSelection, sheetStruct, true, resObj); + sheetStyle.SetDetentSelectionResObj(resObj); + } else { + parseResult = ParseSheetHeight(detentSelection, sheetStruct, true); + } if (!parseResult) { sheetStruct.height.reset(); sheetStruct.sheetMode.reset(); @@ -2341,16 +2442,26 @@ void JSViewAbstract::ParseDetentSelection(const JSRef& paramObj, NG::S } sheetStyle.detentSelection = sheetStruct; } - -bool JSViewAbstract::ParseSheetDetents(const JSRef& args, std::vector& sheetDetents) + +bool JSViewAbstract::ParseSheetDetents(const JSRef& args, + std::vector& sheetDetents, NG::SheetStyle& sheetStyle) { if (!args->IsArray()) { return false; } JSRef array = JSRef::Cast(args); NG::SheetHeight sheetDetent; + std::vector> detentsResObj; for (size_t i = 0; i < array->Length(); i++) { - bool parseResult = ParseSheetHeight(array->GetValueAt(i), sheetDetent, false); + bool parseResult; + if (SystemProperties::ConfigChangePerform()) { + // When the switch is turned on, the sheet detents and its resource are parsed together. + RefPtr resObj; + parseResult = ParseSheetHeight(array->GetValueAt(i), sheetDetent, false, resObj); + detentsResObj.push_back(resObj); + } else { + parseResult = ParseSheetHeight(array->GetValueAt(i), sheetDetent, false); + } if (!parseResult) { TAG_LOGD(AceLogTag::ACE_SHEET, "parse sheet detent in unnormal condition"); } @@ -2361,6 +2472,9 @@ bool JSViewAbstract::ParseSheetDetents(const JSRef& args, std::vectorGetProperty("title"); auto sheetSubtitle = obj->GetProperty("subtitle"); - if (ParseJsString(sheetTitle, mainTitle)) { - sheetStyle.sheetTitle = mainTitle; - } - if (ParseJsString(sheetSubtitle, subtitle)) { - sheetStyle.sheetSubtitle = subtitle; + if (SystemProperties::ConfigChangePerform()) { + // When the switch is turned on, the sheet title and its resource are parsed together. + RefPtr mainTitleResObj; + if (ParseJsString(sheetTitle, mainTitle, mainTitleResObj)) { + sheetStyle.sheetTitle = mainTitle; + sheetStyle.SetMainTitleResObj(mainTitleResObj); + } + + // When the switch is turned on, the sheet subtitle and its resource are parsed together, + // when title and subtitle are set at the same time. + RefPtr subTitleResObj; + if (ParseJsString(sheetSubtitle, subtitle, subTitleResObj)) { + sheetStyle.sheetSubtitle = subtitle; + sheetStyle.SetSubTitleResObj(subTitleResObj); + } + } else { + if (ParseJsString(sheetTitle, mainTitle)) { + sheetStyle.sheetTitle = mainTitle; + } + if (ParseJsString(sheetSubtitle, subtitle)) { + sheetStyle.sheetSubtitle = subtitle; + } } } } @@ -2552,6 +2683,13 @@ bool JSViewAbstract::ParseSheetMode(const std::string heightStr, NG::SheetHeight bool JSViewAbstract::ParseSheetHeight(const JSRef& args, NG::SheetHeight& detent, bool isReset) +{ + RefPtr resObj; + return ParseSheetHeight(args, detent, isReset, resObj); +} + +bool JSViewAbstract::ParseSheetHeight(const JSRef& args, NG::SheetHeight& detent, + bool isReset, RefPtr& resObj) { detent.height.reset(); detent.sheetMode.reset(); @@ -2575,7 +2713,7 @@ bool JSViewAbstract::ParseSheetHeight(const JSRef& args, NG::SheetHeight& return false; } } - if (!ParseJsDimensionVpNG(args, sheetHeight)) { + if (!ParseJsDimensionVpNG(args, sheetHeight, resObj)) { if (!isReset) { auto sheetTheme = GetTheme(); detent.sheetMode = sheetTheme != nullptr diff --git a/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp b/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp index 4c396b8be33dabec15d595365245423e9b70c21e..56e8b8509c3ccc69d61f80898c020de7b53a09d7 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp @@ -1421,33 +1421,49 @@ void ParseEdgeWidthsProps(const JSRef& object, CommonCalcDimension& co bool notNegative, CalcDimension defaultValue) { CalcDimension left; - if (JSViewAbstract::ParseJsDimensionVpNG(object->GetProperty(LEFT_PROPERTY), left, true)) { + RefPtr leftResObj; + if (JSViewAbstract::ParseJsDimensionVpNG(object->GetProperty(LEFT_PROPERTY), left, leftResObj, true)) { CheckDimensionUnit(left, notPercent, notNegative); commonCalcDimension.left = left; } else { commonCalcDimension.left = defaultValue; } CalcDimension right; - if (JSViewAbstract::ParseJsDimensionVpNG(object->GetProperty(RIGHT_PROPERTY), right, true)) { + RefPtr rightResObj; + if (JSViewAbstract::ParseJsDimensionVpNG(object->GetProperty(RIGHT_PROPERTY), right, rightResObj, true)) { CheckDimensionUnit(right, notPercent, notNegative); commonCalcDimension.right = right; } else { commonCalcDimension.right = defaultValue; } CalcDimension top; - if (JSViewAbstract::ParseJsDimensionVpNG(object->GetProperty(TOP_PROPERTY), top, true)) { + RefPtr topResObj; + if (JSViewAbstract::ParseJsDimensionVpNG(object->GetProperty(TOP_PROPERTY), top, topResObj, true)) { CheckDimensionUnit(top, notPercent, notNegative); commonCalcDimension.top = top; } else { commonCalcDimension.top = defaultValue; } CalcDimension bottom; - if (JSViewAbstract::ParseJsDimensionVpNG(object->GetProperty(BOTTOM_PROPERTY), bottom, true)) { + RefPtr bottomResObj; + if (JSViewAbstract::ParseJsDimensionVpNG(object->GetProperty(BOTTOM_PROPERTY), bottom, bottomResObj, true)) { CheckDimensionUnit(bottom, false, true); commonCalcDimension.bottom = bottom; } else { commonCalcDimension.bottom = defaultValue; } + if (leftResObj) { + commonCalcDimension.leftResObj = leftResObj; + } + if (rightResObj) { + commonCalcDimension.rightResObj = rightResObj; + } + if (topResObj) { + commonCalcDimension.topResObj = topResObj; + } + if (bottomResObj) { + commonCalcDimension.bottomResObj = bottomResObj; + } } void ParseLocalizedEdgeWidths(const JSRef& object, LocalizedCalcDimension& localizedCalcDimension, @@ -1496,33 +1512,41 @@ void ParseLocalizedEdgeWidthsProps(const JSRef& object, LocalizedCalcD if (object->HasProperty(START_PROPERTY) && object->GetProperty(START_PROPERTY)->IsObject()) { JSRef startObj = JSRef::Cast(object->GetProperty(START_PROPERTY)); CalcDimension calcDimension; - if (ParseJsLengthMetrics(startObj, calcDimension)) { + RefPtr leftResObj; + if (JSViewAbstract::ParseJsLengthMetricsVpWithResObj(startObj, calcDimension, leftResObj)) { CheckDimensionUnit(calcDimension, false, true); localizedCalcDimension.start = calcDimension; + localizedCalcDimension.leftResObj = leftResObj; } } if (object->HasProperty(END_PROPERTY) && object->GetProperty(END_PROPERTY)->IsObject()) { JSRef endObj = JSRef::Cast(object->GetProperty(END_PROPERTY)); CalcDimension calcDimension; - if (ParseJsLengthMetrics(endObj, calcDimension)) { + RefPtr rightResObj; + if (JSViewAbstract::ParseJsLengthMetricsVpWithResObj(endObj, calcDimension, rightResObj)) { CheckDimensionUnit(calcDimension, false, true); localizedCalcDimension.end = calcDimension; + localizedCalcDimension.rightResObj = rightResObj; } } if (object->HasProperty(TOP_PROPERTY) && object->GetProperty(TOP_PROPERTY)->IsObject()) { JSRef topObj = JSRef::Cast(object->GetProperty(TOP_PROPERTY)); CalcDimension calcDimension; - if (ParseJsLengthMetrics(topObj, calcDimension)) { + RefPtr topResObj; + if (JSViewAbstract::ParseJsLengthMetricsVpWithResObj(topObj, calcDimension, topResObj)) { CheckDimensionUnit(calcDimension, false, true); localizedCalcDimension.top = calcDimension; + localizedCalcDimension.topResObj = topResObj; } } if (object->HasProperty(BOTTOM_PROPERTY) && object->GetProperty(BOTTOM_PROPERTY)->IsObject()) { JSRef bottomObj = JSRef::Cast(object->GetProperty(BOTTOM_PROPERTY)); CalcDimension calcDimension; - if (ParseJsLengthMetrics(bottomObj, calcDimension)) { + RefPtr bottomResObj; + if (JSViewAbstract::ParseJsLengthMetricsVpWithResObj(bottomObj, calcDimension, bottomResObj)) { CheckDimensionUnit(calcDimension, false, true); localizedCalcDimension.bottom = calcDimension; + localizedCalcDimension.bottomResObj = bottomResObj; } } } @@ -1570,6 +1594,10 @@ void ParseCommonEdgeWidthsProps(const JSRef& object, CommonCalcDimensi commonCalcDimension.bottom = localizedCalcDimension.bottom; commonCalcDimension.left = isRightToLeft ? localizedCalcDimension.end : localizedCalcDimension.start; commonCalcDimension.right = isRightToLeft ? localizedCalcDimension.start : localizedCalcDimension.end; + commonCalcDimension.leftResObj = isRightToLeft ? localizedCalcDimension.rightResObj : localizedCalcDimension.leftResObj; + commonCalcDimension.rightResObj = isRightToLeft ? localizedCalcDimension.leftResObj : localizedCalcDimension.rightResObj; + commonCalcDimension.topResObj = localizedCalcDimension.topResObj; + commonCalcDimension.bottomResObj = localizedCalcDimension.bottomResObj; return; } ParseEdgeWidthsProps(object, commonCalcDimension, false, true, 0.0_vp); @@ -1615,6 +1643,107 @@ void SetConstraintSize(const RefPtr& minWidthResObj, const RefPt ViewAbstractModel::GetInstance()->SetMaxHeight(maxHeightResObj); } } + +void RegisterBorderColorRes(NG::BorderColorProperty& colorProperty, + const CommonColor& commonColor, bool isLocalizedEdgeColor) +{ + if (!SystemProperties::ConfigChangePerform()) { + return; + } + if (commonColor.leftResObj) { + auto&& updateFunc = [isLocalizedEdgeColor](const RefPtr& resObj, NG::BorderColorProperty& borderColors) { + Color result; + ResourceParseUtils::ParseResColor(resObj, result); + isLocalizedEdgeColor ? (borderColors.startColor = result) : (borderColors.leftColor = result); + }; + colorProperty.AddResource("borderColor.start", commonColor.leftResObj, std::move(updateFunc)); + } else { + colorProperty.RemoveResource("borderColor.start"); + } + if (commonColor.rightResObj) { + auto&& updateFunc = [isLocalizedEdgeColor](const RefPtr& resObj, NG::BorderColorProperty& borderColors) { + Color result; + ResourceParseUtils::ParseResColor(resObj, result); + isLocalizedEdgeColor ? (borderColors.endColor = result) : (borderColors.rightColor = result); + }; + colorProperty.AddResource("borderColor.end", commonColor.rightResObj, std::move(updateFunc)); + } else { + colorProperty.RemoveResource("borderColor.end"); + } + if (commonColor.topResObj) { + auto&& updateFunc = [](const RefPtr& resObj, NG::BorderColorProperty& borderColors) { + Color result; + ResourceParseUtils::ParseResColor(resObj, result); + borderColors.topColor = result; + }; + colorProperty.AddResource("borderColor.top", commonColor.topResObj, std::move(updateFunc)); + } else { + colorProperty.RemoveResource("borderColor.top"); + } + if (commonColor.bottomResObj) { + auto&& updateFunc = [](const RefPtr& resObj, NG::BorderColorProperty& borderColors) { + Color result; + ResourceParseUtils::ParseResColor(resObj, result); + borderColors.bottomColor = result; + }; + colorProperty.AddResource("borderColor.bottom", commonColor.bottomResObj, std::move(updateFunc)); + } else { + colorProperty.RemoveResource("borderColor.bottom"); + } +} + +void RegisterRadiusRes(NG::BorderRadiusProperty& radius, + RefPtr topStartResObj, RefPtr topEndResObj, + RefPtr bottomStartResObj, RefPtr bottomEndResObj) +{ + if (!SystemProperties::ConfigChangePerform()) { + return; + } + if (topStartResObj) { + auto&& updateFunc = [](const RefPtr& resObj, NG::BorderRadiusProperty& radius) { + CalcDimension result; + ResourceParseUtils::ParseResDimensionVpNG(resObj, result); + radius.radiusTopLeft = result; + radius.multiValued = true; + }; + radius.AddResource("radius.topStart", topStartResObj, std::move(updateFunc)); + } else { + radius.RemoveResource("radius.topStart"); + } + if (topEndResObj) { + auto&& updateFunc = [](const RefPtr& resObj, NG::BorderRadiusProperty& radius) { + CalcDimension result; + ResourceParseUtils::ParseResDimensionVpNG(resObj, result); + radius.radiusTopRight = result; + radius.multiValued = true; + }; + radius.AddResource("radius.topEnd", topEndResObj, std::move(updateFunc)); + } else { + radius.RemoveResource("radius.topEnd"); + } + if (bottomStartResObj) { + auto&& updateFunc = [](const RefPtr& resObj, NG::BorderRadiusProperty& radius) { + CalcDimension result; + ResourceParseUtils::ParseResDimensionVpNG(resObj, result); + radius.radiusBottomRight = result; + radius.multiValued = true; + }; + radius.AddResource("radius.bottomStart", bottomStartResObj, std::move(updateFunc)); + } else { + radius.RemoveResource("radius.bottomStart"); + } + if (bottomEndResObj) { + auto&& updateFunc = [](const RefPtr& resObj, NG::BorderRadiusProperty& radius) { + CalcDimension result; + ResourceParseUtils::ParseResDimensionVpNG(resObj, result); + radius.radiusBottomLeft = result; + radius.multiValued = true; + }; + radius.AddResource("radius.bottomEnd", bottomEndResObj, std::move(updateFunc)); + } else { + radius.RemoveResource("radius.bottomEnd"); + } +} } // namespace RefPtr JSViewAbstract::GetResourceObject(const JSRef& jsObj) @@ -9041,6 +9170,13 @@ void JSViewAbstract::JsOnCrownEvent(const JSCallbackInfo& args) } void JSViewAbstract::ParseBindSheetBorderRadius(const JSRef& args, NG::SheetStyle& sheetStyle) +{ + RefPtr resObj; + ParseBindSheetBorderRadius(args, sheetStyle, resObj); +} + +void JSViewAbstract::ParseBindSheetBorderRadius(const JSRef& args, + NG::SheetStyle& sheetStyle, RefPtr& resourceObj) { if (!args->IsObject() && !args->IsNumber() && !args->IsString()) { TAG_LOGE(AceLogTag::ACE_SHEET, "radius is not correct type"); @@ -9048,8 +9184,11 @@ void JSViewAbstract::ParseBindSheetBorderRadius(const JSRef& args, NG::Sh } CalcDimension radius; NG::BorderRadiusProperty borderRadius; - if (ParseJsLengthMetrics(args, radius)) { + if (ParseJsLengthMetricsVpWithResObj(args, radius, resourceObj)) { borderRadius.SetRadius(radius); + + // multiValued: indicates whether to set multiple directions. The default value is false. + borderRadius.multiValued = false; sheetStyle.radius = borderRadius; } else if (ParseBindSheetBorderRadiusProps(args, borderRadius)) { sheetStyle.radius = borderRadius; @@ -9064,17 +9203,29 @@ bool JSViewAbstract::ParseBindSheetBorderRadiusProps(const JSRef& args, N if (args->IsObject()) { JSRef object = JSRef::Cast(args); if (CheckLengthMetrics(object)) { - std::optional radiusTopStart = ParseBindSheetBorderRadiusProp(object, TOP_START_PROPERTY); - std::optional radiusTopEnd = ParseBindSheetBorderRadiusProp(object, TOP_END_PROPERTY); + RefPtr topStartResObj; + std::optional radiusTopStart = + ParseBindSheetBorderRadiusProp(object, TOP_START_PROPERTY, topStartResObj); + RefPtr topEndResObj; + std::optional radiusTopEnd = + ParseBindSheetBorderRadiusProp(object, TOP_END_PROPERTY, topEndResObj); + RefPtr bottomStartResObj; std::optional radiusBottomStart = - ParseBindSheetBorderRadiusProp(object, BOTTOM_START_PROPERTY); - std::optional radiusBottomEnd = ParseBindSheetBorderRadiusProp(object, BOTTOM_END_PROPERTY); + ParseBindSheetBorderRadiusProp(object, BOTTOM_START_PROPERTY, bottomStartResObj); + RefPtr bottomEndResObj; + std::optional radiusBottomEnd = + ParseBindSheetBorderRadiusProp(object, BOTTOM_END_PROPERTY, bottomEndResObj); auto isRightToLeft = AceApplicationInfo::GetInstance().IsRightToLeft(); radius.radiusTopLeft = isRightToLeft ? radiusTopEnd : radiusTopStart; radius.radiusTopRight = isRightToLeft ? radiusTopStart : radiusTopEnd; radius.radiusBottomLeft = isRightToLeft ? radiusBottomEnd : radiusBottomStart; radius.radiusBottomRight = isRightToLeft ? radiusBottomStart : radiusBottomEnd; radius.multiValued = true; + if (isRightToLeft) { + RegisterRadiusRes(radius, topEndResObj, topStartResObj, bottomEndResObj, bottomStartResObj); + } else { + RegisterRadiusRes(radius, topStartResObj, topEndResObj, bottomStartResObj, bottomEndResObj); + } } else { ParseBorderRadiusProps(object, radius); } @@ -9084,7 +9235,7 @@ bool JSViewAbstract::ParseBindSheetBorderRadiusProps(const JSRef& args, N } std::optional JSViewAbstract::ParseBindSheetBorderRadiusProp( - const JSRef& object, const char* prop) + const JSRef& object, const char* prop, RefPtr& resourceObj) { if (object->IsEmpty()) { return std::nullopt; @@ -9092,7 +9243,7 @@ std::optional JSViewAbstract::ParseBindSheetBorderRadiusProp( if (object->HasProperty(prop) && object->GetProperty(prop)->IsObject()) { JSRef propObj = JSRef::Cast(object->GetProperty(prop)); CalcDimension calcDimension; - if (ParseJsLengthMetrics(propObj, calcDimension)) { + if (ParseJsLengthMetricsVpWithResObj(propObj, calcDimension, resourceObj)) { return calcDimension; } } @@ -11648,6 +11799,13 @@ void JSViewAbstract::GetBorderColorsFromResource(const JSRef& args, NG::B } bool JSViewAbstract::ParseBorderColorProps(const JSRef& args, NG::BorderColorProperty& colorProperty) +{ + RefPtr resourceObj; + return ParseBorderColorProps(args, colorProperty, resourceObj); +} + +bool JSViewAbstract::ParseBorderColorProps(const JSRef& args, + NG::BorderColorProperty& colorProperty, RefPtr& resourceObj) { if (!args->IsObject() && !args->IsNumber() && !args->IsString()) { return false; @@ -11657,7 +11815,7 @@ bool JSViewAbstract::ParseBorderColorProps(const JSRef& args, NG::BorderC return true; } Color borderColor; - if (ParseJsColor(args, borderColor)) { + if (ParseJsColor(args, borderColor, resourceObj)) { colorProperty.SetColor(borderColor); return true; } else if (args->IsObject()) { @@ -11674,12 +11832,20 @@ bool JSViewAbstract::ParseBorderColorProps(const JSRef& args, NG::BorderC colorProperty.rightColor = commonColor.right; } colorProperty.multiValued = true; + RegisterBorderColorRes(colorProperty, commonColor, isLocalizedEdgeColor); return true; } return false; } bool JSViewAbstract::ParseBorderWidthProps(const JSRef& args, NG::BorderWidthProperty& borderWidthProperty) +{ + RefPtr resourceObj; + return ParseBorderWidthProps(args, borderWidthProperty, resourceObj); +} + +bool JSViewAbstract::ParseBorderWidthProps(const JSRef& args, + NG::BorderWidthProperty& borderWidthProperty, RefPtr& resourceObj) { if (!args->IsObject() && !args->IsNumber() && !args->IsString()) { return false; @@ -11689,7 +11855,7 @@ bool JSViewAbstract::ParseBorderWidthProps(const JSRef& args, NG::BorderW return true; } CalcDimension borderWidth; - if (ParseJsDimensionVpNG(args, borderWidth, true)) { + if (ParseJsDimensionVpNG(args, borderWidth, resourceObj, true)) { if (borderWidth.IsNegative()) { borderWidth.Reset(); } @@ -11705,6 +11871,11 @@ bool JSViewAbstract::ParseBorderWidthProps(const JSRef& args, NG::BorderW borderWidthProperty.leftDimen = commonCalcDimension.left; borderWidthProperty.rightDimen = commonCalcDimension.right; borderWidthProperty.multiValued = true; + if (SystemProperties::ConfigChangePerform()) { + ParseEdgeWidthsResObjFunc(borderWidthProperty, + commonCalcDimension.leftResObj, commonCalcDimension.rightResObj, + commonCalcDimension.topResObj, commonCalcDimension.bottomResObj); + } return true; } return false; @@ -11751,19 +11922,23 @@ void JSViewAbstract::ParseBorderRadiusProps(const JSRef& object, NG::B std::optional radiusBottomLeft; std::optional radiusBottomRight; CalcDimension topLeft; - if (ParseJsDimensionVpNG(object->GetProperty("topLeft"), topLeft, true)) { + RefPtr topStartResObj; + if (ParseJsDimensionVpNG(object->GetProperty("topLeft"), topLeft, topStartResObj, true)) { radiusTopLeft = topLeft; } CalcDimension topRight; - if (ParseJsDimensionVpNG(object->GetProperty("topRight"), topRight, true)) { + RefPtr topEndResObj; + if (ParseJsDimensionVpNG(object->GetProperty("topRight"), topRight, topEndResObj, true)) { radiusTopRight = topRight; } CalcDimension bottomLeft; - if (ParseJsDimensionVpNG(object->GetProperty("bottomLeft"), bottomLeft, true)) { + RefPtr bottomStartResObj; + if (ParseJsDimensionVpNG(object->GetProperty("bottomLeft"), bottomLeft, bottomStartResObj, true)) { radiusBottomLeft = bottomLeft; } CalcDimension bottomRight; - if (ParseJsDimensionVpNG(object->GetProperty("bottomRight"), bottomRight, true)) { + RefPtr bottomEndResObj; + if (ParseJsDimensionVpNG(object->GetProperty("bottomRight"), bottomRight, bottomEndResObj, true)) { radiusBottomRight = bottomRight; } CheckLengthMetrics(object); @@ -11772,6 +11947,7 @@ void JSViewAbstract::ParseBorderRadiusProps(const JSRef& object, NG::B radius.radiusBottomLeft = radiusBottomLeft; radius.radiusBottomRight = radiusBottomRight; radius.multiValued = true; + RegisterRadiusRes(radius, topStartResObj, topEndResObj, bottomStartResObj, bottomEndResObj); return; } diff --git a/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h b/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h index 6b0050cea6b070e1e4bd1d434256f442d3bd2274..013778e2583a441be87533b4532ce27b1858ae26 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h +++ b/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h @@ -72,6 +72,10 @@ struct LocalizedCalcDimension { std::optional end; std::optional top; std::optional bottom; + RefPtr leftResObj; + RefPtr rightResObj; + RefPtr topResObj; + RefPtr bottomResObj; }; struct CommonCalcDimension { @@ -225,11 +229,17 @@ public: const JSRef& paramObj, NG::SheetStyle& sheetStyle, bool isPartialUpdate = false); static NG::SheetEffectEdge ParseSheetEffectEdge(const JSRef& paramObj); static void ParseBindSheetBorderRadius(const JSRef& args, NG::SheetStyle& sheetStyle); + static void ParseBindSheetBorderRadius(const JSRef& args, + NG::SheetStyle& sheetStyle, RefPtr& resourceObj); static bool ParseBindSheetBorderRadiusProps(const JSRef& args, NG::BorderRadiusProperty& radius); - static std::optional ParseBindSheetBorderRadiusProp(const JSRef& object, const char* prop); + static std::optional ParseBindSheetBorderRadiusProp(const JSRef& object, + const char* prop, RefPtr& resourceObj); static bool ParseSheetMode(const std::string heightStr, NG::SheetHeight& detent); - static bool ParseSheetDetents(const JSRef& args, std::vector& sheetDetents); + static bool ParseSheetDetents(const JSRef& args, + std::vector& sheetDetents, NG::SheetStyle& sheetStyle); static bool ParseSheetHeight(const JSRef& args, NG::SheetHeight& detent, bool isReset); + static bool ParseSheetHeight(const JSRef& args, + NG::SheetHeight& detent, bool isReset, RefPtr& resObj); static bool ParseSheetBackgroundBlurStyle(const JSRef& args, BlurStyleOption& blurStyleOptions); static bool ParseSheetLevel(const JSRef& args, NG::SheetLevel& sheetLevel); static void ParseCallback(const JSRef& paramObj, @@ -805,6 +815,8 @@ public: bool enableResourceUpdate = false, std::vector>>& resObjArr = DEFAULT_RESOURCE_PAIR_ARRAY); static bool ParseBorderWidthProps(const JSRef& args, NG::BorderWidthProperty& borderWidthProperty); + static bool ParseBorderWidthProps(const JSRef& args, + NG::BorderWidthProperty& borderWidthProperty, RefPtr& resourceObj); static bool ParseBorderColorProps(const JSRef& args, NG::BorderColorProperty& colorProperty); static bool ParseBorderStyleProps(const JSRef& args, NG::BorderStyleProperty& borderStyleProperty); static bool ParseBorderRadius(const JSRef& args, NG::BorderRadiusProperty& radius, bool notNegative = true); @@ -918,6 +930,8 @@ private: static void SetBorderColorProps(const Color& color, NG::BorderColorProperty& props, const char* corner); static void ParseBorderColorProps( const JSRef& object, NG::BorderColorProperty& props, const char* propName); + static bool ParseBorderColorProps(const JSRef& args, + NG::BorderColorProperty& colorProperty, RefPtr& resourceObj); static void GetBorderColors(const JSRef& object, NG::BorderColorProperty& borderColor); static void GetBorderColorsFromResource(const JSRef& args, NG::BorderColorProperty& colorProperty); static void SetBorderRadiusProps(const CalcDimension& dim, NG::BorderRadiusProperty& props, const char* propName); diff --git a/frameworks/core/components_ng/pattern/BUILD.gn b/frameworks/core/components_ng/pattern/BUILD.gn index 64d39e24479e33d4d25f69ca421297831eda3a1e..56c3f561239fe5c0bb834dab9658b8f3a4e2f585 100644 --- a/frameworks/core/components_ng/pattern/BUILD.gn +++ b/frameworks/core/components_ng/pattern/BUILD.gn @@ -326,6 +326,7 @@ build_component_ng("pattern_ng") { "overlay/sheet_view.cpp", "overlay/sheet_wrapper_layout_algorithm.cpp", "overlay/sheet_wrapper_paint_method.cpp", + "overlay/sheet_wrapper_pattern.cpp", "panel/close_icon_layout_algorithm.cpp", "panel/close_icon_pattern.cpp", "panel/drag_bar_layout_algorithm.cpp", diff --git a/frameworks/core/components_ng/pattern/overlay/modal_presentation_pattern.cpp b/frameworks/core/components_ng/pattern/overlay/modal_presentation_pattern.cpp index dbbbd2502c980cff573a4a3c15fe78d2f4959970..6bbaa2a898e262f407c1133f8fec6d43491f3f68 100644 --- a/frameworks/core/components_ng/pattern/overlay/modal_presentation_pattern.cpp +++ b/frameworks/core/components_ng/pattern/overlay/modal_presentation_pattern.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +#include "core/common/resource/resource_parse_utils.h" #include "core/components_ng/pattern/overlay/modal_presentation_pattern.h" #include "core/components_ng/pattern/navigation/navigation_declaration.h" @@ -81,4 +82,31 @@ void ModalPresentationPattern::BeforeCreateLayoutWrapper() modalNodeLayoutProperty->ResetSafeAreaPadding(); ContentRootPattern::BeforeCreateLayoutWrapper(); } + +void ModalPresentationPattern::RegisterModalBgColorResFunc( + const RefPtr& modalNode, NG::ModalStyle& modalStyle) +{ + CHECK_NULL_VOID(modalNode); + auto pattern = modalNode->GetPattern(); + CHECK_NULL_VOID(pattern); + auto resObj = modalStyle.GetBackgroundColorResObj(); + if (resObj) { + auto modalWK = AceType::WeakClaim(AceType::RawPtr(modalNode)); + auto&& updateFunc = [modalWK](const RefPtr& resObj) { + auto modalNode = modalWK.Upgrade(); + CHECK_NULL_VOID(modalNode); + Color backgroundColor; + + // Reparse modal background color and update it. + bool result = ResourceParseUtils::ParseResColor(resObj, backgroundColor); + CHECK_NULL_VOID(result); + auto renderContext = modalNode->GetRenderContext(); + CHECK_NULL_VOID(renderContext); + renderContext->UpdateBackgroundColor(backgroundColor); + }; + pattern->AddResObj("modalPage.backgroundColor", resObj, std::move(updateFunc)); + } else { + pattern->RemoveResObj("modalPage.backgroundColor"); + } +} } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/overlay/modal_presentation_pattern.h b/frameworks/core/components_ng/pattern/overlay/modal_presentation_pattern.h index 477ccbb7507348576c8613358019e16dbb08caa7..fa89a58503901cadb80e55c653449deaf0796efa 100644 --- a/frameworks/core/components_ng/pattern/overlay/modal_presentation_pattern.h +++ b/frameworks/core/components_ng/pattern/overlay/modal_presentation_pattern.h @@ -194,6 +194,9 @@ public: return !isUIExtension_; } + void RegisterModalBgColorResFunc(const RefPtr& modalNode, + NG::ModalStyle& modalStyle); + bool TriggerAutoSaveWhenInvisible() override { return true; diff --git a/frameworks/core/components_ng/pattern/overlay/modal_style.h b/frameworks/core/components_ng/pattern/overlay/modal_style.h index 6d1597c3b39b7822cc0be4eeac2adb918707717c..fc5e34b1dbe071b2351adce216e91777da954550 100644 --- a/frameworks/core/components_ng/pattern/overlay/modal_style.h +++ b/frameworks/core/components_ng/pattern/overlay/modal_style.h @@ -19,6 +19,7 @@ #include #include "core/components/common/properties/color.h" +#include "core/common/resource/resource_object.h" namespace OHOS::Ace::NG { enum ModalTransition { @@ -44,6 +45,18 @@ struct ModalStyle { isAllowAddChildBelowModalUec != modelStyle.isAllowAddChildBelowModalUec || prohibitedRemoveByNavigation != modelStyle.prohibitedRemoveByNavigation); } + + void SetBackgroundColorResObj(RefPtr& obj) + { + backgroundColorObj_ = obj; + } + + const RefPtr& GetBackgroundColorResObj() + { + return backgroundColorObj_; + } + + RefPtr backgroundColorObj_; }; } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp b/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp index c06847fb5428179d09209bb006b68cb20b3383a5..9cfe23d18886594ef8c8d595614fffeafbd9dbec 100644 --- a/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp +++ b/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp @@ -45,6 +45,7 @@ #include "core/common/interaction/interaction_interface.h" #include "core/common/modal_ui_extension.h" #include "core/common/recorder/event_recorder.h" +#include "core/common/resource/resource_parse_utils.h" #include "core/components/common/properties/color.h" #include "core/components/select/select_theme.h" #include "core/components/text_overlay/text_overlay_theme.h" @@ -5003,11 +5004,16 @@ void OverlayManager::HandleModalShow(std::function&& c AceType::MakeRefPtr( targetId, static_cast(modalTransition.value()), std::move(callback))); CHECK_NULL_VOID(modalNode); + auto modalPagePattern = modalNode->GetPattern(); + CHECK_NULL_VOID(modalPagePattern); if (modalStyle.backgroundColor.has_value()) { + // When the background color is configured and the switch is enabled, + // register modal resource update func. + if (SystemProperties::ConfigChangePerform()) { + modalPagePattern->RegisterModalBgColorResFunc(modalNode, modalStyle); + } modalNode->GetRenderContext()->UpdateBackgroundColor(modalStyle.backgroundColor.value()); } - auto modalPagePattern = modalNode->GetPattern(); - CHECK_NULL_VOID(modalPagePattern); modalPagePattern->UpdateOnDisappear(std::move(onDisappear)); modalPagePattern->UpdateOnWillDisappear(std::move(onWillDisappear)); modalPagePattern->UpdateOnAppear(std::move(onAppear)); @@ -5854,6 +5860,34 @@ void OverlayManager::UpdateSheetPage(const RefPtr& sheetNode, const N } } +void OverlayManager::UpdateSheetPage(const RefPtr& sheetNode, const NG::SheetStyle& sheetStyle) +{ + auto sheetNodePattern = sheetNode->GetPattern(); + CHECK_NULL_VOID(sheetNodePattern); + + sheetNodePattern->IsNeedPlayTransition(sheetStyle); + auto layoutProperty = sheetNode->GetLayoutProperty(); + layoutProperty->UpdateSheetStyle(sheetStyle); + UpdateSheetProperty(sheetNode, sheetStyle, false); + sheetNodePattern->SetBottomOffset(sheetStyle); + sheetNode->MarkModifyDone(); + auto pipeline = sheetNode->GetContext(); + CHECK_NULL_VOID(pipeline); + sheetNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF); + auto sheetWrapper = sheetNode->GetParent(); + CHECK_NULL_VOID(sheetWrapper); + sheetWrapper->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF); + ComputeSheetOffset(sheetStyle, sheetNode); + + // The animation generated by the developer actively switching the SheetType, does not rely on PlaySheetTransition, + // but on the above FlushUITasks, and ondirty. + auto sheetType = sheetNodePattern->GetSheetType(); + if (sheetType != SheetType::SHEET_POPUP && !sheetNodePattern->GetDismissProcess() && + sheetNodePattern->GetIsPlayTransition()) { + PlaySheetTransition(sheetNode, true, false); + } +} + SheetStyle OverlayManager::UpdateSheetStyle( const RefPtr& sheetNode, const SheetStyle& sheetStyle, bool isPartialUpdate) { @@ -5919,6 +5953,10 @@ void OverlayManager::OnBindSheetInner(std::function&& InitSheetWrapperAction(sheetNode, targetNode, sheetStyle); auto sheetNodePattern = sheetNode->GetPattern(); CHECK_NULL_VOID(sheetNodePattern); + if (SystemProperties::ConfigChangePerform()) { + // Register the resource update function as required during sheet node creation. + sheetNodePattern->UpdateSheetParamResource(sheetNode, sheetStyle); + } sheetNodePattern->UpdateIndexByDetentSelection(sheetStyle, true); ComputeSheetOffset(sheetStyle, sheetNode); sheetNodePattern->OnWillAppear(); @@ -5958,6 +5996,10 @@ RefPtr OverlayManager::MountSheetWrapperAndChildren(const RefPtrMountToParent(sheetWrapperNode); auto sheetWrapperPattern = sheetWrapperNode->GetPattern(); CHECK_NULL_RETURN(sheetWrapperPattern, nullptr); + if (SystemProperties::ConfigChangePerform()) { + // Register the resource update function as required during sheet mask node creation. + sheetWrapperPattern->UpdateSheetMaskResource(sheetWrapperNode, sheetNode, sheetStyle); + } sheetWrapperPattern->SetSheetPageNode(sheetNode); auto levelOrder = GetLevelOrder(sheetWrapperNode); MountToParentWithService(rootNode, sheetWrapperNode, levelOrder); @@ -6064,7 +6106,7 @@ void OverlayManager::UpdateSheetMask(const RefPtr& maskNode, { auto maskRenderContext = maskNode->GetRenderContext(); CHECK_NULL_VOID(maskRenderContext); - auto pipeline = PipelineContext::GetCurrentContext(); + auto pipeline = maskNode->GetContext(); CHECK_NULL_VOID(pipeline); auto sheetTheme = pipeline->GetTheme(); CHECK_NULL_VOID(sheetTheme); diff --git a/frameworks/core/components_ng/pattern/overlay/overlay_manager.h b/frameworks/core/components_ng/pattern/overlay/overlay_manager.h index 158a0f5c0db130bd2c498ddc1b20d3ca85298690..943a87f19abaf6b8cd0a644e2d451a8de6209f2c 100644 --- a/frameworks/core/components_ng/pattern/overlay/overlay_manager.h +++ b/frameworks/core/components_ng/pattern/overlay/overlay_manager.h @@ -748,6 +748,8 @@ public: return overlayInfo_; } + void UpdateSheetPage(const RefPtr& sheetNode, const NG::SheetStyle& sheetStyle); + RefPtr GetDialogNodeWithExistContent(const RefPtr& node); OffsetF CalculateMenuPosition(const RefPtr& menuWrapperNode, const OffsetF& offset); BorderRadiusProperty GetPrepareDragFrameNodeBorderRadius() const; diff --git a/frameworks/core/components_ng/pattern/overlay/sheet_presentation_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/overlay/sheet_presentation_layout_algorithm.cpp index 11ba7b308a8f76da3ae28de1591af04eb7e0077f..6f5393303dff494fca2f5b6b8556a350e2b2f5ee 100755 --- a/frameworks/core/components_ng/pattern/overlay/sheet_presentation_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/overlay/sheet_presentation_layout_algorithm.cpp @@ -468,8 +468,6 @@ void SheetPresentationLayoutAlgorithm::LayoutDragBar(const NG::OffsetF& translat void SheetPresentationLayoutAlgorithm::Layout(LayoutWrapper* layoutWrapper) { CHECK_NULL_VOID(layoutWrapper); - const auto& pipeline = PipelineContext::GetCurrentContext(); - CHECK_NULL_VOID(pipeline); sheetOffsetX_ = (sheetMaxWidth_ - sheetWidth_) / DOUBLE_SIZE; if (sheetType_ == SheetType::SHEET_BOTTOMLANDSPACE) { sheetOffsetX_ = (sheetMaxWidth_ - sheetWidth_) / DOUBLE_SIZE; @@ -493,7 +491,7 @@ void SheetPresentationLayoutAlgorithm::Layout(LayoutWrapper* layoutWrapper) geometryNode->SetMarginFrameOffset(positionOffset); OffsetF translate(0.0f, 0.0f); if (sheetType_ == SheetType::SHEET_POPUP) { - UpdateTranslateOffsetWithPlacement(translate); + UpdateTranslateOffsetWithPlacement(translate, layoutWrapper); } LayoutCloseIcon(translate, layoutWrapper); LayoutDragBar(translate, layoutWrapper); @@ -501,9 +499,12 @@ void SheetPresentationLayoutAlgorithm::Layout(LayoutWrapper* layoutWrapper) LayoutScrollNode(translate, layoutWrapper); } -void SheetPresentationLayoutAlgorithm::UpdateTranslateOffsetWithPlacement(OffsetF& translate) +void SheetPresentationLayoutAlgorithm::UpdateTranslateOffsetWithPlacement(OffsetF& translate, + LayoutWrapper* layoutWrapper) { - if (Container::LessThanAPITargetVersion(PlatformVersion::VERSION_EIGHTEEN)) { + auto host = layoutWrapper->GetHostNode(); + CHECK_NULL_VOID(host); + if (host->LessThanAPITargetVersion(PlatformVersion::VERSION_EIGHTEEN)) { translate += OffsetF(0, SHEET_ARROW_HEIGHT.ConvertToPx()); return; } @@ -700,7 +701,9 @@ LayoutConstraintF SheetPresentationLayoutAlgorithm::CreateSheetChildConstraint( RefPtr layoutprop, LayoutWrapper* layoutWrapper) { auto childConstraint = layoutprop->CreateChildConstraint(); - auto pipeline = PipelineContext::GetCurrentContext(); + auto host = layoutWrapper->GetHostNode(); + CHECK_NULL_RETURN(host, childConstraint); + auto pipeline = host->GetContext(); CHECK_NULL_RETURN(pipeline, childConstraint); auto sheetTheme = pipeline->GetTheme(); CHECK_NULL_RETURN(sheetTheme, childConstraint); @@ -709,8 +712,6 @@ LayoutConstraintF SheetPresentationLayoutAlgorithm::CreateSheetChildConstraint( auto maxHeight = sheetHeight_; if ((sheetStyle_.isTitleBuilder.has_value()) && ((sheetType_ == SheetType::SHEET_CENTER) || (sheetType_ == SheetType::SHEET_POPUP))) { - auto host = layoutWrapper->GetHostNode(); - CHECK_NULL_RETURN(host, childConstraint); auto sheetPattern = host->GetPattern(); CHECK_NULL_RETURN(sheetPattern, childConstraint); auto operationNode = sheetPattern->GetTitleBuilderNode(); @@ -722,7 +723,7 @@ LayoutConstraintF SheetPresentationLayoutAlgorithm::CreateSheetChildConstraint( } auto maxWidth = sheetWidth_; if (sheetType_ == SheetType::SHEET_POPUP) { - UpdateMaxSizeWithPlacement(maxWidth, maxHeight); + UpdateMaxSizeWithPlacement(maxWidth, maxHeight, layoutWrapper); } if (sheetPopupInfo_.finalPlacement != Placement::NONE) { childConstraint.maxSize.SetWidth(maxWidth); @@ -733,9 +734,12 @@ LayoutConstraintF SheetPresentationLayoutAlgorithm::CreateSheetChildConstraint( return childConstraint; } -void SheetPresentationLayoutAlgorithm::UpdateMaxSizeWithPlacement(float& maxWidth, float& maxHeight) +void SheetPresentationLayoutAlgorithm::UpdateMaxSizeWithPlacement(float& maxWidth, float& maxHeight, + LayoutWrapper* layoutWrapper) { - if (Container::LessThanAPITargetVersion(PlatformVersion::VERSION_EIGHTEEN)) { + auto host = layoutWrapper->GetHostNode(); + CHECK_NULL_VOID(host); + if (host->LessThanAPITargetVersion(PlatformVersion::VERSION_EIGHTEEN)) { maxHeight -= SHEET_ARROW_HEIGHT.ConvertToPx(); return; } @@ -783,7 +787,9 @@ bool SheetPresentationLayoutAlgorithm::SheetInSplitWindow() const { //whether window in up and down split mode auto pipelineContext = PipelineContext::GetCurrentContext(); + CHECK_NULL_RETURN(pipelineContext, false); auto windowManager = pipelineContext->GetWindowManager(); + CHECK_NULL_RETURN(windowManager, false); auto windowGlobalRect = pipelineContext->GetDisplayWindowRectInfo(); int32_t deviceHeight = SystemProperties::GetDeviceHeight(); if (sheetType_ == SheetType::SHEET_CENTER && windowManager && windowGlobalRect.Height() < deviceHeight && @@ -803,7 +809,9 @@ void SheetPresentationLayoutAlgorithm::UpdatePopupInfoAndRemeasure(LayoutWrapper sheetPopupInfo_ = sheetPopupInfo; sheetOffsetX_ = sheetPopupInfo.sheetOffsetX; sheetOffsetY_ = sheetPopupInfo.sheetOffsetY; - if (Container::LessThanAPITargetVersion(PlatformVersion::VERSION_EIGHTEEN)) { + auto host = layoutWrapper->GetHostNode(); + CHECK_NULL_VOID(host); + if (host->LessThanAPITargetVersion(PlatformVersion::VERSION_EIGHTEEN)) { return; } sheetWidth_ = sheetWidth; diff --git a/frameworks/core/components_ng/pattern/overlay/sheet_presentation_layout_algorithm.h b/frameworks/core/components_ng/pattern/overlay/sheet_presentation_layout_algorithm.h index fb18760de059d88339cca299512e4d20684d8f32..aebae182913ab7ae89aed8f669a49ccd12dd9216 100755 --- a/frameworks/core/components_ng/pattern/overlay/sheet_presentation_layout_algorithm.h +++ b/frameworks/core/components_ng/pattern/overlay/sheet_presentation_layout_algorithm.h @@ -95,8 +95,8 @@ private: bool SheetInSplitWindow() const; LayoutConstraintF CreateSheetChildConstraint( RefPtr layoutprop, LayoutWrapper* layoutWrapper); - void UpdateMaxSizeWithPlacement(float& maxWidth, float& maxHeight); - void UpdateTranslateOffsetWithPlacement(OffsetF& translate); + void UpdateMaxSizeWithPlacement(float& maxWidth, float& maxHeight, LayoutWrapper* layoutWrapper); + void UpdateTranslateOffsetWithPlacement(OffsetF& translate, LayoutWrapper* layoutWrapper); void AddArrowHeightToSheetSize(); void RemeasureForPopup(const RefPtr& layoutWrapper); void MinusSubwindowDistance(const RefPtr& sheetWrapper); diff --git a/frameworks/core/components_ng/pattern/overlay/sheet_presentation_pattern.cpp b/frameworks/core/components_ng/pattern/overlay/sheet_presentation_pattern.cpp index c1da6f0b17b9c8423f605200825c24d6680f43fe..f544e347b4844f52bff94f823e087c98d993214f 100644 --- a/frameworks/core/components_ng/pattern/overlay/sheet_presentation_pattern.cpp +++ b/frameworks/core/components_ng/pattern/overlay/sheet_presentation_pattern.cpp @@ -14,6 +14,7 @@ */ #include "core/components_ng/pattern/overlay/sheet_presentation_pattern.h" +#include "overlay_manager.h" #include "base/geometry/dimension.h" #include "base/log/dump_log.h" @@ -24,6 +25,7 @@ #include "core/animation/curve.h" #include "core/common/ace_engine.h" #include "core/common/container.h" +#include "core/common/resource/resource_parse_utils.h" #include "core/components/drag_bar/drag_bar_theme.h" #include "core/components_ng/base/frame_node.h" #include "core/components_ng/event/event_hub.h" @@ -179,7 +181,9 @@ float SheetPresentationPattern::GetSheetTopSafeArea() void SheetPresentationPattern::InitPageHeight() { - auto pipelineContext = PipelineContext::GetCurrentContext(); + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto pipelineContext = host->GetContext(); CHECK_NULL_VOID(pipelineContext); auto safeAreaInsets = pipelineContext->GetSafeAreaWithoutProcess(); auto currentTopSafeArea = sheetTopSafeArea_; @@ -1188,7 +1192,7 @@ void SheetPresentationPattern::UpdateDragBarStatus() CHECK_NULL_VOID(sheetDragBar); auto dragBarLayoutProperty = sheetDragBar->GetLayoutProperty(); CHECK_NULL_VOID(dragBarLayoutProperty); - if (!Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_ELEVEN)) { + if (!host->GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_ELEVEN)) { dragBarLayoutProperty->UpdateVisibility(showDragIndicator ? VisibleType::VISIBLE : VisibleType::GONE); sheetDragBar->MarkDirtyNode(PROPERTY_UPDATE_RENDER); return; @@ -1875,18 +1879,20 @@ void SheetPresentationPattern::SheetTransitionAction(float offset, bool isFirstT SheetType SheetPresentationPattern::GetSheetType() const { - if (!Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_ELEVEN)) { + SheetType sheetType = SheetType::SHEET_BOTTOM; + auto host = GetHost(); + CHECK_NULL_RETURN(host, sheetType); + if (!host->GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_ELEVEN)) { return SHEET_BOTTOM; } - SheetType sheetType = SheetType::SHEET_BOTTOM; - auto pipelineContext = PipelineContext::GetCurrentContext(); - CHECK_NULL_RETURN(pipelineContext, sheetType); auto layoutProperty = GetLayoutProperty(); CHECK_NULL_RETURN(layoutProperty, sheetType); auto sheetStyle = layoutProperty->GetSheetStyleValue(SheetStyle()); if (sheetStyle.showInSubWindow.value_or(false)) { return ComputeSheetTypeInSubWindow(); } + auto pipelineContext = host->GetContext(); + CHECK_NULL_RETURN(pipelineContext, sheetType); auto windowGlobalRect = pipelineContext->GetDisplayWindowRectInfo(); TAG_LOGD(AceLogTag::ACE_SHEET, "GetSheetType displayWindowRect info is : %{public}s", windowGlobalRect.ToString().c_str()); @@ -1927,14 +1933,17 @@ void SheetPresentationPattern::GetSheetTypeWithAuto(SheetType& sheetType) const { double rootWidth = 0.0; double rootHeight = 0.0; + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto pipeline = host->GetContext(); + CHECK_NULL_VOID(pipeline); if (windowSize_.has_value()) { rootWidth = windowSize_.value().Width(); rootHeight = windowSize_.value().Height(); } else { - rootWidth = PipelineContext::GetCurrentRootWidth(); - rootHeight = PipelineContext::GetCurrentRootHeight(); + rootWidth = pipeline->GetRootWidth(); + rootHeight = pipeline->GetRootHeight(); } - auto pipeline = PipelineContext::GetCurrentContext(); auto sheetTheme = pipeline->GetTheme(); CHECK_NULL_VOID(sheetTheme); #ifdef PREVIEW @@ -2179,7 +2188,7 @@ void SheetPresentationPattern::ResetToInvisible() bool SheetPresentationPattern::IsFoldExpand() const { bool isExpand = false; - auto container = Container::Current(); + auto container = Container::CurrentSafelyWithCheck(); CHECK_NULL_RETURN(container, false); auto foldStatus = container->GetCurrentFoldStatus(); isExpand = foldStatus != FoldStatus::FOLDED && foldStatus != FoldStatus::UNKNOWN; @@ -2451,7 +2460,9 @@ void SheetPresentationPattern::CalculateAloneSheetRadius( std::string SheetPresentationPattern::GetPopupStyleSheetClipPath( const SizeF& sheetSize, const BorderRadiusProperty& sheetRadius) { - if (Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_EIGHTEEN)) { + auto host = GetHost(); + CHECK_NULL_RETURN(host, ""); + if (host->GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_EIGHTEEN)) { return GetPopupStyleSheetClipPathNew(sheetSize, sheetRadius); } auto radiusTopLeft = sheetRadius.radiusTopLeft->ConvertToPx(); @@ -2563,7 +2574,11 @@ RefPtr SheetPresentationPattern::GetOverlayManager() return overlayManager; } if (!showInPage) { - return PipelineContext::GetCurrentContext()->GetOverlayManager(); + auto host = GetHost(); + CHECK_NULL_RETURN(host, nullptr); + auto pipeline = host->GetContext(); + CHECK_NULL_RETURN(pipeline, nullptr); + return pipeline->GetOverlayManager(); } auto host = GetHost(); CHECK_NULL_RETURN(host, nullptr); @@ -2611,13 +2626,15 @@ RefPtr SheetPresentationPattern::GetOverlayRoot() const auto& layoutProp = GetLayoutProperty(); CHECK_NULL_RETURN(layoutProp, nullptr); auto showInPage = layoutProp->GetSheetStyleValue(SheetStyle()).showInPage.value_or(false); + auto host = GetHost(); + CHECK_NULL_RETURN(host, nullptr); if (!showInPage) { - auto overlay = PipelineContext::GetCurrentContext()->GetOverlayManager(); + auto pipelineContext = host->GetContext(); + CHECK_NULL_RETURN(pipelineContext, nullptr); + auto overlay = pipelineContext->GetOverlayManager(); CHECK_NULL_RETURN(overlay, nullptr); return AceType::DynamicCast(overlay->GetRootNode().Upgrade()); } - auto host = GetHost(); - CHECK_NULL_RETURN(host, nullptr); auto sheetWrapper = host->GetParent(); CHECK_NULL_RETURN(sheetWrapper, nullptr); return AceType::DynamicCast(sheetWrapper->GetParent()); @@ -3286,7 +3303,9 @@ void SheetPresentationPattern::GetArrowOffsetByPlacement( const RefPtr& layoutAlgorithm) { CHECK_NULL_VOID(layoutAlgorithm); - if (!Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_EIGHTEEN)) { + auto host = GetHost(); + CHECK_NULL_VOID(host); + if (!host->GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_EIGHTEEN)) { return; } finalPlacement_ = sheetPopupInfo_.finalPlacement; @@ -3880,6 +3899,550 @@ void SheetPresentationPattern::UpdateSheetObject(SheetType newType) AvoidAiBar(); } +void SheetPresentationPattern::UpdateBkgColor(const RefPtr& resObj, + const WeakPtr& sheetNodeWK) +{ + auto sheetNode = sheetNodeWK.Upgrade(); + CHECK_NULL_VOID(sheetNode); + // Parse the background olor using the resource object. + Color backgroundColor; + bool result = ResourceParseUtils::ParseResColor(resObj, backgroundColor); + if (!result) { + auto pipelineContext = sheetNode->GetContext(); + CHECK_NULL_VOID(pipelineContext); + auto sheetTheme = pipelineContext->GetTheme(); + backgroundColor = (sheetTheme != nullptr) ? sheetTheme->GetSheetBackgoundColor() : backgroundColor; + } + + // Update sheetStyle. + auto layoutProperty = DynamicCast(sheetNode->GetLayoutProperty()); + CHECK_NULL_VOID(layoutProperty); + auto sheetStyle = layoutProperty->GetSheetStyleValue(); + NG::SheetStyle currSheetStyle = sheetStyle; + currSheetStyle.backgroundColor = backgroundColor; + layoutProperty->UpdateSheetStyle(currSheetStyle); + + // Update sheet mask background color. + auto renderContext = sheetNode->GetRenderContext(); + renderContext->UpdateBackgroundColor(backgroundColor); + sheetNode->MarkModifyDone(); +} + +void SheetPresentationPattern::RegisterBkgColorRes( + const RefPtr& sheetNode, RefPtr& colorResObj) +{ + CHECK_NULL_VOID(sheetNode); + auto pattern = sheetNode->GetPattern(); + CHECK_NULL_VOID(pattern); + if (colorResObj) { + auto&& updateFunc = [sheetNodeWK = AceType::WeakClaim(AceType::RawPtr(sheetNode)), weak = WeakClaim(this)] + (const RefPtr& colorResObj) { + auto pattern = weak.Upgrade(); + CHECK_NULL_VOID(pattern); + pattern->UpdateBkgColor(colorResObj, sheetNodeWK); + }; + pattern->AddResObj("sheetPage.backgroundColor", colorResObj, std::move(updateFunc)); + } else { + pattern->RemoveResObj("sheetPage.backgroundColor"); + } +} + +void SheetPresentationPattern::RegisterRadiusRes(const RefPtr& sheetNode, RefPtr& resObj) +{ + CHECK_NULL_VOID(sheetNode); + auto pattern = sheetNode->GetPattern(); + CHECK_NULL_VOID(pattern); + auto sheetNodeWK = AceType::WeakClaim(AceType::RawPtr(sheetNode)); + auto&& updateFunc = [sheetNodeWK](const RefPtr& resObj) { + auto sheetNode = sheetNodeWK.Upgrade(); + CHECK_NULL_VOID(sheetNode); + auto layoutProperty = DynamicCast(sheetNode->GetLayoutProperty()); + CHECK_NULL_VOID(layoutProperty); + auto sheetStyle = layoutProperty->GetSheetStyleValue(); + NG::SheetStyle currSheetStyle = sheetStyle; + NG::BorderRadiusProperty radius; + radius.multiValued = false; + if (sheetStyle.radius->multiValued) { + // When multiValued is true, the value is set in multiple directions. + // In this case, invoke ReloadResources to re-parse. + radius = sheetStyle.radius.value(); + radius.ReloadResources(); + } else if (resObj) { + // When multiValued is false and resource object is not empty, same value in all directions. + // In this case, parse the sheet radius using the resource object. + CalcDimension radiusSingle; + ResourceParseUtils::ParseResDimensionVpNG(resObj, radiusSingle); + radius.SetRadius(radiusSingle); + } + currSheetStyle.radius = radius; + // Update sheet style and radius when radius changes. + layoutProperty->UpdateSheetStyle(currSheetStyle); + auto pattern = sheetNode->GetPattern(); + CHECK_NULL_VOID(pattern); + pattern->ClipSheetNode(); + sheetNode->MarkModifyDone(); + }; + resObj = resObj ? resObj : AceType::MakeRefPtr(); + pattern->AddResObj("sheetPage.radius", resObj, std::move(updateFunc)); +} + +void SheetPresentationPattern::UpdateBorderWidthOrColor(const RefPtr& resObj, + const WeakPtr& sheetNodeWK) +{ + auto sheetNode = sheetNodeWK.Upgrade(); + CHECK_NULL_VOID(sheetNode); + auto layoutProperty = DynamicCast(sheetNode->GetLayoutProperty()); + CHECK_NULL_VOID(layoutProperty); + auto sheetStyle = layoutProperty->GetSheetStyleValue(); + NG::BorderWidthProperty borderWidth; + if (sheetStyle.borderWidth->multiValued) { + // When multiValued is true, the value is set in multiple directions. + // In this case, invoke ReloadResources of border width to re-parse. + borderWidth = sheetStyle.borderWidth.value(); + borderWidth.ReloadResources(); + } else if (resObj) { + // When multiValued is false and resource object is not empty, same value in all directions. + // In this case, parse the sheet border width using the resource object. + CalcDimension borderWidthSingle; + ResourceParseUtils::ParseResDimensionVpNG(resObj, borderWidthSingle); + borderWidth = NG::BorderWidthProperty({ borderWidthSingle, borderWidthSingle, + borderWidthSingle, borderWidthSingle, std::nullopt, std::nullopt}); + } + // Update sheet style and border width when border width changes. + NG::SheetStyle currSheetStyle = sheetStyle; + currSheetStyle.borderWidth = borderWidth; + layoutProperty->UpdateSheetStyle(currSheetStyle); + auto pattern = sheetNode->GetPattern(); + CHECK_NULL_VOID(pattern); + borderWidth = pattern->GetSheetObject()->PostProcessBorderWidth(borderWidth); + layoutProperty->UpdateBorderWidth(borderWidth); + auto renderContext = sheetNode->GetRenderContext(); + CHECK_NULL_VOID(renderContext); + renderContext->UpdateBorderWidth(borderWidth); + + // re-parse border color when needed + NG::BorderColorProperty borderColor; + auto colorResObj = sheetStyle.GetBorderColorResObj(); + if (!sheetStyle.borderColor.has_value()) { + sheetNode->MarkModifyDone(); + return; + } else if (sheetStyle.borderColor->multiValued) { + // When multiValued is true, the value is set in multiple directions. + // In this case, invoke ReloadResources of border Color to re-parse. + borderColor = sheetStyle.borderColor.value(); + borderColor.ReloadResources(); + } else if (colorResObj) { + // When multiValued is false and resource object is not empty, same value in all directions. + // In this case, parse the sheet border color using the resource object. + Color borderColorSingle; + ResourceParseUtils::ParseResColor(colorResObj, borderColorSingle); + borderColor.SetColor(borderColorSingle); + } + // Update sheet style and border color when border color changes. + currSheetStyle.borderColor = borderColor; + layoutProperty->UpdateSheetStyle(currSheetStyle); + renderContext->UpdateBorderColor(borderColor); + sheetNode->MarkModifyDone(); +} + +void SheetPresentationPattern::RegisterBorderWidthOrColorRes(const RefPtr& sheetNode, + RefPtr& resObjWidth) +{ + CHECK_NULL_VOID(sheetNode); + auto pattern = sheetNode->GetPattern(); + CHECK_NULL_VOID(pattern); + auto&& updateFunc = [sheetNodeWK= AceType::WeakClaim(AceType::RawPtr(sheetNode)), weak = WeakClaim(this)] + (const RefPtr& resObjWidth) { + auto pattern = weak.Upgrade(); + CHECK_NULL_VOID(pattern); + pattern->UpdateBorderWidthOrColor(resObjWidth, sheetNodeWK); + }; + resObjWidth = resObjWidth ? resObjWidth : AceType::MakeRefPtr(); + pattern->AddResObj("sheetPage.border", resObjWidth, std::move(updateFunc)); +} + +void SheetPresentationPattern::RegisterTitleRes(const RefPtr& sheetNode, + RefPtr& mainTitleResObj) +{ + CHECK_NULL_VOID(sheetNode); + auto pattern = sheetNode->GetPattern(); + CHECK_NULL_VOID(pattern); + if (!mainTitleResObj) { + pattern->RemoveResObj("sheetPage.title"); + } + auto&& updateFunc = + [sheetNodeWK = AceType::WeakClaim(AceType::RawPtr(sheetNode)), + weak = WeakClaim(this)](const RefPtr& mainTitleResObj) { + // Parse the sheet main title using the resource object. + // Return when parse failed. + std::string mainTitle; + bool result = ResourceParseUtils::ParseResString(mainTitleResObj, mainTitle); + CHECK_NULL_VOID(result); + // Update sheetStyle. + auto sheetNode = sheetNodeWK.Upgrade(); + CHECK_NULL_VOID(sheetNode); + auto layoutProperty = DynamicCast(sheetNode->GetLayoutProperty()); + CHECK_NULL_VOID(layoutProperty); + auto sheetStyle = layoutProperty->GetSheetStyleValue(); + NG::SheetStyle currSheetStyle = sheetStyle; + currSheetStyle.sheetTitle = mainTitle; + layoutProperty->UpdateSheetStyle(currSheetStyle); + // Update sheet main title content. + auto pattern = weak.Upgrade(); + CHECK_NULL_VOID(pattern); + auto titleNode = + AceType::DynamicCast(ElementRegister::GetInstance()->GetNodeById(pattern->GetTitleId())); + CHECK_NULL_VOID(titleNode); + auto titleProp = titleNode->GetLayoutProperty(); + CHECK_NULL_VOID(titleProp); + titleProp->UpdateContent(mainTitle); + titleNode->MarkDirtyNode(PROPERTY_UPDATE_RENDER); + sheetNode->MarkModifyDone(); + + auto subTitleResObj = sheetStyle.GetSubTitleResObj(); + if (sheetStyle.sheetSubtitle.has_value() && subTitleResObj) { + // Parse the sheet subtitle using the resource object. + // Return when parse failed. + std::string subTitle; + bool result = ResourceParseUtils::ParseResString(subTitleResObj, subTitle); + CHECK_NULL_VOID(result); + // Update sheetStyle. + currSheetStyle.sheetSubtitle = subTitle; + layoutProperty->UpdateSheetStyle(currSheetStyle); + // Update sheet subtitle content. + auto subtitleNode = + DynamicCast(ElementRegister::GetInstance()->GetNodeById(pattern->GetSubtitleId())); + CHECK_NULL_VOID(subtitleNode); + auto subtitleProp = subtitleNode->GetLayoutProperty(); + CHECK_NULL_VOID(subtitleProp); + subtitleProp->UpdateContent(subTitle); + subtitleNode->MarkDirtyNode(PROPERTY_UPDATE_RENDER); + sheetNode->MarkModifyDone(); + } + }; + pattern->AddResObj("sheetPage.title", mainTitleResObj, std::move(updateFunc)); +} + +void SheetPresentationPattern::RegisterDetentSelectionRes(const RefPtr& sheetNode, + RefPtr& resObj) +{ + CHECK_NULL_VOID(sheetNode); + auto pattern = sheetNode->GetPattern(); + CHECK_NULL_VOID(pattern); + if (resObj) { + auto sheetNodeWK = AceType::WeakClaim(AceType::RawPtr(sheetNode)); + auto overlayWk = pattern->GetOverlay(); + auto&& updateFunc = [overlayWk, sheetNodeWK](const RefPtr& resObj) { + auto sheetNode = sheetNodeWK.Upgrade(); + CHECK_NULL_VOID(sheetNode); + auto layoutProperty = DynamicCast(sheetNode->GetLayoutProperty()); + CHECK_NULL_VOID(layoutProperty); + auto sheetStyle = layoutProperty->GetSheetStyleValue(); + NG::SheetStyle currSheetStyle = sheetStyle; + CalcDimension detentSelection; + currSheetStyle.detentSelection->height.reset(); + currSheetStyle.detentSelection->sheetMode.reset(); + // Parse the sheet detentSelection using the resource object. + bool result = ResourceParseUtils::ParseResDimensionVpNG(resObj, detentSelection); + if (result) { + currSheetStyle.detentSelection->height = detentSelection; + } else { + // Use the default detentSelection in sheetTheme for parse failed. + auto pipelineContext = sheetNode->GetContext(); + CHECK_NULL_VOID(pipelineContext); + auto sheetTheme = pipelineContext->GetTheme(); + CHECK_NULL_VOID(sheetTheme); + currSheetStyle.detentSelection->sheetMode = + static_cast(sheetTheme->GetSheetHeightDefaultMode()); + } + auto overlayManager = overlayWk.Upgrade(); + if (overlayManager) { + // Update sheetpage when detentSelection changes. + overlayManager->UpdateSheetPage(sheetNode, currSheetStyle); + } + }; + pattern->AddResObj("sheetPage.detentSelection", resObj, std::move(updateFunc)); + } else { + pattern->RemoveResObj("sheetPage.detentSelection"); + } +} + +void SheetPresentationPattern::RegisterShowCloseRes(const RefPtr& sheetNode, + RefPtr& showCloseResObj) +{ + CHECK_NULL_VOID(sheetNode); + auto pattern = sheetNode->GetPattern(); + CHECK_NULL_VOID(pattern); + if (showCloseResObj) { + auto sheetNodeWK = AceType::WeakClaim(AceType::RawPtr(sheetNode)); + auto&& updateFunc = [sheetNodeWK, weak = WeakClaim(this)](const RefPtr& showCloseResObj) { + bool showCloseIcon = true; + bool result = ResourceParseUtils::ParseResBool(showCloseResObj, showCloseIcon); + auto sheetNode = sheetNodeWK.Upgrade(); + CHECK_NULL_VOID(sheetNode); + if (!result) { + // Use the default showCloseIcon in sheetTheme for parse failed. + auto pipelineContext = sheetNode->GetContext(); + CHECK_NULL_VOID(pipelineContext); + auto sheetTheme = pipelineContext->GetTheme(); + showCloseIcon = (sheetTheme != nullptr) ? sheetTheme->GetShowCloseIcon() : showCloseIcon; + } + + // Update sheetStyle. + auto layoutProperty = DynamicCast(sheetNode->GetLayoutProperty()); + CHECK_NULL_VOID(layoutProperty); + auto sheetStyle = layoutProperty->GetSheetStyleValue(); + NG::SheetStyle currSheetStyle = sheetStyle; + currSheetStyle.showCloseIcon = showCloseIcon; + layoutProperty->UpdateSheetStyle(currSheetStyle); + + // Update sheet close icom visible status. + auto pattern = weak.Upgrade(); + CHECK_NULL_VOID(pattern); + auto sheetCloseIcon = pattern->GetSheetCloseIcon(); + CHECK_NULL_VOID(sheetCloseIcon); + auto iconLayoutProperty = sheetCloseIcon->GetLayoutProperty(); + CHECK_NULL_VOID(iconLayoutProperty); + iconLayoutProperty->UpdateVisibility(showCloseIcon ? VisibleType::VISIBLE : VisibleType::INVISIBLE); + sheetCloseIcon->MarkDirtyNode(PROPERTY_UPDATE_RENDER); + sheetNode->MarkModifyDone(); + }; + pattern->AddResObj("sheetPage.showClose", showCloseResObj, std::move(updateFunc)); + } else { + pattern->RemoveResObj("sheetPage.showClose"); + } +} + +void SheetPresentationPattern::RegisterHeightRes(const RefPtr& sheetNode, + RefPtr& resObj) +{ + CHECK_NULL_VOID(sheetNode); + auto pattern = sheetNode->GetPattern(); + CHECK_NULL_VOID(pattern); + if (resObj) { + auto sheetNodeWK = AceType::WeakClaim(AceType::RawPtr(sheetNode)); + auto overlayWk = pattern->GetOverlay(); + auto&& updateFunc = [overlayWk, sheetNodeWK](const RefPtr& resObj) { + auto sheetNode = sheetNodeWK.Upgrade(); + CHECK_NULL_VOID(sheetNode); + auto layoutProperty = DynamicCast(sheetNode->GetLayoutProperty()); + CHECK_NULL_VOID(layoutProperty); + auto sheetStyle = layoutProperty->GetSheetStyleValue(); + NG::SheetStyle currSheetStyle = sheetStyle; + CalcDimension sheetHeightValue; + // Parse the sheet height using the resource object. + bool result = ResourceParseUtils::ParseResDimensionVpNG(resObj, sheetHeightValue); + currSheetStyle.sheetHeight.height.reset(); + currSheetStyle.sheetHeight.sheetMode.reset(); + if (result) { + currSheetStyle.sheetHeight.height = sheetHeightValue; + } else { + // Use the default sheetMode in sheetTheme for parse failed. + auto pipelineContext = sheetNode->GetContext(); + CHECK_NULL_VOID(pipelineContext); + auto sheetTheme = pipelineContext->GetTheme(); + CHECK_NULL_VOID(sheetTheme); + currSheetStyle.sheetHeight.sheetMode = + static_cast(sheetTheme->GetSheetHeightDefaultMode()); + } + auto overlayManager = overlayWk.Upgrade(); + if (overlayManager) { + // Update sheetpage when height changes. + overlayManager->UpdateSheetPage(sheetNode, currSheetStyle); + } + }; + pattern->AddResObj("sheetPage.sheetHeight", resObj, std::move(updateFunc)); + } else { + pattern->RemoveResObj("sheetPage.sheetHeight"); + } +} + +void SheetPresentationPattern::RegisterWidthRes(const RefPtr& sheetNode, + RefPtr& resObj) +{ + CHECK_NULL_VOID(sheetNode); + auto pattern = sheetNode->GetPattern(); + CHECK_NULL_VOID(pattern); + if (resObj) { + auto sheetNodeWK = AceType::WeakClaim(AceType::RawPtr(sheetNode)); + auto overlayWk = pattern->GetOverlay(); + auto&& updateFunc = [overlayWk, weak = WeakClaim(this), sheetNodeWK](const RefPtr& resObj) { + auto sheetNode = sheetNodeWK.Upgrade(); + CHECK_NULL_VOID(sheetNode); + auto layoutProperty = DynamicCast(sheetNode->GetLayoutProperty()); + CHECK_NULL_VOID(layoutProperty); + auto sheetStyle = layoutProperty->GetSheetStyleValue(); + NG::SheetStyle currSheetStyle = sheetStyle; + CalcDimension width; + // Parse the sheet width using the resource object. + bool result = ResourceParseUtils::ParseResDimensionVpNG(resObj, width); + if (result) { + currSheetStyle.width = width; + } else { + // Use the default width in sheetTheme for parse failed, + // when sheet type is SHEET_CENTER. + auto pipeline = sheetNode->GetContext(); + CHECK_NULL_VOID(pipeline); + auto sheetTheme = pipeline->GetTheme(); + auto pattern = weak.Upgrade(); + CHECK_NULL_VOID(pattern); + currSheetStyle.width = ((sheetTheme != nullptr) && pattern->GetSheetType() == SHEET_CENTER) + ? sheetTheme->GetCenterDefaultWidth() + : width; + } + auto overlayManager = overlayWk.Upgrade(); + if (overlayManager) { + // Update sheetpage when width changes. + overlayManager->UpdateSheetPage(sheetNode, currSheetStyle); + } + }; + pattern->AddResObj("sheetPage.width", resObj, std::move(updateFunc)); + } else { + pattern->RemoveResObj("sheetPage.width"); + } +} + +void SheetPresentationPattern::UpdateSheetDetents(const RefPtr& resObj, + const WeakPtr& sheetNodeWK, const WeakPtr& overlayWk) +{ + auto sheetNode = sheetNodeWK.Upgrade(); + CHECK_NULL_VOID(sheetNode); + auto layoutProperty = DynamicCast(sheetNode->GetLayoutProperty()); + CHECK_NULL_VOID(layoutProperty); + auto sheetStyle = layoutProperty->GetSheetStyleValue(); + NG::SheetStyle sheetStyleValue = sheetStyle; + std::vector> resObjVector = sheetStyle.GetDetentsResObjs(); + std::vector sheetDetents; + for (const auto& resObj : resObjVector) { + // Traverse resObjVector and parse each detents height resource. + if (resObj == nullptr) { + continue; + } + NG::SheetHeight sheetDetent; + CalcDimension sheetHeightValue; + bool result = ResourceParseUtils::ParseResDimensionVpNG(resObj, sheetHeightValue); + if (result) { + sheetDetent.height = sheetHeightValue; + } else { + // Use the default sheetMode in sheetTheme for parse failed. + auto pipelineContext = sheetNode->GetContext(); + CHECK_NULL_VOID(pipelineContext); + auto sheetTheme = pipelineContext->GetTheme(); + CHECK_NULL_VOID(sheetTheme); + sheetDetent.sheetMode = static_cast(sheetTheme->GetSheetHeightDefaultMode()); + } + sheetDetents.emplace_back(sheetDetent); + } + sheetStyleValue.detents = sheetDetents; + auto overlayManager = overlayWk.Upgrade(); + if (overlayManager) { + // Update sheetpage when detents changes. + overlayManager->UpdateSheetPage(sheetNode, sheetStyleValue); + } +} + +void SheetPresentationPattern::RegisterDetentsRes(const RefPtr& sheetNode, + std::vector>& resObjVec) +{ + CHECK_NULL_VOID(sheetNode); + auto pattern = sheetNode->GetPattern(); + CHECK_NULL_VOID(pattern); + bool isNeedRegisterRes = + !resObjVec.empty() && + std::any_of(resObjVec.begin(), resObjVec.end(), [](const RefPtr& resObj) { + return resObj != nullptr; + }); + if (isNeedRegisterRes) { + RefPtr resObject = AceType::MakeRefPtr(); + auto sheetNodeWK = AceType::WeakClaim(AceType::RawPtr(sheetNode)); + auto overlayWk = pattern->GetOverlay(); + auto&& updateFunc = [overlayWk, sheetNodeWK, weak = WeakClaim(this)] + (const RefPtr& resObject) { + auto pattern = weak.Upgrade(); + CHECK_NULL_VOID(pattern); + pattern->UpdateSheetDetents(resObject, sheetNodeWK, overlayWk); + }; + pattern->AddResObj("sheetPage.sheetDetents", resObject, std::move(updateFunc)); + } else { + pattern->RemoveResObj("sheetPage.sheetDetents"); + } +} + +void SheetPresentationPattern::RegisterShadowRes(const RefPtr& sheetNode) +{ + CHECK_NULL_VOID(sheetNode); + auto pattern = sheetNode->GetPattern(); + CHECK_NULL_VOID(pattern); + auto sheetNodeWK = AceType::WeakClaim(AceType::RawPtr(sheetNode)); + auto&& updateFunc = [sheetNodeWK](const RefPtr& resObj) { + auto sheetNode = sheetNodeWK.Upgrade(); + CHECK_NULL_VOID(sheetNode); + auto layoutProperty = DynamicCast(sheetNode->GetLayoutProperty()); + CHECK_NULL_VOID(layoutProperty); + auto sheetStyle = layoutProperty->GetSheetStyleValue(); + NG::SheetStyle currSheetStyle = sheetStyle; + std::optional shadow; + if (sheetStyle.shadow.has_value()) { + // If the shadow in the sheetstyle is not empty, + // reload the shadow to update its value. + shadow = sheetStyle.shadow.value(); + shadow->ReloadResources(); + currSheetStyle.shadow = shadow; + layoutProperty->UpdateSheetStyle(currSheetStyle); + auto renderContext = sheetNode->GetRenderContext(); + CHECK_NULL_VOID(renderContext); + renderContext->UpdateBackShadow(shadow.value()); + sheetNode->MarkModifyDone(); + } + }; + RefPtr resObj = AceType::MakeRefPtr(); + pattern->AddResObj("sheetPage.shadow", resObj, std::move(updateFunc)); +} + +void SheetPresentationPattern::UpdateSheetParamResource(const RefPtr& sheetNode, + NG::SheetStyle& sheetStyle) +{ + if (sheetStyle.sheetHeight.height.has_value()) { + auto resObj = sheetStyle.GetSheetHeightResObj(); + RegisterHeightRes(sheetNode, resObj); + } + if (!sheetStyle.detents.empty()) { + auto resObjVec = sheetStyle.GetDetentsResObjs(); + RegisterDetentsRes(sheetNode, resObjVec); + } + if (sheetStyle.detentSelection.has_value()) { + auto resObj = sheetStyle.GetDetentSelectionResObj(); + RegisterDetentSelectionRes(sheetNode, resObj); + } + if (sheetStyle.showCloseIcon.has_value()) { + auto resObj = sheetStyle.GetShowCloseResObj(); + RegisterShowCloseRes(sheetNode, resObj); + } + if (sheetStyle.sheetTitle.has_value()) { + auto mainTitleResObj = sheetStyle.GetMainTitleResObj(); + RegisterTitleRes(sheetNode, mainTitleResObj); + } + if (sheetStyle.width.has_value()) { + auto resObj = sheetStyle.GetSheetWidthResObj(); + RegisterWidthRes(sheetNode, resObj); + } + if (sheetStyle.backgroundColor.has_value()) { + auto resObj = sheetStyle.GetBackgroundColorResObj(); + RegisterBkgColorRes(sheetNode, resObj); + } + if (sheetStyle.borderWidth.has_value()) { + auto resObjWidth = sheetStyle.GetBorderWidthResObj(); + RegisterBorderWidthOrColorRes(sheetNode, resObjWidth); + } + if (sheetStyle.radius.has_value()) { + auto resObj = sheetStyle.GetRadiusResObj(); + RegisterRadiusRes(sheetNode, resObj); + } + if (sheetStyle.shadow.has_value()) { + RegisterShadowRes(sheetNode); + } +} + void SheetPresentationPattern::ResetLayoutInfo() { height_ = 0.0f; diff --git a/frameworks/core/components_ng/pattern/overlay/sheet_presentation_pattern.h b/frameworks/core/components_ng/pattern/overlay/sheet_presentation_pattern.h index a3b4a96bb6f47447a062f0f7ecdc99012e01b64c..3410548e3ef112e121e802f7ff19ee233148d876 100644 --- a/frameworks/core/components_ng/pattern/overlay/sheet_presentation_pattern.h +++ b/frameworks/core/components_ng/pattern/overlay/sheet_presentation_pattern.h @@ -80,6 +80,11 @@ public: overlayManager_ = overlayManager; } + WeakPtr GetOverlay() + { + return overlayManager_; + } + bool IsAtomicNode() const override { return false; @@ -1077,6 +1082,26 @@ public: void HandleDragEndAccessibilityEvent(); void DismissTransition(bool isTransitionIn, float dragVelocity = 0.0f); + // Create Dark Light Resource Method. + void UpdateSheetParamResource(const RefPtr& sheetNode, NG::SheetStyle& sheetStyle); + void RegisterWidthRes(const RefPtr& sheetNode, RefPtr& resObj); + void RegisterHeightRes(const RefPtr& sheetNode, RefPtr& sheetHeightResObj); + void UpdateSheetDetents(const RefPtr& resObj, + const WeakPtr& sheetNodeWK, const WeakPtr& overlayWk); + void RegisterDetentsRes(const RefPtr& sheetNode, + std::vector>& sheetHeightResObj); + void RegisterBkgColorRes(const RefPtr& sheetNode, RefPtr& colorResObj); + void UpdateBkgColor(const RefPtr& resObj, const WeakPtr& sheetNodeWK); + void RegisterTitleRes(const RefPtr& sheetNode, RefPtr& mainTitleResObj); + void RegisterDetentSelectionRes(const RefPtr& sheetNode, RefPtr& resObj); + void RegisterShowCloseRes(const RefPtr& sheetNode, RefPtr& resObj); + void RegisterRadiusRes(const RefPtr& sheetNode, RefPtr& resObj); + void RegisterShadowRes(const RefPtr& sheetNode); + void UpdateBorderWidthOrColor(const RefPtr& resObj, + const WeakPtr& sheetNodeWK); + void RegisterBorderWidthOrColorRes(const RefPtr& sheetNode, + RefPtr& resObjWidth); + protected: void OnDetachFromFrameNode(FrameNode* sheetNode) override; diff --git a/frameworks/core/components_ng/pattern/overlay/sheet_style.h b/frameworks/core/components_ng/pattern/overlay/sheet_style.h index 31926f7aa94ee3da435c2d902fcd6ec817c0e8f4..65b684c814f49edc65a703740c3622b67b03b079 100644 --- a/frameworks/core/components_ng/pattern/overlay/sheet_style.h +++ b/frameworks/core/components_ng/pattern/overlay/sheet_style.h @@ -25,6 +25,14 @@ #include "core/components/common/properties/placement.h" #include "core/components_ng/pattern/overlay/modal_style.h" #include "core/components_ng/pattern/overlay/sheet_theme.h" +#include "core/common/resource/resource_object.h" + +#define ACE_SHEET_CREATE_RESOURCE_FUNCTIONS(name) \ +public: \ + void Set##name##ResObj(RefPtr& obj) { prop##name##Obj_ = obj; } \ + const RefPtr& Get##name##ResObj() const { return prop##name##Obj_; } \ +private: \ + RefPtr prop##name##Obj_ namespace OHOS::Ace::NG { constexpr float SHEET_VELOCITY_THRESHOLD = 1000.0f; @@ -266,6 +274,29 @@ struct SheetStyle { placementOnTarget = sheetStyle.placementOnTarget.has_value() ? sheetStyle.placementOnTarget : placementOnTarget; } + + // Register the set/get method of the resource. + void SetDetentsResObjs(std::vector>&& resObjs) + { + detentsObj_ = std::move(resObjs); + } + + const std::vector>& GetDetentsResObjs() const + { + return detentsObj_; + } + ACE_SHEET_CREATE_RESOURCE_FUNCTIONS(SheetHeight); + ACE_SHEET_CREATE_RESOURCE_FUNCTIONS(DetentSelection); + ACE_SHEET_CREATE_RESOURCE_FUNCTIONS(SheetWidth); + ACE_SHEET_CREATE_RESOURCE_FUNCTIONS(ShowClose); + ACE_SHEET_CREATE_RESOURCE_FUNCTIONS(MaskColor); + ACE_SHEET_CREATE_RESOURCE_FUNCTIONS(MainTitle); + ACE_SHEET_CREATE_RESOURCE_FUNCTIONS(SubTitle); + ACE_SHEET_CREATE_RESOURCE_FUNCTIONS(BorderWidth); + ACE_SHEET_CREATE_RESOURCE_FUNCTIONS(BorderColor); + ACE_SHEET_CREATE_RESOURCE_FUNCTIONS(Radius); + ACE_SHEET_CREATE_RESOURCE_FUNCTIONS(BackgroundColor); + std::vector> detentsObj_; }; } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/overlay/sheet_wrapper_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/overlay/sheet_wrapper_layout_algorithm.cpp index 42f6bc2123475b39a928267f96e2c30dc61c280a..0a79108531fd8feee7abe4f89c6ec81c90368780 100644 --- a/frameworks/core/components_ng/pattern/overlay/sheet_wrapper_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/overlay/sheet_wrapper_layout_algorithm.cpp @@ -201,7 +201,7 @@ void SheetWrapperLayoutAlgorithm::InitParameter(LayoutWrapper* layoutWrapper) sheetPopupInfo_.placementOnTarget = sheetStyle.placementOnTarget.value_or(true); windowGlobalRect_ = pipeline->GetDisplayWindowRectInfo(); windowEdgeWidth_ = WINDOW_EDGE_SPACE.ConvertToPx(); - if (Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_EIGHTEEN)) { + if (host->GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_EIGHTEEN)) { // global rect need to reduce the top and bottom safe area windowGlobalRect_ = pipeline->GetCurrentWindowRect(); auto safeArea = pipeline->GetSafeArea(); @@ -250,7 +250,7 @@ void SheetWrapperLayoutAlgorithm::GetSheetPageSize(LayoutWrapper* layoutWrapper) void SheetWrapperLayoutAlgorithm::DecreaseArrowHeightWhenArrowIsShown(const RefPtr& sheetNode) { - if (Container::LessThanAPITargetVersion(PlatformVersion::VERSION_EIGHTEEN)) { + if (sheetNode->LessThanAPITargetVersion(PlatformVersion::VERSION_EIGHTEEN)) { return; } @@ -306,7 +306,7 @@ OffsetF SheetWrapperLayoutAlgorithm::GetPopupStyleSheetOffset(LayoutWrapper* lay auto geometryNode = targetNode->GetGeometryNode(); CHECK_NULL_RETURN(geometryNode, OffsetF()); auto targetSize = geometryNode->GetFrameSize(); - if (Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_EIGHTEEN)) { + if (host->GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_EIGHTEEN)) { targetSize = targetNode->GetPaintRectWithTransform().GetSize(); } auto targetOffset = targetNode->GetPaintRectOffset(); @@ -332,7 +332,9 @@ OffsetF SheetWrapperLayoutAlgorithm::GetPopupStyleSheetOffset(LayoutWrapper* lay OffsetF SheetWrapperLayoutAlgorithm::GetOffsetInAvoidanceRule( LayoutWrapper* layoutWrapper, const SizeF& targetSize, const OffsetF& targetOffset) { - if (Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_EIGHTEEN)) { + auto host = layoutWrapper->GetHostNode(); + CHECK_NULL_RETURN(host, OffsetF()); + if (host->GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_EIGHTEEN)) { sheetPopupInfo_.finalPlacement = AvoidanceRuleOfPlacement(layoutWrapper, targetSize, targetOffset); } else { // before api 16, only placement bottom is used diff --git a/frameworks/core/components_ng/pattern/overlay/sheet_wrapper_pattern.cpp b/frameworks/core/components_ng/pattern/overlay/sheet_wrapper_pattern.cpp new file mode 100644 index 0000000000000000000000000000000000000000..916d3f90340646acabf4c6cb58f89f339716e781 --- /dev/null +++ b/frameworks/core/components_ng/pattern/overlay/sheet_wrapper_pattern.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "core/components_ng/pattern/overlay/sheet_wrapper_pattern.h" + +namespace OHOS::Ace::NG { + +void SheetWrapperPattern::RegisterSheetMaskColorRes(const RefPtr& maskNode, + const RefPtr& sheetNode, RefPtr& resObj) +{ + CHECK_NULL_VOID(maskNode); + auto pattern = maskNode->GetPattern(); + CHECK_NULL_VOID(pattern); + if (resObj) { + auto maskNodeWK = AceType::WeakClaim(AceType::RawPtr(maskNode)); + auto sheetNodeWK = AceType::WeakClaim(AceType::RawPtr(sheetNode)); + auto&& updateFunc = + [maskNodeWK, sheetNodeWK](const RefPtr& resObj) { + // Parse the maskColor using the resource object. + // If parse failed, use the default value in sheetTheme. + Color maskColor; + bool result = ResourceParseUtils::ParseResColor(resObj, maskColor); + if (!result) { + auto pipeline = PipelineBase::GetCurrentContext(); + CHECK_NULL_VOID(pipeline); + auto sheetTheme = pipeline->GetTheme(); + CHECK_NULL_VOID(sheetTheme); + maskColor = sheetTheme->GetMaskColor(); + } + + // Update sheetStyle. + auto sheetNode = sheetNodeWK.Upgrade(); + CHECK_NULL_VOID(sheetNode); + auto layoutProperty = sheetNode->GetLayoutProperty(); + auto sheetStyle = layoutProperty->GetSheetStyleValue(); + NG::SheetStyle sheetStyleVal = sheetStyle; + sheetStyleVal.maskColor = maskColor; + layoutProperty->UpdateSheetStyle(sheetStyleVal); + + // Update sheet mask background color. + auto maskNode = maskNodeWK.Upgrade(); + CHECK_NULL_VOID(maskNode); + auto maskRenderContext = maskNode->GetRenderContext(); + CHECK_NULL_VOID(maskRenderContext); + maskRenderContext->UpdateBackgroundColor(maskColor); + }; + pattern->AddResObj("sheetWrapper.maskColor", resObj, std::move(updateFunc)); + } else { + pattern->RemoveResObj("sheetWrapper.maskColor"); + } +} + +void SheetWrapperPattern::UpdateSheetMaskResource(const RefPtr& maskNode, + const RefPtr& sheetNode, NG::SheetStyle& sheetStyle) +{ + if (sheetStyle.maskColor.has_value()) { + auto resObj = sheetStyle.GetMaskColorResObj(); + RegisterSheetMaskColorRes(maskNode, sheetNode, resObj); + } +} +} // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/overlay/sheet_wrapper_pattern.h b/frameworks/core/components_ng/pattern/overlay/sheet_wrapper_pattern.h index 5ecb10e855226a0d0078caf42869e1e950d82cc6..38ef6301c94eab1082bd6cc0125319e2803d4edc 100644 --- a/frameworks/core/components_ng/pattern/overlay/sheet_wrapper_pattern.h +++ b/frameworks/core/components_ng/pattern/overlay/sheet_wrapper_pattern.h @@ -16,8 +16,9 @@ #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_OVERLAY_SHEET_WRAPPER_PATTERN_H #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_OVERLAY_SHEET_WRAPPER_PATTERN_H -#include "core/common/ace_engine.h" #include "base/subwindow/subwindow_manager.h" +#include "core/common/ace_engine.h" +#include "core/common/resource/resource_parse_utils.h" #include "core/components_ng/pattern/navrouter/navdestination_pattern.h" #include "core/components_ng/pattern/overlay/popup_base_pattern.h" #include "core/components_ng/pattern/overlay/sheet_presentation_pattern.h" @@ -165,6 +166,12 @@ public: return subWindowId_; } + void RegisterSheetMaskColorRes(const RefPtr& maskNode, + const RefPtr& sheetNode, RefPtr& resObj); + + void UpdateSheetMaskResource(const RefPtr& maskNode, + const RefPtr& sheetNode, NG::SheetStyle& sheetStyle); + protected: bool AvoidKeyboard() const override { diff --git a/frameworks/core/components_ng/pattern/sheet/sheet_object.cpp b/frameworks/core/components_ng/pattern/sheet/sheet_object.cpp index 23a1c8ca462decd45170e190c5e7f7ec83804d64..a358466b02b0825aeaa036871c9a66dea2640b63 100644 --- a/frameworks/core/components_ng/pattern/sheet/sheet_object.cpp +++ b/frameworks/core/components_ng/pattern/sheet/sheet_object.cpp @@ -139,7 +139,7 @@ void SheetObject::ClipSheetNode() auto geometryNode = host->GetGeometryNode(); CHECK_NULL_VOID(geometryNode); auto sheetSize = geometryNode->GetFrameSize(); - auto pipeline = PipelineContext::GetCurrentContext(); + auto pipeline = host->GetContext(); CHECK_NULL_VOID(pipeline); auto sheetTheme = pipeline->GetTheme(); CHECK_NULL_VOID(sheetTheme); diff --git a/frameworks/core/components_ng/property/border_property.h b/frameworks/core/components_ng/property/border_property.h index f15e6f624d2f709778b067eadaf9153f80bb60ea..b7f071a0e1e62d741ed5b942ff707b0f021e0843 100644 --- a/frameworks/core/components_ng/property/border_property.h +++ b/frameworks/core/components_ng/property/border_property.h @@ -162,6 +162,14 @@ struct BorderRadiusPropertyT { } } + void RemoveResource(const std::string& key) + { + auto iter = resMap_.find(key); + if (iter != resMap_.end()) { + resMap_.erase(iter); + } + } + void ClearResources() { resMap_.clear(); @@ -278,6 +286,14 @@ struct BorderColorProperty { resourceUpdater.updateFunc(resourceUpdater.resObj, *this); } } + + void RemoveResource(const std::string& key) + { + auto iter = resMap_.find(key); + if (iter != resMap_.end()) { + resMap_.erase(iter); + } + } }; template diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index a4c6247546bb6e3c7568ef28531057874c25286f..09fe5c3507f87f60044fe0943967864ba8434c36 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -1131,6 +1131,7 @@ ohos_source_set("ace_components_pattern") { "$ace_root/frameworks/core/components_ng/pattern/overlay/sheet_view.cpp", "$ace_root/frameworks/core/components_ng/pattern/overlay/sheet_wrapper_layout_algorithm.cpp", "$ace_root/frameworks/core/components_ng/pattern/overlay/sheet_wrapper_paint_method.cpp", + "$ace_root/frameworks/core/components_ng/pattern/overlay/sheet_wrapper_pattern.cpp", "$ace_root/frameworks/core/components_ng/pattern/panel/close_icon_layout_algorithm.cpp", "$ace_root/frameworks/core/components_ng/pattern/panel/close_icon_pattern.cpp", "$ace_root/frameworks/core/components_ng/pattern/panel/drag_bar_layout_algorithm.cpp", diff --git a/test/unittest/core/pattern/overlay/sheet_presentation_test_ng.cpp b/test/unittest/core/pattern/overlay/sheet_presentation_test_ng.cpp index 23d4250cae7ca2604e5a01a19039f1ee3869f2b7..74004365c0ecd27454d1ea29f0b57b27e61231e8 100644 --- a/test/unittest/core/pattern/overlay/sheet_presentation_test_ng.cpp +++ b/test/unittest/core/pattern/overlay/sheet_presentation_test_ng.cpp @@ -50,6 +50,7 @@ public: static void SetSheetTheme(RefPtr sheetTheme); static void SetSheetType(RefPtr sheetPattern, SheetType sheetType); static void TearDownTestCase(); + static void SetApiVersion(int32_t apiTargetVersion); }; void SheetPresentationTestNg::SetUpTestCase() @@ -87,7 +88,6 @@ void SheetPresentationTestNg::SetSheetTheme(RefPtr sheetTheme) void SheetPresentationTestNg::SetSheetType(RefPtr sheetPattern, SheetType sheetType) { - PipelineBase::GetCurrentContext()->minPlatformVersion_ = static_cast(PlatformVersion::VERSION_TWELVE); auto pipelineContext = PipelineContext::GetCurrentContext(); pipelineContext->displayWindowRectInfo_.width_ = SHEET_DEVICE_WIDTH_BREAKPOINT.ConvertToPx(); auto layoutProperty = sheetPattern->GetLayoutProperty(); @@ -105,6 +105,13 @@ void SheetPresentationTestNg::SetSheetType(RefPtr shee SheetPresentationTestNg::SetSheetTheme(sheetTheme); } +void SheetPresentationTestNg::SetApiVersion(int32_t apiTargetVersion) +{ + auto container = Container::Current(); + ASSERT_NE(container, nullptr); + container->SetApiTargetVersion(apiTargetVersion); +} + void SheetPresentationTestNg::TearDownTestCase() { MockPipelineContext::TearDown(); @@ -204,6 +211,7 @@ HWTEST_F(SheetPresentationTestNg, HandleScrollWithSheet001, TestSize.Level1) HWTEST_F(SheetPresentationTestNg, HandleScrollWithSheet002, TestSize.Level1) { SheetPresentationTestNg::SetUpTestCase(); + SheetPresentationTestNg::SetApiVersion(static_cast(PlatformVersion::VERSION_TWELVE)); auto callback = [](const std::string&) {}; auto sheetNode = FrameNode::CreateFrameNode("Sheet", 101, AceType::MakeRefPtr(201, "SheetPresentation", std::move(callback))); @@ -230,6 +238,7 @@ HWTEST_F(SheetPresentationTestNg, HandleScrollWithSheet002, TestSize.Level1) HWTEST_F(SheetPresentationTestNg, OnDirtyLayoutWrapperSwap001, TestSize.Level1) { SheetPresentationTestNg::SetUpTestCase(); + SheetPresentationTestNg::SetApiVersion(static_cast(PlatformVersion::VERSION_TWELVE)); auto callback = [](const std::string&) {}; auto sheetNode = FrameNode::CreateFrameNode("Sheet", 101, AceType::MakeRefPtr(201, "SheetPresentation", std::move(callback))); @@ -334,6 +343,7 @@ HWTEST_F(SheetPresentationTestNg, CheckBuilderChange001, TestSize.Level1) HWTEST_F(SheetPresentationTestNg, OnAttachToFrameNode001, TestSize.Level1) { SheetPresentationTestNg::SetUpTestCase(); + SheetPresentationTestNg::SetApiVersion(static_cast(PlatformVersion::VERSION_TWELVE)); auto callback = [](const std::string&) {}; auto sheetNode = FrameNode::CreateFrameNode("Sheet", 101, AceType::MakeRefPtr(201, "SheetPresentation", std::move(callback))); @@ -514,9 +524,7 @@ HWTEST_F(SheetPresentationTestNg, GetSheetTypeWithAuto001, TestSize.Level1) /** * @tc.steps: step1. set API14. */ - auto container = Container::Current(); - ASSERT_NE(container, nullptr); - container->SetApiTargetVersion(static_cast(PlatformVersion::VERSION_FOURTEEN)); + SheetPresentationTestNg::SetApiVersion(static_cast(PlatformVersion::VERSION_FOURTEEN)); auto callback = [](const std::string&) {}; auto sheetNode = FrameNode::CreateFrameNode("Sheet", 101, @@ -570,9 +578,7 @@ HWTEST_F(SheetPresentationTestNg, GetSheetTypeWithAuto002, TestSize.Level1) /** * @tc.steps: step1. set API14. */ - auto container = Container::Current(); - ASSERT_NE(container, nullptr); - container->SetApiTargetVersion(static_cast(PlatformVersion::VERSION_FOURTEEN)); + SheetPresentationTestNg::SetApiVersion(static_cast(PlatformVersion::VERSION_FOURTEEN)); auto callback = [](const std::string&) {}; auto sheetNode = FrameNode::CreateFrameNode("Sheet", 101, @@ -939,6 +945,7 @@ HWTEST_F(SheetPresentationTestNg, GetOverlayManager001, TestSize.Level1) HWTEST_F(SheetPresentationTestNg, OnWindowSizeChanged001, TestSize.Level1) { SheetPresentationTestNg::SetUpTestCase(); + SheetPresentationTestNg::SetApiVersion(static_cast(PlatformVersion::VERSION_TWELVE)); auto callback = [](const std::string&) {}; auto sheetNode = FrameNode::CreateFrameNode("Sheet", 301, AceType::MakeRefPtr(401, "SheetPresentation", std::move(callback))); @@ -1010,6 +1017,7 @@ HWTEST_F(SheetPresentationTestNg, HandleFitContontChange001, TestSize.Level1) HWTEST_F(SheetPresentationTestNg, DismissTransition001, TestSize.Level1) { SheetPresentationTestNg::SetUpTestCase(); + SheetPresentationTestNg::SetApiVersion(static_cast(PlatformVersion::VERSION_TWELVE)); auto callback = [](const std::string&) {}; auto sheetNode = FrameNode::CreateFrameNode("Sheet", 301, AceType::MakeRefPtr(401, "SheetPresentation", std::move(callback))); @@ -1373,6 +1381,7 @@ HWTEST_F(SheetPresentationTestNg, SetSheetOuterBorderWidth001, TestSize.Level1) * @tc.steps: step1. create target node. */ SheetPresentationTestNg::SetUpTestCase(); + SheetPresentationTestNg::SetApiVersion(static_cast(PlatformVersion::VERSION_TWELVE)); auto callback = [](const std::string&) {}; auto sheetNode = FrameNode::CreateFrameNode( "Sheet", 101, AceType::MakeRefPtr(201, "SheetPresentation", std::move(callback))); @@ -1413,6 +1422,7 @@ HWTEST_F(SheetPresentationTestNg, SetSheetOuterBorderWidth002, TestSize.Level1) * @tc.steps: step1. create target node. */ SheetPresentationTestNg::SetUpTestCase(); + SheetPresentationTestNg::SetApiVersion(static_cast(PlatformVersion::VERSION_TWELVE)); auto callback = [](const std::string&) {}; auto sheetNode = FrameNode::CreateFrameNode( "Sheet", 101, AceType::MakeRefPtr(201, "SheetPresentation", std::move(callback))); @@ -1449,6 +1459,7 @@ HWTEST_F(SheetPresentationTestNg, SetSheetOuterBorderWidth003, TestSize.Level1) * @tc.steps: step1. create target node. */ SheetPresentationTestNg::SetUpTestCase(); + SheetPresentationTestNg::SetApiVersion(static_cast(PlatformVersion::VERSION_TWELVE)); auto callback = [](const std::string&) {}; auto sheetNode = FrameNode::CreateFrameNode( "Sheet", 101, AceType::MakeRefPtr(201, "SheetPresentation", std::move(callback))); @@ -1487,6 +1498,7 @@ HWTEST_F(SheetPresentationTestNg, SetSheetOuterBorderWidth004, TestSize.Level1) * @tc.steps: step1. create target node. */ SheetPresentationTestNg::SetUpTestCase(); + SheetPresentationTestNg::SetApiVersion(static_cast(PlatformVersion::VERSION_TWELVE)); auto callback = [](const std::string&) {}; auto sheetNode = FrameNode::CreateFrameNode( "Sheet", 101, AceType::MakeRefPtr(201, "SheetPresentation", std::move(callback))); @@ -1523,6 +1535,7 @@ HWTEST_F(SheetPresentationTestNg, SetSheetOuterBorderWidth005, TestSize.Level1) * @tc.steps: step1. create target node. */ SheetPresentationTestNg::SetUpTestCase(); + SheetPresentationTestNg::SetApiVersion(static_cast(PlatformVersion::VERSION_TWELVE)); auto callback = [](const std::string&) {}; auto sheetNode = FrameNode::CreateFrameNode( "Sheet", 101, AceType::MakeRefPtr(201, "SheetPresentation", std::move(callback))); diff --git a/test/unittest/core/pattern/overlay/sheet_presentation_test_three_ng.cpp b/test/unittest/core/pattern/overlay/sheet_presentation_test_three_ng.cpp index 9b304af4035fab39a0fa34def4fc090e1961cab3..cb5fb95fbdd34daa94b7cfd9bfe76ab9f7834ef7 100644 --- a/test/unittest/core/pattern/overlay/sheet_presentation_test_three_ng.cpp +++ b/test/unittest/core/pattern/overlay/sheet_presentation_test_three_ng.cpp @@ -47,6 +47,7 @@ public: static RefPtr sheetTheme_; static void SetUpTestCase(); static void TearDownTestCase(); + static void SetApiVersion(int32_t apiTargetVersion); }; RefPtr SheetPresentationTestThreeNg::sheetTheme_ = nullptr; @@ -74,6 +75,13 @@ void SheetPresentationTestThreeNg::TearDownTestCase() MockContainer::TearDown(); } +void SheetPresentationTestThreeNg::SetApiVersion(int32_t apiTargetVersion) +{ + auto container = Container::Current(); + ASSERT_NE(container, nullptr); + container->SetApiTargetVersion(apiTargetVersion); +} + /** * @tc.name: ComputeCenterStyleOffset001 * @tc.desc: Branch: if (!showInSubWindow) = true @@ -291,13 +299,18 @@ HWTEST_F(SheetPresentationTestThreeNg, ComputeCenterStyleOffset005, TestSize.Lev HWTEST_F(SheetPresentationTestThreeNg, UpdateTranslateOffsetWithPlacement001, TestSize.Level1) { SheetPresentationTestThreeNg::SetUpTestCase(); + SheetPresentationTestThreeNg::SetApiVersion(static_cast(PlatformVersion::VERSION_TWELVE)); + auto callback = [](const std::string&) {}; + auto sheetNode = FrameNode::CreateFrameNode(V2::SHEET_PAGE_TAG, ElementRegister::GetInstance()->MakeUniqueId(), + AceType::MakeRefPtr( + ElementRegister::GetInstance()->MakeUniqueId(), V2::TEXT_ETS_TAG, std::move(callback))); auto sheetLayoutAlgorithm = AceType::MakeRefPtr(); - auto container = Container::Current(); - ASSERT_NE(container, nullptr); - container->SetApiTargetVersion(static_cast(PlatformVersion::VERSION_TWELVE)); OffsetF translate; - sheetLayoutAlgorithm->UpdateTranslateOffsetWithPlacement(translate); + auto layoutWrapperNode = AceType::MakeRefPtr( + sheetNode, sheetNode->GetGeometryNode(), sheetNode->GetLayoutProperty()); + auto layoutWrapper = reinterpret_cast(Referenced::RawPtr(layoutWrapperNode)); + sheetLayoutAlgorithm->UpdateTranslateOffsetWithPlacement(translate, layoutWrapper); EXPECT_EQ(translate.GetX(), 0.0f); EXPECT_EQ(translate.GetY(), 8.0f); SheetPresentationTestThreeNg::TearDownTestCase(); @@ -314,15 +327,20 @@ HWTEST_F(SheetPresentationTestThreeNg, UpdateTranslateOffsetWithPlacement001, Te HWTEST_F(SheetPresentationTestThreeNg, UpdateTranslateOffsetWithPlacement002, TestSize.Level1) { SheetPresentationTestThreeNg::SetUpTestCase(); + SheetPresentationTestThreeNg::SetApiVersion(static_cast(PlatformVersion::VERSION_EIGHTEEN)); + auto callback = [](const std::string&) {}; + auto sheetNode = FrameNode::CreateFrameNode(V2::SHEET_PAGE_TAG, ElementRegister::GetInstance()->MakeUniqueId(), + AceType::MakeRefPtr( + ElementRegister::GetInstance()->MakeUniqueId(), V2::TEXT_ETS_TAG, std::move(callback))); auto sheetLayoutAlgorithm = AceType::MakeRefPtr(); - auto container = Container::Current(); - ASSERT_NE(container, nullptr); - container->SetApiTargetVersion(static_cast(PlatformVersion::VERSION_EIGHTEEN)); sheetLayoutAlgorithm->sheetPopupInfo_.placementRechecked = true; sheetLayoutAlgorithm->sheetPopupInfo_.placementOnTarget = true; OffsetF translate; - sheetLayoutAlgorithm->UpdateTranslateOffsetWithPlacement(translate); + auto layoutWrapperNode = AceType::MakeRefPtr( + sheetNode, sheetNode->GetGeometryNode(), sheetNode->GetLayoutProperty()); + auto layoutWrapper = reinterpret_cast(Referenced::RawPtr(layoutWrapperNode)); + sheetLayoutAlgorithm->UpdateTranslateOffsetWithPlacement(translate, layoutWrapper); EXPECT_EQ(translate.GetX(), 0.0f); EXPECT_EQ(translate.GetY(), 0.0f); SheetPresentationTestThreeNg::TearDownTestCase(); @@ -339,15 +357,20 @@ HWTEST_F(SheetPresentationTestThreeNg, UpdateTranslateOffsetWithPlacement002, Te HWTEST_F(SheetPresentationTestThreeNg, UpdateTranslateOffsetWithPlacement003, TestSize.Level1) { SheetPresentationTestThreeNg::SetUpTestCase(); + SheetPresentationTestThreeNg::SetApiVersion(static_cast(PlatformVersion::VERSION_EIGHTEEN)); + auto callback = [](const std::string&) {}; + auto sheetNode = FrameNode::CreateFrameNode(V2::SHEET_PAGE_TAG, ElementRegister::GetInstance()->MakeUniqueId(), + AceType::MakeRefPtr( + ElementRegister::GetInstance()->MakeUniqueId(), V2::TEXT_ETS_TAG, std::move(callback))); auto sheetLayoutAlgorithm = AceType::MakeRefPtr(); - auto container = Container::Current(); - ASSERT_NE(container, nullptr); - container->SetApiTargetVersion(static_cast(PlatformVersion::VERSION_EIGHTEEN)); sheetLayoutAlgorithm->sheetPopupInfo_.placementRechecked = false; sheetLayoutAlgorithm->sheetPopupInfo_.showArrow = false; OffsetF translate; - sheetLayoutAlgorithm->UpdateTranslateOffsetWithPlacement(translate); + auto layoutWrapperNode = AceType::MakeRefPtr( + sheetNode, sheetNode->GetGeometryNode(), sheetNode->GetLayoutProperty()); + auto layoutWrapper = reinterpret_cast(Referenced::RawPtr(layoutWrapperNode)); + sheetLayoutAlgorithm->UpdateTranslateOffsetWithPlacement(translate, layoutWrapper); EXPECT_EQ(translate.GetX(), 0.0f); EXPECT_EQ(translate.GetY(), 0.0f); SheetPresentationTestThreeNg::TearDownTestCase(); @@ -365,16 +388,21 @@ HWTEST_F(SheetPresentationTestThreeNg, UpdateTranslateOffsetWithPlacement003, Te HWTEST_F(SheetPresentationTestThreeNg, UpdateTranslateOffsetWithPlacement004, TestSize.Level1) { SheetPresentationTestThreeNg::SetUpTestCase(); + SheetPresentationTestThreeNg::SetApiVersion(static_cast(PlatformVersion::VERSION_EIGHTEEN)); + auto callback = [](const std::string&) {}; + auto sheetNode = FrameNode::CreateFrameNode(V2::SHEET_PAGE_TAG, ElementRegister::GetInstance()->MakeUniqueId(), + AceType::MakeRefPtr( + ElementRegister::GetInstance()->MakeUniqueId(), V2::TEXT_ETS_TAG, std::move(callback))); auto sheetLayoutAlgorithm = AceType::MakeRefPtr(); - auto container = Container::Current(); - ASSERT_NE(container, nullptr); - container->SetApiTargetVersion(static_cast(PlatformVersion::VERSION_EIGHTEEN)); sheetLayoutAlgorithm->sheetPopupInfo_.placementRechecked = true; sheetLayoutAlgorithm->sheetPopupInfo_.placementOnTarget = false; sheetLayoutAlgorithm->sheetPopupInfo_.showArrow = false; OffsetF translate; - sheetLayoutAlgorithm->UpdateTranslateOffsetWithPlacement(translate); + auto layoutWrapperNode = AceType::MakeRefPtr( + sheetNode, sheetNode->GetGeometryNode(), sheetNode->GetLayoutProperty()); + auto layoutWrapper = reinterpret_cast(Referenced::RawPtr(layoutWrapperNode)); + sheetLayoutAlgorithm->UpdateTranslateOffsetWithPlacement(translate, layoutWrapper); EXPECT_EQ(translate.GetX(), 0.0f); EXPECT_EQ(translate.GetY(), 0.0f); SheetPresentationTestThreeNg::TearDownTestCase(); @@ -398,46 +426,51 @@ HWTEST_F(SheetPresentationTestThreeNg, UpdateTranslateOffsetWithPlacement004, Te HWTEST_F(SheetPresentationTestThreeNg, UpdateTranslateOffsetWithPlacement005, TestSize.Level1) { SheetPresentationTestThreeNg::SetUpTestCase(); + SheetPresentationTestThreeNg::SetApiVersion(static_cast(PlatformVersion::VERSION_EIGHTEEN)); + auto callback = [](const std::string&) {}; + auto sheetNode = FrameNode::CreateFrameNode(V2::SHEET_PAGE_TAG, ElementRegister::GetInstance()->MakeUniqueId(), + AceType::MakeRefPtr( + ElementRegister::GetInstance()->MakeUniqueId(), V2::TEXT_ETS_TAG, std::move(callback))); auto sheetLayoutAlgorithm = AceType::MakeRefPtr(); - auto container = Container::Current(); - ASSERT_NE(container, nullptr); - container->SetApiTargetVersion(static_cast(PlatformVersion::VERSION_EIGHTEEN)); sheetLayoutAlgorithm->sheetPopupInfo_.placementRechecked = false; sheetLayoutAlgorithm->sheetPopupInfo_.showArrow = true; sheetLayoutAlgorithm->sheetPopupInfo_.finalPlacement = Placement::BOTTOM_LEFT; OffsetF translate; - sheetLayoutAlgorithm->UpdateTranslateOffsetWithPlacement(translate); + auto layoutWrapperNode = AceType::MakeRefPtr( + sheetNode, sheetNode->GetGeometryNode(), sheetNode->GetLayoutProperty()); + auto layoutWrapper = reinterpret_cast(Referenced::RawPtr(layoutWrapperNode)); + sheetLayoutAlgorithm->UpdateTranslateOffsetWithPlacement(translate, layoutWrapper); EXPECT_EQ(translate.GetX(), 0.0f); EXPECT_EQ(translate.GetY(), 8.0f); sheetLayoutAlgorithm->sheetPopupInfo_.finalPlacement = Placement::BOTTOM_RIGHT; - sheetLayoutAlgorithm->UpdateTranslateOffsetWithPlacement(translate); + sheetLayoutAlgorithm->UpdateTranslateOffsetWithPlacement(translate, layoutWrapper); EXPECT_EQ(translate.GetX(), 0.0f); EXPECT_EQ(translate.GetY(), 16.0f); sheetLayoutAlgorithm->sheetPopupInfo_.finalPlacement = Placement::BOTTOM; - sheetLayoutAlgorithm->UpdateTranslateOffsetWithPlacement(translate); + sheetLayoutAlgorithm->UpdateTranslateOffsetWithPlacement(translate, layoutWrapper); EXPECT_EQ(translate.GetX(), 0.0f); EXPECT_EQ(translate.GetY(), 24.0f); sheetLayoutAlgorithm->sheetPopupInfo_.finalPlacement = Placement::RIGHT_TOP; - sheetLayoutAlgorithm->UpdateTranslateOffsetWithPlacement(translate); + sheetLayoutAlgorithm->UpdateTranslateOffsetWithPlacement(translate, layoutWrapper); EXPECT_EQ(translate.GetX(), 8.0f); EXPECT_EQ(translate.GetY(), 24.0f); sheetLayoutAlgorithm->sheetPopupInfo_.finalPlacement = Placement::RIGHT_BOTTOM; - sheetLayoutAlgorithm->UpdateTranslateOffsetWithPlacement(translate); + sheetLayoutAlgorithm->UpdateTranslateOffsetWithPlacement(translate, layoutWrapper); EXPECT_EQ(translate.GetX(), 16.0f); EXPECT_EQ(translate.GetY(), 24.0f); sheetLayoutAlgorithm->sheetPopupInfo_.finalPlacement = Placement::RIGHT; - sheetLayoutAlgorithm->UpdateTranslateOffsetWithPlacement(translate); + sheetLayoutAlgorithm->UpdateTranslateOffsetWithPlacement(translate, layoutWrapper); EXPECT_EQ(translate.GetX(), 24.0f); EXPECT_EQ(translate.GetY(), 24.0f); sheetLayoutAlgorithm->sheetPopupInfo_.finalPlacement = Placement::NONE; - sheetLayoutAlgorithm->UpdateTranslateOffsetWithPlacement(translate); + sheetLayoutAlgorithm->UpdateTranslateOffsetWithPlacement(translate, layoutWrapper); EXPECT_EQ(translate.GetX(), 24.0f); EXPECT_EQ(translate.GetY(), 24.0f); SheetPresentationTestThreeNg::TearDownTestCase(); @@ -1167,14 +1200,19 @@ HWTEST_F(SheetPresentationTestThreeNg, IsShowInSubWindowTest001, TestSize.Level1 HWTEST_F(SheetPresentationTestThreeNg, UpdateMaxSizeWithPlacement001, TestSize.Level1) { SheetPresentationTestThreeNg::SetUpTestCase(); + SheetPresentationTestThreeNg::SetApiVersion(static_cast(PlatformVersion::VERSION_TWELVE)); + auto callback = [](const std::string&) {}; + auto sheetNode = FrameNode::CreateFrameNode(V2::SHEET_PAGE_TAG, ElementRegister::GetInstance()->MakeUniqueId(), + AceType::MakeRefPtr( + ElementRegister::GetInstance()->MakeUniqueId(), V2::TEXT_ETS_TAG, std::move(callback))); auto sheetLayoutAlgorithm = AceType::MakeRefPtr(); - auto container = Container::Current(); - ASSERT_NE(container, nullptr); - container->SetApiTargetVersion(static_cast(PlatformVersion::VERSION_TWELVE)); float maxWidth = 3000.0f; float maxHeight = 2000.0f; - sheetLayoutAlgorithm->UpdateMaxSizeWithPlacement(maxWidth, maxHeight); + auto layoutWrapperNode = AceType::MakeRefPtr( + sheetNode, sheetNode->GetGeometryNode(), sheetNode->GetLayoutProperty()); + auto layoutWrapper = reinterpret_cast(Referenced::RawPtr(layoutWrapperNode)); + sheetLayoutAlgorithm->UpdateMaxSizeWithPlacement(maxWidth, maxHeight, layoutWrapper); EXPECT_EQ(maxWidth, 3000.0f); EXPECT_EQ(maxHeight, 1992.0f); SheetPresentationTestThreeNg::TearDownTestCase(); @@ -1191,16 +1229,21 @@ HWTEST_F(SheetPresentationTestThreeNg, UpdateMaxSizeWithPlacement001, TestSize.L HWTEST_F(SheetPresentationTestThreeNg, UpdateMaxSizeWithPlacement002, TestSize.Level1) { SheetPresentationTestThreeNg::SetUpTestCase(); + SheetPresentationTestThreeNg::SetApiVersion(static_cast(PlatformVersion::VERSION_EIGHTEEN)); + auto callback = [](const std::string&) {}; + auto sheetNode = FrameNode::CreateFrameNode(V2::SHEET_PAGE_TAG, ElementRegister::GetInstance()->MakeUniqueId(), + AceType::MakeRefPtr( + ElementRegister::GetInstance()->MakeUniqueId(), V2::TEXT_ETS_TAG, std::move(callback))); auto sheetLayoutAlgorithm = AceType::MakeRefPtr(); - auto container = Container::Current(); - ASSERT_NE(container, nullptr); - container->SetApiTargetVersion(static_cast(PlatformVersion::VERSION_EIGHTEEN)); sheetLayoutAlgorithm->sheetPopupInfo_.placementRechecked = true; sheetLayoutAlgorithm->sheetPopupInfo_.placementOnTarget = true; float maxWidth = 3000.0f; float maxHeight = 2000.0f; - sheetLayoutAlgorithm->UpdateMaxSizeWithPlacement(maxWidth, maxHeight); + auto layoutWrapperNode = AceType::MakeRefPtr( + sheetNode, sheetNode->GetGeometryNode(), sheetNode->GetLayoutProperty()); + auto layoutWrapper = reinterpret_cast(Referenced::RawPtr(layoutWrapperNode)); + sheetLayoutAlgorithm->UpdateMaxSizeWithPlacement(maxWidth, maxHeight, layoutWrapper); EXPECT_EQ(maxWidth, 3000.0f); EXPECT_EQ(maxHeight, 2000.0f); SheetPresentationTestThreeNg::TearDownTestCase(); @@ -1217,16 +1260,21 @@ HWTEST_F(SheetPresentationTestThreeNg, UpdateMaxSizeWithPlacement002, TestSize.L HWTEST_F(SheetPresentationTestThreeNg, UpdateMaxSizeWithPlacement003, TestSize.Level1) { SheetPresentationTestThreeNg::SetUpTestCase(); + SheetPresentationTestThreeNg::SetApiVersion(static_cast(PlatformVersion::VERSION_EIGHTEEN)); + auto callback = [](const std::string&) {}; + auto sheetNode = FrameNode::CreateFrameNode(V2::SHEET_PAGE_TAG, ElementRegister::GetInstance()->MakeUniqueId(), + AceType::MakeRefPtr( + ElementRegister::GetInstance()->MakeUniqueId(), V2::TEXT_ETS_TAG, std::move(callback))); auto sheetLayoutAlgorithm = AceType::MakeRefPtr(); - auto container = Container::Current(); - ASSERT_NE(container, nullptr); - container->SetApiTargetVersion(static_cast(PlatformVersion::VERSION_EIGHTEEN)); sheetLayoutAlgorithm->sheetPopupInfo_.placementRechecked = false; sheetLayoutAlgorithm->sheetPopupInfo_.showArrow = false; float maxWidth = 3000.0f; float maxHeight = 2000.0f; - sheetLayoutAlgorithm->UpdateMaxSizeWithPlacement(maxWidth, maxHeight); + auto layoutWrapperNode = AceType::MakeRefPtr( + sheetNode, sheetNode->GetGeometryNode(), sheetNode->GetLayoutProperty()); + auto layoutWrapper = reinterpret_cast(Referenced::RawPtr(layoutWrapperNode)); + sheetLayoutAlgorithm->UpdateMaxSizeWithPlacement(maxWidth, maxHeight, layoutWrapper); EXPECT_EQ(maxWidth, 3000.0f); EXPECT_EQ(maxHeight, 2000.0f); SheetPresentationTestThreeNg::TearDownTestCase(); @@ -1244,17 +1292,22 @@ HWTEST_F(SheetPresentationTestThreeNg, UpdateMaxSizeWithPlacement003, TestSize.L HWTEST_F(SheetPresentationTestThreeNg, UpdateMaxSizeWithPlacement004, TestSize.Level1) { SheetPresentationTestThreeNg::SetUpTestCase(); + SheetPresentationTestThreeNg::SetApiVersion(static_cast(PlatformVersion::VERSION_EIGHTEEN)); + auto callback = [](const std::string&) {}; + auto sheetNode = FrameNode::CreateFrameNode(V2::SHEET_PAGE_TAG, ElementRegister::GetInstance()->MakeUniqueId(), + AceType::MakeRefPtr( + ElementRegister::GetInstance()->MakeUniqueId(), V2::TEXT_ETS_TAG, std::move(callback))); auto sheetLayoutAlgorithm = AceType::MakeRefPtr(); - auto container = Container::Current(); - ASSERT_NE(container, nullptr); - container->SetApiTargetVersion(static_cast(PlatformVersion::VERSION_EIGHTEEN)); sheetLayoutAlgorithm->sheetPopupInfo_.placementRechecked = true; sheetLayoutAlgorithm->sheetPopupInfo_.placementOnTarget = false; sheetLayoutAlgorithm->sheetPopupInfo_.showArrow = false; float maxWidth = 3000.0f; float maxHeight = 2000.0f; - sheetLayoutAlgorithm->UpdateMaxSizeWithPlacement(maxWidth, maxHeight); + auto layoutWrapperNode = AceType::MakeRefPtr( + sheetNode, sheetNode->GetGeometryNode(), sheetNode->GetLayoutProperty()); + auto layoutWrapper = reinterpret_cast(Referenced::RawPtr(layoutWrapperNode)); + sheetLayoutAlgorithm->UpdateMaxSizeWithPlacement(maxWidth, maxHeight, layoutWrapper); EXPECT_EQ(maxWidth, 3000.0f); EXPECT_EQ(maxHeight, 2000.0f); SheetPresentationTestThreeNg::TearDownTestCase(); @@ -1277,42 +1330,47 @@ HWTEST_F(SheetPresentationTestThreeNg, UpdateMaxSizeWithPlacement004, TestSize.L HWTEST_F(SheetPresentationTestThreeNg, UpdateMaxSizeWithPlacement005, TestSize.Level1) { SheetPresentationTestThreeNg::SetUpTestCase(); + SheetPresentationTestThreeNg::SetApiVersion(static_cast(PlatformVersion::VERSION_EIGHTEEN)); + auto callback = [](const std::string&) {}; + auto sheetNode = FrameNode::CreateFrameNode(V2::SHEET_PAGE_TAG, ElementRegister::GetInstance()->MakeUniqueId(), + AceType::MakeRefPtr( + ElementRegister::GetInstance()->MakeUniqueId(), V2::TEXT_ETS_TAG, std::move(callback))); auto sheetLayoutAlgorithm = AceType::MakeRefPtr(); - auto container = Container::Current(); - ASSERT_NE(container, nullptr); - container->SetApiTargetVersion(static_cast(PlatformVersion::VERSION_EIGHTEEN)); sheetLayoutAlgorithm->sheetPopupInfo_.placementRechecked = false; sheetLayoutAlgorithm->sheetPopupInfo_.showArrow = true; sheetLayoutAlgorithm->sheetPopupInfo_.finalPlacement = Placement::BOTTOM_LEFT; float maxWidth = 3000.0f; float maxHeight = 2000.0f; - sheetLayoutAlgorithm->UpdateMaxSizeWithPlacement(maxWidth, maxHeight); + auto layoutWrapperNode = AceType::MakeRefPtr( + sheetNode, sheetNode->GetGeometryNode(), sheetNode->GetLayoutProperty()); + auto layoutWrapper = reinterpret_cast(Referenced::RawPtr(layoutWrapperNode)); + sheetLayoutAlgorithm->UpdateMaxSizeWithPlacement(maxWidth, maxHeight, layoutWrapper); EXPECT_EQ(maxWidth, 3000.0f); EXPECT_EQ(maxHeight, 1992.0f); sheetLayoutAlgorithm->sheetPopupInfo_.finalPlacement = Placement::BOTTOM_RIGHT; - sheetLayoutAlgorithm->UpdateMaxSizeWithPlacement(maxWidth, maxHeight); + sheetLayoutAlgorithm->UpdateMaxSizeWithPlacement(maxWidth, maxHeight, layoutWrapper); EXPECT_EQ(maxWidth, 3000.0f); EXPECT_EQ(maxHeight, 1984.0f); sheetLayoutAlgorithm->sheetPopupInfo_.finalPlacement = Placement::BOTTOM; - sheetLayoutAlgorithm->UpdateMaxSizeWithPlacement(maxWidth, maxHeight); + sheetLayoutAlgorithm->UpdateMaxSizeWithPlacement(maxWidth, maxHeight, layoutWrapper); EXPECT_EQ(maxWidth, 3000.0f); EXPECT_EQ(maxHeight, 1976.0f); sheetLayoutAlgorithm->sheetPopupInfo_.finalPlacement = Placement::TOP_LEFT; - sheetLayoutAlgorithm->UpdateMaxSizeWithPlacement(maxWidth, maxHeight); + sheetLayoutAlgorithm->UpdateMaxSizeWithPlacement(maxWidth, maxHeight, layoutWrapper); EXPECT_EQ(maxWidth, 3000.0f); EXPECT_EQ(maxHeight, 1968.0f); sheetLayoutAlgorithm->sheetPopupInfo_.finalPlacement = Placement::TOP_RIGHT; - sheetLayoutAlgorithm->UpdateMaxSizeWithPlacement(maxWidth, maxHeight); + sheetLayoutAlgorithm->UpdateMaxSizeWithPlacement(maxWidth, maxHeight, layoutWrapper); EXPECT_EQ(maxWidth, 3000.0f); EXPECT_EQ(maxHeight, 1960.0f); sheetLayoutAlgorithm->sheetPopupInfo_.finalPlacement = Placement::TOP; - sheetLayoutAlgorithm->UpdateMaxSizeWithPlacement(maxWidth, maxHeight); + sheetLayoutAlgorithm->UpdateMaxSizeWithPlacement(maxWidth, maxHeight, layoutWrapper); EXPECT_EQ(maxWidth, 3000.0f); EXPECT_EQ(maxHeight, 1952.0f); SheetPresentationTestThreeNg::TearDownTestCase(); @@ -1336,47 +1394,52 @@ HWTEST_F(SheetPresentationTestThreeNg, UpdateMaxSizeWithPlacement005, TestSize.L HWTEST_F(SheetPresentationTestThreeNg, UpdateMaxSizeWithPlacement006, TestSize.Level1) { SheetPresentationTestThreeNg::SetUpTestCase(); + SheetPresentationTestThreeNg::SetApiVersion(static_cast(PlatformVersion::VERSION_EIGHTEEN)); + auto callback = [](const std::string&) {}; + auto sheetNode = FrameNode::CreateFrameNode(V2::SHEET_PAGE_TAG, ElementRegister::GetInstance()->MakeUniqueId(), + AceType::MakeRefPtr( + ElementRegister::GetInstance()->MakeUniqueId(), V2::TEXT_ETS_TAG, std::move(callback))); auto sheetLayoutAlgorithm = AceType::MakeRefPtr(); - auto container = Container::Current(); - ASSERT_NE(container, nullptr); - container->SetApiTargetVersion(static_cast(PlatformVersion::VERSION_EIGHTEEN)); sheetLayoutAlgorithm->sheetPopupInfo_.placementRechecked = false; sheetLayoutAlgorithm->sheetPopupInfo_.showArrow = true; sheetLayoutAlgorithm->sheetPopupInfo_.finalPlacement = Placement::RIGHT_TOP; float maxWidth = 3000.0f; float maxHeight = 2000.0f; - sheetLayoutAlgorithm->UpdateMaxSizeWithPlacement(maxWidth, maxHeight); + auto layoutWrapperNode = AceType::MakeRefPtr( + sheetNode, sheetNode->GetGeometryNode(), sheetNode->GetLayoutProperty()); + auto layoutWrapper = reinterpret_cast(Referenced::RawPtr(layoutWrapperNode)); + sheetLayoutAlgorithm->UpdateMaxSizeWithPlacement(maxWidth, maxHeight, layoutWrapper); EXPECT_EQ(maxWidth, 2992.0f); EXPECT_EQ(maxHeight, 2000.0f); sheetLayoutAlgorithm->sheetPopupInfo_.finalPlacement = Placement::RIGHT_BOTTOM; - sheetLayoutAlgorithm->UpdateMaxSizeWithPlacement(maxWidth, maxHeight); + sheetLayoutAlgorithm->UpdateMaxSizeWithPlacement(maxWidth, maxHeight, layoutWrapper); EXPECT_EQ(maxWidth, 2984.0f); EXPECT_EQ(maxHeight, 2000.0f); sheetLayoutAlgorithm->sheetPopupInfo_.finalPlacement = Placement::RIGHT; - sheetLayoutAlgorithm->UpdateMaxSizeWithPlacement(maxWidth, maxHeight); + sheetLayoutAlgorithm->UpdateMaxSizeWithPlacement(maxWidth, maxHeight, layoutWrapper); EXPECT_EQ(maxWidth, 2976.0f); EXPECT_EQ(maxHeight, 2000.0f); sheetLayoutAlgorithm->sheetPopupInfo_.finalPlacement = Placement::LEFT_TOP; - sheetLayoutAlgorithm->UpdateMaxSizeWithPlacement(maxWidth, maxHeight); + sheetLayoutAlgorithm->UpdateMaxSizeWithPlacement(maxWidth, maxHeight, layoutWrapper); EXPECT_EQ(maxWidth, 2968.0f); EXPECT_EQ(maxHeight, 2000.0f); sheetLayoutAlgorithm->sheetPopupInfo_.finalPlacement = Placement::LEFT_BOTTOM; - sheetLayoutAlgorithm->UpdateMaxSizeWithPlacement(maxWidth, maxHeight); + sheetLayoutAlgorithm->UpdateMaxSizeWithPlacement(maxWidth, maxHeight, layoutWrapper); EXPECT_EQ(maxWidth, 2960.0f); EXPECT_EQ(maxHeight, 2000.0f); sheetLayoutAlgorithm->sheetPopupInfo_.finalPlacement = Placement::LEFT; - sheetLayoutAlgorithm->UpdateMaxSizeWithPlacement(maxWidth, maxHeight); + sheetLayoutAlgorithm->UpdateMaxSizeWithPlacement(maxWidth, maxHeight, layoutWrapper); EXPECT_EQ(maxWidth, 2952.0f); EXPECT_EQ(maxHeight, 2000.0f); sheetLayoutAlgorithm->sheetPopupInfo_.finalPlacement = Placement::NONE; - sheetLayoutAlgorithm->UpdateMaxSizeWithPlacement(maxWidth, maxHeight); + sheetLayoutAlgorithm->UpdateMaxSizeWithPlacement(maxWidth, maxHeight, layoutWrapper); EXPECT_EQ(maxWidth, 2952.0f); EXPECT_EQ(maxHeight, 2000.0f); SheetPresentationTestThreeNg::TearDownTestCase(); diff --git a/test/unittest/core/pattern/overlay/sheet_presentation_test_two_ng.cpp b/test/unittest/core/pattern/overlay/sheet_presentation_test_two_ng.cpp index 111d7e636c416a91fb3e67fb4ec100d9da9d37d9..12d4ea98f8e1e37213d2197015ca21eb57c37f93 100644 --- a/test/unittest/core/pattern/overlay/sheet_presentation_test_two_ng.cpp +++ b/test/unittest/core/pattern/overlay/sheet_presentation_test_two_ng.cpp @@ -48,6 +48,7 @@ public: static void SetSheetTheme(RefPtr sheetTheme); static void SetSheetType(RefPtr sheetPattern, SheetType sheetType); static void TearDownTestCase(); + static void SetApiVersion(int32_t apiTargetVersion); private: void SetOnBindSheet(); @@ -131,7 +132,6 @@ void SheetPresentationTestTwoNg::SetOnBindSheet() void SheetPresentationTestTwoNg::SetSheetType(RefPtr sheetPattern, SheetType sheetType) { - PipelineBase::GetCurrentContext()->minPlatformVersion_ = static_cast(PlatformVersion::VERSION_TWELVE); auto pipelineContext = PipelineContext::GetCurrentContext(); pipelineContext->displayWindowRectInfo_.width_ = SHEET_DEVICE_WIDTH_BREAKPOINT.ConvertToPx(); auto layoutProperty = sheetPattern->GetLayoutProperty(); @@ -149,6 +149,13 @@ void SheetPresentationTestTwoNg::SetSheetType(RefPtr s SheetPresentationTestTwoNg::SetSheetTheme(sheetTheme); } +void SheetPresentationTestTwoNg::SetApiVersion(int32_t apiTargetVersion) +{ + auto container = Container::Current(); + ASSERT_NE(container, nullptr); + container->SetApiTargetVersion(apiTargetVersion); +} + void SheetPresentationTestTwoNg::TearDownTestCase() { MockPipelineContext::TearDown(); @@ -163,6 +170,7 @@ void SheetPresentationTestTwoNg::TearDownTestCase() HWTEST_F(SheetPresentationTestTwoNg, SetSheetType001, TestSize.Level1) { SheetPresentationTestTwoNg::SetUpTestCase(); + SheetPresentationTestTwoNg::SetApiVersion(static_cast(PlatformVersion::VERSION_TWELVE)); auto callback = [](const std::string&) {}; auto sheetNode = FrameNode::CreateFrameNode("Sheet", 101, AceType::MakeRefPtr(201, "SheetPresentation", std::move(callback))); @@ -330,6 +338,7 @@ HWTEST_F(SheetPresentationTestTwoNg, IsPhoneInLandScape004, TestSize.Level1) HWTEST_F(SheetPresentationTestTwoNg, HandleDragUpdate001, TestSize.Level1) { SheetPresentationTestTwoNg::SetUpTestCase(); + SheetPresentationTestTwoNg::SetApiVersion(static_cast(PlatformVersion::VERSION_TWELVE)); auto callback = [](const std::string&) {}; auto sheetNode = FrameNode::CreateFrameNode("Sheet", 101, AceType::MakeRefPtr(201, "SheetPresentation", std::move(callback))); @@ -547,6 +556,7 @@ HWTEST_F(SheetPresentationTestTwoNg, HandleDragUpdate006, TestSize.Level1) HWTEST_F(SheetPresentationTestTwoNg, HandleDragUpdate007, TestSize.Level1) { SheetPresentationTestTwoNg::SetUpTestCase(); + SheetPresentationTestTwoNg::SetApiVersion(static_cast(PlatformVersion::VERSION_TWELVE)); auto callback = [](const std::string&) {}; auto sheetNode = FrameNode::CreateFrameNode("Sheet", 101, AceType::MakeRefPtr(201, "SheetPresentation", std::move(callback))); @@ -1706,6 +1716,7 @@ HWTEST_F(SheetPresentationTestTwoNg, SheetOffset004, TestSize.Level1) * @tc.steps: step1. set up bind sheet and theme */ SheetPresentationTestTwoNg::SetUpTestCase(); + SheetPresentationTestTwoNg::SetApiVersion(static_cast(PlatformVersion::VERSION_TWELVE)); auto callback = [](const std::string&) {}; auto sheetNode = FrameNode::CreateFrameNode( "Sheet", 101, AceType::MakeRefPtr(201, "SheetPresentation", std::move(callback))); @@ -1721,7 +1732,6 @@ HWTEST_F(SheetPresentationTestTwoNg, SheetOffset004, TestSize.Level1) sheetStyle.sheetType = SheetType::SHEET_BOTTOM; sheetStyle.bottomOffset = { 10, 20 }; layoutProperty->propSheetStyle_ = sheetStyle; - PipelineBase::GetCurrentContext()->minPlatformVersion_ = static_cast(PlatformVersion::VERSION_TWELVE); auto pipelineContext = PipelineContext::GetCurrentContext(); pipelineContext->displayWindowRectInfo_.width_ = SHEET_DEVICE_WIDTH_BREAKPOINT.ConvertToPx(); @@ -1798,6 +1808,7 @@ HWTEST_F(SheetPresentationTestTwoNg, SheetOffset006, TestSize.Level1) * @tc.steps: step1. set up bind sheet and theme. */ SheetPresentationTestTwoNg::SetUpTestCase(); + SheetPresentationTestTwoNg::SetApiVersion(static_cast(PlatformVersion::VERSION_TWELVE)); auto callback = [](const std::string&) {}; auto sheetNode = FrameNode::CreateFrameNode( "Sheet", 101, AceType::MakeRefPtr(201, "SheetPresentation", std::move(callback))); @@ -1820,7 +1831,6 @@ HWTEST_F(SheetPresentationTestTwoNg, SheetOffset006, TestSize.Level1) DirtySwapConfig config; config.skipMeasure = false; sheetPattern->OnDirtyLayoutWrapperSwap(dirty, config); - PipelineBase::GetCurrentContext()->minPlatformVersion_ = static_cast(PlatformVersion::VERSION_TWELVE); auto pipelineContext = PipelineContext::GetCurrentContext(); pipelineContext->displayWindowRectInfo_.width_ = SHEET_DEVICE_WIDTH_BREAKPOINT.ConvertToPx(); auto manager = pipelineContext->GetWindowManager(); @@ -2024,9 +2034,7 @@ HWTEST_F(SheetPresentationTestTwoNg, UpdateBackBlurStyle001, TestSize.Level1) * @tc.steps: step1. create target node and set API12. */ SheetPresentationTestTwoNg::SetUpTestCase(); - auto container = Container::Current(); - ASSERT_NE(container, nullptr); - container->SetApiTargetVersion(static_cast(PlatformVersion::VERSION_TWELVE)); + SheetPresentationTestTwoNg::SetApiVersion(static_cast(PlatformVersion::VERSION_TWELVE)); auto targetNode = FrameNode::GetOrCreateFrameNode(V2::BUTTON_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr(); }); @@ -2293,6 +2301,7 @@ HWTEST_F(SheetPresentationTestTwoNg, ComputeSheetOffset001, TestSize.Level1) * @tc.steps: step1. create target node. */ SheetPresentationTestTwoNg::SetUpTestCase(); + SheetPresentationTestTwoNg::SetApiVersion(static_cast(PlatformVersion::VERSION_TWELVE)); auto targetNode = FrameNode::GetOrCreateFrameNode(V2::BUTTON_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr(); }); auto stageNode = FrameNode::CreateFrameNode( @@ -2322,32 +2331,6 @@ HWTEST_F(SheetPresentationTestTwoNg, ComputeSheetOffset001, TestSize.Level1) auto sheetPattern = sheetNode->GetPattern(); ASSERT_NE(sheetPattern, nullptr); - /** - * @tc.steps: step4. set API11. - */ - int originApiVersion = AceApplicationInfo::GetInstance().GetApiTargetVersion(); - AceApplicationInfo::GetInstance().apiVersion_ = static_cast(PlatformVersion::VERSION_ELEVEN); - - /** - * @tc.steps: step5. set SheetType to SHEET_BOTTOMLANDSPACE. - * @tc.expected: SheetType is SHEET_BOTTOMLANDSPACE and pageHeight_ is 800. - */ - SheetPresentationTestTwoNg::SetSheetType(sheetPattern, SheetType::SHEET_BOTTOMLANDSPACE); - EXPECT_EQ(sheetPattern->GetSheetType(), SheetType::SHEET_BOTTOMLANDSPACE); - sheetPattern->pageHeight_ = 800.0f; - - /** - * @tc.steps: step6. excute ComputeSheetOffset function. - * @tc.expected: sheetHeight_ is (pageHeight_ - SHEET_BLANK_MINI_HEIGHT.ConvertToPx()). - */ - overlayManager->ComputeSheetOffset(sheetStyle, sheetNode); - EXPECT_EQ(overlayManager->sheetHeight_, 800 - SHEET_BLANK_MINI_HEIGHT.ConvertToPx()); - - /** - * @tc.steps: step7. set API12. - */ - AceApplicationInfo::GetInstance().apiVersion_ = static_cast(PlatformVersion::VERSION_TWELVE); - /** * @tc.steps: step8. set SheetType to SHEET_BOTTOMLANDSPACE. * @tc.expected: SheetType is SHEET_BOTTOMLANDSPACE and pageHeight_ is 1000 and frameSize height is 500. @@ -2380,7 +2363,56 @@ HWTEST_F(SheetPresentationTestTwoNg, ComputeSheetOffset001, TestSize.Level1) overlayManager->ComputeSheetOffset(sheetStyle, sheetNode); EXPECT_EQ(overlayManager->sheetHeight_, 1200); SheetPresentationTestTwoNg::TearDownTestCase(); - AceApplicationInfo::GetInstance().SetApiTargetVersion(originApiVersion); +} + +/** + * @tc.name: ComputeSheetOffset002 + * @tc.desc: Test OverlayManager::ComputeSheetOffset. + * @tc.type: FUNC + */ +HWTEST_F(SheetPresentationTestTwoNg, ComputeSheetOffset002, TestSize.Level1) +{ + /** + * @tc.steps: step1. create target node. + */ + SheetPresentationTestTwoNg::SetUpTestCase(); + SheetPresentationTestTwoNg::SetApiVersion(static_cast(PlatformVersion::VERSION_ELEVEN)); + auto targetNode = FrameNode::GetOrCreateFrameNode(V2::BUTTON_ETS_TAG, + ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr(); }); + auto stageNode = FrameNode::CreateFrameNode( + V2::STAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr()); + auto rootNode = FrameNode::CreateFrameNode(V2::ROOT_ETS_TAG, 1, AceType::MakeRefPtr()); + stageNode->MountToParent(rootNode); + targetNode->MountToParent(stageNode); + rootNode->MarkDirtyNode(); + + /** + * @tc.steps: step2. create sheetNode, get sheetNode. + * @tc.expected: sheetNode is not nullptr. + */ + SheetStyle sheetStyle; + bool isShow = true; + CreateSheetBuilder(); + auto overlayManager = AceType::MakeRefPtr(rootNode); + overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc_), std::move(titleBuilderFunc_), sheetStyle, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, targetNode); + EXPECT_FALSE(overlayManager->modalStack_.empty()); + auto sheetNode = overlayManager->modalStack_.top().Upgrade(); + ASSERT_NE(sheetNode, nullptr); + + /** + * @tc.steps: step3. get sheetPattern. + */ + auto sheetPattern = sheetNode->GetPattern(); + ASSERT_NE(sheetPattern, nullptr); + + /** + * @tc.steps: step5. set SheetType to SHEET_BOTTOMLANDSPACE. + * @tc.expected: SheetType is SHEET_BOTTOMLANDSPACE and pageHeight_ is 800. + */ + SheetPresentationTestTwoNg::SetSheetType(sheetPattern, SheetType::SHEET_BOTTOMLANDSPACE); + EXPECT_EQ(sheetPattern->GetSheetType(), SheetType::SHEET_BOTTOMLANDSPACE); + SheetPresentationTestTwoNg::TearDownTestCase(); } /** @@ -2652,6 +2684,7 @@ HWTEST_F(SheetPresentationTestTwoNg, SheetHoverStatus006, TestSize.Level1) overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc_), std::move(titleBuilderFunc_), sheetStyle, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, targetNode); SheetPresentationTestTwoNg::SetUpTestCase(); + SheetPresentationTestTwoNg::SetApiVersion(static_cast(PlatformVersion::VERSION_TWELVE)); auto callback = [](const std::string&) {}; auto sheetNode = FrameNode::CreateFrameNode( "Sheet", 101, AceType::MakeRefPtr(201, "SheetPresentation", std::move(callback))); @@ -2660,7 +2693,6 @@ HWTEST_F(SheetPresentationTestTwoNg, SheetHoverStatus006, TestSize.Level1) sheetPattern->UpdateSheetType(); sheetPattern->InitSheetObject(); ASSERT_NE(sheetPattern->GetSheetObject(), nullptr); - PipelineBase::GetCurrentContext()->minPlatformVersion_ = static_cast(PlatformVersion::VERSION_TWELVE); auto pipeline = PipelineContext::GetCurrentContext(); pipeline->displayWindowRectInfo_.width_ = SHEET_DEVICE_WIDTH_BREAKPOINT.ConvertToPx(); auto sheetTheme = AceType::MakeRefPtr(); @@ -2725,6 +2757,7 @@ HWTEST_F(SheetPresentationTestTwoNg, SheetHoverStatus007, TestSize.Level1) overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc_), std::move(titleBuilderFunc_), sheetStyle, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, targetNode); SheetPresentationTestTwoNg::SetUpTestCase(); + SheetPresentationTestTwoNg::SetApiVersion(static_cast(PlatformVersion::VERSION_TWELVE)); /** * @tc.steps: step3. set sheet theme. @@ -2734,7 +2767,6 @@ HWTEST_F(SheetPresentationTestTwoNg, SheetHoverStatus007, TestSize.Level1) "Sheet", 101, AceType::MakeRefPtr(201, "SheetPresentation", std::move(callback))); auto sheetPattern = sheetNode->GetPattern(); ASSERT_NE(sheetPattern, nullptr); - PipelineBase::GetCurrentContext()->minPlatformVersion_ = static_cast(PlatformVersion::VERSION_TWELVE); auto pipeline = PipelineContext::GetCurrentContext(); pipeline->displayWindowRectInfo_.width_ = SHEET_DEVICE_WIDTH_BREAKPOINT.ConvertToPx(); auto sheetTheme = AceType::MakeRefPtr(); diff --git a/test/unittest/core/pattern/overlay/sheet_showInSubwindow_test_ng.cpp b/test/unittest/core/pattern/overlay/sheet_showInSubwindow_test_ng.cpp index d55421b753a7d02b5f618b1110328279cb816527..99543c12319576556894e3d79f38e7958551a580 100644 --- a/test/unittest/core/pattern/overlay/sheet_showInSubwindow_test_ng.cpp +++ b/test/unittest/core/pattern/overlay/sheet_showInSubwindow_test_ng.cpp @@ -67,6 +67,7 @@ public: std::function()> builderFunc_; std::function()> titleBuilderFunc_; static void SetSheetTheme(RefPtr sheetTheme); + static void SetApiVersion(int32_t apiTargetVersion); // Before each TEST_F, the scope is a single test case void SetUp() override; // After each TEST_F, the scope is a single test case @@ -205,6 +206,13 @@ RefPtr SheetShowInSubwindowTestNg::InitTargetNodeEnv(RefPtrSetApiTargetVersion(apiTargetVersion); +} + HWTEST_F(SheetShowInSubwindowTestNg, RemoveSheet001, TestSize.Level1) { /** @@ -551,7 +559,7 @@ HWTEST_F(SheetShowInSubwindowTestNg, InitSheetWrapperAction004, TestSize.Level1) */ HWTEST_F(SheetShowInSubwindowTestNg, GetSheetTypeNumber1, TestSize.Level1) { - PipelineBase::GetCurrentContext()->SetMinPlatformVersion(static_cast(PlatformVersion::VERSION_FOURTEEN)); + SheetShowInSubwindowTestNg::SetApiVersion(static_cast(PlatformVersion::VERSION_FOURTEEN)); /** * @tc.steps: step1. create sheet page, get sheet pattern. */ @@ -609,8 +617,7 @@ HWTEST_F(SheetShowInSubwindowTestNg, GetSheetTypeNumber1, TestSize.Level1) */ HWTEST_F(SheetShowInSubwindowTestNg, GetSheetTypeNumber2, TestSize.Level1) { - MockPipelineContext::GetCurrentContext()->SetMinPlatformVersion( - static_cast(PlatformVersion::VERSION_FOURTEEN)); + SheetShowInSubwindowTestNg::SetApiVersion(static_cast(PlatformVersion::VERSION_FOURTEEN)); /** * @tc.steps: step1. create sheet page, get sheet pattern. */ @@ -673,7 +680,7 @@ HWTEST_F(SheetShowInSubwindowTestNg, GetSheetTypeNumber2, TestSize.Level1) */ HWTEST_F(SheetShowInSubwindowTestNg, GetSheetTypeNumber3, TestSize.Level1) { - PipelineBase::GetCurrentContext()->SetMinPlatformVersion(static_cast(PlatformVersion::VERSION_FOURTEEN)); + SheetShowInSubwindowTestNg::SetApiVersion(static_cast(PlatformVersion::VERSION_FOURTEEN)); /** * @tc.steps: step1. create sheet page, get sheet pattern. @@ -859,7 +866,7 @@ HWTEST_F(SheetShowInSubwindowTestNg, GetSheetTypeNumber5, TestSize.Level1) */ HWTEST_F(SheetShowInSubwindowTestNg, GetSheetTypeNumber6, TestSize.Level1) { - PipelineBase::GetCurrentContext()->SetMinPlatformVersion(static_cast(PlatformVersion::VERSION_TWENTY)); + SheetShowInSubwindowTestNg::SetApiVersion(static_cast(PlatformVersion::VERSION_TWENTY)); /** * @tc.steps: step1. create sheet page, get sheet pattern. */ @@ -1122,8 +1129,8 @@ HWTEST_F(SheetShowInSubwindowTestNg, SideSheetLayoutAlgorithm5, TestSize.Level1) Dimension titleTextMargin = 2.0_vp; auto pipelineContext = MockPipelineContext::GetCurrentContext(); ASSERT_NE(pipelineContext, nullptr); - pipelineContext->SetMinPlatformVersion(static_cast(PlatformVersion::VERSION_TWENTY)); pipelineContext->SetDisplayWindowRectInfo({ 0, 0, 1000, 1600 }); + pipelineContext->SetMinPlatformVersion(static_cast(PlatformVersion::VERSION_TWENTY)); auto sheetTheme = AceType::MakeRefPtr(); sheetTheme->closeIconButtonWidth_ = closeIconButtonWidth; sheetTheme->titleTextMargin_ = titleTextMargin; diff --git a/test/unittest/core/pattern/overlay/sheet_wrapper_layout_test_ng.cpp b/test/unittest/core/pattern/overlay/sheet_wrapper_layout_test_ng.cpp index 2fb815c0b8a7d212956cbc77341136175dfd8279..30ab60a09647648adfde54e02f3bed9d2324ecb1 100644 --- a/test/unittest/core/pattern/overlay/sheet_wrapper_layout_test_ng.cpp +++ b/test/unittest/core/pattern/overlay/sheet_wrapper_layout_test_ng.cpp @@ -37,6 +37,7 @@ class SheetWrapperLayoutTestNg : public testing::Test { public: static void SetUpTestCase(); static void TearDownTestCase(); + static void SetApiVersion(int32_t apiTargetVersion); }; void SheetWrapperLayoutTestNg::SetUpTestCase() @@ -61,6 +62,13 @@ void SheetWrapperLayoutTestNg::TearDownTestCase() MockContainer::TearDown(); } +void SheetWrapperLayoutTestNg::SetApiVersion(int32_t apiTargetVersion) +{ + auto container = Container::Current(); + ASSERT_NE(container, nullptr); + container->SetApiTargetVersion(apiTargetVersion); +} + /** * @tc.name: DecreaseArrowHeightWhenArrowIsShown001 * @tc.desc: Branch: if (Container::LessThanAPITargetVersion(VERSION_EIGHTEEN)) = true @@ -69,6 +77,7 @@ void SheetWrapperLayoutTestNg::TearDownTestCase() HWTEST_F(SheetWrapperLayoutTestNg, DecreaseArrowHeightWhenArrowIsShown001, TestSize.Level1) { SheetWrapperLayoutTestNg::SetUpTestCase(); + SheetWrapperLayoutTestNg::SetApiVersion(static_cast(PlatformVersion::VERSION_TWELVE)); auto callback = [](const std::string&) {}; auto sheetNode = FrameNode::CreateFrameNode(V2::SHEET_PAGE_TAG, ElementRegister::GetInstance()->MakeUniqueId(), @@ -76,9 +85,6 @@ HWTEST_F(SheetWrapperLayoutTestNg, DecreaseArrowHeightWhenArrowIsShown001, TestS V2::TEXT_ETS_TAG, std::move(callback))); auto sheetWrapperLayoutAlgorithm = AceType::MakeRefPtr(); sheetWrapperLayoutAlgorithm->sheetRadius_ = { 0.0_vp, 0.0_vp, 0.0_vp, 0.0_vp }; - auto container = Container::Current(); - ASSERT_NE(container, nullptr); - container->SetApiTargetVersion(static_cast(PlatformVersion::VERSION_TWELVE)); sheetWrapperLayoutAlgorithm->sheetHeight_ = 1000.0f; sheetWrapperLayoutAlgorithm->sheetWidth_ = 400.0f; @@ -97,6 +103,7 @@ HWTEST_F(SheetWrapperLayoutTestNg, DecreaseArrowHeightWhenArrowIsShown001, TestS HWTEST_F(SheetWrapperLayoutTestNg, DecreaseArrowHeightWhenArrowIsShown002, TestSize.Level1) { SheetWrapperLayoutTestNg::SetUpTestCase(); + SheetWrapperLayoutTestNg::SetApiVersion(static_cast(PlatformVersion::VERSION_EIGHTEEN)); auto callback = [](const std::string&) {}; auto sheetNode = FrameNode::CreateFrameNode(V2::SHEET_PAGE_TAG, ElementRegister::GetInstance()->MakeUniqueId(), @@ -104,9 +111,6 @@ HWTEST_F(SheetWrapperLayoutTestNg, DecreaseArrowHeightWhenArrowIsShown002, TestS V2::TEXT_ETS_TAG, std::move(callback))); auto sheetWrapperLayoutAlgorithm = AceType::MakeRefPtr(); sheetWrapperLayoutAlgorithm->sheetRadius_ = { 0.0_vp, 0.0_vp, 0.0_vp, 0.0_vp }; - auto container = Container::Current(); - ASSERT_NE(container, nullptr); - container->SetApiTargetVersion(static_cast(PlatformVersion::VERSION_EIGHTEEN)); auto sheetPattern = sheetNode->GetPattern(); sheetPattern->sheetPopupInfo_.showArrow = false; sheetWrapperLayoutAlgorithm->sheetHeight_ = 1000.0f; @@ -133,6 +137,7 @@ HWTEST_F(SheetWrapperLayoutTestNg, DecreaseArrowHeightWhenArrowIsShown002, TestS HWTEST_F(SheetWrapperLayoutTestNg, DecreaseArrowHeightWhenArrowIsShown003, TestSize.Level1) { SheetWrapperLayoutTestNg::SetUpTestCase(); + SheetWrapperLayoutTestNg::SetApiVersion(static_cast(PlatformVersion::VERSION_EIGHTEEN)); auto callback = [](const std::string&) {}; auto sheetNode = FrameNode::CreateFrameNode(V2::SHEET_PAGE_TAG, ElementRegister::GetInstance()->MakeUniqueId(), @@ -140,9 +145,6 @@ HWTEST_F(SheetWrapperLayoutTestNg, DecreaseArrowHeightWhenArrowIsShown003, TestS V2::TEXT_ETS_TAG, std::move(callback))); auto sheetWrapperLayoutAlgorithm = AceType::MakeRefPtr(); sheetWrapperLayoutAlgorithm->sheetRadius_ = { 0.0_vp, 0.0_vp, 0.0_vp, 0.0_vp }; - auto container = Container::Current(); - ASSERT_NE(container, nullptr); - container->SetApiTargetVersion(static_cast(PlatformVersion::VERSION_EIGHTEEN)); auto sheetPattern = sheetNode->GetPattern(); sheetPattern->sheetPopupInfo_.showArrow = true; sheetPattern->sheetPopupInfo_.finalPlacement = Placement::BOTTOM_LEFT; @@ -193,6 +195,7 @@ HWTEST_F(SheetWrapperLayoutTestNg, DecreaseArrowHeightWhenArrowIsShown003, TestS HWTEST_F(SheetWrapperLayoutTestNg, DecreaseArrowHeightWhenArrowIsShown004, TestSize.Level1) { SheetWrapperLayoutTestNg::SetUpTestCase(); + SheetWrapperLayoutTestNg::SetApiVersion(static_cast(PlatformVersion::VERSION_EIGHTEEN)); auto callback = [](const std::string&) {}; auto sheetNode = FrameNode::CreateFrameNode(V2::SHEET_PAGE_TAG, ElementRegister::GetInstance()->MakeUniqueId(), @@ -200,9 +203,6 @@ HWTEST_F(SheetWrapperLayoutTestNg, DecreaseArrowHeightWhenArrowIsShown004, TestS V2::TEXT_ETS_TAG, std::move(callback))); auto sheetWrapperLayoutAlgorithm = AceType::MakeRefPtr(); sheetWrapperLayoutAlgorithm->sheetRadius_ = { 0.0_vp, 0.0_vp, 0.0_vp, 0.0_vp }; - auto container = Container::Current(); - ASSERT_NE(container, nullptr); - container->SetApiTargetVersion(static_cast(PlatformVersion::VERSION_EIGHTEEN)); auto sheetPattern = sheetNode->GetPattern(); sheetPattern->sheetPopupInfo_.showArrow = true; sheetPattern->sheetPopupInfo_.finalPlacement = Placement::RIGHT_TOP; @@ -248,6 +248,7 @@ HWTEST_F(SheetWrapperLayoutTestNg, DecreaseArrowHeightWhenArrowIsShown004, TestS HWTEST_F(SheetWrapperLayoutTestNg, DecreaseArrowHeightWhenArrowIsShown005, TestSize.Level1) { SheetWrapperLayoutTestNg::SetUpTestCase(); + SheetWrapperLayoutTestNg::SetApiVersion(static_cast(PlatformVersion::VERSION_EIGHTEEN)); auto callback = [](const std::string&) {}; auto sheetNode = FrameNode::CreateFrameNode(V2::SHEET_PAGE_TAG, ElementRegister::GetInstance()->MakeUniqueId(), @@ -255,9 +256,6 @@ HWTEST_F(SheetWrapperLayoutTestNg, DecreaseArrowHeightWhenArrowIsShown005, TestS V2::TEXT_ETS_TAG, std::move(callback))); auto sheetWrapperLayoutAlgorithm = AceType::MakeRefPtr(); sheetWrapperLayoutAlgorithm->sheetRadius_ = { 0.0_vp, 0.0_vp, 0.0_vp, 0.0_vp }; - auto container = Container::Current(); - ASSERT_NE(container, nullptr); - container->SetApiTargetVersion(static_cast(PlatformVersion::VERSION_EIGHTEEN)); auto sheetPattern = sheetNode->GetPattern(); sheetPattern->sheetPopupInfo_.showArrow = true; sheetWrapperLayoutAlgorithm->sheetHeight_ = 1000.0f; diff --git a/test/unittest/core/pattern/overlay/sheet_wrapper_paint_test_ng.cpp b/test/unittest/core/pattern/overlay/sheet_wrapper_paint_test_ng.cpp index 473f8157bbe2596b7ca44cff5864f4552faa9f5f..91fbb7f4017457def86f48429fedd89387b65fa5 100644 --- a/test/unittest/core/pattern/overlay/sheet_wrapper_paint_test_ng.cpp +++ b/test/unittest/core/pattern/overlay/sheet_wrapper_paint_test_ng.cpp @@ -39,6 +39,7 @@ public: static void SetUpTestCase(); static void TearDownTestCase(); static void SetSheetType(RefPtr sheetPattern, SheetType sheetType); + static void SetApiVersion(int32_t apiTargetVersion); }; RefPtr SheetWrapperPaintTestNg::sheetTheme_ = nullptr; @@ -68,7 +69,6 @@ void SheetWrapperPaintTestNg::TearDownTestCase() void SheetWrapperPaintTestNg::SetSheetType(RefPtr sheetPattern, SheetType sheetType) { - PipelineBase::GetCurrentContext()->minPlatformVersion_ = static_cast(PlatformVersion::VERSION_TWELVE); auto pipelineContext = PipelineContext::GetCurrentContext(); pipelineContext->displayWindowRectInfo_.width_ = SHEET_DEVICE_WIDTH_BREAKPOINT.ConvertToPx(); auto layoutProperty = sheetPattern->GetLayoutProperty(); @@ -83,6 +83,13 @@ void SheetWrapperPaintTestNg::SetSheetType(RefPtr shee sheetTheme_->sheetType_ = "popup"; } +void SheetWrapperPaintTestNg::SetApiVersion(int32_t apiTargetVersion) +{ + auto container = Container::Current(); + ASSERT_NE(container, nullptr); + container->SetApiTargetVersion(apiTargetVersion); +} + /** * @tc.name: IsDrawBorder001 * @tc.desc: Branch: if (sheetTheme->IsOuterBorderEnable() && sheetType == SheetType::SHEET_POPUP && @@ -126,6 +133,7 @@ HWTEST_F(SheetWrapperPaintTestNg, IsDrawBorder001, TestSize.Level1) HWTEST_F(SheetWrapperPaintTestNg, IsDrawBorder002, TestSize.Level1) { SheetWrapperPaintTestNg::SetUpTestCase(); + SheetWrapperPaintTestNg::SetApiVersion(static_cast(PlatformVersion::VERSION_TWELVE)); auto columnNode = FrameNode::GetOrCreateFrameNode(V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr(true); }); @@ -161,6 +169,7 @@ HWTEST_F(SheetWrapperPaintTestNg, IsDrawBorder002, TestSize.Level1) HWTEST_F(SheetWrapperPaintTestNg, IsDrawBorder003, TestSize.Level1) { SheetWrapperPaintTestNg::SetUpTestCase(); + SheetWrapperPaintTestNg::SetApiVersion(static_cast(PlatformVersion::VERSION_TWELVE)); auto columnNode = FrameNode::GetOrCreateFrameNode(V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr(true); }); @@ -197,6 +206,7 @@ HWTEST_F(SheetWrapperPaintTestNg, IsDrawBorder003, TestSize.Level1) HWTEST_F(SheetWrapperPaintTestNg, IsDrawBorder004, TestSize.Level1) { SheetWrapperPaintTestNg::SetUpTestCase(); + SheetWrapperPaintTestNg::SetApiVersion(static_cast(PlatformVersion::VERSION_TWELVE)); auto columnNode = FrameNode::GetOrCreateFrameNode(V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr(true); });