diff --git a/frameworks/core/components/xcomponent/native_interface_xcomponent_impl.cpp b/frameworks/core/components/xcomponent/native_interface_xcomponent_impl.cpp index 545fef8d2d106ce5bd1683fbbd307d19bf45fa81..71d18ca0052d07b091d6fc1037ccffa0db23655a 100644 --- a/frameworks/core/components/xcomponent/native_interface_xcomponent_impl.cpp +++ b/frameworks/core/components/xcomponent/native_interface_xcomponent_impl.cpp @@ -366,7 +366,7 @@ int32_t OH_NativeXComponent::GetAccessibilityProvider(ArkUI_AccessibilityProvide return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER; } - (*handle) = xcomponentImpl_->GetAccessbilityProvider().get(); + (*handle) = xcomponentImpl_->GetAccessibilityProvider().get(); return OH_NATIVEXCOMPONENT_RESULT_SUCCESS; } diff --git a/frameworks/core/components/xcomponent/native_interface_xcomponent_impl.h b/frameworks/core/components/xcomponent/native_interface_xcomponent_impl.h index a15cd8a66b373c27e7b15818f93cb7295aad39d4..12fd4a360268e0a9e3c551c87bbb190089a2a217 100644 --- a/frameworks/core/components/xcomponent/native_interface_xcomponent_impl.h +++ b/frameworks/core/components/xcomponent/native_interface_xcomponent_impl.h @@ -79,6 +79,7 @@ class NativeXComponentImpl : public virtual AceType { public: NativeXComponentImpl() { + // can be created as needed accessbilityProvider_ = std::make_shared(); } @@ -300,7 +301,7 @@ public: return &keyEvent_; } - std::shared_ptr GetAccessbilityProvider() + std::shared_ptr GetAccessibilityProvider() { return accessbilityProvider_; } diff --git a/frameworks/core/components_ng/pattern/xcomponent/BUILD.gn b/frameworks/core/components_ng/pattern/xcomponent/BUILD.gn index 1bdf20296398a09c0eac19fcb77aaa8a2666295b..906c200e53a4e201579aaa9e5e7ba8d6b1ca8261 100644 --- a/frameworks/core/components_ng/pattern/xcomponent/BUILD.gn +++ b/frameworks/core/components_ng/pattern/xcomponent/BUILD.gn @@ -21,13 +21,15 @@ build_component_ng("xcomponent_pattern_ng") { "xcomponent_accessibility_session_adapter.cpp", "xcomponent_controller_ng.cpp", "xcomponent_ext_surface_callback_client.cpp", + "xcomponent_inner_surface_controller.cpp", "xcomponent_layout_algorithm.cpp", "xcomponent_model_ng.cpp", "xcomponent_paint_method.cpp", "xcomponent_pattern.cpp", - "xcomponent_pattern_v2.cpp", + "xcomponent_proxy/xcomponent_proxy.cpp", + "xcomponent_proxy/xcomponent_proxy_native_xcomponent.cpp", + "xcomponent_proxy/xcomponent_proxy_surface_holder.cpp", "xcomponent_utils.cpp", - "xcomponent_inner_surface_controller.cpp", ] if (is_ohos_standard_system) { diff --git a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_accessibility_provider.cpp b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_accessibility_provider.cpp index 5cf06063f6b2b0835b76095fb65591684dfed36f..9498fd043c434ba332a61b1783b226aa139642ba 100644 --- a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_accessibility_provider.cpp +++ b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_accessibility_provider.cpp @@ -24,7 +24,7 @@ namespace OHOS::Ace::NG { namespace { constexpr int32_t SEND_EVENT_FAILED = -1; -ArkUI_AccessibilityProvider* GetAccessbilityProvider( +ArkUI_AccessibilityProvider* GetAccessibilityProvider( const WeakPtr& weakPattern) { auto pattern = weakPattern.Upgrade(); @@ -37,7 +37,7 @@ int32_t XComponentAccessibilityProvider::FindAccessibilityNodeInfosById( std::vector& infos) { int32_t errorCode = 0; - auto accessbilityProvider = GetAccessbilityProvider(weakPattern_); + auto accessbilityProvider = GetAccessibilityProvider(weakPattern_); CHECK_NULL_RETURN(accessbilityProvider, errorCode); int32_t ret = accessbilityProvider->FindAccessibilityNodeInfosById( elementId, mode, requestId, infos); @@ -50,7 +50,7 @@ int32_t XComponentAccessibilityProvider::FindAccessibilityNodeInfosByText( std::vector& infos) { int32_t errorCode = 0; - auto accessbilityProvider = GetAccessbilityProvider(weakPattern_); + auto accessbilityProvider = GetAccessibilityProvider(weakPattern_); CHECK_NULL_RETURN(accessbilityProvider, errorCode); int32_t ret = accessbilityProvider->FindAccessibilityNodeInfosByText( elementId, text, requestId, infos); @@ -63,7 +63,7 @@ int32_t XComponentAccessibilityProvider::FindFocusedAccessibilityNode( ArkUI_AccessibilityElementInfo& info) { int32_t errorCode = 0; - auto accessbilityProvider = GetAccessbilityProvider(weakPattern_); + auto accessbilityProvider = GetAccessibilityProvider(weakPattern_); CHECK_NULL_RETURN(accessbilityProvider, errorCode); int32_t ret = accessbilityProvider->FindFocusedAccessibilityNode( elementId, focusType, requestId, info); @@ -76,7 +76,7 @@ int32_t XComponentAccessibilityProvider::FindNextFocusAccessibilityNode( ArkUI_AccessibilityElementInfo& info) { int32_t errorCode = 0; - auto accessbilityProvider = GetAccessbilityProvider(weakPattern_); + auto accessbilityProvider = GetAccessibilityProvider(weakPattern_); CHECK_NULL_RETURN(accessbilityProvider, errorCode); int32_t ret = accessbilityProvider->FindNextFocusAccessibilityNode( elementId, direction, requestId, info); @@ -89,7 +89,7 @@ int32_t XComponentAccessibilityProvider::ExecuteAccessibilityAction( const std::map& actionArguments) { int32_t errorCode = 0; - auto accessbilityProvider = GetAccessbilityProvider(weakPattern_); + auto accessbilityProvider = GetAccessibilityProvider(weakPattern_); CHECK_NULL_RETURN(accessbilityProvider, errorCode); int32_t ret = accessbilityProvider->ExecuteAccessibilityAction( elementId, action, requestId, actionArguments); @@ -100,7 +100,7 @@ int32_t XComponentAccessibilityProvider::ExecuteAccessibilityAction( int32_t XComponentAccessibilityProvider::ClearFocusedAccessibilityNode() { int32_t errorCode = 0; - auto accessbilityProvider = GetAccessbilityProvider(weakPattern_); + auto accessbilityProvider = GetAccessibilityProvider(weakPattern_); CHECK_NULL_RETURN(accessbilityProvider, errorCode); int32_t ret = accessbilityProvider->ClearFocusedAccessibilityNode(); CHECK_EQUAL_RETURN(ret, AccessibilityProviderOperatorErrorCode::NOT_REGISTERED, errorCode); @@ -111,7 +111,7 @@ int32_t XComponentAccessibilityProvider::GetAccessibilityNodeCursorPosition( const int64_t elementId, const int32_t requestId, int32_t &cursorPosition) { int32_t errorCode = 0; - auto accessbilityProvider = GetAccessbilityProvider(weakPattern_); + auto accessbilityProvider = GetAccessibilityProvider(weakPattern_); CHECK_NULL_RETURN(accessbilityProvider, errorCode); int32_t ret = accessbilityProvider->GetAccessibilityNodeCursorPosition( elementId, requestId, cursorPosition); diff --git a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_model_ng.cpp b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_model_ng.cpp index ef0c28c5773ddd50bfb56790d5a4187f3952536a..98f12dcb572199d4483dd74704d7242f9f7b44bf 100644 --- a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_model_ng.cpp @@ -14,9 +14,12 @@ */ #include "core/components_ng/pattern/xcomponent/xcomponent_model_ng.h" +#include +#include "ui/base/utils/utils.h" +#include "core/components/common/layout/constants.h" #include "core/components_ng/pattern/xcomponent/xcomponent_pattern.h" -#include "core/components_ng/pattern/xcomponent/xcomponent_pattern_v2.h" +// #include "core/components_ng/pattern/xcomponent/xcomponent_pattern_v2.h" #include "base/display_manager/display_manager.h" #include "base/error/error_code.h" @@ -28,7 +31,9 @@ void XComponentModelNG::Create(XComponentType type) auto nodeId = stack->ClaimNodeId(); ACE_LAYOUT_SCOPED_TRACE("Create[%sNative][self:%d]", V2::XCOMPONENT_ETS_TAG, nodeId); auto frameNode = FrameNode::GetOrCreateFrameNode(V2::XCOMPONENT_ETS_TAG, nodeId, - [type]() { return AceType::MakeRefPtr(type, XComponentNodeType::DECLARATIVE_NODE); }); + []() { return AceType::MakeRefPtr(XComponentNodeType::DECLARATIVE_NODE); }); + auto pattern = frameNode->GetPattern(); + pattern->InitParams(std::nullopt, type, std::nullopt, nullptr); stack->Push(frameNode); ACE_UPDATE_LAYOUT_PROPERTY(XComponentLayoutProperty, XComponentType, type); } @@ -41,13 +46,17 @@ void XComponentModelNG::Create(const std::optional& id, XComponentT auto nodeId = stack->ClaimNodeId(); ACE_LAYOUT_SCOPED_TRACE("Create[%s][self:%d]", V2::XCOMPONENT_ETS_TAG, nodeId); auto frameNode = FrameNode::GetOrCreateFrameNode( - V2::XCOMPONENT_ETS_TAG, nodeId, [id, type, libraryname, xcomponentController]() { - return AceType::MakeRefPtr(id, type, libraryname, xcomponentController); + V2::XCOMPONENT_ETS_TAG, nodeId, []() { + return AceType::MakeRefPtr(XComponentNodeType::DECLARATIVE_NODE); }); + auto pattern = frameNode->GetPattern(); + CHECK_NULL_VOID(pattern); + pattern->InitParams(id, type, libraryname, xcomponentController); stack->Push(frameNode); ACE_UPDATE_LAYOUT_PROPERTY(XComponentLayoutProperty, XComponentType, type); } +// for XComponentNode which is deprecated RefPtr XComponentModelNG::Create(int32_t nodeId, float width, float height, const std::string& id, XComponentType type, const std::string& libraryname, const std::shared_ptr& xcomponentController) @@ -55,13 +64,14 @@ RefPtr XComponentModelNG::Create(int32_t nodeId, float width, float hei ACE_LAYOUT_SCOPED_TRACE("Create[%s][self:%d]", V2::XCOMPONENT_ETS_TAG, nodeId); auto calcWidth = CalcLength(width, DimensionUnit::VP); auto calcHeight = CalcLength(height, DimensionUnit::VP); - auto frameNode = FrameNode::GetOrCreateFrameNode( - V2::XCOMPONENT_ETS_TAG, nodeId, [id, type, libraryname, xcomponentController, calcWidth, calcHeight]() { - return AceType::MakeRefPtr(id, type, libraryname, xcomponentController, - calcWidth.GetDimension().ConvertToPx(), calcHeight.GetDimension().ConvertToPx()); - }); + auto frameNode = FrameNode::GetOrCreateFrameNode(V2::XCOMPONENT_ETS_TAG, nodeId, + []() { return AceType::MakeRefPtr(XComponentNodeType::DECLARATIVE_NODE); }); CHECK_NULL_RETURN(frameNode, nullptr); + auto pattern = frameNode->GetPattern(); + CHECK_NULL_RETURN(pattern, nullptr); + pattern->InitParams(id, type, libraryname, xcomponentController, calcWidth.GetDimension().ConvertToPx(), + calcHeight.GetDimension().ConvertToPx()); auto layoutProperty = frameNode->GetLayoutProperty(); CHECK_NULL_RETURN(layoutProperty, frameNode); layoutProperty->UpdateXComponentType(type); @@ -324,11 +334,12 @@ XComponentType XComponentModelNG::GetType(FrameNode* frameNode) } // For CAPI XComponent -RefPtr XComponentModelNG::CreateFrameNode(int32_t nodeId, const std::string& id, XComponentType type, - const std::optional& libraryname) +RefPtr XComponentModelNG::CreateFrameNode( + int32_t nodeId, const std::string& id, XComponentType type, const std::optional& libraryname) { - auto pattern = AceType::MakeRefPtr(type, XComponentNodeType::CNODE); + auto pattern = AceType::MakeRefPtr(XComponentNodeType::CNODE); auto frameNode = FrameNode::CreateFrameNode(V2::XCOMPONENT_ETS_TAG, nodeId, pattern); + pattern->InitParams(id, type, libraryname, nullptr); auto layoutProperty = frameNode->GetLayoutProperty(); CHECK_NULL_RETURN(layoutProperty, frameNode); layoutProperty->UpdateXComponentType(type); @@ -345,11 +356,17 @@ RefPtr XComponentModelNG::CreateTypeNode(int32_t nodeId, ArkUI_XCompo RefPtr frameNode; if (id.empty() && controller == nullptr && (type == XComponentType::SURFACE || type == XComponentType::TEXTURE)) { - frameNode = FrameNode::CreateFrameNode(V2::XCOMPONENT_ETS_TAG, nodeId, - AceType::MakeRefPtr(type, XComponentNodeType::TYPE_NODE)); + frameNode = FrameNode::CreateFrameNode( + V2::XCOMPONENT_ETS_TAG, nodeId, AceType::MakeRefPtr(XComponentNodeType::TYPE_NODE)); + auto pattern = frameNode->GetPattern(); + CHECK_NULL_RETURN(pattern, nullptr); + pattern->InitParams(std::nullopt, type, libraryName, controller); } else { - frameNode = FrameNode::CreateFrameNode(V2::XCOMPONENT_ETS_TAG, nodeId, - AceType::MakeRefPtr(id, type, libraryName, controller, 0.0, 0.0, true)); + frameNode = FrameNode::CreateFrameNode( + V2::XCOMPONENT_ETS_TAG, nodeId, AceType::MakeRefPtr(XComponentNodeType::TYPE_NODE)); + auto pattern = frameNode->GetPattern(); + CHECK_NULL_RETURN(pattern, nullptr); + pattern->InitParams(id, type, libraryName, controller); } auto layoutProperty = frameNode->GetLayoutProperty(); if (layoutProperty) { @@ -624,9 +641,9 @@ bool XComponentModelNG::GetXComponentEnableAnalyzer(FrameNode* frameNode) int32_t XComponentModelNG::SetExpectedRateRange(FrameNode* frameNode, int32_t min, int32_t max, int32_t expected) { CHECK_NULL_RETURN(frameNode, ERROR_CODE_PARAM_INVALID); - auto xcPattern = frameNode->GetPattern(); + auto xcPattern = frameNode->GetPattern(); CHECK_NULL_RETURN(xcPattern, ERROR_CODE_PARAM_INVALID); - if (xcPattern->HasGotNativeXComponent()) { + if (xcPattern->IsUsingNativeXComponent()) { return ERROR_CODE_PARAM_INVALID; } xcPattern->SetExpectedRateRange(min, max, expected); @@ -637,9 +654,9 @@ int32_t XComponentModelNG::SetOnFrameCallback(FrameNode* frameNode, void(*callback)(void*, uint64_t, uint64_t), void* arkuiNode) { CHECK_NULL_RETURN(frameNode, ERROR_CODE_PARAM_INVALID); - auto xcPattern = frameNode->GetPattern(); + auto xcPattern = frameNode->GetPattern(); CHECK_NULL_RETURN(xcPattern, ERROR_CODE_PARAM_INVALID); - if (xcPattern->HasGotNativeXComponent()) { + if (xcPattern->IsUsingNativeXComponent()) { return ERROR_CODE_PARAM_INVALID; } xcPattern->UpdateOnFrameEvent(callback, arkuiNode); @@ -649,9 +666,9 @@ int32_t XComponentModelNG::SetOnFrameCallback(FrameNode* frameNode, int32_t XComponentModelNG::UnregisterOnFrameCallback(FrameNode* frameNode) { CHECK_NULL_RETURN(frameNode, ERROR_CODE_PARAM_INVALID); - auto xcPattern = frameNode->GetPattern(); + auto xcPattern = frameNode->GetPattern(); CHECK_NULL_RETURN(xcPattern, ERROR_CODE_PARAM_INVALID); - if (xcPattern->HasGotNativeXComponent()) { + if (xcPattern->IsUsingNativeXComponent()) { return ERROR_CODE_PARAM_INVALID; } xcPattern->UpdateOnFrameEvent(nullptr, nullptr); @@ -662,9 +679,9 @@ int32_t XComponentModelNG::UnregisterOnFrameCallback(FrameNode* frameNode) int32_t XComponentModelNG::SetNeedSoftKeyboard(FrameNode* frameNode, bool needSoftKeyboard) { CHECK_NULL_RETURN(frameNode, ERROR_CODE_PARAM_INVALID); - auto xcPattern = frameNode->GetPattern(); + auto xcPattern = frameNode->GetPattern(); CHECK_NULL_RETURN(xcPattern, ERROR_CODE_PARAM_INVALID); - if (xcPattern->HasGotNativeXComponent()) { + if (xcPattern->IsUsingNativeXComponent()) { return ERROR_CODE_PARAM_INVALID; } xcPattern->SetNeedSoftKeyboard(needSoftKeyboard); @@ -674,9 +691,9 @@ int32_t XComponentModelNG::SetNeedSoftKeyboard(FrameNode* frameNode, bool needSo void* XComponentModelNG::CreateAccessibilityProvider(FrameNode* frameNode) { CHECK_NULL_RETURN(frameNode, nullptr); - auto xcPattern = frameNode->GetPattern(); + auto xcPattern = frameNode->GetPattern(); CHECK_NULL_RETURN(xcPattern, nullptr); - if (xcPattern->HasGotNativeXComponent()) { + if (xcPattern->IsUsingNativeXComponent()) { return nullptr; } return xcPattern->CreateAccessibilityProvider(); @@ -686,13 +703,13 @@ void XComponentModelNG::DisposeAccessibilityProvider(ArkUI_AccessibilityProvider { CHECK_NULL_VOID(provider); bool isProviderValied = false; - auto frameNode = XComponentPatternV2::QueryAccessibilityProviderHost(provider, isProviderValied); + auto frameNode = XComponentPattern::QueryAccessibilityProviderHost(provider, isProviderValied); if (!isProviderValied) { return; } - RefPtr xcPattern = (frameNode == nullptr) + RefPtr xcPattern = (frameNode == nullptr) ? (nullptr) - : (frameNode->GetPattern()); + : (frameNode->GetPattern()); if (xcPattern) { xcPattern->DisposeAccessibilityProvider(provider); return; diff --git a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.cpp b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.cpp index ad286ea83da6f9790fc5a588d9184607d9f6b38e..ba4ec5dad632307702e4cdc8f94755741366f058 100644 --- a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.cpp +++ b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.cpp @@ -17,9 +17,13 @@ #include #include +#include #include "interfaces/native/event/ui_input_event_impl.h" +#include "interfaces/native/native_interface_accessibility.h" +#include "interfaces/native/native_interface_xcomponent.h" #include "interfaces/native/ui_input_event.h" +#include "ui/base/utils/utils.h" #include "base/geometry/ng/point_t.h" #include "base/geometry/ng/size_t.h" @@ -36,6 +40,8 @@ #include "core/components/common/layout/constants.h" #include "core/components_ng/event/gesture_event_hub.h" #include "core/components_ng/pattern/xcomponent/xcomponent_controller_ng.h" +#include "core/components_ng/pattern/xcomponent/xcomponent_proxy/xcomponent_proxy_native_xcomponent.h" +#include "core/components_ng/pattern/xcomponent/xcomponent_proxy/xcomponent_proxy_surface_holder.h" #include "core/event/axis_event.h" #ifdef NG_BUILD #include "bridge/declarative_frontend/ng/declarative_frontend_ng.h" @@ -71,18 +77,151 @@ namespace { const std::string BUFFER_USAGE_XCOMPONENT = "xcomponent"; } // namespace -XComponentPattern::XComponentPattern(const std::optional& id, XComponentType type, +XComponentPattern::XComponentPattern(XComponentNodeType nodeType) : nodeType_(nodeType) +{ + RegisterSurfaceCallbackModeEvent(); +} + +void XComponentPattern::InitParams(const std::optional& id, XComponentType type, const std::optional& libraryname, - const std::shared_ptr& xcomponentController, float initWidth, float initHeight, - bool isTypedNode) - : id_(id), type_(type), xcomponentController_(xcomponentController), initSize_(initWidth, initHeight), - isTypedNode_(isTypedNode) + const std::shared_ptr& xcomponentController, float initWidth, float initHeight) { + if (type_ != XComponentType::UNKNOWN) { + return; + } + id_ = id; + type_ = type; SetLibraryName(libraryname); - if (!isTypedNode_) { + xcomponentController_ = xcomponentController; + if (type == XComponentType::SURFACE || type == XComponentType::TEXTURE) { + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto renderContext = host->GetRenderContext(); + CHECK_NULL_VOID(renderContext); + + renderContext->SetClipToFrame(true); + renderContext->SetClipToBounds(true); + if (FrameReport::GetInstance().GetEnable()) { + FrameReport::GetInstance().EnableSelfRender(); + } + } + if (id == std::nullopt && xcomponentController == nullptr && + (type == XComponentType::SURFACE || type == XComponentType::TEXTURE) && + nodeType_ != XComponentNodeType::CNODE) { + InitForSurfaceHolder(); + } else { + initSize_ = SizeF { initWidth, initHeight }; // only for XComponentNode which is deprecated + InitForNonSurfaceHolder(); + } +} + +void XComponentPattern::InitForNonSurfaceHolder() +{ + if (type_ == XComponentType::NODE) { + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto focusHub = host->GetOrCreateFocusHub(); + focusHub->SetFocusType(FocusType::SCOPE); + focusHub->SetFocusable(true); + } + xcomponentProxy_ = MakeRefPtr(WeakClaim(this)); + if (nodeType_ == XComponentNodeType::CNODE) { + xcomponentProxy_->SetToggleEnabled(true); + } + if (nodeType_ != XComponentNodeType::TYPE_NODE) { InitNativeXComponent(); } - RegisterSurfaceCallbackModeEvent(); + if (type_ == XComponentType::SURFACE || type_ == XComponentType::TEXTURE) { + InitSurface(); + if (nodeType_ == XComponentNodeType::TYPE_NODE || nodeType_ == XComponentNodeType::CNODE) { + InitNativeWindow(initSize_.Width(), initSize_.Height()); + } + // only xcomponent created by capi will set successfully, others will be set in FireExternalEvent + SetExpectedRateRangeInit(); + OnFrameEventInit(); + UnregisterOnFrameEventInit(); + InitEvent(); + InitController(); + } else if (type_ == XComponentType::NODE) { + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto focusHub = host->GetOrCreateFocusHub(); + focusHub->SetFocusType(FocusType::SCOPE); + focusHub->SetFocusable(true); + auto context = host->GetContextRefPtr(); + if (id_.has_value() && context) { + FireExternalEvent(context, id_.value(), host->GetId(), false); + InitNativeNodeCallbacks(); + } + } + if (nodeType_ != XComponentNodeType::TYPE_NODE) { + InitializeAccessibility(); + } +} + +void XComponentPattern::InitForSurfaceHolder() +{ + xcomponentProxy_ = MakeRefPtr(WeakClaim(this)); + InitSurface(); + renderSurface_->RegisterSurface(); + InitNativeWindow(paintRect_.Width(), paintRect_.Height()); + auto xcomponentProxySurfaceHolder = DynamicCast(xcomponentProxy_); + CHECK_NULL_VOID(xcomponentProxySurfaceHolder); + xcomponentProxySurfaceHolder->SetNativeWindow(nativeWindow_); +} + +void XComponentPattern::ReinitializeSurfaceProperties() +{ + CHECK_NULL_VOID(renderContextForSurface_); + CHECK_NULL_VOID(renderSurface_); + if (!paintRect_.IsEmpty()) { + auto width = paintRect_.Width(); + auto height = paintRect_.Height(); + renderContextForSurface_->SetBounds(paintRect_.GetX(), paintRect_.GetY(), width, height); + renderSurface_->UpdateSurfaceSizeInUserData(static_cast(width), static_cast(height)); + renderSurface_->SetSurfaceDefaultSize(static_cast(width), static_cast(height)); + } + renderContextForSurface_->UpdateBackgroundColor(bkColor_); + renderContextForSurface_->SetHDRBrightness(hdrBrightness_); + renderContextForSurface_->SetTransparentLayer(isTransparentLayer_); + renderContextForSurface_->SetSecurityLayer(isEnableSecure_); + renderContextForSurface_->SetSurfaceRotation(isSurfaceLock_); + renderContextForSurface_->SetRenderFit(renderFit_); + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto renderContext = host->GetRenderContext(); + CHECK_NULL_VOID(renderContext); + renderContext->AddChild(renderContextForSurface_, 0); + needReinitialize_ = false; +} + +void XComponentPattern::OnSizeChange( + bool offsetChanged, bool sizeChanged, bool frameOffsetChange, bool needFireNativeEvent) +{ + if (!hasXComponentInit_) { + initSize_ = paintRect_.GetSize(); + if (!SystemProperties::GetExtSurfaceEnabled() && nodeType_ != XComponentNodeType::TYPE_NODE) { + XComponentSizeInit(); + } + auto offset = globalPosition_ + paintRect_.GetOffset(); + NativeXComponentOffset(offset.GetX(), offset.GetY()); + hasXComponentInit_ = true; + } +#ifndef RENDER_EXTRACT_SUPPORTED + auto host = GetHost(); + CHECK_NULL_VOID(host); + if (SystemProperties::GetExtSurfaceEnabled()) { + auto transformRelativeOffset = host->GetTransformRelativeOffset(); + renderSurface_->SetExtSurfaceBounds( + static_cast(transformRelativeOffset.GetX() + localPosition_.GetX()), + static_cast(transformRelativeOffset.GetY() + localPosition_.GetY()), + static_cast(drawSize_.Width()), static_cast(drawSize_.Height())); + } + HandleSurfaceChangeEvent(false, offsetChanged, sizeChanged, needFireNativeEvent, frameOffsetChange); +#endif + if (type_ == XComponentType::SURFACE && renderType_ == NodeRenderType::RENDER_TYPE_TEXTURE) { + AddAfterLayoutTaskForExportTexture(); + } } std::string XComponentPattern::XComponentTypeToString(XComponentType type) @@ -135,15 +274,15 @@ void XComponentPattern::InitNativeXComponent() { if ((type_ == XComponentType::SURFACE || type_ == XComponentType::TEXTURE) && libraryname_.has_value()) { isNativeXComponent_ = true; - nativeXComponentImpl_ = AceType::MakeRefPtr(); - nativeXComponent_ = std::make_shared(AceType::RawPtr(nativeXComponentImpl_)); + auto xcomponentProxyNativeXComponent = DynamicCast(xcomponentProxy_); + xcomponentProxyNativeXComponent->GetOrCreateNativeXComponent(); } } void XComponentPattern::InitXComponent() { // used for TypedNode, not for declareative - if (isTypedNode_) { + if (nodeType_ == XComponentNodeType::TYPE_NODE) { InitNativeXComponent(); if (isNativeXComponent_) { InitializeAccessibility(); @@ -154,18 +293,14 @@ void XComponentPattern::InitXComponent() void XComponentPattern::InitSurface() { + if (renderSurface_) { + return; + } auto host = GetHost(); CHECK_NULL_VOID(host); auto renderContext = host->GetRenderContext(); CHECK_NULL_VOID(renderContext); - // only xcomponent created by capi will set successfully, others will be set in FireExternalEvent - SetExpectedRateRangeInit(); - OnFrameEventInit(); - UnregisterOnFrameEventInit(); - - renderContext->SetClipToFrame(true); - renderContext->SetClipToBounds(true); #ifdef RENDER_EXTRACT_SUPPORTED renderSurface_ = RenderSurface::Create(CovertToRenderSurfaceType(type_)); #else @@ -198,9 +333,6 @@ void XComponentPattern::InitSurface() if (type_ == XComponentType::TEXTURE) { renderSurface_->RegisterBufferCallback(); } - if (isTypedNode_ || isCNode_) { - InitNativeWindow(initSize_.Width(), initSize_.Height()); - } surfaceId_ = renderSurface_->GetUniqueId(); initialSurfaceId_ = surfaceId_; UpdateTransformHint(); @@ -247,34 +379,11 @@ void XComponentPattern::RegisterTransformHintCallback(PipelineContext* context) UpdateTransformHintChangedCallbackId(callbackId); } -void XComponentPattern::Initialize() -{ - if (type_ == XComponentType::SURFACE || type_ == XComponentType::TEXTURE) { - InitSurface(); - InitEvent(); - InitController(); - } else if (type_ == XComponentType::NODE && id_.has_value()) { - auto host = GetHost(); - CHECK_NULL_VOID(host); - auto context = host->GetContextRefPtr(); - if (context) { - FireExternalEvent(context, id_.value(), host->GetId(), false); - InitNativeNodeCallbacks(); - } - } - if (!isTypedNode_) { - InitializeAccessibility(); - } -} - void XComponentPattern::OnAttachToMainTree() { TAG_LOGI(AceLogTag::ACE_XCOMPONENT, "XComponent[%{public}s] AttachToMainTree", GetId().c_str()); ACE_SCOPED_TRACE("XComponent[%s] AttachToMainTree", GetId().c_str()); isOnTree_ = true; - if (isTypedNode_ && surfaceCallbackMode_ == SurfaceCallbackMode::DEFAULT) { - HandleSurfaceCreated(); - } auto host = GetHost(); CHECK_NULL_VOID(host); if (host->GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_EIGHTEEN)) { @@ -285,6 +394,9 @@ void XComponentPattern::OnAttachToMainTree() needRecoverDisplaySync_ = false; } } + if (xcomponentProxy_) { + xcomponentProxy_->OnAttachToMainTree(); + } } void XComponentPattern::OnDetachFromMainTree() @@ -292,9 +404,6 @@ void XComponentPattern::OnDetachFromMainTree() TAG_LOGI(AceLogTag::ACE_XCOMPONENT, "XComponent[%{public}s] DetachFromMainTree", GetId().c_str()); ACE_SCOPED_TRACE("XComponent[%s] DetachFromMainTree", GetId().c_str()); isOnTree_ = false; - if (isTypedNode_ && surfaceCallbackMode_ == SurfaceCallbackMode::DEFAULT) { - HandleSurfaceDestroyed(); - } auto host = GetHost(); CHECK_NULL_VOID(host); if (host->GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_EIGHTEEN)) { @@ -305,10 +414,16 @@ void XComponentPattern::OnDetachFromMainTree() needRecoverDisplaySync_ = true; } } + if (xcomponentProxy_) { + xcomponentProxy_->OnDetachFromMainTree(); + } } void XComponentPattern::InitializeRenderContext() { + if (renderContextForSurface_) { + return; + } renderContextForSurface_ = RenderContext::Create(); #ifdef RENDER_EXTRACT_SUPPORTED auto contextType = type_ == XComponentType::TEXTURE ? RenderContext::ContextType::HARDWARE_TEXTURE @@ -321,7 +436,9 @@ void XComponentPattern::InitializeRenderContext() renderContextForSurface_->InitContext(false, param); - renderContextForSurface_->UpdateBackgroundColor(Color::BLACK); + if (needReinitialize_) { + ReinitializeSurfaceProperties(); + } } #ifdef RENDER_EXTRACT_SUPPORTED @@ -374,18 +491,11 @@ void XComponentPattern::RequestFocus() } #endif -void XComponentPattern::OnAttachToFrameNode() -{ - Initialize(); - if (FrameReport::GetInstance().GetEnable()) { - FrameReport::GetInstance().EnableSelfRender(); - } -} - void XComponentPattern::OnModifyDone() { Pattern::OnModifyDone(); // if surface has been reset by pip, do not set backgourndColor + // need do sth for pip if (handlingSurfaceRenderContext_ != renderContextForSurface_) { return; } @@ -469,7 +579,7 @@ void XComponentPattern::OnDetachFromFrameNode(FrameNode* frameNode) UnregisterSurfaceRenderContext(); CHECK_NULL_VOID(frameNode); UninitializeAccessibility(frameNode); - if (isTypedNode_) { + if (nodeType_ == XComponentNodeType::TYPE_NODE) { if (surfaceCallbackMode_ == SurfaceCallbackMode::PIP) { HandleSurfaceDestroyed(frameNode); } @@ -531,7 +641,7 @@ void XComponentPattern::InitController() }, "ArkUIXComponentSurfaceConfigChange"); }); - if (!isTypedNode_) { + if (nodeType_ != XComponentNodeType::TYPE_NODE) { xcomponentController_->SetSurfaceId(surfaceId_); } } @@ -616,27 +726,8 @@ void XComponentPattern::BeforeSyncGeometryProperties(const DirtySwapConfig& conf UpdateAnalyzerUIConfig(geometryNode); } const auto& [offsetChanged, sizeChanged, needFireNativeEvent] = UpdateSurfaceRect(); - if (!hasXComponentInit_) { - initSize_ = paintRect_.GetSize(); - if (!SystemProperties::GetExtSurfaceEnabled() && !isTypedNode_) { - XComponentSizeInit(); - } - auto offset = globalPosition_ + paintRect_.GetOffset(); - NativeXComponentOffset(offset.GetX(), offset.GetY()); - hasXComponentInit_ = true; - } -#ifndef RENDER_EXTRACT_SUPPORTED - if (SystemProperties::GetExtSurfaceEnabled()) { - auto transformRelativeOffset = host->GetTransformRelativeOffset(); - renderSurface_->SetExtSurfaceBounds( - static_cast(transformRelativeOffset.GetX() + localPosition_.GetX()), - static_cast(transformRelativeOffset.GetY() + localPosition_.GetY()), - static_cast(drawSize_.Width()), static_cast(drawSize_.Height())); - } - HandleSurfaceChangeEvent(false, offsetChanged, sizeChanged, needFireNativeEvent, config.frameOffsetChange); -#endif - if (type_ == XComponentType::SURFACE && renderType_ == NodeRenderType::RENDER_TYPE_TEXTURE) { - AddAfterLayoutTaskForExportTexture(); + if (xcomponentProxy_) { + xcomponentProxy_->OnSizeChange(offsetChanged, sizeChanged, needFireNativeEvent, config.frameOffsetChange); } host->MarkNeedSyncRenderTree(); } @@ -663,50 +754,44 @@ void XComponentPattern::DumpAdvanceInfo() } } +std::pair, std::weak_ptr> +XComponentPattern::GetNativeXComponent() +{ + auto xcomponentProxyNativeXComponent = DynamicCast(xcomponentProxy_); + CHECK_NULL_RETURN(xcomponentProxyNativeXComponent, {}); + return xcomponentProxyNativeXComponent->GetOrCreateNativeXComponent(); +} + void XComponentPattern::NativeXComponentOffset(double x, double y) { CHECK_RUN_ON(UI); - CHECK_NULL_VOID(nativeXComponent_); - CHECK_NULL_VOID(nativeXComponentImpl_); auto host = GetHost(); CHECK_NULL_VOID(host); auto pipelineContext = host->GetContextRefPtr(); CHECK_NULL_VOID(pipelineContext); float scale = pipelineContext->GetViewScale(); - nativeXComponentImpl_->SetXComponentOffsetX(x * scale); - nativeXComponentImpl_->SetXComponentOffsetY(y * scale); -} - -void XComponentPattern::NativeXComponentDispatchTouchEvent( - const OH_NativeXComponent_TouchEvent& touchEvent, const std::vector& xComponentTouchPoints) -{ - CHECK_RUN_ON(UI); - CHECK_NULL_VOID(nativeXComponent_); - CHECK_NULL_VOID(nativeXComponentImpl_); - nativeXComponentImpl_->SetTouchEvent(touchEvent); - nativeXComponentImpl_->SetTouchPoint(xComponentTouchPoints); - auto* surface = const_cast(nativeXComponentImpl_->GetSurface()); - const auto* callback = nativeXComponentImpl_->GetCallback(); - CHECK_NULL_VOID(callback); - CHECK_NULL_VOID(callback->DispatchTouchEvent); - callback->DispatchTouchEvent(nativeXComponent_.get(), surface); + auto xcomponentProxyNativeXComponent = DynamicCast(xcomponentProxy_); + CHECK_NULL_VOID(xcomponentProxyNativeXComponent); + xcomponentProxyNativeXComponent->SetNativeXComponentOffset(x * scale, y * scale); } void XComponentPattern::InitNativeWindow(float textureWidth, float textureHeight) { - auto host = GetHost(); - CHECK_NULL_VOID(host); - auto context = host->GetContextRefPtr(); - CHECK_NULL_VOID(context); CHECK_NULL_VOID(renderSurface_); if (renderSurface_->GetNativeWindow()) { return; } if (renderSurface_->IsSurfaceValid() && (type_ == XComponentType::SURFACE || type_ == XComponentType::TEXTURE)) { - float viewScale = context->GetViewScale(); renderSurface_->CreateNativeWindow(); - renderSurface_->AdjustNativeWindowSize( - static_cast(textureWidth * viewScale), static_cast(textureHeight * viewScale)); + if (textureWidth > 0 && textureHeight > 0) { + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto context = host->GetContextRefPtr(); + CHECK_NULL_VOID(context); + float viewScale = context->GetViewScale(); + renderSurface_->AdjustNativeWindowSize( + static_cast(textureWidth * viewScale), static_cast(textureHeight * viewScale)); + } nativeWindow_ = renderSurface_->GetNativeWindow(); } } @@ -716,12 +801,12 @@ void XComponentPattern::XComponentSizeInit() CHECK_RUN_ON(UI); auto host = GetHost(); CHECK_NULL_VOID(host); - if (!isCNode_) { + if (nodeType_ != XComponentNodeType::CNODE) { InitNativeWindow(initSize_.Width(), initSize_.Height()); } else { AdjustNativeWindowSize(initSize_.Width(), initSize_.Height()); } - + #ifdef RENDER_EXTRACT_SUPPORTED if (xcomponentController_ && renderSurface_) { surfaceId_ = renderSurface_->GetUniqueId(); @@ -745,15 +830,17 @@ void XComponentPattern::XComponentSizeChange(const RectF& surfaceRect, bool need CHECK_NULL_VOID(host); renderSurface_->UpdateSurfaceSizeInUserData( static_cast(surfaceRect.Width()), static_cast(surfaceRect.Height())); - // In declarative mode: Native onSurfaceCreated callback is triggred // when the component finish it's first layout, so do not trigger the native onSurfaceChanged callback - if (!isTypedNode_ && isNativeXComponent_ && !needFireNativeEvent) { + if (nodeType_ != XComponentNodeType::TYPE_NODE && isNativeXComponent_ && !needFireNativeEvent) { return; } // When creating the surface for the first time, needFireNativeEvent = false, other time needFireNativeEvent = true // the first time change size no need to resize nativeWindow - OnSurfaceChanged(surfaceRect, needFireNativeEvent); + if (needFireNativeEvent) { + AdjustNativeWindowSize(surfaceRect.Width(), surfaceRect.Height()); + } + OnSurfaceChanged(surfaceRect); } RefPtr XComponentPattern::GetAccessibilitySessionAdapter() @@ -763,55 +850,22 @@ RefPtr XComponentPattern::GetAccessibilitySessionAd void XComponentPattern::InitializeAccessibility() { - if (accessibilityChildTreeCallback_) { - return; - } - - InitializeAccessibilityCallback(); - auto host = GetHost(); - CHECK_NULL_VOID(host); - int64_t accessibilityId = host->GetAccessibilityId(); - TAG_LOGI(AceLogTag::ACE_XCOMPONENT, - "InitializeAccessibility accessibilityId: %{public}" PRId64 "", accessibilityId); - auto pipeline = host->GetContextRefPtr(); - CHECK_NULL_VOID(pipeline); - auto accessibilityManager = pipeline->GetAccessibilityManager(); - CHECK_NULL_VOID(accessibilityManager); - accessibilityChildTreeCallback_ = std::make_shared( - WeakClaim(this), host->GetAccessibilityId()); - accessibilityManager->RegisterAccessibilityChildTreeCallback( - accessibilityId, accessibilityChildTreeCallback_); - if (accessibilityManager->IsRegister()) { - accessibilityChildTreeCallback_->OnRegister( - pipeline->GetWindowId(), accessibilityManager->GetTreeId()); + if (xcomponentProxy_) { + xcomponentProxy_->InitializeAccessibility(); } } void XComponentPattern::UninitializeAccessibility(FrameNode* frameNode) { - TAG_LOGI(AceLogTag::ACE_XCOMPONENT, "UninitializeAccessibility"); - CHECK_NULL_VOID(frameNode); - int64_t accessibilityId = frameNode->GetAccessibilityId(); - auto pipeline = frameNode->GetContextRefPtr(); - CHECK_NULL_VOID(pipeline); - auto accessibilityManager = pipeline->GetAccessibilityManager(); - CHECK_NULL_VOID(accessibilityManager); - if (accessibilityManager->IsRegister() && accessibilityChildTreeCallback_) { - accessibilityChildTreeCallback_->OnDeregister(); + if (xcomponentProxy_) { + xcomponentProxy_->UninitializeAccessibility(frameNode); } - accessibilityManager->DeregisterAccessibilityChildTreeCallback(accessibilityId); - accessibilityChildTreeCallback_ = nullptr; } ArkUI_AccessibilityProvider* XComponentPattern::GetNativeProvider() { - if(useNodeHandleAccessibilityProvider_) { - return arkuiAccessibilityProvider_; - } - auto pair = GetNativeXComponent(); - auto nativeXComponentImpl = pair.first; - CHECK_NULL_RETURN(nativeXComponentImpl, nullptr); - return nativeXComponentImpl->GetAccessbilityProvider().get(); + CHECK_NULL_RETURN(xcomponentProxy_, nullptr); + return xcomponentProxy_->GetAccessibilityProvider(); } bool XComponentPattern::OnAccessibilityChildTreeRegister(uint32_t windowId, int32_t treeId) @@ -862,7 +916,7 @@ bool XComponentPattern::OnAccessibilityChildTreeDeregister() CHECK_NULL_RETURN(pipeline, false); auto accessibilityManager = pipeline->GetAccessibilityManager(); CHECK_NULL_RETURN(accessibilityManager, false); - auto nativeProvider = GetNativeProvider(); + auto* nativeProvider = GetNativeProvider(); CHECK_NULL_RETURN(nativeProvider, false); nativeProvider->SetInnerAccessibilityProvider(nullptr); accessibilitySessionAdapter_ = nullptr; @@ -885,72 +939,13 @@ void XComponentPattern::OnSetAccessibilityChildTree( accessibilityProperty->SetChildTreeId(childTreeId); } -void XComponentPattern::InitializeAccessibilityCallback() -{ - TAG_LOGI(AceLogTag::ACE_XCOMPONENT, "InitializeAccessibilityCallback"); - CHECK_NULL_VOID(nativeXComponentImpl_); - auto nativeProvider = nativeXComponentImpl_->GetAccessbilityProvider(); - CHECK_NULL_VOID(nativeProvider); - nativeProvider->SetRegisterCallback( - [weak = WeakClaim(this)] (bool isRegister) { - auto pattern = weak.Upgrade(); - CHECK_NULL_VOID(pattern); - pattern->HandleRegisterAccessibilityEvent(isRegister); - }); -} - -void XComponentPattern::HandleRegisterAccessibilityEvent(bool isRegister) -{ - TAG_LOGI(AceLogTag::ACE_XCOMPONENT, "HandleRegisterAccessibilityEvent, " - "isRegister: %{public}d.", isRegister); - CHECK_NULL_VOID(accessibilityChildTreeCallback_); - auto host = GetHost(); - CHECK_NULL_VOID(host); - auto pipeline = host->GetContextRefPtr(); - CHECK_NULL_VOID(pipeline); - auto accessibilityManager = pipeline->GetAccessibilityManager(); - CHECK_NULL_VOID(accessibilityManager); - if (!isRegister) { - accessibilityChildTreeCallback_->OnDeregister(); - return; - } - - if (accessibilityManager->IsRegister()) { - accessibilityChildTreeCallback_->OnRegister( - pipeline->GetWindowId(), accessibilityManager->GetTreeId()); - } -} - void XComponentPattern::InitNativeNodeCallbacks() { - CHECK_NULL_VOID(nativeXComponent_); - CHECK_NULL_VOID(nativeXComponentImpl_); - auto host = GetHost(); CHECK_NULL_VOID(host); - nativeXComponentImpl_->registerContaner(AceType::RawPtr(host)); - - auto OnAttachRootNativeNode = [](void* container, void* root) { - ContainerScope scope(Container::CurrentIdSafely()); - auto node = AceType::Claim(reinterpret_cast(root)); - CHECK_NULL_VOID(node); - auto host = AceType::Claim(reinterpret_cast(container)); - CHECK_NULL_VOID(host); - host->AddChild(node); - host->MarkDirtyNode(PROPERTY_UPDATE_MEASURE); - }; - - auto OnDetachRootNativeNode = [](void* container, void* root) { - ContainerScope scope(Container::CurrentIdSafely()); - auto node = AceType::Claim(reinterpret_cast(root)); - CHECK_NULL_VOID(node); - auto host = AceType::Claim(reinterpret_cast(container)); - CHECK_NULL_VOID(host); - host->RemoveChild(node); - }; - - nativeXComponentImpl_->registerNativeNodeCallbacks( - std::move(OnAttachRootNativeNode), std::move(OnDetachRootNativeNode)); + auto xcomponentProxyNativeXComponent = DynamicCast(xcomponentProxy_); + CHECK_NULL_VOID(xcomponentProxyNativeXComponent); + xcomponentProxyNativeXComponent->RegisterNodeCallback(AceType::RawPtr(host)); } void XComponentPattern::InitEvent() @@ -1006,41 +1001,23 @@ void XComponentPattern::InitFocusEvent(const RefPtr& focusHub) } void XComponentPattern::HandleFocusEvent() { - CHECK_NULL_VOID(nativeXComponent_); - CHECK_NULL_VOID(nativeXComponentImpl_); - auto* surface = const_cast(nativeXComponentImpl_->GetSurface()); - const auto focusEventCallback = nativeXComponentImpl_->GetFocusEventCallback(); - CHECK_NULL_VOID(focusEventCallback); - focusEventCallback(nativeXComponent_.get(), surface); + auto xcomponentProxyNativeXComponent = DynamicCast(xcomponentProxy_); + CHECK_NULL_VOID(xcomponentProxyNativeXComponent); + xcomponentProxyNativeXComponent->DispatchFocusEvent(); } bool XComponentPattern::HandleKeyEvent(const KeyEvent& event) { - CHECK_NULL_RETURN(nativeXComponent_, false); - CHECK_NULL_RETURN(nativeXComponentImpl_, false); - - OH_NativeXComponent_KeyEvent keyEvent = XComponentUtils::ConvertNativeXComponentKeyEvent(event); - nativeXComponentImpl_->SetKeyEvent(keyEvent); - - auto* surface = const_cast(nativeXComponentImpl_->GetSurface()); - const auto keyEventCallbackWithResult = nativeXComponentImpl_->GetKeyEventCallbackWithResult(); - if (keyEventCallbackWithResult) { - return keyEventCallbackWithResult(nativeXComponent_.get(), surface); - } - const auto keyEventCallback = nativeXComponentImpl_->GetKeyEventCallback(); - CHECK_NULL_RETURN(keyEventCallback, false); - keyEventCallback(nativeXComponent_.get(), surface); - return false; + auto xcomponentProxyNativeXComponent = DynamicCast(xcomponentProxy_); + CHECK_NULL_RETURN(xcomponentProxyNativeXComponent, false); + return xcomponentProxyNativeXComponent->DispatchKeyEvent(event); } void XComponentPattern::HandleBlurEvent() { - CHECK_NULL_VOID(nativeXComponent_); - CHECK_NULL_VOID(nativeXComponentImpl_); - auto* surface = const_cast(nativeXComponentImpl_->GetSurface()); - const auto blurEventCallback = nativeXComponentImpl_->GetBlurEventCallback(); - CHECK_NULL_VOID(blurEventCallback); - blurEventCallback(nativeXComponent_.get(), surface); + auto xcomponentProxyNativeXComponent = DynamicCast(xcomponentProxy_); + CHECK_NULL_VOID(xcomponentProxyNativeXComponent); + xcomponentProxyNativeXComponent->DispatchBlurEvent(); } void XComponentPattern::InitTouchEvent(const RefPtr& gestureHub) @@ -1081,13 +1058,10 @@ void XComponentPattern::InitOnTouchIntercept(const RefPtr& gest CHECK_NULL_RETURN(pattern, NG::HitTestMode::HTMDEFAULT); auto hostNode = pattern->GetHost(); CHECK_NULL_RETURN(hostNode, NG::HitTestMode::HTMDEFAULT); - CHECK_NULL_RETURN(pattern->nativeXComponentImpl_, hostNode->GetHitTestMode()); - const auto onTouchInterceptCallback = pattern->nativeXComponentImpl_->GetOnTouchInterceptCallback(); - CHECK_NULL_RETURN(onTouchInterceptCallback, hostNode->GetHitTestMode()); - auto event = touchEvent.ConvertToTouchEvent(); - ArkUI_UIInputEvent uiEvent { ARKUI_UIINPUTEVENT_TYPE_TOUCH, TOUCH_EVENT_ID, &event, false, - Container::GetCurrentApiTargetVersion() }; - return static_cast(onTouchInterceptCallback(pattern->nativeXComponent_.get(), &uiEvent)); + auto xcomponentProxyNativeXComponent = DynamicCast(pattern->xcomponentProxy_); + auto defaultHitTestMode = hostNode->GetHitTestMode(); + CHECK_NULL_RETURN(xcomponentProxyNativeXComponent, defaultHitTestMode); + return xcomponentProxyNativeXComponent->InitOnTouchIntercept(touchEvent, defaultHitTestMode); }); } @@ -1149,14 +1123,15 @@ void XComponentPattern::HandleTouchEvent(const TouchEventInfo& info) localOffset.GetX(), localOffset.GetY(), touchInfo.GetFingerId(), touchInfoList.front().GetTouchType(), static_cast(touchInfo.GetSize())); SetTouchPoint(info.GetTouches(), timeStamp, touchType); - - if (nativeXComponent_ && nativeXComponentImpl_) { - nativeXComponentImpl_->SetHistoricalPoint(SetHistoryPoint(info.GetHistory())); - nativeXComponentImpl_->SetCurrentSourceType({ touchInfo.GetFingerId(), - XComponentUtils::ConvertNativeXComponentEventSourceType(info.GetSourceDevice()) }); + { + CHECK_RUN_ON(UI); + auto xcomponentProxyNativeXComponent = DynamicCast(xcomponentProxy_); + CHECK_NULL_VOID(xcomponentProxyNativeXComponent); + xcomponentProxyNativeXComponent->DispatchTouchEvent(touchEventPoint_, nativeXComponentTouchPoints_, + SetHistoryPoint(info.GetHistory()), + { touchInfo.GetFingerId(), + XComponentUtils::ConvertNativeXComponentEventSourceType(info.GetSourceDevice()) }); } - NativeXComponentDispatchTouchEvent(touchEventPoint_, nativeXComponentTouchPoints_); - #ifdef RENDER_EXTRACT_SUPPORTED if (touchType == TouchType::DOWN) { RequestFocus(); @@ -1176,51 +1151,31 @@ void XComponentPattern::HandleMouseEvent(const MouseInfo& info) mouseEventPoint.timestamp = info.GetTimeStamp().time_since_epoch().count(); OH_NativeXComponent_ExtraMouseEventInfo extraMouseEventInfo; extraMouseEventInfo.modifierKeyStates = CalculateModifierKeyState(info.GetPressedKeyCodes()); - NativeXComponentDispatchMouseEvent(mouseEventPoint, extraMouseEventInfo); + { + CHECK_RUN_ON(UI); + auto xcomponentProxyNativeXComponent = DynamicCast(xcomponentProxy_); + CHECK_NULL_VOID(xcomponentProxyNativeXComponent); + xcomponentProxyNativeXComponent->DispatchMouseEvent(mouseEventPoint, extraMouseEventInfo); + } } void XComponentPattern::HandleAxisEvent(const AxisInfo& info) { auto axisEvent = info.ConvertToAxisEvent(); - NativeXComponentDispatchAxisEvent(&axisEvent); + { + CHECK_RUN_ON(UI); + auto xcomponentProxyNativeXComponent = DynamicCast(xcomponentProxy_); + CHECK_NULL_VOID(xcomponentProxyNativeXComponent); + xcomponentProxyNativeXComponent->DispatchAxisEvent(&axisEvent); + } } void XComponentPattern::HandleMouseHoverEvent(bool isHover) { CHECK_RUN_ON(UI); - CHECK_NULL_VOID(nativeXComponent_); - CHECK_NULL_VOID(nativeXComponentImpl_); - const auto* callback = nativeXComponentImpl_->GetMouseEventCallback(); - CHECK_NULL_VOID(callback); - CHECK_NULL_VOID(callback->DispatchHoverEvent); - callback->DispatchHoverEvent(nativeXComponent_.get(), isHover); -} - -void XComponentPattern::NativeXComponentDispatchMouseEvent(const OH_NativeXComponent_MouseEvent& mouseEvent, - const OH_NativeXComponent_ExtraMouseEventInfo& extraMouseEventInfo) -{ - CHECK_RUN_ON(UI); - CHECK_NULL_VOID(nativeXComponent_); - CHECK_NULL_VOID(nativeXComponentImpl_); - nativeXComponentImpl_->SetMouseEvent(mouseEvent); - nativeXComponentImpl_->SetExtraMouseEventInfo(extraMouseEventInfo); - auto* surface = const_cast(nativeXComponentImpl_->GetSurface()); - const auto* callback = nativeXComponentImpl_->GetMouseEventCallback(); - CHECK_NULL_VOID(callback); - CHECK_NULL_VOID(callback->DispatchMouseEvent); - callback->DispatchMouseEvent(nativeXComponent_.get(), surface); -} - -void XComponentPattern::NativeXComponentDispatchAxisEvent(AxisEvent* axisEvent) -{ - CHECK_RUN_ON(UI); - CHECK_NULL_VOID(nativeXComponent_); - CHECK_NULL_VOID(nativeXComponentImpl_); - const auto callback = nativeXComponentImpl_->GetUIAxisEventCallback(); - CHECK_NULL_VOID(callback); - ArkUI_UIInputEvent uiEvent { ARKUI_UIINPUTEVENT_TYPE_AXIS, AXIS_EVENT_ID, axisEvent, false, - Container::GetCurrentApiTargetVersion() }; - callback(nativeXComponent_.get(), &uiEvent, ArkUI_UIInputEvent_Type::ARKUI_UIINPUTEVENT_TYPE_AXIS); + auto xcomponentProxyNativeXComponent = DynamicCast(xcomponentProxy_); + CHECK_NULL_VOID(xcomponentProxyNativeXComponent); + xcomponentProxyNativeXComponent->DispatchMouseHoverEvent(isHover); } void XComponentPattern::SetTouchPoint( @@ -1388,10 +1343,10 @@ XComponentControllerErrorCode XComponentPattern::ResetExtController(const RefPtr void XComponentPattern::HandleSetExpectedRateRangeEvent() { - CHECK_NULL_VOID(nativeXComponent_); - CHECK_NULL_VOID(nativeXComponentImpl_); CHECK_NULL_VOID(displaySync_); - OH_NativeXComponent_ExpectedRateRange* range = nativeXComponentImpl_->GetRateRange(); + auto xcomponentProxyNativeXComponent = DynamicCast(xcomponentProxy_); + CHECK_NULL_VOID(xcomponentProxyNativeXComponent); + OH_NativeXComponent_ExpectedRateRange* range = xcomponentProxyNativeXComponent->GetRateRange(); CHECK_NULL_VOID(range); FrameRateRange frameRateRange; frameRateRange.Set(range->min, range->max, range->expected); @@ -1408,29 +1363,26 @@ void XComponentPattern::HandleSetExpectedRateRangeEvent() void XComponentPattern::HandleOnFrameEvent() { - CHECK_NULL_VOID(nativeXComponent_); - CHECK_NULL_VOID(nativeXComponentImpl_); CHECK_NULL_VOID(displaySync_); displaySync_->RegisterOnFrameWithData([weak = AceType::WeakClaim(this)](RefPtr displaySyncData) { + CHECK_NULL_VOID(displaySyncData); auto xComponentPattern = weak.Upgrade(); CHECK_NULL_VOID(xComponentPattern); - CHECK_NULL_VOID(xComponentPattern->nativeXComponentImpl_->GetOnFrameCallback()); - xComponentPattern->nativeXComponentImpl_->GetOnFrameCallback()(xComponentPattern->nativeXComponent_.get(), + auto xcomponentProxyNativeXComponent = + DynamicCast(xComponentPattern->xcomponentProxy_); + CHECK_NULL_VOID(xcomponentProxyNativeXComponent); + xcomponentProxyNativeXComponent->DispatchOnFrameEvent( displaySyncData->GetTimestamp(), displaySyncData->GetTargetTimestamp()); }); - TAG_LOGD(AceLogTag::ACE_XCOMPONENT, "Id: %{public}" PRIu64 " RegisterOnFrame", - displaySync_->GetId()); + TAG_LOGD(AceLogTag::ACE_XCOMPONENT, "Id: %{public}" PRIu64 " RegisterOnFrame", displaySync_->GetId()); displaySync_->AddToPipelineOnContainer(); } void XComponentPattern::HandleUnregisterOnFrameEvent() { - CHECK_NULL_VOID(nativeXComponent_); - CHECK_NULL_VOID(nativeXComponentImpl_); CHECK_NULL_VOID(displaySync_); displaySync_->UnregisterOnFrame(); - TAG_LOGD(AceLogTag::ACE_XCOMPONENT, "Id: %{public}" PRIu64 " UnregisterOnFrame", - displaySync_->GetId()); + TAG_LOGD(AceLogTag::ACE_XCOMPONENT, "Id: %{public}" PRIu64 " UnregisterOnFrame", displaySync_->GetId()); displaySync_->DelFromPipelineOnContainer(); needRecoverDisplaySync_ = false; } @@ -1596,6 +1548,42 @@ void XComponentPattern::HandleSurfaceChangeEvent( } } +void XComponentPattern::HandleSurfaceChangeEventForSurfaceHolder(bool sizeChanged) +{ + if (!drawSize_.IsPositive()) { + return; + } + if (sizeChanged) { + XComponentSizeChangeForSurfaceHolder(paintRect_); + } + if (renderContextForSurface_) { + renderContextForSurface_->SetBounds( + paintRect_.GetX(), paintRect_.GetY(), paintRect_.Width(), paintRect_.Height()); + } + if (renderSurface_) { + renderSurface_->SetSurfaceDefaultSize( + static_cast(paintRect_.Width()), static_cast(paintRect_.Height())); + } +} + +void XComponentPattern::XComponentSizeChangeForSurfaceHolder(const RectF& surfaceRect) +{ + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto context = host->GetContextRefPtr(); + CHECK_NULL_VOID(context); + auto viewScale = context->GetViewScale(); + CHECK_NULL_VOID(renderSurface_); + auto width = surfaceRect.Width(); + auto height = surfaceRect.Height(); + needNotifySizeChanged_ = true; + renderSurface_->UpdateSurfaceSizeInUserData( + static_cast(width), static_cast(height)); + renderSurface_->AdjustNativeWindowSize( + static_cast(width * viewScale), static_cast(height * viewScale)); + OnSurfaceChangedForSurfaceHolder(surfaceRect); +} + std::tuple XComponentPattern::UpdateSurfaceRect() { if (!drawSize_.IsPositive()) { @@ -1663,17 +1651,11 @@ void XComponentPattern::OnSurfaceCreated() auto width = initSize_.Width(); auto height = initSize_.Height(); if (isNativeXComponent_) { - CHECK_NULL_VOID(nativeXComponentImpl_); - CHECK_NULL_VOID(nativeXComponent_); - nativeXComponentImpl_->SetXComponentWidth(static_cast(width)); - nativeXComponentImpl_->SetXComponentHeight(static_cast(height)); - nativeXComponentImpl_->SetSurface(nativeWindow_); - const auto* callback = nativeXComponentImpl_->GetCallback(); - CHECK_NULL_VOID(callback); - CHECK_NULL_VOID(callback->OnSurfaceCreated); TAG_LOGI(AceLogTag::ACE_XCOMPONENT, "XComponent[%{public}s] native OnSurfaceCreated", GetId().c_str()); ACE_SCOPED_TRACE("XComponent[%s] NativeSurfaceCreated[w:%f,h:%f]", GetId().c_str(), width, height); - callback->OnSurfaceCreated(nativeXComponent_.get(), nativeWindow_); + CHECK_NULL_VOID(xcomponentProxy_); + xcomponentProxy_->DispatchSurfaceCreatedEvent( + static_cast(width), static_cast(height), nativeWindow_); } else { auto host = GetHost(); CHECK_NULL_VOID(host); @@ -1683,29 +1665,17 @@ void XComponentPattern::OnSurfaceCreated() } } -void XComponentPattern::OnSurfaceChanged(const RectF& surfaceRect, bool needResizeNativeWindow) +void XComponentPattern::OnSurfaceChanged(const RectF& surfaceRect) { CHECK_RUN_ON(UI); auto host = GetHost(); CHECK_NULL_VOID(host); - auto width = surfaceRect.Width(); - auto height = surfaceRect.Height(); - if (needResizeNativeWindow) { - AdjustNativeWindowSize(width, height); - } if (isNativeXComponent_) { - CHECK_NULL_VOID(nativeXComponent_); - CHECK_NULL_VOID(nativeXComponentImpl_); - nativeXComponentImpl_->SetXComponentWidth(static_cast(width)); - nativeXComponentImpl_->SetXComponentHeight(static_cast(height)); - auto* surface = const_cast(nativeXComponentImpl_->GetSurface()); - const auto* callback = nativeXComponentImpl_->GetCallback(); - CHECK_NULL_VOID(callback); - CHECK_NULL_VOID(callback->OnSurfaceChanged); - { - ACE_SCOPED_TRACE("XComponent[%s] native OnSurfaceChanged[w:%f,h:%f]", GetId().c_str(), width, height); - callback->OnSurfaceChanged(nativeXComponent_.get(), surface); - } + auto width = surfaceRect.Width(); + auto height = surfaceRect.Height(); + ACE_SCOPED_TRACE("XComponent[%s] native OnSurfaceChanged[w:%f,h:%f]", GetId().c_str(), width, height); + CHECK_NULL_VOID(xcomponentProxy_); + xcomponentProxy_->DispatchSurfaceChangedEvent(static_cast(width), static_cast(height)); } else { auto eventHub = host->GetOrCreateEventHub(); CHECK_NULL_VOID(eventHub); @@ -1713,21 +1683,26 @@ void XComponentPattern::OnSurfaceChanged(const RectF& surfaceRect, bool needResi } } +void XComponentPattern::OnSurfaceChangedForSurfaceHolder(const RectF& surfaceRect) +{ + CHECK_RUN_ON(UI); + auto xcomponentProxySurfaceHolder = DynamicCast(xcomponentProxy_); + CHECK_NULL_VOID(xcomponentProxySurfaceHolder); + CHECK_EQUAL_VOID(xcomponentProxySurfaceHolder->IsInitialized(), false); + ACE_SCOPED_TRACE("XComponent[%s] surfaceHolder OnSurfaceChanged", GetId().c_str()); + xcomponentProxySurfaceHolder->DispatchSurfaceChangedEvent(surfaceRect.Width(), surfaceRect.Height()); + needNotifySizeChanged_ = false; +} + void XComponentPattern::OnSurfaceDestroyed(FrameNode* frameNode) { if (isNativeXComponent_) { CHECK_RUN_ON(UI); - CHECK_NULL_VOID(nativeXComponent_); - CHECK_NULL_VOID(nativeXComponentImpl_); - auto* surface = const_cast(nativeXComponentImpl_->GetSurface()); - const auto* callback = nativeXComponentImpl_->GetCallback(); - CHECK_NULL_VOID(callback); - CHECK_NULL_VOID(callback->OnSurfaceDestroyed); TAG_LOGI(AceLogTag::ACE_XCOMPONENT, "XComponent[%{public}s] native OnSurfaceDestroyed", GetId().c_str()); ACE_SCOPED_TRACE("XComponent[%s] native OnSurfaceDestroyed", GetId().c_str()); - callback->OnSurfaceDestroyed(nativeXComponent_.get(), surface); - nativeXComponentImpl_->SetSurface(nullptr); - } else if (isTypedNode_) { + CHECK_NULL_VOID(xcomponentProxy_); + xcomponentProxy_->DispatchSurfaceDestroyedEvent(); + } else if (nodeType_ == XComponentNodeType::TYPE_NODE) { RefPtr host; if (!frameNode) { host = GetHost(); @@ -1742,7 +1717,7 @@ void XComponentPattern::OnSurfaceDestroyed(FrameNode* frameNode) void XComponentPattern::RegisterSurfaceCallbackModeEvent() { - if (isTypedNode_ && !surfaceCallbackModeChangeEvent_) { + if (nodeType_ == XComponentNodeType::TYPE_NODE && !surfaceCallbackModeChangeEvent_) { surfaceCallbackModeChangeEvent_ = [weak = WeakClaim(this)](SurfaceCallbackMode mode) { auto xcPattern = weak.Upgrade(); CHECK_NULL_VOID(xcPattern); @@ -1776,6 +1751,24 @@ void XComponentPattern::HandleSurfaceCreated() OnSurfaceCreated(); } +int32_t XComponentPattern::HandleSurfaceCreatedForSurfaceHolder() +{ + auto xcomponentProxySurfaceHolder = DynamicCast(xcomponentProxy_); + CHECK_NULL_RETURN(xcomponentProxySurfaceHolder, ERROR_CODE_XCOMPONENT_STATE_INVALID); + CHECK_EQUAL_RETURN(xcomponentProxySurfaceHolder->IsInitialized(), true, ERROR_CODE_XCOMPONENT_STATE_INVALID); + InitSurface(); + renderSurface_->RegisterSurface(); + InitNativeWindow(paintRect_.Width(), paintRect_.Height()); + TAG_LOGI(AceLogTag::ACE_XCOMPONENT, "XComponent[%{public}s] surfaceHolder OnSurfaceCreated", GetId().c_str()); + ACE_SCOPED_TRACE("XComponent[%s] surfaceHolder OnSurfaceCreated", GetId().c_str()); + // width&height is unnecessary + xcomponentProxySurfaceHolder->DispatchSurfaceCreatedEvent(-1, -1, nativeWindow_); + if (needNotifySizeChanged_) { + OnSurfaceChangedForSurfaceHolder(paintRect_); + } + return ERROR_CODE_NO_ERROR; +} + void XComponentPattern::HandleSurfaceDestroyed(FrameNode* frameNode) { CHECK_NULL_VOID(renderSurface_); @@ -1786,28 +1779,86 @@ void XComponentPattern::HandleSurfaceDestroyed(FrameNode* frameNode) xcomponentController_->SetSurfaceId(""); } -void XComponentPattern::NativeSurfaceShow() +int32_t XComponentPattern::HandleSurfaceDestroyedForSurfaceHolder() { - CHECK_RUN_ON(UI); - CHECK_NULL_VOID(nativeXComponentImpl_); - CHECK_NULL_VOID(nativeXComponent_); - auto* surface = const_cast(nativeXComponentImpl_->GetSurface()); - const auto surfaceShowCallback = nativeXComponentImpl_->GetSurfaceShowCallback(); - CHECK_NULL_VOID(surfaceShowCallback); - surfaceShowCallback(nativeXComponent_.get(), surface); + auto xcomponentProxySurfaceHolder = DynamicCast(xcomponentProxy_); + CHECK_NULL_RETURN(xcomponentProxySurfaceHolder, ERROR_CODE_XCOMPONENT_STATE_INVALID); + CHECK_EQUAL_RETURN(xcomponentProxySurfaceHolder->IsInitialized(), false, ERROR_CODE_XCOMPONENT_STATE_INVALID); + TAG_LOGI(AceLogTag::ACE_XCOMPONENT, "XComponent[%{public}s] surfaceHolder OnSurfaceDestroyed", GetId().c_str()); + ACE_SCOPED_TRACE("XComponent[%s] surfaceHolder OnSurfaceDestroyed", GetId().c_str()); + xcomponentProxySurfaceHolder->DispatchSurfaceDestroyedEvent(); + DisposeSurface(); + return ERROR_CODE_NO_ERROR; } -void XComponentPattern::NativeSurfaceHide() +void XComponentPattern::DisposeSurface() { - CHECK_RUN_ON(UI); - CHECK_NULL_VOID(nativeXComponent_); - CHECK_NULL_VOID(nativeXComponentImpl_); - auto* surface = const_cast(nativeXComponentImpl_->GetSurface()); - const auto surfaceHideCallback = nativeXComponentImpl_->GetSurfaceHideCallback(); - CHECK_NULL_VOID(surfaceHideCallback); - surfaceHideCallback(nativeXComponent_.get(), surface); - CHECK_NULL_VOID(renderSurface_); - renderSurface_->ReleaseSurfaceBuffers(); + if (type_ == XComponentType::SURFACE) { + XComponentInnerSurfaceController::UnregisterSurfaceRenderContext(surfaceId_); + surfaceId_ = ""; + } + if (renderSurface_) { + renderSurface_->ReleaseSurfaceBuffers(); + renderSurface_->UnregisterSurface(); + renderSurface_ = nullptr; + } + auto xcomponentProxySurfaceHolder = DynamicCast(xcomponentProxy_); + CHECK_NULL_VOID(xcomponentProxySurfaceHolder); + xcomponentProxySurfaceHolder->SetNativeWindow(nullptr); + nativeWindow_ = nullptr; + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto renderContext = host->GetRenderContext(); + CHECK_NULL_VOID(renderContext); + // for surface type + CHECK_NULL_VOID(renderContextForSurface_); + renderContext->RemoveChild(renderContextForSurface_); + renderContextForSurface_ = nullptr; + needReinitialize_ = true; +#ifdef ENABLE_ROSEN_BACKEND + FlushImplicitTransaction(host); +#endif +} + +std::shared_ptr XComponentPattern::GetRSTransactionHandler( + const RefPtr& frameNode) +{ +#ifdef ENABLE_ROSEN_BACKEND + if (!SystemProperties::GetMultiInstanceEnabled()) { + return nullptr; + } + auto rsUIContext = GetRSUIContext(frameNode); + CHECK_NULL_RETURN(rsUIContext, nullptr); + return rsUIContext->GetRSTransaction(); +#endif + return nullptr; +} + +std::shared_ptr XComponentPattern::GetRSUIContext(const RefPtr& frameNode) +{ +#ifdef ENABLE_ROSEN_BACKEND + CHECK_NULL_RETURN(frameNode, nullptr); + auto pipeline = frameNode->GetContext(); + CHECK_NULL_RETURN(pipeline, nullptr); + auto window = pipeline->GetWindow(); + CHECK_NULL_RETURN(window, nullptr); + auto rsUIDirector = window->GetRSUIDirector(); + CHECK_NULL_RETURN(rsUIDirector, nullptr); + auto rsUIContext = rsUIDirector->GetRSUIContext(); + return rsUIContext; +#endif + return nullptr; +} + +void XComponentPattern::FlushImplicitTransaction(const RefPtr& frameNode) +{ +#ifdef ENABLE_ROSEN_BACKEND + if (auto transactionHandler = GetRSTransactionHandler(frameNode)) { + transactionHandler->FlushImplicitTransaction(); + } else { + Rosen::RSTransactionProxy::GetInstance()->FlushImplicitTransaction(); + } +#endif } void XComponentPattern::OnWindowHide() @@ -1819,7 +1870,11 @@ void XComponentPattern::OnWindowHide() if (renderSurface_) { renderSurface_->OnWindowStateChange(false); } - NativeSurfaceHide(); + if (xcomponentProxy_ && xcomponentProxy_->DispatchSurfaceHideEvent()) { + if (renderSurface_) { + renderSurface_->ReleaseSurfaceBuffers(); + } + } hasReleasedSurface_ = true; } @@ -1832,7 +1887,9 @@ void XComponentPattern::OnWindowShow() if (renderSurface_) { renderSurface_->OnWindowStateChange(true); } - NativeSurfaceShow(); + if (xcomponentProxy_) { + xcomponentProxy_->DispatchSurfaceShowEvent(); + } hasReleasedSurface_ = false; } @@ -2173,4 +2230,184 @@ void XComponentPattern::UnlockCanvasAndPost(RSCanvas* canvas) TAG_LOGW(AceLogTag::ACE_XCOMPONENT, "XComponent[%{public}s] UnlockCanvasAndPost failed", GetId().c_str()); } } + +void XComponentPattern::SetExpectedRateRange(int32_t min, int32_t max, int32_t expected) +{ + if (IsUsingNativeXComponent()) { + return; + } + CHECK_NULL_VOID(displaySync_); + FrameRateRange frameRateRange; + frameRateRange.Set(min, max, expected); + displaySync_->SetExpectedFrameRateRange(frameRateRange); + TAG_LOGD(AceLogTag::ACE_XCOMPONENT, + "Id: %{public}" PRIu64 " SetExpectedFrameRateRange" + "{%{public}d, %{public}d, %{public}d}", + displaySync_->GetId(), min, max, expected); +} + +void XComponentPattern::UpdateOnFrameEvent(void(*callback)(void*, uint64_t, uint64_t), void* arkuiNode) +{ + if (IsUsingNativeXComponent()) { + return; + } + CHECK_NULL_VOID(displaySync_); + displaySync_->RegisterOnFrameWithData([weak = AceType::WeakClaim(this), + callback, arkuiNode](RefPtr displaySyncData) { + auto xComponentPattern = weak.Upgrade(); + CHECK_NULL_VOID(xComponentPattern); + CHECK_NULL_VOID(callback); + CHECK_NULL_VOID(arkuiNode); + CHECK_NULL_VOID(displaySyncData); + callback(arkuiNode, displaySyncData->GetTimestamp(), displaySyncData->GetTargetTimestamp()); + }); + TAG_LOGD(AceLogTag::ACE_XCOMPONENT, "Id: %{public}" PRIu64 " RegisterOnFrame", + displaySync_->GetId()); + displaySync_->AddToPipelineOnContainer(); +} + +void XComponentPattern::UnregisterOnFrameEvent() +{ + if (IsUsingNativeXComponent()) { + return; + } + CHECK_NULL_VOID(displaySync_); + displaySync_->UnregisterOnFrame(); + TAG_LOGD(AceLogTag::ACE_XCOMPONENT, "Id: %{public}" PRIu64 " UnregisterOnFrame", + displaySync_->GetId()); + displaySync_->DelFromPipelineOnContainer(); + needRecoverDisplaySync_ = false; +} + +void XComponentPattern::SetNeedSoftKeyboard(bool isNeedSoftKeyboard) +{ + if (IsUsingNativeXComponent()) { + return; + } + if (xcomponentProxy_->IsToggleEnabled()) { + xcomponentProxy_.Swap(MakeRefPtr(WeakClaim(this))); + xcomponentProxy_->SetToggleEnabled(false); + } + auto xcomponentProxySurfaceHolder = DynamicCast(xcomponentProxy_); + xcomponentProxySurfaceHolder->SetNeedSoftKeyboard(isNeedSoftKeyboard); +} + +OH_ArkUI_SurfaceHolder* XComponentPattern::GetSurfaceHolder() +{ + if (IsUsingNativeXComponent()) { + return nullptr; + } + if (xcomponentProxy_->IsToggleEnabled()) { + xcomponentProxy_.Swap(MakeRefPtr(WeakClaim(this))); + xcomponentProxy_->SetToggleEnabled(false); + return nullptr; + } + auto xcomponentProxySurfaceHolder = DynamicCast(xcomponentProxy_); + CHECK_NULL_RETURN(xcomponentProxySurfaceHolder, nullptr); + return xcomponentProxySurfaceHolder->GetSurfaceHolder(); +} + +void XComponentPattern::SetSurfaceHolder(OH_ArkUI_SurfaceHolder* surfaceHolder) +{ + if (xcomponentProxy_->IsToggleEnabled()) { + xcomponentProxy_.Swap(MakeRefPtr(WeakClaim(this))); + xcomponentProxy_->SetToggleEnabled(false); + } + auto xcomponentProxySurfaceHolder = DynamicCast(xcomponentProxy_); + xcomponentProxySurfaceHolder->SetSurfaceHolder(surfaceHolder); + xcomponentProxySurfaceHolder->SetNativeWindow(nativeWindow_); +} + +int32_t XComponentPattern::Initialize() +{ + if (IsUsingNativeXComponent()) { + return OHOS::Ace::ERROR_CODE_PARAM_INVALID; + } + if (xcomponentProxy_->IsToggleEnabled()) { + xcomponentProxy_.Swap(MakeRefPtr(WeakClaim(this))); + xcomponentProxy_->SetToggleEnabled(false); + } + return HandleSurfaceCreatedForSurfaceHolder(); +} +int32_t XComponentPattern::Finalize() +{ + if (IsUsingNativeXComponent()) { + return OHOS::Ace::ERROR_CODE_PARAM_INVALID; + } + if (xcomponentProxy_->IsToggleEnabled()) { + xcomponentProxy_.Swap(MakeRefPtr(WeakClaim(this))); + xcomponentProxy_->SetToggleEnabled(false); + } + return HandleSurfaceDestroyedForSurfaceHolder(); +} +int32_t XComponentPattern::SetAutoInitialize(bool autoInitialize) +{ + if (IsUsingNativeXComponent()) { + return OHOS::Ace::ERROR_CODE_PARAM_INVALID; + } + if (xcomponentProxy_->IsToggleEnabled()) { + xcomponentProxy_.Swap(MakeRefPtr(WeakClaim(this))); + xcomponentProxy_->SetToggleEnabled(false); + } + return ERROR_CODE_NO_ERROR; +} +int32_t XComponentPattern::IsInitialized(bool& isInitialized) +{ + if (IsUsingNativeXComponent()) { + return OHOS::Ace::ERROR_CODE_PARAM_INVALID; + } + if (xcomponentProxy_->IsToggleEnabled()) { + xcomponentProxy_.Swap(MakeRefPtr(WeakClaim(this))); + xcomponentProxy_->SetToggleEnabled(false); + } + auto xcomponentProxySurfaceHolder = DynamicCast(xcomponentProxy_); + isInitialized = xcomponentProxySurfaceHolder->IsInitialized(); + return ERROR_CODE_NO_ERROR; +} + +bool XComponentPattern::IsUsingNativeXComponent() const +{ + CHECK_NULL_RETURN(xcomponentProxy_, true); + return InstanceOf(xcomponentProxy_) && !xcomponentProxy_->IsToggleEnabled(); +} + +void XComponentPattern::SetHasGotNativeXComponent(bool hasGotNativeXComponent) +{ + if (hasGotNativeXComponent) { + CHECK_NULL_VOID(xcomponentProxy_); + xcomponentProxy_->SetToggleEnabled(false); + } +} + +bool XComponentPattern::IsBindNative() const +{ + return InstanceOf(xcomponentProxy_) || nodeType_ == XComponentNodeType::CNODE; +} + +ArkUI_AccessibilityProvider* XComponentPattern::CreateAccessibilityProvider() +{ + if (IsUsingNativeXComponent()) { + return nullptr; + } + if (xcomponentProxy_->IsToggleEnabled()) { + xcomponentProxy_.Swap(MakeRefPtr(WeakClaim(this))); + xcomponentProxy_->SetToggleEnabled(false); + } + auto xcomponentProxySurfaceHolder = DynamicCast(xcomponentProxy_); + return xcomponentProxySurfaceHolder->CreateAccessibilityProvider(); +} + +void XComponentPattern::DisposeAccessibilityProvider(ArkUI_AccessibilityProvider* provider) +{ + if (IsUsingNativeXComponent()) { + return; + } + auto xcomponentProxySurfaceHolder = DynamicCast(xcomponentProxy_); + xcomponentProxySurfaceHolder->DisposeAccessibilityProvider(provider); +} + +FrameNode* XComponentPattern::QueryAccessibilityProviderHost(void* provider, bool& isProviderValied) +{ + return XComponentProxySurfaceHolder::QueryAccessibilityProviderHost(provider, isProviderValied); +} } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.h b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.h index 328318b006a9277ba432d88a46c4d462d280acdd..ecf0fa22b0eafcf4c5a7a8df8d503ad55ce2dcb6 100644 --- a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.h +++ b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.h @@ -20,14 +20,7 @@ #include #include -#include "base/geometry/dimension.h" -#include "base/geometry/ng/offset_t.h" #include "base/geometry/ng/rect_t.h" -#include "base/geometry/ng/size_t.h" -#include "base/geometry/size.h" -#include "base/memory/referenced.h" -#include "base/utils/utils.h" -#include "core/common/thread_checker.h" #include "core/components/common/layout/constants.h" #include "core/components/xcomponent/native_interface_xcomponent_impl.h" #include "core/components_ng/event/focus_hub.h" @@ -39,27 +32,38 @@ #include "core/components_ng/pattern/xcomponent/xcomponent_layout_algorithm.h" #include "core/components_ng/pattern/xcomponent/xcomponent_layout_property.h" #include "core/components_ng/pattern/xcomponent/xcomponent_paint_method.h" +#include "core/components_ng/pattern/xcomponent/xcomponent_proxy/xcomponent_proxy.h" +#include "core/components_ng/pattern/xcomponent/xcomponent_proxy/xcomponent_proxy_native_xcomponent.h" +#include "core/components_ng/pattern/xcomponent/xcomponent_surface_holder.h" #include "core/components_ng/property/property.h" #include "core/components_ng/render/render_surface.h" #include "core/pipeline_ng/pipeline_context.h" -#include "core/components_ng/manager/display_sync/ui_display_sync.h" -#include "core/gestures/velocity.h" + +namespace OHOS::Rosen { +class Session; +class RSNode; +class RSTransaction; +class RSTransactionHandler; +class RSUIContext; +} // namespace OHOS::Rosen namespace OHOS::Ace { class ImageAnalyzerManager; -} +} // namespace OHOS::Ace namespace OHOS::Ace::NG { class XComponentExtSurfaceCallbackClient; class XComponentPattern : public Pattern { DECLARE_ACE_TYPE(XComponentPattern, Pattern); public: - XComponentPattern() = default; - XComponentPattern(const std::optional& id, XComponentType type, + XComponentPattern() = delete; + explicit XComponentPattern(XComponentNodeType nodeType); + ~XComponentPattern() override = default; + + void InitParams(const std::optional& id, XComponentType type, const std::optional& libraryname, const std::shared_ptr& xcomponentController, float initWidth = 0.0f, - float initHeight = 0.0f, bool isTypedNode = false); - ~XComponentPattern() override = default; + float initHeight = 0.0f); bool IsEnableMatchParent() override { @@ -107,33 +111,20 @@ public: bool NeedSoftKeyboard() const override { - return (nativeXComponentImpl_ ? nativeXComponentImpl_->IsNeedSoftKeyboard() : false) || isNeedSoftKeyboard_; - } - - std::pair, std::weak_ptr> GetNativeXComponent() - { - if (!nativeXComponent_ || !nativeXComponentImpl_) { - // for XComponentType::NODE - nativeXComponentImpl_ = AceType::MakeRefPtr(); - nativeXComponent_ = std::make_shared(AceType::RawPtr(nativeXComponentImpl_)); - } - return std::make_pair(nativeXComponentImpl_, nativeXComponent_); + return xcomponentProxy_ ? xcomponentProxy_->NeedSoftKeyboard() : false; } - void NativeXComponentDispatchTouchEvent(const OH_NativeXComponent_TouchEvent& touchEvent, - const std::vector& xComponentTouchPoints); - void NativeXComponentDispatchMouseEvent(const OH_NativeXComponent_MouseEvent& mouseEvent, - const OH_NativeXComponent_ExtraMouseEventInfo& extraMouseEventInfo); - void NativeXComponentDispatchAxisEvent(AxisEvent* axisEvent); + std::pair, std::weak_ptr> GetNativeXComponent(); void InitXComponent(); void InitNativeXComponent(); void InitNativeWindow(float textureWidth, float textureHeight); void XComponentSizeInit(); void XComponentSizeChange(const RectF& surfaceRect, bool needFireNativeEvent); + void XComponentSizeChangeForSurfaceHolder(const RectF& surfaceRect); void NativeXComponentInit() { - if (!isTypedNode_) { + if (nodeType_ != XComponentNodeType::TYPE_NODE) { OnSurfaceCreated(); } } @@ -206,16 +197,11 @@ public: void SetSurfaceRotation(bool isLock); - bool GetSurfaceRotation() + bool GetSurfaceRotation() const { return isSurfaceLock_; } - void SetIsTypeNode(bool isTypeNode) - { - isTypedNode_ = isTypeNode; - } - std::shared_ptr GetXComponentController() { return xcomponentController_; @@ -230,32 +216,23 @@ public: void SetExpectedRateRangeInit() { - CHECK_NULL_VOID(nativeXComponentImpl_); - nativeXComponentImpl_->SetExpectedRateRangeEventCallback([weak = AceType::WeakClaim(this)]() { - auto xComponentPattern = weak.Upgrade(); - CHECK_NULL_VOID(xComponentPattern); - xComponentPattern->HandleSetExpectedRateRangeEvent(); - }); + auto xcomponentProxyNativeXComponent = DynamicCast(xcomponentProxy_); + CHECK_NULL_VOID(xcomponentProxyNativeXComponent); + xcomponentProxyNativeXComponent->SetExpectedRateRangeInit(); } void OnFrameEventInit() { - CHECK_NULL_VOID(nativeXComponentImpl_); - nativeXComponentImpl_->SetOnFrameEventCallback([weak = AceType::WeakClaim(this)]() { - auto xComponentPattern = weak.Upgrade(); - CHECK_NULL_VOID(xComponentPattern); - xComponentPattern->HandleOnFrameEvent(); - }); + auto xcomponentProxyNativeXComponent = DynamicCast(xcomponentProxy_); + CHECK_NULL_VOID(xcomponentProxyNativeXComponent); + xcomponentProxyNativeXComponent->OnFrameEventInit(); } void UnregisterOnFrameEventInit() { - CHECK_NULL_VOID(nativeXComponentImpl_); - nativeXComponentImpl_->SetUnregisterOnFrameEventCallback([weak = AceType::WeakClaim(this)]() { - auto xComponentPattern = weak.Upgrade(); - CHECK_NULL_VOID(xComponentPattern); - xComponentPattern->HandleUnregisterOnFrameEvent(); - }); + auto xcomponentProxyNativeXComponent = DynamicCast(xcomponentProxy_); + CHECK_NULL_VOID(xcomponentProxyNativeXComponent); + xcomponentProxyNativeXComponent->UnregisterOnFrameEventInit(); } void SetXcomponentInit(bool isInit) @@ -282,34 +259,47 @@ public: bool NeedTriggerLoadEventImmediately() const { - return isTypedNode_ && isNativeXComponent_ && hasLoadNativeDone_; + return nodeType_ == XComponentNodeType::TYPE_NODE && isNativeXComponent_ && hasLoadNativeDone_; } - bool HasGotSurfaceHolder() const - { - return hasGotSurfaceHolder_; - } + bool IsUsingNativeXComponent() const; - bool HasGotNativeXComponent() const - { - return hasGotNativeXComponent_; - } + bool IsBindNative() const; - virtual bool IsBindNative() + void SetHasGotNativeXComponent(bool hasGotNativeXComponent); + + XComponentNodeType GetNodeType() const { - return false; + return nodeType_; } - bool IsNativeXComponentDisabled() const + SurfaceCallbackMode GetSurfaceCallbackMode() const { - return isNativeXComponentDisabled_; + return surfaceCallbackMode_; } - void SetHasGotNativeXComponent(bool hasGotNativeXComponent) + OH_ArkUI_SurfaceHolder* GetSurfaceHolder(); + + void SetSurfaceHolder(OH_ArkUI_SurfaceHolder* surfaceHolder); + + XComponentNodeType GetXComponentNodeType() const { - hasGotNativeXComponent_ = hasGotNativeXComponent; + return nodeType_; } + int32_t Initialize(); + int32_t Finalize(); + int32_t SetAutoInitialize(bool autoInitialize); + int32_t IsInitialized(bool& isInitialized); + + void SetExpectedRateRange(int32_t min, int32_t max, int32_t expected); + void UpdateOnFrameEvent(void (*callback)(void*, uint64_t, uint64_t), void* arkuiNode); + void UnregisterOnFrameEvent(); + void SetNeedSoftKeyboard(bool isNeedSoftKeyboard); + ArkUI_AccessibilityProvider* CreateAccessibilityProvider(); + void DisposeAccessibilityProvider(ArkUI_AccessibilityProvider* provider); + static FrameNode* QueryAccessibilityProviderHost(void* provider, bool& isProviderValied); + void SetExportTextureSurfaceId(const std::string& surfaceId); void FireExternalEvent(RefPtr context, const std::string& componentId, const uint32_t nodeId, const bool isDestroy); @@ -323,8 +313,6 @@ public: void OnSetAccessibilityChildTree(int32_t childWindowId, int32_t childTreeId); void SetAccessibilityState(bool state) {} RefPtr GetAccessibilitySessionAdapter() override; - void InitializeAccessibilityCallback(); - void HandleRegisterAccessibilityEvent(bool isRegister); void SetIdealSurfaceWidth(float surfaceWidth); void SetIdealSurfaceHeight(float surfaceHeight); @@ -334,6 +322,7 @@ public: std::tuple UpdateSurfaceRect(); void HandleSurfaceChangeEvent(bool needForceRender, bool offsetChanged, bool sizeChanged, bool needFireNativeEvent, bool frameOffsetChange = false); + void HandleSurfaceChangeEventForSurfaceHolder(bool sizeChanged); void EnableAnalyzer(bool enable); void SetImageAIOptions(void* options); void StartImageAnalyzer(void* config, OnAnalyzedCallback& onAnalyzed); @@ -344,7 +333,10 @@ public: void SetRenderFit(RenderFit renderFit); void SetScreenId(uint64_t screenId); void HandleSurfaceCreated(); + int32_t HandleSurfaceCreatedForSurfaceHolder(); void HandleSurfaceDestroyed(FrameNode* frameNode = nullptr); + int32_t HandleSurfaceDestroyedForSurfaceHolder(); + void DisposeSurface(); void ChangeSurfaceCallbackMode(SurfaceCallbackMode mode) { if (surfaceCallbackModeChangeEvent_) { @@ -362,10 +354,14 @@ public: void UnlockCanvasAndPost(RSCanvas* canvas); ArkUI_AccessibilityProvider* GetNativeProvider(); + void OnSizeChange(bool offsetChanged, bool sizeChanged, bool frameOffsetChange, bool needFireNativeEvent); + void HandleSetExpectedRateRangeEvent(); + void HandleOnFrameEvent(); + void HandleUnregisterOnFrameEvent(); + protected: void OnAttachToMainTree() override; void OnDetachFromMainTree() override; - void OnAttachToFrameNode() override; void OnDetachFromFrameNode(FrameNode* frameNode) override; void BeforeSyncGeometryProperties(const DirtySwapConfig& config) override; void OnRebuildFrame() override; @@ -381,36 +377,6 @@ protected: bool IsSupportImageAnalyzerFeature(); void UpdateAnalyzerUIConfig(const RefPtr& geometryNode); - std::optional id_; - XComponentType type_; - bool hasGotSurfaceHolder_ = false; - bool hasGotNativeXComponent_ = false; - bool isNativeXComponentDisabled_ = false; - bool isCNode_ = false; - bool useNodeHandleAccessibilityProvider_ = false; - RefPtr renderSurface_; - OffsetF localPosition_; - OffsetF surfaceOffset_; - SizeF drawSize_; - SizeF surfaceSize_; - RectF paintRect_; - void* nativeWindow_ = nullptr; - bool hasReleasedSurface_ = false; - RefPtr renderContextForSurface_; - std::optional transformHintChangedCallbackId_; - std::string surfaceId_; - bool isOnTree_ = false; - float hdrBrightness_ = 1.0f; - bool isTransparentLayer_ = false; - bool isEnableSecure_ = false; - bool isSurfaceLock_ = false; - RenderFit renderFit_ = RenderFit::RESIZE_FILL; - RefPtr displaySync_ = AceType::MakeRefPtr(UIObjectType::DISPLAYSYNC_XCOMPONENT); - bool needRecoverDisplaySync_ = false; - std::shared_ptr accessibilityChildTreeCallback_; - ArkUI_AccessibilityProvider* arkuiAccessibilityProvider_ = nullptr; - bool isNeedSoftKeyboard_ = false; - private: void OnAreaChangedInner() override; void DumpSimplifyInfo(std::unique_ptr& json) override {} @@ -428,12 +394,9 @@ private: void OnNativeUnload(FrameNode* frameNode); void OnSurfaceCreated(); - void OnSurfaceChanged(const RectF& surfaceRect, bool needResizeNativeWindow); + void OnSurfaceChanged(const RectF& surfaceRect); + void OnSurfaceChangedForSurfaceHolder(const RectF& surfaceRect); - void NativeSurfaceShow(); - void NativeSurfaceHide(); - - void Initialize(); void InitController(); void InitSurface(); void InitNativeNodeCallbacks(); @@ -453,11 +416,15 @@ private: void HandleBlurEvent(); ExternalEvent CreateExternalEvent(); + void InitForNonSurfaceHolder(); + void InitForSurfaceHolder(); + void ReinitializeSurfaceProperties(); + std::shared_ptr GetRSUIContext(const RefPtr& frameNode); + void FlushImplicitTransaction(const RefPtr& frameNode); + std::shared_ptr GetRSTransactionHandler(const RefPtr& frameNode); + void SetTouchPoint( const std::list& touchInfoList, int64_t timeStamp, const TouchType& touchType); - void HandleSetExpectedRateRangeEvent(); - void HandleOnFrameEvent(); - void HandleUnregisterOnFrameEvent(); bool ExportTextureAvailable(); bool DoTextureExport(); bool StopTextureExport(); @@ -480,17 +447,36 @@ private: #endif std::vector SetHistoryPoint(const std::list& touchInfoList); + + std::optional id_; + XComponentType type_ = XComponentType::UNKNOWN; std::optional libraryname_; std::shared_ptr xcomponentController_; std::optional soPath_; + RefPtr renderSurface_; + OffsetF localPosition_; + OffsetF surfaceOffset_; + SizeF drawSize_; + SizeF surfaceSize_; + RectF paintRect_; + void* nativeWindow_ = nullptr; + bool hasReleasedSurface_ = false; + RefPtr renderContextForSurface_; + std::optional transformHintChangedCallbackId_; + std::string surfaceId_; + bool isOnTree_ = false; + float hdrBrightness_ = 1.0f; + bool isTransparentLayer_ = false; + bool isEnableSecure_ = false; + bool isSurfaceLock_ = false; + RenderFit renderFit_ = RenderFit::RESIZE_FILL; + RefPtr displaySync_ = AceType::MakeRefPtr(UIObjectType::DISPLAYSYNC_XCOMPONENT); + bool needRecoverDisplaySync_ = false; std::optional screenId_; RefPtr handlingSurfaceRenderContext_; WeakPtr extPattern_; - std::shared_ptr nativeXComponent_; - RefPtr nativeXComponentImpl_; - bool hasXComponentInit_ = false; RefPtr touchEvent_; @@ -523,7 +509,6 @@ private: std::shared_ptr imageAnalyzerManager_; bool isEnableAnalyzer_ = false; uint32_t rotation_ = 0; - bool isTypedNode_ = false; bool isNativeXComponent_ = false; bool hasLoadNativeDone_ = false; SurfaceCallbackMode surfaceCallbackMode_ = SurfaceCallbackMode::DEFAULT; @@ -533,6 +518,13 @@ private: WeakPtr initialContext_ = nullptr; // record the initial surfaceId_ in InitSurface, this variable should not be modified after the initial assignment std::string initialSurfaceId_; + + XComponentNodeType nodeType_ = XComponentNodeType::UNKNOWN; + Color bkColor_ = Color::BLACK; + bool needReinitialize_ = false; + bool needNotifySizeChanged_ = false; + + RefPtr xcomponentProxy_ = nullptr; }; } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern_v2.cpp b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern_v2.cpp deleted file mode 100644 index a453215ba055f90375ac349e3e30ec15a0e684e0..0000000000000000000000000000000000000000 --- a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern_v2.cpp +++ /dev/null @@ -1,719 +0,0 @@ -/* - * 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. - */ - -#include "core/components_ng/pattern/xcomponent/xcomponent_pattern_v2.h" - -#include "base/log/dump_log.h" -#include "base/utils/utils.h" -#include "core/accessibility/accessibility_session_adapter.h" -#include "core/components_ng/pattern/xcomponent/xcomponent_accessibility_child_tree_callback.h" -#include "core/components_ng/pattern/xcomponent/xcomponent_accessibility_session_adapter.h" -#include "core/components_ng/pattern/xcomponent/xcomponent_ext_surface_callback_client.h" -#include "core/components_ng/pattern/xcomponent/xcomponent_inner_surface_controller.h" -#ifdef ENABLE_ROSEN_BACKEND -#include "transaction/rs_transaction.h" -#include "transaction/rs_transaction_handler.h" -#include "transaction/rs_transaction_proxy.h" -#include "transaction/rs_sync_transaction_controller.h" -#include "transaction/rs_sync_transaction_handler.h" -#include "ui/rs_ui_context.h" -#include "ui/rs_ui_director.h" -#endif - -namespace OHOS::Ace::NG { - -namespace { -const std::string BUFFER_USAGE_XCOMPONENT = "xcomponent"; - -inline std::string BoolToString(bool value) -{ - return value ? "true" : "false"; -} -} // namespace - -XComponentPatternV2::XComponentPatternV2(XComponentType type, XComponentNodeType nodeType) - : XComponentPattern((nodeType == XComponentNodeType::CNODE) ? std::make_optional("") : std::nullopt, - type, (nodeType == XComponentNodeType::CNODE) ? std::make_optional("") : std::nullopt, nullptr) -{ - nodeType_ = nodeType; - if (nodeType == XComponentNodeType::CNODE) { - isCNode_ = true; - } -} - -void XComponentPatternV2::SetSurfaceHolder(OH_ArkUI_SurfaceHolder* surfaceHolder) -{ - surfaceHolder_ = surfaceHolder; - if (surfaceHolder_) { - surfaceHolder_->nativeWindow_ = reinterpret_cast(nativeWindow_); - hasGotSurfaceHolder_ = true; - } -} - -OH_ArkUI_SurfaceHolder* XComponentPatternV2::GetSurfaceHolder() -{ - return surfaceHolder_; -} - -void XComponentPatternV2::OnAttachToFrameNode() -{ - if (isCNode_) { - XComponentPattern::OnAttachToFrameNode(); - return; - } - auto host = GetHost(); - CHECK_NULL_VOID(host); - auto renderContext = host->GetRenderContext(); - CHECK_NULL_VOID(renderContext); - - renderContext->SetClipToFrame(true); - renderContext->SetClipToBounds(true); - InitSurface(); - if (FrameReport::GetInstance().GetEnable()) { - FrameReport::GetInstance().EnableSelfRender(); - } - UpdateTransformHint(); -} - -void XComponentPatternV2::OnAttachToMainTree() -{ - UpdateUsesSuperMethod(); - if (usesSuperMethod_) { - XComponentPattern::OnAttachToMainTree(); - return; - } - isOnTree_ = true; - if (autoInitialize_) { - HandleSurfaceCreated(); - } - if (needRecoverDisplaySync_ && displaySync_ && !displaySync_->IsOnPipeline()) { - TAG_LOGD(AceLogTag::ACE_XCOMPONENT, "OnAttachToMainTree:recover displaySync: " - "%{public}s(%{public}" PRIu64 ")", GetId().c_str(), displaySync_->GetId()); - displaySync_->AddToPipelineOnContainer(); - needRecoverDisplaySync_ = false; - } -} - -void XComponentPatternV2::BeforeSyncGeometryProperties(const DirtySwapConfig& config) -{ - UpdateUsesSuperMethod(); - if (usesSuperMethod_) { - XComponentPattern::BeforeSyncGeometryProperties(config); - return; - } - CHECK_EQUAL_VOID(config.skipMeasure, true); - auto host = GetHost(); - CHECK_NULL_VOID(host); - auto geometryNode = host->GetGeometryNode(); - CHECK_NULL_VOID(geometryNode); - drawSize_ = geometryNode->GetContentSize(); - if (!drawSize_.IsPositive()) { - TAG_LOGW( - AceLogTag::ACE_XCOMPONENT, "XComponent[%{public}s]'s size is not positive", GetId().c_str()); - return; - } - localPosition_ = geometryNode->GetContentOffset(); - if (IsSupportImageAnalyzerFeature()) { - UpdateAnalyzerUIConfig(geometryNode); - } - const auto& [offsetChanged, sizeChanged] = UpdateSurfaceRect(); - HandleSurfaceChangeEvent(offsetChanged, sizeChanged, config.frameOffsetChange); - AddAfterLayoutTaskForExportTexture(); - host->MarkNeedSyncRenderTree(); -} - -std::pair XComponentPatternV2::UpdateSurfaceRect() -{ - if (!drawSize_.IsPositive()) { - return { false, false }; - } - auto preSurfaceSize = surfaceSize_; - auto preSurfaceOffset = surfaceOffset_; - - surfaceSize_ = drawSize_; - surfaceOffset_ = localPosition_; - auto offsetChanged = preSurfaceOffset != surfaceOffset_; - auto sizeChanged = preSurfaceSize != surfaceSize_; - if (offsetChanged || sizeChanged) { - paintRect_ = AdjustPaintRect( - surfaceOffset_.GetX(), surfaceOffset_.GetY(), surfaceSize_.Width(), surfaceSize_.Height(), true); - } - return { offsetChanged, sizeChanged }; -} - -void XComponentPatternV2::HandleSurfaceChangeEvent(bool offsetChanged, bool sizeChanged, bool frameOffsetChange) -{ - if (!drawSize_.IsPositive()) { - return; - } - if (sizeChanged) { - XComponentSizeChange(paintRect_); - } - if (renderContextForSurface_) { - renderContextForSurface_->SetBounds( - paintRect_.GetX(), paintRect_.GetY(), paintRect_.Width(), paintRect_.Height()); - } - if (renderSurface_) { - renderSurface_->SetSurfaceDefaultSize( - static_cast(paintRect_.Width()), static_cast(paintRect_.Height())); - } -} - -void XComponentPatternV2::XComponentSizeChange(const RectF& surfaceRect) -{ - auto host = GetHost(); - CHECK_NULL_VOID(host); - auto context = host->GetContextRefPtr(); - CHECK_NULL_VOID(context); - auto viewScale = context->GetViewScale(); - CHECK_NULL_VOID(renderSurface_); - auto width = surfaceRect.Width(); - auto height = surfaceRect.Height(); - needNotifySizeChanged_ = true; - renderSurface_->UpdateSurfaceSizeInUserData( - static_cast(width), static_cast(height)); - renderSurface_->AdjustNativeWindowSize( - static_cast(width * viewScale), static_cast(height * viewScale)); - OnSurfaceChanged(surfaceRect); -} - -void XComponentPatternV2::OnSurfaceChanged(const RectF& surfaceRect) -{ - CHECK_RUN_ON(UI); - CHECK_NULL_VOID(surfaceHolder_); - CHECK_EQUAL_VOID(isInitialized_, false); - ACE_SCOPED_TRACE("XComponent[%s] surfaceHolder OnSurfaceChanged", GetId().c_str()); - auto callbackList = surfaceHolder_->surfaceCallbackList_; - for (const auto& iter : callbackList) { - auto callback = iter->OnSurfaceChanged; - if (callback) { - callback(surfaceHolder_, surfaceRect.Width(), surfaceRect.Height()); - } - } - needNotifySizeChanged_ = false; -} - -void XComponentPatternV2::OnDetachFromMainTree() -{ - if (usesSuperMethod_) { - XComponentPattern::OnDetachFromMainTree(); - return; - } - isOnTree_ = false; - if (autoInitialize_) { - HandleSurfaceDestroyed(); - } - if (displaySync_ && displaySync_->IsOnPipeline()) { - TAG_LOGD(AceLogTag::ACE_XCOMPONENT, "OnDetachFromMainTree:remove displaySync: " - "%{public}s(%{public}" PRIu64 ")", GetId().c_str(), displaySync_->GetId()); - displaySync_->DelFromPipelineOnContainer(); - needRecoverDisplaySync_ = true; - } -} - -void XComponentPatternV2::OnDetachFromFrameNode(FrameNode* frameNode) -{ - UpdateUsesSuperMethod(); - if (usesSuperMethod_) { - XComponentPattern::OnDetachFromFrameNode(frameNode); - return; - } - auto id = frameNode->GetId(); - auto pipeline = frameNode->GetContextRefPtr(); - CHECK_NULL_VOID(pipeline); - pipeline->RemoveWindowStateChangedCallback(id); - if (HasTransformHintChangedCallbackId()) { - pipeline->UnregisterTransformHintChangedCallback(transformHintChangedCallbackId_.value_or(-1)); - } - if (FrameReport::GetInstance().GetEnable()) { - FrameReport::GetInstance().DisableSelfRender(); - } - HandleSurfaceDestroyed(); - - CHECK_NULL_VOID(surfaceHolder_); - surfaceHolder_->nativeWindow_ = nullptr; - surfaceHolder_->node_ = nullptr; -} - -void XComponentPatternV2::InitSurface() -{ - if (renderSurface_) { - return; - } - auto host = GetHost(); - CHECK_NULL_VOID(host); - auto renderContext = host->GetRenderContext(); - CHECK_NULL_VOID(renderContext); - - renderSurface_ = RenderSurface::Create(); - renderSurface_->SetInstanceId(GetHostInstanceId()); - renderSurface_->SetBufferUsage(BUFFER_USAGE_XCOMPONENT); - if (type_ == XComponentType::SURFACE) { - InitializeRenderContext(); - renderSurface_->SetRenderContext(renderContextForSurface_); - renderContext->AddChild(renderContextForSurface_, 0); - } else if (type_ == XComponentType::TEXTURE) { - renderSurface_->SetRenderContext(renderContext); - renderSurface_->SetIsTexture(true); - renderContext->OnNodeNameUpdate(GetId()); - } - renderSurface_->InitSurface(); - renderSurface_->UpdateSurfaceConfig(); - if (type_ == XComponentType::TEXTURE) { - renderSurface_->RegisterBufferCallback(); - } - auto width = paintRect_.Width(); - auto height = paintRect_.Height(); - if (!paintRect_.IsEmpty()) { - renderSurface_->UpdateSurfaceSizeInUserData( - static_cast(width), static_cast(height)); - renderSurface_->SetSurfaceDefaultSize( - static_cast(width), static_cast(height)); - } - renderSurface_->RegisterSurface(); - InitNativeWindow(width, height); - if (surfaceHolder_) { - surfaceHolder_->nativeWindow_ = reinterpret_cast(nativeWindow_); - } - surfaceId_ = renderSurface_->GetUniqueId(); - if (type_ == XComponentType::SURFACE) { - XComponentInnerSurfaceController::RegisterSurfaceRenderContext( - surfaceId_, WeakPtr(renderContextForSurface_)); - } -} - -void XComponentPatternV2::DisposeSurface() -{ - if (type_ == XComponentType::SURFACE) { - XComponentInnerSurfaceController::UnregisterSurfaceRenderContext( - surfaceId_); - surfaceId_ = ""; - } - if (renderSurface_) { - renderSurface_->ReleaseSurfaceBuffers(); - renderSurface_->UnregisterSurface(); - renderSurface_ = nullptr; - } - if (surfaceHolder_) { - surfaceHolder_->nativeWindow_ = nullptr; - } - nativeWindow_ = nullptr; - auto host = GetHost(); - CHECK_NULL_VOID(host); - auto renderContext = host->GetRenderContext(); - CHECK_NULL_VOID(renderContext); - // for surface type - CHECK_NULL_VOID(renderContextForSurface_); - renderContext->RemoveChild(renderContextForSurface_); - renderContextForSurface_ = nullptr; -#ifdef ENABLE_ROSEN_BACKEND - FlushImplicitTransaction(host); -#endif -} - -std::shared_ptr XComponentPatternV2::GetRSTransactionHandler( - const RefPtr& frameNode) -{ -#ifdef ENABLE_ROSEN_BACKEND - if (!SystemProperties::GetMultiInstanceEnabled()) { - return nullptr; - } - auto rsUIContext = GetRSUIContext(frameNode); - CHECK_NULL_RETURN(rsUIContext, nullptr); - return rsUIContext->GetRSTransaction(); -#endif - return nullptr; -} - -std::shared_ptr XComponentPatternV2::GetRSUIContext(const RefPtr& frameNode) -{ -#ifdef ENABLE_ROSEN_BACKEND - CHECK_NULL_RETURN(frameNode, nullptr); - auto pipeline = frameNode->GetContext(); - CHECK_NULL_RETURN(pipeline, nullptr); - auto window = pipeline->GetWindow(); - CHECK_NULL_RETURN(window, nullptr); - auto rsUIDirector = window->GetRSUIDirector(); - CHECK_NULL_RETURN(rsUIDirector, nullptr); - auto rsUIContext = rsUIDirector->GetRSUIContext(); - return rsUIContext; -#endif - return nullptr; -} - -void XComponentPatternV2::FlushImplicitTransaction(const RefPtr& frameNode) -{ -#ifdef ENABLE_ROSEN_BACKEND - if (auto transactionHandler = GetRSTransactionHandler(frameNode)) { - transactionHandler->FlushImplicitTransaction(); - } else { - Rosen::RSTransactionProxy::GetInstance()->FlushImplicitTransaction(); - } -#endif -} - -int32_t XComponentPatternV2::HandleSurfaceCreated() -{ - CHECK_EQUAL_RETURN(isInitialized_, true, ERROR_CODE_XCOMPONENT_STATE_INVALID); - InitSurface(); - CHECK_NULL_RETURN(renderSurface_, ERROR_CODE_PARAM_INVALID); - isInitialized_ = true; - if (surfaceHolder_) { - auto callbackList = surfaceHolder_->surfaceCallbackList_; - TAG_LOGI(AceLogTag::ACE_XCOMPONENT, "XComponent[%{public}s] surfaceHolder OnSurfaceCreated", GetId().c_str()); - ACE_SCOPED_TRACE("XComponent[%s] surfaceHolder OnSurfaceCreated", GetId().c_str()); - for (const auto& iter : callbackList) { - auto callback = iter->OnSurfaceCreated; - if (callback) { - callback(surfaceHolder_); - } - } - } - if (needNotifySizeChanged_) { - OnSurfaceChanged(paintRect_); - } - return ERROR_CODE_NO_ERROR; -} - -int32_t XComponentPatternV2::HandleSurfaceDestroyed() -{ - CHECK_EQUAL_RETURN(isInitialized_, false, ERROR_CODE_XCOMPONENT_STATE_INVALID); - isInitialized_ = false; - if (surfaceHolder_) { - auto callbackList = surfaceHolder_->surfaceCallbackList_; - TAG_LOGI(AceLogTag::ACE_XCOMPONENT, "XComponent[%{public}s] surfaceHolder OnSurfaceDestroyed", GetId().c_str()); - ACE_SCOPED_TRACE("XComponent[%s] surfaceHolder OnSurfaceDestroyed", GetId().c_str()); - for (const auto& iter : callbackList) { - auto callback = iter->OnSurfaceDestroyed; - if (callback) { - callback(surfaceHolder_); - } - } - } - DisposeSurface(); - return ERROR_CODE_NO_ERROR; -} - -int32_t XComponentPatternV2::Initialize() -{ - CHECK_EQUAL_RETURN(usesSuperMethod_, true, ERROR_CODE_PARAM_INVALID); - isLifecycleInterfaceCalled_ = true; - return HandleSurfaceCreated(); -} - -int32_t XComponentPatternV2::Finalize() -{ - CHECK_EQUAL_RETURN(usesSuperMethod_, true, ERROR_CODE_PARAM_INVALID); - isLifecycleInterfaceCalled_ = true; - return HandleSurfaceDestroyed(); -} - -int32_t XComponentPatternV2::SetAutoInitialize(bool autoInitialize) -{ - CHECK_EQUAL_RETURN(usesSuperMethod_, true, ERROR_CODE_PARAM_INVALID); - isLifecycleInterfaceCalled_ = true; - autoInitialize_ = autoInitialize; - return ERROR_CODE_NO_ERROR; -} - -int32_t XComponentPatternV2::IsInitialized(bool& isInitialized) -{ - CHECK_EQUAL_RETURN(usesSuperMethod_, true, ERROR_CODE_PARAM_INVALID); - isLifecycleInterfaceCalled_ = true; - isInitialized = isInitialized_; - return ERROR_CODE_NO_ERROR; -} - -void XComponentPatternV2::OnWindowHide() -{ - if (usesSuperMethod_) { - XComponentPattern::OnWindowHide(); - return; - } - CHECK_EQUAL_VOID(hasReleasedSurface_, true); - if (renderSurface_) { - renderSurface_->OnWindowStateChange(false); - } - OnSurfaceHide(); - hasReleasedSurface_ = true; -} - -void XComponentPatternV2::OnWindowShow() -{ - if (usesSuperMethod_) { - XComponentPattern::OnWindowShow(); - return; - } - CHECK_EQUAL_VOID(hasReleasedSurface_, false); - if (renderSurface_) { - renderSurface_->OnWindowStateChange(true); - } - OnSurfaceShow(); - hasReleasedSurface_ = false; -} - -void XComponentPatternV2::OnRebuildFrame() -{ - if (usesSuperMethod_) { - XComponentPattern::OnRebuildFrame(); - return; - } - if (type_ != XComponentType::SURFACE) { - return; - } - CHECK_NULL_VOID(renderSurface_); - if (!renderSurface_->IsSurfaceValid()) { - return; - } - auto host = GetHost(); - CHECK_NULL_VOID(host); - auto renderContext = host->GetRenderContext(); - CHECK_NULL_VOID(renderContext); - CHECK_NULL_VOID(renderContextForSurface_); - renderContext->AddChild(renderContextForSurface_, 0); -} - -void XComponentPatternV2::InitializeRenderContext() -{ - if (renderContextForSurface_) { - return; - } - renderContextForSurface_ = RenderContext::Create(); - RenderContext::ContextParam param = { RenderContext::ContextType::HARDWARE_SURFACE, GetId() + "Surface", - RenderContext::PatternType::XCOM }; - renderContextForSurface_->InitContext(false, param); - if (!paintRect_.IsEmpty()) { - renderContextForSurface_->SetBounds( - paintRect_.GetX(), paintRect_.GetY(), paintRect_.Width(), paintRect_.Height()); - } - renderContextForSurface_->UpdateBackgroundColor(bkColor_); - renderContextForSurface_->SetHDRBrightness(hdrBrightness_); - renderContextForSurface_->SetTransparentLayer(isTransparentLayer_); - renderContextForSurface_->SetSecurityLayer(isEnableSecure_); - renderContextForSurface_->SetSurfaceRotation(isSurfaceLock_); - renderContextForSurface_->SetRenderFit(renderFit_); -} - -void XComponentPatternV2::OnModifyDone() -{ - if (usesSuperMethod_) { - XComponentPattern::OnModifyDone(); - return; - } - Pattern::OnModifyDone(); - auto host = GetHost(); - CHECK_NULL_VOID(host); - auto renderContext = host->GetRenderContext(); - CHECK_NULL_VOID(renderContext); - CHECK_NULL_VOID(renderContextForSurface_); - auto bkColor = renderContext->GetBackgroundColor(); - if (bkColor.has_value()) { - bool isTransparent = bkColor.value().GetAlpha() < UINT8_MAX; - bkColor_ = isTransparent ? Color::TRANSPARENT : bkColor.value(); - } - renderContextForSurface_->UpdateBackgroundColor(bkColor_); -} - -void XComponentPatternV2::DumpInfo() -{ - if (usesSuperMethod_) { - XComponentPattern::DumpInfo(); - return; - } - DumpLog::GetInstance().AddDesc(std::string("autoInitialize: ").append(BoolToString(autoInitialize_))); - DumpLog::GetInstance().AddDesc(std::string("isInitialized: ").append(BoolToString(isInitialized_))); - DumpLog::GetInstance().AddDesc( - std::string("xcomponentNodeType: ").append(XComponentPattern::XComponentNodeTypeToString(nodeType_))); - DumpLog::GetInstance().AddDesc( - std::string("xcomponentType: ").append(XComponentPattern::XComponentTypeToString(type_))); - DumpLog::GetInstance().AddDesc(std::string("surfaceId: ").append(surfaceId_)); - DumpLog::GetInstance().AddDesc(std::string("surfaceRect: ").append(paintRect_.ToString())); -} - -void XComponentPatternV2::SetExpectedRateRange(int32_t min, int32_t max, int32_t expected) -{ - if (hasGotNativeXComponent_) { - return; - } - isNativeXComponentDisabled_ = true; - CHECK_NULL_VOID(displaySync_); - FrameRateRange frameRateRange; - frameRateRange.Set(min, max, expected); - displaySync_->SetExpectedFrameRateRange(frameRateRange); - TAG_LOGD(AceLogTag::ACE_XCOMPONENT, "Id: %{public}" PRIu64 " SetExpectedFrameRateRange" - "{%{public}d, %{public}d, %{public}d}", displaySync_->GetId(), min, max, expected); -} - -void XComponentPatternV2::UpdateOnFrameEvent(void(*callback)(void*, uint64_t, uint64_t), void* arkuiNode) -{ - if (hasGotNativeXComponent_) { - return; - } - isNativeXComponentDisabled_ = true; - CHECK_NULL_VOID(displaySync_); - displaySync_->RegisterOnFrameWithData([weak = AceType::WeakClaim(this), - callback, arkuiNode](RefPtr displaySyncData) { - auto xComponentPattern = weak.Upgrade(); - CHECK_NULL_VOID(xComponentPattern); - CHECK_NULL_VOID(callback); - CHECK_NULL_VOID(arkuiNode); - CHECK_NULL_VOID(displaySyncData); - callback(arkuiNode, displaySyncData->GetTimestamp(), displaySyncData->GetTargetTimestamp()); - }); - TAG_LOGD(AceLogTag::ACE_XCOMPONENT, "Id: %{public}" PRIu64 " RegisterOnFrame", - displaySync_->GetId()); - displaySync_->AddToPipelineOnContainer(); -} - -void XComponentPatternV2::UnregisterOnFrameEvent() -{ - if (hasGotNativeXComponent_) { - return; - } - isNativeXComponentDisabled_ = true; - CHECK_NULL_VOID(displaySync_); - displaySync_->UnregisterOnFrame(); - TAG_LOGD(AceLogTag::ACE_XCOMPONENT, "Id: %{public}" PRIu64 " UnregisterOnFrame", - displaySync_->GetId()); - displaySync_->DelFromPipelineOnContainer(); - needRecoverDisplaySync_ = false; -} - -void XComponentPatternV2::SetNeedSoftKeyboard(bool isNeedSoftKeyboard) -{ - if (hasGotNativeXComponent_) { - return; - } - isNativeXComponentDisabled_ = true; - isNeedSoftKeyboard_ = isNeedSoftKeyboard; -} - -void XComponentPatternV2::OnSurfaceShow() -{ - CHECK_RUN_ON(UI); - CHECK_NULL_VOID(surfaceHolder_); - auto callbackList = surfaceHolder_->surfaceCallbackList_; - for (const auto& iter : callbackList) { - auto callback = iter->onSurfaceShow; - if (callback) { - callback(surfaceHolder_); - } - } -} - -void XComponentPatternV2::OnSurfaceHide() -{ - CHECK_RUN_ON(UI); - CHECK_NULL_VOID(surfaceHolder_); - auto callbackList = surfaceHolder_->surfaceCallbackList_; - bool hasCallback = false; - for (const auto& iter : callbackList) { - auto callback = iter->onSurfaceHide; - if (callback) { - callback(surfaceHolder_); - hasCallback = true; - } - } - if (hasCallback) { - CHECK_NULL_VOID(renderSurface_); - renderSurface_->ReleaseSurfaceBuffers(); - } -} - -void XComponentPatternV2::ResetAndInitializeNodeHandleAccessibility() -{ - auto host = GetHost(); - CHECK_NULL_VOID(host); - auto pipeline = host->GetContextRefPtr(); - CHECK_NULL_VOID(pipeline); - auto accessibilityManager = pipeline->GetAccessibilityManager(); - CHECK_NULL_VOID(accessibilityManager); - if (accessibilityChildTreeCallback_) { - accessibilityManager->DeregisterAccessibilityChildTreeCallback( - accessibilityChildTreeCallback_->GetAccessibilityId() - ); - accessibilityChildTreeCallback_.reset(); - accessibilityChildTreeCallback_ = nullptr; - } - - TAG_LOGI(AceLogTag::ACE_XCOMPONENT, "InitializeNodeHandleAccessibility"); - CHECK_NULL_VOID(arkuiAccessibilityProvider_); - arkuiAccessibilityProvider_->SetRegisterCallback( - [weak = WeakClaim(this)] (bool isRegister) { - auto pattern = weak.Upgrade(); - CHECK_NULL_VOID(pattern); - pattern->HandleRegisterAccessibilityEvent(isRegister); - }); - int64_t accessibilityId = host->GetAccessibilityId(); - TAG_LOGI(AceLogTag::ACE_XCOMPONENT, - "InitializeNodeHandleAccessibility accessibilityId: %{public}" PRId64 "", accessibilityId); - accessibilityChildTreeCallback_ = std::make_shared( - WeakClaim(this), host->GetAccessibilityId()); - accessibilityManager->RegisterAccessibilityChildTreeCallback( - accessibilityId, accessibilityChildTreeCallback_); - if (accessibilityManager->IsRegister()) { - accessibilityChildTreeCallback_->OnRegister( - pipeline->GetWindowId(), accessibilityManager->GetTreeId()); - } -} - -ArkUI_AccessibilityProvider* XComponentPatternV2::CreateAccessibilityProvider() -{ - if (hasGotNativeXComponent_) { - return nullptr; - } - isNativeXComponentDisabled_ = true; - useNodeHandleAccessibilityProvider_ = true; - if (arkuiAccessibilityProvider_) { - return arkuiAccessibilityProvider_; - } - auto host = GetHost(); - CHECK_NULL_RETURN(host, nullptr); - arkuiAccessibilityProvider_ = new ArkUI_AccessibilityProvider(); - XComponentPatternV2::XComponentAccessibilityProviderMap[arkuiAccessibilityProvider_] = WeakPtr(host); - ResetAndInitializeNodeHandleAccessibility(); - return arkuiAccessibilityProvider_; -} - -void XComponentPatternV2::DisposeAccessibilityProvider(ArkUI_AccessibilityProvider* provider) -{ - if (hasGotNativeXComponent_ || (provider != arkuiAccessibilityProvider_)) { - return; - } - CHECK_NULL_VOID(arkuiAccessibilityProvider_); - isNativeXComponentDisabled_ = true; - XComponentPatternV2::XComponentAccessibilityProviderMap.erase(arkuiAccessibilityProvider_); - auto host = GetHost(); - UninitializeAccessibility(AceType::RawPtr(host)); - delete arkuiAccessibilityProvider_; - arkuiAccessibilityProvider_ = nullptr; -} - -std::unordered_map> XComponentPatternV2::XComponentAccessibilityProviderMap; - -FrameNode* XComponentPatternV2::QueryAccessibilityProviderHost(void* provider, bool& isProviderValied) -{ - auto it = XComponentAccessibilityProviderMap.find(provider); - if (it == XComponentAccessibilityProviderMap.end()) { - isProviderValied = false; - return nullptr; - } - isProviderValied = true; - auto weakHost = it->second; - auto host = weakHost.Upgrade(); - CHECK_NULL_RETURN(host, nullptr); - return AceType::RawPtr(host); -} -} // namespace OHOS::Ace::NG \ No newline at end of file diff --git a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_proxy/xcomponent_proxy.cpp b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_proxy/xcomponent_proxy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..40277fb8be0c59449a20fd2d998386dce8b6a8c3 --- /dev/null +++ b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_proxy/xcomponent_proxy.cpp @@ -0,0 +1,112 @@ +/* + * 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. + */ + +#include "core/components_ng/pattern/xcomponent/xcomponent_proxy/xcomponent_proxy.h" + +#include "core/components_ng/pattern/xcomponent/xcomponent_accessibility_child_tree_callback.h" +#include "core/components_ng/pattern/xcomponent/xcomponent_pattern.h" + +namespace OHOS::Ace::NG { +void XComponentProxy::InitializeAccessibility() +{ + if (accessibilityChildTreeCallback_) { + return; + } + InitializeAccessibilityCallback(); + auto xcPattern = pattern_.Upgrade(); + CHECK_NULL_VOID(xcPattern); + auto host = xcPattern->GetHost(); + CHECK_NULL_VOID(host); + int64_t accessibilityId = host->GetAccessibilityId(); + TAG_LOGI( + AceLogTag::ACE_XCOMPONENT, "InitializeAccessibility accessibilityId: %{public}" PRId64 "", accessibilityId); + auto pipeline = host->GetContextRefPtr(); + CHECK_NULL_VOID(pipeline); + auto accessibilityManager = pipeline->GetAccessibilityManager(); + CHECK_NULL_VOID(accessibilityManager); + accessibilityChildTreeCallback_ = + std::make_shared(pattern_, host->GetAccessibilityId()); + accessibilityManager->RegisterAccessibilityChildTreeCallback(accessibilityId, accessibilityChildTreeCallback_); + if (accessibilityManager->IsRegister()) { + accessibilityChildTreeCallback_->OnRegister(pipeline->GetWindowId(), accessibilityManager->GetTreeId()); + } +} + +void XComponentProxy::InitializeAccessibilityCallback() +{ + TAG_LOGI(AceLogTag::ACE_XCOMPONENT, "InitializeAccessibilityCallback"); + auto* nativeProvider = GetAccessibilityProvider(); + CHECK_NULL_VOID(nativeProvider); + nativeProvider->SetRegisterCallback([weak = WeakClaim(this)](bool isRegister) { + auto proxy = weak.Upgrade(); + CHECK_NULL_VOID(proxy); + proxy->HandleRegisterAccessibilityEvent(isRegister); + }); +} + +void XComponentProxy::HandleRegisterAccessibilityEvent(bool isRegister) +{ + TAG_LOGI(AceLogTag::ACE_XCOMPONENT, "HandleRegisterAccessibilityEvent, isRegister: %{public}d.", isRegister); + CHECK_NULL_VOID(accessibilityChildTreeCallback_); + auto xcPattern = pattern_.Upgrade(); + CHECK_NULL_VOID(xcPattern); + auto host = xcPattern->GetHost(); + CHECK_NULL_VOID(host); + auto pipeline = host->GetContextRefPtr(); + CHECK_NULL_VOID(pipeline); + auto accessibilityManager = pipeline->GetAccessibilityManager(); + CHECK_NULL_VOID(accessibilityManager); + if (!isRegister) { + accessibilityChildTreeCallback_->OnDeregister(); + return; + } + if (accessibilityManager->IsRegister()) { + accessibilityChildTreeCallback_->OnRegister(pipeline->GetWindowId(), accessibilityManager->GetTreeId()); + } +} + +void XComponentProxy::ResetAccessibilityChildTreeCallback() +{ + auto xcPattern = pattern_.Upgrade(); + CHECK_NULL_VOID(xcPattern); + auto host = xcPattern->GetHost(); + CHECK_NULL_VOID(host); + auto pipeline = host->GetContextRefPtr(); + CHECK_NULL_VOID(pipeline); + auto accessibilityManager = pipeline->GetAccessibilityManager(); + if (accessibilityChildTreeCallback_) { + accessibilityManager->DeregisterAccessibilityChildTreeCallback( + accessibilityChildTreeCallback_->GetAccessibilityId()); + accessibilityChildTreeCallback_.reset(); + accessibilityChildTreeCallback_ = nullptr; + } +} + +void XComponentProxy::UninitializeAccessibility(FrameNode* frameNode) +{ + TAG_LOGI(AceLogTag::ACE_XCOMPONENT, "UninitializeAccessibility"); + CHECK_NULL_VOID(frameNode); + int64_t accessibilityId = frameNode->GetAccessibilityId(); + auto pipeline = frameNode->GetContextRefPtr(); + CHECK_NULL_VOID(pipeline); + auto accessibilityManager = pipeline->GetAccessibilityManager(); + CHECK_NULL_VOID(accessibilityManager); + if (accessibilityManager->IsRegister() && accessibilityChildTreeCallback_) { + accessibilityChildTreeCallback_->OnDeregister(); + } + accessibilityManager->DeregisterAccessibilityChildTreeCallback(accessibilityId); + accessibilityChildTreeCallback_ = nullptr; +} +} // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_proxy/xcomponent_proxy.h b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_proxy/xcomponent_proxy.h new file mode 100644 index 0000000000000000000000000000000000000000..ca3bb9866770d316fd89b6aa1882a92801c39412 --- /dev/null +++ b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_proxy/xcomponent_proxy.h @@ -0,0 +1,74 @@ +/* + * 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_XCOMPONENT_XCOMPONENT_PROXY_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_XCOMPONENT_XCOMPONENT_PROXY_H + +#include "ui/base/ace_type.h" +#include "ui/base/referenced.h" + +#include "core/accessibility/accessibility_manager.h" +#include "core/accessibility/native_interface_accessibility_provider.h" +#include "core/components_ng/base/frame_node.h" + +namespace OHOS::Ace::NG { + +class XComponentPattern; +class XComponentProxy : public AceType { + DECLARE_ACE_TYPE(XComponentProxy, AceType); + +public: + XComponentProxy() = delete; + explicit XComponentProxy(const WeakPtr& pattern) : pattern_(pattern) {}; + ~XComponentProxy() override = default; + + virtual void OnAttachToMainTree() = 0; + virtual void OnDetachFromMainTree() = 0; + virtual void OnSizeChange( + bool offsetChanged, bool sizeChanged, bool frameOffsetChange, bool needFireNativeEvent) = 0; + virtual bool NeedSoftKeyboard() = 0; + virtual ArkUI_AccessibilityProvider* GetAccessibilityProvider() const = 0; + virtual void DispatchSurfaceCreatedEvent(int32_t width, int32_t height, void* nativeWindow) = 0; + virtual void DispatchSurfaceChangedEvent(int32_t width, int32_t height) = 0; + virtual void DispatchSurfaceDestroyedEvent() = 0; + virtual void DispatchSurfaceShowEvent() = 0; + // return true means need to release buffer + virtual bool DispatchSurfaceHideEvent() = 0; + + // only CNODE&XComponentProxyNativeXComponent may return true + bool IsToggleEnabled() const + { + return toggleEnabled_; + } + void SetToggleEnabled(bool toggleEnabled) + { + toggleEnabled_ = toggleEnabled; + } + void InitializeAccessibility(); + void UninitializeAccessibility(FrameNode* frameNode); + +protected: + void HandleRegisterAccessibilityEvent(bool isRegister); + void ResetAccessibilityChildTreeCallback(); + WeakPtr pattern_ = nullptr; + +private: + void InitializeAccessibilityCallback(); + // true means XComponentProxy can toggle between XComponentProxyNativeXComponent and XComponentProxySurfaceHolder + bool toggleEnabled_ = false; + std::shared_ptr accessibilityChildTreeCallback_; +}; +} // namespace OHOS::Ace::NG +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_XCOMPONENT_XCOMPONENT_PROXY_H diff --git a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_proxy/xcomponent_proxy_native_xcomponent.cpp b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_proxy/xcomponent_proxy_native_xcomponent.cpp new file mode 100644 index 0000000000000000000000000000000000000000..961a16ecdc3afc44ff5334524376a02676f990b5 --- /dev/null +++ b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_proxy/xcomponent_proxy_native_xcomponent.cpp @@ -0,0 +1,304 @@ +/* + * 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. + */ + +#include "core/components_ng/pattern/xcomponent/xcomponent_proxy/xcomponent_proxy_native_xcomponent.h" + +#include "interfaces/native/event/ui_input_event_impl.h" +#include "interfaces/native/ui_input_event.h" +#include "ui/base/utils/utils.h" + +#include "core/accessibility/native_interface_accessibility_provider.h" +#include "core/components_ng/pattern/xcomponent/xcomponent_pattern.h" +#include "core/components_ng/pattern/xcomponent/xcomponent_utils.h" + +namespace OHOS::Ace::NG { +void XComponentProxyNativeXComponent::OnAttachToMainTree() +{ + auto xcPattern = pattern_.Upgrade(); + CHECK_NULL_VOID(xcPattern); + if (xcPattern->GetNodeType() == XComponentNodeType::TYPE_NODE && + xcPattern->GetSurfaceCallbackMode() == SurfaceCallbackMode::DEFAULT) { + xcPattern->HandleSurfaceCreated(); + } +} +void XComponentProxyNativeXComponent::OnDetachFromMainTree() +{ + auto xcPattern = pattern_.Upgrade(); + CHECK_NULL_VOID(xcPattern); + if (xcPattern->GetNodeType() == XComponentNodeType::TYPE_NODE && + xcPattern->GetSurfaceCallbackMode() == SurfaceCallbackMode::DEFAULT) { + xcPattern->HandleSurfaceDestroyed(); + } +} +void XComponentProxyNativeXComponent::OnSizeChange( + bool offsetChanged, bool sizeChanged, bool frameOffsetChange, bool needFireNativeEvent) +{ + auto xcPattern = pattern_.Upgrade(); + CHECK_NULL_VOID(xcPattern); + xcPattern->OnSizeChange(offsetChanged, sizeChanged, frameOffsetChange, needFireNativeEvent); +} + +bool XComponentProxyNativeXComponent::NeedSoftKeyboard() +{ + return nativeXComponentImpl_ ? nativeXComponentImpl_->IsNeedSoftKeyboard() : false; +} + +void XComponentProxyNativeXComponent::SetExpectedRateRangeInit() +{ + CHECK_NULL_VOID(nativeXComponentImpl_); + nativeXComponentImpl_->SetExpectedRateRangeEventCallback([weak = pattern_]() { + auto xComponentPattern = weak.Upgrade(); + CHECK_NULL_VOID(xComponentPattern); + xComponentPattern->HandleSetExpectedRateRangeEvent(); + }); +} +void XComponentProxyNativeXComponent::OnFrameEventInit() +{ + CHECK_NULL_VOID(nativeXComponentImpl_); + nativeXComponentImpl_->SetOnFrameEventCallback([weak = pattern_]() { + auto xComponentPattern = weak.Upgrade(); + CHECK_NULL_VOID(xComponentPattern); + xComponentPattern->HandleOnFrameEvent(); + }); +} +void XComponentProxyNativeXComponent::UnregisterOnFrameEventInit() +{ + CHECK_NULL_VOID(nativeXComponentImpl_); + nativeXComponentImpl_->SetUnregisterOnFrameEventCallback([weak = pattern_]() { + auto xComponentPattern = weak.Upgrade(); + CHECK_NULL_VOID(xComponentPattern); + xComponentPattern->HandleUnregisterOnFrameEvent(); + }); +} + +void XComponentProxyNativeXComponent::SetNativeXComponentOffset(double offsetX, double offsetY) +{ + CHECK_NULL_VOID(nativeXComponent_); + CHECK_NULL_VOID(nativeXComponentImpl_); + nativeXComponentImpl_->SetXComponentOffsetX(offsetX); + nativeXComponentImpl_->SetXComponentOffsetY(offsetY); +} + +void XComponentProxyNativeXComponent::DispatchTouchEvent(const OH_NativeXComponent_TouchEvent& touchEvent, + const std::vector& xComponentTouchPoints, + const std::vector& historicalPoints, + std::pair&& curSourceType) +{ + CHECK_NULL_VOID(nativeXComponent_); + CHECK_NULL_VOID(nativeXComponentImpl_); + nativeXComponentImpl_->SetHistoricalPoint(historicalPoints); + nativeXComponentImpl_->SetCurrentSourceType(std::move(curSourceType)); + nativeXComponentImpl_->SetTouchEvent(touchEvent); + nativeXComponentImpl_->SetTouchPoint(xComponentTouchPoints); + auto* nativeWindow = const_cast(nativeXComponentImpl_->GetSurface()); + const auto* callback = nativeXComponentImpl_->GetCallback(); + CHECK_NULL_VOID(callback); + CHECK_NULL_VOID(callback->DispatchTouchEvent); + callback->DispatchTouchEvent(nativeXComponent_.get(), nativeWindow); +} + +void XComponentProxyNativeXComponent::RegisterNodeCallback(void* xcFrameNode) +{ + CHECK_NULL_VOID(nativeXComponent_); + CHECK_NULL_VOID(nativeXComponentImpl_); + + nativeXComponentImpl_->registerContaner(xcFrameNode); + + auto OnAttachRootNativeNode = [](void* container, void* root) { + ContainerScope scope(Container::CurrentIdSafely()); + auto node = AceType::Claim(reinterpret_cast(root)); + CHECK_NULL_VOID(node); + auto host = AceType::Claim(reinterpret_cast(container)); + CHECK_NULL_VOID(host); + host->AddChild(node); + host->MarkDirtyNode(PROPERTY_UPDATE_MEASURE); + }; + + auto OnDetachRootNativeNode = [](void* container, void* root) { + ContainerScope scope(Container::CurrentIdSafely()); + auto node = AceType::Claim(reinterpret_cast(root)); + CHECK_NULL_VOID(node); + auto host = AceType::Claim(reinterpret_cast(container)); + CHECK_NULL_VOID(host); + host->RemoveChild(node); + }; + + nativeXComponentImpl_->registerNativeNodeCallbacks( + std::move(OnAttachRootNativeNode), std::move(OnDetachRootNativeNode)); +} + +void XComponentProxyNativeXComponent::DispatchFocusEvent() +{ + CHECK_NULL_VOID(nativeXComponent_); + CHECK_NULL_VOID(nativeXComponentImpl_); + auto* nativeWindow = const_cast(nativeXComponentImpl_->GetSurface()); + const auto focusEventCallback = nativeXComponentImpl_->GetFocusEventCallback(); + CHECK_NULL_VOID(focusEventCallback); + focusEventCallback(nativeXComponent_.get(), nativeWindow); +} +bool XComponentProxyNativeXComponent::DispatchKeyEvent(const KeyEvent& event) +{ + CHECK_NULL_RETURN(nativeXComponent_, false); + CHECK_NULL_RETURN(nativeXComponentImpl_, false); + + OH_NativeXComponent_KeyEvent keyEvent = XComponentUtils::ConvertNativeXComponentKeyEvent(event); + nativeXComponentImpl_->SetKeyEvent(keyEvent); + + auto* nativeWindow = const_cast(nativeXComponentImpl_->GetSurface()); + const auto keyEventCallbackWithResult = nativeXComponentImpl_->GetKeyEventCallbackWithResult(); + if (keyEventCallbackWithResult) { + return keyEventCallbackWithResult(nativeXComponent_.get(), nativeWindow); + } + const auto keyEventCallback = nativeXComponentImpl_->GetKeyEventCallback(); + CHECK_NULL_RETURN(keyEventCallback, false); + keyEventCallback(nativeXComponent_.get(), nativeWindow); + return false; +} +void XComponentProxyNativeXComponent::DispatchBlurEvent() +{ + CHECK_NULL_VOID(nativeXComponent_); + CHECK_NULL_VOID(nativeXComponentImpl_); + auto* surface = const_cast(nativeXComponentImpl_->GetSurface()); + const auto blurEventCallback = nativeXComponentImpl_->GetBlurEventCallback(); + CHECK_NULL_VOID(blurEventCallback); + blurEventCallback(nativeXComponent_.get(), surface); +} + +HitTestMode XComponentProxyNativeXComponent::InitOnTouchIntercept( + const TouchEventInfo& touchEvent, HitTestMode defaultHitTestMode) +{ + CHECK_NULL_RETURN(nativeXComponent_, defaultHitTestMode); + CHECK_NULL_RETURN(nativeXComponentImpl_, defaultHitTestMode); + const auto onTouchInterceptCallback = nativeXComponentImpl_->GetOnTouchInterceptCallback(); + CHECK_NULL_RETURN(onTouchInterceptCallback, defaultHitTestMode); + auto event = touchEvent.ConvertToTouchEvent(); + ArkUI_UIInputEvent uiEvent { ARKUI_UIINPUTEVENT_TYPE_TOUCH, TOUCH_EVENT_ID, &event, false, + Container::GetCurrentApiTargetVersion() }; + return static_cast(onTouchInterceptCallback(nativeXComponent_.get(), &uiEvent)); +} + +void XComponentProxyNativeXComponent::DispatchMouseHoverEvent(bool isHover) +{ + CHECK_NULL_VOID(nativeXComponent_); + CHECK_NULL_VOID(nativeXComponentImpl_); + const auto* callback = nativeXComponentImpl_->GetMouseEventCallback(); + CHECK_NULL_VOID(callback); + CHECK_NULL_VOID(callback->DispatchHoverEvent); + callback->DispatchHoverEvent(nativeXComponent_.get(), isHover); +} + +void XComponentProxyNativeXComponent::DispatchMouseEvent(const OH_NativeXComponent_MouseEvent& mouseEvent, + const OH_NativeXComponent_ExtraMouseEventInfo& extraMouseEventInfo) +{ + CHECK_NULL_VOID(nativeXComponent_); + CHECK_NULL_VOID(nativeXComponentImpl_); + nativeXComponentImpl_->SetMouseEvent(mouseEvent); + nativeXComponentImpl_->SetExtraMouseEventInfo(extraMouseEventInfo); + auto* nativeWindow = const_cast(nativeXComponentImpl_->GetSurface()); + const auto* callback = nativeXComponentImpl_->GetMouseEventCallback(); + CHECK_NULL_VOID(callback); + CHECK_NULL_VOID(callback->DispatchMouseEvent); + callback->DispatchMouseEvent(nativeXComponent_.get(), nativeWindow); +} + +void XComponentProxyNativeXComponent::DispatchAxisEvent(AxisEvent* axisEvent) +{ + CHECK_NULL_VOID(nativeXComponent_); + CHECK_NULL_VOID(nativeXComponentImpl_); + const auto callback = nativeXComponentImpl_->GetUIAxisEventCallback(); + CHECK_NULL_VOID(callback); + ArkUI_UIInputEvent uiEvent { ARKUI_UIINPUTEVENT_TYPE_AXIS, AXIS_EVENT_ID, axisEvent, false, + Container::GetCurrentApiTargetVersion() }; + callback(nativeXComponent_.get(), &uiEvent, ArkUI_UIInputEvent_Type::ARKUI_UIINPUTEVENT_TYPE_AXIS); +} + +OH_NativeXComponent_ExpectedRateRange* XComponentProxyNativeXComponent::GetRateRange() +{ + CHECK_NULL_RETURN(nativeXComponent_, nullptr); + CHECK_NULL_RETURN(nativeXComponentImpl_, nullptr); + return nativeXComponentImpl_->GetRateRange(); +} + +void XComponentProxyNativeXComponent::DispatchOnFrameEvent(int64_t timestamp, int64_t targetTimestamp) +{ + CHECK_NULL_VOID(nativeXComponent_); + CHECK_NULL_VOID(nativeXComponentImpl_); + const auto callback = nativeXComponentImpl_->GetOnFrameCallback(); + CHECK_NULL_VOID(callback); + callback(nativeXComponent_.get(), timestamp, targetTimestamp); +} + +void XComponentProxyNativeXComponent::DispatchSurfaceCreatedEvent(int32_t width, int32_t height, void* nativeWindow) +{ + CHECK_NULL_VOID(nativeXComponentImpl_); + CHECK_NULL_VOID(nativeXComponent_); + nativeXComponentImpl_->SetXComponentWidth(static_cast(width)); + nativeXComponentImpl_->SetXComponentHeight(static_cast(height)); + nativeXComponentImpl_->SetSurface(nativeWindow); + const auto* callback = nativeXComponentImpl_->GetCallback(); + CHECK_NULL_VOID(callback); + CHECK_NULL_VOID(callback->OnSurfaceCreated); + callback->OnSurfaceCreated(nativeXComponent_.get(), nativeWindow); +} +void XComponentProxyNativeXComponent::DispatchSurfaceChangedEvent(int32_t width, int32_t height) +{ + CHECK_NULL_VOID(nativeXComponent_); + CHECK_NULL_VOID(nativeXComponentImpl_); + nativeXComponentImpl_->SetXComponentWidth(static_cast(width)); + nativeXComponentImpl_->SetXComponentHeight(static_cast(height)); + auto* nativeWindow = const_cast(nativeXComponentImpl_->GetSurface()); + const auto* callback = nativeXComponentImpl_->GetCallback(); + CHECK_NULL_VOID(callback); + CHECK_NULL_VOID(callback->OnSurfaceChanged); + callback->OnSurfaceChanged(nativeXComponent_.get(), nativeWindow); +} +void XComponentProxyNativeXComponent::DispatchSurfaceDestroyedEvent() +{ + CHECK_NULL_VOID(nativeXComponent_); + CHECK_NULL_VOID(nativeXComponentImpl_); + auto* nativeWindow = const_cast(nativeXComponentImpl_->GetSurface()); + const auto* callback = nativeXComponentImpl_->GetCallback(); + CHECK_NULL_VOID(callback); + CHECK_NULL_VOID(callback->OnSurfaceDestroyed); + callback->OnSurfaceDestroyed(nativeXComponent_.get(), nativeWindow); + nativeXComponentImpl_->SetSurface(nullptr); +} +void XComponentProxyNativeXComponent::DispatchSurfaceShowEvent() +{ + CHECK_NULL_VOID(nativeXComponentImpl_); + CHECK_NULL_VOID(nativeXComponent_); + auto* surface = const_cast(nativeXComponentImpl_->GetSurface()); + const auto surfaceShowCallback = nativeXComponentImpl_->GetSurfaceShowCallback(); + CHECK_NULL_VOID(surfaceShowCallback); + surfaceShowCallback(nativeXComponent_.get(), surface); +} +bool XComponentProxyNativeXComponent::DispatchSurfaceHideEvent() +{ + CHECK_NULL_RETURN(nativeXComponent_, false); + CHECK_NULL_RETURN(nativeXComponentImpl_, false); + auto* surface = const_cast(nativeXComponentImpl_->GetSurface()); + const auto surfaceHideCallback = nativeXComponentImpl_->GetSurfaceHideCallback(); + CHECK_NULL_RETURN(surfaceHideCallback, false); + surfaceHideCallback(nativeXComponent_.get(), surface); + return true; +} + +ArkUI_AccessibilityProvider* XComponentProxyNativeXComponent::GetAccessibilityProvider() const +{ + CHECK_NULL_RETURN(nativeXComponent_, nullptr); + CHECK_NULL_RETURN(nativeXComponentImpl_, nullptr); + return nativeXComponentImpl_->GetAccessibilityProvider().get(); +} +} // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_proxy/xcomponent_proxy_native_xcomponent.h b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_proxy/xcomponent_proxy_native_xcomponent.h new file mode 100644 index 0000000000000000000000000000000000000000..3a76476535fb613a868061ca3868c50cf6dbc309 --- /dev/null +++ b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_proxy/xcomponent_proxy_native_xcomponent.h @@ -0,0 +1,88 @@ +/* + * 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_XCOMPONENT_XCOMPONENT_PROXY_NATIVE_XCOMPONENT_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_XCOMPONENT_XCOMPONENT_PROXY_NATIVE_XCOMPONENT_H + +#include "interfaces/native/native_interface_xcomponent.h" +#include "ui/base/ace_type.h" + +#include "core/components/xcomponent/native_interface_xcomponent_impl.h" +#include "core/components_ng/pattern/xcomponent/xcomponent_proxy/xcomponent_proxy.h" + +namespace OHOS::Ace::NG { + +class XComponentProxyNativeXComponent : public XComponentProxy { + DECLARE_ACE_TYPE(XComponentProxyNativeXComponent, XComponentProxy); + +public: + explicit XComponentProxyNativeXComponent(const WeakPtr& pattern) : XComponentProxy(pattern) {} + ~XComponentProxyNativeXComponent() override = default; + + void OnAttachToMainTree() override; + void OnDetachFromMainTree() override; + void OnSizeChange(bool offsetChanged, bool sizeChanged, bool frameOffsetChange, bool needFireNativeEvent) override; + bool NeedSoftKeyboard() override; + ArkUI_AccessibilityProvider* GetAccessibilityProvider() const override; + void DispatchSurfaceCreatedEvent(int32_t width, int32_t height, void* nativeWindow) override; + void DispatchSurfaceChangedEvent(int32_t width, int32_t height) override; + void DispatchSurfaceDestroyedEvent() override; + void DispatchSurfaceShowEvent() override; + // return true means need to release buffer + bool DispatchSurfaceHideEvent() override; + + std::pair, std::weak_ptr> GetOrCreateNativeXComponent() + { + if (!nativeXComponent_ || !nativeXComponentImpl_) { + nativeXComponentImpl_ = AceType::MakeRefPtr(); + nativeXComponent_ = std::make_shared(AceType::RawPtr(nativeXComponentImpl_)); + } + return std::make_pair(nativeXComponentImpl_, nativeXComponent_); + } + void SetExpectedRateRangeInit(); + void OnFrameEventInit(); + void UnregisterOnFrameEventInit(); + + void SetNativeXComponentOffset(double offsetX, double offsetY); + + void DispatchTouchEvent(const OH_NativeXComponent_TouchEvent& touchEvent, + const std::vector& xComponentTouchPoints, + const std::vector& historicalPoints, + std::pair&& curSourceType); + + // for type is node which is deprecated + void RegisterNodeCallback(void* xcFrameNode); + + void DispatchFocusEvent(); + bool DispatchKeyEvent(const KeyEvent& event); + void DispatchBlurEvent(); + + HitTestMode InitOnTouchIntercept(const TouchEventInfo& touchEvent, HitTestMode defaultHitTestMode); + + void DispatchMouseHoverEvent(bool isHover); + void DispatchMouseEvent(const OH_NativeXComponent_MouseEvent& mouseEvent, + const OH_NativeXComponent_ExtraMouseEventInfo& extraMouseEventInfo); + void DispatchAxisEvent(AxisEvent* axisEvent); + + OH_NativeXComponent_ExpectedRateRange* GetRateRange(); + + void DispatchOnFrameEvent(int64_t timestamp, int64_t targetTimestamp); + +private: + std::shared_ptr nativeXComponent_ = nullptr; + RefPtr nativeXComponentImpl_ = nullptr; +}; +} // namespace OHOS::Ace::NG +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_XCOMPONENT_XCOMPONENT_PROXY_NATIVE_XCOMPONENT_H diff --git a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_proxy/xcomponent_proxy_surface_holder.cpp b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_proxy/xcomponent_proxy_surface_holder.cpp new file mode 100644 index 0000000000000000000000000000000000000000..280002af6cbb14015f23b36de51ce0c3259544bf --- /dev/null +++ b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_proxy/xcomponent_proxy_surface_holder.cpp @@ -0,0 +1,187 @@ +/* + * 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. + */ + +#include "core/components_ng/pattern/xcomponent/xcomponent_proxy/xcomponent_proxy_surface_holder.h" + +#include "ui/base/utils/utils.h" + +#include "core/components_ng/pattern/xcomponent/xcomponent_accessibility_child_tree_callback.h" +#include "core/components_ng/pattern/xcomponent/xcomponent_pattern.h" + +namespace OHOS::Ace::NG { +void XComponentProxySurfaceHolder::OnAttachToMainTree() +{ + if (autoInitialize_) { + auto xcPattern = pattern_.Upgrade(); + CHECK_NULL_VOID(xcPattern); + xcPattern->HandleSurfaceCreatedForSurfaceHolder(); + } +} +void XComponentProxySurfaceHolder::OnDetachFromMainTree() +{ + if (autoInitialize_) { + auto xcPattern = pattern_.Upgrade(); + CHECK_NULL_VOID(xcPattern); + xcPattern->HandleSurfaceDestroyedForSurfaceHolder(); + } +} +void XComponentProxySurfaceHolder::OnSizeChange([[maybe_unused]] bool offsetChanged, bool sizeChanged, + [[maybe_unused]] bool frameOffsetChange, [[maybe_unused]] bool needFireNativeEvent) +{ + auto xcPattern = pattern_.Upgrade(); + CHECK_NULL_VOID(xcPattern); + xcPattern->HandleSurfaceChangeEventForSurfaceHolder(sizeChanged); +} + +bool XComponentProxySurfaceHolder::NeedSoftKeyboard() +{ + return isNeedSoftKeyboard_; +} + +void XComponentProxySurfaceHolder::SetNativeWindow(void* nativeWindow) +{ + if (surfaceHolder_) { + surfaceHolder_->nativeWindow_ = reinterpret_cast(nativeWindow); + } +} + +void XComponentProxySurfaceHolder::DispatchSurfaceCreatedEvent( + [[maybe_unused]] int32_t width, [[maybe_unused]] int32_t height, void* nativeWindow) +{ + CHECK_NULL_VOID(surfaceHolder_); + surfaceHolder_->nativeWindow_ = reinterpret_cast(nativeWindow); + isInitialized_ = true; + auto callbackList = surfaceHolder_->surfaceCallbackList_; + for (const auto& iter : callbackList) { + auto callback = iter->OnSurfaceCreated; + if (callback) { + callback(surfaceHolder_); + } + } +} +void XComponentProxySurfaceHolder::DispatchSurfaceChangedEvent(int32_t width, int32_t height) +{ + CHECK_NULL_VOID(surfaceHolder_); + CHECK_EQUAL_VOID(isInitialized_, false); + auto callbackList = surfaceHolder_->surfaceCallbackList_; + for (const auto& iter : callbackList) { + auto callback = iter->OnSurfaceChanged; + if (callback) { + callback(surfaceHolder_, width, height); + } + } +} +void XComponentProxySurfaceHolder::DispatchSurfaceDestroyedEvent() +{ + isInitialized_ = false; + CHECK_NULL_VOID(surfaceHolder_); + auto callbackList = surfaceHolder_->surfaceCallbackList_; + for (const auto& iter : callbackList) { + auto callback = iter->OnSurfaceDestroyed; + if (callback) { + callback(surfaceHolder_); + } + } +} +void XComponentProxySurfaceHolder::DispatchSurfaceShowEvent() +{ + CHECK_NULL_VOID(surfaceHolder_); + auto callbackList = surfaceHolder_->surfaceCallbackList_; + for (const auto& iter : callbackList) { + auto callback = iter->onSurfaceShow; + if (callback) { + callback(surfaceHolder_); + } + } +} +// return true means need to release buffer +bool XComponentProxySurfaceHolder::DispatchSurfaceHideEvent() +{ + CHECK_NULL_RETURN(surfaceHolder_, false); + auto callbackList = surfaceHolder_->surfaceCallbackList_; + bool hasCallback = false; + for (const auto& iter : callbackList) { + auto callback = iter->onSurfaceHide; + if (callback) { + callback(surfaceHolder_); + hasCallback = true; + } + } + return hasCallback; +} + +void XComponentProxySurfaceHolder::SetSurfaceHolder(OH_ArkUI_SurfaceHolder* surfaceHolder) +{ + surfaceHolder_ = surfaceHolder; +} + +ArkUI_AccessibilityProvider* XComponentProxySurfaceHolder::GetAccessibilityProvider() const +{ + return arkuiAccessibilityProvider_; +} + +void XComponentProxySurfaceHolder::SetAutoInitialize(bool autoInitialize) +{ + autoInitialize_ = autoInitialize; +} + +std::unordered_map> XComponentProxySurfaceHolder::XComponentAccessibilityProviderMap; + +ArkUI_AccessibilityProvider* XComponentProxySurfaceHolder::CreateAccessibilityProvider() +{ + if (arkuiAccessibilityProvider_) { + return arkuiAccessibilityProvider_; + } + auto xcPattern = pattern_.Upgrade(); + CHECK_NULL_RETURN(xcPattern, nullptr); + auto host = xcPattern->GetHost(); + CHECK_NULL_RETURN(host, nullptr); + arkuiAccessibilityProvider_ = new ArkUI_AccessibilityProvider(); + XComponentAccessibilityProviderMap[arkuiAccessibilityProvider_] = WeakPtr(host); + ResetAccessibilityChildTreeCallback(); + InitializeAccessibility(); + return arkuiAccessibilityProvider_; +} + +void XComponentProxySurfaceHolder::DisposeAccessibilityProvider(ArkUI_AccessibilityProvider* provider) +{ + if (provider != arkuiAccessibilityProvider_) { + return; + } + CHECK_NULL_VOID(arkuiAccessibilityProvider_); + XComponentAccessibilityProviderMap.erase(arkuiAccessibilityProvider_); + auto xcPattern = pattern_.Upgrade(); + CHECK_NULL_VOID(xcPattern); + auto host = xcPattern->GetHost(); + UninitializeAccessibility(AceType::RawPtr(host)); + delete arkuiAccessibilityProvider_; + arkuiAccessibilityProvider_ = nullptr; +} + +FrameNode* XComponentProxySurfaceHolder::QueryAccessibilityProviderHost(void* provider, bool& isProviderValied) +{ + auto it = XComponentAccessibilityProviderMap.find(provider); + if (it == XComponentAccessibilityProviderMap.end()) { + isProviderValied = false; + return nullptr; + } + isProviderValied = true; + auto weakHost = it->second; + auto host = weakHost.Upgrade(); + CHECK_NULL_RETURN(host, nullptr); + return AceType::RawPtr(host); +} + +} // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern_v2.h b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_proxy/xcomponent_proxy_surface_holder.h similarity index 32% rename from frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern_v2.h rename to frameworks/core/components_ng/pattern/xcomponent/xcomponent_proxy/xcomponent_proxy_surface_holder.h index 70e47215667119bdd5cd2d7d61c2eb124a5d417c..7207eec46b1c490d4e9e523f1afd130317e4dd52 100644 --- a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern_v2.h +++ b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_proxy/xcomponent_proxy_surface_holder.h @@ -13,112 +13,64 @@ * limitations under the License. */ -#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_XCOMPONENT_XCOMPONENT_PATTERN_V2_H -#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_XCOMPONENT_XCOMPONENT_PATTERN_V2_H -#include "core/components_ng/pattern/xcomponent/xcomponent_pattern.h" -#include "core/components_ng/pattern/xcomponent/xcomponent_surface_holder.h" -#include "core/accessibility/native_interface_accessibility_provider.h" +#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_XCOMPONENT_XCOMPONENT_PROXY_SURFACE_HOLDER_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_XCOMPONENT_XCOMPONENT_PROXY_SURFACE_HOLDER_H + +#include "ui/base/ace_type.h" -namespace OHOS::Rosen { -class Session; -class RSNode; -class RSTransaction; -class RSTransactionHandler; -class RSUIContext; -} // namespace OHOS::Rosen +#include "core/accessibility/accessibility_manager.h" +#include "core/components_ng/pattern/xcomponent/xcomponent_proxy/xcomponent_proxy.h" +#include "core/components_ng/pattern/xcomponent/xcomponent_surface_holder.h" namespace OHOS::Ace::NG { -class XComponentPatternV2 : public XComponentPattern { - DECLARE_ACE_TYPE(XComponentPatternV2, XComponentPattern); -public: - XComponentPatternV2() = default; - XComponentPatternV2(XComponentType type, XComponentNodeType nodeType); - ~XComponentPatternV2() override = default; - void SetSurfaceHolder(OH_ArkUI_SurfaceHolder* surfaceHolder); - OH_ArkUI_SurfaceHolder* GetSurfaceHolder(); - int32_t Initialize(); - int32_t Finalize(); - int32_t SetAutoInitialize(bool autoInitialize); - int32_t IsInitialized(bool& isInitialized); +class FrameNode; +class XComponentProxySurfaceHolder : public XComponentProxy { + DECLARE_ACE_TYPE(XComponentProxySurfaceHolder, XComponentProxy); - bool IsCreateSurfaceHolderForbidden() +public: + explicit XComponentProxySurfaceHolder(const WeakPtr& pattern) : XComponentProxy(pattern) {} + ~XComponentProxySurfaceHolder() override = default; + static FrameNode* QueryAccessibilityProviderHost(void* provider, bool& isProviderValied); + void OnAttachToMainTree() override; + void OnDetachFromMainTree() override; + void OnSizeChange(bool offsetChanged, bool sizeChanged, bool frameOffsetChange, bool needFireNativeEvent) override; + bool NeedSoftKeyboard() override; + ArkUI_AccessibilityProvider* GetAccessibilityProvider() const override; + void DispatchSurfaceCreatedEvent(int32_t width, int32_t height, void* nativeWindow) override; + void DispatchSurfaceChangedEvent(int32_t width, int32_t height) override; + void DispatchSurfaceDestroyedEvent() override; + void DispatchSurfaceShowEvent() override; + // return true means need to release buffer + bool DispatchSurfaceHideEvent() override; + + void SetNeedSoftKeyboard(bool isNeedSoftKeyboard) { - return (hasGotNativeXComponent_ || usesSuperMethod_); + isNeedSoftKeyboard_ = isNeedSoftKeyboard; } - - XComponentNodeType GetXComponentNodeType() const + bool IsInitialized() const { - return nodeType_; + return isInitialized_; } - bool IsBindNative() override + OH_ArkUI_SurfaceHolder* GetSurfaceHolder() const { - return true; + return surfaceHolder_; } - - void SetExpectedRateRange(int32_t min, int32_t max, int32_t expected); - - void UpdateOnFrameEvent(void(*callback)(void*, uint64_t, uint64_t), void* arkuiNode); - - void UnregisterOnFrameEvent(); - - void SetNeedSoftKeyboard(bool isNeedSoftKeyboard); + void SetSurfaceHolder(OH_ArkUI_SurfaceHolder* surfaceHolder); + void SetNativeWindow(void* nativeWindow); + void SetAutoInitialize(bool autoInitialize); ArkUI_AccessibilityProvider* CreateAccessibilityProvider(); - void DisposeAccessibilityProvider(ArkUI_AccessibilityProvider* provider); - static FrameNode* QueryAccessibilityProviderHost(void* provider, bool& isProviderValied); - private: - void OnAttachToFrameNode() override; - void OnAttachToMainTree() override; - void BeforeSyncGeometryProperties(const DirtySwapConfig& config) override; - void OnDetachFromMainTree() override; - void OnDetachFromFrameNode(FrameNode* frameNode) override; - void OnWindowHide() override; - void OnWindowShow() override; - void OnRebuildFrame() override; - void OnModifyDone() override; - void DumpInfo() override; - - void InitSurface(); - void DisposeSurface(); - int32_t HandleSurfaceCreated(); - int32_t HandleSurfaceDestroyed(); - void InitializeRenderContext(); - std::pair UpdateSurfaceRect(); - void HandleSurfaceChangeEvent(bool offsetChanged, bool sizeChanged, bool frameOffsetChange); - void XComponentSizeChange(const RectF& surfaceRect); - void OnSurfaceChanged(const RectF& surfaceRect); - std::shared_ptr GetRSUIContext(const RefPtr& frameNode); - void FlushImplicitTransaction(const RefPtr& frameNode); - std::shared_ptr GetRSTransactionHandler(const RefPtr& frameNode); - - void OnSurfaceShow(); - void OnSurfaceHide(); - void ResetAndInitializeNodeHandleAccessibility(); - - void UpdateUsesSuperMethod() - { - if (usesSuperMethod_) { - return; - } - usesSuperMethod_ = (isCNode_ && !isLifecycleInterfaceCalled_ && !surfaceHolder_); - } - + OH_ArkUI_SurfaceHolder* surfaceHolder_ = nullptr; bool autoInitialize_ = true; bool isInitialized_ = false; - bool isLifecycleInterfaceCalled_ = false; - bool usesSuperMethod_ = false; - bool needNotifySizeChanged_ = false; - OH_ArkUI_SurfaceHolder* surfaceHolder_ = nullptr; - XComponentNodeType nodeType_ = XComponentNodeType::UNKNOWN; - Color bkColor_ = Color::BLACK; - + bool isNeedSoftKeyboard_ = false; + ArkUI_AccessibilityProvider* arkuiAccessibilityProvider_ = nullptr; static std::unordered_map> XComponentAccessibilityProviderMap; }; } // namespace OHOS::Ace::NG - -#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_XCOMPONENT_XCOMPONENT_PATTERN_V2_H +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_XCOMPONENT_XCOMPONENT_PROXY_SURFACE_HOLDER_H diff --git a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_surface_holder.h b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_surface_holder.h index ffff5a6b3acbd5b750ade81b5645339055cf908e..ec7b8529c691168a577e306d7c2a0b9aee12feff 100644 --- a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_surface_holder.h +++ b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_surface_holder.h @@ -19,6 +19,7 @@ #include #include #include "interfaces/native/native_interface_xcomponent.h" +#include "base/error/error_code.h" struct OH_ArkUI_SurfaceCallback { /** Called when the surface is created. */ diff --git a/frameworks/core/interfaces/native/node/node_xcomponent_modifier.cpp b/frameworks/core/interfaces/native/node/node_xcomponent_modifier.cpp index 949537c18d4074c0343ab885ef507a57cba07580..8ca65b4b6bb8562d43283dbaa46c89becd8663e1 100644 --- a/frameworks/core/interfaces/native/node/node_xcomponent_modifier.cpp +++ b/frameworks/core/interfaces/native/node/node_xcomponent_modifier.cpp @@ -16,7 +16,7 @@ #include "core/components_ng/pattern/xcomponent/xcomponent_model_ng.h" #include "core/components_ng/pattern/xcomponent/xcomponent_pattern.h" -#include "core/components_ng/pattern/xcomponent/xcomponent_pattern_v2.h" +// #include "core/components_ng/pattern/xcomponent/xcomponent_pattern_v2.h" #include "core/components_ng/base/view_abstract.h" namespace OHOS::Ace::NG { @@ -155,16 +155,17 @@ ArkUI_Uint32 GetXComponentSurfaceHeight(ArkUINodeHandle node) void* GetNativeXComponent(ArkUINodeHandle node) { - auto *frameNode = reinterpret_cast(node); + auto* frameNode = reinterpret_cast(node); CHECK_NULL_RETURN(frameNode, nullptr); auto xcPattern = frameNode->GetPattern(); CHECK_NULL_RETURN(xcPattern, nullptr); - if (xcPattern->HasGotSurfaceHolder() || xcPattern->IsNativeXComponentDisabled()) { - return nullptr; - } auto pair = xcPattern->GetNativeXComponent(); - xcPattern->SetHasGotNativeXComponent(true); - return reinterpret_cast(pair.second.lock().get()); + auto nativeXComponent = pair.second.lock(); + if (nativeXComponent) { + xcPattern->SetHasGotNativeXComponent(true); + return reinterpret_cast(nativeXComponent.get()); + } + return nullptr; } void SetXComponentLibraryname(ArkUINodeHandle node, const char* libraryname) @@ -354,9 +355,9 @@ void* CreateSurfaceHolder(ArkUINodeHandle node) { auto* frameNode = reinterpret_cast(node); CHECK_NULL_RETURN(frameNode, nullptr); - auto xcPattern = frameNode->GetPattern(); + auto xcPattern = frameNode->GetPattern(); CHECK_NULL_RETURN(xcPattern, nullptr); - if (xcPattern->IsCreateSurfaceHolderForbidden()) { + if (xcPattern->IsUsingNativeXComponent()) { return nullptr; } OH_ArkUI_SurfaceHolder* surfaceHolder = xcPattern->GetSurfaceHolder(); @@ -371,7 +372,7 @@ void Dispose(ArkUINodeHandle node) { auto* frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); - auto xcPattern = frameNode->GetPattern(); + auto xcPattern = frameNode->GetPattern(); CHECK_NULL_VOID(xcPattern); xcPattern->SetSurfaceHolder(nullptr); } @@ -380,7 +381,7 @@ ArkUI_Int32 SetAutoInitialize(ArkUINodeHandle node, ArkUI_Bool autoInitialize) { auto* frameNode = reinterpret_cast(node); CHECK_NULL_RETURN(frameNode, ERROR_CODE_PARAM_INVALID); - auto xcPattern = frameNode->GetPattern(); + auto xcPattern = frameNode->GetPattern(); CHECK_NULL_RETURN(xcPattern, ERROR_CODE_PARAM_INVALID); auto nodeType = xcPattern->GetXComponentNodeType(); if (nodeType != XComponentNodeType::TYPE_NODE && nodeType != XComponentNodeType::CNODE) { @@ -393,7 +394,7 @@ ArkUI_Int32 Initialize(ArkUINodeHandle node) { auto* frameNode = reinterpret_cast(node); CHECK_NULL_RETURN(frameNode, ERROR_CODE_PARAM_INVALID); - auto xcPattern = frameNode->GetPattern(); + auto xcPattern = frameNode->GetPattern(); CHECK_NULL_RETURN(xcPattern, ERROR_CODE_PARAM_INVALID); auto nodeType = xcPattern->GetXComponentNodeType(); if (nodeType != XComponentNodeType::TYPE_NODE && nodeType != XComponentNodeType::CNODE) { @@ -406,7 +407,7 @@ ArkUI_Int32 IsInitialized(ArkUINodeHandle node, ArkUI_Bool* isInitialized) { auto* frameNode = reinterpret_cast(node); CHECK_NULL_RETURN(frameNode, ERROR_CODE_PARAM_INVALID); - auto xcPattern = frameNode->GetPattern(); + auto xcPattern = frameNode->GetPattern(); CHECK_NULL_RETURN(xcPattern, ERROR_CODE_PARAM_INVALID); auto nodeType = xcPattern->GetXComponentNodeType(); if (nodeType != XComponentNodeType::TYPE_NODE && nodeType != XComponentNodeType::CNODE) { @@ -422,7 +423,7 @@ ArkUI_Int32 Finalize(ArkUINodeHandle node) { auto* frameNode = reinterpret_cast(node); CHECK_NULL_RETURN(frameNode, ERROR_CODE_PARAM_INVALID); - auto xcPattern = frameNode->GetPattern(); + auto xcPattern = frameNode->GetPattern(); CHECK_NULL_RETURN(xcPattern, ERROR_CODE_PARAM_INVALID); auto nodeType = xcPattern->GetXComponentNodeType(); if (nodeType != XComponentNodeType::TYPE_NODE && nodeType != XComponentNodeType::CNODE) { diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 51925a89af21f1f564efb203a617b8c3da667c88..fd0647133dca8e13f85742ee93ea52243234f15c 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -1468,7 +1468,9 @@ ohos_source_set("ace_components_pattern") { "$ace_root/frameworks/core/components_ng/pattern/xcomponent/xcomponent_model_ng.cpp", "$ace_root/frameworks/core/components_ng/pattern/xcomponent/xcomponent_paint_method.cpp", "$ace_root/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.cpp", - "$ace_root/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern_v2.cpp", + "$ace_root/frameworks/core/components_ng/pattern/xcomponent/xcomponent_proxy/xcomponent_proxy.cpp", + "$ace_root/frameworks/core/components_ng/pattern/xcomponent/xcomponent_proxy/xcomponent_proxy_native_xcomponent.cpp", + "$ace_root/frameworks/core/components_ng/pattern/xcomponent/xcomponent_proxy/xcomponent_proxy_surface_holder.cpp", "$ace_root/frameworks/core/components_ng/pattern/xcomponent/xcomponent_utils.cpp", "$ace_root/test/mock/core/pattern/mock_indexer_vibrator.cpp", "$ace_root/test/mock/core/pattern/mock_picker_haptic_factory.cpp", diff --git a/test/unittest/core/pattern/web/BUILD.gn b/test/unittest/core/pattern/web/BUILD.gn index 85fbef5288684839b49b034015d1734a8fea5cbe..86e49cf4388373c1b1e6c7b0e5883b6380e62a1d 100755 --- a/test/unittest/core/pattern/web/BUILD.gn +++ b/test/unittest/core/pattern/web/BUILD.gn @@ -631,7 +631,6 @@ ohos_unittest("web_pattern_unit_test_ohos") { "$ace_root/frameworks/core/components_ng/pattern/xcomponent/xcomponent_model_ng.cpp", "$ace_root/frameworks/core/components_ng/pattern/xcomponent/xcomponent_paint_method.cpp", "$ace_root/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.cpp", - "$ace_root/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern_v2.cpp", "$ace_root/test/mock/adapter/mock_ace_container.cpp", "$ace_root/test/mock/core/pattern/mock_indexer_vibrator.cpp", "$ace_root/test/mock/core/pattern/mock_picker_haptic_factory.cpp", diff --git a/test/unittest/core/pattern/xcomponent/BUILD.gn b/test/unittest/core/pattern/xcomponent/BUILD.gn index 0f6e48464cb59bd0b0962d255880a4dce33321b1..9ce23a789ed7557361516e5bfcf3d2e7ba2ca280 100644 --- a/test/unittest/core/pattern/xcomponent/BUILD.gn +++ b/test/unittest/core/pattern/xcomponent/BUILD.gn @@ -21,7 +21,6 @@ ace_unittest("xcomponent_test_ng") { "xcomponent_test_ng.cpp", "xcomponent_testtwo_ng.cpp", "xcomponent_utils_test_ng.cpp", - "xcomponent_v2_test_ng.cpp", ] external_deps = [ "bounds_checking_function:libsec_shared" ] diff --git a/test/unittest/core/pattern/xcomponent/xcomponent_property_test_ng.cpp b/test/unittest/core/pattern/xcomponent/xcomponent_property_test_ng.cpp index 2537afab6501d097a9f1b0fa114321447a1acb0b..f168c4df256451914a267fdaec8203226746bbe3 100644 --- a/test/unittest/core/pattern/xcomponent/xcomponent_property_test_ng.cpp +++ b/test/unittest/core/pattern/xcomponent/xcomponent_property_test_ng.cpp @@ -20,6 +20,7 @@ #include "gtest/gtest.h" #include "base/geometry/ng/size_t.h" +#include "core/components/common/layout/constants.h" #define private public #define protected public @@ -36,7 +37,6 @@ #include "core/components_ng/pattern/xcomponent/xcomponent_layout_algorithm.h" #include "core/components_ng/pattern/xcomponent/xcomponent_model_ng.h" #include "core/components_ng/pattern/xcomponent/xcomponent_pattern.h" -#include "core/components_ng/pattern/xcomponent/xcomponent_pattern_v2.h" #include "core/components_ng/pattern/xcomponent/xcomponent_surface_holder.h" #include "core/components_ng/property/measure_property.h" #include "core/components_v2/inspector/inspector_constants.h" @@ -507,10 +507,11 @@ HWTEST_F(XComponentPropertyTestNg, XComponentControllerSetExtControllerTest013, * case: pattern->GetType() != XComponentType::SURFACE * @tc.expected: result = XCOMPONENT_CONTROLLER_TYPE_ERROR */ - XComponentModelNG::SetXComponentType(Referenced::RawPtr(frameNode), XCOMPONENT_SURFACE_TYPE_VALUE); + XComponentModelNG::SetXComponentType(Referenced::RawPtr(frameNode), XComponentType::UNKNOWN); auto pattern = frameNode->GetPattern(); ASSERT_TRUE(pattern); pattern->OnAttachToFrameNode(); + pattern->InitParams(XCOMPONENT_ID, XCOMPONENT_NODE_TYPE_VALUE, XCOMPONENT_LIBRARY_NAME, xComponentController); XComponentModelNG::SetXComponentType(Referenced::RawPtr(frameNode), XCOMPONENT_TEXTURE_TYPE_VALUE); result = xComponentController->SetExtController(xComponentController); EXPECT_EQ(result, XCOMPONENT_CONTROLLER_TYPE_ERROR); @@ -520,8 +521,9 @@ HWTEST_F(XComponentPropertyTestNg, XComponentControllerSetExtControllerTest013, * case: !extPattern * @tc.expected: result = XCOMPONENT_CONTROLLER_BAD_PARAMETER */ - XComponentModelNG::SetXComponentType(Referenced::RawPtr(frameNode), XCOMPONENT_SURFACE_TYPE_VALUE); + XComponentModelNG::SetXComponentType(Referenced::RawPtr(frameNode), XComponentType::UNKNOWN); pattern->OnAttachToFrameNode(); + pattern->InitParams(XCOMPONENT_ID, XCOMPONENT_NODE_TYPE_VALUE, XCOMPONENT_LIBRARY_NAME, xComponentController); auto xComponentController2 = std::make_shared(); result = xComponentController->SetExtController(xComponentController2); EXPECT_EQ(result, XCOMPONENT_CONTROLLER_BAD_PARAMETER); @@ -575,11 +577,12 @@ HWTEST_F(XComponentPropertyTestNg, XComponentControllerResetExtControllerTest014 * case: pattern->GetType() != XComponentType::SURFACE * @tc.expected: result = XCOMPONENT_CONTROLLER_TYPE_ERROR */ - XComponentModelNG::SetXComponentType(Referenced::RawPtr(frameNode), XCOMPONENT_SURFACE_TYPE_VALUE); + XComponentModelNG::SetXComponentType(Referenced::RawPtr(frameNode), XComponentType::UNKNOWN); auto pattern = frameNode->GetPattern(); ASSERT_TRUE(pattern); pattern->OnAttachToFrameNode(); - XComponentModelNG::SetXComponentType(Referenced::RawPtr(frameNode), XCOMPONENT_TEXTURE_TYPE_VALUE); + pattern->InitParams(XCOMPONENT_ID, XCOMPONENT_SURFACE_TYPE_VALUE, XCOMPONENT_LIBRARY_NAME, xComponentController); + XComponentModelNG::SetXComponentType(Referenced::RawPtr(frameNode), XComponentType::UNKNOWN); result = xComponentController->ResetExtController(xComponentController); EXPECT_EQ(result, XCOMPONENT_CONTROLLER_TYPE_ERROR); @@ -588,8 +591,9 @@ HWTEST_F(XComponentPropertyTestNg, XComponentControllerResetExtControllerTest014 * case: !extPattern * @tc.expected: result = XCOMPONENT_CONTROLLER_BAD_PARAMETER */ - XComponentModelNG::SetXComponentType(Referenced::RawPtr(frameNode), XCOMPONENT_SURFACE_TYPE_VALUE); + XComponentModelNG::SetXComponentType(Referenced::RawPtr(frameNode), XComponentType::UNKNOWN); pattern->OnAttachToFrameNode(); + pattern->InitParams(XCOMPONENT_ID, XCOMPONENT_SURFACE_TYPE_VALUE, XCOMPONENT_LIBRARY_NAME, xComponentController); auto xComponentController2 = std::make_shared(); result = xComponentController->ResetExtController(xComponentController2); EXPECT_EQ(result, XCOMPONENT_CONTROLLER_BAD_PARAMETER); diff --git a/test/unittest/core/pattern/xcomponent/xcomponent_test_ng.cpp b/test/unittest/core/pattern/xcomponent/xcomponent_test_ng.cpp index c85ffc94df87cc7d7b6e33b64fff2d3990172f64..17decae57fce83813809de53d820a647d72d13e7 100644 --- a/test/unittest/core/pattern/xcomponent/xcomponent_test_ng.cpp +++ b/test/unittest/core/pattern/xcomponent/xcomponent_test_ng.cpp @@ -35,7 +35,6 @@ #include "core/components_ng/pattern/xcomponent/xcomponent_layout_algorithm.h" #include "core/components_ng/pattern/xcomponent/xcomponent_model_ng.h" #include "core/components_ng/pattern/xcomponent/xcomponent_pattern.h" -#include "core/components_ng/pattern/xcomponent/xcomponent_pattern_v2.h" #include "core/components_ng/pattern/xcomponent/xcomponent_surface_holder.h" #include "core/components_ng/pattern/xcomponent/xcomponent_inner_surface_controller.h" #include "core/components_ng/property/measure_property.h" @@ -1296,8 +1295,10 @@ HWTEST_F(XComponentTestNg, XComponentSourceTypeTest, TestSize.Level1) for (SourceType& sourceType : sourceTypes) { touchEventInfoSourceType.SetSourceDevice(sourceType); pattern->HandleTouchEvent(touchEventInfoSourceType); - EXPECT_EQ(pattern->nativeXComponentImpl_->curSourceType_.first, 0); - EXPECT_EQ(static_cast(pattern->nativeXComponentImpl_->curSourceType_.second), + auto xcomponentProxyNativeXComponent = AceType::DynamicCast(pattern->xcomponentProxy_); + EXPECT_TRUE(xcomponentProxyNativeXComponent); + EXPECT_EQ(xcomponentProxyNativeXComponent->nativeXComponentImpl_->curSourceType_.first, 0); + EXPECT_EQ(static_cast(xcomponentProxyNativeXComponent->nativeXComponentImpl_->curSourceType_.second), static_cast(ConvertNativeXComponentEventSourceType(sourceType))); } } @@ -1395,8 +1396,10 @@ HWTEST_F(XComponentTestNg, XComponentSurfaceLifeCycleCallback, TestSize.Level1) pattern->BeforeSyncGeometryProperties(config); EXPECT_STREQ(SURFACE_ID.c_str(), onSurfaceCreatedSurfaceId.c_str()); EXPECT_STREQ(SURFACE_ID.c_str(), onSurfaceChangedSurfaceId.c_str()); - EXPECT_FALSE(pattern->nativeXComponent_); - EXPECT_FALSE(pattern->nativeXComponentImpl_); + auto xcomponentProxyNativeXComponent = AceType::DynamicCast(pattern->xcomponentProxy_); + EXPECT_TRUE(xcomponentProxyNativeXComponent); + EXPECT_FALSE(xcomponentProxyNativeXComponent->nativeXComponent_); + EXPECT_FALSE(xcomponentProxyNativeXComponent->nativeXComponentImpl_); /** * @tc.steps: step3. call OnDetachFromFrameNode diff --git a/test/unittest/core/pattern/xcomponent/xcomponent_testtwo_ng.cpp b/test/unittest/core/pattern/xcomponent/xcomponent_testtwo_ng.cpp index 8fce1b2cfabb65200a91ac24141a4fde694b5e34..5d39b0d6787ee090eef66746f01a7735b868d8fd 100644 --- a/test/unittest/core/pattern/xcomponent/xcomponent_testtwo_ng.cpp +++ b/test/unittest/core/pattern/xcomponent/xcomponent_testtwo_ng.cpp @@ -38,7 +38,6 @@ #include "core/components_ng/pattern/xcomponent/xcomponent_layout_algorithm.h" #include "core/components_ng/pattern/xcomponent/xcomponent_model_ng.h" #include "core/components_ng/pattern/xcomponent/xcomponent_pattern.h" -#include "core/components_ng/pattern/xcomponent/xcomponent_pattern_v2.h" #include "core/components_ng/pattern/xcomponent/xcomponent_surface_holder.h" #include "core/components_ng/property/measure_property.h" #include "core/components_v2/inspector/inspector_constants.h" @@ -487,7 +486,7 @@ HWTEST_F(XComponentTestTwoNg, ChangeSurfaceCallbackModeTest, TestSize.Level1) ASSERT_TRUE(frameNode); auto pattern = frameNode->GetPattern(); ASSERT_TRUE(pattern); - pattern->isTypedNode_ = true; + pattern->nodeType_ = XComponentNodeType::TYPE_NODE; pattern->RegisterSurfaceCallbackModeEvent(); EXPECT_EQ(pattern->surfaceCallbackMode_, SurfaceCallbackMode::DEFAULT); @@ -766,10 +765,13 @@ HWTEST_F(XComponentTestTwoNg, NativeXComponentCallbackTest, TestSize.Level1) pattern->OnSurfaceCreated(); ASSERT_TRUE(hasSurfaceCreated); - pattern->OnSurfaceChanged(MAX_SURFACE_RECT, true); + pattern->OnSurfaceChanged(MAX_SURFACE_RECT); ASSERT_TRUE(hasSurfaceChanged); - pattern->NativeXComponentDispatchTouchEvent({}, {}); + // pattern->NativeXComponentDispatchTouchEvent({}, {}); + auto xcomponentProxyNativeXComponent = AceType::DynamicCast(pattern->xcomponentProxy_); + ASSERT_TRUE(xcomponentProxyNativeXComponent); + xcomponentProxyNativeXComponent->DispatchTouchEvent({}, {}, {}, {}); ASSERT_TRUE(hasDispatchTouchEvent); pattern->OnSurfaceDestroyed(); @@ -912,7 +914,7 @@ HWTEST_F(XComponentTestTwoNg, InitXComponentShouldCallInitNativeXComponentAndLoa ASSERT_TRUE(frameNode); auto pattern = frameNode->GetPattern(); ASSERT_TRUE(pattern); - pattern->isTypedNode_ = true; + pattern->nodeType_ = XComponentNodeType::TYPE_NODE; XComponentModelNG().InitXComponent(Referenced::RawPtr(frameNode)); EXPECT_EQ(pattern->isNativeXComponent_, true); @@ -932,7 +934,7 @@ HWTEST_F(XComponentTestTwoNg, InitXComponentShouldCallInitNativeXComponentTest, ASSERT_TRUE(frameNode); auto pattern = frameNode->GetPattern(); ASSERT_TRUE(pattern); - pattern->isTypedNode_ = true; + pattern->nodeType_ = XComponentNodeType::TYPE_NODE; XComponentModelNG().InitXComponent(Referenced::RawPtr(frameNode)); EXPECT_EQ(pattern->isNativeXComponent_, false); @@ -970,11 +972,11 @@ HWTEST_F(XComponentTestTwoNg, InitXComponentShouldCallInitAccessibilty, TestSize ASSERT_TRUE(frameNode); auto pattern = frameNode->GetPattern(); ASSERT_TRUE(pattern); - pattern->isTypedNode_ = true; + pattern->nodeType_ = XComponentNodeType::TYPE_NODE; XComponentModelNG().InitXComponent(Referenced::RawPtr(frameNode)); EXPECT_EQ(pattern->isNativeXComponent_, false); - EXPECT_NE(pattern->accessibilityChildTreeCallback_, nullptr); + EXPECT_NE(pattern->xcomponentProxy_->accessibilityChildTreeCallback_, nullptr); } /** @@ -991,11 +993,11 @@ HWTEST_F(XComponentTestTwoNg, InitializeNotCallInitAccessibilty, TestSize.Level1 ASSERT_TRUE(frameNode); auto pattern = frameNode->GetPattern(); ASSERT_TRUE(pattern); - pattern->isTypedNode_ = true; - pattern->accessibilityChildTreeCallback_ = nullptr; + pattern->nodeType_ = XComponentNodeType::TYPE_NODE; + pattern->xcomponentProxy_->accessibilityChildTreeCallback_ = nullptr; pattern->Initialize(); - EXPECT_EQ(pattern->accessibilityChildTreeCallback_, nullptr); + EXPECT_EQ(pattern->xcomponentProxy_->accessibilityChildTreeCallback_, nullptr); } /** @@ -1881,7 +1883,7 @@ HWTEST_F(XComponentTestTwoNg, SetHasGotNativeXComponentTest, TestSize.Level1) * @tc.steps2: Check Param hasGotNativeXComponent_'s value. * @tc.expected: Param hasGotNativeXComponent_ equals true. */ - pattern->SetHasGotNativeXComponent(true); - EXPECT_TRUE(pattern->hasGotNativeXComponent_); + // pattern->SetHasGotNativeXComponent(true); + // EXPECT_TRUE(pattern->hasGotNativeXComponent_); } } // namespace OHOS::Ace::NG diff --git a/test/unittest/core/pattern/xcomponent/xcomponent_v2_test_ng.cpp b/test/unittest/core/pattern/xcomponent/xcomponent_v2_test_ng.cpp index 270f6cd76918b1eb0326a54ab81642652ebf8ae2..002de5f2213d359765dcbb3ceb45a9ca659eb8fe 100644 --- a/test/unittest/core/pattern/xcomponent/xcomponent_v2_test_ng.cpp +++ b/test/unittest/core/pattern/xcomponent/xcomponent_v2_test_ng.cpp @@ -32,7 +32,6 @@ #include "core/components_ng/pattern/xcomponent/xcomponent_layout_algorithm.h" #include "core/components_ng/pattern/xcomponent/xcomponent_model_ng.h" #include "core/components_ng/pattern/xcomponent/xcomponent_pattern.h" -#include "core/components_ng/pattern/xcomponent/xcomponent_pattern_v2.h" #include "core/components_ng/pattern/xcomponent/xcomponent_surface_holder.h" #include "core/components_ng/property/measure_property.h"