diff --git a/frameworks/core/interfaces/native/implementation/container_span_modifier.cpp b/frameworks/core/interfaces/native/implementation/container_span_modifier.cpp index dd4e53bd1148e667679233149c8ce4a4ef1ae062..ab69f171a1fd1b7415b0a851655c9803151de7b1 100644 --- a/frameworks/core/interfaces/native/implementation/container_span_modifier.cpp +++ b/frameworks/core/interfaces/native/implementation/container_span_modifier.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +#include "core/common/multi_thread_build_manager.h" #include "core/components_ng/base/frame_node.h" #include "core/components_ng/pattern/text/span_model_ng.h" #include "core/components_ng/pattern/text/span_model_static.h" @@ -25,6 +26,9 @@ namespace ContainerSpanModifier { Ark_NativePointer ConstructImpl(Ark_Int32 id, Ark_Int32 flags) { + if (MultiThreadBuildManager::IsParallelScope()) { + LOGF_ABORT("Unsupported UI components ContainerSpan used in ParallelizeUI"); + } auto spanNode = SpanModelStatic::CreateContainerSpanNode(id); CHECK_NULL_RETURN(spanNode, nullptr); spanNode->IncRefCount(); diff --git a/frameworks/core/interfaces/native/implementation/image_span_modifier.cpp b/frameworks/core/interfaces/native/implementation/image_span_modifier.cpp index 01bb71e3389babb764cc7cfa206e7fe862001187..4fa52e90d2a5ff4b265b1c11f147ad4e1b90b2a5 100644 --- a/frameworks/core/interfaces/native/implementation/image_span_modifier.cpp +++ b/frameworks/core/interfaces/native/implementation/image_span_modifier.cpp @@ -13,11 +13,13 @@ * limitations under the License. */ +#include "core/common/multi_thread_build_manager.h" #include "core/interfaces/native/utility/reverse_converter.h" #include "core/image/image_source_info.h" #include "core/components_ng/pattern/text/image_span_view.h" #include "core/components_ng/pattern/text/image_span_view_static.h" #include "core/components_ng/pattern/image/image_model_ng.h" +#include "core/interfaces/native/implementation/image_common_methods.h" #include "core/interfaces/native/utility/callback_helper.h" #include "pixel_map_peer.h" @@ -26,6 +28,9 @@ namespace ImageSpanModifier { Ark_NativePointer ConstructImpl(Ark_Int32 id, Ark_Int32 flags) { + if (MultiThreadBuildManager::IsParallelScope()) { + LOGF_ABORT("Unsupported UI components ImageSpan used in ParallelizeUI"); + } auto imageSpanNode = ImageSpanView::CreateFrameNode(id); CHECK_NULL_RETURN(imageSpanNode, nullptr); imageSpanNode->IncRefCount(); @@ -57,8 +62,7 @@ void SetVerticalAlignImpl(Ark_NativePointer node, void SetColorFilterImpl(Ark_NativePointer node, const Opt_Union_ColorFilter_DrawingColorFilter* value) { - auto frameNode = reinterpret_cast(node); - CHECK_NULL_VOID(frameNode); + ImageCommonMethods::ApplyColorFilterValues(node, value); } void SetObjectFitImpl(Ark_NativePointer node, const Opt_ImageFit* value) diff --git a/frameworks/core/interfaces/native/implementation/marquee_modifier.cpp b/frameworks/core/interfaces/native/implementation/marquee_modifier.cpp index 0ec5bcce6652b97bdf20fa0a224e52ce797695d0..18f50f26b4ab8c4a098507a2c93887c413273aad 100644 --- a/frameworks/core/interfaces/native/implementation/marquee_modifier.cpp +++ b/frameworks/core/interfaces/native/implementation/marquee_modifier.cpp @@ -116,7 +116,10 @@ void SetFontSizeImpl(Ark_NativePointer node, { auto frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); - auto convValue = Converter::OptConvertPtr(value); + std::optional convValue = std::nullopt; + if (value->tag != INTEROP_TAG_UNDEFINED) { + convValue = Converter::OptConvertFromArkNumStrRes(value->value, DimensionUnit::FP); + } Validator::ValidateNonNegative(convValue); Validator::ValidateNonPercent(convValue); MarqueeModelNG::SetFontSize(frameNode, convValue); diff --git a/frameworks/core/interfaces/native/implementation/pulse_symbol_effect_accessor.cpp b/frameworks/core/interfaces/native/implementation/pulse_symbol_effect_accessor.cpp index f16699c4a48c2bb577a7f9534ea399548dac8d87..134db94b1244aee438f71cfe51d587a571a26c8e 100644 --- a/frameworks/core/interfaces/native/implementation/pulse_symbol_effect_accessor.cpp +++ b/frameworks/core/interfaces/native/implementation/pulse_symbol_effect_accessor.cpp @@ -16,15 +16,17 @@ #include "core/components_ng/base/frame_node.h" #include "core/interfaces/native/utility/converter.h" #include "arkoala_api_generated.h" +#include "core/interfaces/native/implementation/symbol_effect_peer.h" namespace OHOS::Ace::NG::GeneratedModifier { namespace PulseSymbolEffectAccessor { void DestroyPeerImpl(Ark_PulseSymbolEffect peer) { + PeerUtils::DestroyPeer(peer); } Ark_PulseSymbolEffect ConstructImpl() { - return {}; + return PeerUtils::CreatePeer(); } Ark_NativePointer GetFinalizerImpl() { diff --git a/frameworks/core/interfaces/native/implementation/search_modifier.cpp b/frameworks/core/interfaces/native/implementation/search_modifier.cpp index 03e9056fe0c66449bcf4bd86d7f6e5c10a243bb8..7303e6dc490d046e23cccb7c922b7406e2c614ac 100644 --- a/frameworks/core/interfaces/native/implementation/search_modifier.cpp +++ b/frameworks/core/interfaces/native/implementation/search_modifier.cpp @@ -50,7 +50,7 @@ std::optional ProcessBindableValue(FrameNode* frameNode, const Opt_ auto onEvent = [arkCallback = CallbackHelper(src.onChange)](const std::u16string& content) { Converter::ConvContext ctx; auto arkContent = Converter::ArkValue(content, &ctx); - arkCallback.Invoke(arkContent); + arkCallback.InvokeSync(arkContent); }; SearchModelStatic::SetOnChangeEvent(frameNode, std::move(onEvent)); }, @@ -162,7 +162,7 @@ void SetCancelButtonImpl(Ark_NativePointer node, { auto frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); - Converter::VisitUnionPtr(value, + Converter::VisitUnionPtr(value, [frameNode](const Ark_CancelButtonOptions& src) { auto cancelButtonStyle = Converter::OptConvert(src.style); auto iconOptions = Converter::OptConvert(src.icon); @@ -181,7 +181,10 @@ void SetTextIndentImpl(Ark_NativePointer node, { auto frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); - auto indentValue = Converter::OptConvertPtr(value); + std::optional indentValue = std::nullopt; + if (value->tag != INTEROP_TAG_UNDEFINED) { + indentValue = Converter::OptConvertFromArkNumStrRes(value->value, DimensionUnit::FP); + } SearchModelStatic::SetTextIndent(frameNode, indentValue); } void SetOnEditChangeImpl(Ark_NativePointer node, @@ -195,7 +198,7 @@ void SetOnEditChangeImpl(Ark_NativePointer node, return; } auto onEditChange = [arkCallback = CallbackHelper(*optValue)](bool value) { - arkCallback.Invoke(value); + arkCallback.InvokeSync(value); }; SearchModelNG::SetOnEditChange(frameNode, std::move(onEditChange)); } @@ -252,6 +255,32 @@ void SetEnterKeyTypeImpl(Ark_NativePointer node, void SetOnSubmitImpl(Ark_NativePointer node, const Opt_Union_Callback_String_Void_SearchSubmitCallback* value) { + auto frameNode = reinterpret_cast(node); + CHECK_NULL_VOID(frameNode); + Converter::VisitUnionPtr(value, + [frameNode](const Callback_String_Void& src) { + auto onSubmit = [arkCallback = CallbackHelper(src)](const std::u16string& value, + NG::TextFieldCommonEvent&) { + Converter::ConvContext ctx; + auto arkStringValue = Converter::ArkValue(value, &ctx); + arkCallback.InvokeSync(arkStringValue); + }; + SearchModelNG::SetOnSubmit(frameNode, std::move(onSubmit)); + }, + [frameNode](const SearchSubmitCallback& src) { + auto weakNode = AceType::WeakClaim(frameNode); + auto onSubmit = [arkCallback = CallbackHelper(src), node = weakNode]( + const std::u16string& value, NG::TextFieldCommonEvent& info) { + PipelineContext::SetCallBackNode(node); + Converter::ConvContext ctx; + auto arkStringValue = Converter::ArkValue(value, &ctx); + const auto event = Converter::ArkSubmitEventSync(info); + auto eventArkValue = Converter::ArkValue(event.ArkValue()); + arkCallback.InvokeSync(arkStringValue, eventArkValue); + }; + SearchModelNG::SetOnSubmit(frameNode, std::move(onSubmit)); + }, + [] {}); } void OnSubmit0Impl(Ark_NativePointer node, const Opt_Callback_String_Void* value) @@ -268,7 +297,7 @@ void OnSubmit0Impl(Ark_NativePointer node, ) { Converter::ConvContext ctx; auto arkStringValue = Converter::ArkValue(value, &ctx); - arkCallback.Invoke(arkStringValue); + arkCallback.InvokeSync(arkStringValue); }; SearchModelNG::SetOnSubmit(frameNode, std::move(onSubmit)); } @@ -328,7 +357,7 @@ void SetOnTextSelectionChangeImpl(Ark_NativePointer node, ) { auto arkSelectionStart = Converter::ArkValue(selectionStart); auto arkSelectionEnd = Converter::ArkValue(selectionEnd); - arkCallback.Invoke(arkSelectionStart, arkSelectionEnd); + arkCallback.InvokeSync(arkSelectionStart, arkSelectionEnd); }; SearchModelNG::SetOnTextSelectionChange(frameNode, std::move(onTextSelectionChange)); } @@ -345,7 +374,7 @@ void SetOnContentScrollImpl(Ark_NativePointer node, auto onContentScroll = [arkCallback = CallbackHelper(*optValue)](float totalOffsetX, float totalOffsetY) { auto arkTotalOffsetX = Converter::ArkValue(totalOffsetX); auto arkTotalOffsetY = Converter::ArkValue(totalOffsetY); - arkCallback.Invoke(arkTotalOffsetX, arkTotalOffsetY); + arkCallback.InvokeSync(arkTotalOffsetX, arkTotalOffsetY); }; SearchModelNG::SetOnContentScroll(frameNode, std::move(onContentScroll)); } @@ -362,7 +391,7 @@ void SetOnCopyImpl(Ark_NativePointer node, auto onCopy = [arkCallback = CallbackHelper(*optValue)](const std::u16string& value) { Converter::ConvContext ctx; auto textArkString = Converter::ArkValue(value, &ctx); - arkCallback.Invoke(textArkString); + arkCallback.InvokeSync(textArkString); }; SearchModelNG::SetOnCopy(frameNode, std::move(onCopy)); } @@ -379,7 +408,7 @@ void SetOnCutImpl(Ark_NativePointer node, auto onCut = [arkCallback = CallbackHelper(*optValue)](const std::u16string& value) { Converter::ConvContext ctx; auto textArkString = Converter::ArkValue(value, &ctx); - arkCallback.Invoke(textArkString); + arkCallback.InvokeSync(textArkString); }; SearchModelNG::SetOnCut(frameNode, std::move(onCut)); } @@ -403,7 +432,7 @@ void SetOnPasteImpl(Ark_NativePointer node, Ark_PasteEvent arkEvent = { .preventDefault = Converter::ArkValue(keeper.ArkValue()) }; - arkCallback.Invoke(arkContent, arkEvent); + arkCallback.InvokeSync(arkContent, arkEvent); }; SearchModelNG::SetOnPasteWithEvent(frameNode, std::move(onPaste)); } @@ -455,7 +484,10 @@ void SetMinFontSizeImpl(Ark_NativePointer node, { auto frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); - auto optValue = Converter::OptConvertPtr(value); + std::optional optValue = std::nullopt; + if (value->tag != INTEROP_TAG_UNDEFINED) { + optValue = Converter::OptConvertFromArkNumStrRes(value->value); + } Validator::ValidateNonNegative(optValue); Validator::ValidateNonPercent(optValue); SearchModelStatic::SetAdaptMinFontSize(frameNode, optValue); @@ -465,7 +497,10 @@ void SetMaxFontSizeImpl(Ark_NativePointer node, { auto frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); - auto optValue = Converter::OptConvertPtr(value); + std::optional optValue = std::nullopt; + if (value->tag != INTEROP_TAG_UNDEFINED) { + optValue = Converter::OptConvertFromArkNumStrRes(value->value); + } Validator::ValidateNonNegative(optValue); Validator::ValidateNonPercent(optValue); SearchModelStatic::SetAdaptMaxFontSize(frameNode, optValue); @@ -506,7 +541,10 @@ void SetLetterSpacingImpl(Ark_NativePointer node, { auto frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); - auto spacing = Converter::OptConvertPtr(value); + std::optional spacing = std::nullopt; + if (value->tag != INTEROP_TAG_UNDEFINED) { + spacing = Converter::OptConvertFromArkNumStrRes(value->value); + } Validator::ValidateNonNegative(spacing); Validator::ValidateNonPercent(spacing); SearchModelStatic::SetLetterSpacing(frameNode, spacing); @@ -575,7 +613,7 @@ void SetOnDidInsertImpl(Ark_NativePointer node, .insertOffset = Converter::ArkValue(value.insertOffset), .insertValue = Converter::ArkValue(value.insertValue, &ctx) }; - arkCallback.Invoke(insertValue); + arkCallback.InvokeSync(insertValue); }; SearchModelNG::SetOnDidInsertValueEvent(frameNode, std::move(onDidInsert)); } @@ -618,7 +656,7 @@ void SetOnDidDeleteImpl(Ark_NativePointer node, .direction = Converter::ArkValue(value.direction), .deleteValue = Converter::ArkValue(value.deleteValue, &ctx) }; - arkCallback.Invoke(deleteValue); + arkCallback.InvokeSync(deleteValue); }; SearchModelNG::SetOnDidDeleteEvent(frameNode, std::move(onDidDelete)); } @@ -743,7 +781,7 @@ void SetInputFilterImpl(Ark_NativePointer node, if (arkErrorEvent) { errorEvent = [callback = CallbackHelper(*arkErrorEvent)](const std::u16string& val) { auto errortArkString = Converter::ArkValue(val, Converter::FC); - callback.Invoke(errortArkString); + callback.InvokeSync(errortArkString); }; } SearchModelNG::SetInputFilter(frameNode, valueString.value_or(""), errorEvent); diff --git a/frameworks/core/interfaces/native/implementation/span_modifier.cpp b/frameworks/core/interfaces/native/implementation/span_modifier.cpp index 2527d273330d847353cee78165e820ee6ef48b19..9eda6b90d423ec50b92bc6326797587ff37d4a59 100644 --- a/frameworks/core/interfaces/native/implementation/span_modifier.cpp +++ b/frameworks/core/interfaces/native/implementation/span_modifier.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +#include "core/common/multi_thread_build_manager.h" #include "core/components_ng/base/frame_node.h" #include "core/interfaces/native/utility/converter.h" #include "arkoala_api_generated.h" @@ -25,6 +26,9 @@ namespace SpanModifier { Ark_NativePointer ConstructImpl(Ark_Int32 id, Ark_Int32 flags) { + if (MultiThreadBuildManager::IsParallelScope()) { + LOGF_ABORT("Unsupported UI components Span used in ParallelizeUI"); + } auto spanNode = SpanModelNG::CreateSpanNode(id, u""); CHECK_NULL_RETURN(spanNode, nullptr); spanNode->IncRefCount(); @@ -81,7 +85,10 @@ void SetFontSizeImpl(Ark_NativePointer node, { auto frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); - auto convValue = Converter::OptConvertPtr(value); + std::optional convValue = std::nullopt; + if (value->tag != INTEROP_TAG_UNDEFINED) { + convValue = Converter::OptConvertFromArkNumStrRes(value->value); + } Validator::ValidateNonNegative(convValue); Validator::ValidateNonPercent(convValue); SpanModelStatic::SetFontSize(frameNode, convValue); diff --git a/frameworks/core/interfaces/native/implementation/symbol_glyph_modifier.cpp b/frameworks/core/interfaces/native/implementation/symbol_glyph_modifier.cpp index 90da11d010aea608882dc025cf1f733eba379dfd..53694005712c17119856106f8543ea07c9519b23 100644 --- a/frameworks/core/interfaces/native/implementation/symbol_glyph_modifier.cpp +++ b/frameworks/core/interfaces/native/implementation/symbol_glyph_modifier.cpp @@ -40,6 +40,9 @@ enum class TextFontWeight { MEDIUM, REGULAR, }; +constexpr int32_t SYSTEM_SYMBOL_BOUNDARY = 0XFFFFF; +const std::string DEFAULT_SYMBOL_FONTFAMILY = "HM Symbol"; +const std::string CUSTOM_SYMBOL_SUFFIX = "_CustomSymbol"; } namespace OHOS::Ace::NG::Converter { @@ -84,6 +87,30 @@ void AssignCast(std::optional& dst, const Ark_String& src) dst = static_cast(fontWeight.value()); } } + +template<> +void AssignCast(std::optional& dst, const Ark_Resource& src) +{ + ResourceConverter converter(src); + if (!dst) { + dst = SymbolData(); + } + dst->symbol = converter.ToSymbol(); + if (!dst->symbol.has_value()) { + return; + } + if (dst->symbol.value() > SYSTEM_SYMBOL_BOUNDARY) { + std::string bundleName = converter.BundleName(); + std::string moduleName = converter.ModuleName(); + auto customSymbolFamilyName = bundleName + "_" + moduleName + CUSTOM_SYMBOL_SUFFIX; + std::replace(customSymbolFamilyName.begin(), customSymbolFamilyName.end(), '.', '_'); + dst->symbolType = SymbolType::CUSTOM; + dst->symbolFamilyName.push_back(customSymbolFamilyName); + } else { + dst->symbolType = SymbolType::SYSTEM; + dst->symbolFamilyName.push_back(DEFAULT_SYMBOL_FONTFAMILY); + } +} } namespace OHOS::Ace::NG::GeneratedModifier { constexpr float SCALE_LIMIT = 1.f; @@ -105,7 +132,9 @@ void SetSymbolGlyphOptionsImpl(Ark_NativePointer node, CHECK_NULL_VOID(frameNode); auto convValue = Converter::OptConvertPtr(value); if (convValue.has_value() && convValue->symbol.has_value()) { - SymbolModelNG::InitialSymbol(frameNode, convValue->symbol.value()); + SymbolModelStatic::InitialSymbol(frameNode, convValue->symbol.value()); + SymbolModelStatic::SetFontFamilies(frameNode, convValue->symbolFamilyName); + SymbolModelStatic::SetSymbolType(frameNode, convValue->symbolType); } } } // SymbolGlyphInterfaceModifier @@ -115,7 +144,10 @@ void SetFontSizeImpl(Ark_NativePointer node, { auto frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); - auto convValue = Converter::OptConvertPtr(value); + std::optional convValue = std::nullopt; + if (value->tag != INTEROP_TAG_UNDEFINED) { + convValue = Converter::OptConvertFromArkNumStrRes(value->value); + } Validator::ValidateNonNegative(convValue); Validator::ValidateNonPercent(convValue); SymbolModelStatic::SetFontSize(frameNode, convValue); @@ -215,7 +247,9 @@ void SetSymbolEffectImpl(Ark_NativePointer node, [&symbolEffectOptions](const Ark_Number& src) { symbolEffectOptions.SetTriggerNum(Converter::Convert(src)); }, - []() {}); + [&symbolEffectOptions]() { + symbolEffectOptions.SetIsActive(false); + }); SymbolModelNG::SetSymbolEffectOptions(frameNode, symbolEffectOptions); } } // SymbolGlyphAttributeModifier diff --git a/frameworks/core/interfaces/native/implementation/symbol_span_modifier.cpp b/frameworks/core/interfaces/native/implementation/symbol_span_modifier.cpp index 3e60de24c7ba0fcd33fafa4fc3f60328d6a72d36..dd82133f9f60590d6cc6abeeb0307435e4246c10 100644 --- a/frameworks/core/interfaces/native/implementation/symbol_span_modifier.cpp +++ b/frameworks/core/interfaces/native/implementation/symbol_span_modifier.cpp @@ -41,7 +41,9 @@ void SetSymbolSpanOptionsImpl(Ark_NativePointer node, CHECK_NULL_VOID(value); auto convValue = Converter::OptConvert(*value); if (convValue.has_value() && convValue->symbol.has_value()) { - SymbolSpanModelNG::InitialSymbol(frameNode, convValue->symbol.value()); + SymbolSpanModelStatic::InitialSymbol(frameNode, convValue->symbol.value()); + SymbolSpanModelStatic::SetFontFamilies(frameNode, convValue->symbolFamilyName); + SymbolSpanModelStatic::SetSymbolType(frameNode, convValue->symbolType); } } } // SymbolSpanInterfaceModifier diff --git a/frameworks/core/interfaces/native/implementation/text_area_modifier.cpp b/frameworks/core/interfaces/native/implementation/text_area_modifier.cpp index 3c9131d76e18153f1a3cf03eafcbcfaab1cee20d..748261b77943b22157716a5a742c172235490a13 100644 --- a/frameworks/core/interfaces/native/implementation/text_area_modifier.cpp +++ b/frameworks/core/interfaces/native/implementation/text_area_modifier.cpp @@ -39,7 +39,7 @@ std::optional ProcessBindableText(FrameNode* frameNode, auto onEvent = [arkCallback = CallbackHelper(src.onChange)](const std::u16string& content) { Converter::ConvContext ctx; auto arkContent = Converter::ArkValue(content, &ctx); - arkCallback.Invoke(arkContent); + arkCallback.InvokeSync(arkContent); }; TextFieldModelStatic::SetOnChangeEvent(frameNode, std::move(onEvent)); }, @@ -48,7 +48,7 @@ std::optional ProcessBindableText(FrameNode* frameNode, auto onEvent = [arkCallback = CallbackHelper(src.onChange)](const std::u16string& content) { Converter::ConvContext ctx; auto arkContent = Converter::ArkUnion(content, &ctx); - arkCallback.Invoke(arkContent); + arkCallback.InvokeSync(arkContent); }; TextFieldModelStatic::SetOnChangeEvent(frameNode, std::move(onEvent)); }, @@ -68,7 +68,7 @@ namespace TextAreaModifier { Ark_NativePointer ConstructImpl(Ark_Int32 id, Ark_Int32 flags) { - auto frameNode = TextFieldModelNG::CreateFrameNode(id, u"", u"", true); + auto frameNode = TextFieldModelStatic::CreateTextAreaNode(id, u"", u""); CHECK_NULL_RETURN(frameNode, nullptr); frameNode->IncRefCount(); return AceType::RawPtr(frameNode); @@ -192,7 +192,10 @@ void SetTextIndentImpl(Ark_NativePointer node, { auto frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); - auto convValue = Converter::OptConvertPtr(value); + std::optional convValue = std::nullopt; + if (value->tag != INTEROP_TAG_UNDEFINED) { + convValue = Converter::OptConvertFromArkNumStrRes(value->value, DimensionUnit::FP); + } TextFieldModelStatic::SetTextIndent(frameNode, convValue); } void SetCaretStyleImpl(Ark_NativePointer node, @@ -218,6 +221,29 @@ void SetSelectedBackgroundColorImpl(Ark_NativePointer node, void SetOnSubmitImpl(Ark_NativePointer node, const Opt_Union_Callback_EnterKeyType_Void_TextAreaSubmitCallback* value) { + auto frameNode = reinterpret_cast(node); + CHECK_NULL_VOID(frameNode); + Converter::VisitUnionPtr(value, + [frameNode](const Callback_EnterKeyType_Void& src) { + auto onSubmit = [arkCallback = CallbackHelper(src)](int32_t enterKey, NG::TextFieldCommonEvent& event) { + auto enterKeyType = Converter::ArkValue(static_cast(enterKey)); + arkCallback.InvokeSync(enterKeyType); + }; + TextFieldModelNG::SetOnSubmit(frameNode, std::move(onSubmit)); + }, + [frameNode](const TextAreaSubmitCallback& src) { + auto weakNode = AceType::WeakClaim(frameNode); + auto onSubmit = [arkCallback = CallbackHelper(src), node = weakNode]( + const int32_t& keyType, NG::TextFieldCommonEvent& info) { + PipelineContext::SetCallBackNode(node); + auto enterKeyType = Converter::ArkValue(static_cast(keyType)); + const auto event = Converter::ArkSubmitEventSync(info); + auto eventArkValue = Converter::ArkValue(event.ArkValue()); + arkCallback.InvokeSync(enterKeyType, eventArkValue); + }; + TextFieldModelNG::SetOnSubmit(frameNode, std::move(onSubmit)); + }, + [] {}); } void OnSubmit0Impl(Ark_NativePointer node, const Opt_Callback_EnterKeyType_Void* value) @@ -231,7 +257,7 @@ void OnSubmit0Impl(Ark_NativePointer node, } auto onSubmit = [arkCallback = CallbackHelper(*optValue)](int32_t enterKey, NG::TextFieldCommonEvent& event) { auto enterKeyType = Converter::ArkValue(static_cast(enterKey)); - arkCallback.Invoke(enterKeyType); + arkCallback.InvokeSync(enterKeyType); }; TextFieldModelNG::SetOnSubmit(frameNode, std::move(onSubmit)); } @@ -288,7 +314,7 @@ void SetOnTextSelectionChangeImpl(Ark_NativePointer node, auto onEvent = [arkCallback = CallbackHelper(*optValue)](int32_t selectionStart, int32_t selectionEnd) { auto arkSelectionStart = Converter::ArkValue(selectionStart); auto arkSelectionEnd = Converter::ArkValue(selectionEnd); - arkCallback.Invoke(arkSelectionStart, arkSelectionEnd); + arkCallback.InvokeSync(arkSelectionStart, arkSelectionEnd); }; TextFieldModelNG::SetOnTextSelectionChange(frameNode, std::move(onEvent)); } @@ -305,7 +331,7 @@ void SetOnContentScrollImpl(Ark_NativePointer node, auto onContentScroll = [arkCallback = CallbackHelper(*optValue)](float totalOffsetX, float totalOffsetY) { auto arkTotalOffsetX = Converter::ArkValue(totalOffsetX); auto arkTotalOffsetY = Converter::ArkValue(totalOffsetY); - arkCallback.Invoke(arkTotalOffsetX, arkTotalOffsetY); + arkCallback.InvokeSync(arkTotalOffsetX, arkTotalOffsetY); }; TextFieldModelNG::SetOnContentScroll(frameNode, std::move(onContentScroll)); } @@ -320,7 +346,7 @@ void SetOnEditChangeImpl(Ark_NativePointer node, return; } auto onEditEvent = [arkCallback = CallbackHelper(*optValue)](const bool value) { - arkCallback.Invoke(Converter::ArkValue(value)); + arkCallback.InvokeSync(Converter::ArkValue(value)); }; TextFieldModelNG::SetOnEditChange(frameNode, std::move(onEditEvent)); } @@ -337,7 +363,7 @@ void SetOnCopyImpl(Ark_NativePointer node, auto onCopy = [arkCallback = CallbackHelper(*optValue)](const std::u16string& value) { Converter::ConvContext ctx; auto textArkString = Converter::ArkValue(value, &ctx); - arkCallback.Invoke(textArkString); + arkCallback.InvokeSync(textArkString); }; TextFieldModelNG::SetOnCopy(frameNode, std::move(onCopy)); } @@ -354,7 +380,7 @@ void SetOnCutImpl(Ark_NativePointer node, auto onCut = [arkCallback = CallbackHelper(*optValue)](const std::u16string& value) { Converter::ConvContext ctx; auto textArkString = Converter::ArkValue(value, &ctx); - arkCallback.Invoke(textArkString); + arkCallback.InvokeSync(textArkString); }; TextFieldModelNG::SetOnCut(frameNode, std::move(onCut)); } @@ -378,7 +404,7 @@ void SetOnPasteImpl(Ark_NativePointer node, Ark_PasteEvent arkEvent = { .preventDefault = Converter::ArkValue(keeper.ArkValue()) }; - arkCallback.Invoke(arkContent, arkEvent); + arkCallback.InvokeSync(arkContent, arkEvent); }; TextFieldModelNG::SetOnPasteWithEvent(frameNode, std::move(onPaste)); } @@ -439,7 +465,10 @@ void SetMinFontSizeImpl(Ark_NativePointer node, { auto frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); - auto optValue = Converter::OptConvertPtr(value); + std::optional optValue = std::nullopt; + if (value->tag != INTEROP_TAG_UNDEFINED) { + optValue = Converter::OptConvertFromArkNumStrRes(value->value); + } Validator::ValidateNonNegative(optValue); Validator::ValidateNonPercent(optValue); TextFieldModelStatic::SetAdaptMinFontSize(frameNode, optValue); @@ -449,7 +478,10 @@ void SetMaxFontSizeImpl(Ark_NativePointer node, { auto frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); - auto optValue = Converter::OptConvertPtr(value); + std::optional optValue = std::nullopt; + if (value->tag != INTEROP_TAG_UNDEFINED) { + optValue = Converter::OptConvertFromArkNumStrRes(value->value); + } Validator::ValidateNonNegative(optValue); Validator::ValidateNonPercent(optValue); TextFieldModelStatic::SetAdaptMaxFontSize(frameNode, optValue); @@ -523,7 +555,10 @@ void SetLetterSpacingImpl(Ark_NativePointer node, { auto frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); - auto spacing = Converter::OptConvertPtr(value); + std::optional spacing = std::nullopt; + if (value->tag != INTEROP_TAG_UNDEFINED) { + spacing = Converter::OptConvertFromArkNumStrRes(value->value); + } Validator::ValidateNonNegative(spacing); Validator::ValidateNonPercent(spacing); TextFieldModelStatic::SetLetterSpacing(frameNode, spacing); @@ -542,7 +577,10 @@ void SetLineHeightImpl(Ark_NativePointer node, { auto frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); - auto optValue = Converter::OptConvertPtr(value); + std::optional optValue = std::nullopt; + if (value->tag != INTEROP_TAG_UNDEFINED) { + optValue = Converter::OptConvertFromArkNumStrRes(value->value); + } Validator::ValidateNonNegative(optValue); TextFieldModelStatic::SetLineHeight(frameNode, optValue); } @@ -616,7 +654,7 @@ void SetOnDidInsertImpl(Ark_NativePointer node, .insertOffset = Converter::ArkValue(value.insertOffset), .insertValue = Converter::ArkValue(value.insertValue, &ctx) }; - arkCallback.Invoke(insertValue); + arkCallback.InvokeSync(insertValue); }; TextFieldModelNG::SetOnDidInsertValueEvent(frameNode, std::move(onDidInsert)); } @@ -659,7 +697,7 @@ void SetOnDidDeleteImpl(Ark_NativePointer node, .direction = Converter::ArkValue(value.direction), .deleteValue = Converter::ArkValue(value.deleteValue, &ctx) }; - arkCallback.Invoke(deleteValue); + arkCallback.InvokeSync(deleteValue); }; TextFieldModelNG::SetOnDidDeleteEvent(frameNode, std::move(onDidDelete)); } @@ -777,7 +815,7 @@ void SetInputFilterImpl(Ark_NativePointer node, if (arkOnError) { onErrorEvent = [arkCallback = CallbackHelper(arkOnError.value())](const std::u16string& val) { Converter::ConvContext ctx; - arkCallback.Invoke(Converter::ArkValue(val, &ctx)); + arkCallback.InvokeSync(Converter::ArkValue(val, &ctx)); }; } TextFieldModelNG::SetInputFilter(frameNode, valueString.value_or(""), std::move(onErrorEvent)); diff --git a/frameworks/core/interfaces/native/implementation/text_content_controller_base_accessor.cpp b/frameworks/core/interfaces/native/implementation/text_content_controller_base_accessor.cpp index 7aaa461cd080fea20c205004f06880aa532a8db3..a15438df9ba36de33bc9bea02b91a2d82dd9f226 100644 --- a/frameworks/core/interfaces/native/implementation/text_content_controller_base_accessor.cpp +++ b/frameworks/core/interfaces/native/implementation/text_content_controller_base_accessor.cpp @@ -23,6 +23,12 @@ template<> void AssignCast(std::optional& dst, const Ark_TextContentCon { dst = Converter::OptConvert(src.offset); } + +void AssignArkValue(Ark_CaretOffset& dst, const NG::OffsetF& src) +{ + dst.x = Converter::ArkValue(src.GetX()); + dst.y = Converter::ArkValue(src.GetY()); +} } namespace OHOS::Ace::NG::GeneratedModifier { namespace TextContentControllerBaseAccessor { @@ -42,7 +48,9 @@ Ark_CaretOffset GetCaretOffsetImpl(Ark_TextContentControllerBase peer) { CHECK_NULL_RETURN(peer && peer->controller_, {}); auto offset = peer->controller_->GetCaretPosition(); - return Converter::ArkValue(offset); + Ark_CaretOffset caretOffset = Converter::ArkValue(offset); + caretOffset.index = Converter::ArkValue(peer->controller_->GetCaretIndex()); + return caretOffset; } Ark_RectResult GetTextContentRectImpl(Ark_TextContentControllerBase peer) { diff --git a/frameworks/core/interfaces/native/implementation/text_controller_accessor.cpp b/frameworks/core/interfaces/native/implementation/text_controller_accessor.cpp index 4add263a86293d0067c10d9af3bd02366c01d218..b0c6129ae9dfd8db66417b2cf8b0875744b00e2e 100644 --- a/frameworks/core/interfaces/native/implementation/text_controller_accessor.cpp +++ b/frameworks/core/interfaces/native/implementation/text_controller_accessor.cpp @@ -43,8 +43,12 @@ void CloseSelectionMenuImpl(Ark_TextController peer) void SetStyledStringImpl(Ark_TextController peer, Ark_StyledString value) { - CHECK_NULL_VOID(peer && peer->controller); + CHECK_NULL_VOID(peer); CHECK_NULL_VOID(value); + if (!peer->controller) { + peer->SetStyledStringCache(value->spanString); + return; + } peer->controller->SetStyledString(value->spanString); } Ark_LayoutManager GetLayoutManagerImpl(Ark_TextController peer) diff --git a/frameworks/core/interfaces/native/implementation/text_controller_peer_impl.h b/frameworks/core/interfaces/native/implementation/text_controller_peer_impl.h index 06098b4551397860559863a706831b2e18f679f8..93def7108d752a49cf912e2966e3f415d449b77d 100644 --- a/frameworks/core/interfaces/native/implementation/text_controller_peer_impl.h +++ b/frameworks/core/interfaces/native/implementation/text_controller_peer_impl.h @@ -19,5 +19,18 @@ struct TextControllerPeer { OHOS::Ace::RefPtr controller; + + void SetStyledStringCache(const OHOS::Ace::RefPtr& styledString) + { + styledStringCache_ = styledString; + } + + OHOS::Ace::RefPtr GetStyledStringCache() const + { + return styledStringCache_; + } + +private: + OHOS::Ace::RefPtr styledStringCache_; }; #endif // FOUNDATION_ARKUI_ACE_ENGINE_FRAMEWORKS_CORE_INTERFACES_NATIVE_IMPL_TEXT_CONTROLLER_PEER_IMPL_H \ No newline at end of file diff --git a/frameworks/core/interfaces/native/implementation/text_input_modifier.cpp b/frameworks/core/interfaces/native/implementation/text_input_modifier.cpp index e3877047a18e9c6adab0e1785225833aebb9439d..23445006e052731a0dfa0e75786a8f35df270182 100644 --- a/frameworks/core/interfaces/native/implementation/text_input_modifier.cpp +++ b/frameworks/core/interfaces/native/implementation/text_input_modifier.cpp @@ -53,7 +53,7 @@ std::optional ProcessBindableText(FrameNode* frameNode, auto onEvent = [arkCallback = CallbackHelper(src.onChange)](const std::u16string& content) { Converter::ConvContext ctx; auto arkContent = Converter::ArkValue(content, &ctx); - arkCallback.Invoke(arkContent); + arkCallback.InvokeSync(arkContent); }; TextFieldModelStatic::SetOnChangeEvent(frameNode, std::move(onEvent)); }, @@ -62,7 +62,7 @@ std::optional ProcessBindableText(FrameNode* frameNode, auto onEvent = [arkCallback = CallbackHelper(src.onChange)](const std::u16string& content) { Converter::ConvContext ctx; auto arkContent = Converter::ArkUnion(content, &ctx); - arkCallback.Invoke(arkContent); + arkCallback.InvokeSync(arkContent); }; TextFieldModelStatic::SetOnChangeEvent(frameNode, std::move(onEvent)); }, @@ -116,7 +116,7 @@ namespace TextInputModifier { Ark_NativePointer ConstructImpl(Ark_Int32 id, Ark_Int32 flags) { - auto frameNode = TextFieldModelNG::CreateFrameNode(id, u"", u"", false); + auto frameNode = TextFieldModelStatic::CreateTextInputNode(id, u"", u""); CHECK_NULL_RETURN(frameNode, nullptr); frameNode->IncRefCount(); return AceType::RawPtr(frameNode); @@ -184,7 +184,10 @@ void SetTextIndentImpl(Ark_NativePointer node, { auto frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); - auto convValue = Converter::OptConvertPtr(value); + std::optional convValue = std::nullopt; + if (value->tag != INTEROP_TAG_UNDEFINED) { + convValue = Converter::OptConvertFromArkNumStrRes(value->value, DimensionUnit::FP); + } TextFieldModelStatic::SetTextIndent(frameNode, convValue); } void SetPlaceholderFontImpl(Ark_NativePointer node, @@ -222,7 +225,7 @@ void SetOnEditChangeImpl(Ark_NativePointer node, return; } auto onEditChange = [arkCallback = CallbackHelper(*optValue)](const bool& boolValue) { - arkCallback.Invoke(Converter::ArkValue(boolValue)); + arkCallback.InvokeSync(Converter::ArkValue(boolValue)); }; TextFieldModelNG::SetOnEditChange(frameNode, onEditChange); } @@ -274,7 +277,7 @@ void SetOnTextSelectionChangeImpl(Ark_NativePointer node, return; } auto onTextSelectionChange = [arkCallback = CallbackHelper(*optValue)](const int32_t& start, const int32_t& end) { - arkCallback.Invoke(Converter::ArkValue(start), Converter::ArkValue(end)); + arkCallback.InvokeSync(Converter::ArkValue(start), Converter::ArkValue(end)); }; TextFieldModelNG::SetOnTextSelectionChange(frameNode, onTextSelectionChange); } @@ -289,7 +292,7 @@ void SetOnContentScrollImpl(Ark_NativePointer node, return; } auto onContentScroll = [arkCallback = CallbackHelper(*optValue)](const float& offsetX, const float& offsetY) { - arkCallback.Invoke(Converter::ArkValue(offsetX), Converter::ArkValue(offsetY)); + arkCallback.InvokeSync(Converter::ArkValue(offsetX), Converter::ArkValue(offsetY)); }; TextFieldModelNG::SetOnContentScroll(frameNode, onContentScroll); } @@ -363,7 +366,7 @@ void SetOnCopyImpl(Ark_NativePointer node, } auto onCopy = [arkCallback = CallbackHelper(*optValue)](const std::u16string& copyStr) { Converter::ConvContext ctx; - arkCallback.Invoke(Converter::ArkValue(copyStr, &ctx)); + arkCallback.InvokeSync(Converter::ArkValue(copyStr, &ctx)); }; TextFieldModelNG::SetOnCopy(frameNode, onCopy); } @@ -379,7 +382,7 @@ void SetOnCutImpl(Ark_NativePointer node, } auto onCut = [arkCallback = CallbackHelper(*optValue)](const std::u16string& cutStr) { Converter::ConvContext ctx; - arkCallback.Invoke(Converter::ArkValue(cutStr, &ctx)); + arkCallback.InvokeSync(Converter::ArkValue(cutStr, &ctx)); }; TextFieldModelNG::SetOnCut(frameNode, onCut); } @@ -403,7 +406,7 @@ void SetOnPasteImpl(Ark_NativePointer node, Ark_PasteEvent arkEvent = { .preventDefault = Converter::ArkValue(keeper.ArkValue()) }; - arkCallback.Invoke(arkContent, arkEvent); + arkCallback.InvokeSync(arkContent, arkEvent); }; TextFieldModelNG::SetOnPasteWithEvent(frameNode, std::move(onPaste)); } @@ -582,18 +585,11 @@ void SetLineBreakStrategyImpl(Ark_NativePointer node, auto convValue = Converter::OptConvertPtr(value); TextFieldModelStatic::SetLineBreakStrategy(frameNode, convValue); } -void SetCancelButtonImpl(Ark_NativePointer node, - const Opt_Union_CancelButtonOptions_CancelButtonSymbolOptions* value) -{ -} -void CancelButton0Impl(Ark_NativePointer node, - const Opt_CancelButtonOptions* value) +void CancelButton0Impl(FrameNode *frameNode, + const Ark_CancelButtonOptions& src) { - auto frameNode = reinterpret_cast(node); - CHECK_NULL_VOID(frameNode); - auto optValue = Converter::GetOptPtr(value); - auto cleanButtonStyle = optValue ? Converter::OptConvert(optValue->style) : std::nullopt; - auto optIconOptions = optValue ? Converter::OptConvert(optValue->icon) : std::nullopt; + auto cleanButtonStyle = Converter::OptConvert(src.style); + auto optIconOptions = Converter::OptConvert(src.icon); TextFieldModelStatic::SetCleanNodeStyle(frameNode, cleanButtonStyle); TextFieldModelNG::SetIsShowCancelButton(frameNode, true); TextFieldModelNG::SetCancelButtonSymbol(frameNode, false); @@ -642,6 +638,22 @@ void CancelButton1Impl(Ark_NativePointer node, LOGE("TextInputModifier::CancelButton1Impl need to know what data is in value->icon"); } } +void SetCancelButtonImpl(Ark_NativePointer node, + const Opt_Union_CancelButtonOptions_CancelButtonSymbolOptions* value) +{ + auto frameNode = reinterpret_cast(node); + CHECK_NULL_VOID(frameNode); + Converter::VisitUnionPtr(value, + [frameNode](const Ark_CancelButtonOptions& src) { + CancelButton0Impl(frameNode, src); + }, + [frameNode](const Ark_CancelButtonSymbolOptions& src) { + LOGE("ARKOALA CancelButtonSymbolModifier not implemented."); + }, + [frameNode] { + TextFieldModelStatic::SetDefaultCancelIcon(frameNode); + }); +} void SetSelectAllImpl(Ark_NativePointer node, const Opt_Boolean* value) { @@ -655,7 +667,10 @@ void SetMinFontSizeImpl(Ark_NativePointer node, { auto frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); - auto convValue = Converter::OptConvertPtr(value); + std::optional convValue = std::nullopt; + if (value->tag != INTEROP_TAG_UNDEFINED) { + convValue = Converter::OptConvertFromArkNumStrRes(value->value); + } Validator::ValidateNonNegative(convValue); Validator::ValidateNonPercent(convValue); TextFieldModelStatic::SetAdaptMinFontSize(frameNode, convValue); @@ -665,7 +680,10 @@ void SetMaxFontSizeImpl(Ark_NativePointer node, { auto frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); - auto convValue = Converter::OptConvertPtr(value); + std::optional convValue = std::nullopt; + if (value->tag != INTEROP_TAG_UNDEFINED) { + convValue = Converter::OptConvertFromArkNumStrRes(value->value); + } Validator::ValidateNonNegative(convValue); Validator::ValidateNonPercent(convValue); TextFieldModelStatic::SetAdaptMaxFontSize(frameNode, convValue); @@ -722,7 +740,10 @@ void SetLetterSpacingImpl(Ark_NativePointer node, { auto frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); - auto spacing = Converter::OptConvertPtr(value); + std::optional spacing = std::nullopt; + if (value->tag != INTEROP_TAG_UNDEFINED) { + spacing = Converter::OptConvertFromArkNumStrRes(value->value); + } Validator::ValidateNonPercent(spacing); TextFieldModelStatic::SetLetterSpacing(frameNode, spacing); } @@ -731,7 +752,10 @@ void SetLineHeightImpl(Ark_NativePointer node, { auto frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); - auto optValue = Converter::OptConvertPtr(value); + std::optional optValue = std::nullopt; + if (value->tag != INTEROP_TAG_UNDEFINED) { + optValue = Converter::OptConvertFromArkNumStrRes(value->value); + } Validator::ValidateNonNegative(optValue); TextFieldModelStatic::SetLineHeight(frameNode, optValue); } @@ -773,7 +797,7 @@ void SetOnSecurityStateChangeImpl(Ark_NativePointer node, return; } auto onSecurityStateChange = [arkCallback = CallbackHelper(*optValue)](const bool& boolValue) { - arkCallback.Invoke(Converter::ArkValue(boolValue)); + arkCallback.InvokeSync(Converter::ArkValue(boolValue)); }; TextFieldModelStatic::SetOnSecurityStateChange(frameNode, onSecurityStateChange); } @@ -810,7 +834,7 @@ void SetOnDidInsertImpl(Ark_NativePointer node, } auto onDidInsert = [arkCallback = CallbackHelper(*optValue)](const InsertValueInfo& insertValueInfo) { Converter::ConvContext ctx; - arkCallback.Invoke(Ark_InsertValue { + arkCallback.InvokeSync(Ark_InsertValue { .insertOffset = Converter::ArkValue(insertValueInfo.insertOffset), .insertValue = Converter::ArkValue(insertValueInfo.insertValue, &ctx) }); @@ -851,7 +875,7 @@ void SetOnDidDeleteImpl(Ark_NativePointer node, } auto onDidDelete = [arkCallback = CallbackHelper(*optValue)](const DeleteValueInfo& deleteValueInfo) { Converter::ConvContext ctx; - arkCallback.Invoke(Ark_DeleteValue { + arkCallback.InvokeSync(Ark_DeleteValue { .deleteOffset = Converter::ArkValue(deleteValueInfo.deleteOffset), .direction = Converter::ArkValue(deleteValueInfo.direction), .deleteValue = Converter::ArkValue(deleteValueInfo.deleteValue, &ctx) @@ -973,7 +997,7 @@ void SetInputFilterImpl(Ark_NativePointer node, if (arkOnError) { onErrorEvent = [arkCallback = CallbackHelper(arkOnError.value())](const std::u16string& val) { Converter::ConvContext ctx; - arkCallback.Invoke(Converter::ArkValue(val, &ctx)); + arkCallback.InvokeSync(Converter::ArkValue(val, &ctx)); }; } TextFieldModelNG::SetInputFilter(frameNode, valueString.value_or(""), std::move(onErrorEvent)); diff --git a/frameworks/core/interfaces/native/implementation/text_modifier.cpp b/frameworks/core/interfaces/native/implementation/text_modifier.cpp index 1c8d1bc444b0a154a4203b9f5bda9d644ec37c7d..2167379c03e1ed2830de135ac5cbbf4430538a45 100644 --- a/frameworks/core/interfaces/native/implementation/text_modifier.cpp +++ b/frameworks/core/interfaces/native/implementation/text_modifier.cpp @@ -168,7 +168,7 @@ void AssignArkValue(Ark_MarqueeState& dst, int32_t src) break; } } -} +} /* namespace OHOS::Ace::NG::Converter */ namespace OHOS::Ace::NG::GeneratedModifier { namespace TextModifier { @@ -199,8 +199,14 @@ void SetTextOptionsImpl(Ark_NativePointer node, // pass internal controller to peer auto textOptions = Converter::OptConvertPtr(value); - if (textOptions && textOptions->peer) { - textOptions->peer->controller = AceType::DynamicCast(internalController); + CHECK_NULL_VOID(textOptions); + auto textController = textOptions->peer; + CHECK_NULL_VOID(textController); + textController->controller = AceType::DynamicCast(internalController); + auto styledStringCache = textController->GetStyledStringCache(); + if (styledStringCache) { + textController->controller->SetStyledString(styledStringCache); + textController->SetStyledStringCache(nullptr); } } } // TextInterfaceModifier @@ -218,7 +224,10 @@ void SetFontSizeImpl(Ark_NativePointer node, { auto frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); - auto fontSize = Converter::OptConvertPtr(value); + std::optional fontSize = std::nullopt; + if (value->tag != INTEROP_TAG_UNDEFINED) { + fontSize = Converter::OptConvertFromArkNumStrRes(value->value); + } Validator::ValidateNonNegative(fontSize); Validator::ValidateNonPercent(fontSize); TextModelStatic::SetFontSize(frameNode, fontSize); @@ -228,7 +237,10 @@ void SetMinFontSizeImpl(Ark_NativePointer node, { auto frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); - auto fontSize = Converter::OptConvertPtr(value); + std::optional fontSize = std::nullopt; + if (value->tag != INTEROP_TAG_UNDEFINED) { + fontSize = Converter::OptConvertFromArkNumStrRes(value->value); + } Validator::ValidateNonNegative(fontSize); Validator::ValidateNonPercent(fontSize); TextModelStatic::SetAdaptMinFontSize(frameNode, fontSize); @@ -238,7 +250,10 @@ void SetMaxFontSizeImpl(Ark_NativePointer node, { auto frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); - auto fontSize = Converter::OptConvertPtr(value); + std::optional fontSize = std::nullopt; + if (value->tag != INTEROP_TAG_UNDEFINED) { + fontSize = Converter::OptConvertFromArkNumStrRes(value->value); + } Validator::ValidateNonNegative(fontSize); Validator::ValidateNonPercent(fontSize); TextModelStatic::SetAdaptMaxFontSize(frameNode, fontSize); @@ -294,7 +309,10 @@ void SetLineHeightImpl(Ark_NativePointer node, { auto frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); - auto lineHeight = Converter::OptConvertPtr(value); + std::optional lineHeight = std::nullopt; + if (value->tag != INTEROP_TAG_UNDEFINED) { + lineHeight = Converter::OptConvertFromArkNumStrRes(value->value); + } Validator::ValidateNonNegative(lineHeight); TextModelStatic::SetLineHeight(frameNode, lineHeight); } @@ -410,7 +428,10 @@ void SetTextIndentImpl(Ark_NativePointer node, { auto frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); - auto indent = Converter::OptConvertPtr(value); + std::optional indent = std::nullopt; + if (value->tag != INTEROP_TAG_UNDEFINED) { + indent = Converter::OptConvertFromArkNumStrRes(value->value, DimensionUnit::FP); + } TextModelStatic::SetTextIndent(frameNode, indent); } void SetWordBreakImpl(Ark_NativePointer node, @@ -613,6 +634,12 @@ void SetFontImpl(Ark_NativePointer node, if (convValue.has_value()) { convValue->enableVariableFontWeight = enableVariableFontWeight; } + Converter::FontWeightInt defaultWeight = {}; + std::optional weight = defaultWeight; + if (fontValue->tag != INTEROP_TAG_UNDEFINED) { + weight = Converter::OptConvert(fontValue->value.weight).value_or(defaultWeight); + } + TextModelStatic::SetVariableFontWeight(frameNode, weight->variable); TextModelStatic::SetFont(frameNode, convValue); } void SetFontWeightImpl(Ark_NativePointer node, diff --git a/frameworks/core/interfaces/native/utility/ace_engine_types.h b/frameworks/core/interfaces/native/utility/ace_engine_types.h index af6c8b776f481ea8651595d881f215bc0c7274d6..742f2cf816293c131aedeb23fe5ab3a4f4880c66 100644 --- a/frameworks/core/interfaces/native/utility/ace_engine_types.h +++ b/frameworks/core/interfaces/native/utility/ace_engine_types.h @@ -73,6 +73,8 @@ struct AnimateParam { struct SymbolData { std::optional symbol; + std::vector symbolFamilyName; + SymbolType symbolType; }; struct FontFamilies { diff --git a/frameworks/core/interfaces/native/utility/converter.cpp b/frameworks/core/interfaces/native/utility/converter.cpp index 0b4a04385e1802cf66d16b1d7ffd67182f79f167..dd6e85ac081be39a607efb73974d5874c7f39dc8 100644 --- a/frameworks/core/interfaces/native/utility/converter.cpp +++ b/frameworks/core/interfaces/native/utility/converter.cpp @@ -567,6 +567,13 @@ std::optional ResourceConverter::ToInt() std::optional ResourceConverter::ToSymbol() { CHECK_NULL_RETURN(resWrapper_, std::nullopt); + if (type_ == ResourceType::STRING) { + auto result = GetStringResource(); + if (result.has_value() && !result.value().empty()) { + /* 16: specifies base 16 (hexadecimal) */ + return static_cast(strtol(result.value().c_str(), nullptr, 16)); + } + } if (id_ != -1) { return resWrapper_->GetSymbolById(id_); } else if (auto name = GetResourceName(); name) { @@ -2030,28 +2037,36 @@ std::optional OptConvertFromArkLengthResource(const Ark_Resource& src return dimension; } -std::optional OptConvertFromArkNumStrRes(const Ark_Union_Number_String_Resource& src, - DimensionUnit defaultUnit) +template +std::optional OptConvertFromArkNumStrRes(const T& src, DimensionUnit defaultUnit) { std::optional dimension; - auto selector = src.selector; - if (selector == NUM_0) { - std::optional optValue = Converter::OptConvert(src.value0); - if (optValue.has_value()) { - dimension = Dimension(optValue.value(), defaultUnit); - } - } else if (selector == NUM_1) { - std::optional optStr = Converter::OptConvert(src.value1); - if (optStr.has_value()) { - dimension = ConvertFromString(optStr.value(), defaultUnit); - } - } else if (selector == NUM_2) { - dimension = OptConvertFromArkResource(src.value2, defaultUnit); - } else { - LOGE("Unexpected converter type: %{public}d\n", selector); - } + Converter::VisitUnion(src, + [&dimension, defaultUnit](const Ark_Number& value) { + std::optional optValue = Converter::OptConvert(value); + if (optValue.has_value()) { + dimension = Dimension(optValue.value(), defaultUnit); + } + }, + [&dimension, defaultUnit](const Ark_String& value) { + std::optional optStr = Converter::OptConvert(value); + if (optStr.has_value()) { + dimension = ConvertFromString(optStr.value(), defaultUnit); + } + }, + [&dimension, defaultUnit](const Ark_Resource& value) { + dimension = OptConvertFromArkResource(value, defaultUnit); + }, + [&dimension]() { + dimension = Dimension(); + }); + return dimension; } +template std::optional OptConvertFromArkNumStrRes( + const Ark_Union_Number_String_Resource&, DimensionUnit); +template std::optional OptConvertFromArkNumStrRes(const Ark_Dimension&, DimensionUnit); +template std::optional OptConvertFromArkNumStrRes(const Ark_Length&, DimensionUnit); std::optional OptConvertFromArkLength(const Ark_Length& src, DimensionUnit defaultUnit) { @@ -2677,16 +2692,6 @@ void AssignCast(std::optional& dst, const Ark_ShadowStyle& src) dst = shadowTheme->GetShadow(shadowStyle, context->GetColorMode()); } -template<> -void AssignCast(std::optional& dst, const Ark_Resource& src) -{ - ResourceConverter converter(src); - if (!dst) { - dst = SymbolData(); - } - dst->symbol = converter.ToSymbol(); -} - template<> void AssignCast(std::optional& dst, const Ark_UnderlineColor& src) { diff --git a/frameworks/core/interfaces/native/utility/converter.h b/frameworks/core/interfaces/native/utility/converter.h index 1261ce3b040dc9cc2ee2e452c57373cbbac776e4..9e1a94f5d2fd8bc067e70cc25ad3c9fdc3c4a6ea 100644 --- a/frameworks/core/interfaces/native/utility/converter.h +++ b/frameworks/core/interfaces/native/utility/converter.h @@ -211,7 +211,7 @@ namespace Converter { std::vector params_; }; Dimension ConvertFromString(const std::string& str, DimensionUnit unit = DimensionUnit::FP); - std::optional OptConvertFromArkNumStrRes(const Ark_Union_Number_String_Resource& src, + template std::optional OptConvertFromArkNumStrRes(const T& src, DimensionUnit defaultUnit = DimensionUnit::FP); std::optional OptConvertFromArkLength(const Ark_Length& src, DimensionUnit defaultUnit = DimensionUnit::VP); @@ -219,6 +219,7 @@ namespace Converter { DimensionUnit defaultUnit = DimensionUnit::FP); std::optional OptConvertFromArkLengthResource(const Ark_Resource& src, DimensionUnit defaultUnit = DimensionUnit::VP); + template void AssignCast(std::optional& dst, const P& src) { diff --git a/frameworks/core/interfaces/native/utility/reverse_converter.cpp b/frameworks/core/interfaces/native/utility/reverse_converter.cpp index c10d46727317aaa1d143922f3bae209fee2c7293..13212cfd284553d4ace3ded6ebb5225a9f5dea14 100644 --- a/frameworks/core/interfaces/native/utility/reverse_converter.cpp +++ b/frameworks/core/interfaces/native/utility/reverse_converter.cpp @@ -107,13 +107,6 @@ void AssignArkValue(Ark_Area& dst, const BaseEventInfo& src, ConvContext *ctx) dst.height = Converter::ArkValue(src.GetTarget().area.GetHeight().ConvertToVp(), ctx); } -void AssignArkValue(Ark_CaretOffset& dst, const NG::OffsetF& src) -{ - dst.index = Converter::ArkValue(0); - dst.x = Converter::ArkValue(src.GetX()); - dst.y = Converter::ArkValue(src.GetY()); -} - void AssignArkValue(Ark_DragEvent& dragEvent, const RefPtr& info) { const auto peer = PeerUtils::CreatePeer();