From 26beefcc3fc0cb05a9a7074ebc75b8bff3ac2c61 Mon Sep 17 00:00:00 2001 From: jiangdayuan Date: Tue, 4 Jul 2023 21:45:57 +0800 Subject: [PATCH 1/2] add form link event processing Signed-off-by: jiangdayuan Change-Id: Ia15cedccfd00712aefb7da330acb68e2323603db --- adapter/ohos/entrance/ui_content_impl.cpp | 10 ++ adapter/ohos/entrance/ui_content_impl.h | 1 + .../card_frontend/form_frontend_declarative.h | 2 +- .../form/resource/form_manager_delegate.cpp | 103 ++++++++++-------- .../form/resource/form_manager_delegate.h | 12 +- .../core/components_ng/pattern/BUILD.gn | 1 + .../pattern/form/form_pattern.cpp | 97 +++++++++++------ .../components_ng/pattern/form/form_pattern.h | 10 +- .../pattern/form_link/form_link_infos.h | 54 +++++++++ .../pattern/form_link/form_link_model_ng.cpp | 2 + .../pattern/form_link/form_link_pattern.cpp | 44 ++++++++ .../pattern/form_link/form_link_pattern.h | 26 +++++ .../form/mock/mock_form_manager_delegate.cpp | 10 +- frameworks/core/pipeline/pipeline_base.cpp | 6 +- frameworks/core/pipeline/pipeline_base.h | 19 +++- interfaces/inner_api/ace/ui_content.h | 1 + .../form_render/include/form_renderer.h | 16 +-- .../include/form_renderer_delegate_impl.h | 12 +- .../form_renderer_delegate_interface.h | 23 ++-- .../include/form_renderer_delegate_proxy.h | 6 +- .../include/form_renderer_delegate_stub.h | 21 ++-- .../form_render/src/form_renderer.cpp | 38 +++++-- .../src/form_renderer_delegate_impl.cpp | 26 ++++- .../src/form_renderer_delegate_proxy.cpp | 44 ++++++-- .../src/form_renderer_delegate_stub.cpp | 30 +++-- 25 files changed, 451 insertions(+), 163 deletions(-) create mode 100644 frameworks/core/components_ng/pattern/form_link/form_link_infos.h create mode 100644 frameworks/core/components_ng/pattern/form_link/form_link_pattern.cpp diff --git a/adapter/ohos/entrance/ui_content_impl.cpp b/adapter/ohos/entrance/ui_content_impl.cpp index 7c4cf5b09c8..b4c23f7a264 100644 --- a/adapter/ohos/entrance/ui_content_impl.cpp +++ b/adapter/ohos/entrance/ui_content_impl.cpp @@ -1660,6 +1660,16 @@ void UIContentImpl::SetActionEventHandler(std::functionSetActionEventHandler(std::move(actionCallback)); } +void UIContentImpl::SetFormLinkInfoUpdateHandler(std::function&)>&& callback) +{ + CHECK_NULL_VOID(callback); + auto container = Platform::AceContainer::GetContainer(instanceId_); + CHECK_NULL_VOID(container); + auto pipelineContext = container->GetPipelineContext(); + CHECK_NULL_VOID(pipelineContext); + pipelineContext->SetFormLinkInfoUpdateHandler(std::move(callback)); +} + void UIContentImpl::SetErrorEventHandler(std::function&& errorCallback) { CHECK_NULL_VOID(errorCallback); diff --git a/adapter/ohos/entrance/ui_content_impl.h b/adapter/ohos/entrance/ui_content_impl.h index 9a49b0dd69c..e816277fb95 100644 --- a/adapter/ohos/entrance/ui_content_impl.h +++ b/adapter/ohos/entrance/ui_content_impl.h @@ -107,6 +107,7 @@ public: void SetActionEventHandler(std::function&& actionCallback) override; void SetErrorEventHandler(std::function&& errorCallback) override; + void SetFormLinkInfoUpdateHandler(std::function&)>&& callback) override; void OnFormSurfaceChange(float width, float height) override; diff --git a/frameworks/bridge/card_frontend/form_frontend_declarative.h b/frameworks/bridge/card_frontend/form_frontend_declarative.h index 4656f196ccf..5b55f8e2c94 100644 --- a/frameworks/bridge/card_frontend/form_frontend_declarative.h +++ b/frameworks/bridge/card_frontend/form_frontend_declarative.h @@ -51,7 +51,7 @@ public: void OnSurfaceChanged(int32_t width, int32_t height) override; void SetColorMode(ColorMode colorMode) override; - void SetLoadCardCallBack(WeakPtr outSidePipelineContext) + void SetLoadCardCallBack(const WeakPtr& outSidePipelineContext) { const auto& loadCallback = [outSidePipelineContext](const std::string& url, int64_t cardId) -> bool { auto context = outSidePipelineContext.Upgrade(); diff --git a/frameworks/core/components/form/resource/form_manager_delegate.cpp b/frameworks/core/components/form/resource/form_manager_delegate.cpp index 181defecfc8..51038b3d028 100644 --- a/frameworks/core/components/form/resource/form_manager_delegate.cpp +++ b/frameworks/core/components/form/resource/form_manager_delegate.cpp @@ -26,15 +26,15 @@ #include "frameworks/core/common/frontend.h" #ifdef OHOS_STANDARD_SYSTEM -#include "core/common/form_manager.h" -#include "core/components/form/resource/form_utils.h" - #include "form_callback_client.h" #include "form_host_client.h" -#include "form_js_info.h" #include "form_info.h" +#include "form_js_info.h" #include "form_mgr.h" #include "pointer_event.h" + +#include "core/common/form_manager.h" +#include "core/components/form/resource/form_utils.h" #endif namespace OHOS::Ace { @@ -52,14 +52,10 @@ constexpr char ALLOW_UPDATE[] = "allowUpdate"; constexpr char IS_DYNAMIC[] = "isDynamic"; bool GetFormInfo( - std::string& bundleName, - std::string& moduleName, - const std::string& cardName, - OHOS::AppExecFwk::FormInfo& formInfo) + std::string& bundleName, std::string& moduleName, const std::string& cardName, OHOS::AppExecFwk::FormInfo& formInfo) { std::vector formInfos; - auto result = OHOS::AppExecFwk::FormMgr::GetInstance() - .GetFormsInfoByModule(bundleName, moduleName, formInfos); + auto result = OHOS::AppExecFwk::FormMgr::GetInstance().GetFormsInfoByModule(bundleName, moduleName, formInfos); if (result != 0) { LOGW("Query FormInfo failed."); return false; @@ -147,8 +143,8 @@ void FormManagerDelegate::AddForm(const WeakPtr& context, const Re wantCache_.SetParam(OHOS::AppExecFwk::Constants::PARAM_MODULE_NAME_KEY, info.moduleName); wantCache_.SetParam(OHOS::AppExecFwk::Constants::PARAM_FORM_NAME_KEY, info.cardName); wantCache_.SetParam(OHOS::AppExecFwk::Constants::PARAM_FORM_TEMPORARY_KEY, info.temporary); - wantCache_.SetParam(OHOS::AppExecFwk::Constants::ACQUIRE_TYPE, - OHOS::AppExecFwk::Constants::ACQUIRE_TYPE_CREATE_FORM); + wantCache_.SetParam( + OHOS::AppExecFwk::Constants::ACQUIRE_TYPE, OHOS::AppExecFwk::Constants::ACQUIRE_TYPE_CREATE_FORM); wantCache_.SetParam(OHOS::AppExecFwk::Constants::PARAM_FORM_WIDTH_KEY, info.width.Value()); wantCache_.SetParam(OHOS::AppExecFwk::Constants::PARAM_FORM_HEIGHT_KEY, info.height.Value()); wantCache_.SetParam(OHOS::AppExecFwk::Constants::FORM_COMP_ID, std::to_string(info.index)); @@ -220,8 +216,8 @@ void FormManagerDelegate::AddForm(const WeakPtr& context, const Re void FormManagerDelegate::OnSurfaceCreate(const AppExecFwk::FormJsInfo& formInfo, const std::shared_ptr& rsSurfaceNode, const AAFwk::Want& want) { - LOGI("Form OnSurfaceCreate formId: %{public}s, isDynamic: %{public}d", - std::to_string(formInfo.formId).c_str(), formInfo.isDynamic); + LOGI("Form OnSurfaceCreate formId: %{public}s, isDynamic: %{public}d", std::to_string(formInfo.formId).c_str(), + formInfo.isDynamic); if (!rsSurfaceNode) { LOGE("Form OnSurfaceCreate rsSurfaceNode is null"); return; @@ -399,6 +395,15 @@ void FormManagerDelegate::AddFormSurfaceChangeCallback(OnFormSurfaceChangeCallba onFormSurfaceChangeCallback_ = std::move(callback); } +void FormManagerDelegate::AddFormLinkInfoUpdateCallback(OnFormLinkInfoUpdateCallback&& callback) +{ + if (!callback || state_ == State::RELEASED) { + LOGE("callback is null or has released"); + return; + } + onFormLinkInfoUpdateCallback_ = std::move(callback); +} + void FormManagerDelegate::AddActionEventHandle(const ActionEventHandle& callback) { if (!callback || state_ == State::RELEASED) { @@ -434,7 +439,7 @@ void FormManagerDelegate::AddSnapshotCallback(SnapshotCallback&& callback) snapshotCallback_ = std::move(callback); } -bool FormManagerDelegate::ParseAction(const std::string &action, const std::string& type, AAFwk::Want &want) +bool FormManagerDelegate::ParseAction(const std::string& action, const std::string& type, AAFwk::Want& want) { auto eventAction = JsonUtil::ParseJsonString(action); auto bundleName = eventAction->GetValue("bundleName"); @@ -509,12 +514,11 @@ void FormManagerDelegate::RegisterRenderDelegateEvent() }; renderDelegate_->SetActionEventHandler(std::move(actionEventHandler)); - auto&& onErrorEventHandler = - [weak = WeakClaim(this)](const std::string& code, const std::string& msg) { - auto formManagerDelegate = weak.Upgrade(); - CHECK_NULL_VOID(formManagerDelegate); - formManagerDelegate->OnFormError(code, msg); - }; + auto&& onErrorEventHandler = [weak = WeakClaim(this)](const std::string& code, const std::string& msg) { + auto formManagerDelegate = weak.Upgrade(); + CHECK_NULL_VOID(formManagerDelegate); + formManagerDelegate->OnFormError(code, msg); + }; renderDelegate_->SetErrorEventHandler(std::move(onErrorEventHandler)); auto&& onSurfaceChangeHandler = [weak = WeakClaim(this)](float width, float height) { @@ -523,6 +527,13 @@ void FormManagerDelegate::RegisterRenderDelegateEvent() formManagerDelegate->OnFormSurfaceChange(width, height); }; renderDelegate_->SetSurfaceChangeEventHandler(std::move(onSurfaceChangeHandler)); + + auto&& onFormLinkInfoUpdateHandler = [weak = WeakClaim(this)](const std::vector& formLinkInfos) { + auto formManagerDelegate = weak.Upgrade(); + CHECK_NULL_VOID(formManagerDelegate); + formManagerDelegate->OnFormLinkInfoUpdate(formLinkInfos); + }; + renderDelegate_->SetFormLinkInfoUpdateHandler(std::move(onFormLinkInfoUpdateHandler)); } void FormManagerDelegate::OnActionEvent(const std::string& action) @@ -554,8 +565,7 @@ void FormManagerDelegate::OnActionEvent(const std::string& action) auto context = context_.Upgrade(); CHECK_NULL_VOID(context); auto instantId = context->GetInstanceId(); - formUtils_->RouterEvent( - runningCardId_, action, instantId, wantCache_.GetElement().GetBundleName()); + formUtils_->RouterEvent(runningCardId_, action, instantId, wantCache_.GetElement().GetBundleName()); } return; } else if (type == "call") { @@ -567,9 +577,8 @@ void FormManagerDelegate::OnActionEvent(const std::string& action) auto context = context_.Upgrade(); CHECK_NULL_VOID(context); auto instantId = context->GetInstanceId(); - formUtils_->BackgroundEvent( - runningCardId_, action, instantId, wantCache_.GetElement().GetBundleName()); - } + formUtils_->BackgroundEvent(runningCardId_, action, instantId, wantCache_.GetElement().GetBundleName()); + } return; } @@ -585,8 +594,8 @@ void FormManagerDelegate::OnActionEvent(const std::string& action) } // requestForm request to fms - int resultCode = AppExecFwk::FormMgr::GetInstance().MessageEvent(runningCardId_, want, - AppExecFwk::FormHostClient::GetInstance()); + int resultCode = AppExecFwk::FormMgr::GetInstance().MessageEvent( + runningCardId_, want, AppExecFwk::FormHostClient::GetInstance()); if (resultCode != ERR_OK) { LOGE("failed to notify the form service, error code is %{public}d.", resultCode); } @@ -597,14 +606,13 @@ void FormManagerDelegate::OnActionEvent(const std::string& action) paramStream << "type" << FORM_MANAGER_PARAM_EQUALS << type << FORM_MANAGER_PARAM_AND << "action" << FORM_MANAGER_PARAM_EQUALS << action; std::string param = paramStream.str(); - LOGI("send method:%{private}s, type:%{public}s params:%{private}s", - actionMethod.c_str(), type.c_str(), param.c_str()); + LOGI("send method:%{private}s, type:%{public}s params:%{private}s", actionMethod.c_str(), type.c_str(), + param.c_str()); CallResRegisterMethod(actionMethod, param, nullptr); #endif } -void FormManagerDelegate::DispatchPointerEvent( - const std::shared_ptr& pointerEvent) +void FormManagerDelegate::DispatchPointerEvent(const std::shared_ptr& pointerEvent) { if (!isDynamic_ || formRendererDispatcher_ == nullptr) { LOGI("Is not dynamic or dispatchPointerEvent is null"); @@ -640,12 +648,19 @@ void FormManagerDelegate::OnFormSurfaceChange(float width, float height) } } +void FormManagerDelegate::OnFormLinkInfoUpdate(const std::vector& formLinkInfos) +{ + if (onFormLinkInfoUpdateCallback_) { + onFormLinkInfoUpdateCallback_(formLinkInfos); + } +} + void FormManagerDelegate::OnFormAcquired(const std::string& param) { auto result = ParseMapFromString(param); if (onFormAcquiredCallbackForJava_) { - onFormAcquiredCallbackForJava_(StringUtils::StringToLongInt(result["formId"]), result["codePath"], - result["moduleName"], result["data"]); + onFormAcquiredCallbackForJava_( + StringUtils::StringToLongInt(result["formId"]), result["codePath"], result["moduleName"], result["data"]); } } @@ -706,10 +721,10 @@ void FormManagerDelegate::HandleSnapshotCallback() void FormManagerDelegate::ReAddForm() { LOGI("ReAddForm."); - formRendererDispatcher_ = nullptr; // formRendererDispatcher_ need reset, otherwise PointerEvent will disable + formRendererDispatcher_ = nullptr; // formRendererDispatcher_ need reset, otherwise PointerEvent will disable auto clientInstance = OHOS::AppExecFwk::FormHostClient::GetInstance(); - auto ret = OHOS::AppExecFwk::FormMgr::GetInstance().AddForm( - formJsInfo_.formId, wantCache_, clientInstance, formJsInfo_); + auto ret = + OHOS::AppExecFwk::FormMgr::GetInstance().AddForm(formJsInfo_.formId, wantCache_, clientInstance, formJsInfo_); if (ret != 0) { auto errorMsg = OHOS::AppExecFwk::FormMgr::GetInstance().GetErrorMessage(ret); LOGE("Add form failed, ret:%{public}d detail:%{public}s", ret, errorMsg.c_str()); @@ -728,8 +743,8 @@ void FormManagerDelegate::ResetForm() void FormManagerDelegate::ReleaseForm() { - LOGI("FormManagerDelegate releaseForm. formId: %{public}" PRId64 ", %{public}s", - runningCardId_, runningCompId_.c_str()); + LOGI("FormManagerDelegate releaseForm. formId: %{public}" PRId64 ", %{public}s", runningCardId_, + runningCompId_.c_str()); if (runningCardId_ <= 0) { return; } @@ -742,7 +757,7 @@ void FormManagerDelegate::ReleaseForm() clientInstance->RemoveForm(formCallbackClient_, runningCardId_); } -void FormManagerDelegate::ProcessFormUpdate(const AppExecFwk::FormJsInfo &formJsInfo) +void FormManagerDelegate::ProcessFormUpdate(const AppExecFwk::FormJsInfo& formJsInfo) { if (formJsInfo.formId != runningCardId_) { LOGI("form update, but card is not current card"); @@ -767,8 +782,8 @@ void FormManagerDelegate::ProcessFormUpdate(const AppExecFwk::FormJsInfo &formJs uiSyntax = OHOS::Ace::FrontendType::ETS_CARD; } formJsInfo_ = formJsInfo; - onFormAcquiredCallback_(runningCardId_, formJsInfo.jsFormCodePath, formJsInfo.formName, - formJsInfo.formData, formJsInfo.imageDataMap, formJsInfo, type, uiSyntax); + onFormAcquiredCallback_(runningCardId_, formJsInfo.jsFormCodePath, formJsInfo.formName, formJsInfo.formData, + formJsInfo.imageDataMap, formJsInfo, type, uiSyntax); } else { if (formJsInfo.formData.empty()) { LOGE("update form data success, but data is empty!!!"); @@ -785,8 +800,8 @@ void FormManagerDelegate::ProcessFormUpdate(const AppExecFwk::FormJsInfo &formJs void FormManagerDelegate::ReleaseRenderer() { - LOGI("FormManagerDelegate releaseForm. formId: %{public}" PRId64 ", %{public}s", - runningCardId_, runningCompId_.c_str()); + LOGI("FormManagerDelegate releaseForm. formId: %{public}" PRId64 ", %{public}s", runningCardId_, + runningCompId_.c_str()); if (runningCardId_ <= 0) { return; } diff --git a/frameworks/core/components/form/resource/form_manager_delegate.h b/frameworks/core/components/form/resource/form_manager_delegate.h index 18f517d3c95..0a6883b7366 100644 --- a/frameworks/core/components/form/resource/form_manager_delegate.h +++ b/frameworks/core/components/form/resource/form_manager_delegate.h @@ -20,6 +20,7 @@ #include "interfaces/inner_api/form_render/include/form_renderer_delegate_impl.h" #include "interfaces/inner_api/form_render/include/form_renderer_dispatcher_interface.h" + #include "core/components/common/layout/constants.h" #include "core/components/form/resource/form_manager_resource.h" #include "core/components/form/resource/form_request_data.h" @@ -45,10 +46,11 @@ public: std::function; using OnFormUpdateCallbackForJava = std::function; using OnFormAcquiredCallback = std::function>&, - const AppExecFwk::FormJsInfo&, const FrontendType& frontendType, const FrontendType& uiSyntax)>; + const std::string&, const std::map>&, const AppExecFwk::FormJsInfo&, + const FrontendType& frontendType, const FrontendType& uiSyntax)>; using OnFormUpdateCallback = std::function>&)>; + using OnFormLinkInfoUpdateCallback = std::function&)>; using OnFormErrorCallback = std::function; using OnFormUninstallCallback = std::function; using OnFormSurfaceNodeCallback = std::function&)>; @@ -80,17 +82,18 @@ public: void AddFormUninstallCallback(const OnFormUninstallCallback& callback); void AddFormSurfaceNodeCallback(const OnFormSurfaceNodeCallback& callback); void AddFormSurfaceChangeCallback(OnFormSurfaceChangeCallback&& callback); + void AddFormLinkInfoUpdateCallback(OnFormLinkInfoUpdateCallback&& callback); void AddActionEventHandle(const ActionEventHandle& callback); void AddUnTrustFormCallback(const UnTrustFormCallback& callback); void AddSnapshotCallback(SnapshotCallback&& callback); void OnActionEventHandle(const std::string& action); void SetAllowUpdate(bool allowUpdate); void OnActionEvent(const std::string& action); - void DispatchPointerEvent( - const std::shared_ptr& pointerEvent); + void DispatchPointerEvent(const std::shared_ptr& pointerEvent); void AddRenderDelegate(); void RegisterRenderDelegateEvent(); void OnFormError(const std::string& code, const std::string& msg); + void OnFormLinkInfoUpdate(const std::vector& formLinkInfos); void ReleaseRenderer(); #ifdef OHOS_STANDARD_SYSTEM void ProcessFormUpdate(const AppExecFwk::FormJsInfo& formJsInfo); @@ -124,6 +127,7 @@ private: OnFormUpdateCallbackForJava onFormUpdateCallbackForJava_; OnFormAcquiredCallback onFormAcquiredCallback_; OnFormUpdateCallback onFormUpdateCallback_; + OnFormLinkInfoUpdateCallback onFormLinkInfoUpdateCallback_; OnFormErrorCallback onFormErrorCallback_; OnFormUninstallCallback onFormUninstallCallback_; OnFormSurfaceNodeCallback onFormSurfaceNodeCallback_; diff --git a/frameworks/core/components_ng/pattern/BUILD.gn b/frameworks/core/components_ng/pattern/BUILD.gn index 511e08be497..2950145ec64 100644 --- a/frameworks/core/components_ng/pattern/BUILD.gn +++ b/frameworks/core/components_ng/pattern/BUILD.gn @@ -102,6 +102,7 @@ build_component_ng("pattern_ng") { "flex/flex_model_ng.cpp", "flex/wrap_layout_algorithm.cpp", "form_link/form_link_model_ng.cpp", + "form_link/form_link_pattern.cpp", "gauge/gauge_accessibility_property.cpp", "gauge/gauge_layout_algorithm.cpp", "gauge/gauge_model_ng.cpp", diff --git a/frameworks/core/components_ng/pattern/form/form_pattern.cpp b/frameworks/core/components_ng/pattern/form/form_pattern.cpp index 769acda1cda..5daf7373d21 100644 --- a/frameworks/core/components_ng/pattern/form/form_pattern.cpp +++ b/frameworks/core/components_ng/pattern/form/form_pattern.cpp @@ -15,6 +15,9 @@ #include "core/components_ng/pattern/form/form_pattern.h" +#include "pointer_event.h" +#include "transaction/rs_interfaces.h" + #include "base/geometry/dimension.h" #include "base/utils/utils.h" #include "core/common/form_manager.h" @@ -29,8 +32,6 @@ #include "core/components_ng/property/property.h" #include "core/components_ng/render/adapter/rosen_render_context.h" #include "core/pipeline_ng/pipeline_context.h" -#include "pointer_event.h" -#include "transaction/rs_interfaces.h" #ifdef ENABLE_DRAG_FRAMEWORK #include "core/common/udmf/udmf_client.h" @@ -91,8 +92,8 @@ void FormPattern::OnAttachToFrameNode() FormManager::GetInstance().AddSubContainer(id, subContainer); uiTaskExecutor.PostDelayedTask( [id, nodeId = subContainer->GetNodeId()] { - auto cachedubContainer = FormManager::GetInstance().GetSubContainer(id); - if (cachedubContainer != nullptr && cachedubContainer->GetNodeId() == nodeId) { + auto cachedSubContainer = FormManager::GetInstance().GetSubContainer(id); + if (cachedSubContainer != nullptr && cachedSubContainer->GetNodeId() == nodeId) { FormManager::GetInstance().RemoveSubContainer(id); } }, @@ -143,8 +144,7 @@ void FormPattern::UpdateBackgroundColorWhenUnTrustForm() auto formTheme = pipelineContext->GetTheme(); CHECK_NULL_VOID(formTheme); Color unTrustBackgroundColor = formTheme->GetUnTrustBackgroundColor(); - LOGI("UpdateBackgroundColor: %{public}s when isUnTrust.", - unTrustBackgroundColor.ColorToString().c_str()); + LOGI("UpdateBackgroundColor: %{public}s when isUnTrust.", unTrustBackgroundColor.ColorToString().c_str()); host->GetRenderContext()->UpdateBackgroundColor(unTrustBackgroundColor); } @@ -161,6 +161,36 @@ void FormPattern::HandleSnapshot() form->TakeSurfaceCaptureForUI(); }, TaskExecutor::TaskType::UI, DELAY_TIME_FOR_FORM_SNAPSHOT); + + // Init click event for static form. + auto gestureEventHub = GetHost()->GetOrCreateGestureEventHub(); + auto clickCallback = [weak = WeakClaim(this)](GestureEvent& info) { + auto formPattern = weak.Upgrade(); + CHECK_NULL_VOID(formPattern); + formPattern->HandleStaticFormEvent({ info.GetLocalLocation().GetX(), info.GetLocalLocation().GetY() }); + }; + auto clickEvent = AceType::MakeRefPtr(std::move(clickCallback)); + gestureEventHub->AddClickEvent(clickEvent); +} + +void FormPattern::HandleStaticFormEvent(const PointF& touchPoint) +{ + if (formLinkInfos_.empty()) { + LOGE("formLinkInfos is empty, do not handle event."); + return; + } + for (auto info : formLinkInfos_) { + auto linkInfo = JsonUtil::ParseJsonString(info); + auto action = linkInfo->GetValue("action")->GetString(); + auto rectStr = linkInfo->GetValue("formLinkRect")->GetString(); + RectF linkRect = RectF::FromString(rectStr); + LOGI("touchPoint: %{public}s, action: %{public}s, linkRect: %{public}s", + touchPoint.ToString().c_str() action.c_str(), linkRect.ToString().c_str()); + if (linkRect.IsInRegion(touchPoint)) { + OnActionEvent(action); + break; + } + } } void FormPattern::TakeSurfaceCaptureForUI() @@ -407,8 +437,7 @@ void FormPattern::InitFormManagerDelegate() const std::map>& imageDataMap, const AppExecFwk::FormJsInfo& formJsInfo, - const FrontendType& frontendType, - const FrontendType& uiSyntax) { + const FrontendType& frontendType, const FrontendType& uiSyntax) { ContainerScope scope(instanceID); auto form = weak.Upgrade(); CHECK_NULL_VOID(form); @@ -416,8 +445,8 @@ void FormPattern::InitFormManagerDelegate() CHECK_NULL_VOID(host); auto uiTaskExecutor = SingleTaskExecutor::Make(host->GetContext()->GetTaskExecutor(), TaskExecutor::TaskType::UI); - uiTaskExecutor.PostTask([id, path, module, data, imageDataMap, formJsInfo, weak, - instanceID, frontendType, uiSyntax] { + uiTaskExecutor.PostTask([id, path, module, data, imageDataMap, formJsInfo, weak, instanceID, frontendType, + uiSyntax] { ContainerScope scope(instanceID); auto form = weak.Upgrade(); CHECK_NULL_VOID(form); @@ -518,7 +547,7 @@ void FormPattern::InitFormManagerDelegate() parent->RebuildRenderContextTree(); host->GetRenderContext()->RequestNextFrame(); formComponent->OnLoadEvent(); - }); + }); formManagerBridge_->AddFormSurfaceChangeCallback([weak = WeakClaim(this), instanceID](float width, float height) { auto formComponent = weak.Upgrade(); @@ -537,32 +566,37 @@ void FormPattern::InitFormManagerDelegate() host->GetRenderContext()->RequestNextFrame(); }); - formManagerBridge_->AddActionEventHandle( - [weak = WeakClaim(this), instanceID](const std::string& action) { - ContainerScope scope(instanceID); - LOGI("OnActionEvent action: %{public}s", action.c_str()); - auto formPattern = weak.Upgrade(); - CHECK_NULL_VOID(formPattern); - formPattern->OnActionEvent(action); + formManagerBridge_->AddActionEventHandle([weak = WeakClaim(this), instanceID](const std::string& action) { + ContainerScope scope(instanceID); + LOGI("OnActionEvent action: %{public}s", action.c_str()); + auto formPattern = weak.Upgrade(); + CHECK_NULL_VOID(formPattern); + formPattern->OnActionEvent(action); }); - formManagerBridge_->AddUnTrustFormCallback( - [weak = WeakClaim(this), instanceID]() { - ContainerScope scope(instanceID); - LOGI("HandleUnTrustForm"); - auto formPattern = weak.Upgrade(); - CHECK_NULL_VOID(formPattern); - formPattern->HandleUnTrustForm(); + formManagerBridge_->AddUnTrustFormCallback([weak = WeakClaim(this), instanceID]() { + ContainerScope scope(instanceID); + LOGI("HandleUnTrustForm"); + auto formPattern = weak.Upgrade(); + CHECK_NULL_VOID(formPattern); + formPattern->HandleUnTrustForm(); }); - formManagerBridge_->AddSnapshotCallback( - [weak = WeakClaim(this), instanceID]() { + formManagerBridge_->AddSnapshotCallback([weak = WeakClaim(this), instanceID]() { + ContainerScope scope(instanceID); + LOGI("HandleSnapshot"); + auto formPattern = weak.Upgrade(); + CHECK_NULL_VOID(formPattern); + formPattern->HandleSnapshot(); + }); + + formManagerBridge_->AddFormLinkInfoUpdateCallback( + [weak = WeakClaim(this), instanceID](const std::vector& infos) { ContainerScope scope(instanceID); - LOGI("HandleSnapshot"); auto formPattern = weak.Upgrade(); CHECK_NULL_VOID(formPattern); - formPattern->HandleSnapshot(); - }); + formPattern->SetFormLinkInfos(infos); + }); } void FormPattern::CreateCardContainer() @@ -787,8 +821,7 @@ const RefPtr& FormPattern::GetSubContainer() const return subContainer_; } -void FormPattern::DispatchPointerEvent( - const std::shared_ptr& pointerEvent) const +void FormPattern::DispatchPointerEvent(const std::shared_ptr& pointerEvent) const { if (!pointerEvent || !formManagerBridge_) { LOGE("Func: %{public}s, pointerEvent or formManagerBridge is null", __func__); diff --git a/frameworks/core/components_ng/pattern/form/form_pattern.h b/frameworks/core/components_ng/pattern/form/form_pattern.h index ba1a968a14d..8491c64f6ab 100644 --- a/frameworks/core/components_ng/pattern/form/form_pattern.h +++ b/frameworks/core/components_ng/pattern/form/form_pattern.h @@ -61,8 +61,7 @@ public: const RefPtr& GetSubContainer() const; - void DispatchPointerEvent( - const std::shared_ptr& pointerEvent) const; + void DispatchPointerEvent(const std::shared_ptr& pointerEvent) const; void OnSnapshot(std::shared_ptr pixelMap); @@ -81,6 +80,11 @@ public: isUnTrust_ = isUnTrust; } + void SetFormLinkInfos(const std::vector& infos) + { + formLinkInfos_ = infos; + } + private: void OnAttachToFrameNode() override; bool OnDirtyLayoutWrapperSwap(const RefPtr& dirty, const DirtySwapConfig& config) override; @@ -110,6 +114,7 @@ private: void RemoveFrsNode(); void ReleaseRenderer(); void HideImageNode(); + void HandleStaticFormEvent(const PointF& touchPoint); // used by ArkTS Card, for RSSurfaceNode from FRS, RefPtr externalRenderContext_; @@ -125,6 +130,7 @@ private: RefPtr pixelMap_ = nullptr; int32_t scopeId_; std::string localeTag_ = AceApplicationInfo::GetInstance().GetLocaleTag(); + std::vector formLinkInfos_; }; } // namespace NG diff --git a/frameworks/core/components_ng/pattern/form_link/form_link_infos.h b/frameworks/core/components_ng/pattern/form_link/form_link_infos.h new file mode 100644 index 00000000000..414ed48eb4b --- /dev/null +++ b/frameworks/core/components_ng/pattern/form_link/form_link_infos.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2023 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_NG_PATTERN_FORM_LINK_INFOS_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_LINK_INFOS_H + +#include "base/geometry/ng/rect_t.h" +#include "base/json/json_util.h" + +namespace OHOS::Ace::NG { +class FormLinkInfo final { +public: + FormLinkInfo() = default; + + ~FormLinkInfo() = default; + + void SetAction(const std::string& action) + { + action_ = action; + } + + void SetFomLinkRect(const RectF& rect) + { + formLinkRect_ = rect; + } + + std::string ToString() + { + auto json = JsonUtil::Create(true); + json->Put("action", action_.c_str()); + json->Put("formLinkRect", formLinkRect_.ToString().c_str()); + return json->ToString(); + } + +private: + RectF formLinkRect_; + std::string action_; +}; + +} // namespace OHOS::Ace::NG + +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_LINK_INFOS_H diff --git a/frameworks/core/components_ng/pattern/form_link/form_link_model_ng.cpp b/frameworks/core/components_ng/pattern/form_link/form_link_model_ng.cpp index 992e72a686b..c232a3f411c 100644 --- a/frameworks/core/components_ng/pattern/form_link/form_link_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/form_link/form_link_model_ng.cpp @@ -26,6 +26,8 @@ void FormLinkModelNG::Create(const std::string& action) auto* stack = ViewStackProcessor::GetInstance(); auto frameNode = FrameNode::GetOrCreateFrameNode( V2::FORM_LINK_ETS_TAG, stack->ClaimNodeId(), []() { return AceType::MakeRefPtr(); }); + auto pattern = frameNode->GetPattern(); + pattern->SetAction(action); stack->Push(frameNode); } } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/form_link/form_link_pattern.cpp b/frameworks/core/components_ng/pattern/form_link/form_link_pattern.cpp new file mode 100644 index 00000000000..c10ca1c980a --- /dev/null +++ b/frameworks/core/components_ng/pattern/form_link/form_link_pattern.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2023 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_ng/pattern/form_link/form_link_pattern.h" + +#include "core/pipeline_ng/pipeline_context.h" + +namespace OHOS::Ace::NG { + +void FormLinkPattern::OnAttachToFrameNode() +{ + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto context = host->GetRenderContext(); + CHECK_NULL_VOID(context); + host->GetLayoutProperty()->UpdateMeasureType(MeasureType::MATCH_CONTENT); +} + +bool FormLinkPattern::OnDirtyLayoutWrapperSwap(const RefPtr& dirty, const DirtySwapConfig& config) +{ + CHECK_NULL_RETURN(dirty, false); + auto geometryNode = dirty->GetGeometryNode(); + CHECK_NULL_RETURN(geometryNode, false); + formLinkInfo_.SetFomLinkRect(geometryNode->GetFrameRect()); + auto pipeline = PipelineContext::GetCurrentContext(); + CHECK_NULL_RETURN(pipeline, false); + pipeline->AddFormLinkInfo(formLinkInfo_.ToString()); + LOGI("formLinkInfo is %{public}s", formLinkInfo_.ToString().c_str()); + return false; +} + +} // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/form_link/form_link_pattern.h b/frameworks/core/components_ng/pattern/form_link/form_link_pattern.h index 3adb2bbd844..9301e56d464 100644 --- a/frameworks/core/components_ng/pattern/form_link/form_link_pattern.h +++ b/frameworks/core/components_ng/pattern/form_link/form_link_pattern.h @@ -16,6 +16,7 @@ #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_LINK_PATTERN_H #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_LINK_PATTERN_H +#include "core/components_ng/pattern/form_link/form_link_infos.h" #include "core/components_ng/pattern/pattern.h" namespace OHOS::Ace::NG { @@ -26,6 +27,31 @@ class FormLinkPattern : public Pattern { public: FormLinkPattern() = default; ~FormLinkPattern() override = default; + + void OnModifyDone() override; + + bool IsMeasureBoundary() const override + { + return true; + } + + bool IsAtomicNode() const override + { + return false; + } + + void SetAction(const std::string& action) + { + formLinkInfo_.SetAction(action); + } + +private: + void OnAttachToFrameNode() override; + bool OnDirtyLayoutWrapperSwap(const RefPtr& dirty, const DirtySwapConfig& config) override; + + void UpdateFormLinkHotZone(); + + FormLinkInfo formLinkInfo_; }; } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/test/pattern/form/mock/mock_form_manager_delegate.cpp b/frameworks/core/components_ng/test/pattern/form/mock/mock_form_manager_delegate.cpp index 0e59326896e..08d7f155f25 100644 --- a/frameworks/core/components_ng/test/pattern/form/mock/mock_form_manager_delegate.cpp +++ b/frameworks/core/components_ng/test/pattern/form/mock/mock_form_manager_delegate.cpp @@ -57,9 +57,9 @@ void FormManagerDelegate::AddRenderDelegate() {} void FormManagerDelegate::RegisterRenderDelegateEvent() {} -void FormManagerDelegate::AddFormSurfaceNodeCallback(const OnFormSurfaceNodeCallback &callback) {} +void FormManagerDelegate::AddFormSurfaceNodeCallback(const OnFormSurfaceNodeCallback& callback) {} -void FormManagerDelegate::AddActionEventHandle(const ActionEventHandle &callback) {} +void FormManagerDelegate::AddActionEventHandle(const ActionEventHandle& callback) {} void FormManagerDelegate::SetAllowUpdate(bool allowUpdate) {} @@ -67,7 +67,9 @@ void FormManagerDelegate::DispatchPointerEvent(const std::shared_ptr& formLinkInfos) {} } // namespace OHOS::Ace diff --git a/frameworks/core/pipeline/pipeline_base.cpp b/frameworks/core/pipeline/pipeline_base.cpp index 3a95ce63eea..b73b63d062f 100644 --- a/frameworks/core/pipeline/pipeline_base.cpp +++ b/frameworks/core/pipeline/pipeline_base.cpp @@ -327,9 +327,9 @@ void PipelineBase::NotifyDestroyEventDismiss() const void PipelineBase::NotifyDispatchTouchEventDismiss(const TouchEvent& event) const { CHECK_RUN_ON(UI); - for (auto& iterDispatchTouchEventHander : dispatchTouchEventHandler_) { - if (iterDispatchTouchEventHander) { - iterDispatchTouchEventHander(event); + for (auto& iterDispatchTouchEventHandler : dispatchTouchEventHandler_) { + if (iterDispatchTouchEventHandler) { + iterDispatchTouchEventHandler(event); } } } diff --git a/frameworks/core/pipeline/pipeline_base.h b/frameworks/core/pipeline/pipeline_base.h index b61e4b2772d..ef3aa5af9fe 100644 --- a/frameworks/core/pipeline/pipeline_base.h +++ b/frameworks/core/pipeline/pipeline_base.h @@ -295,6 +295,12 @@ public: actionEventHandler_ = std::move(listener); } + using FormLinkInfoUpdateHandler = std::function&)>; + void SetFormLinkInfoUpdateHandler(FormLinkInfoUpdateHandler&& listener) + { + formLinkInfoUpdateHandler_ = std::move(listener); + } + using StatusBarEventHandler = std::function; void SetStatusBarEventHandler(StatusBarEventHandler&& listener) { @@ -560,7 +566,7 @@ public: return dipScale_; } - // Get the widnow design scale used to covert lpx to logic px. + // Get the window design scale used to covert lpx to logic px. double GetLogicScale() const { return designWidthScale_; @@ -897,6 +903,12 @@ public: return lastTouchTime_; } + void AddFormLinkInfo(const std::string& info) + { + LOGI("AddFormLinkInfo is %{public}s", info.c_str()); + formLinkInfos_.push_back(info); + } + protected: void TryCallNextFrameLayoutCallback() { @@ -905,6 +917,9 @@ protected: nextFrameLayoutCallback_(); LOGI("nextFrameLayoutCallback called"); } + if (formLinkInfoUpdateHandler_) { + formLinkInfoUpdateHandler_(formLinkInfos_); + } } virtual bool OnDumpInfo(const std::vector& params) const @@ -987,6 +1002,7 @@ protected: FinishEventHandler finishEventHandler_; StartAbilityHandler startAbilityHandler_; ActionEventHandler actionEventHandler_; + FormLinkInfoUpdateHandler formLinkInfoUpdateHandler_; RefPtr platformResRegister_; WeakPtr parentPipeline_; @@ -1004,6 +1020,7 @@ protected: SharePanelCallback sharePanelCallback_ = nullptr; std::atomic isForegroundCalled_ = false; uint64_t lastTouchTime_ = 0; + std::vector formLinkInfos_; private: void DumpFrontend() const; diff --git a/interfaces/inner_api/ace/ui_content.h b/interfaces/inner_api/ace/ui_content.h index c2050abc06b..0e32c4dc11f 100644 --- a/interfaces/inner_api/ace/ui_content.h +++ b/interfaces/inner_api/ace/ui_content.h @@ -139,6 +139,7 @@ public: virtual void SetActionEventHandler(std::function&& actionCallback) = 0; virtual void SetErrorEventHandler(std::function&& errorCallback) = 0; + virtual void SetFormLinkInfoUpdateHandler(std::function&)>&& callback) = 0; // for distribute UI source virtual SerializeableObjectArray DumpUITree() diff --git a/interfaces/inner_api/form_render/include/form_renderer.h b/interfaces/inner_api/form_render/include/form_renderer.h index 36150d2f4b6..b9fc38ec071 100644 --- a/interfaces/inner_api/form_render/include/form_renderer.h +++ b/interfaces/inner_api/form_render/include/form_renderer.h @@ -18,13 +18,12 @@ #include "ability_context.h" #include "form_js_info.h" +#include "form_renderer_delegate_interface.h" +#include "form_renderer_dispatcher_impl.h" #include "js_runtime.h" #include "runtime.h" #include "ui_content.h" -#include "form_renderer_delegate_interface.h" -#include "form_renderer_dispatcher_impl.h" - namespace OHOS { namespace AppExecFwk { class Configuration; @@ -36,7 +35,7 @@ namespace Ace { class FormRenderer : public std::enable_shared_from_this { public: FormRenderer(const std::shared_ptr context, - const std::shared_ptr runtime); + const std::shared_ptr runtime); ~FormRenderer() = default; void AddForm(const OHOS::AAFwk::Want& want, const OHOS::AppExecFwk::FormJsInfo& formJsInfo); @@ -52,13 +51,14 @@ public: void OnActionEvent(const std::string& action); void OnError(const std::string& code, const std::string& msg); void OnSurfaceChange(float width, float height); + void OnFormLinkInfoUpdate(const std::vector& formLinkInfos); void UpdateConfiguration(const std::shared_ptr& config); void AttachForm(const OHOS::AAFwk::Want& want, const OHOS::AppExecFwk::FormJsInfo& formJsInfo); private: void InitUIContent(const OHOS::AppExecFwk::FormJsInfo& formJsInfo); void ParseWant(const OHOS::AAFwk::Want& want); - void SetRenderDelegate(const sptr &renderRemoteObj); + void SetRenderDelegate(const sptr& renderRemoteObj); void AttachUIContent(const OHOS::AppExecFwk::FormJsInfo& formJsInfo); bool allowUpdate_ = true; @@ -89,6 +89,6 @@ public: private: RemoteDiedHandler handler_; }; -} // namespace Ace -} // namespace OHOS -#endif // FOUNDATION_ACE_INTERFACE_INNERKITS_FORM_RENDERER_H +} // namespace Ace +} // namespace OHOS +#endif // FOUNDATION_ACE_INTERFACE_INNERKITS_FORM_RENDERER_H diff --git a/interfaces/inner_api/form_render/include/form_renderer_delegate_impl.h b/interfaces/inner_api/form_render/include/form_renderer_delegate_impl.h index 67942f609a5..4a1213a95c3 100644 --- a/interfaces/inner_api/form_render/include/form_renderer_delegate_impl.h +++ b/interfaces/inner_api/form_render/include/form_renderer_delegate_impl.h @@ -34,10 +34,8 @@ public: * @param formJsInfo The formJsInfo. * @param want The want. */ - int32_t OnSurfaceCreate( - const std::shared_ptr& surfaceNode, - const OHOS::AppExecFwk::FormJsInfo& formJsInfo, - const AAFwk::Want& want) override; + int32_t OnSurfaceCreate(const std::shared_ptr& surfaceNode, + const OHOS::AppExecFwk::FormJsInfo& formJsInfo, const AAFwk::Want& want) override; /** * @brief OnActionEvent. * @param action The action. @@ -56,11 +54,14 @@ public: */ int32_t OnSurfaceChange(float width, float height) override; + int32_t OnFormLinkInfoUpdate(const std::vector& formLinkInfos) override; + void SetSurfaceCreateEventHandler(std::function&, const OHOS::AppExecFwk::FormJsInfo&, const AAFwk::Want&)>&& listener); void SetActionEventHandler(std::function&& listener); void SetErrorEventHandler(std::function&& listener); void SetSurfaceChangeEventHandler(std::function&& listener); + void SetFormLinkInfoUpdateHandler(std::function&)>&& listener); private: std::function actionEventHandler_; std::function errorEventHandler_; std::function surfaceChangeEventHandler_; + std::function&)> formLinkInfoUpdateHandler_; }; } // namespace Ace } // namespace OHOS -#endif // FOUNDATION_ACE_INTERFACE_INNERKITS_FORM_RENDERER_DELEGATE_IMPL_H +#endif // FOUNDATION_ACE_INTERFACE_INNERKITS_FORM_RENDERER_DELEGATE_IMPL_H diff --git a/interfaces/inner_api/form_render/include/form_renderer_delegate_interface.h b/interfaces/inner_api/form_render/include/form_renderer_delegate_interface.h index 56a52a2e8b8..a05da7e7898 100644 --- a/interfaces/inner_api/form_render/include/form_renderer_delegate_interface.h +++ b/interfaces/inner_api/form_render/include/form_renderer_delegate_interface.h @@ -43,19 +43,16 @@ public: * @param formJsInfo The formJsInfo. * @param want The want. */ - virtual int32_t OnSurfaceCreate( - const std::shared_ptr& surfaceNode, - const OHOS::AppExecFwk::FormJsInfo& formJsInfo, - const AAFwk::Want& want) = 0; + virtual int32_t OnSurfaceCreate(const std::shared_ptr& surfaceNode, + const OHOS::AppExecFwk::FormJsInfo& formJsInfo, const AAFwk::Want& want) = 0; /** * @brief OnSurfaceReuse. * @param surfaceId The surfaceNode ID. * @param formJsInfo The formJsInfo. * @param want The want. */ - virtual int32_t OnSurfaceReuse(uint64_t surfaceId, - const OHOS::AppExecFwk::FormJsInfo& formJsInfo, - const AAFwk::Want& want) + virtual int32_t OnSurfaceReuse( + uint64_t surfaceId, const OHOS::AppExecFwk::FormJsInfo& formJsInfo, const AAFwk::Want& want) { return ERR_OK; } @@ -84,6 +81,11 @@ public: * @param height */ virtual int32_t OnSurfaceChange(float width, float height) = 0; + /** + * @brief OnFormLinkInfoUpdate. + * @param formLinkInfos + */ + virtual int32_t OnFormLinkInfoUpdate(const std::vector& formLinkInfos) = 0; enum Message : uint32_t { ON_SURFACE_CREATE = 1, @@ -92,8 +94,9 @@ public: ON_ACTION_CREATE, ON_ERROR, ON_SURFACE_CHANGE, + ON_FORM_LINK_INFO_UPDATE, }; }; -} // namespace Ace -} // namespace OHOS -#endif // FOUNDATION_ACE_INTERFACE_INNERKITS_FORM_RENDERER_DELEGATE_INTERFACE_H +} // namespace Ace +} // namespace OHOS +#endif // FOUNDATION_ACE_INTERFACE_INNERKITS_FORM_RENDERER_DELEGATE_INTERFACE_H diff --git a/interfaces/inner_api/form_render/include/form_renderer_delegate_proxy.h b/interfaces/inner_api/form_render/include/form_renderer_delegate_proxy.h index b15d12d1ed8..4b8dd27ed52 100644 --- a/interfaces/inner_api/form_render/include/form_renderer_delegate_proxy.h +++ b/interfaces/inner_api/form_render/include/form_renderer_delegate_proxy.h @@ -35,8 +35,8 @@ public: int32_t OnSurfaceCreate(const std::shared_ptr& surfaceNode, const OHOS::AppExecFwk::FormJsInfo& formJsInfo, const AAFwk::Want& want) override; - int32_t OnSurfaceReuse(uint64_t surfaceId, - const OHOS::AppExecFwk::FormJsInfo& formJsInfo, const AAFwk::Want& want) override; + int32_t OnSurfaceReuse( + uint64_t surfaceId, const OHOS::AppExecFwk::FormJsInfo& formJsInfo, const AAFwk::Want& want) override; int32_t OnSurfaceRelease(uint64_t surfaceId) override; @@ -46,6 +46,8 @@ public: int32_t OnSurfaceChange(float width, float height) override; + int32_t OnFormLinkInfoUpdate(const std::vector& formLinkInfos) override; + private: static bool WriteInterfaceToken(MessageParcel& data); diff --git a/interfaces/inner_api/form_render/include/form_renderer_delegate_stub.h b/interfaces/inner_api/form_render/include/form_renderer_delegate_stub.h index 45b0d4d8bd8..36a731e7884 100644 --- a/interfaces/inner_api/form_render/include/form_renderer_delegate_stub.h +++ b/interfaces/inner_api/form_render/include/form_renderer_delegate_stub.h @@ -41,19 +41,18 @@ public: * @param option message option. * @return Returns ERR_OK on success, others on failure. */ - int32_t OnRemoteRequest( - uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override; private: - int32_t HandleOnSurfaceCreate(MessageParcel &data, MessageParcel &reply); - int32_t HandleOnSurfaceReuse(MessageParcel &data, MessageParcel &reply); - int32_t HandleOnSurfaceRelease(MessageParcel &data, MessageParcel &reply); - int32_t HandleOnActionEvent(MessageParcel &data, MessageParcel &reply); - int32_t HandleOnError(MessageParcel &data, MessageParcel &reply); - int32_t HandleOnSurfaceChange(MessageParcel &data, MessageParcel &reply); - - using FormRendererDelegateFunc = - int32_t (FormRendererDelegateStub::*)(MessageParcel &data, MessageParcel &reply); + int32_t HandleOnSurfaceCreate(MessageParcel& data, MessageParcel& reply); + int32_t HandleOnSurfaceReuse(MessageParcel& data, MessageParcel& reply); + int32_t HandleOnSurfaceRelease(MessageParcel& data, MessageParcel& reply); + int32_t HandleOnActionEvent(MessageParcel& data, MessageParcel& reply); + int32_t HandleOnError(MessageParcel& data, MessageParcel& reply); + int32_t HandleOnSurfaceChange(MessageParcel& data, MessageParcel& reply); + int32_t HandleOnFormLinkInfoUpdate(MessageParcel& data, MessageParcel& reply); + + using FormRendererDelegateFunc = int32_t (FormRendererDelegateStub::*)(MessageParcel& data, MessageParcel& reply); std::map memberFuncMap_; DISALLOW_COPY_AND_MOVE(FormRendererDelegateStub); diff --git a/interfaces/inner_api/form_render/src/form_renderer.cpp b/interfaces/inner_api/form_render/src/form_renderer.cpp index e4071a01e90..0f2b94208b0 100644 --- a/interfaces/inner_api/form_render/src/form_renderer.cpp +++ b/interfaces/inner_api/form_render/src/form_renderer.cpp @@ -15,21 +15,21 @@ #include "form_renderer.h" -#include "base/utils/utils.h" #include "configuration.h" #include "form_constants.h" #include "form_renderer_hilog.h" #include "refbase.h" +#include "base/utils/utils.h" + namespace OHOS { namespace Ace { namespace { constexpr char FORM_RENDERER_ALLOW_UPDATE[] = "allowUpdate"; constexpr char FORM_RENDERER_DISPATCHER[] = "ohos.extra.param.key.process_on_form_renderer_dispatcher"; constexpr char FORM_RENDERER_PROCESS_ON_ADD_SURFACE[] = "ohos.extra.param.key.process_on_add_surface"; -} -FormRenderer::FormRenderer( - const std::shared_ptr context, +} // namespace +FormRenderer::FormRenderer(const std::shared_ptr context, const std::shared_ptr runtime) : context_(context), runtime_(runtime) { @@ -67,6 +67,14 @@ void FormRenderer::InitUIContent(const OHOS::AppExecFwk::FormJsInfo& formJsInfo) }; uiContent_->SetErrorEventHandler(errorEventHandler); + auto formLinkInfoUpdateHandler = [weak = weak_from_this()](const std::vector& formLinkInfos) { + auto formRenderer = weak.lock(); + if (formRenderer) { + formRenderer->OnFormLinkInfoUpdate(formLinkInfos); + } + }; + uiContent_->SetFormLinkInfoUpdateHandler(formLinkInfoUpdateHandler); + auto rsSurfaceNode = uiContent_->GetFormRootNode(); if (rsSurfaceNode == nullptr) { return; @@ -232,7 +240,17 @@ void FormRenderer::OnError(const std::string& code, const std::string& msg) formRendererDelegate_->OnError(code, msg); } -void FormRenderer::SetRenderDelegate(const sptr &remoteObj) +void FormRenderer::OnFormLinkInfoUpdate(const std::vector& formLinkInfos) +{ + if (!formRendererDelegate_) { + HILOG_ERROR("formRendererDelegate is null!"); + return; + } + + formRendererDelegate_->OnFormLinkInfoUpdate(formLinkInfos); +} + +void FormRenderer::SetRenderDelegate(const sptr& remoteObj) { HILOG_INFO("Get renderRemoteObj, add death recipient."); auto renderRemoteObj = iface_cast(remoteObj); @@ -267,8 +285,7 @@ void FormRenderer::ResetRenderDelegate() formRendererDelegate_ = nullptr; } -void FormRenderer::UpdateConfiguration( - const std::shared_ptr& config) +void FormRenderer::UpdateConfiguration(const std::shared_ptr& config) { if (!uiContent_) { HILOG_ERROR("uiContent_ is null"); @@ -311,8 +328,7 @@ void FormRenderer::AttachUIContent(const OHOS::AppExecFwk::FormJsInfo& formJsInf HILOG_ERROR("rsSurfaceNode is nullptr."); return; } - if (!NearEqual(width_, uiContent_->GetFormWidth()) || - !NearEqual(height_, uiContent_->GetFormHeight())) { + if (!NearEqual(width_, uiContent_->GetFormWidth()) || !NearEqual(height_, uiContent_->GetFormHeight())) { uiContent_->SetFormWidth(width_); uiContent_->SetFormHeight(height_); uiContent_->OnFormSurfaceChange(width_, height_); @@ -320,5 +336,5 @@ void FormRenderer::AttachUIContent(const OHOS::AppExecFwk::FormJsInfo& formJsInf } uiContent_->Foreground(); } -} // namespace Ace -} // namespace OHOS +} // namespace Ace +} // namespace OHOS diff --git a/interfaces/inner_api/form_render/src/form_renderer_delegate_impl.cpp b/interfaces/inner_api/form_render/src/form_renderer_delegate_impl.cpp index 2de00d1d2e9..bebc6bb5f75 100644 --- a/interfaces/inner_api/form_render/src/form_renderer_delegate_impl.cpp +++ b/interfaces/inner_api/form_render/src/form_renderer_delegate_impl.cpp @@ -19,10 +19,8 @@ namespace OHOS { namespace Ace { -int32_t FormRendererDelegateImpl::OnSurfaceCreate( - const std::shared_ptr& surfaceNode, - const OHOS::AppExecFwk::FormJsInfo& formJsInfo, - const AAFwk::Want& want) +int32_t FormRendererDelegateImpl::OnSurfaceCreate(const std::shared_ptr& surfaceNode, + const OHOS::AppExecFwk::FormJsInfo& formJsInfo, const AAFwk::Want& want) { HILOG_DEBUG("%{public}s called.", __func__); if (!surfaceNode) { @@ -78,6 +76,17 @@ int32_t FormRendererDelegateImpl::OnSurfaceChange(float width, float height) return ERR_OK; } +int32_t FormRendererDelegateImpl::OnFormLinkInfoUpdate(const std::vector& formLinkInfos) +{ + HILOG_DEBUG("%{public}s called.", __func__); + if (!formLinkInfoUpdateHandler_) { + HILOG_ERROR("formLinkInfoUpdateHandler_ is null"); + return ERR_INVALID_DATA; + } + formLinkInfoUpdateHandler_(formLinkInfos); + return ERR_OK; +} + void FormRendererDelegateImpl::SetSurfaceCreateEventHandler( std::function&, const OHOS::AppExecFwk::FormJsInfo&, const AAFwk::Want&)>&& listener) @@ -85,8 +94,7 @@ void FormRendererDelegateImpl::SetSurfaceCreateEventHandler( surfaceCreateEventHandler_ = std::move(listener); } -void FormRendererDelegateImpl::SetActionEventHandler( - std::function&& listener) +void FormRendererDelegateImpl::SetActionEventHandler(std::function&& listener) { actionEventHandler_ = std::move(listener); } @@ -101,5 +109,11 @@ void FormRendererDelegateImpl::SetSurfaceChangeEventHandler(std::function&)>&& listener) +{ + formLinkInfoUpdateHandler_ = std::move(listener); +} } // namespace Ace } // namespace OHOS diff --git a/interfaces/inner_api/form_render/src/form_renderer_delegate_proxy.cpp b/interfaces/inner_api/form_render/src/form_renderer_delegate_proxy.cpp index 6019d1f53d1..e178a2e1a76 100644 --- a/interfaces/inner_api/form_render/src/form_renderer_delegate_proxy.cpp +++ b/interfaces/inner_api/form_render/src/form_renderer_delegate_proxy.cpp @@ -20,12 +20,11 @@ namespace OHOS { namespace Ace { FormRendererDelegateProxy::FormRendererDelegateProxy(const sptr& impl) - : IRemoteProxy(impl) {} + : IRemoteProxy(impl) +{} -int32_t FormRendererDelegateProxy::OnSurfaceCreate( - const std::shared_ptr& surfaceNode, - const OHOS::AppExecFwk::FormJsInfo& formJsInfo, - const AAFwk::Want& want) +int32_t FormRendererDelegateProxy::OnSurfaceCreate(const std::shared_ptr& surfaceNode, + const OHOS::AppExecFwk::FormJsInfo& formJsInfo, const AAFwk::Want& want) { MessageParcel data; if (!WriteInterfaceToken(data)) { @@ -67,8 +66,8 @@ int32_t FormRendererDelegateProxy::OnSurfaceCreate( return reply.ReadInt32(); } -int32_t FormRendererDelegateProxy::OnSurfaceReuse(uint64_t surfaceId, - const OHOS::AppExecFwk::FormJsInfo& formJsInfo, const AAFwk::Want& want) +int32_t FormRendererDelegateProxy::OnSurfaceReuse( + uint64_t surfaceId, const OHOS::AppExecFwk::FormJsInfo& formJsInfo, const AAFwk::Want& want) { MessageParcel data; if (!WriteInterfaceToken(data)) { @@ -175,8 +174,8 @@ int32_t FormRendererDelegateProxy::OnError(const std::string& code, const std::s MessageParcel reply; MessageOption option; - int32_t error = Remote()->SendRequest( - static_cast(IFormRendererDelegate::Message::ON_ERROR), data, reply, option); + int32_t error = + Remote()->SendRequest(static_cast(IFormRendererDelegate::Message::ON_ERROR), data, reply, option); if (error != NO_ERROR) { HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error); return error; @@ -213,7 +212,32 @@ int32_t FormRendererDelegateProxy::OnSurfaceChange(float width, float height) return reply.ReadInt32(); } -bool FormRendererDelegateProxy::WriteInterfaceToken(MessageParcel &data) +int32_t FormRendererDelegateProxy::OnFormLinkInfoUpdate(const std::vector& formLinkInfos) +{ + MessageParcel data; + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("%{public}s, failed to write interface token", __func__); + return ERR_INVALID_VALUE; + } + + if (!data.WriteStringVector(formLinkInfos)) { + HILOG_ERROR("%{public}s, write formLinkInfos error", __func__); + return ERR_INVALID_VALUE; + } + + MessageParcel reply; + MessageOption option; + int32_t error = Remote()->SendRequest( + static_cast(IFormRendererDelegate::Message::ON_FORM_LINK_INFO_UPDATE), data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error); + return error; + } + + return reply.ReadInt32(); +} + +bool FormRendererDelegateProxy::WriteInterfaceToken(MessageParcel& data) { if (!data.WriteInterfaceToken(FormRendererDelegateProxy::GetDescriptor())) { HILOG_ERROR("%{public}s, failed to write interface token", __func__); diff --git a/interfaces/inner_api/form_render/src/form_renderer_delegate_stub.cpp b/interfaces/inner_api/form_render/src/form_renderer_delegate_stub.cpp index 9e8d5a8470e..7b88fdd9b5d 100644 --- a/interfaces/inner_api/form_render/src/form_renderer_delegate_stub.cpp +++ b/interfaces/inner_api/form_render/src/form_renderer_delegate_stub.cpp @@ -35,6 +35,8 @@ FormRendererDelegateStub::FormRendererDelegateStub() &FormRendererDelegateStub::HandleOnError; memberFuncMap_[static_cast(IFormRendererDelegate::Message::ON_SURFACE_CHANGE)] = &FormRendererDelegateStub::HandleOnSurfaceChange; + memberFuncMap_[static_cast(IFormRendererDelegate::Message::ON_FORM_LINK_INFO_UPDATE)] = + &FormRendererDelegateStub::HandleOnFormLinkInfoUpdate; } FormRendererDelegateStub::~FormRendererDelegateStub() @@ -43,10 +45,9 @@ FormRendererDelegateStub::~FormRendererDelegateStub() } int FormRendererDelegateStub::OnRemoteRequest( - uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) + uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) { - HILOG_DEBUG("FormRendererDelegateStub::OnReceived, code = %{public}u, flags= %{public}d.", - code, option.GetFlags()); + HILOG_DEBUG("FormRendererDelegateStub::OnReceived, code = %{public}u, flags= %{public}d.", code, option.GetFlags()); std::u16string descriptor = FormRendererDelegateStub::GetDescriptor(); std::u16string remoteDescriptor = data.ReadInterfaceToken(); if (descriptor != remoteDescriptor) { @@ -65,7 +66,7 @@ int FormRendererDelegateStub::OnRemoteRequest( return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } -int FormRendererDelegateStub::HandleOnSurfaceCreate(MessageParcel &data, MessageParcel &reply) +int FormRendererDelegateStub::HandleOnSurfaceCreate(MessageParcel& data, MessageParcel& reply) { auto surfaceNode = Rosen::RSSurfaceNode::Unmarshalling(data); if (surfaceNode == nullptr) { @@ -94,7 +95,7 @@ int FormRendererDelegateStub::HandleOnSurfaceCreate(MessageParcel &data, Message return ERR_OK; } -int32_t FormRendererDelegateStub::HandleOnSurfaceReuse(MessageParcel &data, MessageParcel &reply) +int32_t FormRendererDelegateStub::HandleOnSurfaceReuse(MessageParcel& data, MessageParcel& reply) { uint64_t id = UINT64_MAX; data.ReadUint64(id); @@ -129,7 +130,7 @@ int32_t FormRendererDelegateStub::HandleOnSurfaceReuse(MessageParcel &data, Mess return ERR_OK; } -int32_t FormRendererDelegateStub::HandleOnSurfaceRelease(MessageParcel &data, MessageParcel &reply) +int32_t FormRendererDelegateStub::HandleOnSurfaceRelease(MessageParcel& data, MessageParcel& reply) { uint64_t id = UINT64_MAX; data.ReadUint64(id); @@ -146,7 +147,7 @@ int32_t FormRendererDelegateStub::HandleOnSurfaceRelease(MessageParcel &data, Me return ERR_OK; } -int FormRendererDelegateStub::HandleOnActionEvent(MessageParcel &data, MessageParcel &reply) +int FormRendererDelegateStub::HandleOnActionEvent(MessageParcel& data, MessageParcel& reply) { std::string action = data.ReadString(); int32_t errCode = OnActionEvent(action); @@ -154,7 +155,7 @@ int FormRendererDelegateStub::HandleOnActionEvent(MessageParcel &data, MessagePa return ERR_OK; } -int32_t FormRendererDelegateStub::HandleOnError(MessageParcel &data, MessageParcel &reply) +int32_t FormRendererDelegateStub::HandleOnError(MessageParcel& data, MessageParcel& reply) { std::string code = data.ReadString(); std::string msg = data.ReadString(); @@ -171,5 +172,14 @@ int32_t FormRendererDelegateStub::HandleOnSurfaceChange(MessageParcel& data, Mes reply.WriteInt32(ERR_OK); return ERR_OK; } -} // namespace Ace -} // namespace OHOS + +int32_t FormRendererDelegateStub::HandleOnFormLinkInfoUpdate(MessageParcel& data, MessageParcel& reply) +{ + std::vector formLinkInfos; + data.ReadStringVector(&formLinkInfos); + int32_t errCode = OnFormLinkInfoUpdate(formLinkInfos); + reply.WriteInt32(errCode); + return ERR_OK; +} +} // namespace Ace +} // namespace OHOS -- Gitee From bc59dd26fdfdd6a35fb1f7e26a2b2e5a60923fe3 Mon Sep 17 00:00:00 2001 From: jiangdayuan Date: Wed, 5 Jul 2023 09:28:28 +0800 Subject: [PATCH 2/2] fix build Signed-off-by: jiangdayuan Change-Id: If2b94bd7c5856f40f36446a02b12dfac9920fb0d --- adapter/preview/entrance/ui_content_impl.h | 1 + .../pattern/form/form_pattern.cpp | 14 +++++++++----- .../{form_link_infos.h => form_link_info.h} | 6 +++--- .../pattern/form_link/form_link_pattern.cpp | 3 --- .../pattern/form_link/form_link_pattern.h | 6 +----- frameworks/core/pipeline/pipeline_base.h | 1 + interfaces/inner_api/ace/ui_content.h | 6 +++--- .../form_render/include/form_renderer.h | 1 + .../form_render/src/form_renderer.cpp | 19 +++++++++++-------- test/mock/interfaces/mock_uicontent.h | 1 + 10 files changed, 31 insertions(+), 27 deletions(-) rename frameworks/core/components_ng/pattern/form_link/{form_link_infos.h => form_link_info.h} (96%) diff --git a/adapter/preview/entrance/ui_content_impl.h b/adapter/preview/entrance/ui_content_impl.h index 4cfcd02e8b0..366593e5aab 100644 --- a/adapter/preview/entrance/ui_content_impl.h +++ b/adapter/preview/entrance/ui_content_impl.h @@ -85,6 +85,7 @@ public: void SetAppWindowIcon(const std::shared_ptr& pixelMap) override {} void SetActionEventHandler(std::function&& actionCallback) override {} void SetErrorEventHandler(std::function&& errorCallback) override {} + void SetFormLinkInfoUpdateHandler(std::function&)>&& callback) override {} // ArkTS Form void OnFormSurfaceChange(float width, float height) override {} diff --git a/frameworks/core/components_ng/pattern/form/form_pattern.cpp b/frameworks/core/components_ng/pattern/form/form_pattern.cpp index 5daf7373d21..c0d4128f4a9 100644 --- a/frameworks/core/components_ng/pattern/form/form_pattern.cpp +++ b/frameworks/core/components_ng/pattern/form/form_pattern.cpp @@ -163,11 +163,14 @@ void FormPattern::HandleSnapshot() TaskExecutor::TaskType::UI, DELAY_TIME_FOR_FORM_SNAPSHOT); // Init click event for static form. - auto gestureEventHub = GetHost()->GetOrCreateGestureEventHub(); + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto gestureEventHub = host->GetOrCreateGestureEventHub(); auto clickCallback = [weak = WeakClaim(this)](GestureEvent& info) { auto formPattern = weak.Upgrade(); CHECK_NULL_VOID(formPattern); - formPattern->HandleStaticFormEvent({ info.GetLocalLocation().GetX(), info.GetLocalLocation().GetY() }); + formPattern->HandleStaticFormEvent( + { static_cast(info.GetLocalLocation().GetX()), static_cast(info.GetLocalLocation().GetY()) }); }; auto clickEvent = AceType::MakeRefPtr(std::move(clickCallback)); gestureEventHub->AddClickEvent(clickEvent); @@ -179,13 +182,14 @@ void FormPattern::HandleStaticFormEvent(const PointF& touchPoint) LOGE("formLinkInfos is empty, do not handle event."); return; } - for (auto info : formLinkInfos_) { + for (const auto& info : formLinkInfos_) { auto linkInfo = JsonUtil::ParseJsonString(info); + CHECK_NULL_VOID(linkInfo); auto action = linkInfo->GetValue("action")->GetString(); auto rectStr = linkInfo->GetValue("formLinkRect")->GetString(); RectF linkRect = RectF::FromString(rectStr); - LOGI("touchPoint: %{public}s, action: %{public}s, linkRect: %{public}s", - touchPoint.ToString().c_str() action.c_str(), linkRect.ToString().c_str()); + LOGD("touchPoint: %{public}s, action: %{public}s, linkRect: %{public}s", touchPoint.ToString().c_str(), + action.c_str(), linkRect.ToString().c_str()); if (linkRect.IsInRegion(touchPoint)) { OnActionEvent(action); break; diff --git a/frameworks/core/components_ng/pattern/form_link/form_link_infos.h b/frameworks/core/components_ng/pattern/form_link/form_link_info.h similarity index 96% rename from frameworks/core/components_ng/pattern/form_link/form_link_infos.h rename to frameworks/core/components_ng/pattern/form_link/form_link_info.h index 414ed48eb4b..1910653ad5d 100644 --- a/frameworks/core/components_ng/pattern/form_link/form_link_infos.h +++ b/frameworks/core/components_ng/pattern/form_link/form_link_info.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_LINK_INFOS_H -#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_LINK_INFOS_H +#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_LINK_INFO_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_LINK_INFO_H #include "base/geometry/ng/rect_t.h" #include "base/json/json_util.h" @@ -51,4 +51,4 @@ private: } // namespace OHOS::Ace::NG -#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_LINK_INFOS_H +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_LINK_INFO_H diff --git a/frameworks/core/components_ng/pattern/form_link/form_link_pattern.cpp b/frameworks/core/components_ng/pattern/form_link/form_link_pattern.cpp index c10ca1c980a..d35fa7300a6 100644 --- a/frameworks/core/components_ng/pattern/form_link/form_link_pattern.cpp +++ b/frameworks/core/components_ng/pattern/form_link/form_link_pattern.cpp @@ -23,8 +23,6 @@ void FormLinkPattern::OnAttachToFrameNode() { auto host = GetHost(); CHECK_NULL_VOID(host); - auto context = host->GetRenderContext(); - CHECK_NULL_VOID(context); host->GetLayoutProperty()->UpdateMeasureType(MeasureType::MATCH_CONTENT); } @@ -37,7 +35,6 @@ bool FormLinkPattern::OnDirtyLayoutWrapperSwap(const RefPtr& dirt auto pipeline = PipelineContext::GetCurrentContext(); CHECK_NULL_RETURN(pipeline, false); pipeline->AddFormLinkInfo(formLinkInfo_.ToString()); - LOGI("formLinkInfo is %{public}s", formLinkInfo_.ToString().c_str()); return false; } diff --git a/frameworks/core/components_ng/pattern/form_link/form_link_pattern.h b/frameworks/core/components_ng/pattern/form_link/form_link_pattern.h index 9301e56d464..27d3bbbb31f 100644 --- a/frameworks/core/components_ng/pattern/form_link/form_link_pattern.h +++ b/frameworks/core/components_ng/pattern/form_link/form_link_pattern.h @@ -16,7 +16,7 @@ #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_LINK_PATTERN_H #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_LINK_PATTERN_H -#include "core/components_ng/pattern/form_link/form_link_infos.h" +#include "core/components_ng/pattern/form_link/form_link_info.h" #include "core/components_ng/pattern/pattern.h" namespace OHOS::Ace::NG { @@ -28,8 +28,6 @@ public: FormLinkPattern() = default; ~FormLinkPattern() override = default; - void OnModifyDone() override; - bool IsMeasureBoundary() const override { return true; @@ -49,8 +47,6 @@ private: void OnAttachToFrameNode() override; bool OnDirtyLayoutWrapperSwap(const RefPtr& dirty, const DirtySwapConfig& config) override; - void UpdateFormLinkHotZone(); - FormLinkInfo formLinkInfo_; }; diff --git a/frameworks/core/pipeline/pipeline_base.h b/frameworks/core/pipeline/pipeline_base.h index ef3aa5af9fe..b47a249d0be 100644 --- a/frameworks/core/pipeline/pipeline_base.h +++ b/frameworks/core/pipeline/pipeline_base.h @@ -917,6 +917,7 @@ protected: nextFrameLayoutCallback_(); LOGI("nextFrameLayoutCallback called"); } + // Update FormLinkInfo after layout. (For static form use only) if (formLinkInfoUpdateHandler_) { formLinkInfoUpdateHandler_(formLinkInfos_); } diff --git a/interfaces/inner_api/ace/ui_content.h b/interfaces/inner_api/ace/ui_content.h index 0e32c4dc11f..e7591967ff1 100644 --- a/interfaces/inner_api/ace/ui_content.h +++ b/interfaces/inner_api/ace/ui_content.h @@ -137,9 +137,9 @@ public: virtual void ReloadForm(const std::string& url) {}; virtual void OnFormSurfaceChange(float width, float height) {} - virtual void SetActionEventHandler(std::function&& actionCallback) = 0; - virtual void SetErrorEventHandler(std::function&& errorCallback) = 0; - virtual void SetFormLinkInfoUpdateHandler(std::function&)>&& callback) = 0; + virtual void SetActionEventHandler(std::function&& actionCallback) {}; + virtual void SetErrorEventHandler(std::function&& errorCallback) {}; + virtual void SetFormLinkInfoUpdateHandler(std::function&)>&& callback) {}; // for distribute UI source virtual SerializeableObjectArray DumpUITree() diff --git a/interfaces/inner_api/form_render/include/form_renderer.h b/interfaces/inner_api/form_render/include/form_renderer.h index b9fc38ec071..e0991a1b580 100644 --- a/interfaces/inner_api/form_render/include/form_renderer.h +++ b/interfaces/inner_api/form_render/include/form_renderer.h @@ -64,6 +64,7 @@ private: bool allowUpdate_ = true; float width_ = 0.0f; float height_ = 0.0f; + std::vector cachedInfos_; std::shared_ptr context_; std::shared_ptr runtime_; sptr formRendererDispatcherImpl_; diff --git a/interfaces/inner_api/form_render/src/form_renderer.cpp b/interfaces/inner_api/form_render/src/form_renderer.cpp index 0f2b94208b0..718cd0de49b 100644 --- a/interfaces/inner_api/form_render/src/form_renderer.cpp +++ b/interfaces/inner_api/form_render/src/form_renderer.cpp @@ -67,13 +67,15 @@ void FormRenderer::InitUIContent(const OHOS::AppExecFwk::FormJsInfo& formJsInfo) }; uiContent_->SetErrorEventHandler(errorEventHandler); - auto formLinkInfoUpdateHandler = [weak = weak_from_this()](const std::vector& formLinkInfos) { - auto formRenderer = weak.lock(); - if (formRenderer) { - formRenderer->OnFormLinkInfoUpdate(formLinkInfos); - } - }; - uiContent_->SetFormLinkInfoUpdateHandler(formLinkInfoUpdateHandler); + if (!formJsInfo.isDynamic) { + auto formLinkInfoUpdateHandler = [weak = weak_from_this()](const std::vector& formLinkInfos) { + auto formRenderer = weak.lock(); + if (formRenderer) { + formRenderer->OnFormLinkInfoUpdate(formLinkInfos); + } + }; + uiContent_->SetFormLinkInfoUpdateHandler(formLinkInfoUpdateHandler); + } auto rsSurfaceNode = uiContent_->GetFormRootNode(); if (rsSurfaceNode == nullptr) { @@ -218,6 +220,7 @@ void FormRenderer::OnSurfaceReuse(const OHOS::AppExecFwk::FormJsInfo& formJsInfo newWant.SetParam(FORM_RENDERER_DISPATCHER, formRendererDispatcherImpl_->AsObject()); HILOG_INFO("Form OnSurfaceReuse."); formRendererDelegate_->OnSurfaceReuse(rsSurfaceNode->GetId(), formJsInfo, newWant); + formRendererDelegate_->OnFormLinkInfoUpdate(cachedInfos_); } void FormRenderer::OnActionEvent(const std::string& action) @@ -246,7 +249,7 @@ void FormRenderer::OnFormLinkInfoUpdate(const std::vector& formLink HILOG_ERROR("formRendererDelegate is null!"); return; } - + cachedInfos_ = formLinkInfos; formRendererDelegate_->OnFormLinkInfoUpdate(formLinkInfos); } diff --git a/test/mock/interfaces/mock_uicontent.h b/test/mock/interfaces/mock_uicontent.h index c6863a40768..6d3d7baaf2c 100644 --- a/test/mock/interfaces/mock_uicontent.h +++ b/test/mock/interfaces/mock_uicontent.h @@ -65,6 +65,7 @@ public: MOCK_METHOD0(GetFormHeight, float()); MOCK_METHOD2(OnFormSurfaceChange, void(float width, float height)); MOCK_METHOD1(SetActionEventHandler, void(std::function&& actionCallback)); + MOCK_METHOD1(SetFormLinkInfoUpdateHandler, void(std::function&)>&& callback)); MOCK_METHOD1(SetErrorEventHandler, void(std::function&& actionCallback)); MOCK_METHOD1(ReloadForm, void(const std::string& url)); -- Gitee