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 102 // Only for the currently loaded children, do not expand. 103 void GetCurrentChildrenFocusHub(std::list<RefPtr<FocusHub>>& focusNodes); 104 105 void GetFocusChildren(std::list<RefPtr<FrameNode>>& children) const; 106 void Clean(bool cleanDirectly = false, bool allowTransition = false, int32_t branchId = -1); 107 void RemoveChildAtIndex(int32_t index); 108 RefPtr<UINode> GetChildAtIndex(int32_t index) const; 109 int32_t GetChildIndex(const RefPtr<UINode>& child) const; 110 [[deprecated]] void AttachToMainTree(bool recursive = false); 111 void AttachToMainTree(bool recursive, PipelineContext* context); 112 void DetachFromMainTree(bool recursive = false); 113 virtual void FireCustomDisappear(); 114 void UpdateConfigurationUpdate(const ConfigurationChange& configurationChange); OnConfigurationUpdate(const ConfigurationChange & configurationChange)115 virtual void OnConfigurationUpdate(const ConfigurationChange& configurationChange) {} 116 117 // process offscreen process. 118 void ProcessOffscreenTask(bool recursive = false); 119 UpdateModalUiextensionCount(bool addNode)120 void UpdateModalUiextensionCount(bool addNode) 121 { 122 if (addNode) { 123 modalUiextensionCount_++; 124 } else { 125 modalUiextensionCount_--; 126 } 127 } 128 129 int32_t TotalChildCount() const; 130 virtual void UpdateGeometryTransition(); 131 132 // Returns index in the flatten tree structure 133 // of the node with given id and type 134 // Returns std::pair with 135 // boolean first - indication of node is found 136 // int32_t second - index of the node 137 std::pair<bool, int32_t> GetChildFlatIndex(int32_t id); 138 139 virtual const std::list<RefPtr<UINode>>& GetChildren(bool notDetach = false) const 140 { 141 return children_; 142 } 143 GetLastChild()144 RefPtr<UINode> GetLastChild() 145 { 146 if (children_.empty()) { 147 return nullptr; 148 } 149 return children_.back(); 150 } 151 GetFirstChild()152 RefPtr<UINode> GetFirstChild() 153 { 154 if (children_.empty()) { 155 return nullptr; 156 } 157 return children_.front(); 158 } 159 160 void GenerateOneDepthVisibleFrame(std::list<RefPtr<FrameNode>>& visibleList); 161 void GenerateOneDepthVisibleFrameWithTransition(std::list<RefPtr<FrameNode>>& visibleList); 162 void GenerateOneDepthVisibleFrameWithOffset( 163 std::list<RefPtr<FrameNode>>& visibleList, OffsetF& offset); 164 void GenerateOneDepthAllFrame(std::list<RefPtr<FrameNode>>& visibleList); 165 166 int32_t GetChildIndexById(int32_t id); 167 GetParent()168 RefPtr<UINode> GetParent() const 169 { 170 return parent_.Upgrade(); 171 } 172 SetNeedCallChildrenUpdate(bool needCallChildrenUpdate)173 void SetNeedCallChildrenUpdate(bool needCallChildrenUpdate) 174 { 175 needCallChildrenUpdate_ = needCallChildrenUpdate; 176 } 177 SetParent(const WeakPtr<UINode> & parent)178 virtual void SetParent(const WeakPtr<UINode>& parent) 179 { 180 parent_ = parent; 181 } 182 // Tree operation end. 183 184 // performance. 185 PipelineContext* GetContext() const; 186 PipelineContext* GetAttachedContext() 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(const PointF& globalPoint, const PointF& parentLocalPoint, 313 const PointF& parentRevertPoint, TouchRestrict& touchRestrict, 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( 548 int32_t start, int32_t end, int32_t cacheStart, int32_t cacheEnd, bool showCache = false); DoSetActiveChildRange(const std::set<int32_t> & activeItems,const std::set<int32_t> & cachedItems,int32_t baseIndex)549 virtual void DoSetActiveChildRange( 550 const std::set<int32_t>& activeItems, const std::set<int32_t>& cachedItems, int32_t baseIndex) 551 {} 552 virtual void OnSetCacheCount(int32_t cacheCount, const std::optional<LayoutConstraintF>& itemConstraint); 553 554 // return value: true if the node can be removed immediately. 555 virtual bool OnRemoveFromParent(bool allowTransition); 556 MarkForceMeasure()557 void MarkForceMeasure() 558 { 559 MarkDirtyNode(PROPERTY_UPDATE_MEASURE); 560 for (const auto& child : children_) { 561 child->MarkForceMeasure(); 562 } 563 } 564 565 std::string GetCurrentCustomNodeInfo(); 566 static int64_t GenerateAccessibilityId(); 567 568 // used by BuilderNode 569 NodeStatus GetNodeStatus() const; 570 void UpdateNodeStatus(NodeStatus nodeStatus); 571 void SetIsRootBuilderNode(bool isRootBuilderNode); 572 bool GetIsRootBuilderNode() const; 573 IsArkTsFrameNode()574 bool IsArkTsFrameNode() const 575 { 576 return isArkTsFrameNode_; 577 } 578 SetIsArkTsFrameNode(bool isArkTsFrameNode)579 void SetIsArkTsFrameNode(bool isArkTsFrameNode) 580 { 581 isArkTsFrameNode_ = isArkTsFrameNode; 582 } 583 GetExportTextureInfo()584 const RefPtr<ExportTextureInfo>& GetExportTextureInfo() const 585 { 586 return exportTextureInfo_; 587 } 588 589 void CreateExportTextureInfoIfNeeded(); 590 591 bool IsNeedExportTexture() const; 592 593 virtual bool SetParentLayoutConstraint(const SizeF& size) const; 594 SetNodeIndexOffset(int32_t start,int32_t count)595 virtual void SetNodeIndexOffset(int32_t start, int32_t count) {} 596 IsLayoutSeperately()597 bool IsLayoutSeperately() const 598 { 599 return layoutSeperately_; 600 } 601 602 virtual void PaintDebugBoundaryTreeAll(bool flag); 603 static void DFSAllChild(const RefPtr<UINode>& root, std::vector<RefPtr<UINode>>& res); 604 static void GetBestBreakPoint(RefPtr<UINode>& breakPointChild, RefPtr<UINode>& breakPointParent); 605 SetAccessibilityNodeVirtual()606 void SetAccessibilityNodeVirtual() 607 { 608 isAccessibilityVirtualNode_ = true; 609 for (auto& it : GetChildren()) { 610 it->SetAccessibilityNodeVirtual(); 611 } 612 } 613 IsAccessibilityVirtualNode()614 bool IsAccessibilityVirtualNode() const 615 { 616 return isAccessibilityVirtualNode_; 617 } 618 SetAccessibilityVirtualNodeParent(const RefPtr<UINode> & parent)619 void SetAccessibilityVirtualNodeParent(const RefPtr<UINode>& parent) 620 { 621 parentForAccessibilityVirtualNode_ = parent; 622 for (auto& it : GetChildren()) { 623 it->SetAccessibilityVirtualNodeParent(parent); 624 } 625 } 626 GetVirtualNodeParent()627 WeakPtr<UINode> GetVirtualNodeParent() const 628 { 629 return parentForAccessibilityVirtualNode_; 630 } 631 IsFirstVirtualNode()632 bool IsFirstVirtualNode() const 633 { 634 return isFirstAccessibilityVirtualNode_; 635 } 636 SetFirstAccessibilityVirtualNode()637 void SetFirstAccessibilityVirtualNode() 638 { 639 isFirstAccessibilityVirtualNode_ = true; 640 } 641 SetRootNodeId(int32_t rootNodeId)642 void SetRootNodeId(int32_t rootNodeId) 643 { 644 rootNodeId_ = rootNodeId; 645 } 646 HasVirtualNodeAccessibilityProperty()647 virtual bool HasVirtualNodeAccessibilityProperty() 648 { 649 return false; 650 } 651 GetRootNodeId()652 int32_t GetRootNodeId() const 653 { 654 return rootNodeId_; 655 } 656 RootNodeIsPage()657 bool RootNodeIsPage() const 658 { 659 return rootNodeType_ == RootNodeType::PAGE_ETS_TAG; 660 } 661 SetRootNodeType(RootNodeType rootNodeType)662 void SetRootNodeType(RootNodeType rootNodeType) 663 { 664 rootNodeType_ = rootNodeType; 665 } 666 GetRootNodeType()667 RootNodeType GetRootNodeType() const 668 { 669 return rootNodeType_; 670 } 671 672 virtual void ClearSubtreeLayoutAlgorithm(bool includeSelf = true, bool clearEntireTree = false); 673 674 void GetPageNodeCountAndDepth(int32_t* count, int32_t* depth); 675 RegisterUpdateJSInstanceCallback(std::function<void (int32_t)> && callback)676 virtual void RegisterUpdateJSInstanceCallback(std::function<void(int32_t)>&& callback) 677 { 678 updateJSInstanceCallback_ = std::move(callback); 679 } 680 GetInstanceId()681 int32_t GetInstanceId() const 682 { 683 return instanceId_; 684 } 685 SetGeometryTransitionInRecursive(bool isGeometryTransitionIn)686 virtual void SetGeometryTransitionInRecursive(bool isGeometryTransitionIn) 687 { 688 for (const auto& child : GetChildren()) { 689 child->SetGeometryTransitionInRecursive(isGeometryTransitionIn); 690 } 691 } 692 SetOnNodeDestroyCallback(std::function<void (int32_t)> && destroyCallback)693 virtual void SetOnNodeDestroyCallback(std::function<void(int32_t)>&& destroyCallback) 694 { 695 destroyCallback_ = std::move(destroyCallback); 696 } 697 HasOnNodeDestroyCallback()698 virtual bool HasOnNodeDestroyCallback() 699 { 700 return destroyCallback_ != nullptr; 701 } 702 FireOnNodeDestroyCallback()703 virtual void FireOnNodeDestroyCallback() 704 { 705 CHECK_NULL_VOID(destroyCallback_); 706 destroyCallback_(GetId()); 707 } 708 SetBuilderFunc(std::function<void ()> && lazyBuilderFunc)709 void SetBuilderFunc(std::function<void()>&& lazyBuilderFunc) 710 { 711 lazyBuilderFunc_ = lazyBuilderFunc; 712 } 713 GetBuilderFunc()714 std::function<void()> GetBuilderFunc() const 715 { 716 return lazyBuilderFunc_; 717 } 718 SetUpdateNodeFunc(std::function<void (int32_t,RefPtr<UINode> &)> && updateNodeFunc)719 void SetUpdateNodeFunc(std::function<void(int32_t, RefPtr<UINode>&)>&& updateNodeFunc) 720 { 721 updateNodeFunc_ = updateNodeFunc; 722 } 723 GetUpdateNodeFunc()724 std::function<void(int32_t, RefPtr<UINode>&)> GetUpdateNodeFunc() 725 { 726 return updateNodeFunc_; 727 } 728 SetUpdateNodeConfig(std::function<void ()> && updateNodeConfig)729 void SetUpdateNodeConfig(std::function<void()>&& updateNodeConfig) 730 { 731 updateNodeConfig_ = updateNodeConfig; 732 } 733 GetUpdateNodeConfig()734 std::function<void()> GetUpdateNodeConfig() 735 { 736 return updateNodeConfig_; 737 } 738 AddFlag(uint32_t flag)739 void AddFlag(uint32_t flag) 740 { 741 nodeFlag_ |= flag; 742 } 743 IsNodeHasFlag(uint32_t flag)744 bool IsNodeHasFlag(uint32_t flag) const 745 { 746 return (flag & nodeFlag_) == flag; 747 } 748 749 virtual void GetInspectorValue(); 750 virtual void NotifyWebPattern(bool isRegister); 751 void GetContainerComponentText(std::string& text); 752 753 enum class NotificationType : int32_t { 754 START_CHANGE_POSITION = 0, 755 END_CHANGE_POSITION = 1, 756 START_AND_END_CHANGE_POSITION = 2 757 }; 758 /** 759 * @brief For a DataChange happened in child [id], notify the corresponding change position to parent. 760 * 761 * @param changeIdx change index in child [id]. 762 * @param count change of item count. 763 * @param id the accessibilityId of child who call this function. 764 * @param notificationType the type of notification. 765 */ 766 virtual void NotifyChange(int32_t changeIdx, int32_t count, int64_t id, NotificationType notificationType); 767 768 // Used to mark freeze and block dirty mark. 769 virtual void SetFreeze(bool isFreeze); IsFreeze()770 bool IsFreeze() const 771 { 772 return isFreeze_; 773 } 774 IsCNode()775 bool IsCNode() const 776 { 777 return isCNode_; 778 } 779 setIsCNode(bool createByCapi)780 void setIsCNode(bool createByCapi) 781 { 782 isCNode_ = createByCapi; 783 } 784 GetCurrentPageRootNode()785 virtual RefPtr<UINode> GetCurrentPageRootNode() 786 { 787 return nullptr; 788 } 789 AddCustomProperty(const std::string & key,const std::string & value)790 virtual void AddCustomProperty(const std::string& key, const std::string& value) {} RemoveCustomProperty(const std::string & key)791 virtual void RemoveCustomProperty(const std::string& key) {} 792 793 protected: ModifyChildren()794 std::list<RefPtr<UINode>>& ModifyChildren() 795 { 796 return children_; 797 } 798 OnGenerateOneDepthVisibleFrame(std::list<RefPtr<FrameNode>> & visibleList)799 virtual void OnGenerateOneDepthVisibleFrame(std::list<RefPtr<FrameNode>>& visibleList) 800 { 801 for (const auto& child : GetChildren()) { 802 child->OnGenerateOneDepthVisibleFrame(visibleList); 803 } 804 } 805 806 virtual void OnGenerateOneDepthVisibleFrameWithTransition(std::list<RefPtr<FrameNode>>& visibleList); 807 808 virtual void OnGenerateOneDepthVisibleFrameWithOffset( 809 std::list<RefPtr<FrameNode>>& visibleList, OffsetF& offset); 810 OnGenerateOneDepthAllFrame(std::list<RefPtr<FrameNode>> & allList)811 virtual void OnGenerateOneDepthAllFrame(std::list<RefPtr<FrameNode>>& allList) 812 { 813 for (const auto& child : GetChildren()) { 814 child->OnGenerateOneDepthAllFrame(allList); 815 } 816 } 817 AfterMountToParent()818 virtual void AfterMountToParent() {} OnContextAttached()819 virtual void OnContextAttached() {} 820 // dump self info. DumpInfo()821 virtual void DumpInfo() {} DumpSimplifyInfo(std::unique_ptr<JsonValue> & json)822 virtual void DumpSimplifyInfo(std::unique_ptr<JsonValue>& json) {} DumpAdvanceInfo()823 virtual void DumpAdvanceInfo() {} 824 virtual void DumpViewDataPageNode(RefPtr<ViewDataWrap> viewDataWrap, bool needsRecordData = false) {} CheckAutoSave()825 virtual bool CheckAutoSave() 826 { 827 return false; 828 } 829 // Mount to the main tree to display. 830 virtual void OnAttachToMainTree(bool recursive = false); 831 virtual void OnDetachFromMainTree(bool recursive = false, PipelineContext* context = nullptr); OnAttachToBuilderNode(NodeStatus nodeStatus)832 virtual void OnAttachToBuilderNode(NodeStatus nodeStatus) {} 833 OnFreezeStateChange()834 virtual void OnFreezeStateChange() {} 835 virtual void UpdateChildrenFreezeState(bool isFreeze); 836 837 // run offscreen process. OnOffscreenProcess(bool recursive)838 virtual void OnOffscreenProcess(bool recursive) {} 839 840 bool isRemoving_ = false; 841 842 virtual bool RemoveImmediately() const; 843 void ResetParent(); 844 static void RemoveFromParentCleanly(const RefPtr<UINode>& child, const RefPtr<UINode>& parent); 845 846 // update visible change signal to children 847 void UpdateChildrenVisible(VisibleType preVisibility, VisibleType currentVisibility) const; 848 849 void CollectRemovedChildren(const std::list<RefPtr<UINode>>& children, 850 std::list<int32_t>& removedElmtId, bool isEntry); 851 void CollectRemovedChild(const RefPtr<UINode>& child, std::list<int32_t>& removedElmtId); 852 853 bool needCallChildrenUpdate_ = true; 854 855 bool layoutSeperately_ = false; 856 PaintDebugBoundary(bool flag)857 virtual void PaintDebugBoundary(bool flag) {} 858 859 void TraversingCheck(RefPtr<UINode> node = nullptr, bool withAbort = false); 860 861 PipelineContext* context_ = nullptr; 862 863 /** 864 * @brief Transform the [changeIdx] given by child [id] to corresponding position in [this] node. 865 * 866 * @param changeIdx change index in child [id]. 867 * @param id the accessibilityId of child. 868 */ 869 int32_t CalcAbsPosition(int32_t changeIdx, int64_t id) const; 870 871 private: 872 void DoAddChild(std::list<RefPtr<UINode>>::iterator& it, const RefPtr<UINode>& child, bool silently = false, 873 bool addDefaultTransition = false); 874 875 std::list<RefPtr<UINode>> children_; 876 // disappearingChild、index、branchId 877 std::list<std::tuple<RefPtr<UINode>, uint32_t, int32_t>> disappearingChildren_; 878 std::unique_ptr<PerformanceCheckNode> nodeInfo_; 879 WeakPtr<UINode> parent_; 880 std::string tag_ = "UINode"; 881 int32_t depth_ = INT32_MAX; 882 int32_t hostRootId_ = 0; 883 int32_t hostPageId_ = 0; 884 int32_t nodeId_ = 0; 885 int64_t accessibilityId_ = -1; 886 int32_t layoutPriority_ = 0; 887 int32_t rootNodeId_ = 0; // host is Page or NavDestination 888 bool isRoot_ = false; 889 bool onMainTree_ = false; 890 bool removeSilently_ = true; 891 bool isInDestroying_ = false; 892 bool isDisappearing_ = false; 893 bool isBuildByJS_ = false; 894 bool isRootBuilderNode_ = false; 895 bool isArkTsFrameNode_ = false; 896 bool isTraversing_ = false; 897 NodeStatus nodeStatus_ = NodeStatus::NORMAL_NODE; 898 RootNodeType rootNodeType_ = RootNodeType::PAGE_ETS_TAG; 899 RefPtr<ExportTextureInfo> exportTextureInfo_; 900 901 uint32_t nodeFlag_ { 0 }; 902 903 int32_t restoreId_ = -1; 904 905 bool useOffscreenProcess_ = false; 906 907 bool isCNode_ = false; 908 909 std::function<void(int32_t)> updateJSInstanceCallback_; 910 std::function<void()> lazyBuilderFunc_; 911 std::function<void(int32_t, RefPtr<UINode>&)> updateNodeFunc_; 912 std::function<void()> updateNodeConfig_; 913 914 std::string debugLine_; 915 std::string viewId_; 916 int32_t instanceId_ = -1; 917 void* externalData_ = nullptr; 918 std::function<void(int32_t)> destroyCallback_; 919 // Other components cannot be masked above the modal uiextension, 920 // except for the modal uiextension 921 // Used to mark modal uiextension count below the root node 922 int32_t modalUiextensionCount_ = 0; 923 bool isAccessibilityVirtualNode_ = false; 924 WeakPtr<UINode> parentForAccessibilityVirtualNode_; 925 bool isFirstAccessibilityVirtualNode_ = false; 926 // the flag to block dirty mark. 927 bool isFreeze_ = false; 928 friend class RosenRenderContext; 929 ACE_DISALLOW_COPY_AND_MOVE(UINode); 930 }; 931 932 } // namespace OHOS::Ace::NG 933 934 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_BASE_UI_NODE_H 935