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