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 RefPtr<ResourceObject> blankResObj;
28 auto nodeInfo = ArkTSUtils::MakeNativeNodeInfo(nativeNode);
29 if (ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color, blankResObj, nodeInfo)) {
30 uint32_t value = color.GetValue();
31 auto blankRawPtr = AceType::RawPtr(blankResObj);
32 GetArkUINodeModifiers()->getBlankModifier()->setColor(nativeNode, value, blankRawPtr);
33 } else {
34 GetArkUINodeModifiers()->getBlankModifier()->resetColor(nativeNode);
35 }
36 return panda::JSValueRef::Undefined(vm);
37 }
ResetColor(ArkUIRuntimeCallInfo * runtimeCallInfo)38 ArkUINativeModuleValue BlankBridge::ResetColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
39 {
40 EcmaVM* vm = runtimeCallInfo->GetVM();
41 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
42 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
43 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
44 GetArkUINodeModifiers()->getBlankModifier()->resetColor(nativeNode);
45 return panda::JSValueRef::Undefined(vm);
46 }
SetBlankHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)47 ArkUINativeModuleValue BlankBridge::SetBlankHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
48 {
49 EcmaVM* vm = runtimeCallInfo->GetVM();
50 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
51 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
52 Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(1);
53 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
54 CalcDimension height;
55 RefPtr<ResourceObject> heightResObj;
56 std::string calcStr;
57 if (!ArkTSUtils::ParseJsDimensionVpNG(vm, valueArg, height, heightResObj)) {
58 GetArkUINodeModifiers()->getCommonModifier()->resetHeight(nativeNode);
59 } else {
60 if (LessNotEqual(height.Value(), 0.0)) {
61 height.SetValue(0.0);
62 }
63 auto heightRawResObj = AceType::RawPtr(heightResObj);
64 if (height.Unit() == DimensionUnit::CALC) {
65 GetArkUINodeModifiers()->getCommonModifier()->setHeight(nativeNode, height.Value(),
66 static_cast<int32_t>(height.Unit()), height.CalcValue().c_str(), heightRawResObj);
67 } else {
68 GetArkUINodeModifiers()->getCommonModifier()->setHeight(
69 nativeNode, height.Value(), static_cast<int32_t>(height.Unit()), calcStr.c_str(), heightRawResObj);
70 }
71 }
72 if (!ArkTSUtils::ParseJsDimensionVp(vm, valueArg, height)) {
73 return panda::JSValueRef::Undefined(vm);
74 }
75 GetArkUINodeModifiers()->getBlankModifier()->setBlankHeight(
76 nativeNode, height.Value(), static_cast<int32_t>(height.Unit()));
77 return panda::JSValueRef::Undefined(vm);
78 }
ResetBlankHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)79 ArkUINativeModuleValue BlankBridge::ResetBlankHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
80 {
81 EcmaVM* vm = runtimeCallInfo->GetVM();
82 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
83 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
84 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
85 GetArkUINodeModifiers()->getBlankModifier()->resetBlankHeight(nativeNode);
86 return panda::JSValueRef::Undefined(vm);
87 }
SetBlankMin(ArkUIRuntimeCallInfo * runtimeCallInfo)88 ArkUINativeModuleValue BlankBridge::SetBlankMin(ArkUIRuntimeCallInfo* runtimeCallInfo)
89 {
90 EcmaVM* vm = runtimeCallInfo->GetVM();
91 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
92 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
93 Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(1);
94 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
95
96 CalcDimension blankMin;
97 if (!ArkTSUtils::ParseJsDimensionVp(vm, valueArg, blankMin)) {
98 return panda::JSValueRef::Undefined(vm);
99 }
100
101 if (blankMin.IsNegative() || blankMin.Unit() == DimensionUnit::PERCENT) {
102 blankMin.SetValue(0.0);
103 }
104 GetArkUINodeModifiers()->getBlankModifier()->setBlankMin(
105 nativeNode, blankMin.Value(), static_cast<int32_t>(blankMin.Unit()));
106 return panda::JSValueRef::Undefined(vm);
107 }
ResetBlankMin(ArkUIRuntimeCallInfo * runtimeCallInfo)108 ArkUINativeModuleValue BlankBridge::ResetBlankMin(ArkUIRuntimeCallInfo* runtimeCallInfo)
109 {
110 EcmaVM* vm = runtimeCallInfo->GetVM();
111 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
112 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
113 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
114 GetArkUINodeModifiers()->getBlankModifier()->resetBlankMin(nativeNode);
115 return panda::JSValueRef::Undefined(vm);
116 }
117 }
118