• 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     RefPtr<ResourceObject> colorResObj;
32     auto nodeInfo = ArkTSUtils::MakeNativeNodeInfo(nativeNode);
33     if (!ArkTSUtils::ParseJsColorAlpha(vm, qrColorArg, color, colorResObj, nodeInfo)) {
34         GetArkUINodeModifiers()->getQRCodeModifier()->resetQRColor(nativeNode);
35     } else {
36         auto colorRawPtr = AceType::RawPtr(colorResObj);
37         GetArkUINodeModifiers()->getQRCodeModifier()->setQRColorPtr(nativeNode, color.GetValue(), colorRawPtr);
38     }
39     return panda::JSValueRef::Undefined(vm);
40 }
41 
ResetQRColor(ArkUIRuntimeCallInfo * runtimeCallInfo)42 ArkUINativeModuleValue QRCodeBridge::ResetQRColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
43 {
44     EcmaVM *vm = runtimeCallInfo->GetVM();
45     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
46     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
47     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
48     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
49     GetArkUINodeModifiers()->getQRCodeModifier()->resetQRColor(nativeNode);
50     return panda::JSValueRef::Undefined(vm);
51 }
SetQRBackgroundColor(ArkUIRuntimeCallInfo * runtimeCallInfo)52 ArkUINativeModuleValue QRCodeBridge::SetQRBackgroundColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
53 {
54     EcmaVM *vm = runtimeCallInfo->GetVM();
55     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
56     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
57     Local<JSValueRef> qrBackgroundColor = runtimeCallInfo->GetCallArgRef(1);
58 
59     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
60     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
61     Color color;
62     RefPtr<ResourceObject> colorResObj;
63     auto nodeInfo = ArkTSUtils::MakeNativeNodeInfo(nativeNode);
64     if (!ArkTSUtils::ParseJsColorAlpha(vm, qrBackgroundColor, color, colorResObj, nodeInfo)) {
65         GetArkUINodeModifiers()->getQRCodeModifier()->resetQRBackgroundColor(nativeNode);
66     } else {
67         auto colorRawPtr = AceType::RawPtr(colorResObj);
68         GetArkUINodeModifiers()->getQRCodeModifier()->setQRBackgroundColorPtr(
69             nativeNode, color.GetValue(), colorRawPtr);
70     }
71     return panda::JSValueRef::Undefined(vm);
72 }
73 
ResetQRBackgroundColor(ArkUIRuntimeCallInfo * runtimeCallInfo)74 ArkUINativeModuleValue QRCodeBridge::ResetQRBackgroundColor(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()->getQRCodeModifier()->resetQRBackgroundColor(nativeNode);
82     return panda::JSValueRef::Undefined(vm);
83 }
SetContentOpacity(ArkUIRuntimeCallInfo * runtimeCallInfo)84 ArkUINativeModuleValue QRCodeBridge::SetContentOpacity(ArkUIRuntimeCallInfo *runtimeCallInfo)
85 {
86     EcmaVM *vm = runtimeCallInfo->GetVM();
87     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
88     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
89     Local<JSValueRef> qrContentOpacity = runtimeCallInfo->GetCallArgRef(1);
90     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
91     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
92     double opacity;
93     RefPtr<ResourceObject> opacityResObj;
94     if (!ArkTSUtils::ParseJsDouble(vm, qrContentOpacity, opacity, opacityResObj)) {
95         GetArkUINodeModifiers()->getQRCodeModifier()->resetContentOpacity(nativeNode);
96     } else {
97         auto opacityRawPtr = AceType::RawPtr(opacityResObj);
98         GetArkUINodeModifiers()->getQRCodeModifier()->setContentOpacityPtr(
99             nativeNode, static_cast<ArkUI_Float32>(opacity), opacityRawPtr);
100     }
101     return panda::JSValueRef::Undefined(vm);
102 }
103 
ResetContentOpacity(ArkUIRuntimeCallInfo * runtimeCallInfo)104 ArkUINativeModuleValue QRCodeBridge::ResetContentOpacity(ArkUIRuntimeCallInfo *runtimeCallInfo)
105 {
106     EcmaVM *vm = runtimeCallInfo->GetVM();
107     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
108     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
109     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
110     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
111     GetArkUINodeModifiers()->getQRCodeModifier()->resetContentOpacity(nativeNode);
112     return panda::JSValueRef::Undefined(vm);
113 }
114 
SetQRValue(ArkUIRuntimeCallInfo * runtimeCallInfo)115 ArkUINativeModuleValue QRCodeBridge::SetQRValue(ArkUIRuntimeCallInfo* runtimeCallInfo)
116 {
117     EcmaVM* vm = runtimeCallInfo->GetVM();
118     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
119     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
120     Local<JSValueRef> value = runtimeCallInfo->GetCallArgRef(1);
121     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
122     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
123     GetArkUINodeModifiers()->getQRCodeModifier()->setQRValue(nativeNode, value->ToString(vm)->ToString(vm).c_str());
124     return panda::JSValueRef::Undefined(vm);
125 }
126 } // namespace OHOS::Ace::NG
127