1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_container_span_bridge.h"
16
17 #include "frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
18
19 namespace OHOS::Ace::NG {
20 namespace {
21 constexpr int BORDER_RADIUS_START_INDEX = 2; // Border Radius args start index
22 } // namespace
23
SetTextBackgroundStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)24 ArkUINativeModuleValue ContainerSpanBridge::SetTextBackgroundStyle(ArkUIRuntimeCallInfo* runtimeCallInfo)
25 {
26 EcmaVM* vm = runtimeCallInfo->GetVM();
27 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
28 Color color;
29 std::vector<ArkUI_Float32> radiusArray;
30 std::vector<ArkUI_Int32> valueUnits;
31 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
32 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
33 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
34 if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color)) {
35 GetArkUINodeModifiers()->getContainerSpanModifier()->resetContainerSpanTextBackgroundStyle(nativeNode);
36 } else {
37 ArkTSUtils::ParseOuterBorderRadius(runtimeCallInfo, vm, radiusArray, valueUnits, BORDER_RADIUS_START_INDEX);
38 GetArkUINodeModifiers()->getContainerSpanModifier()->setContainerSpanTextBackgroundStyle(nativeNode,
39 color.GetValue(), radiusArray.data(), valueUnits.data(), static_cast<int32_t>(radiusArray.size()));
40 }
41 return panda::JSValueRef::Undefined(vm);
42 }
43
ResetTextBackgroundStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)44 ArkUINativeModuleValue ContainerSpanBridge::ResetTextBackgroundStyle(ArkUIRuntimeCallInfo* runtimeCallInfo)
45 {
46 EcmaVM* vm = runtimeCallInfo->GetVM();
47 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
48 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
49 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
50 GetArkUINodeModifiers()->getContainerSpanModifier()->resetContainerSpanTextBackgroundStyle(nativeNode);
51 return panda::JSValueRef::Undefined(vm);
52 }
53 } // namespace OHOS::Ace::NG
54