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_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 #include <mutex> 23 24 #include "base/geometry/ng/offset_t.h" 25 #include "base/geometry/ng/point_t.h" 26 #include "base/geometry/ng/rect_t.h" 27 #include "base/geometry/ng/vector.h" 28 #include "base/memory/ace_type.h" 29 #include "base/memory/referenced.h" 30 #include "base/thread/cancelable_callback.h" 31 #include "base/thread/task_executor.h" 32 #include "base/utils/macros.h" 33 #include "base/utils/utils.h" 34 #include "core/accessibility/accessibility_utils.h" 35 #include "core/common/recorder/exposure_processor.h" 36 #include "core/common/resource/resource_configuration.h" 37 #include "core/components/common/layout/constants.h" 38 #include "core/components_ng/base/extension_handler.h" 39 #include "core/components_ng/base/frame_scene_status.h" 40 #include "core/components_ng/base/geometry_node.h" 41 #include "core/components_ng/base/modifier.h" 42 #include "core/components_ng/base/ui_node.h" 43 #include "core/components_ng/event/event_hub.h" 44 #include "core/components_ng/event/focus_hub.h" 45 #include "core/components_ng/event/gesture_event_hub.h" 46 #include "core/components_ng/event/input_event_hub.h" 47 #include "core/components_ng/event/target_component.h" 48 #include "core/components_ng/layout/layout_property.h" 49 #include "core/components_ng/property/accessibility_property.h" 50 #include "core/components_ng/property/flex_property.h" 51 #include "core/components_ng/property/layout_constraint.h" 52 #include "core/components_ng/property/property.h" 53 #include "core/components_ng/render/paint_property.h" 54 #include "core/components_ng/render/paint_wrapper.h" 55 #include "core/components_ng/render/render_context.h" 56 #include "core/components_v2/inspector/inspector_constants.h" 57 #include "core/components_v2/inspector/inspector_node.h" 58 59 namespace OHOS::Accessibility { 60 class AccessibilityElementInfo; 61 class AccessibilityEventInfo; 62 } // namespace OHOS::Accessibility 63 64 namespace OHOS::Ace::Kit { 65 class FrameNode; 66 } 67 68 namespace OHOS::Ace::NG { 69 class InspectorFilter; 70 class PipelineContext; 71 class Pattern; 72 class StateModifyTask; 73 class UITask; 74 struct DirtySwapConfig; 75 76 struct CacheVisibleRectResult { 77 OffsetF windowOffset = OffsetF(); 78 RectF visibleRect = RectF(); 79 RectF innerVisibleRect = RectF(); 80 VectorF cumulativeScale = {1.0f, 1.0f}; 81 RectF frameRect = RectF(); 82 RectF innerBoundaryRect = RectF(); 83 }; 84 85 struct CacheMatrixInfo { 86 Matrix4 revertMatrix = Matrix4::CreateIdentity(); 87 Matrix4 localMatrix = Matrix4::CreateIdentity(); 88 RectF paintRectWithTransform; 89 }; 90 91 // FrameNode will display rendering region in the screen. 92 class ACE_FORCE_EXPORT FrameNode : public UINode, public LayoutWrapper { 93 DECLARE_ACE_TYPE(FrameNode, UINode, LayoutWrapper); 94 95 private: 96 class FrameProxy; 97 98 public: 99 // create a new child element with new element tree. 100 static RefPtr<FrameNode> CreateFrameNodeWithTree( 101 const std::string& tag, int32_t nodeId, const RefPtr<Pattern>& pattern); 102 103 static RefPtr<FrameNode> GetOrCreateFrameNode( 104 const std::string& tag, int32_t nodeId, const std::function<RefPtr<Pattern>(void)>& patternCreator); 105 106 static RefPtr<FrameNode> GetOrCreateCommonNode(const std::string& tag, int32_t nodeId, bool isLayoutNode, 107 const std::function<RefPtr<Pattern>(void)>& patternCreator); 108 109 // create a new element with new pattern. 110 static RefPtr<FrameNode> CreateFrameNode( 111 const std::string& tag, int32_t nodeId, const RefPtr<Pattern>& pattern, bool isRoot = false); 112 113 static RefPtr<FrameNode> CreateCommonNode(const std::string& tag, int32_t nodeId, bool isLayoutNode, 114 const RefPtr<Pattern>& pattern, bool isRoot = false); 115 116 // get element with nodeId from node map. 117 static RefPtr<FrameNode> GetFrameNode(const std::string& tag, int32_t nodeId); 118 119 static RefPtr<FrameNode> GetFrameNodeOnly(const std::string& tag, int32_t nodeId); 120 121 static void ProcessOffscreenNode(const RefPtr<FrameNode>& node, bool needRemainActive = false); 122 // avoid use creator function, use CreateFrameNode 123 124 FrameNode(const std::string& tag, int32_t nodeId, const RefPtr<Pattern>& pattern, 125 bool isRoot = false, bool isLayoutNode = false); 126 127 ~FrameNode() override; 128 FrameCount()129 int32_t FrameCount() const override 130 { 131 return 1; 132 } 133 CurrentFrameCount()134 int32_t CurrentFrameCount() const override 135 { 136 return 1; 137 } 138 SetCheckboxFlag(const bool checkboxFlag)139 void SetCheckboxFlag(const bool checkboxFlag) 140 { 141 checkboxFlag_ = checkboxFlag; 142 } 143 GetCheckboxFlag()144 bool GetCheckboxFlag() const 145 { 146 return checkboxFlag_; 147 } 148 SetDisallowDropForcedly(bool isDisallowDropForcedly)149 void SetDisallowDropForcedly(bool isDisallowDropForcedly) 150 { 151 isDisallowDropForcedly_ = isDisallowDropForcedly; 152 } 153 GetDisallowDropForcedly()154 bool GetDisallowDropForcedly() const 155 { 156 return isDisallowDropForcedly_; 157 } 158 159 void OnInspectorIdUpdate(const std::string& id) override; 160 161 void OnAutoEventParamUpdate(const std::string& value) override; 162 163 void UpdateGeometryTransition() override; 164 165 struct ZIndexComparator { operatorZIndexComparator166 bool operator()(const WeakPtr<FrameNode>& weakLeft, const WeakPtr<FrameNode>& weakRight) const 167 { 168 auto left = weakLeft.Upgrade(); 169 auto right = weakRight.Upgrade(); 170 if (left && right) { 171 return left->GetRenderContext()->GetZIndexValue(ZINDEX_DEFAULT_VALUE) < 172 right->GetRenderContext()->GetZIndexValue(ZINDEX_DEFAULT_VALUE); 173 } 174 return false; 175 } 176 }; 177 GetFrameChildren()178 const std::multiset<WeakPtr<FrameNode>, ZIndexComparator>& GetFrameChildren() const 179 { 180 return frameChildren_; 181 } 182 183 void InitializePatternAndContext(); 184 185 virtual void MarkModifyDone(); 186 187 void MarkDirtyNode(PropertyChangeFlag extraFlag = PROPERTY_UPDATE_NORMAL) override; 188 189 void ProcessFreezeNode(); 190 191 void OnFreezeStateChange() override; 192 ProcessPropertyDiff()193 void ProcessPropertyDiff() 194 { 195 if (isPropertyDiffMarked_) { 196 MarkModifyDone(); 197 MarkDirtyNode(); 198 isPropertyDiffMarked_ = false; 199 } 200 } 201 202 void FlushUpdateAndMarkDirty() override; 203 204 void MarkNeedFrameFlushDirty(PropertyChangeFlag extraFlag = PROPERTY_UPDATE_NORMAL) override 205 { 206 MarkDirtyNode(extraFlag); 207 } 208 209 [[deprecated]] void OnMountToParentDone(); 210 211 void AfterMountToParent() override; 212 213 bool GetIsLayoutNode(); 214 215 bool GetIsFind(); 216 217 void SetIsFind(bool isFind); 218 219 void GetOneDepthVisibleFrame(std::list<RefPtr<FrameNode>>& children); 220 221 void GetOneDepthVisibleFrameWithOffset(std::list<RefPtr<FrameNode>>& children, OffsetF& offset); 222 223 void UpdateLayoutConstraint(const MeasureProperty& calcLayoutConstraint); 224 225 RefPtr<LayoutWrapperNode> CreateLayoutWrapper(bool forceMeasure = false, bool forceLayout = false) override; 226 227 RefPtr<LayoutWrapperNode> UpdateLayoutWrapper( 228 RefPtr<LayoutWrapperNode> layoutWrapper, bool forceMeasure = false, bool forceLayout = false); 229 230 void CreateLayoutTask(bool forceUseMainThread = false); 231 232 std::optional<UITask> CreateRenderTask(bool forceUseMainThread = false); 233 234 void SwapDirtyLayoutWrapperOnMainThread(const RefPtr<LayoutWrapper>& dirty); 235 236 // Clear the user callback. 237 void ClearUserOnAreaChange(); 238 239 void SetOnAreaChangeCallback(OnAreaChangedFunc&& callback); 240 241 void TriggerOnAreaChangeCallback(uint64_t nanoTimestamp); 242 243 void OnConfigurationUpdate(const ConfigurationChange& configurationChange) override; 244 SetVisibleAreaUserCallback(const std::vector<double> & ratios,const VisibleCallbackInfo & callback)245 void SetVisibleAreaUserCallback(const std::vector<double>& ratios, const VisibleCallbackInfo& callback) 246 { 247 CreateEventHubInner(); 248 CHECK_NULL_VOID(eventHub_); 249 eventHub_->SetVisibleAreaRatiosAndCallback(callback, ratios, true); 250 } 251 252 void CleanVisibleAreaUserCallback(bool isApproximate = false); 253 254 void SetVisibleAreaInnerCallback(const std::vector<double>& ratios, const VisibleCallbackInfo& callback, 255 bool isCalculateInnerClip = false) 256 { 257 isCalculateInnerVisibleRectClip_ = isCalculateInnerClip; 258 CreateEventHubInner(); 259 CHECK_NULL_VOID(eventHub_); 260 eventHub_->SetVisibleAreaRatiosAndCallback(callback, ratios, false); 261 } 262 263 void SetIsCalculateInnerVisibleRectClip(bool isCalculateInnerClip = true) 264 { 265 isCalculateInnerVisibleRectClip_ = isCalculateInnerClip; 266 } 267 268 void SetIsCalculateInnerClip(bool isCalculateInnerClip = false) 269 { 270 isCalculateInnerVisibleRectClip_ = isCalculateInnerClip; 271 } 272 CleanVisibleAreaInnerCallback()273 void CleanVisibleAreaInnerCallback() 274 { 275 CHECK_NULL_VOID(eventHub_); 276 eventHub_->CleanVisibleAreaCallback(false); 277 } 278 279 void TriggerVisibleAreaChangeCallback(uint64_t timestamp, bool forceDisappear = false); 280 281 void SetOnSizeChangeCallback(OnSizeChangedFunc&& callback); 282 283 void AddInnerOnSizeChangeCallback(int32_t id, OnSizeChangedFunc&& callback); 284 285 void SetJSFrameNodeOnSizeChangeCallback(OnSizeChangedFunc&& callback); 286 287 void TriggerOnSizeChangeCallback(); 288 289 void SetGeometryNode(const RefPtr<GeometryNode>& node); 290 GetRenderContext()291 const RefPtr<RenderContext>& GetRenderContext() const 292 { 293 return renderContext_; 294 } 295 296 const RefPtr<Pattern>& GetPattern() const; 297 298 template<typename T> GetPatternPtr()299 T* GetPatternPtr() const 300 { 301 return reinterpret_cast<T*>(RawPtr(pattern_)); 302 } 303 304 template<typename T> GetPattern()305 RefPtr<T> GetPattern() const 306 { 307 return DynamicCast<T>(pattern_); 308 } 309 310 template<typename T> GetAccessibilityProperty()311 RefPtr<T> GetAccessibilityProperty() const 312 { 313 return DynamicCast<T>(accessibilityProperty_); 314 } 315 316 template<typename T> GetLayoutPropertyPtr()317 T* GetLayoutPropertyPtr() const 318 { 319 return reinterpret_cast<T*>(RawPtr(layoutProperty_)); 320 } 321 322 template<typename T> GetLayoutProperty()323 RefPtr<T> GetLayoutProperty() const 324 { 325 return DynamicCast<T>(layoutProperty_); 326 } 327 328 template<typename T> GetPaintPropertyPtr()329 T* GetPaintPropertyPtr() const 330 { 331 return reinterpret_cast<T*>(RawPtr(paintProperty_)); 332 } 333 334 template<typename T> GetPaintProperty()335 RefPtr<T> GetPaintProperty() const 336 { 337 return DynamicCast<T>(paintProperty_); 338 } 339 340 template<typename T> GetEventHub()341 RefPtr<T> GetEventHub() 342 { 343 CreateEventHubInner(); 344 CHECK_NULL_RETURN(eventHub_, nullptr); 345 return DynamicCast<T>(eventHub_); 346 } 347 348 template<typename T> GetEventHubOnly()349 RefPtr<T> GetEventHubOnly() 350 { 351 return DynamicCast<T>(eventHub_); 352 } 353 GetOrCreateGestureEventHub()354 RefPtr<GestureEventHub> GetOrCreateGestureEventHub() 355 { 356 CreateEventHubInner(); 357 CHECK_NULL_RETURN(eventHub_, nullptr); 358 return eventHub_->GetOrCreateGestureEventHub(); 359 } 360 GetOrCreateInputEventHub()361 RefPtr<InputEventHub> GetOrCreateInputEventHub() 362 { 363 CreateEventHubInner(); 364 return eventHub_->GetOrCreateInputEventHub(); 365 } 366 367 RefPtr<FocusHub> GetOrCreateFocusHub(); 368 const RefPtr<FocusHub>& GetOrCreateFocusHub(FocusType type, bool focusable, FocusStyleType focusStyleType, 369 const std::unique_ptr<FocusPaintParam>& paintParamsPtr); 370 const RefPtr<FocusHub>& GetOrCreateFocusHub(const FocusPattern& focusPattern); 371 372 void CreateEventHubInner(); 373 GetFocusHub()374 const RefPtr<FocusHub>& GetFocusHub() const 375 { 376 return focusHub_; 377 } 378 HasVirtualNodeAccessibilityProperty()379 bool HasVirtualNodeAccessibilityProperty() override 380 { 381 if (accessibilityProperty_ && accessibilityProperty_->GetAccessibilityVirtualNode()) { 382 return true; 383 } 384 return false; 385 } 386 GetFocusType()387 FocusType GetFocusType() const 388 { 389 FocusType type = FocusType::DISABLE; 390 auto focusHub = GetFocusHub(); 391 if (focusHub) { 392 type = focusHub->GetFocusType(); 393 } 394 return type; 395 } 396 397 void PostIdleTask(std::function<void(int64_t deadline, bool canUseLongPredictTask)>&& task); 398 399 void AddJudgeToTargetComponent(RefPtr<TargetComponent>& targetComponent); 400 401 // If return true, will prevent TouchTest Bubbling to parent and brother nodes. 402 HitTestResult TouchTest(const PointF& globalPoint, const PointF& parentLocalPoint, const PointF& parentRevertPoint, 403 TouchRestrict& touchRestrict, TouchTestResult& result, int32_t touchId, ResponseLinkResult& responseLinkResult, 404 bool isDispatch = false) override; 405 406 HitTestResult MouseTest(const PointF& globalPoint, const PointF& parentLocalPoint, MouseTestResult& onMouseResult, 407 MouseTestResult& onHoverResult, RefPtr<FrameNode>& hoverNode) override; 408 409 HitTestResult AxisTest(const PointF &globalPoint, const PointF &parentLocalPoint, const PointF &parentRevertPoint, 410 TouchRestrict &touchRestrict, AxisTestResult &axisResult) override; 411 412 void CollectSelfAxisResult(const PointF& globalPoint, const PointF& localPoint, bool& consumed, 413 const PointF& parentRevertPoint, AxisTestResult& axisResult, bool& preventBubbling, HitTestResult& testResult, 414 TouchRestrict& touchRestrict); 415 416 void AnimateHoverEffect(bool isHovered) const; 417 418 bool IsAtomicNode() const override; 419 420 void MarkNeedSyncRenderTree(bool needRebuild = false) override; 421 422 void RebuildRenderContextTree() override; 423 424 bool IsContextTransparent() override; 425 IsTrimMemRecycle()426 bool IsTrimMemRecycle() const 427 { 428 return isTrimMemRecycle_; 429 } 430 SetTrimMemRecycle(bool isTrimMemRecycle)431 void SetTrimMemRecycle(bool isTrimMemRecycle) 432 { 433 isTrimMemRecycle_ = isTrimMemRecycle; 434 } 435 IsVisible()436 bool IsVisible() const 437 { 438 return layoutProperty_->GetVisibility().value_or(VisibleType::VISIBLE) == VisibleType::VISIBLE; 439 } 440 IsPrivacySensitive()441 bool IsPrivacySensitive() const 442 { 443 return isPrivacySensitive_; 444 } 445 SetPrivacySensitive(bool flag)446 void SetPrivacySensitive(bool flag) 447 { 448 isPrivacySensitive_ = flag; 449 } 450 451 void ChangeSensitiveStyle(bool isSensitive); 452 453 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override; 454 455 void ToTreeJson(std::unique_ptr<JsonValue>& json, const InspectorConfig& config) const override; 456 457 void FromJson(const std::unique_ptr<JsonValue>& json) override; 458 459 RefPtr<FrameNode> GetAncestorNodeOfFrame(bool checkBoundary) const; 460 GetNodeName()461 std::string& GetNodeName() 462 { 463 return nodeName_; 464 } 465 SetNodeName(std::string & nodeName)466 void SetNodeName(std::string& nodeName) 467 { 468 nodeName_ = nodeName; 469 } 470 471 void OnWindowShow() override; 472 473 void OnWindowHide() override; 474 475 void OnWindowFocused() override; 476 477 void OnWindowUnfocused() override; 478 479 void OnWindowActivated() override; 480 481 void OnWindowDeactivated() override; 482 483 void OnWindowSizeChanged(int32_t width, int32_t height, WindowSizeChangeReason type) override; 484 485 void OnNotifyMemoryLevel(int32_t level) override; 486 487 // call by recycle framework. 488 void OnRecycle() override; 489 void OnReuse() override; 490 491 OffsetF GetOffsetRelativeToWindow() const; 492 493 OffsetF GetPositionToScreen(); 494 495 OffsetF GetPositionToParentWithTransform() const; 496 497 OffsetF GetPositionToScreenWithTransform(); 498 499 OffsetF GetPositionToWindowWithTransform(bool fromBottom = false) const; 500 501 OffsetF GetTransformRelativeOffset() const; 502 503 VectorF GetTransformScaleRelativeToWindow() const; 504 505 RectF GetTransformRectRelativeToWindow(bool checkBoundary = false) const; 506 507 // deprecated, please use GetPaintRectOffsetNG. 508 // this function only consider transform of itself when calculate transform, 509 // do not consider the transform of its ansestors 510 OffsetF GetPaintRectOffset(bool excludeSelf = false, bool checkBoundary = false) const; 511 512 // returns a node's offset relative to root. 513 // and accumulate every ancestor node's graphic properties such as rotate and transform 514 // @param excludeSelf default false, set true can exclude self. 515 // @param checkBoundary default false. should be true if you want check boundary of window scene 516 // for getting the offset to window. 517 OffsetF GetPaintRectOffsetNG(bool excludeSelf = false, bool checkBoundary = false) const; 518 519 bool GetRectPointToParentWithTransform(std::vector<Point>& pointList, const RefPtr<FrameNode>& parent) const; 520 521 RectF GetPaintRectToWindowWithTransform(); 522 523 std::pair<OffsetF, bool> GetPaintRectGlobalOffsetWithTranslate( 524 bool excludeSelf = false, bool checkBoundary = false) const; 525 526 OffsetF GetPaintRectOffsetToStage() const; 527 528 RectF GetPaintRectWithTransform() const; 529 530 VectorF GetTransformScale() const; 531 532 void AdjustGridOffset(); 533 IsInternal()534 bool IsInternal() const 535 { 536 return isInternal_; 537 } 538 SetInternal()539 void SetInternal() 540 { 541 isInternal_ = true; 542 } 543 544 int32_t GetAllDepthChildrenCount(); 545 546 void OnAccessibilityEvent( 547 AccessibilityEventType eventType, WindowsContentChangeTypes windowsContentChangeType = 548 WindowsContentChangeTypes::CONTENT_CHANGE_TYPE_INVALID) const; 549 550 void OnAccessibilityEventForVirtualNode(AccessibilityEventType eventType, int64_t accessibilityId); 551 552 void OnAccessibilityEvent( 553 AccessibilityEventType eventType, int32_t startIndex, int32_t endIndex); 554 555 void OnAccessibilityEvent( 556 AccessibilityEventType eventType, std::string beforeText, std::string latestContent); 557 558 void OnAccessibilityEvent( 559 AccessibilityEventType eventType, int64_t stackNodeId, WindowsContentChangeTypes windowsContentChangeType); 560 561 void OnAccessibilityEvent( 562 AccessibilityEventType eventType, std::string textAnnouncedForAccessibility); 563 void MarkNeedRenderOnly(); 564 565 void OnDetachFromMainTree(bool recursive, PipelineContext* context) override; 566 void OnAttachToMainTree(bool recursive) override; 567 void OnAttachToBuilderNode(NodeStatus nodeStatus) override; 568 bool RenderCustomChild(int64_t deadline) override; 569 void TryVisibleChangeOnDescendant(VisibleType preVisibility, VisibleType currentVisibility) override; 570 void NotifyVisibleChange(VisibleType preVisibility, VisibleType currentVisibility); 571 PushDestroyCallbackWithTag(std::function<void ()> && callback,std::string tag)572 void PushDestroyCallbackWithTag(std::function<void()>&& callback, std::string tag) 573 { 574 destroyCallbacksMap_[tag] = callback; 575 } 576 SetColorModeUpdateCallback(const std::function<void ()> && callback)577 void SetColorModeUpdateCallback(const std::function<void()>&& callback) 578 { 579 colorModeUpdateCallback_ = callback; 580 } 581 582 void SetNDKColorModeUpdateCallback(const std::function<void(int32_t)>&& callback); 583 SetNDKFontUpdateCallback(const std::function<void (float,float)> && callback)584 void SetNDKFontUpdateCallback(const std::function<void(float, float)>&& callback) 585 { 586 std::unique_lock<std::shared_mutex> lock(fontSizeCallbackMutex_); 587 ndkFontUpdateCallback_ = callback; 588 } 589 590 void FireColorNDKCallback(); 591 void FireFontNDKCallback(const ConfigurationChange& configurationChange); 592 593 bool MarkRemoving() override; 594 595 void AddHotZoneRect(const DimensionRect& hotZoneRect); 596 void RemoveLastHotZoneRect() const; 597 598 virtual bool IsOutOfTouchTestRegion(const PointF& parentLocalPoint, const TouchEvent& touchEvent, 599 std::vector<RectF>* regionList = nullptr); 600 IsLayoutDirtyMarked()601 bool IsLayoutDirtyMarked() const 602 { 603 return isLayoutDirtyMarked_; 604 } 605 SetLayoutDirtyMarked(bool marked)606 void SetLayoutDirtyMarked(bool marked) 607 { 608 isLayoutDirtyMarked_ = marked; 609 } 610 HasPositionProp()611 bool HasPositionProp() const 612 { 613 CHECK_NULL_RETURN(renderContext_, false); 614 return renderContext_->HasPosition() || renderContext_->HasOffset() || renderContext_->HasPositionEdges() || 615 renderContext_->HasOffsetEdges() || renderContext_->HasAnchor(); 616 } 617 618 // The function is only used for fast preview. FastPreviewUpdateChildDone()619 void FastPreviewUpdateChildDone() override 620 { 621 OnMountToParentDone(); 622 } 623 IsExclusiveEventForChild()624 bool IsExclusiveEventForChild() const 625 { 626 return exclusiveEventForChild_; 627 } 628 SetExclusiveEventForChild(bool exclusiveEventForChild)629 void SetExclusiveEventForChild(bool exclusiveEventForChild) 630 { 631 exclusiveEventForChild_ = exclusiveEventForChild; 632 } 633 SetDraggable(bool draggable)634 void SetDraggable(bool draggable) 635 { 636 draggable_ = draggable; 637 userSet_ = true; 638 customerSet_ = false; 639 } 640 SetCustomerDraggable(bool draggable)641 void SetCustomerDraggable(bool draggable) 642 { 643 draggable_ = draggable; 644 userSet_ = true; 645 customerSet_ = true; 646 } 647 648 void SetDragPreviewOptions(const DragPreviewOption& previewOption, bool isResetOptions = true) 649 { 650 if (isResetOptions) { 651 previewOption_ = previewOption; 652 } else { 653 auto options = previewOption_.options; 654 previewOption_ = previewOption; 655 previewOption_.options = options; 656 } 657 previewOption_.onApply = std::move(previewOption.onApply); 658 } 659 SetOptionsAfterApplied(const OptionsAfterApplied & optionsAfterApplied)660 void SetOptionsAfterApplied(const OptionsAfterApplied& optionsAfterApplied) 661 { 662 previewOption_.options = optionsAfterApplied; 663 } 664 GetDragPreviewOption()665 DragPreviewOption GetDragPreviewOption() const 666 { 667 return previewOption_; 668 } 669 SetBackgroundFunction(std::function<RefPtr<UINode> ()> && buildFunc)670 void SetBackgroundFunction(std::function<RefPtr<UINode>()>&& buildFunc) 671 { 672 builderFunc_ = std::move(buildFunc); 673 backgroundNode_ = nullptr; 674 } 675 IsDraggable()676 bool IsDraggable() const 677 { 678 return draggable_; 679 } 680 IsLayoutComplete()681 bool IsLayoutComplete() const 682 { 683 return isLayoutComplete_; 684 } 685 IsUserSet()686 bool IsUserSet() const 687 { 688 return userSet_; 689 } 690 IsCustomerSet()691 bool IsCustomerSet() const 692 { 693 return customerSet_; 694 } 695 GetPreGrayedOpacity()696 float GetPreGrayedOpacity() const 697 { 698 return preOpacity_; 699 } 700 SetPreGrayedOpacity(float preOpacity)701 void SetPreGrayedOpacity(float preOpacity) 702 { 703 preOpacity_ = preOpacity; 704 } 705 SetAllowDrop(const std::set<std::string> & allowDrop)706 void SetAllowDrop(const std::set<std::string>& allowDrop) 707 { 708 allowDrop_ = allowDrop; 709 } 710 GetAllowDrop()711 const std::set<std::string>& GetAllowDrop() const 712 { 713 return allowDrop_; 714 } 715 SetDrawModifier(const RefPtr<NG::DrawModifier> & drawModifier)716 void SetDrawModifier(const RefPtr<NG::DrawModifier>& drawModifier) 717 { 718 if (!extensionHandler_) { 719 extensionHandler_ = MakeRefPtr<ExtensionHandler>(); 720 extensionHandler_->AttachFrameNode(this); 721 } 722 extensionHandler_->SetDrawModifier(drawModifier); 723 } 724 725 bool IsSupportDrawModifier(); 726 SetDragPreview(const NG::DragDropInfo & info)727 void SetDragPreview(const NG::DragDropInfo& info) 728 { 729 dragPreviewInfo_ = info; 730 } 731 GetDragPreview()732 const DragDropInfo& GetDragPreview() const 733 { 734 return dragPreviewInfo_; 735 } 736 SetOverlayNode(const RefPtr<FrameNode> & overlayNode)737 void SetOverlayNode(const RefPtr<FrameNode>& overlayNode) 738 { 739 overlayNode_ = overlayNode; 740 } 741 GetOverlayNode()742 RefPtr<FrameNode> GetOverlayNode() const 743 { 744 return overlayNode_; 745 } 746 747 RefPtr<FrameNode> FindChildByPosition(float x, float y); 748 // some developer use translate to make Grid drag animation, using old function can't find accurate child. 749 // new function will ignore child's position and translate properties. 750 RefPtr<FrameNode> FindChildByPositionWithoutChildTransform(float x, float y); 751 752 RefPtr<NodeAnimatablePropertyBase> GetAnimatablePropertyFloat(const std::string& propertyName) const; 753 static RefPtr<FrameNode> FindChildByName(const RefPtr<FrameNode>& parentNode, const std::string& nodeName); 754 void CreateAnimatablePropertyFloat(const std::string& propertyName, float value, 755 const std::function<void(float)>& onCallbackEvent, const PropertyUnit& propertyType = PropertyUnit::UNKNOWN); 756 void DeleteAnimatablePropertyFloat(const std::string& propertyName); 757 void UpdateAnimatablePropertyFloat(const std::string& propertyName, float value); 758 void CreateAnimatableArithmeticProperty(const std::string& propertyName, RefPtr<CustomAnimatableArithmetic>& value, 759 std::function<void(const RefPtr<CustomAnimatableArithmetic>&)>& onCallbackEvent); 760 void UpdateAnimatableArithmeticProperty(const std::string& propertyName, RefPtr<CustomAnimatableArithmetic>& value); 761 762 void SetHitTestMode(HitTestMode mode); 763 HitTestMode GetHitTestMode() const override; 764 765 TouchResult GetOnChildTouchTestRet(const std::vector<TouchTestInfo>& touchInfo); 766 OnChildTouchTestFunc GetOnTouchTestFunc(); 767 void CollectTouchInfos( 768 const PointF& globalPoint, const PointF& parentRevertPoint, std::vector<TouchTestInfo>& touchInfos); 769 RefPtr<FrameNode> GetDispatchFrameNode(const TouchResult& touchRes); 770 771 std::string ProvideRestoreInfo(); 772 773 static std::vector<RefPtr<FrameNode>> GetNodesById(const std::unordered_set<int32_t>& set); 774 static std::vector<FrameNode*> GetNodesPtrById(const std::unordered_set<int32_t>& set); 775 776 double GetPreviewScaleVal() const; 777 778 bool IsPreviewNeedScale() const; 779 SetViewPort(RectF viewPort)780 void SetViewPort(RectF viewPort) 781 { 782 viewPort_ = viewPort; 783 } 784 GetSelfViewPort()785 std::optional<RectF> GetSelfViewPort() const 786 { 787 return viewPort_; 788 } 789 790 std::optional<RectF> GetViewPort(bool checkBoundary = false) const; 791 792 // Frame Rate Controller(FRC) decides FrameRateRange by scene, speed and scene status 793 // speed is measured by millimeter/second 794 void AddFRCSceneInfo(const std::string& scene, float speed, SceneStatus status); 795 796 void TryPrintDebugLog(const std::string& scene, float speed, SceneStatus status); 797 798 OffsetF GetParentGlobalOffsetDuringLayout() const; OnSetCacheCount(int32_t cacheCount,const std::optional<LayoutConstraintF> & itemConstraint)799 void OnSetCacheCount(int32_t cacheCount, const std::optional<LayoutConstraintF>& itemConstraint) override {}; 800 801 // layoutwrapper function override 802 const RefPtr<LayoutAlgorithmWrapper>& GetLayoutAlgorithm(bool needReset = false) override; 803 804 void Measure(const std::optional<LayoutConstraintF>& parentConstraint) override; 805 806 // Called to perform layout children. 807 void Layout() override; 808 GetTotalChildCount()809 int32_t GetTotalChildCount() const override 810 { 811 return UINode::TotalChildCount(); 812 } 813 GetTotalChildCountWithoutExpanded()814 int32_t GetTotalChildCountWithoutExpanded() const 815 { 816 return UINode::CurrentFrameCount(); 817 } 818 GetGeometryNode()819 const RefPtr<GeometryNode>& GetGeometryNode() const override 820 { 821 return geometryNode_; 822 } 823 SetLayoutProperty(const RefPtr<LayoutProperty> & layoutProperty)824 void SetLayoutProperty(const RefPtr<LayoutProperty>& layoutProperty) 825 { 826 layoutProperty_ = layoutProperty; 827 layoutProperty_->SetHost(WeakClaim(this)); 828 } 829 GetLayoutProperty()830 const RefPtr<LayoutProperty>& GetLayoutProperty() const override 831 { 832 return layoutProperty_; 833 } 834 835 RefPtr<LayoutWrapper> GetOrCreateChildByIndex( 836 uint32_t index, bool addToRenderTree = true, bool isCache = false) override; 837 RefPtr<LayoutWrapper> GetChildByIndex(uint32_t index, bool isCache = false) override; 838 839 FrameNode* GetFrameNodeChildByIndex(uint32_t index, bool isCache = false, bool isExpand = true); 840 FrameNode* GetFrameNodeChildByIndexWithoutBuild(uint32_t index); 841 /** 842 * @brief Get the index of Child among all FrameNode children of [this]. 843 * Handles intermediate SyntaxNodes like LazyForEach. 844 * 845 * @param child pointer to the Child FrameNode. 846 * @return index of Child, or -1 if not found. 847 */ 848 int32_t GetChildTrueIndex(const RefPtr<LayoutWrapper>& child) const; 849 uint32_t GetChildTrueTotalCount() const; 850 ChildrenListWithGuard GetAllChildrenWithBuild(bool addToRenderTree = true) override; 851 void RemoveChildInRenderTree(uint32_t index) override; 852 void RemoveAllChildInRenderTree() override; 853 void DoRemoveChildInRenderTree(uint32_t index, bool isAll) override; 854 void SetActiveChildRange( 855 int32_t start, int32_t end, int32_t cacheStart = 0, int32_t cacheEnd = 0, bool showCached = false) override; 856 void SetActiveChildRange(const std::optional<ActiveChildSets>& activeChildSets, 857 const std::optional<ActiveChildRange>& activeChildRange = std::nullopt) override; 858 void DoSetActiveChildRange( 859 int32_t start, int32_t end, int32_t cacheStart, int32_t cacheEnd, bool showCache = false) override; 860 void RecycleItemsByIndex(int32_t start, int32_t end) override; GetHostTag()861 const std::string& GetHostTag() const override 862 { 863 return GetTag(); 864 } 865 866 void UpdateFocusState(); 867 bool SelfOrParentExpansive(); 868 bool SelfExpansive(); 869 bool SelfExpansiveToKeyboard(); 870 bool ParentExpansive(); 871 IsActive()872 bool IsActive() const override 873 { 874 return isActive_; 875 } 876 877 void SetActive(bool active = true, bool needRebuildRenderContext = false) override; 878 GetAccessibilityVisible()879 bool GetAccessibilityVisible() const 880 { 881 return accessibilityVisible_; 882 } 883 SetAccessibilityVisible(const bool accessibilityVisible)884 void SetAccessibilityVisible(const bool accessibilityVisible) 885 { 886 accessibilityVisible_ = accessibilityVisible; 887 } 888 IsOutOfLayout()889 bool IsOutOfLayout() const override 890 { 891 return renderContext_->HasPosition() || renderContext_->HasPositionEdges(); 892 } 893 void ProcessSafeAreaPadding(); 894 895 bool SkipMeasureContent() const override; 896 float GetBaselineDistance() const override; 897 void SetCacheCount( 898 int32_t cacheCount = 0, const std::optional<LayoutConstraintF>& itemConstraint = std::nullopt) override; 899 900 void SyncGeometryNode(bool needSyncRsNode, const DirtySwapConfig& config); 901 RefPtr<UINode> GetFrameChildByIndex( 902 uint32_t index, bool needBuild, bool isCache = false, bool addToRenderTree = false) override; 903 RefPtr<UINode> GetFrameChildByIndexWithoutExpanded(uint32_t index) override; 904 bool CheckNeedForceMeasureAndLayout() override; 905 906 bool SetParentLayoutConstraint(const SizeF& size) const override; 907 void ForceSyncGeometryNode(); 908 909 template<typename T> FindFocusChildNodeOfClass()910 RefPtr<T> FindFocusChildNodeOfClass() 911 { 912 const auto& children = GetChildren(); 913 for (auto iter = children.rbegin(); iter != children.rend(); ++iter) { 914 auto& child = *iter; 915 auto target = DynamicCast<FrameNode>(child->FindChildNodeOfClass<T>()); 916 if (target && target->eventHub_) { 917 auto focusEvent = target->eventHub_->GetFocusHub(); 918 if (focusEvent && focusEvent->IsCurrentFocus()) { 919 return AceType::DynamicCast<T>(target); 920 } 921 } 922 } 923 924 if (AceType::InstanceOf<T>(this)) { 925 auto target = DynamicCast<FrameNode>(this); 926 if (target && target->eventHub_) { 927 auto focusEvent = target->eventHub_->GetFocusHub(); 928 if (focusEvent && focusEvent->IsCurrentFocus()) { 929 return Claim(AceType::DynamicCast<T>(this)); 930 } 931 } 932 } 933 return nullptr; 934 } 935 936 virtual std::vector<RectF> GetResponseRegionList(const RectF& rect, int32_t sourceType); 937 IsFirstBuilding()938 bool IsFirstBuilding() const 939 { 940 return isFirstBuilding_; 941 } 942 MarkBuildDone()943 void MarkBuildDone() 944 { 945 isFirstBuilding_ = false; 946 } 947 GetLocalMatrix()948 Matrix4 GetLocalMatrix() const 949 { 950 return localMat_; 951 } 952 OffsetF GetOffsetInScreen(); 953 OffsetF GetOffsetInSubwindow(const OffsetF& subwindowOffset); 954 RefPtr<PixelMap> GetDragPixelMap(); 955 RefPtr<FrameNode> GetPageNode(); 956 RefPtr<FrameNode> GetFirstAutoFillContainerNode(); 957 RefPtr<FrameNode> GetNodeContainer(); 958 RefPtr<ContentModifier> GetContentModifier(); 959 GetExtensionHandler()960 ExtensionHandler* GetExtensionHandler() const 961 { 962 return RawPtr(extensionHandler_); 963 } 964 SetExtensionHandler(const RefPtr<ExtensionHandler> & handler)965 void SetExtensionHandler(const RefPtr<ExtensionHandler>& handler) 966 { 967 extensionHandler_ = handler; 968 if (extensionHandler_) { 969 extensionHandler_->AttachFrameNode(this); 970 } 971 } 972 973 void NotifyFillRequestSuccess(RefPtr<ViewDataWrap> viewDataWrap, 974 RefPtr<PageNodeInfoWrap> nodeWrap, AceAutoFillType autoFillType); 975 void NotifyFillRequestFailed(int32_t errCode, const std::string& fillContent = "", bool isPopup = false); 976 977 int32_t GetUiExtensionId(); 978 int64_t WrapExtensionAbilityId(int64_t extensionOffset, int64_t abilityId); 979 void SearchExtensionElementInfoByAccessibilityIdNG( 980 int64_t elementId, int32_t mode, int64_t offset, std::list<Accessibility::AccessibilityElementInfo>& output); 981 void SearchElementInfosByTextNG(int64_t elementId, const std::string& text, int64_t offset, 982 std::list<Accessibility::AccessibilityElementInfo>& output); 983 void FindFocusedExtensionElementInfoNG( 984 int64_t elementId, int32_t focusType, int64_t offset, Accessibility::AccessibilityElementInfo& output); 985 void FocusMoveSearchNG( 986 int64_t elementId, int32_t direction, int64_t offset, Accessibility::AccessibilityElementInfo& output); 987 bool TransferExecuteAction( 988 int64_t elementId, const std::map<std::string, std::string>& actionArguments, int32_t action, int64_t offset); 989 std::vector<RectF> GetResponseRegionListForRecognizer(int32_t sourceType); 990 991 std::vector<RectF> GetResponseRegionListForTouch(const RectF& rect); 992 993 void GetResponseRegionListByTraversal(std::vector<RectF>& responseRegionList); 994 995 bool InResponseRegionList(const PointF& parentLocalPoint, const std::vector<RectF>& responseRegionList); 996 997 bool GetMonopolizeEvents() const; 998 IsWindowBoundary()999 bool IsWindowBoundary() const 1000 { 1001 return isWindowBoundary_; 1002 } 1003 1004 void SetWindowBoundary(bool isWindowBoundary = true) 1005 { 1006 isWindowBoundary_ = isWindowBoundary; 1007 } 1008 SetIsMeasureBoundary(bool isMeasureBoundary)1009 void SetIsMeasureBoundary(bool isMeasureBoundary) 1010 { 1011 isMeasureBoundary_ = isMeasureBoundary; 1012 } 1013 1014 void InitLastArea(); 1015 1016 OffsetF CalculateCachedTransformRelativeOffset(uint64_t nanoTimestamp); 1017 1018 void PaintDebugBoundary(bool flag) override; 1019 RectF GetRectWithRender(); 1020 bool CheckAncestorPageShow(); 1021 SetRemoveCustomProperties(std::function<void ()> func)1022 void SetRemoveCustomProperties(std::function<void()> func) 1023 { 1024 if (!removeCustomProperties_) { 1025 removeCustomProperties_ = func; 1026 } 1027 } 1028 1029 void GetVisibleRect(RectF& visibleRect, RectF& frameRect) const; 1030 void GetVisibleRectWithClip(RectF& visibleRect, RectF& visibleInnerRect, RectF& frameRect) const; 1031 1032 void AttachContext(PipelineContext* context, bool recursive = false) override; 1033 void DetachContext(bool recursive = false) override; 1034 1035 void SetExposureProcessor(const RefPtr<Recorder::ExposureProcessor>& processor); 1036 GetIsGeometryTransitionIn()1037 bool GetIsGeometryTransitionIn() const 1038 { 1039 return isGeometryTransitionIn_; 1040 } 1041 SetIsGeometryTransitionIn(bool isGeometryTransitionIn)1042 void SetIsGeometryTransitionIn(bool isGeometryTransitionIn) 1043 { 1044 isGeometryTransitionIn_ = isGeometryTransitionIn; 1045 } 1046 SetGeometryTransitionInRecursive(bool isGeometryTransitionIn)1047 void SetGeometryTransitionInRecursive(bool isGeometryTransitionIn) override 1048 { 1049 SetIsGeometryTransitionIn(isGeometryTransitionIn); 1050 UINode::SetGeometryTransitionInRecursive(isGeometryTransitionIn); 1051 } 1052 static std::pair<float, float> ContextPositionConvertToPX( 1053 const RefPtr<RenderContext>& context, const SizeF& percentReference); 1054 1055 // Notified by render context when any transform attributes updated, 1056 // this flag will be used to refresh the transform matrix cache if it's dirty NotifyTransformInfoChanged()1057 void NotifyTransformInfoChanged() 1058 { 1059 isTransformNotChanged_ = false; 1060 } 1061 AddPredictLayoutNode(const RefPtr<FrameNode> & node)1062 void AddPredictLayoutNode(const RefPtr<FrameNode>& node) 1063 { 1064 predictLayoutNode_.emplace_back(node); 1065 } 1066 CheckAccessibilityLevelNo()1067 bool CheckAccessibilityLevelNo() const { 1068 return false; 1069 } 1070 HasAccessibilityVirtualNode(bool hasAccessibilityVirtualNode)1071 void HasAccessibilityVirtualNode(bool hasAccessibilityVirtualNode) 1072 { 1073 hasAccessibilityVirtualNode_ = hasAccessibilityVirtualNode; 1074 } 1075 1076 void ProcessAccessibilityVirtualNode(); 1077 1078 void UpdateAccessibilityNodeRect(); 1079 GetVirtualNodeTransformRectRelativeToWindow()1080 RectF GetVirtualNodeTransformRectRelativeToWindow() 1081 { 1082 auto parentUinode = GetVirtualNodeParent().Upgrade(); 1083 CHECK_NULL_RETURN(parentUinode, RectF {}); 1084 auto parentFrame = AceType::DynamicCast<FrameNode>(parentUinode); 1085 CHECK_NULL_RETURN(parentFrame, RectF {}); 1086 auto parentRect = parentFrame->GetTransformRectRelativeToWindow(); 1087 auto currentRect = GetTransformRectRelativeToWindow(); 1088 currentRect.SetTop(currentRect.Top() + parentRect.Top()); 1089 currentRect.SetLeft(currentRect.Left() + parentRect.Left()); 1090 return currentRect; 1091 } 1092 SetIsUseTransitionAnimator(bool isUseTransitionAnimator)1093 void SetIsUseTransitionAnimator(bool isUseTransitionAnimator) 1094 { 1095 isUseTransitionAnimator_ = isUseTransitionAnimator; 1096 } 1097 GetIsUseTransitionAnimator()1098 bool GetIsUseTransitionAnimator() 1099 { 1100 return isUseTransitionAnimator_; 1101 } 1102 1103 // this method will check the cache state and return the cached revert matrix preferentially, 1104 // but the caller can pass in true to forcible refresh the cache 1105 CacheMatrixInfo& GetOrRefreshMatrixFromCache(bool forceRefresh = false); 1106 1107 // apply the matrix to the given point specified by dst 1108 static void MapPointTo(PointF& dst, Matrix4& matrix); 1109 void SetSuggestOpIncMarked(bool flag); 1110 bool GetSuggestOpIncMarked(); 1111 void SetCanSuggestOpInc(bool flag); 1112 bool GetCanSuggestOpInc(); 1113 void SetApplicationRenderGroupMarked(bool flag); 1114 bool GetApplicationRenderGroupMarked(); 1115 void SetSuggestOpIncActivatedOnce(); 1116 bool GetSuggestOpIncActivatedOnce(); 1117 bool MarkSuggestOpIncGroup(bool suggest, bool calc); 1118 void SetOpIncGroupCheckedThrough(bool flag); 1119 bool GetOpIncGroupCheckedThrough(); 1120 void SetOpIncCheckedOnce(); 1121 bool GetOpIncCheckedOnce(); 1122 void MarkAndCheckNewOpIncNode(); 1123 ChildrenListWithGuard GetAllChildren(); 1124 OPINC_TYPE_E FindSuggestOpIncNode(std::string& path, const SizeF& boundary, int32_t depth); 1125 void GetInspectorValue() override; 1126 void NotifyWebPattern(bool isRegister) override; 1127 GetChangeInfoFlag()1128 FrameNodeChangeInfoFlag GetChangeInfoFlag() 1129 { 1130 return changeInfoFlag_; 1131 } 1132 SetDeleteRsNode(bool isDelete)1133 void SetDeleteRsNode(bool isDelete) { 1134 isDeleteRsNode_ = isDelete; 1135 } 1136 GetIsDelete()1137 bool GetIsDelete() const { 1138 return isDeleteRsNode_; 1139 } 1140 SetPositionZ(bool hasPositionZ)1141 void SetPositionZ(bool hasPositionZ) { 1142 hasPositionZ_ = hasPositionZ; 1143 } 1144 HasPositionZ()1145 bool HasPositionZ() const { 1146 return hasPositionZ_; 1147 } 1148 1149 void ClearSubtreeLayoutAlgorithm(bool includeSelf = true, bool clearEntireTree = false) override; 1150 ClearChangeInfoFlag()1151 void ClearChangeInfoFlag() 1152 { 1153 changeInfoFlag_ = FRAME_NODE_CHANGE_INFO_NONE; 1154 } 1155 1156 void OnSyncGeometryFrameFinish(const RectF& paintRect); 1157 void AddFrameNodeChangeInfoFlag(FrameNodeChangeInfoFlag changeFlag = FRAME_NODE_CHANGE_INFO_NONE); 1158 void RegisterNodeChangeListener(); 1159 void UnregisterNodeChangeListener(); 1160 void ProcessFrameNodeChangeFlag(); 1161 void OnNodeTransformInfoUpdate(bool changed); 1162 void OnNodeTransitionInfoUpdate(); 1163 uint32_t GetWindowPatternType() const; 1164 ResetLayoutAlgorithm()1165 void ResetLayoutAlgorithm() 1166 { 1167 layoutAlgorithm_.Reset(); 1168 } 1169 HasLayoutAlgorithm()1170 bool HasLayoutAlgorithm() 1171 { 1172 return layoutAlgorithm_ != nullptr; 1173 } 1174 GetDragHitTestBlock()1175 bool GetDragHitTestBlock() const 1176 { 1177 return dragHitTestBlock_; 1178 } 1179 SetDragHitTestBlock(bool dragHitTestBlock)1180 void SetDragHitTestBlock(bool dragHitTestBlock) 1181 { 1182 dragHitTestBlock_ = dragHitTestBlock; 1183 } 1184 1185 void NotifyChange(int32_t changeIdx, int32_t count, int64_t id, NotificationType notificationType) override; 1186 1187 void ChildrenUpdatedFrom(int32_t index); GetChildrenUpdated()1188 int32_t GetChildrenUpdated() const 1189 { 1190 return childrenUpdatedFrom_; 1191 } 1192 1193 void SetJSCustomProperty(std::function<bool()> func, std::function<std::string(const std::string&)> getFunc); 1194 bool GetJSCustomProperty(const std::string& key, std::string& value); 1195 bool GetCapiCustomProperty(const std::string& key, std::string& value); 1196 1197 void AddCustomProperty(const std::string& key, const std::string& value) override; 1198 void RemoveCustomProperty(const std::string& key) override; 1199 1200 void SetCustomPropertyMapFlagByKey(const std::string& key); 1201 1202 void AddExtraCustomProperty(const std::string& key, void* extraData); 1203 void* GetExtraCustomProperty(const std::string& key) const; 1204 void RemoveExtraCustomProperty(const std::string& key); 1205 bool GetCustomPropertyByKey(const std::string& key, std::string& value); 1206 void ExtraCustomPropertyToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const; 1207 void AddNodeDestroyCallback(const std::string& callbackKey, std::function<void()>&& callback); 1208 void RemoveNodeDestroyCallback(const std::string& callbackKey); 1209 void FireOnExtraNodeDestroyCallback(); 1210 1211 LayoutConstraintF GetLayoutConstraint() const; 1212 GetTargetComponent()1213 WeakPtr<TargetComponent> GetTargetComponent() const 1214 { 1215 return targetComponent_; 1216 } 1217 SetExposeInnerGestureFlag(bool exposeInnerGestureFlag)1218 void SetExposeInnerGestureFlag(bool exposeInnerGestureFlag) 1219 { 1220 exposeInnerGestureFlag_ = exposeInnerGestureFlag; 1221 } 1222 GetExposeInnerGestureFlag()1223 bool GetExposeInnerGestureFlag() const 1224 { 1225 return exposeInnerGestureFlag_; 1226 } 1227 1228 RefPtr<UINode> GetCurrentPageRootNode() override; 1229 1230 std::list<RefPtr<FrameNode>> GetActiveChildren(); 1231 1232 void MarkDirtyWithOnProChange(PropertyChangeFlag extraFlag); 1233 void OnPropertyChangeMeasure() const; 1234 1235 void SetKitNode(const RefPtr<Kit::FrameNode>& node); 1236 const RefPtr<Kit::FrameNode>& GetKitNode() const; 1237 SetVisibleAreaChangeTriggerReason(VisibleAreaChangeTriggerReason triggerReason)1238 void SetVisibleAreaChangeTriggerReason(VisibleAreaChangeTriggerReason triggerReason) 1239 { 1240 if (visibleAreaChangeTriggerReason_ != triggerReason) { 1241 visibleAreaChangeTriggerReason_ = triggerReason; 1242 } 1243 } 1244 1245 void OnThemeScopeUpdate(int32_t themeScopeId) override; 1246 1247 OffsetF CalculateOffsetRelativeToWindow(uint64_t nanoTimestamp, bool logFlag = false); 1248 1249 bool IsDebugInspectorId(); 1250 GetLastFrameRect()1251 RectF GetLastFrameRect() const 1252 { 1253 RectF rect; 1254 return lastFrameRect_ ? *lastFrameRect_ : rect; 1255 } SetLastFrameRect(const RectF & lastFrameRect)1256 void SetLastFrameRect(const RectF& lastFrameRect) 1257 { 1258 *lastFrameRect_ = lastFrameRect; 1259 } GetLastParentOffsetToWindow()1260 OffsetF GetLastParentOffsetToWindow() const 1261 { 1262 OffsetF offset; 1263 return lastParentOffsetToWindow_ ? *lastParentOffsetToWindow_ : offset; 1264 } SetLastParentOffsetToWindow(const OffsetF & lastParentOffsetToWindow)1265 void SetLastParentOffsetToWindow(const OffsetF& lastParentOffsetToWindow) 1266 { 1267 *lastParentOffsetToWindow_ = lastParentOffsetToWindow; 1268 } GetLastHostParentOffsetToWindow()1269 std::shared_ptr<OffsetF>& GetLastHostParentOffsetToWindow() 1270 { 1271 return lastHostParentOffsetToWindow_; 1272 } ResetRenderDirtyMarked(bool isRenderDirtyMarked)1273 void ResetRenderDirtyMarked(bool isRenderDirtyMarked) 1274 { 1275 isRenderDirtyMarked_ = isRenderDirtyMarked; 1276 } 1277 1278 void SetFrameNodeDestructorCallback(const std::function<void(int32_t)>&& callback); 1279 void FireFrameNodeDestructorCallback(); 1280 CheckTopWindowBoundary()1281 bool CheckTopWindowBoundary() const 1282 { 1283 return topWindowBoundary_; 1284 } 1285 SetTopWindowBoundary(bool topWindowBoundary)1286 void SetTopWindowBoundary(bool topWindowBoundary) 1287 { 1288 topWindowBoundary_ = topWindowBoundary; 1289 } 1290 bool CheckVisibleOrActive() override; 1291 SetPaintNode(const RefPtr<FrameNode> & paintNode)1292 void SetPaintNode(const RefPtr<FrameNode>& paintNode) 1293 { 1294 paintNode_ = paintNode; 1295 } 1296 GetPaintNode()1297 const RefPtr<FrameNode>& GetPaintNode() const 1298 { 1299 return paintNode_; 1300 } 1301 SetFocusPaintNode(const RefPtr<FrameNode> & accessibilityFocusPaintNode)1302 void SetFocusPaintNode(const RefPtr<FrameNode>& accessibilityFocusPaintNode) 1303 { 1304 accessibilityFocusPaintNode_ = accessibilityFocusPaintNode; 1305 } 1306 GetFocusPaintNode()1307 const RefPtr<FrameNode>& GetFocusPaintNode() const 1308 { 1309 return accessibilityFocusPaintNode_; 1310 } 1311 1312 bool IsDrawFocusOnTop() const; 1313 SetNeedLazyLayout(bool value)1314 void SetNeedLazyLayout(bool value) 1315 { 1316 layoutProperty_->SetNeedLazyLayout(value); 1317 } 1318 1319 void AddVisibilityDumpInfo(const std::pair<uint64_t, std::pair<VisibleType, bool>>& dumpInfo); 1320 1321 std::string PrintVisibilityDumpInfo() const; 1322 ResetLastFrameNodeRect()1323 void ResetLastFrameNodeRect() 1324 { 1325 if (lastFrameNodeRect_) { 1326 lastFrameNodeRect_.reset(); 1327 } 1328 } 1329 1330 protected: 1331 void DumpInfo() override; 1332 std::unordered_map<std::string, std::function<void()>> destroyCallbacksMap_; 1333 void DumpInfo(std::unique_ptr<JsonValue>& json) override; 1334 void DumpSimplifyInfo(std::unique_ptr<JsonValue>& json) override; 1335 void OnCollectRemoved() override; 1336 1337 private: 1338 void MarkDirtyNode( 1339 bool isMeasureBoundary, bool isRenderBoundary, PropertyChangeFlag extraFlag = PROPERTY_UPDATE_NORMAL); 1340 OPINC_TYPE_E IsOpIncValidNode(const SizeF& boundary, int32_t childNumber = 0); 1341 static int GetValidLeafChildNumber(const RefPtr<FrameNode>& host, int32_t thresh); 1342 void MarkNeedRender(bool isRenderBoundary); 1343 bool IsNeedRequestParentMeasure() const; 1344 void UpdateLayoutPropertyFlag() override; 1345 void ForceUpdateLayoutPropertyFlag(PropertyChangeFlag propertyChangeFlag) override; 1346 void AdjustParentLayoutFlag(PropertyChangeFlag& flag) override; 1347 /** 1348 * @brief try to mark Parent dirty with flag PROPERTY_UPDATE_BY_CHILD_REQUEST. 1349 * 1350 * @return true if Parent is successfully marked dirty. 1351 */ 1352 virtual bool RequestParentDirty(); 1353 1354 void UpdateChildrenLayoutWrapper(const RefPtr<LayoutWrapperNode>& self, bool forceMeasure, bool forceLayout); 1355 void AdjustLayoutWrapperTree(const RefPtr<LayoutWrapperNode>& parent, bool forceMeasure, bool forceLayout) override; 1356 1357 RefPtr<PaintWrapper> CreatePaintWrapper(); 1358 void LayoutOverlay(); 1359 1360 void OnGenerateOneDepthVisibleFrame(std::list<RefPtr<FrameNode>>& visibleList) override; 1361 void OnGenerateOneDepthVisibleFrameWithTransition(std::list<RefPtr<FrameNode>>& visibleList) override; 1362 void OnGenerateOneDepthVisibleFrameWithOffset( 1363 std::list<RefPtr<FrameNode>>& visibleList, OffsetF& offset) override; 1364 void OnGenerateOneDepthAllFrame(std::list<RefPtr<FrameNode>>& allList) override; 1365 1366 bool IsMeasureBoundary(); 1367 bool IsRenderBoundary(); 1368 1369 bool OnRemoveFromParent(bool allowTransition) override; 1370 bool RemoveImmediately() const override; 1371 1372 bool IsPaintRectWithTransformValid(); 1373 1374 // dump self info. 1375 void DumpDragInfo(); 1376 void DumpOverlayInfo(); 1377 void DumpCommonInfo(); 1378 void DumpCommonInfo(std::unique_ptr<JsonValue>& json); 1379 void DumpSimplifyCommonInfo(std::unique_ptr<JsonValue>& json); 1380 void DumpSimplifySafeAreaInfo(std::unique_ptr<JsonValue>& json); 1381 void DumpSimplifyOverlayInfo(std::unique_ptr<JsonValue>& json); 1382 void DumpBorder(const std::unique_ptr<NG::BorderWidthProperty>& border, std::string label, 1383 std::unique_ptr<JsonValue>& json); 1384 void DumpPadding(const std::unique_ptr<NG::PaddingProperty>& border, std::string label, 1385 std::unique_ptr<JsonValue>& json); 1386 void DumpOverlayInfo(std::unique_ptr<JsonValue>& json); 1387 void DumpDragInfo(std::unique_ptr<JsonValue>& json); 1388 void DumpAlignRulesInfo(std::unique_ptr<JsonValue>& json); 1389 void DumpSafeAreaInfo(std::unique_ptr<JsonValue>& json); 1390 void DumpExtensionHandlerInfo(std::unique_ptr<JsonValue>& json); 1391 void DumpOnSizeChangeInfo(std::unique_ptr<JsonValue>& json); 1392 void BuildLayoutInfo(std::unique_ptr<JsonValue>& json); 1393 1394 void DumpSafeAreaInfo(); 1395 void DumpAlignRulesInfo(); 1396 void DumpExtensionHandlerInfo(); 1397 void DumpAdvanceInfo() override; 1398 void DumpAdvanceInfo(std::unique_ptr<JsonValue>& json) override; 1399 void DumpViewDataPageNode(RefPtr<ViewDataWrap> viewDataWrap, bool needsRecordData = false) override; 1400 void DumpOnSizeChangeInfo(); 1401 void DumpKeyboardShortcutInfo(); 1402 bool CheckAutoSave() override; 1403 void MouseToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const; 1404 void TouchToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const; 1405 void GeometryNodeToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const; 1406 1407 bool GetTouchable() const; 1408 bool OnLayoutFinish(bool& needSyncRsNode, DirtySwapConfig& config); 1409 1410 void ProcessVisibleAreaChangeEvent(const RectF& visibleRect, const RectF& frameRect, 1411 const std::vector<double>& visibleAreaRatios, VisibleCallbackInfo& visibleAreaCallback, bool isUser); 1412 void ProcessAllVisibleCallback(const std::vector<double>& visibleAreaUserRatios, 1413 VisibleCallbackInfo& visibleAreaUserCallback, double currentVisibleRatio, 1414 double lastVisibleRatio, bool isThrottled = false, bool isInner = false); 1415 void ProcessThrottledVisibleCallback(bool forceDisappear); 1416 bool IsFrameDisappear() const; 1417 bool IsFrameDisappear(uint64_t timestamp); 1418 bool IsFrameAncestorDisappear(uint64_t timestamp); 1419 void ThrottledVisibleTask(); 1420 1421 void OnPixelRoundFinish(const SizeF& pixelGridRoundSize); 1422 1423 double CalculateCurrentVisibleRatio(const RectF& visibleRect, const RectF& renderRect); 1424 1425 // set costom background layoutConstraint 1426 void SetBackgroundLayoutConstraint(const RefPtr<FrameNode>& customNode); 1427 1428 void GetPercentSensitive(); 1429 void UpdatePercentSensitive(); 1430 1431 void AddFrameNodeSnapshot(bool isHit, int32_t parentId, std::vector<RectF> responseRegionList, EventTreeType type); 1432 1433 int32_t GetNodeExpectedRate(); 1434 1435 void RecordExposureInner(); 1436 1437 const std::pair<uint64_t, OffsetF>& GetCachedGlobalOffset() const; 1438 1439 void SetCachedGlobalOffset(const std::pair<uint64_t, OffsetF>& timestampOffset); 1440 1441 const std::pair<uint64_t, OffsetF>& GetCachedTransformRelativeOffset() const; 1442 1443 void SetCachedTransformRelativeOffset(const std::pair<uint64_t, OffsetF>& timestampOffset); 1444 1445 HitTestMode TriggerOnTouchIntercept(const TouchEvent& touchEvent); 1446 1447 void TriggerShouldParallelInnerWith( 1448 const ResponseLinkResult& currentRecognizers, const ResponseLinkResult& responseLinkRecognizers); 1449 1450 void TriggerRsProfilerNodeMountCallbackIfExist(); 1451 1452 void AddTouchEventAllFingersInfo(TouchEventInfo& event, const TouchEvent& touchEvent); 1453 1454 RectF ApplyFrameNodeTranformToRect(const RectF& rect, const RefPtr<FrameNode>& parent) const; 1455 1456 CacheVisibleRectResult GetCacheVisibleRect(uint64_t timestamp, bool logFlag = false); 1457 1458 CacheVisibleRectResult CalculateCacheVisibleRect(CacheVisibleRectResult& parentCacheVisibleRect, 1459 const RefPtr<FrameNode>& parentUi, RectF& rectToParent, VectorF scale, uint64_t timestamp); 1460 1461 void NotifyConfigurationChangeNdk(const ConfigurationChange& configurationChange); 1462 1463 bool AllowVisibleAreaCheck() const; 1464 1465 bool ProcessMouseTestHit(const PointF& globalPoint, const PointF& localPoint, 1466 TouchRestrict& touchRestrict, TouchTestResult& newComingTargets); 1467 1468 void HandleAreaChangeDestruct(); 1469 1470 void ResetPredictNodes(); 1471 1472 bool isTrimMemRecycle_ = false; 1473 // sort in ZIndex. 1474 std::multiset<WeakPtr<FrameNode>, ZIndexComparator> frameChildren_; 1475 RefPtr<GeometryNode> geometryNode_ = MakeRefPtr<GeometryNode>(); 1476 1477 std::function<void()> colorModeUpdateCallback_; 1478 std::function<void(int32_t)> ndkColorModeUpdateCallback_; 1479 std::function<void(float, float)> ndkFontUpdateCallback_; 1480 RefPtr<AccessibilityProperty> accessibilityProperty_; 1481 bool hasAccessibilityVirtualNode_ = false; 1482 RefPtr<LayoutProperty> layoutProperty_; 1483 RefPtr<PaintProperty> paintProperty_; 1484 RefPtr<RenderContext> renderContext_ = RenderContext::Create(); 1485 RefPtr<EventHub> eventHub_; 1486 RefPtr<Pattern> pattern_; 1487 RefPtr<FocusHub> focusHub_; 1488 1489 RefPtr<ExtensionHandler> extensionHandler_; 1490 1491 RefPtr<FrameNode> backgroundNode_; 1492 std::function<RefPtr<UINode>()> builderFunc_; 1493 std::unique_ptr<RectF> lastFrameRect_; 1494 std::unique_ptr<OffsetF> lastParentOffsetToWindow_; 1495 std::shared_ptr<OffsetF> lastHostParentOffsetToWindow_; 1496 std::unique_ptr<RectF> lastFrameNodeRect_; 1497 std::set<std::string> allowDrop_; 1498 std::function<void()> removeCustomProperties_; 1499 std::function<std::string(const std::string& key)> getCustomProperty_; 1500 std::optional<RectF> viewPort_; 1501 NG::DragDropInfo dragPreviewInfo_; 1502 1503 RefPtr<LayoutAlgorithmWrapper> layoutAlgorithm_; 1504 RefPtr<GeometryNode> oldGeometryNode_; 1505 std::optional<bool> skipMeasureContent_; 1506 std::unique_ptr<FrameProxy> frameProxy_; 1507 WeakPtr<TargetComponent> targetComponent_; 1508 1509 bool needSyncRenderTree_ = false; 1510 1511 bool isPropertyDiffMarked_ = false; 1512 bool isLayoutDirtyMarked_ = false; 1513 bool isRenderDirtyMarked_ = false; 1514 bool isMeasureBoundary_ = false; 1515 bool hasPendingRequest_ = false; 1516 bool isPrivacySensitive_ = false; 1517 1518 // for container, this flag controls only the last child in touch area is consuming event. 1519 bool exclusiveEventForChild_ = false; 1520 bool isActive_ = false; 1521 bool accessibilityVisible_ = true; 1522 bool isResponseRegion_ = false; 1523 bool isLayoutComplete_ = false; 1524 bool isFirstBuilding_ = true; 1525 1526 double lastVisibleRatio_ = 0.0; 1527 double lastInnerVisibleRatio_ = 0.0; 1528 double lastVisibleCallbackRatio_ = 0.0; 1529 double lastInnerVisibleCallbackRatio_ = 0.0; 1530 double lastThrottledVisibleRatio_ = 0.0; 1531 double lastThrottledVisibleCbRatio_ = 0.0; 1532 int64_t lastThrottledTriggerTime_ = 0; 1533 bool throttledCallbackOnTheWay_ = false; 1534 1535 // internal node such as Text in Button CreateWithLabel 1536 // should not seen by preview inspector or accessibility 1537 bool isInternal_ = false; 1538 1539 std::string nodeName_; 1540 1541 ColorMode colorMode_ = ColorMode::LIGHT; 1542 1543 bool draggable_ = false; 1544 bool userSet_ = false; 1545 bool customerSet_ = false; 1546 bool isWindowBoundary_ = false; 1547 uint8_t suggestOpIncByte_ = 0; 1548 uint64_t getCacheNanoTime_ = 0; 1549 RectF prePaintRect_; 1550 1551 std::map<std::string, RefPtr<NodeAnimatablePropertyBase>> nodeAnimatablePropertyMap_; 1552 Matrix4 localMat_ = Matrix4::CreateIdentity(); 1553 // this is just used for the hit test process of event handling, do not used for other purpose 1554 CacheMatrixInfo cacheMatrixInfo_; 1555 // control the localMat_ and localRevertMatrix_ available or not, set to false when any transform info is set 1556 bool isTransformNotChanged_ = false; 1557 bool isFind_ = false; 1558 1559 bool isRestoreInfoUsed_ = false; 1560 bool checkboxFlag_ = false; 1561 bool isDisallowDropForcedly_ = false; 1562 bool isGeometryTransitionIn_ = false; 1563 bool isLayoutNode_ = false; 1564 bool isCalculateInnerVisibleRectClip_ = false; 1565 bool dragHitTestBlock_ = false; 1566 1567 bool isUseTransitionAnimator_ = false; 1568 1569 bool exposeInnerGestureFlag_ = false; 1570 bool isDeleteRsNode_ = false; 1571 bool hasPositionZ_ = false; 1572 1573 RefPtr<FrameNode> overlayNode_; 1574 1575 RefPtr<FrameNode> paintNode_; 1576 1577 RefPtr<FrameNode> accessibilityFocusPaintNode_; 1578 1579 std::unordered_map<std::string, int32_t> sceneRateMap_; 1580 1581 DragPreviewOption previewOption_; 1582 1583 std::unordered_map<std::string, std::vector<std::string>> customPropertyMap_; 1584 1585 std::unordered_map<std::string, void*> extraCustomPropertyMap_; 1586 1587 std::map<std::string, std::function<void()>> destroyCallbacks_; 1588 1589 RefPtr<Recorder::ExposureProcessor> exposureProcessor_; 1590 1591 std::pair<uint64_t, OffsetF> cachedGlobalOffset_ = { 0, OffsetF() }; 1592 std::pair<uint64_t, OffsetF> cachedTransformRelativeOffset_ = { 0, OffsetF() }; 1593 std::pair<uint64_t, bool> cachedIsFrameDisappear_ = { 0, false }; 1594 std::pair<uint64_t, CacheVisibleRectResult> cachedVisibleRectResult_ = { 0, CacheVisibleRectResult() }; 1595 1596 struct onSizeChangeDumpInfo { 1597 int64_t onSizeChangeTimeStamp; 1598 RectF lastFrameRect; 1599 RectF currFrameRect; 1600 }; 1601 std::vector<onSizeChangeDumpInfo> onSizeChangeDumpInfos; 1602 std::list<WeakPtr<FrameNode>> predictLayoutNode_; 1603 FrameNodeChangeInfoFlag changeInfoFlag_ = FRAME_NODE_CHANGE_INFO_NONE; 1604 std::optional<RectF> syncedFramePaintRect_; 1605 1606 int32_t childrenUpdatedFrom_ = -1; 1607 VisibleAreaChangeTriggerReason visibleAreaChangeTriggerReason_ = VisibleAreaChangeTriggerReason::IDLE; 1608 float preOpacity_ = 1.0f; 1609 std::function<void(int32_t)> frameNodeDestructorCallback_; 1610 1611 bool topWindowBoundary_ = false; 1612 1613 friend class RosenRenderContext; 1614 friend class RenderContext; 1615 friend class Pattern; 1616 mutable std::shared_mutex fontSizeCallbackMutex_; 1617 mutable std::shared_mutex colorModeCallbackMutex_; 1618 std::deque<std::pair<uint64_t, std::pair<VisibleType, bool>>> visibilityDumpInfos_; 1619 1620 RefPtr<Kit::FrameNode> kitNode_; 1621 ACE_DISALLOW_COPY_AND_MOVE(FrameNode); 1622 }; 1623 } // namespace OHOS::Ace::NG 1624 1625 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_BASE_FRAME_NODE_H 1626