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_grid_col_bridge.h"
16
17 namespace OHOS::Ace::NG {
18 constexpr int32_t MAX_NUMBER_BREAKPOINT = 6;
19 constexpr int XS = 0;
20 constexpr int SM = 1;
21 constexpr int MD = 2;
22 constexpr int LG = 3;
23 constexpr int XL = 4;
24 constexpr int XXL = 5;
25 int32_t defaultVal = 0;
26
SetGridColOffset(ArkUIRuntimeCallInfo * runtimeCallInfo)27 ArkUINativeModuleValue GridColBridge::SetGridColOffset(ArkUIRuntimeCallInfo *runtimeCallInfo)
28 {
29 EcmaVM *vm = runtimeCallInfo->GetVM();
30 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
31 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
32 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
33 Local<JSValueRef> xs = runtimeCallInfo->GetCallArgRef(XS + 1);
34 Local<JSValueRef> sm = runtimeCallInfo->GetCallArgRef(SM + 1);
35 Local<JSValueRef> md = runtimeCallInfo->GetCallArgRef(MD + 1);
36 Local<JSValueRef> lg = runtimeCallInfo->GetCallArgRef(LG + 1);
37 Local<JSValueRef> xl = runtimeCallInfo->GetCallArgRef(XL + 1);
38 Local<JSValueRef> xxl = runtimeCallInfo->GetCallArgRef(XXL + 1);
39 int32_t containerSizeArray[MAX_NUMBER_BREAKPOINT];
40 if (xs->IsNumber() && xs->Int32Value(vm) >= 0) {
41 containerSizeArray[XS] = xs->Int32Value(vm);
42 } else {
43 containerSizeArray[XS] = -1;
44 }
45 if (sm->IsNumber() && sm->Int32Value(vm) >= 0) {
46 containerSizeArray[SM] = sm->Int32Value(vm);
47 } else {
48 containerSizeArray[SM] = -1;
49 }
50 if (md->IsNumber() && md->Int32Value(vm) >= 0) {
51 containerSizeArray[MD] = md->Int32Value(vm);
52 } else {
53 containerSizeArray[MD] = -1;
54 }
55 if (lg->IsNumber() && lg->Int32Value(vm) >= 0) {
56 containerSizeArray[LG] = lg->Int32Value(vm);
57 } else {
58 containerSizeArray[LG] = -1;
59 }
60 if (xl->IsNumber() && xl->Int32Value(vm) >= 0) {
61 containerSizeArray[XL] = xl->Int32Value(vm);
62 } else {
63 containerSizeArray[XL] = -1;
64 }
65 if (xxl->IsNumber() && xxl->Int32Value(vm) >= 0) {
66 containerSizeArray[XXL] = xxl->Int32Value(vm);
67 } else {
68 containerSizeArray[XXL] = -1;
69 }
70 GetArkUINodeModifiers()->getGridColModifier()->setGridColOffset(nativeNode, containerSizeArray,
71 MAX_NUMBER_BREAKPOINT);
72 return panda::JSValueRef::Undefined(vm);
73 }
74
ResetGridColOffset(ArkUIRuntimeCallInfo * runtimeCallInfo)75 ArkUINativeModuleValue GridColBridge::ResetGridColOffset(ArkUIRuntimeCallInfo *runtimeCallInfo)
76 {
77 EcmaVM *vm = runtimeCallInfo->GetVM();
78 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
79 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
80 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
81 GetArkUINodeModifiers()->getGridColModifier()->resetGridColOffset(nativeNode);
82 return panda::JSValueRef::Undefined(vm);
83 }
84
SetSpan(ArkUIRuntimeCallInfo * runtimeCallInfo)85 ArkUINativeModuleValue GridColBridge::SetSpan(ArkUIRuntimeCallInfo *runtimeCallInfo)
86 {
87 EcmaVM *vm = runtimeCallInfo->GetVM();
88 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
89 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
90 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
91 Local<JSValueRef> xs = runtimeCallInfo->GetCallArgRef(XS + 1);
92 Local<JSValueRef> sm = runtimeCallInfo->GetCallArgRef(SM + 1);
93 Local<JSValueRef> md = runtimeCallInfo->GetCallArgRef(MD + 1);
94 Local<JSValueRef> lg = runtimeCallInfo->GetCallArgRef(LG + 1);
95 Local<JSValueRef> xl = runtimeCallInfo->GetCallArgRef(XL + 1);
96 Local<JSValueRef> xxl = runtimeCallInfo->GetCallArgRef(XXL + 1);
97 int32_t containerSizeArray[MAX_NUMBER_BREAKPOINT];
98 if (xs->IsNumber() && xs->Int32Value(vm) >= 0) {
99 containerSizeArray[XS] = xs->Int32Value(vm);
100 } else {
101 containerSizeArray[XS] = -1;
102 }
103 if (sm->IsNumber() && sm->Int32Value(vm) >= 0) {
104 containerSizeArray[SM] = sm->Int32Value(vm);
105 } else {
106 containerSizeArray[SM] = -1;
107 }
108 if (md->IsNumber() && md->Int32Value(vm) >= 0) {
109 containerSizeArray[MD] = md->Int32Value(vm);
110 } else {
111 containerSizeArray[MD] = -1;
112 }
113 if (lg->IsNumber() && lg->Int32Value(vm) >= 0) {
114 containerSizeArray[LG] = lg->Int32Value(vm);
115 } else {
116 containerSizeArray[LG] = -1;
117 }
118 if (xl->IsNumber() && xl->Int32Value(vm) >= 0) {
119 containerSizeArray[XL] = xl->Int32Value(vm);
120 } else {
121 containerSizeArray[XL] = -1;
122 }
123 if (xxl->IsNumber() && xxl->Int32Value(vm) >= 0) {
124 containerSizeArray[XXL] = xxl->Int32Value(vm);
125 } else {
126 containerSizeArray[XXL] = -1;
127 }
128 GetArkUINodeModifiers()->getGridColModifier()->setSpan(nativeNode, containerSizeArray, MAX_NUMBER_BREAKPOINT);
129 return panda::JSValueRef::Undefined(vm);
130 }
131
ResetSpan(ArkUIRuntimeCallInfo * runtimeCallInfo)132 ArkUINativeModuleValue GridColBridge::ResetSpan(ArkUIRuntimeCallInfo *runtimeCallInfo)
133 {
134 EcmaVM *vm = runtimeCallInfo->GetVM();
135 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
136 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
137 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
138 GetArkUINodeModifiers()->getGridColModifier()->resetSpan(nativeNode);
139 return panda::JSValueRef::Undefined(vm);
140 }
141
SetOrder(ArkUIRuntimeCallInfo * runtimeCallInfo)142 ArkUINativeModuleValue GridColBridge::SetOrder(ArkUIRuntimeCallInfo *runtimeCallInfo)
143 {
144 EcmaVM *vm = runtimeCallInfo->GetVM();
145 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
146 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
147 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
148 Local<JSValueRef> xs = runtimeCallInfo->GetCallArgRef(XS + 1);
149 Local<JSValueRef> sm = runtimeCallInfo->GetCallArgRef(SM + 1);
150 Local<JSValueRef> md = runtimeCallInfo->GetCallArgRef(MD + 1);
151 Local<JSValueRef> lg = runtimeCallInfo->GetCallArgRef(LG + 1);
152 Local<JSValueRef> xl = runtimeCallInfo->GetCallArgRef(XL + 1);
153 Local<JSValueRef> xxl = runtimeCallInfo->GetCallArgRef(XXL + 1);
154 int32_t containerSizeArray[MAX_NUMBER_BREAKPOINT];
155 if (xs->IsNumber() && xs->Int32Value(vm) >= 0) {
156 containerSizeArray[XS] = xs->Int32Value(vm);
157 } else {
158 containerSizeArray[XS] = -1;
159 }
160 if (sm->IsNumber() && sm->Int32Value(vm) >= 0) {
161 containerSizeArray[SM] = sm->Int32Value(vm);
162 } else {
163 containerSizeArray[SM] = -1;
164 }
165 if (md->IsNumber() && md->Int32Value(vm) >= 0) {
166 containerSizeArray[MD] = md->Int32Value(vm);
167 } else {
168 containerSizeArray[MD] = -1;
169 }
170 if (lg->IsNumber() && lg->Int32Value(vm) >= 0) {
171 containerSizeArray[LG] = lg->Int32Value(vm);
172 } else {
173 containerSizeArray[LG] = -1;
174 }
175 if (xl->IsNumber() && xl->Int32Value(vm) >= 0) {
176 containerSizeArray[XL] = xl->Int32Value(vm);
177 } else {
178 containerSizeArray[XL] = -1;
179 }
180 if (xxl->IsNumber() && xxl->Int32Value(vm) >= 0) {
181 containerSizeArray[XXL] = xxl->Int32Value(vm);
182 } else {
183 containerSizeArray[XXL] = -1;
184 }
185 GetArkUINodeModifiers()->getGridColModifier()->setOrder(nativeNode, containerSizeArray, MAX_NUMBER_BREAKPOINT);
186 return panda::JSValueRef::Undefined(vm);
187 }
188
ResetOrder(ArkUIRuntimeCallInfo * runtimeCallInfo)189 ArkUINativeModuleValue GridColBridge::ResetOrder(ArkUIRuntimeCallInfo *runtimeCallInfo)
190 {
191 EcmaVM *vm = runtimeCallInfo->GetVM();
192 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
193 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
194 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
195 GetArkUINodeModifiers()->getGridColModifier()->resetOrder(nativeNode);
196 return panda::JSValueRef::Undefined(vm);
197 }
198 }