• 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_pattern_lock_bridge.h"
16 
17 #include "base/geometry/dimension.h"
18 #include "base/utils/utils.h"
19 #include "core/components/common/layout/constants.h"
20 #include "core/pipeline/pipeline_base.h"
21 #include "frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
22 #include "frameworks/core/components_v2/pattern_lock/pattern_lock_component.h"
23 
24 namespace OHOS::Ace::NG {
25 constexpr int NUM_0 = 0;
26 constexpr int NUM_1 = 1;
27 
SetSideLength(ArkUIRuntimeCallInfo * runtimeCallInfo)28 ArkUINativeModuleValue PatternLockBridge::SetSideLength(ArkUIRuntimeCallInfo* runtimeCallInfo)
29 {
30     EcmaVM* vm = runtimeCallInfo->GetVM();
31     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
32     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
33     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
34     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
35     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
36     CalcDimension sideLength;
37     RefPtr<ResourceObject> sideLengthResObj;
38     if (!(ArkTSUtils::ParseJsDimensionVp(vm, secondArg, sideLength, sideLengthResObj))) {
39         GetArkUINodeModifiers()->getPatternLockModifier()->resetPatternLockSideLength(nativeNode);
40     }
41     auto sideLengthRawPtr = AceType::RawPtr(sideLengthResObj);
42     GetArkUINodeModifiers()->getPatternLockModifier()->setPatternLockSideLengthRes(
43         nativeNode, sideLength.Value(), static_cast<int8_t>(sideLength.Unit()), sideLengthRawPtr);
44     return panda::JSValueRef::Undefined(vm);
45 }
46 
ResetSideLength(ArkUIRuntimeCallInfo * runtimeCallInfo)47 ArkUINativeModuleValue PatternLockBridge::ResetSideLength(ArkUIRuntimeCallInfo* runtimeCallInfo)
48 {
49     EcmaVM* vm = runtimeCallInfo->GetVM();
50     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
51     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
52     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
53     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
54     GetArkUINodeModifiers()->getPatternLockModifier()->resetPatternLockSideLength(nativeNode);
55     return panda::JSValueRef::Undefined(vm);
56 }
57 
SetAutoReset(ArkUIRuntimeCallInfo * runtimeCallInfo)58 ArkUINativeModuleValue PatternLockBridge::SetAutoReset(ArkUIRuntimeCallInfo* runtimeCallInfo)
59 {
60     EcmaVM* vm = runtimeCallInfo->GetVM();
61     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
62     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
63     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
64     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
65     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
66     uint32_t value = 1;
67     if (secondArg->IsBoolean()) {
68         value = static_cast<uint32_t>(secondArg->ToBoolean(vm)->Value());
69     }
70     GetArkUINodeModifiers()->getPatternLockModifier()->setPatternLockAutoReset(nativeNode, value);
71     return panda::JSValueRef::Undefined(vm);
72 }
73 
ResetAutoReset(ArkUIRuntimeCallInfo * runtimeCallInfo)74 ArkUINativeModuleValue PatternLockBridge::ResetAutoReset(ArkUIRuntimeCallInfo* runtimeCallInfo)
75 {
76     EcmaVM* vm = runtimeCallInfo->GetVM();
77     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
78     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
79     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
80     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
81     GetArkUINodeModifiers()->getPatternLockModifier()->resetPatternLockAutoReset(nativeNode);
82     return panda::JSValueRef::Undefined(vm);
83 }
84 
SetPathStrokeWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)85 ArkUINativeModuleValue PatternLockBridge::SetPathStrokeWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
86 {
87     EcmaVM* vm = runtimeCallInfo->GetVM();
88     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
89     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
90     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
91     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
92     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
93     CalcDimension strokeWidth;
94     if (!(ArkTSUtils::ParseJsDimensionVp(vm, secondArg, strokeWidth))) {
95         GetArkUINodeModifiers()->getPatternLockModifier()->resetPatternLockPathStrokeWidth(nativeNode);
96     }
97     GetArkUINodeModifiers()->getPatternLockModifier()->setPatternLockPathStrokeWidth(
98         nativeNode, strokeWidth.Value(), static_cast<int8_t>(strokeWidth.Unit()));
99     return panda::JSValueRef::Undefined(vm);
100 }
101 
ResetPathStrokeWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)102 ArkUINativeModuleValue PatternLockBridge::ResetPathStrokeWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
103 {
104     EcmaVM* vm = runtimeCallInfo->GetVM();
105     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
106     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
107     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
108     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
109     GetArkUINodeModifiers()->getPatternLockModifier()->resetPatternLockPathStrokeWidth(nativeNode);
110     return panda::JSValueRef::Undefined(vm);
111 }
112 
SetRegularColor(ArkUIRuntimeCallInfo * runtimeCallInfo)113 ArkUINativeModuleValue PatternLockBridge::SetRegularColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
114 {
115     EcmaVM* vm = runtimeCallInfo->GetVM();
116     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
117     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
118     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
119     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
120     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
121     Color color;
122     RefPtr<ResourceObject> regularColorResObj;
123     auto nodeInfo = ArkTSUtils::MakeNativeNodeInfo(nativeNode);
124     if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color, regularColorResObj, nodeInfo)) {
125         GetArkUINodeModifiers()->getPatternLockModifier()->resetPatternLockRegularColor(nativeNode);
126     } else {
127         auto regularColorRawPtr = AceType::RawPtr(regularColorResObj);
128         GetArkUINodeModifiers()->getPatternLockModifier()->setPatternLockRegularColorRes(
129             nativeNode, color.GetValue(), regularColorRawPtr);
130     }
131     return panda::JSValueRef::Undefined(vm);
132 }
133 
ResetRegularColor(ArkUIRuntimeCallInfo * runtimeCallInfo)134 ArkUINativeModuleValue PatternLockBridge::ResetRegularColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
135 {
136     EcmaVM* vm = runtimeCallInfo->GetVM();
137     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
138     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
139     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
140     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
141     GetArkUINodeModifiers()->getPatternLockModifier()->resetPatternLockRegularColor(nativeNode);
142     return panda::JSValueRef::Undefined(vm);
143 }
144 
SetPathColor(ArkUIRuntimeCallInfo * runtimeCallInfo)145 ArkUINativeModuleValue PatternLockBridge::SetPathColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
146 {
147     EcmaVM* vm = runtimeCallInfo->GetVM();
148     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
149     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
150     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
151     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
152     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
153     Color color;
154     RefPtr<ResourceObject> pathColorResObj;
155     auto nodeInfo = ArkTSUtils::MakeNativeNodeInfo(nativeNode);
156     if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color, pathColorResObj, nodeInfo)) {
157         GetArkUINodeModifiers()->getPatternLockModifier()->resetPatternLockPathColor(nativeNode);
158     } else {
159         auto pathColorRawPtr = AceType::RawPtr(pathColorResObj);
160         GetArkUINodeModifiers()->getPatternLockModifier()->setPatternLockPathColorRes(
161             nativeNode, color.GetValue(), pathColorRawPtr);
162     }
163     return panda::JSValueRef::Undefined(vm);
164 }
165 
ResetPathColor(ArkUIRuntimeCallInfo * runtimeCallInfo)166 ArkUINativeModuleValue PatternLockBridge::ResetPathColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
167 {
168     EcmaVM* vm = runtimeCallInfo->GetVM();
169     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
170     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
171     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
172     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
173     GetArkUINodeModifiers()->getPatternLockModifier()->resetPatternLockPathColor(nativeNode);
174     return panda::JSValueRef::Undefined(vm);
175 }
176 
SetPatternLockActiveColor(ArkUIRuntimeCallInfo * runtimeCallInfo)177 ArkUINativeModuleValue PatternLockBridge::SetPatternLockActiveColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
178 {
179     EcmaVM* vm = runtimeCallInfo->GetVM();
180     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
181     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
182     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
183     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
184     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
185     Color color;
186     RefPtr<ResourceObject> activeColorResObj;
187     auto nodeInfo = ArkTSUtils::MakeNativeNodeInfo(nativeNode);
188     if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color, activeColorResObj, nodeInfo)) {
189         GetArkUINodeModifiers()->getPatternLockModifier()->resetPatternLockActiveColor(nativeNode);
190     } else {
191         auto activeColorRawPtr = AceType::RawPtr(activeColorResObj);
192         GetArkUINodeModifiers()->getPatternLockModifier()->setPatternLockActiveColorRes(
193             nativeNode, color.GetValue(), activeColorRawPtr);
194     }
195     return panda::JSValueRef::Undefined(vm);
196 }
197 
ResetPatternLockActiveColor(ArkUIRuntimeCallInfo * runtimeCallInfo)198 ArkUINativeModuleValue PatternLockBridge::ResetPatternLockActiveColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
199 {
200     EcmaVM* vm = runtimeCallInfo->GetVM();
201     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
202     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
203     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
204     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
205     GetArkUINodeModifiers()->getPatternLockModifier()->resetPatternLockActiveColor(nativeNode);
206     return panda::JSValueRef::Undefined(vm);
207 }
208 
SetPatternLockCircleRadius(ArkUIRuntimeCallInfo * runtimeCallInfo)209 ArkUINativeModuleValue PatternLockBridge::SetPatternLockCircleRadius(ArkUIRuntimeCallInfo* runtimeCallInfo)
210 {
211     EcmaVM* vm = runtimeCallInfo->GetVM();
212     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
213     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
214     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
215     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
216     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
217     CalcDimension circleRadius;
218     RefPtr<ResourceObject> circleRadiusResObj;
219     if (ArkTSUtils::ParseJsDimensionVp(vm, secondArg, circleRadius, circleRadiusResObj) &&
220         !(circleRadius.IsNonPositive())) {
221         auto circleRadiusRawPtr = AceType::RawPtr(circleRadiusResObj);
222         GetArkUINodeModifiers()->getPatternLockModifier()->setPatternLockCircleRadiusRes(
223             nativeNode, circleRadius.Value(), static_cast<int8_t>(circleRadius.Unit()), circleRadiusRawPtr);
224     } else {
225         GetArkUINodeModifiers()->getPatternLockModifier()->resetPatternLockCircleRadius(nativeNode);
226     }
227     return panda::JSValueRef::Undefined(vm);
228 }
229 
ResetPatternLockCircleRadius(ArkUIRuntimeCallInfo * runtimeCallInfo)230 ArkUINativeModuleValue PatternLockBridge::ResetPatternLockCircleRadius(ArkUIRuntimeCallInfo* runtimeCallInfo)
231 {
232     EcmaVM* vm = runtimeCallInfo->GetVM();
233     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
234     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
235     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
236     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
237     GetArkUINodeModifiers()->getPatternLockModifier()->resetPatternLockCircleRadius(nativeNode);
238     return panda::JSValueRef::Undefined(vm);
239 }
240 
SetPatternLockSelectedColor(ArkUIRuntimeCallInfo * runtimeCallInfo)241 ArkUINativeModuleValue PatternLockBridge::SetPatternLockSelectedColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
242 {
243     EcmaVM* vm = runtimeCallInfo->GetVM();
244     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
245     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
246     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
247     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
248     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
249     Color color;
250     RefPtr<ResourceObject> selectedColorResObj;
251     auto nodeInfo = ArkTSUtils::MakeNativeNodeInfo(nativeNode);
252     if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color, selectedColorResObj, nodeInfo)) {
253         GetArkUINodeModifiers()->getPatternLockModifier()->resetPatternLockSelectedColor(nativeNode);
254     } else {
255         auto selectedColorRawPtr = AceType::RawPtr(selectedColorResObj);
256         GetArkUINodeModifiers()->getPatternLockModifier()->setPatternLockSelectedColorRes(
257             nativeNode, color.GetValue(), selectedColorRawPtr);
258     }
259     return panda::JSValueRef::Undefined(vm);
260 }
261 
ResetPatternLockSelectedColor(ArkUIRuntimeCallInfo * runtimeCallInfo)262 ArkUINativeModuleValue PatternLockBridge::ResetPatternLockSelectedColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
263 {
264     EcmaVM* vm = runtimeCallInfo->GetVM();
265     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
266     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
267     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
268     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
269     GetArkUINodeModifiers()->getPatternLockModifier()->resetPatternLockSelectedColor(nativeNode);
270     return panda::JSValueRef::Undefined(vm);
271 }
272 
SetPatternLockActivateCircleStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)273 ArkUINativeModuleValue PatternLockBridge::SetPatternLockActivateCircleStyle(ArkUIRuntimeCallInfo* runtimeCallInfo)
274 {
275     EcmaVM* vm = runtimeCallInfo->GetVM();
276     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
277     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
278     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
279     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
280     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
281     if (!secondArg->IsObject(vm)) {
282         GetArkUINodeModifiers()->getPatternLockModifier()->resetPatternLockActiveCircleColor(nativeNode);
283         GetArkUINodeModifiers()->getPatternLockModifier()->resetPatternLockActiveCircleRadius(nativeNode);
284         GetArkUINodeModifiers()->getPatternLockModifier()->resetPatternLockEnableWaveEffect(nativeNode);
285         GetArkUINodeModifiers()->getPatternLockModifier()->resetPatternLockEnableForeground(nativeNode);
286     } else {
287         auto obj = secondArg->ToObject(vm);
288         auto jsColor = obj->Get(vm, panda::StringRef::NewFromUtf8(vm, "color"));
289         auto jsRadius = obj->Get(vm, panda::StringRef::NewFromUtf8(vm, "radius"));
290         auto jsEnable = obj->Get(vm, panda::StringRef::NewFromUtf8(vm, "enableWaveEffect"));
291         auto jsEnableForeground = obj->Get(vm, panda::StringRef::NewFromUtf8(vm, "enableForeground"));
292         Color color;
293         RefPtr<ResourceObject> colorResObj;
294         auto nodeInfo = ArkTSUtils::MakeNativeNodeInfo(nativeNode);
295         if (!ArkTSUtils::ParseJsColorAlpha(vm, jsColor, color, colorResObj, nodeInfo)) {
296             GetArkUINodeModifiers()->getPatternLockModifier()->resetPatternLockActiveCircleColor(nativeNode);
297         } else {
298             auto activeCircleColorRawPtr = AceType::RawPtr(colorResObj);
299             GetArkUINodeModifiers()->getPatternLockModifier()->setPatternLockActiveCircleColorRes(
300                 nativeNode, color.GetValue(), activeCircleColorRawPtr);
301         }
302         CalcDimension circleRadius;
303         if (jsRadius->IsObject(vm) && ArkTSUtils::ParseJsLengthMetrics(vm, jsRadius, circleRadius) &&
304             !(circleRadius.IsNonPositive())) {
305             GetArkUINodeModifiers()->getPatternLockModifier()->setPatternLockActiveCircleRadius(
306                 nativeNode, circleRadius.Value(), static_cast<int8_t>(circleRadius.Unit()));
307         } else {
308             GetArkUINodeModifiers()->getPatternLockModifier()->resetPatternLockActiveCircleRadius(nativeNode);
309         }
310         uint32_t value = 1;
311         if (jsEnable->IsBoolean()) {
312             value = static_cast<uint32_t>(jsEnable->ToBoolean(vm)->Value());
313         }
314         GetArkUINodeModifiers()->getPatternLockModifier()->setPatternLockEnableWaveEffect(nativeNode, value);
315         uint32_t enableForegroundValue = 0;
316         if (jsEnableForeground->IsBoolean()) {
317             enableForegroundValue = static_cast<uint32_t>(jsEnableForeground->ToBoolean(vm)->Value());
318         }
319         GetArkUINodeModifiers()->getPatternLockModifier()->setPatternLockEnableForeground(
320             nativeNode, enableForegroundValue);
321     }
322     return panda::JSValueRef::Undefined(vm);
323 }
324 
ResetPatternLockActivateCircleStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)325 ArkUINativeModuleValue PatternLockBridge::ResetPatternLockActivateCircleStyle(ArkUIRuntimeCallInfo* runtimeCallInfo)
326 {
327     EcmaVM* vm = runtimeCallInfo->GetVM();
328     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
329     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
330     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
331     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
332     GetArkUINodeModifiers()->getPatternLockModifier()->resetPatternLockActiveCircleColor(nativeNode);
333     GetArkUINodeModifiers()->getPatternLockModifier()->resetPatternLockActiveCircleRadius(nativeNode);
334     GetArkUINodeModifiers()->getPatternLockModifier()->resetPatternLockEnableWaveEffect(nativeNode);
335     GetArkUINodeModifiers()->getPatternLockModifier()->resetPatternLockEnableForeground(nativeNode);
336     return panda::JSValueRef::Undefined(vm);
337 }
338 
SetPatternLockSkipUnselectedPoint(ArkUIRuntimeCallInfo * runtimeCallInfo)339 ArkUINativeModuleValue PatternLockBridge::SetPatternLockSkipUnselectedPoint(ArkUIRuntimeCallInfo* runtimeCallInfo)
340 {
341     EcmaVM* vm = runtimeCallInfo->GetVM();
342     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
343     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
344     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
345     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
346     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
347     uint32_t value = 0;
348     if (secondArg->IsBoolean()) {
349         value = static_cast<uint32_t>(secondArg->ToBoolean(vm)->Value());
350     }
351     GetArkUINodeModifiers()->getPatternLockModifier()->setPatternLockSkipUnselectedPoint(nativeNode, value);
352     return panda::JSValueRef::Undefined(vm);
353 }
354 
ResetPatternLockSkipUnselectedPoint(ArkUIRuntimeCallInfo * runtimeCallInfo)355 ArkUINativeModuleValue PatternLockBridge::ResetPatternLockSkipUnselectedPoint(ArkUIRuntimeCallInfo* runtimeCallInfo)
356 {
357     EcmaVM* vm = runtimeCallInfo->GetVM();
358     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
359     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
360     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
361     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
362     GetArkUINodeModifiers()->getPatternLockModifier()->resetPatternLockSkipUnselectedPoint(nativeNode);
363     return panda::JSValueRef::Undefined(vm);
364 }
365 
SetPatternLockOnPatternComplete(ArkUIRuntimeCallInfo * runtimeCallInfo)366 ArkUINativeModuleValue PatternLockBridge::SetPatternLockOnPatternComplete(ArkUIRuntimeCallInfo* runtimeCallInfo)
367 {
368     EcmaVM* vm = runtimeCallInfo->GetVM();
369     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
370     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
371     Local<JSValueRef> callbackArg = runtimeCallInfo->GetCallArgRef(1);
372     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
373     if (callbackArg->IsUndefined() || callbackArg->IsNull() || !callbackArg->IsFunction(vm)) {
374         GetArkUINodeModifiers()->getPatternLockModifier()->resetPatternLockOnPatternComplete(nativeNode);
375         return panda::JSValueRef::Undefined(vm);
376     }
377     auto frameNode = reinterpret_cast<FrameNode*>(nativeNode);
378     panda::Local<panda::FunctionRef> func = callbackArg->ToObject(vm);
379     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
380     std::function<void(const BaseEventInfo* event)> callback = [vm, frameNode, func = panda::CopyableGlobal(vm, func)](
381                                                                    const BaseEventInfo* event) {
382         panda::LocalScope pandaScope(vm);
383         panda::TryCatch trycatch(vm);
384         PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode));
385         const auto* eventInfo = TypeInfoHelper::DynamicCast<V2::PatternCompleteEvent>(event);
386         CHECK_NULL_VOID(eventInfo);
387         panda::Local<panda::JSValueRef> params[] = { ArkTSUtils::ChoosePointToJSValue(vm, eventInfo->GetInput()) };
388         func->Call(vm, func.ToLocal(), params, 1);
389     };
390     GetArkUINodeModifiers()->getPatternLockModifier()->setPatternLockOnPatternComplete(
391         nativeNode, reinterpret_cast<void*>(&callback));
392     return panda::JSValueRef::Undefined(vm);
393 }
394 
ResetPatternLockOnPatternComplete(ArkUIRuntimeCallInfo * runtimeCallInfo)395 ArkUINativeModuleValue PatternLockBridge::ResetPatternLockOnPatternComplete(ArkUIRuntimeCallInfo* runtimeCallInfo)
396 {
397     EcmaVM* vm = runtimeCallInfo->GetVM();
398     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
399     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
400     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
401     CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
402     GetArkUINodeModifiers()->getPatternLockModifier()->resetPatternLockOnPatternComplete(nativeNode);
403     return panda::JSValueRef::Undefined(vm);
404 }
405 
SetPatternLockOnDotConnect(ArkUIRuntimeCallInfo * runtimeCallInfo)406 ArkUINativeModuleValue PatternLockBridge::SetPatternLockOnDotConnect(ArkUIRuntimeCallInfo* runtimeCallInfo)
407 {
408     EcmaVM* vm = runtimeCallInfo->GetVM();
409     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
410     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
411     Local<JSValueRef> callbackArg = runtimeCallInfo->GetCallArgRef(1);
412     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
413     if (callbackArg->IsUndefined() || callbackArg->IsNull() || !callbackArg->IsFunction(vm)) {
414         GetArkUINodeModifiers()->getPatternLockModifier()->resetPatternLockOnDotConnect(nativeNode);
415         return panda::JSValueRef::Undefined(vm);
416     }
417     auto frameNode = reinterpret_cast<FrameNode*>(nativeNode);
418     panda::Local<panda::FunctionRef> func = callbackArg->ToObject(vm);
419     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
420     std::function<void(int32_t code)> callback = [vm, frameNode, func = panda::CopyableGlobal(vm, func)](int32_t code) {
421         panda::LocalScope pandaScope(vm);
422         panda::TryCatch trycatch(vm);
423         PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode));
424         panda::Local<panda::JSValueRef> params = ArkTSUtils::ToJSValueWithVM(vm, code);
425         func->Call(vm, func.ToLocal(), &params, 1);
426     };
427     GetArkUINodeModifiers()->getPatternLockModifier()->setPatternLockOnDotConnect(
428         nativeNode, reinterpret_cast<void*>(&callback));
429     return panda::JSValueRef::Undefined(vm);
430 }
431 
ResetPatternLockOnDotConnect(ArkUIRuntimeCallInfo * runtimeCallInfo)432 ArkUINativeModuleValue PatternLockBridge::ResetPatternLockOnDotConnect(ArkUIRuntimeCallInfo* runtimeCallInfo)
433 {
434     EcmaVM* vm = runtimeCallInfo->GetVM();
435     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
436     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
437     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
438     CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
439     GetArkUINodeModifiers()->getPatternLockModifier()->resetPatternLockOnDotConnect(nativeNode);
440     return panda::JSValueRef::Undefined(vm);
441 }
442 } // namespace OHOS::Ace::NG
443