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