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