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 CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
34 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
35 std::shared_ptr<TextBackgroundStyle> style = std::make_shared<TextBackgroundStyle>();
36 RefPtr<ResourceObject> colorResObj;
37 auto nodeInfo = ArkTSUtils::MakeNativeNodeInfo(nativeNode);
38 if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color, colorResObj, nodeInfo)) {
39 GetArkUINodeModifiers()->getContainerSpanModifier()->resetContainerSpanTextBackgroundStyle(nativeNode);
40 return panda::JSValueRef::Undefined(vm);
41 }
42 ArkTSUtils::ParseOuterBorderRadius(runtimeCallInfo, vm, radiusArray, valueUnits, BORDER_RADIUS_START_INDEX,
43 style);
44 ArkTSUtils::SetTextBackgroundStyle(style, color, colorResObj, radiusArray.data(), valueUnits.data());
45 GetArkUINodeModifiers()->getContainerSpanModifier()->setContainerSpanTextBackgroundStyle(nativeNode,
46 color.GetValue(), radiusArray.data(), valueUnits.data(), static_cast<int32_t>(radiusArray.size()),
47 style.get());
48 return panda::JSValueRef::Undefined(vm);
49 }
50
ResetTextBackgroundStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)51 ArkUINativeModuleValue ContainerSpanBridge::ResetTextBackgroundStyle(ArkUIRuntimeCallInfo* runtimeCallInfo)
52 {
53 EcmaVM* vm = runtimeCallInfo->GetVM();
54 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
55 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
56 CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
57 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
58 GetArkUINodeModifiers()->getContainerSpanModifier()->resetContainerSpanTextBackgroundStyle(nativeNode);
59 return panda::JSValueRef::Undefined(vm);
60 }
61 } // namespace OHOS::Ace::NG
62