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