• 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_loading_progress_bridge.h"
16 
17 #include "core/interfaces/native/node/api.h"
18 #include "frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
19 using namespace OHOS::Ace::Framework;
20 
21 namespace OHOS::Ace::NG {
22 namespace {
23 constexpr int NUM_0 = 0;
24 constexpr int NUM_1 = 1;
25 } // namespace
SetColor(ArkUIRuntimeCallInfo * runtimeCallInfo)26 ArkUINativeModuleValue LoadingProgressBridge::SetColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
27 {
28     EcmaVM* vm = runtimeCallInfo->GetVM();
29     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
30     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
31     Local<JSValueRef> colorArg = runtimeCallInfo->GetCallArgRef(NUM_1);
32     void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
33     Color color;
34     if (!ArkTSUtils::ParseJsColorAlpha(vm, colorArg, color)) {
35         GetArkUIInternalNodeAPI()->GetLoadingProgressModifier().ResetColor(nativeNode);
36     } else {
37         GetArkUIInternalNodeAPI()->GetLoadingProgressModifier().SetColor(nativeNode, color.GetValue());
38     }
39     return panda::JSValueRef::Undefined(vm);
40 }
41 
ResetColor(ArkUIRuntimeCallInfo * runtimeCallInfo)42 ArkUINativeModuleValue LoadingProgressBridge::ResetColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
43 {
44     EcmaVM* vm = runtimeCallInfo->GetVM();
45     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
46     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
47     void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
48     GetArkUIInternalNodeAPI()->GetLoadingProgressModifier().ResetColor(nativeNode);
49     return panda::JSValueRef::Undefined(vm);
50 }
51 
SetEnableLoading(ArkUIRuntimeCallInfo * runtimeCallInfo)52 ArkUINativeModuleValue LoadingProgressBridge::SetEnableLoading(ArkUIRuntimeCallInfo* runtimeCallInfo)
53 {
54     EcmaVM* vm = runtimeCallInfo->GetVM();
55     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
56     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
57     Local<JSValueRef> enableLoadingArg = runtimeCallInfo->GetCallArgRef(NUM_1);
58     void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
59     bool boolValue = enableLoadingArg->ToBoolean(vm)->Value();
60     GetArkUIInternalNodeAPI()->GetLoadingProgressModifier().SetEnableLoading(nativeNode, boolValue);
61     return panda::JSValueRef::Undefined(vm);
62 }
63 
ResetEnableLoading(ArkUIRuntimeCallInfo * runtimeCallInfo)64 ArkUINativeModuleValue LoadingProgressBridge::ResetEnableLoading(ArkUIRuntimeCallInfo* runtimeCallInfo)
65 {
66     EcmaVM* vm = runtimeCallInfo->GetVM();
67     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
68     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
69     void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
70     GetArkUIInternalNodeAPI()->GetLoadingProgressModifier().ResetEnableLoading(nativeNode);
71     return panda::JSValueRef::Undefined(vm);
72 }
73 
ParseJsColorStrategy(const EcmaVM * vm,const Local<JSValueRef> & jsValue,ForegroundColorStrategy & strategy)74 bool ParseJsColorStrategy(const EcmaVM* vm, const Local<JSValueRef>& jsValue, ForegroundColorStrategy& strategy)
75 {
76     if (jsValue->IsString()) {
77         std::string colorStr = jsValue->ToString(vm)->ToString();
78         if (colorStr.compare("invert") == 0) {
79             strategy = ForegroundColorStrategy::INVERT;
80             return true;
81         }
82     }
83     return false;
84 }
85 
SetForegroundColor(ArkUIRuntimeCallInfo * runtimeCallInfo)86 ArkUINativeModuleValue LoadingProgressBridge::SetForegroundColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
87 {
88     EcmaVM *vm = runtimeCallInfo->GetVM();
89     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
90     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
91     auto colorArg = runtimeCallInfo->GetCallArgRef(1);
92     auto nativeNode = nodeArg->ToNativePointer(vm)->Value();
93 
94     ForegroundColorStrategy strategy;
95     if (ParseJsColorStrategy(vm, colorArg, strategy)) {
96         auto strategyInt = static_cast<uint32_t>(ForegroundColorStrategy::INVERT);
97         GetArkUIInternalNodeAPI()->GetCommonModifier().SetForegroundColor(nativeNode, false, strategyInt);
98         return panda::JSValueRef::Undefined(vm);
99     }
100     Color foregroundColor;
101     if (!ArkTSUtils::ParseJsColorAlpha(vm, colorArg, foregroundColor)) {
102         GetArkUIInternalNodeAPI()->GetLoadingProgressModifier().ResetForegroundColor(nativeNode);
103     } else {
104         GetArkUIInternalNodeAPI()->GetLoadingProgressModifier().SetForegroundColor(
105             nativeNode, foregroundColor.GetValue());
106     }
107     return panda::JSValueRef::Undefined(vm);
108 }
109 
ResetForegroundColor(ArkUIRuntimeCallInfo * runtimeCallInfo)110 ArkUINativeModuleValue LoadingProgressBridge::ResetForegroundColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
111 {
112     EcmaVM* vm = runtimeCallInfo->GetVM();
113     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
114     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
115     void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
116     GetArkUIInternalNodeAPI()->GetLoadingProgressModifier().ResetForegroundColor(nativeNode);
117     return panda::JSValueRef::Undefined(vm);
118 }
119 } // namespace OHOS::Ace::NG
120