diff --git a/frameworks/core/components_ng/pattern/form/form_model_ng.cpp b/frameworks/core/components_ng/pattern/form/form_model_ng.cpp index c28396e5da0a9c162208156e1370df55e1660697..cfe3d21e26b4fd3bcc1d56059a95aaebbba0c352 100644 --- a/frameworks/core/components_ng/pattern/form/form_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/form/form_model_ng.cpp @@ -29,6 +29,20 @@ #include "core/components/common/layout/constants.h" namespace OHOS::Ace::NG { +RefPtr FormModelNG::CreateFrameNode(int32_t nodeId) +{ + auto* stack = ViewStackProcessor::GetInstance(); + if (stack == nullptr) { + LOGE("stack is nullptr"); + return nullptr; + } + ACE_LAYOUT_SCOPED_TRACE("Create[%s][self:%d]", V2::FORM_ETS_TAG, nodeId); + auto frameNode = + FormNode::GetOrCreateFormNode(V2::FORM_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr(); }); + stack->Push(frameNode); + return frameNode; +} + void FormModelNG::Create(const RequestFormInfo& formInfo) { auto* stack = ViewStackProcessor::GetInstance(); @@ -188,61 +202,4 @@ void FormModelNG::SetOnUpdate(std::function&& onUpdate eventHub->SetOnUpdate(std::move(onUpdate)); } -void FormModelNG::SetVisibility(FrameNode* frameNode, VisibleType visible) -{ - CHECK_NULL_VOID(frameNode); - auto formPattern = frameNode->GetPattern(); - CHECK_NULL_VOID(formPattern); - auto isLoaded = formPattern->GetIsLoaded(); - auto layoutProperty = frameNode->GetLayoutProperty(); - CHECK_NULL_VOID(layoutProperty); - if (isLoaded || visible != VisibleType::VISIBLE) { - layoutProperty->UpdateVisibility(visible, true); - } else { - layoutProperty->UpdateVisibility(VisibleType::INVISIBLE, true); - } - - ACE_UPDATE_NODE_LAYOUT_PROPERTY(FormLayoutProperty, VisibleType, visible, frameNode); -} - -void FormModelNG::AllowUpdate(FrameNode* frameNode, bool allowUpdate) -{ - 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 FormModelNG::SetDimension(FrameNode* frameNode, int32_t dimension) -{ - CHECK_NULL_VOID(frameNode); - auto property = frameNode->GetLayoutProperty(); - CHECK_NULL_VOID(property); - if (!property->HasRequestFormInfo()) { - return; - } - auto formInfo = property->GetRequestFormInfoValue(); - formInfo.dimension = dimension; - ACE_UPDATE_NODE_LAYOUT_PROPERTY(FormLayoutProperty, RequestFormInfo, formInfo, frameNode); -} - -void FormModelNG::SetModuleName(FrameNode* frameNode, const std::string& moduleName) -{ - 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 FormModelNG::SetSize(FrameNode* frameNode, const Dimension& width, const Dimension& height) {} } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/form/form_model_ng.h b/frameworks/core/components_ng/pattern/form/form_model_ng.h index a67fdc01777d6271609f5fd42018d151174b0279..3d963657b823202420dbef0aaa8e3160098adf03 100644 --- a/frameworks/core/components_ng/pattern/form/form_model_ng.h +++ b/frameworks/core/components_ng/pattern/form/form_model_ng.h @@ -46,19 +46,8 @@ public: void SetObscured(const std::vector& reasons) override; static RefPtr CreateFrameNode(int32_t nodeId); - static void UpdateProperty(const RequestFormInfo& formInfo); - static void SetVisibility(FrameNode* frameNode, VisibleType visible); - static void AllowUpdate(FrameNode* frameNode, bool value); - static void SetDimension(FrameNode* frameNode, int32_t value); - static void SetModuleName(FrameNode* frameNode, const std::string& value); - static void SetSize(FrameNode* frameNode, const Dimension& width, const Dimension& height); int32_t RequestPublishFormWithSnapshot(const AAFwk::Want& want, const std::string& formBindingDataStr, int64_t& formId, std::string &errMsg) override; - static void SetOnAcquired(FrameNode* frameNode, std::function&& onAcquired); - static void SetOnError(FrameNode* frameNode, std::function&& onError); - static void SetOnUninstall(FrameNode* frameNode, std::function&& onUninstall); - static void SetOnLoad(FrameNode* frameNode, std::function&& onLoad); - static void SetOnRouter(FrameNode* frameNode, std::function&& onRouter); }; } // namespace OHOS::Ace::NG #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_FORM_MODEL_NG_H diff --git a/frameworks/core/components_ng/pattern/form/form_model_static_ng.cpp b/frameworks/core/components_ng/pattern/form/form_model_static_ng.cpp index 87256d66f058927df6fd2f05544900ae2b8d9897..487a657a4dc3b29d58dcc715ba78eb3f94989a11 100644 --- a/frameworks/core/components_ng/pattern/form/form_model_static_ng.cpp +++ b/frameworks/core/components_ng/pattern/form/form_model_static_ng.cpp @@ -15,89 +15,75 @@ #include "core/components_ng/base/view_abstract.h" #include "core/components_ng/base/view_stack_processor.h" -#include "core/components_ng/pattern/form/form_model_ng.h" +#include "core/components_ng/pattern/form/form_model_static_ng.h" #include "core/components_ng/pattern/form/form_layout_property.h" #include "core/components_ng/pattern/form/form_pattern.h" namespace OHOS::Ace::NG { -RefPtr FormModelNG::CreateFrameNode(int32_t nodeId) -{ - auto* stack = ViewStackProcessor::GetInstance(); - if (stack == nullptr) { - LOGE("stack is nullptr"); - return nullptr; - } - ACE_LAYOUT_SCOPED_TRACE("Create[%s][self:%d]", V2::FORM_ETS_TAG, nodeId); - auto frameNode = FormNode::GetOrCreateFormNode( - V2::FORM_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr(); }); - stack->Push(frameNode); - return frameNode; -} - -void FormModelNG::UpdateProperty(const RequestFormInfo& formInfo) +void FormModelStatic::UpdateProperty(const RequestFormInfo& formInfo) { ACE_UPDATE_LAYOUT_PROPERTY(FormLayoutProperty, RequestFormInfo, formInfo); ACE_UPDATE_LAYOUT_PROPERTY(LayoutProperty, Visibility, VisibleType::INVISIBLE); ACE_UPDATE_LAYOUT_PROPERTY(FormLayoutProperty, VisibleType, VisibleType::VISIBLE); } -// void FormModelNG::AllowUpdate(FrameNode* frameNode, bool allowUpdate) -// { -// 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 FormModelStatic::SetVisibility(FrameNode* frameNode, VisibleType visible) +{ + CHECK_NULL_VOID(frameNode); + auto formPattern = frameNode->GetPattern(); + CHECK_NULL_VOID(formPattern); + auto isLoaded = formPattern->GetIsLoaded(); + auto layoutProperty = frameNode->GetLayoutProperty(); + CHECK_NULL_VOID(layoutProperty); + if (isLoaded || visible != VisibleType::VISIBLE) { + layoutProperty->UpdateVisibility(visible, true); + } else { + layoutProperty->UpdateVisibility(VisibleType::INVISIBLE, true); + } -// void FormModelNG::SetVisibility(FrameNode* frameNode, VisibleType visible) -// { -// CHECK_NULL_VOID(frameNode); -// auto formPattern = frameNode->GetPattern(); -// CHECK_NULL_VOID(formPattern); -// auto isLoaded = formPattern->GetIsLoaded(); -// auto layoutProperty = frameNode->GetLayoutProperty(); -// CHECK_NULL_VOID(layoutProperty); -// if (isLoaded || visible != VisibleType::VISIBLE) { -// layoutProperty->UpdateVisibility(visible, true); -// } else { -// layoutProperty->UpdateVisibility(VisibleType::INVISIBLE, true); -// } -// ACE_UPDATE_NODE_LAYOUT_PROPERTY(FormLayoutProperty, VisibleType, visible, frameNode); -// } + ACE_UPDATE_NODE_LAYOUT_PROPERTY(FormLayoutProperty, VisibleType, visible, frameNode); +} -// void FormModelNG::SetDimension(FrameNode* frameNode, int32_t dimension) -// { -// CHECK_NULL_VOID(frameNode); -// auto property = frameNode->GetLayoutProperty(); -// CHECK_NULL_VOID(property); -// if (!property->HasRequestFormInfo()) { -// return; -// } -// auto formInfo = property->GetRequestFormInfoValue(); -// formInfo.dimension = dimension; -// ACE_UPDATE_NODE_LAYOUT_PROPERTY(FormLayoutProperty, RequestFormInfo, formInfo, frameNode); -// } +void FormModelStatic::AllowUpdate(FrameNode* frameNode, bool allowUpdate) +{ + 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 FormModelNG::SetModuleName(FrameNode* frameNode, const std::string& moduleName) -// { -// 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 FormModelStatic::SetDimension(FrameNode* frameNode, int32_t dimension) +{ + CHECK_NULL_VOID(frameNode); + auto property = frameNode->GetLayoutProperty(); + CHECK_NULL_VOID(property); + if (!property->HasRequestFormInfo()) { + return; + } + auto formInfo = property->GetRequestFormInfoValue(); + formInfo.dimension = dimension; + ACE_UPDATE_NODE_LAYOUT_PROPERTY(FormLayoutProperty, RequestFormInfo, formInfo, frameNode); +} + +void FormModelStatic::SetModuleName(FrameNode* frameNode, const std::string& moduleName) +{ + 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 FormModelNG::SetSize(FrameNode* frameNode, const Dimension& width, const Dimension& height) {} -void FormModelNG::SetSize(FrameNode* frameNode, const Dimension& width, const Dimension& height) +void FormModelStatic::SetSize(FrameNode* frameNode, const Dimension& width, const Dimension& height) { CHECK_NULL_VOID(frameNode); auto property = frameNode->GetLayoutProperty(); @@ -111,39 +97,46 @@ void FormModelNG::SetSize(FrameNode* frameNode, const Dimension& width, const Di ACE_UPDATE_NODE_LAYOUT_PROPERTY(FormLayoutProperty, RequestFormInfo, formInfo, frameNode); } -void FormModelNG::SetOnAcquired(FrameNode* frameNode, std::function&& onAcquired) +void FormModelStatic::SetOnAcquired(FrameNode* frameNode, std::function&& onAcquired) { CHECK_NULL_VOID(frameNode); auto eventHub = frameNode->GetEventHub(); CHECK_NULL_VOID(eventHub); eventHub->SetOnAcquired(std::move(onAcquired)); } -void FormModelNG::SetOnError(FrameNode* frameNode, std::function&& onError) +void FormModelStatic::SetOnError(FrameNode* frameNode, std::function&& onError) { CHECK_NULL_VOID(frameNode); auto eventHub = frameNode->GetEventHub(); CHECK_NULL_VOID(eventHub); eventHub->SetOnError(std::move(onError)); } -void FormModelNG::SetOnUninstall(FrameNode* frameNode, std::function&& onUninstall) +void FormModelStatic::SetOnUninstall(FrameNode* frameNode, std::function&& onUninstall) { CHECK_NULL_VOID(frameNode); auto eventHub = frameNode->GetEventHub(); CHECK_NULL_VOID(eventHub); eventHub->SetOnUninstall(std::move(onUninstall)); } -void FormModelNG::SetOnLoad(FrameNode* frameNode, std::function&& onLoad) +void FormModelStatic::SetOnLoad(FrameNode* frameNode, std::function&& onLoad) { CHECK_NULL_VOID(frameNode); auto eventHub = frameNode->GetEventHub(); CHECK_NULL_VOID(eventHub); eventHub->SetOnLoad(std::move(onLoad)); } -void FormModelNG::SetOnRouter(FrameNode* frameNode, std::function&& onRouter) +void FormModelStatic::SetOnRouter(FrameNode* frameNode, std::function&& onRouter) { CHECK_NULL_VOID(frameNode); auto eventHub = frameNode->GetEventHub(); CHECK_NULL_VOID(eventHub); eventHub->SetOnRouter(std::move(onRouter)); } +void FormModelStatic::SetOnUpdate(FrameNode* frameNode, std::function&& onUpdate) +{ + CHECK_NULL_VOID(frameNode); + auto eventHub = frameNode->GetOrCreateEventHub(); + CHECK_NULL_VOID(eventHub); + eventHub->SetOnUpdate(std::move(onUpdate)); +} } // namespace OHOS::Ace::NG \ No newline at end of file diff --git a/frameworks/core/components_ng/pattern/form/form_model_static_ng.h b/frameworks/core/components_ng/pattern/form/form_model_static_ng.h new file mode 100644 index 0000000000000000000000000000000000000000..8d1962c5da788f6b458732abb5bb4c4eac7b5961 --- /dev/null +++ b/frameworks/core/components_ng/pattern/form/form_model_static_ng.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_FORM_MODEL_STATIC_NG_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_FORM_MODEL_STATIC_NG_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/base/frame_node.h" +#include "core/components_ng/pattern/form/form_event_hub.h" +#include "core/components_ng/pattern/form/form_model.h" +#include "core/components_ng/pattern/form/form_node.h" + +namespace OHOS::Ace::NG { +class ACE_EXPORT FormModelStatic { +public: + static void UpdateProperty(const RequestFormInfo& formInfo); + static void SetVisibility(FrameNode* frameNode, VisibleType visible); + static void AllowUpdate(FrameNode* frameNode, bool value); + static void SetDimension(FrameNode* frameNode, int32_t value); + static void SetModuleName(FrameNode* frameNode, const std::string& value); + static void SetSize(FrameNode* frameNode, const Dimension& width, const Dimension& height); + static void SetOnAcquired(FrameNode* frameNode, std::function&& onAcquired); + static void SetOnError(FrameNode* frameNode, std::function&& onError); + static void SetOnUninstall(FrameNode* frameNode, std::function&& onUninstall); + static void SetOnLoad(FrameNode* frameNode, std::function&& onLoad); + static void SetOnRouter(FrameNode* frameNode, std::function&& onRouter); + static void SetOnUpdate(FrameNode* frameNode, std::function&& onUpdate); +}; +} // namespace OHOS::Ace::NG +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_FORM_MODEL_STATIC_NG_H diff --git a/frameworks/core/interfaces/native/implementation/form_component_modifier.cpp b/frameworks/core/interfaces/native/implementation/form_component_modifier.cpp index 9dac244536ca79c050725c42acc2bb5500b5ac15..a3574151c11c80a56bbe4e98d069bd5aa4319f20 100644 --- a/frameworks/core/interfaces/native/implementation/form_component_modifier.cpp +++ b/frameworks/core/interfaces/native/implementation/form_component_modifier.cpp @@ -16,6 +16,7 @@ #include "core/components_ng/base/frame_node.h" #ifdef FORM_SUPPORTED #include "core/components_ng/pattern/form/form_model_ng.h" +#include "core/components_ng/pattern/form/form_model_static_ng.h" #endif #include "core/interfaces/native/utility/converter.h" #include "core/interfaces/native/utility/reverse_converter.h" @@ -153,9 +154,9 @@ void SetFormComponentOptionsImpl(Ark_NativePointer node, CHECK_NULL_VOID(frameNode); CHECK_NULL_VOID(value); auto formInfo = Converter::Convert(*value); - FormModelNG::SetModuleName(frameNode, formInfo.module); + FormModelStatic::SetModuleName(frameNode, formInfo.module); if (formInfo.dimension) { - FormModelNG::SetDimension(frameNode, *formInfo.dimension); + FormModelStatic::SetDimension(frameNode, *formInfo.dimension); } LOGE("ARKOALA FormComponentInterfaceModifier::SetFormComponentOptionsImpl - CustomObject is not supported " "the type Ark_FormInfo::Opt_Want::Opt_Map_String_CustomObject::Ark_CustomObject."); @@ -176,7 +177,7 @@ void SetSizeImpl(Ark_NativePointer node, .height = 0.0_vp, }; } - FormModelNG::SetSize(frameNode, dimension->width, dimension->height); + FormModelStatic::SetSize(frameNode, dimension->width, dimension->height); #endif // FORM_SUPPORTED } void SetModuleNameImpl(Ark_NativePointer node, @@ -186,7 +187,7 @@ void SetModuleNameImpl(Ark_NativePointer node, auto frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); auto convValue = Converter::OptConvertPtr(value).value_or(FormComponentModifier::DEFAULT_MODULE_NAME); - FormModelNG::SetModuleName(frameNode, convValue); + FormModelStatic::SetModuleName(frameNode, convValue); #endif // FORM_SUPPORTED } void SetDimensionImpl(Ark_NativePointer node, @@ -196,7 +197,7 @@ void SetDimensionImpl(Ark_NativePointer node, auto frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); auto convValue = Converter::OptConvertPtr(value).value_or(FormComponentModifier::DEFAULT_DIMENSION); - FormModelNG::SetDimension(frameNode, convValue); + FormModelStatic::SetDimension(frameNode, convValue); #endif // FORM_SUPPORTED } void SetAllowUpdateImpl(Ark_NativePointer node, @@ -206,7 +207,7 @@ void SetAllowUpdateImpl(Ark_NativePointer node, auto frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); auto convValue = Converter::OptConvertPtr(value).value_or(FormComponentModifier::DEFAULT_ALLOW_UPDATE); - FormModelNG::AllowUpdate(frameNode, convValue); + FormModelStatic::AllowUpdate(frameNode, convValue); #endif // FORM_SUPPORTED } void SetVisibilityImpl(Ark_NativePointer node, @@ -217,7 +218,7 @@ void SetVisibilityImpl(Ark_NativePointer node, CHECK_NULL_VOID(frameNode); auto opt = Converter::OptConvertPtr(value); CHECK_NULL_VOID(opt); - FormModelNG::SetVisibility(frameNode, *opt); + FormModelStatic::SetVisibility(frameNode, *opt); #endif // FORM_SUPPORTED } void SetOnAcquiredImpl(Ark_NativePointer node, @@ -247,7 +248,7 @@ void SetOnAcquiredImpl(Ark_NativePointer node, }; arkCallback.Invoke(parameter); }; - FormModelNG::SetOnAcquired(frameNode, onAcquired); + FormModelStatic::SetOnAcquired(frameNode, onAcquired); #endif // FORM_SUPPORTED } void SetOnErrorImpl(Ark_NativePointer node, @@ -275,7 +276,7 @@ void SetOnErrorImpl(Ark_NativePointer node, .msg = Converter::ArkValue(msg) }; arkCallback.Invoke(parameter); }; - FormModelNG::SetOnError(frameNode, onError); + FormModelStatic::SetOnError(frameNode, onError); #endif // FORM_SUPPORTED } void SetOnRouterImpl(Ark_NativePointer node, @@ -315,7 +316,7 @@ void SetOnUninstallImpl(Ark_NativePointer node, }; arkCallback.Invoke(parameter); }; - FormModelNG::SetOnUninstall(frameNode, onUninstall); + FormModelStatic::SetOnUninstall(frameNode, onUninstall); #endif // FORM_SUPPORTED } void SetOnLoadImpl(Ark_NativePointer node, @@ -329,14 +330,36 @@ void SetOnLoadImpl(Ark_NativePointer node, auto onLoad = [arkCallback](const std::string& param) { arkCallback.Invoke(); }; - FormModelNG::SetOnLoad(frameNode, std::move(onLoad)); + FormModelStatic::SetOnLoad(frameNode, std::move(onLoad)); #endif // FORM_SUPPORTED } void SetOnUpdateImpl(Ark_NativePointer node, const Opt_Callback_FormCallbackInfo_Void* value) { +#ifdef FORM_SUPPORTED auto frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); + auto optValue = Converter::GetOptPtr(value); + auto arkCallback = optValue ? CallbackHelper(*optValue) : CallbackHelper(); + auto onUpdate = [arkCallback](const std::string& param) { + int64_t id = FORM_ON_ACQUIRED_ID_INVALID; + std::string idString = FORM_ON_ACQUIRED_ID_STRING_INVALID; + auto sourceJson = JsonUtil::ParseJsonString(param); + if (sourceJson && !sourceJson->IsNull()) { + char* endptr; + auto jsonId = sourceJson->GetString(FORM_COMPONENT_ID_KEY, FORM_ON_ACQUIRED_ID_STRING_INVALID); + idString = sourceJson->GetString(FORM_COMPONENT_ID_STRING_KEY, FORM_ON_ACQUIRED_ID_STRING_INVALID); + int64_t result = std::strtoul(jsonId.c_str(), &endptr, 10); + if (*endptr == '\0') { + id = result; + } + } + Ark_FormCallbackInfo parameter = { .id = Converter::ArkValue(id), + .idString = Converter::ArkValue(idString) }; + arkCallback.Invoke(parameter); + }; + FormModelStatic::SetOnUpdate(frameNode, onUpdate); +#endif // FORM_SUPPORTED } } // FormComponentAttributeModifier const GENERATED_ArkUIFormComponentModifier* GetFormComponentModifier() diff --git a/frameworks/core/interfaces/native/implementation/image_bitmap_accessor.cpp b/frameworks/core/interfaces/native/implementation/image_bitmap_accessor.cpp index 592b35340c32d9fe986e42ce19d2bfe5c93b8062..ad0f3c82a70e5c022546cc674f1fd466c52215f1 100644 --- a/frameworks/core/interfaces/native/implementation/image_bitmap_accessor.cpp +++ b/frameworks/core/interfaces/native/implementation/image_bitmap_accessor.cpp @@ -39,6 +39,10 @@ Ark_ImageBitmap ConstructImpl(const Ark_Union_PixelMap_String* src, peer->SetOptions("", src->pixelMap); }, []() {}); + auto optUnit = Converter::OptConvertPtr(unit); + if (optUnit) { + peer->SetUnit(optUnit.value()); + } return peer; } Ark_NativePointer GetFinalizerImpl() @@ -59,6 +63,10 @@ Ark_Number GetHeightImpl(Ark_ImageBitmap peer) void SetHeightImpl(Ark_ImageBitmap peer, const Ark_Number* height) { + CHECK_NULL_VOID(peer); + CHECK_NULL_VOID(height); + auto value = Converter::Convert(*height); + peer->SetHeight(value); } Ark_Number GetWidthImpl(Ark_ImageBitmap peer) { @@ -69,6 +77,10 @@ Ark_Number GetWidthImpl(Ark_ImageBitmap peer) void SetWidthImpl(Ark_ImageBitmap peer, const Ark_Number* width) { + CHECK_NULL_VOID(peer); + CHECK_NULL_VOID(width); + auto value = Converter::Convert(*width); + peer->SetWidth(value); } } // ImageBitmapAccessor const GENERATED_ArkUIImageBitmapAccessor* GetImageBitmapAccessor() diff --git a/frameworks/core/interfaces/native/node/form_component_modifier.cpp b/frameworks/core/interfaces/native/node/form_component_modifier.cpp index 1df2484fa9694de1661a004d8f83d78810db9498..6fd5a29c187ac3a12c91eab3aa0744c87b98e25b 100644 --- a/frameworks/core/interfaces/native/node/form_component_modifier.cpp +++ b/frameworks/core/interfaces/native/node/form_component_modifier.cpp @@ -15,7 +15,7 @@ #include "core/interfaces/native/node/form_component_modifier.h" -#include "core/components_ng/pattern/form/form_model_ng.h" +#include "core/components_ng/pattern/form/form_model_static_ng.h" namespace OHOS::Ace::NG { const int32_t DEFAULT_VISIBILITY = 0; @@ -26,21 +26,21 @@ void SetFormVisibility(ArkUINodeHandle node, ArkUI_Int32 visible) auto* frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); VisibleType visibility = static_cast(visible); - FormModelNG::SetVisibility(frameNode, visibility); + FormModelStatic::SetVisibility(frameNode, visibility); } void AllowUpdate(ArkUINodeHandle node, ArkUI_Bool value) { auto* frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); - FormModelNG::AllowUpdate(frameNode, value); + FormModelStatic::AllowUpdate(frameNode, value); } void SetDimension(ArkUINodeHandle node, ArkUI_Int32 dimension) { auto* frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); - FormModelNG::SetDimension(frameNode, dimension); + FormModelStatic::SetDimension(frameNode, dimension); } void SetModuleName(ArkUINodeHandle node, const char* value) @@ -48,7 +48,7 @@ void SetModuleName(ArkUINodeHandle node, const char* value) auto* frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); std::string moduleName(value); - FormModelNG::SetModuleName(frameNode, moduleName); + FormModelStatic::SetModuleName(frameNode, moduleName); } void SetFormSize(ArkUINodeHandle node, ArkUI_Float32 widthValue, ArkUI_Int32 widthUnit, @@ -56,7 +56,7 @@ void SetFormSize(ArkUINodeHandle node, ArkUI_Float32 widthValue, ArkUI_Int32 wid { auto* frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); - FormModelNG::SetSize(frameNode, + FormModelStatic::SetSize(frameNode, Dimension(widthValue, static_cast(widthUnit)), Dimension(heightValue, static_cast(heightUnit))); } @@ -66,21 +66,21 @@ void ResetFormVisibility(ArkUINodeHandle node) auto* frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); VisibleType visibility = static_cast(DEFAULT_VISIBILITY); - FormModelNG::SetVisibility(frameNode, visibility); + FormModelStatic::SetVisibility(frameNode, visibility); } void DisallowUpdate(ArkUINodeHandle node) { auto* frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); - FormModelNG::AllowUpdate(frameNode, DEFAULT_ALLOW_UPDATE); + FormModelStatic::AllowUpdate(frameNode, DEFAULT_ALLOW_UPDATE); } void ResetDimension(ArkUINodeHandle node) { auto* frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); - FormModelNG::SetDimension(frameNode, DEFAULT_FORM_DIM); + FormModelStatic::SetDimension(frameNode, DEFAULT_FORM_DIM); } void ResetModuleName(ArkUINodeHandle node) {} @@ -91,7 +91,7 @@ void ResetFormSize(ArkUINodeHandle node) CHECK_NULL_VOID(frameNode); Dimension width = 0.0_vp; Dimension height = 0.0_vp; - FormModelNG::SetSize(frameNode, width, height); + FormModelStatic::SetSize(frameNode, width, height); } namespace NodeModifier { diff --git a/test/unittest/capi/accessors/image_bitmap_accessor_test.cpp b/test/unittest/capi/accessors/image_bitmap_accessor_test.cpp index 64dc99d678bef1e24fe290de2020cefd31111e80..68125234a3a4f0f33406a60892b9d0c40c2d67fa 100644 --- a/test/unittest/capi/accessors/image_bitmap_accessor_test.cpp +++ b/test/unittest/capi/accessors/image_bitmap_accessor_test.cpp @@ -30,6 +30,17 @@ const std::string DEFAULT_STRING_VALUE = "text"; const int DEFAULT_INT_VALUE = 100; const Ark_Int32 DEFAULT_HEIGHT_VALUE = 0; const Ark_Int32 DEFAULT_WIDTH_VALUE = 0; +const auto DEFAULT_RESOURCE = Converter::ArkUnion(DEFAULT_STRING_VALUE); +const auto DEFAULT_METRICS = Converter::ArkValue(Ace::CanvasUnit::PX); + +std::vector> arkNumberTestPlan = { + { Converter::ArkValue(100), 100 }, + { Converter::ArkValue(0), 0 }, + { Converter::ArkValue(-100), -100 }, + { Converter::ArkValue(12.34), 12.34 }, + { Converter::ArkValue(-56.73), -56.73 }, +}; + namespace { struct MockImageBitmapPeer : public ImageBitmapPeer { public: @@ -46,7 +57,7 @@ public: static void SetUpTestCase() { ASSERT_NE(accessor_, nullptr); - ASSERT_NE(accessor_->ctor, nullptr); + ASSERT_NE(accessor_->construct, nullptr); finalyzer_ = reinterpret_cast(accessor_->getFinalizer()); ASSERT_NE(accessor_->getFinalizer, nullptr); } @@ -90,8 +101,7 @@ public: */ HWTEST_F(ImageBitmapAccessorTest, close_success, TestSize.Level1) { - auto imageResource = Converter::ArkValue(DEFAULT_STRING_VALUE, Converter::FC); - peer_ = reinterpret_cast(accessor_->ctor(&imageResource)); + peer_ = reinterpret_cast(accessor_->construct(&DEFAULT_RESOURCE, &DEFAULT_METRICS)); bool result = false; auto clouseFunc = [&result]() { result = true; @@ -111,8 +121,7 @@ HWTEST_F(ImageBitmapAccessorTest, close_success, TestSize.Level1) */ HWTEST_F(ImageBitmapAccessorTest, getHeight, TestSize.Level1) { - auto imageResource = Converter::ArkValue(DEFAULT_STRING_VALUE, Converter::FC); - peer_ = reinterpret_cast(accessor_->ctor(&imageResource)); + peer_ = reinterpret_cast(accessor_->construct(&DEFAULT_RESOURCE, &DEFAULT_METRICS)); ASSERT_NE(peer_, nullptr); peer_->SetHeight(DEFAULT_INT_VALUE); ASSERT_NE(accessor_->getHeight, nullptr); @@ -129,8 +138,7 @@ HWTEST_F(ImageBitmapAccessorTest, getHeight, TestSize.Level1) */ HWTEST_F(ImageBitmapAccessorTest, getWidth, TestSize.Level1) { - auto imageResource = Converter::ArkValue(DEFAULT_STRING_VALUE, Converter::FC); - peer_ = reinterpret_cast(accessor_->ctor(&imageResource)); + peer_ = reinterpret_cast(accessor_->construct(&DEFAULT_RESOURCE, &DEFAULT_METRICS)); ASSERT_NE(peer_, nullptr); peer_->SetWidth(DEFAULT_INT_VALUE); ASSERT_NE(accessor_->getHeight, nullptr); @@ -177,4 +185,36 @@ HWTEST_F(ImageBitmapAccessorTest, getWidthImpl_NullPointer, TestSize.Level1) auto result = Converter::Convert(accessor_->getWidth(nullptr)); EXPECT_EQ(result, DEFAULT_WIDTH_VALUE); } + +/** + * @tc.name: setHeightTest + * @tc.desc: + * @tc.type: FUNC + */ +HWTEST_F(ImageBitmapAccessorTest, setHeightTest, TestSize.Level1) +{ + peer_ = reinterpret_cast(accessor_->construct(&DEFAULT_RESOURCE, &DEFAULT_METRICS)); + ASSERT_NE(peer_, nullptr); + ASSERT_NE(accessor_->setHeight, nullptr); + for (const auto& [actual, expected] : arkNumberTestPlan) { + accessor_->setHeight(peer_, &actual); + EXPECT_FLOAT_EQ (peer_->GetHeight(), expected); + } +} + +/** + * @tc.name: setWidthTest + * @tc.desc: + * @tc.type: FUNC + */ +HWTEST_F(ImageBitmapAccessorTest, setWidthTest, TestSize.Level1) +{ + peer_ = reinterpret_cast(accessor_->construct(&DEFAULT_RESOURCE, &DEFAULT_METRICS)); + ASSERT_NE(peer_, nullptr); + ASSERT_NE(accessor_->setWidth, nullptr); + for (const auto& [actual, expected] : arkNumberTestPlan) { + accessor_->setWidth(peer_, &actual); + EXPECT_FLOAT_EQ (peer_->GetWidth(), expected); + } +} } // namespace OHOS::Ace::NG diff --git a/test/unittest/capi/modifiers/form_component_modifier_test.cpp b/test/unittest/capi/modifiers/form_component_modifier_test.cpp index 68ee72b607317748665f11f05ddf2b908330a2ed..4cd2b3a1bf49bfefc8cb9dc35256f3488f70a385 100644 --- a/test/unittest/capi/modifiers/form_component_modifier_test.cpp +++ b/test/unittest/capi/modifiers/form_component_modifier_test.cpp @@ -698,4 +698,39 @@ HWTEST_F(FormComponentModifierTest, setFormComponentOptionsDimensionValues, Test checkValue(input, value, expected); } } + +/* + * @tc.name: setOnUpdateTest + * @tc.desc: + * @tc.type: FUNC + */ +HWTEST_F(FormComponentModifierTest, setOnUpdateTest, TestSize.Level1) +{ + ASSERT_NE(modifier_->setOnUpdate, nullptr); + + auto frameNode = reinterpret_cast(node_); + ASSERT_NE(frameNode, nullptr); + auto eventHub = frameNode->GetOrCreateEventHub(); + ASSERT_NE(eventHub, nullptr); + + static std::optional> formInfo = std::nullopt; + auto onUpdate = [](const Ark_Int32 resourceId, const Ark_FormCallbackInfo parameter) { + std::pair info; + info.first = Converter::Convert(parameter.id); + info.second = Converter::Convert(parameter.idString); + formInfo = info; + }; + auto optFunc = Converter::ArkValue( + Converter::ArkValue(onUpdate, frameNode->GetId())); + + modifier_->setOnUpdate(node_, &optFunc); + for (const auto& [actual, expectedNum, expectedStr] : testFixtureFormOnAcquiredCallbackTestValues) { + formInfo = std::nullopt; + auto testValue = ToJson(actual); + eventHub->FireOnUpdate(testValue); + EXPECT_TRUE(formInfo.has_value()); + EXPECT_EQ(formInfo->first, expectedNum); + EXPECT_EQ(formInfo->second, expectedStr); + } +} } // namespace OHOS::Ace::NG diff --git a/test/unittest/capi/stubs/mock_model_pattern.cpp b/test/unittest/capi/stubs/mock_model_pattern.cpp index cfcfe5ab9b1036903d2caf3b9304364d7089d58d..f923fb65aef94fff4bf01a38594e8862e87cea83 100755 --- a/test/unittest/capi/stubs/mock_model_pattern.cpp +++ b/test/unittest/capi/stubs/mock_model_pattern.cpp @@ -15,8 +15,6 @@ #include "mock_model_pattern.h" -#include "core/components_ng/pattern/form/form_model_ng.h" - namespace OHOS::Ace::NG { ModelPattern::ModelPattern(uint32_t key, const ModelViewContext& context) : key_(key) @@ -163,20 +161,4 @@ void ModelPattern::ToJsonValue(std::unique_ptr& json, const Inspector json->PutExtAttr("scene", SceneResourceToStr(mainProperty).c_str(), filter); } -// TEMPORARY SUBSTITUIONS!!! -void FormModelNG::SetModuleName(FrameNode* frameNode, const std::string& moduleName) -{ -} - -void FormModelNG::SetDimension(FrameNode* frameNode, int32_t dimension) -{ -} - -void FormModelNG::AllowUpdate(FrameNode* frameNode, bool allowUpdate) -{ -} - -void FormModelNG::SetVisibility(FrameNode* frameNode, VisibleType visible) -{ -} } \ No newline at end of file