1 /* 2 * Copyright (c) 2022-2024 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_BASE_UI_NODE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_BASE_UI_NODE_H 18 19 #include <cstdint> 20 #include <list> 21 #include <memory> 22 #include <string> 23 #include <unordered_map> 24 25 #include "base/geometry/ng/point_t.h" 26 #include "base/geometry/ng/size_t.h" 27 #include "base/log/ace_performance_check.h" 28 #include "base/memory/ace_type.h" 29 #include "base/memory/referenced.h" 30 #include "base/utils/macros.h" 31 #include "base/view_data/view_data_wrap.h" 32 #include "core/common/resource/resource_configuration.h" 33 #include "core/components_ng/event/focus_hub.h" 34 #include "core/components_ng/event/gesture_event_hub.h" 35 #include "core/components_ng/export_texture_info/export_texture_info.h" 36 #include "core/components_ng/layout/layout_wrapper.h" 37 #include "core/components_ng/layout/layout_wrapper_node.h" 38 #include "core/components_ng/property/accessibility_property.h" 39 #include "core/event/touch_event.h" 40 41 namespace OHOS::Ace::NG { 42 class AccessibilityProperty; 43 44 struct ExtraInfo { 45 std::string page; 46 int32_t line = 0; 47 int32_t col = 0; 48 }; 49 50 enum class NodeStatus : char { 51 NORMAL_NODE = 0, // Indicates it is a normal node; 52 BUILDER_NODE_OFF_MAINTREE = 1, // Indicates it is a BuilderNode and is detach from the mainTree; 53 BUILDER_NODE_ON_MAINTREE = 2 // Indicates it is a BuilderNode and is attach to the mainTree; 54 }; 55 56 enum class RootNodeType : int32_t { 57 PAGE_ETS_TAG = 0, 58 NAVDESTINATION_VIEW_ETS_TAG = 1, 59 WINDOW_SCENE_ETS_TAG = 2 60 }; 61 62 class InspectorFilter; 63 class PipelineContext; 64 constexpr int32_t DEFAULT_NODE_SLOT = -1; 65 66 // UINode is the base class of FrameNode and SyntaxNode. 67 class ACE_FORCE_EXPORT UINode : public virtual AceType { 68 DECLARE_ACE_TYPE(UINode, AceType); 69 70 public: 71 UINode(const std::string& tag, int32_t nodeId, bool isRoot = false); 72 ~UINode() override; 73 74 // atomic node is like button, image, custom node and so on. 75 // In ets UI compiler, the atomic node does not Add Pop function, only have Create function. 76 virtual bool IsAtomicNode() const = 0; 77 78 virtual void AttachContext(PipelineContext* context, bool recursive = false); 79 virtual void DetachContext(bool recursive = false); 80 81 virtual int32_t FrameCount() const; 82 virtual int32_t CurrentFrameCount() const; 83 virtual RefPtr<LayoutWrapperNode> CreateLayoutWrapper(bool forceMeasure = false, bool forceLayout = false); 84 85 // Tree operation start. 86 virtual void AddChild(const RefPtr<UINode>& child, int32_t slot = DEFAULT_NODE_SLOT, bool silently = false, 87 bool addDefaultTransition = false, bool addModalUiextension = false); 88 void AddChildAfter(const RefPtr<UINode>& child, const RefPtr<UINode>& siblingNode); 89 void AddChildBefore(const RefPtr<UINode>& child, const RefPtr<UINode>& siblingNode); 90 91 std::list<RefPtr<UINode>>::iterator RemoveChild(const RefPtr<UINode>& child, bool allowTransition = false); 92 int32_t RemoveChildAndReturnIndex(const RefPtr<UINode>& child); 93 void ReplaceChild(const RefPtr<UINode>& oldNode, const RefPtr<UINode>& newNode); 94 void MovePosition(int32_t slot); 95 void MountToParent(const RefPtr<UINode>& parent, int32_t slot = DEFAULT_NODE_SLOT, bool silently = false, 96 bool addDefaultTransition = false, bool addModalUiextension = false); 97 RefPtr<FrameNode> GetParentFrameNode() const; 98 RefPtr<CustomNode> GetParentCustomNode() const; 99 RefPtr<FrameNode> GetFocusParent() const; 100 RefPtr<FocusHub> GetFirstFocusHubChild() const; 101 void GetChildrenFocusHub(std::list<RefPtr<FocusHub>>& focusNodes); 102 103 // Only for the currently loaded children, do not expand. 104 void GetCurrentChildrenFocusHub(std::list<RefPtr<FocusHub>>& focusNodes); 105 106 void GetFocusChildren(std::list<RefPtr<FrameNode>>& children) const; 107 void Clean(bool cleanDirectly = false, bool allowTransition = false, int32_t branchId = -1); 108 void RemoveChildAtIndex(int32_t index); 109 RefPtr<UINode> GetChildAtIndex(int32_t index) const; 110 int32_t GetChildIndex(const RefPtr<UINode>& child) const; 111 [[deprecated]] void AttachToMainTree(bool recursive = false); 112 void AttachToMainTree(bool recursive, PipelineContext* context); 113 void DetachFromMainTree(bool recursive = false); 114 virtual void FireCustomDisappear(); 115 void UpdateConfigurationUpdate(const ConfigurationChange& configurationChange); OnConfigurationUpdate(const ConfigurationChange & configurationChange)116 virtual void OnConfigurationUpdate(const ConfigurationChange& configurationChange) {} 117 118 // process offscreen process. 119 void ProcessOffscreenTask(bool recursive = false); 120 UpdateModalUiextensionCount(bool addNode)121 void UpdateModalUiextensionCount(bool addNode) 122 { 123 if (addNode) { 124 modalUiextensionCount_++; 125 } else { 126 modalUiextensionCount_--; 127 } 128 } 129 130 int32_t TotalChildCount() const; 131 virtual void UpdateGeometryTransition(); 132 133 // Returns index in the flatten tree structure 134 // of the node with given id and type 135 // Returns std::pair with 136 // boolean first - indication of node is found 137 // int32_t second - index of the node 138 std::pair<bool, int32_t> GetChildFlatIndex(int32_t id); 139 140 virtual const std::list<RefPtr<UINode>>& GetChildren(bool notDetach = false) const 141 { 142 return children_; 143 } 144 GetLastChild()145 RefPtr<UINode> GetLastChild() 146 { 147 if (children_.empty()) { 148 return nullptr; 149 } 150 return children_.back(); 151 } 152 GetFirstChild()153 RefPtr<UINode> GetFirstChild() 154 { 155 if (children_.empty()) { 156 return nullptr; 157 } 158 return children_.front(); 159 } 160 161 void GenerateOneDepthVisibleFrame(std::list<RefPtr<FrameNode>>& visibleList); 162 void GenerateOneDepthVisibleFrameWithTransition(std::list<RefPtr<FrameNode>>& visibleList); 163 void GenerateOneDepthVisibleFrameWithOffset( 164 std::list<RefPtr<FrameNode>>& visibleList, OffsetF& offset); 165 void GenerateOneDepthAllFrame(std::list<RefPtr<FrameNode>>& visibleList); 166 167 int32_t GetChildIndexById(int32_t id); 168 GetParent()169 RefPtr<UINode> GetParent() const 170 { 171 return parent_.Upgrade(); 172 } 173 SetNeedCallChildrenUpdate(bool needCallChildrenUpdate)174 void SetNeedCallChildrenUpdate(bool needCallChildrenUpdate) 175 { 176 needCallChildrenUpdate_ = needCallChildrenUpdate; 177 } 178 SetParent(const WeakPtr<UINode> & parent)179 virtual void SetParent(const WeakPtr<UINode>& parent) 180 { 181 parent_ = parent; 182 } 183 // Tree operation end. 184 185 // performance. 186 PipelineContext* GetContext() const; 187 PipelineContext* GetContextWithCheck(); 188 189 RefPtr<PipelineContext> GetContextRefPtr() const; 190 191 // When FrameNode creates a layout task, the corresponding LayoutWrapper tree is created, and UINode needs to update 192 // the corresponding LayoutWrapper tree node at this time like add self wrapper to wrapper tree. 193 virtual void AdjustLayoutWrapperTree(const RefPtr<LayoutWrapperNode>& parent, bool forceMeasure, bool forceLayout); 194 195 bool IsAutoFillContainerNode(); 196 void DumpViewDataPageNodes( 197 RefPtr<ViewDataWrap> viewDataWrap, bool skipSubAutoFillContainer = false, bool needsRecordData = false); 198 bool NeedRequestAutoSave(); 199 // DFX info. 200 void DumpTree(int32_t depth); 201 void DumpSimplifyTree(int32_t depth, std::unique_ptr<JsonValue>& current); 202 virtual bool IsContextTransparent(); 203 204 bool DumpTreeById(int32_t depth, const std::string& id); 205 GetTag()206 const std::string& GetTag() const 207 { 208 return tag_; 209 } 210 GetId()211 int32_t GetId() const 212 { 213 return nodeId_; 214 } 215 GetAccessibilityId()216 int64_t GetAccessibilityId() const 217 { 218 return accessibilityId_; 219 } 220 SetDepth(int32_t depth)221 void SetDepth(int32_t depth) 222 { 223 depth_ = depth; 224 for (auto& child : children_) { 225 child->SetDepth(depth_ + 1); 226 } 227 } 228 IsRootNode()229 bool IsRootNode() const 230 { 231 return isRoot_; 232 } 233 GetDepth()234 int32_t GetDepth() const 235 { 236 return depth_; 237 } 238 GetRootId()239 int32_t GetRootId() const 240 { 241 return hostRootId_; 242 } 243 GetPageId()244 int32_t GetPageId() const 245 { 246 return hostPageId_; 247 } 248 249 // TODO: SetHostRootId step on create node. SetHostRootId(int32_t id)250 void SetHostRootId(int32_t id) 251 { 252 hostRootId_ = id; 253 } 254 255 // TODO: SetHostPageId step on mount to page. SetHostPageId(int32_t id)256 void SetHostPageId(int32_t id) 257 { 258 hostPageId_ = id; 259 for (auto& child : children_) { 260 child->SetHostPageId(id); 261 } 262 } 263 SetRemoveSilently(bool removeSilently)264 void SetRemoveSilently(bool removeSilently) 265 { 266 removeSilently_ = removeSilently; 267 } 268 SetUndefinedNodeId()269 void SetUndefinedNodeId() 270 { 271 nodeId_ = -1; 272 } 273 IsRemoving()274 bool IsRemoving() const 275 { 276 return isRemoving_; 277 } 278 GetLayoutPriority()279 int32_t GetLayoutPriority() const 280 { 281 return layoutPriority_; 282 } 283 SetLayoutPriority(int32_t priority)284 void SetLayoutPriority(int32_t priority) 285 { 286 layoutPriority_ = priority; 287 } 288 SetInDestroying()289 void SetInDestroying() 290 { 291 isInDestroying_ = true; 292 } 293 IsInDestroying()294 bool IsInDestroying() const 295 { 296 return isInDestroying_; 297 } 298 299 void SetChildrenInDestroying(); 300 301 virtual HitTestResult TouchTest(const PointF& globalPoint, const PointF& parentLocalPoint, 302 const PointF& parentRevertPoint, TouchRestrict& touchRestrict, TouchTestResult& result, int32_t touchId, 303 ResponseLinkResult& responseLinkResult, bool isDispatch = false); GetHitTestMode()304 virtual HitTestMode GetHitTestMode() const 305 { 306 return HitTestMode::HTMDEFAULT; 307 } 308 309 virtual HitTestResult MouseTest(const PointF& globalPoint, const PointF& parentLocalPoint, 310 MouseTestResult& onMouseResult, MouseTestResult& onHoverResult, RefPtr<FrameNode>& hoverNode); 311 312 virtual HitTestResult AxisTest( 313 const PointF& globalPoint, const PointF& parentLocalPoint, AxisTestResult& onAxisResult); 314 315 // In the request to re-layout the scene, needs to obtain the changed state of the child node for the creation 316 // of parent's layout wrapper 317 virtual void UpdateLayoutPropertyFlag(); 318 ForceUpdateLayoutPropertyFlag(PropertyChangeFlag propertyChangeFlag)319 virtual void ForceUpdateLayoutPropertyFlag(PropertyChangeFlag propertyChangeFlag) {} 320 321 virtual void AdjustParentLayoutFlag(PropertyChangeFlag& flag); 322 323 virtual void MarkDirtyNode(PropertyChangeFlag extraFlag = PROPERTY_UPDATE_NORMAL); 324 325 virtual void MarkNeedFrameFlushDirty(PropertyChangeFlag extraFlag = PROPERTY_UPDATE_NORMAL); 326 FlushUpdateAndMarkDirty()327 virtual void FlushUpdateAndMarkDirty() 328 { 329 for (const auto& child : children_) { 330 child->FlushUpdateAndMarkDirty(); 331 } 332 } 333 334 virtual void MarkNeedSyncRenderTree(bool needRebuild = false); 335 336 virtual void RebuildRenderContextTree(); 337 OnWindowShow()338 virtual void OnWindowShow() {} 339 OnWindowHide()340 virtual void OnWindowHide() {} 341 virtual void Build(std::shared_ptr<std::list<ExtraInfo>> extraInfos); 342 343 virtual bool RenderCustomChild(int64_t deadline); 344 OnWindowFocused()345 virtual void OnWindowFocused() {} 346 OnWindowUnfocused()347 virtual void OnWindowUnfocused() {} 348 OnWindowSizeChanged(int32_t width,int32_t height,WindowSizeChangeReason type)349 virtual void OnWindowSizeChanged(int32_t width, int32_t height, WindowSizeChangeReason type) {} 350 OnNotifyMemoryLevel(int32_t level)351 virtual void OnNotifyMemoryLevel(int32_t level) {} 352 353 virtual void SetActive(bool active, bool needRebuildRenderContext = false); 354 355 virtual void SetJSViewActive(bool active, bool isLazyForEachNode = false); 356 357 virtual void TryVisibleChangeOnDescendant(VisibleType preVisibility, VisibleType currentVisibility); 358 359 // call by recycle framework. 360 virtual void OnRecycle(); 361 virtual void OnReuse(); 362 363 virtual bool MarkRemoving(); 364 IsOnMainTree()365 bool IsOnMainTree() const 366 { 367 return onMainTree_; 368 } 369 UseOffscreenProcess()370 bool UseOffscreenProcess() const 371 { 372 return useOffscreenProcess_; 373 } 374 ToJsonValue(std::unique_ptr<JsonValue> & json,const InspectorFilter & filter)375 virtual void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const {} 376 FromJson(const std::unique_ptr<JsonValue> & json)377 virtual void FromJson(const std::unique_ptr<JsonValue>& json) {} 378 379 ACE_DEFINE_PROPERTY_ITEM_FUNC_WITHOUT_GROUP(InspectorId, std::string); OnInspectorIdUpdate(const std::string &)380 virtual void OnInspectorIdUpdate(const std::string& /*unused*/) {} 381 382 ACE_DEFINE_PROPERTY_ITEM_FUNC_WITHOUT_GROUP(AutoEventParam, std::string); OnAutoEventParamUpdate(const std::string &)383 virtual void OnAutoEventParamUpdate(const std::string& /*unused*/) {} 384 385 template<typename T> FindChildNodeOfClass()386 RefPtr<T> FindChildNodeOfClass() 387 { 388 const auto& children = GetChildren(); 389 for (auto iter = children.rbegin(); iter != children.rend(); ++iter) { 390 auto& child = *iter; 391 392 auto target = child->FindChildNodeOfClass<T>(); 393 if (target) { 394 return target; 395 } 396 } 397 398 RefPtr<UINode> uiNode = AceType::Claim<UINode>(this); 399 if (AceType::InstanceOf<T>(uiNode)) { 400 return AceType::DynamicCast<T>(uiNode); 401 } 402 return nullptr; 403 } 404 405 // utility function for adding child to disappearingChildren_ 406 void AddDisappearingChild(const RefPtr<UINode>& child, uint32_t index = UINT32_MAX, int32_t branchId = -1); 407 // utility function for removing child from disappearingChildren_, return true if child is removed 408 bool RemoveDisappearingChild(const RefPtr<UINode>& child); 409 // return if we are in parent's disappearing children IsDisappearing()410 bool IsDisappearing() const 411 { 412 return isDisappearing_; 413 } 414 RefPtr<UINode> GetDisappearingChildById(const std::string& id, int32_t branchId) const; 415 416 // These two interfaces are only used for fast preview. 417 // FastPreviewUpdateChild: Replace the old child at the specified slot with the new created node. 418 // FastPreviewUpdateChildDone: the new created node performs some special operations. FastPreviewUpdateChild(int32_t slot,const RefPtr<UINode> & newChild)419 virtual void FastPreviewUpdateChild(int32_t slot, const RefPtr<UINode>& newChild) 420 { 421 RemoveChildAtIndex(slot); 422 newChild->MountToParent(AceType::Claim(this), slot, false); 423 } FastPreviewUpdateChildDone()424 virtual void FastPreviewUpdateChildDone() {} 425 virtual RefPtr<UINode> GetFrameChildByIndex(uint32_t index, bool needBuild, bool isCache = false, 426 bool addToRenderTree = false); 427 virtual RefPtr<UINode> GetFrameChildByIndexWithoutExpanded(uint32_t index); 428 // Get current frameNode index with or without expanded all LazyForEachNode; 429 virtual int32_t GetFrameNodeIndex(const RefPtr<FrameNode>& node, bool isExpanded = true); SetDebugLine(const std::string & line)430 void SetDebugLine(const std::string& line) 431 { 432 debugLine_ = line; 433 } GetDebugLine()434 std::string GetDebugLine() const 435 { 436 return debugLine_; 437 } 438 SetViewId(const std::string & viewId)439 void SetViewId(const std::string& viewId) 440 { 441 viewId_ = viewId; 442 } 443 GetViewId()444 std::string GetViewId() const 445 { 446 return viewId_; 447 } 448 SetRestoreId(int32_t restoreId)449 void SetRestoreId(int32_t restoreId) 450 { 451 restoreId_ = restoreId; 452 } 453 GetRestoreId()454 int32_t GetRestoreId() 455 { 456 return restoreId_; 457 } 458 UpdateRecycleElmtId(int32_t newElmtId)459 void UpdateRecycleElmtId(int32_t newElmtId) 460 { 461 nodeId_ = newElmtId; 462 } 463 464 // -------------------------------------------------------------------------------- 465 // performance check get child count, depth, flex layout times and layout time 466 void GetPerformanceCheckData(PerformanceCheckNodeMap& nodeMap); SetLayoutTime(int64_t time)467 void SetLayoutTime(int64_t time) 468 { 469 if (nodeInfo_) { 470 nodeInfo_->layoutTime = time; 471 } 472 } GetLayoutTime()473 int64_t GetLayoutTime() 474 { 475 if (nodeInfo_) { 476 return nodeInfo_->layoutTime; 477 } 478 return 0; 479 } GetFlexLayouts()480 int32_t GetFlexLayouts() 481 { 482 if (nodeInfo_) { 483 return nodeInfo_->flexLayouts; 484 } 485 return 0; 486 } GetRow()487 int32_t GetRow() const 488 { 489 if (nodeInfo_) { 490 return nodeInfo_->codeRow; 491 } 492 return 0; 493 } GetCol()494 int32_t GetCol() const 495 { 496 if (nodeInfo_) { 497 return nodeInfo_->codeCol; 498 } 499 return 0; 500 } SetRow(const int32_t row)501 void SetRow(const int32_t row) 502 { 503 if (nodeInfo_) { 504 nodeInfo_->codeRow = row; 505 } 506 } SetCol(const int32_t col)507 void SetCol(const int32_t col) 508 { 509 if (nodeInfo_) { 510 nodeInfo_->codeCol = col; 511 } 512 } SetForeachItem()513 void SetForeachItem() 514 { 515 if (nodeInfo_) { 516 nodeInfo_->isForEachItem = true; 517 } 518 } AddFlexLayouts()519 void AddFlexLayouts() 520 { 521 if (nodeInfo_) { 522 nodeInfo_->flexLayouts++; 523 } 524 } GetCustomTag()525 virtual std::string GetCustomTag() 526 { 527 return GetTag(); 528 } SetBuildByJs(bool isBuildByJS)529 void SetBuildByJs(bool isBuildByJS) 530 { 531 isBuildByJS_ = isBuildByJS; 532 } 533 GetExternalData()534 void* GetExternalData() const 535 { 536 return externalData_; 537 } 538 SetExternalData(void * externalData)539 void SetExternalData(void* externalData) 540 { 541 externalData_ = externalData; 542 } 543 544 // -------------------------------------------------------------------------------- 545 546 virtual void DoRemoveChildInRenderTree(uint32_t index, bool isAll = false); 547 virtual void DoSetActiveChildRange(int32_t start, int32_t end, int32_t cacheStart, int32_t cacheEnd); DoSetActiveChildRange(const std::set<int32_t> & activeItems,const std::set<int32_t> & cachedItems,int32_t baseIndex)548 virtual void DoSetActiveChildRange( 549 const std::set<int32_t>& activeItems, const std::set<int32_t>& cachedItems, int32_t baseIndex) 550 {} 551 virtual void OnSetCacheCount(int32_t cacheCount, const std::optional<LayoutConstraintF>& itemConstraint); 552 553 // return value: true if the node can be removed immediately. 554 virtual bool OnRemoveFromParent(bool allowTransition); 555 MarkForceMeasure()556 void MarkForceMeasure() 557 { 558 MarkDirtyNode(PROPERTY_UPDATE_MEASURE); 559 for (const auto& child : children_) { 560 child->MarkForceMeasure(); 561 } 562 } 563 564 std::string GetCurrentCustomNodeInfo(); 565 static int64_t GenerateAccessibilityId(); 566 567 // used by BuilderNode 568 NodeStatus GetNodeStatus() const; 569 void UpdateNodeStatus(NodeStatus nodeStatus); 570 void SetIsRootBuilderNode(bool isRootBuilderNode); 571 bool GetIsRootBuilderNode() const; 572 IsArkTsFrameNode()573 bool IsArkTsFrameNode() const 574 { 575 return isArkTsFrameNode_; 576 } 577 SetIsArkTsFrameNode(bool isArkTsFrameNode)578 void SetIsArkTsFrameNode(bool isArkTsFrameNode) 579 { 580 isArkTsFrameNode_ = isArkTsFrameNode; 581 } 582 GetExportTextureInfo()583 const RefPtr<ExportTextureInfo>& GetExportTextureInfo() const 584 { 585 return exportTextureInfo_; 586 } 587 588 void CreateExportTextureInfoIfNeeded(); 589 590 bool IsNeedExportTexture() const; 591 592 virtual bool SetParentLayoutConstraint(const SizeF& size) const; 593 SetNodeIndexOffset(int32_t start,int32_t count)594 virtual void SetNodeIndexOffset(int32_t start, int32_t count) {} 595 IsLayoutSeperately()596 bool IsLayoutSeperately() const 597 { 598 return layoutSeperately_; 599 } 600 601 virtual void PaintDebugBoundaryTreeAll(bool flag); 602 static void DFSAllChild(const RefPtr<UINode>& root, std::vector<RefPtr<UINode>>& res); 603 static void GetBestBreakPoint(RefPtr<UINode>& breakPointChild, RefPtr<UINode>& breakPointParent); 604 SetAccessibilityNodeVirtual()605 void SetAccessibilityNodeVirtual() 606 { 607 isAccessibilityVirtualNode_ = true; 608 for (auto& it : GetChildren()) { 609 it->SetAccessibilityNodeVirtual(); 610 } 611 } 612 IsAccessibilityVirtualNode()613 bool IsAccessibilityVirtualNode() const 614 { 615 return isAccessibilityVirtualNode_; 616 } 617 SetAccessibilityVirtualNodeParent(const RefPtr<UINode> & parent)618 void SetAccessibilityVirtualNodeParent(const RefPtr<UINode>& parent) 619 { 620 parentForAccessibilityVirtualNode_ = parent; 621 for (auto& it : GetChildren()) { 622 it->SetAccessibilityVirtualNodeParent(parent); 623 } 624 } 625 GetVirtualNodeParent()626 WeakPtr<UINode> GetVirtualNodeParent() const 627 { 628 return parentForAccessibilityVirtualNode_; 629 } 630 IsFirstVirtualNode()631 bool IsFirstVirtualNode() const 632 { 633 return isFirstAccessibilityVirtualNode_; 634 } 635 SetFirstAccessibilityVirtualNode()636 void SetFirstAccessibilityVirtualNode() 637 { 638 isFirstAccessibilityVirtualNode_ = true; 639 } 640 SetRootNodeId(int32_t rootNodeId)641 void SetRootNodeId(int32_t rootNodeId) 642 { 643 rootNodeId_ = rootNodeId; 644 } 645 HasVirtualNodeAccessibilityProperty()646 virtual bool HasVirtualNodeAccessibilityProperty() 647 { 648 return false; 649 } 650 GetRootNodeId()651 int32_t GetRootNodeId() const 652 { 653 return rootNodeId_; 654 } 655 RootNodeIsPage()656 bool RootNodeIsPage() const 657 { 658 return rootNodeType_ == RootNodeType::PAGE_ETS_TAG; 659 } 660 SetRootNodeType(RootNodeType rootNodeType)661 void SetRootNodeType(RootNodeType rootNodeType) 662 { 663 rootNodeType_ = rootNodeType; 664 } 665 GetRootNodeType()666 RootNodeType GetRootNodeType() const 667 { 668 return rootNodeType_; 669 } 670 671 virtual void ClearSubtreeLayoutAlgorithm(bool includeSelf = true, bool clearEntireTree = false); 672 673 void GetPageNodeCountAndDepth(int32_t* count, int32_t* depth); 674 RegisterUpdateJSInstanceCallback(std::function<void (int32_t)> && callback)675 virtual void RegisterUpdateJSInstanceCallback(std::function<void(int32_t)>&& callback) 676 { 677 updateJSInstanceCallback_ = std::move(callback); 678 } 679 GetInstanceId()680 int32_t GetInstanceId() const 681 { 682 return instanceId_; 683 } 684 SetGeometryTransitionInRecursive(bool isGeometryTransitionIn)685 virtual void SetGeometryTransitionInRecursive(bool isGeometryTransitionIn) 686 { 687 for (const auto& child : GetChildren()) { 688 child->SetGeometryTransitionInRecursive(isGeometryTransitionIn); 689 } 690 } 691 SetOnNodeDestroyCallback(std::function<void (int32_t)> && destroyCallback)692 virtual void SetOnNodeDestroyCallback(std::function<void(int32_t)>&& destroyCallback) 693 { 694 destroyCallback_ = std::move(destroyCallback); 695 } 696 HasOnNodeDestroyCallback()697 virtual bool HasOnNodeDestroyCallback() 698 { 699 return destroyCallback_ != nullptr; 700 } 701 FireOnNodeDestroyCallback()702 virtual void FireOnNodeDestroyCallback() 703 { 704 CHECK_NULL_VOID(destroyCallback_); 705 destroyCallback_(GetId()); 706 } 707 SetBuilderFunc(std::function<void ()> && lazyBuilderFunc)708 void SetBuilderFunc(std::function<void()>&& lazyBuilderFunc) 709 { 710 lazyBuilderFunc_ = lazyBuilderFunc; 711 } 712 GetBuilderFunc()713 std::function<void()> GetBuilderFunc() const 714 { 715 return lazyBuilderFunc_; 716 } 717 SetUpdateNodeFunc(std::function<void (int32_t,RefPtr<UINode> &)> && updateNodeFunc)718 void SetUpdateNodeFunc(std::function<void(int32_t, RefPtr<UINode>&)>&& updateNodeFunc) 719 { 720 updateNodeFunc_ = updateNodeFunc; 721 } 722 GetUpdateNodeFunc()723 std::function<void(int32_t, RefPtr<UINode>&)> GetUpdateNodeFunc() 724 { 725 return updateNodeFunc_; 726 } 727 SetUpdateNodeConfig(std::function<void ()> && updateNodeConfig)728 void SetUpdateNodeConfig(std::function<void()>&& updateNodeConfig) 729 { 730 updateNodeConfig_ = updateNodeConfig; 731 } 732 GetUpdateNodeConfig()733 std::function<void()> GetUpdateNodeConfig() 734 { 735 return updateNodeConfig_; 736 } 737 AddFlag(uint32_t flag)738 void AddFlag(uint32_t flag) 739 { 740 nodeFlag_ |= flag; 741 } 742 IsNodeHasFlag(uint32_t flag)743 bool IsNodeHasFlag(uint32_t flag) const 744 { 745 return (flag & nodeFlag_) == flag; 746 } 747 748 virtual void GetInspectorValue(); 749 virtual void NotifyWebPattern(bool isRegister); 750 void GetContainerComponentText(std::string& text); 751 752 enum class NotificationType : int32_t { 753 START_CHANGE_POSITION = 0, 754 END_CHANGE_POSITION = 1, 755 START_AND_END_CHANGE_POSITION = 2 756 }; 757 /** 758 * @brief For a DataChange happened in child [id], notify the corresponding change position to parent. 759 * 760 * @param changeIdx change index in child [id]. 761 * @param count change of item count. 762 * @param id the accessibilityId of child who call this function. 763 * @param notificationType the type of notification. 764 */ 765 virtual void NotifyChange(int32_t changeIdx, int32_t count, int64_t id, NotificationType notificationType); 766 767 // Used to mark freeze and block dirty mark. 768 virtual void SetFreeze(bool isFreeze); IsFreeze()769 bool IsFreeze() const 770 { 771 return isFreeze_; 772 } 773 IsCNode()774 bool IsCNode() const 775 { 776 return isCNode_; 777 } 778 setIsCNode(bool createByCapi)779 void setIsCNode(bool createByCapi) 780 { 781 isCNode_ = createByCapi; 782 } 783 784 protected: ModifyChildren()785 std::list<RefPtr<UINode>>& ModifyChildren() 786 { 787 return children_; 788 } 789 OnGenerateOneDepthVisibleFrame(std::list<RefPtr<FrameNode>> & visibleList)790 virtual void OnGenerateOneDepthVisibleFrame(std::list<RefPtr<FrameNode>>& visibleList) 791 { 792 for (const auto& child : GetChildren()) { 793 child->OnGenerateOneDepthVisibleFrame(visibleList); 794 } 795 } 796 797 virtual void OnGenerateOneDepthVisibleFrameWithTransition(std::list<RefPtr<FrameNode>>& visibleList); 798 799 virtual void OnGenerateOneDepthVisibleFrameWithOffset( 800 std::list<RefPtr<FrameNode>>& visibleList, OffsetF& offset); 801 OnGenerateOneDepthAllFrame(std::list<RefPtr<FrameNode>> & allList)802 virtual void OnGenerateOneDepthAllFrame(std::list<RefPtr<FrameNode>>& allList) 803 { 804 for (const auto& child : GetChildren()) { 805 child->OnGenerateOneDepthAllFrame(allList); 806 } 807 } 808 AfterMountToParent()809 virtual void AfterMountToParent() {} OnContextAttached()810 virtual void OnContextAttached() {} 811 // dump self info. DumpInfo()812 virtual void DumpInfo() {} DumpSimplifyInfo(std::unique_ptr<JsonValue> & json)813 virtual void DumpSimplifyInfo(std::unique_ptr<JsonValue>& json) {} DumpAdvanceInfo()814 virtual void DumpAdvanceInfo() {} 815 virtual void DumpViewDataPageNode(RefPtr<ViewDataWrap> viewDataWrap, bool needsRecordData = false) {} CheckAutoSave()816 virtual bool CheckAutoSave() 817 { 818 return false; 819 } 820 // Mount to the main tree to display. 821 virtual void OnAttachToMainTree(bool recursive = false); 822 virtual void OnDetachFromMainTree(bool recursive = false, PipelineContext* context = nullptr); OnAttachToBuilderNode(NodeStatus nodeStatus)823 virtual void OnAttachToBuilderNode(NodeStatus nodeStatus) {} 824 OnFreezeStateChange()825 virtual void OnFreezeStateChange() {} 826 virtual void UpdateChildrenFreezeState(bool isFreeze); 827 828 // run offscreen process. OnOffscreenProcess(bool recursive)829 virtual void OnOffscreenProcess(bool recursive) {} 830 831 bool isRemoving_ = false; 832 833 virtual bool RemoveImmediately() const; 834 void ResetParent(); 835 static void RemoveFromParentCleanly(const RefPtr<UINode>& child, const RefPtr<UINode>& parent); 836 837 // update visible change signal to children 838 void UpdateChildrenVisible(VisibleType preVisibility, VisibleType currentVisibility) const; 839 840 void CollectRemovedChildren(const std::list<RefPtr<UINode>>& children, 841 std::list<int32_t>& removedElmtId, bool isEntry); 842 void CollectRemovedChild(const RefPtr<UINode>& child, std::list<int32_t>& removedElmtId); 843 844 bool needCallChildrenUpdate_ = true; 845 846 bool layoutSeperately_ = false; 847 PaintDebugBoundary(bool flag)848 virtual void PaintDebugBoundary(bool flag) {} 849 850 void TraversingCheck(RefPtr<UINode> node = nullptr, bool withAbort = false); 851 852 PipelineContext* context_ = nullptr; 853 854 /** 855 * @brief Transform the [changeIdx] given by child [id] to corresponding position in [this] node. 856 * 857 * @param changeIdx change index in child [id]. 858 * @param id the accessibilityId of child. 859 */ 860 int32_t CalcAbsPosition(int32_t changeIdx, int64_t id) const; 861 862 private: 863 void DoAddChild(std::list<RefPtr<UINode>>::iterator& it, const RefPtr<UINode>& child, bool silently = false, 864 bool addDefaultTransition = false); 865 866 std::list<RefPtr<UINode>> children_; 867 // disappearingChild、index、branchId 868 std::list<std::tuple<RefPtr<UINode>, uint32_t, int32_t>> disappearingChildren_; 869 std::unique_ptr<PerformanceCheckNode> nodeInfo_; 870 WeakPtr<UINode> parent_; 871 std::string tag_ = "UINode"; 872 int32_t depth_ = INT32_MAX; 873 int32_t hostRootId_ = 0; 874 int32_t hostPageId_ = 0; 875 int32_t nodeId_ = 0; 876 int64_t accessibilityId_ = -1; 877 int32_t layoutPriority_ = 0; 878 int32_t rootNodeId_ = 0; // host is Page or NavDestination 879 bool isRoot_ = false; 880 bool onMainTree_ = false; 881 bool removeSilently_ = true; 882 bool isInDestroying_ = false; 883 bool isDisappearing_ = false; 884 bool isBuildByJS_ = false; 885 bool isRootBuilderNode_ = false; 886 bool isArkTsFrameNode_ = false; 887 bool isTraversing_ = false; 888 NodeStatus nodeStatus_ = NodeStatus::NORMAL_NODE; 889 RootNodeType rootNodeType_ = RootNodeType::PAGE_ETS_TAG; 890 RefPtr<ExportTextureInfo> exportTextureInfo_; 891 892 uint32_t nodeFlag_ { 0 }; 893 894 int32_t restoreId_ = -1; 895 896 bool useOffscreenProcess_ = false; 897 898 bool isCNode_ = false; 899 900 std::function<void(int32_t)> updateJSInstanceCallback_; 901 std::function<void()> lazyBuilderFunc_; 902 std::function<void(int32_t, RefPtr<UINode>&)> updateNodeFunc_; 903 std::function<void()> updateNodeConfig_; 904 905 std::string debugLine_; 906 std::string viewId_; 907 int32_t instanceId_ = -1; 908 void* externalData_ = nullptr; 909 std::function<void(int32_t)> destroyCallback_; 910 // Other components cannot be masked above the modal uiextension, 911 // except for the modal uiextension 912 // Used to mark modal uiextension count below the root node 913 int32_t modalUiextensionCount_ = 0; 914 bool isAccessibilityVirtualNode_ = false; 915 WeakPtr<UINode> parentForAccessibilityVirtualNode_; 916 bool isFirstAccessibilityVirtualNode_ = false; 917 // the flag to block dirty mark. 918 bool isFreeze_ = false; 919 friend class RosenRenderContext; 920 ACE_DISALLOW_COPY_AND_MOVE(UINode); 921 }; 922 923 } // namespace OHOS::Ace::NG 924 925 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_BASE_UI_NODE_H 926