From 450962aaf5aa1adc97099064d53564dc643f742d Mon Sep 17 00:00:00 2001 From: Caoruihong Date: Wed, 11 Jun 2025 18:04:45 +0800 Subject: [PATCH] refactor: optimize js_function class Signed-off-by: Caoruihong --- .gitee/CODEOWNERS | 12 + .../bridge/declarative_frontend/BUILD.gn | 20 +- .../functions/js_accessibility_function.h | 4 +- .../js_animation_on_finish_function.cpp | 41 +++ .../js_animation_on_finish_function.h | 36 +++ .../engine/functions/js_animator_function.h | 2 +- .../functions/js_cited_event_function.cpp | 20 ++ .../functions/js_cited_event_function.h | 71 ++++++ .../engine/functions/js_click_function.cpp | 2 + .../engine/functions/js_click_function.h | 4 +- .../engine/functions/js_clipboard_function.h | 2 +- .../functions/js_common_event_function.cpp | 20 ++ .../functions/js_common_event_function.h | 41 +++ .../functions/js_common_gesture_function.cpp | 37 +++ .../functions/js_common_gesture_function.h | 37 +++ .../engine/functions/js_common_utils.cpp | 26 ++ .../engine/functions/js_common_utils.h | 1 + .../engine/functions/js_crown_function.cpp | 92 +++---- .../engine/functions/js_crown_function.h | 86 +++---- .../engine/functions/js_drag_function.h | 2 +- .../engine/functions/js_event_function.cpp | 20 ++ .../engine/functions/js_event_function.h | 59 +++++ .../engine/functions/js_focus_function.h | 2 +- .../engine/functions/js_foreach_function.cpp | 6 +- .../engine/functions/js_function.cpp | 210 ++-------------- .../engine/functions/js_function.h | 235 +++--------------- .../engine/functions/js_gesture_function.cpp | 3 +- .../engine/functions/js_gesture_function.h | 11 +- .../functions/js_gesture_judge_function.h | 11 +- .../engine/functions/js_hover_function.cpp | 2 + .../engine/functions/js_key_function.h | 2 +- .../engine/functions/js_navigation_function.h | 2 +- .../functions/js_on_area_change_function.h | 2 +- .../js_on_child_touch_test_function.h | 2 +- .../functions/js_on_size_change_function.h | 2 +- .../functions/js_page_transition_function.h | 2 +- .../engine/functions/js_pan_function.h | 2 +- ...ilt_in_recognizer_parallel_with_function.h | 2 +- .../engine/functions/js_swiper_function.h | 2 +- .../engine/functions/js_tabs_function.h | 2 +- .../engine/functions/js_touch_function.cpp | 2 + .../engine/functions/js_touch_function.h | 2 +- .../functions/js_touch_intercept_function.h | 2 +- .../functions/js_touch_test_done_function.h | 2 +- .../engine/functions/js_webview_function.h | 2 +- .../js_xcomponent_onload_function.cpp | 39 +++ .../functions/js_xcomponent_onload_function.h | 36 +++ .../engine/jsi/jsi_types.cpp | 24 +- .../engine/jsi/jsi_types.h | 6 +- .../arkts_native_frame_node_bridge.cpp | 2 +- .../jsview/js_checkboxgroup.cpp | 1 + .../jsview/js_datepicker.cpp | 2 +- .../jsview/js_dynamic_component.cpp | 2 +- .../jsview/js_folder_stack.cpp | 1 + .../declarative_frontend/jsview/js_image.cpp | 1 + .../jsview/js_image_span.cpp | 1 + .../jsview/js_indicator.cpp | 1 + .../jsview/js_isolated_component.cpp | 2 +- .../jsview/js_location_button.cpp | 2 + .../jsview/js_location_button.h | 2 +- .../jsview/js_navigation.cpp | 1 + .../jsview/js_paste_button.cpp | 2 + .../jsview/js_paste_button.h | 2 +- .../declarative_frontend/jsview/js_plugin.cpp | 4 +- .../jsview/js_richeditor.cpp | 4 +- .../jsview/js_save_button.cpp | 2 + .../jsview/js_save_button.h | 2 +- .../declarative_frontend/jsview/js_search.cpp | 4 +- .../declarative_frontend/jsview/js_swiper.cpp | 1 + .../declarative_frontend/jsview/js_tabs.cpp | 1 + .../jsview/js_textfield.cpp | 4 +- .../jsview/js_ui_extension.cpp | 16 +- .../jsview/js_view_abstract.cpp | 1 + .../jsview/js_view_context.cpp | 14 +- .../declarative_frontend/jsview/js_web.cpp | 3 + .../jsview/js_xcomponent.cpp | 3 +- frameworks/core/animation/animation_pub.cpp | 2 +- frameworks/core/animation/animation_pub.h | 2 +- .../pattern/list/list_item_pattern.cpp | 2 +- .../pattern/list/list_item_pattern.h | 2 +- .../global_scope_animation_helper.cpp | 2 +- .../interfaces/native/node/node_animate.cpp | 4 +- .../pattern/plugin/plugin_pattern_test_ng.cpp | 40 +++ 83 files changed, 809 insertions(+), 576 deletions(-) create mode 100644 frameworks/bridge/declarative_frontend/engine/functions/js_animation_on_finish_function.cpp create mode 100644 frameworks/bridge/declarative_frontend/engine/functions/js_animation_on_finish_function.h create mode 100644 frameworks/bridge/declarative_frontend/engine/functions/js_cited_event_function.cpp create mode 100644 frameworks/bridge/declarative_frontend/engine/functions/js_cited_event_function.h create mode 100644 frameworks/bridge/declarative_frontend/engine/functions/js_common_event_function.cpp create mode 100644 frameworks/bridge/declarative_frontend/engine/functions/js_common_event_function.h create mode 100644 frameworks/bridge/declarative_frontend/engine/functions/js_common_gesture_function.cpp create mode 100644 frameworks/bridge/declarative_frontend/engine/functions/js_common_gesture_function.h mode change 100755 => 100644 frameworks/bridge/declarative_frontend/engine/functions/js_crown_function.cpp mode change 100755 => 100644 frameworks/bridge/declarative_frontend/engine/functions/js_crown_function.h create mode 100644 frameworks/bridge/declarative_frontend/engine/functions/js_event_function.cpp create mode 100644 frameworks/bridge/declarative_frontend/engine/functions/js_event_function.h create mode 100644 frameworks/bridge/declarative_frontend/engine/functions/js_xcomponent_onload_function.cpp create mode 100644 frameworks/bridge/declarative_frontend/engine/functions/js_xcomponent_onload_function.h diff --git a/.gitee/CODEOWNERS b/.gitee/CODEOWNERS index fdb480130c3..79f068b8cc9 100644 --- a/.gitee/CODEOWNERS +++ b/.gitee/CODEOWNERS @@ -726,6 +726,18 @@ frameworks/bridge/declarative_frontend/engine/functions/js_foreach_function.cpp frameworks/bridge/declarative_frontend/engine/functions/js_foreach_function.h @arkuistatemgmt frameworks/bridge/declarative_frontend/engine/functions/js_function.cpp @arkuievent frameworks/bridge/declarative_frontend/engine/functions/js_function.h @arkuievent +frameworks/bridge/declarative_frontend/engine/functions/js_animation_on_finish_function.cpp @arkuievent +frameworks/bridge/declarative_frontend/engine/functions/js_animation_on_finish_function.h @arkuievent +frameworks/bridge/declarative_frontend/engine/functions/js_cited_event_function.cpp @arkuievent +frameworks/bridge/declarative_frontend/engine/functions/js_cited_event_function.h @arkuievent +frameworks/bridge/declarative_frontend/engine/functions/js_common_event_function.cpp @arkuievent +frameworks/bridge/declarative_frontend/engine/functions/js_common_event_function.h @arkuievent +frameworks/bridge/declarative_frontend/engine/functions/js_common_gesture_function.cpp @arkuievent +frameworks/bridge/declarative_frontend/engine/functions/js_common_gesture_function.h @arkuievent +frameworks/bridge/declarative_frontend/engine/functions/js_event_function.cpp @arkuievent +frameworks/bridge/declarative_frontend/engine/functions/js_event_function.h @arkuievent +frameworks/bridge/declarative_frontend/engine/functions/js_xcomponent_onload_function.cpp @arkuievent +frameworks/bridge/declarative_frontend/engine/functions/js_xcomponent_onload_function.h @arkuievent frameworks/bridge/declarative_frontend/engine/functions/js_gesture_function.cpp @arkuievent frameworks/bridge/declarative_frontend/engine/functions/js_gesture_function.h @arkuievent frameworks/bridge/declarative_frontend/engine/functions/js_gesture_judge_function.cpp @arkuievent diff --git a/frameworks/bridge/declarative_frontend/BUILD.gn b/frameworks/bridge/declarative_frontend/BUILD.gn index 8e12f70b075..ef65e57d452 100644 --- a/frameworks/bridge/declarative_frontend/BUILD.gn +++ b/frameworks/bridge/declarative_frontend/BUILD.gn @@ -222,17 +222,21 @@ template("declarative_js_engine") { "engine/bindings_implementation.cpp", "engine/declarative_engine_loader.cpp", "engine/functions/js_accessibility_function.cpp", + "engine/functions/js_animation_on_finish_function.cpp", "engine/functions/js_animator_function.cpp", + "engine/functions/js_cited_event_function.cpp", "engine/functions/js_click_function.cpp", "engine/functions/js_clipboard_function.cpp", + "engine/functions/js_common_event_function.cpp", + "engine/functions/js_common_gesture_function.cpp", "engine/functions/js_common_utils.cpp", "engine/functions/js_drag_function.cpp", + "engine/functions/js_event_function.cpp", "engine/functions/js_focus_function.cpp", "engine/functions/js_foreach_function.cpp", "engine/functions/js_function.cpp", "engine/functions/js_gesture_function.cpp", "engine/functions/js_gesture_judge_function.cpp", - "engine/functions/js_touch_test_done_function.cpp", "engine/functions/js_gesture_recognizer.cpp", "engine/functions/js_hover_function.cpp", "engine/functions/js_key_function.cpp", @@ -248,7 +252,9 @@ template("declarative_js_engine") { "engine/functions/js_tabs_function.cpp", "engine/functions/js_touch_function.cpp", "engine/functions/js_touch_intercept_function.cpp", + "engine/functions/js_touch_test_done_function.cpp", "engine/functions/js_webview_function.cpp", + "engine/functions/js_xcomponent_onload_function.cpp", "engine/js_types.cpp", "interfaces/profiler/js_profiler.cpp", "jsview/action_sheet/js_action_sheet.cpp", @@ -430,8 +436,8 @@ template("declarative_js_engine") { "view_stack_processor.cpp", # ark_theme - "ark_theme/theme_apply/js_with_theme.cpp", "ark_theme/theme_apply/js_theme.cpp", + "ark_theme/theme_apply/js_with_theme.cpp", # Models implemenations for classic fw "jsview/models/action_sheet_model_impl.cpp", @@ -790,17 +796,21 @@ template("declarative_js_engine_ng") { "engine/bindings_implementation.cpp", "engine/declarative_engine_loader.cpp", "engine/functions/js_accessibility_function.cpp", + "engine/functions/js_animation_on_finish_function.cpp", "engine/functions/js_animator_function.cpp", + "engine/functions/js_cited_event_function.cpp", "engine/functions/js_click_function.cpp", "engine/functions/js_clipboard_function.cpp", + "engine/functions/js_common_event_function.cpp", + "engine/functions/js_common_gesture_function.cpp", "engine/functions/js_common_utils.cpp", "engine/functions/js_drag_function.cpp", + "engine/functions/js_event_function.cpp", "engine/functions/js_focus_function.cpp", "engine/functions/js_foreach_function.cpp", "engine/functions/js_function.cpp", "engine/functions/js_gesture_function.cpp", "engine/functions/js_gesture_judge_function.cpp", - "engine/functions/js_touch_test_done_function.cpp", "engine/functions/js_gesture_recognizer.cpp", "engine/functions/js_hover_function.cpp", "engine/functions/js_key_function.cpp", @@ -816,7 +826,9 @@ template("declarative_js_engine_ng") { "engine/functions/js_tabs_function.cpp", "engine/functions/js_touch_function.cpp", "engine/functions/js_touch_intercept_function.cpp", + "engine/functions/js_touch_test_done_function.cpp", "engine/functions/js_webview_function.cpp", + "engine/functions/js_xcomponent_onload_function.cpp", "engine/js_types.cpp", "jsview/js_dump_log.cpp", "jsview/js_environment.cpp", @@ -994,8 +1006,8 @@ template("declarative_js_engine_ng") { "style_string/js_span_string.cpp", # ark_theme - "ark_theme/theme_apply/js_with_theme.cpp", "ark_theme/theme_apply/js_theme.cpp", + "ark_theme/theme_apply/js_with_theme.cpp", ] if (!ace_engine_feature_wearable) { diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_accessibility_function.h b/frameworks/bridge/declarative_frontend/engine/functions/js_accessibility_function.h index 5eb93db8725..75d754e247f 100644 --- a/frameworks/bridge/declarative_frontend/engine/functions/js_accessibility_function.h +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_accessibility_function.h @@ -28,7 +28,7 @@ public: ~JsAccessibilityActionInterceptFunction() override = default; - void Execute() override + void Execute() { ExecuteJS(); } @@ -45,7 +45,7 @@ public: ~JsAccessibilityHoverTransparentFunction() override = default; - void Execute() override + void Execute() { ExecuteJS(); } diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_animation_on_finish_function.cpp b/frameworks/bridge/declarative_frontend/engine/functions/js_animation_on_finish_function.cpp new file mode 100644 index 00000000000..078182c615a --- /dev/null +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_animation_on_finish_function.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "frameworks/bridge/declarative_frontend/engine/functions/js_animation_on_finish_function.h" + +namespace OHOS::Ace::Framework { + +void JsAnimationOnFinishFunction::Execute(bool isDebugAnim) +{ + auto vm = jsFunction_->GetEcmaVM(); + panda::TryCatch trycatch(vm); + if (isDebugAnim) { + if (jsFunction_->GetHandle().IsEmpty() || !jsFunction_->GetHandle()->IsFunction(vm) || trycatch.HasCaught()) { + TAG_LOGW(AceLogTag::ACE_ANIMATION, + "call function handle is empty or not function, empty: %{public}d, hasError: %{public}d", + jsFunction_->GetHandle().IsEmpty(), trycatch.HasCaught()); + } else { + TAG_LOGI(AceLogTag::ACE_ANIMATION, + "call function: %{public}s", jsFunction_->GetHandle()->GetName(vm)->ToString(vm).c_str()); + } + } + auto result = ExecuteJS(); + if (isDebugAnim && !result.IsEmpty()) { + TAG_LOGI( + AceLogTag::ACE_ANIMATION, "call function result: %{public}s", result->ToString().c_str()); + } +} + +} // namespace OHOS::Ace::Framework diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_animation_on_finish_function.h b/frameworks/bridge/declarative_frontend/engine/functions/js_animation_on_finish_function.h new file mode 100644 index 00000000000..4e90cf85aab --- /dev/null +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_animation_on_finish_function.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_FUNCTION_JS_ANIMATION_ON_FINISH_FUNCTION_H +#define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_FUNCTION_JS_ANIMATION_ON_FINISH_FUNCTION_H + +#include "frameworks/bridge/declarative_frontend/engine/functions/js_function.h" + +namespace OHOS::Ace::Framework { + +class JsAnimationOnFinishFunction : public JsFunction { + DECLARE_ACE_TYPE(JsAnimationOnFinishFunction, JsFunction) + +public: + explicit JsAnimationOnFinishFunction(const JSRef& jsFunction) + : JsFunction(jsFunction) {} + ~JsAnimationOnFinishFunction() override = default; + + void Execute(bool isDebugAnim); +}; + +} // namespace OHOS::Ace::Framework + +#endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_FUNCTION_JS_ANIMATION_ON_FINISH_FUNCTION_H diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_animator_function.h b/frameworks/bridge/declarative_frontend/engine/functions/js_animator_function.h index 5f7b0e87f3c..ba268f7f1e6 100644 --- a/frameworks/bridge/declarative_frontend/engine/functions/js_animator_function.h +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_animator_function.h @@ -28,7 +28,7 @@ public: explicit JsAnimatorFunction(const JSRef& jsFunction) : JsFunction(JSRef(), jsFunction) {} ~JsAnimatorFunction() override {}; - void Execute() override + void Execute() { ExecuteJS(); } diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_cited_event_function.cpp b/frameworks/bridge/declarative_frontend/engine/functions/js_cited_event_function.cpp new file mode 100644 index 00000000000..b25aae6b6fc --- /dev/null +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_cited_event_function.cpp @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "frameworks/bridge/declarative_frontend/engine/functions/js_cited_event_function.h" + +namespace OHOS::Ace::Framework { + +} // namespace OHOS::Ace::Framework diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_cited_event_function.h b/frameworks/bridge/declarative_frontend/engine/functions/js_cited_event_function.h new file mode 100644 index 00000000000..c5e185fd4a6 --- /dev/null +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_cited_event_function.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_FUNCTION_JS_CITED_EVENT_FUNCTION_H +#define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_FUNCTION_JS_CITED_EVENT_FUNCTION_H + +#include "frameworks/bridge/declarative_frontend/engine/functions/js_function.h" + +namespace OHOS::Ace::Framework { + +template +class ACE_EXPORT JsCitedEventFunction : public JsFunction { + DECLARE_ACE_TYPE(JsCitedEventFunction, JsFunction); + +public: + using ParseFunc = std::function(T&)>; + JsCitedEventFunction() = delete; + JsCitedEventFunction(const JSRef& jsFunction, ParseFunc parser) + : JsFunction(JSRef(), jsFunction), parser_(parser) {} + ~JsCitedEventFunction() override = default; + + void Execute(T& eventInfo) + { + JSRef param; + if (parser_) { + param = parser_(eventInfo); + } + JsFunction::ExecuteJS(ARGC, ¶m); + } + + void Execute(const std::string& val, T& eventInfo) + { + JSRef jsVal = JSRef::Make(ToJSValue(val)); + JSRef itemInfo; + if (parser_) { + itemInfo = parser_(eventInfo); + } + JSRef params[] = { jsVal, itemInfo }; + JsFunction::ExecuteJS(ARGC, params); + } + + void Execute(const std::u16string& val, T& eventInfo) + { + JSRef jsVal = JSRef::Make(ToJSValue(val)); + JSRef itemInfo; + if (parser_) { + itemInfo = parser_(eventInfo); + } + JSRef params[] = { jsVal, itemInfo }; + JsFunction::ExecuteJS(ARGC, params); + } + +private: + ParseFunc parser_; +}; + +} // namespace OHOS::Ace::Framework + +#endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_FUNCTION_JS_CITED_EVENT_FUNCTION_H diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_click_function.cpp b/frameworks/bridge/declarative_frontend/engine/functions/js_click_function.cpp index 4d0724caa1d..c6e85440d50 100644 --- a/frameworks/bridge/declarative_frontend/engine/functions/js_click_function.cpp +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_click_function.cpp @@ -17,8 +17,10 @@ #include "frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h" #include "frameworks/bridge/declarative_frontend/jsview/js_view_register.h" +#include "frameworks/bridge/declarative_frontend/engine/functions/js_common_utils.h" namespace OHOS::Ace::Framework { +using namespace OHOS::Ace::Framework::CommonUtils; void JsClickFunction::Execute() { diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_click_function.h b/frameworks/bridge/declarative_frontend/engine/functions/js_click_function.h index ac11892463b..0f8d446dce2 100644 --- a/frameworks/bridge/declarative_frontend/engine/functions/js_click_function.h +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_click_function.h @@ -34,7 +34,7 @@ public: explicit JsClickFunction(const JSRef& jsFunction) : JsFunction(JSRef(), jsFunction) {} ~JsClickFunction() override {}; - void Execute() override; + void Execute(); void Execute(const ClickInfo& info); void Execute(GestureEvent& info); void Execute(MouseInfo& info); @@ -47,7 +47,7 @@ public: explicit JsWeakClickFunction(const JSRef& jsFunction) : JsWeakFunction(JSRef(), jsFunction) {} ~JsWeakClickFunction() override {}; - void Execute() override; + void Execute(); void Execute(const ClickInfo& info); void Execute(GestureEvent& info); void Execute(MouseInfo& info); diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_clipboard_function.h b/frameworks/bridge/declarative_frontend/engine/functions/js_clipboard_function.h index ead9a060477..4ffdec2bd7b 100644 --- a/frameworks/bridge/declarative_frontend/engine/functions/js_clipboard_function.h +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_clipboard_function.h @@ -26,7 +26,7 @@ class JsClipboardFunction : public JsFunction { public: explicit JsClipboardFunction(const JSRef& jsFunction) : JsFunction(JSRef(), jsFunction) {} ~JsClipboardFunction() override = default; - void Execute() override + void Execute() { ExecuteJS(); } diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_common_event_function.cpp b/frameworks/bridge/declarative_frontend/engine/functions/js_common_event_function.cpp new file mode 100644 index 00000000000..7f48f9c32b9 --- /dev/null +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_common_event_function.cpp @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "frameworks/bridge/declarative_frontend/engine/functions/js_common_event_function.h" + +namespace OHOS::Ace::Framework { + +} // namespace OHOS::Ace::Framework diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_common_event_function.h b/frameworks/bridge/declarative_frontend/engine/functions/js_common_event_function.h new file mode 100644 index 00000000000..3b19ffb2a5d --- /dev/null +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_common_event_function.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_FUNCTION_JS_COMMON_EVENT_FUNCTION_H +#define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_FUNCTION_JS_COMMON_EVENT_FUNCTION_H + +#include "frameworks/bridge/declarative_frontend/engine/functions/js_function.h" + +namespace OHOS::Ace::Framework { + +template +class ACE_EXPORT JsCommonEventFunction : public JsFunction { + DECLARE_ACE_TYPE(JsCommonEventFunction, JsFunction); + +public: + JsCommonEventFunction() = delete; + JsCommonEventFunction(const JSRef& jsFunction) + : JsFunction(JSRef(), jsFunction) {} + ~JsCommonEventFunction() override = default; + + void Execute(JSRef* argv) + { + JsFunction::ExecuteJS(ARGC, argv); + } +}; + +} // namespace OHOS::Ace::Framework + +#endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_FUNCTION_JS_COMMON_EVENT_FUNCTION_H diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_common_gesture_function.cpp b/frameworks/bridge/declarative_frontend/engine/functions/js_common_gesture_function.cpp new file mode 100644 index 00000000000..b5e17f6183b --- /dev/null +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_common_gesture_function.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "frameworks/bridge/declarative_frontend/engine/functions/js_common_gesture_function.h" + +namespace OHOS::Ace::Framework { + +JSRef JsCommonGestureFunction::GetTapLocation(const FingerInfo& fingerInfo) +{ + JSRef objectTemplate = JSRef::New(); + JSRef tapLocation = objectTemplate->NewInstance(); + const OHOS::Ace::Offset& localOffset = fingerInfo.localLocation_; + const OHOS::Ace::Offset& globalOffset = fingerInfo.globalLocation_; + const OHOS::Ace::Offset& screenOffset = fingerInfo.screenLocation_; + tapLocation->SetProperty("windowX", PipelineBase::Px2VpWithCurrentDensity(globalOffset.GetX())); + tapLocation->SetProperty("windowY", PipelineBase::Px2VpWithCurrentDensity(globalOffset.GetY())); + tapLocation->SetProperty("x", PipelineBase::Px2VpWithCurrentDensity(localOffset.GetX())); + tapLocation->SetProperty("y", PipelineBase::Px2VpWithCurrentDensity(localOffset.GetY())); + tapLocation->SetProperty("displayX", PipelineBase::Px2VpWithCurrentDensity(screenOffset.GetX())); + tapLocation->SetProperty("displayY", PipelineBase::Px2VpWithCurrentDensity(screenOffset.GetY())); + + return tapLocation; +} + +} // namespace OHOS::Ace::Framework diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_common_gesture_function.h b/frameworks/bridge/declarative_frontend/engine/functions/js_common_gesture_function.h new file mode 100644 index 00000000000..c7e78c5ea66 --- /dev/null +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_common_gesture_function.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_FUNCTION_JS_COMMON_GESTURE_FUNCTION_H +#define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_FUNCTION_JS_COMMON_GESTURE_FUNCTION_H + +#include "frameworks/bridge/declarative_frontend/engine/functions/js_function.h" + +namespace OHOS::Ace::Framework { + +class JsCommonGestureFunction : public JsFunction { + DECLARE_ACE_TYPE(JsCommonGestureFunction, JsFunction) + +public: + explicit JsCommonGestureFunction(const JSRef& jsFunction) + : JsFunction(jsFunction) {} + ~JsCommonGestureFunction() override = default; + +protected: + JSRef GetTapLocation(const FingerInfo& fingerInfo); +}; + +} // namespace OHOS::Ace::Framework + +#endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_FUNCTION_JS_COMMON_GESTURE_FUNCTION_H diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_common_utils.cpp b/frameworks/bridge/declarative_frontend/engine/functions/js_common_utils.cpp index 81c8a60bab2..a66b795d9ea 100644 --- a/frameworks/bridge/declarative_frontend/engine/functions/js_common_utils.cpp +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_common_utils.cpp @@ -59,6 +59,32 @@ JSRef CreateEventTargetObject(const std::shared_ptr& return target; } +JSRef CreateEventTargetObject(const BaseEventInfo& info) +{ + JSRef objectTemplate = JSRef::New(); + JSRef target = objectTemplate->NewInstance(); + JSRef area = objectTemplate->NewInstance(); + JSRef offset = objectTemplate->NewInstance(); + JSRef globalOffset = objectTemplate->NewInstance(); + const auto& localOffset = info.GetTarget().area.GetOffset(); + const auto& origin = info.GetTarget().origin; + offset->SetProperty("x", localOffset.GetX().ConvertToVp()); + offset->SetProperty("y", localOffset.GetY().ConvertToVp()); + globalOffset->SetProperty("x", (origin.GetX().ConvertToVp() + localOffset.GetX().ConvertToVp())); + globalOffset->SetProperty("y", (origin.GetY().ConvertToVp() + localOffset.GetY().ConvertToVp())); + area->SetPropertyObject("position", offset); + area->SetPropertyObject("globalPosition", globalOffset); + area->SetProperty("width", info.GetTarget().area.GetWidth().ConvertToVp()); + area->SetProperty("height", info.GetTarget().area.GetHeight().ConvertToVp()); + target->SetPropertyObject("area", area); + if (info.GetTarget().id.empty()) { + target->SetPropertyObject("id", JsiValue::Undefined()); + } else { + target->SetProperty("id", info.GetTarget().id.c_str()); + } + return target; +} + bool SetBaseGestureEventInfo(JSRef obj, const std::shared_ptr& info) { CHECK_NULL_RETURN(info, false); diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_common_utils.h b/frameworks/bridge/declarative_frontend/engine/functions/js_common_utils.h index 344586bd00d..f51a20a6c27 100644 --- a/frameworks/bridge/declarative_frontend/engine/functions/js_common_utils.h +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_common_utils.h @@ -28,6 +28,7 @@ namespace OHOS::Ace::Framework::CommonUtils { JSRef CreateFingerInfo(const FingerInfo& fingerInfo); JSRef CreateEventTargetObject(const std::shared_ptr& info); + JSRef CreateEventTargetObject(const BaseEventInfo& info); bool SetBaseGestureEventInfo(JSRef obj, const std::shared_ptr& info); JSRef CreateFingerInfosObject(const std::shared_ptr& info, JSRef& obj); } // namespace OHOS::Ace::Framework::CommonUtils diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_crown_function.cpp b/frameworks/bridge/declarative_frontend/engine/functions/js_crown_function.cpp old mode 100755 new mode 100644 index aeebcf41c50..65b029798ea --- a/frameworks/bridge/declarative_frontend/engine/functions/js_crown_function.cpp +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_crown_function.cpp @@ -1,47 +1,47 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "frameworks/bridge/declarative_frontend/engine/functions/js_crown_function.h" - -namespace OHOS::Ace::Framework { - -JSRef JsCrownFunction::createCrownEvent(CrownEventInfo& event) -{ - JSRef objectTemplate = JSRef::New(); - objectTemplate->SetInternalFieldCount(1); - JSRef crownEventObj = objectTemplate->NewInstance(); - crownEventObj->SetProperty("timestamp", static_cast - (event.GetTimeStamp().time_since_epoch().count())); - crownEventObj->SetProperty("angularVelocity", static_cast(event.GetAngularVelocity())); - crownEventObj->SetProperty("degree", static_cast(event.GetDegree())); - crownEventObj->SetProperty("action", static_cast(event.GetAction())); - crownEventObj->SetPropertyObject("stopPropagation", JSRef::New(JsStopPropagation)); - crownEventObj->Wrap(&event); - return crownEventObj; -} - -void JsCrownFunction::Execute(OHOS::Ace::CrownEventInfo& event) -{ - JSRef param = JSRef::Cast(createCrownEvent(event)); - JsFunction::ExecuteJS(1, ¶m); -} - -JSRef JsCrownFunction::ExecuteWithValue(OHOS::Ace::CrownEventInfo& event) -{ - JSRef param = JSRef::Cast(createCrownEvent(event)); - return JsFunction::ExecuteJS(1, ¶m); -} - +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "frameworks/bridge/declarative_frontend/engine/functions/js_crown_function.h" + +namespace OHOS::Ace::Framework { + +JSRef JsCrownFunction::createCrownEvent(CrownEventInfo& event) +{ + JSRef objectTemplate = JSRef::New(); + objectTemplate->SetInternalFieldCount(1); + JSRef crownEventObj = objectTemplate->NewInstance(); + crownEventObj->SetProperty("timestamp", static_cast + (event.GetTimeStamp().time_since_epoch().count())); + crownEventObj->SetProperty("angularVelocity", static_cast(event.GetAngularVelocity())); + crownEventObj->SetProperty("degree", static_cast(event.GetDegree())); + crownEventObj->SetProperty("action", static_cast(event.GetAction())); + crownEventObj->SetPropertyObject("stopPropagation", JSRef::New(JsStopPropagation)); + crownEventObj->Wrap(&event); + return crownEventObj; +} + +void JsCrownFunction::Execute(OHOS::Ace::CrownEventInfo& event) +{ + JSRef param = JSRef::Cast(createCrownEvent(event)); + JsFunction::ExecuteJS(1, ¶m); +} + +JSRef JsCrownFunction::ExecuteWithValue(OHOS::Ace::CrownEventInfo& event) +{ + JSRef param = JSRef::Cast(createCrownEvent(event)); + return JsFunction::ExecuteJS(1, ¶m); +} + } // namespace OHOS::Ace::Framework \ No newline at end of file diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_crown_function.h b/frameworks/bridge/declarative_frontend/engine/functions/js_crown_function.h old mode 100755 new mode 100644 index 52b787ccbf1..bb9bcd17b43 --- a/frameworks/bridge/declarative_frontend/engine/functions/js_crown_function.h +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_crown_function.h @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_FUNCTION_JS_CROWN_FUNCTION_H -#define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_FUNCTION_JS_CROWN_FUNCTION_H -#include "frameworks/bridge/declarative_frontend/engine/functions/js_function.h" -#include "frameworks/core/event/crown_event.h" - -namespace OHOS::Ace::Framework { - -class JsCrownFunction : public JsFunction { - DECLARE_ACE_TYPE(JsCrownFunction, JsFunction) -public: - explicit JsCrownFunction(const JSRef& jsFunction) - : JsFunction(JSRef(), jsFunction) {} - ~JsCrownFunction() override = default; - void Execute() override - { - ExecuteJS(); - } - void Execute(OHOS::Ace::CrownEventInfo& event); - - JSRef ExecuteWithValue(OHOS::Ace::CrownEventInfo& event); - -private: - JSRef createCrownEvent(OHOS::Ace::CrownEventInfo& event); -}; - -} // namespace OHOS::Ace::Framework - -#endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_FUNCTION_JS_CROWN_FUNCTION_H +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_FUNCTION_JS_CROWN_FUNCTION_H +#define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_FUNCTION_JS_CROWN_FUNCTION_H +#include "frameworks/bridge/declarative_frontend/engine/functions/js_function.h" +#include "frameworks/core/event/crown_event.h" + +namespace OHOS::Ace::Framework { + +class JsCrownFunction : public JsFunction { + DECLARE_ACE_TYPE(JsCrownFunction, JsFunction) +public: + explicit JsCrownFunction(const JSRef& jsFunction) + : JsFunction(JSRef(), jsFunction) {} + ~JsCrownFunction() override = default; + void Execute() + { + ExecuteJS(); + } + void Execute(OHOS::Ace::CrownEventInfo& event); + + JSRef ExecuteWithValue(OHOS::Ace::CrownEventInfo& event); + +private: + JSRef createCrownEvent(OHOS::Ace::CrownEventInfo& event); +}; + +} // namespace OHOS::Ace::Framework + +#endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_FUNCTION_JS_CROWN_FUNCTION_H diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_drag_function.h b/frameworks/bridge/declarative_frontend/engine/functions/js_drag_function.h index d6fa1afdc66..7acb12b61cd 100644 --- a/frameworks/bridge/declarative_frontend/engine/functions/js_drag_function.h +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_drag_function.h @@ -29,7 +29,7 @@ public: static void JSBind(BindingTarget globalObj); ~JsDragFunction() override {}; - void Execute() override; + void Execute(); JSRef Execute(const RefPtr& info); JSRef ItemDragStartExecute(const ItemDragInfo& info, int32_t itemIndex); void ItemDragEnterExecute(const ItemDragInfo& info); diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_event_function.cpp b/frameworks/bridge/declarative_frontend/engine/functions/js_event_function.cpp new file mode 100644 index 00000000000..3add0bbac08 --- /dev/null +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_event_function.cpp @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "frameworks/bridge/declarative_frontend/engine/functions/js_event_function.h" + +namespace OHOS::Ace::Framework { + +} // namespace OHOS::Ace::Framework diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_event_function.h b/frameworks/bridge/declarative_frontend/engine/functions/js_event_function.h new file mode 100644 index 00000000000..4b91bca2643 --- /dev/null +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_event_function.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_FUNCTION_JS_EVENT_FUNCTION_H +#define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_FUNCTION_JS_EVENT_FUNCTION_H + +#include "frameworks/bridge/declarative_frontend/engine/functions/js_function.h" + +namespace OHOS::Ace::Framework { + +template +class ACE_EXPORT JsEventFunction : public JsFunction { + DECLARE_ACE_TYPE(JsEventFunction, JsFunction); + +public: + using ParseFunc = std::function(const T&)>; + JsEventFunction() = delete; + JsEventFunction(const JSRef& jsFunction, ParseFunc parser) + : JsFunction(JSRef(), jsFunction), parser_(parser) + {} + ~JsEventFunction() override = default; + + void Execute(const T& eventInfo) + { + JSRef param; + if (parser_) { + param = parser_(eventInfo); + } + JsFunction::ExecuteJS(ARGC, ¶m); + } + + JSRef ExecuteWithValue(const T& eventInfo) + { + JSRef param; + if (parser_) { + param = parser_(eventInfo); + } + return JsFunction::ExecuteJS(ARGC, ¶m); + } + +private: + ParseFunc parser_; +}; + +} // namespace OHOS::Ace::Framework + +#endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_FUNCTION_JS_EVENT_FUNCTION_H diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_focus_function.h b/frameworks/bridge/declarative_frontend/engine/functions/js_focus_function.h index 056b2951c60..a8ebeedcd38 100644 --- a/frameworks/bridge/declarative_frontend/engine/functions/js_focus_function.h +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_focus_function.h @@ -28,7 +28,7 @@ public: ~JsFocusFunction() override = default; void Execute(int direction); - void Execute() override; + void Execute(); }; } // namespace OHOS::Ace::Framework diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_foreach_function.cpp b/frameworks/bridge/declarative_frontend/engine/functions/js_foreach_function.cpp index 0d79a2416e1..dc7a569bbe1 100644 --- a/frameworks/bridge/declarative_frontend/engine/functions/js_foreach_function.cpp +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_foreach_function.cpp @@ -38,7 +38,7 @@ std::vector JsForEachFunction::ExecuteIdentityMapper() jsKeysArr = JSRef::Cast(jsKeys); } } else { - jsKeysArr = JSRef::Cast(jsThis_.Lock()); + jsKeysArr = JSRef::Cast(This()); } int length = static_cast(jsKeysArr->Length()); @@ -63,11 +63,11 @@ std::vector JsForEachFunction::ExecuteIdentityMapper() void JsForEachFunction::ExecuteBuilderForIndex(int32_t index) { // indexed item - JSRef jsArray = JSRef::Cast(jsThis_.Lock()); + JSRef jsArray = JSRef::Cast(This()); JSRef params[2]; params[0] = jsArray->GetValueAt(index); params[1] = JSRef::Make(ToJSValue(index)); - jsViewMapperFunc_.Lock()->Call(jsThis_.Lock(), 2, params); + jsViewMapperFunc_.Lock()->Call(This(), 2, params); // 2: array size of params } } // namespace OHOS::Ace::Framework diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_function.cpp b/frameworks/bridge/declarative_frontend/engine/functions/js_function.cpp index e70fe82f4ec..ead984c9633 100644 --- a/frameworks/bridge/declarative_frontend/engine/functions/js_function.cpp +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_function.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -19,101 +19,10 @@ #include "base/log/ace_performance_monitor.h" #include "base/log/ace_trace.h" #include "base/log/log.h" -#include "frameworks/bridge/declarative_frontend/jsview/js_xcomponent.h" namespace OHOS::Ace::Framework { - -JsFunction::JsFunction(const JSRef& jsFunction) -{ - jsFunction_ = jsFunction; -} - -JsFunction::JsFunction(const JSRef& jsObject, const JSRef& jsFunction) -{ - jsThis_ = jsObject; - jsFunction_ = jsFunction; -} - -JsWeakFunction::JsWeakFunction(const JSRef& jsFunction) -{ - jsWeakFunction_ = jsFunction; -} - -JsWeakFunction::JsWeakFunction(const JSRef& jsObject, const JSRef& jsFunction) -{ - jsThis_ = jsObject; - jsWeakFunction_ = jsFunction; -} - -JSRef JsFunction::GetTapLocation(const FingerInfo& fingerInfo) -{ - JSRef objectTemplate = JSRef::New(); - JSRef tapLocation = objectTemplate->NewInstance(); - const OHOS::Ace::Offset& localOffset = fingerInfo.localLocation_; - const OHOS::Ace::Offset& globalOffset = fingerInfo.globalLocation_; - const OHOS::Ace::Offset& screenOffset = fingerInfo.screenLocation_; - tapLocation->SetProperty("windowX", PipelineBase::Px2VpWithCurrentDensity(globalOffset.GetX())); - tapLocation->SetProperty("windowY", PipelineBase::Px2VpWithCurrentDensity(globalOffset.GetY())); - tapLocation->SetProperty("x", PipelineBase::Px2VpWithCurrentDensity(localOffset.GetX())); - tapLocation->SetProperty("y", PipelineBase::Px2VpWithCurrentDensity(localOffset.GetY())); - tapLocation->SetProperty("displayX", PipelineBase::Px2VpWithCurrentDensity(screenOffset.GetX())); - tapLocation->SetProperty("displayY", PipelineBase::Px2VpWithCurrentDensity(screenOffset.GetY())); - - return tapLocation; -} - -JsFunction::~JsFunction() {} - -void JsFunctionBase::Execute(const JSRef& jsParamsObject) -{ - JSRef paramObj = JSRef::Cast(jsParamsObject); - ExecuteJS(1, ¶mObj); -} - -void JsFunctionBase::Execute(const std::vector& keys, const std::string& param) -{ - std::unique_ptr argsPtr = JsonUtil::ParseJsonString(param); - if (!argsPtr) { - return; - } - JSRef eventInfo = JSRef::New(); - for (auto iter = keys.begin(); iter != keys.end(); iter++) { - const std::string key = *iter; - const auto value = argsPtr->GetValue(key); - if (!value) { - LOGD("key[%{public}s] not exist.", key.c_str()); - continue; - } - ExecuteInternal(value, key, eventInfo); - } - - JSRef paramObj = JSRef::Cast(eventInfo); - ExecuteJS(1, ¶mObj); -} - -void JsFunctionBase::ExecuteWithContext( - const std::vector& keys, const std::string& param, const JSExecutionContext& context) -{ - std::unique_ptr argsPtr = JsonUtil::ParseJsonString(param); - if (!argsPtr) { - return; - } - JSRef eventInfo = JSRef::New(); - for (auto iter = keys.begin(); iter != keys.end(); iter++) { - const std::string key = *iter; - const auto value = argsPtr->GetValue(key); - if (!value) { - LOGD("key[%{public}s] not exist.", key.c_str()); - continue; - } - ExecuteInternal(value, key, eventInfo); - } - - JSRef paramObj = JSRef::Cast(eventInfo); - ExecuteJSWithContext(1, ¶mObj, context); -} - -void JsFunctionBase::ExecuteInternal(const std::unique_ptr& value, const std::string& key, +namespace { +void ExecuteInternal(const std::unique_ptr& value, const std::string& key, const JSRef& eventInfo) { if (value->IsString()) { @@ -138,117 +47,44 @@ void JsFunctionBase::ExecuteInternal(const std::unique_ptr& value, co eventInfo->SetPropertyObject(key.c_str(), valueArray); } } - -void JsFunctionBase::ExecuteNew(const std::vector& keys, const std::string& param) -{ - JSRef jsVal; - if (keys.size() > 1) { - auto result = XComponentClient::GetInstance().GetJSVal(keys[1], jsVal); - RefPtr controller = - XComponentClient::GetInstance().GetControllerFromJSXComponentControllersMap(keys[1]); - if (result && controller) { - controller->SetXComponentContext(jsVal); - } - } - ExecuteJS(1, &jsVal); } -JSRef JsWeakFunction::ExecuteJS(int argc, JSRef argv[], bool isAnimation) +void JsFunctionBase::Execute(const std::vector& keys, const std::string& param) { - int32_t id = -1; - if (SystemProperties::GetAcePerformanceMonitorEnabled()) { - id = Container::CurrentId(); + std::unique_ptr argsPtr = JsonUtil::ParseJsonString(param); + if (!argsPtr) { + return; } - JS_CALLBACK_DURATION(id); - JAVASCRIPT_EXECUTION_SCOPE_STATIC - ACE_FUNCTION_TRACE(); - JSRef jsObject = jsThis_.Lock(); - auto jsFunction = jsWeakFunction_.Lock(); - if (jsFunction.IsEmpty()) { - LOGW("js function is null."); - return {}; + JSRef eventInfo = JSRef::New(); + for (auto iter = keys.begin(); iter != keys.end(); iter++) { + const std::string key = *iter; + const auto value = argsPtr->GetValue(key); + if (!value) { + LOGD("key[%{public}s] not exist.", key.c_str()); + continue; + } + ExecuteInternal(value, key, eventInfo); } - JSRef result = jsFunction->Call(jsObject, argc, argv); - return result; + + JSRef paramObj = JSRef::Cast(eventInfo); + ExecuteJS(1, ¶mObj); } -#ifdef USE_ARK_ENGINE -JSRef JsWeakFunction::ExecuteJSWithContext( - int argc, JSRef argv[], const JSExecutionContext& context, bool isAnimation) +JSRef JsFunctionBase::ExecuteJS(int argc, JSRef argv[]) { int32_t id = -1; if (SystemProperties::GetAcePerformanceMonitorEnabled()) { id = Container::CurrentId(); } JS_CALLBACK_DURATION(id); - JAVASCRIPT_EXECUTION_SCOPE(context); + JAVASCRIPT_EXECUTION_SCOPE_STATIC; ACE_FUNCTION_TRACE(); - JSRef jsObject = jsThis_.Lock(); - auto jsFunction = jsWeakFunction_.Lock(); + auto jsFunction = GetFunction(); if (jsFunction.IsEmpty()) { LOGW("js function is null."); return {}; } - JSRef result = jsFunction->Call(jsObject, argc, argv); - return result; -} - -JSRef JsFunction::ExecuteJSWithContext( - int argc, JSRef argv[], const JSExecutionContext& context, bool isAnimation) -{ - int32_t id = -1; - if (SystemProperties::GetAcePerformanceMonitorEnabled()) { - id = Container::CurrentId(); - } - JS_CALLBACK_DURATION(id); - JAVASCRIPT_EXECUTION_SCOPE(context); - ACE_FUNCTION_TRACE(); - - JSRef jsObject = jsThis_.Lock(); - JSRef result = jsFunction_->Call(jsObject, argc, argv, isAnimation); - return result; -} -#endif - -JSRef JsFunction::ExecuteJS(int argc, JSRef argv[], bool isAnimation) -{ - int32_t id = -1; - if (SystemProperties::GetAcePerformanceMonitorEnabled()) { - id = Container::CurrentId(); - } - JS_CALLBACK_DURATION(id); - JAVASCRIPT_EXECUTION_SCOPE_STATIC - ACE_FUNCTION_TRACE(); - - JSRef jsObject = jsThis_.Lock(); - JSRef result = jsFunction_->Call(jsObject, argc, argv, isAnimation); - return result; -} - -JSRef CreateEventTargetObject(const BaseEventInfo& info) -{ - JSRef objectTemplate = JSRef::New(); - JSRef target = objectTemplate->NewInstance(); - JSRef area = objectTemplate->NewInstance(); - JSRef offset = objectTemplate->NewInstance(); - JSRef globalOffset = objectTemplate->NewInstance(); - const auto& localOffset = info.GetTarget().area.GetOffset(); - const auto& origin = info.GetTarget().origin; - offset->SetProperty("x", localOffset.GetX().ConvertToVp()); - offset->SetProperty("y", localOffset.GetY().ConvertToVp()); - globalOffset->SetProperty("x", (origin.GetX().ConvertToVp() + localOffset.GetX().ConvertToVp())); - globalOffset->SetProperty("y", (origin.GetY().ConvertToVp() + localOffset.GetY().ConvertToVp())); - area->SetPropertyObject("position", offset); - area->SetPropertyObject("globalPosition", globalOffset); - area->SetProperty("width", info.GetTarget().area.GetWidth().ConvertToVp()); - area->SetProperty("height", info.GetTarget().area.GetHeight().ConvertToVp()); - target->SetPropertyObject("area", area); - if (info.GetTarget().id.empty()) { - target->SetPropertyObject("id", JsiValue::Undefined()); - } else { - target->SetProperty("id", info.GetTarget().id.c_str()); - } - return target; + return jsFunction->Call(This(), argc, argv); } } // namespace OHOS::Ace::Framework diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_function.h b/frameworks/bridge/declarative_frontend/engine/functions/js_function.h index 994133ed570..319c2cd1ada 100644 --- a/frameworks/bridge/declarative_frontend/engine/functions/js_function.h +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_function.h @@ -24,9 +24,6 @@ #include "frameworks/bridge/declarative_frontend/engine/bindings.h" #include "frameworks/bridge/declarative_frontend/engine/js_execution_scope_defines.h" #include "frameworks/bridge/declarative_frontend/engine/js_ref_ptr.h" -#if defined(XCOMPONENT_SUPPORTED) -#include "frameworks/bridge/declarative_frontend/jsview/js_xcomponent_controller.h" -#endif namespace OHOS::Ace::Framework { @@ -34,230 +31,64 @@ class ACE_EXPORT JsFunctionBase : public virtual AceType { DECLARE_ACE_TYPE(JsFunctionBase, AceType); public: - virtual void Execute() + JsFunctionBase(const JSRef& jsObject) + : jsThis_(jsObject) {} + + void Execute() { ExecuteJS(); } - void Execute(const JSRef& jsParamsObject); void Execute(const std::vector& keys, const std::string& param); - void ExecuteWithContext( - const std::vector& keys, const std::string& param, const JSExecutionContext& context); - void ExecuteNew(const std::vector& keys, const std::string& param); - - virtual JSRef ExecuteJS(int argc) - { - return ExecuteJS(argc, nullptr); - } - virtual JSRef ExecuteJS(JSRef* argv) - { - return ExecuteJS(0, argv); - } - virtual JSRef ExecuteJS() - { - return ExecuteJS(0, nullptr); - } - // Empty realization in JsFunctionBase - virtual JSRef ExecuteJS(int argc, JSRef* argv, bool isAnimation = false) - { - JSRef eventInfo = JSRef::New(); - return JSRef::Cast(eventInfo); - } - -#ifdef USE_ARK_ENGINE - virtual JSRef ExecuteJSWithContext( - int argc, JSRef argv[], const JSExecutionContext& context, bool isAnimation = false) - { - JSRef eventInfo = JSRef::New(); - return JSRef::Cast(eventInfo); - } -#endif - -protected: - JSWeak jsThis_; - -private: - void ExecuteInternal(const std::unique_ptr& value, const std::string& key, - const JSRef& eventInfo); -}; - -class ACE_EXPORT JsFunction : public virtual JsFunctionBase { - DECLARE_ACE_TYPE(JsFunction, JsFunctionBase); - -public: - explicit JsFunction(const JSRef& jsFunction); - JsFunction(const JSRef& jsObject, const JSRef& jsFunction); - ~JsFunction() override; - - JSRef ExecuteJS(int argc) override - { - return ExecuteJS(argc, nullptr); - } - JSRef ExecuteJS(JSRef* argv) override - { - return ExecuteJS(0, argv); - } - JSRef ExecuteJS() override - { - return ExecuteJS(0, nullptr); - } - JSRef ExecuteJS(int argc, JSRef* argv, bool isAnimation = false) override; - -#ifdef USE_ARK_ENGINE - JSRef ExecuteJSWithContext(int argc, JSRef argv[], - const JSExecutionContext& context, bool isAnimation = false) override; -#endif - -protected: - JSRef GetTapLocation(const FingerInfo& fingerInfo); - JSRef jsFunction_; -}; - -class ACE_EXPORT JsWeakFunction : public virtual JsFunctionBase { - DECLARE_ACE_TYPE(JsWeakFunction, JsFunctionBase); - -public: - explicit JsWeakFunction(const JSRef& jsFunction); - JsWeakFunction(const JSRef& jsObject, const JSRef& jsFunction); - ~JsWeakFunction() override = default; - JSRef ExecuteJS(int argc) override - { - return ExecuteJS(argc, nullptr); - } - JSRef ExecuteJS(JSRef* argv) override - { - return ExecuteJS(0, argv); - } - JSRef ExecuteJS() override + JSRef ExecuteJS() { return ExecuteJS(0, nullptr); } - JSRef ExecuteJS(int argc, JSRef* argv, bool isAnimation = false) override; -#ifdef USE_ARK_ENGINE - JSRef ExecuteJSWithContext(int argc, JSRef argv[], - const JSExecutionContext& context, bool isAnimation = false) override; -#endif + JSRef ExecuteJS(int argc, JSRef argv[]); protected: - JSWeak jsWeakFunction_; -}; - -template -class ACE_EXPORT JsCitedEventFunction : public JsFunction { - DECLARE_ACE_TYPE(JsCitedEventFunction, JsFunction); - -public: - using ParseFunc = std::function(T&)>; - JsCitedEventFunction() = delete; - JsCitedEventFunction(const JSRef& jsFunction, ParseFunc parser) - : JsFunction(JSRef(), jsFunction), parser_(parser) - {} - ~JsCitedEventFunction() override = default; - - void Execute() override + JSRef This() { - JsFunction::ExecuteJS(); - } - - void Execute(T& eventInfo) - { - JSRef param; - if (parser_) { - param = parser_(eventInfo); - } - JsFunction::ExecuteJS(ARGC, ¶m); - } - - void Execute(const std::string& val, T& eventInfo) - { - JSRef jsVal = JSRef::Make(ToJSValue(val)); - JSRef itemInfo; - if (parser_) { - itemInfo = parser_(eventInfo); - } - JSRef params[] = { jsVal, itemInfo }; - JsFunction::ExecuteJS(ARGC, params); - } - - void Execute(const std::u16string& val, T& eventInfo) - { - JSRef jsVal = JSRef::Make(ToJSValue(val)); - JSRef itemInfo; - if (parser_) { - itemInfo = parser_(eventInfo); - } - JSRef params[] = { jsVal, itemInfo }; - JsFunction::ExecuteJS(ARGC, params); + return jsThis_.Lock(); } + virtual JSRef GetFunction() = 0; private: - ParseFunc parser_; + JSWeak jsThis_; }; -template -class ACE_EXPORT JsCommonEventFunction : public JsFunction { - DECLARE_ACE_TYPE(JsCommonEventFunction, JsFunction); +template class Ref = JSRef> +class ACE_EXPORT JsFunctionT : public JsFunctionBase { + DECLARE_ACE_TYPE(JsFunctionT, JsFunctionBase); public: - JsCommonEventFunction() = delete; - JsCommonEventFunction(const JSRef& jsFunction) - : JsFunction(JSRef(), jsFunction) - {} - ~JsCommonEventFunction() override = default; + explicit JsFunctionT(const JSRef& jsFunction) + : JsFunctionT({}, jsFunction) {} + JsFunctionT(const JSRef& jsObject, const JSRef& jsFunction) + : JsFunctionBase(jsObject), jsFunction_(jsFunction) {} + ~JsFunctionT() override = default; - void Execute() override - { - JsFunction::ExecuteJS(); - } - - void Execute(JSRef* argv) - { - JsFunction::ExecuteJS(ARGC, argv); - } +protected: + JSRef GetFunction() override; + Ref jsFunction_; }; -template -class ACE_EXPORT JsEventFunction : public JsFunction { - DECLARE_ACE_TYPE(JsEventFunction, JsFunction); - -public: - using ParseFunc = std::function(const T&)>; - JsEventFunction() = delete; - JsEventFunction(const JSRef& jsFunction, ParseFunc parser) - : JsFunction(JSRef(), jsFunction), parser_(parser) - {} - ~JsEventFunction() override = default; +using JsFunction = JsFunctionT; +using JsWeakFunction = JsFunctionT; - void Execute() override - { - JsFunction::ExecuteJS(); - } - - void Execute(const T& eventInfo) - { - JSRef param; - if (parser_) { - param = parser_(eventInfo); - } - JsFunction::ExecuteJS(ARGC, ¶m); - } - - JSRef ExecuteWithValue(const T& eventInfo) - { - JSRef param; - if (parser_) { - param = parser_(eventInfo); - } - return JsFunction::ExecuteJS(ARGC, ¶m); - } - -private: - ParseFunc parser_; -}; +template<> +inline JSRef JsWeakFunction::GetFunction() +{ + return jsFunction_.Lock(); +} -JSRef CreateEventTargetObject(const BaseEventInfo& info); +template<> +inline JSRef JsFunction::GetFunction() +{ + return jsFunction_; +} } // namespace OHOS::Ace::Framework diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_gesture_function.cpp b/frameworks/bridge/declarative_frontend/engine/functions/js_gesture_function.cpp index 4e6b827827c..79594cf7cc1 100644 --- a/frameworks/bridge/declarative_frontend/engine/functions/js_gesture_function.cpp +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_gesture_function.cpp @@ -18,9 +18,10 @@ #include "base/log/log.h" #include "frameworks/bridge/declarative_frontend/jsview/js_view_register.h" +#include "frameworks/bridge/declarative_frontend/engine/functions/js_common_utils.h" namespace OHOS::Ace::Framework { - +using namespace OHOS::Ace::Framework::CommonUtils; void JsGestureFunction::Execute() { JsFunction::Execute(); diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_gesture_function.h b/frameworks/bridge/declarative_frontend/engine/functions/js_gesture_function.h index bbfab4788a0..fa3675b1336 100644 --- a/frameworks/bridge/declarative_frontend/engine/functions/js_gesture_function.h +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_gesture_function.h @@ -16,19 +16,20 @@ #ifndef FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_FUNCTION_JS_GESTURE_FUNCTION_H #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_FUNCTION_JS_GESTURE_FUNCTION_H -#include "frameworks/bridge/declarative_frontend/engine/functions/js_function.h" +#include "frameworks/bridge/declarative_frontend/engine/functions/js_common_gesture_function.h" #include "frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h" namespace OHOS::Ace::Framework { -class JsGestureFunction : public JsFunction { - DECLARE_ACE_TYPE(JsGestureFunction, JsFunction) +class JsGestureFunction : public JsCommonGestureFunction { + DECLARE_ACE_TYPE(JsGestureFunction, JsCommonGestureFunction) public: - explicit JsGestureFunction(const JSRef& jsFunction) : JsFunction(JSRef(), jsFunction) {} + explicit JsGestureFunction(const JSRef& jsFunction) + : JsCommonGestureFunction(jsFunction) {} ~JsGestureFunction() override {}; - void Execute() override; + void Execute(); void Execute(const GestureEvent& info); private: diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_gesture_judge_function.h b/frameworks/bridge/declarative_frontend/engine/functions/js_gesture_judge_function.h index af13a716d58..6af38d1f2cb 100644 --- a/frameworks/bridge/declarative_frontend/engine/functions/js_gesture_judge_function.h +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_gesture_judge_function.h @@ -23,19 +23,20 @@ #include "core/components/common/layout/constants.h" #include "core/components_ng/gestures/base_gesture_event.h" #include "core/gestures/gesture_info.h" -#include "frameworks/bridge/declarative_frontend/engine/functions/js_function.h" +#include "frameworks/bridge/declarative_frontend/engine/functions/js_common_gesture_function.h" namespace OHOS::Ace::Framework { using TouchRecognizerMap = std::map, std::unordered_set>; -class JsGestureJudgeFunction : public JsFunction { - DECLARE_ACE_TYPE(JsGestureJudgeFunction, JsFunction) +class JsGestureJudgeFunction : public JsCommonGestureFunction { + DECLARE_ACE_TYPE(JsGestureJudgeFunction, JsCommonGestureFunction) public: - explicit JsGestureJudgeFunction(const JSRef& jsFunction) : JsFunction(JSRef(), jsFunction) {} + explicit JsGestureJudgeFunction(const JSRef& jsFunction) + : JsCommonGestureFunction(jsFunction) {} ~JsGestureJudgeFunction() override = default; - void Execute() override + void Execute() { ExecuteJS(); } diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_hover_function.cpp b/frameworks/bridge/declarative_frontend/engine/functions/js_hover_function.cpp index 75edd2eba6a..f086344ff30 100644 --- a/frameworks/bridge/declarative_frontend/engine/functions/js_hover_function.cpp +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_hover_function.cpp @@ -16,8 +16,10 @@ #include "frameworks/bridge/declarative_frontend/engine/functions/js_hover_function.h" #include "frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h" +#include "frameworks/bridge/declarative_frontend/engine/functions/js_common_utils.h" namespace OHOS::Ace::Framework { +using namespace OHOS::Ace::Framework::CommonUtils; void JsHoverFunction::HoverExecute(bool isHover, HoverInfo& hoverInfo) { JSRef isHoverParam = JSRef::Make(ToJSValue(isHover)); diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_key_function.h b/frameworks/bridge/declarative_frontend/engine/functions/js_key_function.h index 268e8bb0223..7c759b4f80f 100644 --- a/frameworks/bridge/declarative_frontend/engine/functions/js_key_function.h +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_key_function.h @@ -28,7 +28,7 @@ public: explicit JsKeyFunction(const JSRef& jsFunction) : JsFunction(JSRef(), jsFunction) {} ~JsKeyFunction() override = default; - void Execute() override + void Execute() { ExecuteJS(); } diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_navigation_function.h b/frameworks/bridge/declarative_frontend/engine/functions/js_navigation_function.h index 081ae160226..2e9b4dda595 100644 --- a/frameworks/bridge/declarative_frontend/engine/functions/js_navigation_function.h +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_navigation_function.h @@ -32,7 +32,7 @@ public: ~JsNavigationFunction() override {}; - void Execute() override + void Execute() { ExecuteJS(); } diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_on_area_change_function.h b/frameworks/bridge/declarative_frontend/engine/functions/js_on_area_change_function.h index 2b28cf13d91..52e0cd2c517 100644 --- a/frameworks/bridge/declarative_frontend/engine/functions/js_on_area_change_function.h +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_on_area_change_function.h @@ -32,7 +32,7 @@ class JsOnAreaChangeFunction : public JsFunction { public: explicit JsOnAreaChangeFunction(const JSRef& jsFunction) : JsFunction(jsFunction) {} ~JsOnAreaChangeFunction() override = default; - void Execute() override + void Execute() { ExecuteJS(); } diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_on_child_touch_test_function.h b/frameworks/bridge/declarative_frontend/engine/functions/js_on_child_touch_test_function.h index 180bba24c34..6459dd15fb7 100644 --- a/frameworks/bridge/declarative_frontend/engine/functions/js_on_child_touch_test_function.h +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_on_child_touch_test_function.h @@ -25,7 +25,7 @@ class JsOnChildTouchTestFunction : public JsFunction { public: explicit JsOnChildTouchTestFunction(const JSRef& jsFunction) : JsFunction(JSRef(), jsFunction) {} ~JsOnChildTouchTestFunction() override = default; - void Execute() override; + void Execute(); JSRef Execute(const std::vector& touchInfo); private: diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_on_size_change_function.h b/frameworks/bridge/declarative_frontend/engine/functions/js_on_size_change_function.h index cc038dfffc5..4cb265ff295 100644 --- a/frameworks/bridge/declarative_frontend/engine/functions/js_on_size_change_function.h +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_on_size_change_function.h @@ -32,7 +32,7 @@ class JsOnSizeChangeFunction : public JsFunction { public: explicit JsOnSizeChangeFunction(const JSRef& jsFunction) : JsFunction(jsFunction) {} ~JsOnSizeChangeFunction() override = default; - void Execute() override + void Execute() { ExecuteJS(); } diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_page_transition_function.h b/frameworks/bridge/declarative_frontend/engine/functions/js_page_transition_function.h index a2dc40e597e..cdd5e1309f4 100644 --- a/frameworks/bridge/declarative_frontend/engine/functions/js_page_transition_function.h +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_page_transition_function.h @@ -29,7 +29,7 @@ public: explicit JsPageTransitionFunction(const JSRef& jsFunction) : JsFunction(JSRef(), jsFunction) {} ~JsPageTransitionFunction() override {}; - void Execute() override + void Execute() { ExecuteJS(); } diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_pan_function.h b/frameworks/bridge/declarative_frontend/engine/functions/js_pan_function.h index e1429dec392..6e73d009855 100644 --- a/frameworks/bridge/declarative_frontend/engine/functions/js_pan_function.h +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_pan_function.h @@ -33,7 +33,7 @@ public: void Execute(const DragStartInfo& info); void Execute(const DragUpdateInfo& info); void Execute(const DragEndInfo& info); - void Execute() override; + void Execute(); private: JSRef createPanInfo(const TouchLocationInfo& info); diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_should_built_in_recognizer_parallel_with_function.h b/frameworks/bridge/declarative_frontend/engine/functions/js_should_built_in_recognizer_parallel_with_function.h index a0d758bf608..9fb497ad00a 100644 --- a/frameworks/bridge/declarative_frontend/engine/functions/js_should_built_in_recognizer_parallel_with_function.h +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_should_built_in_recognizer_parallel_with_function.h @@ -29,7 +29,7 @@ public: ~JsShouldBuiltInRecognizerParallelWithFunction() override = default; - void Execute() override + void Execute() { ExecuteJS(); } diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_swiper_function.h b/frameworks/bridge/declarative_frontend/engine/functions/js_swiper_function.h index d830b2c6dcd..fe82b642ae1 100644 --- a/frameworks/bridge/declarative_frontend/engine/functions/js_swiper_function.h +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_swiper_function.h @@ -32,7 +32,7 @@ public: ~JsSwiperFunction() override {}; - void Execute() override + void Execute() { ExecuteJS(); } diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_tabs_function.h b/frameworks/bridge/declarative_frontend/engine/functions/js_tabs_function.h index 985b18d573f..e15417bc726 100644 --- a/frameworks/bridge/declarative_frontend/engine/functions/js_tabs_function.h +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_tabs_function.h @@ -29,7 +29,7 @@ public: ~JsTabsFunction() override {}; - void Execute() override + void Execute() { ExecuteJS(); } diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_touch_function.cpp b/frameworks/bridge/declarative_frontend/engine/functions/js_touch_function.cpp index 5ca7a56569e..195acdcd123 100644 --- a/frameworks/bridge/declarative_frontend/engine/functions/js_touch_function.cpp +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_touch_function.cpp @@ -17,10 +17,12 @@ #include "frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h" #include "base/log/log.h" +#include "bridge/declarative_frontend/engine/functions/js_common_utils.h" #include "bridge/declarative_frontend/engine/functions/js_function.h" #include "frameworks/bridge/declarative_frontend/jsview/js_view_register.h" namespace OHOS::Ace::Framework { +using namespace OHOS::Ace::Framework::CommonUtils; JSRef JsTouchFunction::CreateTouchInfo(const TouchLocationInfo& touchInfo, TouchEventInfo& info) { diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_touch_function.h b/frameworks/bridge/declarative_frontend/engine/functions/js_touch_function.h index 705ad942858..1f7c5798aea 100644 --- a/frameworks/bridge/declarative_frontend/engine/functions/js_touch_function.h +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_touch_function.h @@ -32,7 +32,7 @@ public: {} ~JsTouchFunction() override {}; - void Execute() override + void Execute() { JsFunction::Execute(); } diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_touch_intercept_function.h b/frameworks/bridge/declarative_frontend/engine/functions/js_touch_intercept_function.h index dade10fcf9b..4fd1c272209 100644 --- a/frameworks/bridge/declarative_frontend/engine/functions/js_touch_intercept_function.h +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_touch_intercept_function.h @@ -27,7 +27,7 @@ public: ~JsTouchInterceptFunction() override = default; - void Execute() override + void Execute() { ExecuteJS(); } diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_touch_test_done_function.h b/frameworks/bridge/declarative_frontend/engine/functions/js_touch_test_done_function.h index d8be22151e2..f50082ce29c 100644 --- a/frameworks/bridge/declarative_frontend/engine/functions/js_touch_test_done_function.h +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_touch_test_done_function.h @@ -34,7 +34,7 @@ public: ~JsTouchTestDoneFunction() override = default; - void Execute() override + void Execute() { ExecuteJS(); } diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_webview_function.h b/frameworks/bridge/declarative_frontend/engine/functions/js_webview_function.h index 7201b2c1e5a..2fe65c6d9bb 100644 --- a/frameworks/bridge/declarative_frontend/engine/functions/js_webview_function.h +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_webview_function.h @@ -26,7 +26,7 @@ public: explicit JsWebViewFunction(const JSRef& jsFunction) : JsFunction(JSRef(), jsFunction) {} ~JsWebViewFunction() override = default; - void Execute() override + void Execute() { ExecuteJS(); } diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_xcomponent_onload_function.cpp b/frameworks/bridge/declarative_frontend/engine/functions/js_xcomponent_onload_function.cpp new file mode 100644 index 00000000000..34ebbfa2271 --- /dev/null +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_xcomponent_onload_function.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "frameworks/bridge/declarative_frontend/engine/functions/js_xcomponent_onload_function.h" + +#if defined(XCOMPONENT_SUPPORTED) +#include "frameworks/bridge/declarative_frontend/jsview/js_xcomponent_controller.h" +#endif +#include "frameworks/bridge/declarative_frontend/jsview/js_xcomponent.h" + +namespace OHOS::Ace::Framework { + +void JsXComponentOnloadFunction::ExecuteNew(const std::vector& keys, const std::string& param) +{ + JSRef jsVal; + if (keys.size() > 1) { + auto result = XComponentClient::GetInstance().GetJSVal(keys[1], jsVal); + RefPtr controller = + XComponentClient::GetInstance().GetControllerFromJSXComponentControllersMap(keys[1]); + if (result && controller) { + controller->SetXComponentContext(jsVal); + } + } + ExecuteJS(1, &jsVal); +} + +} // namespace OHOS::Ace::Framework diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_xcomponent_onload_function.h b/frameworks/bridge/declarative_frontend/engine/functions/js_xcomponent_onload_function.h new file mode 100644 index 00000000000..282ee9067e7 --- /dev/null +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_xcomponent_onload_function.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_FUNCTION_JS_XCOMPONENT_ONLOAD_FUNCTION_H +#define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_FUNCTION_JS_XCOMPONENT_ONLOAD_FUNCTION_H + +#include "frameworks/bridge/declarative_frontend/engine/functions/js_function.h" + +namespace OHOS::Ace::Framework { + +class JsXComponentOnloadFunction : public JsFunction { + DECLARE_ACE_TYPE(JsXComponentOnloadFunction, JsFunction) + +public: + explicit JsXComponentOnloadFunction(const JSRef& jsFunction) + : JsFunction(jsFunction) {} + ~JsXComponentOnloadFunction() override = default; + + void ExecuteNew(const std::vector& keys, const std::string& param); +}; + +} // namespace OHOS::Ace::Framework + +#endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_FUNCTION_JS_XCOMPONENT_ONLOAD_FUNCTION_H diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/jsi_types.cpp b/frameworks/bridge/declarative_frontend/engine/jsi/jsi_types.cpp index be5f795b40e..224b51b0d89 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/jsi_types.cpp +++ b/frameworks/bridge/declarative_frontend/engine/jsi/jsi_types.cpp @@ -395,7 +395,7 @@ JsiFunction::JsiFunction(panda::Local val) : JsiType(val) {} JsiFunction::JsiFunction(const EcmaVM *vm, panda::Local val) : JsiType(vm, val) {} -JsiRef JsiFunction::Call(JsiRef thisVal, int argc, JsiRef argv[], bool isAnimation) const +JsiRef JsiFunction::Call(JsiRef thisVal, int argc, JsiRef argv[]) const { int32_t id = -1; if (SystemProperties::GetAcePerformanceMonitorEnabled()) { @@ -406,30 +406,17 @@ JsiRef JsiFunction::Call(JsiRef thisVal, int argc, JsiRefGetName(vm)->ToString(vm).c_str()); + funcName = GetHandle()->GetName(vm)->ToString(vm); } + ACE_SCOPED_TRACE("ExecuteJS[%s]", funcName.c_str()); std::vector> arguments; for (int i = 0; i < argc; ++i) { arguments.emplace_back(argv[i].Get().GetLocalHandle()); } auto thisObj = thisVal.Get().GetLocalHandle(); - if (isAnimation) { - if (GetHandle().IsEmpty() || !GetHandle()->IsFunction(vm) || trycatch.HasCaught()) { - TAG_LOGW(AceLogTag::ACE_ANIMATION, - "call function handle is empty or not function, empty: %{public}d, hasError: %{public}d", - GetHandle().IsEmpty(), trycatch.HasCaught()); - } else { - TAG_LOGI( - AceLogTag::ACE_ANIMATION, "call function: %{public}s", GetHandle()->GetName(vm)->ToString(vm).c_str()); - } - } auto result = GetHandle()->Call(vm, thisObj, arguments.data(), argc); - if (isAnimation && !result.IsEmpty()) { - TAG_LOGI( - AceLogTag::ACE_ANIMATION, "call function result: %{public}s", result->ToString(vm)->ToString(vm).c_str()); - } JSNApi::ExecutePendingJob(vm); auto runtime = std::static_pointer_cast(JsiDeclarativeEngineInstance::GetCurrentRuntime()); if (result.IsEmpty() || trycatch.HasCaught()) { @@ -438,9 +425,6 @@ JsiRef JsiFunction::Call(JsiRef thisVal, int argc, JsiRefHandleUncaughtException(trycatch); result = JSValueRef::Undefined(vm); } - if (traceEnabled) { - AceTraceEnd(); - } return JsiRef::Make(result); } diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/jsi_types.h b/frameworks/bridge/declarative_frontend/engine/jsi/jsi_types.h index 802bae3133f..fbfae0b376a 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/jsi_types.h +++ b/frameworks/bridge/declarative_frontend/engine/jsi/jsi_types.h @@ -281,8 +281,7 @@ public: explicit JsiFunction(const panda::CopyableGlobal& val); ~JsiFunction() override = default; - JsiRef Call( - JsiRef thisVal, int argc = 0, JsiRef argv[] = nullptr, bool isAnimation = false) const; + JsiRef Call(JsiRef thisVal, int argc = 0, JsiRef argv[] = nullptr) const; static panda::Local New(JsiFunctionCallback func); template static auto Cast(const JsiType& that) @@ -321,7 +320,8 @@ public: }; struct JsiExecutionContext { - panda::ecmascript::EcmaVM* vm_ = nullptr; + JsiExecutionContext(panda::ecmascript::EcmaVM* vm = nullptr): vm_(vm) {} + panda::ecmascript::EcmaVM* vm_; }; class JsiCallbackInfo { diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_frame_node_bridge.cpp b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_frame_node_bridge.cpp index 90424e8162d..596bbd9a8e8 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_frame_node_bridge.cpp +++ b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_frame_node_bridge.cpp @@ -105,7 +105,7 @@ std::function ParseFinishCallback(const panda::Local& panda::Local onFinishValue = obj->Get(vm, "onFinish"); if (onFinishValue->IsFunction(vm)) { panda::Local onFinish = onFinishValue->ToObject(vm); - finishCount = GetAnimationFinshCount(); + finishCount = GetAnimationFinishCount(); return [func = panda::CopyableGlobal(vm, onFinish), id = Container::CurrentIdSafely(), node = AceType::WeakClaim(frameNode), count = finishCount.value(), vm]() mutable { if (func.IsEmpty()) { diff --git a/frameworks/bridge/declarative_frontend/jsview/js_checkboxgroup.cpp b/frameworks/bridge/declarative_frontend/jsview/js_checkboxgroup.cpp index db22cccd619..ae343f144c3 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_checkboxgroup.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_checkboxgroup.cpp @@ -15,6 +15,7 @@ #include "bridge/declarative_frontend/jsview/js_checkboxgroup.h" +#include "bridge/declarative_frontend/engine/functions/js_event_function.h" #include "bridge/declarative_frontend/jsview/js_interactable_view.h" #include "bridge/declarative_frontend/jsview/js_view_common_def.h" #include "bridge/declarative_frontend/jsview/models/checkboxgroup_model_impl.h" diff --git a/frameworks/bridge/declarative_frontend/jsview/js_datepicker.cpp b/frameworks/bridge/declarative_frontend/jsview/js_datepicker.cpp index 921a6ffc6de..05ddd56755b 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_datepicker.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_datepicker.cpp @@ -20,7 +20,7 @@ #include "base/log/ace_scoring_log.h" #include "base/utils/utils.h" #include "bridge/common/utils/engine_helper.h" -#include "bridge/declarative_frontend/engine/functions/js_function.h" +#include "bridge/declarative_frontend/engine/functions/js_event_function.h" #include "bridge/declarative_frontend/jsview/js_interactable_view.h" #include "bridge/declarative_frontend/jsview/js_utils.h" #include "bridge/declarative_frontend/jsview/js_view_common_def.h" diff --git a/frameworks/bridge/declarative_frontend/jsview/js_dynamic_component.cpp b/frameworks/bridge/declarative_frontend/jsview/js_dynamic_component.cpp index d74846d257f..5f256d537e3 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_dynamic_component.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_dynamic_component.cpp @@ -177,7 +177,7 @@ void JSDynamicComponent::JsOnError(const JSCallbackInfo& info) obj->SetProperty("name", name); obj->SetProperty("message", message); auto returnValue = JSRef::Cast(obj); - func->ExecuteJSWithContext(1, &returnValue, execCtx); + func->ExecuteJS(1, &returnValue); }; NG::DynamicModelNG::GetInstance()->SetPlatformOnError(std::move(onError)); } diff --git a/frameworks/bridge/declarative_frontend/jsview/js_folder_stack.cpp b/frameworks/bridge/declarative_frontend/jsview/js_folder_stack.cpp index 74b9a81d5ca..4f7bb16c2ce 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_folder_stack.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_folder_stack.cpp @@ -23,6 +23,7 @@ #include "core/common/container.h" #include "core/common/display_info.h" #include "core/components_ng/pattern/folder_stack/folder_stack_event_info.h" +#include "frameworks/bridge/declarative_frontend/engine/functions/js_event_function.h" #include "frameworks/bridge/declarative_frontend/engine/js_ref_ptr.h" #include "frameworks/bridge/declarative_frontend/jsview/js_view_common_def.h" #include "frameworks/bridge/declarative_frontend/jsview/models/stack_model_impl.h" diff --git a/frameworks/bridge/declarative_frontend/jsview/js_image.cpp b/frameworks/bridge/declarative_frontend/jsview/js_image.cpp index 205dfaabeaa..5311d9f42b2 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_image.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_image.cpp @@ -34,6 +34,7 @@ #include "base/log/ace_trace.h" #include "bridge/common/utils/engine_helper.h" #include "bridge/declarative_frontend/engine/functions/js_drag_function.h" +#include "bridge/declarative_frontend/engine/functions/js_event_function.h" #include "bridge/declarative_frontend/engine/js_ref_ptr.h" #include "bridge/declarative_frontend/engine/js_types.h" #include "bridge/declarative_frontend/engine/jsi/js_ui_index.h" diff --git a/frameworks/bridge/declarative_frontend/jsview/js_image_span.cpp b/frameworks/bridge/declarative_frontend/jsview/js_image_span.cpp index 06428030c6c..341dfe21bd3 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_image_span.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_image_span.cpp @@ -25,6 +25,7 @@ #include "core/components_ng/pattern/image/image_model.h" #include "core/components_ng/pattern/text/image_span_view.h" #include "bridge/declarative_frontend/jsview/js_view_common_def.h" +#include "bridge/declarative_frontend/engine/functions/js_event_function.h" #include "frameworks/bridge/declarative_frontend/jsview/js_image.h" namespace OHOS::Ace::Framework { diff --git a/frameworks/bridge/declarative_frontend/jsview/js_indicator.cpp b/frameworks/bridge/declarative_frontend/jsview/js_indicator.cpp index 9689cdc6fbd..4d095d5003a 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_indicator.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_indicator.cpp @@ -15,6 +15,7 @@ #include "frameworks/bridge/declarative_frontend/jsview/js_indicator.h" +#include "bridge/declarative_frontend/engine/functions/js_event_function.h" #include "bridge/declarative_frontend/engine/jsi/js_ui_index.h" #include "core/components/swiper/swiper_indicator_theme.h" #include "core/components_ng/base/view_stack_processor.h" diff --git a/frameworks/bridge/declarative_frontend/jsview/js_isolated_component.cpp b/frameworks/bridge/declarative_frontend/jsview/js_isolated_component.cpp index 4fa7bd44e8e..238fc27afa1 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_isolated_component.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_isolated_component.cpp @@ -140,7 +140,7 @@ void JSIsolatedComponent::JsOnError(const JSCallbackInfo& info) obj->SetProperty("name", name); obj->SetProperty("message", message); auto returnValue = JSRef::Cast(obj); - func->ExecuteJSWithContext(1, &returnValue, execCtx); + func->ExecuteJS(1, &returnValue); }; UIExtensionModel::GetInstance()->SetPlatformOnError(std::move(onError)); } diff --git a/frameworks/bridge/declarative_frontend/jsview/js_location_button.cpp b/frameworks/bridge/declarative_frontend/jsview/js_location_button.cpp index fd6e0647f84..fa623fa36ab 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_location_button.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_location_button.cpp @@ -19,6 +19,7 @@ #endif #include "bridge/common/utils/utils.h" +#include "bridge/declarative_frontend/engine/functions/js_common_utils.h" #include "core/common/container.h" #include "core/components/common/properties/text_style.h" #include "core/components_ng/base/view_abstract_model.h" @@ -29,6 +30,7 @@ using OHOS::Ace::NG::LocationButtonModelNG; using OHOS::Ace::NG::SecurityComponentTheme; namespace OHOS::Ace::Framework { +using namespace OHOS::Ace::Framework::CommonUtils; bool JSLocationButton::ParseComponentStyle(const JSCallbackInfo& info, LocationButtonLocationDescription& text, LocationButtonIconStyle& icon, int32_t& bg) { diff --git a/frameworks/bridge/declarative_frontend/jsview/js_location_button.h b/frameworks/bridge/declarative_frontend/jsview/js_location_button.h index 7b61a94ef34..0c867748160 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_location_button.h +++ b/frameworks/bridge/declarative_frontend/jsview/js_location_button.h @@ -33,7 +33,7 @@ public: JsFunction(JSRef(), jsFunction) {} ~JsLocationButtonClickFunction() override {}; - void Execute() override + void Execute() { JsFunction::ExecuteJS(); }; diff --git a/frameworks/bridge/declarative_frontend/jsview/js_navigation.cpp b/frameworks/bridge/declarative_frontend/jsview/js_navigation.cpp index 3b3902570eb..bc711107fdc 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_navigation.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_navigation.cpp @@ -21,6 +21,7 @@ #include "base/memory/referenced.h" #include "base/system_bar/system_bar_style.h" #include "bridge/declarative_frontend/engine/functions/js_click_function.h" +#include "bridge/declarative_frontend/engine/functions/js_event_function.h" #include "bridge/declarative_frontend/engine/functions/js_navigation_function.h" #include "bridge/declarative_frontend/engine/js_converter.h" #include "bridge/declarative_frontend/engine/js_ref_ptr.h" diff --git a/frameworks/bridge/declarative_frontend/jsview/js_paste_button.cpp b/frameworks/bridge/declarative_frontend/jsview/js_paste_button.cpp index bd56d1b9688..244dd4f6c56 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_paste_button.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_paste_button.cpp @@ -19,6 +19,7 @@ #endif #include "bridge/common/utils/utils.h" +#include "bridge/declarative_frontend/engine/functions/js_common_utils.h" #include "core/common/container.h" #include "core/components/common/properties/text_style.h" #include "core/components_ng/base/view_abstract_model.h" @@ -29,6 +30,7 @@ using OHOS::Ace::NG::PasteButtonModelNG; using OHOS::Ace::NG::SecurityComponentTheme; namespace OHOS::Ace::Framework { +using namespace OHOS::Ace::Framework::CommonUtils; bool JSPasteButton::ParseComponentStyle(const JSCallbackInfo& info, PasteButtonPasteDescription& text, PasteButtonIconStyle& icon, int32_t& bg) { diff --git a/frameworks/bridge/declarative_frontend/jsview/js_paste_button.h b/frameworks/bridge/declarative_frontend/jsview/js_paste_button.h index fafff9c9c88..8d875c26690 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_paste_button.h +++ b/frameworks/bridge/declarative_frontend/jsview/js_paste_button.h @@ -33,7 +33,7 @@ public: JsFunction(JSRef(), jsFunction) {} ~JsPasteButtonClickFunction() override {}; - void Execute() override + void Execute() { JsFunction::ExecuteJS(); }; diff --git a/frameworks/bridge/declarative_frontend/jsview/js_plugin.cpp b/frameworks/bridge/declarative_frontend/jsview/js_plugin.cpp index 00e4c9f6f53..f970b0f3245 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_plugin.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_plugin.cpp @@ -134,7 +134,7 @@ void JSPlugin::JsOnComplete(const JSCallbackInfo& info) JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); ACE_SCORING_EVENT("Plugin.OnComplete"); PipelineContext::SetCallBackNode(node); - func->ExecuteJSWithContext(0, nullptr, execCtx); + func->Execute(); }; PluginModel::GetInstance()->SetOnComplete(std::move(OnComplete)); } @@ -153,7 +153,7 @@ void JSPlugin::JsOnError(const JSCallbackInfo& info) ACE_SCORING_EVENT("Plugin.OnComplete"); std::vector keys = { "errcode", "msg" }; PipelineContext::SetCallBackNode(node); - func->ExecuteWithContext(keys, param, execCtx); + func->Execute(keys, param); }; PluginModel::GetInstance()->SetOnError(std::move(onError)); } diff --git a/frameworks/bridge/declarative_frontend/jsview/js_richeditor.cpp b/frameworks/bridge/declarative_frontend/jsview/js_richeditor.cpp index 7dc0dfc9954..37a1292ce88 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_richeditor.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_richeditor.cpp @@ -24,7 +24,9 @@ #include "base/log/ace_scoring_log.h" #include "bridge/common/utils/utils.h" #include "bridge/declarative_frontend/engine/functions/js_click_function.h" -#include "bridge/declarative_frontend/engine/functions/js_function.h" +#include "bridge/declarative_frontend/engine/functions/js_common_event_function.h" +#include "bridge/declarative_frontend/engine/functions/js_cited_event_function.h" +#include "bridge/declarative_frontend/engine/functions/js_event_function.h" #include "bridge/declarative_frontend/engine/functions/js_hover_function.h" #include "bridge/declarative_frontend/engine/js_ref_ptr.h" #include "bridge/declarative_frontend/engine/js_types.h" diff --git a/frameworks/bridge/declarative_frontend/jsview/js_save_button.cpp b/frameworks/bridge/declarative_frontend/jsview/js_save_button.cpp index 30fb0392850..badb62de38e 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_save_button.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_save_button.cpp @@ -19,6 +19,7 @@ #endif #include "bridge/common/utils/utils.h" +#include "bridge/declarative_frontend/engine/functions/js_common_utils.h" #include "bridge/declarative_frontend/jsview/js_utils.h" #include "core/common/container.h" #include "core/components/common/properties/text_style.h" @@ -32,6 +33,7 @@ using OHOS::Ace::NG::SecurityComponentModelNG; using OHOS::Ace::NG::SecurityComponentTheme; namespace OHOS::Ace::Framework { +using namespace OHOS::Ace::Framework::CommonUtils; bool JSSaveButton::ParseComponentStyle(const JSCallbackInfo& info, SaveButtonSaveDescription& text, SaveButtonIconStyle& icon, int32_t& bg) diff --git a/frameworks/bridge/declarative_frontend/jsview/js_save_button.h b/frameworks/bridge/declarative_frontend/jsview/js_save_button.h index 1914f8be9ce..ca57bfefde0 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_save_button.h +++ b/frameworks/bridge/declarative_frontend/jsview/js_save_button.h @@ -33,7 +33,7 @@ public: JsFunction(JSRef(), jsFunction) {} ~JsSaveButtonClickFunction() override {}; - void Execute() override + void Execute() { JsFunction::ExecuteJS(); }; diff --git a/frameworks/bridge/declarative_frontend/jsview/js_search.cpp b/frameworks/bridge/declarative_frontend/jsview/js_search.cpp index a05ba79ac1b..8b3a7ae18d4 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_search.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_search.cpp @@ -21,7 +21,9 @@ #include "base/log/ace_scoring_log.h" #include "bridge/declarative_frontend/engine/functions/js_clipboard_function.h" -#include "bridge/declarative_frontend/engine/functions/js_function.h" +#include "bridge/declarative_frontend/engine/functions/js_common_event_function.h" +#include "bridge/declarative_frontend/engine/functions/js_cited_event_function.h" +#include "bridge/declarative_frontend/engine/functions/js_event_function.h" #include "bridge/declarative_frontend/engine/jsi/js_ui_index.h" #include "bridge/declarative_frontend/jsview/js_text_editable_controller.h" #include "bridge/declarative_frontend/jsview/js_textfield.h" diff --git a/frameworks/bridge/declarative_frontend/jsview/js_swiper.cpp b/frameworks/bridge/declarative_frontend/jsview/js_swiper.cpp index 7302bb6a890..411d03fda20 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_swiper.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_swiper.cpp @@ -27,6 +27,7 @@ #include "bridge/declarative_frontend/ark_theme/theme_apply/js_swiper_theme.h" #include "bridge/declarative_frontend/ark_theme/theme_apply/js_theme_utils.h" #include "bridge/declarative_frontend/engine/functions/js_click_function.h" +#include "bridge/declarative_frontend/engine/functions/js_event_function.h" #include "bridge/declarative_frontend/engine/functions/js_swiper_function.h" #include "bridge/declarative_frontend/engine/js_converter.h" #include "bridge/declarative_frontend/engine/jsi/js_ui_index.h" diff --git a/frameworks/bridge/declarative_frontend/jsview/js_tabs.cpp b/frameworks/bridge/declarative_frontend/jsview/js_tabs.cpp index b204a712b4d..d14dd6145f2 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_tabs.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_tabs.cpp @@ -17,6 +17,7 @@ #include "interfaces/inner_api/ui_session/ui_session_manager.h" #include "base/log/ace_scoring_log.h" +#include "bridge/declarative_frontend/engine/functions/js_event_function.h" #include "bridge/declarative_frontend/engine/functions/js_swiper_function.h" #include "bridge/declarative_frontend/engine/functions/js_tabs_function.h" #include "bridge/declarative_frontend/jsview/js_scrollable.h" diff --git a/frameworks/bridge/declarative_frontend/jsview/js_textfield.cpp b/frameworks/bridge/declarative_frontend/jsview/js_textfield.cpp index 76be26dc657..95a1243b7e7 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_textfield.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_textfield.cpp @@ -29,7 +29,9 @@ #include "bridge/common/utils/utils.h" #include "bridge/declarative_frontend/engine/functions/js_click_function.h" #include "bridge/declarative_frontend/engine/functions/js_clipboard_function.h" -#include "bridge/declarative_frontend/engine/functions/js_function.h" +#include "bridge/declarative_frontend/engine/functions/js_common_event_function.h" +#include "bridge/declarative_frontend/engine/functions/js_cited_event_function.h" +#include "bridge/declarative_frontend/engine/functions/js_event_function.h" #include "bridge/declarative_frontend/engine/jsi/js_ui_index.h" #include "bridge/declarative_frontend/jsview/js_container_base.h" #include "bridge/declarative_frontend/jsview/js_interactable_view.h" diff --git a/frameworks/bridge/declarative_frontend/jsview/js_ui_extension.cpp b/frameworks/bridge/declarative_frontend/jsview/js_ui_extension.cpp index de48b4d8095..ab014129ee0 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_ui_extension.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_ui_extension.cpp @@ -251,7 +251,7 @@ void JSUIExtensionProxy::On(const JSCallbackInfo& info) proxy->SetInstanceId(instanceId); proxy->SetProxy(session); auto param = JSRef::Cast(contextObj); - func->ExecuteJSWithContext(1, ¶m, execCtx); + func->ExecuteJS(1, ¶m); }; ContainerScope scope(instanceId_); @@ -473,7 +473,7 @@ void JSUIExtension::OnRemoteReady(const JSCallbackInfo& info) proxy->SetInstanceId(instanceId); proxy->SetProxy(session); auto returnValue = JSRef::Cast(contextObj); - func->ExecuteJSWithContext(1, &returnValue, execCtx); + func->ExecuteJS(1, &returnValue); }; UIExtensionModel::GetInstance()->SetOnRemoteReady(std::move(onRemoteReady)); } @@ -501,7 +501,7 @@ void JSUIExtension::OnReceive(const JSCallbackInfo& info) auto env = reinterpret_cast(nativeEngine); auto nativeWantParams = WantWrap::ConvertParamsToNativeValue(wantParams, env); auto wantParamsJSVal = JsConverter::ConvertNapiValueToJsVal(nativeWantParams); - func->ExecuteJSWithContext(1, &wantParamsJSVal, execCtx); + func->ExecuteJS(1, &wantParamsJSVal); }; UIExtensionModel::GetInstance()->SetOnReceive(std::move(onReceive)); } @@ -523,7 +523,7 @@ void JSUIExtension::OnRelease(const JSCallbackInfo& info) CHECK_NULL_VOID(pipelineContext); pipelineContext->UpdateCurrentActiveNode(node); auto newJSVal = JSRef::Make(ToJSValue(releaseCode)); - func->ExecuteJSWithContext(1, &newJSVal, execCtx); + func->ExecuteJS(1, &newJSVal); }; UIExtensionModel::GetInstance()->SetOnRelease(std::move(onRelease)); } @@ -554,7 +554,7 @@ void JSUIExtension::OnResult(const JSCallbackInfo& info) obj->SetProperty("code", code); obj->SetPropertyObject("want", wantJSVal); auto returnValue = JSRef::Cast(obj); - func->ExecuteJSWithContext(1, &returnValue, execCtx); + func->ExecuteJS(1, &returnValue); }; UIExtensionModel::GetInstance()->SetOnResult(std::move(onResult)); } @@ -580,7 +580,7 @@ void JSUIExtension::OnError(const JSCallbackInfo& info) obj->SetProperty("name", name); obj->SetProperty("message", message); auto returnValue = JSRef::Cast(obj); - func->ExecuteJSWithContext(1, &returnValue, execCtx); + func->ExecuteJS(1, &returnValue); }; UIExtensionModel::GetInstance()->SetOnError(std::move(onError)); } @@ -614,7 +614,7 @@ void JSUIExtension::OnTerminated(const JSCallbackInfo& info) obj->SetPropertyObject("want", wantJSVal); } auto returnValue = JSRef::Cast(obj); - func->ExecuteJSWithContext(1, &returnValue, execCtx); + func->ExecuteJS(1, &returnValue); }; UIExtensionModel::GetInstance()->SetOnTerminated(std::move(onTerminated)); } @@ -636,7 +636,7 @@ void JSUIExtension::OnDrawReady(const JSCallbackInfo& info) CHECK_NULL_VOID(pipelineContext); pipelineContext->UpdateCurrentActiveNode(node); auto newJSVal = JSRef::Make(); - func->ExecuteJSWithContext(1, &newJSVal, execCtx); + func->ExecuteJS(1, &newJSVal); }; UIExtensionModel::GetInstance()->SetOnDrawReady(std::move(onDrawReady)); } diff --git a/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp b/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp index e819fdd6edf..f9eecb7a0f3 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp @@ -42,6 +42,7 @@ #include "bridge/common/utils/engine_helper.h" #include "bridge/declarative_frontend/engine/functions/js_click_function.h" #include "bridge/declarative_frontend/engine/functions/js_clipboard_function.h" +#include "bridge/declarative_frontend/engine/functions/js_event_function.h" #include "bridge/declarative_frontend/engine/functions/js_on_child_touch_test_function.h" #include "bridge/declarative_frontend/engine/functions/js_focus_function.h" #include "bridge/declarative_frontend/engine/functions/js_gesture_judge_function.h" diff --git a/frameworks/bridge/declarative_frontend/jsview/js_view_context.cpp b/frameworks/bridge/declarative_frontend/jsview/js_view_context.cpp index 12e1a52f7ab..5b8347e0fbb 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_view_context.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_view_context.cpp @@ -27,7 +27,7 @@ #include "base/utils/utils.h" #include "bridge/common/utils/engine_helper.h" #include "bridge/common/utils/utils.h" -#include "bridge/declarative_frontend/engine/functions/js_function.h" +#include "bridge/declarative_frontend/engine/functions/js_animation_on_finish_function.h" #include "bridge/declarative_frontend/engine/js_converter.h" #include "bridge/declarative_frontend/jsview/js_view_abstract.h" #include "bridge/declarative_frontend/jsview/js_tabs_feature.h" @@ -351,14 +351,14 @@ AnimationOption ParseKeyframeOverallParam(const JSExecutionContext& executionCon JSRef onFinish = obj->GetProperty("onFinish"); AnimationOption option; if (onFinish->IsFunction()) { - count = GetAnimationFinshCount(); - RefPtr jsFunc = AceType::MakeRefPtr(JSRef(), JSRef::Cast(onFinish)); + count = GetAnimationFinishCount(); + auto jsFunc = AceType::MakeRefPtr(JSRef::Cast(onFinish)); std::function onFinishEvent = [execCtx = executionContext, func = std::move(jsFunc), id = Container::CurrentIdSafely()]() mutable { CHECK_NULL_VOID(func); ContainerScope scope(id); JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); - func->Execute(); + func->Execute(false); func = nullptr; }; option.SetOnFinishEvent(onFinishEvent); @@ -750,9 +750,9 @@ void JSViewContext::AnimateToInner(const JSCallbackInfo& info, bool immediately) RefPtr debugCurve = Curves::FAST_OUT_LINEAR_IN; auto isDebugAnim = option.GetDuration() == DEBUG_DURATION && debugCurve->IsEqual(option.GetCurve()); if (onFinish->IsFunction()) { - count = GetAnimationFinshCount(); + count = GetAnimationFinishCount(); auto frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); - RefPtr jsFunc = AceType::MakeRefPtr(JSRef(), JSRef::Cast(onFinish)); + auto jsFunc = AceType::MakeRefPtr(JSRef::Cast(onFinish)); onFinishEvent = [execCtx = info.GetExecutionContext(), func = std::move(jsFunc), id = Container::CurrentIdSafely(), traceStreamPtr, node = frameNode, count, iterations, isDebugAnim]() mutable { @@ -765,7 +765,7 @@ void JSViewContext::AnimateToInner(const JSCallbackInfo& info, bool immediately) CHECK_NULL_VOID(pipelineContext); pipelineContext->UpdateCurrentActiveNode(node); TAG_LOGI(AceLogTag::ACE_ANIMATION, "animateTo finish, cnt:%{public}d", count.value()); - func->ExecuteJS(0, nullptr, isDebugAnim); + func->Execute(isDebugAnim); if (isDebugAnim) { TAG_LOGI(AceLogTag::ACE_ANIMATION, "animateTo finish after ExecuteJS, cnt:%{public}d", count.value()); } diff --git a/frameworks/bridge/declarative_frontend/jsview/js_web.cpp b/frameworks/bridge/declarative_frontend/jsview/js_web.cpp index 2ebffa5cfd8..10dfa57a292 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_web.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_web.cpp @@ -32,7 +32,9 @@ #endif #include "bridge/common/utils/engine_helper.h" #include "bridge/declarative_frontend/engine/functions/js_click_function.h" +#include "bridge/declarative_frontend/engine/functions/js_common_utils.h" #include "bridge/declarative_frontend/engine/functions/js_drag_function.h" +#include "bridge/declarative_frontend/engine/functions/js_event_function.h" #include "bridge/declarative_frontend/engine/functions/js_key_function.h" #include "bridge/declarative_frontend/engine/js_converter.h" #include "bridge/declarative_frontend/engine/js_ref_ptr.h" @@ -98,6 +100,7 @@ WebModel* WebModel::GetInstance() } // namespace OHOS::Ace namespace OHOS::Ace::Framework { +using namespace OHOS::Ace::Framework::CommonUtils; bool JSWeb::webDebuggingAccess_ = false; int32_t JSWeb::webDebuggingPort_ = 0; class JSWebDialog : public Referenced { diff --git a/frameworks/bridge/declarative_frontend/jsview/js_xcomponent.cpp b/frameworks/bridge/declarative_frontend/jsview/js_xcomponent.cpp index 1674596baa0..f64f96a506d 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_xcomponent.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_xcomponent.cpp @@ -19,6 +19,7 @@ #include "base/memory/referenced.h" #include "base/utils/utils.h" #include "bridge/common/utils/engine_helper.h" +#include "bridge/declarative_frontend/engine/functions/js_xcomponent_onload_function.h" #include "bridge/declarative_frontend/engine/js_converter.h" #include "bridge/declarative_frontend/engine/js_ref_ptr.h" #include "bridge/declarative_frontend/jsview/js_view_common_def.h" @@ -338,7 +339,7 @@ void JSXComponent::JsOnLoad(const JSCallbackInfo& args) if (args.Length() < 1 || !args[0]->IsFunction()) { return; } - auto jsFunc = AceType::MakeRefPtr(JSRef(), JSRef::Cast(args[0])); + auto jsFunc = AceType::MakeRefPtr(JSRef::Cast(args[0])); WeakPtr targetNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto onLoad = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = targetNode]( const std::string& xcomponentId) { diff --git a/frameworks/core/animation/animation_pub.cpp b/frameworks/core/animation/animation_pub.cpp index 2f6e6842076..bb0bf44adde 100644 --- a/frameworks/core/animation/animation_pub.cpp +++ b/frameworks/core/animation/animation_pub.cpp @@ -35,7 +35,7 @@ const char* GetAnimationInterfaceName(AnimationInterface interfaceName) return g_animationInterfaceNames[static_cast(interfaceName)]; } -int32_t GetAnimationFinshCount() +int32_t GetAnimationFinishCount() { return g_animationCount++; } diff --git a/frameworks/core/animation/animation_pub.h b/frameworks/core/animation/animation_pub.h index 6f581a857c0..7dc65e4f3a2 100644 --- a/frameworks/core/animation/animation_pub.h +++ b/frameworks/core/animation/animation_pub.h @@ -24,7 +24,7 @@ const char* GetAnimationInterfaceName(AnimationInterface interfaceName); using ShareId = std::string; -int32_t GetAnimationFinshCount(); +int32_t GetAnimationFinishCount(); constexpr uint32_t ROTATION_PARAM_SIZE = 3; constexpr uint32_t TRANSLATION_PARAM_SIZE = 2; diff --git a/frameworks/core/components_ng/pattern/list/list_item_pattern.cpp b/frameworks/core/components_ng/pattern/list/list_item_pattern.cpp index 87d9c3d9dd0..0700338453f 100644 --- a/frameworks/core/components_ng/pattern/list/list_item_pattern.cpp +++ b/frameworks/core/components_ng/pattern/list/list_item_pattern.cpp @@ -674,7 +674,7 @@ void ListItemPattern::StartSpringMotion(float start, float end, float velocity, } listItem->MarkDirtyNode(); if (trigOnFinishEvent) { - listItem->FireOnFinshEvent(); + listItem->FireOnFinishEvent(); } }); } diff --git a/frameworks/core/components_ng/pattern/list/list_item_pattern.h b/frameworks/core/components_ng/pattern/list/list_item_pattern.h index 51a4c0de4ed..c5bd3328d8a 100644 --- a/frameworks/core/components_ng/pattern/list/list_item_pattern.h +++ b/frameworks/core/components_ng/pattern/list/list_item_pattern.h @@ -215,7 +215,7 @@ public: void CloseSwipeAction(OnFinishFunc&& onFinishCallback); - void FireOnFinshEvent() const + void FireOnFinishEvent() const { if (onFinishEvent_) { onFinishEvent_(); diff --git a/frameworks/core/interfaces/native/implementation/global_scope_animation_helper.cpp b/frameworks/core/interfaces/native/implementation/global_scope_animation_helper.cpp index 30cbd290d0d..8e1c925ae47 100644 --- a/frameworks/core/interfaces/native/implementation/global_scope_animation_helper.cpp +++ b/frameworks/core/interfaces/native/implementation/global_scope_animation_helper.cpp @@ -235,7 +235,7 @@ void AnimateToInner(const Ark_AnimateParam* value, auto traceStreamPtr = std::make_shared(); auto onFinish = Converter::OptConvert(value->onFinish); if (onFinish.has_value()) { - count = GetAnimationFinshCount(); + count = GetAnimationFinishCount(); onFinishEvent = [arkCallback = CallbackHelper(*onFinish), id = Container::CurrentIdSafely(), traceStreamPtr, count]() mutable { ContainerScope scope(id); diff --git a/frameworks/core/interfaces/native/node/node_animate.cpp b/frameworks/core/interfaces/native/node/node_animate.cpp index eed7e9155ed..d91b3034e13 100644 --- a/frameworks/core/interfaces/native/node/node_animate.cpp +++ b/frameworks/core/interfaces/native/node/node_animate.cpp @@ -237,7 +237,7 @@ void AnimateTo(ArkUIContext* context, ArkUIAnimateOption option, void (*event)(v std::optional count; std::function onFinishEvent; if (option.onFinishCallback) { - count = GetAnimationFinshCount(); + count = GetAnimationFinishCount(); onFinishEvent = [option, count]() { ACE_SCOPED_TRACE("nodeAnimate:onFinish[cnt:%d]", count.value()); TAG_LOGI(AceLogTag::ACE_ANIMATION, "nodeAnimate:animateTo finish, cnt:%{public}d", count.value()); @@ -299,7 +299,7 @@ void KeyframeAnimateTo(ArkUIContext* context, ArkUIKeyframeAnimateOption* animat AnimationOption option; std::optional count; if (animateOption->onFinish) { - count = GetAnimationFinshCount(); + count = GetAnimationFinishCount(); auto onFinishEvent = [onFinish = animateOption->onFinish, userData = animateOption->userData, id = context->id]() { ContainerScope scope(id); diff --git a/test/unittest/core/pattern/plugin/plugin_pattern_test_ng.cpp b/test/unittest/core/pattern/plugin/plugin_pattern_test_ng.cpp index d5ca258eaa0..a3f389497e1 100644 --- a/test/unittest/core/pattern/plugin/plugin_pattern_test_ng.cpp +++ b/test/unittest/core/pattern/plugin/plugin_pattern_test_ng.cpp @@ -630,4 +630,44 @@ HWTEST_F(PluginPatternTestNg, PluginLayoutTestNg, TestSize.Level1) layout->Clone(); layout.Reset(); } + +/** + * @tc.name: JSPluginOnCompleteTest + * @tc.desc: Test funcions in JSPlugin. + * @tc.type: FUNC + */ +HWTEST_F(PluginPatternTestNg, JSPluginOnCompleteTest, TestSize.Level1) +{ + RefPtr frameNode = CreatePluginParagraph(); + auto pattern = frameNode->GetPattern(); + ASSERT_NE(pattern, nullptr); + auto eventHub = AceType::DynamicCast(pattern->CreateEventHub()); + EXPECT_NE(eventHub, nullptr); + auto onComplete = [](const std::string& param) { EXPECT_EQ(param, "OnComplete"); }; + + pluginModel.SetOnComplete(onComplete); + eventHub->FireOnComplete("OnComplete"); + auto allowUpdate = pattern->ISAllowUpdate(); + EXPECT_TRUE(allowUpdate); +} + +/** + * @tc.name: JSPluginOnErrorTest + * @tc.desc: Test funcions in JSPlugin. + * @tc.type: FUNC + */ +HWTEST_F(PluginPatternTestNg, JSPluginOnErrorTest, TestSize.Level1) +{ + RefPtr frameNode = CreatePluginParagraph(); + auto pattern = frameNode->GetPattern(); + ASSERT_NE(pattern, nullptr); + auto eventHub = AceType::DynamicCast(pattern->CreateEventHub()); + EXPECT_NE(eventHub, nullptr); + auto onError = [](const std::string& param) { EXPECT_EQ(param, "OnError"); }; + + pluginModel.SetOnError(onError); + eventHub->FireOnError("OnError"); + auto allowUpdate = pattern->ISAllowUpdate(); + EXPECT_TRUE(allowUpdate); +} } // namespace OHOS::Ace::NG -- Gitee