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_divider_bridge.h"
16
17 #include "base/geometry/dimension.h"
18 #include "core/interfaces/native/node/api.h"
19 #include "bridge/declarative_frontend/jsview/js_view_abstract.h"
20 #include "core/components/divider/divider_theme.h"
21 #include "frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
22
23 namespace OHOS::Ace::NG {
SetStrokeWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)24 ArkUINativeModuleValue DividerBridge::SetStrokeWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
25 {
26 EcmaVM* vm = runtimeCallInfo->GetVM();
27 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
28 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(0);
29 Local<JSValueRef> strokeWidthArg = runtimeCallInfo->GetCallArgRef(1);
30 void* nativeNode = nativeNodeArg->ToNativePointer(vm)->Value();
31 CalcDimension strokeWidth;
32 if (ArkTSUtils::ParseJsDimensionVpNG(vm, strokeWidthArg, strokeWidth, false) &&
33 strokeWidth.Value() >= 0) {
34 GetArkUIInternalNodeAPI()->GetDividerModifier().SetDividerStrokeWidth(
35 nativeNode, strokeWidth.Value(), static_cast<int32_t>(strokeWidth.Unit()));
36 } else {
37 GetArkUIInternalNodeAPI()->GetDividerModifier().ResetDividerStrokeWidth(nativeNode);
38 }
39 return panda::JSValueRef::Undefined(vm);
40 }
41
ResetStrokeWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)42 ArkUINativeModuleValue DividerBridge::ResetStrokeWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
43 {
44 EcmaVM* vm = runtimeCallInfo->GetVM();
45 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
46 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(0);
47 void* nativeNode = nativeNodeArg->ToNativePointer(vm)->Value();
48 GetArkUIInternalNodeAPI()->GetDividerModifier().ResetDividerStrokeWidth(nativeNode);
49 return panda::JSValueRef::Undefined(vm);
50 }
51
SetLineCap(ArkUIRuntimeCallInfo * runtimeCallInfo)52 ArkUINativeModuleValue DividerBridge::SetLineCap(ArkUIRuntimeCallInfo* runtimeCallInfo)
53 {
54 EcmaVM* vm = runtimeCallInfo->GetVM();
55 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
56 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(0);
57 Local<JSValueRef> lineCapArg = runtimeCallInfo->GetCallArgRef(1);
58 void* nativeNode = nativeNodeArg->ToNativePointer(vm)->Value();
59 if (lineCapArg->IsNumber()) {
60 int32_t lineCap = lineCapArg->Int32Value(vm);
61 GetArkUIInternalNodeAPI()->GetDividerModifier().SetDividerLineCap(nativeNode, lineCap);
62 } else {
63 GetArkUIInternalNodeAPI()->GetDividerModifier().ResetDividerLineCap(nativeNode);
64 }
65 return panda::JSValueRef::Undefined(vm);
66 }
67
ResetLineCap(ArkUIRuntimeCallInfo * runtimeCallInfo)68 ArkUINativeModuleValue DividerBridge::ResetLineCap(ArkUIRuntimeCallInfo* runtimeCallInfo)
69 {
70 EcmaVM* vm = runtimeCallInfo->GetVM();
71 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
72 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(0);
73 void* nativeNode = nativeNodeArg->ToNativePointer(vm)->Value();
74 GetArkUIInternalNodeAPI()->GetDividerModifier().ResetDividerLineCap(nativeNode);
75 return panda::JSValueRef::Undefined(vm);
76 }
77
SetColor(ArkUIRuntimeCallInfo * runtimeCallInfo)78 ArkUINativeModuleValue DividerBridge::SetColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
79 {
80 EcmaVM* vm = runtimeCallInfo->GetVM();
81 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
82 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(0);
83 Local<JSValueRef> colorArg = runtimeCallInfo->GetCallArgRef(1);
84 void* nativeNode = nativeNodeArg->ToNativePointer(vm)->Value();
85 Color color;
86 if (ArkTSUtils::ParseJsColorAlpha(vm, colorArg, color)) {
87 GetArkUIInternalNodeAPI()->GetDividerModifier().SetDividerColor(nativeNode, color.GetValue());
88 } else {
89 GetArkUIInternalNodeAPI()->GetDividerModifier().ResetDividerColor(nativeNode);
90 }
91 return panda::JSValueRef::Undefined(vm);
92 }
93
ResetColor(ArkUIRuntimeCallInfo * runtimeCallInfo)94 ArkUINativeModuleValue DividerBridge::ResetColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
95 {
96 EcmaVM* vm = runtimeCallInfo->GetVM();
97 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
98 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(0);
99 void* nativeNode = nativeNodeArg->ToNativePointer(vm)->Value();
100 GetArkUIInternalNodeAPI()->GetDividerModifier().ResetDividerColor(nativeNode);
101 return panda::JSValueRef::Undefined(vm);
102 }
103
SetVertical(ArkUIRuntimeCallInfo * runtimeCallInfo)104 ArkUINativeModuleValue DividerBridge::SetVertical(ArkUIRuntimeCallInfo* runtimeCallInfo)
105 {
106 EcmaVM* vm = runtimeCallInfo->GetVM();
107 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
108 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(0);
109 Local<JSValueRef> verticalArg = runtimeCallInfo->GetCallArgRef(1);
110 void* nativeNode = nativeNodeArg->ToNativePointer(vm)->Value();
111 if (verticalArg->IsBoolean()) {
112 bool value = verticalArg->ToBoolean(vm)->Value();
113 GetArkUIInternalNodeAPI()->GetDividerModifier().SetDividerVertical(nativeNode, value);
114 } else {
115 GetArkUIInternalNodeAPI()->GetDividerModifier().ResetDividerVertical(nativeNode);
116 }
117 return panda::JSValueRef::Undefined(vm);
118 }
119
ResetVertical(ArkUIRuntimeCallInfo * runtimeCallInfo)120 ArkUINativeModuleValue DividerBridge::ResetVertical(ArkUIRuntimeCallInfo* runtimeCallInfo)
121 {
122 EcmaVM* vm = runtimeCallInfo->GetVM();
123 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
124 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(0);
125 void* nativeNode = nativeNodeArg->ToNativePointer(vm)->Value();
126 GetArkUIInternalNodeAPI()->GetDividerModifier().ResetDividerVertical(nativeNode);
127 return panda::JSValueRef::Undefined(vm);
128 }
129 } // namespace OHOS::Ace::NG
130