123b3eb3cSopenharmony_ci/* 223b3eb3cSopenharmony_ci * Copyright (c) 2021-2023 Huawei Device Co., Ltd. 323b3eb3cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 423b3eb3cSopenharmony_ci * you may not use this file except in compliance with the License. 523b3eb3cSopenharmony_ci * You may obtain a copy of the License at 623b3eb3cSopenharmony_ci * 723b3eb3cSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 823b3eb3cSopenharmony_ci * 923b3eb3cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1023b3eb3cSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1123b3eb3cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1223b3eb3cSopenharmony_ci * See the License for the specific language governing permissions and 1323b3eb3cSopenharmony_ci * limitations under the License. 1423b3eb3cSopenharmony_ci */ 1523b3eb3cSopenharmony_ci 1623b3eb3cSopenharmony_ci#include "frameworks/bridge/common/utils/utils.h" 1723b3eb3cSopenharmony_ci 1823b3eb3cSopenharmony_ci#include "frameworks/bridge/js_frontend/engine/common/js_constants.h" 1923b3eb3cSopenharmony_ci#include "interfaces/native/native_type.h" 2023b3eb3cSopenharmony_ci 2123b3eb3cSopenharmony_cinamespace OHOS::Ace::Framework { 2223b3eb3cSopenharmony_ci 2323b3eb3cSopenharmony_cinamespace { 2423b3eb3cSopenharmony_ci 2523b3eb3cSopenharmony_ciusing CustomCurveCreator = RefPtr<Curve> (*)(const std::vector<std::string>&); 2623b3eb3cSopenharmony_ci 2723b3eb3cSopenharmony_ciconst size_t STEPS_PARAMS_SIZE = 2; 2823b3eb3cSopenharmony_ciconst size_t CUBIC_PARAMS_SIZE = 4; 2923b3eb3cSopenharmony_ciconst size_t SPRING_PARAMS_SIZE = 4; 3023b3eb3cSopenharmony_ciconstexpr size_t RESPONSIVE_SPRING_MOTION_PARAMS_SIZE = 3; 3123b3eb3cSopenharmony_ciconstexpr size_t INTERPOLATING_SPRING_PARAMS_SIZE = 4; 3223b3eb3cSopenharmony_ci 3323b3eb3cSopenharmony_cistatic const std::unordered_set<std::string> HORIZON_SET = { 3423b3eb3cSopenharmony_ci DOM_BACKGROUND_IMAGE_POSITION_LEFT, 3523b3eb3cSopenharmony_ci DOM_BACKGROUND_IMAGE_POSITION_RIGHT, 3623b3eb3cSopenharmony_ci}; 3723b3eb3cSopenharmony_cistatic const std::unordered_set<std::string> VERTICAL_SET = { 3823b3eb3cSopenharmony_ci DOM_BACKGROUND_IMAGE_POSITION_TOP, 3923b3eb3cSopenharmony_ci DOM_BACKGROUND_IMAGE_POSITION_BOTTOM, 4023b3eb3cSopenharmony_ci}; 4123b3eb3cSopenharmony_cistatic const std::unordered_set<std::string> OBJECT_HORIZON_SET = { 4223b3eb3cSopenharmony_ci DOM_IMAGE_POSITION_LEFT, 4323b3eb3cSopenharmony_ci DOM_IMAGE_POSITION_RIGHT, 4423b3eb3cSopenharmony_ci}; 4523b3eb3cSopenharmony_cistatic const std::unordered_set<std::string> OBJECT_VERTICAL_SET = { 4623b3eb3cSopenharmony_ci DOM_IMAGE_POSITION_TOP, 4723b3eb3cSopenharmony_ci DOM_IMAGE_POSITION_BOTTOM, 4823b3eb3cSopenharmony_ci}; 4923b3eb3cSopenharmony_ci 5023b3eb3cSopenharmony_ciRefPtr<Curve> StepsCurveCreator(const std::vector<std::string>& params) 5123b3eb3cSopenharmony_ci{ 5223b3eb3cSopenharmony_ci if (params.empty() || params.size() > STEPS_PARAMS_SIZE) { 5323b3eb3cSopenharmony_ci return nullptr; 5423b3eb3cSopenharmony_ci } 5523b3eb3cSopenharmony_ci auto step = StringUtils::StringToInt(params.front()); 5623b3eb3cSopenharmony_ci if (step <= 0) { 5723b3eb3cSopenharmony_ci return nullptr; 5823b3eb3cSopenharmony_ci } 5923b3eb3cSopenharmony_ci StepsCurvePosition position = StepsCurvePosition::END; 6023b3eb3cSopenharmony_ci if (params.size() > 1) { 6123b3eb3cSopenharmony_ci if (params.back() == "start") { 6223b3eb3cSopenharmony_ci position = StepsCurvePosition::START; 6323b3eb3cSopenharmony_ci } else if (params.back() == "end") { 6423b3eb3cSopenharmony_ci position = StepsCurvePosition::END; 6523b3eb3cSopenharmony_ci } else { 6623b3eb3cSopenharmony_ci return nullptr; 6723b3eb3cSopenharmony_ci } 6823b3eb3cSopenharmony_ci } 6923b3eb3cSopenharmony_ci return AceType::MakeRefPtr<StepsCurve>(step, position); 7023b3eb3cSopenharmony_ci} 7123b3eb3cSopenharmony_ci 7223b3eb3cSopenharmony_ciRefPtr<Curve> CubicCurveCreator(const std::vector<std::string>& params) 7323b3eb3cSopenharmony_ci{ 7423b3eb3cSopenharmony_ci if (params.size() != CUBIC_PARAMS_SIZE) { 7523b3eb3cSopenharmony_ci return nullptr; 7623b3eb3cSopenharmony_ci } 7723b3eb3cSopenharmony_ci double x1 = StringToDouble(params.at(0)); 7823b3eb3cSopenharmony_ci double y1 = StringToDouble(params.at(1)); 7923b3eb3cSopenharmony_ci double x2 = StringToDouble(params.at(2)); 8023b3eb3cSopenharmony_ci double y2 = StringToDouble(params.at(3)); 8123b3eb3cSopenharmony_ci return AceType::MakeRefPtr<CubicCurve>(x1, y1, x2, y2); 8223b3eb3cSopenharmony_ci} 8323b3eb3cSopenharmony_ci 8423b3eb3cSopenharmony_ciRefPtr<Curve> SpringCurveCreator(const std::vector<std::string>& params) 8523b3eb3cSopenharmony_ci{ 8623b3eb3cSopenharmony_ci if (params.size() != SPRING_PARAMS_SIZE) { 8723b3eb3cSopenharmony_ci return nullptr; 8823b3eb3cSopenharmony_ci } 8923b3eb3cSopenharmony_ci double velocity = StringToDouble(params.at(0)); 9023b3eb3cSopenharmony_ci double mass = StringToDouble(params.at(1)); 9123b3eb3cSopenharmony_ci double stiffness = StringToDouble(params.at(2)); 9223b3eb3cSopenharmony_ci double damping = StringToDouble(params.at(3)); 9323b3eb3cSopenharmony_ci return AceType::MakeRefPtr<SpringCurve>(velocity, mass, stiffness, damping); 9423b3eb3cSopenharmony_ci} 9523b3eb3cSopenharmony_ci 9623b3eb3cSopenharmony_ciRefPtr<Curve> InterpolatingSpringCreator(const std::vector<std::string>& params) 9723b3eb3cSopenharmony_ci{ 9823b3eb3cSopenharmony_ci if (params.size() != INTERPOLATING_SPRING_PARAMS_SIZE) { 9923b3eb3cSopenharmony_ci return nullptr; 10023b3eb3cSopenharmony_ci } 10123b3eb3cSopenharmony_ci double velocity = StringToDouble(params.at(0)); 10223b3eb3cSopenharmony_ci double mass = StringToDouble(params.at(1)); 10323b3eb3cSopenharmony_ci double stiffness = StringToDouble(params.at(2)); 10423b3eb3cSopenharmony_ci double damping = StringToDouble(params.at(3)); 10523b3eb3cSopenharmony_ci return AceType::MakeRefPtr<InterpolatingSpring>(velocity, mass, stiffness, damping); 10623b3eb3cSopenharmony_ci} 10723b3eb3cSopenharmony_ci 10823b3eb3cSopenharmony_ciRefPtr<Curve> SpringMotionCreator(const std::vector<std::string>& params) 10923b3eb3cSopenharmony_ci{ 11023b3eb3cSopenharmony_ci if (params.size() > RESPONSIVE_SPRING_MOTION_PARAMS_SIZE) { 11123b3eb3cSopenharmony_ci return nullptr; 11223b3eb3cSopenharmony_ci } 11323b3eb3cSopenharmony_ci size_t paramSize = params.size(); 11423b3eb3cSopenharmony_ci float response = paramSize > 0 ? StringUtils::StringToFloat(params[0]) 11523b3eb3cSopenharmony_ci : ResponsiveSpringMotion::DEFAULT_SPRING_MOTION_RESPONSE; 11623b3eb3cSopenharmony_ci float dampingRatio = paramSize > 1 ? StringUtils::StringToFloat(params[1]) 11723b3eb3cSopenharmony_ci : ResponsiveSpringMotion::DEFAULT_SPRING_MOTION_DAMPING_RATIO; 11823b3eb3cSopenharmony_ci float blendDuration = paramSize > 2 ? StringUtils::StringToFloat(params[2]) 11923b3eb3cSopenharmony_ci : ResponsiveSpringMotion::DEFAULT_SPRING_MOTION_BLEND_DURATION; 12023b3eb3cSopenharmony_ci return AceType::MakeRefPtr<ResponsiveSpringMotion>(response, dampingRatio, blendDuration); 12123b3eb3cSopenharmony_ci} 12223b3eb3cSopenharmony_ci 12323b3eb3cSopenharmony_ciRefPtr<Curve> ResponsiveSpringMotionCreator(const std::vector<std::string>& params) 12423b3eb3cSopenharmony_ci{ 12523b3eb3cSopenharmony_ci if (params.size() > RESPONSIVE_SPRING_MOTION_PARAMS_SIZE) { 12623b3eb3cSopenharmony_ci return nullptr; 12723b3eb3cSopenharmony_ci } 12823b3eb3cSopenharmony_ci size_t paramSize = params.size(); 12923b3eb3cSopenharmony_ci float response = paramSize > 0 ? StringUtils::StringToFloat(params[0]) 13023b3eb3cSopenharmony_ci : ResponsiveSpringMotion::DEFAULT_RESPONSIVE_SPRING_MOTION_RESPONSE; 13123b3eb3cSopenharmony_ci float dampingRatio = paramSize > 1 ? StringUtils::StringToFloat(params[1]) 13223b3eb3cSopenharmony_ci : ResponsiveSpringMotion::DEFAULT_RESPONSIVE_SPRING_MOTION_DAMPING_RATIO; 13323b3eb3cSopenharmony_ci float blendDuration = paramSize > 2 ? StringUtils::StringToFloat(params[2]) 13423b3eb3cSopenharmony_ci : ResponsiveSpringMotion::DEFAULT_RESPONSIVE_SPRING_MOTION_BLEND_DURATION; 13523b3eb3cSopenharmony_ci return AceType::MakeRefPtr<ResponsiveSpringMotion>(response, dampingRatio, blendDuration); 13623b3eb3cSopenharmony_ci} 13723b3eb3cSopenharmony_ci#ifndef FUZZTEST 13823b3eb3cSopenharmony_civoid SetBgImgPositionX( 13923b3eb3cSopenharmony_ci const BackgroundImagePositionType type, const double value, BackgroundImagePosition& bgImgPosition) 14023b3eb3cSopenharmony_ci{ 14123b3eb3cSopenharmony_ci bgImgPosition.SetSizeTypeX(type); 14223b3eb3cSopenharmony_ci bgImgPosition.SetSizeValueX(value); 14323b3eb3cSopenharmony_ci} 14423b3eb3cSopenharmony_ci 14523b3eb3cSopenharmony_civoid SetBgImgPositionY( 14623b3eb3cSopenharmony_ci const BackgroundImagePositionType type, const double value, BackgroundImagePosition& bgImgPosition) 14723b3eb3cSopenharmony_ci{ 14823b3eb3cSopenharmony_ci bgImgPosition.SetSizeTypeY(type); 14923b3eb3cSopenharmony_ci bgImgPosition.SetSizeValueY(value); 15023b3eb3cSopenharmony_ci} 15123b3eb3cSopenharmony_ci 15223b3eb3cSopenharmony_civoid SetBgImgPosition( 15323b3eb3cSopenharmony_ci const BackgroundImagePositionType type, const double value, BackgroundImagePosition& bgImgPosition) 15423b3eb3cSopenharmony_ci{ 15523b3eb3cSopenharmony_ci SetBgImgPositionX(type, value, bgImgPosition); 15623b3eb3cSopenharmony_ci SetBgImgPositionY(type, value, bgImgPosition); 15723b3eb3cSopenharmony_ci} 15823b3eb3cSopenharmony_ci 15923b3eb3cSopenharmony_civoid GetOffsetValue(std::vector<std::string> offsets, std::string& posX, std::string& posY) 16023b3eb3cSopenharmony_ci{ 16123b3eb3cSopenharmony_ci if (offsets.size() == 1) { 16223b3eb3cSopenharmony_ci posX = offsets.front(); 16323b3eb3cSopenharmony_ci if (VERTICAL_SET.find(posX) != VERTICAL_SET.end()) { 16423b3eb3cSopenharmony_ci posY = offsets.front(); 16523b3eb3cSopenharmony_ci posX = DOM_BACKGROUND_IMAGE_POSITION_CENTER; 16623b3eb3cSopenharmony_ci } else { 16723b3eb3cSopenharmony_ci posY = DOM_BACKGROUND_IMAGE_POSITION_CENTER; 16823b3eb3cSopenharmony_ci } 16923b3eb3cSopenharmony_ci } else { 17023b3eb3cSopenharmony_ci posX = offsets.front(); 17123b3eb3cSopenharmony_ci posY = offsets.back(); 17223b3eb3cSopenharmony_ci if (VERTICAL_SET.find(posX) != VERTICAL_SET.end() && HORIZON_SET.find(posY) != HORIZON_SET.end()) { 17323b3eb3cSopenharmony_ci posY = offsets.front(); 17423b3eb3cSopenharmony_ci posX = offsets.back(); 17523b3eb3cSopenharmony_ci } 17623b3eb3cSopenharmony_ci } 17723b3eb3cSopenharmony_ci} 17823b3eb3cSopenharmony_ci 17923b3eb3cSopenharmony_ci// object-position check msg number 18023b3eb3cSopenharmony_civoid GetOffsetValueObjectPosition(std::vector<std::string> offsets, std::string& posX, std::string& posY) 18123b3eb3cSopenharmony_ci{ 18223b3eb3cSopenharmony_ci if (offsets.size() == 1) { 18323b3eb3cSopenharmony_ci posX = offsets.front(); 18423b3eb3cSopenharmony_ci if (OBJECT_VERTICAL_SET.find(posX) != OBJECT_VERTICAL_SET.end()) { 18523b3eb3cSopenharmony_ci posY = offsets.front(); 18623b3eb3cSopenharmony_ci posX = DOM_IMAGE_POSITION_CENTER; 18723b3eb3cSopenharmony_ci } else { 18823b3eb3cSopenharmony_ci posY = DOM_IMAGE_POSITION_CENTER; 18923b3eb3cSopenharmony_ci } 19023b3eb3cSopenharmony_ci } else { 19123b3eb3cSopenharmony_ci posX = offsets.front(); 19223b3eb3cSopenharmony_ci posY = offsets.back(); 19323b3eb3cSopenharmony_ci if (OBJECT_VERTICAL_SET.find(posX) != OBJECT_VERTICAL_SET.end() 19423b3eb3cSopenharmony_ci && OBJECT_HORIZON_SET.find(posY) != OBJECT_HORIZON_SET.end()) { 19523b3eb3cSopenharmony_ci posY = offsets.front(); 19623b3eb3cSopenharmony_ci posX = offsets.back(); 19723b3eb3cSopenharmony_ci } 19823b3eb3cSopenharmony_ci } 19923b3eb3cSopenharmony_ci} 20023b3eb3cSopenharmony_ci 20123b3eb3cSopenharmony_cibool BgImgPositionIsValid(const std::string& posX, const std::string& posY) 20223b3eb3cSopenharmony_ci{ 20323b3eb3cSopenharmony_ci if ((posX == DOM_BACKGROUND_IMAGE_POSITION_CENTER) || (posY == DOM_BACKGROUND_IMAGE_POSITION_CENTER)) { 20423b3eb3cSopenharmony_ci return true; 20523b3eb3cSopenharmony_ci } 20623b3eb3cSopenharmony_ci // posX and posY are not strictly corresponding to horizontal or vertical, but they must not conflict, 20723b3eb3cSopenharmony_ci // for example both of them are "top" is invalid. 20823b3eb3cSopenharmony_ci if (posX.find("px") != std::string::npos || posX.find('%') != std::string::npos || 20923b3eb3cSopenharmony_ci HORIZON_SET.find(posX) != HORIZON_SET.end()) { 21023b3eb3cSopenharmony_ci if (posY.find("px") != std::string::npos || posY.find('%') != std::string::npos || 21123b3eb3cSopenharmony_ci VERTICAL_SET.find(posY) != VERTICAL_SET.end()) { 21223b3eb3cSopenharmony_ci return true; 21323b3eb3cSopenharmony_ci } 21423b3eb3cSopenharmony_ci } 21523b3eb3cSopenharmony_ci return VERTICAL_SET.find(posX) != VERTICAL_SET.end() && HORIZON_SET.find(posY) != HORIZON_SET.end(); 21623b3eb3cSopenharmony_ci} 21723b3eb3cSopenharmony_ci 21823b3eb3cSopenharmony_ci// objectPosition 21923b3eb3cSopenharmony_cibool ObjectImgPositionIsValid(const std::string& posX, const std::string& posY) 22023b3eb3cSopenharmony_ci{ 22123b3eb3cSopenharmony_ci if (posX.find("px") != std::string::npos || posX.find('%') != std::string::npos || 22223b3eb3cSopenharmony_ci OBJECT_HORIZON_SET.find(posX) != OBJECT_HORIZON_SET.end() || posX != DOM_IMAGE_POSITION_CENTER) { 22323b3eb3cSopenharmony_ci if (posY.find("px") != std::string::npos || posY.find('%') != std::string::npos || 22423b3eb3cSopenharmony_ci OBJECT_VERTICAL_SET.find(posY) != OBJECT_VERTICAL_SET.end() || posY != DOM_IMAGE_POSITION_CENTER) { 22523b3eb3cSopenharmony_ci return true; 22623b3eb3cSopenharmony_ci } 22723b3eb3cSopenharmony_ci } 22823b3eb3cSopenharmony_ci return false; 22923b3eb3cSopenharmony_ci} 23023b3eb3cSopenharmony_ci 23123b3eb3cSopenharmony_civoid SetBgImgSizeX(BackgroundImageSizeType type, double value, BackgroundImageSize& bgImgSize) 23223b3eb3cSopenharmony_ci{ 23323b3eb3cSopenharmony_ci bgImgSize.SetSizeTypeX(type); 23423b3eb3cSopenharmony_ci bgImgSize.SetSizeValueX(value); 23523b3eb3cSopenharmony_ci} 23623b3eb3cSopenharmony_ci 23723b3eb3cSopenharmony_civoid SetBgImgSizeY(BackgroundImageSizeType type, double value, BackgroundImageSize& bgImgSize) 23823b3eb3cSopenharmony_ci{ 23923b3eb3cSopenharmony_ci bgImgSize.SetSizeTypeY(type); 24023b3eb3cSopenharmony_ci bgImgSize.SetSizeValueY(value); 24123b3eb3cSopenharmony_ci} 24223b3eb3cSopenharmony_ci#endif 24323b3eb3cSopenharmony_ci} // namespace 24423b3eb3cSopenharmony_ci 24523b3eb3cSopenharmony_ciRefPtr<Curve> CreateBuiltinCurve(const std::string& aniTimFunc) 24623b3eb3cSopenharmony_ci{ 24723b3eb3cSopenharmony_ci // this map should be sorted by key 24823b3eb3cSopenharmony_ci static const LinearMapNode<RefPtr<Curve>> aniTimFuncMap[] = { 24923b3eb3cSopenharmony_ci { DOM_ANIMATION_TIMING_FUNCTION_EASE, Curves::EASE }, 25023b3eb3cSopenharmony_ci { DOM_ANIMATION_TIMING_FUNCTION_EASE_IN, Curves::EASE_IN }, 25123b3eb3cSopenharmony_ci { DOM_ANIMATION_TIMING_FUNCTION_EASE_IN_OUT, Curves::EASE_IN_OUT }, 25223b3eb3cSopenharmony_ci { DOM_ANIMATION_TIMING_FUNCTION_EASE_OUT, Curves::EASE_OUT }, 25323b3eb3cSopenharmony_ci { DOM_ANIMATION_TIMING_FUNCTION_EXTREME_DECELERATION, Curves::EXTREME_DECELERATION }, 25423b3eb3cSopenharmony_ci { DOM_ANIMATION_TIMING_FUNCTION_FAST_OUT_LINEAR_IN, Curves::FAST_OUT_LINEAR_IN }, 25523b3eb3cSopenharmony_ci { DOM_ANIMATION_TIMING_FUNCTION_FAST_OUT_SLOW_IN, Curves::FAST_OUT_SLOW_IN }, 25623b3eb3cSopenharmony_ci { DOM_ANIMATION_TIMING_FUNCTION_FRICTION, Curves::FRICTION }, 25723b3eb3cSopenharmony_ci { DOM_ANIMATION_TIMING_FUNCTION_LINEAR, Curves::LINEAR }, 25823b3eb3cSopenharmony_ci { DOM_ANIMATION_TIMING_FUNCTION_LINEAR_OUT_SLOW_IN, Curves::LINEAR_OUT_SLOW_IN }, 25923b3eb3cSopenharmony_ci { DOM_ANIMATION_TIMING_FUNCTION_RHYTHM, Curves::RHYTHM }, 26023b3eb3cSopenharmony_ci { DOM_ANIMATION_TIMING_FUNCTION_SHARP, Curves::SHARP }, 26123b3eb3cSopenharmony_ci { DOM_ANIMATION_TIMING_FUNCTION_SMOOTH, Curves::SMOOTH }, 26223b3eb3cSopenharmony_ci }; 26323b3eb3cSopenharmony_ci auto index = BinarySearchFindIndex(aniTimFuncMap, ArraySize(aniTimFuncMap), aniTimFunc.c_str()); 26423b3eb3cSopenharmony_ci return index < 0 ? nullptr : aniTimFuncMap[index].value; 26523b3eb3cSopenharmony_ci} 26623b3eb3cSopenharmony_ci 26723b3eb3cSopenharmony_cistd::string CurveIntToString(int curve) 26823b3eb3cSopenharmony_ci{ 26923b3eb3cSopenharmony_ci static const LinearEnumMapNode<ArkUI_AnimationCurve, std::string> curveMap[] = { 27023b3eb3cSopenharmony_ci { ArkUI_AnimationCurve::ARKUI_CURVE_EASE, DOM_ANIMATION_TIMING_FUNCTION_EASE }, 27123b3eb3cSopenharmony_ci { ArkUI_AnimationCurve::ARKUI_CURVE_EASE_IN, DOM_ANIMATION_TIMING_FUNCTION_EASE_IN }, 27223b3eb3cSopenharmony_ci { ArkUI_AnimationCurve::ARKUI_CURVE_EASE_IN_OUT, DOM_ANIMATION_TIMING_FUNCTION_EASE_IN_OUT }, 27323b3eb3cSopenharmony_ci { ArkUI_AnimationCurve::ARKUI_CURVE_EASE_OUT, DOM_ANIMATION_TIMING_FUNCTION_EASE_OUT}, 27423b3eb3cSopenharmony_ci { ArkUI_AnimationCurve::ARKUI_CURVE_EXTREME_DECELERATION, DOM_ANIMATION_TIMING_FUNCTION_EXTREME_DECELERATION }, 27523b3eb3cSopenharmony_ci { ArkUI_AnimationCurve::ARKUI_CURVE_FAST_OUT_LINEAR_IN, DOM_ANIMATION_TIMING_FUNCTION_FAST_OUT_LINEAR_IN }, 27623b3eb3cSopenharmony_ci { ArkUI_AnimationCurve::ARKUI_CURVE_FAST_OUT_SLOW_IN, DOM_ANIMATION_TIMING_FUNCTION_FAST_OUT_SLOW_IN}, 27723b3eb3cSopenharmony_ci { ArkUI_AnimationCurve::ARKUI_CURVE_FRICTION, DOM_ANIMATION_TIMING_FUNCTION_FRICTION }, 27823b3eb3cSopenharmony_ci { ArkUI_AnimationCurve::ARKUI_CURVE_LINEAR, DOM_ANIMATION_TIMING_FUNCTION_LINEAR}, 27923b3eb3cSopenharmony_ci { ArkUI_AnimationCurve::ARKUI_CURVE_LINEAR_OUT_SLOW_IN, DOM_ANIMATION_TIMING_FUNCTION_LINEAR_OUT_SLOW_IN}, 28023b3eb3cSopenharmony_ci { ArkUI_AnimationCurve::ARKUI_CURVE_RHYTHM, DOM_ANIMATION_TIMING_FUNCTION_RHYTHM}, 28123b3eb3cSopenharmony_ci { ArkUI_AnimationCurve::ARKUI_CURVE_SHARP, DOM_ANIMATION_TIMING_FUNCTION_SHARP}, 28223b3eb3cSopenharmony_ci { ArkUI_AnimationCurve::ARKUI_CURVE_SMOOTH, DOM_ANIMATION_TIMING_FUNCTION_SMOOTH}, 28323b3eb3cSopenharmony_ci }; 28423b3eb3cSopenharmony_ci auto index = BinarySearchFindIndex(curveMap, ArraySize(curveMap), static_cast<ArkUI_AnimationCurve>(curve)); 28523b3eb3cSopenharmony_ci return index < 0 ? DOM_ANIMATION_TIMING_FUNCTION_LINEAR : curveMap[index].value; 28623b3eb3cSopenharmony_ci} 28723b3eb3cSopenharmony_ci 28823b3eb3cSopenharmony_cibool ParseCurveParam( 28923b3eb3cSopenharmony_ci const std::string& aniTimFunc, std::string& curveName, std::vector<std::string>& paramsVector) 29023b3eb3cSopenharmony_ci{ 29123b3eb3cSopenharmony_ci if (aniTimFunc.back() != ')') { 29223b3eb3cSopenharmony_ci return false; 29323b3eb3cSopenharmony_ci } 29423b3eb3cSopenharmony_ci std::string::size_type leftEmbracePosition = aniTimFunc.find_last_of('('); 29523b3eb3cSopenharmony_ci if (leftEmbracePosition == std::string::npos) { 29623b3eb3cSopenharmony_ci return false; 29723b3eb3cSopenharmony_ci } 29823b3eb3cSopenharmony_ci auto aniTimFuncName = aniTimFunc.substr(0, leftEmbracePosition); 29923b3eb3cSopenharmony_ci auto params = aniTimFunc.substr(leftEmbracePosition + 1, aniTimFunc.length() - leftEmbracePosition - 2); 30023b3eb3cSopenharmony_ci if (aniTimFuncName.empty() || params.empty()) { 30123b3eb3cSopenharmony_ci return false; 30223b3eb3cSopenharmony_ci } 30323b3eb3cSopenharmony_ci StringUtils::StringSplitter(params, ',', paramsVector); 30423b3eb3cSopenharmony_ci for (auto& param : paramsVector) { 30523b3eb3cSopenharmony_ci RemoveHeadTailSpace(param); 30623b3eb3cSopenharmony_ci } 30723b3eb3cSopenharmony_ci curveName = std::move(aniTimFuncName); 30823b3eb3cSopenharmony_ci return true; 30923b3eb3cSopenharmony_ci} 31023b3eb3cSopenharmony_ci 31123b3eb3cSopenharmony_ciRefPtr<Curve> CreateCustomCurve(const std::string& aniTimFunc) 31223b3eb3cSopenharmony_ci{ 31323b3eb3cSopenharmony_ci std::string aniTimFuncName; 31423b3eb3cSopenharmony_ci std::vector<std::string> paramsVector; 31523b3eb3cSopenharmony_ci bool result = ParseCurveParam(aniTimFunc, aniTimFuncName, paramsVector); 31623b3eb3cSopenharmony_ci if (!result) { 31723b3eb3cSopenharmony_ci return nullptr; 31823b3eb3cSopenharmony_ci } 31923b3eb3cSopenharmony_ci static const LinearMapNode<CustomCurveCreator> customCurveMap[] = { 32023b3eb3cSopenharmony_ci { DOM_ANIMATION_TIMING_FUNCTION_CUBIC_BEZIER, CubicCurveCreator }, 32123b3eb3cSopenharmony_ci { DOM_ANIMATION_TIMING_FUNCTION_INTERPOLATING_SPRING, InterpolatingSpringCreator }, 32223b3eb3cSopenharmony_ci { DOM_ANIMATION_TIMING_FUNCTION_RESPONSIVE_SPRING_MOTION, ResponsiveSpringMotionCreator }, 32323b3eb3cSopenharmony_ci { DOM_ANIMATION_TIMING_FUNCTION_SPRING, SpringCurveCreator }, 32423b3eb3cSopenharmony_ci { DOM_ANIMATION_TIMING_FUNCTION_SPRING_MOTION, SpringMotionCreator }, 32523b3eb3cSopenharmony_ci { DOM_ANIMATION_TIMING_FUNCTION_STEPS, StepsCurveCreator }, 32623b3eb3cSopenharmony_ci }; 32723b3eb3cSopenharmony_ci int64_t index = BinarySearchFindIndex(customCurveMap, ArraySize(customCurveMap), aniTimFuncName.c_str()); 32823b3eb3cSopenharmony_ci if (index < 0) { 32923b3eb3cSopenharmony_ci return nullptr; 33023b3eb3cSopenharmony_ci } 33123b3eb3cSopenharmony_ci return customCurveMap[index].value(paramsVector); 33223b3eb3cSopenharmony_ci} 33323b3eb3cSopenharmony_ci 33423b3eb3cSopenharmony_ciRefPtr<Curve> CreateCustomCurveExceptSpring(const std::string& aniTimFunc) 33523b3eb3cSopenharmony_ci{ 33623b3eb3cSopenharmony_ci std::string aniTimFuncName; 33723b3eb3cSopenharmony_ci std::vector<std::string> paramsVector; 33823b3eb3cSopenharmony_ci bool result = ParseCurveParam(aniTimFunc, aniTimFuncName, paramsVector); 33923b3eb3cSopenharmony_ci if (!result) { 34023b3eb3cSopenharmony_ci return nullptr; 34123b3eb3cSopenharmony_ci } 34223b3eb3cSopenharmony_ci static const LinearMapNode<CustomCurveCreator> customCurveExceptSpringMap[] = { 34323b3eb3cSopenharmony_ci { DOM_ANIMATION_TIMING_FUNCTION_CUBIC_BEZIER, CubicCurveCreator }, 34423b3eb3cSopenharmony_ci { DOM_ANIMATION_TIMING_FUNCTION_SPRING, SpringCurveCreator }, 34523b3eb3cSopenharmony_ci { DOM_ANIMATION_TIMING_FUNCTION_STEPS, StepsCurveCreator }, 34623b3eb3cSopenharmony_ci }; 34723b3eb3cSopenharmony_ci int64_t index = BinarySearchFindIndex( 34823b3eb3cSopenharmony_ci customCurveExceptSpringMap, ArraySize(customCurveExceptSpringMap), aniTimFuncName.c_str()); 34923b3eb3cSopenharmony_ci if (index < 0) { 35023b3eb3cSopenharmony_ci return nullptr; 35123b3eb3cSopenharmony_ci } 35223b3eb3cSopenharmony_ci return customCurveExceptSpringMap[index].value(paramsVector); 35323b3eb3cSopenharmony_ci} 35423b3eb3cSopenharmony_ci 35523b3eb3cSopenharmony_ciRefPtr<Curve> CreateCurve(const std::function<float(float)>& jsFunc) 35623b3eb3cSopenharmony_ci{ 35723b3eb3cSopenharmony_ci if (jsFunc) { 35823b3eb3cSopenharmony_ci return AceType::MakeRefPtr<CustomCurve>(jsFunc); 35923b3eb3cSopenharmony_ci } 36023b3eb3cSopenharmony_ci return Curves::EASE_IN_OUT; 36123b3eb3cSopenharmony_ci} 36223b3eb3cSopenharmony_ci 36323b3eb3cSopenharmony_ciRefPtr<Curve> CreateCurve(const std::string& aniTimFunc, bool useDefault) 36423b3eb3cSopenharmony_ci{ 36523b3eb3cSopenharmony_ci auto curve = CreateBuiltinCurve(aniTimFunc); 36623b3eb3cSopenharmony_ci if (curve) { 36723b3eb3cSopenharmony_ci return curve; 36823b3eb3cSopenharmony_ci } 36923b3eb3cSopenharmony_ci curve = CreateCustomCurve(aniTimFunc); 37023b3eb3cSopenharmony_ci if (curve) { 37123b3eb3cSopenharmony_ci return curve; 37223b3eb3cSopenharmony_ci } 37323b3eb3cSopenharmony_ci return useDefault? Curves::EASE_IN_OUT : nullptr; 37423b3eb3cSopenharmony_ci} 37523b3eb3cSopenharmony_ci 37623b3eb3cSopenharmony_ci// create curve whose duration works. i.e not support spring 37723b3eb3cSopenharmony_ciRefPtr<Curve> CreateCurveExceptSpring( 37823b3eb3cSopenharmony_ci const std::string& aniTimFunc, const std::function<float(float)>& jsFunc) 37923b3eb3cSopenharmony_ci{ 38023b3eb3cSopenharmony_ci if (jsFunc) { 38123b3eb3cSopenharmony_ci return AceType::MakeRefPtr<CustomCurve>(jsFunc); 38223b3eb3cSopenharmony_ci } 38323b3eb3cSopenharmony_ci auto curve = CreateBuiltinCurve(aniTimFunc); 38423b3eb3cSopenharmony_ci if (curve) { 38523b3eb3cSopenharmony_ci return curve; 38623b3eb3cSopenharmony_ci } 38723b3eb3cSopenharmony_ci curve = CreateCustomCurveExceptSpring(aniTimFunc); 38823b3eb3cSopenharmony_ci if (curve) { 38923b3eb3cSopenharmony_ci return curve; 39023b3eb3cSopenharmony_ci } 39123b3eb3cSopenharmony_ci return Curves::EASE_IN_OUT; 39223b3eb3cSopenharmony_ci} 39323b3eb3cSopenharmony_ci 39423b3eb3cSopenharmony_ci// used for declarative only 39523b3eb3cSopenharmony_ciTransitionType ParseTransitionType(const std::string& transitionType) 39623b3eb3cSopenharmony_ci{ 39723b3eb3cSopenharmony_ci if (transitionType == "All") { 39823b3eb3cSopenharmony_ci return TransitionType::ALL; 39923b3eb3cSopenharmony_ci } else if (transitionType == "Insert") { 40023b3eb3cSopenharmony_ci return TransitionType::APPEARING; 40123b3eb3cSopenharmony_ci } else if (transitionType == "Delete") { 40223b3eb3cSopenharmony_ci return TransitionType::DISAPPEARING; 40323b3eb3cSopenharmony_ci } else { 40423b3eb3cSopenharmony_ci return TransitionType::ALL; 40523b3eb3cSopenharmony_ci } 40623b3eb3cSopenharmony_ci} 40723b3eb3cSopenharmony_ci#ifndef FUZZTEST 40823b3eb3cSopenharmony_ci// Support keyword values / percentage/px values. Do not support multiple images and edge offsets values. 40923b3eb3cSopenharmony_cibool ParseBackgroundImagePosition(const std::string& value, BackgroundImagePosition& backgroundImagePosition) 41023b3eb3cSopenharmony_ci{ 41123b3eb3cSopenharmony_ci static const LinearMapNode<void (*)(BackgroundImagePosition&)> backGroundPositionOperators[] = { 41223b3eb3cSopenharmony_ci { DOM_BACKGROUND_IMAGE_POSITION_BOTTOM, 41323b3eb3cSopenharmony_ci [](BackgroundImagePosition& backgroundImagePosition) { 41423b3eb3cSopenharmony_ci SetBgImgPositionY(BackgroundImagePositionType::PERCENT, 100.0, backgroundImagePosition); 41523b3eb3cSopenharmony_ci } }, 41623b3eb3cSopenharmony_ci { DOM_BACKGROUND_IMAGE_POSITION_LEFT, 41723b3eb3cSopenharmony_ci [](BackgroundImagePosition& backgroundImagePosition) { 41823b3eb3cSopenharmony_ci SetBgImgPositionX(BackgroundImagePositionType::PERCENT, 0.0, backgroundImagePosition); 41923b3eb3cSopenharmony_ci } }, 42023b3eb3cSopenharmony_ci { DOM_BACKGROUND_IMAGE_POSITION_RIGHT, 42123b3eb3cSopenharmony_ci [](BackgroundImagePosition& backgroundImagePosition) { 42223b3eb3cSopenharmony_ci SetBgImgPositionX(BackgroundImagePositionType::PERCENT, 100.0, backgroundImagePosition); 42323b3eb3cSopenharmony_ci } }, 42423b3eb3cSopenharmony_ci { DOM_BACKGROUND_IMAGE_POSITION_TOP, 42523b3eb3cSopenharmony_ci [](BackgroundImagePosition& backgroundImagePosition) { 42623b3eb3cSopenharmony_ci SetBgImgPositionY(BackgroundImagePositionType::PERCENT, 0.0, backgroundImagePosition); 42723b3eb3cSopenharmony_ci } }, 42823b3eb3cSopenharmony_ci }; 42923b3eb3cSopenharmony_ci 43023b3eb3cSopenharmony_ci std::vector<std::string> offsets; 43123b3eb3cSopenharmony_ci StringUtils::StringSplitter(value, ' ', offsets); 43223b3eb3cSopenharmony_ci if (!offsets.empty()) { 43323b3eb3cSopenharmony_ci std::string valueX = ""; 43423b3eb3cSopenharmony_ci std::string valueY = ""; 43523b3eb3cSopenharmony_ci GetOffsetValue(offsets, valueX, valueY); 43623b3eb3cSopenharmony_ci if (!BgImgPositionIsValid(valueX, valueY)) { 43723b3eb3cSopenharmony_ci return false; 43823b3eb3cSopenharmony_ci } 43923b3eb3cSopenharmony_ci // The input is valid,so set the default is (center,center), 44023b3eb3cSopenharmony_ci // if the value is different, the default value is overwritten. 44123b3eb3cSopenharmony_ci // the center value is 50%. 44223b3eb3cSopenharmony_ci SetBgImgPosition(BackgroundImagePositionType::PERCENT, 50.0, backgroundImagePosition); 44323b3eb3cSopenharmony_ci if (valueX.find("px") != std::string::npos) { 44423b3eb3cSopenharmony_ci SetBgImgPositionX(BackgroundImagePositionType::PX, StringToDouble(valueX), backgroundImagePosition); 44523b3eb3cSopenharmony_ci } else if (valueX.find('%') != std::string::npos) { 44623b3eb3cSopenharmony_ci SetBgImgPositionX(BackgroundImagePositionType::PERCENT, StringToDouble(valueX), backgroundImagePosition); 44723b3eb3cSopenharmony_ci } else { 44823b3eb3cSopenharmony_ci auto operatorIterX = BinarySearchFindIndex( 44923b3eb3cSopenharmony_ci backGroundPositionOperators, ArraySize(backGroundPositionOperators), valueX.c_str()); 45023b3eb3cSopenharmony_ci if (operatorIterX != -1) { 45123b3eb3cSopenharmony_ci backGroundPositionOperators[operatorIterX].value(backgroundImagePosition); 45223b3eb3cSopenharmony_ci } 45323b3eb3cSopenharmony_ci } 45423b3eb3cSopenharmony_ci if (valueY.find("px") != std::string::npos) { 45523b3eb3cSopenharmony_ci SetBgImgPositionY(BackgroundImagePositionType::PX, StringToDouble(valueY), backgroundImagePosition); 45623b3eb3cSopenharmony_ci } else if (valueY.find('%') != std::string::npos) { 45723b3eb3cSopenharmony_ci SetBgImgPositionY(BackgroundImagePositionType::PERCENT, StringToDouble(valueY), backgroundImagePosition); 45823b3eb3cSopenharmony_ci } else { 45923b3eb3cSopenharmony_ci auto operatorIterY = BinarySearchFindIndex( 46023b3eb3cSopenharmony_ci backGroundPositionOperators, ArraySize(backGroundPositionOperators), valueY.c_str()); 46123b3eb3cSopenharmony_ci if (operatorIterY != -1) { 46223b3eb3cSopenharmony_ci backGroundPositionOperators[operatorIterY].value(backgroundImagePosition); 46323b3eb3cSopenharmony_ci } 46423b3eb3cSopenharmony_ci } 46523b3eb3cSopenharmony_ci } else { 46623b3eb3cSopenharmony_ci SetBgImgPosition(BackgroundImagePositionType::PERCENT, 50.0, backgroundImagePosition); 46723b3eb3cSopenharmony_ci if (value.find("px") != std::string::npos) { 46823b3eb3cSopenharmony_ci SetBgImgPositionX(BackgroundImagePositionType::PX, StringToDouble(value), backgroundImagePosition); 46923b3eb3cSopenharmony_ci } else if (value.find('%') != std::string::npos) { 47023b3eb3cSopenharmony_ci SetBgImgPositionX(BackgroundImagePositionType::PERCENT, StringToDouble(value), backgroundImagePosition); 47123b3eb3cSopenharmony_ci } else { 47223b3eb3cSopenharmony_ci auto operatorIter = BinarySearchFindIndex( 47323b3eb3cSopenharmony_ci backGroundPositionOperators, ArraySize(backGroundPositionOperators), value.c_str()); 47423b3eb3cSopenharmony_ci if (operatorIter != -1) { 47523b3eb3cSopenharmony_ci backGroundPositionOperators[operatorIter].value(backgroundImagePosition); 47623b3eb3cSopenharmony_ci } 47723b3eb3cSopenharmony_ci } 47823b3eb3cSopenharmony_ci } 47923b3eb3cSopenharmony_ci return true; 48023b3eb3cSopenharmony_ci} 48123b3eb3cSopenharmony_ci 48223b3eb3cSopenharmony_cibool ParseBackgroundImageSize(const std::string& value, BackgroundImageSize& bgImgSize) 48323b3eb3cSopenharmony_ci{ 48423b3eb3cSopenharmony_ci static const LinearMapNode<BackgroundImageSizeType> bgImageSizeType[] = { 48523b3eb3cSopenharmony_ci { DOM_BACKGROUND_IMAGE_SIZE_AUTO, BackgroundImageSizeType::AUTO }, 48623b3eb3cSopenharmony_ci { DOM_BACKGROUND_IMAGE_SIZE_CONTAIN, BackgroundImageSizeType::CONTAIN }, 48723b3eb3cSopenharmony_ci { DOM_BACKGROUND_IMAGE_SIZE_COVER, BackgroundImageSizeType::COVER }, 48823b3eb3cSopenharmony_ci { DOM_BACKGROUND_IMAGE_SIZE_FILL, BackgroundImageSizeType::FILL }, 48923b3eb3cSopenharmony_ci }; 49023b3eb3cSopenharmony_ci auto spaceIndex = value.find(' ', 0); 49123b3eb3cSopenharmony_ci if (spaceIndex != std::string::npos) { 49223b3eb3cSopenharmony_ci std::string valueX = value.substr(0, spaceIndex); 49323b3eb3cSopenharmony_ci std::string valueY = value.substr(spaceIndex + 1, value.size() - spaceIndex - 1); 49423b3eb3cSopenharmony_ci if (valueX.find("px") != std::string::npos) { 49523b3eb3cSopenharmony_ci SetBgImgSizeX(BackgroundImageSizeType::LENGTH, StringToDouble(valueX), bgImgSize); 49623b3eb3cSopenharmony_ci } else if (valueX.find('%') != std::string::npos) { 49723b3eb3cSopenharmony_ci SetBgImgSizeX(BackgroundImageSizeType::PERCENT, StringToDouble(valueX), bgImgSize); 49823b3eb3cSopenharmony_ci } else { 49923b3eb3cSopenharmony_ci bgImgSize.SetSizeTypeX(BackgroundImageSizeType::AUTO); 50023b3eb3cSopenharmony_ci } 50123b3eb3cSopenharmony_ci if (valueY.find("px") != std::string::npos) { 50223b3eb3cSopenharmony_ci SetBgImgSizeY(BackgroundImageSizeType::LENGTH, StringToDouble(valueY), bgImgSize); 50323b3eb3cSopenharmony_ci } else if (valueY.find('%') != std::string::npos) { 50423b3eb3cSopenharmony_ci SetBgImgSizeY(BackgroundImageSizeType::PERCENT, StringToDouble(valueY), bgImgSize); 50523b3eb3cSopenharmony_ci } else { 50623b3eb3cSopenharmony_ci bgImgSize.SetSizeTypeY(BackgroundImageSizeType::AUTO); 50723b3eb3cSopenharmony_ci } 50823b3eb3cSopenharmony_ci } else { 50923b3eb3cSopenharmony_ci auto sizeTypeIter = BinarySearchFindIndex(bgImageSizeType, ArraySize(bgImageSizeType), value.c_str()); 51023b3eb3cSopenharmony_ci if (sizeTypeIter != -1) { 51123b3eb3cSopenharmony_ci bgImgSize.SetSizeTypeX(bgImageSizeType[sizeTypeIter].value); 51223b3eb3cSopenharmony_ci bgImgSize.SetSizeTypeY(bgImageSizeType[sizeTypeIter].value); 51323b3eb3cSopenharmony_ci } else if (value.find("px") != std::string::npos) { 51423b3eb3cSopenharmony_ci SetBgImgSizeX(BackgroundImageSizeType::LENGTH, StringToDouble(value), bgImgSize); 51523b3eb3cSopenharmony_ci bgImgSize.SetSizeTypeY(BackgroundImageSizeType::AUTO); 51623b3eb3cSopenharmony_ci } else if (value.find('%') != std::string::npos) { 51723b3eb3cSopenharmony_ci SetBgImgSizeX(BackgroundImageSizeType::PERCENT, StringToDouble(value), bgImgSize); 51823b3eb3cSopenharmony_ci bgImgSize.SetSizeTypeY(BackgroundImageSizeType::AUTO); 51923b3eb3cSopenharmony_ci } else { 52023b3eb3cSopenharmony_ci bgImgSize.SetSizeTypeX(BackgroundImageSizeType::AUTO); 52123b3eb3cSopenharmony_ci bgImgSize.SetSizeTypeY(BackgroundImageSizeType::AUTO); 52223b3eb3cSopenharmony_ci } 52323b3eb3cSopenharmony_ci } 52423b3eb3cSopenharmony_ci return true; 52523b3eb3cSopenharmony_ci} 52623b3eb3cSopenharmony_ci#endif 52723b3eb3cSopenharmony_ciRefPtr<ClipPath> CreateClipPath(const std::string& value) 52823b3eb3cSopenharmony_ci{ 52923b3eb3cSopenharmony_ci if (value.empty()) { 53023b3eb3cSopenharmony_ci return nullptr; 53123b3eb3cSopenharmony_ci } 53223b3eb3cSopenharmony_ci auto clipPath = ClipPath::CreateShape(value); 53323b3eb3cSopenharmony_ci GeometryBoxType geometryBoxType = ClipPath::GetGeometryBoxType(value); 53423b3eb3cSopenharmony_ci if (geometryBoxType != GeometryBoxType::NONE) { 53523b3eb3cSopenharmony_ci if (!clipPath) { 53623b3eb3cSopenharmony_ci clipPath = AceType::MakeRefPtr<ClipPath>(); 53723b3eb3cSopenharmony_ci } 53823b3eb3cSopenharmony_ci } 53923b3eb3cSopenharmony_ci if (clipPath) { 54023b3eb3cSopenharmony_ci clipPath->SetGeometryBoxType(geometryBoxType); 54123b3eb3cSopenharmony_ci } 54223b3eb3cSopenharmony_ci return clipPath; 54323b3eb3cSopenharmony_ci} 54423b3eb3cSopenharmony_ci 54523b3eb3cSopenharmony_cistd::optional<RadialSizeType> ParseRadialGradientSize(const std::string& value) 54623b3eb3cSopenharmony_ci{ 54723b3eb3cSopenharmony_ci const static std::unordered_map<std::string, RadialSizeType> sizeTypes = { 54823b3eb3cSopenharmony_ci { DOM_GRADIENT_SIZE_CLOSEST_CORNER, RadialSizeType::CLOSEST_CORNER }, 54923b3eb3cSopenharmony_ci { DOM_GRADIENT_SIZE_CLOSEST_SIDE, RadialSizeType::CLOSEST_SIDE }, 55023b3eb3cSopenharmony_ci { DOM_GRADIENT_SIZE_FARTHEST_CORNER, RadialSizeType::FARTHEST_CORNER }, 55123b3eb3cSopenharmony_ci { DOM_GRADIENT_SIZE_FARTHEST_SIDE, RadialSizeType::FARTHEST_SIDE }, 55223b3eb3cSopenharmony_ci }; 55323b3eb3cSopenharmony_ci if (!value.empty()) { 55423b3eb3cSopenharmony_ci auto pos = sizeTypes.find(value); 55523b3eb3cSopenharmony_ci if (pos != sizeTypes.end()) { 55623b3eb3cSopenharmony_ci return std::make_optional(pos->second); 55723b3eb3cSopenharmony_ci } 55823b3eb3cSopenharmony_ci } 55923b3eb3cSopenharmony_ci return std::nullopt; 56023b3eb3cSopenharmony_ci} 56123b3eb3cSopenharmony_ci#ifndef FUZZTEST 56223b3eb3cSopenharmony_ci// ObjectPosition 56323b3eb3cSopenharmony_ciImageObjectPosition ParseImageObjectPosition(const std::string& value) 56423b3eb3cSopenharmony_ci{ 56523b3eb3cSopenharmony_ci ImageObjectPosition imageObjectPosition; 56623b3eb3cSopenharmony_ci static const LinearMapNode<void (*)(ImageObjectPosition&)> backGroundPositionOperators[] = { 56723b3eb3cSopenharmony_ci { DOM_IMAGE_POSITION_BOTTOM, 56823b3eb3cSopenharmony_ci [](ImageObjectPosition& imageObjectPosition) { 56923b3eb3cSopenharmony_ci SetBgImgPositionY(BackgroundImagePositionType::PERCENT, 100.0, imageObjectPosition); 57023b3eb3cSopenharmony_ci } }, 57123b3eb3cSopenharmony_ci { DOM_IMAGE_POSITION_LEFT, 57223b3eb3cSopenharmony_ci [](ImageObjectPosition& imageObjectPosition) { 57323b3eb3cSopenharmony_ci SetBgImgPositionX(BackgroundImagePositionType::PERCENT, 0.0, imageObjectPosition); 57423b3eb3cSopenharmony_ci } }, 57523b3eb3cSopenharmony_ci { DOM_IMAGE_POSITION_RIGHT, 57623b3eb3cSopenharmony_ci [](ImageObjectPosition& imageObjectPosition) { 57723b3eb3cSopenharmony_ci SetBgImgPositionX(BackgroundImagePositionType::PERCENT, 100.0, imageObjectPosition); 57823b3eb3cSopenharmony_ci } }, 57923b3eb3cSopenharmony_ci { DOM_IMAGE_POSITION_TOP, 58023b3eb3cSopenharmony_ci [](ImageObjectPosition& imageObjectPosition) { 58123b3eb3cSopenharmony_ci SetBgImgPositionY(BackgroundImagePositionType::PERCENT, 0.0, imageObjectPosition); 58223b3eb3cSopenharmony_ci } }, 58323b3eb3cSopenharmony_ci }; 58423b3eb3cSopenharmony_ci 58523b3eb3cSopenharmony_ci std::vector<std::string> offsets; 58623b3eb3cSopenharmony_ci StringUtils::StringSplitter(value, ' ', offsets); 58723b3eb3cSopenharmony_ci if (!offsets.empty()) { 58823b3eb3cSopenharmony_ci std::string valueX = ""; 58923b3eb3cSopenharmony_ci std::string valueY = ""; 59023b3eb3cSopenharmony_ci GetOffsetValueObjectPosition(offsets, valueX, valueY); 59123b3eb3cSopenharmony_ci SetBgImgPosition(BackgroundImagePositionType::PERCENT, 50.0, imageObjectPosition); 59223b3eb3cSopenharmony_ci if (ObjectImgPositionIsValid(valueX, valueY)) { 59323b3eb3cSopenharmony_ci if (valueX.find("px") != std::string::npos) { 59423b3eb3cSopenharmony_ci SetBgImgPositionX(BackgroundImagePositionType::PX, StringToDouble(valueX), imageObjectPosition); 59523b3eb3cSopenharmony_ci } else if (valueX.find('%') != std::string::npos) { 59623b3eb3cSopenharmony_ci SetBgImgPositionX(BackgroundImagePositionType::PERCENT, StringToDouble(valueX), imageObjectPosition); 59723b3eb3cSopenharmony_ci } else { 59823b3eb3cSopenharmony_ci auto operatorIterX = BinarySearchFindIndex( 59923b3eb3cSopenharmony_ci backGroundPositionOperators, ArraySize(backGroundPositionOperators), valueX.c_str()); 60023b3eb3cSopenharmony_ci if (operatorIterX != -1) { 60123b3eb3cSopenharmony_ci backGroundPositionOperators[operatorIterX].value(imageObjectPosition); 60223b3eb3cSopenharmony_ci } 60323b3eb3cSopenharmony_ci } 60423b3eb3cSopenharmony_ci if (valueY.find("px") != std::string::npos) { 60523b3eb3cSopenharmony_ci SetBgImgPositionY(BackgroundImagePositionType::PX, StringToDouble(valueY), imageObjectPosition); 60623b3eb3cSopenharmony_ci } else if (valueY.find('%') != std::string::npos) { 60723b3eb3cSopenharmony_ci SetBgImgPositionY(BackgroundImagePositionType::PERCENT, StringToDouble(valueY), imageObjectPosition); 60823b3eb3cSopenharmony_ci } else { 60923b3eb3cSopenharmony_ci auto operatorIterY = BinarySearchFindIndex( 61023b3eb3cSopenharmony_ci backGroundPositionOperators, ArraySize(backGroundPositionOperators), valueY.c_str()); 61123b3eb3cSopenharmony_ci if (operatorIterY != -1) { 61223b3eb3cSopenharmony_ci backGroundPositionOperators[operatorIterY].value(imageObjectPosition); 61323b3eb3cSopenharmony_ci } 61423b3eb3cSopenharmony_ci } 61523b3eb3cSopenharmony_ci } 61623b3eb3cSopenharmony_ci } 61723b3eb3cSopenharmony_ci 61823b3eb3cSopenharmony_ci return imageObjectPosition; 61923b3eb3cSopenharmony_ci} 62023b3eb3cSopenharmony_ci#endif 62123b3eb3cSopenharmony_ci 62223b3eb3cSopenharmony_ci} // namespace OHOS::Ace::Framework