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_menu_bridge.h"
16 #include "core/interfaces/arkoala/arkoala_api.h"
17 #include "frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
18
19 namespace OHOS::Ace::NG {
20 const std::string FORMAT_FONT = "%s|%s|%s";
21 const std::string DEFAULT_ERR_CODE = "-1";
22 constexpr int ARG_INDEX_0 = 0;
23 constexpr int ARG_INDEX_1 = 1;
24 constexpr int ARG_INDEX_2 = 2;
25 constexpr int ARG_INDEX_3 = 3;
26 constexpr int ARG_INDEX_4 = 4;
27 constexpr int ARG_INDEX_5 = 5;
28 constexpr int COUNT_PROP = 4;
29
30 struct RadiusParseParams {
31 std::vector<ArkUI_Float32> radiusValues;
32 std::vector<int32_t> radiusUnits;
33 std::vector<void*> resObjs;
34 };
35
BuildMenuDividerOptions(EcmaVM * vm,Local<JSValueRef> strokeWidthArg,Local<JSValueRef> startMarginArg,Local<JSValueRef> endMarginArg)36 ArkUIMenuDividerOptions BuildMenuDividerOptions(EcmaVM* vm, Local<JSValueRef> strokeWidthArg,
37 Local<JSValueRef> startMarginArg, Local<JSValueRef> endMarginArg)
38 {
39 ArkUIDimensionType strokeWidthOption;
40 ArkUIDimensionType startMarginOption;
41 ArkUIDimensionType endMarginOption;
42
43 CalcDimension strokeWidth;
44 if (!ArkTSUtils::ParseJsLengthMetrics(vm, strokeWidthArg, strokeWidth)) {
45 strokeWidth = Dimension(0.0);
46 }
47 strokeWidthOption.value = strokeWidth.Value();
48 strokeWidthOption.units = static_cast<int32_t>(strokeWidth.Unit());
49
50 CalcDimension startMargin;
51 if (!ArkTSUtils::ParseJsLengthMetrics(vm, startMarginArg, startMargin)) {
52 startMargin = Dimension(0.0);
53 }
54 startMarginOption.value = startMargin.Value();
55 startMarginOption.units = static_cast<int32_t>(startMargin.Unit());
56
57 CalcDimension endMargin;
58 if (!ArkTSUtils::ParseJsLengthMetrics(vm, endMarginArg, endMargin)) {
59 endMargin = Dimension(0.0);
60 }
61 endMarginOption.value = endMargin.Value();
62 endMarginOption.units = static_cast<int32_t>(endMargin.Unit());
63
64 ArkUIMenuDividerOptions dividerOptions;
65 dividerOptions.strokeWidth = strokeWidthOption;
66 dividerOptions.startMargin = startMarginOption;
67 dividerOptions.endMargin = endMarginOption;
68 return dividerOptions;
69 }
70
SetMenuDivider(ArkUIRuntimeCallInfo * runtimeCallInfo,bool isGroupDivider)71 ArkUINativeModuleValue SetMenuDivider(ArkUIRuntimeCallInfo* runtimeCallInfo, bool isGroupDivider)
72 {
73 EcmaVM* vm = runtimeCallInfo->GetVM();
74 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
75 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(ARG_INDEX_0);
76 Local<JSValueRef> strokeWidthArg = runtimeCallInfo->GetCallArgRef(ARG_INDEX_1);
77 Local<JSValueRef> colorArg = runtimeCallInfo->GetCallArgRef(ARG_INDEX_2);
78 Local<JSValueRef> startMarginArg = runtimeCallInfo->GetCallArgRef(ARG_INDEX_3);
79 Local<JSValueRef> endMarginArg = runtimeCallInfo->GetCallArgRef(ARG_INDEX_4);
80 Local<JSValueRef> modeArg = runtimeCallInfo->GetCallArgRef(ARG_INDEX_5);
81 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
82 if (strokeWidthArg->IsUndefined() && colorArg->IsUndefined() && startMarginArg->IsUndefined()
83 && endMarginArg->IsUndefined() && modeArg->IsUndefined()) {
84 if (isGroupDivider) {
85 GetArkUINodeModifiers()->getMenuModifier()->resetMenuItemGroupDivider(nativeNode);
86 } else {
87 GetArkUINodeModifiers()->getMenuModifier()->resetMenuItemDivider(nativeNode);
88 }
89 return panda::JSValueRef::Undefined(vm);
90 }
91 RefPtr<ResourceObject> colorResObj;
92 auto dividerOptions = BuildMenuDividerOptions(vm, strokeWidthArg, startMarginArg, endMarginArg);
93 Color color;
94 auto nodeInfo = ArkTSUtils::MakeNativeNodeInfo(nativeNode);
95 if (!ArkTSUtils::ParseJsColorAlpha(vm, colorArg, color, colorResObj, nodeInfo)) {
96 color = Color::TRANSPARENT;
97 }
98 dividerOptions.color = color.GetValue();
99 int32_t mode = 0;
100 if (modeArg->IsNumber()) {
101 mode = modeArg->Int32Value(vm);
102 }
103 dividerOptions.mode = mode;
104 auto colorRawPtr = AceType::RawPtr(colorResObj);
105 if (isGroupDivider) {
106 GetArkUINodeModifiers()->getMenuModifier()->setMenuItemGroupDividerWithResource(
107 nativeNode, ÷rOptions, colorRawPtr);
108 } else {
109 GetArkUINodeModifiers()->getMenuModifier()->setMenuItemDividerWithResource(
110 nativeNode, ÷rOptions, colorRawPtr);
111 }
112 return panda::JSValueRef::Undefined(vm);
113 }
114
ResetMenuDivider(ArkUIRuntimeCallInfo * runtimeCallInfo,bool isGroupDivider)115 ArkUINativeModuleValue ResetMenuDivider(ArkUIRuntimeCallInfo* runtimeCallInfo, bool isGroupDivider)
116 {
117 EcmaVM* vm = runtimeCallInfo->GetVM();
118 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
119 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
120 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
121 if (isGroupDivider) {
122 GetArkUINodeModifiers()->getMenuModifier()->resetMenuItemGroupDivider(nativeNode);
123 } else {
124 GetArkUINodeModifiers()->getMenuModifier()->resetMenuItemDivider(nativeNode);
125 }
126 return panda::JSValueRef::Undefined(vm);
127 }
128
SetMenuFontColor(ArkUIRuntimeCallInfo * runtimeCallInfo)129 ArkUINativeModuleValue MenuBridge::SetMenuFontColor(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 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
135 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
136 Color color;
137 RefPtr<ResourceObject> colorResObj;
138 auto nodeInfo = ArkTSUtils::MakeNativeNodeInfo(nativeNode);
139 if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color, colorResObj, nodeInfo)) {
140 GetArkUINodeModifiers()->getMenuModifier()->resetMenuFontColor(nativeNode);
141 } else {
142 auto colorRawPtr = AceType::RawPtr(colorResObj);
143 GetArkUINodeModifiers()->getMenuModifier()->setMenuFontColor(nativeNode, color.GetValue(), colorRawPtr);
144 }
145
146 return panda::JSValueRef::Undefined(vm);
147 }
148
ResetMenuFontColor(ArkUIRuntimeCallInfo * runtimeCallInfo)149 ArkUINativeModuleValue MenuBridge::ResetMenuFontColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
150 {
151 EcmaVM* vm = runtimeCallInfo->GetVM();
152 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
153 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
154 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
155 GetArkUINodeModifiers()->getMenuModifier()->resetMenuFontColor(nativeNode);
156 return panda::JSValueRef::Undefined(vm);
157 }
158
SetFont(ArkUIRuntimeCallInfo * runtimeCallInfo)159 ArkUINativeModuleValue MenuBridge::SetFont(ArkUIRuntimeCallInfo* runtimeCallInfo)
160 {
161 EcmaVM* vm = runtimeCallInfo->GetVM();
162 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
163 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
164 Local<JSValueRef> sizeArg = runtimeCallInfo->GetCallArgRef(1); // 1: index of font size value
165 Local<JSValueRef> weightArg = runtimeCallInfo->GetCallArgRef(2); // 2: index of font weight value
166 Local<JSValueRef> familyArg = runtimeCallInfo->GetCallArgRef(3); // 3: index of font family value
167 Local<JSValueRef> styleArg = runtimeCallInfo->GetCallArgRef(4); // 4: index of font style value
168 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
169 if (sizeArg->IsUndefined() && weightArg->IsUndefined() && familyArg->IsUndefined() && styleArg->IsUndefined()) {
170 GetArkUINodeModifiers()->getMenuModifier()->resetFont(nativeNode);
171 return panda::JSValueRef::Undefined(vm);
172 }
173
174 CalcDimension fontSize;
175 RefPtr<ResourceObject> fontSizeResObj;
176 if (!ArkTSUtils::ParseJsDimensionFp(vm, sizeArg, fontSize, fontSizeResObj, false)) {
177 fontSize = Dimension(0.0);
178 }
179 std::string weight = DEFAULT_ERR_CODE;
180 if (weightArg->IsNumber()) {
181 weight = std::to_string(weightArg->Int32Value(vm));
182 } else {
183 if (!ArkTSUtils::ParseJsString(vm, weightArg, weight) || weight.empty()) {
184 weight = DEFAULT_ERR_CODE;
185 }
186 }
187
188 int32_t style = -1;
189 if (styleArg->IsNumber()) {
190 style = styleArg->Int32Value(vm);
191 }
192
193 std::string family;
194 RefPtr<ResourceObject> fontFamiliesResObj;
195 if (!ArkTSUtils::ParseJsFontFamiliesToString(vm, familyArg, family, fontFamiliesResObj) || family.empty()) {
196 family = DEFAULT_ERR_CODE;
197 }
198 std::string fontSizeStr = fontSize.ToString();
199 std::string fontInfo =
200 StringUtils::FormatString(FORMAT_FONT.c_str(), fontSizeStr.c_str(), weight.c_str(), family.c_str());
201 auto fontSizeRawPtr = AceType::RawPtr(fontSizeResObj);
202 auto fontFamiliesRawPtr = AceType::RawPtr(fontFamiliesResObj);
203 GetArkUINodeModifiers()->getMenuModifier()->setFont(
204 nativeNode, fontInfo.c_str(), style, fontSizeRawPtr, fontFamiliesRawPtr);
205 return panda::JSValueRef::Undefined(vm);
206 }
207
ResetFont(ArkUIRuntimeCallInfo * runtimeCallInfo)208 ArkUINativeModuleValue MenuBridge::ResetFont(ArkUIRuntimeCallInfo* runtimeCallInfo)
209 {
210 EcmaVM* vm = runtimeCallInfo->GetVM();
211 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
212 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
213 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
214 GetArkUINodeModifiers()->getMenuModifier()->resetFont(nativeNode);
215 return panda::JSValueRef::Undefined(vm);
216 }
217
SetRadiusResObjs(std::vector<void * > & resObjs,RefPtr<ResourceObject> & topLeftResObj,RefPtr<ResourceObject> & topRightResObj,RefPtr<ResourceObject> & bottomLeftResObj,RefPtr<ResourceObject> & bottomRightResObj)218 void SetRadiusResObjs(std::vector<void*>& resObjs, RefPtr<ResourceObject>& topLeftResObj,
219 RefPtr<ResourceObject>& topRightResObj, RefPtr<ResourceObject>& bottomLeftResObj,
220 RefPtr<ResourceObject>& bottomRightResObj)
221 {
222 if (topLeftResObj) {
223 topLeftResObj->IncRefCount();
224 }
225 if (topRightResObj) {
226 topRightResObj->IncRefCount();
227 }
228 if (bottomLeftResObj) {
229 bottomLeftResObj->IncRefCount();
230 }
231 if (bottomRightResObj) {
232 bottomRightResObj->IncRefCount();
233 }
234 resObjs.push_back(AceType::RawPtr(topLeftResObj));
235 resObjs.push_back(AceType::RawPtr(topRightResObj));
236 resObjs.push_back(AceType::RawPtr(bottomLeftResObj));
237 resObjs.push_back(AceType::RawPtr(bottomRightResObj));
238 }
239
SetRadiusValues(std::vector<ArkUI_Float32> & radiusValues,CalcDimension topLeft,CalcDimension topRight,CalcDimension bottomLeft,CalcDimension bottomRight)240 void SetRadiusValues(std::vector<ArkUI_Float32>& radiusValues, CalcDimension topLeft, CalcDimension topRight,
241 CalcDimension bottomLeft, CalcDimension bottomRight)
242 {
243 radiusValues.push_back(topLeft.Value());
244 radiusValues.push_back(topRight.Value());
245 radiusValues.push_back(bottomLeft.Value());
246 radiusValues.push_back(bottomRight.Value());
247 }
248
SetRadiusUnits(std::vector<int32_t> & radiusUnits,CalcDimension topLeft,CalcDimension topRight,CalcDimension bottomLeft,CalcDimension bottomRight)249 void SetRadiusUnits(std::vector<int32_t>& radiusUnits, CalcDimension topLeft, CalcDimension topRight,
250 CalcDimension bottomLeft, CalcDimension bottomRight)
251 {
252 radiusUnits.push_back(static_cast<int32_t>(topLeft.Unit()));
253 radiusUnits.push_back(static_cast<int32_t>(topRight.Unit()));
254 radiusUnits.push_back(static_cast<int32_t>(bottomLeft.Unit()));
255 radiusUnits.push_back(static_cast<int32_t>(bottomRight.Unit()));
256 }
257
ParseRadius(EcmaVM * vm,ArkUIRuntimeCallInfo * runtimeCallInfo,ArkUINodeHandle nativeNode,RadiusParseParams & radiusParseParams)258 bool ParseRadius(EcmaVM* vm, ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUINodeHandle nativeNode,
259 RadiusParseParams& radiusParseParams)
260 {
261 Local<JSValueRef> topLeftArgs = runtimeCallInfo->GetCallArgRef(1); // 1: index of top left value
262 Local<JSValueRef> topRightArgs = runtimeCallInfo->GetCallArgRef(2); // 2: index of top right value
263 Local<JSValueRef> bottomLeftArgs = runtimeCallInfo->GetCallArgRef(3); // 3: index of bottom left value
264 Local<JSValueRef> bottomRightArgs = runtimeCallInfo->GetCallArgRef(4); // 4: index of bottom right value
265 Local<JSValueRef> isObjectArgs = runtimeCallInfo->GetCallArgRef(5); // 5: check is object radius
266 if (topLeftArgs->IsUndefined() && topRightArgs->IsUndefined() && bottomLeftArgs->IsUndefined() &&
267 bottomRightArgs->IsUndefined()) {
268 GetArkUINodeModifiers()->getMenuModifier()->resetRadius(nativeNode);
269 return false;
270 }
271 CalcDimension topLeft;
272 CalcDimension topRight;
273 CalcDimension bottomLeft;
274 CalcDimension bottomRight;
275 RefPtr<ResourceObject> topLeftResObj;
276 RefPtr<ResourceObject> topRightResObj;
277 RefPtr<ResourceObject> bottomLeftResObj;
278 RefPtr<ResourceObject> bottomRightResObj;
279 if (isObjectArgs->IsBoolean() && !isObjectArgs->ToBoolean(vm)->Value()) {
280 if (!ArkTSUtils::ParseJsDimensionVpNG(vm, topLeftArgs, topLeft, true)) {
281 GetArkUINodeModifiers()->getMenuModifier()->resetRadius(nativeNode);
282 return false;
283 }
284 if (LessNotEqual(topLeft.Value(), 0.0)) {
285 GetArkUINodeModifiers()->getMenuModifier()->resetRadius(nativeNode);
286 return false;
287 }
288 topRight = topLeft;
289 bottomLeft = topLeft;
290 bottomRight = topLeft;
291 } else {
292 if (!ArkTSUtils::ParseJsDimensionVpNG(vm, topLeftArgs, topLeft, topLeftResObj, true)) {
293 topLeft = CalcDimension(0.0, DimensionUnit::VP);
294 }
295 if (!ArkTSUtils::ParseJsDimensionVpNG(vm, topRightArgs, topRight, topRightResObj, true)) {
296 topRight = CalcDimension(0.0, DimensionUnit::VP);
297 }
298 if (!ArkTSUtils::ParseJsDimensionVpNG(vm, bottomLeftArgs, bottomLeft, bottomLeftResObj, true)) {
299 bottomLeft = CalcDimension(0.0, DimensionUnit::VP);
300 }
301 if (!ArkTSUtils::ParseJsDimensionVpNG(vm, bottomRightArgs, bottomRight, bottomRightResObj, true)) {
302 bottomRight = CalcDimension(0.0, DimensionUnit::VP);
303 }
304 }
305 SetRadiusValues(radiusParseParams.radiusValues, topLeft, topRight, bottomLeft, bottomRight);
306 SetRadiusUnits(radiusParseParams.radiusUnits, topLeft, topRight, bottomLeft, bottomRight);
307 SetRadiusResObjs(radiusParseParams.resObjs, topLeftResObj, topRightResObj, bottomLeftResObj, bottomRightResObj);
308 return true;
309 }
310
SetRadius(ArkUIRuntimeCallInfo * runtimeCallInfo)311 ArkUINativeModuleValue MenuBridge::SetRadius(ArkUIRuntimeCallInfo* runtimeCallInfo)
312 {
313 EcmaVM* vm = runtimeCallInfo->GetVM();
314 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
315 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
316 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
317 RadiusParseParams radiusParseParams;
318 if (!ParseRadius(vm, runtimeCallInfo, nativeNode, radiusParseParams)) {
319 return panda::JSValueRef::Undefined(vm);
320 }
321 GetArkUINodeModifiers()->getMenuModifier()->setRadius(nativeNode, radiusParseParams.radiusValues.data(),
322 radiusParseParams.radiusUnits.data(), radiusParseParams.resObjs.data(), COUNT_PROP);
323 return panda::JSValueRef::Undefined(vm);
324 }
325
ResetRadius(ArkUIRuntimeCallInfo * runtimeCallInfo)326 ArkUINativeModuleValue MenuBridge::ResetRadius(ArkUIRuntimeCallInfo* runtimeCallInfo)
327 {
328 EcmaVM* vm = runtimeCallInfo->GetVM();
329 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
330 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
331 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
332 GetArkUINodeModifiers()->getMenuModifier()->resetRadius(nativeNode);
333 return panda::JSValueRef::Undefined(vm);
334 }
335
SetWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)336 ArkUINativeModuleValue MenuBridge::SetWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
337 {
338 EcmaVM* vm = runtimeCallInfo->GetVM();
339 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
340 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
341 Local<JSValueRef> widthArg = runtimeCallInfo->GetCallArgRef(1);
342 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
343 CalcDimension width;
344 if (!ArkTSUtils::ParseJsDimensionVp(vm, widthArg, width, false)) {
345 GetArkUINodeModifiers()->getMenuModifier()->resetMenuWidth(nativeNode);
346 return panda::JSValueRef::Undefined(vm);
347 }
348 GetArkUINodeModifiers()->getMenuModifier()->setMenuWidth(
349 nativeNode, width.Value(), static_cast<int32_t>(width.Unit()));
350 return panda::JSValueRef::Undefined(vm);
351 }
352
ResetWidth(ArkUIRuntimeCallInfo * runtimeCallInfo)353 ArkUINativeModuleValue MenuBridge::ResetWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
354 {
355 EcmaVM* vm = runtimeCallInfo->GetVM();
356 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
357 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
358 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
359 GetArkUINodeModifiers()->getMenuModifier()->resetMenuWidth(nativeNode);
360 return panda::JSValueRef::Undefined(vm);
361 }
362
SetMenuItemDivider(ArkUIRuntimeCallInfo * runtimeCallInfo)363 ArkUINativeModuleValue MenuBridge::SetMenuItemDivider(ArkUIRuntimeCallInfo* runtimeCallInfo)
364 {
365 return SetMenuDivider(runtimeCallInfo, false);
366 }
367
ResetMenuItemDivider(ArkUIRuntimeCallInfo * runtimeCallInfo)368 ArkUINativeModuleValue MenuBridge::ResetMenuItemDivider(ArkUIRuntimeCallInfo* runtimeCallInfo)
369 {
370 return ResetMenuDivider(runtimeCallInfo, false);
371 }
372
SetMenuItemGroupDivider(ArkUIRuntimeCallInfo * runtimeCallInfo)373 ArkUINativeModuleValue MenuBridge::SetMenuItemGroupDivider(ArkUIRuntimeCallInfo* runtimeCallInfo)
374 {
375 return SetMenuDivider(runtimeCallInfo, true);
376 }
377
ResetMenuItemGroupDivider(ArkUIRuntimeCallInfo * runtimeCallInfo)378 ArkUINativeModuleValue MenuBridge::ResetMenuItemGroupDivider(ArkUIRuntimeCallInfo* runtimeCallInfo)
379 {
380 return ResetMenuDivider(runtimeCallInfo, true);
381 }
382
SetSubMenuExpandingMode(ArkUIRuntimeCallInfo * runtimeCallInfo)383 ArkUINativeModuleValue MenuBridge::SetSubMenuExpandingMode(ArkUIRuntimeCallInfo* runtimeCallInfo)
384 {
385 EcmaVM* vm = runtimeCallInfo->GetVM();
386 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
387 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
388 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
389 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
390 if (secondArg->IsUndefined() || secondArg->IsNull()) {
391 GetArkUINodeModifiers()->getMenuModifier()->resetSubMenuExpandingMode(nativeNode);
392 return panda::JSValueRef::Undefined(vm);
393 }
394 if (secondArg->IsNumber()) {
395 GetArkUINodeModifiers()->getMenuModifier()->setSubMenuExpandingMode(nativeNode,
396 secondArg->ToNumber(vm)->Value());
397 } else {
398 GetArkUINodeModifiers()->getMenuModifier()->resetSubMenuExpandingMode(nativeNode);
399 }
400 return panda::JSValueRef::Undefined(vm);
401 }
402
ResetSubMenuExpandingMode(ArkUIRuntimeCallInfo * runtimeCallInfo)403 ArkUINativeModuleValue MenuBridge::ResetSubMenuExpandingMode(ArkUIRuntimeCallInfo* runtimeCallInfo)
404 {
405 EcmaVM* vm = runtimeCallInfo->GetVM();
406 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
407 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
408 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
409 GetArkUINodeModifiers()->getMenuModifier()->resetSubMenuExpandingMode(nativeNode);
410 return panda::JSValueRef::Undefined(vm);
411 }
412
SetSubMenuExpandSymbol(ArkUIRuntimeCallInfo * runtimeCallInfo)413 ArkUINativeModuleValue MenuBridge::SetSubMenuExpandSymbol(ArkUIRuntimeCallInfo* runtimeCallInfo)
414 {
415 EcmaVM* vm = runtimeCallInfo->GetVM();
416 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
417 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
418 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
419 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
420 std::function<void(WeakPtr<NG::FrameNode>)> symbolApply;
421 if (secondArg->IsObject(vm)) {
422 Framework::JsiCallbackInfo info = Framework::JsiCallbackInfo(runtimeCallInfo);
423 Framework::JSViewAbstract::SetSymbolOptionApply(runtimeCallInfo, symbolApply, info[1]);
424 GetArkUINodeModifiers()->getMenuModifier()->setSubMenuExpandSymbol(
425 nativeNode, reinterpret_cast<void*>(&symbolApply));
426 } else {
427 GetArkUINodeModifiers()->getMenuModifier()->resetSubMenuExpandSymbol(nativeNode);
428 }
429 return panda::JSValueRef::Undefined(vm);
430 }
431
ResetSubMenuExpandSymbol(ArkUIRuntimeCallInfo * runtimeCallInfo)432 ArkUINativeModuleValue MenuBridge::ResetSubMenuExpandSymbol(ArkUIRuntimeCallInfo* runtimeCallInfo)
433 {
434 EcmaVM* vm = runtimeCallInfo->GetVM();
435 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
436 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
437 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
438 GetArkUINodeModifiers()->getMenuModifier()->resetSubMenuExpandSymbol(nativeNode);
439 return panda::JSValueRef::Undefined(vm);
440 }
441
SetFontSize(ArkUIRuntimeCallInfo * runtimeCallInfo)442 ArkUINativeModuleValue MenuBridge::SetFontSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
443 {
444 EcmaVM* vm = runtimeCallInfo->GetVM();
445 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
446 uint32_t argsNumber = runtimeCallInfo->GetArgsNumber();
447 if (argsNumber != ARG_INDEX_2) {
448 return panda::JSValueRef::Undefined(vm);
449 }
450 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(ARG_INDEX_0);
451 Local<JSValueRef> fontSizeArg = runtimeCallInfo->GetCallArgRef(ARG_INDEX_1);
452 auto nativeNode = nodePtr(nativeNodeArg->ToNativePointer(vm)->Value());
453 CalcDimension fontSize;
454 RefPtr<ResourceObject> fontSizeResObj;
455 if (!ArkTSUtils::ParseJsDimensionFp(vm, fontSizeArg, fontSize, fontSizeResObj) || fontSize.IsNegative()) {
456 GetArkUINodeModifiers()->getMenuModifier()->resetMenuFontSize(nativeNode);
457 } else {
458 auto fontSizeRawPtr = AceType::RawPtr(fontSizeResObj);
459 GetArkUINodeModifiers()->getMenuModifier()->setMenuFontSize(
460 nativeNode, fontSize.Value(), static_cast<int>(fontSize.Unit()), fontSizeRawPtr);
461 }
462 return panda::JSValueRef::Undefined(vm);
463 }
464
ResetFontSize(ArkUIRuntimeCallInfo * runtimeCallInfo)465 ArkUINativeModuleValue MenuBridge::ResetFontSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
466 {
467 EcmaVM* vm = runtimeCallInfo->GetVM();
468 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
469 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(ARG_INDEX_0);
470 auto nativeNode = nodePtr(nativeNodeArg->ToNativePointer(vm)->Value());
471 GetArkUINodeModifiers()->getMenuModifier()->resetMenuFontSize(nativeNode);
472 return panda::JSValueRef::Undefined(vm);
473 }
474
475 } // namespace OHOS::Ace::NG
476