From 4dd8c084e62b7aa01644f7b2cf2019f88bfcda43 Mon Sep 17 00:00:00 2001 From: caocan Date: Tue, 13 Sep 2022 20:50:59 +0800 Subject: [PATCH 1/4] =?UTF-8?q?[UI=E7=BB=84=E4=BB=B6=E9=87=8D=E6=9E=84]For?= =?UTF-8?q?m=E7=BB=84=E4=BB=B6=E5=AF=B9=E6=8E=A5=E6=96=B0=E6=A1=86?= =?UTF-8?q?=E6=9E=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: caocan Change-Id: I208e683f7bd33ca6d64573c5ca8d7c79ba800e2f --- .../declarative_frontend/jsview/js_form.cpp | 135 ++++++++++++++--- .../core/components/common/layout/constants.h | 6 + .../components/display/display_component.h | 6 - .../form/resource/form_request_data.h | 9 ++ .../core/components_ng/pattern/BUILD.gn | 3 + .../pattern/form/form_event_hub.h | 91 ++++++++++++ .../pattern/form/form_layout_algorithm.cpp | 27 ++++ .../pattern/form/form_layout_algorithm.h | 36 +++++ .../pattern/form/form_layout_property.h | 52 +++++++ .../pattern/form/form_paint_property.h | 48 ++++++ .../pattern/form/form_pattern.cpp | 50 +++++++ .../components_ng/pattern/form/form_pattern.h | 39 +++++ .../components_ng/pattern/form/form_view.cpp | 139 ++++++++++++++++++ .../components_ng/pattern/form/form_view.h | 44 ++++++ 14 files changed, 661 insertions(+), 24 deletions(-) create mode 100644 frameworks/core/components_ng/pattern/form/form_event_hub.h create mode 100644 frameworks/core/components_ng/pattern/form/form_layout_algorithm.cpp create mode 100644 frameworks/core/components_ng/pattern/form/form_layout_algorithm.h create mode 100644 frameworks/core/components_ng/pattern/form/form_layout_property.h create mode 100644 frameworks/core/components_ng/pattern/form/form_paint_property.h create mode 100644 frameworks/core/components_ng/pattern/form/form_pattern.cpp create mode 100644 frameworks/core/components_ng/pattern/form/form_pattern.h create mode 100644 frameworks/core/components_ng/pattern/form/form_view.cpp create mode 100644 frameworks/core/components_ng/pattern/form/form_view.h diff --git a/frameworks/bridge/declarative_frontend/jsview/js_form.cpp b/frameworks/bridge/declarative_frontend/jsview/js_form.cpp index 18a6a051dc5..885edc78320 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_form.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_form.cpp @@ -16,6 +16,8 @@ #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/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 +56,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"); @@ -79,6 +86,9 @@ void JSForm::SetSize(const JSCallbackInfo& info) width = StringUtils::StringToDimension(widthValue->ToString(), true); } } + if (!width.IsValid()) { + width = 0.0_vp; + } JSRef heightValue = sizeObj->GetProperty("height"); if (!heightValue->IsNull() && !heightValue->IsEmpty()) { @@ -88,14 +98,28 @@ void JSForm::SetSize(const JSCallbackInfo& info) height = StringUtils::StringToDimension(heightValue->ToString(), true); } } + if (!height.IsValid()) { + height = 0.0_vp; + } + + if (Container::IsCurrentUseNewPipeline()) { + NG::FormView::SetSize(width, height); + return; + } + auto form = AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetMainComponent()); if (form) { - form->SetCardSize(width.IsValid() ? width : 0.0_vp, height.IsValid() ? height : 0.0_vp); + form->SetCardSize(width, height); } } 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 +128,77 @@ 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::FormView::SetVisible(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 +217,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.onAcquired"); + 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 +248,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.onAcquired"); + 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 +279,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.onAcquired"); + 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/components/common/layout/constants.h b/frameworks/core/components/common/layout/constants.h index a98ae2ad279..b7d261a3b2c 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 232cde5625b..d9652a5e0cd 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/resource/form_request_data.h b/frameworks/core/components/form/resource/form_request_data.h index a24bec8d93c..c6a5de91cd5 100644 --- a/frameworks/core/components/form/resource/form_request_data.h +++ b/frameworks/core/components/form/resource/form_request_data.h @@ -39,6 +39,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_ng/pattern/BUILD.gn b/frameworks/core/components_ng/pattern/BUILD.gn index 30cf22d5e0b..677bc2c593a 100644 --- a/frameworks/core/components_ng/pattern/BUILD.gn +++ b/frameworks/core/components_ng/pattern/BUILD.gn @@ -33,6 +33,9 @@ build_component_ng("pattern_ng") { "divider/divider_view.cpp", "flex/flex_layout_algorithm.cpp", "flex/flex_view.cpp", + "form/form_layout_algorithm.cpp", + "form/form_pattern.cpp", + "form/form_view.cpp", "grid/grid_item_view.cpp", "grid/grid_layout_algorithm.cpp", "grid/grid_pattern.cpp", 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 00000000000..e93b812a1a3 --- /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_algorithm.cpp b/frameworks/core/components_ng/pattern/form/form_layout_algorithm.cpp new file mode 100644 index 00000000000..601660affb1 --- /dev/null +++ b/frameworks/core/components_ng/pattern/form/form_layout_algorithm.cpp @@ -0,0 +1,27 @@ +/* + * 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_layout_algorithm.h" + +#include "base/utils/utils.h" +#include "core/components_ng/pattern/form/form_layout_property.h" +#include "core/components_ng/property/layout_constraint.h" +#include "core/components_ng/property/measure_property.h" +#include "core/components_ng/property/measure_utils.h" + +namespace OHOS::Ace::NG { + + +} // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/form/form_layout_algorithm.h b/frameworks/core/components_ng/pattern/form/form_layout_algorithm.h new file mode 100644 index 00000000000..5f506c4123d --- /dev/null +++ b/frameworks/core/components_ng/pattern/form/form_layout_algorithm.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_FORM_LAYOUT_ALGORITHM_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_FORM_LAYOUT_ALGORITHM_H + +#include "base/memory/referenced.h" +#include "core/components_ng/layout/layout_algorithm.h" +#include "core/components_ng/layout/layout_wrapper.h" + +namespace OHOS::Ace::NG { + +class ACE_EXPORT FormLayoutAlgorithm : public BoxLayoutAlgorithm { + DECLARE_ACE_TYPE(FormLayoutAlgorithm, BoxLayoutAlgorithm); + +public: + FormLayoutAlgorithm() = default; + ~FormLayoutAlgorithm() override = default; + + void OnReset() override {} +}; + +} // namespace OHOS::Ace::NG +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_FORM_LAYOUT_ALGORITHM_H 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 00000000000..57243cb7956 --- /dev/null +++ b/frameworks/core/components_ng/pattern/form/form_layout_property.h @@ -0,0 +1,52 @@ +/* + * 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_paint_property.h b/frameworks/core/components_ng/pattern/form/form_paint_property.h new file mode 100644 index 00000000000..a40d7b44bfe --- /dev/null +++ b/frameworks/core/components_ng/pattern/form/form_paint_property.h @@ -0,0 +1,48 @@ +/* + * 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_PAINT_PROPERTY_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_FORM_PAINT_PROPERTY_H + +#include "core/components/common/layout/constants.h" +#include "core/components_ng/render/paint_property.h" + +namespace OHOS::Ace::NG { + +class FormPaintProperty : public PaintProperty { + DECLARE_ACE_TYPE(FormPaintProperty, PaintProperty) + +public: + FormPaintProperty() = default; + ~FormPaintProperty() override = default; + + RefPtr Clone() const override + { + auto paintProperty = MakeRefPtr(); + paintProperty->UpdatePaintProperty(this); + return paintProperty; + } + + void Reset() override + { + PaintProperty::Reset(); + } + + ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Visibility, VisibleType, PROPERTY_UPDATE_RENDER); +}; + +} // namespace OHOS::Ace::NG + +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_FORM_PAINT_PROPERTY_H 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 00000000000..9cbd166d96c --- /dev/null +++ b/frameworks/core/components_ng/pattern/form/form_pattern.cpp @@ -0,0 +1,50 @@ +/* + * 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/utils/utils.h" +#include "core/components_ng/property/property.h" + +namespace OHOS::Ace::NG { + +void FormPattern::OnAttachToFrameNode() +{ + auto host = GetHost(); + CHECK_NULL_VOID(host); + host->GetRenderContext()->SetClipToFrame(true); +} + +void FormPattern::OnModifyDone() +{ + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto layoutProperty = host->GetLayoutProperty(); + CHECK_NULL_VOID(layoutProperty); +} + +bool FormPattern::OnDirtyLayoutWrapperSwap(const RefPtr& dirty, const DirtySwapConfig& config) +{ + if (config.skipMeasure && config.skipLayout) { + return false; + } + auto layoutAlgorithmWrapper = DynamicCast(dirty->GetLayoutAlgorithm()); + CHECK_NULL_RETURN(layoutAlgorithmWrapper, false); + auto layoutAlgorithm = DynamicCast(layoutAlgorithmWrapper->GetLayoutAlgorithm()); + CHECK_NULL_RETURN(layoutAlgorithm, false); + return false; +} + +} // 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 00000000000..ef5a3c8655c --- /dev/null +++ b/frameworks/core/components_ng/pattern/form/form_pattern.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#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_ng/event/event_hub.h" +#include "core/components_ng/pattern/pattern.h" + +namespace OHOS::Ace::NG { + +class FormPattern : public Pattern { + DECLARE_ACE_TYPE(FormPattern, Pattern); + +public: + FormPattern() = default; + ~FormPattern() override = default; + +private: + void OnModifyDone() override; + void OnAttachToFrameNode() override; + bool OnDirtyLayoutWrapperSwap(const RefPtr& dirty, const DirtySwapConfig& config) override; +}; + +} // 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 00000000000..06b4586a0f0 --- /dev/null +++ b/frameworks/core/components_ng/pattern/form/form_view.cpp @@ -0,0 +1,139 @@ +/* + * 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_paint_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 = FrameNode::GetOrCreateFrameNode( + V2::FORM_ETS_TAG, stack->ClaimNodeId(), []() { return AceType::MakeRefPtr(); }); + stack->Push(frameNode); + + ACE_UPDATE_LAYOUT_PROPERTY(FormLayoutProperty, RequestFormInfo, formInfo); +} + +void FormView::SetSize(const Dimension& width, const Dimension& height) +{ + 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.width = width; + formInfo.height = height; + property->UpdateRequestFormInfo(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_PAINT_PROPERTY(FormPaintProperty, 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 00000000000..f374e9903b4 --- /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" + +namespace OHOS::Ace::NG { + +class ACE_EXPORT FormView { +public: + static void Create(const RequestFormInfo& formInfo); + static void SetSize(const Dimension& width, const Dimension& height); + 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 -- Gitee From a3d3784d32f12cce7818dc6b193b9b9bed31ef6b Mon Sep 17 00:00:00 2001 From: caocan Date: Thu, 15 Sep 2022 14:24:03 +0800 Subject: [PATCH 2/4] =?UTF-8?q?[UI=E7=BB=84=E4=BB=B6=E9=87=8D=E6=9E=84]For?= =?UTF-8?q?m=E5=BA=95=E5=B1=82=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: caocan Change-Id: I862b2d53ecb7206bd4a44658360faf3e038b5ff5 --- .../declarative_frontend/jsview/js_form.cpp | 12 +- frameworks/core/BUILD.gn | 6 +- frameworks/core/components/form/form_window.h | 4 +- .../core/components/form/render_form.cpp | 2 +- frameworks/core/components/form/render_form.h | 2 +- .../form/resource/form_manager_delegate.cpp | 10 +- .../form/resource/form_manager_delegate.h | 30 +- .../form/resource/form_manager_resource.cpp | 7 +- .../form/resource/form_manager_resource.h | 9 +- .../form/resource/form_request_data.h | 4 + .../core/components/form/sub_container.cpp | 67 ++-- .../core/components/form/sub_container.h | 27 +- .../core/components/plugin/render_plugin.cpp | 2 +- .../core/components/plugin/render_plugin.h | 2 +- .../core/components_ng/base/frame_node.cpp | 37 ++- .../core/components_ng/base/frame_node.h | 8 +- .../core/components_ng/base/view_abstract.cpp | 5 + .../core/components_ng/base/view_abstract.h | 2 + .../components_ng/layout/layout_property.cpp | 21 ++ .../components_ng/layout/layout_property.h | 12 + .../components_ng/layout/layout_wrapper.cpp | 13 + .../components_ng/layout/layout_wrapper.h | 4 +- .../core/components_ng/pattern/BUILD.gn | 3 - .../core/components_ng/pattern/form/BUILD.gn | 36 +++ .../pattern/form/form_layout_property.h | 1 + ...orm_layout_algorithm.cpp => form_node.cpp} | 34 +- .../{form_layout_algorithm.h => form_node.h} | 25 +- .../pattern/form/form_paint_property.h | 48 --- .../pattern/form/form_pattern.cpp | 290 +++++++++++++++++- .../components_ng/pattern/form/form_pattern.h | 44 ++- .../components_ng/pattern/form/form_view.cpp | 28 +- .../components_ng/pattern/form/form_view.h | 5 + .../render/adapter/rosen_render_context.cpp | 2 +- .../core/pipeline/base/render_sub_container.h | 2 +- frameworks/core/pipeline/pipeline_base.cpp | 16 + frameworks/core/pipeline/pipeline_base.h | 51 +++ frameworks/core/pipeline/pipeline_context.cpp | 22 +- frameworks/core/pipeline/pipeline_context.h | 51 --- .../core/pipeline_ng/pipeline_context.cpp | 17 + 39 files changed, 719 insertions(+), 242 deletions(-) create mode 100644 frameworks/core/components_ng/pattern/form/BUILD.gn rename frameworks/core/components_ng/pattern/form/{form_layout_algorithm.cpp => form_node.cpp} (34%) rename frameworks/core/components_ng/pattern/form/{form_layout_algorithm.h => form_node.h} (60%) delete mode 100644 frameworks/core/components_ng/pattern/form/form_paint_property.h diff --git a/frameworks/bridge/declarative_frontend/jsview/js_form.cpp b/frameworks/bridge/declarative_frontend/jsview/js_form.cpp index 885edc78320..4ffc8482b95 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_form.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_form.cpp @@ -17,6 +17,7 @@ #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) @@ -134,7 +135,6 @@ void JSForm::AllowUpdate(const JSCallbackInfo& info) } auto allowUpdate = info[0]->ToBoolean(); - if (Container::IsCurrentUseNewPipeline()) { NG::FormView::SetAllowUpdate(allowUpdate); return; @@ -154,9 +154,8 @@ void JSForm::SetVisibility(const JSCallbackInfo& info) } auto type = info[0]->ToNumber(); - if (Container::IsCurrentUseNewPipeline()) { - NG::FormView::SetVisible(VisibleType(type)); + NG::ViewAbstract::SetVisibility(VisibleType(type)); return; } @@ -173,7 +172,6 @@ void JSForm::SetModuleName(const JSCallbackInfo& info) } auto moduleName = info[0]->ToString(); - if (Container::IsCurrentUseNewPipeline()) { NG::FormView::SetModuleName(moduleName); return; @@ -221,7 +219,7 @@ void JSForm::JsOnError(const JSCallbackInfo& info) 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.onAcquired"); + ACE_SCORING_EVENT("Form.onError"); std::vector keys = { "errcode", "msg" }; func->Execute(keys, param); }; @@ -252,7 +250,7 @@ void JSForm::JsOnUninstall(const JSCallbackInfo& info) 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.onAcquired"); + ACE_SCORING_EVENT("Form.onUninstall"); std::vector keys = { "id" }; func->Execute(keys, param); }; @@ -283,7 +281,7 @@ void JSForm::JsOnRouter(const JSCallbackInfo& info) 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.onAcquired"); + ACE_SCORING_EVENT("Form.onRouter"); std::vector keys = { "action" }; func->Execute(keys, param); }; diff --git a/frameworks/core/BUILD.gn b/frameworks/core/BUILD.gn index 7e9305a41d6..220671bdf6f 100644 --- a/frameworks/core/BUILD.gn +++ b/frameworks/core/BUILD.gn @@ -382,7 +382,10 @@ template("ace_core_source_set") { deps += [ "$ace_root/frameworks/core/components/text_overlay:ace_core_components_text_overlay_$platform" ] } - deps += [ "$ace_root/frameworks/core/components_ng/pattern/qrcode:ace_core_components_qrcode_pattern_ng_$platform" ] + deps += [ + "$ace_root/frameworks/core/components_ng/pattern/form:ace_core_components_form_pattern_ng_$platform", + "$ace_root/frameworks/core/components_ng/pattern/qrcode:ace_core_components_qrcode_pattern_ng_$platform", + ] # xcomponent components supports phone, TV and wearable except PC Preview if (defined(config.xcomponent_components_support) && @@ -634,6 +637,7 @@ template("ace_core_ng_source_set") { "$ace_root/frameworks/core/components_ng/image_provider:ace_core_components_image_provider_ng_$platform", "$ace_root/frameworks/core/components_ng/layout:ace_core_components_layout_ng_$platform", "$ace_root/frameworks/core/components_ng/pattern:ace_core_components_pattern_ng_$platform", + "$ace_root/frameworks/core/components_ng/pattern/form:ace_core_components_form_pattern_ng_$platform", "$ace_root/frameworks/core/components_ng/pattern/qrcode:ace_core_components_qrcode_pattern_ng_$platform", "$ace_root/frameworks/core/components_ng/property:ace_core_components_property_ng_$platform", "$ace_root/frameworks/core/components_ng/render:ace_core_components_render_ng_$platform", diff --git a/frameworks/core/components/form/form_window.h b/frameworks/core/components/form/form_window.h index 732838471b9..280dcea4cad 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 e27c09e6f04..3df9e631cba 100644 --- a/frameworks/core/components/form/render_form.cpp +++ b/frameworks/core/components/form/render_form.cpp @@ -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 71ee5bd100e..e17e12ba886 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 944305a5df7..e8b2b1347b0 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 97b62b819d9..8363d8a5fe9 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 8013ebc047e..137ad577c73 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 779296a8d57..82085d22bed 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 c6a5de91cd5..4ed9e31ea54 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 { diff --git a/frameworks/core/components/form/sub_container.cpp b/frameworks/core/components/form/sub_container.cpp index 05d3b438bc7..2bda6f77a09 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())); } } @@ -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; + CHECK_NULL_VOID(container); + + if (Container::IsCurrentUseNewPipeline()) { + auto form = container->GetFormPattern().Upgrade(); + CHECK_NULL_VOID(form); + form->OnActionEvent(action); + } else { + auto form = AceType::DynamicCast(container->GetFormElement().Upgrade()); + CHECK_NULL_VOID(form); + form->OnActionEvent(action); } - auto form = AceType::DynamicCast(container->GetFormElement().Upgrade()); - if (!form) { - LOGE("ActionEventHandler form is null!"); - return; - } - - 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"); @@ -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] @@ -375,8 +398,8 @@ void SubContainer::GetImageDataFromAshmem( } } -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 69eecd1c70e..86c21622afd 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,8 +32,8 @@ 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; @@ -45,7 +47,7 @@ public: 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 +70,7 @@ public: return taskExecutor_; } - RefPtr GetPipelineContext() const + RefPtr GetPipelineContext() const { return pipelineContext_; } @@ -104,11 +106,21 @@ public: cardWindowConfig_ = cardWindowConfig; } + void SetFormPattern(const WeakPtr& formPattern) + { + formPattern_ = formPattern; + } + + const WeakPtr& GetFormPattern() const + { + return formPattern_; + } + private: RefPtr frontend_; RefPtr taskExecutor_; - RefPtr pipelineContext_; - WeakPtr outSidePipelineContext_; + RefPtr pipelineContext_; + WeakPtr outSidePipelineContext_; RefPtr assetManager_; int32_t instanceId_; @@ -125,6 +137,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/render_plugin.cpp b/frameworks/core/components/plugin/render_plugin.cpp index 264c18cea69..a9319baed98 100644 --- a/frameworks/core/components/plugin/render_plugin.cpp +++ b/frameworks/core/components/plugin/render_plugin.cpp @@ -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 11e5a61fb3f..62478224adb 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 94c1c120ec8..da7fe94c2b4 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() @@ -239,9 +242,10 @@ std::optional FrameNode::CreateLayoutTask(bool forceUseMainThread) RefPtr layoutWrapper; UpdateLayoutPropertyFlag(); layoutWrapper = CreateLayoutWrapper(); + auto isActive = layoutProperty_->GetVisibility().value_or(VisibleType::VISIBLE) == VisibleType::VISIBLE; auto task = [layoutWrapper, layoutConstraint = GetLayoutConstraint(), offset = GetParentGlobalOffset(), - forceUseMainThread]() { - layoutWrapper->SetActive(); + forceUseMainThread, isActive]() { + layoutWrapper->SetActive(isActive); layoutWrapper->SetRootMeasureNode(); { ACE_SCOPED_TRACE("LayoutWrapper::Measure"); @@ -288,18 +292,25 @@ std::optional FrameNode::CreateRenderTask(bool forceUseMainThread) LayoutConstraintF FrameNode::GetLayoutConstraint() const { + auto visible = layoutProperty_->GetVisibility().value_or(VisibleType::VISIBLE); + LayoutConstraintF layoutConstraint; if (geometryNode_->GetParentLayoutConstraint().has_value()) { - return geometryNode_->GetParentLayoutConstraint().value(); - } - 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 = geometryNode_->GetParentLayoutConstraint().value(); + } else { + 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); + } + + if (visible == VisibleType::GONE) { + layoutConstraint.selfIdealSize = OptionalSizeF(SizeF()); + layoutProperty_->UpdateCalcSelfIdealSize(CalcSize(CalcLength(0), CalcLength(0))); + } + return layoutConstraint; } OffsetF FrameNode::GetParentGlobalOffset() const diff --git a/frameworks/core/components_ng/base/frame_node.h b/frameworks/core/components_ng/base/frame_node.h index 8a0d530a43f..a5b037f1f8c 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 0a013412561..65ca4dd0b4b 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 0ae859667a9..996c3d2dc9b 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 21dc355ceb2..dac5b50a264 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,24 @@ PaddingPropertyF LayoutProperty::CreatePaddingWithoutBorder() return ConvertToPaddingPropertyF( padding_, ScaleProperty::CreateScaleProperty(), PipelineContext::GetCurrentRootWidth()); } + +void LayoutProperty::SetHost(const WeakPtr& host) +{ + host_ = host; +} + +const WeakPtr& LayoutProperty::GetHost() const +{ + return host_; +} + +void LayoutProperty::OnVisibilityUpdate(VisibleType /* visible */) const +{ + auto host = GetHost().Upgrade(); + CHECK_NULL_VOID(host); + auto parent = host->GetAncestorNodeOfFrame(); + CHECK_NULL_VOID(parent); + parent->MarkNeedSyncRenderTree(); +} + } // 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 f995f67cba5..6c1866f6eaa 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,9 @@ public: PaddingPropertyF CreatePaddingWithoutBorder(); PaddingPropertyF CreatePaddingAndBorder(); + void SetHost(const WeakPtr& host); + const WeakPtr& GetHost() const; + protected: void UpdateLayoutProperty(const LayoutProperty* layoutProperty); @@ -246,6 +254,10 @@ private: std::unique_ptr flexItemProperty_; std::optional measureType_; + ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP_AND_USING_CALLBACK(Visibility, VisibleType, PROPERTY_UPDATE_MEASURE); + void OnVisibilityUpdate(VisibleType visible) const; + + 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 6f26ef4e79c..1ced3a5e9a5 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" @@ -116,9 +117,21 @@ void LayoutWrapper::Measure(const std::optional& parentConstr isContraintNoChanged_ = true; } + if (!host->IsVisible()) { + isActive_ = false; + } if (parentConstraint) { geometryNode_->SetParentLayoutConstraint(parentConstraint.value()); layoutProperty_->UpdateLayoutConstraint(parentConstraint.value()); + VisibleType visible = VisibleType::VISIBLE; + auto layoutProperty = host->GetLayoutProperty(); + if (layoutProperty) { + visible = layoutProperty->GetVisibility().value_or(VisibleType::VISIBLE); + } + if (visible == VisibleType::GONE) { + layoutProperty_->UpdateSelfIdealSize(SizeF()); + layoutProperty_->UpdateCalcSelfIdealSize(CalcSize(CalcLength(0), CalcLength(0))); + } } else { LayoutConstraintF layoutConstraint; layoutConstraint.percentReference.SetWidth(PipelineContext::GetCurrentRootWidth()); diff --git a/frameworks/core/components_ng/layout/layout_wrapper.h b/frameworks/core/components_ng/layout/layout_wrapper.h index 7dc2640d433..0195e14d372 100644 --- a/frameworks/core/components_ng/layout/layout_wrapper.h +++ b/frameworks/core/components_ng/layout/layout_wrapper.h @@ -119,9 +119,9 @@ public: return isActive_; } - void SetActive() + void SetActive(bool isActive = true) { - isActive_ = true; + isActive_ = isActive; } bool IsRootMeasureNode() const diff --git a/frameworks/core/components_ng/pattern/BUILD.gn b/frameworks/core/components_ng/pattern/BUILD.gn index 677bc2c593a..30cf22d5e0b 100644 --- a/frameworks/core/components_ng/pattern/BUILD.gn +++ b/frameworks/core/components_ng/pattern/BUILD.gn @@ -33,9 +33,6 @@ build_component_ng("pattern_ng") { "divider/divider_view.cpp", "flex/flex_layout_algorithm.cpp", "flex/flex_view.cpp", - "form/form_layout_algorithm.cpp", - "form/form_pattern.cpp", - "form/form_view.cpp", "grid/grid_item_view.cpp", "grid/grid_layout_algorithm.cpp", "grid/grid_pattern.cpp", 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 00000000000..cd6a9592165 --- /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_layout_property.h b/frameworks/core/components_ng/pattern/form/form_layout_property.h index 57243cb7956..5a167a1b226 100644 --- a/frameworks/core/components_ng/pattern/form/form_layout_property.h +++ b/frameworks/core/components_ng/pattern/form/form_layout_property.h @@ -24,6 +24,7 @@ #include "core/components_ng/property/property.h" namespace OHOS::Ace::NG { + class ACE_EXPORT FormLayoutProperty : public LayoutProperty { DECLARE_ACE_TYPE(FormLayoutProperty, LayoutProperty); diff --git a/frameworks/core/components_ng/pattern/form/form_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/form/form_node.cpp similarity index 34% rename from frameworks/core/components_ng/pattern/form/form_layout_algorithm.cpp rename to frameworks/core/components_ng/pattern/form/form_node.cpp index 601660affb1..6af1a3570c0 100644 --- a/frameworks/core/components_ng/pattern/form/form_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/form/form_node.cpp @@ -13,15 +13,37 @@ * limitations under the License. */ -#include "core/components_ng/pattern/form/form_layout_algorithm.h" +#include "core/components_ng/pattern/form/form_node.h" #include "base/utils/utils.h" -#include "core/components_ng/pattern/form/form_layout_property.h" -#include "core/components_ng/property/layout_constraint.h" -#include "core/components_ng/property/measure_property.h" -#include "core/components_ng/property/measure_utils.h" +#include "core/components/form/sub_container.h" +#include "core/components_ng/pattern/form/form_pattern.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 = subContainer->GetPipelineContext(); + CHECK_NULL_RETURN(subContext, HitTestResult::BUBBLING); + auto selfGlobalOffset = GetGeometryNode()->GetParentGlobalOffset() + GetGeometryNode()->GetFrameOffset(); + subContext->SetPluginEventOffset(Offset(selfGlobalOffset.GetX(), selfGlobalOffset.GetY())); -} // namespace OHOS::Ace::NG + auto context = GetContext(); + if (context) { + context->SetTouchPipeline(WeakPtr(subContext)); + } + + return HitTestResult::STOP_BUBBLING; +} + +} // namespace OHOS::Ace::NG \ No newline at end of file diff --git a/frameworks/core/components_ng/pattern/form/form_layout_algorithm.h b/frameworks/core/components_ng/pattern/form/form_node.h similarity index 60% rename from frameworks/core/components_ng/pattern/form/form_layout_algorithm.h rename to frameworks/core/components_ng/pattern/form/form_node.h index 5f506c4123d..f522b427f52 100644 --- a/frameworks/core/components_ng/pattern/form/form_layout_algorithm.h +++ b/frameworks/core/components_ng/pattern/form/form_node.h @@ -13,24 +13,27 @@ * limitations under the License. */ -#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_FORM_LAYOUT_ALGORITHM_H -#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_FORM_LAYOUT_ALGORITHM_H +#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 "base/memory/referenced.h" -#include "core/components_ng/layout/layout_algorithm.h" -#include "core/components_ng/layout/layout_wrapper.h" +#include + +#include "core/components_ng/base/frame_node.h" namespace OHOS::Ace::NG { -class ACE_EXPORT FormLayoutAlgorithm : public BoxLayoutAlgorithm { - DECLARE_ACE_TYPE(FormLayoutAlgorithm, BoxLayoutAlgorithm); +class ACE_EXPORT FormNode : public FrameNode { + DECLARE_ACE_TYPE(FormNode, FrameNode); public: - FormLayoutAlgorithm() = default; - ~FormLayoutAlgorithm() override = default; + FormNode(const std::string& tag, int32_t nodeId, const RefPtr& pattern, bool isRoot = false) + : FrameNode(tag, nodeId, pattern, isRoot) + {} + ~FormNode() override = default; - void OnReset() override {} + HitTestResult TouchTest(const PointF& globalPoint, const PointF& parentLocalPoint, + const TouchRestrict& touchRestrict, TouchTestResult& result) override; }; } // namespace OHOS::Ace::NG -#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_FORM_LAYOUT_ALGORITHM_H +#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_paint_property.h b/frameworks/core/components_ng/pattern/form/form_paint_property.h deleted file mode 100644 index a40d7b44bfe..00000000000 --- a/frameworks/core/components_ng/pattern/form/form_paint_property.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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_PAINT_PROPERTY_H -#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_FORM_PAINT_PROPERTY_H - -#include "core/components/common/layout/constants.h" -#include "core/components_ng/render/paint_property.h" - -namespace OHOS::Ace::NG { - -class FormPaintProperty : public PaintProperty { - DECLARE_ACE_TYPE(FormPaintProperty, PaintProperty) - -public: - FormPaintProperty() = default; - ~FormPaintProperty() override = default; - - RefPtr Clone() const override - { - auto paintProperty = MakeRefPtr(); - paintProperty->UpdatePaintProperty(this); - return paintProperty; - } - - void Reset() override - { - PaintProperty::Reset(); - } - - ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Visibility, VisibleType, PROPERTY_UPDATE_RENDER); -}; - -} // namespace OHOS::Ace::NG - -#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_FORM_PAINT_PROPERTY_H diff --git a/frameworks/core/components_ng/pattern/form/form_pattern.cpp b/frameworks/core/components_ng/pattern/form/form_pattern.cpp index 9cbd166d96c..4b54de5ce10 100644 --- a/frameworks/core/components_ng/pattern/form/form_pattern.cpp +++ b/frameworks/core/components_ng/pattern/form/form_pattern.cpp @@ -16,10 +16,20 @@ #include "core/components_ng/pattern/form/form_pattern.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(); @@ -29,22 +39,284 @@ void FormPattern::OnAttachToFrameNode() void FormPattern::OnModifyDone() { + InitFormManagerDelegate(); + auto host = GetHost(); CHECK_NULL_VOID(host); - auto layoutProperty = host->GetLayoutProperty(); + auto layoutProperty = host->GetLayoutProperty(); CHECK_NULL_VOID(layoutProperty); + auto info = layoutProperty->GetRequestFormInfo().value_or(RequestFormInfo()); + 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; + } + CreateCardContainer(); + if (formManagerBridge_) { + formManagerBridge_->AddForm(host->GetContext(), info); + } +} + +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()); } -bool FormPattern::OnDirtyLayoutWrapperSwap(const RefPtr& dirty, const DirtySwapConfig& config) +void FormPattern::FireOnRouterEvent(const std::unique_ptr& action) const { - if (config.skipMeasure && config.skipLayout) { - return false; + 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); } - auto layoutAlgorithmWrapper = DynamicCast(dirty->GetLayoutAlgorithm()); - CHECK_NULL_RETURN(layoutAlgorithmWrapper, false); - auto layoutAlgorithm = DynamicCast(layoutAlgorithmWrapper->GetLayoutAlgorithm()); - CHECK_NULL_RETURN(layoutAlgorithm, false); - return false; +} + +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 index ef5a3c8655c..62f3d24f2be 100644 --- a/frameworks/core/components_ng/pattern/form/form_pattern.h +++ b/frameworks/core/components_ng/pattern/form/form_pattern.h @@ -16,22 +16,60 @@ #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() = default; - ~FormPattern() override = default; + 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 OnModifyDone() override; 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 diff --git a/frameworks/core/components_ng/pattern/form/form_view.cpp b/frameworks/core/components_ng/pattern/form/form_view.cpp index 06b4586a0f0..c5010d1ef33 100644 --- a/frameworks/core/components_ng/pattern/form/form_view.cpp +++ b/frameworks/core/components_ng/pattern/form/form_view.cpp @@ -22,16 +22,37 @@ #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_paint_property.h" #include "core/components_ng/pattern/form/form_pattern.h" #include "core/components_v2/inspector/inspector_constants.h" namespace OHOS::Ace::NG { +RefPtr FormView::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; +} + void FormView::Create(const RequestFormInfo& formInfo) { auto* stack = ViewStackProcessor::GetInstance(); - auto frameNode = FrameNode::GetOrCreateFrameNode( + auto frameNode = GetOrCreateFormNode( V2::FORM_ETS_TAG, stack->ClaimNodeId(), []() { return AceType::MakeRefPtr(); }); stack->Push(frameNode); @@ -51,6 +72,7 @@ void FormView::SetSize(const Dimension& width, const Dimension& height) formInfo.width = width; formInfo.height = height; property->UpdateRequestFormInfo(formInfo); + property->UpdateCalcSelfIdealSize(CalcSize(NG::CalcLength(width), NG::CalcLength(height))); } void FormView::SetDimension(int32_t dimension) @@ -83,7 +105,7 @@ void FormView::SetAllowUpdate(bool allowUpdate) void FormView::SetVisible(VisibleType visible) { - ACE_UPDATE_PAINT_PROPERTY(FormPaintProperty, Visibility, visible); + ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, Visibility, visible); } void FormView::SetModuleName(const std::string& moduleName) diff --git a/frameworks/core/components_ng/pattern/form/form_view.h b/frameworks/core/components_ng/pattern/form/form_view.h index f374e9903b4..01b6f21e0c7 100644 --- a/frameworks/core/components_ng/pattern/form/form_view.h +++ b/frameworks/core/components_ng/pattern/form/form_view.h @@ -23,6 +23,7 @@ #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 { @@ -38,6 +39,10 @@ public: static void SetOnError(FormCallback&& onError); static void SetOnUninstall(FormCallback&& onUninstall); static void SetOnRouter(FormCallback&& onRouter); + +private: + static RefPtr GetOrCreateFormNode( + const std::string& tag, int32_t nodeId, const std::function(void)>& patternCreator); }; } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/render/adapter/rosen_render_context.cpp b/frameworks/core/components_ng/render/adapter/rosen_render_context.cpp index 0c515796cfe..5c499f028af 100644 --- a/frameworks/core/components_ng/render/adapter/rosen_render_context.cpp +++ b/frameworks/core/components_ng/render/adapter/rosen_render_context.cpp @@ -297,7 +297,7 @@ void RosenRenderContext::ReCreateRsNodeTree(const std::list>& continue; } auto rsnode = rosenRenderContext->GetRSNode(); - if (rsnode) { + if (rsnode && child->IsVisible()) { rsNode_->AddChild(rsnode, -1); } } diff --git a/frameworks/core/pipeline/base/render_sub_container.h b/frameworks/core/pipeline/base/render_sub_container.h index 8ead969407a..9436e77eec5 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/pipeline_base.cpp b/frameworks/core/pipeline/pipeline_base.cpp index 202fdce94f9..30ac1f5bd3f 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 e291b3e7d3f..87a6f16a518 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,49 @@ public: virtual void FlushReloadTransition() {} + double GetDensity() const + { + return density_; + } + + void SetTouchPipeline(const WeakPtr& context); + void RemoveTouchPipeline(const WeakPtr& context); + + void SetPluginOffset(const Offset& offset) + { + pluginOffset_ = offset; + } + + Offset GetPluginOffset() const + { + return pluginOffset_; + } + + void SetPluginEventOffset(const Offset& offset) + { + pluginEventOffset_ = offset; + } + + Offset GetPluginEventOffset() const + { + return pluginEventOffset_; + } + + const RefPtr& GetSharedImageManager() const + { + return sharedImageManager_; + } + + void SetSharedImageManager(const RefPtr& sharedImageManager) + { + sharedImageManager_ = sharedImageManager; + } + + void SetDrawDelegate(std::unique_ptr delegate) + { + drawDelegate_ = std::move(delegate); + } + protected: virtual bool OnDumpInfo(const std::vector& params) const { @@ -527,6 +572,12 @@ protected: StartAbilityHandler startAbilityHandler_; ActionEventHandler actionEventHandler_; + Offset pluginOffset_ { 0, 0 }; + Offset pluginEventOffset_ { 0, 0 }; + std::vector> touchPluginPipelineContext_; + RefPtr sharedImageManager_; + std::unique_ptr drawDelegate_; + private: StatusBarEventHandler statusBarBgColorEventHandler_; PopupEventHandler popupEventHandler_; diff --git a/frameworks/core/pipeline/pipeline_context.cpp b/frameworks/core/pipeline/pipeline_context.cpp index 60ac286cacc..ab532ef688e 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 233cca74614..3e8e4ce5ade 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" @@ -513,11 +511,6 @@ public: void MovePage(const Offset& rootRect, double offsetHeight); - void SetDrawDelegate(std::unique_ptr delegate) - { - drawDelegate_ = std::move(delegate); - } - void SetBuildAfterCallback(const std::function& callback) override { buildAfterCallback_.emplace_back(callback); @@ -574,16 +567,6 @@ public: return buildingFirstPage_; } - const RefPtr& GetSharedImageManager() const - { - return sharedImageManager_; - } - - void SetSharedImageManager(const RefPtr& sharedImageManager) - { - sharedImageManager_ = sharedImageManager; - } - using UpdateWindowBlurDrawOpHandler = std::function; void SetUpdateWindowBlurDrawOpHandler(UpdateWindowBlurDrawOpHandler handler) @@ -737,11 +720,6 @@ public: contextMenu_ = contextMenu; } - double GetDensity() const - { - return density_; - } - void SetClipHole(double left, double top, double width, double height); const Rect& GetTransparentHole() const @@ -774,29 +752,6 @@ public: return isHoleValid_; } - void SetPluginOffset(const Offset& offset) - { - pluginOffset_ = offset; - } - - Offset GetPluginOffset() const - { - return pluginOffset_; - } - - void SetPluginEventOffset(const Offset& offset) - { - pluginEventOffset_ = offset; - } - - Offset GetPluginEventOffset() const - { - return pluginEventOffset_; - } - - void SetTouchPipeline(WeakPtr context); - void RemoveTouchPipeline(WeakPtr context); - void SetRSUIDirector(std::shared_ptr rsUIDirector); std::shared_ptr GetRSUIDirector(); @@ -1155,7 +1110,6 @@ private: RefPtr rootElement_; WeakPtr dirtyFocusNode_; WeakPtr dirtyFocusScope_; - RefPtr sharedImageManager_; std::list> buildAfterCallback_; RefPtr renderFactory_; UpdateWindowBlurRegionHandler updateWindowBlurRegionHandler_; @@ -1231,7 +1185,6 @@ private: uint32_t modalColor_ = 0x00000000; bool isFullWindow_ = false; std::list> hoverNodes_; - std::unique_ptr drawDelegate_; std::function&&)> screenOffCallback_; std::function&&)> screenOnCallback_; #if defined(ENABLE_NATIVE_VIEW) @@ -1254,10 +1207,6 @@ private: SurfaceChangedCallbackMap surfaceChangedCallbackMap_; SurfacePositionChangedCallbackMap surfacePositionChangedCallbackMap_; - std::vector> touchPluginPipelineContext_; - Offset pluginOffset_ { 0, 0 }; - Offset pluginEventOffset_ { 0, 0 }; - bool isShiftDown_ = false; bool isCtrlDown_ = false; bool isKeyboardA_ = false; diff --git a/frameworks/core/pipeline_ng/pipeline_context.cpp b/frameworks/core/pipeline_ng/pipeline_context.cpp index d3aff598e09..6befeea17fd 100644 --- a/frameworks/core/pipeline_ng/pipeline_context.cpp +++ b/frameworks/core/pipeline_ng/pipeline_context.cpp @@ -29,6 +29,7 @@ #include "core/common/container.h" #include "core/common/thread_checker.h" #include "core/common/window.h" +#include "core/components/box/drag_drop_event.h" #include "core/components_ng/base/frame_node.h" #include "core/components_ng/pattern/custom/custom_node.h" #include "core/components_ng/pattern/overlay/overlay_manager.h" @@ -37,6 +38,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 +277,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) { -- Gitee From 710d989ef2f7f5eaa852f9596ec50e2062661919 Mon Sep 17 00:00:00 2001 From: caocan Date: Sat, 17 Sep 2022 17:18:48 +0800 Subject: [PATCH 3/4] =?UTF-8?q?[UI=E7=BB=84=E4=BB=B6=E9=87=8D=E6=9E=84]?= =?UTF-8?q?=E4=BF=AE=E5=A4=8Dcomments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: caocan Change-Id: I5387e4b4bda02b6d657aeb872d023a845199ef32 --- .../declarative_frontend/jsview/js_form.cpp | 2 +- frameworks/core/BUILD.gn | 17 +++++--- .../components_ng/pattern/form/form_node.cpp | 22 ++++++++++ .../components_ng/pattern/form/form_node.h | 3 ++ .../pattern/form/form_pattern.cpp | 20 ++++++++-- .../components_ng/pattern/form/form_pattern.h | 1 + .../components_ng/pattern/form/form_view.cpp | 40 +------------------ .../components_ng/pattern/form/form_view.h | 5 --- 8 files changed, 56 insertions(+), 54 deletions(-) diff --git a/frameworks/bridge/declarative_frontend/jsview/js_form.cpp b/frameworks/bridge/declarative_frontend/jsview/js_form.cpp index 4ffc8482b95..d8d45192519 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_form.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_form.cpp @@ -104,7 +104,7 @@ void JSForm::SetSize(const JSCallbackInfo& info) } if (Container::IsCurrentUseNewPipeline()) { - NG::FormView::SetSize(width, height); + JSViewAbstract::JsSize(info); return; } diff --git a/frameworks/core/BUILD.gn b/frameworks/core/BUILD.gn index 220671bdf6f..5cc9b93dd2d 100644 --- a/frameworks/core/BUILD.gn +++ b/frameworks/core/BUILD.gn @@ -382,10 +382,7 @@ template("ace_core_source_set") { deps += [ "$ace_root/frameworks/core/components/text_overlay:ace_core_components_text_overlay_$platform" ] } - deps += [ - "$ace_root/frameworks/core/components_ng/pattern/form:ace_core_components_form_pattern_ng_$platform", - "$ace_root/frameworks/core/components_ng/pattern/qrcode:ace_core_components_qrcode_pattern_ng_$platform", - ] + deps += [ "$ace_root/frameworks/core/components_ng/pattern/qrcode:ace_core_components_qrcode_pattern_ng_$platform" ] # xcomponent components supports phone, TV and wearable except PC Preview if (defined(config.xcomponent_components_support) && @@ -402,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" ] } } @@ -637,7 +637,6 @@ template("ace_core_ng_source_set") { "$ace_root/frameworks/core/components_ng/image_provider:ace_core_components_image_provider_ng_$platform", "$ace_root/frameworks/core/components_ng/layout:ace_core_components_layout_ng_$platform", "$ace_root/frameworks/core/components_ng/pattern:ace_core_components_pattern_ng_$platform", - "$ace_root/frameworks/core/components_ng/pattern/form:ace_core_components_form_pattern_ng_$platform", "$ace_root/frameworks/core/components_ng/pattern/qrcode:ace_core_components_qrcode_pattern_ng_$platform", "$ace_root/frameworks/core/components_ng/property:ace_core_components_property_ng_$platform", "$ace_root/frameworks/core/components_ng/render:ace_core_components_render_ng_$platform", @@ -652,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_ng/pattern/form/form_node.cpp b/frameworks/core/components_ng/pattern/form/form_node.cpp index 6af1a3570c0..b95fbae4c40 100644 --- a/frameworks/core/components_ng/pattern/form/form_node.cpp +++ b/frameworks/core/components_ng/pattern/form/form_node.cpp @@ -46,4 +46,26 @@ HitTestResult FormNode::TouchTest(const PointF& globalPoint, const PointF& paren 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 index f522b427f52..deb9fc713f5 100644 --- a/frameworks/core/components_ng/pattern/form/form_node.h +++ b/frameworks/core/components_ng/pattern/form/form_node.h @@ -33,6 +33,9 @@ public: 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 diff --git a/frameworks/core/components_ng/pattern/form/form_pattern.cpp b/frameworks/core/components_ng/pattern/form/form_pattern.cpp index 4b54de5ce10..527dfe53f84 100644 --- a/frameworks/core/components_ng/pattern/form/form_pattern.cpp +++ b/frameworks/core/components_ng/pattern/form/form_pattern.cpp @@ -15,6 +15,7 @@ #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" @@ -40,12 +41,24 @@ void FormPattern::OnAttachToFrameNode() void FormPattern::OnModifyDone() { 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_VOID(host); + CHECK_NULL_RETURN(host, false); auto layoutProperty = host->GetLayoutProperty(); - CHECK_NULL_VOID(layoutProperty); + 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) { @@ -67,12 +80,13 @@ void FormPattern::OnModifyDone() subContainer_->UpdateRootElementSize(); subContainer_->UpdateSurfaceSize(); } - return; + return false; } CreateCardContainer(); if (formManagerBridge_) { formManagerBridge_->AddForm(host->GetContext(), info); } + return false; } void FormPattern::InitFormManagerDelegate() diff --git a/frameworks/core/components_ng/pattern/form/form_pattern.h b/frameworks/core/components_ng/pattern/form/form_pattern.h index 62f3d24f2be..ed4816e95f7 100644 --- a/frameworks/core/components_ng/pattern/form/form_pattern.h +++ b/frameworks/core/components_ng/pattern/form/form_pattern.h @@ -55,6 +55,7 @@ public: private: void OnModifyDone() override; void OnAttachToFrameNode() override; + bool OnDirtyLayoutWrapperSwap(const RefPtr& dirty, const DirtySwapConfig& config) override; void InitFormManagerDelegate(); void CreateCardContainer(); diff --git a/frameworks/core/components_ng/pattern/form/form_view.cpp b/frameworks/core/components_ng/pattern/form/form_view.cpp index c5010d1ef33..e67df7aabc5 100644 --- a/frameworks/core/components_ng/pattern/form/form_view.cpp +++ b/frameworks/core/components_ng/pattern/form/form_view.cpp @@ -27,54 +27,16 @@ namespace OHOS::Ace::NG { -RefPtr FormView::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; -} - void FormView::Create(const RequestFormInfo& formInfo) { auto* stack = ViewStackProcessor::GetInstance(); - auto frameNode = GetOrCreateFormNode( + 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::SetSize(const Dimension& width, const Dimension& height) -{ - 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.width = width; - formInfo.height = height; - property->UpdateRequestFormInfo(formInfo); - property->UpdateCalcSelfIdealSize(CalcSize(NG::CalcLength(width), NG::CalcLength(height))); -} - void FormView::SetDimension(int32_t dimension) { auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); diff --git a/frameworks/core/components_ng/pattern/form/form_view.h b/frameworks/core/components_ng/pattern/form/form_view.h index 01b6f21e0c7..a882e4839f6 100644 --- a/frameworks/core/components_ng/pattern/form/form_view.h +++ b/frameworks/core/components_ng/pattern/form/form_view.h @@ -30,7 +30,6 @@ namespace OHOS::Ace::NG { class ACE_EXPORT FormView { public: static void Create(const RequestFormInfo& formInfo); - static void SetSize(const Dimension& width, const Dimension& height); static void SetDimension(int32_t dimension); static void SetAllowUpdate(bool allowUpdate); static void SetVisible(VisibleType visible); @@ -39,10 +38,6 @@ public: static void SetOnError(FormCallback&& onError); static void SetOnUninstall(FormCallback&& onUninstall); static void SetOnRouter(FormCallback&& onRouter); - -private: - static RefPtr GetOrCreateFormNode( - const std::string& tag, int32_t nodeId, const std::function(void)>& patternCreator); }; } // namespace OHOS::Ace::NG -- Gitee From 088c489987616c7feebf16e953571b936d0d544b Mon Sep 17 00:00:00 2001 From: caocan Date: Sun, 18 Sep 2022 13:56:07 +0800 Subject: [PATCH 4/4] =?UTF-8?q?[UI=E7=BB=84=E4=BB=B6=E9=87=8D=E6=9E=84]?= =?UTF-8?q?=E4=BF=AE=E5=A4=8Dcomments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: caocan Change-Id: I2da8ab54480916c419972f93a01ae084c9728bd0 --- .../declarative_frontend/jsview/js_form.cpp | 19 +++------ .../core/components/form/render_form.cpp | 2 +- .../core/components/form/sub_container.cpp | 14 ++++--- .../core/components/form/sub_container.h | 13 +++--- .../plugin/flutter_render_plugin.cpp | 2 +- .../core/components/plugin/render_plugin.cpp | 2 +- .../core/components_ng/base/frame_node.cpp | 38 +++++++++--------- .../components_ng/layout/layout_property.cpp | 7 ++-- .../components_ng/layout/layout_property.h | 8 ++-- .../components_ng/layout/layout_wrapper.cpp | 12 ------ .../components_ng/layout/layout_wrapper.h | 4 +- .../components_ng/pattern/form/form_node.cpp | 3 +- .../pattern/form/form_pattern.cpp | 4 -- .../components_ng/pattern/form/form_pattern.h | 1 - .../render/adapter/rosen_render_context.cpp | 2 +- .../pipeline/base/flutter_render_context.cpp | 2 +- .../pipeline/base/rosen_render_context.cpp | 2 +- frameworks/core/pipeline/pipeline_base.h | 39 ------------------ frameworks/core/pipeline/pipeline_context.h | 40 +++++++++++++++++++ .../core/pipeline_ng/pipeline_context.cpp | 1 - 20 files changed, 97 insertions(+), 118 deletions(-) diff --git a/frameworks/bridge/declarative_frontend/jsview/js_form.cpp b/frameworks/bridge/declarative_frontend/jsview/js_form.cpp index d8d45192519..5d4b7199c73 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_form.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_form.cpp @@ -72,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"); } @@ -87,9 +92,6 @@ void JSForm::SetSize(const JSCallbackInfo& info) width = StringUtils::StringToDimension(widthValue->ToString(), true); } } - if (!width.IsValid()) { - width = 0.0_vp; - } JSRef heightValue = sizeObj->GetProperty("height"); if (!heightValue->IsNull() && !heightValue->IsEmpty()) { @@ -99,18 +101,9 @@ void JSForm::SetSize(const JSCallbackInfo& info) height = StringUtils::StringToDimension(heightValue->ToString(), true); } } - if (!height.IsValid()) { - height = 0.0_vp; - } - - if (Container::IsCurrentUseNewPipeline()) { - JSViewAbstract::JsSize(info); - return; - } - auto form = AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetMainComponent()); if (form) { - form->SetCardSize(width, height); + form->SetCardSize(width.IsValid() ? width : 0.0_vp, height.IsValid() ? height : 0.0_vp); } } diff --git a/frameworks/core/components/form/render_form.cpp b/frameworks/core/components/form/render_form.cpp index 3df9e631cba..b47b8490b27 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; diff --git a/frameworks/core/components/form/sub_container.cpp b/frameworks/core/components/form/sub_container.cpp index 2bda6f77a09..51f41d090f9 100644 --- a/frameworks/core/components/form/sub_container.cpp +++ b/frameworks/core/components/form/sub_container.cpp @@ -140,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"); @@ -225,7 +225,7 @@ void SubContainer::RunCard(const int64_t id, const std::string path, const std:: CHECK_NULL_VOID(container); if (Container::IsCurrentUseNewPipeline()) { - auto form = container->GetFormPattern().Upgrade(); + auto form = container->GetFormPattern(); CHECK_NULL_VOID(form); form->OnActionEvent(action); } else { @@ -306,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; @@ -391,7 +391,9 @@ 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)); @@ -399,7 +401,7 @@ void SubContainer::GetImageDataFromAshmem( } void SubContainer::UpdateCard( - const std::string content, const std::map> imageDataMap) + 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 86c21622afd..616768e62bd 100644 --- a/frameworks/core/components/form/sub_container.h +++ b/frameworks/core/components/form/sub_container.h @@ -39,9 +39,10 @@ public: ~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, @@ -111,15 +112,15 @@ public: formPattern_ = formPattern; } - const WeakPtr& GetFormPattern() const + RefPtr GetFormPattern() const { - return formPattern_; + return formPattern_.Upgrade(); } private: RefPtr frontend_; RefPtr taskExecutor_; - RefPtr pipelineContext_; + RefPtr pipelineContext_; WeakPtr outSidePipelineContext_; RefPtr assetManager_; int32_t instanceId_; diff --git a/frameworks/core/components/plugin/flutter_render_plugin.cpp b/frameworks/core/components/plugin/flutter_render_plugin.cpp index 185a3854ede..a007dec4258 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 a9319baed98..a5d5dfae1ff 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; diff --git a/frameworks/core/components_ng/base/frame_node.cpp b/frameworks/core/components_ng/base/frame_node.cpp index da7fe94c2b4..d1bcf6925a4 100644 --- a/frameworks/core/components_ng/base/frame_node.cpp +++ b/frameworks/core/components_ng/base/frame_node.cpp @@ -242,10 +242,9 @@ std::optional FrameNode::CreateLayoutTask(bool forceUseMainThread) RefPtr layoutWrapper; UpdateLayoutPropertyFlag(); layoutWrapper = CreateLayoutWrapper(); - auto isActive = layoutProperty_->GetVisibility().value_or(VisibleType::VISIBLE) == VisibleType::VISIBLE; auto task = [layoutWrapper, layoutConstraint = GetLayoutConstraint(), offset = GetParentGlobalOffset(), - forceUseMainThread, isActive]() { - layoutWrapper->SetActive(isActive); + forceUseMainThread]() { + layoutWrapper->SetActive(); layoutWrapper->SetRootMeasureNode(); { ACE_SCOPED_TRACE("LayoutWrapper::Measure"); @@ -292,24 +291,17 @@ std::optional FrameNode::CreateRenderTask(bool forceUseMainThread) LayoutConstraintF FrameNode::GetLayoutConstraint() const { - auto visible = layoutProperty_->GetVisibility().value_or(VisibleType::VISIBLE); - LayoutConstraintF layoutConstraint; if (geometryNode_->GetParentLayoutConstraint().has_value()) { - layoutConstraint = geometryNode_->GetParentLayoutConstraint().value(); - } else { - 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); - } - - if (visible == VisibleType::GONE) { - layoutConstraint.selfIdealSize = OptionalSizeF(SizeF()); - layoutProperty_->UpdateCalcSelfIdealSize(CalcSize(CalcLength(0), CalcLength(0))); + return geometryNode_->GetParentLayoutConstraint().value(); } + 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; } @@ -345,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(); @@ -487,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/layout/layout_property.cpp b/frameworks/core/components_ng/layout/layout_property.cpp index dac5b50a264..3ba9826798e 100644 --- a/frameworks/core/components_ng/layout/layout_property.cpp +++ b/frameworks/core/components_ng/layout/layout_property.cpp @@ -215,18 +215,19 @@ void LayoutProperty::SetHost(const WeakPtr& host) host_ = host; } -const WeakPtr& LayoutProperty::GetHost() const +RefPtr LayoutProperty::GetHost() const { - return host_; + return host_.Upgrade(); } void LayoutProperty::OnVisibilityUpdate(VisibleType /* visible */) const { - auto host = GetHost().Upgrade(); + 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 6c1866f6eaa..34c618a7248 100644 --- a/frameworks/core/components_ng/layout/layout_property.h +++ b/frameworks/core/components_ng/layout/layout_property.h @@ -232,7 +232,10 @@ public: PaddingPropertyF CreatePaddingAndBorder(); void SetHost(const WeakPtr& host); - const WeakPtr& GetHost() const; + 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); @@ -254,9 +257,6 @@ private: std::unique_ptr flexItemProperty_; std::optional measureType_; - ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP_AND_USING_CALLBACK(Visibility, VisibleType, PROPERTY_UPDATE_MEASURE); - void OnVisibilityUpdate(VisibleType visible) const; - WeakPtr host_; ACE_DISALLOW_COPY_AND_MOVE(LayoutProperty); }; diff --git a/frameworks/core/components_ng/layout/layout_wrapper.cpp b/frameworks/core/components_ng/layout/layout_wrapper.cpp index 1ced3a5e9a5..e1e3414d9c0 100644 --- a/frameworks/core/components_ng/layout/layout_wrapper.cpp +++ b/frameworks/core/components_ng/layout/layout_wrapper.cpp @@ -117,21 +117,9 @@ void LayoutWrapper::Measure(const std::optional& parentConstr isContraintNoChanged_ = true; } - if (!host->IsVisible()) { - isActive_ = false; - } if (parentConstraint) { geometryNode_->SetParentLayoutConstraint(parentConstraint.value()); layoutProperty_->UpdateLayoutConstraint(parentConstraint.value()); - VisibleType visible = VisibleType::VISIBLE; - auto layoutProperty = host->GetLayoutProperty(); - if (layoutProperty) { - visible = layoutProperty->GetVisibility().value_or(VisibleType::VISIBLE); - } - if (visible == VisibleType::GONE) { - layoutProperty_->UpdateSelfIdealSize(SizeF()); - layoutProperty_->UpdateCalcSelfIdealSize(CalcSize(CalcLength(0), CalcLength(0))); - } } else { LayoutConstraintF layoutConstraint; layoutConstraint.percentReference.SetWidth(PipelineContext::GetCurrentRootWidth()); diff --git a/frameworks/core/components_ng/layout/layout_wrapper.h b/frameworks/core/components_ng/layout/layout_wrapper.h index 0195e14d372..7dc2640d433 100644 --- a/frameworks/core/components_ng/layout/layout_wrapper.h +++ b/frameworks/core/components_ng/layout/layout_wrapper.h @@ -119,9 +119,9 @@ public: return isActive_; } - void SetActive(bool isActive = true) + void SetActive() { - isActive_ = isActive; + isActive_ = true; } bool IsRootMeasureNode() const diff --git a/frameworks/core/components_ng/pattern/form/form_node.cpp b/frameworks/core/components_ng/pattern/form/form_node.cpp index b95fbae4c40..7c50aed3883 100644 --- a/frameworks/core/components_ng/pattern/form/form_node.cpp +++ b/frameworks/core/components_ng/pattern/form/form_node.cpp @@ -18,6 +18,7 @@ #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 { @@ -33,7 +34,7 @@ HitTestResult FormNode::TouchTest(const PointF& globalPoint, const PointF& paren CHECK_NULL_RETURN(pattern, HitTestResult::BUBBLING); auto subContainer = pattern->GetSubContainer(); CHECK_NULL_RETURN(subContainer, HitTestResult::BUBBLING); - auto subContext = subContainer->GetPipelineContext(); + auto subContext = DynamicCast(subContainer->GetPipelineContext()); CHECK_NULL_RETURN(subContext, HitTestResult::BUBBLING); auto selfGlobalOffset = GetGeometryNode()->GetParentGlobalOffset() + GetGeometryNode()->GetFrameOffset(); subContext->SetPluginEventOffset(Offset(selfGlobalOffset.GetX(), selfGlobalOffset.GetY())); diff --git a/frameworks/core/components_ng/pattern/form/form_pattern.cpp b/frameworks/core/components_ng/pattern/form/form_pattern.cpp index 527dfe53f84..13fa6f8b0c6 100644 --- a/frameworks/core/components_ng/pattern/form/form_pattern.cpp +++ b/frameworks/core/components_ng/pattern/form/form_pattern.cpp @@ -36,10 +36,6 @@ void FormPattern::OnAttachToFrameNode() auto host = GetHost(); CHECK_NULL_VOID(host); host->GetRenderContext()->SetClipToFrame(true); -} - -void FormPattern::OnModifyDone() -{ InitFormManagerDelegate(); } diff --git a/frameworks/core/components_ng/pattern/form/form_pattern.h b/frameworks/core/components_ng/pattern/form/form_pattern.h index ed4816e95f7..6c67bf57b7b 100644 --- a/frameworks/core/components_ng/pattern/form/form_pattern.h +++ b/frameworks/core/components_ng/pattern/form/form_pattern.h @@ -53,7 +53,6 @@ public: const RefPtr& GetSubContainer() const; private: - void OnModifyDone() override; void OnAttachToFrameNode() override; bool OnDirtyLayoutWrapperSwap(const RefPtr& dirty, const DirtySwapConfig& config) override; diff --git a/frameworks/core/components_ng/render/adapter/rosen_render_context.cpp b/frameworks/core/components_ng/render/adapter/rosen_render_context.cpp index 5c499f028af..0c515796cfe 100644 --- a/frameworks/core/components_ng/render/adapter/rosen_render_context.cpp +++ b/frameworks/core/components_ng/render/adapter/rosen_render_context.cpp @@ -297,7 +297,7 @@ void RosenRenderContext::ReCreateRsNodeTree(const std::list>& continue; } auto rsnode = rosenRenderContext->GetRSNode(); - if (rsnode && child->IsVisible()) { + if (rsnode) { rsNode_->AddChild(rsnode, -1); } } diff --git a/frameworks/core/pipeline/base/flutter_render_context.cpp b/frameworks/core/pipeline/base/flutter_render_context.cpp index df6baaf7496..8ae247ea0b7 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/rosen_render_context.cpp b/frameworks/core/pipeline/base/rosen_render_context.cpp index 05a1f5a2c60..9e69ef65a3f 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.h b/frameworks/core/pipeline/pipeline_base.h index 87a6f16a518..bd5bf681fba 100644 --- a/frameworks/core/pipeline/pipeline_base.h +++ b/frameworks/core/pipeline/pipeline_base.h @@ -492,41 +492,6 @@ public: void SetTouchPipeline(const WeakPtr& context); void RemoveTouchPipeline(const WeakPtr& context); - void SetPluginOffset(const Offset& offset) - { - pluginOffset_ = offset; - } - - Offset GetPluginOffset() const - { - return pluginOffset_; - } - - void SetPluginEventOffset(const Offset& offset) - { - pluginEventOffset_ = offset; - } - - Offset GetPluginEventOffset() const - { - return pluginEventOffset_; - } - - const RefPtr& GetSharedImageManager() const - { - return sharedImageManager_; - } - - void SetSharedImageManager(const RefPtr& sharedImageManager) - { - sharedImageManager_ = sharedImageManager; - } - - void SetDrawDelegate(std::unique_ptr delegate) - { - drawDelegate_ = std::move(delegate); - } - protected: virtual bool OnDumpInfo(const std::vector& params) const { @@ -572,11 +537,7 @@ protected: StartAbilityHandler startAbilityHandler_; ActionEventHandler actionEventHandler_; - Offset pluginOffset_ { 0, 0 }; - Offset pluginEventOffset_ { 0, 0 }; std::vector> touchPluginPipelineContext_; - RefPtr sharedImageManager_; - std::unique_ptr drawDelegate_; private: StatusBarEventHandler statusBarBgColorEventHandler_; diff --git a/frameworks/core/pipeline/pipeline_context.h b/frameworks/core/pipeline/pipeline_context.h index 3e8e4ce5ade..17f3073e9b9 100644 --- a/frameworks/core/pipeline/pipeline_context.h +++ b/frameworks/core/pipeline/pipeline_context.h @@ -511,6 +511,11 @@ public: void MovePage(const Offset& rootRect, double offsetHeight); + void SetDrawDelegate(std::unique_ptr delegate) + { + drawDelegate_ = std::move(delegate); + } + void SetBuildAfterCallback(const std::function& callback) override { buildAfterCallback_.emplace_back(callback); @@ -567,6 +572,16 @@ public: return buildingFirstPage_; } + const RefPtr& GetSharedImageManager() const + { + return sharedImageManager_; + } + + void SetSharedImageManager(const RefPtr& sharedImageManager) + { + sharedImageManager_ = sharedImageManager; + } + using UpdateWindowBlurDrawOpHandler = std::function; void SetUpdateWindowBlurDrawOpHandler(UpdateWindowBlurDrawOpHandler handler) @@ -752,6 +767,26 @@ public: return isHoleValid_; } + void SetPluginOffset(const Offset& offset) + { + pluginOffset_ = offset; + } + + Offset GetPluginOffset() const + { + return pluginOffset_; + } + + void SetPluginEventOffset(const Offset& offset) + { + pluginEventOffset_ = offset; + } + + Offset GetPluginEventOffset() const + { + return pluginEventOffset_; + } + void SetRSUIDirector(std::shared_ptr rsUIDirector); std::shared_ptr GetRSUIDirector(); @@ -1110,6 +1145,7 @@ private: RefPtr rootElement_; WeakPtr dirtyFocusNode_; WeakPtr dirtyFocusScope_; + RefPtr sharedImageManager_; std::list> buildAfterCallback_; RefPtr renderFactory_; UpdateWindowBlurRegionHandler updateWindowBlurRegionHandler_; @@ -1185,6 +1221,7 @@ private: uint32_t modalColor_ = 0x00000000; bool isFullWindow_ = false; std::list> hoverNodes_; + std::unique_ptr drawDelegate_; std::function&&)> screenOffCallback_; std::function&&)> screenOnCallback_; #if defined(ENABLE_NATIVE_VIEW) @@ -1207,6 +1244,9 @@ private: SurfaceChangedCallbackMap surfaceChangedCallbackMap_; SurfacePositionChangedCallbackMap surfacePositionChangedCallbackMap_; + Offset pluginOffset_ { 0, 0 }; + Offset pluginEventOffset_ { 0, 0 }; + bool isShiftDown_ = false; bool isCtrlDown_ = false; bool isKeyboardA_ = false; diff --git a/frameworks/core/pipeline_ng/pipeline_context.cpp b/frameworks/core/pipeline_ng/pipeline_context.cpp index 6befeea17fd..c0ed77ba980 100644 --- a/frameworks/core/pipeline_ng/pipeline_context.cpp +++ b/frameworks/core/pipeline_ng/pipeline_context.cpp @@ -29,7 +29,6 @@ #include "core/common/container.h" #include "core/common/thread_checker.h" #include "core/common/window.h" -#include "core/components/box/drag_drop_event.h" #include "core/components_ng/base/frame_node.h" #include "core/components_ng/pattern/custom/custom_node.h" #include "core/components_ng/pattern/overlay/overlay_manager.h" -- Gitee