• 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_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     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
29     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
30     Color color;
31     if (!ArkTSUtils::ParseJsColorAlpha(vm, qrColorArg, color)) {
32         GetArkUINodeModifiers()->getQRCodeModifier()->resetQRColor(nativeNode);
33     } else {
34         GetArkUINodeModifiers()->getQRCodeModifier()->setQRColor(nativeNode, color.GetValue());
35     }
36     return panda::JSValueRef::Undefined(vm);
37 }
38 
ResetQRColor(ArkUIRuntimeCallInfo * runtimeCallInfo)39 ArkUINativeModuleValue QRCodeBridge::ResetQRColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
40 {
41     EcmaVM *vm = runtimeCallInfo->GetVM();
42     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
43     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
44     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
45     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
46     GetArkUINodeModifiers()->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     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
57     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
58     Color color;
59     if (!ArkTSUtils::ParseJsColorAlpha(vm, qrBackgroundColor, color)) {
60         GetArkUINodeModifiers()->getQRCodeModifier()->resetQRBackgroundColor(nativeNode);
61     } else {
62         GetArkUINodeModifiers()->getQRCodeModifier()->setQRBackgroundColor(nativeNode, color.GetValue());
63     }
64     return panda::JSValueRef::Undefined(vm);
65 }
66 
ResetQRBackgroundColor(ArkUIRuntimeCallInfo * runtimeCallInfo)67 ArkUINativeModuleValue QRCodeBridge::ResetQRBackgroundColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
68 {
69     EcmaVM *vm = runtimeCallInfo->GetVM();
70     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
71     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
72     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
73     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
74     GetArkUINodeModifiers()->getQRCodeModifier()->resetQRBackgroundColor(nativeNode);
75     return panda::JSValueRef::Undefined(vm);
76 }
SetContentOpacity(ArkUIRuntimeCallInfo * runtimeCallInfo)77 ArkUINativeModuleValue QRCodeBridge::SetContentOpacity(ArkUIRuntimeCallInfo *runtimeCallInfo)
78 {
79     EcmaVM *vm = runtimeCallInfo->GetVM();
80     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
81     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
82     Local<JSValueRef> qrContentOpacity = runtimeCallInfo->GetCallArgRef(1);
83     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
84     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
85     double opacity;
86     if (!ArkTSUtils::ParseJsDouble(vm, qrContentOpacity, opacity)) {
87         GetArkUINodeModifiers()->getQRCodeModifier()->resetContentOpacity(nativeNode);
88     } else {
89         GetArkUINodeModifiers()->getQRCodeModifier()->setContentOpacity(nativeNode,
90             static_cast<ArkUI_Float32>(opacity));
91     }
92     return panda::JSValueRef::Undefined(vm);
93 }
94 
ResetContentOpacity(ArkUIRuntimeCallInfo * runtimeCallInfo)95 ArkUINativeModuleValue QRCodeBridge::ResetContentOpacity(ArkUIRuntimeCallInfo *runtimeCallInfo)
96 {
97     EcmaVM *vm = runtimeCallInfo->GetVM();
98     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
99     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
100     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
101     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
102     GetArkUINodeModifiers()->getQRCodeModifier()->resetContentOpacity(nativeNode);
103     return panda::JSValueRef::Undefined(vm);
104 }
105 
SetQRValue(ArkUIRuntimeCallInfo * runtimeCallInfo)106 ArkUINativeModuleValue QRCodeBridge::SetQRValue(ArkUIRuntimeCallInfo* runtimeCallInfo)
107 {
108     EcmaVM* vm = runtimeCallInfo->GetVM();
109     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
110     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
111     Local<JSValueRef> value = runtimeCallInfo->GetCallArgRef(1);
112     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
113     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
114     GetArkUINodeModifiers()->getQRCodeModifier()->setQRValue(nativeNode, value->ToString(vm)->ToString(vm).c_str());
115     return panda::JSValueRef::Undefined(vm);
116 }
117 } // namespace OHOS::Ace::NG
118