diff --git a/frameworks/bridge/declarative_frontend/jsview/js_form.cpp b/frameworks/bridge/declarative_frontend/jsview/js_form.cpp index 18a6a051dc5da409bdb71c37f2191f1cacac320d..5d4b7199c73de2426d6e458c6e98f7842bc05d86 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_form.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_form.cpp @@ -16,6 +16,9 @@ #include "frameworks/bridge/declarative_frontend/jsview/js_form.h" #include "base/geometry/dimension.h" +#include "base/geometry/ng/size_t.h" +#include "core/components_ng/base/view_abstract.h" +#include "core/components_ng/pattern/form/form_view.h" #include "frameworks/bridge/declarative_frontend/view_stack_processor.h" #if !defined(WEARABLE_PRODUCT) #include "frameworks/core/components/form/form_component.h" @@ -54,6 +57,11 @@ void JSForm::Create(const JSCallbackInfo& info) } fomInfo.temporary = temporary->ToBoolean(); + if (Container::IsCurrentUseNewPipeline()) { + NG::FormView::Create(fomInfo); + return; + } + RefPtr form = AceType::MakeRefPtr(); form->SetFormRequestInfo(fomInfo); form->SetInspectorTag("FormComponent"); @@ -64,6 +72,11 @@ void JSForm::Create(const JSCallbackInfo& info) void JSForm::SetSize(const JSCallbackInfo& info) { + if (Container::IsCurrentUseNewPipeline()) { + JSViewAbstract::JsSize(info); + return; + } + if (info.Length() == 0 || !info[0]->IsObject()) { LOGW("form set size fail due to FormComponent construct param is empty or type is not Object"); } @@ -96,6 +109,11 @@ void JSForm::SetSize(const JSCallbackInfo& info) void JSForm::SetDimension(int32_t value) { + if (Container::IsCurrentUseNewPipeline()) { + NG::FormView::SetDimension(value); + return; + } + auto form = AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetMainComponent()); if (form) { form->SetDimension(value); @@ -104,38 +122,74 @@ void JSForm::SetDimension(int32_t value) void JSForm::AllowUpdate(const JSCallbackInfo& info) { - if (info.Length() > 0 && info[0]->IsBoolean()) { - auto allowUpdate = info[0]->ToBoolean(); - auto form = AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetMainComponent()); - if (form) { - form->SetAllowUpdate(allowUpdate); - } + if (info.Length() <= 0 || !info[0]->IsBoolean()) { + LOGE("param is not valid"); + return; + } + + auto allowUpdate = info[0]->ToBoolean(); + if (Container::IsCurrentUseNewPipeline()) { + NG::FormView::SetAllowUpdate(allowUpdate); + return; + } + + auto form = AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetMainComponent()); + if (form) { + form->SetAllowUpdate(allowUpdate); } } void JSForm::SetVisibility(const JSCallbackInfo& info) { - if (info.Length() > 0 && info[0]->IsNumber()) { - auto type = info[0]->ToNumber(); - auto component = ViewStackProcessor::GetInstance()->GetDisplayComponent(); - auto display = AceType::DynamicCast(component); - display->SetVisible(VisibleType(type)); + if (info.Length() <= 0 || !info[0]->IsNumber()) { + LOGE("param is not valid"); + return; + } + + auto type = info[0]->ToNumber(); + if (Container::IsCurrentUseNewPipeline()) { + NG::ViewAbstract::SetVisibility(VisibleType(type)); + return; } + + auto component = ViewStackProcessor::GetInstance()->GetDisplayComponent(); + auto display = AceType::DynamicCast(component); + display->SetVisible(VisibleType(type)); } void JSForm::SetModuleName(const JSCallbackInfo& info) { - if (info.Length() > 0 && info[0]->IsString()) { - auto moduleName = info[0]->ToString(); - auto form = AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetMainComponent()); - if (form) { - form->SetModuleName(moduleName); - } + if (info.Length() <= 0 || !info[0]->IsString()) { + LOGE("param is not valid"); + return; + } + + auto moduleName = info[0]->ToString(); + if (Container::IsCurrentUseNewPipeline()) { + NG::FormView::SetModuleName(moduleName); + return; + } + + auto form = AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetMainComponent()); + if (form) { + form->SetModuleName(moduleName); } } void JSForm::JsOnAcquired(const JSCallbackInfo& info) { + if (Container::IsCurrentUseNewPipeline()) { + auto jsFunc = AceType::MakeRefPtr(JSRef(), JSRef::Cast(info[0])); + auto onAcquired = [execCtx = info.GetExecutionContext(), func = std::move(jsFunc)](const std::string& param) { + JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); + ACE_SCORING_EVENT("Form.onAcquired"); + std::vector keys = { "id" }; + func->Execute(keys, param); + }; + NG::FormView::SetOnAcquired(std::move(onAcquired)); + return; + } + if (info[0]->IsFunction()) { RefPtr jsFunc = AceType::MakeRefPtr(JSRef(), JSRef::Cast(info[0])); auto form = AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetMainComponent()); @@ -154,6 +208,18 @@ void JSForm::JsOnAcquired(const JSCallbackInfo& info) void JSForm::JsOnError(const JSCallbackInfo& info) { + if (Container::IsCurrentUseNewPipeline()) { + auto jsFunc = AceType::MakeRefPtr(JSRef(), JSRef::Cast(info[0])); + auto onError = [execCtx = info.GetExecutionContext(), func = std::move(jsFunc)](const std::string& param) { + JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); + ACE_SCORING_EVENT("Form.onError"); + std::vector keys = { "errcode", "msg" }; + func->Execute(keys, param); + }; + NG::FormView::SetOnError(std::move(onError)); + return; + } + if (info[0]->IsFunction()) { RefPtr jsFunc = AceType::MakeRefPtr(JSRef(), JSRef::Cast(info[0])); auto form = AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetMainComponent()); @@ -173,6 +239,18 @@ void JSForm::JsOnError(const JSCallbackInfo& info) void JSForm::JsOnUninstall(const JSCallbackInfo& info) { + if (Container::IsCurrentUseNewPipeline()) { + auto jsFunc = AceType::MakeRefPtr(JSRef(), JSRef::Cast(info[0])); + auto onUninstall = [execCtx = info.GetExecutionContext(), func = std::move(jsFunc)](const std::string& param) { + JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); + ACE_SCORING_EVENT("Form.onUninstall"); + std::vector keys = { "id" }; + func->Execute(keys, param); + }; + NG::FormView::SetOnUninstall(std::move(onUninstall)); + return; + } + if (info[0]->IsFunction()) { RefPtr jsFunc = AceType::MakeRefPtr(JSRef(), JSRef::Cast(info[0])); auto form = AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetMainComponent()); @@ -192,6 +270,18 @@ void JSForm::JsOnUninstall(const JSCallbackInfo& info) void JSForm::JsOnRouter(const JSCallbackInfo& info) { + if (Container::IsCurrentUseNewPipeline()) { + auto jsFunc = AceType::MakeRefPtr(JSRef(), JSRef::Cast(info[0])); + auto onRouter = [execCtx = info.GetExecutionContext(), func = std::move(jsFunc)](const std::string& param) { + JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); + ACE_SCORING_EVENT("Form.onRouter"); + std::vector keys = { "action" }; + func->Execute(keys, param); + }; + NG::FormView::SetOnRouter(std::move(onRouter)); + return; + } + if (info[0]->IsFunction()) { RefPtr jsFunc = AceType::MakeRefPtr(JSRef(), JSRef::Cast(info[0])); auto form = AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetMainComponent()); diff --git a/frameworks/core/BUILD.gn b/frameworks/core/BUILD.gn index 7e9305a41d67ebbfc2967d1ff1a19f600e239cef..5cc9b93dd2d3fe0ac99516371bb868d67434bd4a 100644 --- a/frameworks/core/BUILD.gn +++ b/frameworks/core/BUILD.gn @@ -399,7 +399,10 @@ template("ace_core_source_set") { config.form_components_support) { if (!use_mingw_win && !use_mac && !use_linux) { sources += [ "common/form_manager.cpp" ] - deps += [ "$ace_root/frameworks/core/components/form:ace_core_components_form_$platform" ] + deps += [ + "$ace_root/frameworks/core/components/form:ace_core_components_form_$platform", + "$ace_root/frameworks/core/components_ng/pattern/form:ace_core_components_form_pattern_ng_$platform", + ] external_deps = [ "form_fwk:form_manager" ] } } @@ -648,6 +651,12 @@ template("ace_core_ng_source_set") { config.web_components_support) { deps += [ "$ace_root/frameworks/core/components_ng/pattern/web:ace_core_components_web_pattern_ng_$platform" ] } + if (defined(config.form_components_support) && + config.form_components_support) { + if (!use_mingw_win && !use_mac && !use_linux) { + deps += [ "$ace_root/frameworks/core/components_ng/pattern/form:ace_core_components_form_pattern_ng_$platform" ] + } + } cflags_cc = [] cflags_cc += invoker.cflags_cc } diff --git a/frameworks/core/components/common/layout/constants.h b/frameworks/core/components/common/layout/constants.h index a98ae2ad279c8d7f2ba95d511967b9e07307ef05..b7d261a3b2c4134a4ae747de7e9dfc8d7b04e6c7 100644 --- a/frameworks/core/components/common/layout/constants.h +++ b/frameworks/core/components/common/layout/constants.h @@ -524,6 +524,12 @@ enum class CopyOptions { Distributed, }; +enum class VisibleType { + VISIBLE, + INVISIBLE, + GONE, +}; + inline constexpr uint32_t STATE_NORMAL = 0; inline constexpr uint32_t STATE_PRESSED = 1; inline constexpr uint32_t STATE_FOCUS = 1 << 1; diff --git a/frameworks/core/components/display/display_component.h b/frameworks/core/components/display/display_component.h index 232cde5625bb0d119f0786592fab461fbee7c295..d9652a5e0cd1b6dcad9a33b8ae0ae8e62143b88d 100644 --- a/frameworks/core/components/display/display_component.h +++ b/frameworks/core/components/display/display_component.h @@ -27,12 +27,6 @@ enum class DisplayStateAttribute { OPACITY, }; -enum class VisibleType { - VISIBLE, - INVISIBLE, - GONE, -}; - class ACE_EXPORT DisplayComponent : public SoleChildComponent { DECLARE_ACE_TYPE(DisplayComponent, SoleChildComponent); diff --git a/frameworks/core/components/form/form_window.h b/frameworks/core/components/form/form_window.h index 732838471b9e3999c325b2ed2bda7013845d3f0f..280dcea4cad27b5040ac63672522cee1e85e46ca 100644 --- a/frameworks/core/components/form/form_window.h +++ b/frameworks/core/components/form/form_window.h @@ -28,7 +28,7 @@ namespace OHOS::Ace { class ACE_EXPORT FormWindow : public Window { public: - explicit FormWindow(WeakPtr context) : Window(nullptr), outSidePipelineContext_(context) {} + explicit FormWindow(const WeakPtr& context) : Window(nullptr), outSidePipelineContext_(context) {} ~FormWindow() = default; void RequestFrame() override; @@ -42,7 +42,7 @@ public: void SetVsyncCallback(AceVsyncCallback&& callback) override; private: - WeakPtr outSidePipelineContext_; + WeakPtr outSidePipelineContext_; ACE_DISALLOW_COPY_AND_MOVE(FormWindow); }; diff --git a/frameworks/core/components/form/render_form.cpp b/frameworks/core/components/form/render_form.cpp index e27c09e6f04ae90ba618a41419d29ae1227a17be..b47b8490b27773a5c5d6ea1c585ba0ef0f495a27 100644 --- a/frameworks/core/components/form/render_form.cpp +++ b/frameworks/core/components/form/render_form.cpp @@ -63,7 +63,7 @@ bool RenderForm::TouchTest(const Point& globalPoint, if (!InTouchRectList(transformPoint, GetTouchRectList())) { return false; } - auto subContext = GetSubPipelineContext(); + auto subContext = DynamicCast(GetSubPipelineContext()); if (!subContext) { LOGE("subContext is null"); return false; @@ -72,7 +72,7 @@ bool RenderForm::TouchTest(const Point& globalPoint, auto context = GetContext().Upgrade(); if (context) { - context->SetTouchPipeline(WeakPtr(subContext)); + context->SetTouchPipeline(WeakPtr(subContext)); } return true; } diff --git a/frameworks/core/components/form/render_form.h b/frameworks/core/components/form/render_form.h index 71ee5bd100e36480cfa6e81505c095caa4bd3aef..e17e12ba88601770f9264382c0795af4f96c8695 100644 --- a/frameworks/core/components/form/render_form.h +++ b/frameworks/core/components/form/render_form.h @@ -47,7 +47,7 @@ public: subContainer_ = container; } - RefPtr GetSubPipelineContext() override + RefPtr GetSubPipelineContext() override { auto context = subContainer_.Upgrade(); if (context) { diff --git a/frameworks/core/components/form/resource/form_manager_delegate.cpp b/frameworks/core/components/form/resource/form_manager_delegate.cpp index 944305a5df79e06f103a0474c9aba0c51c00b528..e8b2b1347b059973210a43d70f9d42266b7b4ee5 100644 --- a/frameworks/core/components/form/resource/form_manager_delegate.cpp +++ b/frameworks/core/components/form/resource/form_manager_delegate.cpp @@ -82,7 +82,7 @@ void FormManagerDelegate::Stop() void FormManagerDelegate::UnregisterEvent() { - auto context = context_.Upgrade(); + auto context = DynamicCast(context_.Upgrade()); if (!context) { LOGE("fail to get context when unregister event"); return; @@ -93,7 +93,7 @@ void FormManagerDelegate::UnregisterEvent() resRegister->UnregisterEvent(MakeEventHash(FORM_EVENT_ON_ERROR)); } -void FormManagerDelegate::AddForm(const WeakPtr& context, const RequestFormInfo& info) +void FormManagerDelegate::AddForm(const WeakPtr& context, const RequestFormInfo& info) { #ifdef OHOS_STANDARD_SYSTEM // dynamic add new form should release the running form first. @@ -163,12 +163,12 @@ std::string FormManagerDelegate::ConvertRequestInfo(const RequestFormInfo& info) return paramStream.str(); } -void FormManagerDelegate::CreatePlatformResource(const WeakPtr& context, const RequestFormInfo& info) +void FormManagerDelegate::CreatePlatformResource(const WeakPtr& context, const RequestFormInfo& info) { context_ = context; state_ = State::CREATING; - auto pipelineContext = context.Upgrade(); + auto pipelineContext = DynamicCast(context_.Upgrade()); if (!pipelineContext) { state_ = State::CREATEFAILED; OnFormError("internal error"); @@ -219,7 +219,7 @@ void FormManagerDelegate::CreatePlatformResource(const WeakPtr& void FormManagerDelegate::RegisterEvent() { - auto context = context_.Upgrade(); + auto context = DynamicCast(context_.Upgrade()); if (!context) { LOGE("register event error due null context, will not receive form manager event"); return; diff --git a/frameworks/core/components/form/resource/form_manager_delegate.h b/frameworks/core/components/form/resource/form_manager_delegate.h index 97b62b819d96024fc719be2a2136fd7eebaf0ec8..8363d8a5fe99487b7903f0664c4db941e8805bfc 100644 --- a/frameworks/core/components/form/resource/form_manager_delegate.h +++ b/frameworks/core/components/form/resource/form_manager_delegate.h @@ -21,6 +21,7 @@ #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" +#include "core/pipeline/pipeline_base.h" #ifdef OHOS_STANDARD_SYSTEM #include "form_js_info.h" @@ -33,18 +34,17 @@ class FormManagerDelegate : public FormManagerResource { DECLARE_ACE_TYPE(FormManagerDelegate, FormManagerResource); public: - using onFormAcquiredCallbackForJava - = std::function; + using onFormAcquiredCallbackForJava = + std::function; using OnFormUpdateCallbackForJava = std::function; - using OnFormAcquiredCallback - = std::function>&, const AppExecFwk::FormJsInfo&)>; - using OnFormUpdateCallback = std::function>&)>; + using OnFormAcquiredCallback = std::function>&, const AppExecFwk::FormJsInfo&)>; + using OnFormUpdateCallback = + std::function>&)>; using OnFormErrorCallback = std::function; using OnFormUninstallCallback = std::function; - enum class State: char { + enum class State : char { WAITINGFORSIZE, CREATING, CREATED, @@ -54,11 +54,11 @@ public: FormManagerDelegate() = delete; ~FormManagerDelegate() override; - explicit FormManagerDelegate(const WeakPtr& context) - : FormManagerResource("formAdaptor", context), - state_(State::WAITINGFORSIZE) {} + explicit FormManagerDelegate(const WeakPtr& context) + : FormManagerResource("formAdaptor", context), state_(State::WAITINGFORSIZE) + {} - void AddForm(const WeakPtr& context, const RequestFormInfo& info); + void AddForm(const WeakPtr& context, const RequestFormInfo& info); void ReleasePlatformResource(); void AddFormAcquireCallback(const OnFormAcquiredCallback& callback); @@ -68,13 +68,13 @@ public: void OnActionEvent(const std::string& action); #ifdef OHOS_STANDARD_SYSTEM - void ProcessFormUpdate(const AppExecFwk::FormJsInfo &formJsInfo); + void ProcessFormUpdate(const AppExecFwk::FormJsInfo& formJsInfo); void ProcessFormUninstall(const int64_t formId); void OnDeathReceived(); #endif private: - void CreatePlatformResource(const WeakPtr& context, const RequestFormInfo& info); + void CreatePlatformResource(const WeakPtr& context, const RequestFormInfo& info); void Stop(); void RegisterEvent(); void UnregisterEvent(); @@ -83,7 +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); + bool ParseAction(const std::string& action, AAFwk::Want& want); onFormAcquiredCallbackForJava onFormAcquiredCallbackForJava_; OnFormUpdateCallbackForJava onFormUpdateCallbackForJava_; diff --git a/frameworks/core/components/form/resource/form_manager_resource.cpp b/frameworks/core/components/form/resource/form_manager_resource.cpp index 8013ebc047e2e41c943d86f888797cddd533793d..137ad577c738508953f0c075339890a6323c6498 100644 --- a/frameworks/core/components/form/resource/form_manager_resource.cpp +++ b/frameworks/core/components/form/resource/form_manager_resource.cpp @@ -32,15 +32,14 @@ const char FORM_MANAGER_RESULT_FAIL[] = "fail"; void FormManagerResource::Release(const std::function& onRelease) { - auto context = context_.Upgrade(); + auto context = DynamicCast(context_.Upgrade()); if (!context) { LOGE("fail to release resource due to context is null"); return; } auto resRegister = context->GetPlatformResRegister(); - auto platformTaskExecutor = SingleTaskExecutor::Make(context->GetTaskExecutor(), - TaskExecutor::TaskType::PLATFORM); + auto platformTaskExecutor = SingleTaskExecutor::Make(context->GetTaskExecutor(), TaskExecutor::TaskType::PLATFORM); auto weakRes = AceType::WeakClaim(AceType::RawPtr(resRegister)); auto releaseTask = [weak = WeakClaim(this), weakRes, onRelease] { auto resource = weak.Upgrade(); @@ -74,7 +73,7 @@ void FormManagerResource::CallResRegisterMethod( return; } - auto context = context_.Upgrade(); + auto context = DynamicCast(context_.Upgrade()); if (!context) { LOGE("fail to get context to call res register method"); return; diff --git a/frameworks/core/components/form/resource/form_manager_resource.h b/frameworks/core/components/form/resource/form_manager_resource.h index 779296a8d57023a91167d3a14fcf6a2a86d0bd35..82085d22bed27c057c349ec1591df8ca0a0caa63 100644 --- a/frameworks/core/components/form/resource/form_manager_resource.h +++ b/frameworks/core/components/form/resource/form_manager_resource.h @@ -42,15 +42,14 @@ public: using ErrorCallback = std::function; using Method = std::string; - FormManagerResource(const std::string& type, const WeakPtr& context) - : type_(type), context_(context) + FormManagerResource(const std::string& type, const WeakPtr& context) : type_(type), context_(context) {} virtual ~FormManagerResource() = default; void Release(const std::function& onRelease = nullptr); - void CallResRegisterMethod(const Method& method, const std::string& param, - const std::function& callback = nullptr); + void CallResRegisterMethod( + const Method& method, const std::string& param, const std::function& callback = nullptr); int64_t GetId() const { @@ -79,7 +78,7 @@ protected: int64_t id_ = INVALID_ID; std::string hash_; std::string type_; - WeakPtr context_; + WeakPtr context_; }; } // namespace OHOS::Ace diff --git a/frameworks/core/components/form/resource/form_request_data.h b/frameworks/core/components/form/resource/form_request_data.h index a24bec8d93c9ffe7cda2713d28bab66636e654f8..4ed9e31ea5413c2a3b39d1799bf1bf4093b99fda 100644 --- a/frameworks/core/components/form/resource/form_request_data.h +++ b/frameworks/core/components/form/resource/form_request_data.h @@ -16,8 +16,12 @@ #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_FORM_RESOURCE_FORM_REQUEST_DATA_H #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_FORM_RESOURCE_FORM_REQUEST_DATA_H +#include #include +#include "base/geometry/dimension.h" +#include "base/utils/utils.h" + namespace OHOS::Ace { struct RequestFormInfo { @@ -39,6 +43,15 @@ struct RequestFormInfo { paramStream << bundleName << abilityName << moduleName << cardName << dimension << index << temporary; return paramStream.str(); } + + bool operator==(const RequestFormInfo& formInfo) const + { + return id == formInfo.id && cardName == formInfo.cardName && bundleName == formInfo.bundleName && + abilityName == formInfo.abilityName && moduleName == formInfo.moduleName && + temporary == formInfo.temporary && dimension == formInfo.dimension && + allowUpdate == formInfo.allowUpdate && width == formInfo.width && height == formInfo.height && + index == formInfo.index; + } }; } // namespace OHOS::Ace diff --git a/frameworks/core/components/form/sub_container.cpp b/frameworks/core/components/form/sub_container.cpp index 05d3b438bc7b586ae351190394c666cad1b94e9b..51f41d090f951a43915aba900db093d0b0a74a63 100644 --- a/frameworks/core/components/form/sub_container.cpp +++ b/frameworks/core/components/form/sub_container.cpp @@ -13,13 +13,16 @@ * limitations under the License. */ -#include "core/common/container_scope.h" #include "core/components/form/sub_container.h" #include #include "ashmem.h" + #include "adapter/ohos/entrance/file_asset_provider.h" +#include "base/utils/utils.h" +#include "core/common/container_scope.h" +#include "core/components_ng/pattern/form/form_layout_property.h" #include "frameworks/core/common/flutter/flutter_asset_manager.h" #include "frameworks/core/common/flutter/flutter_task_executor.h" #include "frameworks/core/components/form/form_element.h" @@ -72,7 +75,7 @@ void SubContainer::Destroy() auto outPipelineContext = outSidePipelineContext_.Upgrade(); if (outPipelineContext) { - outPipelineContext->RemoveTouchPipeline(WeakPtr(pipelineContext_)); + outPipelineContext->RemoveTouchPipeline(WeakPtr(pipelineContext_)); } assetManager_.Reset(); @@ -81,12 +84,24 @@ void SubContainer::Destroy() void SubContainer::UpdateRootElementSize() { - auto formComponent = AceType::DynamicCast(formComponent_); Dimension rootWidth = 0.0_vp; Dimension rootHeight = 0.0_vp; - if (formComponent) { - rootWidth = formComponent->GetWidth(); - rootHeight = formComponent->GetHeight(); + if (Container::IsCurrentUseNewPipeline()) { + auto form = formPattern_.Upgrade(); + CHECK_NULL_VOID(form); + auto layoutProperty = form->GetLayoutProperty(); + CHECK_NULL_VOID(layoutProperty); + auto formInfo = layoutProperty->GetRequestFormInfo(); + if (formInfo.has_value()) { + rootWidth = formInfo->width; + rootHeight = formInfo->height; + } + } else { + auto formComponent = AceType::DynamicCast(formComponent_); + if (formComponent) { + rootWidth = formComponent->GetWidth(); + rootHeight = formComponent->GetHeight(); + } } if (rootWidht_ == rootWidth && rootHeight_ == rootHeight) { @@ -97,7 +112,8 @@ void SubContainer::UpdateRootElementSize() surfaceWidth_ = outSidePipelineContext_.Upgrade()->NormalizeToPx(rootWidth); surfaceHeight_ = outSidePipelineContext_.Upgrade()->NormalizeToPx(rootHeight); if (pipelineContext_) { - pipelineContext_->SetRootSize(density_, rootWidth.Value(), rootHeight.Value()); + pipelineContext_->SetRootSize( + density_, static_cast(rootWidth.Value()), static_cast(rootHeight.Value())); } } @@ -124,8 +140,8 @@ void SubContainer::UpdateSurfaceSize() TaskExecutor::TaskType::UI); } -void SubContainer::RunCard(const int64_t id, const std::string path, const std::string module, const std::string data, - const std::map> imageDataMap, const std::string formSrc) +void SubContainer::RunCard(int64_t id, const std::string& path, const std::string& module, const std::string& data, + const std::map>& imageDataMap, const std::string& formSrc) { if (id == runningCardId_) { LOGE("the card is showing, no need run again"); @@ -206,22 +222,21 @@ void SubContainer::RunCard(const int64_t id, const std::string path, const std:: auto&& actionEventHandler = [weak = WeakClaim(this)](const std::string& action) { auto container = weak.Upgrade(); - if (!container) { - LOGE("ActionEventHandler sub container is null!"); - return; - } - auto form = AceType::DynamicCast(container->GetFormElement().Upgrade()); - if (!form) { - LOGE("ActionEventHandler form is null!"); - return; + CHECK_NULL_VOID(container); + + if (Container::IsCurrentUseNewPipeline()) { + auto form = container->GetFormPattern(); + CHECK_NULL_VOID(form); + form->OnActionEvent(action); + } else { + auto form = AceType::DynamicCast(container->GetFormElement().Upgrade()); + CHECK_NULL_VOID(form); + form->OnActionEvent(action); } - - form->OnActionEvent(action); }; pipelineContext_->SetActionEventHandler(actionEventHandler); auto weakContext = AceType::WeakClaim(AceType::RawPtr(pipelineContext_)); - taskExecutor_->PostTask( [weakContext]() { auto context = weakContext.Upgrade(); @@ -241,6 +256,14 @@ void SubContainer::RunCard(const int64_t id, const std::string path, const std:: UpdateSurfaceSize(); } + if (Container::IsCurrentUseNewPipeline()) { + auto pattern = formPattern_.Upgrade(); + CHECK_NULL_VOID(pattern); + pipelineContext_->SetDrawDelegate(pattern->GetDrawDelegate()); + frontend_->RunPage(0, "", data); + return; + } + auto form = AceType::DynamicCast(GetFormElement().Upgrade()); if (!form) { LOGE("set draw delegate could not get form element"); @@ -283,7 +306,7 @@ void SubContainer::GetNamesOfSharedImage(std::vector& picNameArray) LOGE("picNameArray is null!"); return; } - auto pipelineCtx = GetPipelineContext(); + auto pipelineCtx = DynamicCast(GetPipelineContext()); if (!pipelineCtx) { LOGE("pipeline context is null!"); return; @@ -291,7 +314,7 @@ void SubContainer::GetNamesOfSharedImage(std::vector& picNameArray) RefPtr sharedImageManager; if (!pipelineCtx->GetSharedImageManager()) { sharedImageManager = AceType::MakeRefPtr(pipelineCtx->GetTaskExecutor()); - GetPipelineContext()->SetSharedImageManager(sharedImageManager); + pipelineCtx->SetSharedImageManager(sharedImageManager); } else { sharedImageManager = pipelineCtx->GetSharedImageManager(); } @@ -351,7 +374,7 @@ void SubContainer::UpdateSharedImage( } void SubContainer::GetImageDataFromAshmem( - const std::string& picName, Ashmem& ashmem, const RefPtr& pipelineContext, int len) + const std::string& picName, Ashmem& ashmem, const RefPtr& pipelineContext, int len) { bool ret = ashmem.MapReadOnlyAshmem(); // if any exception causes a [return] before [AddSharedImage], the memory image will not show because [RenderImage] @@ -368,15 +391,17 @@ void SubContainer::GetImageDataFromAshmem( strerror(errno), picName.c_str(), len, ashmem.GetAshmemFd()); return; } - RefPtr sharedImageManager = pipelineContext->GetSharedImageManager(); + auto context = DynamicCast(pipelineContext); + CHECK_NULL_VOID(context); + RefPtr sharedImageManager = context->GetSharedImageManager(); if (sharedImageManager) { // read image data from shared memory and save a copy to sharedImageManager sharedImageManager->AddSharedImage(picName, std::vector(imageData, imageData + len)); } } -void SubContainer::UpdateCard(const std::string content, - const std::map> imageDataMap) +void SubContainer::UpdateCard( + const std::string& content, const std::map>& imageDataMap) { if (!frontend_) { LOGE("update card fial due to could not find card front end"); diff --git a/frameworks/core/components/form/sub_container.h b/frameworks/core/components/form/sub_container.h index 69eecd1c70e024d34a8e65ae4ef74adfe082a044..616768e62bde073a426924b61c212fc61f0c0abd 100644 --- a/frameworks/core/components/form/sub_container.h +++ b/frameworks/core/components/form/sub_container.h @@ -18,8 +18,10 @@ #include "ashmem.h" #include "form_ashmem.h" + #include "base/thread/task_executor.h" #include "core/common/frontend.h" +#include "core/components_ng/pattern/form/form_pattern.h" #include "frameworks/bridge/card_frontend/card_frontend.h" #include "frameworks/core/pipeline/pipeline_context.h" @@ -30,22 +32,23 @@ class ACE_EXPORT SubContainer : public virtual AceType { public: using OnFormAcquiredCallback = std::function; - explicit SubContainer(const WeakPtr& context) : outSidePipelineContext_(context) {} - SubContainer(const WeakPtr& context, int32_t instanceId) + explicit SubContainer(const WeakPtr& context) : outSidePipelineContext_(context) {} + SubContainer(const WeakPtr& context, int32_t instanceId) : outSidePipelineContext_(context), instanceId_(instanceId) {} ~SubContainer() = default; void Initialize(); - void RunCard(const int64_t id, const std::string path, const std::string module, const std::string data, - std::map> imageDataMap, const std::string formSrc); - void UpdateCard(const std::string content, std::map> imageDataMap); + void RunCard(int64_t id, const std::string& path, const std::string& module, const std::string& data, + const std::map>& imageDataMap, const std::string& formSrc); + void UpdateCard( + const std::string& content, const std::map>& imageDataMap); void Destroy(); void GetNamesOfSharedImage(std::vector& picNameArray); void UpdateSharedImage(std::vector& picNameArray, std::vector& byteLenArray, std::vector& fileDescriptorArray); void GetImageDataFromAshmem( - const std::string& picName, Ashmem& ashmem, const RefPtr& pipelineContext, int len); + const std::string& picName, Ashmem& ashmem, const RefPtr& pipelineContext, int len); void ProcessSharedImage(const std::map> imageDataMap); void SetFormElement(const WeakPtr& element) @@ -68,7 +71,7 @@ public: return taskExecutor_; } - RefPtr GetPipelineContext() const + RefPtr GetPipelineContext() const { return pipelineContext_; } @@ -104,11 +107,21 @@ public: cardWindowConfig_ = cardWindowConfig; } + void SetFormPattern(const WeakPtr& formPattern) + { + formPattern_ = formPattern; + } + + RefPtr GetFormPattern() const + { + return formPattern_.Upgrade(); + } + private: RefPtr frontend_; RefPtr taskExecutor_; RefPtr pipelineContext_; - WeakPtr outSidePipelineContext_; + WeakPtr outSidePipelineContext_; RefPtr assetManager_; int32_t instanceId_; @@ -125,6 +138,9 @@ private: Dimension rootWidht_ = 0.0_vp; Dimension rootHeight_ = 0.0_vp; double density_ = 1.0f; + + // Use for NG. + WeakPtr formPattern_; }; } // namespace OHOS::Ace diff --git a/frameworks/core/components/plugin/flutter_render_plugin.cpp b/frameworks/core/components/plugin/flutter_render_plugin.cpp index 185a3854ede146ee102681d80cee7da6f9388ff9..a007dec4258fd7a1179f4b6bc47d1455545d93d1 100644 --- a/frameworks/core/components/plugin/flutter_render_plugin.cpp +++ b/frameworks/core/components/plugin/flutter_render_plugin.cpp @@ -52,7 +52,7 @@ void FlutterRenderPlugin::NotifyPaintFinish() { auto context = GetContext().Upgrade(); if (context) { - auto pluginContext = GetSubPipelineContext(); + auto pluginContext = DynamicCast(GetSubPipelineContext()); if (pluginContext) { layer_->SetOffset(pluginContext->GetPluginOffset().GetX(), pluginContext->GetPluginOffset().GetY()); } diff --git a/frameworks/core/components/plugin/render_plugin.cpp b/frameworks/core/components/plugin/render_plugin.cpp index 264c18cea6960489f534fb0ece5fa1b30153dfca..a5d5dfae1ff63bebe3e7a79305fbbbe6672c8cd1 100644 --- a/frameworks/core/components/plugin/render_plugin.cpp +++ b/frameworks/core/components/plugin/render_plugin.cpp @@ -67,7 +67,7 @@ bool RenderPlugin::TouchTest(const Point& globalPoint, if (!InTouchRectList(transformPoint, GetTouchRectList())) { return false; } - auto subContext = GetSubPipelineContext(); + auto subContext = DynamicCast(GetSubPipelineContext()); if (!subContext) { LOGE("subContext is null"); return false; @@ -76,7 +76,7 @@ bool RenderPlugin::TouchTest(const Point& globalPoint, auto context = GetContext().Upgrade(); if (context) { - context->SetTouchPipeline(WeakPtr(subContext)); + context->SetTouchPipeline(WeakPtr(subContext)); } return true; } diff --git a/frameworks/core/components/plugin/render_plugin.h b/frameworks/core/components/plugin/render_plugin.h index 11e5a61fb3fd8ef7960ae8ccfcb2c37bb3b584b3..62478224adb64e9e7bc3e089bac81f206211b31f 100644 --- a/frameworks/core/components/plugin/render_plugin.h +++ b/frameworks/core/components/plugin/render_plugin.h @@ -43,7 +43,7 @@ public: pluginContainer_ = container; } - RefPtr GetSubPipelineContext() override + RefPtr GetSubPipelineContext() override { auto context = pluginContainer_.Upgrade(); if (context) { diff --git a/frameworks/core/components_ng/base/frame_node.cpp b/frameworks/core/components_ng/base/frame_node.cpp index 94c1c120ec875caf485ba3bc7edca34cbaf4392f..d1bcf6925a425b602776f7541ea2a8f788f58a4b 100644 --- a/frameworks/core/components_ng/base/frame_node.cpp +++ b/frameworks/core/components_ng/base/frame_node.cpp @@ -18,6 +18,7 @@ #include #include "base/geometry/ng/point_t.h" +#include "base/geometry/ng/size_t.h" #include "base/log/ace_trace.h" #include "base/log/dump_log.h" #include "base/memory/ace_type.h" @@ -25,6 +26,7 @@ #include "base/thread/cancelable_callback.h" #include "base/thread/task_executor.h" #include "base/utils/utils.h" +#include "core/components/common/layout/constants.h" #include "core/components_ng/base/ui_node.h" #include "core/components_ng/event/gesture_event_hub.h" #include "core/components_ng/layout/layout_algorithm.h" @@ -49,6 +51,7 @@ FrameNode::FrameNode(const std::string& tag, int32_t nodeId, const RefPtrCreateEventHub(); // first create make layout property dirty. layoutProperty_->UpdatePropertyChangeFlag(PROPERTY_UPDATE_MEASURE); + layoutProperty_->SetHost(WeakClaim(this)); } FrameNode::~FrameNode() @@ -291,15 +294,15 @@ LayoutConstraintF FrameNode::GetLayoutConstraint() const if (geometryNode_->GetParentLayoutConstraint().has_value()) { return geometryNode_->GetParentLayoutConstraint().value(); } - LayoutConstraintF LayoutConstraint; - LayoutConstraint.scaleProperty = ScaleProperty::CreateScaleProperty(); + LayoutConstraintF layoutConstraint; + layoutConstraint.scaleProperty = ScaleProperty::CreateScaleProperty(); auto rootWidth = PipelineContext::GetCurrentRootWidth(); auto rootHeight = PipelineContext::GetCurrentRootHeight(); - LayoutConstraint.percentReference.SetWidth(rootWidth); - LayoutConstraint.percentReference.SetHeight(rootHeight); - LayoutConstraint.maxSize.SetHeight(rootWidth); - LayoutConstraint.maxSize.SetHeight(rootHeight); - return LayoutConstraint; + layoutConstraint.percentReference.SetWidth(rootWidth); + layoutConstraint.percentReference.SetHeight(rootHeight); + layoutConstraint.maxSize.SetHeight(rootWidth); + layoutConstraint.maxSize.SetHeight(rootHeight); + return layoutConstraint; } OffsetF FrameNode::GetParentGlobalOffset() const @@ -334,6 +337,12 @@ void FrameNode::AdjustParentLayoutFlag(PropertyChangeFlag& flag) RefPtr FrameNode::CreateLayoutWrapper(bool forceMeasure, bool forceLayout) { + if (layoutProperty_->GetVisibility().value_or(VisibleType::VISIBLE) == VisibleType::GONE) { + auto layoutWrapper = MakeRefPtr(WeakClaim(this), MakeRefPtr(), MakeRefPtr()); + layoutWrapper->SetLayoutAlgorithm(MakeRefPtr(nullptr, true, true)); + return layoutWrapper; + } + pattern_->BeforeCreateLayoutWrapper(); isLayoutDirtyMarked_ = false; auto flag = layoutProperty_->GetPropertyChangeFlag(); @@ -476,7 +485,7 @@ void FrameNode::MarkDirtyNode(bool isMeasureBoundary, bool isRenderBoundary, Pro void FrameNode::OnGenerateOneDepthVisibleFrame(std::list>& visibleList) { - if (isActive_) { + if (isActive_ && IsVisible()) { visibleList.emplace_back(Claim(this)); } } diff --git a/frameworks/core/components_ng/base/frame_node.h b/frameworks/core/components_ng/base/frame_node.h index 8a0d530a43f120288f2f364dc1877d4d95315f1a..a5b037f1f8c5f9d9e61923752dd0442b0ab06657 100644 --- a/frameworks/core/components_ng/base/frame_node.h +++ b/frameworks/core/components_ng/base/frame_node.h @@ -25,6 +25,7 @@ #include "base/thread/cancelable_callback.h" #include "base/thread/task_executor.h" #include "base/utils/macros.h" +#include "core/components/common/layout/constants.h" #include "core/components_ng/base/geometry_node.h" #include "core/components_ng/base/ui_node.h" #include "core/components_ng/event/event_hub.h" @@ -188,9 +189,14 @@ public: void RebuildRenderContextTree() override; -private: + bool IsVisible() const + { + return layoutProperty_->GetVisibility().value_or(VisibleType::VISIBLE) == VisibleType::VISIBLE; + } + RefPtr GetAncestorNodeOfFrame() const; +private: void UpdateLayoutPropertyFlag() override; void AdjustParentLayoutFlag(PropertyChangeFlag& flag) override; diff --git a/frameworks/core/components_ng/base/view_abstract.cpp b/frameworks/core/components_ng/base/view_abstract.cpp index 0a013412561869d472f472e1f89b49eee2049fc5..65ca4dd0b4beecbeb2be55a3f6b76cdf0f916a95 100644 --- a/frameworks/core/components_ng/base/view_abstract.cpp +++ b/frameworks/core/components_ng/base/view_abstract.cpp @@ -215,6 +215,11 @@ void ViewAbstract::SetAlign(Alignment alignment) ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, Alignment, alignment); } +void ViewAbstract::SetVisibility(VisibleType visible) +{ + ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, Visibility, visible); +} + void ViewAbstract::SetOpacity(double opacity) { ACE_UPDATE_RENDER_CONTEXT(Opacity, opacity); diff --git a/frameworks/core/components_ng/base/view_abstract.h b/frameworks/core/components_ng/base/view_abstract.h index 0ae859667a9a2af1867d5eef5e68d24bfabf3434..996c3d2dc9b04eb1e878ba1d59ab5f9f7b89c189 100644 --- a/frameworks/core/components_ng/base/view_abstract.h +++ b/frameworks/core/components_ng/base/view_abstract.h @@ -23,6 +23,7 @@ #include "base/geometry/ng/vector.h" #include "base/memory/referenced.h" #include "core/common/container.h" +#include "core/components/common/layout/constants.h" #include "core/components/common/properties/alignment.h" #include "core/components_ng/property/border_property.h" #include "core/components_ng/property/calc_length.h" @@ -53,6 +54,7 @@ public: // layout static void SetAlign(Alignment alignment); + static void SetVisibility(VisibleType visible); // transform static void SetScale(NG::VectorF scale); diff --git a/frameworks/core/components_ng/layout/layout_property.cpp b/frameworks/core/components_ng/layout/layout_property.cpp index 21dc355ceb2e027b599f30e9317b04597ac45efa..3ba9826798ef87d066fa62740c934486a3dd9648 100644 --- a/frameworks/core/components_ng/layout/layout_property.cpp +++ b/frameworks/core/components_ng/layout/layout_property.cpp @@ -17,6 +17,7 @@ #include "base/geometry/ng/size_t.h" #include "base/utils/utils.h" +#include "core/components_ng/base/frame_node.h" #include "core/components_ng/base/ui_node.h" #include "core/components_ng/property/calc_length.h" #include "core/components_ng/property/layout_constraint.h" @@ -208,4 +209,25 @@ PaddingPropertyF LayoutProperty::CreatePaddingWithoutBorder() return ConvertToPaddingPropertyF( padding_, ScaleProperty::CreateScaleProperty(), PipelineContext::GetCurrentRootWidth()); } + +void LayoutProperty::SetHost(const WeakPtr& host) +{ + host_ = host; +} + +RefPtr LayoutProperty::GetHost() const +{ + return host_.Upgrade(); +} + +void LayoutProperty::OnVisibilityUpdate(VisibleType /* visible */) const +{ + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto parent = host->GetAncestorNodeOfFrame(); + CHECK_NULL_VOID(parent); + parent->MarkNeedSyncRenderTree(); + parent->MarkDirtyNode(PROPERTY_UPDATE_MEASURE); +} + } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/layout/layout_property.h b/frameworks/core/components_ng/layout/layout_property.h index f995f67cba5a5665a6a4c304825d487bf0d31f2a..34c618a7248e0cb41669e616f2cf51f7d6abca5c 100644 --- a/frameworks/core/components_ng/layout/layout_property.h +++ b/frameworks/core/components_ng/layout/layout_property.h @@ -25,6 +25,7 @@ #include "base/utils/macros.h" #include "base/utils/noncopyable.h" #include "base/utils/utils.h" +#include "core/components/common/layout/constants.h" #include "core/components_ng/property/border_property.h" #include "core/components_ng/property/flex_property.h" #include "core/components_ng/property/geometry_property.h" @@ -33,8 +34,12 @@ #include "core/components_ng/property/measure_property.h" #include "core/components_ng/property/position_property.h" #include "core/components_ng/property/property.h" +#include "core/pipeline_ng/ui_task_scheduler.h" namespace OHOS::Ace::NG { + +class FrameNode; + class ACE_EXPORT LayoutProperty : public Property { DECLARE_ACE_TYPE(LayoutProperty, Property); @@ -226,6 +231,12 @@ public: PaddingPropertyF CreatePaddingWithoutBorder(); PaddingPropertyF CreatePaddingAndBorder(); + void SetHost(const WeakPtr& host); + RefPtr GetHost() const; + + ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP_AND_USING_CALLBACK(Visibility, VisibleType, PROPERTY_UPDATE_MEASURE); + void OnVisibilityUpdate(VisibleType visible) const; + protected: void UpdateLayoutProperty(const LayoutProperty* layoutProperty); @@ -246,6 +257,7 @@ private: std::unique_ptr flexItemProperty_; std::optional measureType_; + WeakPtr host_; ACE_DISALLOW_COPY_AND_MOVE(LayoutProperty); }; } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/layout/layout_wrapper.cpp b/frameworks/core/components_ng/layout/layout_wrapper.cpp index 6f26ef4e79cb8fbb0c2d308c675f2b1a17c66a7b..e1e3414d9c0859208a130e65d07643a82371edfa 100644 --- a/frameworks/core/components_ng/layout/layout_wrapper.cpp +++ b/frameworks/core/components_ng/layout/layout_wrapper.cpp @@ -17,6 +17,7 @@ #include "base/log/ace_trace.h" #include "base/utils/utils.h" +#include "core/components/common/layout/constants.h" #include "core/components_ng/base/frame_node.h" #include "core/components_ng/layout/layout_wrapper_builder.h" #include "core/components_ng/property/layout_constraint.h" diff --git a/frameworks/core/components_ng/pattern/form/BUILD.gn b/frameworks/core/components_ng/pattern/form/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..cd6a95921657ba7058772b62c91835fe27870ee6 --- /dev/null +++ b/frameworks/core/components_ng/pattern/form/BUILD.gn @@ -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. + +import( + "//foundation/arkui/ace_engine/frameworks/core/components_ng/components.gni") + +build_component_ng("form_pattern_ng") { + sources = [ + "form_node.cpp", + "form_pattern.cpp", + "form_view.cpp", + ] + + if (is_standard_system) { + deps = [ "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client" ] + external_deps = [ + "ability_base:want", + "ability_runtime:app_manager", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "form_fwk:fmskit_native", + "form_fwk:form_manager", + "ipc:ipc_core", + ] + } +} diff --git a/frameworks/core/components_ng/pattern/form/form_event_hub.h b/frameworks/core/components_ng/pattern/form/form_event_hub.h new file mode 100644 index 0000000000000000000000000000000000000000..e93b812a1a3b021c63af10419d781ccaad9c5f6a --- /dev/null +++ b/frameworks/core/components_ng/pattern/form/form_event_hub.h @@ -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. + */ + +#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_FORM_EVENT_HUB_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_FORM_EVENT_HUB_H + +#include + +#include "base/memory/ace_type.h" +#include "core/components_ng/event/event_hub.h" + +namespace OHOS::Ace::NG { + +using FormCallback = std::function; + +class FormEventHub : public EventHub { + DECLARE_ACE_TYPE(FormEventHub, EventHub) + +public: + FormEventHub() = default; + ~FormEventHub() override = default; + + void SetOnAcquired(FormCallback&& onAcquired) + { + onAcquired_ = std::move(onAcquired); + } + + void SetOnError(FormCallback&& onError) + { + onError_ = std::move(onError); + } + + void SetOnUninstall(FormCallback&& onUninstall) + { + onUninstall_ = std::move(onUninstall); + } + + void SetOnRouter(FormCallback&& onRouter) + { + onRouter_ = std::move(onRouter); + } + + void FireOnAcquired(const std::string& param) const + { + if (onAcquired_) { + onAcquired_(param); + } + } + + void FireOnError(const std::string& param) const + { + if (onError_) { + onError_(param); + } + } + + void FireOnUninstall(const std::string& param) const + { + if (onUninstall_) { + onUninstall_(param); + } + } + + void FireOnRouter(const std::string& param) const + { + if (onRouter_) { + onRouter_(param); + } + } + +private: + FormCallback onAcquired_; + FormCallback onError_; + FormCallback onUninstall_; + FormCallback onRouter_; +}; + +} // namespace OHOS::Ace::NG +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_FORM_EVENT_HUB_H \ No newline at end of file diff --git a/frameworks/core/components_ng/pattern/form/form_layout_property.h b/frameworks/core/components_ng/pattern/form/form_layout_property.h new file mode 100644 index 0000000000000000000000000000000000000000..5a167a1b226744a93cdd1cebbb812f677d7a8c83 --- /dev/null +++ b/frameworks/core/components_ng/pattern/form/form_layout_property.h @@ -0,0 +1,53 @@ +/* + * 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_NG_PATTERN_FORM_FORM_LAYOUT_PROPERTY_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_FORM_LAYOUT_PROPERTY_H + +#include "base/geometry/axis.h" +#include "base/utils/macros.h" +#include "core/components/common/layout/constants.h" +#include "core/components/form/resource/form_request_data.h" +#include "core/components_ng/layout/layout_property.h" +#include "core/components_ng/property/property.h" + +namespace OHOS::Ace::NG { + +class ACE_EXPORT FormLayoutProperty : public LayoutProperty { + DECLARE_ACE_TYPE(FormLayoutProperty, LayoutProperty); + +public: + FormLayoutProperty() = default; + ~FormLayoutProperty() override = default; + + RefPtr Clone() const override + { + auto value = MakeRefPtr(); + value->LayoutProperty::UpdateLayoutProperty(DynamicCast(this)); + value->propRequestFormInfo_ = CloneRequestFormInfo(); + return value; + } + + void Reset() override + { + LayoutProperty::Reset(); + ResetRequestFormInfo(); + } + + ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(RequestFormInfo, RequestFormInfo, PROPERTY_UPDATE_MEASURE); +}; + +} // namespace OHOS::Ace::NG +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_FORM_LAYOUT_PROPERTY_H diff --git a/frameworks/core/components_ng/pattern/form/form_node.cpp b/frameworks/core/components_ng/pattern/form/form_node.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7c50aed388387e19b02044cc55f33f1f609cedee --- /dev/null +++ b/frameworks/core/components_ng/pattern/form/form_node.cpp @@ -0,0 +1,72 @@ +/* + * 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_ng/pattern/form/form_node.h" + +#include "base/utils/utils.h" +#include "core/components/form/sub_container.h" +#include "core/components_ng/pattern/form/form_pattern.h" +#include "core/pipeline/pipeline_context.h" +#include "core/pipeline_ng/pipeline_context.h" + +namespace OHOS::Ace::NG { + +HitTestResult FormNode::TouchTest(const PointF& globalPoint, const PointF& parentLocalPoint, + const TouchRestrict& touchRestrict, TouchTestResult& result) +{ + const auto& rect = GetGeometryNode()->GetFrame().GetRect(); + if (!rect.IsInRegion(parentLocalPoint)) { + return HitTestResult::OUT_OF_REGION; + } + auto pattern = GetPattern(); + CHECK_NULL_RETURN(pattern, HitTestResult::BUBBLING); + auto subContainer = pattern->GetSubContainer(); + CHECK_NULL_RETURN(subContainer, HitTestResult::BUBBLING); + auto subContext = DynamicCast(subContainer->GetPipelineContext()); + CHECK_NULL_RETURN(subContext, HitTestResult::BUBBLING); + auto selfGlobalOffset = GetGeometryNode()->GetParentGlobalOffset() + GetGeometryNode()->GetFrameOffset(); + subContext->SetPluginEventOffset(Offset(selfGlobalOffset.GetX(), selfGlobalOffset.GetY())); + + auto context = GetContext(); + if (context) { + context->SetTouchPipeline(WeakPtr(subContext)); + } + + return HitTestResult::STOP_BUBBLING; +} + +RefPtr FormNode::GetOrCreateFormNode( + const std::string& tag, int32_t nodeId, const std::function(void)>& patternCreator) +{ + auto formNode = ElementRegister::GetInstance()->GetSpecificItemById(nodeId); + if (formNode) { + if (formNode->GetTag() == tag) { + return formNode; + } + ElementRegister::GetInstance()->RemoveItemSilently(nodeId); + auto parent = formNode->GetParent(); + if (parent) { + parent->RemoveChild(formNode); + } + } + + auto pattern = patternCreator ? patternCreator() : AceType::MakeRefPtr(); + formNode = AceType::MakeRefPtr(tag, nodeId, pattern, false); + formNode->InitializePatternAndContext(); + ElementRegister::GetInstance()->AddUINode(formNode); + return formNode; +} + +} // namespace OHOS::Ace::NG \ No newline at end of file diff --git a/frameworks/core/components_ng/pattern/form/form_node.h b/frameworks/core/components_ng/pattern/form/form_node.h new file mode 100644 index 0000000000000000000000000000000000000000..deb9fc713f5a9cf907d27db007cacd626b30156a --- /dev/null +++ b/frameworks/core/components_ng/pattern/form/form_node.h @@ -0,0 +1,42 @@ +/* + * 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_NG_PATTERN_FORM_FORM_NODE_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_FORM_NODE_H + +#include + +#include "core/components_ng/base/frame_node.h" + +namespace OHOS::Ace::NG { + +class ACE_EXPORT FormNode : public FrameNode { + DECLARE_ACE_TYPE(FormNode, FrameNode); + +public: + FormNode(const std::string& tag, int32_t nodeId, const RefPtr& pattern, bool isRoot = false) + : FrameNode(tag, nodeId, pattern, isRoot) + {} + ~FormNode() override = default; + + HitTestResult TouchTest(const PointF& globalPoint, const PointF& parentLocalPoint, + const TouchRestrict& touchRestrict, TouchTestResult& result) override; + + static RefPtr GetOrCreateFormNode( + const std::string& tag, int32_t nodeId, const std::function(void)>& patternCreator); +}; + +} // namespace OHOS::Ace::NG +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_FORM_NODE_H \ No newline at end of file diff --git a/frameworks/core/components_ng/pattern/form/form_pattern.cpp b/frameworks/core/components_ng/pattern/form/form_pattern.cpp new file mode 100644 index 0000000000000000000000000000000000000000..13fa6f8b0c6ab719ea2263ce7640220b9050a3ba --- /dev/null +++ b/frameworks/core/components_ng/pattern/form/form_pattern.cpp @@ -0,0 +1,332 @@ +/* + * 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_ng/pattern/form/form_pattern.h" + +#include "base/geometry/dimension.h" +#include "base/utils/utils.h" +#include "core/common/form_manager.h" +#include "core/components/form/resource/form_manager_delegate.h" +#include "core/components/form/sub_container.h" +#include "core/components_ng/pattern/form/form_event_hub.h" +#include "core/components_ng/pattern/form/form_layout_property.h" +#include "core/components_ng/property/property.h" +#include "core/components_ng/render/adapter/rosen_render_context.h" +#include "core/pipeline_ng/pipeline_context.h" + +namespace OHOS::Ace::NG { + +FormPattern::FormPattern() = default; +FormPattern::~FormPattern() = default; + +void FormPattern::OnAttachToFrameNode() +{ + auto host = GetHost(); + CHECK_NULL_VOID(host); + host->GetRenderContext()->SetClipToFrame(true); + InitFormManagerDelegate(); +} + +bool FormPattern::OnDirtyLayoutWrapperSwap(const RefPtr& dirty, const DirtySwapConfig& config) +{ + if (config.skipMeasure && config.skipLayout) { + return false; + } + + auto size = dirty->GetGeometryNode()->GetFrameSize(); + auto host = GetHost(); + CHECK_NULL_RETURN(host, false); + auto layoutProperty = host->GetLayoutProperty(); + CHECK_NULL_RETURN(layoutProperty, false); + auto info = layoutProperty->GetRequestFormInfo().value_or(RequestFormInfo()); + info.width = Dimension(size.Width()); + info.height = Dimension(size.Height()); + layoutProperty->UpdateRequestFormInfo(info); + + if (info.bundleName != cardInfo_.bundleName || info.abilityName != cardInfo_.abilityName || + info.moduleName != cardInfo_.moduleName || info.cardName != cardInfo_.cardName || + info.dimension != cardInfo_.dimension) { + cardInfo_ = info; + } else { + // for update form component + if (cardInfo_.allowUpdate != info.allowUpdate) { + cardInfo_.allowUpdate = info.allowUpdate; + LOGI(" update card allow info:%{public}d", cardInfo_.allowUpdate); + if (subContainer_) { + subContainer_->SetAllowUpdate(cardInfo_.allowUpdate); + } + } + + if (cardInfo_.width != info.width || cardInfo_.height != info.height) { + cardInfo_.width = info.width; + cardInfo_.height = info.height; + subContainer_->SetFormPattern(WeakClaim(this)); + subContainer_->UpdateRootElementSize(); + subContainer_->UpdateSurfaceSize(); + } + return false; + } + CreateCardContainer(); + if (formManagerBridge_) { + formManagerBridge_->AddForm(host->GetContext(), info); + } + return false; +} + +void FormPattern::InitFormManagerDelegate() +{ + if (formManagerBridge_) { + LOGD("Form manager bridge is already initialized."); + return; + } + + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto context = host->GetContext(); + CHECK_NULL_VOID(context); + formManagerBridge_ = AceType::MakeRefPtr(context); + int32_t instanceID = context->GetInstanceId(); + formManagerBridge_->AddFormAcquireCallback([weak = WeakClaim(this), instanceID](int64_t id, const std::string& path, + const std::string& module, const std::string& data, + const std::map>& + imageDataMap, + const AppExecFwk::FormJsInfo& formJsInfo) { + ContainerScope scope(instanceID); + auto form = weak.Upgrade(); + CHECK_NULL_VOID(form); + auto host = form->GetHost(); + CHECK_NULL_VOID(host); + auto uiTaskExecutor = + SingleTaskExecutor::Make(host->GetContext()->GetTaskExecutor(), TaskExecutor::TaskType::UI); + uiTaskExecutor.PostTask([id, path, module, data, imageDataMap, formJsInfo, weak, instanceID] { + ContainerScope scope(instanceID); + auto form = weak.Upgrade(); + CHECK_NULL_VOID(form); + auto container = form->GetSubContainer(); + CHECK_NULL_VOID(container); + container->SetWindowConfig({ formJsInfo.formWindow.designWidth, formJsInfo.formWindow.autoDesignWidth }); + container->RunCard(id, path, module, data, imageDataMap, formJsInfo.formSrc); + }); + }); + + formManagerBridge_->AddFormUpdateCallback( + [weak = WeakClaim(this), instanceID](int64_t id, const std::string& data, + const std::map>& imageDataMap) { + ContainerScope scope(instanceID); + auto form = weak.Upgrade(); + CHECK_NULL_VOID(form); + auto host = form->GetHost(); + CHECK_NULL_VOID(host); + auto uiTaskExecutor = + SingleTaskExecutor::Make(host->GetContext()->GetTaskExecutor(), TaskExecutor::TaskType::UI); + uiTaskExecutor.PostTask([id, data, imageDataMap, weak, instanceID] { + ContainerScope scope(instanceID); + auto form = weak.Upgrade(); + CHECK_NULL_VOID(form); + if (form->ISAllowUpdate()) { + form->GetSubContainer()->UpdateCard(data, imageDataMap); + } + }); + }); + + formManagerBridge_->AddFormErrorCallback( + [weak = WeakClaim(this), instanceID](const std::string& code, const std::string& msg) { + ContainerScope scope(instanceID); + auto form = weak.Upgrade(); + CHECK_NULL_VOID(form); + auto host = form->GetHost(); + CHECK_NULL_VOID(host); + auto uiTaskExecutor = + SingleTaskExecutor::Make(host->GetContext()->GetTaskExecutor(), TaskExecutor::TaskType::UI); + uiTaskExecutor.PostTask([code, msg, weak, instanceID] { + ContainerScope scope(instanceID); + auto form = weak.Upgrade(); + CHECK_NULL_VOID(form); + form->FireOnErrorEvent(code, msg); + }); + }); + + formManagerBridge_->AddFormUninstallCallback([weak = WeakClaim(this), instanceID](int64_t formId) { + ContainerScope scope(instanceID); + auto form = weak.Upgrade(); + CHECK_NULL_VOID(form); + auto host = form->GetHost(); + CHECK_NULL_VOID(host); + auto uiTaskExecutor = + SingleTaskExecutor::Make(host->GetContext()->GetTaskExecutor(), TaskExecutor::TaskType::UI); + uiTaskExecutor.PostTask([formId, weak, instanceID] { + ContainerScope scope(instanceID); + auto form = weak.Upgrade(); + CHECK_NULL_VOID(form); + form->FireOnUninstallEvent(formId); + }); + }); +} + +void FormPattern::CreateCardContainer() +{ + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto context = host->GetContext(); + CHECK_NULL_VOID(context); + auto layoutProperty = host->GetLayoutProperty(); + CHECK_NULL_VOID(layoutProperty); + + if (subContainer_) { + auto id = subContainer_->GetRunningCardId(); + FormManager::GetInstance().RemoveSubContainer(id); + subContainer_->Destroy(); + subContainer_.Reset(); + } + + subContainer_ = AceType::MakeRefPtr(context, context->GetInstanceId()); + CHECK_NULL_VOID(subContainer_); + subContainer_->Initialize(); + subContainer_->SetFormPattern(WeakClaim(this)); + auto info = layoutProperty->GetRequestFormInfo().value_or(RequestFormInfo()); + auto key = info.ToString(); + FormManager::GetInstance().AddNonmatchedContainer(key, subContainer_); + + subContainer_->AddFormAcquireCallback([weak = WeakClaim(this)](size_t id) { + auto pattern = weak.Upgrade(); + CHECK_NULL_VOID(pattern); + auto host = pattern->GetHost(); + CHECK_NULL_VOID(host); + auto uiTaskExecutor = + SingleTaskExecutor::Make(host->GetContext()->GetTaskExecutor(), TaskExecutor::TaskType::UI); + uiTaskExecutor.PostTask([id, weak] { + auto pattern = weak.Upgrade(); + if (pattern) { + LOGI("card id:%{public}zu", id); + pattern->FireOnAcquiredEvent(id); + } + }); + }); +} + +std::unique_ptr FormPattern::GetDrawDelegate() +{ + auto drawDelegate = std::make_unique(); + drawDelegate->SetDrawRSFrameCallback( + [weak = WeakClaim(this)](std::shared_ptr& node, const Rect& /* dirty */) { + auto form = weak.Upgrade(); + CHECK_NULL_VOID(form); + auto host = form->GetHost(); + CHECK_NULL_VOID(host); + auto context = DynamicCast(host->GetRenderContext()); + CHECK_NULL_VOID(context); + auto rsNode = context->GetRSNode(); + CHECK_NULL_VOID(rsNode); + rsNode->AddChild(node, -1); + host->MarkDirtyNode(PROPERTY_UPDATE_LAYOUT); + }); + return drawDelegate; +} + +void FormPattern::FireOnErrorEvent(const std::string& code, const std::string& msg) const +{ + LOGI("FireOnErrorEvent code: %{public}s, msg: %{public}s", code.c_str(), msg.c_str()); + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto eventHub = host->GetEventHub(); + CHECK_NULL_VOID(eventHub); + auto json = JsonUtil::Create(true); + json->Put("errcode", code.c_str()); + json->Put("msg", msg.c_str()); + eventHub->FireOnError(json->ToString()); +} + +void FormPattern::FireOnUninstallEvent(int64_t id) const +{ + LOGI("FireOnUninstallEvent id: %{public}lld", id); + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto eventHub = host->GetEventHub(); + CHECK_NULL_VOID(eventHub); + auto json = JsonUtil::Create(true); + json->Put("id", std::to_string(id).c_str()); + eventHub->FireOnUninstall(json->ToString()); +} + +void FormPattern::FireOnAcquiredEvent(int64_t id) const +{ + LOGI("FireOnAcquiredEvent id: %{public}lld", id); + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto eventHub = host->GetEventHub(); + CHECK_NULL_VOID(eventHub); + auto json = JsonUtil::Create(true); + json->Put("id", std::to_string(id).c_str()); + eventHub->FireOnAcquired(json->ToString()); +} + +void FormPattern::FireOnRouterEvent(const std::unique_ptr& action) const +{ + LOGI("FireOnAcquiredEvent action: %{public}s", action->ToString().c_str()); + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto eventHub = host->GetEventHub(); + CHECK_NULL_VOID(eventHub); + auto json = JsonUtil::Create(true); + json->Put("action", action); + eventHub->FireOnRouter(json->ToString()); +} + +void FormPattern::OnActionEvent(const std::string& action) const +{ + LOGI("OnActionEvent action: %{public}s", action.c_str()); + auto eventAction = JsonUtil::ParseJsonString(action); + if (!eventAction->IsValid()) { + LOGE("get event action failed"); + return; + } + auto actionType = eventAction->GetValue("action"); + if (!actionType->IsValid()) { + LOGE("get event key failed"); + return; + } + + auto type = actionType->GetString(); + if (type != "router" && type != "message") { + LOGE("undefined event type"); + return; + } + + if ("router" == type) { + FireOnRouterEvent(eventAction); + } + + if (formManagerBridge_) { + formManagerBridge_->OnActionEvent(action); + } +} + +bool FormPattern::ISAllowUpdate() const +{ + auto host = GetHost(); + CHECK_NULL_RETURN(host, true); + auto property = host->GetLayoutProperty(); + CHECK_NULL_RETURN(property, true); + auto formInfo = property->GetRequestFormInfo(); + CHECK_NULL_RETURN(property, true); + return formInfo->allowUpdate; +} + +const RefPtr& FormPattern::GetSubContainer() const +{ + return subContainer_; +} + +} // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/form/form_pattern.h b/frameworks/core/components_ng/pattern/form/form_pattern.h new file mode 100644 index 0000000000000000000000000000000000000000..6c67bf57b7b85cf6754addaab76fccf22331bfa9 --- /dev/null +++ b/frameworks/core/components_ng/pattern/form/form_pattern.h @@ -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. + */ + +#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_FORM_PATTERN_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_FORM_PATTERN_H + +#include "core/components/form/resource/form_request_data.h" +#include "core/components_ng/event/event_hub.h" +#include "core/components_ng/pattern/form/form_event_hub.h" +#include "core/components_ng/pattern/form/form_layout_property.h" +#include "core/components_ng/pattern/pattern.h" + +namespace OHOS::Ace { +class SubContainer; +class FormManagerDelegate; +} // namespace OHOS::Ace + +namespace OHOS::Ace::NG { + +class FormPattern : public Pattern { + DECLARE_ACE_TYPE(FormPattern, Pattern); + +public: + FormPattern(); + ~FormPattern() override; + + void OnActionEvent(const std::string& action) const; + + RefPtr CreateLayoutProperty() override + { + return MakeRefPtr(); + } + + RefPtr CreateEventHub() override + { + return MakeRefPtr(); + } + + std::unique_ptr GetDrawDelegate(); + + const RefPtr& GetSubContainer() const; + +private: + void OnAttachToFrameNode() override; + bool OnDirtyLayoutWrapperSwap(const RefPtr& dirty, const DirtySwapConfig& config) override; + + void InitFormManagerDelegate(); + void CreateCardContainer(); + + void FireOnAcquiredEvent(int64_t id) const; + void FireOnRouterEvent(const std::unique_ptr& action) const; + void FireOnErrorEvent(const std::string& code, const std::string& msg) const; + void FireOnUninstallEvent(int64_t id) const; + + bool ISAllowUpdate() const; + + RefPtr subContainer_; + RefPtr formManagerBridge_; + + RequestFormInfo cardInfo_; +}; + +} // namespace OHOS::Ace::NG + +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_FORM_PATTERN_H diff --git a/frameworks/core/components_ng/pattern/form/form_view.cpp b/frameworks/core/components_ng/pattern/form/form_view.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e67df7aabc51de0a60dbef22bf431a0213b72205 --- /dev/null +++ b/frameworks/core/components_ng/pattern/form/form_view.cpp @@ -0,0 +1,123 @@ +/* + * 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_ng/pattern/form/form_view.h" + +#include + +#include "base/geometry/dimension.h" +#include "base/utils/utils.h" +#include "core/components_ng/base/frame_node.h" +#include "core/components_ng/base/view_stack_processor.h" +#include "core/components_ng/pattern/form/form_layout_property.h" +#include "core/components_ng/pattern/form/form_pattern.h" +#include "core/components_v2/inspector/inspector_constants.h" + +namespace OHOS::Ace::NG { + +void FormView::Create(const RequestFormInfo& formInfo) +{ + auto* stack = ViewStackProcessor::GetInstance(); + auto frameNode = FormNode::GetOrCreateFormNode( + V2::FORM_ETS_TAG, stack->ClaimNodeId(), []() { return AceType::MakeRefPtr(); }); + stack->Push(frameNode); + + ACE_UPDATE_LAYOUT_PROPERTY(FormLayoutProperty, RequestFormInfo, formInfo); +} + +void FormView::SetDimension(int32_t dimension) +{ + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + auto property = frameNode->GetLayoutProperty(); + CHECK_NULL_VOID(property); + if (!property->HasRequestFormInfo()) { + return; + } + auto formInfo = property->GetRequestFormInfoValue(); + formInfo.dimension = dimension; + property->UpdateRequestFormInfo(formInfo); +} + +void FormView::SetAllowUpdate(bool allowUpdate) +{ + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + auto property = frameNode->GetLayoutProperty(); + CHECK_NULL_VOID(property); + if (!property->HasRequestFormInfo()) { + return; + } + auto formInfo = property->GetRequestFormInfoValue(); + formInfo.allowUpdate = allowUpdate; + property->UpdateRequestFormInfo(formInfo); +} + +void FormView::SetVisible(VisibleType visible) +{ + ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, Visibility, visible); +} + +void FormView::SetModuleName(const std::string& moduleName) +{ + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + auto property = frameNode->GetLayoutProperty(); + CHECK_NULL_VOID(property); + if (!property->HasRequestFormInfo()) { + return; + } + auto formInfo = property->GetRequestFormInfoValue(); + formInfo.moduleName = moduleName; + property->UpdateRequestFormInfo(formInfo); +} + +void FormView::SetOnAcquired(FormCallback&& onAcquired) +{ + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + auto eventHub = frameNode->GetEventHub(); + CHECK_NULL_VOID(eventHub); + eventHub->SetOnAcquired(std::move(onAcquired)); +} + +void FormView::SetOnError(FormCallback&& onOnError) +{ + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + auto eventHub = frameNode->GetEventHub(); + CHECK_NULL_VOID(eventHub); + eventHub->SetOnError(std::move(onOnError)); +} + +void FormView::SetOnUninstall(FormCallback&& onUninstall) +{ + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + auto eventHub = frameNode->GetEventHub(); + CHECK_NULL_VOID(eventHub); + eventHub->SetOnUninstall(std::move(onUninstall)); +} + +void FormView::SetOnRouter(FormCallback&& onRouter) +{ + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + auto eventHub = frameNode->GetEventHub(); + CHECK_NULL_VOID(eventHub); + eventHub->SetOnRouter(std::move(onRouter)); +} + +} // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/form/form_view.h b/frameworks/core/components_ng/pattern/form/form_view.h new file mode 100644 index 0000000000000000000000000000000000000000..a882e4839f684e9c918763f773098b6f105a24c0 --- /dev/null +++ b/frameworks/core/components_ng/pattern/form/form_view.h @@ -0,0 +1,44 @@ +/* + * 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_NG_PATTERN_FORM_FORM_VIEW_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_FORM_VIEW_H + +#include "base/geometry/dimension.h" +#include "base/geometry/ng/size_t.h" +#include "base/memory/referenced.h" +#include "base/utils/macros.h" +#include "core/components/common/layout/constants.h" +#include "core/components/form/resource/form_request_data.h" +#include "core/components_ng/pattern/form/form_event_hub.h" +#include "core/components_ng/pattern/form/form_node.h" + +namespace OHOS::Ace::NG { + +class ACE_EXPORT FormView { +public: + static void Create(const RequestFormInfo& formInfo); + static void SetDimension(int32_t dimension); + static void SetAllowUpdate(bool allowUpdate); + static void SetVisible(VisibleType visible); + static void SetModuleName(const std::string& moduleName); + static void SetOnAcquired(FormCallback&& onAcquired); + static void SetOnError(FormCallback&& onError); + static void SetOnUninstall(FormCallback&& onUninstall); + static void SetOnRouter(FormCallback&& onRouter); +}; + +} // namespace OHOS::Ace::NG +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_FORM_VIEW_H diff --git a/frameworks/core/pipeline/base/flutter_render_context.cpp b/frameworks/core/pipeline/base/flutter_render_context.cpp index df6baaf7496a5b6f5a63c0a3c2e1a6415aaa0046..8ae247ea0b7bb57b53edc0ac1f455701697cee3a 100644 --- a/frameworks/core/pipeline/base/flutter_render_context.cpp +++ b/frameworks/core/pipeline/base/flutter_render_context.cpp @@ -136,7 +136,7 @@ void FlutterRenderContext::SetOffSet( if (!renderPlugin) { return; } - auto pluginContext = renderPlugin->GetSubPipelineContext(); + auto pluginContext = DynamicCast(renderPlugin->GetSubPipelineContext()); if (!pluginContext) { return; } diff --git a/frameworks/core/pipeline/base/render_sub_container.h b/frameworks/core/pipeline/base/render_sub_container.h index 8ead969407ab456e36772308afef0a74b352f59e..9436e77eec5670510fad16272fa307edc0b8c445 100644 --- a/frameworks/core/pipeline/base/render_sub_container.h +++ b/frameworks/core/pipeline/base/render_sub_container.h @@ -26,7 +26,7 @@ class RenderSubContainer : public RenderNode { public: RenderSubContainer() : RenderNode(false) {} - virtual RefPtr GetSubPipelineContext() = 0; + virtual RefPtr GetSubPipelineContext() = 0; }; } // namespace OHOS::Ace diff --git a/frameworks/core/pipeline/base/rosen_render_context.cpp b/frameworks/core/pipeline/base/rosen_render_context.cpp index 05a1f5a2c60a26aaf88eaf3b8b379c8f67b4a3ac..9e69ef65a3fa62dcd58f0cd7eeee61ddefbb6e99 100644 --- a/frameworks/core/pipeline/base/rosen_render_context.cpp +++ b/frameworks/core/pipeline/base/rosen_render_context.cpp @@ -104,7 +104,7 @@ void RosenRenderContext::PaintChild(const RefPtr& child, const Offse if (!renderPlugin) { return; } - auto pluginContext = renderPlugin->GetSubPipelineContext(); + auto pluginContext = DynamicCast(renderPlugin->GetSubPipelineContext()); if (!pluginContext) { return; } diff --git a/frameworks/core/pipeline/pipeline_base.cpp b/frameworks/core/pipeline/pipeline_base.cpp index 202fdce94f9ac64428bdb0f2a0bb62ce55e24604..30ac1f5bd3f709b64b0e62922f17e38560f516c4 100644 --- a/frameworks/core/pipeline/pipeline_base.cpp +++ b/frameworks/core/pipeline/pipeline_base.cpp @@ -458,4 +458,20 @@ bool PipelineBase::CloseImplicitAnimation() #endif } +void PipelineBase::SetTouchPipeline(const WeakPtr& context) +{ + auto result = std::find(touchPluginPipelineContext_.begin(), touchPluginPipelineContext_.end(), context); + if (result == touchPluginPipelineContext_.end()) { + touchPluginPipelineContext_.emplace_back(context); + } +} + +void PipelineBase::RemoveTouchPipeline(const WeakPtr& context) +{ + auto result = std::find(touchPluginPipelineContext_.begin(), touchPluginPipelineContext_.end(), context); + if (result != touchPluginPipelineContext_.end()) { + touchPluginPipelineContext_.erase(result); + } +} + } // namespace OHOS::Ace diff --git a/frameworks/core/pipeline/pipeline_base.h b/frameworks/core/pipeline/pipeline_base.h index e291b3e7d3f40d8bb5c971fb92ba3f9956537f78..bd5bf681fba7d16b255e61b61f78622adce76a96 100644 --- a/frameworks/core/pipeline/pipeline_base.h +++ b/frameworks/core/pipeline/pipeline_base.h @@ -25,9 +25,11 @@ #include "base/geometry/dimension.h" #include "base/resource/asset_manager.h" #include "base/resource/data_provider_manager.h" +#include "base/resource/shared_image_manager.h" #include "base/thread/task_executor.h" #include "core/accessibility/accessibility_manager.h" #include "core/animation/schedule_task.h" +#include "core/common/draw_delegate.h" #include "core/common/event_manager.h" #include "core/common/platform_bridge.h" #include "core/common/window_animation_config.h" @@ -482,6 +484,14 @@ public: virtual void FlushReloadTransition() {} + double GetDensity() const + { + return density_; + } + + void SetTouchPipeline(const WeakPtr& context); + void RemoveTouchPipeline(const WeakPtr& context); + protected: virtual bool OnDumpInfo(const std::vector& params) const { @@ -527,6 +537,8 @@ protected: StartAbilityHandler startAbilityHandler_; ActionEventHandler actionEventHandler_; + std::vector> touchPluginPipelineContext_; + private: StatusBarEventHandler statusBarBgColorEventHandler_; PopupEventHandler popupEventHandler_; diff --git a/frameworks/core/pipeline/pipeline_context.cpp b/frameworks/core/pipeline/pipeline_context.cpp index 60ac286cacca51a30d167e26f4b90f25f544be19..ab532ef688e6ac901dc48e1b5a854607c4a7b723 100644 --- a/frameworks/core/pipeline/pipeline_context.cpp +++ b/frameworks/core/pipeline/pipeline_context.cpp @@ -15,8 +15,8 @@ #include "core/pipeline/pipeline_context.h" -#include #include +#include #include "base/memory/ace_type.h" #include "base/memory/referenced.h" @@ -1099,7 +1099,7 @@ void PipelineContext::PushPage(const RefPtr& pageComponent, const { ACE_FUNCTION_TRACE(); CHECK_RUN_ON(UI); - std::unordered_map params {{"pageUrl", pageComponent->GetPageUrl()}}; + std::unordered_map params { { "pageUrl", pageComponent->GetPageUrl() } }; ResSchedReportScope report("push_page", params); auto stageElement = stage; if (!stageElement) { @@ -1613,7 +1613,7 @@ void PipelineContext::OnTouchEvent(const TouchEvent& point, bool isSubPipe) scalePoint, rootElement_->GetRenderNode(), touchRestrict, GetPluginEventOffset(), viewScale_, isSubPipe); for (size_t i = 0; i < touchPluginPipelineContext_.size(); i++) { - auto pipelineContext = touchPluginPipelineContext_[i].Upgrade(); + auto pipelineContext = DynamicCast(touchPluginPipelineContext_[i].Upgrade()); if (!pipelineContext || !pipelineContext->rootElement_) { continue; } @@ -3586,22 +3586,6 @@ bool PipelineContext::IsVisibleChangeNodeExists(NodeId index) const return accessibilityManager->IsVisibleChangeNodeExists(index); } -void PipelineContext::SetTouchPipeline(WeakPtr context) -{ - auto result = std::find(touchPluginPipelineContext_.begin(), touchPluginPipelineContext_.end(), context); - if (result == touchPluginPipelineContext_.end()) { - touchPluginPipelineContext_.emplace_back(context); - } -} - -void PipelineContext::RemoveTouchPipeline(WeakPtr context) -{ - auto result = std::find(touchPluginPipelineContext_.begin(), touchPluginPipelineContext_.end(), context); - if (result != touchPluginPipelineContext_.end()) { - touchPluginPipelineContext_.erase(result); - } -} - void PipelineContext::SetRSUIDirector(std::shared_ptr rsUIDirector) { #ifdef ENABLE_ROSEN_BACKEND diff --git a/frameworks/core/pipeline/pipeline_context.h b/frameworks/core/pipeline/pipeline_context.h index 233cca74614f0b84e57e50b3a309cdc68440ff7a..17f3073e9b98822637d295bf7e27a523365497d7 100644 --- a/frameworks/core/pipeline/pipeline_context.h +++ b/frameworks/core/pipeline/pipeline_context.h @@ -31,14 +31,12 @@ #include "base/memory/ace_type.h" #include "base/resource/asset_manager.h" #include "base/resource/data_provider_manager.h" -#include "base/resource/shared_image_manager.h" #include "base/thread/task_executor.h" #include "base/utils/macros.h" #include "base/utils/noncopyable.h" #include "core/animation/flush_event.h" #include "core/animation/page_transition_listener.h" #include "core/animation/schedule_task.h" -#include "core/common/draw_delegate.h" #include "core/common/event_manager.h" #include "core/common/focus_animation_manager.h" #include "core/common/platform_res_register.h" @@ -737,11 +735,6 @@ public: contextMenu_ = contextMenu; } - double GetDensity() const - { - return density_; - } - void SetClipHole(double left, double top, double width, double height); const Rect& GetTransparentHole() const @@ -794,9 +787,6 @@ public: return pluginEventOffset_; } - void SetTouchPipeline(WeakPtr context); - void RemoveTouchPipeline(WeakPtr context); - void SetRSUIDirector(std::shared_ptr rsUIDirector); std::shared_ptr GetRSUIDirector(); @@ -1254,7 +1244,6 @@ private: SurfaceChangedCallbackMap surfaceChangedCallbackMap_; SurfacePositionChangedCallbackMap surfacePositionChangedCallbackMap_; - std::vector> touchPluginPipelineContext_; Offset pluginOffset_ { 0, 0 }; Offset pluginEventOffset_ { 0, 0 }; diff --git a/frameworks/core/pipeline_ng/pipeline_context.cpp b/frameworks/core/pipeline_ng/pipeline_context.cpp index d3aff598e09da37aef77262c93f48316350d2e4b..c0ed77ba9800cd3738dfc8e2a4b1cbe93befc92d 100644 --- a/frameworks/core/pipeline_ng/pipeline_context.cpp +++ b/frameworks/core/pipeline_ng/pipeline_context.cpp @@ -37,6 +37,7 @@ #include "core/components_ng/property/calc_length.h" #include "core/components_ng/property/layout_constraint.h" #include "core/components_v2/inspector/inspector_constants.h" +#include "core/pipeline/pipeline_context.h" #include "core/pipeline_ng/ui_task_scheduler.h" namespace OHOS::Ace::NG { @@ -275,6 +276,21 @@ void PipelineContext::OnTouchEvent(const TouchEvent& point, bool isSubPipe) TouchRestrict touchRestrict { TouchRestrict::NONE }; touchRestrict.sourceType = point.sourceType; eventManager_->TouchTest(scalePoint, rootNode_, touchRestrict, false); + + for (const auto& weakContext : touchPluginPipelineContext_) { + auto pipelineContext = DynamicCast(weakContext.Upgrade()); + if (!pipelineContext) { + continue; + } + auto pluginPoint = + point.UpdateScalePoint(viewScale_, static_cast(pipelineContext->GetPluginEventOffset().GetX()), + static_cast(pipelineContext->GetPluginEventOffset().GetY()), point.id); + auto eventManager = pipelineContext->GetEventManager(); + if (eventManager) { + eventManager->SetInstanceId(pipelineContext->GetInstanceId()); + } + pipelineContext->OnTouchEvent(pluginPoint, true); + } } if (scalePoint.type == TouchType::MOVE) {