• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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_FRAME_NODE_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_BASE_FRAME_NODE_H
18 
19 #include <functional>
20 #include <list>
21 #include <utility>
22 
23 #include "base/geometry/ng/offset_t.h"
24 #include "base/geometry/ng/point_t.h"
25 #include "base/geometry/ng/rect_t.h"
26 #include "base/memory/ace_type.h"
27 #include "base/memory/referenced.h"
28 #include "base/thread/cancelable_callback.h"
29 #include "base/thread/task_executor.h"
30 #include "base/utils/macros.h"
31 #include "base/utils/utils.h"
32 #include "core/accessibility/accessibility_utils.h"
33 #include "core/common/recorder/exposure_processor.h"
34 #include "core/common/resource/resource_configuration.h"
35 #include "core/components/common/layout/constants.h"
36 #include "core/components_ng/base/frame_scene_status.h"
37 #include "core/components_ng/base/geometry_node.h"
38 #include "core/components_ng/base/modifier.h"
39 #include "core/components_ng/base/ui_node.h"
40 #include "core/components_ng/event/event_hub.h"
41 #include "core/components_ng/event/focus_hub.h"
42 #include "core/components_ng/event/gesture_event_hub.h"
43 #include "core/components_ng/event/input_event_hub.h"
44 #include "core/components_ng/event/target_component.h"
45 #include "core/components_ng/layout/layout_property.h"
46 #include "core/components_ng/property/accessibility_property.h"
47 #include "core/components_ng/property/layout_constraint.h"
48 #include "core/components_ng/property/property.h"
49 #include "core/components_ng/render/paint_property.h"
50 #include "core/components_ng/render/paint_wrapper.h"
51 #include "core/components_ng/render/render_context.h"
52 #include "core/components_v2/inspector/inspector_constants.h"
53 #include "core/components_v2/inspector/inspector_node.h"
54 
55 namespace OHOS::Accessibility {
56 class AccessibilityElementInfo;
57 class AccessibilityEventInfo;
58 }
59 
60 namespace OHOS::Ace::NG {
61 class PipelineContext;
62 class Pattern;
63 class StateModifyTask;
64 class UITask;
65 class FramePorxy;
66 
67 // FrameNode will display rendering region in the screen.
68 class ACE_FORCE_EXPORT FrameNode : public UINode, public LayoutWrapper {
69     DECLARE_ACE_TYPE(FrameNode, UINode, LayoutWrapper);
70 
71 public:
72     // create a new child element with new element tree.
73     static RefPtr<FrameNode> CreateFrameNodeWithTree(
74         const std::string& tag, int32_t nodeId, const RefPtr<Pattern>& pattern);
75 
76     static RefPtr<FrameNode> GetOrCreateFrameNode(
77         const std::string& tag, int32_t nodeId, const std::function<RefPtr<Pattern>(void)>& patternCreator);
78 
79     // create a new element with new pattern.
80     static RefPtr<FrameNode> CreateFrameNode(
81         const std::string& tag, int32_t nodeId, const RefPtr<Pattern>& pattern, bool isRoot = false);
82 
83     // get element with nodeId from node map.
84     static RefPtr<FrameNode> GetFrameNode(const std::string& tag, int32_t nodeId);
85 
86     static void ProcessOffscreenNode(const RefPtr<FrameNode>& node);
87     // avoid use creator function, use CreateFrameNode
88     FrameNode(const std::string& tag, int32_t nodeId, const RefPtr<Pattern>& pattern, bool isRoot = false);
89 
90     ~FrameNode() override;
91 
FrameCount()92     int32_t FrameCount() const override
93     {
94         return 1;
95     }
96 
SetCheckboxFlag(const bool checkboxFlag)97     void SetCheckboxFlag(const bool checkboxFlag)
98     {
99         checkboxFlag_ = checkboxFlag;
100     }
101 
GetCheckboxFlag()102     bool GetCheckboxFlag() const
103     {
104         return checkboxFlag_;
105     }
106     void OnInspectorIdUpdate(const std::string& id) override;
107 
108     struct ZIndexComparator {
operatorZIndexComparator109         bool operator()(const WeakPtr<FrameNode>& weakLeft, const WeakPtr<FrameNode>& weakRight) const
110         {
111             auto left = weakLeft.Upgrade();
112             auto right = weakRight.Upgrade();
113             if (left && right) {
114                 return left->GetRenderContext()->GetZIndexValue(ZINDEX_DEFAULT_VALUE) <
115                        right->GetRenderContext()->GetZIndexValue(ZINDEX_DEFAULT_VALUE);
116             }
117             return false;
118         }
119     };
120 
GetFrameChildren()121     const std::multiset<WeakPtr<FrameNode>, ZIndexComparator>& GetFrameChildren() const
122     {
123         return frameChildren_;
124     }
125 
126     void InitializePatternAndContext();
127 
128     virtual void MarkModifyDone();
129 
130     void MarkDirtyNode(
131         PropertyChangeFlag extraFlag = PROPERTY_UPDATE_NORMAL, bool childExpansiveAndMark = false) override;
132 
133     void MarkDirtyNode(bool isMeasureBoundary, bool isRenderBoundary,
134         PropertyChangeFlag extraFlag = PROPERTY_UPDATE_NORMAL, bool childExpansiveAndMark = false);
135 
ProcessPropertyDiff()136     void ProcessPropertyDiff()
137     {
138         // TODO: modify done need to optimize.
139         MarkModifyDone();
140         MarkDirtyNode();
141     }
142 
143     void FlushUpdateAndMarkDirty() override;
144 
145     void MarkNeedFrameFlushDirty(PropertyChangeFlag extraFlag = PROPERTY_UPDATE_NORMAL) override
146     {
147         MarkDirtyNode(extraFlag);
148     }
149 
150     void OnMountToParentDone();
151 
152     void UpdateLayoutConstraint(const MeasureProperty& calcLayoutConstraint);
153 
154     RefPtr<LayoutWrapperNode> CreateLayoutWrapper(bool forceMeasure = false, bool forceLayout = false) override;
155 
156     RefPtr<LayoutWrapperNode> UpdateLayoutWrapper(
157         RefPtr<LayoutWrapperNode> layoutWrapper, bool forceMeasure = false, bool forceLayout = false);
158 
159     void CreateLayoutTask(bool forceUseMainThread = false);
160 
161     std::optional<UITask> CreateRenderTask(bool forceUseMainThread = false);
162 
163     void SwapDirtyLayoutWrapperOnMainThread(const RefPtr<LayoutWrapper>& dirty);
164 
165     // Clear the user callback.
166     void ClearUserOnAreaChange();
167 
168     void SetOnAreaChangeCallback(OnAreaChangedFunc&& callback);
169 
170     void TriggerOnAreaChangeCallback(uint64_t nanoTimestamp);
171 
172     void OnConfigurationUpdate(const ConfigurationChange& configurationChange) override;
173 
AddVisibleAreaUserCallback(double ratio,const VisibleCallbackInfo & callback)174     void AddVisibleAreaUserCallback(double ratio, const VisibleCallbackInfo& callback)
175     {
176         visibleAreaUserCallbacks_[ratio] = callback;
177     }
178 
ClearVisibleAreaUserCallback()179     void ClearVisibleAreaUserCallback()
180     {
181         visibleAreaUserCallbacks_.clear();
182     }
AddVisibleAreaInnerCallback(double ratio,const VisibleCallbackInfo & callback)183     void AddVisibleAreaInnerCallback(double ratio, const VisibleCallbackInfo& callback)
184     {
185         visibleAreaInnerCallbacks_[ratio] = callback;
186     }
187 
188     void TriggerVisibleAreaChangeCallback(bool forceDisappear = false);
189 
190     void SetGeometryNode(const RefPtr<GeometryNode>& node);
191 
GetRenderContext()192     const RefPtr<RenderContext>& GetRenderContext() const
193     {
194         return renderContext_;
195     }
196 
197     const RefPtr<Pattern>& GetPattern() const;
198 
199     template<typename T>
GetPattern()200     RefPtr<T> GetPattern() const
201     {
202         return DynamicCast<T>(pattern_);
203     }
204 
205     template<typename T>
GetAccessibilityProperty()206     RefPtr<T> GetAccessibilityProperty() const
207     {
208         return DynamicCast<T>(accessibilityProperty_);
209     }
210 
211     template<typename T>
GetLayoutProperty()212     RefPtr<T> GetLayoutProperty() const
213     {
214         return DynamicCast<T>(layoutProperty_);
215     }
216 
217     template<typename T>
GetPaintProperty()218     RefPtr<T> GetPaintProperty() const
219     {
220         return DynamicCast<T>(paintProperty_);
221     }
222 
223     template<typename T>
GetEventHub()224     RefPtr<T> GetEventHub() const
225     {
226         return DynamicCast<T>(eventHub_);
227     }
228 
GetOrCreateGestureEventHub()229     RefPtr<GestureEventHub> GetOrCreateGestureEventHub() const
230     {
231         return eventHub_->GetOrCreateGestureEventHub();
232     }
233 
GetOrCreateInputEventHub()234     RefPtr<InputEventHub> GetOrCreateInputEventHub() const
235     {
236         return eventHub_->GetOrCreateInputEventHub();
237     }
238 
239     RefPtr<FocusHub> GetOrCreateFocusHub() const;
240 
GetFocusHub()241     RefPtr<FocusHub> GetFocusHub() const
242     {
243         return eventHub_->GetFocusHub();
244     }
245 
GetFocusType()246     FocusType GetFocusType() const
247     {
248         FocusType type = FocusType::DISABLE;
249         auto focusHub = GetFocusHub();
250         if (focusHub) {
251             type = focusHub->GetFocusType();
252         }
253         return type;
254     }
255 
256     static void PostTask(std::function<void()>&& task, TaskExecutor::TaskType taskType = TaskExecutor::TaskType::UI);
257 
258     void AddJudgeToTargetComponent(RefPtr<TargetComponent>& targetComponent);
259 
260     // If return true, will prevent TouchTest Bubbling to parent and brother nodes.
261     HitTestResult TouchTest(const PointF& globalPoint, const PointF& parentLocalPoint, const PointF& parentRevertPoint,
262         TouchRestrict& touchRestrict, TouchTestResult& result, int32_t touchId, bool isDispatch = false) override;
263 
264     HitTestResult MouseTest(const PointF& globalPoint, const PointF& parentLocalPoint, MouseTestResult& onMouseResult,
265         MouseTestResult& onHoverResult, RefPtr<FrameNode>& hoverNode) override;
266 
267     HitTestResult AxisTest(
268         const PointF& globalPoint, const PointF& parentLocalPoint, AxisTestResult& onAxisResult) override;
269 
270     void CheckSecurityComponentStatus(std::vector<RectF>& rect);
271 
272     bool HaveSecurityComponent();
273 
274     bool IsSecurityComponent();
275 
276     void AnimateHoverEffect(bool isHovered) const;
277 
278     bool IsAtomicNode() const override;
279 
280     void MarkNeedSyncRenderTree(bool needRebuild = false) override;
281 
282     void RebuildRenderContextTree() override;
283 
IsVisible()284     bool IsVisible() const
285     {
286         return layoutProperty_->GetVisibility().value_or(VisibleType::VISIBLE) == VisibleType::VISIBLE;
287     }
288 
289     void ToJsonValue(std::unique_ptr<JsonValue>& json) const override;
290 
291     void FromJson(const std::unique_ptr<JsonValue>& json) override;
292 
293     RefPtr<FrameNode> GetAncestorNodeOfFrame(bool checkBoundary = false) const;
294 
GetNodeName()295     std::string& GetNodeName()
296     {
297         return nodeName_;
298     }
299 
SetNodeName(std::string & nodeName)300     void SetNodeName(std::string& nodeName)
301     {
302         nodeName_ = nodeName;
303     }
304 
305     void OnWindowShow() override;
306 
307     void OnWindowHide() override;
308 
309     void OnWindowFocused() override;
310 
311     void OnWindowUnfocused() override;
312 
313     void OnWindowSizeChanged(int32_t width, int32_t height, WindowSizeChangeReason type) override;
314 
315     void OnNotifyMemoryLevel(int32_t level) override;
316 
317     OffsetF GetOffsetRelativeToWindow() const;
318 
319     OffsetF GetTransformRelativeOffset() const;
320 
321     RectF GetTransformRectRelativeToWindow() const;
322 
323     OffsetF GetPaintRectOffset(bool excludeSelf = false) const;
324 
325     OffsetF GetPaintRectCenter() const;
326 
327     std::pair<OffsetF, bool> GetPaintRectGlobalOffsetWithTranslate(bool excludeSelf = false) const;
328 
329     OffsetF GetPaintRectOffsetToPage() const;
330 
331     RectF GetPaintRectWithTransform() const;
332 
333     VectorF GetTransformScale() const;
334 
335     void AdjustGridOffset();
336 
IsInternal()337     bool IsInternal() const
338     {
339         return isInternal_;
340     }
341 
SetInternal()342     void SetInternal()
343     {
344         isInternal_ = true;
345     }
346 
347     int32_t GetAllDepthChildrenCount();
348 
349     void OnAccessibilityEvent(
350         AccessibilityEventType eventType, WindowsContentChangeTypes windowsContentChangeType =
351                                               WindowsContentChangeTypes::CONTENT_CHANGE_TYPE_INVALID) const;
352 
353     void OnAccessibilityEvent(
354         AccessibilityEventType eventType, std::string beforeText, std::string latestContent) const;
355 
356     void MarkNeedRenderOnly();
357 
358     void OnDetachFromMainTree(bool recursive) override;
359     void OnAttachToMainTree(bool recursive) override;
360     void OnAttachToBuilderNode(NodeStatus nodeStatus) override;
361 
362     void OnVisibleChange(bool isVisible) override;
363 
PushDestroyCallback(std::function<void ()> && callback)364     void PushDestroyCallback(std::function<void()>&& callback)
365     {
366         destroyCallbacks_.emplace_back(callback);
367     }
368 
369     bool MarkRemoving() override;
370 
371     void AddHotZoneRect(const DimensionRect& hotZoneRect) const;
372     void RemoveLastHotZoneRect() const;
373 
374     virtual bool IsOutOfTouchTestRegion(const PointF& parentLocalPoint, int32_t sourceType);
375     bool CheckRectIntersect(const RectF& dest, std::vector<RectF>& origin);
376 
IsLayoutDirtyMarked()377     bool IsLayoutDirtyMarked() const
378     {
379         return isLayoutDirtyMarked_;
380     }
381 
SetLayoutDirtyMarked(bool marked)382     void SetLayoutDirtyMarked(bool marked)
383     {
384         isLayoutDirtyMarked_ = marked;
385     }
386 
HasPositionProp()387     bool HasPositionProp() const
388     {
389         CHECK_NULL_RETURN(renderContext_, false);
390         return renderContext_->HasPosition() || renderContext_->HasOffset() || renderContext_->HasAnchor();
391     }
392 
393     // The function is only used for fast preview.
FastPreviewUpdateChildDone()394     void FastPreviewUpdateChildDone() override
395     {
396         OnMountToParentDone();
397     }
398 
IsExclusiveEventForChild()399     bool IsExclusiveEventForChild() const
400     {
401         return exclusiveEventForChild_;
402     }
403 
SetExclusiveEventForChild(bool exclusiveEventForChild)404     void SetExclusiveEventForChild(bool exclusiveEventForChild)
405     {
406         exclusiveEventForChild_ = exclusiveEventForChild;
407     }
408 
SetDraggable(bool draggable)409     void SetDraggable(bool draggable)
410     {
411         draggable_ = draggable;
412         userSet_ = true;
413         customerSet_ = false;
414     }
415 
SetCustomerDraggable(bool draggable)416     void SetCustomerDraggable(bool draggable) {
417         draggable_ = draggable;
418         userSet_ = true;
419         customerSet_ = true;
420     }
421 
SetDragPreviewOptions(const DragPreviewOption & previewOption)422     void SetDragPreviewOptions(const DragPreviewOption& previewOption)
423     {
424         previewOption_ = previewOption;
425     }
426 
GetDragPreviewOption()427     DragPreviewOption GetDragPreviewOption() const
428     {
429         return previewOption_;
430     }
431 
SetBackgroundFunction(std::function<RefPtr<UINode> ()> && buildFunc)432     void SetBackgroundFunction(std::function<RefPtr<UINode>()>&& buildFunc)
433     {
434         builderFunc_ = std::move(buildFunc);
435         backgroundNode_ = nullptr;
436     }
437 
IsDraggable()438     bool IsDraggable() const
439     {
440         return draggable_;
441     }
442 
IsLayoutComplete()443     bool IsLayoutComplete() const
444     {
445         return isLayoutComplete_;
446     }
447 
IsUserSet()448     bool IsUserSet() const
449     {
450         return userSet_;
451     }
452 
IsCustomerSet()453     bool IsCustomerSet() const
454     {
455         return customerSet_;
456     }
457 
SetAllowDrop(const std::set<std::string> & allowDrop)458     void SetAllowDrop(const std::set<std::string>& allowDrop)
459     {
460         allowDrop_ = allowDrop;
461     }
462 
GetAllowDrop()463     const std::set<std::string>& GetAllowDrop() const
464     {
465         return allowDrop_;
466     }
467 
SetDragPreview(const NG::DragDropInfo & info)468     void SetDragPreview(const NG::DragDropInfo& info)
469     {
470         dragPreviewInfo_ = info;
471     }
472 
GetDragPreview()473     const DragDropInfo& GetDragPreview() const
474     {
475         return dragPreviewInfo_;
476     }
477 
SetOverlayNode(const RefPtr<FrameNode> & overlayNode)478     void SetOverlayNode(const RefPtr<FrameNode>& overlayNode)
479     {
480         overlayNode_ = overlayNode;
481     }
482 
GetOverlayNode()483     RefPtr<FrameNode> GetOverlayNode() const
484     {
485         return overlayNode_;
486     }
487 
488     RefPtr<FrameNode> FindChildByPosition(float x, float y);
489 
490     RefPtr<NodeAnimatablePropertyBase> GetAnimatablePropertyFloat(const std::string& propertyName) const;
491     static RefPtr<FrameNode> FindChildByName(const RefPtr<FrameNode>& parentNode, const std::string& nodeName);
492     void CreateAnimatablePropertyFloat(
493         const std::string& propertyName, float value, const std::function<void(float)>& onCallbackEvent,
494         const PropertyUnit& propertyType = PropertyUnit::UNKNOWN);
495     void DeleteAnimatablePropertyFloat(const std::string& propertyName);
496     void UpdateAnimatablePropertyFloat(const std::string& propertyName, float value);
497     void CreateAnimatableArithmeticProperty(const std::string& propertyName, RefPtr<CustomAnimatableArithmetic>& value,
498         std::function<void(const RefPtr<CustomAnimatableArithmetic>&)>& onCallbackEvent);
499     void UpdateAnimatableArithmeticProperty(const std::string& propertyName, RefPtr<CustomAnimatableArithmetic>& value);
500 
501     void SetHitTestMode(HitTestMode mode);
502     HitTestMode GetHitTestMode() const override;
503 
504     TouchResult GetOnChildTouchTestRet(const std::vector<TouchTestInfo>& touchInfo);
505     OnChildTouchTestFunc GetOnTouchTestFunc();
506     void CollectTouchInfos(
507         const PointF& globalPoint, const PointF& parentRevertPoint, std::vector<TouchTestInfo>& touchInfos);
508     RefPtr<FrameNode> GetDispatchFrameNode(const TouchResult& touchRes);
509 
510     std::string ProvideRestoreInfo();
511 
512     static std::vector<RefPtr<FrameNode>> GetNodesById(const std::unordered_set<int32_t>& set);
513 
514     double GetPreviewScaleVal() const;
515 
516     bool IsPreviewNeedScale() const;
517 
SetViewPort(RectF viewPort)518     void SetViewPort(RectF viewPort)
519     {
520         viewPort_ = viewPort;
521     }
522 
GetSelfViewPort()523     std::optional<RectF> GetSelfViewPort() const
524     {
525         return viewPort_;
526     }
527 
528     std::optional<RectF> GetViewPort() const;
529 
530     // Frame Rate Controller(FRC) decides FrameRateRange by scene, speed and scene status
531     // speed is measured by millimeter/second
532     void AddFRCSceneInfo(const std::string& scene, float speed, SceneStatus status);
533 
534     OffsetF GetParentGlobalOffsetDuringLayout() const;
OnSetCacheCount(int32_t cacheCount,const std::optional<LayoutConstraintF> & itemConstraint)535     void OnSetCacheCount(int32_t cacheCount, const std::optional<LayoutConstraintF>& itemConstraint) override {};
536 
537     // layoutwrapper function override
538     const RefPtr<LayoutAlgorithmWrapper>& GetLayoutAlgorithm(bool needReset = false) override;
539 
540     void Measure(const std::optional<LayoutConstraintF>& parentConstraint) override;
541 
542     // Called to perform layout children.
543     void Layout() override;
544 
GetTotalChildCount()545     int32_t GetTotalChildCount() const override
546     {
547         return UINode::TotalChildCount();
548     }
549 
GetGeometryNode()550     const RefPtr<GeometryNode>& GetGeometryNode() const override
551     {
552         return geometryNode_;
553     }
554 
SetLayoutProperty(const RefPtr<LayoutProperty> & layoutProperty)555     void SetLayoutProperty(const RefPtr<LayoutProperty>& layoutProperty)
556     {
557         layoutProperty_ = layoutProperty;
558         layoutProperty_->SetHost(WeakClaim(this));
559     }
560 
GetLayoutProperty()561     const RefPtr<LayoutProperty>& GetLayoutProperty() const override
562     {
563         return layoutProperty_;
564     }
565 
566     RefPtr<LayoutWrapper> GetOrCreateChildByIndex(uint32_t index, bool addToRenderTree = true) override;
567     RefPtr<LayoutWrapper> GetChildByIndex(uint32_t index) override;
568     const std::list<RefPtr<LayoutWrapper>>& GetAllChildrenWithBuild(bool addToRenderTree = true) override;
569     void RemoveChildInRenderTree(uint32_t index) override;
570     void RemoveAllChildInRenderTree() override;
571     void DoRemoveChildInRenderTree(uint32_t index, bool isAll) override;
572     void SetActiveChildRange(int32_t start, int32_t end) override;
573     void DoSetActiveChildRange(int32_t start, int32_t end) override;
GetHostTag()574     const std::string& GetHostTag() const override
575     {
576         return GetTag();
577     }
578 
579     bool SelfOrParentExpansive();
580     bool SelfExpansive();
581     bool ParentExpansive();
SetNeedRestoreSafeArea(bool needRestore)582     void SetNeedRestoreSafeArea(bool needRestore)
583     {
584         needRestoreSafeArea_ = needRestore;
585     }
NeedRestoreSafeArea()586     bool NeedRestoreSafeArea()
587     {
588         return needRestoreSafeArea_;
589     }
590 
IsActive()591     bool IsActive() const override
592     {
593         return isActive_;
594     }
595 
596     void SetActive(bool active = true) override;
597 
IsOutOfLayout()598     bool IsOutOfLayout() const override
599     {
600         return renderContext_->HasPosition();
601     }
602 
603     bool SkipMeasureContent() const override;
604     float GetBaselineDistance() const override;
605     void SetCacheCount(
606         int32_t cacheCount = 0, const std::optional<LayoutConstraintF>& itemConstraint = std::nullopt) override;
607 
608     void SyncGeometryNode(bool needSyncRsNode);
609     RefPtr<UINode> GetFrameChildByIndex(uint32_t index, bool needBuild) override;
610     bool CheckNeedForceMeasureAndLayout() override;
611 
612     bool SetParentLayoutConstraint(const SizeF& size) const override;
613     void ForceSyncGeometryNode();
614 
615     template<typename T>
FindFocusChildNodeOfClass()616     RefPtr<T> FindFocusChildNodeOfClass()
617     {
618         const auto& children = GetChildren();
619         for (auto iter = children.rbegin(); iter != children.rend(); ++iter) {
620             auto& child = *iter;
621             auto target = DynamicCast<FrameNode>(child->FindChildNodeOfClass<T>());
622             if (target) {
623                 auto focusEvent = target->eventHub_->GetFocusHub();
624                 if (focusEvent && focusEvent->IsCurrentFocus()) {
625                     return AceType::DynamicCast<T>(target);
626                 }
627             }
628         }
629 
630         if (AceType::InstanceOf<T>(this)) {
631             auto target = DynamicCast<FrameNode>(this);
632             if (target) {
633                 auto focusEvent = target->eventHub_->GetFocusHub();
634                 if (focusEvent && focusEvent->IsCurrentFocus()) {
635                     return Claim(AceType::DynamicCast<T>(this));
636                 }
637             }
638         }
639         return nullptr;
640     }
641 
642     virtual std::vector<RectF> GetResponseRegionList(const RectF& rect, int32_t sourceType);
643 
IsFirstBuilding()644     bool IsFirstBuilding() const
645     {
646         return isFirstBuilding_;
647     }
648 
MarkBuildDone()649     void MarkBuildDone()
650     {
651         isFirstBuilding_ = false;
652     }
653 
GetLocalMatrix()654     Matrix4 GetLocalMatrix() const
655     {
656         return localMat_;
657     }
658     OffsetF GetOffsetInScreen();
659     RefPtr<PixelMap> GetPixelMap();
660     RefPtr<FrameNode> GetPageNode();
661     RefPtr<FrameNode> GetNodeContainer();
662     void NotifyFillRequestSuccess(RefPtr<PageNodeInfoWrap> nodeWrap, AceAutoFillType autoFillType);
663     void NotifyFillRequestFailed(int32_t errCode);
664 
665     int32_t GetUiExtensionId();
666     int64_t WrapExtensionAbilityId(int64_t extensionOffset, int64_t abilityId);
667     void SearchExtensionElementInfoByAccessibilityIdNG(int64_t elementId, int32_t mode,
668         int64_t offset, std::list<Accessibility::AccessibilityElementInfo>& output);
669     void SearchElementInfosByTextNG(int64_t elementId, const std::string& text,
670         int64_t offset, std::list<Accessibility::AccessibilityElementInfo>& output);
671     void FindFocusedExtensionElementInfoNG(int64_t elementId, int32_t focusType,
672         int64_t offset, Accessibility::AccessibilityElementInfo& output);
673     void FocusMoveSearchNG(int64_t elementId, int32_t direction,
674         int64_t offset, Accessibility::AccessibilityElementInfo& output);
675     bool TransferExecuteAction(int64_t elementId, const std::map<std::string, std::string>& actionArguments,
676         int32_t action, int64_t offset);
677     std::vector<RectF> GetResponseRegionListForRecognizer(int32_t sourceType);
678     bool InResponseRegionList(const PointF& parentLocalPoint, const std::vector<RectF>& responseRegionList) const;
679 
680     bool GetMonopolizeEvents() const;
681 
IsWindowBoundary()682     bool IsWindowBoundary() const
683     {
684         return isWindowBoundary_;
685     }
686 
687     void SetWindowBoundary(bool isWindowBoundary = true)
688     {
689         isWindowBoundary_ = isWindowBoundary;
690     }
691 
692     void InitLastArea();
693 
694     OffsetF CalculateCachedTransformRelativeOffset(uint64_t nanoTimestamp);
695 
696 private:
697     void MarkNeedRender(bool isRenderBoundary);
698     std::pair<float, float> ContextPositionConvertToPX(
699         const RefPtr<RenderContext>& context, const SizeF& percentReference) const;
700     bool IsNeedRequestParentMeasure() const;
701     void UpdateLayoutPropertyFlag() override;
702     void ForceUpdateLayoutPropertyFlag(PropertyChangeFlag propertyChangeFlag) override;
703     void AdjustParentLayoutFlag(PropertyChangeFlag& flag) override;
704 
705     void UpdateChildrenLayoutWrapper(const RefPtr<LayoutWrapperNode>& self, bool forceMeasure, bool forceLayout);
706     void AdjustLayoutWrapperTree(const RefPtr<LayoutWrapperNode>& parent, bool forceMeasure, bool forceLayout) override;
707 
708     LayoutConstraintF GetLayoutConstraint() const;
709     OffsetF GetParentGlobalOffset() const;
710 
711     RefPtr<PaintWrapper> CreatePaintWrapper();
712     void LayoutOverlay();
713 
714     void OnGenerateOneDepthVisibleFrame(std::list<RefPtr<FrameNode>>& visibleList) override;
715     void OnGenerateOneDepthVisibleFrameWithTransition(std::list<RefPtr<FrameNode>>& visibleList) override;
716     void OnGenerateOneDepthAllFrame(std::list<RefPtr<FrameNode>>& allList) override;
717 
718     bool IsMeasureBoundary();
719     bool IsRenderBoundary();
720 
721     bool OnRemoveFromParent(bool allowTransition) override;
722     bool RemoveImmediately() const override;
723 
724     // dump self info.
725     void DumpInfo() override;
726     void DumpOverlayInfo();
727     void DumpCommonInfo();
728     void DumpAdvanceInfo() override;
729     void DumpViewDataPageNode(RefPtr<ViewDataWrap> viewDataWrap) override;
730     bool CheckAutoSave() override;
731     void FocusToJsonValue(std::unique_ptr<JsonValue>& json) const;
732     void MouseToJsonValue(std::unique_ptr<JsonValue>& json) const;
733     void TouchToJsonValue(std::unique_ptr<JsonValue>& json) const;
734     void GeometryNodeToJsonValue(std::unique_ptr<JsonValue>& json) const;
735 
736     bool GetTouchable() const;
737     bool OnLayoutFinish(bool& needSyncRsNode);
738 
739     void ProcessAllVisibleCallback(
740         std::unordered_map<double, VisibleCallbackInfo>& visibleAreaCallbacks, double currentVisibleRatio);
741     void OnVisibleAreaChangeCallback(
742         std::unordered_map<double, VisibleCallbackInfo>& visibleAreaCallbacks,
743         bool visibleType, double currentVisibleRatio, bool isHandled);
744 
745     void OnPixelRoundFinish(const SizeF& pixelGridRoundSize);
746 
747     double CalculateCurrentVisibleRatio(const RectF& visibleRect, const RectF& renderRect);
748 
749     // set costom background layoutConstraint
750     void SetBackgroundLayoutConstraint(const RefPtr<FrameNode>& customNode);
751 
752     void GetPercentSensitive();
753     void UpdatePercentSensitive();
754 
755     void AddFrameNodeSnapshot(bool isHit, int32_t parentId, std::vector<RectF> responseRegionList);
756 
757     int32_t GetNodeExpectedRate();
758 
759     void RecordExposureIfNeed(const std::string& inspectorId);
760 
761     OffsetF CalculateOffsetRelativeToWindow(uint64_t nanoTimestamp);
762 
763     const std::pair<uint64_t, OffsetF>& GetCachedGlobalOffset() const;
764 
765     void SetCachedGlobalOffset(const std::pair<uint64_t, OffsetF>& timestampOffset);
766 
767     const std::pair<uint64_t, OffsetF>& GetCachedTransformRelativeOffset() const;
768 
769     void SetCachedTransformRelativeOffset(const std::pair<uint64_t, OffsetF>& timestampOffset);
770 
771     // sort in ZIndex.
772     std::multiset<WeakPtr<FrameNode>, ZIndexComparator> frameChildren_;
773     RefPtr<GeometryNode> geometryNode_ = MakeRefPtr<GeometryNode>();
774 
775     std::list<std::function<void()>> destroyCallbacks_;
776     std::unordered_map<double, VisibleCallbackInfo> visibleAreaUserCallbacks_;
777     std::unordered_map<double, VisibleCallbackInfo> visibleAreaInnerCallbacks_;
778 
779     RefPtr<AccessibilityProperty> accessibilityProperty_;
780     RefPtr<LayoutProperty> layoutProperty_;
781     RefPtr<PaintProperty> paintProperty_;
782     RefPtr<RenderContext> renderContext_ = RenderContext::Create();
783     RefPtr<EventHub> eventHub_;
784     RefPtr<Pattern> pattern_;
785 
786     RefPtr<FrameNode> backgroundNode_;
787     std::function<RefPtr<UINode>()> builderFunc_;
788     std::unique_ptr<RectF> lastFrameRect_;
789     std::unique_ptr<OffsetF> lastParentOffsetToWindow_;
790     std::set<std::string> allowDrop_;
791     std::optional<RectF> viewPort_;
792     NG::DragDropInfo dragPreviewInfo_;
793 
794     RefPtr<LayoutAlgorithmWrapper> layoutAlgorithm_;
795     RefPtr<GeometryNode> oldGeometryNode_;
796     std::optional<bool> skipMeasureContent_;
797     std::unique_ptr<FramePorxy> frameProxy_;
798     WeakPtr<TargetComponent> targetComponent_;
799 
800     bool needSyncRenderTree_ = false;
801 
802     bool isPropertyDiffMarked_ = false;
803     bool isLayoutDirtyMarked_ = false;
804     bool isRenderDirtyMarked_ = false;
805     bool isMeasureBoundary_ = false;
806     bool hasPendingRequest_ = false;
807 
808     // for container, this flag controls only the last child in touch area is consuming event.
809     bool exclusiveEventForChild_ = false;
810     bool isActive_ = false;
811     bool isResponseRegion_ = false;
812     bool bypass_ = false;
813     bool isLayoutComplete_ = false;
814     bool isFirstBuilding_ = true;
815 
816     double lastVisibleRatio_ = 0.0;
817 
818     // internal node such as Text in Button CreateWithLabel
819     // should not seen by preview inspector or accessibility
820     bool isInternal_ = false;
821 
822     std::string nodeName_;
823 
824     bool draggable_ = false;
825     bool userSet_ = false;
826     bool customerSet_ = false;
827     bool isWindowBoundary_ = false;
828 
829     std::map<std::string, RefPtr<NodeAnimatablePropertyBase>> nodeAnimatablePropertyMap_;
830     Matrix4 localMat_ = Matrix4::CreateIdentity();
831 
832     bool isRestoreInfoUsed_ = false;
833     bool checkboxFlag_ = false;
834     bool needRestoreSafeArea_ = true;
835 
836     RefPtr<FrameNode> overlayNode_;
837 
838     std::unordered_map<std::string, int32_t> sceneRateMap_;
839 
840     DragPreviewOption previewOption_ { DragPreviewMode::AUTO };
841 
842     RefPtr<Recorder::ExposureProcessor> exposureProcessor_;
843 
844     std::pair<uint64_t, OffsetF> cachedGlobalOffset_ = { 0, OffsetF() };
845     std::pair<uint64_t, OffsetF> cachedTransformRelativeOffset_ = { 0, OffsetF() };
846 
847     friend class RosenRenderContext;
848     friend class RenderContext;
849     friend class Pattern;
850 
851     ACE_DISALLOW_COPY_AND_MOVE(FrameNode);
852 
853 };
854 } // namespace OHOS::Ace::NG
855 
856 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_BASE_FRAME_NODE_H
857