• 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_panel_bridge.h"
16 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
17 
18 namespace OHOS::Ace::NG {
SetPanelBackgroundMask(ArkUIRuntimeCallInfo * runtimeCallInfo)19 ArkUINativeModuleValue PanelBridge::SetPanelBackgroundMask(ArkUIRuntimeCallInfo* runtimeCallInfo)
20 {
21     EcmaVM* vm = runtimeCallInfo->GetVM();
22     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
23     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
24     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
25     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
26 
27     Color color;
28     if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color)) {
29         GetArkUINodeModifiers()->getPanelModifier()->resetPanelBackgroundMask(nativeNode);
30     } else {
31         GetArkUINodeModifiers()->getPanelModifier()->setPanelBackgroundMask(nativeNode, color.GetValue());
32     }
33     return panda::JSValueRef::Undefined(vm);
34 }
35 
ResetPanelBackgroundMask(ArkUIRuntimeCallInfo * runtimeCallInfo)36 ArkUINativeModuleValue PanelBridge::ResetPanelBackgroundMask(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     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
42     GetArkUINodeModifiers()->getPanelModifier()->resetPanelBackgroundMask(nativeNode);
43     return panda::JSValueRef::Undefined(vm);
44 }
45 
SetPanelMode(ArkUIRuntimeCallInfo * runtimeCallInfo)46 ArkUINativeModuleValue PanelBridge::SetPanelMode(ArkUIRuntimeCallInfo* runtimeCallInfo)
47 {
48     EcmaVM* vm = runtimeCallInfo->GetVM();
49     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
50     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
51     Local<JSValueRef> modeArg = runtimeCallInfo->GetCallArgRef(1);
52     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
53     if (modeArg->IsNumber()) {
54         int32_t mode = modeArg->Int32Value(vm);
55         GetArkUINodeModifiers()->getPanelModifier()->setPanelMode(nativeNode, mode);
56     } else {
57         GetArkUINodeModifiers()->getPanelModifier()->resetPanelMode(nativeNode);
58     }
59     return panda::JSValueRef::Undefined(vm);
60 }
61 
ResetPanelMode(ArkUIRuntimeCallInfo * runtimeCallInfo)62 ArkUINativeModuleValue PanelBridge::ResetPanelMode(ArkUIRuntimeCallInfo* runtimeCallInfo)
63 {
64     EcmaVM* vm = runtimeCallInfo->GetVM();
65     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
66     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
67     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
68     GetArkUINodeModifiers()->getPanelModifier()->resetPanelMode(nativeNode);
69     return panda::JSValueRef::Undefined(vm);
70 }
71 
SetPanelType(ArkUIRuntimeCallInfo * runtimeCallInfo)72 ArkUINativeModuleValue PanelBridge::SetPanelType(ArkUIRuntimeCallInfo* runtimeCallInfo)
73 {
74     EcmaVM* vm = runtimeCallInfo->GetVM();
75     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
76     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
77     Local<JSValueRef> typeArg = runtimeCallInfo->GetCallArgRef(1);
78     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
79     if (typeArg->IsNumber()) {
80         int32_t type = typeArg->Int32Value(vm);
81         GetArkUINodeModifiers()->getPanelModifier()->setPanelType(nativeNode, type);
82     } else {
83         GetArkUINodeModifiers()->getPanelModifier()->resetPanelType(nativeNode);
84     }
85     return panda::JSValueRef::Undefined(vm);
86 }
87 
ResetPanelType(ArkUIRuntimeCallInfo * runtimeCallInfo)88 ArkUINativeModuleValue PanelBridge::ResetPanelType(ArkUIRuntimeCallInfo* runtimeCallInfo)
89 {
90     EcmaVM* vm = runtimeCallInfo->GetVM();
91     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
92     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
93     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
94     GetArkUINodeModifiers()->getPanelModifier()->resetPanelType(nativeNode);
95     return panda::JSValueRef::Undefined(vm);
96 }
97 
ResetPanelFullHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)98 ArkUINativeModuleValue PanelBridge::ResetPanelFullHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
99 {
100     EcmaVM* vm = runtimeCallInfo->GetVM();
101     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
102     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
103     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
104     GetArkUINodeModifiers()->getPanelModifier()->resetPanelFullHeight(nativeNode);
105     return panda::JSValueRef::Undefined(vm);
106 }
107 
SetPanelFullHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)108 ArkUINativeModuleValue PanelBridge::SetPanelFullHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
109 {
110     EcmaVM* vm = runtimeCallInfo->GetVM();
111     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
112     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
113     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
114     Local<JSValueRef> jsValue = runtimeCallInfo->GetCallArgRef(1);
115     CalcDimension height;
116 
117     if (jsValue->IsUndefined() || !ArkTSUtils::ParseJsDimensionVpNG(vm, jsValue, height, true)) {
118         GetArkUINodeModifiers()->getPanelModifier()->resetPanelFullHeight(nativeNode);
119     } else {
120         if (LessNotEqual(height.Value(), 0.0)) {
121             height.SetValue(0.0);
122         }
123         GetArkUINodeModifiers()->getPanelModifier()->setPanelFullHeight(
124             nativeNode, height.Value(), static_cast<int>(height.Unit()));
125     }
126     return panda::JSValueRef::Undefined(vm);
127 }
128 
ResetPanelHalfHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)129 ArkUINativeModuleValue PanelBridge::ResetPanelHalfHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
130 {
131     EcmaVM* vm = runtimeCallInfo->GetVM();
132     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
133     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
134     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
135     GetArkUINodeModifiers()->getPanelModifier()->resetPanelHalfHeight(nativeNode);
136     return panda::JSValueRef::Undefined(vm);
137 }
138 
SetPanelHalfHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)139 ArkUINativeModuleValue PanelBridge::SetPanelHalfHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
140 {
141     EcmaVM* vm = runtimeCallInfo->GetVM();
142     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
143     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
144     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
145     Local<JSValueRef> jsValue = runtimeCallInfo->GetCallArgRef(1);
146     CalcDimension height;
147 
148     if (jsValue->IsUndefined() || !ArkTSUtils::ParseJsDimensionVpNG(vm, jsValue, height, true)) {
149         GetArkUINodeModifiers()->getPanelModifier()->resetPanelHalfHeight(nativeNode);
150     } else {
151         if (LessNotEqual(height.Value(), 0.0)) {
152             height.SetValue(0.0);
153         }
154         GetArkUINodeModifiers()->getPanelModifier()->setPanelHalfHeight(
155             nativeNode, height.Value(), static_cast<int>(height.Unit()));
156     }
157     return panda::JSValueRef::Undefined(vm);
158 }
159 
ResetPanelMiniHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)160 ArkUINativeModuleValue PanelBridge::ResetPanelMiniHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
161 {
162     EcmaVM* vm = runtimeCallInfo->GetVM();
163     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
164     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
165     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
166     GetArkUINodeModifiers()->getPanelModifier()->resetPanelMiniHeight(nativeNode);
167     return panda::JSValueRef::Undefined(vm);
168 }
169 
SetPanelMiniHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)170 ArkUINativeModuleValue PanelBridge::SetPanelMiniHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
171 {
172     EcmaVM* vm = runtimeCallInfo->GetVM();
173     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
174     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
175     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
176     Local<JSValueRef> jsValue = runtimeCallInfo->GetCallArgRef(1);
177     CalcDimension height;
178 
179     if (jsValue->IsUndefined() || !ArkTSUtils::ParseJsDimensionVpNG(vm, jsValue, height, true)) {
180         GetArkUINodeModifiers()->getPanelModifier()->resetPanelMiniHeight(nativeNode);
181     } else {
182         if (LessNotEqual(height.Value(), 0.0)) {
183             height.SetValue(0.0);
184         }
185         GetArkUINodeModifiers()->getPanelModifier()->setPanelMiniHeight(
186             nativeNode, height.Value(), static_cast<int>(height.Unit()));
187     }
188     return panda::JSValueRef::Undefined(vm);
189 }
190 
SetPanelCustomHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)191 ArkUINativeModuleValue PanelBridge::SetPanelCustomHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
192 {
193     EcmaVM* vm = runtimeCallInfo->GetVM();
194     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
195     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
196     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
197     Local<JSValueRef> jsValue = runtimeCallInfo->GetCallArgRef(1);
198     CalcDimension customHeight;
199 
200     if (jsValue->IsUndefined()) {
201         GetArkUINodeModifiers()->getPanelModifier()->resetPanelCustomHeight(nativeNode);
202         return panda::JSValueRef::Undefined(vm);
203     }
204     if (jsValue->IsString(vm) && jsValue->ToString(vm)->ToString(vm).find("wrapContent") != std::string::npos) {
205         GetArkUINodeModifiers()->getPanelModifier()->setPanelCustomHeightByString(
206             nativeNode, jsValue->ToString(vm)->ToString(vm).c_str());
207         return panda::JSValueRef::Undefined(vm);
208     } else if (!ArkTSUtils::ParseJsDimensionVp(vm, jsValue, customHeight)) {
209         customHeight = Dimension(0.0);
210     }
211     GetArkUINodeModifiers()->getPanelModifier()->setPanelCustomHeight(
212         nativeNode, customHeight.Value(), static_cast<int>(customHeight.Unit()));
213 
214     return panda::JSValueRef::Undefined(vm);
215 }
216 
ResetPanelCustomHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)217 ArkUINativeModuleValue PanelBridge::ResetPanelCustomHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
218 {
219     EcmaVM* vm = runtimeCallInfo->GetVM();
220     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
221     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
222     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
223     GetArkUINodeModifiers()->getPanelModifier()->resetPanelCustomHeight(nativeNode);
224     return panda::JSValueRef::Undefined(vm);
225 }
226 
SetShowCloseIcon(ArkUIRuntimeCallInfo * runtimeCallInfo)227 ArkUINativeModuleValue PanelBridge::SetShowCloseIcon(ArkUIRuntimeCallInfo* runtimeCallInfo)
228 {
229     EcmaVM* vm = runtimeCallInfo->GetVM();
230     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
231     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
232     Local<JSValueRef> showCloseArg = runtimeCallInfo->GetCallArgRef(1);
233     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
234     if (showCloseArg->IsNull()) {
235         GetArkUINodeModifiers()->getPanelModifier()->resetShowCloseIcon(nativeNode);
236         return panda::JSValueRef::Undefined(vm);
237     }
238     bool boolValue = false;
239     if (showCloseArg->IsBoolean()) {
240         boolValue = showCloseArg->ToBoolean(vm)->Value();
241     }
242     GetArkUINodeModifiers()->getPanelModifier()->setShowCloseIcon(nativeNode, boolValue);
243     return panda::JSValueRef::Undefined(vm);
244 }
245 
ResetShowCloseIcon(ArkUIRuntimeCallInfo * runtimeCallInfo)246 ArkUINativeModuleValue PanelBridge::ResetShowCloseIcon(ArkUIRuntimeCallInfo* runtimeCallInfo)
247 {
248     EcmaVM* vm = runtimeCallInfo->GetVM();
249     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
250     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
251     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
252     GetArkUINodeModifiers()->getPanelModifier()->resetShowCloseIcon(nativeNode);
253     return panda::JSValueRef::Undefined(vm);
254 }
255 
SetDragBar(ArkUIRuntimeCallInfo * runtimeCallInfo)256 ArkUINativeModuleValue PanelBridge::SetDragBar(ArkUIRuntimeCallInfo* runtimeCallInfo)
257 {
258     EcmaVM* vm = runtimeCallInfo->GetVM();
259     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
260     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
261     Local<JSValueRef> dragBarArg = runtimeCallInfo->GetCallArgRef(1);
262     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
263     if (dragBarArg->IsNull()) {
264         GetArkUINodeModifiers()->getPanelModifier()->resetDragBar(nativeNode);
265         return panda::JSValueRef::Undefined(vm);
266     }
267     bool boolValue = true;
268     if (dragBarArg->IsBoolean()) {
269         boolValue = dragBarArg->ToBoolean(vm)->Value();
270     }
271     GetArkUINodeModifiers()->getPanelModifier()->setDragBar(nativeNode, boolValue);
272     return panda::JSValueRef::Undefined(vm);
273 }
274 
ResetDragBar(ArkUIRuntimeCallInfo * runtimeCallInfo)275 ArkUINativeModuleValue PanelBridge::ResetDragBar(ArkUIRuntimeCallInfo* runtimeCallInfo)
276 {
277     EcmaVM* vm = runtimeCallInfo->GetVM();
278     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
279     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
280     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
281     GetArkUINodeModifiers()->getPanelModifier()->resetDragBar(nativeNode);
282     return panda::JSValueRef::Undefined(vm);
283 }
284 
SetShow(ArkUIRuntimeCallInfo * runtimeCallInfo)285 ArkUINativeModuleValue PanelBridge::SetShow(ArkUIRuntimeCallInfo* runtimeCallInfo)
286 {
287     EcmaVM* vm = runtimeCallInfo->GetVM();
288     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
289     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
290     Local<JSValueRef> showArg = runtimeCallInfo->GetCallArgRef(1);
291     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
292     if (Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TEN) &&
293         (showArg->IsUndefined() || showArg->IsNull())) {
294         GetArkUINodeModifiers()->getPanelModifier()->setShow(nativeNode, true);
295         return panda::JSValueRef::Undefined(vm);
296     } else {
297         bool boolValue = true;
298         if (showArg->IsBoolean()) {
299             boolValue = showArg->ToBoolean(vm)->Value();
300         }
301         GetArkUINodeModifiers()->getPanelModifier()->setShow(nativeNode, boolValue);
302         return panda::JSValueRef::Undefined(vm);
303     }
304 }
305 
ResetShow(ArkUIRuntimeCallInfo * runtimeCallInfo)306 ArkUINativeModuleValue PanelBridge::ResetShow(ArkUIRuntimeCallInfo* runtimeCallInfo)
307 {
308     EcmaVM* vm = runtimeCallInfo->GetVM();
309     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
310     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
311     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
312     GetArkUINodeModifiers()->getPanelModifier()->resetShow(nativeNode);
313     return panda::JSValueRef::Undefined(vm);
314 }
315 } // namespace OHOS::Ace::NG