1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_XCOMPONENT_XCOMPONENT_PATTERN_V2_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_XCOMPONENT_XCOMPONENT_PATTERN_V2_H 18 #include "core/components_ng/pattern/xcomponent/xcomponent_pattern.h" 19 #include "core/components_ng/pattern/xcomponent/xcomponent_surface_holder.h" 20 #include "core/accessibility/native_interface_accessibility_provider.h" 21 22 namespace OHOS::Rosen { 23 class Session; 24 class RSNode; 25 class RSTransaction; 26 class RSTransactionHandler; 27 class RSUIContext; 28 } // namespace OHOS::Rosen 29 30 namespace OHOS::Ace::NG { 31 class XComponentPatternV2 : public XComponentPattern { 32 DECLARE_ACE_TYPE(XComponentPatternV2, XComponentPattern); 33 public: 34 XComponentPatternV2() = default; 35 XComponentPatternV2(XComponentType type, XComponentNodeType nodeType); 36 ~XComponentPatternV2() override = default; 37 void SetSurfaceHolder(OH_ArkUI_SurfaceHolder* surfaceHolder); 38 OH_ArkUI_SurfaceHolder* GetSurfaceHolder(); 39 int32_t Initialize(); 40 int32_t Finalize(); 41 int32_t SetAutoInitialize(bool autoInitialize); 42 int32_t IsInitialized(bool& isInitialized); 43 IsCreateSurfaceHolderForbidden()44 bool IsCreateSurfaceHolderForbidden() 45 { 46 return (hasGotNativeXComponent_ || usesSuperMethod_); 47 } 48 GetXComponentNodeType()49 XComponentNodeType GetXComponentNodeType() const 50 { 51 return nodeType_; 52 } 53 IsBindNative()54 bool IsBindNative() override 55 { 56 return true; 57 } 58 59 void SetExpectedRateRange(int32_t min, int32_t max, int32_t expected); 60 61 void UpdateOnFrameEvent(void(*callback)(void*, uint64_t, uint64_t), void* arkuiNode); 62 63 void UnregisterOnFrameEvent(); 64 65 void SetNeedSoftKeyboard(bool isNeedSoftKeyboard); 66 67 ArkUI_AccessibilityProvider* CreateAccessibilityProvider(); 68 69 void DisposeAccessibilityProvider(ArkUI_AccessibilityProvider* provider); 70 71 static FrameNode* QueryAccessibilityProviderHost(void* provider, bool& isProviderValied); 72 73 private: 74 void OnAttachToFrameNode() override; 75 void OnAttachToMainTree() override; 76 void BeforeSyncGeometryProperties(const DirtySwapConfig& config) override; 77 void OnDetachFromMainTree() override; 78 void OnDetachFromFrameNode(FrameNode* frameNode) override; 79 void OnWindowHide() override; 80 void OnWindowShow() override; 81 void OnRebuildFrame() override; 82 void OnModifyDone() override; 83 void DumpInfo() override; 84 85 void InitSurfaceMultiThread(const RefPtr<FrameNode>& host); 86 void OnAttachToMainTreeMultiThread(const RefPtr<FrameNode>& host); 87 void RegisterContextEventMultiThread(const RefPtr<FrameNode>& host); 88 void OnDetachFromMainTreeMultiThread(const RefPtr<FrameNode>& host); 89 void OnDetachFromFrameNodeMultiThread(); 90 91 void InitSurface(); 92 void DisposeSurface(); 93 int32_t HandleSurfaceCreated(); 94 int32_t HandleSurfaceDestroyed(); 95 void InitializeRenderContext(); 96 std::pair<bool, bool> UpdateSurfaceRect(); 97 void HandleSurfaceChangeEvent(bool offsetChanged, bool sizeChanged, bool frameOffsetChange); 98 void XComponentSizeChange(const RectF& surfaceRect); 99 void OnSurfaceChanged(const RectF& surfaceRect); 100 std::shared_ptr<Rosen::RSUIContext> GetRSUIContext(const RefPtr<FrameNode>& frameNode); 101 void FlushImplicitTransaction(const RefPtr<FrameNode>& frameNode); 102 std::shared_ptr<Rosen::RSTransactionHandler> GetRSTransactionHandler(const RefPtr<FrameNode>& frameNode); 103 104 void OnSurfaceShow(); 105 void OnSurfaceHide(); 106 107 void ResetAndInitializeNodeHandleAccessibility(); 108 UpdateUsesSuperMethod()109 void UpdateUsesSuperMethod() 110 { 111 if (usesSuperMethod_) { 112 return; 113 } 114 usesSuperMethod_ = (isCNode_ && !isLifecycleInterfaceCalled_ && !surfaceHolder_); 115 } 116 117 bool autoInitialize_ = true; 118 bool isInitialized_ = false; 119 bool isLifecycleInterfaceCalled_ = false; 120 bool usesSuperMethod_ = false; 121 bool needNotifySizeChanged_ = false; 122 OH_ArkUI_SurfaceHolder* surfaceHolder_ = nullptr; 123 XComponentNodeType nodeType_ = XComponentNodeType::UNKNOWN; 124 Color bkColor_ = Color::BLACK; 125 126 static std::unordered_map<void*, WeakPtr<FrameNode>> XComponentAccessibilityProviderMap; 127 }; 128 } // namespace OHOS::Ace::NG 129 130 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_XCOMPONENT_XCOMPONENT_PATTERN_V2_H 131