1 /*
2 * Copyright (c) 2021-2022 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
16 #include "frameworks/bridge/declarative_frontend/engine/jsi/jsi_view_register.h"
17
18 #include "base/geometry/ng/size_t.h"
19 #include "base/i18n/localization.h"
20 #include "base/log/log.h"
21 #include "base/memory/ace_type.h"
22 #include "base/memory/referenced.h"
23 #include "base/utils/system_properties.h"
24 #include "base/utils/utils.h"
25 #include "bridge/card_frontend/card_frontend_declarative.h"
26 #include "bridge/card_frontend/form_frontend_declarative.h"
27 #include "bridge/common/utils/engine_helper.h"
28 #include "bridge/declarative_frontend/declarative_frontend.h"
29 #include "bridge/declarative_frontend/engine/functions/js_drag_function.h"
30 #include "bridge/declarative_frontend/engine/js_object_template.h"
31 #include "bridge/declarative_frontend/frontend_delegate_declarative.h"
32 #include "bridge/declarative_frontend/interfaces/profiler/js_profiler.h"
33 #include "bridge/declarative_frontend/jsview/js_canvas_image_data.h"
34 #include "bridge/js_frontend/engine/jsi/ark_js_runtime.h"
35 #include "core/common/card_scope.h"
36 #include "core/common/container.h"
37 #include "core/components_ng/base/inspector.h"
38 #include "core/components_ng/pattern/stage/page_pattern.h"
39 #include "core/components_v2/inspector/inspector.h"
40
41 namespace OHOS::Ace::Framework {
42
43 constexpr int FUNC_SET_CREATE_ARG_LEN = 2;
44
CreateJsObjectFromJsonValue(const EcmaVM * vm,const std::unique_ptr<JsonValue> & jsonValue)45 JSRef<JSVal> CreateJsObjectFromJsonValue(const EcmaVM* vm, const std::unique_ptr<JsonValue>& jsonValue)
46 {
47 if (jsonValue->IsBool()) {
48 return JSRef<JSVal>::Make(JsiValueConvertor::toJsiValueWithVM(vm, jsonValue->GetBool()));
49 } else if (jsonValue->IsNumber()) {
50 return JSRef<JSVal>::Make(JsiValueConvertor::toJsiValueWithVM(vm, jsonValue->GetDouble()));
51 } else if (jsonValue->IsString()) {
52 return JSRef<JSVal>::Make(JsiValueConvertor::toJsiValueWithVM(vm, jsonValue->GetString()));
53 } else if (jsonValue->IsArray()) {
54 JSRef<JSArray> array = JSRef<JSArray>::New();
55 int32_t size = jsonValue->GetArraySize();
56 for (int32_t i = 0; i < size; ++i) {
57 std::unique_ptr<JsonValue> item = jsonValue->GetArrayItem(i);
58 array->SetValueAt(i, CreateJsObjectFromJsonValue(vm, item));
59 }
60 return array;
61 } else if (jsonValue->IsObject()) {
62 JSRef<JSObject> object = JSRef<JSObject>::New();
63 std::unique_ptr<JsonValue> child = jsonValue->GetChild();
64 while (child && child->IsValid()) {
65 const std::string& key = child->GetKey();
66 object->SetPropertyObject(key.c_str(), CreateJsObjectFromJsonValue(vm, child));
67 child = child->GetNext();
68 }
69 return object;
70 } else if (jsonValue->IsNull()) {
71 return JSRef<JSVal>::Make(panda::JSValueRef::Null(vm));
72 } else {
73 return JSRef<JSVal>::Make(panda::JSValueRef::Undefined(vm));
74 }
75 }
76
RegisterCardUpdateCallback(int64_t cardId,const panda::Local<panda::ObjectRef> & obj)77 void RegisterCardUpdateCallback(int64_t cardId, const panda::Local<panda::ObjectRef>& obj)
78 {
79 JSRef<JSObject> object = JSRef<JSObject>::Make(obj);
80 JSRef<JSVal> storageValue = object->GetProperty("localStorage_");
81 if (!storageValue->IsObject()) {
82 LOGE("RegisterCardUpdateCallback: can not get property 'localStorage_'!");
83 return;
84 }
85
86 JSRef<JSObject> storage = JSRef<JSObject>::Cast(storageValue);
87 JSRef<JSVal> setOrCreateVal = storage->GetProperty("setOrCreate");
88 if (!setOrCreateVal->IsFunction()) {
89 LOGE("RegisterCardUpdateCallback: can not get property 'setOrCreate'!");
90 return;
91 }
92
93 JSRef<JSFunc> setOrCreate = JSRef<JSFunc>::Cast(setOrCreateVal);
94 auto id = ContainerScope::CurrentId();
95 auto callback = [storage, setOrCreate, id](const std::string& data) {
96 ContainerScope scope(id);
97 const EcmaVM* vm = storage->GetEcmaVM();
98 CHECK_NULL_VOID(vm);
99 std::unique_ptr<JsonValue> jsonRoot = JsonUtil::ParseJsonString(data);
100 CHECK_NULL_VOID(jsonRoot);
101 auto child = jsonRoot->GetChild();
102 if (!child || !child->IsValid()) {
103 LOGE("update card data error");
104 return;
105 }
106
107 while (child && child->IsValid()) {
108 const std::string& key = child->GetKey();
109 JSRef<JSVal> args[] = {
110 JSRef<JSVal>::Make(JsiValueConvertor::toJsiValueWithVM(vm, key)),
111 CreateJsObjectFromJsonValue(vm, child),
112 };
113 setOrCreate->Call(storage, FUNC_SET_CREATE_ARG_LEN, args);
114 child = child->GetNext();
115 }
116 };
117
118 auto container = Container::Current();
119 if (container->IsFRSCardContainer()) {
120 LOGI("RegisterCardUpdateCallback:Run Card In FRS");
121 auto frontEnd = AceType::DynamicCast<FormFrontendDeclarative>(container->GetCardFrontend(cardId).Upgrade());
122 CHECK_NULL_VOID(frontEnd);
123 auto delegate = frontEnd->GetDelegate();
124 CHECK_NULL_VOID(delegate);
125 delegate->SetUpdateCardDataCallback(callback);
126 delegate->UpdatePageDataImmediately();
127 } else {
128 LOGI("RegisterCardUpdateCallback:Run Card In Host");
129 auto frontEnd = AceType::DynamicCast<CardFrontendDeclarative>(container->GetCardFrontend(cardId).Upgrade());
130 CHECK_NULL_VOID(frontEnd);
131 auto delegate = frontEnd->GetDelegate();
132 CHECK_NULL_VOID(delegate);
133 delegate->SetUpdateCardDataCallback(callback);
134 delegate->UpdatePageDataImmediately();
135 }
136 }
137
UpdateCardRootComponent(const panda::Local<panda::ObjectRef> & obj)138 void UpdateCardRootComponent(const panda::Local<panda::ObjectRef>& obj)
139 {
140 auto* view = static_cast<JSView*>(obj->GetNativePointerField(0));
141 if (!view && !static_cast<JSViewPartialUpdate*>(view) && !static_cast<JSViewFullUpdate*>(view)) {
142 LOGE("UpdateCardRootComponent: argument provided is not a View!");
143 return;
144 }
145
146 auto container = Container::Current();
147 if (container && container->IsUseNewPipeline()) {
148 // Set Partial Update
149 Container::SetCurrentUsePartialUpdate(!view->isFullUpdate());
150
151 auto cardId = CardScope::CurrentId();
152 view->SetCardId(cardId);
153
154 RegisterCardUpdateCallback(cardId, obj);
155
156 RefPtr<NG::PageRouterManager> pageRouterManager;
157
158 if (container->IsFRSCardContainer()) {
159 LOGI("Run Card In FRS");
160 auto frontEnd = AceType::DynamicCast<FormFrontendDeclarative>(container->GetCardFrontend(cardId).Upgrade());
161 CHECK_NULL_VOID(frontEnd);
162 auto delegate = frontEnd->GetDelegate();
163 CHECK_NULL_VOID(delegate);
164 pageRouterManager = delegate->GetPageRouterManager();
165 } else {
166 LOGI("Run Card In Host");
167 auto frontEnd = AceType::DynamicCast<CardFrontendDeclarative>(container->GetCardFrontend(cardId).Upgrade());
168 CHECK_NULL_VOID(frontEnd);
169 auto delegate = frontEnd->GetDelegate();
170 CHECK_NULL_VOID(delegate);
171 pageRouterManager = delegate->GetPageRouterManager();
172 }
173 CHECK_NULL_VOID(pageRouterManager);
174 auto pageNode = pageRouterManager->GetCurrentPageNode();
175 CHECK_NULL_VOID(pageNode);
176
177 auto pageRootNode = AceType::DynamicCast<NG::UINode>(view->CreateViewNode());
178 CHECK_NULL_VOID(pageRootNode);
179 pageRootNode->MountToParent(pageNode);
180
181 // update page life cycle function.
182 auto pagePattern = pageNode->GetPattern<NG::PagePattern>();
183 CHECK_NULL_VOID(pagePattern);
184 pagePattern->SetOnPageShow([weak = Referenced::WeakClaim(view)]() {
185 auto view = weak.Upgrade();
186 if (view) {
187 view->FireOnShow();
188 }
189 });
190 pagePattern->SetOnPageHide([weak = Referenced::WeakClaim(view)]() {
191 auto view = weak.Upgrade();
192 if (view) {
193 view->FireOnHide();
194 }
195 });
196 pagePattern->SetOnBackPressed([weak = Referenced::WeakClaim(view)]() {
197 auto view = weak.Upgrade();
198 if (view) {
199 return view->FireOnBackPress();
200 }
201 return false;
202 });
203 return;
204 } else {
205 LOGE("eTSCard only support NG structure");
206 }
207 }
208
JsLoadDocument(panda::JsiRuntimeCallInfo * runtimeCallInfo)209 panda::Local<panda::JSValueRef> JsLoadDocument(panda::JsiRuntimeCallInfo* runtimeCallInfo)
210 {
211 LOGD("Load Document start");
212 EcmaVM* vm = runtimeCallInfo->GetVM();
213 int32_t argc = runtimeCallInfo->GetArgsNumber();
214 if (argc != 1) {
215 LOGE("The arg is wrong, must have one argument");
216 return panda::JSValueRef::Undefined(vm);
217 }
218 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
219 if (!firstArg->IsObject()) {
220 LOGE("The arg is wrong, value must be object");
221 return panda::JSValueRef::Undefined(vm);
222 }
223
224 panda::Local<panda::ObjectRef> obj = firstArg->ToObject(vm);
225 #if defined(PREVIEW)
226 panda::Global<panda::ObjectRef> rootView(vm, obj->ToObject(vm));
227 auto runtime = JsiDeclarativeEngineInstance::GetCurrentRuntime();
228 shared_ptr<ArkJSRuntime> arkRuntime = std::static_pointer_cast<ArkJSRuntime>(runtime);
229 arkRuntime->AddRootView(rootView);
230 #endif
231 UpdateRootComponent(obj);
232
233 return panda::JSValueRef::Undefined(vm);
234 }
235
JsRegisterNamedRoute(panda::JsiRuntimeCallInfo * runtimeCallInfo)236 panda::Local<panda::JSValueRef> JsRegisterNamedRoute(panda::JsiRuntimeCallInfo* runtimeCallInfo)
237 {
238 LOGD("Register NamedRoute start");
239 EcmaVM* vm = runtimeCallInfo->GetVM();
240 int32_t argc = runtimeCallInfo->GetArgsNumber();
241 // will need three arguments
242 if (argc != 3) {
243 LOGE("The arg is wrong, must have three arguments");
244 return panda::JSValueRef::Undefined(vm);
245 }
246 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
247 if (!firstArg->IsFunction()) {
248 LOGE("The arg is wrong, value must be function");
249 return panda::JSValueRef::Undefined(vm);
250 }
251 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
252 if (!secondArg->IsString()) {
253 LOGE("The arg is wrong, value must be string");
254 return panda::JSValueRef::Undefined(vm);
255 }
256 Local<JSValueRef> thirdArg = runtimeCallInfo->GetCallArgRef(2);
257 if (!thirdArg->IsObject()) {
258 LOGE("The arg is wrong, value must be object");
259 return panda::JSValueRef::Undefined(vm);
260 }
261
262 auto engine = EngineHelper::GetEngine(Container::CurrentId());
263 CHECK_NULL_RETURN(engine, panda::JSValueRef::Undefined(vm));
264 auto jsiEngine = AceType::DynamicCast<JsiDeclarativeEngine>(engine);
265 CHECK_NULL_RETURN(jsiEngine, panda::JSValueRef::Undefined(vm));
266
267 jsiEngine->AddToNamedRouterMap(panda::Global<panda::FunctionRef>(vm, Local<panda::FunctionRef>(firstArg)),
268 secondArg->ToString(vm)->ToString(), thirdArg->ToObject(vm));
269
270 return panda::JSValueRef::Undefined(vm);
271 }
272
JSPostCardAction(panda::JsiRuntimeCallInfo * runtimeCallInfo)273 panda::Local<panda::JSValueRef> JSPostCardAction(panda::JsiRuntimeCallInfo* runtimeCallInfo)
274 {
275 EcmaVM* vm = runtimeCallInfo->GetVM();
276 #if defined(PREVIEW)
277 LOGW("[Engine Log] The postCardAction interface in the Previewer is a mocked implementation and"
278 "may behave differently than an real device.");
279 return panda::JSValueRef::Undefined(vm);
280 #endif
281 int32_t argc = runtimeCallInfo->GetArgsNumber();
282 if (argc > 2) {
283 LOGE("The arg is wrong, must have no more than two argument");
284 return panda::JSValueRef::Undefined(vm);
285 }
286 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
287 if (!firstArg->IsObject()) {
288 LOGE("The arg is wrong, value must be IsObject");
289 return panda::JSValueRef::Undefined(vm);
290 }
291
292 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
293 if (!secondArg->IsObject()) {
294 LOGE("The arg is wrong, value must be object");
295 return panda::JSValueRef::Undefined(vm);
296 }
297
298 panda::Local<panda::ObjectRef> obj = firstArg->ToObject(vm);
299 auto* view = static_cast<JSView*>(obj->GetNativePointerField(0));
300 if (!view && !static_cast<JSViewPartialUpdate*>(view) && !static_cast<JSViewFullUpdate*>(view)) {
301 LOGE("JSPostCardAction: argument provided is not a View!");
302 return panda::JSValueRef::Undefined(vm);
303 }
304
305 auto value = panda::JSON::Stringify(vm, secondArg);
306 if (!value->IsString()) {
307 LOGE("The second arg is wrong");
308 return panda::JSValueRef::Undefined(vm);
309 }
310 auto valueStr = panda::Local<panda::StringRef>(value);
311 auto action = valueStr->ToString();
312
313 #if !defined(NG_BUILD)
314 int64_t cardId = view->GetCardId();
315 auto container = Container::Current();
316 if (container && container->IsUseNewPipeline()) {
317 if (container->IsFRSCardContainer()) {
318 LOGE("Form PostCardAction in FRS");
319 auto frontEnd = AceType::DynamicCast<FormFrontendDeclarative>(container->GetCardFrontend(cardId).Upgrade());
320 CHECK_NULL_RETURN(frontEnd, panda::JSValueRef::Undefined(vm));
321 auto delegate = frontEnd->GetDelegate();
322 CHECK_NULL_RETURN(delegate, panda::JSValueRef::Undefined(vm));
323 delegate->FireCardAction(action);
324 } else {
325 LOGE("Form PostCardAction in HOST");
326 auto frontEnd = AceType::DynamicCast<CardFrontendDeclarative>(container->GetCardFrontend(cardId).Upgrade());
327 CHECK_NULL_RETURN(frontEnd, panda::JSValueRef::Undefined(vm));
328 auto delegate = frontEnd->GetDelegate();
329 CHECK_NULL_RETURN(delegate, panda::JSValueRef::Undefined(vm));
330 delegate->FireCardAction(action);
331 }
332 }
333 #endif
334 return panda::JSValueRef::Undefined(vm);
335 }
336
JsLoadEtsCard(panda::JsiRuntimeCallInfo * runtimeCallInfo)337 panda::Local<panda::JSValueRef> JsLoadEtsCard(panda::JsiRuntimeCallInfo* runtimeCallInfo)
338 {
339 LOGI("Load eTS Card start");
340 EcmaVM* vm = runtimeCallInfo->GetVM();
341 int32_t argc = runtimeCallInfo->GetArgsNumber();
342 if (argc > 2) {
343 LOGE("The arg is wrong, must have no more than two argument");
344 return panda::JSValueRef::Undefined(vm);
345 }
346 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
347 if (!firstArg->IsObject()) {
348 LOGE("The arg is wrong, value must be object");
349 return panda::JSValueRef::Undefined(vm);
350 }
351
352 panda::Local<panda::ObjectRef> obj = firstArg->ToObject(vm);
353 UpdateCardRootComponent(obj);
354
355 return panda::JSValueRef::Undefined(vm);
356 }
357
358 #if defined(PREVIEW)
JsPreviewerComponent(panda::JsiRuntimeCallInfo * runtimeCallInfo)359 panda::Local<panda::JSValueRef> JsPreviewerComponent(panda::JsiRuntimeCallInfo* runtimeCallInfo)
360 {
361 LOGD("PreviewerComponent start");
362 EcmaVM* vm = runtimeCallInfo->GetVM();
363
364 auto runtime = JsiDeclarativeEngineInstance::GetCurrentRuntime();
365 shared_ptr<ArkJSRuntime> arkRuntime = std::static_pointer_cast<ArkJSRuntime>(runtime);
366 std::string requiredComponentName = arkRuntime->GetRequiredComponent();
367 panda::Global<panda::ObjectRef> obj = arkRuntime->GetPreviewComponent(vm, requiredComponentName);
368 if (obj->IsUndefined()) {
369 LOGE("Get PreviewComponent object from map failed");
370 return panda::JSValueRef::Undefined(vm);
371 }
372 UpdateRootComponent(obj.ToLocal());
373
374 return panda::JSValueRef::Undefined(vm);
375 }
376
JsGetPreviewComponentFlag(panda::JsiRuntimeCallInfo * runtimeCallInfo)377 panda::Local<panda::JSValueRef> JsGetPreviewComponentFlag(panda::JsiRuntimeCallInfo* runtimeCallInfo)
378 {
379 LOGD("Get PreviewComponentFlag start");
380 EcmaVM* vm = runtimeCallInfo->GetVM();
381
382 auto runtime = JsiDeclarativeEngineInstance::GetCurrentRuntime();
383 shared_ptr<ArkJSRuntime> arkRuntime = std::static_pointer_cast<ArkJSRuntime>(runtime);
384 bool isComponentPreview = arkRuntime->GetPreviewFlag();
385 if (!isComponentPreview) {
386 return panda::JSValueRef::False(vm);
387 }
388 return panda::JSValueRef::True(vm);
389 }
390
JsStorePreviewComponents(panda::JsiRuntimeCallInfo * runtimeCallInfo)391 panda::Local<panda::JSValueRef> JsStorePreviewComponents(panda::JsiRuntimeCallInfo* runtimeCallInfo)
392 {
393 LOGD("Store PreviewerComponents start");
394 EcmaVM* vm = runtimeCallInfo->GetVM();
395
396 auto runtime = JsiDeclarativeEngineInstance::GetCurrentRuntime();
397 shared_ptr<ArkJSRuntime> arkRuntime = std::static_pointer_cast<ArkJSRuntime>(runtime);
398 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
399 if (!firstArg->IsNumber()) {
400 LOGE("The first value must be a number when calling JsStorePreviewComponents");
401 return panda::JSValueRef::Undefined(vm);
402 }
403 panda::Local<NumberRef> componentNum = firstArg->ToNumber(vm);
404 uint32_t numOfComponent = componentNum->Value();
405 for (uint32_t index = 1; index <= numOfComponent * 2; index++) { // 2: each component pass two args, name and itself
406 Local<JSValueRef> componentName = runtimeCallInfo->GetCallArgRef(index);
407 if (!componentName->IsString()) {
408 LOGE("The %{private}d componentName passed by StorePreviewComponents is not a string", index);
409 return panda::JSValueRef::Undefined(vm);
410 }
411 std::string name = componentName->ToString(vm)->ToString();
412 Local<JSValueRef> componentObj = runtimeCallInfo->GetCallArgRef(++index);
413 if (componentObj->IsUndefined()) {
414 LOGE("The %{private}d component passed by StorePreviewComponents is undefined", index);
415 return panda::JSValueRef::Undefined(vm);
416 }
417 panda::Global<panda::ObjectRef> obj(vm, componentObj->ToObject(vm));
418 arkRuntime->AddPreviewComponent(name, obj);
419 }
420
421 return panda::JSValueRef::Undefined(vm);
422 }
423
JsGetRootView(panda::JsiRuntimeCallInfo * runtimeCallInfo)424 panda::Local<panda::JSValueRef> JsGetRootView(panda::JsiRuntimeCallInfo* runtimeCallInfo)
425 {
426 LOGD("JsGetRootView");
427 auto runtime = JsiDeclarativeEngineInstance::GetCurrentRuntime();
428 shared_ptr<ArkJSRuntime> arkRuntime = std::static_pointer_cast<ArkJSRuntime>(runtime);
429 return arkRuntime->GetRootView().ToLocal();
430 }
431 #endif
432
JsDumpMemoryStats(panda::JsiRuntimeCallInfo * runtimeCallInfo)433 panda::Local<panda::JSValueRef> JsDumpMemoryStats(panda::JsiRuntimeCallInfo* runtimeCallInfo)
434 {
435 LOGD("dumpMemoryStats: Not Implemented for ARK. UnSupported");
436 EcmaVM* vm = runtimeCallInfo->GetVM();
437 return panda::JSValueRef::Undefined(vm);
438 }
439
JsGetI18nResource(panda::JsiRuntimeCallInfo * runtimeCallInfo)440 panda::Local<panda::JSValueRef> JsGetI18nResource(panda::JsiRuntimeCallInfo* runtimeCallInfo)
441 {
442 LOGD("JsGetI18nResource");
443 EcmaVM* vm = runtimeCallInfo->GetVM();
444 int32_t argc = runtimeCallInfo->GetArgsNumber();
445 if (vm == nullptr) {
446 LOGE("The EcmaVM is null");
447 return panda::JSValueRef::Undefined(vm);
448 }
449 if (argc != 2 && argc != 1) {
450 LOGE("The arg is wrong, it is supposed to have one or two arguments");
451 return panda::JSValueRef::Undefined(vm);
452 }
453 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
454 if (!firstArg->IsString()) {
455 LOGE("The arg is wrong, value must be string");
456 return panda::JSValueRef::Undefined(vm);
457 }
458
459 std::vector<std::string> splitStr;
460 std::string str = firstArg->ToString(vm)->ToString();
461 StringUtils::SplitStr(str, ".", splitStr);
462 if (splitStr.size() != 2) {
463 LOGE("input string res value must can be split by dot");
464 return panda::JSValueRef::Undefined(vm);
465 }
466
467 auto targetStringKey = splitStr[0];
468 auto targetStringKeyValue = splitStr[1];
469 auto resultStrJson = JsiDeclarativeEngineInstance::GetI18nStringResource(targetStringKey, targetStringKeyValue);
470 auto resultStr = resultStrJson->GetString();
471 if (argc == 2) {
472 panda::LocalScope scope(vm);
473 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
474 if (secondArg->IsArray(vm)) {
475 auto arrayVal = panda::Local<panda::ArrayRef>(secondArg);
476 auto len = arrayVal->Length(vm);
477 std::vector<std::string> arrayResult;
478 for (auto i = 0U; i < len; i++) {
479 auto subItemVal = panda::ArrayRef::GetValueAt(vm, arrayVal, i);
480 if (!subItemVal->IsString()) {
481 arrayResult.emplace_back(std::string());
482 continue;
483 }
484 auto itemVal = panda::Local<panda::StringRef>(subItemVal);
485 arrayResult.emplace_back(itemVal->ToString());
486 }
487 ReplacePlaceHolderArray(resultStr, arrayResult);
488 } else if (secondArg->IsObject()) {
489 auto value = panda::JSON::Stringify(vm, secondArg);
490 if (value->IsString()) {
491 auto valueStr = panda::Local<panda::StringRef>(value);
492 std::unique_ptr<JsonValue> argsPtr = JsonUtil::ParseJsonString(valueStr->ToString());
493 ReplacePlaceHolder(resultStr, argsPtr);
494 }
495 } else if (secondArg->IsNumber()) {
496 double count = secondArg->ToNumber(vm)->Value();
497 auto pluralChoice = Localization::GetInstance()->PluralRulesFormat(count);
498 if (!pluralChoice.empty()) {
499 resultStr = ParserPluralResource(resultStrJson, pluralChoice, str);
500 }
501 }
502 }
503
504 return panda::StringRef::NewFromUtf8(vm, resultStr.c_str());
505 }
506
JsGetMediaResource(panda::JsiRuntimeCallInfo * runtimeCallInfo)507 panda::Local<panda::JSValueRef> JsGetMediaResource(panda::JsiRuntimeCallInfo* runtimeCallInfo)
508 {
509 LOGD("JsGetMediaResource");
510 EcmaVM* vm = runtimeCallInfo->GetVM();
511 int32_t argc = runtimeCallInfo->GetArgsNumber();
512 if (argc != 1) {
513 LOGE("The arg is wrong, must have one argument");
514 return panda::JSValueRef::Undefined(vm);
515 }
516 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
517 if (!firstArg->IsString()) {
518 LOGE("The arg is wrong, value must be string");
519 return panda::JSValueRef::Undefined(vm);
520 }
521
522 std::string targetMediaFileName = firstArg->ToString(vm)->ToString();
523 std::string filePath = JsiDeclarativeEngineInstance::GetMediaResource(targetMediaFileName);
524 return panda::StringRef::NewFromUtf8(vm, filePath.c_str());
525 }
526
JsGetFrontendDelegate()527 RefPtr<FrontendDelegate> JsGetFrontendDelegate()
528 {
529 auto engine = EngineHelper::GetEngine(Container::CurrentId());
530 auto jsiEngine = AceType::DynamicCast<JsiDeclarativeEngine>(engine);
531 if (!jsiEngine) {
532 LOGE("jsiEngine is null");
533 return nullptr;
534 }
535 auto engineInstance = jsiEngine->GetEngineInstance();
536 if (engineInstance == nullptr) {
537 LOGE("engineInstance is null!");
538 return nullptr;
539 }
540 return engineInstance->GetDelegate();
541 }
542
JsGetInspectorNodes(panda::JsiRuntimeCallInfo * runtimeCallInfo)543 panda::Local<panda::JSValueRef> JsGetInspectorNodes(panda::JsiRuntimeCallInfo* runtimeCallInfo)
544 {
545 EcmaVM* vm = runtimeCallInfo->GetVM();
546 if (vm == nullptr) {
547 LOGE("The EcmaVM is null");
548 return panda::JSValueRef::Undefined(vm);
549 }
550 auto declarativeDelegate = AceType::DynamicCast<FrontendDelegateDeclarative>(JsGetFrontendDelegate());
551 if (!declarativeDelegate) {
552 LOGE("declarativeDelegate is null!");
553 return panda::JSValueRef::Undefined(vm);
554 }
555 auto accessibilityManager = declarativeDelegate->GetJSAccessibilityManager();
556 auto nodeInfos = accessibilityManager->DumpComposedElementsToJson();
557 return panda::JSON::Parse(vm, panda::StringRef::NewFromUtf8(vm, nodeInfos->ToString().c_str()));
558 }
559
JsGetInspectorNodeById(panda::JsiRuntimeCallInfo * runtimeCallInfo)560 panda::Local<panda::JSValueRef> JsGetInspectorNodeById(panda::JsiRuntimeCallInfo* runtimeCallInfo)
561 {
562 EcmaVM* vm = runtimeCallInfo->GetVM();
563 int32_t argc = runtimeCallInfo->GetArgsNumber();
564 if (vm == nullptr) {
565 LOGE("The EcmaVM is null");
566 return panda::JSValueRef::Undefined(vm);
567 }
568 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
569 if (argc < 1 || !firstArg->IsNumber()) {
570 LOGE("The arg is wrong, must have one argument");
571 return panda::JSValueRef::Undefined(vm);
572 }
573 auto declarativeDelegate = OHOS::Ace::AceType::DynamicCast<FrontendDelegateDeclarative>(JsGetFrontendDelegate());
574 if (!declarativeDelegate) {
575 LOGE("declarativeDelegate is null!");
576 return panda::JSValueRef::Undefined(vm);
577 }
578 auto accessibilityManager = declarativeDelegate->GetJSAccessibilityManager();
579 if (!accessibilityManager) {
580 LOGE("accessibilityManager is null!");
581 return panda::JSValueRef::Undefined(vm);
582 }
583 int32_t intValue = firstArg->Int32Value(vm);
584 auto nodeInfo = accessibilityManager->DumpComposedElementToJson(intValue);
585 return panda::JSON::Parse(vm, panda::StringRef::NewFromUtf8(vm, nodeInfo->ToString().c_str()));
586 }
587
JsGetInspectorTree(panda::JsiRuntimeCallInfo * runtimeCallInfo)588 panda::Local<panda::JSValueRef> JsGetInspectorTree(panda::JsiRuntimeCallInfo* runtimeCallInfo)
589 {
590 EcmaVM* vm = runtimeCallInfo->GetVM();
591 if (vm == nullptr) {
592 LOGE("The EcmaVM is null");
593 return panda::JSValueRef::Undefined(vm);
594 }
595 auto container = Container::Current();
596 if (!container) {
597 LOGW("container is null");
598 return panda::JSValueRef::Undefined(vm);
599 }
600
601 if (container->IsUseNewPipeline()) {
602 auto nodeInfos = NG::Inspector::GetInspector();
603 return panda::JSON::Parse(vm, panda::StringRef::NewFromUtf8(vm, nodeInfos.c_str()));
604 }
605 #if !defined(NG_BUILD)
606 auto pipelineContext = AceType::DynamicCast<PipelineContext>(container->GetPipelineContext());
607 if (pipelineContext == nullptr) {
608 LOGE("pipeline is null");
609 return panda::JSValueRef::Undefined(vm);
610 }
611 auto nodeInfos = V2::Inspector::GetInspectorTree(pipelineContext);
612 return panda::JSON::Parse(vm, panda::StringRef::NewFromUtf8(vm, nodeInfos.c_str()));
613 #else
614 return panda::JSValueRef::Undefined(vm);
615 #endif
616 }
617
JsGetInspectorByKey(panda::JsiRuntimeCallInfo * runtimeCallInfo)618 panda::Local<panda::JSValueRef> JsGetInspectorByKey(panda::JsiRuntimeCallInfo* runtimeCallInfo)
619 {
620 EcmaVM* vm = runtimeCallInfo->GetVM();
621 auto argc = runtimeCallInfo->GetArgsNumber();
622 if (vm == nullptr) {
623 LOGE("The EcmaVM is null");
624 return panda::JSValueRef::Undefined(vm);
625 }
626 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
627 if (argc < 1 || !firstArg->IsString()) {
628 LOGE("The arg is wrong, must have one string argument");
629 return panda::JSValueRef::Undefined(vm);
630 }
631 auto container = Container::Current();
632 if (!container) {
633 LOGW("container is null");
634 return panda::JSValueRef::Undefined(vm);
635 }
636 std::string key = firstArg->ToString(vm)->ToString();
637 if (container->IsUseNewPipeline()) {
638 auto resultStr = NG::Inspector::GetInspectorNodeByKey(key);
639 return panda::StringRef::NewFromUtf8(vm, resultStr.c_str());
640 }
641 #if !defined(NG_BUILD)
642 auto pipelineContext = AceType::DynamicCast<PipelineContext>(container->GetPipelineContext());
643 if (pipelineContext == nullptr) {
644 LOGE("pipelineContext==nullptr");
645 return panda::JSValueRef::Undefined(vm);
646 }
647 auto resultStr = V2::Inspector::GetInspectorNodeByKey(pipelineContext, key);
648 return panda::StringRef::NewFromUtf8(vm, resultStr.c_str());
649 #else
650 return panda::JSValueRef::Undefined(vm);
651 #endif
652 }
653
JsSendEventByKey(panda::JsiRuntimeCallInfo * runtimeCallInfo)654 panda::Local<panda::JSValueRef> JsSendEventByKey(panda::JsiRuntimeCallInfo* runtimeCallInfo)
655 {
656 EcmaVM* vm = runtimeCallInfo->GetVM();
657 auto argc = runtimeCallInfo->GetArgsNumber();
658 if (vm == nullptr) {
659 LOGE("The EcmaVM is null");
660 return panda::JSValueRef::Undefined(vm);
661 }
662 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
663 if (argc < 3 || !firstArg->IsString()) { // 3: arg numbers
664 LOGE("The arg is wrong, must have one string argument");
665 return panda::JSValueRef::Undefined(vm);
666 }
667 auto container = Container::Current();
668 if (!container) {
669 LOGW("container is null");
670 return panda::JSValueRef::Undefined(vm);
671 }
672
673 std::string key = firstArg->ToString(vm)->ToString();
674 auto action = runtimeCallInfo->GetCallArgRef(1)->Int32Value(vm);
675 auto params = runtimeCallInfo->GetCallArgRef(2)->ToString(vm)->ToString();
676 if (container->IsUseNewPipeline()) {
677 auto result = NG::Inspector::SendEventByKey(key, action, params);
678 return panda::BooleanRef::New(vm, result);
679 }
680 #if !defined(NG_BUILD)
681 auto pipelineContext = AceType::DynamicCast<PipelineContext>(container->GetPipelineContext());
682 if (pipelineContext == nullptr) {
683 LOGE("pipelineContext==nullptr");
684 return panda::JSValueRef::Undefined(vm);
685 }
686 auto result = V2::Inspector::SendEventByKey(pipelineContext, key, action, params);
687 return panda::BooleanRef::New(vm, result);
688 #else
689 return panda::JSValueRef::Undefined(vm);
690 #endif
691 }
692
GetTouchPointFromJS(const JsiObject & value)693 static TouchEvent GetTouchPointFromJS(const JsiObject& value)
694 {
695 TouchEvent touchPoint;
696
697 auto type = value->GetProperty("type");
698 touchPoint.type = static_cast<TouchType>(type->ToNumber<int32_t>());
699
700 auto id = value->GetProperty("id");
701 touchPoint.id = id->ToNumber<int32_t>();
702
703 auto x = value->GetProperty("x");
704 touchPoint.x = x->ToNumber<float>();
705
706 auto y = value->GetProperty("y");
707 touchPoint.y = y->ToNumber<float>();
708
709 touchPoint.time = std::chrono::high_resolution_clock::now();
710
711 return touchPoint;
712 }
713
JsSendTouchEvent(panda::JsiRuntimeCallInfo * runtimeCallInfo)714 panda::Local<panda::JSValueRef> JsSendTouchEvent(panda::JsiRuntimeCallInfo* runtimeCallInfo)
715 {
716 EcmaVM* vm = runtimeCallInfo->GetVM();
717 auto argc = runtimeCallInfo->GetArgsNumber();
718 if (vm == nullptr) {
719 LOGE("The EcmaVM is null");
720 return panda::JSValueRef::Undefined(vm);
721 }
722 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
723 if (argc < 1 || !firstArg->IsObject()) {
724 LOGE("The arg is wrong, must have one object argument");
725 return panda::JSValueRef::Undefined(vm);
726 }
727
728 auto container = Container::Current();
729 if (!container) {
730 LOGW("container is null");
731 return panda::JSValueRef::Undefined(vm);
732 }
733 auto pipelineContext = container->GetPipelineContext();
734 if (pipelineContext == nullptr) {
735 LOGE("pipelineContext==nullptr");
736 return panda::JSValueRef::Undefined(vm);
737 }
738 JsiObject obj(firstArg);
739 TouchEvent touchPoint = GetTouchPointFromJS(obj);
740 auto result = pipelineContext->GetTaskExecutor()->PostTask(
741 [pipelineContext, touchPoint]() { pipelineContext->OnTouchEvent(touchPoint); }, TaskExecutor::TaskType::UI);
742 return panda::BooleanRef::New(vm, result);
743 }
744
GetKeyEventFromJS(const JsiObject & value)745 static KeyEvent GetKeyEventFromJS(const JsiObject& value)
746 {
747 auto type = value->GetProperty("type");
748 auto action = static_cast<KeyAction>(type->ToNumber<int32_t>());
749
750 auto jsKeyCode = value->GetProperty("keyCode");
751 auto code = static_cast<KeyCode>(jsKeyCode->ToNumber<int32_t>());
752
753 KeyEvent keyEvent(code, action);
754
755 auto jsKeySource = value->GetProperty("keySource");
756 keyEvent.sourceType = static_cast<SourceType>(jsKeySource->ToNumber<int32_t>());
757
758 auto jsDeviceId = value->GetProperty("deviceId");
759 keyEvent.deviceId = jsDeviceId->ToNumber<int32_t>();
760
761 auto jsMetaKey = value->GetProperty("metaKey");
762 keyEvent.metaKey = jsMetaKey->ToNumber<int32_t>();
763
764 auto jsTimestamp = value->GetProperty("timestamp");
765 auto timeStamp = jsTimestamp->ToNumber<int64_t>();
766 keyEvent.SetTimeStamp(timeStamp);
767
768 return keyEvent;
769 }
770
JsSendKeyEvent(panda::JsiRuntimeCallInfo * runtimeCallInfo)771 panda::Local<panda::JSValueRef> JsSendKeyEvent(panda::JsiRuntimeCallInfo* runtimeCallInfo)
772 {
773 EcmaVM* vm = runtimeCallInfo->GetVM();
774 auto argc = runtimeCallInfo->GetArgsNumber();
775 if (vm == nullptr) {
776 LOGE("The EcmaVM is null");
777 return panda::JSValueRef::Undefined(vm);
778 }
779 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
780 if (argc < 1 || !firstArg->IsObject()) {
781 LOGE("The arg is wrong, must have one object argument");
782 return panda::JSValueRef::Undefined(vm);
783 }
784
785 auto container = Container::Current();
786 if (!container) {
787 LOGW("container is null");
788 return panda::JSValueRef::Undefined(vm);
789 }
790 auto pipelineContext = container->GetPipelineContext();
791 if (pipelineContext == nullptr) {
792 LOGE("pipelineContext==nullptr");
793 return panda::JSValueRef::Undefined(vm);
794 }
795 JsiObject obj(firstArg);
796 KeyEvent keyEvent = GetKeyEventFromJS(obj);
797 auto result = pipelineContext->GetTaskExecutor()->PostTask(
798 [pipelineContext, keyEvent]() { pipelineContext->OnKeyEvent(keyEvent); }, TaskExecutor::TaskType::UI);
799 return panda::BooleanRef::New(vm, result);
800 }
801
GetMouseEventFromJS(const JsiObject & value)802 static MouseEvent GetMouseEventFromJS(const JsiObject& value)
803 {
804 MouseEvent mouseEvent;
805
806 auto action = value->GetProperty("action");
807 mouseEvent.action = static_cast<MouseAction>(action->ToNumber<int32_t>());
808
809 auto button = value->GetProperty("button");
810 mouseEvent.button = static_cast<MouseButton>(button->ToNumber<int32_t>());
811
812 auto x = value->GetProperty("x");
813 mouseEvent.x = x->ToNumber<float>();
814 mouseEvent.deltaX = mouseEvent.x;
815
816 auto y = value->GetProperty("y");
817 mouseEvent.y = y->ToNumber<float>();
818 mouseEvent.deltaY = mouseEvent.y;
819
820 mouseEvent.time = std::chrono::high_resolution_clock::now();
821 mouseEvent.sourceType = SourceType::MOUSE;
822 return mouseEvent;
823 }
824
JsSendMouseEvent(panda::JsiRuntimeCallInfo * runtimeCallInfo)825 panda::Local<panda::JSValueRef> JsSendMouseEvent(panda::JsiRuntimeCallInfo* runtimeCallInfo)
826 {
827 EcmaVM* vm = runtimeCallInfo->GetVM();
828 auto argc = runtimeCallInfo->GetArgsNumber();
829 if (vm == nullptr) {
830 LOGE("The EcmaVM is null");
831 return panda::JSValueRef::Undefined(vm);
832 }
833 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
834 if (argc < 1 || !firstArg->IsObject()) {
835 LOGE("The arg is wrong, must have one object argument");
836 return panda::JSValueRef::Undefined(vm);
837 }
838
839 auto container = Container::Current();
840 if (!container) {
841 LOGW("container is null");
842 return panda::JSValueRef::Undefined(vm);
843 }
844 auto pipelineContext = container->GetPipelineContext();
845 if (pipelineContext == nullptr) {
846 LOGE("pipelineContext==nullptr");
847 return panda::JSValueRef::Undefined(vm);
848 }
849 JsiObject obj(firstArg);
850 MouseEvent mouseEvent = GetMouseEventFromJS(obj);
851 auto result = pipelineContext->GetTaskExecutor()->PostTask(
852 [pipelineContext, mouseEvent]() { pipelineContext->OnMouseEvent(mouseEvent); }, TaskExecutor::TaskType::UI);
853 return panda::BooleanRef::New(vm, result);
854 }
855
Vp2Px(panda::JsiRuntimeCallInfo * runtimeCallInfo)856 panda::Local<panda::JSValueRef> Vp2Px(panda::JsiRuntimeCallInfo* runtimeCallInfo)
857 {
858 EcmaVM* vm = runtimeCallInfo->GetVM();
859 int32_t argc = runtimeCallInfo->GetArgsNumber();
860 if (argc != 1) {
861 LOGE("The arg is wrong, must have one argument");
862 return panda::JSValueRef::Undefined(vm);
863 }
864 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
865 if (!firstArg->IsNumber()) {
866 LOGE("The arg is wrong, value must be number");
867 return panda::JSValueRef::Undefined(vm);
868 }
869
870 double vpValue = firstArg->ToNumber(vm)->Value();
871 double density = SystemProperties::GetResolution();
872 double pxValue = vpValue * density;
873 return panda::NumberRef::New(vm, pxValue);
874 }
875
Px2Vp(panda::JsiRuntimeCallInfo * runtimeCallInfo)876 panda::Local<panda::JSValueRef> Px2Vp(panda::JsiRuntimeCallInfo* runtimeCallInfo)
877 {
878 EcmaVM* vm = runtimeCallInfo->GetVM();
879 int32_t argc = runtimeCallInfo->GetArgsNumber();
880 if (argc != 1) {
881 LOGE("The arg is wrong, must have one argument");
882 return panda::JSValueRef::Undefined(vm);
883 }
884 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
885 if (!firstArg->IsNumber()) {
886 LOGE("The arg is wrong, value must be number");
887 return panda::JSValueRef::Undefined(vm);
888 }
889 double density = SystemProperties::GetResolution();
890 if (NearZero(density)) {
891 LOGE("The density cannot be zero");
892 return panda::JSValueRef::Undefined(vm);
893 }
894
895 double pxValue = firstArg->ToNumber(vm)->Value();
896 double vpValue = pxValue / density;
897
898 return panda::NumberRef::New(vm, vpValue);
899 }
900
Fp2Px(panda::JsiRuntimeCallInfo * runtimeCallInfo)901 panda::Local<panda::JSValueRef> Fp2Px(panda::JsiRuntimeCallInfo* runtimeCallInfo)
902 {
903 EcmaVM* vm = runtimeCallInfo->GetVM();
904 int32_t argc = runtimeCallInfo->GetArgsNumber();
905 if (argc != 1) {
906 LOGE("The arg is wrong, must have one argument");
907 return panda::JSValueRef::Undefined(vm);
908 }
909 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
910 if (!firstArg->IsNumber()) {
911 LOGE("The arg is wrong, value must be number");
912 return panda::JSValueRef::Undefined(vm);
913 }
914
915 double density = SystemProperties::GetResolution();
916 double fpValue = firstArg->ToNumber(vm)->Value();
917
918 auto container = Container::Current();
919 if (!container) {
920 LOGW("container is null");
921 return panda::JSValueRef::Undefined(vm);
922 }
923 auto pipelineContext = container->GetPipelineContext();
924 double fontScale = 1.0;
925 if (pipelineContext) {
926 fontScale = pipelineContext->GetFontScale();
927 }
928 double pxValue = fpValue * density * fontScale;
929 return panda::NumberRef::New(vm, pxValue);
930 }
931
Px2Fp(panda::JsiRuntimeCallInfo * runtimeCallInfo)932 panda::Local<panda::JSValueRef> Px2Fp(panda::JsiRuntimeCallInfo* runtimeCallInfo)
933 {
934 EcmaVM* vm = runtimeCallInfo->GetVM();
935 int32_t argc = runtimeCallInfo->GetArgsNumber();
936 if (argc != 1) {
937 LOGE("The arg is wrong, must have one argument");
938 return panda::JSValueRef::Undefined(vm);
939 }
940 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
941 if (!firstArg->IsNumber()) {
942 LOGE("The arg is wrong, value must be number");
943 return panda::JSValueRef::Undefined(vm);
944 }
945 double density = SystemProperties::GetResolution();
946 if (NearZero(density)) {
947 LOGE("The density cannot be zero");
948 return panda::JSValueRef::Undefined(vm);
949 }
950
951 double pxValue = firstArg->ToNumber(vm)->Value();
952 auto container = Container::Current();
953 if (!container) {
954 LOGW("container is null");
955 return panda::JSValueRef::Undefined(vm);
956 }
957 auto pipelineContext = container->GetPipelineContext();
958 double fontScale = 1.0;
959 if (pipelineContext) {
960 fontScale = pipelineContext->GetFontScale();
961 }
962 double ratio = density * fontScale;
963 double fpValue = pxValue / ratio;
964 return panda::NumberRef::New(vm, fpValue);
965 }
966
Lpx2Px(panda::JsiRuntimeCallInfo * runtimeCallInfo)967 panda::Local<panda::JSValueRef> Lpx2Px(panda::JsiRuntimeCallInfo* runtimeCallInfo)
968 {
969 EcmaVM* vm = runtimeCallInfo->GetVM();
970 int32_t argc = runtimeCallInfo->GetArgsNumber();
971 if (argc != 1) {
972 LOGE("The arg is wrong, must have one argument");
973 return panda::JSValueRef::Undefined(vm);
974 }
975 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
976 if (!firstArg->IsNumber()) {
977 LOGE("The arg is wrong, value must be number");
978 return panda::JSValueRef::Undefined(vm);
979 }
980 auto container = Container::Current();
981 CHECK_NULL_RETURN(container, panda::JSValueRef::Undefined(vm));
982 auto frontend = container->GetFrontend();
983 CHECK_NULL_RETURN(frontend, panda::JSValueRef::Undefined(vm));
984 auto windowConfig = frontend->GetWindowConfig();
985 double lpxValue = firstArg->ToNumber(vm)->Value();
986 double pxValue = lpxValue * windowConfig.GetDesignWidthScale(SystemProperties::GetDeviceWidth());
987 return panda::NumberRef::New(vm, pxValue);
988 }
989
Px2Lpx(panda::JsiRuntimeCallInfo * runtimeCallInfo)990 panda::Local<panda::JSValueRef> Px2Lpx(panda::JsiRuntimeCallInfo* runtimeCallInfo)
991 {
992 EcmaVM* vm = runtimeCallInfo->GetVM();
993 int32_t argc = runtimeCallInfo->GetArgsNumber();
994 if (argc != 1) {
995 LOGE("The arg is wrong, must have one argument");
996 return panda::JSValueRef::Undefined(vm);
997 }
998 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
999 if (!firstArg->IsNumber()) {
1000 LOGE("The arg is wrong, value must be number");
1001 return panda::JSValueRef::Undefined(vm);
1002 }
1003 auto container = Container::Current();
1004 CHECK_NULL_RETURN(container, panda::JSValueRef::Undefined(vm));
1005 auto frontend = container->GetFrontend();
1006 CHECK_NULL_RETURN(frontend, panda::JSValueRef::Undefined(vm));
1007 auto windowConfig = frontend->GetWindowConfig();
1008 double pxValue = firstArg->ToNumber(vm)->Value();
1009 double lpxValue = pxValue / windowConfig.GetDesignWidthScale(SystemProperties::GetDeviceWidth());
1010 return panda::NumberRef::New(vm, lpxValue);
1011 }
1012
SetAppBackgroundColor(panda::JsiRuntimeCallInfo * runtimeCallInfo)1013 panda::Local<panda::JSValueRef> SetAppBackgroundColor(panda::JsiRuntimeCallInfo* runtimeCallInfo)
1014 {
1015 EcmaVM* vm = runtimeCallInfo->GetVM();
1016 int32_t argc = runtimeCallInfo->GetArgsNumber();
1017 if (argc != 1) {
1018 LOGE("The arg is wrong, must have one argument");
1019 return panda::JSValueRef::Undefined(vm);
1020 }
1021 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1022 if (!firstArg->IsString()) {
1023 LOGE("The arg is wrong, value must be number");
1024 return panda::JSValueRef::Undefined(vm);
1025 }
1026 std::string backgroundColorStr = firstArg->ToString(vm)->ToString();
1027 auto container = Container::Current();
1028 if (!container) {
1029 LOGW("container is null");
1030 return panda::JSValueRef::Undefined(vm);
1031 }
1032 auto pipelineContext = container->GetPipelineContext();
1033 if (pipelineContext) {
1034 pipelineContext->SetAppBgColor(Color::FromString(backgroundColorStr));
1035 }
1036 return panda::JSValueRef::Undefined(vm);
1037 }
1038
RequestFocus(panda::JsiRuntimeCallInfo * runtimeCallInfo)1039 panda::Local<panda::JSValueRef> RequestFocus(panda::JsiRuntimeCallInfo* runtimeCallInfo)
1040 {
1041 EcmaVM* vm = runtimeCallInfo->GetVM();
1042 int32_t argc = runtimeCallInfo->GetArgsNumber();
1043 if (vm == nullptr) {
1044 LOGE("The EcmaVM is null");
1045 return panda::JSValueRef::Undefined(vm);
1046 }
1047 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1048 if (argc < 1 || !firstArg->IsString()) {
1049 LOGE("The arg is wrong, must have one object argument");
1050 return panda::JSValueRef::Undefined(vm);
1051 }
1052 std::string inspectorKey = firstArg->ToString(vm)->ToString();
1053
1054 bool result = false;
1055 auto pipelineContext = PipelineContext::GetCurrentContext();
1056 CHECK_NULL_RETURN(pipelineContext, panda::BooleanRef::New(vm, result));
1057 if (!pipelineContext->GetTaskExecutor()) {
1058 LOGE("pipelineContext's task excutor is null");
1059 return panda::BooleanRef::New(vm, result);
1060 }
1061 pipelineContext->GetTaskExecutor()->PostSyncTask(
1062 [pipelineContext, inspectorKey, &result]() { result = pipelineContext->RequestFocus(inspectorKey); },
1063 TaskExecutor::TaskType::UI);
1064 return panda::BooleanRef::New(vm, result);
1065 }
1066
1067 #ifdef FORM_SUPPORTED
JsRegisterFormViews(BindingTarget globalObj,const std::unordered_set<std::string> & formModuleList,bool isReload)1068 void JsRegisterFormViews(BindingTarget globalObj, const std::unordered_set<std::string>& formModuleList, bool isReload)
1069 {
1070 auto runtime = std::static_pointer_cast<ArkJSRuntime>(JsiDeclarativeEngineInstance::GetCurrentRuntime());
1071 if (!runtime) {
1072 LOGE("JsRegisterViews can't find runtime");
1073 return;
1074 }
1075 if (isReload) {
1076 JsBindFormViews(globalObj, formModuleList, isReload);
1077 return;
1078 }
1079 auto vm = runtime->GetEcmaVm();
1080 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "loadEtsCard"),
1081 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), JsLoadEtsCard));
1082 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "postCardAction"),
1083 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), JSPostCardAction));
1084 #if defined(PREVIEW)
1085 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "previewComponent"),
1086 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), JsPreviewerComponent));
1087 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "getPreviewComponentFlag"),
1088 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), JsGetPreviewComponentFlag));
1089 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "storePreviewComponents"),
1090 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), JsStorePreviewComponents));
1091 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "GetRootView"),
1092 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), JsGetRootView));
1093 #endif
1094 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "dumpMemoryStats"),
1095 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), JsDumpMemoryStats));
1096 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "$s"),
1097 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), JsGetI18nResource));
1098 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "$m"),
1099 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), JsGetMediaResource));
1100 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "getInspectorNodes"),
1101 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), JsGetInspectorNodes));
1102 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "getInspectorNodeById"),
1103 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), JsGetInspectorNodeById));
1104 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "getInspectorTree"),
1105 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), JsGetInspectorTree));
1106 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "getInspectorByKey"),
1107 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), JsGetInspectorByKey));
1108 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "sendEventByKey"),
1109 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), JsSendEventByKey));
1110 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "sendTouchEvent"),
1111 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), JsSendTouchEvent));
1112 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "sendKeyEvent"),
1113 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), JsSendKeyEvent));
1114 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "sendMouseEvent"),
1115 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), JsSendMouseEvent));
1116 globalObj->Set(
1117 vm, panda::StringRef::NewFromUtf8(vm, "vp2px"), panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), Vp2Px));
1118 globalObj->Set(
1119 vm, panda::StringRef::NewFromUtf8(vm, "px2vp"), panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), Px2Vp));
1120 globalObj->Set(
1121 vm, panda::StringRef::NewFromUtf8(vm, "fp2px"), panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), Fp2Px));
1122 globalObj->Set(
1123 vm, panda::StringRef::NewFromUtf8(vm, "px2fp"), panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), Px2Fp));
1124 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "lpx2px"),
1125 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), Lpx2Px));
1126 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "px2lpx"),
1127 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), Px2Lpx));
1128 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "setAppBgColor"),
1129 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), SetAppBackgroundColor));
1130
1131 JsBindFormViews(globalObj, formModuleList);
1132
1133 JSObjectTemplate toggleType;
1134 toggleType.Constant("Checkbox", 0);
1135 toggleType.Constant("Switch", 1);
1136 toggleType.Constant("Button", 2); // 2 means index of constant
1137
1138 JSObjectTemplate refreshStatus;
1139 refreshStatus.Constant("Inactive", 0);
1140 refreshStatus.Constant("Drag", 1);
1141 refreshStatus.Constant("OverDrag", 2);
1142 refreshStatus.Constant("Refresh", 3); // 3 means index of constant
1143 refreshStatus.Constant("Done", 4); // 4 means index of constant
1144
1145 JSObjectTemplate mainAxisAlign;
1146 mainAxisAlign.Constant("Start", 1);
1147 mainAxisAlign.Constant("Center", 2); // 2 means index of constant
1148 mainAxisAlign.Constant("End", 3); // 3 means index of constant
1149 mainAxisAlign.Constant("SpaceBetween", 6); // 6 means index of constant
1150 mainAxisAlign.Constant("SpaceAround", 7); // 7 means index of constant
1151
1152 JSObjectTemplate crossAxisAlign;
1153 crossAxisAlign.Constant("Start", 1);
1154
1155 crossAxisAlign.Constant("Center", 2); // 2 means index of constant
1156 crossAxisAlign.Constant("End", 3); // 3 means index of constant
1157 crossAxisAlign.Constant("Stretch", 4); // 4 means index of constant
1158
1159 JSObjectTemplate direction;
1160 direction.Constant("Horizontal", 0);
1161 direction.Constant("Vertical", 1);
1162
1163 JSObjectTemplate loadingProgressStyle;
1164 loadingProgressStyle.Constant("Default", 1);
1165 loadingProgressStyle.Constant("Circular", 2); // 2 means index of constant
1166 loadingProgressStyle.Constant("Orbital", 3); // 3 means index of constant
1167
1168 JSObjectTemplate progressStyle;
1169 progressStyle.Constant("Linear", 0);
1170 progressStyle.Constant("Ring", 1); // 1 means index of constant
1171 progressStyle.Constant("Eclipse", 2); // 2 means index of constant
1172 progressStyle.Constant("ScaleRing", 3); // 3 means index of constant
1173 progressStyle.Constant("Capsule", 4); // 4 means index of constant
1174
1175 JSObjectTemplate stackFit;
1176 stackFit.Constant("Keep", 0);
1177 stackFit.Constant("Stretch", 1);
1178 stackFit.Constant("Inherit", 2); // 2 means index of constant
1179 stackFit.Constant("FirstChild", 3); // 3 means index of constant
1180
1181 JSObjectTemplate overflow;
1182 overflow.Constant("Clip", 0);
1183 overflow.Constant("Observable", 1);
1184
1185 JSObjectTemplate alignment;
1186 alignment.Constant("TopLeft", 0);
1187 alignment.Constant("TopCenter", 1);
1188 alignment.Constant("TopRight", 2); // 2 means index of constant
1189 alignment.Constant("CenterLeft", 3); // 3 means index of constant
1190 alignment.Constant("Center", 4); // 4 means index of constant
1191 alignment.Constant("CenterRight", 5); // 5 means index of constant
1192 alignment.Constant("BottomLeft", 6); // 6 means index of constant
1193 alignment.Constant("BottomCenter", 7); // 7 means index of constant
1194 alignment.Constant("BottomRight", 8); // 8 means index of constant
1195
1196 JSObjectTemplate sliderStyle;
1197 sliderStyle.Constant("OutSet", 0);
1198 sliderStyle.Constant("InSet", 1);
1199
1200 JSObjectTemplate sliderChangeMode;
1201 sliderChangeMode.Constant("Begin", 0);
1202 sliderChangeMode.Constant("Moving", 1);
1203 sliderChangeMode.Constant("End", 2); // 2 means index of constant
1204
1205 JSObjectTemplate pickerStyle;
1206 pickerStyle.Constant("Inline", 0);
1207 pickerStyle.Constant("Block", 1);
1208 pickerStyle.Constant("Fade", 2); // 2 means index of constant
1209
1210 JSObjectTemplate buttonType;
1211 buttonType.Constant("Normal", (int)ButtonType::NORMAL);
1212 buttonType.Constant("Capsule", (int)ButtonType::CAPSULE);
1213 buttonType.Constant("Circle", (int)ButtonType::CIRCLE);
1214 buttonType.Constant("Arc", (int)ButtonType::ARC);
1215
1216 JSObjectTemplate iconPosition;
1217 iconPosition.Constant("Start", 0);
1218 iconPosition.Constant("End", 1);
1219
1220 JSObjectTemplate badgePosition;
1221 badgePosition.Constant("RightTop", 0);
1222 badgePosition.Constant("Right", 1);
1223 badgePosition.Constant("Left", 2); // 2 means index of constant
1224
1225 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "MainAxisAlign"), *mainAxisAlign);
1226 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "CrossAxisAlign"), *crossAxisAlign);
1227 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "Direction"), *direction);
1228 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "StackFit"), *stackFit);
1229 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "Align"), *alignment);
1230 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "Overflow"), *overflow);
1231 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "ButtonType"), *buttonType);
1232 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "LoadingProgressStyle"), *loadingProgressStyle);
1233 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "ProgressStyle"), *progressStyle);
1234 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "ToggleType"), *toggleType);
1235 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "RefreshStatus"), *refreshStatus);
1236 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "SliderStyle"), *sliderStyle);
1237 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "SliderChangeMode"), *sliderChangeMode);
1238 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "IconPosition"), *iconPosition);
1239 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "PickerStyle"), *pickerStyle);
1240 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "BadgePosition"), *badgePosition);
1241 LOGD("View classes and jsCreateDocument, registerObservableObject functions registered.");
1242 }
1243 #endif
1244
JsRegisterViews(BindingTarget globalObj)1245 void JsRegisterViews(BindingTarget globalObj)
1246 {
1247 auto runtime = std::static_pointer_cast<ArkJSRuntime>(JsiDeclarativeEngineInstance::GetCurrentRuntime());
1248 if (!runtime) {
1249 LOGE("JsRegisterViews can't find runtime");
1250 return;
1251 }
1252 auto vm = runtime->GetEcmaVm();
1253 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "loadDocument"),
1254 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), JsLoadDocument));
1255 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "loadEtsCard"),
1256 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), JsLoadEtsCard));
1257 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "postCardAction"),
1258 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), JSPostCardAction));
1259 #if defined(PREVIEW)
1260 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "previewComponent"),
1261 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), JsPreviewerComponent));
1262 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "getPreviewComponentFlag"),
1263 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), JsGetPreviewComponentFlag));
1264 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "storePreviewComponents"),
1265 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), JsStorePreviewComponents));
1266 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "GetRootView"),
1267 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), JsGetRootView));
1268 #endif
1269 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "dumpMemoryStats"),
1270 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), JsDumpMemoryStats));
1271 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "$s"),
1272 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), JsGetI18nResource));
1273 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "$m"),
1274 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), JsGetMediaResource));
1275 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "getInspectorNodes"),
1276 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), JsGetInspectorNodes));
1277 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "getInspectorNodeById"),
1278 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), JsGetInspectorNodeById));
1279 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "getInspectorTree"),
1280 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), JsGetInspectorTree));
1281 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "getInspectorByKey"),
1282 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), JsGetInspectorByKey));
1283 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "sendEventByKey"),
1284 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), JsSendEventByKey));
1285 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "sendTouchEvent"),
1286 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), JsSendTouchEvent));
1287 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "sendKeyEvent"),
1288 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), JsSendKeyEvent));
1289 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "sendMouseEvent"),
1290 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), JsSendMouseEvent));
1291 globalObj->Set(
1292 vm, panda::StringRef::NewFromUtf8(vm, "vp2px"), panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), Vp2Px));
1293 globalObj->Set(
1294 vm, panda::StringRef::NewFromUtf8(vm, "px2vp"), panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), Px2Vp));
1295 globalObj->Set(
1296 vm, panda::StringRef::NewFromUtf8(vm, "fp2px"), panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), Fp2Px));
1297 globalObj->Set(
1298 vm, panda::StringRef::NewFromUtf8(vm, "px2fp"), panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), Px2Fp));
1299 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "lpx2px"),
1300 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), Lpx2Px));
1301 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "px2lpx"),
1302 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), Px2Lpx));
1303 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "setAppBgColor"),
1304 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), SetAppBackgroundColor));
1305
1306 BindingTarget focusControlObj = panda::ObjectRef::New(const_cast<panda::EcmaVM*>(vm));
1307 focusControlObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "requestFocus"),
1308 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), RequestFocus));
1309 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "focusControl"), focusControlObj);
1310 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "registerNamedRoute"),
1311 panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), JsRegisterNamedRoute));
1312
1313 JsBindViews(globalObj);
1314
1315 JSObjectTemplate toggleType;
1316 toggleType.Constant("Checkbox", 0);
1317 toggleType.Constant("Switch", 1);
1318 toggleType.Constant("Button", 2); // 2 means index of constant
1319
1320 JSObjectTemplate refreshStatus;
1321 refreshStatus.Constant("Inactive", 0);
1322 refreshStatus.Constant("Drag", 1);
1323 refreshStatus.Constant("OverDrag", 2);
1324 refreshStatus.Constant("Refresh", 3); // 3 means index of constant
1325 refreshStatus.Constant("Done", 4); // 4 means index of constant
1326
1327 JSObjectTemplate mainAxisAlign;
1328 mainAxisAlign.Constant("Start", 1);
1329 mainAxisAlign.Constant("Center", 2); // 2 means index of constant
1330 mainAxisAlign.Constant("End", 3); // 3 means index of constant
1331 mainAxisAlign.Constant("SpaceBetween", 6); // 6 means index of constant
1332 mainAxisAlign.Constant("SpaceAround", 7); // 7 means index of constant
1333
1334 JSObjectTemplate crossAxisAlign;
1335 crossAxisAlign.Constant("Start", 1);
1336
1337 crossAxisAlign.Constant("Center", 2); // 2 means index of constant
1338 crossAxisAlign.Constant("End", 3); // 3 means index of constant
1339 crossAxisAlign.Constant("Stretch", 4); // 4 means index of constant
1340
1341 JSObjectTemplate direction;
1342 direction.Constant("Horizontal", 0);
1343 direction.Constant("Vertical", 1);
1344
1345 JSObjectTemplate loadingProgressStyle;
1346 loadingProgressStyle.Constant("Default", 1);
1347 loadingProgressStyle.Constant("Circular", 2); // 2 means index of constant
1348 loadingProgressStyle.Constant("Orbital", 3); // 3 means index of constant
1349
1350 JSObjectTemplate progressStyle;
1351 progressStyle.Constant("Linear", 0);
1352 progressStyle.Constant("Ring", 1); // 1 means index of constant
1353 progressStyle.Constant("Eclipse", 2); // 2 means index of constant
1354 progressStyle.Constant("ScaleRing", 3); // 3 means index of constant
1355 progressStyle.Constant("Capsule", 4); // 4 means index of constant
1356
1357 JSObjectTemplate stackFit;
1358 stackFit.Constant("Keep", 0);
1359 stackFit.Constant("Stretch", 1);
1360 stackFit.Constant("Inherit", 2); // 2 means index of constant
1361 stackFit.Constant("FirstChild", 3); // 3 means index of constant
1362
1363 JSObjectTemplate overflow;
1364 overflow.Constant("Clip", 0);
1365 overflow.Constant("Observable", 1);
1366
1367 JSObjectTemplate alignment;
1368 alignment.Constant("TopLeft", 0);
1369 alignment.Constant("TopCenter", 1);
1370 alignment.Constant("TopRight", 2); // 2 means index of constant
1371 alignment.Constant("CenterLeft", 3); // 3 means index of constant
1372 alignment.Constant("Center", 4); // 4 means index of constant
1373 alignment.Constant("CenterRight", 5); // 5 means index of constant
1374 alignment.Constant("BottomLeft", 6); // 6 means index of constant
1375 alignment.Constant("BottomCenter", 7); // 7 means index of constant
1376 alignment.Constant("BottomRight", 8); // 8 means index of constant
1377
1378 JSObjectTemplate sliderStyle;
1379 sliderStyle.Constant("OutSet", 0);
1380 sliderStyle.Constant("InSet", 1);
1381
1382 JSObjectTemplate sliderChangeMode;
1383 sliderChangeMode.Constant("Begin", 0);
1384 sliderChangeMode.Constant("Moving", 1);
1385 sliderChangeMode.Constant("End", 2); // 2 means index of constant
1386 sliderChangeMode.Constant("Click", 3); // 3 means index of constant
1387
1388 JSObjectTemplate pickerStyle;
1389 pickerStyle.Constant("Inline", 0);
1390 pickerStyle.Constant("Block", 1);
1391 pickerStyle.Constant("Fade", 2); // 2 means index of constant
1392
1393 JSObjectTemplate buttonType;
1394 buttonType.Constant("Normal", (int)ButtonType::NORMAL);
1395 buttonType.Constant("Capsule", (int)ButtonType::CAPSULE);
1396 buttonType.Constant("Circle", (int)ButtonType::CIRCLE);
1397 buttonType.Constant("Arc", (int)ButtonType::ARC);
1398
1399 JSObjectTemplate iconPosition;
1400 iconPosition.Constant("Start", 0);
1401 iconPosition.Constant("End", 1);
1402
1403 JSObjectTemplate badgePosition;
1404 badgePosition.Constant("RightTop", 0);
1405 badgePosition.Constant("Right", 1);
1406 badgePosition.Constant("Left", 2); // 2 means index of constant
1407
1408 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "MainAxisAlign"), *mainAxisAlign);
1409 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "CrossAxisAlign"), *crossAxisAlign);
1410 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "Direction"), *direction);
1411 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "StackFit"), *stackFit);
1412 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "Align"), *alignment);
1413 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "Overflow"), *overflow);
1414 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "ButtonType"), *buttonType);
1415 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "LoadingProgressStyle"), *loadingProgressStyle);
1416 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "ProgressStyle"), *progressStyle);
1417 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "ToggleType"), *toggleType);
1418 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "RefreshStatus"), *refreshStatus);
1419 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "SliderStyle"), *sliderStyle);
1420 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "SliderChangeMode"), *sliderChangeMode);
1421 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "IconPosition"), *iconPosition);
1422 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "PickerStyle"), *pickerStyle);
1423 globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "BadgePosition"), *badgePosition);
1424 LOGD("View classes and jsCreateDocument, registerObservableObject functions registered.");
1425 }
1426
1427 } // namespace OHOS::Ace::Framework
1428