From efd18b64d3d101d59075ef6d81e7808f6cc23e16 Mon Sep 17 00:00:00 2001 From: wenlong12 Date: Fri, 29 Apr 2022 12:10:12 +0800 Subject: [PATCH 01/35] update bytrace warehouse name Signed-off-by: wenlong12 Signed-off-by: wenlong12 --- adapter/ohos/build/bundle.json | 4 ++-- adapter/ohos/osal/BUILD.gn | 4 ++-- adapter/ohos/osal/ace_trace.cpp | 2 +- .../components/test/unittest/transition/BUILD.gn | 12 ++++++------ 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/adapter/ohos/build/bundle.json b/adapter/ohos/build/bundle.json index e4238c11a77..b8391a421a2 100644 --- a/adapter/ohos/build/bundle.json +++ b/adapter/ohos/build/bundle.json @@ -38,7 +38,7 @@ "unittest", "resmgr", "graphic", - "bytrace_standard", + "bytrace", "startup_l2" ], "third_party": [ @@ -86,4 +86,4 @@ ] } } -} \ No newline at end of file +} diff --git a/adapter/ohos/osal/BUILD.gn b/adapter/ohos/osal/BUILD.gn index 41c81beda3c..f61da0a431b 100644 --- a/adapter/ohos/osal/BUILD.gn +++ b/adapter/ohos/osal/BUILD.gn @@ -23,15 +23,15 @@ template("ace_osal_ohos_source_set") { defines += invoker.defines if (is_standard_system) { external_deps = [ - "bytrace_standard:bytrace_core", + "hitrace_native:hitrace_meter", "hiviewdfx_hilog_native:libhilog", "startup_l2:syspara", ] configs = [ "$ace_root:ace_config" ] } else { external_deps = [ - "bytrace:bytrace_core", "hilog:libhilog", + "hitrace_native:hitrace_meter", "startup:syspara", ] diff --git a/adapter/ohos/osal/ace_trace.cpp b/adapter/ohos/osal/ace_trace.cpp index 7dc3637c126..5d1be90d5c7 100644 --- a/adapter/ohos/osal/ace_trace.cpp +++ b/adapter/ohos/osal/ace_trace.cpp @@ -15,7 +15,7 @@ #include "base/log/ace_trace.h" -#include "bytrace.h" +#include "hitrace_meter.h" #include "base/log/log.h" #include "base/utils/macros.h" diff --git a/frameworks/core/components/test/unittest/transition/BUILD.gn b/frameworks/core/components/test/unittest/transition/BUILD.gn index 06c88f0c7ca..304c79391cb 100644 --- a/frameworks/core/components/test/unittest/transition/BUILD.gn +++ b/frameworks/core/components/test/unittest/transition/BUILD.gn @@ -237,8 +237,8 @@ ohos_unittest("TransitionElementTest") { if (is_standard_system) { external_deps = [ - "bytrace_standard:bytrace_core", "eventhandler:libeventhandler", + "hitrace_native:hitrace_meter", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "startup_l2:syspara", @@ -246,8 +246,8 @@ ohos_unittest("TransitionElementTest") { configs += [ "//base/startup/syspara_lite/interfaces/innerkits/native/syspara:syspara_config" ] } else { external_deps = [ - "bytrace:bytrace_core", "hilog:libhilog", + "hitrace_native:hitrace_meter", "startup:syspara", ] } @@ -302,8 +302,8 @@ ohos_unittest("SharedTransitionElementTest") { if (is_standard_system) { external_deps = [ - "bytrace_standard:bytrace_core", "eventhandler:libeventhandler", + "hitrace_native:hitrace_meter", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "startup_l2:syspara", @@ -311,8 +311,8 @@ ohos_unittest("SharedTransitionElementTest") { configs += [ "//base/startup/syspara_lite/interfaces/innerkits/native/syspara:syspara_config" ] } else { external_deps = [ - "bytrace:bytrace_core", "hilog:libhilog", + "hitrace_native:hitrace_meter", "startup:syspara", ] } @@ -362,8 +362,8 @@ ohos_unittest("TransitionPropertyElementTest") { if (is_standard_system) { external_deps = [ - "bytrace_standard:bytrace_core", "eventhandler:libeventhandler", + "hitrace_native:hitrace_meter", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "startup_l2:syspara", @@ -373,8 +373,8 @@ ohos_unittest("TransitionPropertyElementTest") { part_name = "ace_engine_standard" } else { external_deps = [ - "bytrace:bytrace_core", "hilog:libhilog", + "hitrace_native:hitrace_meter", "startup:syspara", ] } From 87ebc158dd66e3e77a9eef55cabe694f21b176c9 Mon Sep 17 00:00:00 2001 From: huangjie Date: Thu, 28 Apr 2022 18:00:05 +0800 Subject: [PATCH 02/35] =?UTF-8?q?=E8=B5=84=E6=BA=90resource=5Fmanagement?= =?UTF-8?q?=E9=83=A8=E4=BB=B6=E5=90=8D=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huangjie --- BUILD.gn | 8 ++++---- adapter/ohos/entrance/BUILD.gn | 2 +- .../entrance/pa_engine/engine/jsi/BUILD.gn | 2 +- .../pa_engine/engine/quickjs/BUILD.gn | 2 +- adapter/ohos/osal/BUILD.gn | 5 +++-- adapter/preview/entrance/BUILD.gn | 4 ++-- adapter/preview/entrance/samples/BUILD.gn | 12 ++++++------ adapter/preview/osal/BUILD.gn | 4 ++-- adapter/preview/sdk/BUILD.gn | 19 ++++++++----------- .../test/unittest/framework/BUILD.gn | 3 ++- .../test/unittest/svg_animate/BUILD.gn | 3 ++- .../test/unittest/image_animator/BUILD.gn | 3 ++- .../components/test/unittest/rating/BUILD.gn | 3 ++- .../test/unittest/semimodal/BUILD.gn | 3 ++- .../components/test/unittest/swiper/BUILD.gn | 3 ++- 15 files changed, 40 insertions(+), 36 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 9e50cb074a6..6fa18fee47e 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -26,8 +26,8 @@ config("ace_config") { if (is_standard_system && !use_mingw_win && !use_mac) { include_dirs += [ - "//base/global/resmgr_standard/frameworks/resmgr/include", - "//base/global/resmgr_standard/interfaces/innerkits/include", + "//base/global/resource_management/frameworks/resmgr/include", + "//base/global/resource_management/interfaces/innerkits/include", "$ace_root/adapter/ohos/services/uiservice/include", ] } @@ -76,8 +76,8 @@ config("ace_test_config") { if (is_standard_system && !use_mingw_win && !use_mac) { include_dirs += [ - "//base/global/resmgr_standard/frameworks/resmgr/include", - "//base/global/resmgr_standard/interfaces/innerkits/include", + "//base/global/resource_management/frameworks/resmgr/include", + "//base/global/resource_management/interfaces/innerkits/include", ] cflags_cc += [ diff --git a/adapter/ohos/entrance/BUILD.gn b/adapter/ohos/entrance/BUILD.gn index fd5eb136952..ea3e17e4cd9 100644 --- a/adapter/ohos/entrance/BUILD.gn +++ b/adapter/ohos/entrance/BUILD.gn @@ -85,7 +85,7 @@ template("ace_ohos_standard_source_set") { ] public_deps = - [ "//base/global/resmgr_standard/frameworks/resmgr:global_resmgr" ] + [ "//base/global/resource_management/frameworks/resmgr:global_resmgr" ] external_deps = [ "ability_base:base", diff --git a/adapter/ohos/entrance/pa_engine/engine/jsi/BUILD.gn b/adapter/ohos/entrance/pa_engine/engine/jsi/BUILD.gn index 8303dcdeff9..5ae003f6931 100644 --- a/adapter/ohos/entrance/pa_engine/engine/jsi/BUILD.gn +++ b/adapter/ohos/entrance/pa_engine/engine/jsi/BUILD.gn @@ -94,7 +94,7 @@ template("js_pa_engine_ark") { ] public_deps = - [ "//base/global/resmgr_standard/frameworks/resmgr:global_resmgr" ] + [ "//base/global/resource_management/frameworks/resmgr:global_resmgr" ] sources = [ "$ace_root/adapter/ohos/entrance/pa_engine/engine/common/js_backend_timer_module.cpp", diff --git a/adapter/ohos/entrance/pa_engine/engine/quickjs/BUILD.gn b/adapter/ohos/entrance/pa_engine/engine/quickjs/BUILD.gn index c577a2e8a17..a41c576b0cf 100644 --- a/adapter/ohos/entrance/pa_engine/engine/quickjs/BUILD.gn +++ b/adapter/ohos/entrance/pa_engine/engine/quickjs/BUILD.gn @@ -65,7 +65,7 @@ template("js_pa_engine_qjs") { ] public_deps = - [ "//base/global/resmgr_standard/frameworks/resmgr:global_resmgr" ] + [ "//base/global/resource_management/frameworks/resmgr:global_resmgr" ] sources = [ "$ace_root/adapter/ohos/entrance/pa_engine/engine/common/js_backend_timer_module.cpp", diff --git a/adapter/ohos/osal/BUILD.gn b/adapter/ohos/osal/BUILD.gn index 41c81beda3c..80cebe31233 100644 --- a/adapter/ohos/osal/BUILD.gn +++ b/adapter/ohos/osal/BUILD.gn @@ -59,8 +59,9 @@ template("ace_osal_ohos_source_set") { sources += [ "resource_adapter_impl.cpp" ] sources += [ "resource_convertor.cpp" ] deps = [ "$ace_flutter_engine_root/icu:ace_libicu_ohos" ] - public_deps += - [ "//base/global/resmgr_standard/frameworks/resmgr:global_resmgr" ] + public_deps += [ + "//base/global/resource_management/frameworks/resmgr:global_resmgr", + ] external_deps += [ "multimedia_image_standard:image" ] if (defined(config.accessibility_support) && config.accessibility_support) { diff --git a/adapter/preview/entrance/BUILD.gn b/adapter/preview/entrance/BUILD.gn index bc330a74247..44f71c25610 100644 --- a/adapter/preview/entrance/BUILD.gn +++ b/adapter/preview/entrance/BUILD.gn @@ -59,7 +59,7 @@ template("preview_entrance_source") { "//utils/native/base/include", "//third_party/glfw/include", ] - deps += [ "//base/global/resmgr_standard/frameworks/resmgr:global_resmgr_win(${current_toolchain})" ] + deps += [ "//base/global/resource_management/frameworks/resmgr:global_resmgr_win(${current_toolchain})" ] cflags_cc += [ "-DNONLS" ] } @@ -68,7 +68,7 @@ template("preview_entrance_source") { "//utils/native/base/include", "//third_party/glfw/include", ] - deps += [ "//base/global/resmgr_standard/frameworks/resmgr:global_resmgr_mac(${current_toolchain})" ] + deps += [ "//base/global/resource_management/frameworks/resmgr:global_resmgr_mac(${current_toolchain})" ] } } } diff --git a/adapter/preview/entrance/samples/BUILD.gn b/adapter/preview/entrance/samples/BUILD.gn index 9b105d12c02..6c3cb457e0e 100644 --- a/adapter/preview/entrance/samples/BUILD.gn +++ b/adapter/preview/entrance/samples/BUILD.gn @@ -195,9 +195,9 @@ ohos_copy("copy_resource_dynamic_library") { if (use_mac) { if (is_standard_system) { resource_manager_library = get_label_info( - "//base/global/resmgr_standard/frameworks/resmgr:global_resmgr_mac", - "root_out_dir") + "/global/resmgr_standard/libglobal_resmgr_mac.dylib" - deps = [ "//base/global/resmgr_standard/frameworks/resmgr:global_resmgr_mac(${current_toolchain})" ] + "//base/global/resource_management/frameworks/resmgr:global_resmgr_mac", + "root_out_dir") + "/global/resource_management/libglobal_resmgr_mac.dylib" + deps = [ "//base/global/resource_management/frameworks/resmgr:global_resmgr_mac(${current_toolchain})" ] sources = [ resource_manager_library ] } else { sources = [ @@ -210,9 +210,9 @@ ohos_copy("copy_resource_dynamic_library") { } else { if (is_standard_system) { resource_manager_library = get_label_info( - "//base/global/resmgr_standard/frameworks/resmgr:global_resmgr_win", - "root_out_dir") + "/global/resmgr_standard/libglobal_resmgr_win.dll" - deps = [ "//base/global/resmgr_standard/frameworks/resmgr:global_resmgr_win(${current_toolchain})" ] + "//base/global/resource_management/frameworks/resmgr:global_resmgr_win", + "root_out_dir") + "/global/resource_management/libglobal_resmgr_win.dll" + deps = [ "//base/global/resource_management/frameworks/resmgr:global_resmgr_win(${current_toolchain})" ] sources = [ resource_manager_library ] } else { sources = [ diff --git a/adapter/preview/osal/BUILD.gn b/adapter/preview/osal/BUILD.gn index b31452a8b1b..974690c6723 100644 --- a/adapter/preview/osal/BUILD.gn +++ b/adapter/preview/osal/BUILD.gn @@ -72,9 +72,9 @@ template("ace_osal_preview_source_set") { include_dirs = [ "//utils/native/base/include" ] defines += [ "OHOS_STANDARD_SYSTEM" ] if (platform == "windows") { - deps += [ "//base/global/resmgr_standard/frameworks/resmgr:global_resmgr_win(${current_toolchain})" ] + deps += [ "//base/global/resource_management/frameworks/resmgr:global_resmgr_win(${current_toolchain})" ] } else if (platform == "mac") { - deps += [ "//base/global/resmgr_standard/frameworks/resmgr:global_resmgr_mac(${current_toolchain})" ] + deps += [ "//base/global/resource_management/frameworks/resmgr:global_resmgr_mac(${current_toolchain})" ] } } else { sources += [ "resource_adapter_impl.cpp" ] diff --git a/adapter/preview/sdk/BUILD.gn b/adapter/preview/sdk/BUILD.gn index ef0896c7a1b..383c6cb9e56 100644 --- a/adapter/preview/sdk/BUILD.gn +++ b/adapter/preview/sdk/BUILD.gn @@ -25,16 +25,13 @@ if (is_standard_system) { get_label_info("//utils/resources/systemres:systemres_hap", "target_out_dir") + "/resources" if (host_os == "mac") { - resource_manager_library = - get_label_info( - "//base/global/resmgr_standard/frameworks/resmgr:global_resmgr_mac", - "root_out_dir") + - "/global/resmgr_standard/libglobal_resmgr_mac.dylib" + resource_manager_library = get_label_info( + "//base/global/resource_management/frameworks/resmgr:global_resmgr_mac", + "root_out_dir") + "/global/resource_management/libglobal_resmgr_mac.dylib" } else { - resource_manager_library = - get_label_info( - "//base/global/resmgr_standard/frameworks/resmgr:global_resmgr_win", - "root_out_dir") + "/global/resmgr_standard/libglobal_resmgr_win.dll" + resource_manager_library = get_label_info( + "//base/global/resource_management/frameworks/resmgr:global_resmgr_win", + "root_out_dir") + "/global/resource_management/libglobal_resmgr_win.dll" } } else { system_resource_hap_path = @@ -178,9 +175,9 @@ if (is_standard_system) { ohos_copy("copy_resource_dynamic_library_standard") { if (host_os == "mac") { - deps = [ "//base/global/resmgr_standard/frameworks/resmgr:global_resmgr_mac(${current_toolchain})" ] + deps = [ "//base/global/resource_management/frameworks/resmgr:global_resmgr_mac(${current_toolchain})" ] } else { - deps = [ "//base/global/resmgr_standard/frameworks/resmgr:global_resmgr_win(${current_toolchain})" ] + deps = [ "//base/global/resource_management/frameworks/resmgr:global_resmgr_win(${current_toolchain})" ] } sources = [ resource_manager_library ] diff --git a/frameworks/core/animation/test/unittest/framework/BUILD.gn b/frameworks/core/animation/test/unittest/framework/BUILD.gn index e3f8a9d62ba..17099481103 100644 --- a/frameworks/core/animation/test/unittest/framework/BUILD.gn +++ b/frameworks/core/animation/test/unittest/framework/BUILD.gn @@ -221,7 +221,8 @@ ohos_unittest("AnimationTest") { ] } else { external_deps = [ "hiviewdfx_hilog_native:libhilog" ] - deps += [ "//base/global/resmgr_standard/frameworks/resmgr:global_resmgr" ] + deps += + [ "//base/global/resource_management/frameworks/resmgr:global_resmgr" ] } if (!is_standard_system) { diff --git a/frameworks/core/animation/test/unittest/svg_animate/BUILD.gn b/frameworks/core/animation/test/unittest/svg_animate/BUILD.gn index 026830c3d12..ad89b4aea22 100644 --- a/frameworks/core/animation/test/unittest/svg_animate/BUILD.gn +++ b/frameworks/core/animation/test/unittest/svg_animate/BUILD.gn @@ -225,7 +225,8 @@ ohos_unittest("SvgAnimateTest") { ] } else { external_deps = [ "hiviewdfx_hilog_native:libhilog" ] - deps += [ "//base/global/resmgr_standard/frameworks/resmgr:global_resmgr" ] + deps += + [ "//base/global/resource_management/frameworks/resmgr:global_resmgr" ] } if (!is_standard_system) { diff --git a/frameworks/core/components/test/unittest/image_animator/BUILD.gn b/frameworks/core/components/test/unittest/image_animator/BUILD.gn index 04025946ee2..53f876ec8a0 100644 --- a/frameworks/core/components/test/unittest/image_animator/BUILD.gn +++ b/frameworks/core/components/test/unittest/image_animator/BUILD.gn @@ -234,7 +234,8 @@ ohos_unittest("ImageAnimatorElementTest") { ] } else { external_deps = [ "hiviewdfx_hilog_native:libhilog" ] - deps += [ "//base/global/resmgr_standard/frameworks/resmgr:global_resmgr" ] + deps += + [ "//base/global/resource_management/frameworks/resmgr:global_resmgr" ] } if (!is_standard_system) { diff --git a/frameworks/core/components/test/unittest/rating/BUILD.gn b/frameworks/core/components/test/unittest/rating/BUILD.gn index 53e50ec61b9..dcf5510c8fb 100644 --- a/frameworks/core/components/test/unittest/rating/BUILD.gn +++ b/frameworks/core/components/test/unittest/rating/BUILD.gn @@ -244,7 +244,8 @@ ohos_unittest("RatingComponentTest") { deps += [ "$ace_root/frameworks/base:ace_base_ohos" ] } else { external_deps = [ "hiviewdfx_hilog_native:libhilog" ] - deps += [ "//base/global/resmgr_standard/frameworks/resmgr:global_resmgr" ] + deps += + [ "//base/global/resource_management/frameworks/resmgr:global_resmgr" ] } if (!is_standard_system) { diff --git a/frameworks/core/components/test/unittest/semimodal/BUILD.gn b/frameworks/core/components/test/unittest/semimodal/BUILD.gn index 71036dedc51..320792c4729 100644 --- a/frameworks/core/components/test/unittest/semimodal/BUILD.gn +++ b/frameworks/core/components/test/unittest/semimodal/BUILD.gn @@ -239,7 +239,8 @@ ohos_unittest("RenderSemiModalTest") { ] } else { external_deps = [ "hiviewdfx_hilog_native:libhilog" ] - deps += [ "//base/global/resmgr_standard/frameworks/resmgr:global_resmgr" ] + deps += + [ "//base/global/resource_management/frameworks/resmgr:global_resmgr" ] } if (!is_standard_system) { diff --git a/frameworks/core/components/test/unittest/swiper/BUILD.gn b/frameworks/core/components/test/unittest/swiper/BUILD.gn index e29c6913def..94c4fb03e41 100644 --- a/frameworks/core/components/test/unittest/swiper/BUILD.gn +++ b/frameworks/core/components/test/unittest/swiper/BUILD.gn @@ -254,7 +254,8 @@ ohos_unittest("SwiperComponentTest") { ] } else { external_deps = [ "hiviewdfx_hilog_native:libhilog" ] - deps += [ "//base/global/resmgr_standard/frameworks/resmgr:global_resmgr" ] + deps += + [ "//base/global/resource_management/frameworks/resmgr:global_resmgr" ] } if (!is_standard_system) { From 578eadc6c074829519f6da83be65073be4ab3e74 Mon Sep 17 00:00:00 2001 From: Yao yuchi Date: Thu, 5 May 2022 13:54:54 +0800 Subject: [PATCH 03/35] waterflow committed by fix bugs of unit test Signed-off-by: Yao yuchi --- .../bridge/declarative_frontend/BUILD.gn | 2 + .../engine/jsi/jsi_view_register.cpp | 6 +- .../engine/quickjs/qjs_view_register.cpp | 5 + .../engine/v8/v8_view_register.cpp | 6 +- .../jsview/js_water_flow.cpp | 150 ++ .../jsview/js_water_flow.h | 33 + .../jsview/js_water_flow_item.cpp | 60 + .../jsview/js_water_flow_item.h | 32 + .../view_stack_processor.cpp | 7 +- frameworks/core/BUILD.gn | 1 + .../scroll_bar/scroll_bar_proxy.cpp | 22 +- .../core/components/test/unittest/BUILD.gn | 3 +- .../test/unittest/water_flow/BUILD.gn | 45 + .../water_flow/render_water_flow_test.cpp | 846 ++++++++ .../water_flow/water_flow_test_utils.cpp | 91 + .../water_flow/water_flow_test_utils.h | 38 + .../core/components_v2/water_flow/BUILD.gn | 31 + .../water_flow/flutter_render_water_flow.cpp | 71 + .../water_flow/flutter_render_water_flow.h | 37 + .../water_flow/render_water_flow.cpp | 1804 +++++++++++++++++ .../water_flow/render_water_flow.h | 327 +++ .../water_flow/render_water_flow_creator.cpp | 32 + .../water_flow/render_water_flow_item.cpp | 84 + .../water_flow/render_water_flow_item.h | 122 ++ .../water_flow/rosen_render_water_flow.cpp | 77 + .../water_flow/rosen_render_water_flow.h | 35 + .../water_flow/water_flow_component.cpp | 114 ++ .../water_flow/water_flow_component.h | 136 ++ .../water_flow/water_flow_element.cpp | 214 ++ .../water_flow/water_flow_element.h | 49 + .../water_flow/water_flow_item_component.cpp | 49 + .../water_flow/water_flow_item_component.h | 100 + .../water_flow/water_flow_item_element.cpp | 39 + .../water_flow/water_flow_item_element.h | 38 + .../water_flow_position_controller.cpp | 66 + .../water_flow_position_controller.h | 38 + .../water_flow_scroll_controller.cpp | 71 + .../water_flow/water_flow_scroll_controller.h | 38 + 38 files changed, 4912 insertions(+), 7 deletions(-) create mode 100644 frameworks/bridge/declarative_frontend/jsview/js_water_flow.cpp create mode 100644 frameworks/bridge/declarative_frontend/jsview/js_water_flow.h create mode 100644 frameworks/bridge/declarative_frontend/jsview/js_water_flow_item.cpp create mode 100644 frameworks/bridge/declarative_frontend/jsview/js_water_flow_item.h create mode 100644 frameworks/core/components/test/unittest/water_flow/BUILD.gn create mode 100644 frameworks/core/components/test/unittest/water_flow/render_water_flow_test.cpp create mode 100644 frameworks/core/components/test/unittest/water_flow/water_flow_test_utils.cpp create mode 100644 frameworks/core/components/test/unittest/water_flow/water_flow_test_utils.h create mode 100644 frameworks/core/components_v2/water_flow/BUILD.gn create mode 100644 frameworks/core/components_v2/water_flow/flutter_render_water_flow.cpp create mode 100644 frameworks/core/components_v2/water_flow/flutter_render_water_flow.h create mode 100644 frameworks/core/components_v2/water_flow/render_water_flow.cpp create mode 100644 frameworks/core/components_v2/water_flow/render_water_flow.h create mode 100644 frameworks/core/components_v2/water_flow/render_water_flow_creator.cpp create mode 100644 frameworks/core/components_v2/water_flow/render_water_flow_item.cpp create mode 100644 frameworks/core/components_v2/water_flow/render_water_flow_item.h create mode 100644 frameworks/core/components_v2/water_flow/rosen_render_water_flow.cpp create mode 100644 frameworks/core/components_v2/water_flow/rosen_render_water_flow.h create mode 100644 frameworks/core/components_v2/water_flow/water_flow_component.cpp create mode 100644 frameworks/core/components_v2/water_flow/water_flow_component.h create mode 100644 frameworks/core/components_v2/water_flow/water_flow_element.cpp create mode 100644 frameworks/core/components_v2/water_flow/water_flow_element.h create mode 100644 frameworks/core/components_v2/water_flow/water_flow_item_component.cpp create mode 100644 frameworks/core/components_v2/water_flow/water_flow_item_component.h create mode 100644 frameworks/core/components_v2/water_flow/water_flow_item_element.cpp create mode 100644 frameworks/core/components_v2/water_flow/water_flow_item_element.h create mode 100644 frameworks/core/components_v2/water_flow/water_flow_position_controller.cpp create mode 100644 frameworks/core/components_v2/water_flow/water_flow_position_controller.h create mode 100644 frameworks/core/components_v2/water_flow/water_flow_scroll_controller.cpp create mode 100644 frameworks/core/components_v2/water_flow/water_flow_scroll_controller.h diff --git a/frameworks/bridge/declarative_frontend/BUILD.gn b/frameworks/bridge/declarative_frontend/BUILD.gn index c503837127a..10d92720767 100644 --- a/frameworks/bridge/declarative_frontend/BUILD.gn +++ b/frameworks/bridge/declarative_frontend/BUILD.gn @@ -224,6 +224,8 @@ template("declarative_js_engine") { "jsview/js_view_context.cpp", "jsview/js_view_functions.cpp", "jsview/js_view_stack_processor.cpp", + "jsview/js_water_flow.cpp", + "jsview/js_water_flow_item.cpp", "jsview/menu/js_context_menu.cpp", "jsview/scroll_bar/js_scroll_bar.cpp", "sharedata/js_share_data.cpp", diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/jsi_view_register.cpp b/frameworks/bridge/declarative_frontend/engine/jsi/jsi_view_register.cpp index fa3bb5a19e4..9a02c59a861 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/jsi_view_register.cpp +++ b/frameworks/bridge/declarative_frontend/engine/jsi/jsi_view_register.cpp @@ -140,6 +140,8 @@ #include "frameworks/bridge/declarative_frontend/jsview/js_view.h" #include "frameworks/bridge/declarative_frontend/jsview/js_view_context.h" #include "frameworks/bridge/declarative_frontend/jsview/js_view_stack_processor.h" +#include "frameworks/bridge/declarative_frontend/jsview/js_water_flow.h" +#include "frameworks/bridge/declarative_frontend/jsview/js_water_flow_item.h" #if !defined(WINDOWS_PLATFORM) and !defined(MAC_PLATFORM) #include "frameworks/bridge/declarative_frontend/jsview/js_xcomponent.h" #include "frameworks/bridge/declarative_frontend/jsview/js_xcomponent_controller.h" @@ -926,7 +928,9 @@ static const std::unordered_map> { "TextTimerController", JSTextTimerController::JSBind }, { "Checkbox", JSCheckbox::JSBind }, { "CheckboxGroup", JSCheckboxGroup::JSBind }, - { "Refresh", JSRefresh::JSBind } + { "Refresh", JSRefresh::JSBind }, + { "WaterFlow", JSWaterFlow::JSBind }, + { "FlowItem", JSWaterFlowItem::JSBind } }; void RegisterAllModule(BindingTarget globalObj) diff --git a/frameworks/bridge/declarative_frontend/engine/quickjs/qjs_view_register.cpp b/frameworks/bridge/declarative_frontend/engine/quickjs/qjs_view_register.cpp index 314ecec7bac..01d7abdcada 100644 --- a/frameworks/bridge/declarative_frontend/engine/quickjs/qjs_view_register.cpp +++ b/frameworks/bridge/declarative_frontend/engine/quickjs/qjs_view_register.cpp @@ -140,6 +140,8 @@ #include "frameworks/bridge/declarative_frontend/jsview/js_view_register.h" #include "frameworks/bridge/declarative_frontend/jsview/js_view_stack_processor.h" #include "frameworks/bridge/declarative_frontend/jsview/js_local_storage.h" +#include "frameworks/bridge/declarative_frontend/jsview/js_water_flow.h" +#include "frameworks/bridge/declarative_frontend/jsview/js_water_flow_item.h" #ifdef XCOMPONENT_SUPPORTED #include "frameworks/bridge/declarative_frontend/jsview/js_xcomponent.h" #include "frameworks/bridge/declarative_frontend/jsview/js_xcomponent_controller.h" @@ -952,6 +954,9 @@ void JsRegisterViews(BindingTarget globalObj) JSTextPickerDialog::JSBind(globalObj); JSCheckbox::JSBind(globalObj); JSCheckboxGroup::JSBind(globalObj); + JSWaterFlow::JSBind(globalObj); + JSWaterFlowItem::JSBind(globalObj); + JSObjectTemplate toggleType; toggleType.Constant("Checkbox", 0); diff --git a/frameworks/bridge/declarative_frontend/engine/v8/v8_view_register.cpp b/frameworks/bridge/declarative_frontend/engine/v8/v8_view_register.cpp index 98f120cda32..c04c39cd178 100644 --- a/frameworks/bridge/declarative_frontend/engine/v8/v8_view_register.cpp +++ b/frameworks/bridge/declarative_frontend/engine/v8/v8_view_register.cpp @@ -136,6 +136,8 @@ #include "frameworks/bridge/declarative_frontend/jsview/js_view.h" #include "frameworks/bridge/declarative_frontend/jsview/js_view_context.h" #include "frameworks/bridge/declarative_frontend/jsview/js_view_stack_processor.h" +#include "frameworks/bridge/declarative_frontend/jsview/js_water_flow.h" +#include "frameworks/bridge/declarative_frontend/jsview/js_water_flow_item.h" #if !defined(WINDOWS_PLATFORM) and !defined(MAC_PLATFORM) #include "frameworks/bridge/declarative_frontend/jsview/js_xcomponent.h" #include "frameworks/bridge/declarative_frontend/jsview/js_xcomponent_controller.h" @@ -696,7 +698,9 @@ static const std::unordered_map> {"TextTimerController", JSTextTimerController::JSBind}, {"TextClockController", JSTextClockController::JSBind}, {"Checkbox", JSCheckbox::JSBind}, - {"CheckboxGroup", JSCheckboxGroup::JSBind} + {"CheckboxGroup", JSCheckboxGroup::JSBind}, + {"WaterFlow", JSWaterFLow::JSBind}, + {"FlowItem", JSFLowItem::JSBind} }; void RegisterAllModule(BindingTarget globalObj) diff --git a/frameworks/bridge/declarative_frontend/jsview/js_water_flow.cpp b/frameworks/bridge/declarative_frontend/jsview/js_water_flow.cpp new file mode 100644 index 00000000000..69bee2c4123 --- /dev/null +++ b/frameworks/bridge/declarative_frontend/jsview/js_water_flow.cpp @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2022 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/jsview/js_water_flow.h" + +#include "bridge/declarative_frontend/jsview/js_view_common_def.h" +#include "frameworks/bridge/declarative_frontend/jsview/js_interactable_view.h" +#include "frameworks/bridge/declarative_frontend/jsview/js_scroller.h" +#include "frameworks/bridge/declarative_frontend/view_stack_processor.h" +#include "frameworks/core/components_v2/water_flow/water_flow_component.h" + +namespace OHOS::Ace::Framework { +namespace { +const std::vector LAYOUT_DIRECTION = { FlexDirection::ROW, FlexDirection::COLUMN, + FlexDirection::ROW_REVERSE, FlexDirection::COLUMN_REVERSE }; +} // namespace + +void JSWaterFlow::Create(const JSCallbackInfo& args) +{ + LOGI("Create component: WaterFLow"); + if (args.Length() < 1) { + LOGE("Arg is wrong, it is supposed to have at least 1 arguments"); + return; + } + + if (!args[0]->IsObject()) { + LOGE("Arg is not object"); + return; + } + + JSRef obj = JSRef::Cast(args[0]); + JSRef crossSplice = obj->GetProperty("crossSplice"); + if (!crossSplice->IsNumber()) { + LOGW("Args is invalid"); + return; + } + + // create waterflow component + std::list> componentChildren; + auto waterflowComponent = + AceType::MakeRefPtr(componentChildren, crossSplice->ToNumber()); + + // mainLength + JSRef jsMainLength = obj->GetProperty("mainLength"); + Dimension mainLength; + if (ParseJsDimensionVp(jsMainLength, mainLength)) { + waterflowComponent->SetMainLength(mainLength); + } else { + LOGW("The parameter of mainLength not exists."); + } + + // scroller + if (args.Length() > 1 && args[1]->IsObject()) { + JSScroller* jsScroller = JSRef::Cast(args[1])->Unwrap(); + if (jsScroller) { + auto positionController = AceType::MakeRefPtr(); + jsScroller->SetController(positionController); + waterflowComponent->SetController(positionController); + + // Init scroll bar proxy. + auto proxy = jsScroller->GetScrollBarProxy(); + if (!proxy) { + proxy = AceType::MakeRefPtr(); + jsScroller->SetScrollBarProxy(proxy); + } + waterflowComponent->SetScrollBarProxy(proxy); + } + } else { + LOGW("The parameter of scroller not exists."); + } + + ViewStackProcessor::GetInstance()->Push(waterflowComponent); +} + +void JSWaterFlow::JSBind(BindingTarget globalObj) +{ + LOGD("JSWaterFlow:JSBind"); + JSClass::Declare("WaterFlow"); + + MethodOptions opt = MethodOptions::NONE; + JSClass::StaticMethod("create", &JSWaterFlow::Create, opt); + JSClass::StaticMethod("columnsGap", &JSWaterFlow::SetColumnsGap, opt); + JSClass::StaticMethod("rowsGap", &JSWaterFlow::SetRowsGap, opt); + JSClass::StaticMethod("layoutDirection", &JSWaterFlow::SetLayoutDirection, opt); + JSClass::StaticMethod("onAppear", &JSInteractableView::JsOnAppear); + JSClass::StaticMethod("onDisAppear", &JSInteractableView::JsOnDisAppear); + + JSClass::Inherit(); + JSClass::Inherit(); + JSClass::Bind<>(globalObj); +} + +void JSWaterFlow::SetColumnsGap(const JSCallbackInfo& info) +{ + if (info.Length() < 1) { + LOGE("Arg is wrong, it is supposed to have at least 1 argument"); + return; + } + Dimension colGap; + if (!ParseJsDimensionVp(info[0], colGap)) { + return; + } + auto component = ViewStackProcessor::GetInstance()->GetMainComponent(); + auto waterflow = AceType::DynamicCast(component); + if (waterflow) { + waterflow->SetColumnsGap(colGap); + } +} + +void JSWaterFlow::SetRowsGap(const JSCallbackInfo& info) +{ + if (info.Length() < 1) { + LOGE("Arg is wrong, it is supposed to have at least 1 argument"); + return; + } + Dimension rowGap; + if (!ParseJsDimensionVp(info[0], rowGap)) { + return; + } + auto component = ViewStackProcessor::GetInstance()->GetMainComponent(); + auto waterflow = AceType::DynamicCast(component); + if (waterflow) { + waterflow->SetRowsGap(rowGap); + } +} + +void JSWaterFlow::SetLayoutDirection(int32_t value) +{ + if (value >= 0 && value < static_cast(LAYOUT_DIRECTION.size())) { + auto component = ViewStackProcessor::GetInstance()->GetMainComponent(); + auto waterflow = AceType::DynamicCast(component); + if (waterflow) { + // not support the other layoutDirection except default for now. + waterflow->SetLayoutDirection(FlexDirection::COLUMN); + } + } +} +} // namespace OHOS::Ace::Framework diff --git a/frameworks/bridge/declarative_frontend/jsview/js_water_flow.h b/frameworks/bridge/declarative_frontend/jsview/js_water_flow.h new file mode 100644 index 00000000000..6889efed4ec --- /dev/null +++ b/frameworks/bridge/declarative_frontend/jsview/js_water_flow.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2022 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_JS_VIEW_JS_WATER_FLOW_H +#define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_WATER_FLOW_H + +#include "frameworks/bridge/declarative_frontend/jsview/js_container_base.h" + +namespace OHOS::Ace::Framework { +class JSWaterFlow : public JSContainerBase { +public: + static void Create(const JSCallbackInfo& args); + static void JSBind(BindingTarget globalObj); + +protected: + static void SetColumnsGap(const JSCallbackInfo& info); + static void SetRowsGap(const JSCallbackInfo& info); + static void SetLayoutDirection(int32_t value); +}; +} // namespace OHOS::Ace::Framework +#endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_WATER_FLOW_H diff --git a/frameworks/bridge/declarative_frontend/jsview/js_water_flow_item.cpp b/frameworks/bridge/declarative_frontend/jsview/js_water_flow_item.cpp new file mode 100644 index 00000000000..3f40d9c927f --- /dev/null +++ b/frameworks/bridge/declarative_frontend/jsview/js_water_flow_item.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2022 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/jsview/js_water_flow_item.h" + +#include "frameworks/bridge/declarative_frontend/view_stack_processor.h" +#include "frameworks/core/components_v2/water_flow/water_flow_item_component.h" + +namespace OHOS::Ace::Framework { +void JSWaterFlowItem::Create() +{ + auto itemComponent = AceType::MakeRefPtr(); + ViewStackProcessor::GetInstance()->Push(itemComponent); +} + +void JSWaterFlowItem::JSBind(BindingTarget globalObj) +{ + LOGD("JSWaterFlowItem:JSBind"); + JSClass::Declare("FlowItem"); + + MethodOptions opt = MethodOptions::NONE; + JSClass::StaticMethod("create", &JSWaterFlowItem::Create, opt); + JSClass::StaticMethod("rowSpan", &JSWaterFlowItem::SetRowSpan, opt); + JSClass::StaticMethod("columnSpan", &JSWaterFlowItem::SetColumnSpan, opt); + + JSClass::Inherit(); + JSClass::Inherit(); + JSClass::Bind<>(globalObj); +} + +void JSWaterFlowItem::SetRowSpan(int32_t rowSpan) +{ + auto flowItem = + AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetMainComponent()); + if (flowItem) { + flowItem->SetRowSpan(rowSpan); + } +} + +void JSWaterFlowItem::SetColumnSpan(int32_t columnSpan) +{ + auto flowItem = + AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetMainComponent()); + if (flowItem) { + flowItem->SetColumnSpan(columnSpan); + } +} +} // namespace OHOS::Ace::Framework diff --git a/frameworks/bridge/declarative_frontend/jsview/js_water_flow_item.h b/frameworks/bridge/declarative_frontend/jsview/js_water_flow_item.h new file mode 100644 index 00000000000..cfce3720127 --- /dev/null +++ b/frameworks/bridge/declarative_frontend/jsview/js_water_flow_item.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2022 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_JS_VIEW_JS_WATER_FLOW_ITEM_H +#define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_WATER_FLOW_ITEM_H + +#include "frameworks/bridge/declarative_frontend/jsview/js_container_base.h" + +namespace OHOS::Ace::Framework { +class JSWaterFlowItem : public JSContainerBase { +public: + static void JSBind(BindingTarget globalObj); + static void Create(); + +protected: + static void SetRowSpan(int32_t rowSpan); + static void SetColumnSpan(int32_t columnSpan); +}; +} // namespace OHOS::Ace::Framework +#endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_WATER_FLOW_ITEM_H diff --git a/frameworks/bridge/declarative_frontend/view_stack_processor.cpp b/frameworks/bridge/declarative_frontend/view_stack_processor.cpp index 262af9d75c4..a3c3cd814a3 100644 --- a/frameworks/bridge/declarative_frontend/view_stack_processor.cpp +++ b/frameworks/bridge/declarative_frontend/view_stack_processor.cpp @@ -35,6 +35,7 @@ #include "core/components/web/web_component.h" #include "core/components/xcomponent/xcomponent_component.h" #include "core/components_v2/list/list_item_component.h" +#include "core/components_v2/water_flow/water_flow_item_component.h" #include "core/pipeline/base/component.h" #include "core/pipeline/base/multi_composed_component.h" #include "core/pipeline/base/sole_child_component.h" @@ -558,7 +559,8 @@ RefPtr ViewStackProcessor::WrapComponents() std::unordered_map> videoMap; bool isItemComponent = AceType::InstanceOf(mainComponent) || - AceType::InstanceOf(mainComponent); + AceType::InstanceOf(mainComponent) || + AceType::InstanceOf(mainComponent); RefPtr itemChildComponent; @@ -816,8 +818,7 @@ RefPtr ViewStackProcessor::GetScoringComponent() const void ViewStackProcessor::CreateInspectorComposedComponent(const std::string& inspectorTag) { if (V2::InspectorComposedComponent::HasInspectorFinished(inspectorTag)) { - auto composedComponent = - AceType::MakeRefPtr(GenerateId(), inspectorTag); + auto composedComponent = AceType::MakeRefPtr(GenerateId(), inspectorTag); auto& wrappingComponentsMap = componentsStack_.top(); wrappingComponentsMap.emplace("inspector", composedComponent); } diff --git a/frameworks/core/BUILD.gn b/frameworks/core/BUILD.gn index 2c6f865ef6c..f50fb61a8ed 100644 --- a/frameworks/core/BUILD.gn +++ b/frameworks/core/BUILD.gn @@ -327,6 +327,7 @@ template("ace_core_source_set") { "$ace_root/frameworks/core/components_v2/pattern_lock:ace_core_components_pattern_lock_$platform", "$ace_root/frameworks/core/components_v2/swiper:ace_core_components_swiper_v2_$platform", "$ace_root/frameworks/core/components_v2/tabs:ace_core_components_tabs_v2_$platform", + "$ace_root/frameworks/core/components_v2/water_flow:ace_core_components_water_flow_v2_$platform", ] if (defined(config.enable_rosen_backend) && config.enable_rosen_backend) { diff --git a/frameworks/core/components/scroll_bar/scroll_bar_proxy.cpp b/frameworks/core/components/scroll_bar/scroll_bar_proxy.cpp index f4a4b6c0a24..eec16884119 100644 --- a/frameworks/core/components/scroll_bar/scroll_bar_proxy.cpp +++ b/frameworks/core/components/scroll_bar/scroll_bar_proxy.cpp @@ -19,6 +19,7 @@ #include "core/components/scroll_bar/render_scroll_bar.h" #include "core/components_v2/grid/render_grid_scroll.h" #include "core/components_v2/list/render_list.h" +#include "core/components_v2/water_flow/render_water_flow.h" namespace OHOS::Ace { @@ -208,7 +209,7 @@ void ScrollBarProxy::StopScrollBarAnimator() const bool ScrollBarProxy::CheckScrollable(const RefPtr& node) const { return AceType::InstanceOf(node) || AceType::InstanceOf(node) || - AceType::InstanceOf(node); + AceType::InstanceOf(node) || AceType::InstanceOf(node); } Axis ScrollBarProxy::GetScrollableAxis(const RefPtr& node) const @@ -225,6 +226,10 @@ Axis ScrollBarProxy::GetScrollableAxis(const RefPtr& node) const if (renderList) { return renderList->GetAxis(); } + auto renderWaterFlow = AceType::DynamicCast(node); + if (renderWaterFlow) { + return renderWaterFlow->GetAxis(); + } return Axis::NONE; } @@ -250,6 +255,12 @@ Size ScrollBarProxy::GetScrollableChildSize( : result.SetWidth(renderList->GetEstimatedHeight()); return result; } + auto renderWaterFlow = AceType::DynamicCast(scrollable); + if (renderWaterFlow) { + scrollBarAxis == Axis::VERTICAL ? result.SetHeight(renderWaterFlow->GetEstimatedHeight()) + : result.SetWidth(renderWaterFlow->GetEstimatedHeight()); + return result; + } return result; } @@ -281,6 +292,15 @@ void ScrollBarProxy::AdjustParam(const RefPtr& scrollable, Axis scro scrollableAxis = renderList->GetAxis(); scrollableChildPosition = renderList->GetLastOffset(); } + + auto renderWaterFlow = AceType::DynamicCast(scrollable); + if (renderWaterFlow) { + scrollBarAxis == Axis::VERTICAL ? scrollableChildSize.SetHeight(renderWaterFlow->GetEstimatedHeight()) + : scrollableChildSize.SetWidth(renderWaterFlow->GetEstimatedHeight()); + scrollableAxis = renderWaterFlow->GetAxis(); + scrollableChildPosition = renderWaterFlow->GetLastOffset(); + return; + } } } // namespace OHOS::Ace \ No newline at end of file diff --git a/frameworks/core/components/test/unittest/BUILD.gn b/frameworks/core/components/test/unittest/BUILD.gn index 8c7c78799eb..a5979e26a36 100644 --- a/frameworks/core/components/test/unittest/BUILD.gn +++ b/frameworks/core/components/test/unittest/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 @@ -65,6 +65,7 @@ group("unittest") { "tween:unittest", #"view_update:unittest", + "water_flow:unittest", "wrap:unittest", ] if (!is_wearable_product) { diff --git a/frameworks/core/components/test/unittest/water_flow/BUILD.gn b/frameworks/core/components/test/unittest/water_flow/BUILD.gn new file mode 100644 index 00000000000..ec248b08528 --- /dev/null +++ b/frameworks/core/components/test/unittest/water_flow/BUILD.gn @@ -0,0 +1,45 @@ +# Copyright (c) 2022 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. + +import("//build/test.gni") +import("//foundation/arkui/ace_engine/ace_config.gni") + +if (is_standard_system) { + module_output_path = "ace_engine_standard/backenduicomponent/water_flow" +} else { + module_output_path = "ace_engine_full/backenduicomponent/water_flow" +} + +ohos_unittest("RenderWaterFlowTest") { + module_out_path = module_output_path + + sources = [ + "$ace_root/frameworks/core/components/test/json/json_frontend.cpp", + "$ace_root/frameworks/core/components/test/unittest/mock/mock_render_common.cpp", + "render_water_flow_test.cpp", + "water_flow_test_utils.cpp", + ] + + configs = [ "$ace_root:ace_test_config" ] + + deps = [ "$ace_root/build:ace_ohos_unittest_base" ] + + part_name = ace_engine_part +} + +group("unittest") { + testonly = true + deps = [] + + deps = [ ":RenderWaterFlowTest" ] +} diff --git a/frameworks/core/components/test/unittest/water_flow/render_water_flow_test.cpp b/frameworks/core/components/test/unittest/water_flow/render_water_flow_test.cpp new file mode 100644 index 00000000000..432c6efd6df --- /dev/null +++ b/frameworks/core/components/test/unittest/water_flow/render_water_flow_test.cpp @@ -0,0 +1,846 @@ +/* + * Copyright (c) 2022 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 "gtest/gtest.h" + +#include "core/components/test/unittest/mock/mock_render_common.h" + +#define private public +#define protected public +#include "core/components/test/unittest/water_flow/water_flow_test_utils.h" +#include "core/components_v2/water_flow/render_water_flow.h" +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; +using RenderWaterFlow = OHOS::Ace::V2::RenderWaterFlow; +using RenderWaterFlowItem = OHOS::Ace::V2::RenderWaterFlowItem; +using WaterFlowComponent = OHOS::Ace::V2::WaterFlowComponent; +using WaterFlowItemComponent = OHOS::Ace::V2::WaterFlowItemComponent; +using WaterFlowPositionController = OHOS::Ace::V2::WaterFlowPositionController; + +namespace OHOS::Ace { +constexpr int32_t WATER_FLOW_COLUMNS_NUMBERS = 5; +constexpr Dimension height = 160.0_px; +constexpr double view_width = 1000.0; +constexpr double view_height = 1000.0; +constexpr double rowGap = 50.0; +constexpr double colGap = 50.0; +constexpr int32_t rowCount = 5; +constexpr int32_t colCount = 5; + +class RenderWaterFlowTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; + + void CreateWaterFlow(int32_t itemMainSpan, int32_t itemCrossSpan); + void CreateWaterFlowDefaultHeight(); + void FillItems( + int32_t index, int32_t MainSpan, int32_t CrossSpan, int32_t callbackMainSpan, int32_t callbackCrossSpan); + void SetCallback(int32_t itemMainSpan, int32_t itemCrossSpan); + + RefPtr mockContext_; + RefPtr renderNode_; + const int32_t render_component_count = 5; +}; + +void RenderWaterFlowTest::SetUpTestCase() {} +void RenderWaterFlowTest::TearDownTestCase() {} + +void RenderWaterFlowTest::SetUp() +{ + mockContext_ = MockRenderCommon::GetMockContext(); + renderNode_ = AceType::MakeRefPtr(); + renderNode_->Attach(mockContext_); +} + +void RenderWaterFlowTest::TearDown() +{ + mockContext_ = nullptr; + renderNode_ = nullptr; +} + +void RenderWaterFlowTest::CreateWaterFlow(int32_t itemMainSpan, int32_t itemCrossSpan) +{ + auto Component = WaterFlowTestUtils::CreateComponent(FlexDirection::COLUMN, WATER_FLOW_COLUMNS_NUMBERS); + auto waterflowComponent = AceType::DynamicCast(Component); + if (!waterflowComponent) { + GTEST_LOG_(INFO) << "create WaterFlow component failed!"; + return; + } + RefPtr controller = AceType::MakeRefPtr(); + RefPtr scrollBarProxy = AceType::MakeRefPtr(); + waterflowComponent->SetController(controller); + waterflowComponent->SetScrollBarProxy(scrollBarProxy); + waterflowComponent->SetMainLength(height); + if (renderNode_ == nullptr) { + GTEST_LOG_(INFO) << "renderNode_ == nullptr!"; + } + renderNode_->mainSize_ = view_height; + renderNode_->crossSize_ = view_width; + renderNode_->mainCount_ = rowCount; + renderNode_->crossCount_ = colCount; + renderNode_->mainGap_ = rowGap; + renderNode_->crossGap_ = colGap; + renderNode_->useScrollable_ = V2::RenderWaterFlow::SCROLLABLE::VERTICAL; + DisplayMode displayMode = DisplayMode::AUTO; + renderNode_->scrollBar_ = AceType::MakeRefPtr(displayMode); + renderNode_->totalCountFlag_ = true; + renderNode_->GetChildViewPort().SetWidth(view_width); + renderNode_->GetChildViewPort().SetHeight(view_height); + SetCallback(itemMainSpan, itemCrossSpan); + renderNode_->Update(waterflowComponent); +} + +void RenderWaterFlowTest::CreateWaterFlowDefaultHeight() +{ + auto Component = WaterFlowTestUtils::CreateComponent(FlexDirection::ROW, WATER_FLOW_COLUMNS_NUMBERS); + auto waterflowComponent = AceType::DynamicCast(Component); + if (!waterflowComponent) { + GTEST_LOG_(INFO) << "create WaterFlow component failed!"; + return; + } + RefPtr controller = AceType::MakeRefPtr(); + RefPtr scrollBarProxy = AceType::MakeRefPtr(); + waterflowComponent->SetController(controller); + waterflowComponent->SetScrollBarProxy(scrollBarProxy); + renderNode_->Update(waterflowComponent); +} + +void RenderWaterFlowTest::FillItems( + int32_t index, int32_t itemMainSpan, int32_t itemCrossSpan, int32_t callbackMainSpan, int32_t callbackCrossSpan) +{ + CreateWaterFlow(callbackMainSpan, callbackCrossSpan); + auto item = WaterFlowTestUtils::CreateRenderItem(itemMainSpan, itemCrossSpan, index, mockContext_); + auto flowitem = AceType::DynamicCast(item); + if (flowitem == nullptr) { + GTEST_LOG_(INFO) << "flowitem == nullptr!"; + return; + } + renderNode_->AddChildByIndex(index, flowitem); +} + +void RenderWaterFlowTest::SetCallback(int32_t callMainSpan, int32_t callCrossSpan) +{ + renderNode_->SetBuildChildByIndex([this, callMainSpan, callCrossSpan](int32_t index) { + GTEST_LOG_(INFO) << "SetBuildChildByIndex called!"; + auto item = WaterFlowTestUtils::CreateRenderItem(callMainSpan, callCrossSpan, index, mockContext_); + if (item) { + item->GetChildren().front()->Attach(mockContext_); + item->Attach(mockContext_); + renderNode_->AddChildByIndex(index, item); + return true; + } else { + GTEST_LOG_(INFO) << "create RenderWaterFlowItem component failed!"; + return false; + } + }); + renderNode_->SetDeleteChildByIndex([this](int32_t index) { + for (auto outIt = renderNode_->flowMatrix_.begin(); outIt != renderNode_->flowMatrix_.end(); outIt++) { + for (auto inIt = outIt->second.begin(); inIt != outIt->second.end(); inIt++) { + if (inIt->second == index) { + GTEST_LOG_(INFO) << "delete: rowIndex:" << outIt->first << "columnIndex:" << inIt->first + << "index:" << inIt->second; + return; + } + } + } + }); + renderNode_->SetGetChildSpanByIndex( + [](int32_t index, bool isHorizontal, int32_t& itemMainSpan, int32_t& itemCrossSpan) { + GTEST_LOG_(INFO) << "SetGetChildSpanByIndex called !"; + + if (index >= 0) { + if (isHorizontal) { + itemMainSpan = 1; + itemCrossSpan = 1; + } else { + itemMainSpan = 1; + itemCrossSpan = 1; + } + return true; + } + return false; + }); +} + +HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_GetItemCalSizeNeeded_001, TestSize.Level1) +{ + RefPtr renderitem = nullptr; + auto result = renderNode_->GetItemCalSizeNeeded(renderitem); + EXPECT_EQ(result, false); + auto item = WaterFlowTestUtils::CreateRenderItem(1, 1, 1, mockContext_); + if (item) { + item->GetChildren().front()->Attach(mockContext_); + item->Attach(mockContext_); + } + auto expect = renderNode_->GetItemCalSizeNeeded(item); + EXPECT_EQ(expect, true); +} + +HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_SetItemCalSizeNeeded_001, TestSize.Level1) +{ + auto item = WaterFlowTestUtils::CreateRenderItem(1, 1, 1, mockContext_); + if (item) { + item->GetChildren().front()->Attach(mockContext_); + item->Attach(mockContext_); + } + renderNode_->SetItemCalSizeNeeded(item, true); + EXPECT_TRUE(item->GetCalSizeNeeded()); +} + +HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_UpdateAccessibilityAttr_001, TestSize.Level1) +{ + CreateWaterFlow(1, 1); + NodeId nodeId = 1; + std::string nodeName = "string"; + auto sAbilityNode = AceType::MakeRefPtr(nodeId, nodeName); + WeakPtr wAbilityNode(sAbilityNode); + auto wref = wAbilityNode.Upgrade(); + if (wref == nullptr) { + GTEST_LOG_(INFO) << "wref == nullptr!"; + return; + } + + renderNode_->SetAccessibilityNode(wAbilityNode); + renderNode_->UpdateAccessibilityAttr(); + auto refPtr = renderNode_->GetAccessibilityNode().Upgrade(); + if (refPtr) { + EXPECT_EQ(refPtr->GetCollectionInfo().rows, 5); + EXPECT_EQ(refPtr->GetCollectionInfo().columns, 5); + } else { + GTEST_LOG_(INFO) << "the refptr is nullptr"; + } +} + +HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_GetIndexByFlow_001, TestSize.Level1) +{ + CreateWaterFlow(1, 1); + int32_t row = 1; + int32_t col = 2; + int32_t index = 1; + for (int32_t i = 1; i < 3; i++) { + for (int32_t j = 1; j < 3; j++) { + renderNode_->flowMatrix_[i][j] = index; + index++; + } + } + int32_t result = renderNode_->GetIndexByFlow(row, col); + EXPECT_EQ(result, 2); +} + +HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_focusMove_001, TestSize.Level1) +{ + CreateWaterFlow(1, 1); + int32_t index = 0; + KeyDirection direction = KeyDirection::DOWN; + for (int32_t i = 0; i < 4; i++) { + for (int32_t j = 0; j < 4; j++) { + renderNode_->flowMatrix_[i][j] = index; + index++; + } + } + renderNode_->focusRow_ = 0; + renderNode_->focusCol_ = 1; + renderNode_->focusIndex_ = 1; + int32_t result = renderNode_->focusMove(direction); + EXPECT_EQ(result, 5); +} + +HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_GetItemSpan_001, TestSize.Level1) +{ + CreateWaterFlow(1, 1); + auto item = WaterFlowTestUtils::CreateRenderItem(1, 2, 1, mockContext_); + auto flowItem = AceType::DynamicCast(item); + EXPECT_NE(flowItem, nullptr); + int32_t rowresult = renderNode_->GetItemSpan(flowItem, true); + EXPECT_EQ(rowresult, 1); + int32_t colresult = renderNode_->GetItemSpan(flowItem, false); + EXPECT_EQ(colresult, 2); +} + +HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_updatefocusinfo_001, TestSize.Level1) +{ + CreateWaterFlow(1, 1); + int32_t index = 0; + int32_t focusIndex = 1; + for (int32_t i = 0; i < 4; i++) { + for (int32_t j = 0; j < 4; j++) { + renderNode_->flowMatrixByIndex_[i][j] = index; + index++; + } + } + + renderNode_->UpdateFocusInfo(focusIndex); + EXPECT_EQ(renderNode_->focusRow_, 0); + EXPECT_EQ(renderNode_->focusCol_, 4); +} + +HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_RequestNextFocus_001, TestSize.Level1) +{ + CreateWaterFlow(1, 1); + int32_t index = 0; + bool vertical = true; + bool reverse = false; + for (int32_t i = 0; i < 4; i++) { + for (int32_t j = 0; j < 4; j++) { + renderNode_->flowMatrix_[j][i] = index; + index++; + } + } + renderNode_->focusRow_ = 0; + renderNode_->focusCol_ = 1; + renderNode_->focusIndex_ = 1; + int32_t result = renderNode_->RequestNextFocus(vertical, reverse); + EXPECT_EQ(result, 5); +} + +HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_ParseCrossLength_001, TestSize.Level1) +{ + CreateWaterFlow(1, 1); + std::vector rowlens; + std::vector collens; + rowlens = renderNode_->ParseCrossLength(renderNode_->mainSize_, renderNode_->mainGap_); + for (auto& len : rowlens) { + EXPECT_EQ(len, 160); + } + collens = renderNode_->ParseCrossLength(renderNode_->crossSize_, renderNode_->crossGap_); + for (auto len : collens) { + EXPECT_EQ(len, 160); + } +} + +HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_UpdateScrollPosition_001, TestSize.Level1) +{ + CreateWaterFlow(1, 1); + renderNode_->currentOffset_ = 1.0; + double offset1 = 3.1; + int32_t source = 10; + bool result = renderNode_->UpdateScrollPosition(offset1, source); + EXPECT_TRUE(result); + EXPECT_EQ(renderNode_->currentOffset_, 1.0); + + double offset = 2.1; + int32_t source2 = 2; + renderNode_->reachHead_ = false; + renderNode_->reachTail_ = true; + renderNode_->currentOffset_ = 1.0; + auto expect = renderNode_->UpdateScrollPosition(offset, source2); + EXPECT_EQ(renderNode_->reachTail_, false); + EXPECT_TRUE(expect); + EXPECT_EQ(renderNode_->currentOffset_, 3.0); + + double offset2 = -2.1; + int32_t source3 = 2; + renderNode_->reachHead_ = true; + renderNode_->reachTail_ = false; + renderNode_->currentOffset_ = 1.0; + auto expect2 = renderNode_->UpdateScrollPosition(offset2, source3); + EXPECT_EQ(renderNode_->reachHead_, false); + EXPECT_TRUE(expect2); + EXPECT_EQ(renderNode_->currentOffset_, -1.0); +} + +HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_HandleAxisEvent_001, TestSize.Level1) +{ + AxisEvent event; + event.horizontalAxis = 1.5; + event.verticalAxis = 1.5; + renderNode_->reachHead_ = true; + renderNode_->reachTail_ = false; + renderNode_->currentOffset_ = 1.0; + renderNode_->HandleAxisEvent(event); + EXPECT_EQ(renderNode_->reachHead_, false); + EXPECT_EQ(renderNode_->currentOffset_, -11.0); +} + +HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_isScrollable_001, TestSize.Level1) +{ + AxisDirection direction1 = AxisDirection::UP; + renderNode_->isVertical_ = true; + renderNode_->reachHead_ = false; + renderNode_->reachTail_ = true; + EXPECT_TRUE(renderNode_->IsAxisScrollable(direction1)); + + AxisDirection direction2 = AxisDirection::DOWN; + renderNode_->reachHead_ = true; + renderNode_->reachTail_ = false; + EXPECT_TRUE(renderNode_->IsAxisScrollable(direction2)); + + renderNode_->isVertical_ = false; + AxisDirection direction3 = AxisDirection::LEFT; + renderNode_->reachHead_ = false; + renderNode_->reachTail_ = true; + EXPECT_TRUE(renderNode_->IsAxisScrollable(direction3)); + + AxisDirection direction4 = AxisDirection::RIGHT; + renderNode_->reachHead_ = true; + renderNode_->reachTail_ = false; + EXPECT_TRUE(renderNode_->IsAxisScrollable(direction4)); +} + +HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_OnPaintFinish_001, TestSize.Level1) +{ + renderNode_->showItem_ = {1.0, 2.0}; + renderNode_->OnPaintFinish(); + EXPECT_EQ(renderNode_->startShowItemIndex_, 1.0); + EXPECT_EQ(renderNode_->endShowItemIndex_, 2.0); +} + +HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_ClearItems_001, TestSize.Level1) +{ + FillItems(0, 1, 1, 1, 1); + renderNode_->ClearItems(); + EXPECT_EQ(renderNode_->items_.size(), 0); +} + +HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_GetItemSpanFromCache_001, TestSize.Level1) +{ + int32_t itemMainSpan = 0; + int32_t itemCrossSpan = 0; + int32_t index = 2; + for (int32_t i = 0; i < 5; i++) { + FillItems(i, 1, 1, 1, 1); + } + bool result = renderNode_->GetItemSpanFromCache(index, itemMainSpan, itemCrossSpan); + auto it = renderNode_->itemSpanCache_.find(2); + if (it != renderNode_->itemSpanCache_.end()) { + EXPECT_EQ(it->second.rowSpan, 1); + EXPECT_EQ(it->second.colSpan, 1); + } + EXPECT_TRUE(result); +} + +HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_OnDataSourceUpdated_001, TestSize.Level1) +{ + for (int32_t i = 0; i < 5; i++) { + FillItems(i, 1, 1, 1, 1); + } + int32_t index = -1; + for (int32_t i = 0; i < 4; i++) { + for (int32_t j = 0; j < 4; j++) { + renderNode_->flowMatrix_[i][j] = index; + } + } + renderNode_->OnDataSourceUpdated(index); + EXPECT_EQ(renderNode_->items_.size(), 0); +} + +HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_GetItemMainIndex_001, TestSize.Level1) +{ + for (int32_t i = 0; i < 5; i++) { + FillItems(i, 1, 1, 1, 1); + } + int32_t index = 0; + int32_t findindex = 2; + int32_t mainIndex = 0; + int32_t crossIndex = 0; + for (int32_t i = 0; i < 4; i++) { + for (int32_t j = 0; j < 4; j++) { + renderNode_->flowMatrixByIndex_[i][j] = index; + index++; + } + } + bool result = renderNode_->GetItemMainCrossIndex(1, mainIndex, crossIndex); + EXPECT_TRUE(result); + EXPECT_EQ(mainIndex, 0); + EXPECT_EQ(crossIndex, 4); + EXPECT_EQ(renderNode_->GetItemMainIndex(findindex), 0); + findindex = 6; + EXPECT_EQ(renderNode_->GetItemMainIndex(findindex), -1); +} + +HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_DeleteItems_001, TestSize.Level1) +{ + for (int32_t i = 0; i < 5; i++) { + FillItems(i, 1, 1, 1, 1); + } + int32_t index = 0; + for (int32_t i = 0; i < 3; i++) { + for (int32_t j = 0; j < 3; j++) { + renderNode_->flowMatrix_[i][j] = index; + index++; + } + } + EXPECT_EQ(renderNode_->items_.size(), 5); + renderNode_->DeleteItems(0, false); + EXPECT_EQ(renderNode_->items_.size(), 2); +} + +HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_BuildFlow_001, TestSize.Level1) +{ + std::vector cross; + for (int32_t i = 0; i < 5; i++) { + FillItems(i, 1, 1, 1, 1); + } + renderNode_->BuildFlow(cross); + if (cross.empty()) { + GTEST_LOG_(INFO) << "buildflow failed!"; + return; + } + EXPECT_EQ(renderNode_->flowCells_.Width(), 160.0); +} + +HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_NeedUpdate_001, TestSize.Level1) +{ + FlexDirection directionExpect = FlexDirection::COLUMN; + int32_t cols = 3; + auto component = WaterFlowTestUtils::CreateComponent(directionExpect, cols); + bool update = renderNode_->NeedUpdate(component); + EXPECT_TRUE(update); +} + +HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_AddChildByIndex_001, TestSize.Level1) +{ + for (int32_t index = 0; index < render_component_count; index++) { + auto item = WaterFlowTestUtils::CreateRenderItem(1, 1, index, mockContext_); + auto flowitem = AceType::DynamicCast(item); + renderNode_->AddChildByIndex(index, flowitem); + } + EXPECT_EQ(renderNode_->items_.size(), render_component_count); + EXPECT_EQ(renderNode_->RenderNode::GetChildren().size(), render_component_count); +} + +HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_SetChildPosition_001, TestSize.Level1) +{ + int32_t index = 0; + Size size(160, 160); + for (int32_t i = 0; i < 6; i++) { + FillItems(i, 1, 1, 1, 1); + } + for (int32_t i = 0; i < 3; i++) { + for (int32_t j = 0; j < 3; j++) { + renderNode_->flowMatrixByIndex_[i][j] = index; + index++; + } + } + renderNode_->flowCells_ = size; + auto item = renderNode_->items_.find(3); + int32_t itemMainSpan = renderNode_->GetItemSpan(item->second, false); + int32_t itemCrosspan = renderNode_->GetItemSpan(item->second, true); + int32_t itemMain = renderNode_->GetItemMainIndex(1); + item->second->SetLayoutSize(Size(160, 160)); + renderNode_->SetChildPosition(item->second, itemMain, 1, itemMainSpan, itemCrosspan); + EXPECT_TRUE(item->second->GetPosition() == Offset(210.0, 0.0)); +} + +HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_CheckFlowPlaced_001, TestSize.Level1) +{ + int32_t itemMain = 0; + int32_t itemCross = 2; + int32_t itemMainSpan = 0; + int32_t itemCrossSpan = 0; + int32_t index = 2; + for (int32_t i = 0; i < 5; i++) { + FillItems(i, 1, 1, 1, 1); + } + EXPECT_TRUE(renderNode_->GetItemSpanFromCache(index, itemMainSpan, itemCrossSpan)); + bool result = renderNode_->CheckFlowPlaced(index, itemMain, itemCross, itemMainSpan, itemCrossSpan); + EXPECT_TRUE(result); + EXPECT_TRUE(renderNode_->flowMatrix_.count(0)); +} + +HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_MakeInnerLayoutParam_001, TestSize.Level1) +{ + int32_t itemMain = 0; + int32_t itemCross = 2; + int32_t itemMainSpan = 0; + int32_t itemCrossSpan = 0; + int32_t index = 2; + Size size(160, 160); + for (int32_t i = 0; i < 5; i++) { + FillItems(i, 1, 1, 1, 1); + } + renderNode_->flowCells_ = size; + EXPECT_TRUE(renderNode_->GetItemSpanFromCache(index, itemMainSpan, itemCrossSpan)); + const auto& it = renderNode_->MakeInnerLayoutParam(itemMain, itemCross, itemMainSpan, itemCrossSpan); + EXPECT_EQ(it.GetMaxSize(), size); +} + +HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_LayoutChild_001, TestSize.Level1) +{ + int32_t itemMain = 0; + int32_t itemCross = 1; + int32_t itemMainSpan = 1; + int32_t itemCrossSpan = 1; + + Size size(160, 160); + for (int32_t i = 0; i < 5; i++) { + FillItems(i, 1, 1, 1, 1); + } + renderNode_->flowCells_ = size; + renderNode_->mainSize_ = 160; + auto item = renderNode_->items_.find(1); + renderNode_->LayoutChild(item->second, itemMain, itemCross, itemMainSpan, itemCrossSpan); + EXPECT_EQ(item->second->GetPosition(), Offset(0, 210)); +} + +HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_GetFlowSize_001, TestSize.Level1) +{ + for (int32_t i = 0; i < 5; i++) { + FillItems(i, 1, 1, 1, 1); + } + renderNode_->mainSize_ = 0; + renderNode_->crossSize_ = 0; + Size sizemax(1000, 1000); + Size sizemin(160, 160); + LayoutParam layoutParam(sizemax, sizemin); + renderNode_->SetLayoutParam(layoutParam); + EXPECT_TRUE(renderNode_->GetFlowSize()); + EXPECT_EQ(renderNode_->mainSize_, 1000); + EXPECT_EQ(renderNode_->crossSize_, 1000); +} + +HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_Rank_001, TestSize.Level1) +{ + for (int32_t i = 0; i < 5; i++) { + FillItems(i, 1, 1, 1, 1); + } + int32_t index = 0; + for (int32_t i = 0; i < 4; i++) { + for (int32_t j = 0; j < 4; j++) { + renderNode_->flowMatrix_[i][j] = index; + index++; + } + } + bool result = renderNode_->Rank(3); + EXPECT_TRUE(result); +} + +HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_CreateScrollable_001, TestSize.Level1) +{ + for (int32_t i = 0; i < 5; i++) { + FillItems(i, 1, 1, 1, 1); + } + renderNode_->scrollable_ = nullptr; + renderNode_->CreateScrollable(); + EXPECT_TRUE(renderNode_->scrollable_ != nullptr); +} + +HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_SupplyItems_001, TestSize.Level1) +{ + std::vector main; + + int32_t mainIndex = 0; + bool vailSupplyItem = false; + for (int32_t i = 0; i < 5; i++) { + FillItems(i, 1, 1, 1, 1); + } + int32_t index = 0; + for (int32_t i = 0; i < 4; i++) { + for (int32_t j = 0; j < 4; j++) { + renderNode_->flowMatrix_[i][j] = -1; + index++; + } + } + renderNode_->BuildFlow(main); + renderNode_->SupplyItems(vailSupplyItem, mainIndex); + + EXPECT_TRUE(renderNode_->inCache_.count(mainIndex)); +} + +HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_PerformLayout_001, TestSize.Level1) +{ + CreateWaterFlow(1, 1); + renderNode_->mainSize_ = 0; + renderNode_->crossSize_ = 0; + Size sizemax(1000, 1000); + Size sizemin(160, 160); + LayoutParam layoutParam(sizemax, sizemin); + renderNode_->SetLayoutParam(layoutParam); + renderNode_->PerformLayout(); + const std::list>& items = renderNode_->RenderNode::GetChildren(); + EXPECT_TRUE(!items.empty()); + int32_t index = 0; + for (const auto& item : items) { + EXPECT_TRUE(item->GetPosition() == Offset(index % 5 * 210, index / 5 * 210)); + EXPECT_TRUE(item->GetLayoutSize() == Size(160.0, 160.0)); + index++; + } +} + +HWTEST_F(RenderWaterFlowTest, PerformLayout_002, TestSize.Level1) +{ + CreateWaterFlow(2, 2); + renderNode_->SetGetChildSpanByIndex( + [](int32_t index, bool isHorizontal, int32_t& itemMainSpan, int32_t& itemCrossSpan) { + GTEST_LOG_(INFO) << "SetGetChildSpanByIndex called start!"; + if (index >= 0) { + itemMainSpan = 2; + itemCrossSpan = 2; + return true; + } + return false; + }); + renderNode_->SetDeleteChildByIndex([](int32_t index) {}); + + LayoutParam layoutParam; + layoutParam.SetMinSize(Size(0.0, 0.0)); + layoutParam.SetMaxSize(Size(1000.0, 1000.0)); + renderNode_->SetLayoutParam(layoutParam); + + renderNode_->PerformLayout(); + + auto& items = renderNode_->RenderNode::GetChildren(); + EXPECT_TRUE(!items.empty()); + int32_t index = 0; + for (const auto& item : items) { + if ((index + 1) % 3 == 0) { + EXPECT_TRUE(item->GetPosition() == Offset(index % 3 * 420, index / 3 * 420)); + EXPECT_TRUE(item->GetLayoutSize() == Size(160.0, 2 * 160 + 50)); + } else { + EXPECT_TRUE(item->GetPosition() == Offset(index % 3 * 420, index / 3 * 420)); + EXPECT_TRUE(item->GetLayoutSize() == Size(2 * 160 + 50, 2 * 160 + 50)); + } + index++; + } +} + +HWTEST_F(RenderWaterFlowTest, PerformLayout_003, TestSize.Level1) +{ + CreateWaterFlow(3, 3); + renderNode_->SetGetChildSpanByIndex( + [](int32_t index, bool isHorizontal, int32_t& itemMainSpan, int32_t& itemCrossSpan) { + GTEST_LOG_(INFO) << "SetGetChildSpanByIndex called start!"; + if (index >= 0) { + itemMainSpan = 3; + itemCrossSpan = 3; + return true; + } + return false; + }); + renderNode_->SetDeleteChildByIndex([](int32_t index) {}); + + LayoutParam layoutParam; + layoutParam.SetMinSize(Size(0.0, 0.0)); + layoutParam.SetMaxSize(Size(1000.0, 1000.0)); + renderNode_->SetLayoutParam(layoutParam); + + renderNode_->PerformLayout(); + + auto& items = renderNode_->RenderNode::GetChildren(); + EXPECT_TRUE(!items.empty()); + int32_t index = 0; + for (const auto& item : items) { + if ((index + 1) % 2 == 0) { + EXPECT_TRUE(item->GetPosition() == Offset(index % 2 * 630, index / 2 * 630)); + EXPECT_TRUE(item->GetLayoutSize() == Size(2 * 160 + 50, 3 * 160 + 50 * 2)); + } else { + EXPECT_TRUE(item->GetPosition() == Offset(index % 2 * 630, index / 2 * 630)); + EXPECT_TRUE(item->GetLayoutSize() == Size(3 * 160 + 50 * 2, 3 * 160 + 50 * 2)); + } + index++; + } +} + +HWTEST_F(RenderWaterFlowTest, PerformLayout_004, TestSize.Level1) +{ + CreateWaterFlow(4, 4); + renderNode_->SetGetChildSpanByIndex( + [](int32_t index, bool isHorizontal, int32_t& itemMainSpan, int32_t& itemCrossSpan) { + GTEST_LOG_(INFO) << "SetGetChildSpanByIndex called start!"; + if (index >= 0) { + itemMainSpan = 4; + itemCrossSpan = 4; + return true; + } + return false; + }); + renderNode_->SetDeleteChildByIndex([](int32_t index) {}); + + LayoutParam layoutParam; + layoutParam.SetMinSize(Size(0.0, 0.0)); + layoutParam.SetMaxSize(Size(1000.0, 1000.0)); + renderNode_->SetLayoutParam(layoutParam); + + renderNode_->PerformLayout(); + + auto& items = renderNode_->RenderNode::GetChildren(); + EXPECT_TRUE(!items.empty()); + int32_t index = 0; + for (const auto& item : items) { + if ((index + 1) % 2 == 0) { + EXPECT_TRUE(item->GetPosition() == Offset(index % 2 * 840, index / 2 * 840)); + EXPECT_TRUE(item->GetLayoutSize() == Size(160, 4 * 160 + 50 * 3)); + } else { + EXPECT_TRUE(item->GetPosition() == Offset(index % 2 * 840, index / 2 * 840)); + EXPECT_TRUE(item->GetLayoutSize() == Size(4 * 160 + 50 * 3, 4 * 160 + 50 * 3)); + } + index++; + } +} + +HWTEST_F(RenderWaterFlowTest, PerformLayout_005, TestSize.Level1) +{ + CreateWaterFlow(5, 5); + renderNode_->SetGetChildSpanByIndex( + [](int32_t index, bool isHorizontal, int32_t& itemMainSpan, int32_t& itemCrossSpan) { + GTEST_LOG_(INFO) << "SetGetChildSpanByIndex called start!"; + if (index >= 0) { + itemMainSpan = 5; + itemCrossSpan = 5; + return true; + } + return false; + }); + renderNode_->SetDeleteChildByIndex([](int32_t index) {}); + + LayoutParam layoutParam; + layoutParam.SetMinSize(Size(0.0, 0.0)); + layoutParam.SetMaxSize(Size(1000.0, 1000.0)); + renderNode_->SetLayoutParam(layoutParam); + + renderNode_->PerformLayout(); + + auto& items = renderNode_->RenderNode::GetChildren(); + EXPECT_TRUE(items.size() == 1); + auto it = items.begin(); + EXPECT_TRUE((*it)->GetPosition() == Offset(0, 0)); + EXPECT_TRUE((*it)->GetLayoutSize() == Size(1000, 1000)); +} + +HWTEST_F(RenderWaterFlowTest, PerformLayout_006, TestSize.Level1) +{ + CreateWaterFlow(6, 6); + renderNode_->SetGetChildSpanByIndex( + [](int32_t index, bool isHorizontal, int32_t& itemMainSpan, int32_t& itemCrossSpan) { + GTEST_LOG_(INFO) << "SetGetChildSpanByIndex called start!"; + if (index >= 0) { + itemMainSpan = 6; + itemCrossSpan = 6; + return true; + } + return false; + }); + renderNode_->SetDeleteChildByIndex([](int32_t index) {}); + + LayoutParam layoutParam; + layoutParam.SetMinSize(Size(0.0, 0.0)); + layoutParam.SetMaxSize(Size(1000.0, 1000.0)); + renderNode_->SetLayoutParam(layoutParam); + + renderNode_->PerformLayout(); + + auto& items = renderNode_->RenderNode::GetChildren(); + EXPECT_TRUE(items.size() == 1); + auto it = items.begin(); + EXPECT_TRUE((*it)->GetPosition() == Offset(0, 0)); + EXPECT_TRUE((*it)->GetLayoutSize() == Size(1000, 1210)); +} +} // namespace OHOS::Ace diff --git a/frameworks/core/components/test/unittest/water_flow/water_flow_test_utils.cpp b/frameworks/core/components/test/unittest/water_flow/water_flow_test_utils.cpp new file mode 100644 index 00000000000..8fb9c05d09f --- /dev/null +++ b/frameworks/core/components/test/unittest/water_flow/water_flow_test_utils.cpp @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2022 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 "core/components/test/unittest/water_flow/water_flow_test_utils.h" +#include "core/components_v2/water_flow/render_water_flow_item.h" +#include "core/components/box/box_component.h" + +namespace OHOS::Ace { +RefPtr WaterFlowTestUtils::CreateComponent(FlexDirection direction, int32_t cols) +{ + std::list> children; + Dimension RowGap = 50.0_px; + Dimension ColumnsGap = 50.0_px; + RefPtr component = AceType::MakeRefPtr(children, cols); + component->SetRowsGap(RowGap); + component->SetColumnsGap(ColumnsGap); + component->SetLayoutDirection(direction); + return component; +} + +RefPtr WaterFlowTestUtils::CreateComponentItem(const int32_t& itemMainSpan, const int32_t& itemCrossSpan) +{ + RefPtr box = AceType::MakeRefPtr(); + RefPtr ComponentItem = AceType::MakeRefPtr(box); + auto flowItem = AceType::DynamicCast(ComponentItem); + if (flowItem) { + flowItem->SetRowSpan(itemMainSpan); + flowItem->SetColumnSpan(itemCrossSpan); + return flowItem; + } + return nullptr; +} + +RefPtr WaterFlowTestUtils::CreateRenderItem( + int32_t rowSpan, int32_t colSpan, int32_t index, const RefPtr& context) +{ + constexpr double DIM_SIZE_VALUE_TEST = 150.0; + RefPtr boxComponent = AceType::MakeRefPtr(); + RefPtr renderBox = AceType::MakeRefPtr(); + boxComponent->SetWidth(DIM_SIZE_VALUE_TEST); + boxComponent->SetHeight(DIM_SIZE_VALUE_TEST); + renderBox->Update(boxComponent); + renderBox->Attach(context); + RefPtr Renderitem = AceType::MakeRefPtr(); + if (Renderitem) { + auto itemComponent = CreateComponentItem(rowSpan, colSpan); + if (itemComponent) { + Renderitem->Update(itemComponent); + Renderitem->SetBoundary(); + Renderitem->SetIndex(index); + Renderitem->Attach(context); + Renderitem->SetHidden(false); + Renderitem->AddChild(renderBox); + return Renderitem; + } + } + return nullptr; +} + +RefPtr WaterFlowTestUtils::CreateRenderItem( + double width, double height, int32_t rowspan, int32_t colspan, const RefPtr& context) +{ + RefPtr parent = AceType::MakeRefPtr(); + RefPtr child = AceType::MakeRefPtr(); + RefPtr renderBox = AceType::MakeRefPtr(); + parent->Attach(context); + child->Attach(context); + renderBox->Attach(context); + RefPtr boxComponent = AceType::MakeRefPtr(); + boxComponent->SetWidth(width); + boxComponent->SetHeight(height); + renderBox->Update(boxComponent); + child->SetRowSpan(rowspan); + child->SetColumnSpan(colspan); + parent->AddChild(child); + child->AddChild(renderBox); + return parent; +} +} // namespace OHOS::Ace diff --git a/frameworks/core/components/test/unittest/water_flow/water_flow_test_utils.h b/frameworks/core/components/test/unittest/water_flow/water_flow_test_utils.h new file mode 100644 index 00000000000..cfb592abb68 --- /dev/null +++ b/frameworks/core/components/test/unittest/water_flow/water_flow_test_utils.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2022 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TEST_UNITTEST_WATER_FLOW_WARER_FLOW_TEST_UTILS_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TEST_UNITTEST_WATER_FLOW_WARER_FLOW_TEST_UTILS_H + +#include "core/components_v2/water_flow/water_flow_component.h" +#include "core/components_v2/water_flow/render_water_flow.h" +#include "core/components_v2/water_flow/water_flow_item_component.h" +#include "core/components/box/render_box.h" +#include "core/components/image/render_image.h" +#include "core/components/image/image_component.h" + +namespace OHOS::Ace { +class WaterFlowTestUtils { +public: + static RefPtr CreateRenderItem( + double width, double height, int32_t rowspan, int32_t colspan, const RefPtr& context); + static RefPtr CreateRenderItem( + int32_t rowspan, int32_t colspan, int32_t index, const RefPtr& contex); + static RefPtr CreateComponent(FlexDirection direction, int32_t cols); + static RefPtr CreateComponentItem(const int32_t& itemMainSpan, const int32_t& itemCrossSpan); +}; +} // namespace OHOS::Ace + +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TEST_UNITTEST_WATER_FLOW_WARER_FLOW_TEST_UTILS_H diff --git a/frameworks/core/components_v2/water_flow/BUILD.gn b/frameworks/core/components_v2/water_flow/BUILD.gn new file mode 100644 index 00000000000..73a19909270 --- /dev/null +++ b/frameworks/core/components_v2/water_flow/BUILD.gn @@ -0,0 +1,31 @@ +# Copyright (c) 2022 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. + +import( + "//foundation/arkui/ace_engine/frameworks/core/components/components.gni") + +build_component("water_flow_v2") { + sources = [ + "flutter_render_water_flow.cpp", + "render_water_flow.cpp", + "render_water_flow_creator.cpp", + "render_water_flow_item.cpp", + "water_flow_component.cpp", + "water_flow_element.cpp", + "water_flow_item_component.cpp", + "water_flow_item_element.cpp", + "water_flow_position_controller.cpp", + "water_flow_scroll_controller.cpp", + ] + rosen_sources = [ "rosen_render_water_flow.cpp" ] +} diff --git a/frameworks/core/components_v2/water_flow/flutter_render_water_flow.cpp b/frameworks/core/components_v2/water_flow/flutter_render_water_flow.cpp new file mode 100644 index 00000000000..b9b8e4eed28 --- /dev/null +++ b/frameworks/core/components_v2/water_flow/flutter_render_water_flow.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2022 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 "core/components_v2/water_flow/flutter_render_water_flow.h" + +#include "core/components/common/painter/flutter_scroll_bar_painter.h" +#include "core/pipeline/base/flutter_render_context.h" + +namespace OHOS::Ace::V2 { +using namespace Flutter; +RenderLayer FlutterRenderWaterFlow::GetRenderLayer() +{ + if (!layer_) { + layer_ = AceType::MakeRefPtr( + 0.0, GetLayoutSize().Width(), 0.0, GetLayoutSize().Height(), Clip::HARD_EDGE); + TakeBoundary(); + } + return AceType::RawPtr(layer_); +} + +void FlutterRenderWaterFlow::Paint(RenderContext& context, const Offset& offset) +{ + LOGD("Paint %{public}lf %{public}lf", GetLayoutSize().Width(), GetLayoutSize().Height()); + layer_->SetClip(0.0, GetLayoutSize().Width(), 0.0, GetLayoutSize().Height(), Clip::HARD_EDGE); + RenderNode::Paint(context, offset); + + // Notify scroll bar to update. + if (scrollBarProxy_) { + scrollBarProxy_->NotifyScrollBar(AceType::WeakClaim(this)); + } + + // render scroll bar + if (!scrollBar_ || !scrollBar_->NeedPaint()) { + GetEstimatedHeight(); + return; + } + bool needPaint = false; + if (scrollBar_->GetFirstLoad() || scrollBar_->IsActive() || scrollBar_->GetDisplayMode() == DisplayMode::ON) { + scrollBarOpacity_ = UINT8_MAX; + needPaint = true; + } else { + if (scrollBarOpacity_ != 0) { + needPaint = true; + } + } + if (!needPaint) { + return; + } + const auto renderContext = static_cast(&context); + flutter::Canvas* canvas = renderContext->GetCanvas(); + Offset lastOffset = isVertical_ ? Offset(0, lastOffset_) : Offset(lastOffset_, 0); + scrollBar_->UpdateScrollBarRegion(offset, GetLayoutSize(), lastOffset, GetEstimatedHeight()); + RefPtr scrollPainter = AceType::MakeRefPtr(); + scrollPainter->PaintBar(canvas, offset, GetPaintRect(), scrollBar_, GetGlobalOffset(), scrollBarOpacity_); + if (scrollBar_->GetFirstLoad()) { + scrollBar_->SetFirstLoad(false); + scrollBar_->HandleScrollBarEnd(); + } +} +} // namespace OHOS::Ace::V2 diff --git a/frameworks/core/components_v2/water_flow/flutter_render_water_flow.h b/frameworks/core/components_v2/water_flow/flutter_render_water_flow.h new file mode 100644 index 00000000000..60d4fa9301a --- /dev/null +++ b/frameworks/core/components_v2/water_flow/flutter_render_water_flow.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2022 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_FLUTTER_RENDER_WATER_FLOW_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_FLUTTER_RENDER_WATER_FLOW_H + +#include "core/components_v2/water_flow/render_water_flow.h" +#include "core/pipeline/layers/clip_layer.h" + +namespace OHOS::Ace::V2 { +class FlutterRenderWaterFlow : public RenderWaterFlow { + DECLARE_ACE_TYPE(FlutterRenderWaterFlow, RenderWaterFlow); + +public: + FlutterRenderWaterFlow() = default; + ~FlutterRenderWaterFlow() override = default; + + RenderLayer GetRenderLayer() override; + void Paint(RenderContext& context, const Offset& offset) override; + +private: + RefPtr layer_; +}; +} // namespace OHOS::Ace::V2 +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_FLUTTER_RENDER_WATER_FLOW_H diff --git a/frameworks/core/components_v2/water_flow/render_water_flow.cpp b/frameworks/core/components_v2/water_flow/render_water_flow.cpp new file mode 100644 index 00000000000..1ed46200c20 --- /dev/null +++ b/frameworks/core/components_v2/water_flow/render_water_flow.cpp @@ -0,0 +1,1804 @@ +/* + * Copyright (c) 2022 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 "core/components_v2/water_flow/render_water_flow.h" + +#include "base/log/ace_trace.h" +#include "base/log/event_report.h" +#include "base/log/log.h" +#include "base/utils/string_utils.h" +#include "base/utils/time_util.h" +#include "base/utils/utils.h" +#include "core/animation/curve_animation.h" +#include "core/components_v2/water_flow/render_water_flow_item.h" +#include "core/components_v2/water_flow/water_flow_component.h" +#include "core/components_v2/water_flow/water_flow_scroll_controller.h" +#include "core/event/ace_event_helper.h" + +namespace OHOS::Ace::V2 { +namespace { +constexpr int32_t TIMETHRESHOLD = 3 * 1000000; // milliseconds +constexpr int32_t MICROSEC_TO_NANOSEC = 1000; +constexpr int32_t DEFAULT_DEPTH = 10; +constexpr bool HORIZONTAL = false; +constexpr bool VERTICAL = true; +constexpr bool FORWARD = false; +constexpr bool REVERSE = true; + +// first bool mean if vertical, second bool mean if reverse +// false, false --> RIGHT +// false, true --> LEFT +// true, false --> DOWN +// true, true ---> UP +// This map will adapter the WaterFlow FlexDirection with Key Direction. +const std::map>> DIRECTION_MAP = { + { false, // RTL is false + { { HORIZONTAL, { { FORWARD, KeyDirection::RIGHT }, { REVERSE, KeyDirection::LEFT } } }, + { VERTICAL, { { FORWARD, KeyDirection::DOWN }, { REVERSE, KeyDirection::UP } } } } }, + { true, // RTL is true + { { HORIZONTAL, { { FORWARD, KeyDirection::LEFT }, { REVERSE, KeyDirection::RIGHT } } }, + { VERTICAL, { { FORWARD, KeyDirection::DOWN }, { REVERSE, KeyDirection::UP } } } } } +}; +} // namespace + +std::string WaterFlowEventInfo::ToJSONString() const +{ + return std::string("\"waterflow\",{\"first\":").append(std::to_string(scrollIndex_)).append("},null"); +} + +RenderWaterFlow::~RenderWaterFlow() +{ + if (scrollBarProxy_) { + scrollBarProxy_->UnRegisterScrollableNode(AceType::WeakClaim(this)); + } +} + +void RenderWaterFlow::Update(const RefPtr& component) +{ + InitScrollBar(component); + if (!NeedUpdate(component)) { + return; + } + + startRankItemIndex_ = 0; + currentItemIndex_ = 0; + const RefPtr flow = AceType::DynamicCast(component); + if (!flow) { + LOGE("RenderWaterFlow update failed."); + EventReport::SendRenderException(RenderExcepType::RENDER_COMPONENT_ERR); + return; + } + + isVertical_ = true; + updateFlag_ = true; + direction_ = flow->GetDirection(); + userColGap_ = flow->GetColumnsGap(); + userRowGap_ = flow->GetRowsGap(); + userMainLength_ = flow->GetMainLength(); + scrollBarProxy_ = flow->GetScrollBarProxy(); + crossCount_ = flow->GetCrossSplice(); + if (direction_ == FlexDirection::COLUMN || direction_ == FlexDirection::COLUMN_REVERSE) { + mainGap_ = NormalizePercentToPx(userRowGap_, true); + crossGap_ = NormalizePercentToPx(userColGap_, false); + useScrollable_ = SCROLLABLE::VERTICAL; + } else { + crossGap_ = NormalizePercentToPx(userRowGap_, true); + mainGap_ = NormalizePercentToPx(userColGap_, false); + useScrollable_ = SCROLLABLE::HORIZONTAL; + } + + InitScrollBarProxy(); + CreateScrollable(); + MarkNeedLayout(); + LOGD("%{public}s mainCount_:%{public}d crossCount_:%{public}d mainGap_:%{public}f " + "crossGap_:%{public}f", + __PRETTY_FUNCTION__, mainCount_, crossCount_, mainGap_, crossGap_); +} + +void RenderWaterFlow::CalAndPosItems(double& drawLength, int32_t& main) +{ + for (; main < mainCount_; main++) { + for (int32_t cross = 0; cross < crossCount_; cross++) { + auto mainIter = flowMatrix_.find(main); + if (mainIter == flowMatrix_.end()) { + LOGD("PerformLayout. main: %{public}d. skip flowMatrix_", main); + continue; + } + auto crossIter = mainIter->second.find(cross); + if (crossIter == mainIter->second.end()) { + LOGD("PerformLayout. main: %{public}d, cross: %{public}d. skip flowMatrix_", main, cross); + continue; + } + if (buildChildByIndex_ && (inCache_.count(main) == 0 || !CheckMainFull(main))) { + bool vail = false; + SupplyItems(vail, main); + } + if (showItem_.count(crossIter->second) != 0) { + continue; + } + + showItem_.insert(crossIter->second); + CheckAndInsertItems(main, crossIter->second); + auto item = items_.find(crossIter->second); + if (item != items_.end()) { + childrenInRect_.push_back(item->second); + int32_t itemMainSpan = GetItemSpan(item->second, useScrollable_ != SCROLLABLE::HORIZONTAL); + int32_t itemCrosspan = GetItemSpan(item->second, useScrollable_ == SCROLLABLE::HORIZONTAL); + int32_t itemMain = GetItemMainIndex(crossIter->second); + LOGD("PerformLayout. marix_ss itemInfo. itemindex:%{public}d, row:%{public}d, col:%{public}d, " + "rowSpan:%{public}d," + "colSpan:%{public}d.", + crossIter->second, itemMain, cross, itemMainSpan, itemCrosspan); + SetChildPosition(item->second, itemMain, cross, itemMainSpan, itemCrosspan); + } + } + if (main >= startIndex_) { + drawLength += GetSize(flowCells_) + mainGap_; + } + if (GreatOrEqual(drawLength, mainSize_)) { + break; + } + } +} + +void RenderWaterFlow::PerformLayout() +{ + if (RenderNode::GetChildren().empty() && !buildChildByIndex_) { + return; + } + + // calulate rowSize colSize mainLength + if (direction_ == FlexDirection::COLUMN || direction_ == FlexDirection::COLUMN_REVERSE) { + mainSize_ = GetLayoutParam().GetMaxSize().Height(); + crossSize_ = GetLayoutParam().GetMaxSize().Width(); + if (NearEqual(mainSize_, Size::INFINITE_SIZE)) { + mainSize_ = viewPort_.Height(); + } + if (NearEqual(crossSize_, Size::INFINITE_SIZE)) { + crossSize_ = viewPort_.Width(); + } + } else { + crossSize_ = GetLayoutParam().GetMaxSize().Height(); + mainSize_ = GetLayoutParam().GetMaxSize().Width(); + if (NearEqual(crossSize_, Size::INFINITE_SIZE)) { + crossSize_ = viewPort_.Height(); + } + if (NearEqual(mainSize_, Size::INFINITE_SIZE)) { + mainSize_ = viewPort_.Width(); + } + } + mainLength_ = NormalizePercentToPx(userMainLength_, true); + if (NearZero(mainLength_)) { + mainLength_ = ParseCrossLength(crossSize_, crossGap_).at(0); + } + + InitialFlowProp(); + CaculateViewPort(); + showItem_.clear(); + childrenInRect_.clear(); + double drawLength = 0.0 - firstItemOffset_; + int32_t main = startIndex_ > 0 ? startIndex_ - 1 : startIndex_; + LOGD("PerformLayout. main: %{public}d. start", main); + CalAndPosItems(drawLength, main); + SetLayoutSize(GetLayoutParam().Constrain(Size(crossSize_, mainSize_))); + endIndex_ = main; + MarkNeedPredictLayout(); + CalculateWholeSize(drawLength); + lastOffset_ = startMainPos_ + firstItemOffset_ - currentOffset_; + LOGD("PerformLayout. offset_ss lastOffset_:%{public}lf, startMainPos_:%{public}lf, firstItemOffset_:%{public}lf," + "currentOffset_:%{public}lf", + lastOffset_, startMainPos_, firstItemOffset_, currentOffset_); + LOGD("PerformLayout. offset_ss mainCount_:%{public}d", mainCount_); +} + +bool RenderWaterFlow::NeedUpdate(const RefPtr& component) +{ + const RefPtr flow = AceType::DynamicCast(component); + if (!flow) { + LOGE("RenderWaterFlow update failed."); + EventReport::SendRenderException(RenderExcepType::RENDER_COMPONENT_ERR); + return false; + } + auto controller = flow->GetController(); + if (controller) { + controller->SetScrollNode(WeakClaim(this)); + } + if (!animator_) { + animator_ = AceType::MakeRefPtr(GetContext()); + } + + if (direction_ != flow->GetDirection() || crossAxisAlign_ != flow->GetFlexAlign() || + userColGap_ != flow->GetColumnsGap() || userRowGap_ != flow->GetRowsGap() || + rightToLeft_ != flow->GetRightToLeft()) { + return true; + }; + return false; +} + +void RenderWaterFlow::AddChildByIndex(int32_t index, const RefPtr& renderNode) +{ + auto iter = items_.find(index); + if (iter != items_.end() && iter->second == nullptr) { + items_.erase(index); + itemSpanCache_.erase(index); + } + auto itor = items_.try_emplace(index, renderNode); + if (itor.second) { + AddChild(renderNode); + SetItemCalSizeNeeded(renderNode, true); + RefPtr node = AceType::DynamicCast(renderNode); + if (node) { + node->SetBoundary(); + node->SetIndex(index); + node->SetHidden(false); + } + Span span; + span.rowSpan = node->GetRowSpan(); + span.colSpan = node->GetColumnSpan(); + itemSpanCache_.emplace(std::make_pair(index, span)); + } +} + +void RenderWaterFlow::CreateScrollable() +{ + scrollable_ = nullptr; + if (useScrollable_ == SCROLLABLE::NO_SCROLL) { + return; + } + + auto callback = [weak = AceType::WeakClaim(this)](double offset, int32_t source) { + auto flow = weak.Upgrade(); + if (!flow) { + return false; + } + // Stop animator of scroll bar. + auto scrollBarProxy = flow->scrollBarProxy_; + if (scrollBarProxy) { + scrollBarProxy->StopScrollBarAnimator(); + } + return flow->UpdateScrollPosition(offset, source); + }; + scrollable_ = AceType::MakeRefPtr( + callback, useScrollable_ == SCROLLABLE::HORIZONTAL ? Axis::HORIZONTAL : Axis::VERTICAL); + scrollable_->SetScrollEndCallback([weak = AceType::WeakClaim(this)]() { + auto flow = weak.Upgrade(); + if (flow) { + auto proxy = flow->scrollBarProxy_; + if (proxy) { + proxy->StartScrollBarAnimator(); + } + } + }); + scrollable_->Initialize(context_); +} + +bool RenderWaterFlow::UpdateScrollPosition(double offset, int32_t source) +{ + if (source == SCROLL_FROM_START) { + return true; + } + + if (NearZero(offset)) { + return true; + } + if (scrollBar_ && scrollBar_->NeedScrollBar()) { + scrollBar_->SetActive(SCROLL_FROM_CHILD != source); + } + + if (reachHead_ && reachTail_) { + return false; + } + + if (offset > 0.0) { + if (reachHead_) { + return false; + } + reachTail_ = false; + } else { + if (reachTail_) { + return false; + } + reachHead_ = false; + } + + currentOffset_ += Round(offset); + MarkNeedLayout(true); + return true; +} + +void RenderWaterFlow::OnTouchTestHit( + const Offset& coordinateOffset, const TouchRestrict& touchRestrict, TouchTestResult& result) +{ + if (!GetVisible()) { + return; + } + if (!scrollable_ || !scrollable_->Available()) { + return; + } + if (scrollBar_ && scrollBar_->InBarRegion(globalPoint_ - coordinateOffset)) { + scrollBar_->AddScrollBarController(coordinateOffset, result); + } else { + scrollable_->SetCoordinateOffset(coordinateOffset); + scrollable_->SetDragTouchRestrict(touchRestrict); + result.emplace_back(scrollable_); + } + result.emplace_back(scrollable_); +} + +bool RenderWaterFlow::IsChildrenTouchEnable() +{ + bool ret = scrollable_->IsMotionStop(); + return ret; +} + +void RenderWaterFlow::SetChildPosition( + const RefPtr& child, int32_t main, int32_t cross, int32_t mainSpan, int32_t crossSpan) +{ + // Calculate the position for current child. + double positionMain = 0.0; + double positionCross = 0.0; + if (main < startIndex_) { + positionMain -= GetSize(flowCells_) * (startIndex_ - main); + positionMain += (main - startIndex_) * mainGap_; + } else { + positionMain += GetSize(flowCells_) * (main - startIndex_); + positionMain += (main - startIndex_) * mainGap_; + } + + positionCross += GetSize(flowCells_, false) * cross; + positionCross += cross * crossGap_; + + // Calculate the size for current child. + double mainLen = 0.0; + double crossLen = 0.0; + mainLen += GetSize(flowCells_) * mainSpan; + mainLen += (mainSpan - 1) * mainGap_; + crossLen += GetSize(flowCells_, false) * crossSpan; + crossLen += (crossSpan - 1) * crossGap_; + + // If RTL, place the item from right. + if (rightToLeft_) { + if (useScrollable_ != SCROLLABLE::HORIZONTAL) { + positionCross = crossSize_ - positionCross - crossLen; + } + } + + double mainOffset = (mainLen - GetSize(child->GetLayoutSize())) / 2.0; + double crosstOffset = (crossLen - GetSize(child->GetLayoutSize(), false)) / 2.0; + + Offset offset; + if (useScrollable_ != SCROLLABLE::HORIZONTAL) { + offset = Offset(positionCross + crosstOffset, positionMain + mainOffset - firstItemOffset_); + } else { + offset = Offset(positionMain + mainOffset - firstItemOffset_, positionCross + crosstOffset); + } + + child->SetPosition(offset); +} + +double RenderWaterFlow::GetSize(const Size& src, bool isMain) const +{ + if (useScrollable_ == SCROLLABLE::HORIZONTAL) { + return isMain ? src.Width() : src.Height(); + } + + return isMain ? src.Height() : src.Width(); +} + +bool RenderWaterFlow::GetFlowSize() +{ + double rowSize = ((flowHeight_ > 0.0) && (flowHeight_ < GetLayoutParam().GetMaxSize().Height())) + ? flowHeight_ + : GetLayoutParam().GetMaxSize().Height(); + double colSize = ((flowWidth_ > 0.0) && (flowWidth_ < GetLayoutParam().GetMaxSize().Width())) + ? flowWidth_ + : GetLayoutParam().GetMaxSize().Width(); + if (direction_ == FlexDirection::COLUMN || direction_ == FlexDirection::COLUMN_REVERSE) { + useScrollable_ = SCROLLABLE::VERTICAL; + if (NearEqual(mainSize_, Size::INFINITE_SIZE)) { + mainSize_ = viewPort_.Height(); + } + if (NearEqual(crossSize_, Size::INFINITE_SIZE)) { + crossSize_ = viewPort_.Width(); + } + LOGD("GetFlowSize %lf, %lf [%lf- %lf]", rowSize, colSize, mainSize_, crossSize_); + if (rowSize != mainSize_ || colSize != crossSize_) { + mainSize_ = rowSize; + crossSize_ = colSize; + CreateScrollable(); + return true; + } + } else { + useScrollable_ = SCROLLABLE::HORIZONTAL; + if (NearEqual(mainSize_, Size::INFINITE_SIZE)) { + mainSize_ = viewPort_.Width(); + } + if (NearEqual(crossSize_, Size::INFINITE_SIZE)) { + crossSize_ = viewPort_.Height(); + } + LOGD("GetFlowSize %lf, %lf [%lf- %lf]", rowSize, colSize, mainSize_, crossSize_); + if (rowSize != crossSize_ || colSize != mainSize_) { + crossSize_ = rowSize; + mainSize_ = colSize; + CreateScrollable(); + return true; + } + } + return false; +} + +void RenderWaterFlow::BuildFlow(std::vector& cross) +{ + cross = ParseCrossLength(crossSize_, crossGap_); + if (useScrollable_ == SCROLLABLE::VERTICAL) { + flowCells_ = Size(cross.at(0), mainLength_); + } else if (useScrollable_ == SCROLLABLE::HORIZONTAL) { + flowCells_ = Size(mainLength_, cross.at(0)); + } +} + +void RenderWaterFlow::CallGap() +{ + if (direction_ == FlexDirection::COLUMN || direction_ == FlexDirection::COLUMN_REVERSE) { + mainGap_ = NormalizePercentToPx(userRowGap_, true); + crossGap_ = NormalizePercentToPx(userColGap_, false); + } else { + crossGap_ = NormalizePercentToPx(userRowGap_, true); + mainGap_ = NormalizePercentToPx(userColGap_, false); + } +} + +void RenderWaterFlow::InitialFlowProp() +{ + // Not first time layout after update, no need to initial. + if (!GetFlowSize() && !updateFlag_) { + return; + } + ACE_SCOPED_TRACE("InitialFlowProp"); + OnDataSourceUpdated(-1); + CallGap(); + std::vector cross; + BuildFlow(cross); + // Initialize the columnCount and rowCount, default is 1 + crossCount_ = cross.size(); + mainCount_ = 0; + UpdateAccessibilityAttr(); + + if (!buildChildByIndex_) { + LOGE("%{public}s. buildChildByIndex_ is null.", __PRETTY_FUNCTION__); + return; + } + + int32_t endIndex = -1; + mainCount_ = GetItemMainIndex(startRankItemIndex_); + if (mainCount_ < 0) { + mainCount_ = 0; + } + while (endIndex < currentItemIndex_) { + Rank(mainCount_, startRankItemIndex_); + mainCount_++; + auto mainItor = flowMatrix_.find(mainCount_ - 1); + if (mainItor == flowMatrix_.end()) { + break; + } + for (int32_t crossIndex = crossCount_ - 1; crossIndex >= 0; crossIndex--) { + auto iter = mainItor->second.find(crossIndex); + if (iter != mainItor->second.end()) { + endIndex = iter->second; + break; + } + } + } + startRankItemIndex_ = 0; + currentItemIndex_ = 0; + bool vail = false; + SupplyItems(vail, mainCount_ > 0 ? mainCount_ - 1 : 0); + startIndex_ = mainCount_ > 0 ? mainCount_ - 1 : 0; + if (NearZero(currentOffset_)) { + needCalculateViewPort_ = true; + } + + updateFlag_ = false; + if (firstLineToBottom_ && firstLineToBottom_.value()) { + // calculate the distance from the first line to the last line + currentOffset_ = mainSize_ - GetSize(flowCells_); + needCalculateViewPort_ = false; + } + firstLineToBottom_ = std::nullopt; +} + +double RenderWaterFlow::BuildLazyFlowLayout(int32_t index, double sizeNeed) +{ + if (!buildChildByIndex_ || index < 0 || NearZero(sizeNeed)) { + return 0.0; + } + double size = 0.0; + int32_t startIndex = index; + while (size < sizeNeed) { + bool vail = false; + auto suppleSize = SupplyItems(vail, startIndex); + if (NearZero(suppleSize)) { + break; + } + mainCount_ = ++startIndex; + size += suppleSize + mainGap_; + } + return size; +} + +void RenderWaterFlow::CalculateCrossSpan( + int32_t mainIndex, int32_t cross, int32_t crossSpan, int32_t& calculateCrossSpan) +{ + auto mainIter = flowMatrix_.find(mainIndex); + if (mainIter != flowMatrix_.end()) { + int32_t tempCrossSpan = 0; + for (int32_t j = 0; j < crossSpan; j++) { + if ((mainIter->second.find(j + cross) == mainIter->second.end()) && (crossCount_ > (j + cross))) { + tempCrossSpan = j + 1; + } else if (tempCrossSpan > 0) { + break; + } + } + if ((calculateCrossSpan == 0) || (calculateCrossSpan >= tempCrossSpan)) { + calculateCrossSpan = tempCrossSpan; + } + } else { + // check if the first flowitem's crossSpan of the row is large then crossCount_ + if (crossCount_ < crossSpan && calculateCrossSpan == 0) { + calculateCrossSpan = crossCount_; + } + } +} + +bool RenderWaterFlow::CheckFlowPlaced(int32_t index, int32_t main, int32_t cross, int32_t& mainSpan, int32_t& crossSpan) +{ + auto mainIter = flowMatrix_.find(main); + if (mainIter != flowMatrix_.end()) { + auto crossIter = mainIter->second.find(cross); + if (crossIter != mainIter->second.end()) { + return false; + } + } + int32_t calculateCrossSpan = 0; + for (int32_t i = 0; i < mainSpan; i++) { + CalculateCrossSpan(i + main, cross, crossSpan, calculateCrossSpan); + } + if ((calculateCrossSpan != 0) && (calculateCrossSpan != crossSpan)) { + auto iter = itemSpanCache_.find(index); + if (iter != itemSpanCache_.end()) { + itemSpanCache_.erase(index); + } + Span span; + span.rowSpan = mainSpan; + span.colSpan = calculateCrossSpan; + itemSpanCache_.emplace(std::make_pair(index, span)); + crossSpan = calculateCrossSpan; + } + + for (int32_t i = main; i < main + mainSpan; ++i) { + std::map mainMap; + auto iter = flowMatrix_.find(i); + if (iter != flowMatrix_.end()) { + mainMap = iter->second; + } + for (int32_t j = cross; j < cross + crossSpan; ++j) { + mainMap.emplace(std::make_pair(j, index)); + } + flowMatrix_[i] = mainMap; + } + + std::map flowMap; + auto iterFlow = flowMatrixByIndex_.find(index); + if (iterFlow != flowMatrixByIndex_.end()) { + flowMap = iterFlow->second; + } + for (int32_t i = main; i < main + mainSpan; ++i) { + for (int32_t j = cross; j < cross + crossSpan; ++j) { + flowMap.emplace(std::make_pair(i, j)); + } + } + flowMatrixByIndex_[index] = flowMap; + + LOGD("CheckFlowPlaced done %{public}d %{public}d %{public}d %{public}d %{public}d", index, main, cross, mainSpan, + crossSpan); + return true; +} + +void RenderWaterFlow::LayoutChild(const RefPtr& child, int32_t main, int32_t cross, int32_t mainSpan, + int32_t crossSpan, bool needPosition) +{ + child->Layout(MakeInnerLayoutParam(main, cross, mainSpan, crossSpan)); + SetItemCalSizeNeeded(child, false); + + if (!needPosition) { + return; + } + if (useScrollable_ != SCROLLABLE::HORIZONTAL) { + child->SetPosition(Offset(0, mainSize_ + mainGap_)); + } else { + child->SetPosition(Offset(mainSize_ + mainGap_, 0)); + } +} + +void RenderWaterFlow::GetNextFlow(int32_t& curMain, int32_t& curCross) const +{ + ++curCross; + if (curCross >= crossCount_) { + curCross = 0; + ++curMain; + } +} + +void RenderWaterFlow::GetPreviousFlow(int32_t& curMain, int32_t& curCross) +{ + --curCross; + if (curCross < 0) { + curCross = crossCount_; + --curMain; + } +} + +LayoutParam RenderWaterFlow::MakeInnerLayoutParam( + int32_t main, int32_t cross, int32_t mainSpan, int32_t crossSpan) const +{ + LayoutParam innerLayout; + double mainLen = 0.0; + double crossLen = 0.0; + mainLen += GetSize(flowCells_) * mainSpan; + mainLen += (mainSpan - 1) * mainGap_; + + crossLen += GetSize(flowCells_, false) * crossSpan; + crossLen += (crossSpan - 1) * crossGap_; + + Size size; + LOGD("mainLen: %{public}lf", mainLen); + if (useScrollable_ == SCROLLABLE::HORIZONTAL) { + size = Size(mainLen, crossLen); + } else { + size = Size(crossLen, mainLen); + } + if (crossAxisAlign_ == FlexAlign::STRETCH) { + innerLayout.SetMinSize(size); + innerLayout.SetMaxSize(size); + } else { + innerLayout.SetMaxSize(size); + innerLayout.SetMinSize(size); + } + return innerLayout; +} + +void RenderWaterFlow::LoadForward() +{ + auto firstItem = 0; + decltype(flowMatrix_) flowMatrix(std::move(flowMatrix_)); + + int32_t count = 0; + int32_t endIndex = -1; + while (endIndex < startRankItemIndex_ - 1) { + if (!Rank(count, count == 0 ? firstItem : -1)) { + break; + } + count++; + auto mainItor = flowMatrix_.find(count - 1); + if (mainItor == flowMatrix_.end()) { + break; + } + for (int32_t cross = crossCount_ - 1; cross >= 0; cross--) { + auto iter = mainItor->second.find(cross); + if (iter != mainItor->second.end()) { + endIndex = iter->second; + break; + } + } + } + startRankItemIndex_ = firstItem; + if (count == 0) { + return; + } + for (const auto& item : flowMatrix) { + flowMatrix_[item.first + count] = item.second; + } + + decltype(inCache_) inCache(std::move(inCache_)); + for (const auto& item : inCache) { + LOGD("LoadForward inCache_.insert mainIndex: %{public}d.", item + count); + inCache_.insert(item + count); + } + + mainCount_ += count; + startIndex_ += count; +} + +void RenderWaterFlow::CaculateViewPortSceneOne() +{ + // move to top/left of first row/column + if (!NearZero(firstItemOffset_)) { + if (inCache_.find(startIndex_ + 1) != inCache_.end()) { + currentOffset_ += GetSize(flowCells_) + mainGap_ - firstItemOffset_; + startIndex_++; + } + firstItemOffset_ = 0.0; + } + // Move up + while (currentOffset_ > 0) { + if (startIndex_ > 0) { + currentOffset_ -= GetSize(flowCells_) + mainGap_; + startIndex_--; + } + if (startIndex_ == 0 && startRankItemIndex_ > 0 && currentOffset_ > 0) { + LoadForward(); + } + if (startIndex_ == 0) { + break; + } + } + if (currentOffset_ < 0) { + firstItemOffset_ -= currentOffset_; + } else { + if (startIndex_ == 0) { + reachHead_ = true; + } + } + currentOffset_ = 0.0; +} + +bool RenderWaterFlow::CaculateViewPortSceneTwo(bool& NeedContinue) +{ + NeedContinue = false; + if (!NearZero(firstItemOffset_)) { + currentOffset_ -= firstItemOffset_; + firstItemOffset_ = 0.0; + } + // Move down + while (startIndex_ < mainCount_ && (currentOffset_ < 0 || needCalculateViewPort_)) { + currentOffset_ += GetSize(flowCells_) + mainGap_; + startIndex_++; + } + needCalculateViewPort_ = false; + if (currentOffset_ > 0) { + firstItemOffset_ = GetSize(flowCells_) + mainGap_ - currentOffset_; + currentOffset_ = 0.0; + startIndex_--; + } else if (!GreatOrEqual(0.0, BuildLazyFlowLayout(mainCount_, -currentOffset_))) { + NeedContinue = true; + return true; + } + currentOffset_ = 0.0; + auto blank = CalculateBlankOfEnd(); + if (GreatOrEqual(0.0, blank)) { + return false; + } + // request new item. + blank -= BuildLazyFlowLayout(mainCount_, blank); + if (blank <= 0) { + return false; + } + blank = blank - firstItemOffset_; + firstItemOffset_ = 0; + // Move up + while (blank > 0) { + if (startIndex_ == 0 && startRankItemIndex_ > 0) { + LoadForward(); + } + if (startIndex_ == 0) { + break; + } + if (inCache_.find(startIndex_ - 1) == inCache_.end()) { + bool vail = false; + SupplyItems(vail, startIndex_ - 1); + } + blank -= GetSize(flowCells_) + mainGap_; + startIndex_--; + } + firstItemOffset_ -= blank; + if (firstItemOffset_ < 0) { + firstItemOffset_ = 0; + } + reachTail_ = true; + return true; +} + +void RenderWaterFlow::CaculateViewPort() +{ + while (!NearZero(currentOffset_) || needCalculateViewPort_) { + if (currentOffset_ > 0) { + CaculateViewPortSceneOne(); + } else { + bool needSkip = false; + if (!CaculateViewPortSceneTwo(needSkip)) { + return; + } + if (needSkip) { + continue; + } + } + } +} + +double RenderWaterFlow::CalculateBlankOfEnd() +{ + double drawLength = 0.0 - firstItemOffset_; + for (int32_t main = startIndex_; main < mainCount_; main++) { + drawLength += GetSize(flowCells_) + mainGap_; + if (GreatOrEqual(drawLength, mainSize_)) { + break; + } + } + return mainSize_ - drawLength; +} + +bool RenderWaterFlow::CheckMainFull(int32_t mainIndex) +{ + auto mainItor = flowMatrix_.find(mainIndex); + if (mainItor == flowMatrix_.end()) { + return false; + } + + if (mainItor->second.size() < crossCount_) { + return false; + } + + return true; +} + +double RenderWaterFlow::SupplyItems( + bool& vailSupplyItem, int32_t mainIndex, int32_t itemIndex, bool needPosition, bool needRank) +{ + LOGD("%{public}s called mainIndex: %{public}d.", __PRETTY_FUNCTION__, mainIndex); + loadingIndex_ = -1; + ACE_SCOPED_TRACE("SupplyItems %d", mainIndex); + auto mainItor = flowMatrix_.find(mainIndex); + if (mainItor != flowMatrix_.end()) { + if (mainItor->second.size() == crossCount_) { + needRank = false; + } + } + + if ((inCache_.find(mainIndex) == inCache_.end() || !CheckMainFull(mainIndex)) && (mainIndex != 0) && needRank) { + Rank(mainIndex, itemIndex); + } + + vailSupplyItem = false; + + auto iter = flowMatrix_.find(mainIndex); + if (iter != flowMatrix_.end()) { + int32_t frontIndex = -1; + for (const auto& item : iter->second) { + if (item.second == frontIndex) { + continue; + } + if (((items_.find(item.second) != items_.end() && items_[item.second] != nullptr) || + buildChildByIndex_(item.second)) && + GetItemCalSizeNeeded(items_[item.second])) { + LOGD("SupplyItems resize() itemIndex: %{public}d", item.second); + int32_t itemRowSpan = GetItemSpan(items_[item.second], true); + int32_t itemColSpan = GetItemSpan(items_[item.second], false); + int32_t itemMain = -1; + int32_t itemCross = -1; + if (!GetItemMainCrossIndex(item.second, itemMain, itemCross)) { + itemMain = mainIndex; + itemCross = item.first; + } + if (useScrollable_ == SCROLLABLE::VERTICAL) { + LayoutChild(items_[item.second], itemMain, itemCross, itemRowSpan, itemColSpan, needPosition); + } else { + LayoutChild(items_[item.second], itemMain, itemCross, itemColSpan, itemRowSpan, needPosition); + } + vailSupplyItem = true; + } + frontIndex = item.second; + } + LOGD("SupplyItems inCache_.insert mainIndex: %{public}d.", mainIndex); + inCache_.insert(mainIndex); + return NearEqual(GetSize(flowCells_), Size::INFINITE_SIZE) ? 0.0 : GetSize(flowCells_); + } + return 0.0; +} + +int32_t RenderWaterFlow::CalItemIndexInRank(int32_t mainIndex) +{ + int32_t itemIndex = -1; + for (int32_t i = 1; (mainIndex - i) >= 0; i++) { + auto mainItor = flowMatrix_.find(mainIndex - i); + if (mainItor == flowMatrix_.end()) { + continue; + } + for (int32_t cross = crossCount_ - 1; cross >= 0; cross--) { + auto iter = mainItor->second.find(cross); + if (iter == mainItor->second.end()) { + continue; + } + if (itemIndex == -1) { + // fine the first itemIndex + itemIndex = iter->second + 1; + } else if (itemIndex <= iter->second + 1) { + // fine the max ID of itemIndex in the last line + itemIndex = iter->second + 1; + } + } + if (static_cast(mainItor->second.size()) == (crossCount_ - 1)) { + // search to the end, then the row of flowMatrix_ is all layouted + break; + } + } + return itemIndex; +} + +bool RenderWaterFlow::Rank(int32_t mainIndex, int32_t itemIndex) +{ + LOGD("%{public}s called. mainIndex:%{public}d itemIndex:%{public}d", __PRETTY_FUNCTION__, mainIndex, itemIndex); + + if (inCache_.find(mainIndex) != inCache_.end() && CheckMainFull(mainIndex)) { + return true; + } + ACE_SCOPED_TRACE("Rank [%d]", mainIndex); + + if (itemIndex == -1) { + itemIndex = CalItemIndexInRank(mainIndex); + } + + if (itemIndex == -1) { + LOGE("failed, itemIndex = -1, mainIndex = %d", mainIndex); + return false; + } + bool isFilled = false; + int32_t index = mainIndex; + int32_t crossIndex = 0; + bool placed = false; + while (!isFilled) { + int32_t itemMainSpan = -1; + int32_t itemCrossSpan = -1; + if (flowMatrixByIndex_.find(itemIndex) != flowMatrixByIndex_.end()) { + itemIndex++; + continue; + } + + if (!GetItemSpanFromCache(itemIndex, itemMainSpan, itemCrossSpan)) { + return false; + } + while (!CheckFlowPlaced(itemIndex, mainIndex, crossIndex, itemMainSpan, itemCrossSpan)) { + GetNextFlow(mainIndex, crossIndex); // crossIndex++ + if (mainIndex > index) { + isFilled = true; + break; + } + } + if (!isFilled) { + placed = true; + } + itemIndex++; + } + return true; +} + +void RenderWaterFlow::DealCache(int32_t start, int32_t end) +{ + if (loadingIndex_ != -1) { + return; + } + + std::set deleteItem; + for (const auto& item : inCache_) { + if (!(item < start - cacheCount_ || item > end + cacheCount_)) { + continue; + } + // check all item of inCache_ is in viewprot, if in viewprot the cacheCount_ cann't be delete + bool deleteEnable = true; + auto iter = flowMatrix_.find(item); + if (iter != flowMatrix_.end()) { + for (const auto& eachItem : iter->second) { + auto eachItemStartMain = GetItemMainIndex(eachItem.second); + if (items_[eachItem.second] == nullptr) { + continue; + } + auto eachItemEndMain = + eachItemStartMain + GetItemSpan(items_[eachItem.second], useScrollable_ != SCROLLABLE::HORIZONTAL); + if (!(eachItemEndMain < (start - cacheCount_) || eachItemStartMain > (end + cacheCount_))) { + deleteEnable = false; + break; + } + } + } + + if (deleteEnable) { + deleteItem.insert(item); + } + } + + for (const auto& item : deleteItem) { + DeleteItems(item, false); + } + LOGD("DealCache end: %{public}d, start: %{public}d", end, start); + for (int32_t i = 1; i <= cacheCount_; i++) { + if (inCache_.count(i + end) == 0 || !CheckMainFull(i + end)) { + loadingIndex_ = i + end; + LOGD("DealCache loadingIndex_: %{public}d.", loadingIndex_); + break; + } + if (start >= i && ((inCache_.count(start - i) == 0) || !CheckMainFull(start - i))) { + loadingIndex_ = start - i; + break; + } + } +} + +void RenderWaterFlow::DeleteItems(int32_t index, bool isTail) +{ + LOGD("%{public}s called. index: %{public}d", __PRETTY_FUNCTION__, index); + if (!deleteChildByIndex_) { + return; + } + + auto iter = flowMatrix_.find(index); + if (iter == flowMatrix_.end()) { + return; + } + for (const auto& item : iter->second) { + deleteChildByIndex_(item.second); + RemoveChildByIndex(item.second); + } + + inCache_.erase(index); +} + +void RenderWaterFlow::ClearLayout(int32_t index) +{ + currentOffset_ = 0.0; + showItem_.clear(); + childrenInRect_.clear(); + updateFlag_ = true; + reachHead_ = false; + reachTail_ = false; + startMainPos_ = 0.0; + endMainPos_ = 0.0; + firstItemOffset_ = 0.0; + endIndex_ = -1; + mainScrollExtent_ = 0.0; + lastOffset_ = 0.0; + estimateHeight_ = 0.0; + if (index > -1) { + int32_t main = GetItemMainIndex(index); + int32_t rows = flowMatrix_.size(); + DeleteItemsInMarix(rows, index); + for (auto it = inCache_.begin(); it != inCache_.end();) { + if (*it >= main) { + inCache_.erase(it++); + } else { + it++; + } + } + auto itFirst1 = itemSpanCache_.find(index); + if (itFirst1 != itemSpanCache_.end()) { + itemSpanCache_.erase(itFirst1, itemSpanCache_.end()); + } + auto itFirst3 = flowMatrixByIndex_.find(index); + if (itFirst3 != flowMatrixByIndex_.end()) { + flowMatrixByIndex_.erase(itFirst3, flowMatrixByIndex_.end()); + } + if (main <= startIndex_) { + startIndex_ = main; + } + } else { + startIndex_ = 0; + inCache_.clear(); + flowMatrix_.clear(); + flowMatrixByIndex_.clear(); + itemSpanCache_.clear(); + } +} + +void RenderWaterFlow::ClearItems(int32_t index) +{ + decltype(items_) items(std::move(items_)); + for (const auto& item : items) { + if (index <= item.first) { + deleteChildByIndex_(item.first); + RemoveChildByIndex(item.first); + } + } + loadingIndex_ = -1; +} + +int32_t RenderWaterFlow::GetItemMainIndex(int32_t index) const +{ + auto iter = flowMatrixByIndex_.find(index); + if (iter != flowMatrixByIndex_.end()) { + return iter->second.begin()->first; + } + return -1; +} + +bool RenderWaterFlow::GetItemMainCrossIndex(int32_t index, int32_t& mainIndex, int32_t& crossIndex) +{ + auto iter = flowMatrixByIndex_.find(index); + if (iter != flowMatrixByIndex_.end()) { + mainIndex = iter->second.begin()->first; + crossIndex = iter->second.begin()->second; + return true; + } + return false; +} + +void RenderWaterFlow::OnDataSourceUpdated(int32_t index) +{ + LOGD("OnDataSourceUpdated called. index:%{public}d", index); + if (items_.empty() && updateFlag_) { + return; + } + + ACE_SCOPED_TRACE("OnDataSourceUpdated %d", index); + auto items = flowMatrix_.find(startIndex_); + if (items != flowMatrix_.end() && items->second.size() > 0) { + currentItemIndex_ = items->second.begin()->second; + } + if (index >= 0) { + startRankItemIndex_ = index; + } else { + startRankItemIndex_ = 0; + } + auto offset = firstItemOffset_; + ClearItems(index); + ClearLayout(index); + currentOffset_ = -offset; + MarkNeedLayout(); +} + +bool RenderWaterFlow::CheckEndShowItemPlace(int32_t index) +{ + int32_t main = 0; + int32_t cross = 0; + if (!GetItemMainCrossIndex(index, main, cross)) { + return false; + } + int32_t itemMainSpan = GetItemSpan(items_[index], useScrollable_ != SCROLLABLE::HORIZONTAL); + int32_t mainIndex = main; + for (; mainIndex < (main + itemMainSpan); mainIndex++) { + auto items = flowMatrix_.find(mainIndex); + if (items == flowMatrix_.end()) { + return false; + } + if (items->second.size() < crossCount_) { + return true; + } + } + auto itemsNext = flowMatrix_.find(mainIndex); + if (itemsNext == flowMatrix_.end()) { + return true; + } + auto item = itemsNext->second.find(cross); + if (item == itemsNext->second.end()) { + return true; + } + return false; +} + +void RenderWaterFlow::CalculateWholeSize(double drawLength) +{ + if (flowMatrix_.empty()) { + return; + } + if (totalCountFlag_) { + int32_t lastRow = flowMatrix_.rbegin()->first; + int32_t totalRows = mainCount_; + lastRow++; + totalRows++; + if (lastRow > totalRows) { + totalRows = lastRow; + } + double drawLength2 = totalRows * mainLength_ + (totalRows - 1) * mainGap_; + if (lastRow <= totalRows && lastRow > 0) { + mainScrollExtent_ = (lastRow * drawLength2) / totalRows; + } + estimateHeight_ = mainScrollExtent_; + totalCountFlag_ = false; + } + bool isScrollable = false; + if (estimateHeight_ > mainSize_) { + isScrollable = true; + } + if (scrollBar_) { + scrollBar_->SetScrollable(isScrollable); + } + // get the start position in flow + LOGD("offset_ss startIndex_: %{public}d.", startIndex_); + startMainPos_ = GetSize(flowCells_) * (startIndex_) + mainGap_ * (startIndex_ - 1); + scrollBarExtent_ = GetSize(flowCells_) * (mainCount_) + mainGap_ * (mainCount_ - 1); + if (!isScrollable) { + currentOffset_ = 0.0; + } +} + +double RenderWaterFlow::GetEstimatedHeight() +{ + if (reachTail_) { + // reach the end og flow, update the total scroll bar length + estimateHeight_ = scrollBarExtent_; + } else { + estimateHeight_ = std::max(estimateHeight_, scrollBarExtent_); + } + return estimateHeight_; +} + +void RenderWaterFlow::InitScrollBar(const RefPtr& component) +{ + const RefPtr flow = AceType::DynamicCast(component); + if (!flow) { + LOGE("RenderWaterFlow update failed."); + EventReport::SendRenderException(RenderExcepType::RENDER_COMPONENT_ERR); + return; + } + + if (!flow->GetController()) { + flow->SetScrollBarDisplayMode(DisplayMode::OFF); + } + + const RefPtr theme = GetTheme(); + if (!theme) { + return; + } + if (scrollBar_) { + scrollBar_->Reset(); + } else { + RefPtr controller = AceType::MakeRefPtr(); + scrollBar_ = AceType::MakeRefPtr(flow->GetScrollBarDisplayMode(), theme->GetShapeMode()); + scrollBar_->SetScrollBarController(controller); + } + // set the scroll bar style + scrollBar_->SetReservedHeight(theme->GetReservedHeight()); + scrollBar_->SetMinHeight(theme->GetMinHeight()); + scrollBar_->SetMinDynamicHeight(theme->GetMinDynamicHeight()); + auto& scrollBarColor = flow->GetScrollBarColor(); + if (!scrollBarColor.empty()) { + scrollBarColor_ = Color::FromString(scrollBarColor); + } else { + scrollBarColor_ = theme->GetForegroundColor(); + } + scrollBar_->SetForegroundColor(scrollBarColor_); + scrollBar_->SetBackgroundColor(theme->GetBackgroundColor()); + scrollBar_->SetPadding(theme->GetPadding()); + scrollBar_->SetScrollable(true); + if (!flow->GetScrollBarWidth().empty()) { + const auto& width = StringUtils::StringToDimension(flow->GetScrollBarWidth()); + scrollBar_->SetInactiveWidth(width); + scrollBar_->SetNormalWidth(width); + scrollBar_->SetActiveWidth(width); + scrollBar_->SetTouchWidth(width); + } else { + scrollBar_->SetInactiveWidth(theme->GetNormalWidth()); + scrollBar_->SetNormalWidth(theme->GetNormalWidth()); + scrollBar_->SetActiveWidth(theme->GetActiveWidth()); + scrollBar_->SetTouchWidth(theme->GetTouchWidth()); + } + scrollBar_->InitScrollBar(AceType::WeakClaim(this), GetContext()); + SetScrollBarCallback(); +} + +void RenderWaterFlow::InitScrollBarProxy() +{ + if (!scrollBarProxy_) { + return; + } + auto&& scrollCallback = [weakScroll = AceType::WeakClaim(this)](double value, int32_t source) { + auto flow = weakScroll.Upgrade(); + if (!flow) { + LOGE("render flow is released"); + return false; + } + return flow->UpdateScrollPosition(value, source); + }; + scrollBarProxy_->UnRegisterScrollableNode(AceType::WeakClaim(this)); + scrollBarProxy_->RegisterScrollableNode({ AceType::WeakClaim(this), scrollCallback }); +} + +void RenderWaterFlow::SetScrollBarCallback() +{ + if (!scrollBar_ || !scrollBar_->NeedScrollBar()) { + return; + } + auto&& barEndCallback = [weakFlow = AceType::WeakClaim(this)](int32_t value) { + auto flow = weakFlow.Upgrade(); + if (!flow) { + LOGE("render flow is released"); + return; + } + flow->scrollBarOpacity_ = value; + flow->MarkNeedLayout(true); + }; + auto&& scrollEndCallback = [weakFlow = AceType::WeakClaim(this)]() { + auto flow = weakFlow.Upgrade(); + if (!flow) { + LOGE("render flow is released"); + return; + } + LOGD("trigger scroll end callback"); + }; + auto&& scrollCallback = [weakScroll = AceType::WeakClaim(this)](double value, int32_t source) { + auto flow = weakScroll.Upgrade(); + if (!flow) { + LOGE("render flow is released"); + return false; + } + return flow->UpdateScrollPosition(value, source); + }; + scrollBar_->SetCallBack(scrollCallback, barEndCallback, scrollEndCallback); +} + +bool RenderWaterFlow::AnimateTo(const Dimension& position, float duration, const RefPtr& curve) +{ + if (!animator_->IsStopped()) { + animator_->Stop(); + } + animator_->ClearInterpolators(); + animateDelta_ = 0.0; + auto animation = AceType::MakeRefPtr>(GetCurrentOffset(), NormalizeToPx(position), curve); + animation->AddListener([weakScroll = AceType::WeakClaim(this)](double value) { + auto scroll = weakScroll.Upgrade(); + if (scroll) { + scroll->DoJump(value, SCROLL_FROM_JUMP); + } + }); + animator_->AddInterpolator(animation); + animator_->SetDuration(duration); + animator_->ClearStopListeners(); + animator_->AddStopListener([weakScroll = AceType::WeakClaim(this)]() { + auto scroll = weakScroll.Upgrade(); + if (scroll) { + scroll->animateDelta_ = 0.0; + } + }); + animator_->Play(); + return true; +} + +Offset RenderWaterFlow::CurrentOffset() +{ + auto ctx = GetContext().Upgrade(); + if (!ctx) { + return useScrollable_ == SCROLLABLE::HORIZONTAL ? Offset(GetCurrentOffset(), 0.0) + : Offset(0.0, GetCurrentOffset()); + } + auto mainOffset = ctx->ConvertPxToVp(Dimension(GetCurrentOffset(), DimensionUnit::PX)); + Offset currentOffset = useScrollable_ == SCROLLABLE::HORIZONTAL ? Offset(mainOffset, 0.0) : Offset(0.0, mainOffset); + return currentOffset; +} + +void RenderWaterFlow::ScrollToEdge(OHOS::Ace::ScrollEdgeType edgeType, bool smooth) +{ + if (edgeType != ScrollEdgeType::SCROLL_TOP) { + LOGW("Not supported yet"); + return; + } + if (items_.empty() && updateFlag_) { + return; + } + if (scrollable_ && !scrollable_->IsStopped()) { + scrollable_->StopScrollable(); + } + currentItemIndex_ = 0; + startRankItemIndex_ = 0; + ClearItems(); + ClearLayout(); + MarkNeedLayout(); +} + +void RenderWaterFlow::DoJump(double position, int32_t source) +{ + double delta = position - animateDelta_; + UpdateScrollPosition(delta, source); + animateDelta_ = position; +} + +void RenderWaterFlow::OnPaintFinish() +{ + RenderNode::OnPaintFinish(); + if (showItem_.empty()) { + return; + } + auto currentStartItemCount = *showItem_.begin(); + auto currentEndItemCount = *showItem_.rbegin(); + if ((startShowItemIndex_ != currentStartItemCount) || (endShowItemIndex_ != currentEndItemCount)) { + startShowItemIndex_ = currentStartItemCount; + endShowItemIndex_ = currentEndItemCount; + } +} + +void RenderWaterFlow::OnPredictLayout(int64_t deadline) +{ + if (updateFlag_) { + return; + } + auto startTime = GetSysTimestamp(); // unit: ns + auto context = context_.Upgrade(); + if (!context) { + return; + } + if (!context->IsTransitionStop()) { + LOGD("In page transition, skip predict."); + return; + } + if (loadingIndex_ == -1) { + DealCache(startIndex_, endIndex_); + if (loadingIndex_ == -1) { + if (startIndex_ == 0 && startRankItemIndex_ > 0) { + LoadForward(); + MarkNeedPredictLayout(); + } + return; + } + } + LOGD("OnPredictLayout loadingIndex_: %{public}d.", loadingIndex_); + ACE_SCOPED_TRACE("OnPredictLayout %d", loadingIndex_); + if (GetSysTimestamp() - startTime + TIMETHRESHOLD > deadline * MICROSEC_TO_NANOSEC) { + MarkNeedPredictLayout(); + return; + } + bool vail = false; + SupplyItems(vail, loadingIndex_, -1); + if (vail) { + MarkNeedPredictLayout(); + } else { + loadingIndex_ = -1; + } +} + +bool RenderWaterFlow::IsAxisScrollable(AxisDirection direction) +{ + if (isVertical_) { + if (direction == AxisDirection::UP && reachHead_) { + return false; + } else if (direction == AxisDirection::DOWN && reachTail_) { + return false; + } else if (direction == AxisDirection::NONE) { + return false; + } + } else { + if (direction == AxisDirection::LEFT && reachHead_) { + return false; + } else if (direction == AxisDirection::RIGHT && reachTail_) { + return false; + } else if (direction == AxisDirection::NONE) { + return false; + } + } + return true; +} + +void RenderWaterFlow::HandleAxisEvent(const AxisEvent& event) +{ + double degree = 0.0f; + if (!NearZero(event.horizontalAxis)) { + degree = event.horizontalAxis; + } else if (!NearZero(event.verticalAxis)) { + degree = event.verticalAxis; + } + double offset = SystemProperties::Vp2Px(DP_PER_LINE_DESKTOP * LINE_NUMBER_DESKTOP * degree / MOUSE_WHEEL_DEGREES); + UpdateScrollPosition(-offset, SCROLL_FROM_ROTATE); +} + +WeakPtr RenderWaterFlow::CheckAxisNode() +{ + return AceType::WeakClaim(this); +} + +std::vector RenderWaterFlow::ParseCrossLength(double size, double gap) +{ + std::vector lens; + double crossLength = (size - (crossCount_ - 1) * gap) / crossCount_; + for (int32_t i = 0; i < crossCount_; i++) { + lens.push_back(crossLength); + } + + return lens; +} + +void RenderWaterFlow::OnChildAdded(const RefPtr& renderNode) +{ + RenderNode::OnChildAdded(renderNode); +} + +bool RenderWaterFlow::IsUseOnly() +{ + return true; +} + +int32_t RenderWaterFlow::RequestNextFocus(bool vertical, bool reverse) +{ + KeyDirection key = DIRECTION_MAP.at(rightToLeft_).at(vertical).at(reverse); + int32_t index = focusMove(key); + if (index < 0) { + return index; + } + return focusIndex_; +} + +void RenderWaterFlow::UpdateFocusInfo(int32_t focusIndex) +{ + if (focusIndex < 0) { + LOGW("Invalid focus index, update focus info failed."); + return; + } + if (focusIndex != focusIndex_) { + LOGD("Update focus index from %{public}d to %{public}d", focusIndex_, focusIndex); + focusIndex_ = focusIndex; + auto iter = flowMatrixByIndex_.find(focusIndex); + if (iter != flowMatrixByIndex_.end()) { + focusRow_ = iter->second.begin()->first; + focusCol_ = iter->second.begin()->second; + } + } +} + +int32_t RenderWaterFlow::GetItemSpan(const RefPtr& child, bool isRow) const +{ + int32_t depth = DEFAULT_DEPTH; + int32_t span = -1; + auto item = child; + auto flowItem = AceType::DynamicCast(item); + while (!flowItem && depth > 0) { + if (!item || item->GetChildren().empty()) { + return span; + } + item = item->GetChildren().front(); + flowItem = AceType::DynamicCast(item); + --depth; + } + if (flowItem) { + if (isRow) { + span = flowItem->GetRowSpan(); + } else { + auto crossItor = itemSpanCache_.find(GetIndexByNode(child)); + if (crossItor != itemSpanCache_.end()) { + span = crossItor->second.colSpan; + } else { + span = flowItem->GetColumnSpan(); + } + } + } + return span < 1 ? 1 : span; +} + +bool RenderWaterFlow::GetItemSpanFromCache(int32_t index, int32_t& rowSpan, int32_t& colSpan) +{ + auto itor = itemSpanCache_.find(index); + if (itor != itemSpanCache_.end()) { + rowSpan = itor->second.rowSpan; + colSpan = itor->second.colSpan; + } else { + auto item = items_.find(index); + if (item != items_.end()) { + rowSpan = GetItemSpan(item->second, useScrollable_ != SCROLLABLE::HORIZONTAL); + colSpan = GetItemSpan(item->second, useScrollable_ == SCROLLABLE::HORIZONTAL); + } else { + if (!getChildSpanByIndex_(index, useScrollable_ == SCROLLABLE::HORIZONTAL, rowSpan, colSpan)) { + return false; + } + } + Span span; + span.rowSpan = rowSpan; + span.colSpan = colSpan; + itemSpanCache_.emplace(std::make_pair(index, span)); + } + + return true; +} + +int32_t RenderWaterFlow::GetIndexByNode(const RefPtr& child) const +{ + for (const auto& item : items_) { + if (item.second == child) { + return item.first; + } + } + return -1; +} + +int32_t RenderWaterFlow::GetIndexByFlow(int32_t row, int32_t column) const +{ + LOGD("%{public}s begin. row: %{public}d, column: %{public}d", __PRETTY_FUNCTION__, row, column); + auto rowIter = flowMatrix_.find(row); + if (rowIter != flowMatrix_.end()) { + auto colIter = rowIter->second.find(column); + if (colIter != rowIter->second.end()) { + return colIter->second; + } + } + return -1; +} + +// Handle direction key move +int32_t RenderWaterFlow::focusMove(KeyDirection direction) +{ + int32_t nextRow = focusRow_ < 0 ? 0 : focusRow_; + int32_t nextCol = focusCol_ < 0 ? 0 : focusCol_; + int32_t next = focusIndex_; + while (focusIndex_ == next || next < 0) { + switch (direction) { + case KeyDirection::UP: + --nextRow; + break; + case KeyDirection::DOWN: + ++nextRow; + break; + case KeyDirection::LEFT: + --nextCol; + break; + case KeyDirection::RIGHT: + ++nextCol; + break; + default: + return -1; + } + if (direction_ == FlexDirection::COLUMN || direction_ == FlexDirection::COLUMN_REVERSE) { + if (nextRow < 0 || nextCol < 0 || nextRow >= mainCount_ || nextCol >= crossCount_) { + return -1; + } + } else { + if (nextRow < 0 || nextCol < 0 || nextRow >= crossCount_ || nextCol >= mainCount_) { + return -1; + } + } + + next = GetIndexByFlow(nextRow, nextCol); + } + LOGD("PreFocus:%{public}d CurrentFocus:%{public}d", focusIndex_, next); + focusRow_ = nextRow; + focusCol_ = nextCol; + focusIndex_ = next; + return next; +} + +void RenderWaterFlow::UpdateAccessibilityAttr() +{ + auto refPtr = accessibilityNode_.Upgrade(); + if (!refPtr) { + LOGD("accessibility node is not enabled."); + return; + } + auto collectionInfo = refPtr->GetCollectionInfo(); + if (direction_ == FlexDirection::COLUMN || direction_ == FlexDirection::COLUMN_REVERSE) { + collectionInfo.rows = mainCount_; + collectionInfo.columns = crossCount_; + } else { + collectionInfo.rows = crossCount_; + collectionInfo.columns = mainCount_; + } + + refPtr->SetCollectionInfo(collectionInfo); +} + +void RenderWaterFlow::SetItemCalSizeNeeded(const RefPtr& child, bool need) +{ + int32_t depth = DEFAULT_DEPTH; + auto item = child; + auto flowItem = AceType::DynamicCast(item); + while (!flowItem && depth > 0) { + if (!item || item->GetChildren().empty()) { + flowItem->SetCalSizeNeeded(need); + return; + } + item = item->GetChildren().front(); + flowItem = AceType::DynamicCast(item); + --depth; + } + if (flowItem) { + flowItem->SetCalSizeNeeded(need); + } +} + +bool RenderWaterFlow::GetItemCalSizeNeeded(const RefPtr& child) const +{ + int32_t depth = DEFAULT_DEPTH; + bool need = false; + auto item = child; + auto flowItem = AceType::DynamicCast(item); + while (!flowItem && depth > 0) { + if (!item || item->GetChildren().empty()) { + return need; + } + item = item->GetChildren().front(); + flowItem = AceType::DynamicCast(item); + --depth; + } + if (flowItem) { + need = flowItem->GetCalSizeNeeded(); + } + return need; +} + +void RenderWaterFlow::CheckAndInsertItems(int32_t mainIndex, int32_t itemIndex) +{ + auto item = items_.find(itemIndex); + if (((item != items_.end()) && (item->second == nullptr)) || (item == items_.end())) { + bool vail = false; + SupplyItems(vail, mainIndex, itemIndex); + } +} + +void RenderWaterFlow::OutPutMarix(int32_t rows, bool before) +{ + if (before) { + LOGD("marix_ss OutPutMarix before"); + } else { + LOGD("marix_ss OutPutMarix after"); + } + int32_t cols[5]; + for (int32_t i = 0; i < rows; i++) { + auto iterMain = flowMatrix_.find(i); + if (iterMain == flowMatrix_.end()) { + LOGD("marix_ss marix: %{public}d %{public}d %{public}d %{public}d %{public}d", -1, -1, -1, -1, -1); + continue; + } + std::map crossMap = iterMain->second; + for (int32_t j = 0; j < crossCount_; j++) { + auto iterCell = crossMap.find(j); + if (iterCell != crossMap.end()) { + cols[j] = iterCell->second; + } else { + cols[j] = -1; + } + } + } +} + +bool RenderWaterFlow::DeleteItemsInMarix(int32_t rows, int32_t itemIndex) +{ + bool deleteMainBeDelete = true; + int32_t main = -1; + int32_t cross = -1; + if (!GetItemMainCrossIndex(itemIndex, main, cross)) { + deleteMainBeDelete = false; + return deleteMainBeDelete; + } + for (int32_t i = 0; i < rows; i++) { + auto iter5 = flowMatrix_.find(i); + if (iter5 == flowMatrix_.end()) { + continue; + } + std::map mainMap2 = iter5->second; + for (int32_t j = 0; j < crossCount_; j++) { + auto iter6 = mainMap2.find(j); + if (iter6 == mainMap2.end()) { + continue; + } + if (iter6->second >= itemIndex) { + mainMap2.erase(j); + } + } + if (mainMap2.size() > 0) { + flowMatrix_[i] = mainMap2; + } else { + flowMatrix_.erase(i); + } + } + auto iter7 = flowMatrix_.find(main); + if (iter7 != flowMatrix_.end()) { + std::map mainMap = iter7->second; + for (int32_t k = 0; k < cross; k++) { + auto iteminf = mainMap.find(k); + if (iteminf == mainMap.end()) { + continue; + } + + int32_t Index = iteminf->second; + int32_t mainIndex = GetItemMainIndex(Index); + if (mainIndex == main) { + deleteMainBeDelete = false; + break; + } + } + } + return deleteMainBeDelete; +} +} // namespace OHOS::Ace::V2 \ No newline at end of file diff --git a/frameworks/core/components_v2/water_flow/render_water_flow.h b/frameworks/core/components_v2/water_flow/render_water_flow.h new file mode 100644 index 00000000000..edaf1f4457b --- /dev/null +++ b/frameworks/core/components_v2/water_flow/render_water_flow.h @@ -0,0 +1,327 @@ +/* + * Copyright (c) 2022 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_RENDER_WATER_FLOW_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_RENDER_WATER_FLOW_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "core/components/common/layout/constants.h" +#include "core/components/common/properties/scroll_bar.h" +#include "core/components/positioned/positioned_component.h" +#include "core/components/scroll/scroll_bar_theme.h" +#include "core/components/scroll/scrollable.h" +#include "core/components/stack/stack_element.h" +#include "core/components_v2/water_flow/render_water_flow_item.h" +#include "core/components_v2/water_flow/water_flow_component.h" +#include "core/pipeline/base/render_node.h" + +namespace OHOS::Ace::V2 { +class WaterFlowEventInfo : public BaseEventInfo, public EventToJSONStringAdapter { + DECLARE_RELATIONSHIP_OF_CLASSES(WaterFlowEventInfo, BaseEventInfo, EventToJSONStringAdapter); + +public: + explicit WaterFlowEventInfo(int32_t scrollIndex) : BaseEventInfo("waterflow"), scrollIndex_(scrollIndex) {} + + ~WaterFlowEventInfo() = default; + + std::string ToJSONString() const override; + + int32_t GetScrollIndex() const + { + return scrollIndex_; + } + +private: + int32_t scrollIndex_ = 0; +}; + +typedef struct { + int32_t rowSpan = 0; + int32_t colSpan = 0; +} Span; + +class RenderWaterFlow : public RenderNode { + DECLARE_ACE_TYPE(RenderWaterFlow, RenderNode); + +public: + using BuildChildByIndex = std::function; + using GetChildSpanByIndex = std::function; + using DeleteChildByIndex = std::function; + + RenderWaterFlow() = default; + ~RenderWaterFlow() override; + + static RefPtr Create(); + + void Update(const RefPtr& component) override; + void CalAndPosItems(double& drawLength, int32_t& main); + void PerformLayout() override; + void OnPredictLayout(int64_t deadline) override; + + const std::list>& GetChildren() const override + { + return childrenInRect_; + } + + void SetBuildChildByIndex(BuildChildByIndex func) + { + buildChildByIndex_ = std::move(func); + } + + void SetDeleteChildByIndex(DeleteChildByIndex func) + { + deleteChildByIndex_ = std::move(func); + } + + void SetGetChildSpanByIndex(GetChildSpanByIndex func) + { + getChildSpanByIndex_ = std::move(func); + } + + void AddChildByIndex(int32_t index, const RefPtr& renderNode); + void RemoveChildByIndex(int32_t index) + { + auto item = items_.find(index); + if (item != items_.end()) { + RemoveChild(item->second); + items_.erase(item); + } + } + void ClearLayout(int32_t index = -1); + void ClearItems(int32_t index = 0); + void OnDataSourceUpdated(int32_t index); + bool CheckEndShowItemPlace(int32_t index); + + void SetTotalCount(int32_t totalCount) + { + if (totalCount_ == totalCount) { + return; + } + totalCount_ = totalCount; + totalCountFlag_ = true; + } + + double GetEstimatedHeight(); + // Used in WaterFlowPositionController + bool AnimateTo(const Dimension& position, float duration, const RefPtr& curve); + Offset CurrentOffset(); + void ScrollToEdge(ScrollEdgeType edgeType, bool smooth); + + Axis GetAxis() const + { + return useScrollable_ == SCROLLABLE::VERTICAL ? Axis::VERTICAL : Axis::HORIZONTAL; + } + + void OnPaintFinish() override; + + bool IsChildrenTouchEnable() override; + + size_t GetCachedSize() const + { + return endShowItemIndex_ - startShowItemIndex_; + } + + Offset GetLastOffset() const + { + return useScrollable_ == SCROLLABLE::VERTICAL ? Offset(0, lastOffset_) : Offset(lastOffset_, 0); + } + + void HandleAxisEvent(const AxisEvent& event) override; + + bool IsAxisScrollable(AxisDirection direction) override; + + WeakPtr CheckAxisNode() override; + + void OnChildAdded(const RefPtr& renderNode) override; + bool IsUseOnly() override; + int32_t RequestNextFocus(bool vertical, bool reverse); + void UpdateFocusInfo(int32_t focusIndex); + +protected: + int32_t GetItemSpan(const RefPtr& child, bool isRow) const; + bool GetItemSpanFromCache(int32_t index, int32_t& rowSpan, int32_t& colSpan); + int32_t GetIndexByFlow(int32_t row, int32_t column) const; + int32_t GetIndexByNode(const RefPtr& child) const; + // Handle direction key move + int32_t focusMove(KeyDirection direction); + void UpdateAccessibilityAttr(); + + std::vector ParseCrossLength(double size, double gap); + int32_t GetItemMainIndex(int32_t index) const; + void SetMainSize(Size& dst, const Size& src); + double GetSize(const Size& src, bool isMain = true) const; + void GetNextFlow(int32_t& curMain, int32_t& curCross) const; + void GetPreviousFlow(int32_t& curMain, int32_t& curCross); + LayoutParam MakeInnerLayoutParam(int32_t row, int32_t col, int32_t rowSpan, int32_t colSpan) const; + void CalculateCrossSpan(int32_t mainIndex, int32_t cross, int32_t crossSpan, int32_t& calculateCrossSpan); + bool CheckFlowPlaced(int32_t index, int32_t row, int32_t col, int32_t& rowSpan, int32_t& colSpan); + + // Sets child position, the mainAxis does not contain the offset. + void SetChildPosition(const RefPtr& child, int32_t row, int32_t col, int32_t rowSpan, int32_t colSpan); + + void CreateScrollable(); + void LayoutChild(const RefPtr& child, int32_t row, int32_t col, int32_t rowSpan, int32_t colSpan, + bool needPosition = true); + void OnTouchTestHit( + const Offset& coordinateOffset, const TouchRestrict& touchRestrict, TouchTestResult& result) override; + bool UpdateScrollPosition(double offset, int32_t source); + void RecordLocation(); + + void CallGap(); + void InitialFlowProp(); + void CaculateViewPortSceneOne(); + bool CaculateViewPortSceneTwo(bool& NeedContinue); + void CaculateViewPort(); + double BuildLazyFlowLayout(int32_t index, double sizeNeed); + bool GetFlowSize(); + void BuildFlow(std::vector& cols); + double CalculateBlankOfEnd(); + double SupplyItems(bool& vailSupplyItem, int32_t mainIndex, int32_t itemIndex = -1, bool needPosition = true, + bool needRank = true); + bool CheckMainFull(int32_t mainIndex); + int32_t CalItemIndexInRank(int32_t mainIndex); + bool Rank(int32_t mainIndex, int32_t itemIndex = -1); + void DealCache(int32_t start, int32_t end); + void DeleteItems(int32_t index, bool isTail); + + void GetMinAndMaxIndex(int32_t& min, int32_t& max); + bool GetItemMainCrossIndex(int32_t index, int32_t& mainIndex, int32_t& crossIndex); + + bool NeedUpdate(const RefPtr& component); + + void CalculateWholeSize(double drawLength); + + void InitScrollBar(const RefPtr& component); + void InitScrollBarProxy(); + + void DoJump(double position, int32_t source); + void LoadForward(); + + double GetCurrentOffset() const + { + return startMainPos_ + currentOffset_ - firstItemOffset_; + } + + void SetScrollBarCallback(); + + void SetItemCalSizeNeeded(const RefPtr& child, bool need); + + bool GetItemCalSizeNeeded(const RefPtr& child) const; + + void CheckAndInsertItems(int32_t mainIndex, int32_t itemIndex); + + void OutPutMarix(int32_t rows, bool before); + + bool DeleteItemsInMarix(int32_t rows, int32_t itemIndex); + + enum class SCROLLABLE : uint32_t { + NO_SCROLL = 0, + VERTICAL, + HORIZONTAL, + }; + + SCROLLABLE useScrollable_ = SCROLLABLE::NO_SCROLL; + + std::unordered_map> items_; + std::set showItem_; + std::set inCache_; + std::list> childrenInRect_; + // Map structure: [Index - (rowSpan, columnSpan)] + std::map itemSpanCache_; + + RefPtr scrollable_; + bool reachHead_ = false; + bool reachTail_ = false; + std::optional firstLineToBottom_; + bool needCalculateViewPort_ = false; + double startMainPos_ = 0.0; + double endMainPos_ = 0.0; + double currentOffset_ = 0.0; + double animateDelta_ = 0.0; + double lastOffset_ = 0.0; + double firstItemOffset_ = 0.0; + int32_t startIndex_ = 0; + int32_t endIndex_ = -1; + + int32_t startShowItemIndex_ = 0; + int32_t endShowItemIndex_ = -1; + + int32_t startRankItemIndex_ = 0; + int32_t currentItemIndex_ = 0; + + double mainSize_ = 0.0; + double crossSize_ = 0.0; + int32_t mainCount_ = 0; + int32_t crossCount_ = 0; + double crossGap_ = 0.0; + double mainGap_ = 0.0; + int32_t totalCount_ = 0; + + // used for scrollbar + double scrollBarExtent_ = 0.0; + double mainScrollExtent_ = 0.0; + int32_t scrollBarOpacity_ = 0; + double estimateHeight_ = 0.0; + bool totalCountFlag_ = false; + Color scrollBarColor_; + + RefPtr scrollBarProxy_; + RefPtr scrollBar_; + RefPtr animator_; + RefPtr component_; + BuildChildByIndex buildChildByIndex_; + DeleteChildByIndex deleteChildByIndex_; + GetChildSpanByIndex getChildSpanByIndex_; + + int32_t loadingIndex_ = -1; + + int32_t cacheCount_ = 10; + + // add from RenderWaterFlowBase + bool isVertical_ = false; + bool updateFlag_ = false; + FlexDirection direction_ = FlexDirection::ROW; + FlexAlign crossAxisAlign_ = FlexAlign::CENTER; + + int32_t focusRow_ = -1; + int32_t focusCol_ = -1; + int32_t focusIndex_ = 0; + + double flowWidth_ = -1.0; + double flowHeight_ = -1.0; + double mainLength_ = 0.0; + Dimension userColGap_ = 0.0_px; + Dimension userRowGap_ = 0.0_px; + Dimension userMainLength_ = 0.0_px; + DisplayMode displayMode_ = DisplayMode::OFF; + bool rightToLeft_ = false; + // Map structure: [rowIndex - (columnIndex, index)] + std::map> flowMatrix_; + // Map structure: [Index - (rowIndex, columnIndex)] + std::map> flowMatrixByIndex_; + // Map structure: [rowIndex - columnIndex - (width, height)] + Size flowCells_; +}; +} // namespace OHOS::Ace::V2 +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_RENDER_WATER_FLOW_H \ No newline at end of file diff --git a/frameworks/core/components_v2/water_flow/render_water_flow_creator.cpp b/frameworks/core/components_v2/water_flow/render_water_flow_creator.cpp new file mode 100644 index 00000000000..58e5956155b --- /dev/null +++ b/frameworks/core/components_v2/water_flow/render_water_flow_creator.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2022 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 "flutter_render_water_flow.h" +#include "rosen_render_water_flow.h" + +namespace OHOS::Ace::V2 { +RefPtr RenderWaterFlow::Create() +{ + if (SystemProperties::GetRosenBackendEnabled()) { +#ifdef ENABLE_ROSEN_BACKEND + return AceType::MakeRefPtr(); +#else + return nullptr; +#endif + } else { + return AceType::MakeRefPtr(); + } +} +} // namespace OHOS::Ace::V2 diff --git a/frameworks/core/components_v2/water_flow/render_water_flow_item.cpp b/frameworks/core/components_v2/water_flow/render_water_flow_item.cpp new file mode 100644 index 00000000000..2b47fc19b8c --- /dev/null +++ b/frameworks/core/components_v2/water_flow/render_water_flow_item.cpp @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2022 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 "core/components_v2/water_flow/render_water_flow_item.h" + +#include "base/utils/utils.h" +#include "core/components_v2/water_flow/render_water_flow.h" +#include "core/components_v2/water_flow/water_flow_item_component.h" + +namespace OHOS::Ace::V2 { +RefPtr RenderWaterFlowItem::Create() +{ + return AceType::MakeRefPtr(); +} + +void RenderWaterFlowItem::Update(const RefPtr& component) +{ + const RefPtr flowItem = AceType::DynamicCast(component); + if (!flowItem) { + return; + } + SetColumnSpan(flowItem->GetColumnSpan()); + SetRowSpan(flowItem->GetRowSpan()); + SetForceRebuild(flowItem->ForceRebuild()); + onSelectId_ = flowItem->GetOnSelectId(); + selectable_ = flowItem->GetSelectable(); + MarkNeedLayout(); +} + +void RenderWaterFlowItem::PerformLayout() +{ + if (GetChildren().empty()) { + LOGE("RenderWaterFlowItem: no child found in RenderWaterFlowItem!"); + } else { + auto child = GetChildren().front(); + child->Layout(GetLayoutParam()); + child->SetPosition(Offset::Zero()); + SetLayoutSize(child->GetLayoutSize()); + } +} + +void RenderWaterFlowItem::HandleOnFocus() +{ + auto parent = GetParent().Upgrade(); + while (parent) { + auto waterFlow = AceType::DynamicCast(parent); + if (waterFlow) { + waterFlow->UpdateFocusInfo(index_); + break; + } + parent = parent->GetParent().Upgrade(); + } +} + +void RenderWaterFlowItem::SetColumnSpan(int32_t columnSpan) +{ + if (columnSpan <= 0) { + LOGW("Invalid columnSpan %{public}d", columnSpan); + return; + } + columnSpan_ = columnSpan; +} + +void RenderWaterFlowItem::SetRowSpan(int32_t rowSpan) +{ + if (rowSpan <= 0) { + LOGW("Invalid rowSpan %{public}d", rowSpan); + return; + } + rowSpan_ = rowSpan; +} +} // namespace OHOS::Ace::V2 diff --git a/frameworks/core/components_v2/water_flow/render_water_flow_item.h b/frameworks/core/components_v2/water_flow/render_water_flow_item.h new file mode 100644 index 00000000000..bfc85fd3ffc --- /dev/null +++ b/frameworks/core/components_v2/water_flow/render_water_flow_item.h @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2022 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_RENDER_WATER_FLOW_ITEM_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_RENDER_WATER_FLOW_ITEM_H + +#include "core/pipeline/base/render_node.h" + +namespace OHOS::Ace::V2 { +class RenderWaterFlowItem : public RenderNode { + DECLARE_ACE_TYPE(RenderWaterFlowItem, RenderNode); + +public: + using OnItemLongPressed = std::function&)>; + using OnSelectFunc = std::function; + + static RefPtr Create(); + + void Update(const RefPtr& component) override; + + void PerformLayout() override; + + void HandleOnFocus(); + + void SetColumnIndex(int32_t columnIndex); + void SetRowIndex(int32_t rowIndex); + void SetColumnSpan(int32_t columnSpan); + void SetRowSpan(int32_t rowSpan); + void SetForceRebuild(bool forceRebuild) + { + forceRebuild_ = forceRebuild; + } + + bool GetForceRebuild() const + { + return forceRebuild_; + } + + void SetBoundary() + { + TakeBoundary(); + } + + int32_t GetColumnSpan() const + { + return columnSpan_; + } + + int32_t GetRowSpan() const + { + return rowSpan_; + } + + void SetIndex(int32_t index) + { + index_ = index; + } + + bool ForceRebuild() const + { + return forceRebuild_; + } + + int32_t GetIndex() const + { + return index_; + } + + bool GetSelectable() const + { + return selectable_; + } + + OnSelectFunc GetOnSelectId() const + { + return onSelectId_; + } + + void MarkIsSelected(bool isSelected) + { + isSelected_ = isSelected; + } + + bool IsSelected() const + { + return isSelected_; + } + + void SetCalSizeNeeded(bool need) + { + needCalSize_ = need; + } + + bool GetCalSizeNeeded() const + { + return needCalSize_; + } + +private: + int32_t index_ = -1; + int32_t columnSpan_ = 1; + int32_t rowSpan_ = 1; + bool forceRebuild_ = false; + OnSelectFunc onSelectId_; + bool selectable_ = false; + bool isSelected_ = false; + bool needCalSize_ = true; +}; +} // namespace OHOS::Ace::V2 +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_RENDER_WATER_FLOW_ITEM_H diff --git a/frameworks/core/components_v2/water_flow/rosen_render_water_flow.cpp b/frameworks/core/components_v2/water_flow/rosen_render_water_flow.cpp new file mode 100644 index 00000000000..300321a68ea --- /dev/null +++ b/frameworks/core/components_v2/water_flow/rosen_render_water_flow.cpp @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2022 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 "core/components_v2/water_flow/rosen_render_water_flow.h" + +#include "render_service_client/core/ui/rs_node.h" + +#include "core/components/common/painter/rosen_scroll_bar_painter.h" +#include "core/pipeline/base/rosen_render_context.h" + +namespace OHOS::Ace::V2 { +void RosenRenderWaterFlow::Update(const RefPtr& component) +{ + RenderWaterFlow::Update(component); + auto rsNode = GetRSNode(); + if (rsNode == nullptr) { + return; + } + rsNode->SetClipToFrame(true); +} + +void RosenRenderWaterFlow::Paint(RenderContext& context, const Offset& offset) +{ + LOGD("Paint %{public}lf %{public}lf", GetLayoutSize().Width(), GetLayoutSize().Height()); + RenderNode::Paint(context, offset); + + // Notify scroll bar to update. + if (scrollBarProxy_) { + scrollBarProxy_->NotifyScrollBar(AceType::WeakClaim(this)); + } + + // render scroll bar + if (!scrollBar_ || !scrollBar_->NeedPaint()) { + GetEstimatedHeight(); + return; + } + bool needPaint = false; + if (scrollBar_->GetFirstLoad() || scrollBar_->IsActive() || scrollBar_->GetDisplayMode() == DisplayMode::ON) { + scrollBarOpacity_ = UINT8_MAX; + needPaint = true; + } else { + if (scrollBarOpacity_ != 0) { + needPaint = true; + } + } + if (!needPaint) { + return; + } + const auto renderContext = static_cast(&context); + auto canvas = renderContext->GetCanvas(); + auto rsNode = renderContext->GetRSNode(); + if (!canvas || !rsNode) { + LOGE("canvas is null"); + return; + } + rsNode->SetPaintOrder(true); + Offset lastOffset = isVertical_ ? Offset(0, lastOffset_) : Offset(lastOffset_, 0); + scrollBar_->UpdateScrollBarRegion(offset, GetLayoutSize(), lastOffset, GetEstimatedHeight()); + RefPtr scrollPainter = AceType::MakeRefPtr(); + scrollPainter->PaintBar(canvas, offset, GetPaintRect(), scrollBar_, GetGlobalOffset(), scrollBarOpacity_); + if (scrollBar_->GetFirstLoad()) { + scrollBar_->SetFirstLoad(false); + scrollBar_->HandleScrollBarEnd(); + } +} +} // namespace OHOS::Ace::V2 diff --git a/frameworks/core/components_v2/water_flow/rosen_render_water_flow.h b/frameworks/core/components_v2/water_flow/rosen_render_water_flow.h new file mode 100644 index 00000000000..db7f02b747a --- /dev/null +++ b/frameworks/core/components_v2/water_flow/rosen_render_water_flow.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2022 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_ROSEN_RENDER_WATER_FLOW_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_ROSEN_RENDER_WATER_FLOW_H + +#include "core/components_v2/water_flow/render_water_flow.h" + +namespace OHOS::Ace::V2 { +class RosenRenderWaterFlow : public RenderWaterFlow { + DECLARE_ACE_TYPE(RosenRenderWaterFlow, RenderWaterFlow); + +public: + RosenRenderWaterFlow() = default; + ~RosenRenderWaterFlow() override = default; + + void Update(const RefPtr& component) override; + void Paint(RenderContext& context, const Offset& offset) override; + +private: +}; +} // namespace OHOS::Ace::V2 +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_ROSEN_RENDER_WATER_FLOW_H diff --git a/frameworks/core/components_v2/water_flow/water_flow_component.cpp b/frameworks/core/components_v2/water_flow/water_flow_component.cpp new file mode 100644 index 00000000000..b4ed5362593 --- /dev/null +++ b/frameworks/core/components_v2/water_flow/water_flow_component.cpp @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2022 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 "core/components_v2/water_flow/water_flow_component.h" + +#include "core/components_v2/water_flow/render_water_flow.h" +#include "core/components_v2/water_flow/water_flow_element.h" +#include "core/pipeline/base/multi_composed_component.h" + +namespace OHOS::Ace::V2 { +RefPtr WaterFlowComponent::CreateElement() +{ + return AceType::MakeRefPtr(); +} + +RefPtr WaterFlowComponent::CreateRenderNode() +{ + return RenderWaterFlow::Create(); +} + +void WaterFlowComponent::SetMainLength(const Dimension& mainLength) +{ + if (mainLength.Value() < 0.0) { + LOGW("Invalid MainLength use 0px"); + return; + } + mainLength_ = mainLength; +} + +void WaterFlowComponent::SetColumnsGap(const Dimension& columnsGap) +{ + if (columnsGap.Value() < 0.0) { + LOGW("Invalid RowGap, use 0px"); + columnsGap_ = 0.0_px; + return; + } + columnsGap_ = columnsGap; +} + +void WaterFlowComponent::SetRowsGap(const Dimension& rowsGap) +{ + if (rowsGap.Value() < 0.0) { + LOGW("Invalid RowGap, use 0px"); + rowsGap_ = 0.0_px; + return; + } + rowsGap_ = rowsGap; +} + +void WaterFlowComponent::SetLayoutDirection(FlexDirection direction) +{ + if (direction < FlexDirection::ROW || direction > FlexDirection::COLUMN_REVERSE) { + LOGW("Invalid direction %{public}d", direction); + return; + } + direction_ = direction; +} + +void WaterFlowComponent::SetFlexAlign(FlexAlign flexAlign) +{ + if (flexAlign < FlexAlign::FLEX_START || flexAlign > FlexAlign::STRETCH) { + LOGW("Invalid flexAlign %{public}d", flexAlign); + return; + } + flexAlign_ = flexAlign; +} + +void WaterFlowComponent::SetController(const RefPtr& controller) +{ + controller_ = controller; +} + +void WaterFlowComponent::SetScrollBarProxy(const RefPtr& scrollBarProxy) +{ + scrollBarProxy_ = scrollBarProxy; +} + +void WaterFlowComponent::SetRightToLeft(bool rightToLeft) +{ + rightToLeft_ = rightToLeft; +} + +void WaterFlowComponent::SetScrolledEvent(const EventMarker& event) +{ + scrolledEvent_ = event; +} + +void WaterFlowComponent::SetScrollBarDisplayMode(DisplayMode displayMode) +{ + displayMode_ = displayMode; +} + +void WaterFlowComponent::SetScrollBarColor(const std::string& color) +{ + scrollBarColor_ = color; +} + +void WaterFlowComponent::SetScrollBarWidth(const std::string& width) +{ + scrollBarWidth_ = width; +} +} // namespace OHOS::Ace::V2 diff --git a/frameworks/core/components_v2/water_flow/water_flow_component.h b/frameworks/core/components_v2/water_flow/water_flow_component.h new file mode 100644 index 00000000000..bce75fedc29 --- /dev/null +++ b/frameworks/core/components_v2/water_flow/water_flow_component.h @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2022 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_WATER_FLOW_COMPONENT_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_WATER_FLOW_COMPONENT_H + +#include "base/utils/macros.h" +#include "core/components/common/layout/constants.h" +#include "core/components/common/properties/scroll_bar.h" +#include "core/components/scroll_bar/scroll_bar_proxy.h" +#include "core/components_v2/water_flow/water_flow_position_controller.h" +#include "core/pipeline/base/component_group.h" + +namespace OHOS::Ace::V2 { +class ACE_EXPORT WaterFlowComponent : public ComponentGroup { + DECLARE_ACE_TYPE(WaterFlowComponent, ComponentGroup); + +public: + WaterFlowComponent(const std::list>& children, int32_t crossSplice) + : ComponentGroup(children), crossSplice_(crossSplice) + {} + + ~WaterFlowComponent() override = default; + + RefPtr CreateElement() override; + RefPtr CreateRenderNode() override; + + void SetMainLength(const Dimension& mainLength); + void SetColumnsGap(const Dimension& columnsGap); + void SetRowsGap(const Dimension& rowsGap); + void SetFlexAlign(FlexAlign flexAlign); + void SetRightToLeft(bool rightToLeft); + void SetLayoutDirection(FlexDirection direction); + void SetController(const RefPtr& controller); + void SetScrollBarProxy(const RefPtr& scrollBarProxy); + void SetScrolledEvent(const EventMarker& event); + void SetScrollBarDisplayMode(DisplayMode displayMode); + void SetScrollBarColor(const std::string& color); + void SetScrollBarWidth(const std::string& width); + + int32_t GetCrossSplice() const + { + return crossSplice_; + } + + const Dimension& GetMainLength() const + { + return mainLength_; + } + + const Dimension& GetColumnsGap() const + { + return columnsGap_; + } + + const Dimension& GetRowsGap() const + { + return rowsGap_; + } + + FlexDirection GetDirection() const + { + return direction_; + } + + FlexAlign GetFlexAlign() const + { + return flexAlign_; + } + + const RefPtr& GetController() const + { + return controller_; + } + + const RefPtr& GetScrollBarProxy() const + { + return scrollBarProxy_; + } + + bool GetRightToLeft() const + { + return rightToLeft_; + } + + const EventMarker& GetScrolledEvent() const + { + return scrolledEvent_; + } + + DisplayMode GetScrollBarDisplayMode() + { + return displayMode_; + } + + const std::string& GetScrollBarColor() const + { + return scrollBarColor_; + } + + const std::string& GetScrollBarWidth() const + { + return scrollBarWidth_; + } + +private: + int32_t crossSplice_ = 0; + Dimension mainLength_ = 0.0_px; + Dimension columnsGap_ = 0.0_px; + Dimension rowsGap_ = 0.0_px; + FlexDirection direction_ = FlexDirection::COLUMN; + FlexAlign flexAlign_ = FlexAlign::CENTER; + bool rightToLeft_ = false; + + // scroll bar attribute + std::string scrollBarColor_; + std::string scrollBarWidth_; + DisplayMode displayMode_ = DisplayMode::ON; + RefPtr controller_; + RefPtr scrollBarProxy_; + EventMarker scrolledEvent_; +}; +} // namespace OHOS::Ace::V2 +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_WATER_FLOW_COMPONENT_H diff --git a/frameworks/core/components_v2/water_flow/water_flow_element.cpp b/frameworks/core/components_v2/water_flow/water_flow_element.cpp new file mode 100644 index 00000000000..f9328b8e8e5 --- /dev/null +++ b/frameworks/core/components_v2/water_flow/water_flow_element.cpp @@ -0,0 +1,214 @@ +/* + * Copyright (c) 2022 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 "core/components_v2/water_flow/water_flow_element.h" + +#include "base/log/log.h" +#include "base/utils/utils.h" +#include "core/components/proxy/render_item_proxy.h" +#include "core/components_v2/water_flow/render_water_flow.h" +#include "core/components_v2/water_flow/water_flow_component.h" +#include "core/components_v2/water_flow/water_flow_item_component.h" + +namespace OHOS::Ace::V2 { +void WaterFlowElement::Update() +{ + RenderElement::Update(); + RefPtr render = AceType::DynamicCast(renderNode_); + if (!render) { + return; + } + render->OnDataSourceUpdated(0); +} + +RefPtr WaterFlowElement::CreateRenderNode() +{ + auto render = RenderElement::CreateRenderNode(); + RefPtr renderWaterFlow = AceType::DynamicCast(render); + if (renderWaterFlow) { + renderWaterFlow->SetBuildChildByIndex([weak = WeakClaim(this)](int32_t index) { + auto element = weak.Upgrade(); + if (!element) { + return false; + } + return element->BuildChildByIndex(index); + }); + + renderWaterFlow->SetDeleteChildByIndex([weak = WeakClaim(this)](int32_t index) { + auto element = weak.Upgrade(); + if (!element) { + return; + } + element->DeleteChildByIndex(index); + }); + + renderWaterFlow->SetGetChildSpanByIndex( + [weak = WeakClaim(this)](int32_t index, bool isHorizontal, int32_t& itemMainSpan, int32_t& itemCrossSpan) { + auto element = weak.Upgrade(); + if (!element) { + return false; + } + return element->GetItemSpanByIndex(index, isHorizontal, itemMainSpan, itemCrossSpan); + }); + } + + return render; +} + +void WaterFlowElement::PerformBuild() +{ + auto component = AceType::DynamicCast(component_); + ACE_DCHECK(component); // MUST be WaterFlowComponent + V2::ElementProxyHost::UpdateChildren(component->GetChildren()); +} + +bool WaterFlowElement::BuildChildByIndex(int32_t index) +{ + if (index < 0) { + return false; + } + auto element = GetElementByIndex(index); + if (!element) { + LOGE("GetElementByIndex failed index=[%d]", index); + return false; + } + auto renderNode = element->GetRenderNode(); + if (!renderNode) { + LOGE("GetRenderNode failed"); + return false; + } + RefPtr waterFlow = AceType::DynamicCast(renderNode_); + if (!waterFlow) { + return false; + } + waterFlow->AddChildByIndex(index, renderNode); + return true; +} + +bool WaterFlowElement::GetItemSpanByIndex( + int32_t index, bool isHorizontal, int32_t& itemMainSpan, int32_t& itemCrossSpan) +{ + if (index < 0) { + return false; + } + auto component = GetComponentByIndex(index); + auto flowItem = AceType::DynamicCast(component); + + if (!flowItem) { + return false; + } + if (isHorizontal) { + itemMainSpan = flowItem->GetColumnSpan(); + itemCrossSpan = flowItem->GetRowSpan(); + } else { + itemMainSpan = flowItem->GetRowSpan(); + itemCrossSpan = flowItem->GetColumnSpan(); + } + return true; +} + +void WaterFlowElement::DeleteChildByIndex(int32_t index) +{ + ReleaseElementByIndex(index); +} + +bool WaterFlowElement::RequestNextFocus(bool vertical, bool reverse, const Rect& rect) +{ + RefPtr waterFlow = AceType::DynamicCast(renderNode_); + if (!waterFlow) { + LOGE("Render waterFlow is null."); + return false; + } + LOGI("RequestNextFocus vertical:%{public}d reverse:%{public}d.", vertical, reverse); + bool ret = false; + while (!ret) { + int32_t focusIndex = waterFlow->RequestNextFocus(vertical, reverse); + int32_t size = GetChildrenList().size(); + if (focusIndex < 0 || focusIndex >= size) { + return false; + } + auto iter = GetChildrenList().begin(); + std::advance(iter, focusIndex); + auto focusNode = *iter; + if (!focusNode) { + LOGE("Target focus node is null."); + return false; + } + // If current Node can not obtain focus, move to next. + ret = focusNode->RequestFocusImmediately(); + } + return ret; +} + +void WaterFlowElement::ApplyRenderChild(const RefPtr& renderChild) +{ + if (!renderChild) { + LOGE("Element child is null"); + return; + } + + if (!renderNode_) { + LOGE("RenderElement don't have a render node"); + return; + } + renderNode_->AddChild(renderChild->GetRenderNode()); +} + +RefPtr WaterFlowElement::OnUpdateElement(const RefPtr& element, const RefPtr& component) +{ + return UpdateChild(element, component); +} + +RefPtr WaterFlowElement::OnMakeEmptyComponent() +{ + return AceType::MakeRefPtr(); +} + +void WaterFlowElement::OnDataSourceUpdated(size_t startIndex) +{ + auto context = context_.Upgrade(); + if (context) { + context->AddPostFlushListener(AceType::Claim(this)); + } + RefPtr render = AceType::DynamicCast(renderNode_); + if (!render) { + return; + } + render->OnDataSourceUpdated(static_cast(startIndex)); + render->SetTotalCount(ElementProxyHost::TotalCount()); +} + +void WaterFlowElement::OnPostFlush() +{ + ReleaseRedundantComposeIds(); +} + +size_t WaterFlowElement::GetReloadedCheckNum() +{ + RefPtr render = AceType::DynamicCast(renderNode_); + if (render) { + size_t cachedNum = render->GetCachedSize(); + if (cachedNum > 0) { + return cachedNum; + } + } + return ElementProxyHost::GetReloadedCheckNum(); +} + +void WaterFlowElement::Dump() +{ + DumpProxy(); +} +} // namespace OHOS::Ace::V2 diff --git a/frameworks/core/components_v2/water_flow/water_flow_element.h b/frameworks/core/components_v2/water_flow/water_flow_element.h new file mode 100644 index 00000000000..3c895c2cac5 --- /dev/null +++ b/frameworks/core/components_v2/water_flow/water_flow_element.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2022 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_WATER_FLOW_ELEMENT_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_WATER_FLOW_ELEMENT_H + +#include "base/utils/noncopyable.h" +#include "core/components_v2/common/element_proxy.h" +#include "core/focus/focus_node.h" +#include "core/pipeline/base/render_element.h" + +namespace OHOS::Ace::V2 { +class WaterFlowElement : public RenderElement, public FocusGroup, public FlushEvent, private V2::ElementProxyHost { + DECLARE_ACE_TYPE(WaterFlowElement, RenderElement, FocusGroup); + +public: + void Update() override; + void PerformBuild() override; + bool RequestNextFocus(bool vertical, bool reverse, const Rect& rect) override; + + bool BuildChildByIndex(int32_t index); + void DeleteChildByIndex(int32_t index); + bool GetItemSpanByIndex(int32_t index, bool isHorizontal, int32_t& itemMainSpan, int32_t& itemCrossSpan); + size_t GetReloadedCheckNum() override; + void OnPostFlush() override; + void Dump() override; + +private: + RefPtr CreateRenderNode() override; + void ApplyRenderChild(const RefPtr& renderChild) override; + + RefPtr OnUpdateElement(const RefPtr& element, const RefPtr& component) override; + RefPtr OnMakeEmptyComponent() override; + void OnDataSourceUpdated(size_t startIndex) override; +}; +} // namespace OHOS::Ace::V2 +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_WATER_FLOW_ELEMENT_H diff --git a/frameworks/core/components_v2/water_flow/water_flow_item_component.cpp b/frameworks/core/components_v2/water_flow/water_flow_item_component.cpp new file mode 100644 index 00000000000..ed3184e459c --- /dev/null +++ b/frameworks/core/components_v2/water_flow/water_flow_item_component.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2022 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 "core/components_v2/water_flow/water_flow_item_component.h" + +#include "core/components_v2/water_flow/render_water_flow_item.h" +#include "core/components_v2/water_flow/water_flow_item_element.h" + +namespace OHOS::Ace::V2 { +RefPtr WaterFlowItemComponent::CreateElement() +{ + return AceType::MakeRefPtr(); +} + +RefPtr WaterFlowItemComponent::CreateRenderNode() +{ + return RenderWaterFlowItem::Create(); +} + +void WaterFlowItemComponent::SetColumnSpan(int32_t columnSpan) +{ + if (columnSpan <= 0) { + LOGW("Invalid columnSpan %{public}d", columnSpan); + return; + } + columnSpan_ = columnSpan; +} + +void WaterFlowItemComponent::SetRowSpan(int32_t rowSpan) +{ + if (rowSpan <= 0) { + LOGW("Invalid rowSpan %{public}d", rowSpan); + return; + } + rowSpan_ = rowSpan; +} +} // namespace OHOS::Ace::V2 diff --git a/frameworks/core/components_v2/water_flow/water_flow_item_component.h b/frameworks/core/components_v2/water_flow/water_flow_item_component.h new file mode 100644 index 00000000000..194b378dac0 --- /dev/null +++ b/frameworks/core/components_v2/water_flow/water_flow_item_component.h @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2022 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_WATER_FLOW_ITEM_COMPONENT_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_WATER_FLOW_ITEM_COMPONENT_H + +#include "base/utils/macros.h" +#include "core/pipeline/base/sole_child_component.h" + +namespace OHOS::Ace::V2 { +using OnSelectFunc = std::function; + +class ACE_EXPORT WaterFlowItemComponent : public SoleChildComponent { + DECLARE_ACE_TYPE(WaterFlowItemComponent, SoleChildComponent); + +public: + WaterFlowItemComponent() = default; + explicit WaterFlowItemComponent(const RefPtr& child) : SoleChildComponent(child) {} + ~WaterFlowItemComponent() override = default; + + RefPtr CreateRenderNode() override; + + RefPtr CreateElement() override; + + void SetColumnIndex(int32_t columnIndex); + void SetRowIndex(int32_t rowIndex); + void SetColumnSpan(int32_t columnSpan); + void SetRowSpan(int32_t rowSpan); + void SetForceRebuild(bool forceRebuild) + { + forceRebuild_ = forceRebuild; + } + + void SetClickedEventId(const EventMarker& eventId) + { + clickEventId_ = eventId; + } + + const EventMarker& GetClickedEventId() const + { + return clickEventId_; + } + + int32_t GetColumnSpan() const + { + return columnSpan_; + } + + int32_t GetRowSpan() const + { + return rowSpan_; + } + + bool ForceRebuild() const + { + return forceRebuild_; + } + + bool GetSelectable() const + { + return selectable_; + } + + void SetSelectable(bool selectable) + { + selectable_ = selectable; + } + + OnSelectFunc GetOnSelectId() const + { + return onSelectId_; + } + + void SetOnSelectId(const OnSelectFunc& onSelectId) + { + onSelectId_ = onSelectId; + } + +private: + EventMarker clickEventId_; + int32_t columnSpan_ = 1; + int32_t rowSpan_ = 1; + bool forceRebuild_ = false; + OnSelectFunc onSelectId_; + bool selectable_ = false; +}; +} // namespace OHOS::Ace::V2 +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_WATER_FLOW_ITEM_COMPONENT_H diff --git a/frameworks/core/components_v2/water_flow/water_flow_item_element.cpp b/frameworks/core/components_v2/water_flow/water_flow_item_element.cpp new file mode 100644 index 00000000000..d9469115c21 --- /dev/null +++ b/frameworks/core/components_v2/water_flow/water_flow_item_element.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2022 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 "core/components_v2/water_flow/water_flow_item_element.h" + +#include "core/components_v2/water_flow/render_water_flow_item.h" + +namespace OHOS::Ace::V2 { +RefPtr WaterFlowItemElement::CreateRenderNode() +{ + SetOnFocusCallback([weak = WeakClaim(this)](void) { + auto element = weak.Upgrade(); + if (element) { + element->HandleOnFocus(); + } + }); + return SoleChildElement::CreateRenderNode(); +} + +void WaterFlowItemElement::HandleOnFocus() +{ + auto waterFlowItem = AceType::DynamicCast(GetRenderNode()); + if (waterFlowItem) { + waterFlowItem->HandleOnFocus(); + } +} +} // namespace OHOS::Ace::V2 diff --git a/frameworks/core/components_v2/water_flow/water_flow_item_element.h b/frameworks/core/components_v2/water_flow/water_flow_item_element.h new file mode 100644 index 00000000000..1c88869e796 --- /dev/null +++ b/frameworks/core/components_v2/water_flow/water_flow_item_element.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2022 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_WATER_FLOW_ITEM_ELEMENT_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_WATER_FLOW_ITEM_ELEMENT_H + +#include "core/pipeline/base/sole_child_element.h" + +namespace OHOS::Ace::V2 { +class WaterFlowItemElement : public SoleChildElement, public FocusGroup { + DECLARE_ACE_TYPE(WaterFlowItemElement, SoleChildElement, FocusGroup); + +public: + void HandleOnFocus(); + + bool RequestNextFocus(bool vertical, bool reverse, const Rect& rect) override + { + // waterflow Item just one child, all focus move event make it blur. + return false; + } + +private: + RefPtr CreateRenderNode() override; +}; +} // namespace OHOS::Ace::V2 +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_WATER_FLOW_ITEM_ELEMENT_H diff --git a/frameworks/core/components_v2/water_flow/water_flow_position_controller.cpp b/frameworks/core/components_v2/water_flow/water_flow_position_controller.cpp new file mode 100644 index 00000000000..221f53cd2bb --- /dev/null +++ b/frameworks/core/components_v2/water_flow/water_flow_position_controller.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2022 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 "core/components_v2/water_flow/water_flow_position_controller.h" + +#include "core/components_v2/water_flow/render_water_flow.h" +#include "core/components_v2/water_flow/water_flow_scroll_controller.h" + +namespace OHOS::Ace::V2 { +void WaterFlowPositionController::JumpTo(int32_t index, int32_t source) +{ + auto waterFlow = AceType::DynamicCast(scroll_.Upgrade()); + if (!waterFlow) { + return; + } + return; +} + +bool WaterFlowPositionController::AnimateTo(const Dimension& position, float duration, const RefPtr& curve) +{ + auto waterFlow = AceType::DynamicCast(scroll_.Upgrade()); + if (!waterFlow) { + return false; + } + return waterFlow->AnimateTo(position, duration, curve); +} + +Offset WaterFlowPositionController::GetCurrentOffset() const +{ + auto waterFlow = AceType::DynamicCast(scroll_.Upgrade()); + if (!waterFlow) { + return Offset::Zero(); + } + return waterFlow->CurrentOffset(); +} + +Axis WaterFlowPositionController::GetScrollDirection() const +{ + auto waterFlow = AceType::DynamicCast(scroll_.Upgrade()); + if (!waterFlow) { + return Axis::VERTICAL; + } + return waterFlow->GetAxis(); +} + +void WaterFlowPositionController::ScrollToEdge(ScrollEdgeType scrollEdgeType, bool smooth) +{ + auto waterFlow = AceType::DynamicCast(scroll_.Upgrade()); + if (!waterFlow) { + return; + } + waterFlow->ScrollToEdge(scrollEdgeType, smooth); +} +} // namespace OHOS::Ace::V2 diff --git a/frameworks/core/components_v2/water_flow/water_flow_position_controller.h b/frameworks/core/components_v2/water_flow/water_flow_position_controller.h new file mode 100644 index 00000000000..d3f025a4246 --- /dev/null +++ b/frameworks/core/components_v2/water_flow/water_flow_position_controller.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2022 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_WATER_FLOW_POSITION_CONTROLLER_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_WATER_FLOW_POSITION_CONTROLLER_H + +#include "core/components/scroll/scroll_controller_interface.h" +#include "core/components/scroll/scrollable.h" + +namespace OHOS::Ace::V2 { +class ACE_EXPORT WaterFlowPositionController : public ScrollController { + DECLARE_ACE_TYPE(WaterFlowPositionController, ScrollController); + +public: + WaterFlowPositionController() = default; + ~WaterFlowPositionController() override = default; + Axis GetScrollDirection() const override; + + void JumpTo(int32_t index, int32_t source = SCROLL_FROM_JUMP) override; + bool AnimateTo(const Dimension& position, float duration, const RefPtr& curve) override; + void ScrollToEdge(ScrollEdgeType scrollEdgeType, bool smooth) override; + + Offset GetCurrentOffset() const override; +}; +} // namespace OHOS::Ace::V2 +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_WATER_FLOW_POSITION_CONTROLLER_H diff --git a/frameworks/core/components_v2/water_flow/water_flow_scroll_controller.cpp b/frameworks/core/components_v2/water_flow/water_flow_scroll_controller.cpp new file mode 100644 index 00000000000..f642f8b00d0 --- /dev/null +++ b/frameworks/core/components_v2/water_flow/water_flow_scroll_controller.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2022 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 "core/components_v2/water_flow/water_flow_scroll_controller.h" + +#include "core/components_v2/water_flow/render_water_flow.h" + +namespace OHOS::Ace::V2 { +void WaterFlowScrollController::MarkScrollRender() +{ + auto waterFlow = AceType::DynamicCast(scroll_.Upgrade()); + if (waterFlow) { + waterFlow->MarkNeedLayout(); + } +} + +bool WaterFlowScrollController::CheckScroll() +{ + auto waterFlow = AceType::DynamicCast(scroll_.Upgrade()); + return waterFlow != nullptr; +} + +bool WaterFlowScrollController::UpdateScrollPosition(const double offset, int32_t source) +{ + if (!callback_) { + return true; + } + auto waterFlow = AceType::DynamicCast(scroll_.Upgrade()); + if (!waterFlow || NearZero(waterFlow->GetEstimatedHeight())) { + return true; + } + double height = waterFlow->GetLayoutSize().Height(); + double estimateHeight = waterFlow->GetEstimatedHeight(); + if (NearZero(estimateHeight)) { + return false; + } + double activeHeight = height * height / estimateHeight; + if (!NearEqual(height, activeHeight)) { + if (NearZero(height)) { + return false; + } + double value = offset * estimateHeight / height; + return callback_(value, source); + } + return true; +} + +void WaterFlowScrollController::ProcessScrollMotion(double position) +{ + if (!NearEqual(currentPos_, position)) { + UpdateScrollPosition(0.0, SCROLL_FROM_ANIMATION); + } else { + if (!UpdateScrollPosition(currentPos_ - position, SCROLL_FROM_BAR)) { + dragEndAnimator_->Stop(); + } + } + currentPos_ = position; +} +} // namespace OHOS::Ace::V2 \ No newline at end of file diff --git a/frameworks/core/components_v2/water_flow/water_flow_scroll_controller.h b/frameworks/core/components_v2/water_flow/water_flow_scroll_controller.h new file mode 100644 index 00000000000..417cc97bbb7 --- /dev/null +++ b/frameworks/core/components_v2/water_flow/water_flow_scroll_controller.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2022 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_WATER_FLOW_SCROLL_CONTROLLER_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_WATER_FLOW_SCROLL_CONTROLLER_H + +#include "core/components/scroll/scroll_bar_controller.h" + +namespace OHOS::Ace::V2 { +class WaterFlowScrollController : public ScrollBarController { + DECLARE_ACE_TYPE(WaterFlowScrollController, ScrollBarController); + +public: + WaterFlowScrollController() = default; + ~WaterFlowScrollController() override = default; + + void MarkScrollRender() override; + bool CheckScroll() override; + +protected: + bool UpdateScrollPosition(double offset, int32_t source) override; + + void ProcessScrollMotion(double position) override; +}; +} // namespace OHOS::Ace::V2 +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_WATER_FLOW_SCROLL_CONTROLLER_H \ No newline at end of file From 1899b2ec86affd884a18bf0e65079e9a9f217048 Mon Sep 17 00:00:00 2001 From: h00611971 Date: Tue, 19 Apr 2022 21:12:35 +0800 Subject: [PATCH 04/35] support multi-instance in ark debugger Signed-off-by: h00611971 --- adapter/ohos/build/BUILD.gn | 5 +- adapter/ohos/build/config.gni | 2 +- adapter/ohos/entrance/ace_container.cpp | 7 +- .../pa_engine/engine/jsi/jsi_pa_engine.cpp | 2 +- .../engine/jsi/jsi_declarative_engine.cpp | 41 ++++++- .../engine/jsi/jsi_declarative_engine.h | 7 ++ .../js_frontend/engine/jsi/ark_js_runtime.cpp | 9 +- .../js_frontend/engine/jsi/ark_js_runtime.h | 3 +- .../engine/jsi/debugger/inspector.cpp | 66 +++++------ .../engine/jsi/debugger/inspector.h | 9 +- .../engine/jsi/debugger/ws_server.cpp | 42 ++++++- .../engine/jsi/debugger/ws_server.h | 7 +- .../js_frontend/engine/jsi/js_runtime.h | 2 +- .../js_frontend/engine/jsi/jsi_engine.cpp | 40 ++++++- .../js_frontend/engine/jsi/jsi_engine.h | 2 +- .../core/common/connect_server_manager.cpp | 75 +++++-------- .../core/common/connect_server_manager.h | 12 +- frameworks/core/common/debugger/BUILD.gn | 11 +- .../common/debugger/connect_inspector.cpp | 102 ++++++----------- .../core/common/debugger/connect_inspector.h | 23 +++- .../core/common/debugger/connect_server.cpp | 28 ----- .../core/common/debugger/connect_server.h | 11 +- .../core/common/debugger/unix_socket.cpp | 104 ------------------ frameworks/core/common/debugger/unix_socket.h | 40 ------- frameworks/core/common/hdc_register.cpp | 9 +- frameworks/core/common/hdc_register.h | 6 +- .../core/common/register/hdc_connect.cpp | 10 +- 27 files changed, 285 insertions(+), 390 deletions(-) delete mode 100644 frameworks/core/common/debugger/unix_socket.cpp delete mode 100644 frameworks/core/common/debugger/unix_socket.h diff --git a/adapter/ohos/build/BUILD.gn b/adapter/ohos/build/BUILD.gn index 6e849ccb350..8578cd27456 100644 --- a/adapter/ohos/build/BUILD.gn +++ b/adapter/ohos/build/BUILD.gn @@ -52,6 +52,9 @@ group("ace_packages") { "$ace_root/frameworks/bridge/js_frontend/engine/jsi/debugger:ark_debugger", ] - # pid Register + # pid register deps += [ "$ace_root/frameworks/core/common/register:hdc_register" ] + + # connect server + deps += [ "$ace_root/frameworks/core/common/debugger:connectserver_debugger" ] } diff --git a/adapter/ohos/build/config.gni b/adapter/ohos/build/config.gni index 4a7618410da..feb88ac95ab 100644 --- a/adapter/ohos/build/config.gni +++ b/adapter/ohos/build/config.gni @@ -65,7 +65,7 @@ plugin_components_support = true xcomponent_components_support = true pixel_map_support = true js_pa_support = true -connect_server_support = false +connect_server_support = true hdc_register_support = true pa_engine_path = "adapter/ohos/entrance/pa_engine" enable_rosen_backend = true diff --git a/adapter/ohos/entrance/ace_container.cpp b/adapter/ohos/entrance/ace_container.cpp index 98f01aad113..9d522f2b970 100644 --- a/adapter/ohos/entrance/ace_container.cpp +++ b/adapter/ohos/entrance/ace_container.cpp @@ -29,6 +29,7 @@ #include "base/utils/system_properties.h" #include "base/utils/utils.h" #include "core/common/ace_engine.h" +#include "core/common/connect_server_manager.h" #include "core/common/container_scope.h" #include "core/common/flutter/flutter_asset_manager.h" #include "core/common/flutter/flutter_task_executor.h" @@ -589,7 +590,8 @@ void AceContainer::CreateContainer(int32_t instanceId, FrontendType type, bool i instanceId, type, isArkApp, aceAbility, std::move(callback), useCurrentEventRunner); AceEngine::Get().AddContainer(instanceId, aceContainer); - HdcRegister::Get().StartHdcRegister(); + HdcRegister::Get().StartHdcRegister(instanceId); + ConnectServerManager::Get().AddInstance(instanceId); aceContainer->Initialize(); ContainerScope scope(instanceId); auto front = aceContainer->GetFrontend(); @@ -612,7 +614,7 @@ void AceContainer::DestroyContainer(int32_t instanceId) LOGE("no AceContainer with id %{private}d in AceEngine", instanceId); return; } - HdcRegister::Get().StopHdcRegister(); + HdcRegister::Get().StopHdcRegister(instanceId); container->Destroy(); auto taskExecutor = container->GetTaskExecutor(); if (taskExecutor) { @@ -625,6 +627,7 @@ void AceContainer::DestroyContainer(int32_t instanceId) LOGI("Remove on Platform thread..."); EngineHelper::RemoveEngine(instanceId); AceEngine::Get().RemoveContainer(instanceId); + ConnectServerManager::Get().RemoveInstance(instanceId); }, TaskExecutor::TaskType::PLATFORM); } } diff --git a/adapter/ohos/entrance/pa_engine/engine/jsi/jsi_pa_engine.cpp b/adapter/ohos/entrance/pa_engine/engine/jsi/jsi_pa_engine.cpp index e1f3f0de195..009f75d8377 100644 --- a/adapter/ohos/entrance/pa_engine/engine/jsi/jsi_pa_engine.cpp +++ b/adapter/ohos/entrance/pa_engine/engine/jsi/jsi_pa_engine.cpp @@ -290,7 +290,7 @@ bool JsiPaEngineInstance::InitJsEnv(bool debuggerMode, const std::unordered_map< if (debuggerMode) { libraryPath = ARK_DEBUGGER_LIB_PATH; } - if (!runtime_->Initialize(libraryPath, isDebugMode_)) { + if (!runtime_->Initialize(libraryPath, isDebugMode_, instanceId_)) { LOGE("JsiPaEngineInstance initialize runtime failed"); return false; } diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/jsi_declarative_engine.cpp b/frameworks/bridge/declarative_frontend/engine/jsi/jsi_declarative_engine.cpp index 28a8b6fa955..d9a537a783d 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/jsi_declarative_engine.cpp +++ b/frameworks/bridge/declarative_frontend/engine/jsi/jsi_declarative_engine.cpp @@ -22,6 +22,7 @@ #include "base/log/event_report.h" #include "core/common/ace_application_info.h" #include "core/common/ace_view.h" +#include "core/common/connect_server_manager.h" #include "core/common/container.h" #include "core/common/container_scope.h" #include "frameworks/bridge/common/utils/engine_helper.h" @@ -188,7 +189,7 @@ bool JsiDeclarativeEngineInstance::InitJsEnv(bool debuggerMode, if (debuggerMode) { libraryPath = ARK_DEBUGGER_LIB_PATH; } - if (!usingSharedRuntime_ && !runtime_->Initialize(libraryPath, isDebugMode_)) { + if (!usingSharedRuntime_ && !runtime_->Initialize(libraryPath, isDebugMode_, instanceId_)) { LOGE("Js Engine initialize runtime failed"); return false; } @@ -713,6 +714,7 @@ bool JsiDeclarativeEngine::Initialize(const RefPtr& delegate) } nativeEngine_ = nativeArkEngine; } + engineInstance_->SetInstanceId(instanceId_); engineInstance_->SetDebugMode(NeedDebugBreakPoint()); bool result = engineInstance_->InitJsEnv(IsDebugVersion(), GetExtraNativeObject(), arkRuntime); if (!result) { @@ -776,7 +778,13 @@ void JsiDeclarativeEngine::SetPostTask(NativeEngine* nativeEngine) void JsiDeclarativeEngine::RegisterInitWorkerFunc() { auto weakInstance = AceType::WeakClaim(AceType::RawPtr(engineInstance_)); - auto&& initWorkerFunc = [weakInstance](NativeEngine* nativeEngine) { + bool debugVersion = IsDebugVersion(); + bool debugMode = NeedDebugBreakPoint(); + std::string libraryPath = ""; + if (debugVersion) { + libraryPath = ARK_DEBUGGER_LIB_PATH; + } + auto&& initWorkerFunc = [weakInstance, debugMode, libraryPath](NativeEngine* nativeEngine) { LOGI("WorkerCore RegisterInitWorkerFunc called"); if (nativeEngine == nullptr) { LOGE("nativeEngine is nullptr"); @@ -792,6 +800,9 @@ void JsiDeclarativeEngine::RegisterInitWorkerFunc() LOGE("instance is nullptr"); return; } + ConnectServerManager::Get().AddInstance(gettid()); + auto vm = const_cast(arkNativeEngine->GetEcmaVm()); + panda::JSNApi::StartDebugger(libraryPath.c_str(), vm, debugMode, gettid()); instance->InitConsoleModule(arkNativeEngine); std::vector buffer((uint8_t*)_binary_jsEnumStyle_abc_start, (uint8_t*)_binary_jsEnumStyle_abc_end); @@ -803,6 +814,31 @@ void JsiDeclarativeEngine::RegisterInitWorkerFunc() nativeEngine_->SetInitWorkerFunc(initWorkerFunc); } +void JsiDeclarativeEngine::RegisterOffWorkerFunc() +{ + auto weakInstance = AceType::WeakClaim(AceType::RawPtr(engineInstance_)); + bool debugVersion = IsDebugVersion(); + auto&& offWorkerFunc = [debugVersion](NativeEngine* nativeEngine) { + LOGI("WorkerCore RegisterOffWorkerFunc called"); + if (!debugVersion) { + return; + } + if (nativeEngine == nullptr) { + LOGE("nativeEngine is nullptr"); + return; + } + auto arkNativeEngine = static_cast(nativeEngine); + if (arkNativeEngine == nullptr) { + LOGE("arkNativeEngine is nullptr"); + return; + } + ConnectServerManager::Get().RemoveInstance(gettid()); + auto vm = const_cast(arkNativeEngine->GetEcmaVm()); + panda::JSNApi::StopDebugger(vm); + }; + nativeEngine_->SetOffWorkerFunc(offWorkerFunc); +} + void JsiDeclarativeEngine::RegisterAssetFunc() { auto weakDelegate = AceType::WeakClaim(AceType::RawPtr(engineInstance_->GetDelegate())); @@ -826,6 +862,7 @@ void JsiDeclarativeEngine::RegisterAssetFunc() void JsiDeclarativeEngine::RegisterWorker() { RegisterInitWorkerFunc(); + RegisterOffWorkerFunc(); RegisterAssetFunc(); } diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/jsi_declarative_engine.h b/frameworks/bridge/declarative_frontend/engine/jsi/jsi_declarative_engine.h index ed55080da80..44e03834ca7 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/jsi_declarative_engine.h +++ b/frameworks/bridge/declarative_frontend/engine/jsi/jsi_declarative_engine.h @@ -123,6 +123,11 @@ public: isDebugMode_ = isDebugMode; } + void SetInstanceId(int32_t instanceId) + { + instanceId_ = instanceId; + } + void SetRootView(int32_t pageId, panda::Global value) { rootViewMap_.emplace(pageId, value); @@ -174,6 +179,7 @@ private: mutable std::mutex mutex_; bool isDebugMode_ = true; bool usingSharedRuntime_ = false; + int32_t instanceId_ = 0; static bool isModulePreloaded_; static bool isModuleInitialized_; static shared_ptr globalRuntime_; @@ -296,6 +302,7 @@ private: void RegisterWorker(); void RegisterInitWorkerFunc(); + void RegisterOffWorkerFunc(); void RegisterAssetFunc(); bool ExecuteAbc(const shared_ptr runtime, const std::string fileName); diff --git a/frameworks/bridge/js_frontend/engine/jsi/ark_js_runtime.cpp b/frameworks/bridge/js_frontend/engine/jsi/ark_js_runtime.cpp index 4ea41671f4e..ca92198f615 100644 --- a/frameworks/bridge/js_frontend/engine/jsi/ark_js_runtime.cpp +++ b/frameworks/bridge/js_frontend/engine/jsi/ark_js_runtime.cpp @@ -33,7 +33,7 @@ Local FunctionCallback(panda::JsiRuntimeCallInfo *info) return package->Callback(info); } -bool ArkJSRuntime::Initialize(const std::string &libraryPath, bool isDebugMode) +bool ArkJSRuntime::Initialize(const std::string &libraryPath, bool isDebugMode, int32_t instanceId) { LOGI("Ark: create jsvm"); RuntimeOption option; @@ -49,6 +49,7 @@ bool ArkJSRuntime::Initialize(const std::string &libraryPath, bool isDebugMode) option.SetDebuggerLibraryPath(libraryPath); libPath_ = libraryPath; isDebugMode_ = isDebugMode; + instanceId_ = instanceId; vm_ = JSNApi::CreateJSVM(option); return vm_ != nullptr; @@ -101,12 +102,10 @@ bool ArkJSRuntime::EvaluateJsCode(const uint8_t *buffer, int32_t size) bool ArkJSRuntime::ExecuteJsBin(const std::string &fileName) { JSExecutionScope executionScope(vm_); - static bool debugFlag = true; - if (debugFlag && !libPath_.empty()) { + if (!libPath_.empty()) { #ifndef WINDOWS_PLATFORM - JSNApi::StartDebugger(libPath_.c_str(), vm_, isDebugMode_); + JSNApi::StartDebugger(libPath_.c_str(), vm_, isDebugMode_, instanceId_); #endif - debugFlag = false; } LocalScope scope(vm_); bool ret = JSNApi::Execute(vm_, fileName, PANDA_MAIN_FUNCTION); diff --git a/frameworks/bridge/js_frontend/engine/jsi/ark_js_runtime.h b/frameworks/bridge/js_frontend/engine/jsi/ark_js_runtime.h index 876fdcd554f..4498dd2d8d7 100644 --- a/frameworks/bridge/js_frontend/engine/jsi/ark_js_runtime.h +++ b/frameworks/bridge/js_frontend/engine/jsi/ark_js_runtime.h @@ -53,7 +53,7 @@ public: #if !defined(WINDOWS_PLATFORM) bool StartDebugger(const char *libraryPath, EcmaVM *vm) const; #endif - bool Initialize(const std::string &libraryPath, bool isDebugMode) override; + bool Initialize(const std::string &libraryPath, bool isDebugMode, int32_t instanceId) override; bool InitializeFromExistVM(EcmaVM* vm); void Reset() override; void SetLogPrint(LOG_PRINT out) override; @@ -86,6 +86,7 @@ public: private: EcmaVM *vm_ = nullptr; + int32_t instanceId_ = 0; std::vector dataList_; LOG_PRINT print_ { nullptr }; UncaughtExceptionCallback uncaughtErrorHandler_ { nullptr }; diff --git a/frameworks/bridge/js_frontend/engine/jsi/debugger/inspector.cpp b/frameworks/bridge/js_frontend/engine/jsi/debugger/inspector.cpp index 3bad08b28cc..ff12f69330c 100644 --- a/frameworks/bridge/js_frontend/engine/jsi/debugger/inspector.cpp +++ b/frameworks/bridge/js_frontend/engine/jsi/debugger/inspector.cpp @@ -22,8 +22,8 @@ namespace OHOS::Ace::Framework { namespace { -std::unique_ptr g_inspector = nullptr; -void* g_handle = nullptr; +thread_local Inspector* g_inspector = nullptr; +thread_local void* g_handle = nullptr; constexpr char ARK_DEBUGGER_SHARED_LIB[] = "libark_ecma_debugger.so"; void* HandleClient(void* const server) @@ -40,8 +40,11 @@ void* HandleClient(void* const server) void* GetArkDynFunction(const char* symbol) { if (g_handle == nullptr) { - LOGE("Failed to open shared library %{public}s, reason: %{public}sn", ARK_DEBUGGER_SHARED_LIB, dlerror()); - return nullptr; + g_handle = dlopen(ARK_DEBUGGER_SHARED_LIB, RTLD_LAZY); + if (g_handle == nullptr) { + LOGE("Failed to open shared library %{public}s, reason: %{public}sn", ARK_DEBUGGER_SHARED_LIB, dlerror()); + return nullptr; + } } auto function = dlsym(g_handle, symbol); @@ -53,10 +56,11 @@ void* GetArkDynFunction(const char* symbol) void DispatchMsgToArk(int sign) { - if (g_inspector->isDispatchingMsg_) { + if (g_inspector == nullptr || g_inspector->websocketServer_ == nullptr || g_inspector->isDispatchingMsg_) { return; } - auto processMsg = reinterpret_cast(GetArkDynFunction("DispatchProtocolMessage")); + auto processMsg = reinterpret_cast( + GetArkDynFunction("DispatchProtocolMessage")); if (processMsg == nullptr) { LOGE("processMessage is empty"); return; @@ -65,7 +69,7 @@ void DispatchMsgToArk(int sign) while (!g_inspector->websocketServer_->ideMsgQueue.empty()) { const std::string message = g_inspector->websocketServer_->ideMsgQueue.front(); g_inspector->websocketServer_->ideMsgQueue.pop(); - processMsg(message); + processMsg(g_inspector->vm_, message); std::string startDebugging("Runtime.runIfWaitingForDebugger"); if (message.find(startDebugging, 0) != std::string::npos) { g_inspector->waitingForDebugger_ = false; @@ -74,40 +78,47 @@ void DispatchMsgToArk(int sign) g_inspector->isDispatchingMsg_ = false; } -void OnMessage() -{ - pthread_kill(g_inspector->tid_, SIGALRM); - return; -} - void SendReply(const std::string& message) { - if (g_inspector->websocketServer_ != nullptr) { + if (g_inspector != nullptr && g_inspector->websocketServer_ != nullptr) { g_inspector->websocketServer_->SendReply(message); } } void ResetService() { + if (g_inspector != nullptr && g_inspector->websocketServer_ != nullptr) { + g_inspector->websocketServer_->StopServer(); + delete g_inspector; + g_inspector = nullptr; + } if (g_handle != nullptr) { dlclose(g_handle); g_handle = nullptr; } - if (g_inspector->websocketServer_ != nullptr) { - g_inspector->websocketServer_->StopServer(); - g_inspector.reset(); - } } } // namespace -bool StartDebug(const std::string& componentName, void *vm, bool isDebugMode) +void Inspector::OnMessage() +{ + pthread_kill(tid_, SIGALRM); + return; +} + +void Inspector::InitializeInspector(const std::string& componentName, int32_t instanceId) +{ + websocketServer_ = std::make_unique(componentName, std::bind(&Inspector::OnMessage, this), instanceId); +} + +bool StartDebug(const std::string& componentName, void *vm, bool isDebugMode, int32_t instanceId) { LOGI("StartDebug: %{private}s", componentName.c_str()); - g_inspector = std::make_unique(); - g_inspector->websocketServer_ = std::make_unique(componentName, std::bind(&OnMessage)); + g_inspector = new Inspector(); + g_inspector->InitializeInspector(componentName, instanceId); g_inspector->tid_ = pthread_self(); g_inspector->waitingForDebugger_ = isDebugMode; + g_inspector->vm_ = vm; g_handle = dlopen(ARK_DEBUGGER_SHARED_LIB, RTLD_LAZY); if (g_handle == nullptr) { @@ -142,19 +153,12 @@ void StopDebug(const std::string& componentName) if (g_inspector == nullptr) { return; } - if (g_inspector->websocketServer_ != nullptr) { - g_inspector->websocketServer_->StopServer(); - g_inspector.reset(); - } - auto uninitialize = reinterpret_cast(GetArkDynFunction("UninitializeDebugger")); + auto uninitialize = reinterpret_cast(GetArkDynFunction("UninitializeDebugger")); if (uninitialize == nullptr) { return; } - uninitialize(); - if (g_handle != nullptr) { - dlclose(g_handle); - g_handle = nullptr; - } + uninitialize(g_inspector->vm_); + ResetService(); LOGI("StopDebug end"); } diff --git a/frameworks/bridge/js_frontend/engine/jsi/debugger/inspector.h b/frameworks/bridge/js_frontend/engine/jsi/debugger/inspector.h index ebd27bfd716..5a991820149 100644 --- a/frameworks/bridge/js_frontend/engine/jsi/debugger/inspector.h +++ b/frameworks/bridge/js_frontend/engine/jsi/debugger/inspector.h @@ -32,7 +32,7 @@ extern "C" { #endif #endif /* End of #ifdef __cplusplus */ -bool StartDebug(const std::string& componentName, void *vm, bool isDebugMode); +bool StartDebug(const std::string& componentName, void *vm, bool isDebugMode, int32_t instanceId); void StopDebug(const std::string& componentName); @@ -45,14 +45,17 @@ void StopDebug(const std::string& componentName); class Inspector { public: Inspector() = default; - ~Inspector() {} + ~Inspector() = default; + + void OnMessage(); + void InitializeInspector(const std::string& componentName, int32_t instanceId); pthread_t tid_; std::unique_ptr websocketServer_; + void *vm_ = nullptr; static constexpr int DEBUGGER_WAIT_SLEEP_TIME = 100; volatile bool waitingForDebugger_ = true; volatile bool isDispatchingMsg_ = false; - }; } // namespace OHOS::Ace::Framework diff --git a/frameworks/bridge/js_frontend/engine/jsi/debugger/ws_server.cpp b/frameworks/bridge/js_frontend/engine/jsi/debugger/ws_server.cpp index d230b2700e4..f47faf21c1d 100644 --- a/frameworks/bridge/js_frontend/engine/jsi/debugger/ws_server.cpp +++ b/frameworks/bridge/js_frontend/engine/jsi/debugger/ws_server.cpp @@ -20,22 +20,51 @@ #include #include "base/log/log.h" +thread_local boost::asio::io_context g_ioContext; namespace OHOS::Ace::Framework { +void DispatchMsgToSocket(int sign) +{ + g_ioContext.stop(); +} + void WsServer::RunServer() { terminateExecution_ = false; try { boost::asio::io_context ioContext; int appPid = getpid(); + tid_ = pthread_self(); std::string pidStr = std::to_string(appPid); - std::string sockName = '\0' + pidStr + componentName_; - LOGI("WsServer RunServer: %{public}d%{public}s", appPid, componentName_.c_str()); + std::string instanceIdStr(""); + auto& connectFlag = connectState_; + /** + * The old version of IDE is not compatible with the new images due to the connect server. + * The First instance will use "pid" instead of "pid + instanceId" to avoid this. + * If old version of IDE does not get the instanceId by connect server, it can still connect the debug server. + */ + if (instanceId_ != 0) { + instanceIdStr = std::to_string(instanceId_); + } + std::string sockName = '\0' + pidStr + instanceIdStr + componentName_; + LOGI("WsServer RunServer: %{public}d%{public}d%{public}s", appPid, instanceId_, componentName_.c_str()); localSocket::endpoint endPoint(sockName); - localSocket::socket socket(ioContext); - localSocket::acceptor acceptor(ioContext, endPoint); - acceptor.accept(socket); + localSocket::socket socket(g_ioContext); + localSocket::acceptor acceptor(g_ioContext, endPoint); + acceptor.async_accept(socket, [&connectFlag](const boost::system::error_code& error) { + if (!error) { + connectFlag = true; + } + }); + if (signal(SIGURG, &DispatchMsgToSocket) == SIG_ERR) { + LOGE("WsServer RunServer: Error exception"); + return; + } + g_ioContext.run(); + if (terminateExecution_ || !connectState_) { + return; + } webSocket_ = std::unique_ptr>( std::make_unique>(std::move(socket))); webSocket_->accept(); @@ -60,6 +89,9 @@ void WsServer::StopServer() { LOGI("WsServer StopServer"); terminateExecution_ = true; + if (!connectState_) { + pthread_kill(tid_, SIGURG); + } } void WsServer::SendReply(const std::string& message) const diff --git a/frameworks/bridge/js_frontend/engine/jsi/debugger/ws_server.h b/frameworks/bridge/js_frontend/engine/jsi/debugger/ws_server.h index d39c225c926..c78bf570fbe 100644 --- a/frameworks/bridge/js_frontend/engine/jsi/debugger/ws_server.h +++ b/frameworks/bridge/js_frontend/engine/jsi/debugger/ws_server.h @@ -32,8 +32,8 @@ using localSocket = boost::asio::local::stream_protocol; class WsServer { public: - WsServer(const std::string& component, const std::function& onMessage) - : componentName_(component), wsOnMessage_(onMessage) + WsServer(const std::string& component, const std::function& onMessage, int32_t instanceId) + : instanceId_(instanceId), componentName_(component), wsOnMessage_(onMessage) {} ~WsServer() = default; void RunServer(); @@ -42,7 +42,10 @@ public: std::queue ideMsgQueue; private: + volatile bool connectState_ {false}; volatile bool terminateExecution_ { false }; + int32_t instanceId_ {0}; + pthread_t tid_ {0}; std::string componentName_ {}; std::function wsOnMessage_ {}; std::unique_ptr> webSocket_ { nullptr }; diff --git a/frameworks/bridge/js_frontend/engine/jsi/js_runtime.h b/frameworks/bridge/js_frontend/engine/jsi/js_runtime.h index e4ecad87798..28cb081ff52 100644 --- a/frameworks/bridge/js_frontend/engine/jsi/js_runtime.h +++ b/frameworks/bridge/js_frontend/engine/jsi/js_runtime.h @@ -38,7 +38,7 @@ public: virtual ~JsRuntime() = default; // Prepare js environment, returns true if success. - virtual bool Initialize(const std::string &libraryPath, bool isDebugMode) = 0; + virtual bool Initialize(const std::string &libraryPath, bool isDebugMode, int32_t instanceId = 0) = 0; virtual void Reset() = 0; virtual void SetLogPrint(LOG_PRINT out) = 0; diff --git a/frameworks/bridge/js_frontend/engine/jsi/jsi_engine.cpp b/frameworks/bridge/js_frontend/engine/jsi/jsi_engine.cpp index 854f20a89c6..112223e4171 100644 --- a/frameworks/bridge/js_frontend/engine/jsi/jsi_engine.cpp +++ b/frameworks/bridge/js_frontend/engine/jsi/jsi_engine.cpp @@ -29,6 +29,7 @@ #include "bridge/js_frontend/engine/jsi/ark_js_runtime.h" #include "bridge/js_frontend/engine/jsi/ark_js_value.h" #include "core/common/ace_application_info.h" +#include "core/common/connect_server_manager.h" #include "core/common/container.h" #include "core/common/container_scope.h" #include "core/components/common/layout/grid_system_manager.h" @@ -2895,7 +2896,7 @@ bool JsiEngineInstance::InitJsEnv(bool debugger_mode, const std::unordered_mapInitialize(library_path, isDebugMode_)) { + if (!runtime_->Initialize(library_path, isDebugMode_, GetInstanceId())) { LOGE("Js Engine initialize runtime failed"); return false; } @@ -3103,7 +3104,13 @@ void JsiEngine::SetPostTask(NativeEngine* nativeEngine) void JsiEngine::RegisterInitWorkerFunc() { auto weakInstance = AceType::WeakClaim(AceType::RawPtr(engineInstance_)); - auto&& initWorkerFunc = [weakInstance](NativeEngine* nativeEngine) { + bool debugVersion = IsDebugVersion(); + bool debugMode = NeedDebugBreakPoint(); + std::string libraryPath = ""; + if (debugVersion) { + libraryPath = ARK_DEBUGGER_LIB_PATH; + } + auto&& initWorkerFunc = [weakInstance, debugMode, libraryPath](NativeEngine* nativeEngine) { LOGI("WorkerCore RegisterInitWorkerFunc called"); if (nativeEngine == nullptr) { LOGE("nativeEngine is nullptr"); @@ -3119,6 +3126,9 @@ void JsiEngine::RegisterInitWorkerFunc() LOGE("instance is nullptr"); return; } + ConnectServerManager::Get().AddInstance(gettid()); + auto vm = const_cast(arkNativeEngine->GetEcmaVm()); + panda::JSNApi::StartDebugger(libraryPath.c_str(), vm, debugMode, gettid()); instance->RegisterConsoleModule(arkNativeEngine); // load jsfwk if (!arkNativeEngine->ExecuteJsBin("/system/etc/strip.native.min.abc")) { @@ -3128,6 +3138,31 @@ void JsiEngine::RegisterInitWorkerFunc() nativeEngine_->SetInitWorkerFunc(initWorkerFunc); } +void JsiEngine::RegisterOffWorkerFunc() +{ + auto weakInstance = AceType::WeakClaim(AceType::RawPtr(engineInstance_)); + bool debugVersion = IsDebugVersion(); + auto&& offWorkerFunc = [debugVersion](NativeEngine* nativeEngine) { + LOGI("WorkerCore RegisterOffWorkerFunc called"); + if (!debugVersion) { + return; + } + if (nativeEngine == nullptr) { + LOGE("nativeEngine is nullptr"); + return; + } + auto arkNativeEngine = static_cast(nativeEngine); + if (arkNativeEngine == nullptr) { + LOGE("arkNativeEngine is nullptr"); + return; + } + ConnectServerManager::Get().RemoveInstance(gettid()); + auto vm = const_cast(arkNativeEngine->GetEcmaVm()); + panda::JSNApi::StopDebugger(vm); + }; + nativeEngine_->SetOffWorkerFunc(offWorkerFunc); +} + void JsiEngine::RegisterAssetFunc() { auto weakDelegate = AceType::WeakClaim(AceType::RawPtr(engineInstance_->GetDelegate())); @@ -3151,6 +3186,7 @@ void JsiEngine::RegisterAssetFunc() void JsiEngine::RegisterWorker() { RegisterInitWorkerFunc(); + RegisterOffWorkerFunc(); RegisterAssetFunc(); } diff --git a/frameworks/bridge/js_frontend/engine/jsi/jsi_engine.h b/frameworks/bridge/js_frontend/engine/jsi/jsi_engine.h index 8fe3a509736..e01a9ec4e9a 100644 --- a/frameworks/bridge/js_frontend/engine/jsi/jsi_engine.h +++ b/frameworks/bridge/js_frontend/engine/jsi/jsi_engine.h @@ -66,7 +66,6 @@ public: #if defined(WINDOWS_PLATFORM) || defined(MAC_PLATFORM) bool CallCurlFunction(const OHOS::Ace::RequestData& requestData, int32_t callbackId); #endif - void SetArkNativeEngine(ArkNativeEngine* nativeEngine) { nativeEngine_ = nativeEngine; @@ -174,6 +173,7 @@ private: void GetLoadOptions(std::string& optionStr, bool isMainPage, bool hasAppCode); void RegisterWorker(); void RegisterInitWorkerFunc(); + void RegisterOffWorkerFunc(); void RegisterAssetFunc(); bool CallAppFunc(const std::string& appFuncName); bool CallAppFunc(const std::string& appFuncName, std::vector>& argv); diff --git a/frameworks/core/common/connect_server_manager.cpp b/frameworks/core/common/connect_server_manager.cpp index 7b55ea6c11a..477ac4857c4 100644 --- a/frameworks/core/common/connect_server_manager.cpp +++ b/frameworks/core/common/connect_server_manager.cpp @@ -26,27 +26,24 @@ namespace OHOS::Ace { namespace { -using StartServer = bool (*)(const std::string& packageName, const bool flagNeedDebugBreakPoint); -using StartUnixSocket = void (*)(const std::string& packageName); +using StartServer = bool (*)(const std::string& packageName); using SendMessage = void (*)(const std::string& message); using StopServer = void (*)(const std::string& packageName); -using AddMessage = void (*)(const int32_t instanceId, const std::string& message); -using RemoveMessage = void (*)(const int32_t instanceId); -using IsAttachStart = bool (*)(); +using StoreMessage = void (*)(int32_t instanceId, const std::string& message); +using RemoveMessage = void (*)(int32_t instanceId); +using WaitForDebugger = bool (*)(); } // namespace -ConnectServerManager::ConnectServerManager(): isNeedDebugBreakPoint_(false), handlerConnectServerSo_(nullptr) +ConnectServerManager::ConnectServerManager(): handlerConnectServerSo_(nullptr) { isDebugVersion_ = AceApplicationInfo::GetInstance().IsDebugVersion(); if (!isDebugVersion_) { return; } - isNeedDebugBreakPoint_ = AceApplicationInfo::GetInstance().IsNeedDebugBreakPoint(); packageName_ = AceApplicationInfo::GetInstance().GetPackageName(); - OpenConnectServerSo(); + LoadConnectServerSo(); StartConnectServer(); - StartHdcSocket(); } ConnectServerManager::~ConnectServerManager() @@ -64,7 +61,7 @@ ConnectServerManager& ConnectServerManager::Get() return connectServerManager; } -void ConnectServerManager::OpenConnectServerSo() +void ConnectServerManager::LoadConnectServerSo() { const std::string soDir = "libconnectserver_debugger.z.so"; handlerConnectServerSo_ = dlopen(soDir.c_str(), RTLD_LAZY); @@ -94,7 +91,7 @@ void ConnectServerManager::StartConnectServer() LOGE("startServer = NULL, dlerror = %s", dlerror()); return; } - startServer(packageName_, isNeedDebugBreakPoint_); + startServer(packageName_); } void ConnectServerManager::StopConnectServer() @@ -112,24 +109,9 @@ void ConnectServerManager::StopConnectServer() stopServer(packageName_); } -void ConnectServerManager::StartHdcSocket() +void ConnectServerManager::AddInstance(int32_t instanceId, const std::string& instanceName) { - LOGI("Start HDC registration with unix socket"); - if (handlerConnectServerSo_ == nullptr) { - LOGE("handlerConnectServerSo_ is null"); - return; - } - StartUnixSocket startUnixSocket = (StartUnixSocket)dlsym(handlerConnectServerSo_, "StartUnixSocket"); - if (startUnixSocket == nullptr) { - LOGE("startUnixSocket = NULL, dlerror = %s", dlerror()); - return; - } - startUnixSocket(packageName_); -} - -void ConnectServerManager::AddInstance(const int32_t instanceId, const std::string instanceName) -{ - if (!isDebugVersion_) { + if (!isDebugVersion_ || handlerConnectServerSo_ == nullptr) { return; } LOGI("AddInstance %{public}d", instanceId); @@ -144,34 +126,31 @@ void ConnectServerManager::AddInstance(const int32_t instanceId, const std::stri // Get the message including information of new instance, which will be send to IDE. std::string message = GetInstanceMapMessage("addInstance", instanceId); - if (handlerConnectServerSo_ == nullptr) { - LOGE("handlerConnectServerSo_ is null"); + WaitForDebugger waitForDebugger = (WaitForDebugger)dlsym(handlerConnectServerSo_, "WaitForDebugger"); + if (waitForDebugger == nullptr) { return; } - IsAttachStart isAttachStart = (IsAttachStart)dlsym(handlerConnectServerSo_, "IsAttachStart"); - if (isAttachStart != nullptr) { - isNeedDebugBreakPoint_ = isNeedDebugBreakPoint_ || isAttachStart(); - } - if (isNeedDebugBreakPoint_) { + if (!waitForDebugger()) { // waitForDebugger : waitForDebugger means the connection state of the connect server AceApplicationInfo::GetInstance().SetNeedDebugBreakPoint(true); SendMessage sendMessage = (SendMessage)dlsym(handlerConnectServerSo_, "SendMessage"); if (sendMessage != nullptr) { - sendMessage(message); + sendMessage(message); // if connected, message will be sent immediately. } - } else { - AddMessage addMessage = (AddMessage)dlsym(handlerConnectServerSo_, "AddMessage"); - if (addMessage != nullptr) { - addMessage(instanceId, message); + } else { // if not connected, message will be stored and sent later when "connected" coming. + StoreMessage storeMessage = (StoreMessage)dlsym(handlerConnectServerSo_, "StoreMessage"); + if (storeMessage != nullptr) { + storeMessage(instanceId, message); } } } -void ConnectServerManager::RemoveInstance(const int32_t instanceId) +void ConnectServerManager::RemoveInstance(int32_t instanceId) { - if (!isDebugVersion_) { + if (!isDebugVersion_ || handlerConnectServerSo_ == nullptr) { return; } LOGI("RemoveInstance %{public}d", instanceId); + // Get the message including information of deleted instance, which will be send to IDE. std::string message = GetInstanceMapMessage("destroyInstance", instanceId); size_t numInstance = 0; @@ -183,15 +162,11 @@ void ConnectServerManager::RemoveInstance(const int32_t instanceId) LOGW("Instance name not found with instance id: %{public}d", instanceId); } - if (handlerConnectServerSo_ == nullptr) { - LOGE("handlerConnectServerSo_ is null"); + WaitForDebugger waitForDebugger = (WaitForDebugger)dlsym(handlerConnectServerSo_, "WaitForDebugger"); + if (waitForDebugger == nullptr) { return; } - IsAttachStart isAttachStart = (IsAttachStart)dlsym(handlerConnectServerSo_, "IsAttachStart"); - if (isAttachStart != nullptr) { - isNeedDebugBreakPoint_ = isNeedDebugBreakPoint_ || isAttachStart(); - } - if (isNeedDebugBreakPoint_) { + if (!waitForDebugger()) { SendMessage sendMessage = (SendMessage)dlsym(handlerConnectServerSo_, "SendMessage"); if (sendMessage != nullptr) { sendMessage(message); @@ -204,7 +179,7 @@ void ConnectServerManager::RemoveInstance(const int32_t instanceId) } } -std::string ConnectServerManager::GetInstanceMapMessage(const char* messageType, const int32_t instanceId) +std::string ConnectServerManager::GetInstanceMapMessage(const char* messageType, int32_t instanceId) { auto message = JsonUtil::Create(true); message->Put("type", messageType); diff --git a/frameworks/core/common/connect_server_manager.h b/frameworks/core/common/connect_server_manager.h index 9183d7ced95..2bad96bebcb 100644 --- a/frameworks/core/common/connect_server_manager.h +++ b/frameworks/core/common/connect_server_manager.h @@ -25,25 +25,23 @@ namespace OHOS::Ace { -class ConnectServerManager { +class ACE_EXPORT ConnectServerManager { public: ~ConnectServerManager(); static ConnectServerManager& Get(); - void AddInstance(const int32_t instanceId, const std::string instanceName); - void RemoveInstance(const int32_t instanceId); + void AddInstance(int32_t instanceId, const std::string& instanceName = "PandaDebugger"); + void RemoveInstance(int32_t instanceId); private: ConnectServerManager(); - void OpenConnectServerSo(); + void LoadConnectServerSo(); void CloseConnectServerSo(); void StartConnectServer(); void StopConnectServer(); - void StartHdcSocket(); - std::string GetInstanceMapMessage(const char* messageType, const int32_t instanceId); + std::string GetInstanceMapMessage(const char* messageType, int32_t instanceId); mutable std::mutex mutex_; bool isDebugVersion_; - bool isNeedDebugBreakPoint_; void* handlerConnectServerSo_; std::string packageName_; std::unordered_map instanceMap_; diff --git a/frameworks/core/common/debugger/BUILD.gn b/frameworks/core/common/debugger/BUILD.gn index 89e7ef3c8d4..14574380730 100644 --- a/frameworks/core/common/debugger/BUILD.gn +++ b/frameworks/core/common/debugger/BUILD.gn @@ -31,14 +31,9 @@ ohos_shared_library("connectserver_debugger") { "BOOST_CLANG", ] - defines += ace_common_defines + defines += [ "ACE_LOG_TAG=\"ConnectServer\"" ] - external_deps = [ "hilog:libhilog" ] - - deps += [ - "//third_party/boost:boost", - "//utils/native/base:utilsecurec", - ] + external_deps = hilog_deps include_dirs = [ "$ace_root", @@ -46,14 +41,12 @@ ohos_shared_library("connectserver_debugger") { "$ace_root/frameworks/core/common/debugger", "//third_party/boost", "//third_party/boost/boost", - "//utils/native/base/include", ] sources = [ "$ace_root/adapter/ohos/osal/log_wrapper.cpp", "connect_inspector.cpp", "connect_server.cpp", - "unix_socket.cpp", ] configs = [ ":connectserver_debugger_config" ] diff --git a/frameworks/core/common/debugger/connect_inspector.cpp b/frameworks/core/common/debugger/connect_inspector.cpp index ddfe8b97a34..432bb4b536b 100644 --- a/frameworks/core/common/debugger/connect_inspector.cpp +++ b/frameworks/core/common/debugger/connect_inspector.cpp @@ -15,13 +15,9 @@ #include "frameworks/core/common/debugger/connect_inspector.h" #include "base/log/log.h" -#include "frameworks/core/common/debugger/connect_server.h" + namespace OHOS::Ace { -std::unique_ptr g_connectServer = nullptr; -void* g_debugger = nullptr; -std::map g_infoBuffer; -bool g_isAttachStart = false; -int g_ideWaitTime = 100; +std::unique_ptr g_inspector = nullptr; void* HandleDebugManager(void* const server) { @@ -34,18 +30,6 @@ void* HandleDebugManager(void* const server) return nullptr; } -void* HandleHDC(void* const server) -{ - LOGI("HandleHDC"); - if (server == nullptr) { - LOGE("HandleHDC server nullptr"); - return nullptr; - } - int32_t pid = getpid(); - static_cast(server)->Register(pid); - return nullptr; -} - void OnMessage(const std::string& message) { if (message.empty()) { @@ -57,18 +41,10 @@ void OnMessage(const std::string& message) std::string checkMessage = "connected"; if (message.find(checkMessage, 0) != std::string::npos) { LOGI("Find the targeted string: %{private}s", message.c_str()); - if (g_connectServer != nullptr) { - g_connectServer->waitingForDebugger_ = false; - } - } - - checkMessage = "attachStart"; - if (message.find(checkMessage, 0) != std::string::npos) { - LOGI("Find the attach command: %{private}s", message.c_str()); - g_isAttachStart = true; - if (g_connectServer != nullptr) { - for (auto it = g_infoBuffer.begin(); it != g_infoBuffer.end(); it++) { - g_connectServer->SendMessage(it->second); + if (g_inspector != nullptr) { + g_inspector->waitingForDebugger_ = false; + for (auto &info : g_inspector->infoBuffer_) { + SendMessage(info.second); } } } @@ -76,86 +52,70 @@ void OnMessage(const std::string& message) void ResetService() { - if (g_connectServer != nullptr) { - g_connectServer->StopServer(); - g_connectServer.reset(); + if (g_inspector != nullptr && g_inspector->connectServer_ != nullptr) { + g_inspector->connectServer_->StopServer(); + g_inspector->connectServer_.reset(); } } -void StartServer(const std::string& componentName, const bool flagNeedDebugBreakPoint) +void StartServer(const std::string& componentName) { LOGI("StartServer: %{private}s", componentName.c_str()); - g_connectServer = std::make_unique(componentName, std::bind(&OnMessage, std::placeholders::_1), - flagNeedDebugBreakPoint); + g_inspector = std::make_unique(); + g_inspector->connectServer_ = std::make_unique(componentName, + std::bind(&OnMessage, std::placeholders::_1)); + pthread_t tid; - if (pthread_create(&tid, nullptr, &HandleDebugManager, static_cast(g_connectServer.get())) != 0) { + if (pthread_create(&tid, nullptr, &HandleDebugManager, + static_cast(g_inspector->connectServer_.get())) != 0) { LOGE("pthread_create fail!"); ResetService(); return; } - - while (g_connectServer->waitingForDebugger_) { - usleep(g_ideWaitTime); - } - LOGI("StartServer connected."); -} - -void StartUnixSocket(const std::string& componentName) -{ - LOGI("StartUnixSocket: %{private}s", componentName.c_str()); - while (g_connectServer == nullptr) { - LOGI("Waiting for the Connect Server"); - usleep(g_ideWaitTime); - } - LOGI("pid is %{private}d", getpid()); - pthread_t tid; - if (pthread_create(&tid, nullptr, &HandleHDC, static_cast(g_connectServer.get())) != 0) { - LOGE("pthread_create fail!"); - return; - } + LOGI("StartServer Continue."); } void StopServer(const std::string& componentName) { LOGI("StopServer: %{private}s", componentName.c_str()); - if (g_connectServer != nullptr) { - g_connectServer->StopServer(); - g_connectServer.reset(); - } + ResetService(); LOGI("StopServer end"); } -void AddMessage(const int32_t instanceId, const std::string& message) +void StoreMessage(int32_t instanceId, const std::string& message) { LOGI("Add message to information buffer."); - if (g_infoBuffer.count(instanceId) == 1) { + if (g_inspector->infoBuffer_.count(instanceId) == 1) { LOGE("The message with the current instance id has been existed."); return; } - g_infoBuffer[instanceId] = message; + g_inspector->infoBuffer_[instanceId] = message; } -void RemoveMessage(const int32_t instanceId) +void RemoveMessage(int32_t instanceId) { LOGI("Remove message from information buffer."); - if (g_infoBuffer.count(instanceId) != 1) { + if (g_inspector->infoBuffer_.count(instanceId) != 1) { LOGE("The message with the current instance id does not exist."); return; } - g_infoBuffer.erase(instanceId); + g_inspector->infoBuffer_.erase(instanceId); } void SendMessage(const std::string& message) { LOGI("Enter SendMessage"); - if (g_connectServer != nullptr) { - g_connectServer->SendMessage(message); + if (g_inspector != nullptr && g_inspector->connectServer_ != nullptr && !g_inspector->waitingForDebugger_) { + g_inspector->connectServer_->SendMessage(message); } } -bool IsAttachStart() +bool WaitForDebugger() { - return g_isAttachStart; + if (g_inspector == nullptr) { + return true; + } + return g_inspector->waitingForDebugger_; } } // namespace OHOS::Ace diff --git a/frameworks/core/common/debugger/connect_inspector.h b/frameworks/core/common/debugger/connect_inspector.h index a1efd09cba9..fb1b64404bd 100644 --- a/frameworks/core/common/debugger/connect_inspector.h +++ b/frameworks/core/common/debugger/connect_inspector.h @@ -17,7 +17,9 @@ #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_DEBUGGER_CONNECT_INSPECTOR_H #include +#include +#include "frameworks/core/common/debugger/connect_server.h" namespace OHOS::Ace { #ifdef __cplusplus #if __cplusplus @@ -25,25 +27,34 @@ extern "C" { #endif #endif /* End of #ifdef __cplusplus */ -void StartServer(const std::string& componentName, const bool flagNeedDebugBreakPoint); - -void StartUnixSocket(const std::string& componentName); +void StartServer(const std::string& componentName); void StopServer(const std::string& componentName); void SendMessage(const std::string& message); -void AddMessage(const int32_t instanceId, const std::string& message); +void StoreMessage(int32_t instanceId, const std::string& message); -void RemoveMessage(const int32_t instanceId); +void RemoveMessage(int32_t instanceId); -bool IsAttachStart(); +bool WaitForDebugger(); #ifdef __cplusplus #if __cplusplus } #endif #endif /* End of #ifdef __cplusplus */ + +class ConnectInspector { +public: + ConnectInspector() = default; + ~ConnectInspector() = default; + + std::string componentName_ {}; + std::unordered_map infoBuffer_; + std::unique_ptr connectServer_; + volatile bool waitingForDebugger_ = true; +}; } // namespace OHOS::Ace #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_DEBUGGER_CONNECT_INSPECTOR_H diff --git a/frameworks/core/common/debugger/connect_server.cpp b/frameworks/core/common/debugger/connect_server.cpp index ddee5fb60cb..dce1067070a 100644 --- a/frameworks/core/common/debugger/connect_server.cpp +++ b/frameworks/core/common/debugger/connect_server.cpp @@ -17,13 +17,10 @@ #include #include #include -#include #include #include "base/log/log.h" -#include "frameworks/core/common/debugger/unix_socket.h" namespace OHOS::Ace { -std::unique_ptr g_unixSocket = nullptr; void ConnectServer::RunServer() { @@ -83,29 +80,4 @@ void ConnectServer::SendMessage(const std::string& message) const } } -void ConnectServer::WaitMessage() const -{ - beast::flat_buffer buffer; - webSocket_->read(buffer); - std::string message = boost::beast::buffers_to_string(buffer.data()); - LOGI("receive msg from Debug Manager message=%s", message.c_str()); - wsOnMessage_(std::move(message)); -} - -void ConnectServer::Register(int32_t pid) -{ - g_unixSocket = std::make_unique(); - int connRes = g_unixSocket->UnixSocketConn(); - if (connRes < 0) { - return; - } - LOGI("Unix Socket Connect Successfully"); - int res = g_unixSocket->SendMessage(pid); - if (res < 0) { - LOGE("Register Failed!"); - return; - } - LOGI("Register Successfully!"); -} - } // namespace OHOS::Ace diff --git a/frameworks/core/common/debugger/connect_server.h b/frameworks/core/common/debugger/connect_server.h index 9a4f422cc5b..8ff517618d3 100644 --- a/frameworks/core/common/debugger/connect_server.h +++ b/frameworks/core/common/debugger/connect_server.h @@ -30,18 +30,13 @@ using localSocket = boost::asio::local::stream_protocol; class ConnectServer { public: - ConnectServer(const std::string& bundle, std::function onMessage, bool flagNeedDebugBreakPoint) - : bundleName_(bundle), wsOnMessage_(std::move(onMessage)) - { - waitingForDebugger_ = flagNeedDebugBreakPoint; - } + ConnectServer(const std::string& bundleName, std::function onMessage) + : bundleName_(bundleName), wsOnMessage_(std::move(onMessage)) + {} ~ConnectServer() = default; void RunServer(); void StopServer(); void SendMessage(const std::string& message) const; - void WaitMessage() const; - void Register(int32_t pid); - bool waitingForDebugger_; private: volatile bool terminateExecution_ = false; diff --git a/frameworks/core/common/debugger/unix_socket.cpp b/frameworks/core/common/debugger/unix_socket.cpp deleted file mode 100644 index 120884340a8..00000000000 --- a/frameworks/core/common/debugger/unix_socket.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2021 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/core/common/debugger/unix_socket.h" - -#include -#include -#include - -#include "base/log/log.h" -#include "securec.h" - -namespace OHOS::Ace { -static constexpr uint32_t SLEEP_TIME_MS = 500U; -static constexpr int CONTROL_SOCK_SEND_TIMEOUT = 10U; - -int32_t UnixSocketClient::UnixSocketConn() -{ - uint32_t sleep_ms = SLEEP_TIME_MS; - const uint32_t SLEEP_MAX_MS = 4 * SLEEP_TIME_MS; - control_sock = TEMP_FAILURE_RETRY(socket(AF_UNIX, SOCK_STREAM, 0)); - if (control_sock < 0) { - LOGE("Could not create control socket"); - return FAIL_CAUSE_SOCKET_NO_CLIENT; - } - errno_t errRet = memset_s(&controlAddrUn, sizeof(controlAddrUn), 0, sizeof(controlAddrUn)); - if (errRet != EOK) { - LOGE("Socket memset_s fail"); - return FAIL_CAUSE_SOCKET_NO_CLIENT; - } - controlAddrUn.sun_family = AF_UNIX; - errno_t errNum = memcpy_s(controlAddrUn.sun_path, JDWP_CONTROL_NAME_LEN, JDWP_CONTROL_NAME, JDWP_CONTROL_NAME_LEN); - if (errNum != EOK) { - LOGE("Socket memcpy_s fail"); - return FAIL_CAUSE_SOCKET_NO_CLIENT; - } - control_addr_len = sizeof(controlAddrUn.sun_family) + JDWP_CONTROL_NAME_LEN; - int keepalive = 1; - setsockopt(control_sock, SOL_SOCKET, SO_KEEPALIVE, (void *)&keepalive, sizeof(keepalive)); - while (true) { - int ret = TEMP_FAILURE_RETRY(connect(control_sock, (struct sockaddr *)&controlAddrUn, control_addr_len)); - if (ret >= 0) { - LOGI("Connect Successful"); - return SOCKET_SUCCESS; - } - const int sleep_times = 2; - usleep(sleep_ms * SLEEP_TIME_MS * sleep_times); - sleep_ms += (sleep_ms >> 1); - if (sleep_ms > SLEEP_MAX_MS) { - sleep_ms = SLEEP_MAX_MS; - } - return FAIL_CAUSE_SOCKET_COMMON_FAIL; - } - return FAIL_CAUSE_SOCKET_COMMON_FAIL; -} - -int32_t UnixSocketClient::SendMessage(int32_t pid) -{ - std::string pidStr = std::to_string(pid); - int pidSize = pidStr.size(); - int buffSize = pidSize + 1; - char buff[buffSize]; - if (control_sock < 0) { - LOGE("Error Occur!"); - return FAIL_CAUSE_SEND_MSG_FAIL; - } - errno_t errRet = strncpy_s(buff, buffSize, pidStr.c_str(), pidSize); - if (errRet != EOK) { - LOGE("Send Message fail"); - return FAIL_CAUSE_SEND_MSG_FAIL; - } - struct timeval timeout { - }; - timeout.tv_sec = CONTROL_SOCK_SEND_TIMEOUT; - timeout.tv_usec = 0; - setsockopt(control_sock, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout)); - int ret = TEMP_FAILURE_RETRY(send(control_sock, buff, pidSize, 0)); - if (ret >= 0) { - LOGI("PID sent as '%s' to HDC", buff); - return SOCKET_SUCCESS; - } - LOGE("Weird, can't send JDWP process pid to HDC"); - return FAIL_CAUSE_SEND_MSG_FAIL; -} - -void UnixSocketClient::UnixSocketClose() -{ - close(control_sock); -} - -} // namespace OHOS::Ace - diff --git a/frameworks/core/common/debugger/unix_socket.h b/frameworks/core/common/debugger/unix_socket.h deleted file mode 100644 index 9496126586f..00000000000 --- a/frameworks/core/common/debugger/unix_socket.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2021-2022 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_DEBUGGER_UNIX_SOCKET_H -#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_DEBUGGER_UNIX_SOCKET_H -#define FAIL_CAUSE_SOCKET_NO_CLIENT (-1003) -#define FAIL_CAUSE_SOCKET_COMMON_FAIL (-1004) -#define FAIL_CAUSE_SEND_MSG_FAIL (-1005) -#define JDWP_CONTROL_NAME "\0jdwp-control" -#define JDWP_CONTROL_NAME_LEN (sizeof(JDWP_CONTROL_NAME)-1) -#define SOCKET_SUCCESS 0 - -#include -namespace OHOS::Ace { -class UnixSocketClient { -public: - UnixSocketClient() = default; - ~UnixSocketClient() {} - int32_t UnixSocketConn(); - int32_t SendMessage(int32_t pid); - void UnixSocketClose(); -private: - int32_t control_sock = -1; - struct sockaddr_un controlAddrUn; - int32_t control_addr_len; -}; - -} // namespace OHOS::Ace -#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_DEBUGGER_UNIX_SOCKET_H diff --git a/frameworks/core/common/hdc_register.cpp b/frameworks/core/common/hdc_register.cpp index 1935d38f3dd..0b19343cb3f 100644 --- a/frameworks/core/common/hdc_register.cpp +++ b/frameworks/core/common/hdc_register.cpp @@ -56,13 +56,16 @@ void HdcRegister::LoadRegisterSo() } } -void HdcRegister::StartHdcRegister() +void HdcRegister::StartHdcRegister(int32_t instanceId) { LOGI("Start Hdc Register"); if (registerHandler_ == nullptr) { LOGE("registerHandler_ is null"); return; } + if (instanceId != 0) { + return; // Applications and abilities should only call this function once, especially in multi-instance. + } StartRegister startRegister = (StartRegister)dlsym(registerHandler_, "StartConnect"); if (startRegister == nullptr) { LOGE("startRegister = NULL, dlerror = %s", dlerror()); @@ -71,9 +74,9 @@ void HdcRegister::StartHdcRegister() startRegister(pkgName_); } -void HdcRegister::StopHdcRegister() +void HdcRegister::StopHdcRegister(int32_t instanceId) { - if (!isDebugVersion_) { + if (!isDebugVersion_ || instanceId != 0) { return; } LOGI("Stop Hdc Register"); diff --git a/frameworks/core/common/hdc_register.h b/frameworks/core/common/hdc_register.h index fe5d8dc8ede..1abd15d3f84 100644 --- a/frameworks/core/common/hdc_register.h +++ b/frameworks/core/common/hdc_register.h @@ -26,13 +26,13 @@ namespace OHOS::Ace { class HdcRegister { public: - HdcRegister(); ~HdcRegister() = default; static HdcRegister& Get(); - void StartHdcRegister(); - void StopHdcRegister(); + void StartHdcRegister(int32_t instanceId); + void StopHdcRegister(int32_t instanceId); private: + HdcRegister(); void LoadRegisterSo(); bool isDebugVersion_; diff --git a/frameworks/core/common/register/hdc_connect.cpp b/frameworks/core/common/register/hdc_connect.cpp index b0ad5b44e56..ebd20aeb2ec 100644 --- a/frameworks/core/common/register/hdc_connect.cpp +++ b/frameworks/core/common/register/hdc_connect.cpp @@ -93,10 +93,11 @@ bool TryCloseLoop(uv_loop_t *ptrLoop, const char *callerName) void FreeInstance() { - if (clsHdcJdwpSimulator != nullptr) { - delete clsHdcJdwpSimulator; - clsHdcJdwpSimulator = nullptr; + if (clsHdcJdwpSimulator == nullptr) { + return; // if clsHdcJdwpSimulator is nullptr, should return immediately. } + delete clsHdcJdwpSimulator; + clsHdcJdwpSimulator = nullptr; uv_stop(&loopMain); TryCloseLoop(&loopMain, "Hdcjdwp exit"); LOGI("jdwp_process exit."); @@ -134,6 +135,9 @@ void* HdcConnectRun(void* pkgContent) void StartConnect(const std::string& pkgName) { + if (clsHdcJdwpSimulator != nullptr) { + return; + } pthread_t tid; g_connectManagement = std::make_unique(); g_connectManagement->SetPkgName(pkgName); From 02ee5e4d00c003a070d3bde7943e16708775aa22 Mon Sep 17 00:00:00 2001 From: zhangalong Date: Thu, 5 May 2022 16:03:13 +0800 Subject: [PATCH 05/35] change os_account_standard to os_account Signed-off-by:zhang_along Signed-off-by: zhangalong --- ace_config.gni | 2 +- frameworks/core/components/plugin/BUILD.gn | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ace_config.gni b/ace_config.gni index 9f9ee15fdad..9992b1b378f 100644 --- a/ace_config.gni +++ b/ace_config.gni @@ -128,7 +128,7 @@ if (enable_dump_drawcmd) { } if (!defined(global_parts_info) || - defined(global_parts_info.account_os_account_standard)) { + defined(global_parts_info.account_os_account)) { os_account_exists = true ace_common_defines += [ "OS_ACCOUNT_EXISTS" ] } else { diff --git a/frameworks/core/components/plugin/BUILD.gn b/frameworks/core/components/plugin/BUILD.gn index b13ef536987..5b081db420e 100644 --- a/frameworks/core/components/plugin/BUILD.gn +++ b/frameworks/core/components/plugin/BUILD.gn @@ -56,7 +56,7 @@ build_component("plugin") { ] if (os_account_exists) { - external_deps += [ "os_account_standard:os_account_innerkits" ] + external_deps += [ "os_account:os_account_innerkits" ] } } } From 80cfeb27dfca89f7ad49b64e89543e3add51edb6 Mon Sep 17 00:00:00 2001 From: zcdqs Date: Thu, 5 May 2022 17:22:37 +0800 Subject: [PATCH 06/35] dump components count by page Signed-off-by: zcdqs Change-Id: Ifc98680f418d9d78fda66b48be5299f1f763eeac --- frameworks/bridge/common/dom/dom_document.h | 5 +++++ .../declarative_frontend.cpp | 1 + .../frontend_delegate_declarative.cpp | 10 +++++++++ .../frontend_delegate_declarative.h | 1 + .../bridge/js_frontend/frontend_delegate.h | 2 ++ .../js_frontend/frontend_delegate_impl.cpp | 17 ++++++++++++++ .../js_frontend/frontend_delegate_impl.h | 1 + frameworks/bridge/js_frontend/js_frontend.cpp | 1 + .../plugin_frontend/plugin_frontend.cpp | 1 + .../plugin_frontend_delegate.cpp | 10 +++++++++ .../plugin_frontend_delegate.h | 1 + .../core/components/page/page_element.cpp | 22 +++++++++++++++++++ .../core/components/page/page_element.h | 1 + frameworks/core/pipeline/pipeline_context.cpp | 1 - 14 files changed, 73 insertions(+), 1 deletion(-) diff --git a/frameworks/bridge/common/dom/dom_document.h b/frameworks/bridge/common/dom/dom_document.h index 9777ccbd6dc..eb903acbee1 100644 --- a/frameworks/bridge/common/dom/dom_document.h +++ b/frameworks/bridge/common/dom/dom_document.h @@ -56,6 +56,11 @@ public: return (domNode == nullptr) ? nullptr : domNode->GetRootComponent(); } + size_t GetComponentsCount() const + { + return domNodes_.size(); + } + const RefPtr& GetRootStackComponent() const { return rootStackComponent_; diff --git a/frameworks/bridge/declarative_frontend/declarative_frontend.cpp b/frameworks/bridge/declarative_frontend/declarative_frontend.cpp index 5ddb28abae7..b10c1368601 100644 --- a/frameworks/bridge/declarative_frontend/declarative_frontend.cpp +++ b/frameworks/bridge/declarative_frontend/declarative_frontend.cpp @@ -802,6 +802,7 @@ void DeclarativeFrontend::DumpFrontend() const delegate_->GetState(routerIndex, routerName, routerPath); if (DumpLog::GetInstance().GetDumpFile()) { + DumpLog::GetInstance().AddDesc("Components: " + std::to_string(delegate_->GetComponentsCount())); DumpLog::GetInstance().AddDesc("Path: " + routerPath); DumpLog::GetInstance().AddDesc("Length: " + std::to_string(routerIndex)); DumpLog::GetInstance().Print(0, routerName, 0); diff --git a/frameworks/bridge/declarative_frontend/frontend_delegate_declarative.cpp b/frameworks/bridge/declarative_frontend/frontend_delegate_declarative.cpp index 0a7b2020aef..0ebc450a00a 100644 --- a/frameworks/bridge/declarative_frontend/frontend_delegate_declarative.cpp +++ b/frameworks/bridge/declarative_frontend/frontend_delegate_declarative.cpp @@ -919,6 +919,16 @@ void FrontendDelegateDeclarative::GetState(int32_t& index, std::string& name, st } } +size_t FrontendDelegateDeclarative::GetComponentsCount() +{ + auto pipelineContext = pipelineContextHolder_.Get(); + const auto& pageElement = pipelineContext->GetLastPage(); + if (pageElement) { + return pageElement->GetComponentsCount(); + } + return 0; +} + std::string FrontendDelegateDeclarative::GetParams() { if (pageParamMap_.find(pageId_) != pageParamMap_.end()) { diff --git a/frameworks/bridge/declarative_frontend/frontend_delegate_declarative.h b/frameworks/bridge/declarative_frontend/frontend_delegate_declarative.h index 9d84860439e..f5711e1422b 100644 --- a/frameworks/bridge/declarative_frontend/frontend_delegate_declarative.h +++ b/frameworks/bridge/declarative_frontend/frontend_delegate_declarative.h @@ -137,6 +137,7 @@ public: void Clear() override; int32_t GetStackSize() const override; void GetState(int32_t& index, std::string& name, std::string& path) override; + size_t GetComponentsCount() override; std::string GetParams() override; void TriggerPageUpdate(int32_t pageId, bool directExecute = false) override; diff --git a/frameworks/bridge/js_frontend/frontend_delegate.h b/frameworks/bridge/js_frontend/frontend_delegate.h index 6f40fb3cdbd..a1208ce3c61 100644 --- a/frameworks/bridge/js_frontend/frontend_delegate.h +++ b/frameworks/bridge/js_frontend/frontend_delegate.h @@ -67,6 +67,8 @@ public: virtual int32_t GetStackSize() const = 0; // Gets current page's states virtual void GetState(int32_t& index, std::string& name, std::string& path) = 0; + // Gets current page's components count + virtual size_t GetComponentsCount() = 0; // Gets current page's params virtual std::string GetParams() { diff --git a/frameworks/bridge/js_frontend/frontend_delegate_impl.cpp b/frameworks/bridge/js_frontend/frontend_delegate_impl.cpp index b7244838db4..56f0628ef50 100644 --- a/frameworks/bridge/js_frontend/frontend_delegate_impl.cpp +++ b/frameworks/bridge/js_frontend/frontend_delegate_impl.cpp @@ -721,6 +721,23 @@ void FrontendDelegateImpl::GetState(int32_t& index, std::string& name, std::stri } } +size_t FrontendDelegateImpl::GetComponentsCount() +{ + std::lock_guard lock(mutex_); + if (pageRouteStack_.empty()) { + return 0; + } + auto itPage = pageMap_.find(pageRouteStack_.back().pageId); + if (itPage == pageMap_.end()) { + return 0; + } + auto domDoc = itPage->second->GetDomDocument(); + if (!domDoc) { + return 0; + } + return domDoc->GetComponentsCount(); +} + std::string FrontendDelegateImpl::GetParams() { if (pageParamMap_.find(pageId_) != pageParamMap_.end()) { diff --git a/frameworks/bridge/js_frontend/frontend_delegate_impl.h b/frameworks/bridge/js_frontend/frontend_delegate_impl.h index 391cfc69df4..6421b2897d6 100644 --- a/frameworks/bridge/js_frontend/frontend_delegate_impl.h +++ b/frameworks/bridge/js_frontend/frontend_delegate_impl.h @@ -269,6 +269,7 @@ public: void Clear() override; int32_t GetStackSize() const override; void GetState(int32_t& index, std::string& name, std::string& path) override; + size_t GetComponentsCount() override; std::string GetParams() override; void TriggerPageUpdate(int32_t pageId, bool directExecute = false) override; diff --git a/frameworks/bridge/js_frontend/js_frontend.cpp b/frameworks/bridge/js_frontend/js_frontend.cpp index 44fb918aacc..2ffd8775ef2 100644 --- a/frameworks/bridge/js_frontend/js_frontend.cpp +++ b/frameworks/bridge/js_frontend/js_frontend.cpp @@ -732,6 +732,7 @@ void JsFrontend::DumpFrontend() const } if (DumpLog::GetInstance().GetDumpFile()) { + DumpLog::GetInstance().AddDesc("Components: " + std::to_string(delegate_->GetComponentsCount())); DumpLog::GetInstance().AddDesc("Path: " + routerPath); DumpLog::GetInstance().AddDesc("Length: " + std::to_string(routerIndex)); DumpLog::GetInstance().Print(0, routerName, 0); diff --git a/frameworks/bridge/plugin_frontend/plugin_frontend.cpp b/frameworks/bridge/plugin_frontend/plugin_frontend.cpp index 57f1cf07d3e..c418d2cc7c7 100644 --- a/frameworks/bridge/plugin_frontend/plugin_frontend.cpp +++ b/frameworks/bridge/plugin_frontend/plugin_frontend.cpp @@ -755,6 +755,7 @@ void PluginFrontend::DumpFrontend() const delegate_->GetState(routerIndex, routerName, routerPath); if (DumpLog::GetInstance().GetDumpFile()) { + DumpLog::GetInstance().AddDesc("Components: " + std::to_string(delegate_->GetComponentsCount())); DumpLog::GetInstance().AddDesc("Path: " + routerPath); DumpLog::GetInstance().AddDesc("Length: " + std::to_string(routerIndex)); DumpLog::GetInstance().Print(0, routerName, 0); diff --git a/frameworks/bridge/plugin_frontend/plugin_frontend_delegate.cpp b/frameworks/bridge/plugin_frontend/plugin_frontend_delegate.cpp index f1b74f45dce..2690788e550 100644 --- a/frameworks/bridge/plugin_frontend/plugin_frontend_delegate.cpp +++ b/frameworks/bridge/plugin_frontend/plugin_frontend_delegate.cpp @@ -821,6 +821,16 @@ void PluginFrontendDelegate::GetState(int32_t& index, std::string& name, std::st } } +size_t PluginFrontendDelegate::GetComponentsCount() +{ + auto pipelineContext = pipelineContextHolder_.Get(); + const auto& pageElement = pipelineContext->GetLastPage(); + if (pageElement) { + return pageElement->GetComponentsCount(); + } + return 0; +} + std::string PluginFrontendDelegate::GetParams() { if (pageParamMap_.find(pageId_) != pageParamMap_.end()) { diff --git a/frameworks/bridge/plugin_frontend/plugin_frontend_delegate.h b/frameworks/bridge/plugin_frontend/plugin_frontend_delegate.h index a979aea4599..2b2fd2b260c 100644 --- a/frameworks/bridge/plugin_frontend/plugin_frontend_delegate.h +++ b/frameworks/bridge/plugin_frontend/plugin_frontend_delegate.h @@ -127,6 +127,7 @@ public: void Clear() override; int32_t GetStackSize() const override; void GetState(int32_t& index, std::string& name, std::string& path) override; + size_t GetComponentsCount() override; std::string GetParams() override; void TriggerPageUpdate(int32_t pageId, bool directExecute = false) override; diff --git a/frameworks/core/components/page/page_element.cpp b/frameworks/core/components/page/page_element.cpp index 85045c71a62..9f44df93262 100644 --- a/frameworks/core/components/page/page_element.cpp +++ b/frameworks/core/components/page/page_element.cpp @@ -19,6 +19,7 @@ #include "core/common/frontend.h" #include "core/common/text_field_manager.h" #include "core/components/transform/transform_element.h" +#include "core/components_v2/inspector/inspector_composed_element.h" namespace OHOS::Ace { @@ -153,4 +154,25 @@ void PageElement::Dump() } } +int32_t PageElement::GetComponentsCount() +{ + int32_t result = 0; + std::queue> elements; + elements.push(AceType::Claim(this)); + while (!elements.empty()) { + auto& element = elements.front(); + auto inspectorElement = AceType::DynamicCast(element); + if (inspectorElement != nullptr) { + result++; + } + const auto& children = element->GetChildren(); + for (const auto& child : children) { + elements.push(child); + } + elements.pop(); + } + + return result; +} + } // namespace OHOS::Ace \ No newline at end of file diff --git a/frameworks/core/components/page/page_element.h b/frameworks/core/components/page/page_element.h index 8265d55978c..543422d9af7 100644 --- a/frameworks/core/components/page/page_element.h +++ b/frameworks/core/components/page/page_element.h @@ -90,6 +90,7 @@ public: void RemoveGeometryTransition(const std::string& id); void FinishCreateGeometryTransition(const std::string& id); void Dump() override; + int32_t GetComponentsCount(); protected: bool RequestNextFocus(bool vertical, bool reverse, const Rect& rect) override; diff --git a/frameworks/core/pipeline/pipeline_context.cpp b/frameworks/core/pipeline/pipeline_context.cpp index 7406b47a8a8..0591a34100c 100644 --- a/frameworks/core/pipeline/pipeline_context.cpp +++ b/frameworks/core/pipeline/pipeline_context.cpp @@ -3273,7 +3273,6 @@ void PipelineContext::DumpFrontend() const { auto frontend = weakFrontend_.Upgrade(); if (frontend) { - DumpLog::GetInstance().AddDesc("Components: " + std::to_string(composedElementMap_.size())); frontend->DumpFrontend(); } } From 5b2baa623ffdcc271dcf997d7ba71dd38954cc84 Mon Sep 17 00:00:00 2001 From: bird_j Date: Thu, 5 May 2022 11:01:34 +0000 Subject: [PATCH 07/35] =?UTF-8?q?=E8=A7=86=E9=A2=91=E5=AA=92=E4=BD=93?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E6=8E=A5=E5=8F=A3=E4=BF=AE=E6=94=B9=20Signed?= =?UTF-8?q?-off-by:=20bird=5Fj=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/components/camera/standard_system/camera.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/frameworks/core/components/camera/standard_system/camera.cpp b/frameworks/core/components/camera/standard_system/camera.cpp index d7af85b42da..72bab4ce558 100644 --- a/frameworks/core/components/camera/standard_system/camera.cpp +++ b/frameworks/core/components/camera/standard_system/camera.cpp @@ -392,11 +392,7 @@ int32_t CameraCallback::PrepareVideo(sptr c } MakeDir(DEFAULT_CATCH_PATH); - ret = recorder_->SetOutputPath(DEFAULT_CATCH_PATH); - if (ret != ERR_OK) { - LOGE("Camera SetOutputPath failed. ret= %{private}d", ret); - return -1; - } + // need use fd not path ret = recorder_->Prepare(); if (ret != ERR_OK) { LOGE("Prepare failed. ret= %{private}d", ret); From 0681cdd5b70f19183ab6aff69123eea43d8f710e Mon Sep 17 00:00:00 2001 From: caocan <1532643766@qq.com> Date: Thu, 5 May 2022 21:12:12 +0800 Subject: [PATCH 08/35] modify disables to disabled Signed-off-by: caocan <1532643766@qq.com> Change-Id: I051bafe34bf8ffa2b9e7506f8b343491d7171b19 --- .../declarative_frontend/jsview/js_view_stack_processor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/bridge/declarative_frontend/jsview/js_view_stack_processor.cpp b/frameworks/bridge/declarative_frontend/jsview/js_view_stack_processor.cpp index 811f2096d02..33318df0408 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_view_stack_processor.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_view_stack_processor.cpp @@ -60,7 +60,7 @@ VisualState JSViewStackProcessor::StringToVisualState(const std::string& stateSt if (stateString == "pressed") { return VisualState::PRESSED; } - if (stateString == "disables") { + if (stateString == "disabled") { return VisualState::DISABLED; } if (stateString == "hover") { From ea4a31ffd0e27e8390171b14e0e94c2f862eec51 Mon Sep 17 00:00:00 2001 From: lihucheng Date: Fri, 6 May 2022 09:37:43 +0800 Subject: [PATCH 09/35] Delete redundant library dependencies issue:https://gitee.com/openharmony/ace_ace_engine/issues/I55YWD Signed-off-by: lihucheng --- frameworks/bridge/js_frontend/engine/v8/debugger/BUILD.gn | 2 -- 1 file changed, 2 deletions(-) diff --git a/frameworks/bridge/js_frontend/engine/v8/debugger/BUILD.gn b/frameworks/bridge/js_frontend/engine/v8/debugger/BUILD.gn index a57eec592c6..961d42ca1b0 100644 --- a/frameworks/bridge/js_frontend/engine/v8/debugger/BUILD.gn +++ b/frameworks/bridge/js_frontend/engine/v8/debugger/BUILD.gn @@ -46,8 +46,6 @@ ohos_shared_library("v8_debugger") { external_deps = [ "hilog:libhilog" ] } - deps += [ "//third_party/boost:boost" ] - include_dirs = [ "$ace_root", "$ace_root/frameworks", From 70d30ecfccd0137e6a6a8310cd5198a289249359 Mon Sep 17 00:00:00 2001 From: Yao yuchi Date: Fri, 6 May 2022 10:02:28 +0800 Subject: [PATCH 10/35] =?UTF-8?q?plugin=20=E8=BF=BD=E5=8A=A0promise?= =?UTF-8?q?=E9=9C=80=E6=B1=82=EF=BC=8C=E4=BB=A5=E5=8F=8Abugfix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Yao yuchi --- .../services/uiservice/src/ui_mgr_service.cpp | 10 +- .../jsview/js_view_abstract.cpp | 23 ++ frameworks/core/common/plugin_manager.cpp | 1 + frameworks/core/common/plugin_manager.h | 2 +- .../plugin/plugin_component_manager.cpp | 12 +- .../plugin/plugin_component_manager.h | 6 + .../core/components/plugin/plugin_element.cpp | 99 +++--- .../core/components/plugin/plugin_element.h | 2 + .../plugin/plugin_sub_container.cpp | 13 +- .../components/plugin/plugin_sub_container.h | 4 +- .../plugin/resource/plugin_request_data.h | 1 + .../components/plugin/rosen_render_plugin.cpp | 3 + .../plugin/plugin_sub_container_test.cpp | 6 +- .../plugincomponent/js_plugin_callback.cpp | 76 +++-- .../kits/plugincomponent/js_plugin_callback.h | 3 +- .../js_plugin_callback_mgr.cpp | 17 +- .../plugincomponent/js_plugin_callback_mgr.h | 3 + .../plugincomponent/js_plugin_component.cpp | 283 +++++++++++++++++- .../kits/plugincomponent/js_plugin_data.h | 11 + .../kits/plugincomponent/js_plugin_util.cpp | 23 ++ .../kits/plugincomponent/js_plugin_util.h | 2 + 21 files changed, 508 insertions(+), 92 deletions(-) diff --git a/adapter/ohos/services/uiservice/src/ui_mgr_service.cpp b/adapter/ohos/services/uiservice/src/ui_mgr_service.cpp index bb8e7b79ad5..7cf7ee30e6d 100644 --- a/adapter/ohos/services/uiservice/src/ui_mgr_service.cpp +++ b/adapter/ohos/services/uiservice/src/ui_mgr_service.cpp @@ -55,6 +55,7 @@ UIMgrService::UIMgrService() UIMgrService::~UIMgrService() { + std::lock_guard lock(uiMutex_); callbackMap_.clear(); } @@ -496,6 +497,7 @@ int UIMgrService::Push(const AAFwk::Want& want, const std::string& name, { HILOG_INFO("UIMgrService::Push called start"); std::map>::iterator iter; + std::lock_guard lock(uiMutex_); for (iter = callbackMap_.begin(); iter != callbackMap_.end(); ++iter) { sptr uiService = iter->second; if (uiService == nullptr) { @@ -511,6 +513,7 @@ int UIMgrService::Request(const AAFwk::Want& want, const std::string& name, cons { HILOG_INFO("UIMgrService::Request called start"); std::map>::iterator iter; + std::lock_guard lock(uiMutex_); for (iter = callbackMap_.begin(); iter != callbackMap_.end(); ++iter) { sptr uiService = iter->second; if (uiService == nullptr) { @@ -545,7 +548,7 @@ std::shared_ptr UIMgrService::GetEventHandler() int UIMgrService::HandleRegister(const AAFwk::Want& want, const sptr& uiService) { HILOG_INFO("UIMgrService::HandleRegister called start"); - std::lock_guard lock_l(uiMutex_); + std::lock_guard lock(uiMutex_); std::string keyStr = GetCallBackKeyStr(want); HILOG_INFO("UIMgrService::HandleRegister keyStr = %{public}s", keyStr.c_str()); bool exist = CheckCallBackFromMap(keyStr); @@ -560,7 +563,7 @@ int UIMgrService::HandleRegister(const AAFwk::Want& want, const sptr int UIMgrService::HandleUnregister(const AAFwk::Want& want) { HILOG_INFO("UIMgrService::HandleUnregister called start"); - std::lock_guard lock_l(uiMutex_); + std::lock_guard lock(uiMutex_); std::string keyStr = GetCallBackKeyStr(want); bool exist = CheckCallBackFromMap(keyStr); if (!exist) { @@ -577,8 +580,7 @@ std::string UIMgrService::GetCallBackKeyStr(const AAFwk::Want& want) HILOG_INFO("UIMgrService::GetCallBackKeyStr called start"); AppExecFwk::ElementName element = want.GetElement(); std::string bundleName = element.GetBundleName(); - std::string abilityName = element.GetAbilityName(); - std::string keyStr = bundleName + abilityName; + std::string keyStr = bundleName; HILOG_INFO("UIMgrService::GetCallBackKeyStr called end"); return keyStr; } diff --git a/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp b/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp index b6846811e66..ec126dd3869 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp @@ -26,6 +26,9 @@ #include "bridge/declarative_frontend/engine/functions/js_function.h" #include "bridge/declarative_frontend/engine/functions/js_on_area_change_function.h" #include "bridge/declarative_frontend/jsview/js_utils.h" +#ifdef PLUGIN_COMPONENT_SUPPORTED +#include "core/common/plugin_manager.h" +#endif #include "core/components_v2/extensions/events/on_area_change_extension.h" #ifdef USE_V8_ENGINE #include "bridge/declarative_frontend/engine/v8/functions/v8_function.h" @@ -4334,6 +4337,26 @@ void JSViewAbstract::SetDirection(const std::string& dir) RefPtr JSViewAbstract::GetThemeConstants() { +#ifdef PLUGIN_COMPONENT_SUPPORTED + if (Container::CurrentId() >= MIN_PLUGIN_SUBCONTAINER_ID) { + auto pluginContainer = PluginManager::GetInstance().GetPluginSubContainer(Container::CurrentId()); + if (!pluginContainer) { + LOGW("pluginContainer is null"); + return nullptr; + } + auto pliginPipelineContext = pluginContainer->GetPipelineContext(); + if (!pliginPipelineContext) { + LOGE("pliginPipelineContext is null!"); + return nullptr; + } + auto pluginThemeManager = pliginPipelineContext->GetThemeManager(); + if (!pluginThemeManager) { + LOGE("pluginThemeManager is null!"); + return nullptr; + } + return pluginThemeManager->GetThemeConstants(); + } +#endif auto container = Container::Current(); if (!container) { LOGW("container is null"); diff --git a/frameworks/core/common/plugin_manager.cpp b/frameworks/core/common/plugin_manager.cpp index 90b6e508bf4..02dc9b2b4de 100644 --- a/frameworks/core/common/plugin_manager.cpp +++ b/frameworks/core/common/plugin_manager.cpp @@ -20,6 +20,7 @@ namespace OHOS::Ace { std::shared_ptr PluginManager::pluginUtils_ = nullptr; +std::map> PluginManager::pluginSubContainerMap_; PluginManager::PluginManager() {} PluginManager::~PluginManager() diff --git a/frameworks/core/common/plugin_manager.h b/frameworks/core/common/plugin_manager.h index 47eab4fc987..de9fa168330 100644 --- a/frameworks/core/common/plugin_manager.h +++ b/frameworks/core/common/plugin_manager.h @@ -63,7 +63,7 @@ public: private: std::mutex mutex_; - std::map> pluginSubContainerMap_; + static std::map> pluginSubContainerMap_; std::mutex nonmatchedContainerMutex_; std::unordered_map> nonmatchedContainerMap_; std::mutex parentContainerMutex_; diff --git a/frameworks/core/components/plugin/plugin_component_manager.cpp b/frameworks/core/components/plugin/plugin_component_manager.cpp index 730df11924d..c9e5bbef972 100644 --- a/frameworks/core/components/plugin/plugin_component_manager.cpp +++ b/frameworks/core/components/plugin/plugin_component_manager.cpp @@ -63,10 +63,11 @@ int PluginComponentManager::Request( pluginTemplate.SetSource(jsonStr); pluginTemplate.SetAbility(want.GetElement().GetBundleName() + "/" + want.GetElement().GetAbilityName()); + std::lock_guard lock(listener_->GetMutex()); for (auto iter = listener_->GetPluginComponentCallBack().begin(); iter != listener_->GetPluginComponentCallBack().end();) { if (iter->second == CallBackType::RequestCallBack && iter->first != nullptr) { - iter->first->OnRequestCallBack(pluginTemplate, data, ""); + iter->first->OnRequestCallBack(pluginTemplate, data, "{}"); listener_->GetPluginComponentCallBack().erase(iter++); } else { iter++; @@ -126,6 +127,9 @@ void PluginComponentManager::UIServiceListener::OnPushCallBack(const AAFwk::Want std::string jsonStr; auto packagePathStr = PluginComponentManager::GetInstance()->GetPackagePath(want); PluginComponentManager::GetInstance()->GetTemplatePathFromJsonFile(packagePathStr, name, jsonPath, jsonStr); + if (jsonStr.empty()) { + jsonStr = "{}"; + } pluginTemplate.SetSource(jsonStr); } else { pluginTemplate.SetSource(name); @@ -159,7 +163,11 @@ void PluginComponentManager::UIServiceListener::OnReturnRequest( for (auto iter = callbackVec_.begin(); iter != callbackVec_.end();) { if (iter->second == CallBackType::RequestCallBack && iter->first != nullptr) { PluginComponentTemplate pluginTemplate; - pluginTemplate.SetSource(source); + if (source.empty()) { + pluginTemplate.SetSource("{}"); + } else { + pluginTemplate.SetSource(source); + } pluginTemplate.SetAbility(want.GetElement().GetBundleName() + "/" + want.GetElement().GetAbilityName()); iter->first->OnRequestCallBack(pluginTemplate, data, extraData); callbackVec_.erase(iter++); diff --git a/frameworks/core/components/plugin/plugin_component_manager.h b/frameworks/core/components/plugin/plugin_component_manager.h index 27819bbfbe5..8f329db0dfb 100644 --- a/frameworks/core/components/plugin/plugin_component_manager.h +++ b/frameworks/core/components/plugin/plugin_component_manager.h @@ -64,6 +64,7 @@ public: UIServiceListener() = default; ~UIServiceListener() { + std::lock_guard lock(mutex_); callbackVec_.clear(); }; @@ -72,6 +73,11 @@ public: return callbackVec_; } + std::mutex& GetMutex() + { + return mutex_; + } + void ResgisterListener(const std::shared_ptr& callback, CallBackType callBackType); void OnPushCallBack(const AAFwk::Want& want, const std::string& name, const std::string& jsonPath, const std::string& data, const std::string& extraData) override; diff --git a/frameworks/core/components/plugin/plugin_element.cpp b/frameworks/core/components/plugin/plugin_element.cpp index 737dcbe7ead..2f356b81c45 100644 --- a/frameworks/core/components/plugin/plugin_element.cpp +++ b/frameworks/core/components/plugin/plugin_element.cpp @@ -329,48 +329,11 @@ std::string PluginElement::GetPackagePathByWant(const WeakPtr& we pluginElement->SplitString(info.bundleName, '/', strList); if (strList.empty()) { LOGE("App bundleName or abilityName is empty."); - pluginElement->HandleOnErrorEvent("1", "App bundleName is empty"); + pluginElement->HandleOnErrorEvent("1", "App bundleName is empty."); return packagePathStr; } - - auto bms = PluginComponentManager::GetInstance()->GetBundleManager(); - if (!bms) { - LOGE("Bms bundleManager is nullptr."); - pluginElement->HandleOnErrorEvent("1", "Bms bundleManager is nullptr."); - return packagePathStr; - } - - std::vector userIds; - ErrCode errCode = GetActiveAccountIds(userIds); - if (errCode != ERR_OK) { - pluginElement->HandleOnErrorEvent("1", "Query Active OsAccountIds failed!"); - return packagePathStr; - } - if (strList.size() == 1) { - AppExecFwk::BundleInfo bundleInfo; - bool ret = bms->GetBundleInfo(strList[0], AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo, - userIds.size() > 0 ? userIds[0] : AppExecFwk::Constants::UNSPECIFIED_USERID); - if (!ret) { - LOGE("Bms get bundleName failed!"); - pluginElement->HandleOnErrorEvent("1", "Bms get bundleName failed!"); - return packagePathStr; - } - packagePathStr = bundleInfo.applicationInfo.entryDir + "/"; - } else { - AAFwk::Want want; - AppExecFwk::AbilityInfo abilityInfo; - AppExecFwk::ElementName element("", strList[0], strList[1]); - want.SetElement(element); - bool ret = bms->QueryAbilityInfo(want, AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_DEFAULT, - userIds.size() > 0 ? userIds[0] : AppExecFwk::Constants::UNSPECIFIED_USERID, abilityInfo); - if (!ret) { - LOGE("Bms get abilityInfo failed!"); - pluginElement->HandleOnErrorEvent("1", "Bms get bundleName failed!"); - return packagePathStr; - } - packagePathStr = abilityInfo.applicationInfo.codePath + "/" + abilityInfo.package + "/"; - } GetModuleNameByWant(weak, info); + packagePathStr = GerPackagePathByBms(weak, info, strList); return packagePathStr; } @@ -445,6 +408,62 @@ void PluginElement::RunPluginTask(const WeakPtr& weak, const RefP pluginElement->HandleOnErrorEvent("1", "package path is empty."); return; } - container->RunPlugin(packagePathStr, info.moduleName, info.source, plugin->GetData()); + container->RunPlugin(packagePathStr, info.moduleName, info.source, info.moduleResPath, plugin->GetData()); +} + +std::string PluginElement::GerPackagePathByBms( + const WeakPtr& weak, RequestPluginInfo& info, const std::vector& strList) const +{ + std::string packagePathStr; + auto pluginElement = weak.Upgrade(); + if (!pluginElement) { + return packagePathStr; + } + auto bms = PluginComponentManager::GetInstance()->GetBundleManager(); + if (!bms) { + LOGE("Bms bundleManager is nullptr."); + pluginElement->HandleOnErrorEvent("1", "Bms bundleManager is nullptr."); + return packagePathStr; + } + + std::vector userIds; + ErrCode errCode = GetActiveAccountIds(userIds); + if (errCode != ERR_OK) { + pluginElement->HandleOnErrorEvent("1", "Query Active OsAccountIds failed!"); + return packagePathStr; + } + if (strList.size() == 1) { + AppExecFwk::BundleInfo bundleInfo; + bool ret = bms->GetBundleInfo(strList[0], AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo, + userIds.size() > 0 ? userIds[0] : AppExecFwk::Constants::UNSPECIFIED_USERID); + if (!ret) { + LOGE("Bms get bundleName failed!"); + pluginElement->HandleOnErrorEvent("1", "Bms get bundleName failed!"); + return packagePathStr; + } + if (bundleInfo.moduleResPaths.size() == 1) { + info.moduleResPath = bundleInfo.moduleResPaths[0]; + } else { + LOGE("Bms moduleResPaths is empty."); + pluginElement->HandleOnErrorEvent("1", "Bms moduleResPaths is empty."); + return packagePathStr; + } + packagePathStr = bundleInfo.applicationInfo.entryDir + "/"; + } else { + AAFwk::Want want; + AppExecFwk::AbilityInfo abilityInfo; + AppExecFwk::ElementName element("", strList[0], strList[1]); + want.SetElement(element); + bool ret = bms->QueryAbilityInfo(want, AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_DEFAULT, + userIds.size() > 0 ? userIds[0] : AppExecFwk::Constants::UNSPECIFIED_USERID, abilityInfo); + if (!ret) { + LOGE("Bms get abilityInfo failed!"); + pluginElement->HandleOnErrorEvent("1", "Bms get bundleName failed!"); + return packagePathStr; + } + packagePathStr = abilityInfo.applicationInfo.codePath + "/" + abilityInfo.package + "/"; + info.moduleResPath = abilityInfo.resourcePath; + } + return packagePathStr; } } // namespace OHOS::Ace diff --git a/frameworks/core/components/plugin/plugin_element.h b/frameworks/core/components/plugin/plugin_element.h index 22ed7c203c1..4a7684fa7b5 100644 --- a/frameworks/core/components/plugin/plugin_element.h +++ b/frameworks/core/components/plugin/plugin_element.h @@ -56,6 +56,8 @@ private: std::string GetPackagePathByAbsolutePath(const WeakPtr& weak, RequestPluginInfo& info) const; void GetModuleNameByWant(const WeakPtr& weak, RequestPluginInfo& info) const; void RunPluginTask(const WeakPtr& weak, const RefPtr& component); + std::string GerPackagePathByBms( + const WeakPtr& weak, RequestPluginInfo& info, const std::vector& strList) const; private: RefPtr pluginSubContainer_; diff --git a/frameworks/core/components/plugin/plugin_sub_container.cpp b/frameworks/core/components/plugin/plugin_sub_container.cpp index 0ee6db4f1ed..a6ec5b22b73 100644 --- a/frameworks/core/components/plugin/plugin_sub_container.cpp +++ b/frameworks/core/components/plugin/plugin_sub_container.cpp @@ -160,8 +160,8 @@ void PluginSubContainer::UpdateSurfaceSize() TaskExecutor::TaskType::UI); } -void PluginSubContainer::RunPlugin( - const std::string& path, const std::string& module, const std::string& source, const std::string& data) +void PluginSubContainer::RunPlugin(const std::string& path, const std::string& module, + const std::string& source, const std::string& moduleResPath, const std::string& data) { ContainerScope scope(instanceId_); @@ -180,7 +180,7 @@ void PluginSubContainer::RunPlugin( UpdateRootElmentSize(); pipelineContext_->SetIsJsPlugin(true); - SetPluginComponentTheme(path, flutterAssetManager); + SetPluginComponentTheme(moduleResPath, flutterAssetManager); SetActionEventHandler(); auto weakContext = AceType::WeakClaim(AceType::RawPtr(pipelineContext_)); @@ -229,7 +229,12 @@ void PluginSubContainer::SetPluginComponentTheme( ResourceConfiguration resConfig; resConfig.SetDensity(density_); pluginResourceInfo.SetThemeId(THEME_ID_DEFAULT); - pluginResourceInfo.SetPackagePath(path); + auto position = path.rfind('/'); + if (position == std::string::npos) { + pluginResourceInfo.SetPackagePath(path); + } else { + pluginResourceInfo.SetPackagePath(path.substr(0, position + 1)); + } pluginResourceInfo.SetResourceConfiguration(resConfig); pipelineContext_->SetThemeManager(AceType::MakeRefPtr()); auto pluginThemeManager = pipelineContext_->GetThemeManager(); diff --git a/frameworks/core/components/plugin/plugin_sub_container.h b/frameworks/core/components/plugin/plugin_sub_container.h index 8d95d72b8f5..9c507fec00a 100644 --- a/frameworks/core/components/plugin/plugin_sub_container.h +++ b/frameworks/core/components/plugin/plugin_sub_container.h @@ -32,8 +32,8 @@ public: ~PluginSubContainer() = default; void Initialize(); - void RunPlugin( - const std::string& path, const std::string& module, const std::string& source, const std::string& data); + void RunPlugin(const std::string& path, const std::string& module, + const std::string& source, const std::string& moduleResPath, const std::string& data); void UpdatePlugin(const std::string& content); void Destroy(); diff --git a/frameworks/core/components/plugin/resource/plugin_request_data.h b/frameworks/core/components/plugin/resource/plugin_request_data.h index 6d6a500ab10..ded59869902 100644 --- a/frameworks/core/components/plugin/resource/plugin_request_data.h +++ b/frameworks/core/components/plugin/resource/plugin_request_data.h @@ -26,6 +26,7 @@ struct RequestPluginInfo { std::string abilityName; std::string moduleName; std::string source; + std::string moduleResPath; int32_t dimension = -1; bool allowUpate = true; Dimension width; diff --git a/frameworks/core/components/plugin/rosen_render_plugin.cpp b/frameworks/core/components/plugin/rosen_render_plugin.cpp index 7d21d4d445b..f326a986c2d 100644 --- a/frameworks/core/components/plugin/rosen_render_plugin.cpp +++ b/frameworks/core/components/plugin/rosen_render_plugin.cpp @@ -32,6 +32,9 @@ std::unique_ptr RosenRenderPlugin::GetDrawDelegate() SyncRSNodeBoundary(true, true); } auto rsNode = GetRSNode(); + if (node) { + node->SetBackgroundColor(Color::TRANSPARENT.GetValue()); + } rsNode->AddChild(node, -1); MarkNeedLayout(true, true); diff --git a/frameworks/core/components/test/unittest/plugin/plugin_sub_container_test.cpp b/frameworks/core/components/test/unittest/plugin/plugin_sub_container_test.cpp index 12147cbd351..63d0102891b 100644 --- a/frameworks/core/components/test/unittest/plugin/plugin_sub_container_test.cpp +++ b/frameworks/core/components/test/unittest/plugin/plugin_sub_container_test.cpp @@ -326,7 +326,7 @@ HWTEST_F(PluginSubContainerTest, PluginSubContaineRunPlugin001, TestSize.Level1) * @tc.steps: step4. RunPlugin. * @tc.expected: step4. RunPlugin success. */ - pluginSubContainer->RunPlugin(PATH, "newui", "", "data"); + pluginSubContainer->RunPlugin(PATH, "newui", "", "", "data"); } /** @@ -359,7 +359,7 @@ HWTEST_F(PluginSubContainerTest, PluginSubContaineRunPlugin002, TestSize.Level1) * @tc.steps: step4. RunPlugin. * @tc.expected: step4. RunPlugin fail. */ - pluginSubContainer->RunPlugin(PATH, "newui", "", "data"); + pluginSubContainer->RunPlugin(PATH, "newui", "", "", "data"); } /** @@ -397,6 +397,6 @@ HWTEST_F(PluginSubContainerTest, PluginSubContaineRunPlugin003, TestSize.Level1) * @tc.steps: step4. RunPlugin. * @tc.expected: step4. RunPlugin fail. */ - pluginSubContainer->RunPlugin(PATH, "newui", "", "data"); + pluginSubContainer->RunPlugin(PATH, "newui", "", "", "data"); } } // namespace OHOS::Ace diff --git a/interfaces/napi/kits/plugincomponent/js_plugin_callback.cpp b/interfaces/napi/kits/plugincomponent/js_plugin_callback.cpp index 7d20ebc03bb..973dac128bd 100644 --- a/interfaces/napi/kits/plugincomponent/js_plugin_callback.cpp +++ b/interfaces/napi/kits/plugincomponent/js_plugin_callback.cpp @@ -49,7 +49,8 @@ bool AceJSPluginRequestParam::operator!=(const AceJSPluginRequestParam& param) c } JSPluginCallback::JSPluginCallback(CallBackType eventType, - ACECallbackInfo& cbInfo) : eventType_(eventType) + ACECallbackInfo& cbInfo, ACEAsyncJSCallbackInfo* jsCallbackInfo) : eventType_(eventType), + asyncJSCallbackInfo_(jsCallbackInfo) { uuid_++; cbInfo_.env = cbInfo.env; @@ -71,6 +72,7 @@ void JSPluginCallback::DestroyAllResource(void) } cbInfo_.env = nullptr; cbInfo_.callback = nullptr; + asyncJSCallbackInfo_ = nullptr; } void JSPluginCallback::SetWant(const AAFwk::Want& want) @@ -189,11 +191,6 @@ void JSPluginCallback::OnPushEventInner(const OnPluginUvWorkData* workData) componentTemplate.SetSource(workData->sourceName); componentTemplate.SetAbility(workData->abilityName); - napi_open_handle_scope(cbInfo_.env, &scope); - if (scope == nullptr) { - napi_close_handle_scope(cbInfo_.env, scope); - return; - } callbackParam[ACE_PARAM0] = AceWrapWant(cbInfo_.env, workData->want); callbackParam[ACE_PARAM1] = MakePluginTemplateObject(componentTemplate); callbackParam[ACE_PARAM2] = AceStringToKVObject(cbInfo_.env, dataTmp); @@ -220,7 +217,30 @@ void JSPluginCallback::OnPushEvent(const AAFwk::Want& want, uvWorkData_.abilityName = pluginTemplate.GetAbility(); uvWorkData_.data = data; uvWorkData_.extraData = extraData; - OnPushEventInner(&uvWorkData_); + + uv_loop_s* loop = nullptr; + napi_get_uv_event_loop(cbInfo_.env, &loop); + uv_work_t* work = new uv_work_t; + work->data = (void*)this; + int rev = uv_queue_work( + loop, work, [](uv_work_t* work) {}, + [](uv_work_t* work, int status) { + if (work == nullptr) { + return; + } + JSPluginCallback* context = (JSPluginCallback*)work->data; + if (context) { + context->OnPushEventInner(&context->uvWorkData_); + } + delete work; + work = nullptr; + }); + if (rev != 0) { + if (work != nullptr) { + delete work; + work = nullptr; + } + } } void JSPluginCallback::OnRequestEventInner(const OnPluginUvWorkData* workData) @@ -271,6 +291,7 @@ void JSPluginCallback::OnRequestEvent(const AAFwk::Want& want, const std::string void JSPluginCallback::OnRequestCallBackInner(const OnPluginUvWorkData* workData) { + HILOG_INFO("%{public}s called.", __func__); napi_value jsCallback = nullptr; napi_value undefined = nullptr; napi_value jsResult = nullptr; @@ -283,15 +304,16 @@ void JSPluginCallback::OnRequestCallBackInner(const OnPluginUvWorkData* workData PluginComponentTemplate componentTemplate; componentTemplate.SetSource(workData->sourceName); componentTemplate.SetAbility(workData->abilityName); - napi_value callbackParam[ACE_ARGS_TWO] = {nullptr}; - callbackParam[ACE_PARAM0] = AceGetCallbackErrorValue(cbInfo_.env, 0); - callbackParam[ACE_PARAM1] = MakeCallbackParamForRequest(componentTemplate, workData->data, - workData->extraData); - - napi_get_undefined(cbInfo_.env, &undefined); - napi_get_reference_value(cbInfo_.env, cbInfo_.callback, &jsCallback); - napi_call_function(cbInfo_.env, undefined, jsCallback, ACE_ARGS_TWO, callbackParam, &jsResult); + if (cbInfo_.callback != nullptr) { + napi_value callbackParam[ACE_ARGS_TWO] = {nullptr}; + callbackParam[ACE_PARAM0] = AceGetCallbackErrorValue(cbInfo_.env, 0); + callbackParam[ACE_PARAM1] = MakeCallbackParamForRequest(componentTemplate, workData->data, + workData->extraData); + napi_get_undefined(cbInfo_.env, &undefined); + napi_get_reference_value(cbInfo_.env, cbInfo_.callback, &jsCallback); + napi_call_function(cbInfo_.env, undefined, jsCallback, ACE_ARGS_TWO, callbackParam, &jsResult); + } napi_close_handle_scope(cbInfo_.env, scope); } @@ -300,17 +322,27 @@ void JSPluginCallback::OnRequestCallBack(const PluginComponentTemplate& pluginTe { HILOG_INFO("%{public}s called.", __func__); JSPluginCallbackMgr::Instance().UnRegisterEvent(GetID()); - if (cbInfo_.env == nullptr || cbInfo_.callback == nullptr) { + if (cbInfo_.env == nullptr) { HILOG_INFO("%{public}s called, env or callback is null.", __func__); return; } - uvWorkData_.that = (void *)this; - uvWorkData_.sourceName = pluginTemplate.GetSource(); - uvWorkData_.abilityName = pluginTemplate.GetAbility(); - uvWorkData_.data = data; - uvWorkData_.extraData = extraData; - OnRequestCallBackInner(&uvWorkData_); + if (cbInfo_.callback != nullptr) { + uvWorkData_.that = (void *)this; + uvWorkData_.sourceName = pluginTemplate.GetSource(); + uvWorkData_.abilityName = pluginTemplate.GetAbility(); + uvWorkData_.data = data; + uvWorkData_.extraData = extraData; + OnRequestCallBackInner(&uvWorkData_); + } else { + if (asyncJSCallbackInfo_) { + asyncJSCallbackInfo_->requestCallbackData.sourceName = pluginTemplate.GetSource(); + asyncJSCallbackInfo_->requestCallbackData.abilityName = pluginTemplate.GetAbility(); + asyncJSCallbackInfo_->requestCallbackData.data = data; + asyncJSCallbackInfo_->requestCallbackData.extraData = extraData; + asyncJSCallbackInfo_->onRequestCallbackOK = true; + } + } } bool JSPluginCallback::OnEventStrictEquals(CallBackType eventType, const AAFwk::Want& want, diff --git a/interfaces/napi/kits/plugincomponent/js_plugin_callback.h b/interfaces/napi/kits/plugincomponent/js_plugin_callback.h index ccd41f01075..3636572b2f3 100644 --- a/interfaces/napi/kits/plugincomponent/js_plugin_callback.h +++ b/interfaces/napi/kits/plugincomponent/js_plugin_callback.h @@ -55,7 +55,7 @@ public: class JSPluginCallback : public PluginComponentCallBack { public: - JSPluginCallback(CallBackType eventType, ACECallbackInfo& cbInfo); + JSPluginCallback(CallBackType eventType, ACECallbackInfo& cbInfo, ACEAsyncJSCallbackInfo* jsCallbackInfo); virtual ~JSPluginCallback(); void SetWant(const AAFwk::Want& want); AAFwk::Want& GetWant(); @@ -87,6 +87,7 @@ private: std::shared_ptr requestParam_ = nullptr; static std::atomic_size_t uuid_; OnPluginUvWorkData uvWorkData_; + ACEAsyncJSCallbackInfo *asyncJSCallbackInfo_ = nullptr; }; } // namespace OHOS::Ace::Napi #endif // OHOS_NAPI_ACE_PLUGIN_CALLBACK_H diff --git a/interfaces/napi/kits/plugincomponent/js_plugin_callback_mgr.cpp b/interfaces/napi/kits/plugincomponent/js_plugin_callback_mgr.cpp index f862da478a3..7a8e4b50480 100644 --- a/interfaces/napi/kits/plugincomponent/js_plugin_callback_mgr.cpp +++ b/interfaces/napi/kits/plugincomponent/js_plugin_callback_mgr.cpp @@ -30,6 +30,7 @@ JSPluginCallbackMgr::~JSPluginCallbackMgr() } } eventList_.clear(); + asyncJSCallbackInfo_ = nullptr; } JSPluginCallbackMgr& JSPluginCallbackMgr::Instance(void) @@ -49,7 +50,7 @@ bool JSPluginCallbackMgr::RegisterOnEvent(napi_env env, CallBackType eventType, } std::shared_ptr pPluginComponentCallback = - std::make_shared(eventType, cbInfo); + std::make_shared(eventType, cbInfo, asyncJSCallbackInfo_); if (pPluginComponentCallback != nullptr) { pPluginComponentCallback->SetWant(want); eventList_.insert(std::make_pair(pPluginComponentCallback->GetID(), pPluginComponentCallback)); @@ -75,9 +76,10 @@ bool JSPluginCallbackMgr::RegisterRequestEvent(napi_env env, const AAFwk::Want& } std::shared_ptr pPluginComponentCallback = - std::make_shared(CallBackType::RequestCallBack, cbInfo); + std::make_shared(CallBackType::RequestCallBack, cbInfo, asyncJSCallbackInfo_); if (pPluginComponentCallback != nullptr) { pPluginComponentCallback->SetWant(want); + pPluginComponentCallback->SetRequestParam(param); eventList_.insert(std::make_pair(pPluginComponentCallback->GetID(), pPluginComponentCallback)); PluginComponentManager::GetInstance()->RegisterCallBack(want, pPluginComponentCallback, CallBackType::RequestCallBack); @@ -87,6 +89,17 @@ bool JSPluginCallbackMgr::RegisterRequestEvent(napi_env env, const AAFwk::Want& } } +bool JSPluginCallbackMgr::RegisterRequestEvent(napi_env env, const AAFwk::Want& want, + ACEAsyncJSCallbackInfo* jsCallbackInfo, const std::shared_ptr& param) +{ + asyncJSCallbackInfo_ = jsCallbackInfo; + if (jsCallbackInfo) { + return RegisterRequestEvent(env, want, jsCallbackInfo->cbInfo, param); + } else { + return false; + } +} + void JSPluginCallbackMgr::UnRegisterEvent(size_t key) { HILOG_INFO("%{public}s called. ", __func__); diff --git a/interfaces/napi/kits/plugincomponent/js_plugin_callback_mgr.h b/interfaces/napi/kits/plugincomponent/js_plugin_callback_mgr.h index 329ba5573ce..12cc7f1cf55 100644 --- a/interfaces/napi/kits/plugincomponent/js_plugin_callback_mgr.h +++ b/interfaces/napi/kits/plugincomponent/js_plugin_callback_mgr.h @@ -35,10 +35,13 @@ public: bool RegisterOnEvent(napi_env env, CallBackType eventType, const AAFwk::Want& want, ACECallbackInfo& cbInfo); bool RegisterRequestEvent(napi_env env, const AAFwk::Want& want, ACECallbackInfo& cbInfo, const std::shared_ptr& param); + bool RegisterRequestEvent(napi_env env, const AAFwk::Want& want, ACEAsyncJSCallbackInfo* jsCallbackInfo, + const std::shared_ptr& param); void UnRegisterEvent(size_t key); void UnregisterCallBack(napi_env env, const AAFwk::Want& want); private: std::mutex mutex_; + ACEAsyncJSCallbackInfo *asyncJSCallbackInfo_ = nullptr; std::map> eventList_; ACE_DISALLOW_COPY_AND_MOVE(JSPluginCallbackMgr); }; diff --git a/interfaces/napi/kits/plugincomponent/js_plugin_component.cpp b/interfaces/napi/kits/plugincomponent/js_plugin_component.cpp index f128b11c080..c9a5aa39339 100644 --- a/interfaces/napi/kits/plugincomponent/js_plugin_component.cpp +++ b/interfaces/napi/kits/plugincomponent/js_plugin_component.cpp @@ -29,6 +29,7 @@ constexpr int ACE_ARGS_THREE = 3; constexpr int ACE_PARAM0 = 0; constexpr int ACE_PARAM1 = 1; constexpr int ACE_PARAM2 = 2; +constexpr int NAPI_ACE_ERR_ERROR = 1; bool UnwrapStageWantFromJS(napi_env env, napi_value param, ACEAsyncJSCallbackInfo* asyncCallbackInfo) { @@ -141,7 +142,7 @@ bool UnwrapParamForPush(napi_env env, size_t argc, napi_value* argv, { HILOG_INFO("%{public}s called, argc=%{public}zu", __func__, argc); const size_t argcMax = ACE_ARGS_TWO; - if (argc != argcMax) { + if (argc <= 0 || argc > argcMax) { HILOG_INFO("%{public}s called, Params is invalid.", __func__); return false; } @@ -151,9 +152,11 @@ bool UnwrapParamForPush(napi_env env, size_t argc, napi_value* argv, return false; } - if (!AceCreateAsyncCallback(env, argv[ACE_PARAM1], asyncCallbackInfo)) { - HILOG_INFO("%{public}s called, the last parameter is invalid.", __func__); - return false; + if (argc == argcMax) { + if (!AceCreateAsyncCallback(env, argv[ACE_PARAM1], asyncCallbackInfo)) { + HILOG_INFO("%{public}s called, the last parameter is invalid.", __func__); + return false; + } } return true; } @@ -181,6 +184,26 @@ void JSPushCompleteAsyncCallbackWork(napi_env env, napi_status status, void* dat AceCompleteAsyncCallbackWork(env, status, data); } +void JSPushCompletePromiseCallbackWork(napi_env env, napi_status status, void* data) +{ + HILOG_INFO("%{public}s called.", __func__); + + ACEAsyncJSCallbackInfo* asyncCallbackInfo = (ACEAsyncJSCallbackInfo*)data; + if (asyncCallbackInfo == nullptr) { + HILOG_INFO("%{public}s called, asyncCallbackInfo is null", __func__); + return; + } + + PluginComponentManager::GetInstance()->Push(asyncCallbackInfo->jsParamList.want, + asyncCallbackInfo->jsParamList.paramList.GetStringValue("name"), + asyncCallbackInfo->jsParamList.paramList.GetStringValue("jsonPath"), + asyncCallbackInfo->jsParamList.paramList.GetStringValue("data"), + asyncCallbackInfo->jsParamList.paramList.GetStringValue("extraData")); + + asyncCallbackInfo->error_code = 0; + AceCompletePromiseCallbackWork(env, status, data); +} + napi_value NAPI_JSPushWrap(napi_env env, napi_callback_info info, ACEAsyncJSCallbackInfo* asyncCallbackInfo) { HILOG_INFO("%{public}s called.", __func__); @@ -205,7 +228,9 @@ napi_value NAPI_JSPushWrap(napi_env env, napi_callback_info info, ACEAsyncJSCall } else { HILOG_INFO("%{public}s called. promise.", __func__); asyncParamEx.resource = "NAPI_JSPushPromise"; - return nullptr; + asyncParamEx.execute = JSPushWork; + asyncParamEx.complete = JSPushCompletePromiseCallbackWork; + return AceExecutePromiseCallbackWork(env, asyncCallbackInfo, &asyncParamEx); } } @@ -262,7 +287,7 @@ bool UnwrapParamForRequest(napi_env env, size_t argc, napi_value* argv, ACEAsyncJSCallbackInfo* asyncCallbackInfo) { HILOG_INFO("%{public}s called, argc=%{public}zu", __func__, argc); - if (argc != ACE_ARGS_TWO) { + if (argc <= 0 || argc > ACE_ARGS_TWO) { HILOG_INFO("%{public}s called, Params is invalid.", __func__); return false; } @@ -272,9 +297,11 @@ bool UnwrapParamForRequest(napi_env env, size_t argc, napi_value* argv, return false; } - if (!AceCreateAsyncCallback(env, argv[ACE_PARAM1], asyncCallbackInfo)) { - HILOG_INFO("%{public}s called, the last parameter is invalid.", __func__); - return false; + if (argc == ACE_ARGS_TWO) { + if (!AceCreateAsyncCallback(env, argv[ACE_PARAM1], asyncCallbackInfo)) { + HILOG_INFO("%{public}s called, the last parameter is invalid.", __func__); + return false; + } } return true; } @@ -284,6 +311,11 @@ void JSRequestWork(napi_env env, void* data) HILOG_INFO("%{public}s called.", __func__); } +void JSRequestPromiseWork(napi_env env, void* data) +{ + HILOG_INFO("%{public}s called.", __func__); +} + void AceRequestCompleteAsyncCallbackWork(napi_env env, napi_status status, void* data) { HILOG_INFO("%{public}s called.", __func__); @@ -325,6 +357,112 @@ void AceRequestCompleteAsyncCallbackWork(napi_env env, napi_status status, void* AceFreeAsyncJSCallbackInfo(&asyncCallbackInfo); } +napi_value MakePluginTemplateObject(napi_env env, const PluginComponentTemplate& pluginTemplate) +{ + HILOG_INFO("%{public}s called.", __func__); + napi_value jsPluginTemplate = AceCreateJSObject(env); + if (jsPluginTemplate != nullptr) { + napi_value jsSource = AceWrapStringToJS(env, pluginTemplate.GetSource()); + napi_value jsAbility = AceWrapStringToJS(env, pluginTemplate.GetAbility()); + + AceSetPropertyValueByPropertyName(env, jsPluginTemplate, "source", jsSource); + AceSetPropertyValueByPropertyName(env, jsPluginTemplate, "ability", jsAbility); + } + return jsPluginTemplate; +} + +napi_value MakeCallbackParamForRequest(napi_env env, const PluginComponentTemplate& pluginTemplate, + const ACEAsyncJSCallbackInfo* asyncCallbackInfo) +{ + HILOG_INFO("%{public}s called.", __func__); + napi_value jsObject = AceCreateJSObject(env); + if (jsObject == nullptr) { + return nullptr; + } + HILOG_INFO("%{public}s called. 1111", __func__); + std::string dataTmp("{}"); + std::string extraDataTmp("{}"); + if (!asyncCallbackInfo->requestCallbackData.data.empty()) { + dataTmp = asyncCallbackInfo->requestCallbackData.data; + } + if (!asyncCallbackInfo->requestCallbackData.extraData.empty()) { + extraDataTmp = asyncCallbackInfo->requestCallbackData.extraData; + } + + napi_value jsPluginTemplate = MakePluginTemplateObject(env, pluginTemplate); + napi_value jsData = AceStringToKVObject(env, dataTmp); + napi_value jsExtraData = AceStringToKVObject(env, extraDataTmp); + + if (jsData != nullptr) { + HILOG_INFO("%{public}s called. componentTemplate", __func__); + AceSetPropertyValueByPropertyName(env, jsObject, "componentTemplate", jsPluginTemplate); + } + if (jsData != nullptr) { + HILOG_INFO("%{public}s called. data", __func__); + AceSetPropertyValueByPropertyName(env, jsObject, "data", jsData); + } + if (jsExtraData != nullptr) { + HILOG_INFO("%{public}s called. extraData", __func__); + AceSetPropertyValueByPropertyName(env, jsObject, "extraData", jsExtraData); + } + return jsObject; +} + +napi_value TransferRequestCallBackData(napi_env env, ACEAsyncJSCallbackInfo* asyncCallbackInfo) +{ + HILOG_INFO("%{public}s called.", __func__); + PluginComponentTemplate componentTemplate; + componentTemplate.SetSource(asyncCallbackInfo->requestCallbackData.sourceName); + componentTemplate.SetAbility(asyncCallbackInfo->requestCallbackData.abilityName); + napi_value jsResult = MakeCallbackParamForRequest(env, componentTemplate, asyncCallbackInfo); + return jsResult; +} + +void AceRequestPromiseAsyncCallbackWork(napi_env env, napi_status status, void* data) +{ + HILOG_INFO("%{public}s called.", __func__); + ACEAsyncJSCallbackInfo* asyncCallbackInfo = (ACEAsyncJSCallbackInfo*)data; + if (asyncCallbackInfo == nullptr) { + HILOG_INFO("%{public}s called, asyncCallbackInfo is null", __func__); + return; + } + + if (asyncCallbackInfo->ability != nullptr) { + std::shared_ptr pWant = asyncCallbackInfo->ability->GetWant(); + asyncCallbackInfo->wantStage = *pWant; + } + + std::shared_ptr param = std::make_shared( + asyncCallbackInfo->jsParamList.want, + asyncCallbackInfo->jsParamList.paramList.GetStringValue("name"), + asyncCallbackInfo->jsParamList.paramList.GetStringValue("data"), + asyncCallbackInfo->jsParamList.paramList.GetStringValue("jsonPath") + ); + asyncCallbackInfo->onRequestCallbackOK = false; + + if (param != nullptr) { + HILOG_INFO("%{public}s called, pWant = %{public}s:%{public}s", + __func__, asyncCallbackInfo->wantStage.GetElement().GetBundleName().c_str(), + asyncCallbackInfo->wantStage.GetElement().GetAbilityName().c_str()); + JSPluginCallbackMgr::Instance().RegisterRequestEvent(env, asyncCallbackInfo->wantStage, + asyncCallbackInfo, param); + } + + PluginComponentManager::GetInstance()->Request(asyncCallbackInfo->jsParamList.want, + asyncCallbackInfo->jsParamList.paramList.GetStringValue("name"), + asyncCallbackInfo->jsParamList.paramList.GetStringValue("jsonPath"), + asyncCallbackInfo->jsParamList.paramList.GetStringValue("data")); + + if (asyncCallbackInfo->onRequestCallbackOK) { + asyncCallbackInfo->error_code = 0; + napi_resolve_deferred(env, asyncCallbackInfo->deferred, TransferRequestCallBackData(env, asyncCallbackInfo)); + AceFreeAsyncJSCallbackInfo(&asyncCallbackInfo); + } else { + asyncCallbackInfo->error_code = NAPI_ACE_ERR_ERROR; + AceCompletePromiseCallbackWork(env, status, data); + } +} + napi_value NAPI_JSRequestWrap(napi_env env, napi_callback_info info, ACEAsyncJSCallbackInfo* asyncCallbackInfo) { HILOG_INFO("%{public}s called.", __func__); @@ -350,7 +488,9 @@ napi_value NAPI_JSRequestWrap(napi_env env, napi_callback_info info, ACEAsyncJSC } else { HILOG_INFO("%{public}s called. promise.", __func__); asyncParamEx.resource = "NAPI_JSRequestPromise"; - return nullptr; + asyncParamEx.execute = JSRequestPromiseWork; + asyncParamEx.complete = AceRequestPromiseAsyncCallbackWork; + return AceExecutePromiseCallbackWork(env, asyncCallbackInfo, &asyncParamEx); } } @@ -504,18 +644,139 @@ static napi_value JSOn(napi_env env, napi_callback_info info) return rev; } -static napi_value PluginComponentExport(napi_env env, napi_value exports) + +bool UnwrapParamForOff(napi_env env, size_t argc, napi_value* argv, + ACEAsyncJSCallbackInfo* asyncCallbackInfo) { + HILOG_INFO("%{public}s called, argc=%{public}zu", __func__, argc); + + if (argc != ACE_ARGS_TWO) { + HILOG_INFO("%{public}s called, Params is invalid.", __func__); + return false; + } + + if (!UnwrapStageWantFromJS(env, argv[ACE_PARAM0], asyncCallbackInfo)) { + HILOG_INFO("%{public}s called, the owner want parameter is invalid.", __func__); + return false; + } + + if (!AceCreateAsyncCallback(env, argv[ACE_PARAM1], asyncCallbackInfo)) { + HILOG_INFO("%{public}s called, the second parameter is invalid.", __func__); + return false; + } + + return true; +} + +void JSOffWork(napi_env env, void* data) +{ + HILOG_INFO("%{public}s called.", __func__); +} + +void AceOffCompleteAsyncCallbackWork(napi_env env, napi_status status, void* data) +{ + HILOG_INFO("%{public}s called.", __func__); + + ACEAsyncJSCallbackInfo* asyncCallbackInfo = (ACEAsyncJSCallbackInfo*)data; + if (asyncCallbackInfo == nullptr) { + HILOG_INFO("%{public}s called, asyncCallbackInfo is null", __func__); + return; + } + + JSPluginCallbackMgr::Instance().UnregisterCallBack(env, asyncCallbackInfo->wantStage); + napi_delete_async_work(env, asyncCallbackInfo->asyncWork); + AceFreeAsyncJSCallbackInfo(&asyncCallbackInfo); +} + +napi_value NAPI_JSOffWrap(napi_env env, napi_callback_info info, ACEAsyncJSCallbackInfo* asyncCallbackInfo) +{ + HILOG_INFO("%{public}s called.", __func__); + size_t argc = ACE_ARGS_MAX_COUNT; + napi_value args[ACE_ARGS_MAX_COUNT] = {nullptr}; + napi_value jsthis = 0; + void* data = nullptr; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, &jsthis, &data)); + + if (!UnwrapParamForOff(env, argc, args, asyncCallbackInfo)) { + HILOG_INFO("%{public}s called. Invoke UnwrapParamForOff fail", __func__); + return nullptr; + } + + ACEAsyncParamEx asyncParamEx; + if (asyncCallbackInfo->cbInfo.callback != nullptr) { + HILOG_INFO("%{public}s called. asyncCallback.", __func__); + asyncParamEx.resource = "NAPI_JSOffCallback"; + asyncParamEx.execute = JSOffWork; + asyncParamEx.complete = AceOffCompleteAsyncCallbackWork; + + return AceExecuteAsyncCallbackWork(env, asyncCallbackInfo, &asyncParamEx); + } else { + HILOG_INFO("%{public}s called. promise.", __func__); + asyncParamEx.resource = "NAPI_JSOffPromise"; + return nullptr; + } +} + +static napi_value JSOff(napi_env env, napi_callback_info info) +{ + HILOG_INFO("%{public}s called.", __func__); + + ACEAsyncJSCallbackInfo* asyncCallbackInfo = AceCreateAsyncJSCallbackInfo(env); + if (asyncCallbackInfo == nullptr) { + return AceWrapVoidToJS(env); + } + + napi_value rev = NAPI_JSOffWrap(env, info, asyncCallbackInfo); + if (rev == nullptr) { + AceFreeAsyncJSCallbackInfo(&asyncCallbackInfo); + rev = AceWrapVoidToJS(env); + } + return rev; +} + +napi_value PluginComponentEventTypeInit(napi_env env, napi_value exports) +{ + HILOG_INFO("%{public}s, called", __func__); + + napi_value obj = nullptr; + napi_create_object(env, &obj); + + AceSetNamedPropertyByString(env, obj, "push", "EVENT_TYPE_PUSH"); + AceSetNamedPropertyByString(env, obj, "request", "EVENT_TYPE_REQUEST"); + + napi_property_descriptor properties[] = { + DECLARE_NAPI_PROPERTY("EventType", obj), + }; + + NAPI_CALL(env, napi_define_properties(env, exports, sizeof(properties) / sizeof(properties[0]), properties)); + return exports; +} + +napi_value PluginComponentInit(napi_env env, napi_value exports) +{ + HILOG_INFO("%{public}s, called", __func__); + napi_property_descriptor properties[] = { DECLARE_NAPI_FUNCTION("push", JSPush), DECLARE_NAPI_FUNCTION("request", JSRequest), DECLARE_NAPI_FUNCTION("on", JSOn), + DECLARE_NAPI_FUNCTION("off", JSOff), }; NAPI_CALL(env, napi_define_properties(env, exports, sizeof(properties) / sizeof(properties[0]), properties)); return exports; } +static napi_value PluginComponentExport(napi_env env, napi_value exports) +{ + HILOG_INFO("%{public}s, called", __func__); + + PluginComponentEventTypeInit(env, exports); + PluginComponentInit(env, exports); + return exports; +} + static napi_module PlugInComonentModule = { .nm_version = 1, .nm_flags = 0, diff --git a/interfaces/napi/kits/plugincomponent/js_plugin_data.h b/interfaces/napi/kits/plugincomponent/js_plugin_data.h index cbc3818b83c..714d695197b 100644 --- a/interfaces/napi/kits/plugincomponent/js_plugin_data.h +++ b/interfaces/napi/kits/plugincomponent/js_plugin_data.h @@ -56,6 +56,14 @@ struct AceFromJSParam { AppExecFwk::PacMap paramList = {}; }; +struct ACERequestCallbackData { + std::string sourceName; + std::string abilityName; + std::string data; + std::string extraData; + std::string name; +}; + struct ACEAsyncJSCallbackInfo { ACECallbackInfo cbInfo = {}; Ability* ability = nullptr; @@ -66,6 +74,9 @@ struct ACEAsyncJSCallbackInfo { napi_value result = nullptr; int error_code = 0; AAFwk::Want wantStage = {}; + napi_value onRequestData = nullptr; + bool onRequestCallbackOK = false; + ACERequestCallbackData requestCallbackData; }; struct ACEAsyncParamEx { diff --git a/interfaces/napi/kits/plugincomponent/js_plugin_util.cpp b/interfaces/napi/kits/plugincomponent/js_plugin_util.cpp index dcbf1f7051e..69f7b58655c 100644 --- a/interfaces/napi/kits/plugincomponent/js_plugin_util.cpp +++ b/interfaces/napi/kits/plugincomponent/js_plugin_util.cpp @@ -234,6 +234,8 @@ std::string AceUnwrapStringFromJS(napi_env env, napi_value param, const std::str return value; } if (memset_s(buf, size + 1, 0, size + 1) != EOK) { + delete[] buf; + buf = nullptr; return value; } @@ -266,6 +268,8 @@ bool AceUnwrapStringFromJS2(napi_env env, napi_value param, std::string& value) return false; } if (memset_s(buf, (size + 1), 0, (size + 1)) != EOK) { + delete[] buf; + buf = nullptr; return false; } @@ -699,6 +703,9 @@ bool AceIsSameFuncFromJS(ACECallbackInfo& left, ACECallbackInfo& right) if (left.env != right.env) { return false; } + if (left.callback == nullptr && right.callback == nullptr) { + return true; + } bool result = false; napi_value leftFunc = nullptr; @@ -921,6 +928,8 @@ ACEAsyncJSCallbackInfo* AceCreateAsyncJSCallbackInfo(napi_env env) .ability = ability, .asyncWork = nullptr, .deferred = nullptr, + .onRequestData = nullptr, + .onRequestCallbackOK = false, }; if (asyncCallbackInfo != nullptr) { @@ -1168,4 +1177,18 @@ void AceCompletePromiseCallbackWork(napi_env env, napi_status status, void* data delete asyncCallbackInfo; asyncCallbackInfo = nullptr; } + +/** + * @brief Set named property to obj by string + * + * @param jsObject Indicates object passed by JS. + * @param propertyName Indicates the name of the object. + * @param propName Indicates the name of the property. + */ +void AceSetNamedPropertyByString(napi_env env, napi_value jsObject, const char *objName, const char *propName) +{ + napi_value prop = nullptr; + napi_create_string_utf8(env, objName, NAPI_AUTO_LENGTH, &prop); + napi_set_named_property(env, jsObject, propName, prop); +} } // namespace OHOS::Ace::Napi diff --git a/interfaces/napi/kits/plugincomponent/js_plugin_util.h b/interfaces/napi/kits/plugincomponent/js_plugin_util.h index b101f06b14e..d44a20eaca8 100644 --- a/interfaces/napi/kits/plugincomponent/js_plugin_util.h +++ b/interfaces/napi/kits/plugincomponent/js_plugin_util.h @@ -77,6 +77,8 @@ napi_value AceStringToKVObject(napi_env env, const std::string& jsonString); bool AceUnwrapArrayComplexFromJS(napi_env env, napi_value param, ACEComplexArrayData& value); +void AceSetNamedPropertyByString(napi_env env, napi_value jsObject, const char *objName, const char *propName); + bool AceIsSameFuncFromJS(ACECallbackInfo& left, ACECallbackInfo& right); /** * @brief Indicates the specified attribute exists in the object passed by JS. From 729e0a4e9aff3171fe6235bad4b29e1a3af7069c Mon Sep 17 00:00:00 2001 From: yichengzhao Date: Thu, 28 Apr 2022 16:35:55 +0800 Subject: [PATCH 11/35] fix getinfo fail Signed-off-by: yichengzhao Change-Id: Ib9e4243716b9e8d5dc64bab1efc154126d09db50 --- .../js_frontend/engine/jsi/jsi_engine.cpp | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/frameworks/bridge/js_frontend/engine/jsi/jsi_engine.cpp b/frameworks/bridge/js_frontend/engine/jsi/jsi_engine.cpp index 7ae6d31e9e2..5e1ca2f53f4 100644 --- a/frameworks/bridge/js_frontend/engine/jsi/jsi_engine.cpp +++ b/frameworks/bridge/js_frontend/engine/jsi/jsi_engine.cpp @@ -775,16 +775,29 @@ std::string GetDeviceInfo() infoList->Put("manufacturer", SystemProperties::GetManufacturer().c_str()); infoList->Put("model", SystemProperties::GetModel().c_str()); infoList->Put("product", SystemProperties::GetProduct().c_str()); - - if (AceApplicationInfo::GetInstance().GetLanguage().empty()) { - infoList->Put("language", "N/A"); - } else { - infoList->Put("language", AceApplicationInfo::GetInstance().GetLanguage().c_str()); + std::string tmp = SystemProperties::GetApiVersion(); + if (tmp != SystemProperties::INVALID_PARAM) { + char* tmpEnd = nullptr; + infoList->Put( + "apiVersion", static_cast(std::strtol(SystemProperties::GetApiVersion().c_str(), &tmpEnd, 10))); } - if (AceApplicationInfo::GetInstance().GetCountryOrRegion().empty()) { - infoList->Put("region", "N/A"); - } else { - infoList->Put("region", AceApplicationInfo::GetInstance().GetCountryOrRegion().c_str()); + tmp = SystemProperties::GetReleaseType(); + if (tmp != SystemProperties::INVALID_PARAM) { + infoList->Put("releaseType", tmp.c_str()); + } + tmp = SystemProperties::GetParamDeviceType(); + if (tmp != SystemProperties::INVALID_PARAM) { + infoList->Put("deviceType", tmp.c_str()); + } + + tmp = SystemProperties::GetLanguage(); + if (tmp != SystemProperties::INVALID_PARAM) { + infoList->Put("language", tmp.c_str()); + } + + tmp = SystemProperties::GetRegion(); + if (tmp != SystemProperties::INVALID_PARAM) { + infoList->Put("region", tmp.c_str()); } auto container = Container::Current(); From 47825fe8824431965df4239ebcbe50fcb692c715 Mon Sep 17 00:00:00 2001 From: yichengzhao Date: Fri, 29 Apr 2022 14:29:13 +0800 Subject: [PATCH 12/35] change width/height/screenDensity type Signed-off-by: yichengzhao Change-Id: Ie08082d758aae8a7207fffa5f74a391ceb13f256 --- .../bridge/js_frontend/engine/jsi/jsi_engine.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/frameworks/bridge/js_frontend/engine/jsi/jsi_engine.cpp b/frameworks/bridge/js_frontend/engine/jsi/jsi_engine.cpp index 5e1ca2f53f4..f6480cfe667 100644 --- a/frameworks/bridge/js_frontend/engine/jsi/jsi_engine.cpp +++ b/frameworks/bridge/js_frontend/engine/jsi/jsi_engine.cpp @@ -63,6 +63,8 @@ extern const char _binary_strip_native_min_abc_end[]; namespace OHOS::Ace::Framework { +const int SYSTEM_BASE = 10; + #ifdef APP_USE_ARM const std::string ARK_DEBUGGER_LIB_PATH = "/system/lib/libark_debugger.z.so"; #else @@ -778,8 +780,8 @@ std::string GetDeviceInfo() std::string tmp = SystemProperties::GetApiVersion(); if (tmp != SystemProperties::INVALID_PARAM) { char* tmpEnd = nullptr; - infoList->Put( - "apiVersion", static_cast(std::strtol(SystemProperties::GetApiVersion().c_str(), &tmpEnd, 10))); + infoList->Put("apiVersion", static_cast( + std::strtol(SystemProperties::GetApiVersion().c_str(), &tmpEnd, SYSTEM_BASE))); } tmp = SystemProperties::GetReleaseType(); if (tmp != SystemProperties::INVALID_PARAM) { @@ -803,19 +805,19 @@ std::string GetDeviceInfo() auto container = Container::Current(); int32_t width = container ? container->GetViewWidth() : 0; if (width != 0) { - infoList->Put("windowWidth", std::to_string(width).c_str()); + infoList->Put("windowWidth", width); } else { infoList->Put("windowWidth", "N/A"); } int32_t height = container ? container->GetViewHeight() : 0; if (height != 0) { - infoList->Put("windowHeight", std::to_string(height).c_str()); + infoList->Put("windowHeight", height); } else { infoList->Put("windowHeight", "N/A"); } - infoList->Put("screenDensity", std::to_string(SystemProperties::GetResolution()).c_str()); + infoList->Put("screenDensity", SystemProperties::GetResolution()); bool isRound = SystemProperties::GetIsScreenRound(); if (isRound) { From d206f86f2abef5db648f23428b4969b6ff58ab97 Mon Sep 17 00:00:00 2001 From: renwei Date: Fri, 6 May 2022 12:29:26 +0800 Subject: [PATCH 13/35] add secon cfg Signed-off-by: renwei Change-Id: Ibbcaa68ce0c01eb5968af33aae5d8472a324ff76 --- adapter/ohos/services/uiservice/ui_service.cfg | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/adapter/ohos/services/uiservice/ui_service.cfg b/adapter/ohos/services/uiservice/ui_service.cfg index 95d4efe86f2..5097664e86a 100644 --- a/adapter/ohos/services/uiservice/ui_service.cfg +++ b/adapter/ohos/services/uiservice/ui_service.cfg @@ -3,7 +3,8 @@ "name" : "ui_service", "path" : ["/system/bin/sa_main", "/system/profile/ui_service.xml"], "uid" : "system", - "gid" : ["system", "shell"] + "gid" : ["system", "shell"], + "secon" : "u:r:ui_service:s0" } ] } From 8a7eaa1d0197b210c673463e914d6953b7416de7 Mon Sep 17 00:00:00 2001 From: lie Date: Thu, 5 May 2022 16:39:55 +0800 Subject: [PATCH 14/35] support remote debugging of web component Signed-off-by: lie Change-Id: I7107c9fc7867f2b2c5b22064dd0e501cbd8ce99b --- .../declarative_frontend/jsview/js_web.cpp | 14 +++++++++++++- .../declarative_frontend/jsview/js_web.h | 1 + frameworks/core/components/web/render_web.cpp | 1 + .../components/web/resource/web_delegate.cpp | 18 ++++++++++++++++++ .../components/web/resource/web_delegate.h | 3 ++- frameworks/core/components/web/web_component.h | 11 +++++++++++ 6 files changed, 46 insertions(+), 2 deletions(-) diff --git a/frameworks/bridge/declarative_frontend/jsview/js_web.cpp b/frameworks/bridge/declarative_frontend/jsview/js_web.cpp index aad089c7ce8..e19bbb47e93 100755 --- a/frameworks/bridge/declarative_frontend/jsview/js_web.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_web.cpp @@ -578,6 +578,7 @@ void JSWeb::JSBind(BindingTarget globalObj) JSClass::StaticMethod("fileFromUrlAccess", &JSWeb::FileFromUrlAccess); JSClass::StaticMethod("databaseAccess", &JSWeb::DatabaseAccess); JSClass::StaticMethod("textZoomAtio", &JSWeb::TextZoomAtio); + JSClass::StaticMethod("webDebuggingAccess", &JSWeb::WebDebuggingAccessEnabled); JSClass::Inherit(); JSClass::Bind(globalObj); JSWebDialog::JSBind(globalObj); @@ -1055,7 +1056,7 @@ JSRef FileSelectorEventToJSValue(const FileSelectorEvent& eventInfo) JSRef paramObj = JSClass::NewInstance(); auto fileSelectorParam = Referenced::Claim(paramObj->Unwrap()); fileSelectorParam->SetParam(eventInfo); - + JSRef resultObj = JSClass::NewInstance(); auto fileSelectorResult = Referenced::Claim(resultObj->Unwrap()); fileSelectorResult->SetResult(eventInfo); @@ -1354,4 +1355,15 @@ void JSWeb::TextZoomAtio(int32_t textZoomAtioNum) } webComponent->SetTextZoomAtio(textZoomAtioNum); } + +void JSWeb::WebDebuggingAccessEnabled(bool isWebDebuggingAccessEnabled) +{ + auto stack = ViewStackProcessor::GetInstance(); + auto webComponent = AceType::DynamicCast(stack->GetMainComponent()); + if (!webComponent) { + LOGE("JSWeb: MainComponent is null."); + return; + } + webComponent->SetWebDebuggingAccessEnabled(isWebDebuggingAccessEnabled); +} } // namespace OHOS::Ace::Framework diff --git a/frameworks/bridge/declarative_frontend/jsview/js_web.h b/frameworks/bridge/declarative_frontend/jsview/js_web.h index e75231d538e..0eabba7152a 100755 --- a/frameworks/bridge/declarative_frontend/jsview/js_web.h +++ b/frameworks/bridge/declarative_frontend/jsview/js_web.h @@ -62,6 +62,7 @@ public: static void FileFromUrlAccess(bool isFileFromUrlAccessEnabled); static void DatabaseAccess(bool isDatabaseAccessEnabled); static void TextZoomAtio(int32_t textZoomAtioNum); + static void WebDebuggingAccessEnabled(bool isWebDebuggingAccessEnabled); protected: static void OnCommonDialog(const JSCallbackInfo& args, int dialogEventType); diff --git a/frameworks/core/components/web/render_web.cpp b/frameworks/core/components/web/render_web.cpp index f6433eec7d1..7b8b1be031c 100755 --- a/frameworks/core/components/web/render_web.cpp +++ b/frameworks/core/components/web/render_web.cpp @@ -73,6 +73,7 @@ void RenderWeb::Update(const RefPtr& component) delegate_->UpdateFileFromUrlEnabled(web->GetFileFromUrlAccessEnabled()); delegate_->UpdateDatabaseEnabled(web->GetDatabaseAccessEnabled()); delegate_->UpdateTextZoomAtio(web->GetTextZoomAtio()); + delegate_->UpdateWebDebuggingAccess(web->GetWebDebuggingAccessEnabled()); auto userAgent = web->GetUserAgent(); if (!userAgent.empty()) { delegate_->UpdateUserAgent(userAgent); diff --git a/frameworks/core/components/web/resource/web_delegate.cpp b/frameworks/core/components/web/resource/web_delegate.cpp index d32969df886..2c8be3fd7ed 100755 --- a/frameworks/core/components/web/resource/web_delegate.cpp +++ b/frameworks/core/components/web/resource/web_delegate.cpp @@ -1201,6 +1201,7 @@ void WebDelegate::InitWebViewWithSurface(sptr surface) setting->PutEnableRawFileAccessFromFileURLs(component->GetFileFromUrlAccessEnabled()); setting->PutDatabaseAllowed(component->GetDatabaseAccessEnabled()); setting->PutZoomingForTextFactor(component->GetTextZoomAtio()); + setting->PutWebDebuggingAccess(component->GetWebDebuggingAccessEnabled()); }, TaskExecutor::TaskType::PLATFORM); } @@ -1459,6 +1460,23 @@ void WebDelegate::UpdateTextZoomAtio(const int32_t& textZoomAtioNum) TaskExecutor::TaskType::PLATFORM); } +void WebDelegate::UpdateWebDebuggingAccess(bool isWebDebuggingAccessEnabled) +{ + auto context = context_.Upgrade(); + if (!context) { + return; + } + context->GetTaskExecutor()->PostTask( + [weak = WeakClaim(this), isWebDebuggingAccessEnabled]() { + auto delegate = weak.Upgrade(); + if (delegate && delegate->nweb_) { + std::shared_ptr setting = delegate->nweb_->GetPreference(); + setting->PutWebDebuggingAccess(isWebDebuggingAccessEnabled); + } + }, + TaskExecutor::TaskType::PLATFORM); +} + void WebDelegate::LoadUrl() { auto context = context_.Upgrade(); diff --git a/frameworks/core/components/web/resource/web_delegate.h b/frameworks/core/components/web/resource/web_delegate.h index e52dfd10e67..82e16460930 100755 --- a/frameworks/core/components/web/resource/web_delegate.h +++ b/frameworks/core/components/web/resource/web_delegate.h @@ -73,7 +73,7 @@ class FileSelectorParamOhos : public WebFileSelectorParam { public: FileSelectorParamOhos(std::shared_ptr param) : param_(param) {} - + std::string GetTitle() override; int GetMode() override; std::string GetDefaultFileName() override; @@ -161,6 +161,7 @@ public: void UpdateFileFromUrlEnabled(const bool& isFileFromUrlAccessEnabled); void UpdateDatabaseEnabled(const bool& isDatabaseAccessEnabled); void UpdateTextZoomAtio(const int32_t& textZoomAtioNum); + void UpdateWebDebuggingAccess(bool isWebDebuggingAccessEnabled); void LoadUrl(); void HandleTouchDown(const int32_t& id, const double& x, const double& y); void HandleTouchUp(const int32_t& id, const double& x, const double& y); diff --git a/frameworks/core/components/web/web_component.h b/frameworks/core/components/web/web_component.h index 172f4b3244a..870d6c6f02a 100755 --- a/frameworks/core/components/web/web_component.h +++ b/frameworks/core/components/web/web_component.h @@ -795,6 +795,16 @@ public: isDatabaseAccessEnabled_ = isEnabled; } + bool GetWebDebuggingAccessEnabled() + { + return isWebDebuggingAccessEnabled_; + } + + void SetWebDebuggingAccessEnabled(bool isEnabled) + { + isWebDebuggingAccessEnabled_ = isEnabled; + } + int32_t GetTextZoomAtio() { return textZoomAtioNum_; @@ -925,6 +935,7 @@ private: bool isDatabaseAccessEnabled_ = false; int32_t textZoomAtioNum_ = default_text_zoom_atio; WebCacheMode cacheMode_ = WebCacheMode::DEFAULT; + bool isWebDebuggingAccessEnabled_ = false; }; } // namespace OHOS::Ace From 16ad9681b7c19fc8edf275c68379170afd36f585 Mon Sep 17 00:00:00 2001 From: Yao yuchi Date: Fri, 6 May 2022 18:19:03 +0800 Subject: [PATCH 15/35] =?UTF-8?q?=E4=BF=AE=E6=94=B9plugin=E6=8F=90?= =?UTF-8?q?=E4=BA=A4=E6=97=B6review=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Yao yuchi --- .../plugin/plugin_component_manager.cpp | 26 ++++++++++++------- .../plugin/plugin_component_manager.h | 6 +---- .../core/components/plugin/plugin_element.cpp | 26 ++++++++++++------- .../core/components/plugin/plugin_element.h | 3 ++- 4 files changed, 36 insertions(+), 25 deletions(-) diff --git a/frameworks/core/components/plugin/plugin_component_manager.cpp b/frameworks/core/components/plugin/plugin_component_manager.cpp index c9e5bbef972..4329da419b3 100644 --- a/frameworks/core/components/plugin/plugin_component_manager.cpp +++ b/frameworks/core/components/plugin/plugin_component_manager.cpp @@ -62,16 +62,8 @@ int PluginComponentManager::Request( GetTemplatePathFromJsonFile(packagePathStr, name, jsonPath, jsonStr); pluginTemplate.SetSource(jsonStr); pluginTemplate.SetAbility(want.GetElement().GetBundleName() + "/" + want.GetElement().GetAbilityName()); - - std::lock_guard lock(listener_->GetMutex()); - for (auto iter = listener_->GetPluginComponentCallBack().begin(); - iter != listener_->GetPluginComponentCallBack().end();) { - if (iter->second == CallBackType::RequestCallBack && iter->first != nullptr) { - iter->first->OnRequestCallBack(pluginTemplate, data, "{}"); - listener_->GetPluginComponentCallBack().erase(iter++); - } else { - iter++; - } + if (listener_) { + listener_->RequestByJsonPath(pluginTemplate, data); } return 0; } @@ -177,6 +169,20 @@ void PluginComponentManager::UIServiceListener::OnReturnRequest( } } +void PluginComponentManager::UIServiceListener::RequestByJsonPath( + const PluginComponentTemplate& pluginTemplate, const std::string& data) +{ + std::lock_guard lock(mutex_); + for (auto iter = callbackVec_.begin(); iter != callbackVec_.end();) { + if (iter->second == CallBackType::RequestCallBack && iter->first != nullptr) { + iter->first->OnRequestCallBack(pluginTemplate, data, "{}"); + callbackVec_.erase(iter++); + } else { + iter++; + } + } +} + bool PluginComponentManager::GetTemplatePathFromJsonFile( const std::string& packagePathStr, const std::string& pluginName, const std::string& jsonPath, std::string& jsonStr) { diff --git a/frameworks/core/components/plugin/plugin_component_manager.h b/frameworks/core/components/plugin/plugin_component_manager.h index 8f329db0dfb..b3ad409e517 100644 --- a/frameworks/core/components/plugin/plugin_component_manager.h +++ b/frameworks/core/components/plugin/plugin_component_manager.h @@ -73,17 +73,13 @@ public: return callbackVec_; } - std::mutex& GetMutex() - { - return mutex_; - } - void ResgisterListener(const std::shared_ptr& callback, CallBackType callBackType); void OnPushCallBack(const AAFwk::Want& want, const std::string& name, const std::string& jsonPath, const std::string& data, const std::string& extraData) override; void OnRequestCallBack(const AAFwk::Want& want, const std::string& name, const std::string& data) override; void OnReturnRequest(const AAFwk::Want& want, const std::string& source, const std::string& data, const std::string& extraData) override; + void RequestByJsonPath(const PluginComponentTemplate& pluginTemplate, const std::string& data); private: std::mutex mutex_; diff --git a/frameworks/core/components/plugin/plugin_element.cpp b/frameworks/core/components/plugin/plugin_element.cpp index 2f356b81c45..5f295eb5ce0 100644 --- a/frameworks/core/components/plugin/plugin_element.cpp +++ b/frameworks/core/components/plugin/plugin_element.cpp @@ -322,18 +322,23 @@ std::string PluginElement::GetPackagePathByWant(const WeakPtr& we std::string packagePathStr; auto pluginElement = weak.Upgrade(); if (!pluginElement) { + LOGE("pluginElement is nullptr."); + pluginElement->HandleOnErrorEvent("1", "pluginElement is nullptr."); return packagePathStr; } std::vector strList; pluginElement->SplitString(info.bundleName, '/', strList); - if (strList.empty()) { - LOGE("App bundleName or abilityName is empty."); - pluginElement->HandleOnErrorEvent("1", "App bundleName is empty."); + + std::vector userIds; + ErrCode errCode = GetActiveAccountIds(userIds); + if (errCode != ERR_OK) { + LOGE("Query Active OsAccountIds failed!"); + pluginElement->HandleOnErrorEvent("1", "Query Active OsAccountIds failed!"); return packagePathStr; } GetModuleNameByWant(weak, info); - packagePathStr = GerPackagePathByBms(weak, info, strList); + packagePathStr = GerPackagePathByBms(weak, info, strList, userIds); return packagePathStr; } @@ -342,6 +347,8 @@ void PluginElement::GetModuleNameByWant(const WeakPtr& weak, Requ { auto pluginElement = weak.Upgrade(); if (!pluginElement) { + LOGE("pluginElement is nullptr."); + pluginElement->HandleOnErrorEvent("1", "pluginElement is nullptr."); return; } @@ -412,11 +419,13 @@ void PluginElement::RunPluginTask(const WeakPtr& weak, const RefP } std::string PluginElement::GerPackagePathByBms( - const WeakPtr& weak, RequestPluginInfo& info, const std::vector& strList) const + const WeakPtr& weak, RequestPluginInfo& info, + const std::vector& strList, const std::vector& userIds) const { std::string packagePathStr; auto pluginElement = weak.Upgrade(); if (!pluginElement) { + LOGE("pluginElement is nullptr."); return packagePathStr; } auto bms = PluginComponentManager::GetInstance()->GetBundleManager(); @@ -426,10 +435,9 @@ std::string PluginElement::GerPackagePathByBms( return packagePathStr; } - std::vector userIds; - ErrCode errCode = GetActiveAccountIds(userIds); - if (errCode != ERR_OK) { - pluginElement->HandleOnErrorEvent("1", "Query Active OsAccountIds failed!"); + if (strList.empty()) { + LOGE("App bundleName or abilityName is empty."); + pluginElement->HandleOnErrorEvent("1", "App bundleName is empty."); return packagePathStr; } if (strList.size() == 1) { diff --git a/frameworks/core/components/plugin/plugin_element.h b/frameworks/core/components/plugin/plugin_element.h index 4a7684fa7b5..cc44a60740c 100644 --- a/frameworks/core/components/plugin/plugin_element.h +++ b/frameworks/core/components/plugin/plugin_element.h @@ -57,7 +57,8 @@ private: void GetModuleNameByWant(const WeakPtr& weak, RequestPluginInfo& info) const; void RunPluginTask(const WeakPtr& weak, const RefPtr& component); std::string GerPackagePathByBms( - const WeakPtr& weak, RequestPluginInfo& info, const std::vector& strList) const; + const WeakPtr& weak, RequestPluginInfo& info, + const std::vector& strList, const std::vector& userIds) const; private: RefPtr pluginSubContainer_; From 55b17d724e25d89b33dc34f30803c570d250db1a Mon Sep 17 00:00:00 2001 From: Yao yuchi Date: Fri, 6 May 2022 18:24:54 +0800 Subject: [PATCH 16/35] codex for waterflow Signed-off-by: Yao yuchi --- .../water_flow/render_water_flow.cpp | 33 ++++++++++--------- .../water_flow/render_water_flow.h | 2 +- .../water_flow/water_flow_element.cpp | 4 +-- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/frameworks/core/components_v2/water_flow/render_water_flow.cpp b/frameworks/core/components_v2/water_flow/render_water_flow.cpp index 1ed46200c20..1c86054acb5 100644 --- a/frameworks/core/components_v2/water_flow/render_water_flow.cpp +++ b/frameworks/core/components_v2/water_flow/render_water_flow.cpp @@ -472,8 +472,10 @@ void RenderWaterFlow::InitialFlowProp() std::vector cross; BuildFlow(cross); // Initialize the columnCount and rowCount, default is 1 - crossCount_ = cross.size(); - mainCount_ = 0; + crossCount_ = static_cast(cross.size()); + if (crossCount_ < 0) { + return; + } UpdateAccessibilityAttr(); if (!buildChildByIndex_) { @@ -503,9 +505,8 @@ void RenderWaterFlow::InitialFlowProp() } startRankItemIndex_ = 0; currentItemIndex_ = 0; - bool vail = false; - SupplyItems(vail, mainCount_ > 0 ? mainCount_ - 1 : 0); - startIndex_ = mainCount_ > 0 ? mainCount_ - 1 : 0; + SupplyItems(false, mainCount_ > 0 ? mainCount_ - 1 : 0); + startIndex_ = (mainCount_ > 0) ? (mainCount_ - 1) : 0; if (NearZero(currentOffset_)) { needCalculateViewPort_ = true; } @@ -526,7 +527,7 @@ double RenderWaterFlow::BuildLazyFlowLayout(int32_t index, double sizeNeed) } double size = 0.0; int32_t startIndex = index; - while (size < sizeNeed) { + while (ceil(size) < ceil(sizeNeed)) { bool vail = false; auto suppleSize = SupplyItems(vail, startIndex); if (NearZero(suppleSize)) { @@ -732,7 +733,7 @@ void RenderWaterFlow::CaculateViewPortSceneOne() firstItemOffset_ = 0.0; } // Move up - while (currentOffset_ > 0) { + while (ceil(currentOffset_) > 0) { if (startIndex_ > 0) { currentOffset_ -= GetSize(flowCells_) + mainGap_; startIndex_--; @@ -762,7 +763,7 @@ bool RenderWaterFlow::CaculateViewPortSceneTwo(bool& NeedContinue) firstItemOffset_ = 0.0; } // Move down - while (startIndex_ < mainCount_ && (currentOffset_ < 0 || needCalculateViewPort_)) { + while (startIndex_ < mainCount_ && (ceil(currentOffset_) < 0 || needCalculateViewPort_)) { currentOffset_ += GetSize(flowCells_) + mainGap_; startIndex_++; } @@ -788,7 +789,7 @@ bool RenderWaterFlow::CaculateViewPortSceneTwo(bool& NeedContinue) blank = blank - firstItemOffset_; firstItemOffset_ = 0; // Move up - while (blank > 0) { + while (ceil(blank) > 0) { if (startIndex_ == 0 && startRankItemIndex_ > 0) { LoadForward(); } @@ -846,7 +847,7 @@ bool RenderWaterFlow::CheckMainFull(int32_t mainIndex) return false; } - if (mainItor->second.size() < crossCount_) { + if (crossCount_ < 0 || (mainItor->second.size() < static_cast(crossCount_))) { return false; } @@ -861,7 +862,7 @@ double RenderWaterFlow::SupplyItems( ACE_SCOPED_TRACE("SupplyItems %d", mainIndex); auto mainItor = flowMatrix_.find(mainIndex); if (mainItor != flowMatrix_.end()) { - if (mainItor->second.size() == crossCount_) { + if (crossCount_ < 0 || (mainItor->second.size() == static_cast(crossCount_))) { needRank = false; } } @@ -1070,7 +1071,7 @@ void RenderWaterFlow::ClearLayout(int32_t index) estimateHeight_ = 0.0; if (index > -1) { int32_t main = GetItemMainIndex(index); - int32_t rows = flowMatrix_.size(); + size_t rows = flowMatrix_.size(); DeleteItemsInMarix(rows, index); for (auto it = inCache_.begin(); it != inCache_.end();) { if (*it >= main) { @@ -1169,7 +1170,7 @@ bool RenderWaterFlow::CheckEndShowItemPlace(int32_t index) if (items == flowMatrix_.end()) { return false; } - if (items->second.size() < crossCount_) { + if (crossCount_ < 0 || (items->second.size() < static_cast(crossCount_))) { return true; } } @@ -1752,7 +1753,7 @@ void RenderWaterFlow::OutPutMarix(int32_t rows, bool before) } } -bool RenderWaterFlow::DeleteItemsInMarix(int32_t rows, int32_t itemIndex) +bool RenderWaterFlow::DeleteItemsInMarix(size_t rows, int32_t itemIndex) { bool deleteMainBeDelete = true; int32_t main = -1; @@ -1761,7 +1762,7 @@ bool RenderWaterFlow::DeleteItemsInMarix(int32_t rows, int32_t itemIndex) deleteMainBeDelete = false; return deleteMainBeDelete; } - for (int32_t i = 0; i < rows; i++) { + for (size_t i = 0; i < rows; i++) { auto iter5 = flowMatrix_.find(i); if (iter5 == flowMatrix_.end()) { continue; @@ -1801,4 +1802,4 @@ bool RenderWaterFlow::DeleteItemsInMarix(int32_t rows, int32_t itemIndex) } return deleteMainBeDelete; } -} // namespace OHOS::Ace::V2 \ No newline at end of file +} // namespace OHOS::Ace::V2 diff --git a/frameworks/core/components_v2/water_flow/render_water_flow.h b/frameworks/core/components_v2/water_flow/render_water_flow.h index edaf1f4457b..2b6d697ba5a 100644 --- a/frameworks/core/components_v2/water_flow/render_water_flow.h +++ b/frameworks/core/components_v2/water_flow/render_water_flow.h @@ -233,7 +233,7 @@ protected: void OutPutMarix(int32_t rows, bool before); - bool DeleteItemsInMarix(int32_t rows, int32_t itemIndex); + bool DeleteItemsInMarix(size_t rows, int32_t itemIndex); enum class SCROLLABLE : uint32_t { NO_SCROLL = 0, diff --git a/frameworks/core/components_v2/water_flow/water_flow_element.cpp b/frameworks/core/components_v2/water_flow/water_flow_element.cpp index f9328b8e8e5..dbd7208b911 100644 --- a/frameworks/core/components_v2/water_flow/water_flow_element.cpp +++ b/frameworks/core/components_v2/water_flow/water_flow_element.cpp @@ -135,8 +135,8 @@ bool WaterFlowElement::RequestNextFocus(bool vertical, bool reverse, const Rect& bool ret = false; while (!ret) { int32_t focusIndex = waterFlow->RequestNextFocus(vertical, reverse); - int32_t size = GetChildrenList().size(); - if (focusIndex < 0 || focusIndex >= size) { + size_t size = GetChildrenList().size(); + if (focusIndex < 0 || static_cast(focusIndex) >= size) { return false; } auto iter = GetChildrenList().begin(); From 78b35c9a0f9e2a62a7f48303ba573c0cf025dfc5 Mon Sep 17 00:00:00 2001 From: Yao yuchi Date: Fri, 6 May 2022 18:53:45 +0800 Subject: [PATCH 17/35] codex for waterflow Signed-off-by: Yao yuchi --- .../core/components_v2/water_flow/render_water_flow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/core/components_v2/water_flow/render_water_flow.cpp b/frameworks/core/components_v2/water_flow/render_water_flow.cpp index 1c86054acb5..e6c6bfaf04b 100644 --- a/frameworks/core/components_v2/water_flow/render_water_flow.cpp +++ b/frameworks/core/components_v2/water_flow/render_water_flow.cpp @@ -466,7 +466,6 @@ void RenderWaterFlow::InitialFlowProp() if (!GetFlowSize() && !updateFlag_) { return; } - ACE_SCOPED_TRACE("InitialFlowProp"); OnDataSourceUpdated(-1); CallGap(); std::vector cross; @@ -505,7 +504,8 @@ void RenderWaterFlow::InitialFlowProp() } startRankItemIndex_ = 0; currentItemIndex_ = 0; - SupplyItems(false, mainCount_ > 0 ? mainCount_ - 1 : 0); + bool vail = false; + SupplyItems(vail, ((mainCount_ > 0) ? (mainCount_ - 1) : 0)); startIndex_ = (mainCount_ > 0) ? (mainCount_ - 1) : 0; if (NearZero(currentOffset_)) { needCalculateViewPort_ = true; From 35b03a0c8ed5de91097ec2a85645556497d8be79 Mon Sep 17 00:00:00 2001 From: yichengzhao Date: Sat, 7 May 2022 10:25:55 +0800 Subject: [PATCH 18/35] put 'N/A' when exception Signed-off-by: yichengzhao Change-Id: Ie182ff377be9501bc284a2d1f229f880b634a0c5 --- .../bridge/js_frontend/engine/jsi/jsi_engine.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/frameworks/bridge/js_frontend/engine/jsi/jsi_engine.cpp b/frameworks/bridge/js_frontend/engine/jsi/jsi_engine.cpp index f6480cfe667..d832c0e4577 100644 --- a/frameworks/bridge/js_frontend/engine/jsi/jsi_engine.cpp +++ b/frameworks/bridge/js_frontend/engine/jsi/jsi_engine.cpp @@ -782,24 +782,32 @@ std::string GetDeviceInfo() char* tmpEnd = nullptr; infoList->Put("apiVersion", static_cast( std::strtol(SystemProperties::GetApiVersion().c_str(), &tmpEnd, SYSTEM_BASE))); + } else { + infoList->Put("apiVersion", "N/A"); } tmp = SystemProperties::GetReleaseType(); if (tmp != SystemProperties::INVALID_PARAM) { infoList->Put("releaseType", tmp.c_str()); + } else { + infoList->Put("releaseType", "N/A"); } tmp = SystemProperties::GetParamDeviceType(); if (tmp != SystemProperties::INVALID_PARAM) { infoList->Put("deviceType", tmp.c_str()); + } else { + infoList->Put("deviceType", "N/A"); } - tmp = SystemProperties::GetLanguage(); if (tmp != SystemProperties::INVALID_PARAM) { infoList->Put("language", tmp.c_str()); + } else { + infoList->Put("language", "N/A"); } - tmp = SystemProperties::GetRegion(); if (tmp != SystemProperties::INVALID_PARAM) { infoList->Put("region", tmp.c_str()); + } else { + infoList->Put("region", "N/A"); } auto container = Container::Current(); From ab3140a4720cc3b6e9633a72c5b5d2b37a1ce38b Mon Sep 17 00:00:00 2001 From: huangjie Date: Sat, 7 May 2022 11:31:02 +0800 Subject: [PATCH 19/35] =?UTF-8?q?=E5=B0=86innerkits=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=B8=BAinner=5Fapi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huangjie --- BUILD.gn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 6fa18fee47e..e62c9649add 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -27,7 +27,7 @@ config("ace_config") { if (is_standard_system && !use_mingw_win && !use_mac) { include_dirs += [ "//base/global/resource_management/frameworks/resmgr/include", - "//base/global/resource_management/interfaces/innerkits/include", + "//base/global/resource_management/interfaces/inner_api/include", "$ace_root/adapter/ohos/services/uiservice/include", ] } @@ -77,7 +77,7 @@ config("ace_test_config") { if (is_standard_system && !use_mingw_win && !use_mac) { include_dirs += [ "//base/global/resource_management/frameworks/resmgr/include", - "//base/global/resource_management/interfaces/innerkits/include", + "//base/global/resource_management/interfaces/inner_api/include", ] cflags_cc += [ From 211205fd99d32f1aa5be0e710a12ffe2b146a7d1 Mon Sep 17 00:00:00 2001 From: panzhenyu1 Date: Sat, 7 May 2022 15:24:53 +0800 Subject: [PATCH 20/35] Add support for Ark preview on Mac related issue: https://gitee.com/openharmony/arkui_napi/issues/I5694S Signed-off-by: panzhenyu1 Change-Id: Ic92d8c3a9425894f249bfaa8f14c06cea1790028 --- adapter/preview/entrance/samples/BUILD.gn | 82 +++++++++++++++---- adapter/preview/sdk/BUILD.gn | 27 ++++-- .../engine/jsi/jsi_declarative_engine.cpp | 6 ++ .../js_frontend/engine/jsi/ark_js_runtime.cpp | 6 +- .../js_frontend/engine/jsi/jsi_engine.cpp | 6 ++ 5 files changed, 101 insertions(+), 26 deletions(-) diff --git a/adapter/preview/entrance/samples/BUILD.gn b/adapter/preview/entrance/samples/BUILD.gn index 6c3cb457e0e..725c2cda126 100644 --- a/adapter/preview/entrance/samples/BUILD.gn +++ b/adapter/preview/entrance/samples/BUILD.gn @@ -51,6 +51,7 @@ template("ace_test") { deps += [ ":copy_ark_shared_library(${current_toolchain})", ":copy_icu_data_resource(${current_toolchain})", + ":copy_icu_shared_library(${current_toolchain})", ":copy_napi_shared_library(${current_toolchain})", ] } else { @@ -102,42 +103,93 @@ if (enable_ark_preview) { ark_core_shared_library = get_label_info("//ark/runtime_core/libpandabase:libarkbase", "root_out_dir") + "/ark/ark" - sources += [ - "$ark_core_shared_library/libarkbase.dll", - "$ark_core_shared_library/libarkfile.dll", - "$ark_core_shared_library/libarkziparchive.dll", - ] deps += [ "//ark/runtime_core/libpandabase:libarkbase(${current_toolchain})", "//ark/runtime_core/libpandafile:libarkfile(${current_toolchain})", "//ark/runtime_core/libziparchive:libarkziparchive(${current_toolchain})", ] + if (use_mac) { + sources += [ + "$ark_core_shared_library/libarkbase.dylib", + "$ark_core_shared_library/libarkfile.dylib", + "$ark_core_shared_library/libarkziparchive.dylib", + ] + outputs = + [ root_build_dir + "/clang_x64/common/common/{{source_file_part}}" ] + } else { + sources += [ + "$ark_core_shared_library/libarkbase.dll", + "$ark_core_shared_library/libarkfile.dll", + "$ark_core_shared_library/libarkziparchive.dll", + ] + outputs = [ root_build_dir + + "/mingw_x86_64/common/common/{{source_file_part}}" ] + } + ark_js_shared_library = get_label_info("//ark/js_runtime:libark_jsruntime", "root_out_dir") + "/ark/ark_js_runtime" - sources += [ "$ark_js_shared_library/libark_jsruntime.dll" ] deps += [ "//ark/js_runtime:libark_jsruntime" ] - outputs = - [ root_build_dir + "/mingw_x86_64/common/common/{{source_file_part}}" ] + if (use_mac) { + sources += [ "$ark_js_shared_library/libark_jsruntime.dylib" ] + } else { + sources += [ "$ark_js_shared_library/libark_jsruntime.dll" ] + } } ohos_copy("copy_napi_shared_library") { shared_library_path = get_label_info("$ace_napi:ace_napi(${current_toolchain})", "root_out_dir") - sources = [ - "$shared_library_path/arkui/napi/libace_napi.dll", - "$shared_library_path/arkui/napi/libace_napi_ark.dll", - ] deps = [ "$ace_napi:ace_napi(${current_toolchain})", "$ace_napi:ace_napi_ark(${current_toolchain})", ] - outputs = - [ root_build_dir + "/mingw_x86_64/common/common/{{source_file_part}}" ] + if (use_mac) { + sources = [ + "$shared_library_path/arkui/napi/libace_napi.dylib", + "$shared_library_path/arkui/napi/libace_napi_ark.dylib", + ] + outputs = + [ root_build_dir + "/clang_x64/common/common/{{source_file_part}}" ] + } else { + sources = [ + "$shared_library_path/arkui/napi/libace_napi.dll", + "$shared_library_path/arkui/napi/libace_napi_ark.dll", + ] + outputs = [ root_build_dir + + "/mingw_x86_64/common/common/{{source_file_part}}" ] + } + } + ohos_copy("copy_icu_shared_library") { + shared_library_path = + get_label_info("//third_party/icu/icu4c:shared_icuuc", "root_out_dir") + deps = [ + "//third_party/icu/icu4c:shared_icui18n", + "//third_party/icu/icu4c:shared_icuuc", + ] + if (use_mac) { + sources = [ + "$shared_library_path/thirdparty/icu/libhmicui18n.dylib", + "$shared_library_path/thirdparty/icu/libhmicuuc.dylib", + ] + outputs = + [ root_build_dir + "/clang_x64/common/common/{{source_file_part}}" ] + } else { + sources = [ + "$shared_library_path/thirdparty/icu/libhmicui18n.dll", + "$shared_library_path/thirdparty/icu/libhmicuuc.dll", + ] + outputs = [ root_build_dir + + "/mingw_x86_64/common/common/{{source_file_part}}" ] + } } ohos_copy("copy_icu_data_resource") { sources = [ "//third_party/icu/icu4c/source/data/out/tmp/icudt67l.dat" ] - outputs = [ root_build_dir + "/mingw_x86_64/common/common/icudt67l.dat" ] + if (use_mac) { + outputs = [ root_build_dir + "/clang_x64/common/common/icudt67l.dat" ] + } else { + outputs = [ root_build_dir + "/mingw_x86_64/common/common/icudt67l.dat" ] + } } } else { ohos_copy("copy_napi_shared_library_for_test") { diff --git a/adapter/preview/sdk/BUILD.gn b/adapter/preview/sdk/BUILD.gn index 383c6cb9e56..9e93c5e9982 100644 --- a/adapter/preview/sdk/BUILD.gn +++ b/adapter/preview/sdk/BUILD.gn @@ -101,6 +101,15 @@ if (is_standard_system) { ark_js_shared_library = get_label_info("//ark/js_runtime:libark_jsruntime", "root_out_dir") + "/ark/ark_js_runtime" + deps = [ + "$ace_napi:ace_napi", + "$ace_napi:ace_napi_ark", + "//ark/js_runtime:libark_jsruntime", + "//ark/runtime_core/libpandabase:libarkbase", + "//ark/runtime_core/libpandafile:libarkfile", + "//ark/runtime_core/libziparchive:libarkziparchive", + "//third_party/libuv:uv", + ] if (use_mingw_win) { sources = [ "$ark_core_shared_library/libarkbase.dll", @@ -112,14 +121,16 @@ if (is_standard_system) { "$shared_library_path_uv/arkui/napi/libuv.dll", "//third_party/icu/icu4c/source/data/out/tmp/icudt67l.dat", ] - deps = [ - "$ace_napi:ace_napi", - "$ace_napi:ace_napi_ark", - "//ark/js_runtime:libark_jsruntime", - "//ark/runtime_core/libpandabase:libarkbase", - "//ark/runtime_core/libpandafile:libarkfile", - "//ark/runtime_core/libziparchive:libarkziparchive", - "//third_party/libuv:uv", + } else { + sources = [ + "$ark_core_shared_library/libarkbase.dylib", + "$ark_core_shared_library/libarkfile.dylib", + "$ark_core_shared_library/libarkziparchive.dylib", + "$ark_js_shared_library/libark_jsruntime.dylib", + "$shared_library_path_napi/arkui/napi/libace_napi.dylib", + "$shared_library_path_napi/arkui/napi/libace_napi_ark.dylib", + "$shared_library_path_uv/arkui/napi/libuv.dylib", + "//third_party/icu/icu4c/source/data/out/tmp/icudt67l.dat", ] } } else { diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/jsi_declarative_engine.cpp b/frameworks/bridge/declarative_frontend/engine/jsi/jsi_declarative_engine.cpp index d2e5b7961d9..e0efbac2dec 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/jsi_declarative_engine.cpp +++ b/frameworks/bridge/declarative_frontend/engine/jsi/jsi_declarative_engine.cpp @@ -804,9 +804,11 @@ void JsiDeclarativeEngine::RegisterInitWorkerFunc() LOGE("instance is nullptr"); return; } +#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM) ConnectServerManager::Get().AddInstance(gettid()); auto vm = const_cast(arkNativeEngine->GetEcmaVm()); panda::JSNApi::StartDebugger(libraryPath.c_str(), vm, debugMode, gettid()); +#endif instance->InitConsoleModule(arkNativeEngine); std::vector buffer((uint8_t*)_binary_jsEnumStyle_abc_start, (uint8_t*)_binary_jsEnumStyle_abc_end); @@ -818,6 +820,7 @@ void JsiDeclarativeEngine::RegisterInitWorkerFunc() nativeEngine_->SetInitWorkerFunc(initWorkerFunc); } +#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM) void JsiDeclarativeEngine::RegisterOffWorkerFunc() { auto weakInstance = AceType::WeakClaim(AceType::RawPtr(engineInstance_)); @@ -842,6 +845,7 @@ void JsiDeclarativeEngine::RegisterOffWorkerFunc() }; nativeEngine_->SetOffWorkerFunc(offWorkerFunc); } +#endif void JsiDeclarativeEngine::RegisterAssetFunc() { @@ -866,7 +870,9 @@ void JsiDeclarativeEngine::RegisterAssetFunc() void JsiDeclarativeEngine::RegisterWorker() { RegisterInitWorkerFunc(); +#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM) RegisterOffWorkerFunc(); +#endif RegisterAssetFunc(); } diff --git a/frameworks/bridge/js_frontend/engine/jsi/ark_js_runtime.cpp b/frameworks/bridge/js_frontend/engine/jsi/ark_js_runtime.cpp index ca92198f615..84524c95625 100644 --- a/frameworks/bridge/js_frontend/engine/jsi/ark_js_runtime.cpp +++ b/frameworks/bridge/js_frontend/engine/jsi/ark_js_runtime.cpp @@ -38,7 +38,7 @@ bool ArkJSRuntime::Initialize(const std::string &libraryPath, bool isDebugMode, LOGI("Ark: create jsvm"); RuntimeOption option; option.SetGcType(RuntimeOption::GC_TYPE::GEN_GC); -#ifndef WINDOWS_PLATFORM +#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM) option.SetArkProperties(SystemProperties::GetArkProperties()); option.SetAsmInterOption(SystemProperties::GetAsmInterOption()); #endif @@ -67,7 +67,7 @@ void ArkJSRuntime::Reset() { if (vm_ != nullptr) { if (!usingExistVM_) { -#ifndef WINDOWS_PLATFORM +#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM) JSNApi::StopDebugger(vm_); #endif JSNApi::DestroyJSVM(vm_); @@ -103,7 +103,7 @@ bool ArkJSRuntime::ExecuteJsBin(const std::string &fileName) { JSExecutionScope executionScope(vm_); if (!libPath_.empty()) { -#ifndef WINDOWS_PLATFORM +#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM) JSNApi::StartDebugger(libPath_.c_str(), vm_, isDebugMode_, instanceId_); #endif } diff --git a/frameworks/bridge/js_frontend/engine/jsi/jsi_engine.cpp b/frameworks/bridge/js_frontend/engine/jsi/jsi_engine.cpp index 7ae6d31e9e2..b04908e1aa8 100644 --- a/frameworks/bridge/js_frontend/engine/jsi/jsi_engine.cpp +++ b/frameworks/bridge/js_frontend/engine/jsi/jsi_engine.cpp @@ -3167,9 +3167,11 @@ void JsiEngine::RegisterInitWorkerFunc() LOGE("instance is nullptr"); return; } +#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM) ConnectServerManager::Get().AddInstance(gettid()); auto vm = const_cast(arkNativeEngine->GetEcmaVm()); panda::JSNApi::StartDebugger(libraryPath.c_str(), vm, debugMode, gettid()); +#endif instance->RegisterConsoleModule(arkNativeEngine); // load jsfwk if (!arkNativeEngine->ExecuteJsBin("/system/etc/strip.native.min.abc")) { @@ -3179,6 +3181,7 @@ void JsiEngine::RegisterInitWorkerFunc() nativeEngine_->SetInitWorkerFunc(initWorkerFunc); } +#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM) void JsiEngine::RegisterOffWorkerFunc() { auto weakInstance = AceType::WeakClaim(AceType::RawPtr(engineInstance_)); @@ -3203,6 +3206,7 @@ void JsiEngine::RegisterOffWorkerFunc() }; nativeEngine_->SetOffWorkerFunc(offWorkerFunc); } +#endif void JsiEngine::RegisterAssetFunc() { @@ -3227,7 +3231,9 @@ void JsiEngine::RegisterAssetFunc() void JsiEngine::RegisterWorker() { RegisterInitWorkerFunc(); +#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM) RegisterOffWorkerFunc(); +#endif RegisterAssetFunc(); } From 7996d85c5a18c7c4668be3069483820bd703bab0 Mon Sep 17 00:00:00 2001 From: yangzk Date: Thu, 5 May 2022 09:53:21 +0800 Subject: [PATCH 21/35] IssueNo: #I56213 Description: fix form router action event Sig: SIG_ApplicationFramework Feature or Bugfix: Bugfix Binary Source: No Signed-off-by: yangzk Change-Id: Iac9c10632af64baf222b241d838c4107cfe3e203 --- .../core/components/form/form_element.cpp | 11 +---- .../form/resource/form_manager_delegate.cpp | 49 ++++++++++++++----- .../form/resource/form_manager_delegate.h | 2 +- 3 files changed, 40 insertions(+), 22 deletions(-) diff --git a/frameworks/core/components/form/form_element.cpp b/frameworks/core/components/form/form_element.cpp index 6fa47070104..9ea69db4f77 100644 --- a/frameworks/core/components/form/form_element.cpp +++ b/frameworks/core/components/form/form_element.cpp @@ -334,19 +334,12 @@ void FormElement::OnActionEvent(const std::string& action) const return; } +#ifndef OHOS_STANDARD_SYSTEM if ("router" == type) { -#ifdef OHOS_STANDARD_SYSTEM - auto context = GetContext().Upgrade(); - if (context) { - LOGI("send action evetn to ability to process"); - context->OnActionEvent(formManagerBridge_->WrapAction(action)); - formManagerBridge_->OnActionEvent(action); - } -#else HandleOnRouterEvent(eventAction); -#endif return; } +#endif if (formManagerBridge_) { LOGI("send action event to ability."); diff --git a/frameworks/core/components/form/resource/form_manager_delegate.cpp b/frameworks/core/components/form/resource/form_manager_delegate.cpp index f6381a0c84c..74865111a51 100644 --- a/frameworks/core/components/form/resource/form_manager_delegate.cpp +++ b/frameworks/core/components/form/resource/form_manager_delegate.cpp @@ -283,6 +283,37 @@ void FormManagerDelegate::AddFormUninstallCallback(const OnFormUninstallCallback onFormUninstallCallback_ = callback; } +bool FormManagerDelegate::ParseAction(const std::string &action, AAFwk::Want &want) +{ + auto eventAction = JsonUtil::ParseJsonString(action); + auto bundleName = eventAction->GetValue("bundleName"); + auto abilityName = eventAction->GetValue("abilityName"); + auto params = eventAction->GetValue("params"); + auto bundle = bundleName->GetString(); + auto ability = abilityName->GetString(); + LOGI("bundle:%{public}s ability:%{public}s, params:%{public}s", bundle.c_str(), ability.c_str(), + params->GetString().c_str()); + if (bundle.empty()) { + bundle = wantCache_.GetElement().GetBundleName(); + } + if (ability.empty()) { + LOGE("action ability is empty"); + return false; + } + + want.SetElementName(bundle, ability); + if (params->IsValid()) { + auto child = params->GetChild(); + while (child->IsValid()) { + auto key = child->GetKey(); + auto value = child->GetString(); + want.SetParam(key, value); + child = child->GetNext(); + } + } + return true; +} + void FormManagerDelegate::OnActionEvent(const std::string& action) { auto eventAction = JsonUtil::ParseJsonString(action); @@ -304,7 +335,12 @@ void FormManagerDelegate::OnActionEvent(const std::string& action) #ifdef OHOS_STANDARD_SYSTEM if (type == "router") { - AppExecFwk::FormMgr::GetInstance().RouterEvent(runningCardId_); + AAFwk::Want want; + if (!ParseAction(action, want)) { + LOGE("Failed to parse want"); + } else { + AppExecFwk::FormMgr::GetInstance().RouterEvent(runningCardId_, want); + } return; } @@ -411,16 +447,5 @@ void FormManagerDelegate::OnDeathReceived() LOGE("relink to form manager fail!!!"); } } - -std::string FormManagerDelegate::WrapAction(const std::string& action) -{ - auto eventAction = JsonUtil::ParseJsonString(action); - if (!eventAction->Contains("bundleName")) { - eventAction->Put("bundleName", wantCache_.GetElement().GetBundleName().c_str()); - } - auto newAction = eventAction->ToString(); - OHOS::AppExecFwk::FormMgr::GetInstance().UpdateRouterAction(runningCardId_, newAction); - return newAction; -} #endif } // namespace OHOS::Ace diff --git a/frameworks/core/components/form/resource/form_manager_delegate.h b/frameworks/core/components/form/resource/form_manager_delegate.h index a28c90778e4..4b86b3ffe0c 100644 --- a/frameworks/core/components/form/resource/form_manager_delegate.h +++ b/frameworks/core/components/form/resource/form_manager_delegate.h @@ -67,7 +67,6 @@ public: void AddFormUninstallCallback(const OnFormUninstallCallback& callback); void OnActionEvent(const std::string& action); - std::string WrapAction(const std::string& action); #ifdef OHOS_STANDARD_SYSTEM void ProcessFormUpdate(const AppExecFwk::FormJsInfo &formJsInfo); void ProcessFormUninstall(const int64_t formId); @@ -84,6 +83,7 @@ private: void OnFormAcquired(const std::string& param); void OnFormUpdate(const std::string& param); void OnFormError(const std::string& param); + bool ParseAction(const std::string& action, AAFwk::Want &want); onFormAcquiredCallbackForJava onFormAcquiredCallbackForJava_; OnFormUpdateCallbackForJava onFormUpdateCallbackForJava_; From 858a22cbafae93bb3d3e74353bc8266b0737d10c Mon Sep 17 00:00:00 2001 From: xiexiyun Date: Sun, 8 May 2022 16:41:22 +0800 Subject: [PATCH 22/35] watching system parameter to switch status of debug boundary Signed-off-by: xiexiyun Change-Id: Ifb5cb5b918954d401c60ef8e6f92bded42bf37c9 --- adapter/ohos/osal/BUILD.gn | 1 + adapter/ohos/osal/system_properties.cpp | 18 ++++-------------- frameworks/base/utils/system_properties.h | 7 +++++++ frameworks/bridge/common/dom/dom_node.cpp | 1 + .../view_stack_processor.cpp | 4 +--- .../core/components/box/flutter_render_box.cpp | 2 +- .../core/components/box/rosen_render_box.cpp | 2 +- .../common/painter/debug_boundary_painter.cpp | 2 +- .../panel/sliding_panel_component_v2.cpp | 4 +--- .../picker/picker_option_component.cpp | 4 +--- .../core/components/refresh/render_refresh.cpp | 5 +---- .../select_popup/select_popup_component.cpp | 4 +--- .../indexer/indexer_component.cpp | 4 +--- .../indexer/indexer_item_component.cpp | 4 +--- 14 files changed, 23 insertions(+), 39 deletions(-) diff --git a/adapter/ohos/osal/BUILD.gn b/adapter/ohos/osal/BUILD.gn index 284cd04d744..18dde06b608 100644 --- a/adapter/ohos/osal/BUILD.gn +++ b/adapter/ohos/osal/BUILD.gn @@ -26,6 +26,7 @@ template("ace_osal_ohos_source_set") { "bytrace_standard:bytrace_core", "hiviewdfx_hilog_native:libhilog", "startup_l2:syspara", + "startup_l2:syspara_watchagent", ] configs = [ "$ace_root:ace_config" ] } else { diff --git a/adapter/ohos/osal/system_properties.cpp b/adapter/ohos/osal/system_properties.cpp index 972204ae46e..bba4ce23bd4 100644 --- a/adapter/ohos/osal/system_properties.cpp +++ b/adapter/ohos/osal/system_properties.cpp @@ -36,7 +36,8 @@ const char PROPERTY_DEVICE_TYPE_WATCH[] = "watch"; const char PROPERTY_DEVICE_TYPE_CAR[] = "car"; const char DISABLE_ROSEN_FILE_PATH[] = "/etc/disablerosen"; const char DISABLE_WINDOW_ANIMATION_PATH[] = "/etc/disable_window_size_animation"; -const char ENABLE_DEBUG_BOUNDARY_FILE_PATH[] = "/etc/enable_paint_boundary"; +// const char ENABLE_DEBUG_BOUNDARY_FILE_PATH[] = "/etc/enable_paint_boundary"; +const char ENABLE_DEBUG_BOUNDARY_KEY[] = "persist.ace.debug.boundary.enabled"; constexpr int32_t ORIENTATION_PORTRAIT = 0; constexpr int32_t ORIENTATION_LANDSCAPE = 1; @@ -54,17 +55,6 @@ bool IsTraceEnabled() system::GetParameter("debug.ace.trace.enabled", "0") == "1"); } -bool IsDebugBoundaryEnabled() -{ - if (system::GetParameter("persist.ace.debug.boundary.enabled", "0") == "1") { - return true; - } - if (system::GetParameter("persist.ace.debug.boundary.enabled", "0") == "2") { - return false; - } - return access(ENABLE_DEBUG_BOUNDARY_FILE_PATH, F_OK) == 0; -} - bool IsRosenBackendEnabled() { #if defined(WINDOWS_PLATFORM) || defined(MAC_PLATFORM) @@ -171,7 +161,7 @@ ColorMode SystemProperties::colorMode_ { ColorMode::LIGHT }; ScreenShape SystemProperties::screenShape_ { ScreenShape::NOT_ROUND }; LongScreenType SystemProperties::LongScreen_ { LongScreenType::NOT_LONG }; bool SystemProperties::rosenBackendEnabled_ = IsRosenBackendEnabled(); -bool SystemProperties::debugBoundaryEnabled_ = IsDebugBoundaryEnabled(); +bool SystemProperties::debugBoundaryEnabled_ = false; bool SystemProperties::windowAnimationEnabled_ = IsWindowAnimationEnabled(); bool SystemProperties::debugEnabled_ = IsDebugEnabled(); int32_t SystemProperties::windowPosX_ = 0; @@ -227,7 +217,6 @@ void SystemProperties::InitDeviceInfo( traceEnabled_ = IsTraceEnabled(); accessibilityEnabled_ = IsAccessibilityEnabled(); rosenBackendEnabled_ = IsRosenBackendEnabled(); - debugBoundaryEnabled_ = IsDebugBoundaryEnabled(); if (isRound_) { screenShape_ = ScreenShape::ROUND; @@ -236,6 +225,7 @@ void SystemProperties::InitDeviceInfo( } InitDeviceTypeBySystemProperty(); + WatchParameter(ENABLE_DEBUG_BOUNDARY_KEY, SystemProperties::UpdateDebugBoundaryEnabled, nullptr); } void SystemProperties::SetDeviceOrientation(int32_t orientation) diff --git a/frameworks/base/utils/system_properties.h b/frameworks/base/utils/system_properties.h index c4ea2aa01a8..9fec5500791 100644 --- a/frameworks/base/utils/system_properties.h +++ b/frameworks/base/utils/system_properties.h @@ -18,6 +18,8 @@ #include +#include "base/startup/syspara_lite/interfaces/innerkits/native/syspara/include/parameter.h" + #include "base/utils/resource_configuration.h" #include "base/utils/device_type.h" #include "base/utils/macros.h" @@ -274,6 +276,11 @@ public: return windowAnimationEnabled_; } + static void UpdateDebugBoundaryEnabled(const char *key, const char *value, void *context) + { + debugBoundaryEnabled_ = strcmp(value, "1") == 0? true: false; + } + private: static bool traceEnabled_; static bool accessibilityEnabled_; diff --git a/frameworks/bridge/common/dom/dom_node.cpp b/frameworks/bridge/common/dom/dom_node.cpp index 0c11b2c80c4..b14e5634276 100644 --- a/frameworks/bridge/common/dom/dom_node.cpp +++ b/frameworks/bridge/common/dom/dom_node.cpp @@ -95,6 +95,7 @@ DOMNode::DOMNode(NodeId nodeId, const std::string& nodeName) : nodeId_(nodeId), { rootComponent_ = AceType::MakeRefPtr(std::to_string(nodeId), nodeName); boxComponent_ = AceType::MakeRefPtr(); + boxComponent_->SetEnableDebugBoundary(true); CreateDeclaration(nodeName); } diff --git a/frameworks/bridge/declarative_frontend/view_stack_processor.cpp b/frameworks/bridge/declarative_frontend/view_stack_processor.cpp index d7b75011d0d..bac38781b6a 100644 --- a/frameworks/bridge/declarative_frontend/view_stack_processor.cpp +++ b/frameworks/bridge/declarative_frontend/view_stack_processor.cpp @@ -197,9 +197,7 @@ RefPtr ViewStackProcessor::GetBoxComponent() } RefPtr boxComponent = AceType::MakeRefPtr(); - if (SystemProperties::GetDebugBoundaryEnabled()) { - boxComponent->SetEnableDebugBoundary(true); - } + boxComponent->SetEnableDebugBoundary(true); wrappingComponentsMap.emplace("box", boxComponent); return boxComponent; } diff --git a/frameworks/core/components/box/flutter_render_box.cpp b/frameworks/core/components/box/flutter_render_box.cpp index a3baceeaf02..bb7919d7c6a 100644 --- a/frameworks/core/components/box/flutter_render_box.cpp +++ b/frameworks/core/components/box/flutter_render_box.cpp @@ -357,7 +357,7 @@ void FlutterRenderBox::Paint(RenderContext& context, const Offset& offset) outerRRect, canvas->canvas(), frontDecoration_->GetColorBlend(), bgColor); } } - if (RenderBox::needPaintDebugBoundary_) { + if (RenderBox::needPaintDebugBoundary_ && SystemProperties::GetDebugBoundaryEnabled()) { flutter::Canvas* canvas = renderContext->GetCanvas(); if (canvas == nullptr) { LOGE("Paint canvas is null."); diff --git a/frameworks/core/components/box/rosen_render_box.cpp b/frameworks/core/components/box/rosen_render_box.cpp index d4e8e95e9c9..15db8ad8bda 100644 --- a/frameworks/core/components/box/rosen_render_box.cpp +++ b/frameworks/core/components/box/rosen_render_box.cpp @@ -327,7 +327,7 @@ void RosenRenderBox::Paint(RenderContext& context, const Offset& offset) RosenDecorationPainter::PaintColorBlend(outerRRect, canvas, frontDecoration_->GetColorBlend(), bgColor); } } - if (RenderBox::needPaintDebugBoundary_) { + if (RenderBox::needPaintDebugBoundary_ && SystemProperties::GetDebugBoundaryEnabled()) { auto canvas = static_cast(&context)->GetCanvas(); if (canvas == nullptr) { LOGE("Paint canvas is null."); diff --git a/frameworks/core/components/common/painter/debug_boundary_painter.cpp b/frameworks/core/components/common/painter/debug_boundary_painter.cpp index 9267a836ee1..4fafd626282 100644 --- a/frameworks/core/components/common/painter/debug_boundary_painter.cpp +++ b/frameworks/core/components/common/painter/debug_boundary_painter.cpp @@ -27,7 +27,7 @@ namespace OHOS::Ace { namespace { -constexpr double BOUNDARY_STROKE_WIDTH = 3.0; +constexpr double BOUNDARY_STROKE_WIDTH = 1.0; constexpr double BOUNDARY_CORNER_LENGTH = 8.0; constexpr uint32_t BOUNDARY_COLOR = 0xFFFA2A2D; constexpr uint32_t BOUNDARY_CORNER_COLOR = 0xFF007DFF; diff --git a/frameworks/core/components/panel/sliding_panel_component_v2.cpp b/frameworks/core/components/panel/sliding_panel_component_v2.cpp index fd359887669..dde79f22ccb 100644 --- a/frameworks/core/components/panel/sliding_panel_component_v2.cpp +++ b/frameworks/core/components/panel/sliding_panel_component_v2.cpp @@ -85,9 +85,7 @@ void SlidingPanelComponentV2::BuildInnerChild() flexItem->SetChild(GetChild()); column->AppendChild(dragBar); column->AppendChild(flexItem); - if (SystemProperties::GetDebugBoundaryEnabled()) { - boxForContent->SetEnableDebugBoundary(true); - } + boxForContent->SetEnableDebugBoundary(true); boxForContent->SetBackDecoration(backDecoration); boxForContent->SetFrontDecoration(frontDecoration); boxForContent->SetChild(column); diff --git a/frameworks/core/components/picker/picker_option_component.cpp b/frameworks/core/components/picker/picker_option_component.cpp index 620607ffa0e..73a1db04aee 100644 --- a/frameworks/core/components/picker/picker_option_component.cpp +++ b/frameworks/core/components/picker/picker_option_component.cpp @@ -71,9 +71,7 @@ void PickerOptionComponent::Initialize() if (isRtl) { boxComponent_->SetAlignment(Alignment::CENTER_RIGHT); } - if (SystemProperties::GetDebugBoundaryEnabled()) { - boxComponent_->SetEnableDebugBoundary(true); - } + boxComponent_->SetEnableDebugBoundary(true); SetChild(boxComponent_); } diff --git a/frameworks/core/components/refresh/render_refresh.cpp b/frameworks/core/components/refresh/render_refresh.cpp index 706c6290a49..51910f34604 100644 --- a/frameworks/core/components/refresh/render_refresh.cpp +++ b/frameworks/core/components/refresh/render_refresh.cpp @@ -47,10 +47,7 @@ RenderRefresh::RenderRefresh() loading_->SetLoadingMode(MODE_DRAG); loadingBackgroundBoxComponent_ = AceType::MakeRefPtr(); - - if (SystemProperties::GetDebugBoundaryEnabled()) { - loadingBackgroundBoxComponent_->SetEnableDebugBoundary(true); - } + loadingBackgroundBoxComponent_->SetEnableDebugBoundary(true); decoration_ = AceType::MakeRefPtr(); loadingBackgroundBox_ = AceType::DynamicCast(loadingBackgroundBoxComponent_->CreateRenderNode()); diff --git a/frameworks/core/components/select_popup/select_popup_component.cpp b/frameworks/core/components/select_popup/select_popup_component.cpp index 2952b0f1a1b..18b06b51e33 100644 --- a/frameworks/core/components/select_popup/select_popup_component.cpp +++ b/frameworks/core/components/select_popup/select_popup_component.cpp @@ -316,9 +316,7 @@ bool SelectPopupComponent::Initialize(const RefPtr& manage innerClip->SetBottomLeftRadius(Radius(ROUND_RADIUS_PHONE)); innerClip->SetBottomRightRadius(Radius(ROUND_RADIUS_PHONE)); RefPtr box = AceType::MakeRefPtr(); - if (SystemProperties::GetDebugBoundaryEnabled()) { - box->SetEnableDebugBoundary(true); - } + box->SetEnableDebugBoundary(true); box->SetDeliverMinToChild(false); if (!IsTV()) { RefPtr back = AceType::MakeRefPtr(); diff --git a/frameworks/core/components_v2/indexer/indexer_component.cpp b/frameworks/core/components_v2/indexer/indexer_component.cpp index f1e04be69d6..a63850ffb66 100644 --- a/frameworks/core/components_v2/indexer/indexer_component.cpp +++ b/frameworks/core/components_v2/indexer/indexer_component.cpp @@ -106,9 +106,7 @@ void IndexerComponent::BuildBubbleBox() } bubbleText_->SetTextStyle(bubbleStyle_); bubble->SetChild(bubbleText_); - if (SystemProperties::GetDebugBoundaryEnabled()) { - bubble->SetEnableDebugBoundary(true); - } + bubble->SetEnableDebugBoundary(true); RefPtr displayComponent = AceType::MakeRefPtr(bubble); displayComponent->SetOpacity(ZERO_OPACITY); diff --git a/frameworks/core/components_v2/indexer/indexer_item_component.cpp b/frameworks/core/components_v2/indexer/indexer_item_component.cpp index 28ec01d1fcc..0ffe2b71391 100644 --- a/frameworks/core/components_v2/indexer/indexer_item_component.cpp +++ b/frameworks/core/components_v2/indexer/indexer_item_component.cpp @@ -28,9 +28,7 @@ RefPtr IndexerItemComponent::CreateRenderNode() void IndexerItemComponent::BuildItem() { box_ = AceType::MakeRefPtr(); - if (SystemProperties::GetDebugBoundaryEnabled()) { - box_->SetEnableDebugBoundary(true); - } + box_->SetEnableDebugBoundary(true); if (rotate_) { image_ = AceType::MakeRefPtr(InternalResource::ResourceId::INDEXER_ARROW_PNG); image_->SetHeight(itemSize_); From 292dea119bf168988a0e9844f7d5fd325a81a544 Mon Sep 17 00:00:00 2001 From: xiexiyun Date: Sun, 8 May 2022 16:47:10 +0800 Subject: [PATCH 23/35] remove comment Signed-off-by: xiexiyun Change-Id: Ic9de2d42d822636249af2208f8f6b8378dfc60cb --- adapter/ohos/osal/system_properties.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/adapter/ohos/osal/system_properties.cpp b/adapter/ohos/osal/system_properties.cpp index bba4ce23bd4..1f07efa3487 100644 --- a/adapter/ohos/osal/system_properties.cpp +++ b/adapter/ohos/osal/system_properties.cpp @@ -36,7 +36,6 @@ const char PROPERTY_DEVICE_TYPE_WATCH[] = "watch"; const char PROPERTY_DEVICE_TYPE_CAR[] = "car"; const char DISABLE_ROSEN_FILE_PATH[] = "/etc/disablerosen"; const char DISABLE_WINDOW_ANIMATION_PATH[] = "/etc/disable_window_size_animation"; -// const char ENABLE_DEBUG_BOUNDARY_FILE_PATH[] = "/etc/enable_paint_boundary"; const char ENABLE_DEBUG_BOUNDARY_KEY[] = "persist.ace.debug.boundary.enabled"; constexpr int32_t ORIENTATION_PORTRAIT = 0; From c303a85a0493725156b7074bd240d94cccdefb91 Mon Sep 17 00:00:00 2001 From: xiexiyun Date: Sun, 8 May 2022 16:58:32 +0800 Subject: [PATCH 24/35] revise flag changing expression Signed-off-by: xiexiyun Change-Id: Ibd8cb48388f2e2ce5156acab50321f610a3536b2 --- frameworks/base/utils/system_properties.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/frameworks/base/utils/system_properties.h b/frameworks/base/utils/system_properties.h index 9fec5500791..44efce3e7bf 100644 --- a/frameworks/base/utils/system_properties.h +++ b/frameworks/base/utils/system_properties.h @@ -278,7 +278,11 @@ public: static void UpdateDebugBoundaryEnabled(const char *key, const char *value, void *context) { - debugBoundaryEnabled_ = strcmp(value, "1") == 0? true: false; + if (strcmp(value, "true") == 0) { + debugBoundaryEnabled_ = true; + } else if (strcmp(value, "false") == 0) { + debugBoundaryEnabled_ = false; + } } private: From 6a9c27036442782b74572f11aeafa82428680176 Mon Sep 17 00:00:00 2001 From: xiexiyun Date: Sun, 8 May 2022 17:03:49 +0800 Subject: [PATCH 25/35] code check Signed-off-by: xiexiyun Change-Id: I08974202efedb55d90e10d1a064e9f83bc098e8f --- frameworks/base/utils/system_properties.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/base/utils/system_properties.h b/frameworks/base/utils/system_properties.h index 44efce3e7bf..b62291ba229 100644 --- a/frameworks/base/utils/system_properties.h +++ b/frameworks/base/utils/system_properties.h @@ -283,7 +283,7 @@ public: } else if (strcmp(value, "false") == 0) { debugBoundaryEnabled_ = false; } - } + } private: static bool traceEnabled_; From e8b868f5e63e3e5e0330b8c4ef14a2313d3c1939 Mon Sep 17 00:00:00 2001 From: jiangkuaixue Date: Sat, 7 May 2022 11:09:34 +0800 Subject: [PATCH 26/35] add web getcookie and deleteentirelycookie Signed-off-by: jiangkuaixue --- .../jsview/js_web_controller.cpp | 25 ++++++++ .../components/web/resource/web_delegate.cpp | 30 ++++++++++ .../components/web/resource/web_delegate.h | 2 + .../core/components/web/web_component.h | 58 +++++++++++++++++++ 4 files changed, 115 insertions(+) diff --git a/frameworks/bridge/declarative_frontend/jsview/js_web_controller.cpp b/frameworks/bridge/declarative_frontend/jsview/js_web_controller.cpp index cd9c3331824..75b23910155 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_web_controller.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_web_controller.cpp @@ -77,6 +77,8 @@ public: { JSClass::Declare("WebCookie"); JSClass::CustomMethod("setCookie", &JSWebCookie::SetCookie); + JSClass::CustomMethod("getCookie", &JSWebCookie::GetCookie); + JSClass::CustomMethod("deleteEntireCookie", &JSWebCookie::DeleteEntirelyCookie); JSClass::CustomMethod("saveCookieSync", &JSWebCookie::SaveCookieSync); JSClass::Bind(globalObj, JSWebCookie::Constructor, JSWebCookie::Destructor); } @@ -108,6 +110,29 @@ public: args.SetReturnValue(returnValue); } + void GetCookie(const JSCallbackInfo& args) + { + if (!manager_) { + return; + } + std::string url; + if (args[0]->IsString()) { + url = args[0]->ToString(); + } + std::string result = manager_->GetCookie(url); + auto jsVal = JSVal(ToJSValue(result)); + auto returnValue = JSRef::Make(jsVal); + args.SetReturnValue(returnValue); + } + + void DeleteEntirelyCookie(const JSCallbackInfo& args) + { + if (!manager_) { + return; + } + manager_->DeleteEntirelyCookie(); + } + void SaveCookieSync(const JSCallbackInfo& args) { if (!manager_) { diff --git a/frameworks/core/components/web/resource/web_delegate.cpp b/frameworks/core/components/web/resource/web_delegate.cpp index d32969df886..22889244ab8 100755 --- a/frameworks/core/components/web/resource/web_delegate.cpp +++ b/frameworks/core/components/web/resource/web_delegate.cpp @@ -635,6 +635,21 @@ bool WebDelegate::SetCookie(const std::string url, const std::string value) return false; } +std::string WebDelegate::GetCookie(const std::string url) +{ + if (cookieManager_) { + return cookieManager_->ReturnCookie(url); + } + return ""; +} + +void WebDelegate::DeleteEntirelyCookie() +{ + if (cookieManager_) { + cookieManager_->DeleteCookieEntirely(nullptr); + } +} + void WebDelegate::CreatePluginResource( const Size& size, const Offset& position, const WeakPtr& context) { @@ -990,6 +1005,21 @@ void WebDelegate::SetWebCallBack() } return false; }); + webController->SetGetCookieImpl( + [weak = WeakClaim(this)](std::string url) { + auto delegate = weak.Upgrade(); + if (delegate) { + return delegate->GetCookie(url); + } + return std::string(); + }); + webController->SetDeleteEntirelyCookieImpl( + [weak = WeakClaim(this)]() { + auto delegate = weak.Upgrade(); + if (delegate) { + delegate->DeleteEntirelyCookie(); + } + }); webController->SetWebViewJavaScriptResultCallBackImpl([weak = WeakClaim(this), uiTaskExecutor]( WebController::JavaScriptCallBackImpl&& javaScriptCallBackImpl) { uiTaskExecutor.PostTask([weak, javaScriptCallBackImpl]() { diff --git a/frameworks/core/components/web/resource/web_delegate.h b/frameworks/core/components/web/resource/web_delegate.h index e52dfd10e67..1ea9bdc58c7 100755 --- a/frameworks/core/components/web/resource/web_delegate.h +++ b/frameworks/core/components/web/resource/web_delegate.h @@ -225,6 +225,8 @@ private: int GetHitTestResult(); bool SaveCookieSync(); bool SetCookie(const std::string url, const std::string value); + std::string GetCookie(const std::string url); + void DeleteEntirelyCookie(); void RegisterOHOSWebEventAndMethord(); void SetWebCallBack(); diff --git a/frameworks/core/components/web/web_component.h b/frameworks/core/components/web/web_component.h index 172f4b3244a..802bfcced00 100755 --- a/frameworks/core/components/web/web_component.h +++ b/frameworks/core/components/web/web_component.h @@ -58,6 +58,8 @@ class WebCookie : public virtual AceType { public: using SetCookieImpl = std::function; + using GetCookieImpl = std::function; + using DeleteEntirelyCookieImpl = std::function; using SaveCookieSyncImpl = std::function; bool SetCookie(const std::string url, const std::string value) { @@ -67,6 +69,21 @@ public: return false; } + std::string GetCookie(const std::string url) + { + if (getCookieImpl_) { + return getCookieImpl_(url); + } + return ""; + } + + void DeleteEntirelyCookie() + { + if (deleteEntirelyCookieImpl_) { + deleteEntirelyCookieImpl_(); + } + } + bool SaveCookieSync() { if (saveCookieSyncImpl_) { @@ -80,6 +97,16 @@ public: setCookieImpl_ = setCookieImpl; } + void SetGetCookieImpl(GetCookieImpl && getCookieImpl) + { + getCookieImpl_ = getCookieImpl; + } + + void SetDeleteEntirelyCookieImpl(DeleteEntirelyCookieImpl && deleteEntirelyCookieImpl) + { + deleteEntirelyCookieImpl_ = deleteEntirelyCookieImpl; + } + void SetSaveCookieSyncImpl(SaveCookieSyncImpl && saveCookieSyncImpl) { saveCookieSyncImpl_ = saveCookieSyncImpl; @@ -87,6 +114,8 @@ public: private: SetCookieImpl setCookieImpl_; + GetCookieImpl getCookieImpl_; + DeleteEntirelyCookieImpl deleteEntirelyCookieImpl_; SaveCookieSyncImpl saveCookieSyncImpl_; }; @@ -331,6 +360,8 @@ public: cookieManager_ = new WebCookie(); cookieManager_->SetSaveCookieSyncImpl(std::move(saveCookieSyncImpl_)); cookieManager_->SetSetCookieImpl(std::move(setCookieImpl_)); + cookieManager_->SetGetCookieImpl(std::move(getCookieImpl_)); + cookieManager_->SetDeleteEntirelyCookieImpl(std::move(deleteEntirelyCookieImpl_)); return cookieManager_; } @@ -347,6 +378,31 @@ public: setCookieImpl_ = setCookieImpl; } + using GetCookieImpl = std::function; + std::string GetCookie(const std::string url) + { + if (getCookieImpl_) { + return getCookieImpl_(url); + } + return ""; + } + void SetGetCookieImpl(GetCookieImpl && getCookieImpl) + { + getCookieImpl_ = getCookieImpl; + } + + using DeleteEntirelyCookieImpl = std::function; + void DeleteEntirelyCookie() + { + if (deleteEntirelyCookieImpl_) { + deleteEntirelyCookieImpl_(); + } + } + void SetDeleteEntirelyCookieImpl(DeleteEntirelyCookieImpl && deleteEntirelyCookieImpl) + { + deleteEntirelyCookieImpl_ = deleteEntirelyCookieImpl; + } + using SaveCookieSyncImpl = std::function; bool SaveCookieSync() { @@ -447,6 +503,8 @@ private: GetHitTestResultImpl getHitTestResultImpl_; SaveCookieSyncImpl saveCookieSyncImpl_; SetCookieImpl setCookieImpl_; + GetCookieImpl getCookieImpl_; + DeleteEntirelyCookieImpl deleteEntirelyCookieImpl_; AddJavascriptInterfaceImpl addJavascriptInterfaceImpl_; RemoveJavascriptInterfaceImpl removeJavascriptInterfaceImpl_; WebViewJavaScriptResultCallBackImpl webViewJavaScriptResultCallBackImpl_; From e772e1c9bc015c86146d4a632bcd40f31218c1f2 Mon Sep 17 00:00:00 2001 From: yaoyuchi Date: Fri, 6 May 2022 15:36:38 +0800 Subject: [PATCH 27/35] featrure:ability Signed-off-by: yaoyuchi Change-Id: Ic4f40cfd4c0555284f92159e2fa802d657e0e3b2 --- adapter/ohos/build/config.gni | 5 + adapter/ohos/capability/BUILD.gn | 22 +++ .../window_extension_connection_ohos.cpp | 130 ++++++++++++++++++ .../window_extension_connection_ohos.h | 36 +++++ .../window_extension_connection_proxy.cpp | 26 ++++ adapter/preview/build/config_mac.gni | 1 + adapter/preview/build/config_windows.gni | 2 + .../bridge/declarative_frontend/BUILD.gn | 10 +- .../engine/jsi/jsi_view_register.cpp | 2 + .../engine/quickjs/qjs_view_register.cpp | 3 +- .../engine/v8/v8_view_register.cpp | 2 + .../jsview/js_ability_component.cpp | 47 ++++++- .../jsview/js_ability_component.h | 3 + frameworks/core/BUILD.gn | 5 + .../window_extension_connection_adapter.h | 41 ++++++ .../window_extension_connection_proxy.h | 29 ++++ .../components_v2/ability_component/BUILD.gn | 22 +++ .../ability_component/ability_component.cpp | 31 +++++ .../ability_component/ability_component.h | 58 ++++++++ .../ability_component_element.h | 28 ++++ .../render_ability_component.cpp | 62 +++++++++ .../render_ability_component.h | 67 +++++++++ 22 files changed, 627 insertions(+), 5 deletions(-) create mode 100644 adapter/ohos/capability/window_connection/window_extension_connection_ohos.cpp create mode 100644 adapter/ohos/capability/window_connection/window_extension_connection_ohos.h create mode 100644 adapter/ohos/capability/window_connection/window_extension_connection_proxy.cpp create mode 100644 frameworks/core/common/window/window_extension_connection_adapter.h create mode 100644 frameworks/core/common/window/window_extension_connection_proxy.h create mode 100644 frameworks/core/components_v2/ability_component/BUILD.gn create mode 100644 frameworks/core/components_v2/ability_component/ability_component.cpp create mode 100644 frameworks/core/components_v2/ability_component/ability_component.h create mode 100644 frameworks/core/components_v2/ability_component/ability_component_element.h create mode 100644 frameworks/core/components_v2/ability_component/render_ability_component.cpp create mode 100644 frameworks/core/components_v2/ability_component/render_ability_component.h diff --git a/adapter/ohos/build/config.gni b/adapter/ohos/build/config.gni index 55dbdc38866..5bcecb532c8 100644 --- a/adapter/ohos/build/config.gni +++ b/adapter/ohos/build/config.gni @@ -72,6 +72,7 @@ enable_rosen_backend = true enable_standard_input = true build_container_scope_lib = true multiple_window_support = true +enable_ability_component = true if (defined(is_experiment_build) && is_experiment_build) { web_components_support = true @@ -83,6 +84,10 @@ if (defined(web_components_support) && web_components_support) { defines += [ "WEB_SUPPORTED" ] } +if (defined(enable_ability_component) && enable_ability_component) { + defines += [ "ABILITY_COMPONENT_SUPPORTED" ] +} + if (disable_gpu || enable_rosen_backend) { defines += [ "GPU_DISABLED" ] } diff --git a/adapter/ohos/capability/BUILD.gn b/adapter/ohos/capability/BUILD.gn index 0412c38f29a..8da84ab1bd4 100644 --- a/adapter/ohos/capability/BUILD.gn +++ b/adapter/ohos/capability/BUILD.gn @@ -41,6 +41,28 @@ template("ace_capability_ohos_source_set") { external_deps += [ "pasteboard_native:pasteboard_client" ] defines += [ "SYSTEM_CLIPBOARD_SUPPORTED" ] } + if (defined(config.enable_ability_component) && + config.enable_ability_component) { + external_deps += [ + "ability_base:want", + "ability_runtime:ability_manager", + "ability_runtime:abilitykit_native", + "ability_runtime:runtime", + "bundle_framework:appexecfwk_base", + "eventhandler:libeventhandler", + "graphic_standard:surface", + "hiviewdfx_hilog_native:libhilog", + "input:libmmi-client", + "ipc:ipc_core", + "utils_base:utils", + "window_manager:libwindow_extension_client", + ] + deps = [ "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client" ] + sources += [ + "window_connection/window_extension_connection_ohos.cpp", + "window_connection/window_extension_connection_proxy.cpp", + ] + } } } diff --git a/adapter/ohos/capability/window_connection/window_extension_connection_ohos.cpp b/adapter/ohos/capability/window_connection/window_extension_connection_ohos.cpp new file mode 100644 index 00000000000..69530ab4c2d --- /dev/null +++ b/adapter/ohos/capability/window_connection/window_extension_connection_ohos.cpp @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2022 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 "window_extension_connection_ohos.h" + +#include + +#include "element_name.h" +#include "render_service_client/core/ui/rs_surface_node.h" + +#include "base/memory/ace_type.h" +#include "frameworks/base/json/json_util.h" +#include "frameworks/core/components_v2/ability_component/render_ability_component.h" + +#ifdef OS_ACCOUNT_EXISTS +#include "os_account_manager.h" +#endif + +namespace OHOS::Ace { +class ConnectionCallback : public Rosen::IWindowExtensionCallback { +public: + explicit ConnectionCallback(WeakPtr node) : node_(std::move(node)) {} + ~ConnectionCallback() override = default; + void OnWindowReady(const std::shared_ptr& rsSurfaceNode) override + { + LOGI("OnWindowReady and ready to connect extension"); + auto nodeStrong = node_.Upgrade(); + if (!nodeStrong) { + LOGI("cannot replace sureface node because the render node is empty"); + return; + } + rsSurfaceNode->CreateNodeInRenderThread(); + auto rect = nodeStrong->GetPaintRect(); + auto offset = rect.GetOffset(); + auto size = rect.GetSize(); + rsSurfaceNode->SetFrame(static_cast(offset.GetX()), static_cast(offset.GetY()), + static_cast(size.Width()), static_cast(size.Height())); + nodeStrong->SyncRSNode(std::static_pointer_cast(rsSurfaceNode)); + nodeStrong->MarkNeedLayout(); + auto ability = AceType::DynamicCast(nodeStrong); + if (ability) { + ability->FireConnect(); + } + } + + void OnExtensionDisconnected() override + { + auto ability = AceType::DynamicCast(node_.Upgrade()); + if (ability) { + ability->FireDisconnect(); + } + } + + void OnKeyEvent(const std::shared_ptr& event) override {} + void OnPointerEvent(const std::shared_ptr& event) override {} + void OnBackPress() override {} + +private: + WeakPtr node_; +}; + +void RectConverter(const Rect& rect, Rosen::Rect& rosenRect) +{ + rosenRect.posX_ = static_cast(rect.GetOffset().GetX()); + rosenRect.posY_ = static_cast(rect.GetOffset().GetY()); + rosenRect.width_ = static_cast(rect.GetSize().Width()); + rosenRect.height_ = static_cast(rect.GetSize().Height()); +} + +void WantConverter(const std::string& want, AppExecFwk::ElementName& element) +{ + auto json = JsonUtil::ParseJsonString(want); + element.SetAbilityName(json->GetValue("ability")->GetString()); + element.SetBundleName(json->GetValue("bundle")->GetString()); +} + +void WindowExtensionConnectionAdapterOhos::ConnectExtension( + const std::string& want, const Rect& rect, WeakPtr node) +{ +#if defined(ENABLE_ROSEN_BACKEND) && defined(OS_ACCOUNT_EXISTS) + LOGI("connect to windows extension begin"); + windowExtension_ = std::make_unique(); + std::vector userIds; + ErrCode code = AccountSA::OsAccountManager::QueryActiveOsAccountIds(userIds); + if (code != ERR_OK) { + LOGE("fail to queryAccountId, so cannot connect extension"); + return; + } + Rosen::Rect rosenRect; + RectConverter(rect, rosenRect); + AppExecFwk::ElementName element; + WantConverter(want, element); + sptr callback = new ConnectionCallback(node); + windowExtension_->ConnectExtension(element, rosenRect, userIds.front(), callback); +#else + LOGI("unrosen engine doesn't support ability component"); +#endif +} + +void WindowExtensionConnectionAdapterOhos::RemoveExtension() +{ + if (windowExtension_) { + LOGI("no implement for remove"); + } else { + LOGI("ability doesn't connect to window extension. remove extension fail"); + } +} + +void WindowExtensionConnectionAdapterOhos::UpdateRect(const Rect& rect) +{ + if (windowExtension_) { + Rosen::Rect rosenRect; + RectConverter(rect, rosenRect); + windowExtension_->SetBounds(rosenRect); + } else { + LOGI("ability doesn't connect to window extension.cannot update rect region "); + } +} +} // namespace OHOS::Ace diff --git a/adapter/ohos/capability/window_connection/window_extension_connection_ohos.h b/adapter/ohos/capability/window_connection/window_extension_connection_ohos.h new file mode 100644 index 00000000000..5c1317f8065 --- /dev/null +++ b/adapter/ohos/capability/window_connection/window_extension_connection_ohos.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2022 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 FOUNDATION_ACE_ACE_ENGINE_ADAPTER_OHOS_CAPABILITY_WINDOW_CONNECTION_WINDOW_EXTENSION_CONNECTION_OHOS_H +#define FOUNDATION_ACE_ACE_ENGINE_ADAPTER_OHOS_CAPABILITY_WINDOW_CONNECTION_WINDOW_EXTENSION_CONNECTION_OHOS_H + +#include "window_extension_connection.h" + +#include "core/common/window/window_extension_connection_adapter.h" + +namespace OHOS::Ace { +class ACE_EXPORT WindowExtensionConnectionAdapterOhos : public WindowExtensionConnectionAdapter { + DECLARE_ACE_TYPE(WindowExtensionConnectionAdapterOhos, WindowExtensionConnectionAdapter); +public: + void ConnectExtension(const std::string& want, const Rect& rect, WeakPtr node) override; + void RemoveExtension() override; + void UpdateRect(const Rect& rect) override; + +private: + std::unique_ptr windowExtension_; +}; +} // namespace OHOS::Ace + +#endif // FOUNDATION_ACE_ACE_ENGINE_ADAPTER_OHOS_CAPABILITY_WINDOW_CONNECTION_WINDOW_EXTENSION_CONNECTION_OHOS_H \ No newline at end of file diff --git a/adapter/ohos/capability/window_connection/window_extension_connection_proxy.cpp b/adapter/ohos/capability/window_connection/window_extension_connection_proxy.cpp new file mode 100644 index 00000000000..1eb8d20347f --- /dev/null +++ b/adapter/ohos/capability/window_connection/window_extension_connection_proxy.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2022 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 "core/common/window/window_extension_connection_proxy.h" + +#include "window_extension_connection_ohos.h" + +#include "base/memory/ace_type.h" + +namespace OHOS::Ace { +RefPtr WindowExtensionConnectionProxy::CreateAdapter() +{ + return AceType::MakeRefPtr(); +} +} // namespace OHOS::Ace diff --git a/adapter/preview/build/config_mac.gni b/adapter/preview/build/config_mac.gni index aed10805f11..82b7ab2fc88 100644 --- a/adapter/preview/build/config_mac.gni +++ b/adapter/preview/build/config_mac.gni @@ -54,6 +54,7 @@ connect_server_support = false enable_rosen_backend = false enable_standard_input = false enable_system_clipboard = false +enable_ability_component = false if (form_components_support) { defines += [ "FORM_SUPPORTED" ] diff --git a/adapter/preview/build/config_windows.gni b/adapter/preview/build/config_windows.gni index d85a4b3a9ec..e482f4bfa70 100644 --- a/adapter/preview/build/config_windows.gni +++ b/adapter/preview/build/config_windows.gni @@ -38,6 +38,8 @@ if (enable_ark_preview) { xcomponent_components_support = true } +enable_ability_component = false + # windows platform defines and configs defines = [ "WINDOWS_PLATFORM", diff --git a/frameworks/bridge/declarative_frontend/BUILD.gn b/frameworks/bridge/declarative_frontend/BUILD.gn index c503837127a..c3bd7de4391 100644 --- a/frameworks/bridge/declarative_frontend/BUILD.gn +++ b/frameworks/bridge/declarative_frontend/BUILD.gn @@ -122,8 +122,6 @@ template("declarative_js_engine") { "jsview/action_sheet/js_action_sheet.cpp", "jsview/dialog/js_alert_dialog.cpp", "jsview/dialog/js_custom_dialog_controller.cpp", - "jsview/js_ability_component.cpp", - "jsview/js_ability_component_controller.cpp", "jsview/js_animator.cpp", "jsview/js_badge.cpp", "jsview/js_blank.cpp", @@ -250,6 +248,14 @@ template("declarative_js_engine") { ] } + if (defined(config.enable_ability_component) && + config.enable_ability_component) { + sources += [ + "jsview/js_ability_component.cpp", + "jsview/js_ability_component_controller.cpp", + ] + } + if (defined(config.web_components_support) && config.web_components_support) { sources += [ diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/jsi_view_register.cpp b/frameworks/bridge/declarative_frontend/engine/jsi/jsi_view_register.cpp index fa3bb5a19e4..4f3b5957955 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/jsi_view_register.cpp +++ b/frameworks/bridge/declarative_frontend/engine/jsi/jsi_view_register.cpp @@ -856,7 +856,9 @@ static const std::unordered_map> { "ActionSheet", JSActionSheet::JSBind }, { "AlertDialog", JSAlertDialog::JSBind }, { "ContextMenu", JSContextMenu::JSBind }, +#ifdef ABILITY_COMPONENT_SUPPORTED { "AbilityComponent", JSAbilityComponent::JSBind }, +#endif { "TextArea", JSTextArea::JSBind }, { "TextInput", JSTextInput::JSBind }, { "TextClock", JSTextClock::JSBind }, diff --git a/frameworks/bridge/declarative_frontend/engine/quickjs/qjs_view_register.cpp b/frameworks/bridge/declarative_frontend/engine/quickjs/qjs_view_register.cpp index 314ecec7bac..f714c95cf8b 100644 --- a/frameworks/bridge/declarative_frontend/engine/quickjs/qjs_view_register.cpp +++ b/frameworks/bridge/declarative_frontend/engine/quickjs/qjs_view_register.cpp @@ -968,9 +968,10 @@ void JsRegisterViews(BindingTarget globalObj) JSActionSheet::JSBind(globalObj); JSAlertDialog::JSBind(globalObj); JSContextMenu::JSBind(globalObj); +#ifdef ABILITY_COMPONENT_SUPPORTED JSAbilityComponent::JSBind(globalObj); JSAbilityComponentController::JSBind(globalObj); - +#endif JSCustomDialogController::JSBind(globalObj); JSShareData::JSBind(globalObj); diff --git a/frameworks/bridge/declarative_frontend/engine/v8/v8_view_register.cpp b/frameworks/bridge/declarative_frontend/engine/v8/v8_view_register.cpp index 98f120cda32..57cdfd22845 100644 --- a/frameworks/bridge/declarative_frontend/engine/v8/v8_view_register.cpp +++ b/frameworks/bridge/declarative_frontend/engine/v8/v8_view_register.cpp @@ -633,7 +633,9 @@ static const std::unordered_map> {"ActionSheet", JSActionSheet::JSBind}, {"AlertDialog", JSAlertDialog::JSBind}, {"ContextMenu", JSContextMenu::JSBind }, +#ifdef ABILITY_COMPONENT_SUPPORTED {"AbilityComponent", JSAbilityComponent::JSBind}, +#endif {"TextArea", JSTextArea::JSBind}, {"TextInput", JSTextInput::JSBind}, {"TextClock", JSTextClock::JSBind}, diff --git a/frameworks/bridge/declarative_frontend/jsview/js_ability_component.cpp b/frameworks/bridge/declarative_frontend/jsview/js_ability_component.cpp index 09ec59ee7aa..1666b7a3719 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_ability_component.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_ability_component.cpp @@ -15,7 +15,9 @@ #include "frameworks/bridge/declarative_frontend/jsview/js_ability_component.h" +#include "frameworks/base/json/json_util.h" #include "frameworks/bridge/declarative_frontend/jsview/js_ability_component_controller.h" +#include "frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h" #include "frameworks/bridge/declarative_frontend/jsview/js_view_common_def.h" #include "frameworks/bridge/declarative_frontend/view_stack_processor.h" @@ -31,6 +33,8 @@ void JSAbilityComponent::JSBind(BindingTarget globalObj) JSClass::StaticMethod("onAbilityCreated", &JSAbilityComponent::JsOnAbilityCreated, opt); JSClass::StaticMethod("onAbilityMoveToFront", &JSAbilityComponent::JsOnAbilityMovedFront, opt); JSClass::StaticMethod("onAbilityWillRemove", &JSAbilityComponent::JsOnAbilityWillRemove, opt); + JSClass::StaticMethod("width", &JSAbilityComponent::Width, opt); + JSClass::StaticMethod("height", &JSAbilityComponent::Height, opt); JSClass::Inherit(); JSClass::Bind<>(globalObj); } @@ -40,13 +44,26 @@ void JSAbilityComponent::Create(const JSCallbackInfo& info) if (info.Length() != 1 || !info[0]->IsObject()) { return; } - auto component = AceType::MakeRefPtr(); + RefPtr component; auto obj = JSRef::Cast(info[0]); - // Parse want JSRef wantValue = obj->GetProperty("want"); if (wantValue->IsObject()) { + component = AceType::MakeRefPtr(); component->SetWant(wantValue->ToString()); + } else { + RefPtr ability = AceType::MakeRefPtr(); + auto jsonStr = JsonUtil::Create(true); + if (obj->GetProperty("bundleName")->IsNull() || obj->GetProperty("bundleName")->IsUndefined() || + obj->GetProperty("abilityName")->IsNull() || obj->GetProperty("abilityName")->IsUndefined()) { + LOGI("bundleName or abilityName is undefined"); + return; + } + jsonStr->Put("bundle", obj->GetProperty("bundleName")->ToString().c_str()); + jsonStr->Put("ability", obj->GetProperty("abilityName")->ToString().c_str()); + ability->SetWant(jsonStr->ToString()); + ViewStackProcessor::GetInstance()->Push(ability); + return; } // Parse controller @@ -86,4 +103,30 @@ void JSAbilityComponent::JsOnAbilityWillRemove(const JSCallbackInfo& info) JSViewBindEvent(&AbilityComponent::SetOnAbilityWillRemove, info); } +void JSAbilityComponent::Width(const JSCallbackInfo& info) +{ + JSViewAbstract::JsWidth(info); + auto component = AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetMainComponent()); + if (component) { + Dimension value; + if (!ParseJsDimensionVp(info[0], value)) { + return; + } + component->SetWidth(static_cast(value.ConvertToVp())); + } +} + +void JSAbilityComponent::Height(const JSCallbackInfo& info) +{ + JSViewAbstract::JsHeight(info); + auto component = AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetMainComponent()); + if (component) { + Dimension value; + if (!ParseJsDimensionVp(info[0], value)) { + return; + } + component->SetHeight(static_cast(value.ConvertToVp())); + } +} + } // namespace OHOS::Ace::Framework diff --git a/frameworks/bridge/declarative_frontend/jsview/js_ability_component.h b/frameworks/bridge/declarative_frontend/jsview/js_ability_component.h index a329b47c1fd..6d17bc74501 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_ability_component.h +++ b/frameworks/bridge/declarative_frontend/jsview/js_ability_component.h @@ -17,6 +17,7 @@ #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_ABILITY_COMPONENT_H #include "core/components/ability_component/ability_component.h" +#include "core/components_v2/ability_component/ability_component.h" #include "frameworks/bridge/declarative_frontend/jsview/js_interactable_view.h" #include "frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h" @@ -29,6 +30,8 @@ public: static void JsOnReady(const JSCallbackInfo& info); static void JsOnDestroy(const JSCallbackInfo& info); + static void Height(const JSCallbackInfo& info); + static void Width(const JSCallbackInfo& info); static void JsOnAbilityCreated(const JSCallbackInfo& info); static void JsOnAbilityMovedFront(const JSCallbackInfo& info); static void JsOnAbilityWillRemove(const JSCallbackInfo& info); diff --git a/frameworks/core/BUILD.gn b/frameworks/core/BUILD.gn index 2c6f865ef6c..fe14e78bab9 100644 --- a/frameworks/core/BUILD.gn +++ b/frameworks/core/BUILD.gn @@ -350,6 +350,11 @@ template("ace_core_source_set") { deps += [ "$ace_root/frameworks/core/components/xcomponent:ace_core_components_xcomponent_$platform" ] } + if (defined(config.enable_ability_component) && + config.enable_ability_component) { + deps += [ "$ace_root/frameworks/core/components_v2/ability_component:ace_core_components_ability_v2_$platform" ] + } + if (defined(config.form_components_support) && config.form_components_support) { if (!use_mingw_win && !use_mac) { diff --git a/frameworks/core/common/window/window_extension_connection_adapter.h b/frameworks/core/common/window/window_extension_connection_adapter.h new file mode 100644 index 00000000000..986fd7fa4d7 --- /dev/null +++ b/frameworks/core/common/window/window_extension_connection_adapter.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2022 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_WINDOW_WINDOW_EXTENSION_CONNECTION_ADAPTER_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_WINDOW_WINDOW_EXTENSION_CONNECTION_ADAPTER_H + +#include + +#include "base/memory/referenced.h" +#include "base/thread/task_executor.h" +#include "base/geometry/rect.h" +#include "core/pipeline/base/render_node.h" + +namespace OHOS::Ace { +class ACE_EXPORT WindowExtensionConnectionAdapter : public AceType { + DECLARE_ACE_TYPE(WindowExtensionConnectionAdapter, AceType); + +public: + virtual void Show() {} + virtual void Hide() {} + virtual void RequestFocus() {} + + virtual void ConnectExtension(const std::string& want, const Rect& rect, WeakPtr node) = 0; + virtual void UpdateRect(const Rect& rect) = 0; + virtual void RemoveExtension() = 0; +}; +} // namespace OHOS::Ace + +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_WINDOW_WINDOW_EXTENSION_CONNECTION_ADAPTER_H diff --git a/frameworks/core/common/window/window_extension_connection_proxy.h b/frameworks/core/common/window/window_extension_connection_proxy.h new file mode 100644 index 00000000000..f053bf15010 --- /dev/null +++ b/frameworks/core/common/window/window_extension_connection_proxy.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2022 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_WINDOW_WINDOW_EXTENSION_CONNECTION_PROXY_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_WINDOW_WINDOW_EXTENSION_CONNECTION_PROXY_H + +#include "base/memory/referenced.h" +#include "core/common/window/window_extension_connection_adapter.h" + +namespace OHOS::Ace { +class ACE_EXPORT WindowExtensionConnectionProxy { +public: + static RefPtr CreateAdapter(); +}; +} // namespace OHOS::Ace + +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_WINDOW_WINDOW_EXTENSION_CONNECTION_PROXY_H \ No newline at end of file diff --git a/frameworks/core/components_v2/ability_component/BUILD.gn b/frameworks/core/components_v2/ability_component/BUILD.gn new file mode 100644 index 00000000000..7e1e2d696e2 --- /dev/null +++ b/frameworks/core/components_v2/ability_component/BUILD.gn @@ -0,0 +1,22 @@ +# Copyright (c) 2022 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. + +import( + "//foundation/arkui/ace_engine/frameworks/core/components/components.gni") + +build_component("ability_v2") { + sources = [ + "ability_component.cpp", + "render_ability_component.cpp", + ] +} diff --git a/frameworks/core/components_v2/ability_component/ability_component.cpp b/frameworks/core/components_v2/ability_component/ability_component.cpp new file mode 100644 index 00000000000..4880bf5e260 --- /dev/null +++ b/frameworks/core/components_v2/ability_component/ability_component.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2022 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 "core/components_v2/ability_component/ability_component.h" + +#include "core/components_v2/ability_component/ability_component_element.h" +#include "core/components_v2/ability_component/render_ability_component.h" + +namespace OHOS::Ace::V2 { +RefPtr AbilityComponent::CreateRenderNode() +{ + return RenderAbilityComponent::Create(); +} + +RefPtr AbilityComponent::CreateElement() +{ + return AceType::MakeRefPtr(); +} +} // namespace OHOS::Ace::V2 diff --git a/frameworks/core/components_v2/ability_component/ability_component.h b/frameworks/core/components_v2/ability_component/ability_component.h new file mode 100644 index 00000000000..8cfd50c2682 --- /dev/null +++ b/frameworks/core/components_v2/ability_component/ability_component.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2022 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_ABILITY_COMPONENT_ABILITY_COMPONENT_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_ABILITY_COMPONENT_ABILITY_COMPONENT_H + +#include + +#include "core/components_v2/common/common_def.h" +#include "core/pipeline/base/render_component.h" + +namespace OHOS::Ace::V2 { +class ACE_EXPORT AbilityComponent : public RenderComponent { + DECLARE_ACE_TYPE(V2::AbilityComponent, RenderComponent); + +public: + AbilityComponent() = default; + ~AbilityComponent() override = default; + + RefPtr CreateRenderNode() override; + RefPtr CreateElement() override; + + ACE_DEFINE_COMPONENT_PROP(Want, std::string, ""); + ACE_DEFINE_COMPONENT_PROP(Width, float, 0.0F); + ACE_DEFINE_COMPONENT_PROP(Height, float, 0.0F); + + ACE_DEFINE_COMPONENT_EVENT(onConnected, void()); + ACE_DEFINE_COMPONENT_EVENT(onDisconnected, void()); + + void FireOnConnected() + { + if (eventonConnected_) { + eventonConnected_.get(); + } + } + + void FireOnDisconnected() + { + if (eventonDisconnected_) { + eventonDisconnected_.get(); + } + } +}; +} // namespace OHOS::Ace::V2 + +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_ABILITY_COMPONENT_ABILITY_COMPONENT_H diff --git a/frameworks/core/components_v2/ability_component/ability_component_element.h b/frameworks/core/components_v2/ability_component/ability_component_element.h new file mode 100644 index 00000000000..d98115fae9b --- /dev/null +++ b/frameworks/core/components_v2/ability_component/ability_component_element.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2022 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_ABILITY_COMPONENT_ABILITY_COMPONENT_ELEMENT_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_ABILITY_COMPONENT_ABILITY_COMPONENT_ELEMENT_H + +#include "core/components_v2/ability_component/ability_component.h" +#include "core/pipeline/base/render_element.h" + +namespace OHOS::Ace::V2 { +class AbilityComponentElement : public RenderElement { + DECLARE_ACE_TYPE(V2::AbilityComponentElement, RenderElement); +}; +} // namespace OHOS::Ace::V2 + +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_ABILITY_COMPONENT_ABILITY_COMPONENT_ELEMENT_H diff --git a/frameworks/core/components_v2/ability_component/render_ability_component.cpp b/frameworks/core/components_v2/ability_component/render_ability_component.cpp new file mode 100644 index 00000000000..6fa5abdb9eb --- /dev/null +++ b/frameworks/core/components_v2/ability_component/render_ability_component.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2022 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 "core/components_v2/ability_component/render_ability_component.h" + +#include "base/memory/ace_type.h" +#include "core/components_v2/ability_component/ability_component.h" + +namespace OHOS::Ace::V2 { +RefPtr RenderAbilityComponent::Create() +{ + return AceType::MakeRefPtr(); +} + +void RenderAbilityComponent::Update(const RefPtr& component) +{ + RefPtr abilityComponent = AceType::DynamicCast(component); + if (!abilityComponent) { + LOGE("[abilityComponent] Update Get component failed"); + return; + } + component_ = abilityComponent; + + Size size = Size(abilityComponent->GetWidth(), abilityComponent->GetHeight()); + if (currentRect_.GetSize() == size) { + return; + } + currentRect_.SetSize(size); + needLayout_ = true; +} + +void RenderAbilityComponent::PerformLayout() +{ + Offset offset = GetGlobalOffset(); + if (currentRect_.GetSize().IsEmpty()) { + currentRect_.SetSize(GetLayoutParam().GetMaxSize()); + } + if (currentRect_.GetOffset() == offset && !needLayout_ && hasConnectionToAbility_) { + return; + } + currentRect_.SetOffset(offset); + SetLayoutSize(currentRect_.GetSize()); + if (hasConnectionToAbility_) { + adapter_->UpdateRect(currentRect_); + return; + } + adapter_ = WindowExtensionConnectionProxy::CreateAdapter(); + adapter_->ConnectExtension(component_->GetWant(), currentRect_, AceType::Claim(this)); +} +} // namespace OHOS::Ace::V2 diff --git a/frameworks/core/components_v2/ability_component/render_ability_component.h b/frameworks/core/components_v2/ability_component/render_ability_component.h new file mode 100644 index 00000000000..44bb9416617 --- /dev/null +++ b/frameworks/core/components_v2/ability_component/render_ability_component.h @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2022 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_ABILITY_COMPONENT_RENDER_ABILITY_COMPONENT_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_ABILITY_COMPONENT_RENDER_ABILITY_COMPONENT_H + +#include + +#include "base/geometry/rect.h" +#include "core/common/window/window_extension_connection_proxy.h" +#include "core/components_v2/ability_component/ability_component.h" +#include "core/pipeline/base/render_node.h" + +namespace OHOS::Ace::V2 { +class RenderAbilityComponent : public RenderNode { + DECLARE_ACE_TYPE(V2::RenderAbilityComponent, RenderNode); + +public: + ~RenderAbilityComponent() override = default; + + static RefPtr Create(); + void Update(const RefPtr& component) override; + void PerformLayout() override; + + void FireConnect() + { + hasConnectionToAbility_ = true; + if (component_) { + component_->FireOnConnected(); + } else { + LOGI("ability component fire event fail"); + } + } + + void FireDisconnect() + { + hasConnectionToAbility_ = false; + if (component_) { + component_->FireOnDisconnected(); + } else { + LOGI("ability component fire event fail"); + } + } + +private: + Rect currentRect_; + bool needLayout_ = false; + bool hasConnectionToAbility_ = false; + + RefPtr adapter_; + RefPtr component_; +}; +} // namespace OHOS::Ace::V2 + +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_ABILITY_COMPONENT_RENDER_ABILITY_COMPONENT_H From 927316f671dba0f59845c9bf700538d932584b50 Mon Sep 17 00:00:00 2001 From: xiexiyun Date: Mon, 9 May 2022 11:22:03 +0800 Subject: [PATCH 28/35] callback move to cpp file Signed-off-by: xiexiyun Change-Id: Ie2ac86d34e67e6c2dac6d6aff875bccb58783ad9 --- adapter/ohos/osal/system_properties.cpp | 9 +++++++++ frameworks/base/utils/system_properties.h | 9 +-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/adapter/ohos/osal/system_properties.cpp b/adapter/ohos/osal/system_properties.cpp index 1f07efa3487..88b5eafcf6a 100644 --- a/adapter/ohos/osal/system_properties.cpp +++ b/adapter/ohos/osal/system_properties.cpp @@ -111,6 +111,15 @@ bool SystemProperties::IsSyscapExist(const char* cap) #endif } +void SystemProperties::UpdateDebugBoundaryEnabled(const char *key, const char *value, void *context) +{ + if (strcmp(value, "true") == 0) { + debugBoundaryEnabled_ = true; + } else if (strcmp(value, "false") == 0) { + debugBoundaryEnabled_ = false; + } +} + void SystemProperties::InitDeviceType(DeviceType) { // Do nothing, no need to store type here, use system property at 'GetDeviceType' instead. diff --git a/frameworks/base/utils/system_properties.h b/frameworks/base/utils/system_properties.h index b62291ba229..7bec8d12536 100644 --- a/frameworks/base/utils/system_properties.h +++ b/frameworks/base/utils/system_properties.h @@ -276,14 +276,7 @@ public: return windowAnimationEnabled_; } - static void UpdateDebugBoundaryEnabled(const char *key, const char *value, void *context) - { - if (strcmp(value, "true") == 0) { - debugBoundaryEnabled_ = true; - } else if (strcmp(value, "false") == 0) { - debugBoundaryEnabled_ = false; - } - } + static void UpdateDebugBoundaryEnabled(const char *key, const char *value, void *context); private: static bool traceEnabled_; From 0b467f73e37c61ce045defafb3915528e5c2086a Mon Sep 17 00:00:00 2001 From: mengkun Date: Mon, 9 May 2022 12:32:33 +0800 Subject: [PATCH 29/35] =?UTF-8?q?graphic/standard=E6=94=B9=E4=B8=BAgraphic?= =?UTF-8?q?/graphic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: mengkun Change-Id: I91ecb1fed951ca9db2fa0bad40b223aa9aaedd90 --- adapter/ohos/build/config.gni | 2 +- adapter/ohos/capability/BUILD.gn | 2 +- adapter/ohos/entrance/BUILD.gn | 6 +++--- adapter/ohos/entrance/pa_engine/engine/jsi/BUILD.gn | 2 +- .../ohos/entrance/pa_engine/engine/quickjs/BUILD.gn | 2 +- adapter/ohos/services/uiservice/BUILD.gn | 2 +- build/external_config/flutter/BUILD.gn | 6 +++--- build/external_config/flutter/skia/BUILD.gn | 6 +++--- frameworks/core/BUILD.gn | 2 +- frameworks/core/components/camera/BUILD.gn | 2 +- frameworks/core/components/components.gni | 2 +- frameworks/core/components/video/BUILD.gn | 2 +- frameworks/core/components/xcomponent/BUILD.gn | 12 ++++++------ .../core/components/xcomponent/xcomponent_element.h | 2 +- frameworks/core/pipeline/BUILD.gn | 2 +- interfaces/inner_api/ui_service_manager/BUILD.gn | 10 +++++----- 16 files changed, 31 insertions(+), 31 deletions(-) diff --git a/adapter/ohos/build/config.gni b/adapter/ohos/build/config.gni index 60a318c29e6..8f3d8062698 100644 --- a/adapter/ohos/build/config.gni +++ b/adapter/ohos/build/config.gni @@ -12,7 +12,7 @@ # limitations under the License. import("//build/ohos/ace/ace_args.gni") -import("//foundation/graphic/standard/graphic_config.gni") +import("//foundation/graphic/graphic/graphic_config.gni") import("product_config.gni") defines = [ diff --git a/adapter/ohos/capability/BUILD.gn b/adapter/ohos/capability/BUILD.gn index 8da84ab1bd4..c4ed81f126f 100644 --- a/adapter/ohos/capability/BUILD.gn +++ b/adapter/ohos/capability/BUILD.gn @@ -57,7 +57,7 @@ template("ace_capability_ohos_source_set") { "utils_base:utils", "window_manager:libwindow_extension_client", ] - deps = [ "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client" ] + deps = [ "//foundation/graphic/graphic/rosen/modules/render_service_client:librender_service_client" ] sources += [ "window_connection/window_extension_connection_ohos.cpp", "window_connection/window_extension_connection_proxy.cpp", diff --git a/adapter/ohos/entrance/BUILD.gn b/adapter/ohos/entrance/BUILD.gn index ea3e17e4cd9..c5a61f24aed 100644 --- a/adapter/ohos/entrance/BUILD.gn +++ b/adapter/ohos/entrance/BUILD.gn @@ -53,8 +53,8 @@ template("ace_ohos_standard_source_set") { if (defined(config.enable_rosen_backend) && config.enable_rosen_backend) { configs += [ - "//foundation/graphic/standard/rosen/modules/render_service_base:export_config", - "//foundation/graphic/standard/rosen/modules/render_service_client:render_service_client_config", + "//foundation/graphic/graphic/rosen/modules/render_service_base:export_config", + "//foundation/graphic/graphic/rosen/modules/render_service_client:render_service_client_config", ] } @@ -76,7 +76,7 @@ template("ace_ohos_standard_source_set") { "$ace_flutter_engine_root/skia:ace_skia_$platform", "$ace_root/adapter/ohos/capability:ace_capability_ohos", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", - "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", + "//foundation/graphic/graphic/rosen/modules/render_service_client:librender_service_client", "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", "//foundation/multimodalinput/input/frameworks/proxy:libmmi-common", "//foundation/windowmanager/dm:libdm", diff --git a/adapter/ohos/entrance/pa_engine/engine/jsi/BUILD.gn b/adapter/ohos/entrance/pa_engine/engine/jsi/BUILD.gn index 5ae003f6931..d3e9346ba4a 100644 --- a/adapter/ohos/entrance/pa_engine/engine/jsi/BUILD.gn +++ b/adapter/ohos/entrance/pa_engine/engine/jsi/BUILD.gn @@ -75,7 +75,7 @@ template("js_pa_engine_ark") { "//foundation/arkui/napi:ace_napi_ark", "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", - "//foundation/graphic/standard:libwmclient", + "//foundation/graphic/graphic:libwmclient", "//utils/native/base:utils", ] external_deps = [ diff --git a/adapter/ohos/entrance/pa_engine/engine/quickjs/BUILD.gn b/adapter/ohos/entrance/pa_engine/engine/quickjs/BUILD.gn index a41c576b0cf..a20cc0381dd 100644 --- a/adapter/ohos/entrance/pa_engine/engine/quickjs/BUILD.gn +++ b/adapter/ohos/entrance/pa_engine/engine/quickjs/BUILD.gn @@ -45,7 +45,7 @@ template("js_pa_engine_qjs") { "//foundation/arkui/napi:ace_napi", "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", - "//foundation/graphic/standard:libwmclient", + "//foundation/graphic/graphic:libwmclient", "//utils/native/base:utils", ] external_deps = [ diff --git a/adapter/ohos/services/uiservice/BUILD.gn b/adapter/ohos/services/uiservice/BUILD.gn index a127da39e0d..98a185d12f9 100644 --- a/adapter/ohos/services/uiservice/BUILD.gn +++ b/adapter/ohos/services/uiservice/BUILD.gn @@ -82,7 +82,7 @@ template("uiservice_static") { "//foundation/arkui/ace_engine/interfaces/inner_api/ui_service_manager:ui_service_mgr", "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", - "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", + "//foundation/graphic/graphic/rosen/modules/render_service_client:librender_service_client", "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", "//foundation/multimodalinput/input/frameworks/proxy:libmmi-common", "//foundation/windowmanager/wm:libwm", diff --git a/build/external_config/flutter/BUILD.gn b/build/external_config/flutter/BUILD.gn index 73a0fb11c79..a18a2007173 100644 --- a/build/external_config/flutter/BUILD.gn +++ b/build/external_config/flutter/BUILD.gn @@ -443,11 +443,11 @@ template("flutter_engine_shell") { "$flutter_root/engine/flutter/shell/platform/ohos/ohos_surface_gl.cc", ] - public_deps = [ "//foundation/graphic/standard:libgl" ] + public_deps = [ "//foundation/graphic/graphic:libgl" ] } deps += [ - "//foundation/graphic/standard/rosen/modules/composer:libcomposer", - "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", + "//foundation/graphic/graphic/rosen/modules/composer:libcomposer", + "//foundation/graphic/graphic/rosen/modules/render_service_client:librender_service_client", "//foundation/windowmanager/wm:libwm", ] external_deps = [ diff --git a/build/external_config/flutter/skia/BUILD.gn b/build/external_config/flutter/skia/BUILD.gn index ddeeb5e23cd..7ba178c53a8 100644 --- a/build/external_config/flutter/skia/BUILD.gn +++ b/build/external_config/flutter/skia/BUILD.gn @@ -86,7 +86,7 @@ template("make_skia_deps") { ":harfbuzz_config", ] public_deps = - [ "//foundation/graphic/standard/rosen/build/skia:skia_ohos" ] + [ "//foundation/graphic/graphic/rosen/build/skia:skia_ohos" ] } else if (platform == "ohos" && defined(config.enable_native_view) && config.enable_native_view) { public_configs = [ @@ -886,7 +886,7 @@ template("ace_skia_core") { ] } else { if (is_standard_system) { - public_deps = [ "//foundation/graphic/standard:libgl" ] + public_deps = [ "//foundation/graphic/graphic:libgl" ] } else { aosp_deps = [ "shared_library:libEGL", @@ -1505,7 +1505,7 @@ template("ace_gpu") { if (!defined(config.disable_gpu) || !config.disable_gpu) { # Ohos or Android platform if (is_standard_system) { - public_deps = [ "//foundation/graphic/standard:libgl" ] + public_deps = [ "//foundation/graphic/graphic:libgl" ] } else { aosp_deps = [ "shared_library:libEGL", diff --git a/frameworks/core/BUILD.gn b/frameworks/core/BUILD.gn index e9a95317399..c8f0f204488 100644 --- a/frameworks/core/BUILD.gn +++ b/frameworks/core/BUILD.gn @@ -332,7 +332,7 @@ template("ace_core_source_set") { if (defined(config.enable_rosen_backend) && config.enable_rosen_backend) { sources += [ "animation/native_curve_helper.cpp" ] - deps += [ "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client" ] + deps += [ "//foundation/graphic/graphic/rosen/modules/render_service_client:librender_service_client" ] } if (!use_mingw_win && !use_mac && !is_wearable_product && diff --git a/frameworks/core/components/camera/BUILD.gn b/frameworks/core/components/camera/BUILD.gn index 9199d1b0e73..b577383988c 100644 --- a/frameworks/core/components/camera/BUILD.gn +++ b/frameworks/core/components/camera/BUILD.gn @@ -52,7 +52,7 @@ build_component("camera") { sources += [ "standard_system/camera.cpp" ] deps = [ - "//foundation/graphic/standard:libwmclient", + "//foundation/graphic/graphic:libwmclient", "//foundation/multimedia/camera_standard/frameworks/native/camera:camera_framework", "//utils/native/base:utils", ] diff --git a/frameworks/core/components/components.gni b/frameworks/core/components/components.gni index 63fe21c6c9c..c9530eff81d 100644 --- a/frameworks/core/components/components.gni +++ b/frameworks/core/components/components.gni @@ -89,7 +89,7 @@ template("build_component") { if (defined(config.enable_rosen_backend) && config.enable_rosen_backend && defined(invoker.rosen_sources)) { sources += invoker.rosen_sources - configs += [ "//foundation/graphic/standard/rosen/modules/render_service_client:render_service_client_config" ] + configs += [ "//foundation/graphic/graphic/rosen/modules/render_service_client:render_service_client_config" ] } if (defined(config.enable_standard_input) && diff --git a/frameworks/core/components/video/BUILD.gn b/frameworks/core/components/video/BUILD.gn index 58b2cc4386c..9cbc1670d7d 100644 --- a/frameworks/core/components/video/BUILD.gn +++ b/frameworks/core/components/video/BUILD.gn @@ -37,7 +37,7 @@ build_component("video") { "//foundation/multimedia/media_standard/interfaces/inner_api/native", ] - deps = [ "//foundation/graphic/standard:libwmclient" ] + deps = [ "//foundation/graphic/graphic:libwmclient" ] external_deps = [ "ipc:ipc_core" ] } diff --git a/frameworks/core/components/xcomponent/BUILD.gn b/frameworks/core/components/xcomponent/BUILD.gn index 9b211249cd8..b5fd5b44b8d 100644 --- a/frameworks/core/components/xcomponent/BUILD.gn +++ b/frameworks/core/components/xcomponent/BUILD.gn @@ -32,15 +32,15 @@ build_component("xcomponent") { if (is_standard_system && !use_mingw_win && !use_mac) { include_dirs = [ "//drivers/peripheral/display/interfaces/include", - "//foundation/graphic/standard/interfaces/innerkits/wmclient", - "//foundation/graphic/standard/interfaces/innerkits/wm", - "//foundation/graphic/standard/interfaces/innerkits/surface", + "//foundation/graphic/graphic/interfaces/innerkits/wmclient", + "//foundation/graphic/graphic/interfaces/innerkits/wm", + "//foundation/graphic/graphic/interfaces/innerkits/surface", ] deps = [ - "//foundation/graphic/standard:libsurface", - "//foundation/graphic/standard:libwmclient", - "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", + "//foundation/graphic/graphic:libsurface", + "//foundation/graphic/graphic:libwmclient", + "//foundation/graphic/graphic/rosen/modules/render_service_client:librender_service_client", "//foundation/windowmanager/utils:libwmutil", "//foundation/windowmanager/wm:libwm", ] diff --git a/frameworks/core/components/xcomponent/xcomponent_element.h b/frameworks/core/components/xcomponent/xcomponent_element.h index 313dd1d196d..a69959e501b 100644 --- a/frameworks/core/components/xcomponent/xcomponent_element.h +++ b/frameworks/core/components/xcomponent/xcomponent_element.h @@ -23,7 +23,7 @@ #ifdef OHOS_STANDARD_SYSTEM #include "display_type.h" -#include "foundation/graphic/standard/interfaces/inner_api/surface/window.h" +#include "foundation/graphic/graphic/interfaces/inner_api/surface/window.h" #include "foundation/windowmanager/interfaces/innerkits/wm/window.h" #include "render_service_client/core/ui/rs_node.h" #include "render_service_client/core/ui/rs_surface_node.h" diff --git a/frameworks/core/pipeline/BUILD.gn b/frameworks/core/pipeline/BUILD.gn index decc00a2bd3..8ba288b17aa 100644 --- a/frameworks/core/pipeline/BUILD.gn +++ b/frameworks/core/pipeline/BUILD.gn @@ -69,7 +69,7 @@ template("ace_core_pipeline_source_set") { if (defined(config.enable_rosen_backend) && config.enable_rosen_backend) { sources += [ "base/rosen_render_context.cpp" ] - deps += [ "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client" ] + deps += [ "//foundation/graphic/graphic/rosen/modules/render_service_client:librender_service_client" ] } if (platform == "ohos" && defined(config.enable_native_view) && diff --git a/interfaces/inner_api/ui_service_manager/BUILD.gn b/interfaces/inner_api/ui_service_manager/BUILD.gn index a4ba33e459f..9714cc4583d 100755 --- a/interfaces/inner_api/ui_service_manager/BUILD.gn +++ b/interfaces/inner_api/ui_service_manager/BUILD.gn @@ -24,11 +24,11 @@ config("uiservice_manager_public_config") { "//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include/", "//foundation/aafwk/standard/services/uiservicemgr/include", "${innerkits_path}/want/include", - "//foundation/graphic/standard/rosen/modules/render_service_client/core", - "//foundation/graphic/standard/interfaces/innerkits/surface", - "//foundation/graphic/standard/interfaces/innerkits/common", - "//foundation/graphic/standard/utils/buffer_handle/export", - "//foundation/graphic/standard/rosen/modules/render_service_base/include", + "//foundation/graphic/graphic/rosen/modules/render_service_client/core", + "//foundation/graphic/graphic/interfaces/innerkits/surface", + "//foundation/graphic/graphic/interfaces/innerkits/common", + "//foundation/graphic/graphic/utils/buffer_handle/export", + "//foundation/graphic/graphic/rosen/modules/render_service_base/include", "//drivers/peripheral/base", "//third_party/icu/icu4c/source/common", "//third_party/icu/icu4c/source/i18n", From c3ab33f2cfc3a5998c71bc51c42d6291f72b5621 Mon Sep 17 00:00:00 2001 From: h00611971 Date: Sat, 7 May 2022 09:20:00 +0800 Subject: [PATCH 30/35] Adapt SendMessage for IDE in rk3568 use SendMessage in connect server directly issue: https://gitee.com/openharmony/ace_ace_engine/issues/I5660W Signed-off-by: h00611971 --- frameworks/core/common/debugger/connect_inspector.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frameworks/core/common/debugger/connect_inspector.cpp b/frameworks/core/common/debugger/connect_inspector.cpp index 432bb4b536b..bea57e87b6a 100644 --- a/frameworks/core/common/debugger/connect_inspector.cpp +++ b/frameworks/core/common/debugger/connect_inspector.cpp @@ -40,11 +40,11 @@ void OnMessage(const std::string& message) std::string checkMessage = "connected"; if (message.find(checkMessage, 0) != std::string::npos) { - LOGI("Find the targeted string: %{private}s", message.c_str()); - if (g_inspector != nullptr) { + LOGI("Find the target string: %{private}s", message.c_str()); + if (g_inspector != nullptr && g_inspector->connectServer_ != nullptr) { g_inspector->waitingForDebugger_ = false; for (auto &info : g_inspector->infoBuffer_) { - SendMessage(info.second); + g_inspector->connectServer_->SendMessage(info.second); } } } From ce3c32cd95d442f69a5195efb2b1ccb88ef687ba Mon Sep 17 00:00:00 2001 From: xiexiyun Date: Mon, 9 May 2022 15:26:33 +0800 Subject: [PATCH 31/35] change header file and cliding panel parameter injection method Signed-off-by: xiexiyun Change-Id: I8ce5a60070e6e03b39d0f2fadd1deb02dd3e607b --- adapter/ohos/osal/system_properties.cpp | 1 + frameworks/base/utils/system_properties.h | 2 -- .../jsview/js_sliding_panel.cpp | 19 +++++++++++++------ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/adapter/ohos/osal/system_properties.cpp b/adapter/ohos/osal/system_properties.cpp index 88b5eafcf6a..808b766f079 100644 --- a/adapter/ohos/osal/system_properties.cpp +++ b/adapter/ohos/osal/system_properties.cpp @@ -17,6 +17,7 @@ #include +#include "parameter.h" #include "parameters.h" #include "base/log/log.h" diff --git a/frameworks/base/utils/system_properties.h b/frameworks/base/utils/system_properties.h index 7bec8d12536..8b5c9929cab 100644 --- a/frameworks/base/utils/system_properties.h +++ b/frameworks/base/utils/system_properties.h @@ -18,8 +18,6 @@ #include -#include "base/startup/syspara_lite/interfaces/innerkits/native/syspara/include/parameter.h" - #include "base/utils/resource_configuration.h" #include "base/utils/device_type.h" #include "base/utils/macros.h" diff --git a/frameworks/bridge/declarative_frontend/jsview/js_sliding_panel.cpp b/frameworks/bridge/declarative_frontend/jsview/js_sliding_panel.cpp index c7d90e96355..26ca8d6d9bd 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_sliding_panel.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_sliding_panel.cpp @@ -18,6 +18,7 @@ #include #include +#include "bridge/declarative_frontend/jsview/js_view_common_def.h" #include "core/components/panel/sliding_panel_component_v2.h" #include "frameworks/bridge/declarative_frontend/view_stack_processor.h" @@ -279,15 +280,21 @@ void JSSlidingPanel::SetOnSizeChange(const JSCallbackInfo& args) auto onSizeChangeFunc = AceType::MakeRefPtr>( JSRef::Cast(args[0]), SlidingPanelSizeChangeEventToJSValue); auto onSizeChange = EventMarker( - [execCtx = args.GetExecutionContext(), func = std::move(onSizeChangeFunc)](const BaseEventInfo* param) { + [execCtx = args.GetExecutionContext(), func = JSRef::Cast(args[0])](const BaseEventInfo* info) { JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); - auto sizeChange = TypeInfoHelper::DynamicCast(param); - if (!sizeChange) { - LOGE("HandleSizeChangeEvent, sizeChange == nullptr"); + auto eventInfo = TypeInfoHelper::DynamicCast(info); + if (!eventInfo) { return; } - ACE_SCORING_EVENT("SlidingPanel.OnSizeChange"); - func->Execute(*sizeChange); + std::string modeStr = "half"; + const PanelMode& mode = eventInfo->GetMode(); + if (mode == PanelMode::FULL) { + modeStr = "full"; + } else if (mode == PanelMode::MINI) { + modeStr = "mini"; + } + auto params = ConvertToJSValues(eventInfo->GetWidth(), eventInfo->GetHeight(), modeStr.c_str()); + func->Call(JSRef(), params.size(), params.data()); }); auto component = ViewStackProcessor::GetInstance()->GetMainComponent(); auto panel = AceType::DynamicCast(component); From c2bb7d49083ff5b9872f2e3de923bd3500f7b40c Mon Sep 17 00:00:00 2001 From: laosan_ted Date: Mon, 9 May 2022 15:34:12 +0800 Subject: [PATCH 32/35] fix suggestion Signed-off-by: laosan_ted --- .../jsview/js_web_controller.cpp | 7 ++-- .../components/web/resource/web_delegate.cpp | 8 ++--- .../components/web/resource/web_delegate.h | 4 +-- .../core/components/web/web_component.h | 32 +++++++++---------- 4 files changed, 26 insertions(+), 25 deletions(-) diff --git a/frameworks/bridge/declarative_frontend/jsview/js_web_controller.cpp b/frameworks/bridge/declarative_frontend/jsview/js_web_controller.cpp index 75b23910155..e855a416b49 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_web_controller.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_web_controller.cpp @@ -115,10 +115,11 @@ public: if (!manager_) { return; } - std::string url; - if (args[0]->IsString()) { - url = args[0]->ToString(); + if (args.Length() < 1 || !args[0]->IsString()) { + LOGW("invalid url params"); + return; } + std::string url = args[0]->ToString(); std::string result = manager_->GetCookie(url); auto jsVal = JSVal(ToJSValue(result)); auto returnValue = JSRef::Make(jsVal); diff --git a/frameworks/core/components/web/resource/web_delegate.cpp b/frameworks/core/components/web/resource/web_delegate.cpp index 22889244ab8..a6e747f790c 100755 --- a/frameworks/core/components/web/resource/web_delegate.cpp +++ b/frameworks/core/components/web/resource/web_delegate.cpp @@ -627,7 +627,7 @@ bool WebDelegate::SaveCookieSync() return false; } -bool WebDelegate::SetCookie(const std::string url, const std::string value) +bool WebDelegate::SetCookie(const std::string& url, const std::string& value) { if (cookieManager_) { return cookieManager_->SetCookie(url, value); @@ -635,7 +635,7 @@ bool WebDelegate::SetCookie(const std::string url, const std::string value) return false; } -std::string WebDelegate::GetCookie(const std::string url) +std::string WebDelegate::GetCookie(const std::string& url) { if (cookieManager_) { return cookieManager_->ReturnCookie(url); @@ -998,7 +998,7 @@ void WebDelegate::SetWebCallBack() return false; }); webController->SetSetCookieImpl( - [weak = WeakClaim(this)](std::string url, std::string value) { + [weak = WeakClaim(this)](const std::string& url, const std::string& value) { auto delegate = weak.Upgrade(); if (delegate) { return delegate->SetCookie(url, value); @@ -1006,7 +1006,7 @@ void WebDelegate::SetWebCallBack() return false; }); webController->SetGetCookieImpl( - [weak = WeakClaim(this)](std::string url) { + [weak = WeakClaim(this)](const std::string& url) { auto delegate = weak.Upgrade(); if (delegate) { return delegate->GetCookie(url); diff --git a/frameworks/core/components/web/resource/web_delegate.h b/frameworks/core/components/web/resource/web_delegate.h index 1ea9bdc58c7..8ca05930868 100755 --- a/frameworks/core/components/web/resource/web_delegate.h +++ b/frameworks/core/components/web/resource/web_delegate.h @@ -224,8 +224,8 @@ private: void Zoom(float factor); int GetHitTestResult(); bool SaveCookieSync(); - bool SetCookie(const std::string url, const std::string value); - std::string GetCookie(const std::string url); + bool SetCookie(const std::string& url, const std::string& value); + std::string GetCookie(const std::string& url); void DeleteEntirelyCookie(); void RegisterOHOSWebEventAndMethord(); void SetWebCallBack(); diff --git a/frameworks/core/components/web/web_component.h b/frameworks/core/components/web/web_component.h index 802bfcced00..3edf8d9fd8f 100755 --- a/frameworks/core/components/web/web_component.h +++ b/frameworks/core/components/web/web_component.h @@ -57,11 +57,11 @@ class WebCookie : public virtual AceType { DECLARE_ACE_TYPE(WebCookie, AceType); public: - using SetCookieImpl = std::function; - using GetCookieImpl = std::function; + using SetCookieImpl = std::function; + using GetCookieImpl = std::function; using DeleteEntirelyCookieImpl = std::function; using SaveCookieSyncImpl = std::function; - bool SetCookie(const std::string url, const std::string value) + bool SetCookie(const std::string& url, const std::string& value) { if (setCookieImpl_) { return setCookieImpl_(url, value); @@ -69,7 +69,7 @@ public: return false; } - std::string GetCookie(const std::string url) + std::string GetCookie(const std::string& url) { if (getCookieImpl_) { return getCookieImpl_(url); @@ -92,22 +92,22 @@ public: return false; } - void SetSetCookieImpl(SetCookieImpl && setCookieImpl) + void SetSetCookieImpl(SetCookieImpl&& setCookieImpl) { setCookieImpl_ = setCookieImpl; } - void SetGetCookieImpl(GetCookieImpl && getCookieImpl) + void SetGetCookieImpl(GetCookieImpl&& getCookieImpl) { getCookieImpl_ = getCookieImpl; } - void SetDeleteEntirelyCookieImpl(DeleteEntirelyCookieImpl && deleteEntirelyCookieImpl) + void SetDeleteEntirelyCookieImpl(DeleteEntirelyCookieImpl&& deleteEntirelyCookieImpl) { deleteEntirelyCookieImpl_ = deleteEntirelyCookieImpl; } - void SetSaveCookieSyncImpl(SaveCookieSyncImpl && saveCookieSyncImpl) + void SetSaveCookieSyncImpl(SaveCookieSyncImpl&& saveCookieSyncImpl) { saveCookieSyncImpl_ = saveCookieSyncImpl; } @@ -365,28 +365,28 @@ public: return cookieManager_; } - using SetCookieImpl = std::function; - bool SetCookie(const std::string url, const std::string value) + using SetCookieImpl = std::function; + bool SetCookie(const std::string& url, const std::string& value) { if (setCookieImpl_) { return setCookieImpl_(url, value); } return false; } - void SetSetCookieImpl(SetCookieImpl && setCookieImpl) + void SetSetCookieImpl(SetCookieImpl&& setCookieImpl) { setCookieImpl_ = setCookieImpl; } - using GetCookieImpl = std::function; - std::string GetCookie(const std::string url) + using GetCookieImpl = std::function; + std::string GetCookie(const std::string& url) { if (getCookieImpl_) { return getCookieImpl_(url); } return ""; } - void SetGetCookieImpl(GetCookieImpl && getCookieImpl) + void SetGetCookieImpl(GetCookieImpl&& getCookieImpl) { getCookieImpl_ = getCookieImpl; } @@ -398,7 +398,7 @@ public: deleteEntirelyCookieImpl_(); } } - void SetDeleteEntirelyCookieImpl(DeleteEntirelyCookieImpl && deleteEntirelyCookieImpl) + void SetDeleteEntirelyCookieImpl(DeleteEntirelyCookieImpl&& deleteEntirelyCookieImpl) { deleteEntirelyCookieImpl_ = deleteEntirelyCookieImpl; } @@ -411,7 +411,7 @@ public: } return false; } - void SetSaveCookieSyncImpl(SaveCookieSyncImpl && saveCookieSyncImpl) + void SetSaveCookieSyncImpl(SaveCookieSyncImpl&& saveCookieSyncImpl) { saveCookieSyncImpl_ = saveCookieSyncImpl; } From 4c08f14dec960b9f56834e417fab53dc5c6a2273 Mon Sep 17 00:00:00 2001 From: xiexiyun Date: Mon, 9 May 2022 15:45:59 +0800 Subject: [PATCH 33/35] remove redundant virables Signed-off-by: xiexiyun Change-Id: Iea354285716c720135e43a94776340403ff3660d --- .../bridge/declarative_frontend/jsview/js_sliding_panel.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/frameworks/bridge/declarative_frontend/jsview/js_sliding_panel.cpp b/frameworks/bridge/declarative_frontend/jsview/js_sliding_panel.cpp index 26ca8d6d9bd..7b5e1ec0b5d 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_sliding_panel.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_sliding_panel.cpp @@ -18,8 +18,8 @@ #include #include -#include "bridge/declarative_frontend/jsview/js_view_common_def.h" #include "core/components/panel/sliding_panel_component_v2.h" +#include "frameworks/bridge/declarative_frontend/jsview/js_view_common_def.h" #include "frameworks/bridge/declarative_frontend/view_stack_processor.h" namespace OHOS::Ace::Framework { @@ -277,8 +277,6 @@ void JSSlidingPanel::JsPanelBorder(const JSCallbackInfo& info) void JSSlidingPanel::SetOnSizeChange(const JSCallbackInfo& args) { if (args[0]->IsFunction()) { - auto onSizeChangeFunc = AceType::MakeRefPtr>( - JSRef::Cast(args[0]), SlidingPanelSizeChangeEventToJSValue); auto onSizeChange = EventMarker( [execCtx = args.GetExecutionContext(), func = JSRef::Cast(args[0])](const BaseEventInfo* info) { JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); @@ -294,6 +292,7 @@ void JSSlidingPanel::SetOnSizeChange(const JSCallbackInfo& args) modeStr = "mini"; } auto params = ConvertToJSValues(eventInfo->GetWidth(), eventInfo->GetHeight(), modeStr.c_str()); + ACE_SCORING_EVENT("SlidingPanel.OnSizeChange"); func->Call(JSRef(), params.size(), params.data()); }); auto component = ViewStackProcessor::GetInstance()->GetMainComponent(); From 36e4023240967922df060cba23edcdda626151b8 Mon Sep 17 00:00:00 2001 From: xiexiyun Date: Mon, 9 May 2022 16:26:19 +0800 Subject: [PATCH 34/35] remove redundant function Signed-off-by: xiexiyun Change-Id: Iaadf0571382c48b8db624e58dc27a19a0fe88074 --- .../jsview/js_sliding_panel.cpp | 32 +++++-------------- 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/frameworks/bridge/declarative_frontend/jsview/js_sliding_panel.cpp b/frameworks/bridge/declarative_frontend/jsview/js_sliding_panel.cpp index 7b5e1ec0b5d..7400dcff56e 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_sliding_panel.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_sliding_panel.cpp @@ -25,22 +25,6 @@ namespace OHOS::Ace::Framework { namespace { -JSRef SlidingPanelSizeChangeEventToJSValue(const SlidingPanelSizeChangeEvent& eventInfo) -{ - JSRef obj = JSRef::New(); - std::string modeStr = "half"; - const PanelMode& mode = eventInfo.GetMode(); - if (mode == PanelMode::FULL) { - modeStr = "full"; - } else if (mode == PanelMode::MINI) { - modeStr = "mini"; - } - obj->SetProperty("mode", modeStr.c_str()); - obj->SetProperty("width", eventInfo.GetWidth()); - obj->SetProperty("height", eventInfo.GetHeight()); - return JSRef::Cast(obj); -} - } // namespace void JSSlidingPanel::Create(const JSCallbackInfo& info) @@ -284,14 +268,14 @@ void JSSlidingPanel::SetOnSizeChange(const JSCallbackInfo& args) if (!eventInfo) { return; } - std::string modeStr = "half"; - const PanelMode& mode = eventInfo->GetMode(); - if (mode == PanelMode::FULL) { - modeStr = "full"; - } else if (mode == PanelMode::MINI) { - modeStr = "mini"; - } - auto params = ConvertToJSValues(eventInfo->GetWidth(), eventInfo->GetHeight(), modeStr.c_str()); + // std::string modeStr = "half"; + // const PanelMode& mode = eventInfo->GetMode(); + // if (mode == PanelMode::FULL) { + // modeStr = "full"; + // } else if (mode == PanelMode::MINI) { + // modeStr = "mini"; + // } + auto params = ConvertToJSValues(eventInfo->GetWidth(), eventInfo->GetHeight(), eventInfo->GetMode()); ACE_SCORING_EVENT("SlidingPanel.OnSizeChange"); func->Call(JSRef(), params.size(), params.data()); }); From 8c4da4689424932aa207b61e46eec62f9b0340f1 Mon Sep 17 00:00:00 2001 From: xiexiyun Date: Mon, 9 May 2022 17:12:08 +0800 Subject: [PATCH 35/35] remove redundant comment Signed-off-by: xiexiyun Change-Id: I0904a8e8e47a1fe8f56e1db8cdae3ca489b3862a --- .../declarative_frontend/jsview/js_sliding_panel.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/frameworks/bridge/declarative_frontend/jsview/js_sliding_panel.cpp b/frameworks/bridge/declarative_frontend/jsview/js_sliding_panel.cpp index 7400dcff56e..9416410262a 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_sliding_panel.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_sliding_panel.cpp @@ -268,13 +268,6 @@ void JSSlidingPanel::SetOnSizeChange(const JSCallbackInfo& args) if (!eventInfo) { return; } - // std::string modeStr = "half"; - // const PanelMode& mode = eventInfo->GetMode(); - // if (mode == PanelMode::FULL) { - // modeStr = "full"; - // } else if (mode == PanelMode::MINI) { - // modeStr = "mini"; - // } auto params = ConvertToJSValues(eventInfo->GetWidth(), eventInfo->GetHeight(), eventInfo->GetMode()); ACE_SCORING_EVENT("SlidingPanel.OnSizeChange"); func->Call(JSRef(), params.size(), params.data());