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_qrcode_bridge.h"
16
17 #include "core/interfaces/native/node/api.h"
18 #include "bridge/declarative_frontend/jsview/js_utils.h"
19 #include "core/components/common/properties/text_style.h"
20 #include "frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
21
22 namespace OHOS::Ace::NG {
23
SetQRColor(ArkUIRuntimeCallInfo * runtimeCallInfo)24 ArkUINativeModuleValue QRCodeBridge::SetQRColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
25 {
26 EcmaVM *vm = runtimeCallInfo->GetVM();
27 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
28 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
29 Local<JSValueRef> qrColorArg = runtimeCallInfo->GetCallArgRef(1);
30 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
31 Color color;
32 if (!ArkTSUtils::ParseJsColorAlpha(vm, qrColorArg, color)) {
33 GetArkUIInternalNodeAPI()->GetQRCodeModifier().ResetQRColor(nativeNode);
34 } else {
35 GetArkUIInternalNodeAPI()->GetQRCodeModifier().SetQRColor(nativeNode, color.GetValue());
36 }
37 return panda::JSValueRef::Undefined(vm);
38 }
39
ResetQRColor(ArkUIRuntimeCallInfo * runtimeCallInfo)40 ArkUINativeModuleValue QRCodeBridge::ResetQRColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
41 {
42 EcmaVM *vm = runtimeCallInfo->GetVM();
43 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
44 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
45 void *nativeNode = firstArg->ToNativePointer(vm)->Value();
46 GetArkUIInternalNodeAPI()->GetQRCodeModifier().ResetQRColor(nativeNode);
47 return panda::JSValueRef::Undefined(vm);
48 }
SetQRBackgroundColor(ArkUIRuntimeCallInfo * runtimeCallInfo)49 ArkUINativeModuleValue QRCodeBridge::SetQRBackgroundColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
50 {
51 EcmaVM *vm = runtimeCallInfo->GetVM();
52 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
53 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
54 Local<JSValueRef> qrBackgroundColor = runtimeCallInfo->GetCallArgRef(1);
55
56 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
57 Color color;
58 if (!ArkTSUtils::ParseJsColorAlpha(vm, qrBackgroundColor, color)) {
59 GetArkUIInternalNodeAPI()->GetQRCodeModifier().ResetQRBackgroundColor(nativeNode);
60 } else {
61 GetArkUIInternalNodeAPI()->GetQRCodeModifier().SetQRBackgroundColor(nativeNode, color.GetValue());
62 }
63 return panda::JSValueRef::Undefined(vm);
64 }
65
ResetQRBackgroundColor(ArkUIRuntimeCallInfo * runtimeCallInfo)66 ArkUINativeModuleValue QRCodeBridge::ResetQRBackgroundColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
67 {
68 EcmaVM *vm = runtimeCallInfo->GetVM();
69 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
70 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
71 void *nativeNode = firstArg->ToNativePointer(vm)->Value();
72 GetArkUIInternalNodeAPI()->GetQRCodeModifier().ResetQRBackgroundColor(nativeNode);
73 return panda::JSValueRef::Undefined(vm);
74 }
SetContentOpacity(ArkUIRuntimeCallInfo * runtimeCallInfo)75 ArkUINativeModuleValue QRCodeBridge::SetContentOpacity(ArkUIRuntimeCallInfo *runtimeCallInfo)
76 {
77 EcmaVM *vm = runtimeCallInfo->GetVM();
78 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
79 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
80 Local<JSValueRef> qrContentOpacity = runtimeCallInfo->GetCallArgRef(1);
81 void *nativeNode = firstArg->ToNativePointer(vm)->Value();
82 double opacity;
83 if (!ArkTSUtils::ParseJsDouble(vm, qrContentOpacity, opacity)) {
84 GetArkUIInternalNodeAPI()->GetQRCodeModifier().ResetContentOpacity(nativeNode);
85 } else {
86 GetArkUIInternalNodeAPI()->GetQRCodeModifier().SetContentOpacity(nativeNode, opacity);
87 }
88 return panda::JSValueRef::Undefined(vm);
89 }
90
ResetContentOpacity(ArkUIRuntimeCallInfo * runtimeCallInfo)91 ArkUINativeModuleValue QRCodeBridge::ResetContentOpacity(ArkUIRuntimeCallInfo *runtimeCallInfo)
92 {
93 EcmaVM *vm = runtimeCallInfo->GetVM();
94 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
95 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
96 void *nativeNode = firstArg->ToNativePointer(vm)->Value();
97 GetArkUIInternalNodeAPI()->GetQRCodeModifier().ResetContentOpacity(nativeNode);
98 return panda::JSValueRef::Undefined(vm);
99 }
100
101 } // namespace OHOS::Ace::NG
102