1 /*
2 * Copyright (c) 2021-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 "js_form_info.h"
16
17 #include "fms_log_wrapper.h"
18 #include "form_constants.h"
19 #include "form_info.h"
20 #include "form_info_base.h"
21 #include "form_instance.h"
22 #include "form_state_info.h"
23 #include "js_runtime_utils.h"
24 namespace OHOS {
25 namespace AbilityRuntime {
CreateJsFormType(napi_env engine)26 napi_value CreateJsFormType(napi_env engine)
27 {
28 napi_value objValue = nullptr;
29 napi_create_object(engine, &objValue);
30 napi_set_named_property(engine, objValue, "JS", CreateJsValue(engine, AppExecFwk::FormType::JS));
31 napi_set_named_property(engine, objValue, "eTS", CreateJsValue(engine, AppExecFwk::FormType::ETS));
32 napi_set_named_property(engine, objValue, "arkTS", CreateJsValue(engine, AppExecFwk::FormType::ETS));
33 return objValue;
34 }
35
CreateJsColorMode(napi_env engine)36 napi_value CreateJsColorMode(napi_env engine)
37 {
38 napi_value objValue = nullptr;
39 napi_create_object(engine, &objValue);
40 napi_set_named_property(
41 engine, objValue, "MODE_AUTO", CreateJsValue(engine, AppExecFwk::FormsColorMode::AUTO_MODE));
42 napi_set_named_property(
43 engine, objValue, "MODE_DARK", CreateJsValue(engine, AppExecFwk::FormsColorMode::DARK_MODE));
44 napi_set_named_property(
45 engine, objValue, "MODE_LIGHT", CreateJsValue(engine, AppExecFwk::FormsColorMode::LIGHT_MODE));
46 return objValue;
47 }
48
CreateJsRenderingMode(napi_env engine)49 napi_value CreateJsRenderingMode(napi_env engine)
50 {
51 napi_value objValue = nullptr;
52 napi_create_object(engine, &objValue);
53 napi_set_named_property(
54 engine, objValue, "AUTO_COLOR", CreateJsValue(engine, AppExecFwk::FormsRenderingMode::AUTO_COLOR));
55 napi_set_named_property(
56 engine, objValue, "FULL_COLOR", CreateJsValue(engine, AppExecFwk::FormsRenderingMode::FULL_COLOR));
57 napi_set_named_property(
58 engine, objValue, "SINGLE_COLOR", CreateJsValue(engine, AppExecFwk::FormsRenderingMode::SINGLE_COLOR));
59 return objValue;
60 }
61
CreateJsFormState(napi_env engine)62 napi_value CreateJsFormState(napi_env engine)
63 {
64 napi_value objValue = nullptr;
65 napi_create_object(engine, &objValue);
66 napi_set_named_property(engine, objValue, "UNKNOWN", CreateJsValue(engine, AppExecFwk::FormState::UNKNOWN));
67 napi_set_named_property(engine, objValue, "DEFAULT", CreateJsValue(engine, AppExecFwk::FormState::DEFAULT));
68 napi_set_named_property(engine, objValue, "READY", CreateJsValue(engine, AppExecFwk::FormState::READY));
69 return objValue;
70 }
71
CreateJsFormParam(napi_env engine)72 napi_value CreateJsFormParam(napi_env engine)
73 {
74 napi_value objValue = nullptr;
75 napi_create_object(engine, &objValue);
76 napi_set_named_property(
77 engine, objValue, "IDENTITY_KEY", CreateJsValue(engine, AppExecFwk::Constants::PARAM_FORM_IDENTITY_KEY));
78 napi_set_named_property(
79 engine, objValue, "DIMENSION_KEY", CreateJsValue(engine, AppExecFwk::Constants::PARAM_FORM_DIMENSION_KEY));
80 napi_set_named_property(engine, objValue, "RENDERINGMODE_KEY", CreateJsValue(
81 engine, AppExecFwk::Constants::PARAM_FORM_RENDERINGMODE_KEY));
82 napi_set_named_property(
83 engine, objValue, "NAME_KEY", CreateJsValue(engine, AppExecFwk::Constants::PARAM_FORM_NAME_KEY));
84 napi_set_named_property(
85 engine, objValue, "MODULE_NAME_KEY", CreateJsValue(engine, AppExecFwk::Constants::PARAM_MODULE_NAME_KEY));
86 napi_set_named_property(
87 engine, objValue, "WIDTH_KEY", CreateJsValue(engine, AppExecFwk::Constants::PARAM_FORM_WIDTH_KEY));
88 napi_set_named_property(
89 engine, objValue, "HEIGHT_KEY", CreateJsValue(engine, AppExecFwk::Constants::PARAM_FORM_HEIGHT_KEY));
90 napi_set_named_property(
91 engine, objValue, "TEMPORARY_KEY", CreateJsValue(engine, AppExecFwk::Constants::PARAM_FORM_TEMPORARY_KEY));
92 napi_set_named_property(
93 engine, objValue, "BUNDLE_NAME_KEY", CreateJsValue(engine, AppExecFwk::Constants::PARAM_BUNDLE_NAME_KEY));
94 napi_set_named_property(
95 engine, objValue, "ABILITY_NAME_KEY", CreateJsValue(engine, AppExecFwk::Constants::PARAM_ABILITY_NAME_KEY));
96 napi_set_named_property(
97 engine, objValue, "DEVICE_ID_KEY", CreateJsValue(engine, AppExecFwk::Constants::PARAM_DEVICE_ID_KEY));
98 napi_set_named_property(
99 engine, objValue, "LAUNCH_REASON_KEY", CreateJsValue(engine, AppExecFwk::Constants::LAUNCH_REASON_KEY));
100 napi_set_named_property(engine, objValue,
101 "PARAM_FORM_CUSTOMIZE_KEY", CreateJsValue(engine, AppExecFwk::Constants::PARAM_FORM_CUSTOMIZE_KEY));
102 napi_set_named_property(engine, objValue,
103 "FORM_RENDERING_MODE_KEY", CreateJsValue(engine, AppExecFwk::Constants::PARAM_FORM_RENDERINGMODE_KEY));
104 napi_set_named_property(engine, objValue,
105 "HOST_BG_INVERSE_COLOR_KEY", CreateJsValue(engine, AppExecFwk::Constants::PARAM_HOST_BG_INVERSE_COLOR_KEY));
106 napi_set_named_property(engine, objValue,
107 "FORM_PERMISSION_GRANTED_KEY", CreateJsValue(engine, AppExecFwk::Constants::FORM_PERMISSION_GRANTED_KEY));
108 napi_set_named_property(engine, objValue,
109 "FORM_PERMISSION_NAME_KEY", CreateJsValue(engine, AppExecFwk::Constants::FORM_PERMISSION_NAME_KEY));
110 return objValue;
111 }
112
CreateJsFormDimension(napi_env engine)113 napi_value CreateJsFormDimension(napi_env engine)
114 {
115 napi_value objValue = nullptr;
116 napi_create_object(engine, &objValue);
117 napi_set_named_property(
118 engine, objValue, "Dimension_1_2", CreateJsValue(engine, AppExecFwk::Constants::Dimension::DIMENSION_1_2));
119 napi_set_named_property(
120 engine, objValue, "Dimension_2_2", CreateJsValue(engine, AppExecFwk::Constants::Dimension::DIMENSION_2_2));
121 napi_set_named_property(
122 engine, objValue, "Dimension_2_4", CreateJsValue(engine, AppExecFwk::Constants::Dimension::DIMENSION_2_4));
123 napi_set_named_property(
124 engine, objValue, "Dimension_4_4", CreateJsValue(engine, AppExecFwk::Constants::Dimension::DIMENSION_4_4));
125 napi_set_named_property(
126 engine, objValue, "Dimension_2_1", CreateJsValue(engine, AppExecFwk::Constants::Dimension::DIMENSION_2_1));
127 napi_set_named_property(
128 engine, objValue, "DIMENSION_1_1", CreateJsValue(engine, AppExecFwk::Constants::Dimension::DIMENSION_1_1));
129 napi_set_named_property(
130 engine, objValue, "DIMENSION_6_4", CreateJsValue(engine, AppExecFwk::Constants::Dimension::DIMENSION_6_4));
131 #ifdef FORM_DIMENSION_2_3
132 napi_set_named_property(
133 engine, objValue, "DIMENSION_2_3", CreateJsValue(engine, AppExecFwk::Constants::Dimension::DIMENSION_2_3));
134 #endif
135
136 #ifdef FORM_DIMENSION_3_3
137 napi_set_named_property(
138 engine, objValue, "DIMENSION_3_3", CreateJsValue(engine, AppExecFwk::Constants::Dimension::DIMENSION_3_3));
139 #endif
140 return objValue;
141 }
142
CreateJsFormVisibilityType(napi_env engine)143 napi_value CreateJsFormVisibilityType(napi_env engine)
144 {
145 napi_value objValue = nullptr;
146 napi_create_object(engine, &objValue);
147 napi_set_named_property(engine, objValue, "UNKNOWN", CreateJsValue(engine, AppExecFwk::Constants::UNKNOWN));
148 napi_set_named_property(
149 engine, objValue, "FORM_VISIBLE", CreateJsValue(engine, AppExecFwk::Constants::FORM_VISIBLE));
150 napi_set_named_property(
151 engine, objValue, "FORM_INVISIBLE", CreateJsValue(engine, AppExecFwk::Constants::FORM_INVISIBLE));
152 return objValue;
153 }
154
CreateJsFormLaunchReason(napi_env engine)155 napi_value CreateJsFormLaunchReason(napi_env engine)
156 {
157 napi_value objValue = nullptr;
158 napi_create_object(engine, &objValue);
159 napi_set_named_property(
160 engine, objValue, "FORM_DEFAULT", CreateJsValue(engine, AppExecFwk::Constants::FORM_DEFAULT));
161 napi_set_named_property(engine, objValue, "FORM_SHARE", CreateJsValue(engine, AppExecFwk::Constants::FORM_SHARE));
162 return objValue;
163 }
164
CreateJsFormUsageState(napi_env engine)165 napi_value CreateJsFormUsageState(napi_env engine)
166 {
167 napi_value objValue = nullptr;
168 napi_create_object(engine, &objValue);
169 napi_set_named_property(engine, objValue, "USED", CreateJsValue(engine, AppExecFwk::FormUsageState::USED));
170 napi_set_named_property(engine, objValue, "UNUSED", CreateJsValue(engine, AppExecFwk::FormUsageState::UNUSED));
171 return objValue;
172 }
173
CreateJsFormLocation(napi_env engine)174 napi_value CreateJsFormLocation(napi_env engine)
175 {
176 napi_value objValue = nullptr;
177 napi_create_object(engine, &objValue);
178 napi_set_named_property(
179 engine, objValue, "DESKTOP", CreateJsValue(engine, AppExecFwk::Constants::FormLocation::DESKTOP));
180 napi_set_named_property(
181 engine, objValue, "FORM_CENTER", CreateJsValue(engine, AppExecFwk::Constants::FormLocation::FORM_CENTER));
182 napi_set_named_property(
183 engine, objValue, "FORM_MANAGER", CreateJsValue(engine, AppExecFwk::Constants::FormLocation::FORM_MANAGER));
184 napi_set_named_property(
185 engine, objValue, "NEGATIVE_SCREEN", CreateJsValue(engine,
186 AppExecFwk::Constants::FormLocation::NEGATIVE_SCREEN));
187 napi_set_named_property(
188 engine, objValue, "FORM_CENTER_NEGATIVE_SCREEN", CreateJsValue(engine,
189 AppExecFwk::Constants::FormLocation::FORM_CENTER_NEGATIVE_SCREEN));
190 napi_set_named_property(
191 engine, objValue, "FORM_MANAGER_NEGATIVE_SCREEN", CreateJsValue(engine,
192 AppExecFwk::Constants::FormLocation::FORM_MANAGER_NEGATIVE_SCREEN));
193 napi_set_named_property(
194 engine, objValue, "SCREEN_LOCK", CreateJsValue(engine, AppExecFwk::Constants::FormLocation::SCREEN_LOCK));
195 napi_set_named_property(
196 engine, objValue, "AI_SUGGESTION", CreateJsValue(engine, AppExecFwk::Constants::FormLocation::AI_SUGGESTION));
197 napi_set_named_property(
198 engine, objValue, "OTHER", CreateJsValue(engine, AppExecFwk::Constants::FormLocation::OTHER));
199 return objValue;
200 }
201
CreateJsPublishFormErrorCode(napi_env engine)202 napi_value CreateJsPublishFormErrorCode(napi_env engine)
203 {
204 napi_value objValue = nullptr;
205 napi_create_object(engine, &objValue);
206 napi_set_named_property(
207 engine, objValue, "SUCCESS", CreateJsValue(engine, AppExecFwk::Constants::PublishFormErrorCode::SUCCESS));
208 napi_set_named_property(
209 engine, objValue, "NO_SPACE", CreateJsValue(engine, AppExecFwk::Constants::PublishFormErrorCode::NO_SPACE));
210 napi_set_named_property(engine, objValue, "PARAM_ERROR",
211 CreateJsValue(engine, AppExecFwk::Constants::PublishFormErrorCode::PARAM_ERROR));
212 napi_set_named_property(engine, objValue, "INTERNAL_ERROR",
213 CreateJsValue(engine, AppExecFwk::Constants::PublishFormErrorCode::INTERNAL_ERROR));
214 return objValue;
215 }
216
CreateJsFormShape(napi_env engine)217 napi_value CreateJsFormShape(napi_env engine)
218 {
219 napi_value objValue = nullptr;
220 napi_create_object(engine, &objValue);
221 napi_set_named_property(
222 engine, objValue, "RECT", CreateJsValue(engine, AppExecFwk::Constants::Shape::RECT));
223 napi_set_named_property(
224 engine, objValue, "CIRCLE", CreateJsValue(engine, AppExecFwk::Constants::Shape::CIRCLE));
225 return objValue;
226 }
227
FormInfoInit(napi_env engine,napi_value exportObj)228 napi_value FormInfoInit(napi_env engine, napi_value exportObj)
229 {
230 HILOG_INFO("call");
231
232 napi_set_named_property(engine, exportObj, "FormType", CreateJsFormType(engine));
233 napi_set_named_property(engine, exportObj, "ColorMode", CreateJsColorMode(engine));
234 napi_set_named_property(engine, exportObj, "RenderingMode", CreateJsRenderingMode(engine));
235 napi_set_named_property(engine, exportObj, "FormState", CreateJsFormState(engine));
236 napi_set_named_property(engine, exportObj, "FormParam", CreateJsFormParam(engine));
237 napi_set_named_property(engine, exportObj, "FormDimension", CreateJsFormDimension(engine));
238 napi_set_named_property(engine, exportObj, "VisibilityType", CreateJsFormVisibilityType(engine));
239 napi_set_named_property(engine, exportObj, "LaunchReason", CreateJsFormLaunchReason(engine));
240 napi_set_named_property(engine, exportObj, "FormUsageState", CreateJsFormUsageState(engine));
241 napi_set_named_property(engine, exportObj, "FormLocation", CreateJsFormLocation(engine));
242 napi_set_named_property(engine, exportObj, "PublishFormErrorCode", CreateJsPublishFormErrorCode(engine));
243 napi_set_named_property(engine, exportObj, "FormShape", CreateJsFormShape(engine));
244 HILOG_INFO("end");
245 return exportObj;
246 }
247 } // namespace AbilityRuntime
248 } // namespace OHOS
249