• 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_plugin_bridge.h"
16 
17 #include "core/interfaces/native/node/api.h"
18 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
19 
20 namespace OHOS::Ace::NG {
21 
SetSize(ArkUIRuntimeCallInfo * runtimeCallInfo)22 ArkUINativeModuleValue PluginBridge::SetSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
23 {
24     EcmaVM* vm = runtimeCallInfo->GetVM();
25     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
26     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);   // 0: index of parameter frameNode
27     Local<JSValueRef> widthArg = runtimeCallInfo->GetCallArgRef(1);  // 1: index of parameter width
28     Local<JSValueRef> heightArg = runtimeCallInfo->GetCallArgRef(2); // 2: index of parameter height
29     void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
30 
31     CalcDimension width = 0.0_vp;
32     CalcDimension height = 0.0_vp;
33     if (!(ArkTSUtils::ParseJsDimensionVp(vm, widthArg, width, false)) ||
34         !(ArkTSUtils::ParseJsDimensionVp(vm, heightArg, height, false))) {
35         GetArkUIInternalNodeAPI()->GetPluginModifier().ResetPluginSize(nativeNode);
36         return panda::JSValueRef::Undefined(vm);
37     }
38     if (LessNotEqual(width.Value(), 0.0)) {
39         width.SetValue(0.0);
40     }
41     if (LessNotEqual(height.Value(), 0.0)) {
42         height.SetValue(0.0);
43     }
44 
45     GetArkUIInternalNodeAPI()->GetPluginModifier().SetPluginSize(nativeNode, width.Value(), height.Value(),
46         static_cast<int32_t>(width.Unit()), static_cast<int32_t>(height.Unit()));
47     return panda::JSValueRef::Undefined(vm);
48 }
49 
SetWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)50 ArkUINativeModuleValue PluginBridge::SetWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
51 {
52     EcmaVM* vm = runtimeCallInfo->GetVM();
53     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
54     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
55     Local<JSValueRef> widthArg = runtimeCallInfo->GetCallArgRef(1);
56     void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
57 
58     CalcDimension width = 0.0_vp;
59     if (!ArkTSUtils::ParseJsDimensionVp(vm, widthArg, width)) {
60         GetArkUIInternalNodeAPI()->GetPluginModifier().ResetPluginWidth(nativeNode);
61     }
62     if (LessNotEqual(width.Value(), 0.0)) {
63         width.SetValue(0.0);
64     }
65 
66     GetArkUIInternalNodeAPI()->GetPluginModifier().SetPluginWidth(
67         nativeNode, width.Value(), static_cast<int32_t>(width.Unit()));
68     return panda::JSValueRef::Undefined(vm);
69 }
70 
SetHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)71 ArkUINativeModuleValue PluginBridge::SetHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
72 {
73     EcmaVM* vm = runtimeCallInfo->GetVM();
74     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
75     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
76     Local<JSValueRef> heightArg = runtimeCallInfo->GetCallArgRef(1);
77     void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
78 
79     CalcDimension height = 0.0_vp;
80     if (!ArkTSUtils::ParseJsDimensionVp(vm, heightArg, height)) {
81         GetArkUIInternalNodeAPI()->GetPluginModifier().ResetPluginHeight(nativeNode);
82     }
83     if (LessNotEqual(height.Value(), 0.0)) {
84         height.SetValue(0.0);
85     }
86 
87     GetArkUIInternalNodeAPI()->GetPluginModifier().SetPluginHeight(
88         nativeNode, height.Value(), static_cast<int32_t>(height.Unit()));
89     return panda::JSValueRef::Undefined(vm);
90 }
91 
ResetSize(ArkUIRuntimeCallInfo * runtimeCallInfo)92 ArkUINativeModuleValue PluginBridge::ResetSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
93 {
94     EcmaVM* vm = runtimeCallInfo->GetVM();
95     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
96     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
97     void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
98     GetArkUIInternalNodeAPI()->GetPluginModifier().ResetPluginSize(nativeNode);
99     return panda::JSValueRef::Undefined(vm);
100 }
101 
ResetWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)102 ArkUINativeModuleValue PluginBridge::ResetWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
103 {
104     EcmaVM* vm = runtimeCallInfo->GetVM();
105     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
106     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
107     void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
108     GetArkUIInternalNodeAPI()->GetPluginModifier().ResetPluginWidth(nativeNode);
109     return panda::JSValueRef::Undefined(vm);
110 }
111 
ResetHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)112 ArkUINativeModuleValue PluginBridge::ResetHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
113 {
114     EcmaVM* vm = runtimeCallInfo->GetVM();
115     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
116     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
117     void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
118     GetArkUIInternalNodeAPI()->GetPluginModifier().ResetPluginHeight(nativeNode);
119     return panda::JSValueRef::Undefined(vm);
120 }
121 } // namespace OHOS::Ace::NG