From ae0bd0dca673e7acdd9a49230d2db0c2d96c894c Mon Sep 17 00:00:00 2001 From: WyxGitHub <878459285@qq.com> Date: Wed, 6 Nov 2024 10:54:19 +0800 Subject: [PATCH] fixBigMethod Signed-off-by: WyxGitHub <878459285@qq.com> --- .../jsview/js_view_abstract.cpp | 76 +++++++++---------- .../jsview/js_view_abstract.h | 1 + 2 files changed, 37 insertions(+), 40 deletions(-) diff --git a/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp b/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp index ea03c556c7b..6858713e82b 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp @@ -4134,31 +4134,22 @@ void JSViewAbstract::JsBorderImage(const JSCallbackInfo& info) return; } JSRef object = JSRef::Cast(jsVal); - if (object->IsEmpty()) { - return; - } + CHECK_NULL_VOID(!object->IsEmpty()); RefPtr borderImage = AceType::MakeRefPtr(); uint8_t imageBorderBitsets = 0; auto valueSource = object->GetProperty(static_cast(ArkUIIndex::SOURCE)); - if (!valueSource->IsString() && !valueSource->IsObject()) { - return; - } + CHECK_NULL_VOID((valueSource->IsString() || valueSource->IsObject())); std::string srcResult; - if (valueSource->IsString()) { - srcResult = valueSource->ToString(); - if (!srcResult.empty()) { - borderImage->SetSrc(srcResult); - imageBorderBitsets |= BorderImage::SOURCE_BIT; - } + if (valueSource->IsString() && !valueSource->ToString().empty()) { + borderImage->SetSrc(valueSource->ToString()); + imageBorderBitsets |= BorderImage::SOURCE_BIT; + } else if (valueSource->IsObject() && ParseJsMedia(valueSource, srcResult)) { + borderImage->SetSrc(srcResult); + imageBorderBitsets |= BorderImage::SOURCE_BIT; } else if (valueSource->IsObject()) { - if (ParseJsMedia(valueSource, srcResult)) { - borderImage->SetSrc(srcResult); - imageBorderBitsets |= BorderImage::SOURCE_BIT; - } else { - ParseBorderImageLinearGradient(valueSource, imageBorderBitsets); - } + ParseBorderImageLinearGradient(valueSource, imageBorderBitsets); } auto valueOutset = object->GetProperty("outset"); if (valueOutset->IsNumber() || valueOutset->IsString() || valueOutset->IsObject()) { @@ -4311,29 +4302,8 @@ bool JSViewAbstract::CheckJSCallbackInfo( return typeVerified || infoTypes.size() == 0; } -void JSViewAbstract::ParseBorderImageLinearGradient(const JSRef& args, uint8_t& bitset) +void JSViewAbstract::UpdateGradientWithDirection(NG::Gradient& lineGradient, NG::GradientDirection direction) { - if (!args->IsObject()) { - return; - } - JSRef jsObj = JSRef::Cast(args); - NG::Gradient lineGradient; - lineGradient.CreateGradientWithType(NG::GradientType::LINEAR); - // angle - std::optional degree; - if (Container::LessThanAPITargetVersion(PlatformVersion::VERSION_TWELVE)) { - GetJsAngle(static_cast(ArkUIIndex::ANGLE), jsObj, degree); - } else { - GetJsAngleWithDefault(static_cast(ArkUIIndex::ANGLE), jsObj, degree, 180.0f); - } - if (degree) { - lineGradient.GetLinearGradient()->angle = CalcDimension(degree.value(), DimensionUnit::PX); - degree.reset(); - } - // direction - auto direction = static_cast( - jsObj->GetPropertyValue(static_cast(ArkUIIndex::DIRECTION), - static_cast(NG::GradientDirection::NONE))); switch (direction) { case NG::GradientDirection::LEFT: lineGradient.GetLinearGradient()->linearX = NG::GradientDirection::LEFT; @@ -4369,6 +4339,32 @@ void JSViewAbstract::ParseBorderImageLinearGradient(const JSRef& args, ui default: break; } +} + +void JSViewAbstract::ParseBorderImageLinearGradient(const JSRef& args, uint8_t& bitset) +{ + if (!args->IsObject()) { + return; + } + JSRef jsObj = JSRef::Cast(args); + NG::Gradient lineGradient; + lineGradient.CreateGradientWithType(NG::GradientType::LINEAR); + // angle + std::optional degree; + if (Container::LessThanAPITargetVersion(PlatformVersion::VERSION_TWELVE)) { + GetJsAngle(static_cast(ArkUIIndex::ANGLE), jsObj, degree); + } else { + GetJsAngleWithDefault(static_cast(ArkUIIndex::ANGLE), jsObj, degree, 180.0f); + } + if (degree) { + lineGradient.GetLinearGradient()->angle = CalcDimension(degree.value(), DimensionUnit::PX); + degree.reset(); + } + // direction + auto direction = static_cast( + jsObj->GetPropertyValue(static_cast(ArkUIIndex::DIRECTION), + static_cast(NG::GradientDirection::NONE))); + UpdateGradientWithDirection(lineGradient, direction); auto repeating = jsObj->GetPropertyValue(static_cast(ArkUIIndex::REPEATING), false); lineGradient.SetRepeat(repeating); NewGetJsGradientColorStops(lineGradient, jsObj->GetProperty(static_cast(ArkUIIndex::COLORS))); diff --git a/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h b/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h index 05524de614f..44bb6f36635 100755 --- a/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h +++ b/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h @@ -230,6 +230,7 @@ public: const JSRef& args, BorderImage::BorderImageOption& borderImageDimension); static void ParseBorderImageLengthMetrics( const JSRef& object, LocalizedCalcDimension& localizedCalcDimension); + static void UpdateGradientWithDirection(NG::Gradient& lineGradient, NG::GradientDirection direction); static void ParseBorderImageLinearGradient(const JSRef& args, uint8_t& bitset); static void JsUseEffect(const JSCallbackInfo& info); static void JsUseShadowBatching(const JSCallbackInfo& info);