• 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_blank_bridge.h"
16 
17 #include "core/interfaces/native/node/api.h"
18 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
19 namespace OHOS::Ace::NG {
SetColor(ArkUIRuntimeCallInfo * runtimeCallInfo)20 ArkUINativeModuleValue BlankBridge::SetColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
21 {
22     EcmaVM* vm = runtimeCallInfo->GetVM();
23     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
24     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
25     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
26     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
27     Color color;
28     if (ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color)) {
29         uint32_t value = color.GetValue();
30         GetArkUIInternalNodeAPI()->GetBlankModifier().SetColor(nativeNode, value);
31     } else {
32         GetArkUIInternalNodeAPI()->GetBlankModifier().ResetColor(nativeNode);
33     }
34     return panda::JSValueRef::Undefined(vm);
35 }
ResetColor(ArkUIRuntimeCallInfo * runtimeCallInfo)36 ArkUINativeModuleValue BlankBridge::ResetColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
37 {
38     EcmaVM* vm = runtimeCallInfo->GetVM();
39     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
40     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
41     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
42     GetArkUIInternalNodeAPI()->GetBlankModifier().ResetColor(nativeNode);
43     return panda::JSValueRef::Undefined(vm);
44 }
SetBlankHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)45 ArkUINativeModuleValue BlankBridge::SetBlankHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
46 {
47     EcmaVM* vm = runtimeCallInfo->GetVM();
48     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
49     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
50     Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(1);
51     void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
52     CalcDimension height;
53     std::string calcStr;
54     if (!ArkTSUtils::ParseJsDimensionVpNG(vm, valueArg, height)) {
55         GetArkUIInternalNodeAPI()->GetCommonModifier().ResetHeight(nativeNode);
56     } else {
57         if (LessNotEqual(height.Value(), 0.0)) {
58             height.SetValue(0.0);
59         }
60         if (height.Unit() == DimensionUnit::CALC) {
61             GetArkUIInternalNodeAPI()->GetCommonModifier().SetHeight(
62                 nativeNode, height.Value(), static_cast<int32_t>(height.Unit()), height.CalcValue().c_str());
63         } else {
64             GetArkUIInternalNodeAPI()->GetCommonModifier().SetHeight(
65                 nativeNode, height.Value(), static_cast<int32_t>(height.Unit()), calcStr.c_str());
66         }
67     }
68     if (!ArkTSUtils::ParseJsDimensionVp(vm, valueArg, height)) {
69         return panda::JSValueRef::Undefined(vm);
70     }
71     GetArkUIInternalNodeAPI()->GetBlankModifier().SetBlankHeight(
72         nativeNode, height.Value(), static_cast<int32_t>(height.Unit()));
73     return panda::JSValueRef::Undefined(vm);
74 }
ResetBlankHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)75 ArkUINativeModuleValue BlankBridge::ResetBlankHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
76 {
77     EcmaVM* vm = runtimeCallInfo->GetVM();
78     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
79     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
80     void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
81     GetArkUIInternalNodeAPI()->GetBlankModifier().ResetBlankHeight(nativeNode);
82     return panda::JSValueRef::Undefined(vm);
83 }
84 }