• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_counter_bridge.h"
16 
17 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
18 #include "core/interfaces/native/node/api.h"
19 
20 namespace OHOS::Ace::NG {
SetEnableInc(ArkUIRuntimeCallInfo * runtimeCallInfo)21 ArkUINativeModuleValue CounterBridge::SetEnableInc(ArkUIRuntimeCallInfo* runtimeCallInfo)
22 {
23     EcmaVM* vm = runtimeCallInfo->GetVM();
24     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
25     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
26     Local<JSValueRef> flagArg = runtimeCallInfo->GetCallArgRef(1);
27     void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
28     if (flagArg->IsUndefined() || !flagArg->IsBoolean()) {
29         GetArkUIInternalNodeAPI()->GetCounterModifier().ReSetEnableInc(nativeNode);
30         return panda::JSValueRef::Undefined(vm);
31     }
32     bool flag = flagArg->ToBoolean(vm)->Value();
33     GetArkUIInternalNodeAPI()->GetCounterModifier().SetEnableInc(nativeNode, flag);
34     return panda::JSValueRef::Undefined(vm);
35 }
36 
ResetEnableInc(ArkUIRuntimeCallInfo * runtimeCallInfo)37 ArkUINativeModuleValue CounterBridge::ResetEnableInc(ArkUIRuntimeCallInfo* runtimeCallInfo)
38 {
39     EcmaVM* vm = runtimeCallInfo->GetVM();
40     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
41     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
42     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
43     GetArkUIInternalNodeAPI()->GetCounterModifier().ReSetEnableInc(nativeNode);
44     return panda::JSValueRef::Undefined(vm);
45 }
46 
SetEnableDec(ArkUIRuntimeCallInfo * runtimeCallInfo)47 ArkUINativeModuleValue CounterBridge::SetEnableDec(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> flagArg = runtimeCallInfo->GetCallArgRef(1);
53     void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
54     if (flagArg->IsUndefined() || !flagArg->IsBoolean()) {
55         GetArkUIInternalNodeAPI()->GetCounterModifier().ReSetEnableDec(nativeNode);
56         return panda::JSValueRef::Undefined(vm);
57     }
58     bool flag = flagArg->ToBoolean(vm)->Value();
59     GetArkUIInternalNodeAPI()->GetCounterModifier().SetEnableDec(nativeNode, flag);
60     return panda::JSValueRef::Undefined(vm);
61 }
62 
ResetEnableDec(ArkUIRuntimeCallInfo * runtimeCallInfo)63 ArkUINativeModuleValue CounterBridge::ResetEnableDec(ArkUIRuntimeCallInfo* runtimeCallInfo)
64 {
65     EcmaVM* vm = runtimeCallInfo->GetVM();
66     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
67     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
68     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
69     GetArkUIInternalNodeAPI()->GetCounterModifier().ReSetEnableDec(nativeNode);
70     return panda::JSValueRef::Undefined(vm);
71 }
72 
SetCounterHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)73 ArkUINativeModuleValue CounterBridge::SetCounterHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
74 {
75     EcmaVM* vm = runtimeCallInfo->GetVM();
76     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
77     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
78     Local<JSValueRef> heightValue = runtimeCallInfo->GetCallArgRef(1);
79     void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
80 
81     CalcDimension height;
82     ArkTSUtils::ParseJsDimensionVp(vm, heightValue, height, false);
83     if (LessNotEqual(height.Value(), 0.0)) {
84         GetArkUIInternalNodeAPI()->GetCounterModifier().ResetCounterHeight(nativeNode);
85         return panda::JSValueRef::Undefined(vm);
86     }
87     GetArkUIInternalNodeAPI()->GetCounterModifier().SetCounterHeight(
88         nativeNode, height.Value(), static_cast<int>(height.Unit()));
89     return panda::JSValueRef::Undefined(vm);
90 }
91 
ResetCounterHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)92 ArkUINativeModuleValue CounterBridge::ResetCounterHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
93 {
94     EcmaVM* vm = runtimeCallInfo->GetVM();
95     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
96     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
97     void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
98     GetArkUIInternalNodeAPI()->GetCounterModifier().ResetCounterHeight(nativeNode);
99     return panda::JSValueRef::Undefined(vm);
100 }
101 
SetCounterWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)102 ArkUINativeModuleValue CounterBridge::SetCounterWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
103 {
104     EcmaVM* vm = runtimeCallInfo->GetVM();
105     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
106     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
107     Local<JSValueRef> widthValue = runtimeCallInfo->GetCallArgRef(1);
108     void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
109 
110     CalcDimension width;
111     ArkTSUtils::ParseJsDimensionVp(vm, widthValue, width, false);
112     if (LessNotEqual(width.Value(), 0.0)) {
113         GetArkUIInternalNodeAPI()->GetCounterModifier().ResetCounterWidth(nativeNode);
114         return panda::JSValueRef::Undefined(vm);
115     }
116 
117     GetArkUIInternalNodeAPI()->GetCounterModifier().SetCounterWidth(
118         nativeNode, width.Value(), static_cast<int>(width.Unit()));
119     return panda::JSValueRef::Undefined(vm);
120 }
121 
ResetCounterWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)122 ArkUINativeModuleValue CounterBridge::ResetCounterWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
123 {
124     EcmaVM* vm = runtimeCallInfo->GetVM();
125     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
126     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
127     void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
128     GetArkUIInternalNodeAPI()->GetCounterModifier().ResetCounterWidth(nativeNode);
129     return panda::JSValueRef::Undefined(vm);
130 }
131 
SetCounterBackgroundColor(ArkUIRuntimeCallInfo * runtimeCallInfo)132 ArkUINativeModuleValue CounterBridge::SetCounterBackgroundColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
133 {
134     EcmaVM* vm = runtimeCallInfo->GetVM();
135     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
136     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
137     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
138     void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
139     Color color;
140     if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color)) {
141         GetArkUIInternalNodeAPI()->GetCounterModifier().ResetCounterBackgroundColor(nativeNode);
142     } else {
143         GetArkUIInternalNodeAPI()->GetCounterModifier().SetCounterBackgroundColor(nativeNode, color.GetValue());
144     }
145     return panda::JSValueRef::Undefined(vm);
146 }
147 
ResetCounterBackgroundColor(ArkUIRuntimeCallInfo * runtimeCallInfo)148 ArkUINativeModuleValue CounterBridge::ResetCounterBackgroundColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
149 {
150     EcmaVM* vm = runtimeCallInfo->GetVM();
151     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
152     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
153     void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
154     GetArkUIInternalNodeAPI()->GetCounterModifier().ResetCounterBackgroundColor(nativeNode);
155     return panda::JSValueRef::Undefined(vm);
156 }
157 
SetCounterSize(ArkUIRuntimeCallInfo * runtimeCallInfo)158 ArkUINativeModuleValue CounterBridge::SetCounterSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
159 {
160     EcmaVM* vm = runtimeCallInfo->GetVM();
161     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
162     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
163     void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
164     Local<JSValueRef> widthValue = runtimeCallInfo->GetCallArgRef(1); // 1: width Value
165     Local<JSValueRef> heightValue = runtimeCallInfo->GetCallArgRef(2); // 2: height Value
166     CalcDimension width;
167     ArkTSUtils::ParseJsDimensionVp(vm, widthValue, width, false);
168     if (GreatNotEqual(width.Value(), 0.0)) {
169         GetArkUIInternalNodeAPI()->GetCounterModifier().SetCounterWidth(
170             nativeNode, width.Value(), static_cast<int>(width.Unit()));
171     }
172     CalcDimension height;
173     ArkTSUtils::ParseJsDimensionVp(vm, heightValue, height, false);
174     if (GreatNotEqual(height.Value(), 0.0)) {
175         GetArkUIInternalNodeAPI()->GetCounterModifier().SetCounterHeight(
176             nativeNode, height.Value(), static_cast<int>(height.Unit()));
177     }
178     return panda::JSValueRef::Undefined(vm);
179 }
180 
ResetCounterSize(ArkUIRuntimeCallInfo * runtimeCallInfo)181 ArkUINativeModuleValue CounterBridge::ResetCounterSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
182 {
183     EcmaVM* vm = runtimeCallInfo->GetVM();
184     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
185     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
186     void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
187     GetArkUIInternalNodeAPI()->GetCounterModifier().ResetCounterWidth(nativeNode);
188     GetArkUIInternalNodeAPI()->GetCounterModifier().ResetCounterHeight(nativeNode);
189     return panda::JSValueRef::Undefined(vm);
190 }
191 } // namespace OHOS::Ace::NG
192