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/jsview/js_interactable_view.h"
17 #if !defined(PREVIEW) && defined(OHOS_PLATFORM)
18 #include "interfaces/inner_api/ui_session/ui_session_manager.h"
19 #endif
20
21 #include "base/log/ace_scoring_log.h"
22 #include "base/log/log_wrapper.h"
23 #include "base/utils/utf_helper.h"
24 #include "bridge/declarative_frontend/engine/functions/js_click_function.h"
25 #include "bridge/declarative_frontend/engine/functions/js_hover_function.h"
26 #include "bridge/declarative_frontend/engine/functions/js_key_function.h"
27 #include "bridge/declarative_frontend/engine/js_execution_scope_defines.h"
28 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_frame_node_bridge.h"
29 #include "bridge/declarative_frontend/jsview/js_pan_handler.h"
30 #include "bridge/declarative_frontend/jsview/js_touch_handler.h"
31 #include "bridge/declarative_frontend/jsview/js_utils.h"
32 #include "bridge/declarative_frontend/view_stack_processor.h"
33 #include "core/common/container.h"
34 #include "core/components/gesture_listener/gesture_listener_component.h"
35 #include "core/components_ng/base/view_abstract_model.h"
36 #include "core/components_ng/base/view_stack_processor.h"
37 #include "core/gestures/click_recognizer.h"
38 #include "core/pipeline/base/single_child.h"
39 #include "core/pipeline/pipeline_context.h"
40
41 #ifdef PLUGIN_COMPONENT_SUPPORTED
42 #include "core/common/plugin_manager.h"
43 #endif
44
45 namespace OHOS::Ace::Framework {
46
JsOnTouch(const JSCallbackInfo & args)47 void JSInteractableView::JsOnTouch(const JSCallbackInfo& args)
48 {
49 if (args[0]->IsUndefined() && IsDisableEventVersion()) {
50 ViewAbstractModel::GetInstance()->DisableOnTouch();
51 return;
52 }
53 if (!args[0]->IsFunction()) {
54 return;
55 }
56 EcmaVM* vm = args.GetVm();
57 CHECK_NULL_VOID(vm);
58 auto jsOnTouchFunc = JSRef<JSFunc>::Cast(args[0]);
59 if (jsOnTouchFunc->IsEmpty()) {
60 return;
61 }
62 auto jsOnTouchFuncLocalHandle = jsOnTouchFunc->GetLocalHandle();
63 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
64 auto onTouch = [vm, execCtx = args.GetExecutionContext(),
65 func = panda::CopyableGlobal(vm, jsOnTouchFuncLocalHandle),
66 node = frameNode](TouchEventInfo& info) {
67 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
68 ACE_SCORING_EVENT("onTouch");
69 PipelineContext::SetCallBackNode(node);
70 auto eventObj = NG::FrameNodeBridge::CreateTouchEventInfo(vm, info);
71 panda::Local<panda::JSValueRef> params[1] = { eventObj };
72 func->Call(vm, func.ToLocal(), params, 1);
73 };
74 ViewAbstractModel::GetInstance()->SetOnTouch(std::move(onTouch));
75 }
76
JsOnKey(const JSCallbackInfo & args)77 void JSInteractableView::JsOnKey(const JSCallbackInfo& args)
78 {
79 if (args[0]->IsUndefined() && IsDisableEventVersion()) {
80 ViewAbstractModel::GetInstance()->DisableOnKeyEvent();
81 return;
82 }
83 if (!args[0]->IsFunction()) {
84 return;
85 }
86 RefPtr<JsKeyFunction> JsOnKeyEvent = AceType::MakeRefPtr<JsKeyFunction>(JSRef<JSFunc>::Cast(args[0]));
87 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
88 auto onKeyEvent = [execCtx = args.GetExecutionContext(), func = std::move(JsOnKeyEvent), node = frameNode](
89 KeyEventInfo& info) -> bool {
90 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, false);
91 ACE_SCORING_EVENT("onKey");
92 PipelineContext::SetCallBackNode(node);
93 auto ret = func->ExecuteWithValue(info);
94 return ret->IsBoolean() ? ret->ToBoolean() : false;
95 };
96 ViewAbstractModel::GetInstance()->SetOnKeyEvent(std::move(onKeyEvent));
97 }
98
JsOnKeyPreIme(const JSCallbackInfo & args)99 void JSInteractableView::JsOnKeyPreIme(const JSCallbackInfo& args)
100 {
101 if (args[0]->IsUndefined()) {
102 ViewAbstractModel::GetInstance()->DisableOnKeyPreIme();
103 return;
104 }
105 if (!args[0]->IsFunction()) {
106 return;
107 }
108 RefPtr<JsKeyFunction> JsOnPreImeEvent = AceType::MakeRefPtr<JsKeyFunction>(JSRef<JSFunc>::Cast(args[0]));
109 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
110 auto onPreImeEvent = [execCtx = args.GetExecutionContext(), func = std::move(JsOnPreImeEvent), node = frameNode](
111 KeyEventInfo& info) -> bool {
112 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, false);
113 ACE_SCORING_EVENT("onKeyPreIme");
114 PipelineContext::SetCallBackNode(node);
115 auto ret = func->ExecuteWithValue(info);
116 return ret->IsBoolean() ? ret->ToBoolean() : false;
117 };
118 ViewAbstractModel::GetInstance()->SetOnKeyPreIme(std::move(onPreImeEvent));
119 }
120
JsOnKeyEventDispatch(const JSCallbackInfo & args)121 void JSInteractableView::JsOnKeyEventDispatch(const JSCallbackInfo& args)
122 {
123 if (args[0]->IsUndefined() || !args[0]->IsFunction()) {
124 ViewAbstractModel::GetInstance()->DisableOnKeyEventDispatch();
125 return;
126 }
127 RefPtr<JsKeyFunction> JsOnKeyEventDispatch = AceType::MakeRefPtr<JsKeyFunction>(JSRef<JSFunc>::Cast(args[0]));
128 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
129 auto onKeyEventDispatch = [execCtx = args.GetExecutionContext(), func = std::move(JsOnKeyEventDispatch),
130 node = frameNode](KeyEventInfo& keyEvent) -> bool {
131 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, false);
132 ACE_SCORING_EVENT("onKeyEventDispatch");
133 PipelineContext::SetCallBackNode(node);
134 auto ret = func->ExecuteWithValue(keyEvent);
135 return ret->IsBoolean() ? ret->ToBoolean() : false;
136 };
137 ViewAbstractModel::GetInstance()->SetOnKeyEventDispatch(std::move(onKeyEventDispatch));
138 }
139
JsOnHover(const JSCallbackInfo & info)140 void JSInteractableView::JsOnHover(const JSCallbackInfo& info)
141 {
142 if (info[0]->IsUndefined() && IsDisableEventVersion()) {
143 ViewAbstractModel::GetInstance()->DisableOnHover();
144 return;
145 }
146 if (!info[0]->IsFunction()) {
147 return;
148 }
149 RefPtr<JsHoverFunction> jsOnHoverFunc = AceType::MakeRefPtr<JsHoverFunction>(JSRef<JSFunc>::Cast(info[0]));
150 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
151 auto onHover = [execCtx = info.GetExecutionContext(), func = std::move(jsOnHoverFunc), node = frameNode](
152 bool isHover, HoverInfo& hoverInfo) {
153 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
154 ACE_SCORING_EVENT("onHover");
155 PipelineContext::SetCallBackNode(node);
156 func->HoverExecute(isHover, hoverInfo);
157 };
158 ViewAbstractModel::GetInstance()->SetOnHover(std::move(onHover));
159 }
160
JsOnHoverMove(const JSCallbackInfo & info)161 void JSInteractableView::JsOnHoverMove(const JSCallbackInfo& info)
162 {
163 if (info[0]->IsUndefined() && IsDisableEventVersion()) {
164 ViewAbstractModel::GetInstance()->DisableOnHoverMove();
165 return;
166 }
167 if (!info[0]->IsFunction()) {
168 return;
169 }
170 RefPtr<JsHoverFunction> jsOnHoverMoveFunc = AceType::MakeRefPtr<JsHoverFunction>(JSRef<JSFunc>::Cast(info[0]));
171 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
172 auto onHover = [execCtx = info.GetExecutionContext(), func = std::move(jsOnHoverMoveFunc), node = frameNode](
173 HoverInfo& hoverInfo) {
174 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
175 ACE_SCORING_EVENT("onHoverMove");
176 PipelineContext::SetCallBackNode(node);
177 func->HoverMoveExecute(hoverInfo);
178 };
179 ViewAbstractModel::GetInstance()->SetOnHoverMove(std::move(onHover));
180 }
181
JsOnPan(const JSCallbackInfo & args)182 void JSInteractableView::JsOnPan(const JSCallbackInfo& args)
183 {
184 if (args[0]->IsObject()) {
185 #ifndef NG_BUILD
186 JSRef<JSObject> obj = JSRef<JSObject>::Cast(args[0]);
187 JSPanHandler* handler = obj->Unwrap<JSPanHandler>();
188 if (handler) {
189 handler->CreateComponent(args);
190 }
191 #endif
192 }
193 }
194
JsOnDelete(const JSCallbackInfo & info)195 void JSInteractableView::JsOnDelete(const JSCallbackInfo& info)
196 {
197 if (info[0]->IsFunction()) {
198 RefPtr<JsFunction> jsOnDeleteFunc =
199 AceType::MakeRefPtr<JsFunction>(JSRef<JSObject>(), JSRef<JSFunc>::Cast(info[0]));
200 auto frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
201 auto onDelete = [execCtx = info.GetExecutionContext(), func = std::move(jsOnDeleteFunc), node = frameNode]() {
202 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
203 ACE_SCORING_EVENT("onDelete");
204 PipelineContext::SetCallBackNode(node);
205 func->Execute();
206 };
207 ViewAbstractModel::GetInstance()->SetOnDelete(std::move(onDelete));
208 }
209 }
210
JsTouchable(const JSCallbackInfo & info)211 void JSInteractableView::JsTouchable(const JSCallbackInfo& info)
212 {
213 if (info[0]->IsBoolean()) {
214 ViewAbstractModel::GetInstance()->SetTouchable(info[0]->ToBoolean());
215 }
216 }
217
JsMonopolizeEvents(const JSCallbackInfo & info)218 void JSInteractableView::JsMonopolizeEvents(const JSCallbackInfo& info)
219 {
220 if (info[0]->IsBoolean()) {
221 ViewAbstractModel::GetInstance()->SetMonopolizeEvents(info[0]->ToBoolean());
222 } else {
223 ViewAbstractModel::GetInstance()->SetMonopolizeEvents(false);
224 }
225 }
226
JsOnClick(const JSCallbackInfo & info)227 void JSInteractableView::JsOnClick(const JSCallbackInfo& info)
228 {
229 JSRef<JSVal> jsOnClickVal = info[0];
230 if (jsOnClickVal->IsUndefined() && IsDisableEventVersion()) {
231 ViewAbstractModel::GetInstance()->DisableOnClick();
232 return;
233 }
234 if (!jsOnClickVal->IsFunction()) {
235 return;
236 }
237 auto frameNode = NG::ViewStackProcessor::GetInstance()->GetMainFrameNode();
238 WeakPtr<NG::FrameNode> weak = AceType::WeakClaim(frameNode);
239 auto jsOnClickFunc = AceType::MakeRefPtr<JsClickFunction>(JSRef<JSFunc>::Cast(jsOnClickVal));
240 auto onTap = [execCtx = info.GetExecutionContext(), func = jsOnClickFunc, node = weak](GestureEvent& info) {
241 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
242 ACE_SCORING_EVENT("onClick");
243 PipelineContext::SetCallBackNode(node);
244 func->Execute(info);
245 #if !defined(PREVIEW) && defined(OHOS_PLATFORM)
246 ReportClickEvent(node);
247 #endif
248 };
249 auto onClick = [execCtx = info.GetExecutionContext(), func = jsOnClickFunc, node = weak](
250 const ClickInfo* info) {
251 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
252 ACE_SCORING_EVENT("onClick");
253 PipelineContext::SetCallBackNode(node);
254 func->Execute(*info);
255 #if !defined(PREVIEW) && defined(OHOS_PLATFORM)
256 ReportClickEvent(node);
257 #endif
258 };
259
260 Dimension distanceThreshold = Dimension(std::numeric_limits<double>::infinity(), DimensionUnit::PX);
261 if (info.Length() > 1 && info[1]->IsNumber()) {
262 double jsDistanceThreshold = info[1]->ToNumber<double>();
263 distanceThreshold = Dimension(jsDistanceThreshold, DimensionUnit::VP);
264 }
265
266 ViewAbstractModel::GetInstance()->SetOnClick(std::move(onTap), std::move(onClick), distanceThreshold);
267 CHECK_NULL_VOID(frameNode);
268 auto focusHub = frameNode->GetOrCreateFocusHub();
269 CHECK_NULL_VOID(focusHub);
270 focusHub->SetFocusable(true, false);
271 }
272
SetFocusable(bool focusable)273 void JSInteractableView::SetFocusable(bool focusable)
274 {
275 ViewAbstractModel::GetInstance()->SetFocusable(focusable);
276 }
277
SetFocusNode(bool isFocusNode)278 void JSInteractableView::SetFocusNode(bool isFocusNode)
279 {
280 ViewAbstractModel::GetInstance()->SetFocusNode(isFocusNode);
281 }
282
JsOnAppear(const JSCallbackInfo & info)283 void JSInteractableView::JsOnAppear(const JSCallbackInfo& info)
284 {
285 if (info[0]->IsUndefined() && IsDisableEventVersion()) {
286 ViewAbstractModel::GetInstance()->DisableOnAppear();
287 return;
288 }
289 if (info[0]->IsFunction()) {
290 RefPtr<JsFunction> jsOnAppearFunc =
291 AceType::MakeRefPtr<JsFunction>(JSRef<JSObject>(), JSRef<JSFunc>::Cast(info[0]));
292 auto frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
293 auto onAppear = [execCtx = info.GetExecutionContext(), func = std::move(jsOnAppearFunc), node = frameNode]() {
294 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
295 ACE_SCORING_EVENT("onAppear");
296 PipelineContext::SetCallBackNode(node);
297 func->Execute();
298 };
299 ViewAbstractModel::GetInstance()->SetOnAppear(std::move(onAppear));
300 }
301 }
302
JsOnDisAppear(const JSCallbackInfo & info)303 void JSInteractableView::JsOnDisAppear(const JSCallbackInfo& info)
304 {
305 if (info[0]->IsUndefined() && IsDisableEventVersion()) {
306 ViewAbstractModel::GetInstance()->DisableOnDisAppear();
307 return;
308 }
309 if (info[0]->IsFunction()) {
310 RefPtr<JsFunction> jsOnDisAppearFunc =
311 AceType::MakeRefPtr<JsFunction>(JSRef<JSObject>(), JSRef<JSFunc>::Cast(info[0]));
312 auto frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
313 auto onDisappear = [execCtx = info.GetExecutionContext(), func = std::move(jsOnDisAppearFunc),
314 node = frameNode]() {
315 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
316 ACE_SCORING_EVENT("onDisAppear");
317 PipelineContext::SetCallBackNode(node);
318 func->Execute();
319 };
320 ViewAbstractModel::GetInstance()->SetOnDisAppear(std::move(onDisappear));
321 }
322 }
323
JsOnAttach(const JSCallbackInfo & info)324 void JSInteractableView::JsOnAttach(const JSCallbackInfo& info)
325 {
326 if (info[0]->IsUndefined() && IsDisableEventVersion()) {
327 ViewAbstractModel::GetInstance()->DisableOnAttach();
328 return;
329 }
330 if (info[0]->IsFunction()) {
331 RefPtr<JsFunction> jsOnAttachFunc =
332 AceType::MakeRefPtr<JsFunction>(JSRef<JSObject>(), JSRef<JSFunc>::Cast(info[0]));
333 auto frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
334 auto onAttach = [execCtx = info.GetExecutionContext(), func = std::move(jsOnAttachFunc), node = frameNode]() {
335 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
336 ACE_SCORING_EVENT("onAttach");
337 PipelineContext::SetCallBackNode(node);
338 func->Execute();
339 };
340 ViewAbstractModel::GetInstance()->SetOnAttach(std::move(onAttach));
341 }
342 }
343
JsOnDetach(const JSCallbackInfo & info)344 void JSInteractableView::JsOnDetach(const JSCallbackInfo& info)
345 {
346 if (info[0]->IsUndefined() && IsDisableEventVersion()) {
347 ViewAbstractModel::GetInstance()->DisableOnDetach();
348 return;
349 }
350 if (info[0]->IsFunction()) {
351 RefPtr<JsFunction> jsOnDetachFunc =
352 AceType::MakeRefPtr<JsFunction>(JSRef<JSObject>(), JSRef<JSFunc>::Cast(info[0]));
353 auto frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
354 auto onDetach = [execCtx = info.GetExecutionContext(), func = std::move(jsOnDetachFunc), node = frameNode]() {
355 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
356 ACE_SCORING_EVENT("onDetach");
357 PipelineContext::SetCallBackNode(node);
358 func->Execute();
359 };
360 ViewAbstractModel::GetInstance()->SetOnDetach(std::move(onDetach));
361 }
362 }
363
JsOnAccessibility(const JSCallbackInfo & info)364 void JSInteractableView::JsOnAccessibility(const JSCallbackInfo& info)
365 {
366 if (!info[0]->IsFunction()) {
367 return;
368 }
369 RefPtr<JsFunction> jsFunc = AceType::MakeRefPtr<JsFunction>(JSRef<JSObject>(), JSRef<JSFunc>::Cast(info[0]));
370 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
371 auto onAccessibility = [execCtx = info.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
372 const std::string& param) {
373 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
374 ACE_SCORING_EVENT("onAccessibility");
375 PipelineContext::SetCallBackNode(node);
376
377 func->Execute({ "eventType" }, param);
378 };
379 ViewAbstractModel::GetInstance()->SetOnAccessibility(std::move(onAccessibility));
380 }
381
JsCommonRemoteMessage(const JSCallbackInfo & info)382 void JSInteractableView::JsCommonRemoteMessage(const JSCallbackInfo& info)
383 {
384 if (info.Length() != 0 && info[0]->IsObject()) {
385 RemoteCallback remoteCallback;
386 JsRemoteMessage(info, remoteCallback);
387 ViewAbstractModel::GetInstance()->SetOnRemoteMessage(std::move(remoteCallback));
388 }
389 }
390
JsRemoteMessage(const JSCallbackInfo & info,RemoteCallback & remoteCallback)391 void JSInteractableView::JsRemoteMessage(const JSCallbackInfo& info, RemoteCallback& remoteCallback)
392 {
393 if (!info[0]->IsObject()) {
394 return;
395 }
396
397 auto eventCallback = GetRemoteMessageEventCallback(info);
398 remoteCallback = [func = std::move(eventCallback)](const BaseEventInfo* info) {
399 auto touchInfo = TypeInfoHelper::DynamicCast<ClickInfo>(info);
400 if (touchInfo && touchInfo->GetType().compare("onClick") == 0) {
401 func();
402 }
403 };
404 }
405
GetRemoteMessageEventCallback(const JSCallbackInfo & info)406 std::function<void()> JSInteractableView::GetRemoteMessageEventCallback(const JSCallbackInfo& info)
407 {
408 JSRef<JSVal> arg = info[0];
409 if (!arg->IsObject()) {
410 return []() {};
411 }
412 auto obj = JSRef<JSObject>::Cast(arg);
413 auto actionValue = obj->GetProperty("action");
414 std::string action;
415 if (actionValue->IsString()) {
416 action = actionValue->ToString();
417 }
418 auto abilityValue = obj->GetProperty("ability");
419 std::string ability;
420 if (abilityValue->IsString()) {
421 ability = abilityValue->ToString();
422 }
423 auto paramsObj = obj->GetProperty("params");
424 std::string params;
425 if (paramsObj->IsObject()) {
426 params = paramsObj->ToString();
427 }
428 auto eventCallback = [action, ability, params]() {
429 if (action.compare("message") == 0) {
430 // onCall
431 } else if (action.compare("route") == 0) {
432 // startAbility
433 #ifdef PLUGIN_COMPONENT_SUPPORTED
434 std::vector<std::string> strList;
435 SplitString(ability, '/', strList);
436 if (strList.size() <= 1) {
437 return;
438 }
439 int32_t result = PluginManager::GetInstance().StartAbility(strList[0], strList[1], params);
440 if (result != 0) {
441 LOGW("Failed to start the APP %{public}s.", ability.c_str());
442 }
443 #else
444 LOGW("Unsupported Windows and Mac platforms to start APP.");
445 #endif
446 }
447 };
448
449 return eventCallback;
450 }
451
452 #if !defined(PREVIEW) && defined(OHOS_PLATFORM)
ReportClickEvent(const WeakPtr<NG::FrameNode> & weakNode,const std::u16string text)453 void JSInteractableView::ReportClickEvent(const WeakPtr<NG::FrameNode>& weakNode, const std::u16string text)
454 {
455 if (UiSessionManager::GetInstance()->GetClickEventRegistered()) {
456 auto data = JsonUtil::Create();
457 data->Put("event", "onClick");
458 std::u16string content = text;
459 auto node = weakNode.Upgrade();
460 if (node) {
461 data->Put("id", node->GetId());
462 auto children = node->GetChildren();
463 if (!children.empty()) {
464 node->GetContainerComponentText(content);
465 }
466 data->Put("text", UtfUtils::Str16DebugToStr8(content).data());
467 data->Put("position", node->GetGeometryNode()->GetFrameRect().ToString().data());
468 }
469 UiSessionManager::GetInstance()->ReportClickEvent(data->ToString());
470 }
471 }
472 #endif
473
SplitString(const std::string & str,char tag,std::vector<std::string> & strList)474 void JSInteractableView::SplitString(const std::string& str, char tag, std::vector<std::string>& strList)
475 {
476 std::string subStr;
477 for (size_t i = 0; i < str.length(); i++) {
478 if (tag == str[i]) {
479 if (!subStr.empty()) {
480 strList.push_back(subStr);
481 subStr.clear();
482 }
483 } else {
484 subStr.push_back(str[i]);
485 }
486 }
487 if (!subStr.empty()) {
488 strList.push_back(subStr);
489 }
490 }
491 } // namespace OHOS::Ace::Framework
492