1 /*
2 * Copyright (c) 2023 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_blank_bridge.h"
16 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
17
18 namespace OHOS::Ace::NG {
SetColor(ArkUIRuntimeCallInfo * runtimeCallInfo)19 ArkUINativeModuleValue BlankBridge::SetColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
20 {
21 EcmaVM* vm = runtimeCallInfo->GetVM();
22 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
23 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
24 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
25 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
26 Color color;
27 if (ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color)) {
28 uint32_t value = color.GetValue();
29 GetArkUINodeModifiers()->getBlankModifier()->setColor(nativeNode, value);
30 } else {
31 GetArkUINodeModifiers()->getBlankModifier()->resetColor(nativeNode);
32 }
33 return panda::JSValueRef::Undefined(vm);
34 }
ResetColor(ArkUIRuntimeCallInfo * runtimeCallInfo)35 ArkUINativeModuleValue BlankBridge::ResetColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
36 {
37 EcmaVM* vm = runtimeCallInfo->GetVM();
38 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
39 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
40 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
41 GetArkUINodeModifiers()->getBlankModifier()->resetColor(nativeNode);
42 return panda::JSValueRef::Undefined(vm);
43 }
SetBlankHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)44 ArkUINativeModuleValue BlankBridge::SetBlankHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
45 {
46 EcmaVM* vm = runtimeCallInfo->GetVM();
47 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
48 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
49 Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(1);
50 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
51 CalcDimension height;
52 std::string calcStr;
53 if (!ArkTSUtils::ParseJsDimensionVpNG(vm, valueArg, height)) {
54 GetArkUINodeModifiers()->getCommonModifier()->resetHeight(nativeNode);
55 } else {
56 if (LessNotEqual(height.Value(), 0.0)) {
57 height.SetValue(0.0);
58 }
59 if (height.Unit() == DimensionUnit::CALC) {
60 GetArkUINodeModifiers()->getCommonModifier()->setHeight(
61 nativeNode, height.Value(), static_cast<int32_t>(height.Unit()), height.CalcValue().c_str());
62 } else {
63 GetArkUINodeModifiers()->getCommonModifier()->setHeight(
64 nativeNode, height.Value(), static_cast<int32_t>(height.Unit()), calcStr.c_str());
65 }
66 }
67 if (!ArkTSUtils::ParseJsDimensionVp(vm, valueArg, height)) {
68 return panda::JSValueRef::Undefined(vm);
69 }
70 GetArkUINodeModifiers()->getBlankModifier()->setBlankHeight(
71 nativeNode, height.Value(), static_cast<int32_t>(height.Unit()));
72 return panda::JSValueRef::Undefined(vm);
73 }
ResetBlankHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)74 ArkUINativeModuleValue BlankBridge::ResetBlankHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
75 {
76 EcmaVM* vm = runtimeCallInfo->GetVM();
77 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
78 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
79 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
80 GetArkUINodeModifiers()->getBlankModifier()->resetBlankHeight(nativeNode);
81 return panda::JSValueRef::Undefined(vm);
82 }
SetBlankMin(ArkUIRuntimeCallInfo * runtimeCallInfo)83 ArkUINativeModuleValue BlankBridge::SetBlankMin(ArkUIRuntimeCallInfo* runtimeCallInfo)
84 {
85 EcmaVM* vm = runtimeCallInfo->GetVM();
86 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
87 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
88 Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(1);
89 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
90
91 CalcDimension blankMin;
92 if (!ArkTSUtils::ParseJsDimensionVp(vm, valueArg, blankMin)) {
93 return panda::JSValueRef::Undefined(vm);
94 }
95
96 if (blankMin.IsNegative() || blankMin.Unit() == DimensionUnit::PERCENT) {
97 blankMin.SetValue(0.0);
98 }
99 GetArkUINodeModifiers()->getBlankModifier()->setBlankMin(
100 nativeNode, blankMin.Value(), static_cast<int32_t>(blankMin.Unit()));
101 return panda::JSValueRef::Undefined(vm);
102 }
ResetBlankMin(ArkUIRuntimeCallInfo * runtimeCallInfo)103 ArkUINativeModuleValue BlankBridge::ResetBlankMin(ArkUIRuntimeCallInfo* runtimeCallInfo)
104 {
105 EcmaVM* vm = runtimeCallInfo->GetVM();
106 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
107 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
108 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
109 GetArkUINodeModifiers()->getBlankModifier()->resetBlankMin(nativeNode);
110 return panda::JSValueRef::Undefined(vm);
111 }
112 }
113