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_PATTERNS_PATTERN_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_PATTERN_H 18 19 #include <optional> 20 21 #include "base/geometry/ng/rect_t.h" 22 #include "base/memory/ace_type.h" 23 #include "base/memory/referenced.h" 24 #include "base/utils/noncopyable.h" 25 #include "base/utils/utils.h" 26 #include "base/view_data/view_data_wrap.h" 27 #include "core/common/recorder/event_recorder.h" 28 #include "core/components_ng/base/frame_node.h" 29 #include "core/components_ng/event/event_hub.h" 30 #include "core/components_ng/layout/layout_property.h" 31 #include "core/components_ng/property/property.h" 32 #include "core/components_ng/render/node_paint_method.h" 33 #include "core/components_ng/render/paint_property.h" 34 #include "core/event/pointer_event.h" 35 36 namespace OHOS::Accessibility { 37 class AccessibilityElementInfo; 38 class AccessibilityEventInfo; 39 } 40 41 namespace OHOS::Ace::NG { 42 class AccessibilitySessionAdapter; 43 class InspectorFilter; 44 45 struct DirtySwapConfig { 46 bool frameSizeChange = false; 47 bool frameOffsetChange = false; 48 bool contentSizeChange = false; 49 bool contentOffsetChange = false; 50 bool skipMeasure = false; 51 bool skipLayout = false; 52 }; 53 54 class ScrollingListener : public AceType { 55 DECLARE_ACE_TYPE(ScrollingListener, AceType); 56 57 public: ScrollingListener(std::function<void ()> && callback)58 explicit ScrollingListener(std::function<void()>&& callback) : callback_(std::move(callback)) {} 59 60 ~ScrollingListener() override = default; 61 NotifyScrollingEvent()62 void NotifyScrollingEvent() 63 { 64 if (callback_) { 65 callback_(); 66 } 67 } 68 69 private: 70 std::function<void()> callback_; 71 }; 72 73 // Pattern is the base class for different measure, layout and paint behavior. 74 class ACE_FORCE_EXPORT Pattern : public virtual AceType { 75 DECLARE_ACE_TYPE(Pattern, AceType); 76 77 public: 78 Pattern() = default; 79 ~Pattern() override = default; 80 81 // atomic node is like button, image, custom node and so on. 82 // In ets UI compiler, the atomic node does not Add Pop function, only have Create function. IsAtomicNode()83 virtual bool IsAtomicNode() const 84 { 85 return true; 86 } 87 ConsumeChildrenAdjustment(const OffsetF &)88 virtual bool ConsumeChildrenAdjustment(const OffsetF& /* offset */) 89 { 90 return false; 91 } 92 IsNeedPercent()93 virtual bool IsNeedPercent() const 94 { 95 return false; 96 } 97 CheckCustomAvoidKeyboard()98 virtual bool CheckCustomAvoidKeyboard() const 99 { 100 return false; 101 } 102 IsSupportDrawModifier()103 virtual bool IsSupportDrawModifier() const 104 { 105 return true; 106 } 107 108 // The pattern needs softkeyboard is like search, rich editor, text area, text field pattern. NeedSoftKeyboard()109 virtual bool NeedSoftKeyboard() const 110 { 111 return false; 112 } 113 NeedToRequestKeyboardOnFocus()114 virtual bool NeedToRequestKeyboardOnFocus() const 115 { 116 return true; 117 } 118 DefaultSupportDrag()119 virtual bool DefaultSupportDrag() 120 { 121 return false; 122 } 123 GetContextParam()124 virtual std::optional<RenderContext::ContextParam> GetContextParam() const 125 { 126 return std::nullopt; 127 } 128 DetachFromFrameNode(FrameNode * frameNode)129 void DetachFromFrameNode(FrameNode* frameNode) 130 { 131 OnDetachFromFrameNode(frameNode); 132 frameNode_.Reset(); 133 } 134 AttachToFrameNode(const WeakPtr<FrameNode> & frameNode)135 void AttachToFrameNode(const WeakPtr<FrameNode>& frameNode) 136 { 137 if (frameNode_ == frameNode) { 138 return; 139 } 140 frameNode_ = frameNode; 141 OnAttachToFrameNode(); 142 } 143 CreateAccessibilityProperty()144 virtual RefPtr<AccessibilityProperty> CreateAccessibilityProperty() 145 { 146 return MakeRefPtr<AccessibilityProperty>(); 147 } 148 CreatePaintProperty()149 virtual RefPtr<PaintProperty> CreatePaintProperty() 150 { 151 return MakeRefPtr<PaintProperty>(); 152 } 153 CreateLayoutProperty()154 virtual RefPtr<LayoutProperty> CreateLayoutProperty() 155 { 156 return MakeRefPtr<LayoutProperty>(); 157 } 158 CreateLayoutAlgorithm()159 virtual RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() 160 { 161 return MakeRefPtr<BoxLayoutAlgorithm>(); 162 } 163 CreateNodePaintMethod()164 virtual RefPtr<NodePaintMethod> CreateNodePaintMethod() 165 { 166 return nullptr; 167 } 168 CreateDefaultNodePaintMethod()169 virtual RefPtr<NodePaintMethod> CreateDefaultNodePaintMethod() 170 { 171 return MakeRefPtr<NodePaintMethod>(); 172 } 173 GetOverridePaintRect()174 virtual std::optional<RectF> GetOverridePaintRect() const 175 { 176 return std::nullopt; 177 } 178 CreateEventHub()179 virtual RefPtr<EventHub> CreateEventHub() 180 { 181 return MakeRefPtr<EventHub>(); 182 } 183 OnContextAttached()184 virtual void OnContextAttached() {} 185 OpIncType()186 virtual OPINC_TYPE_E OpIncType() 187 { 188 return OPINC_NODE_POSSIBLE; 189 } 190 OnModifyDone()191 virtual void OnModifyDone() 192 { 193 #if (defined(__aarch64__) || defined(__x86_64__)) 194 if (IsNeedInitClickEventRecorder()) { 195 InitClickEventRecorder(); 196 } 197 #endif 198 CheckLocalized(); 199 auto* frameNode = GetUnsafeHostPtr(); 200 const auto& children = frameNode->GetChildren(); 201 if (children.empty()) { 202 return; 203 } 204 const auto& renderContext = frameNode->GetRenderContext(); 205 if (!renderContext->HasForegroundColor() && !renderContext->HasForegroundColorStrategy()) { 206 return; 207 } 208 std::list<RefPtr<FrameNode>> childrenList {}; 209 std::queue<RefPtr<FrameNode>> queue {}; 210 queue.emplace(Claim(frameNode)); 211 RefPtr<FrameNode> parentNode; 212 while (!queue.empty()) { 213 parentNode = queue.front(); 214 queue.pop(); 215 auto childs = parentNode->GetChildren(); 216 if (childs.empty()) { 217 continue; 218 } 219 for (auto child : childs) { 220 if (!AceType::InstanceOf<NG::FrameNode>(child)) { 221 continue; 222 } 223 auto childFrameNode = AceType::DynamicCast<FrameNode>(child); 224 auto childRenderContext = childFrameNode->GetRenderContext(); 225 if (childRenderContext->HasForegroundColorFlag() && childRenderContext->GetForegroundColorFlagValue()) { 226 continue; 227 } 228 queue.emplace(childFrameNode); 229 childrenList.emplace_back(childFrameNode); 230 } 231 } 232 UpdateChildRenderContext(renderContext, childrenList); 233 } 234 UpdateChildRenderContext(const RefPtr<RenderContext> & renderContext,std::list<RefPtr<FrameNode>> & childrenList)235 void UpdateChildRenderContext( 236 const RefPtr<RenderContext>& renderContext, std::list<RefPtr<FrameNode>>& childrenList) 237 { 238 bool isForegroundColor = renderContext->HasForegroundColor(); 239 for (auto child : childrenList) { 240 auto childRenderContext = child->GetRenderContext(); 241 if (!childRenderContext->HasForegroundColor() && !childRenderContext->HasForegroundColorStrategy()) { 242 if (isForegroundColor) { 243 childRenderContext->UpdateForegroundColor(renderContext->GetForegroundColorValue()); 244 childRenderContext->ResetForegroundColorStrategy(); 245 childRenderContext->UpdateForegroundColorFlag(false); 246 } else { 247 childRenderContext->UpdateForegroundColorStrategy(renderContext->GetForegroundColorStrategyValue()); 248 childRenderContext->ResetForegroundColor(); 249 childRenderContext->UpdateForegroundColorFlag(false); 250 } 251 } else { 252 if (!childRenderContext->HasForegroundColorFlag()) { 253 continue; 254 } 255 if (childRenderContext->GetForegroundColorFlagValue()) { 256 continue; 257 } 258 if (isForegroundColor) { 259 childRenderContext->UpdateForegroundColor(renderContext->GetForegroundColorValue()); 260 childRenderContext->ResetForegroundColorStrategy(); 261 childRenderContext->UpdateForegroundColorFlag(false); 262 } else { 263 childRenderContext->UpdateForegroundColorStrategy(renderContext->GetForegroundColorStrategyValue()); 264 childRenderContext->ResetForegroundColor(); 265 childRenderContext->UpdateForegroundColorFlag(false); 266 } 267 } 268 } 269 } 270 OnAfterModifyDone()271 virtual void OnAfterModifyDone() {} 272 OnMountToParentDone()273 virtual void OnMountToParentDone() {} 274 AfterMountToParent()275 virtual void AfterMountToParent() {} 276 OnSensitiveStyleChange(bool isSensitive)277 virtual void OnSensitiveStyleChange(bool isSensitive) {} 278 AllowVisibleAreaCheck()279 virtual bool AllowVisibleAreaCheck() const 280 { 281 return false; 282 } 283 IsRootPattern()284 virtual bool IsRootPattern() const 285 { 286 return false; 287 } 288 IsMeasureBoundary()289 virtual bool IsMeasureBoundary() const 290 { 291 return false; 292 } 293 IsRenderBoundary()294 virtual bool IsRenderBoundary() const 295 { 296 return true; 297 } 298 NotifyForNextTouchEvent()299 virtual void NotifyForNextTouchEvent() {} 300 OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper> &,bool,bool)301 virtual bool OnDirtyLayoutWrapperSwap( 302 const RefPtr<LayoutWrapper>& /*dirty*/, bool /*skipMeasure*/, bool /*skipLayout*/) 303 { 304 return false; 305 } 306 BeforeSyncGeometryProperties(const DirtySwapConfig & config)307 virtual void BeforeSyncGeometryProperties(const DirtySwapConfig& config) {} OnSyncGeometryNode(const DirtySwapConfig & config)308 virtual void OnSyncGeometryNode(const DirtySwapConfig& config) {} 309 310 // Called on main thread to check if need rerender of the content. OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper> &,const DirtySwapConfig &)311 virtual bool OnDirtyLayoutWrapperSwap( 312 const RefPtr<LayoutWrapper>& /*dirty*/, const DirtySwapConfig& /*changeConfig*/) 313 { 314 return false; 315 } 316 UsResRegion()317 virtual bool UsResRegion() 318 { 319 return true; 320 } 321 GetHostFrameSize()322 std::optional<SizeF> GetHostFrameSize() const 323 { 324 auto frameNode = frameNode_.Upgrade(); 325 if (!frameNode) { 326 return std::nullopt; 327 } 328 return frameNode->GetGeometryNode()->GetMarginFrameSize(); 329 } 330 GetHostFrameOffset()331 std::optional<OffsetF> GetHostFrameOffset() const 332 { 333 auto frameNode = frameNode_.Upgrade(); 334 if (!frameNode) { 335 return std::nullopt; 336 } 337 return frameNode->GetGeometryNode()->GetFrameOffset(); 338 } 339 GetHostFrameGlobalOffset()340 std::optional<OffsetF> GetHostFrameGlobalOffset() const 341 { 342 auto frameNode = frameNode_.Upgrade(); 343 if (!frameNode) { 344 return std::nullopt; 345 } 346 return frameNode->GetGeometryNode()->GetFrameOffset() + frameNode->GetGeometryNode()->GetParentGlobalOffset(); 347 } 348 GetHostContentSize()349 std::optional<SizeF> GetHostContentSize() const 350 { 351 auto frameNode = frameNode_.Upgrade(); 352 if (!frameNode) { 353 return std::nullopt; 354 } 355 const auto& content = frameNode->GetGeometryNode()->GetContent(); 356 if (!content) { 357 return std::nullopt; 358 } 359 return content->GetRect().GetSize(); 360 } 361 GetHost()362 RefPtr<FrameNode> GetHost() const 363 { 364 return frameNode_.Upgrade(); 365 } 366 GetHostInstanceId()367 int32_t GetHostInstanceId() const 368 { 369 auto host = GetHost(); 370 CHECK_NULL_RETURN(host, -1); // -1 means no valid id exists 371 return host->GetInstanceId(); 372 } 373 GetUnsafeHostPtr()374 FrameNode* GetUnsafeHostPtr() const 375 { 376 return UnsafeRawPtr(frameNode_); 377 } 378 GetContext()379 PipelineContext* GetContext() 380 { 381 auto frameNode = GetUnsafeHostPtr(); 382 CHECK_NULL_RETURN(frameNode, nullptr); 383 return frameNode->GetContext(); 384 } 385 DumpInfo()386 virtual void DumpInfo() {} DumpSimplifyInfo(std::unique_ptr<JsonValue> & json)387 virtual void DumpSimplifyInfo(std::unique_ptr<JsonValue>& json) {} DumpAdvanceInfo()388 virtual void DumpAdvanceInfo() {} 389 virtual void DumpViewDataPageNode(RefPtr<ViewDataWrap> viewDataWrap, bool needsRecordData = false) {} NotifyFillRequestSuccess(RefPtr<ViewDataWrap> viewDataWrap,RefPtr<PageNodeInfoWrap> nodeWrap,AceAutoFillType autoFillType)390 virtual void NotifyFillRequestSuccess(RefPtr<ViewDataWrap> viewDataWrap, 391 RefPtr<PageNodeInfoWrap> nodeWrap, AceAutoFillType autoFillType) {} 392 virtual void NotifyFillRequestFailed(int32_t errCode, const std::string& fillContent = "", bool isPopup = false) {} CheckAutoSave()393 virtual bool CheckAutoSave() 394 { 395 return false; 396 } 397 398 template<typename T> GetLayoutProperty()399 RefPtr<T> GetLayoutProperty() const 400 { 401 auto host = GetHost(); 402 CHECK_NULL_RETURN(host, nullptr); 403 return DynamicCast<T>(host->GetLayoutProperty<T>()); 404 } 405 406 template<typename T> GetPaintProperty()407 RefPtr<T> GetPaintProperty() const 408 { 409 auto host = GetHost(); 410 CHECK_NULL_RETURN(host, nullptr); 411 return DynamicCast<T>(host->GetPaintProperty<T>()); 412 } 413 414 template<typename T> GetEventHub()415 RefPtr<T> GetEventHub() const 416 { 417 auto host = GetHost(); 418 CHECK_NULL_RETURN(host, nullptr); 419 return DynamicCast<T>(host->GetEventHub<T>()); 420 } 421 422 // Called after frameNode RebuildRenderContextTree. OnRebuildFrame()423 virtual void OnRebuildFrame() {} 424 // Called before frameNode CreateLayoutWrapper. BeforeCreateLayoutWrapper()425 virtual void BeforeCreateLayoutWrapper() {} 426 // Called before frameNode CreatePaintWrapper. BeforeCreatePaintWrapper()427 virtual void BeforeCreatePaintWrapper() {} 428 GetFocusPattern()429 virtual FocusPattern GetFocusPattern() const 430 { 431 return { FocusType::DISABLE, false, FocusStyleType::NONE }; 432 } 433 GetScopeFocusAlgorithm()434 virtual ScopeFocusAlgorithm GetScopeFocusAlgorithm() 435 { 436 return ScopeFocusAlgorithm(); 437 } 438 ScrollToNode(const RefPtr<FrameNode> & focusFrameNode)439 virtual bool ScrollToNode(const RefPtr<FrameNode>& focusFrameNode) 440 { 441 return false; 442 } 443 GetFocusNodeIndex(const RefPtr<FocusHub> & focusNode)444 virtual int32_t GetFocusNodeIndex(const RefPtr<FocusHub>& focusNode) 445 { 446 return -1; 447 } 448 ScrollToFocusNodeIndex(int32_t index)449 virtual void ScrollToFocusNodeIndex(int32_t index) {} 450 451 // out of viewport or visible is none or gone. OnInActive()452 virtual void OnInActive() {} OnActive()453 virtual void OnActive() {} 454 455 // called by window life cycle. OnWindowShow()456 virtual void OnWindowShow() {} OnWindowHide()457 virtual void OnWindowHide() {} OnWindowFocused()458 virtual void OnWindowFocused() {} OnWindowUnfocused()459 virtual void OnWindowUnfocused() {} OnPixelRoundFinish(const SizeF & pixelGridRoundSize)460 virtual void OnPixelRoundFinish(const SizeF& pixelGridRoundSize) {} OnWindowSizeChanged(int32_t width,int32_t height,WindowSizeChangeReason type)461 virtual void OnWindowSizeChanged(int32_t width, int32_t height, WindowSizeChangeReason type) {} OnNotifyMemoryLevel(int32_t level)462 virtual void OnNotifyMemoryLevel(int32_t level) {} 463 464 // get XTS inspector value ToJsonValue(std::unique_ptr<JsonValue> & json,const InspectorFilter & filter)465 virtual void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const {} 466 467 // call by recycle framework. OnRecycle()468 virtual void OnRecycle() {} OnReuse()469 virtual void OnReuse() {} 470 OnAttachToMainTree()471 virtual void OnAttachToMainTree() {} OnAttachToBuilderNode(NodeStatus nodeStatus)472 virtual void OnAttachToBuilderNode(NodeStatus nodeStatus) {} 473 OnDetachFromMainTree()474 virtual void OnDetachFromMainTree() {} 475 FromJson(const std::unique_ptr<JsonValue> & json)476 virtual void FromJson(const std::unique_ptr<JsonValue>& json) {} 477 OnAreaChangedInner()478 virtual void OnAreaChangedInner() {} OnVisibleChange(bool isVisible)479 virtual void OnVisibleChange(bool isVisible) {} ProvideRestoreInfo()480 virtual std::string ProvideRestoreInfo() 481 { 482 return ""; 483 } 484 OnRestoreInfo(const std::string & restoreInfo)485 virtual void OnRestoreInfo(const std::string& restoreInfo) {} 486 IsNeedAdjustByAspectRatio()487 virtual bool IsNeedAdjustByAspectRatio() 488 { 489 auto host = GetHost(); 490 CHECK_NULL_RETURN(host, false); 491 auto layoutProperty = host->GetLayoutProperty(); 492 CHECK_NULL_RETURN(host, false); 493 return layoutProperty->HasAspectRatio(); 494 } 495 OnTouchTestHit(SourceType hitTestType)496 virtual void OnTouchTestHit(SourceType hitTestType) {} 497 GetDragRecordSize()498 virtual int32_t GetDragRecordSize() 499 { 500 return -1; 501 } 502 HandleOnDragStatusCallback(const DragEventType & dragEventType,const RefPtr<NotifyDragEvent> & notifyDragEvent)503 virtual void HandleOnDragStatusCallback( 504 const DragEventType& dragEventType, const RefPtr<NotifyDragEvent>& notifyDragEvent) {}; 505 HandleDragEvent(const PointerEvent & info)506 virtual void HandleDragEvent(const PointerEvent& info) {}; OnLanguageConfigurationUpdate()507 virtual void OnLanguageConfigurationUpdate() {} OnColorConfigurationUpdate()508 virtual void OnColorConfigurationUpdate() {} OnDirectionConfigurationUpdate()509 virtual void OnDirectionConfigurationUpdate() {} OnDpiConfigurationUpdate()510 virtual void OnDpiConfigurationUpdate() {} OnIconConfigurationUpdate()511 virtual void OnIconConfigurationUpdate() {} OnFontConfigurationUpdate()512 virtual void OnFontConfigurationUpdate() {} OnFontScaleConfigurationUpdate()513 virtual void OnFontScaleConfigurationUpdate() {} 514 ResetDragOption()515 virtual void ResetDragOption() {} 516 WrapExtensionAbilityId(int64_t extensionOffset,int64_t abilityId)517 virtual int64_t WrapExtensionAbilityId(int64_t extensionOffset, int64_t abilityId) 518 { 519 return -1; 520 } 521 SearchExtensionElementInfoByAccessibilityId(int64_t elementId,int32_t mode,int64_t baseParent,std::list<Accessibility::AccessibilityElementInfo> & output)522 virtual void SearchExtensionElementInfoByAccessibilityId(int64_t elementId, int32_t mode, 523 int64_t baseParent, std::list<Accessibility::AccessibilityElementInfo>& output) {} SearchElementInfosByText(int64_t elementId,const std::string & text,int64_t baseParent,std::list<Accessibility::AccessibilityElementInfo> & output)524 virtual void SearchElementInfosByText(int64_t elementId, const std::string& text, 525 int64_t baseParent, std::list<Accessibility::AccessibilityElementInfo>& output) {} FindFocusedElementInfo(int64_t elementId,int32_t focusType,int64_t baseParent,Accessibility::AccessibilityElementInfo & output)526 virtual void FindFocusedElementInfo(int64_t elementId, int32_t focusType, 527 int64_t baseParent, Accessibility::AccessibilityElementInfo& output) {} FocusMoveSearch(int64_t elementId,int32_t direction,int64_t baseParent,Accessibility::AccessibilityElementInfo & output)528 virtual void FocusMoveSearch(int64_t elementId, int32_t direction, 529 int64_t baseParent, Accessibility::AccessibilityElementInfo& output) {} TransferExecuteAction(int64_t elementId,const std::map<std::string,std::string> & actionArguments,int32_t action,int64_t offset)530 virtual bool TransferExecuteAction( 531 int64_t elementId, const std::map<std::string, std::string>& actionArguments, int32_t action, int64_t offset) 532 { 533 return false; 534 } 535 GetAccessibilitySessionAdapter()536 virtual RefPtr<AccessibilitySessionAdapter> GetAccessibilitySessionAdapter() 537 { 538 return nullptr; 539 } 540 GetUiExtensionId()541 virtual int32_t GetUiExtensionId() 542 { 543 return -1; 544 } 545 ShouldDelayChildPressedState()546 virtual bool ShouldDelayChildPressedState() const 547 { 548 return false; 549 } 550 RegisterScrollingListener(const RefPtr<ScrollingListener> listener)551 virtual void RegisterScrollingListener(const RefPtr<ScrollingListener> listener) {} FireAndCleanScrollingListener()552 virtual void FireAndCleanScrollingListener() {} CleanScrollingListener()553 virtual void CleanScrollingListener() {} 554 GetLongPressEventRecorder()555 GestureEventFunc GetLongPressEventRecorder() 556 { 557 auto longPressCallback = [weak = WeakClaim(this)](GestureEvent& info) { 558 if (!Recorder::EventRecorder::Get().IsComponentRecordEnable()) { 559 return; 560 } 561 auto pattern = weak.Upgrade(); 562 CHECK_NULL_VOID(pattern); 563 auto host = pattern->GetHost(); 564 CHECK_NULL_VOID(host); 565 auto inspectorId = host->GetInspectorId().value_or(""); 566 auto text = host->GetAccessibilityProperty<NG::AccessibilityProperty>()->GetGroupText(true); 567 auto desc = host->GetAutoEventParamValue(""); 568 if (inspectorId.empty() && text.empty() && desc.empty()) { 569 return; 570 } 571 572 Recorder::EventParamsBuilder builder; 573 builder.SetId(inspectorId) 574 .SetType(host->GetTag()) 575 .SetEventType(Recorder::LONG_PRESS) 576 .SetText(text) 577 .SetDescription(desc); 578 Recorder::EventRecorder::Get().OnEvent(std::move(builder)); 579 }; 580 return longPressCallback; 581 } 582 OnAttachContext(PipelineContext * context)583 virtual void OnAttachContext(PipelineContext *context) {} OnDetachContext(PipelineContext * context)584 virtual void OnDetachContext(PipelineContext *context) {} SetFrameRateRange(const RefPtr<FrameRateRange> & rateRange,SwiperDynamicSyncSceneType type)585 virtual void SetFrameRateRange(const RefPtr<FrameRateRange>& rateRange, SwiperDynamicSyncSceneType type) {} 586 CheckLocalized()587 void CheckLocalized() 588 { 589 auto host = GetHost(); 590 CHECK_NULL_VOID(host); 591 auto layoutProperty = host->GetLayoutProperty(); 592 CHECK_NULL_VOID(layoutProperty); 593 auto layoutDirection = layoutProperty->GetNonAutoLayoutDirection(); 594 if (layoutProperty->IsPositionLocalizedEdges()) { 595 layoutProperty->CheckPositionLocalizedEdges(layoutDirection); 596 } 597 if (layoutProperty->IsMarkAnchorPosition()) { 598 layoutProperty->CheckMarkAnchorPosition(layoutDirection); 599 } 600 if (layoutProperty->IsOffsetLocalizedEdges()) { 601 layoutProperty->CheckOffsetLocalizedEdges(layoutDirection); 602 } 603 layoutProperty->CheckLocalizedPadding(layoutProperty, layoutDirection); 604 layoutProperty->CheckLocalizedMargin(layoutProperty, layoutDirection); 605 layoutProperty->CheckLocalizedEdgeWidths(layoutProperty, layoutDirection); 606 layoutProperty->CheckLocalizedEdgeColors(layoutDirection); 607 layoutProperty->CheckLocalizedBorderRadiuses(layoutDirection); 608 layoutProperty->CheckLocalizedOuterBorderColor(layoutDirection); 609 layoutProperty->CheckLocalizedBorderImageSlice(layoutDirection); 610 layoutProperty->CheckLocalizedBorderImageWidth(layoutDirection); 611 layoutProperty->CheckLocalizedBorderImageOutset(layoutDirection); 612 } 613 OnFrameNodeChanged(FrameNodeChangeInfoFlag flag)614 virtual void OnFrameNodeChanged(FrameNodeChangeInfoFlag flag) {} 615 IsResponseRegionExpandingNeededForStylus(const TouchEvent & touchEvent)616 virtual bool IsResponseRegionExpandingNeededForStylus(const TouchEvent& touchEvent) const 617 { 618 return false; 619 } 620 ExpandDefaultResponseRegion(RectF & rect)621 virtual RectF ExpandDefaultResponseRegion(RectF& rect) 622 { 623 return RectF(); 624 } 625 OnAccessibilityHoverEvent(const PointF & point)626 virtual bool OnAccessibilityHoverEvent(const PointF& point) 627 { 628 return false; 629 } 630 NotifyDataChange(int32_t index,int32_t count)631 virtual void NotifyDataChange(int32_t index, int32_t count) {}; 632 GetWindowPatternType()633 virtual uint32_t GetWindowPatternType() const 634 { 635 return 0; 636 } 637 TriggerAutoSaveWhenInvisible()638 virtual bool TriggerAutoSaveWhenInvisible() 639 { 640 return false; 641 } 642 AddInnerOnGestureRecognizerJudgeBegin(GestureRecognizerJudgeFunc && gestureRecognizerJudgeFunc)643 virtual void AddInnerOnGestureRecognizerJudgeBegin( 644 GestureRecognizerJudgeFunc&& gestureRecognizerJudgeFunc) {}; 645 RenderCustomChild(int64_t deadline)646 virtual bool RenderCustomChild(int64_t deadline) 647 { 648 return true; 649 } 650 651 protected: OnAttachToFrameNode()652 virtual void OnAttachToFrameNode() {} OnDetachFromFrameNode(FrameNode * frameNode)653 virtual void OnDetachFromFrameNode(FrameNode* frameNode) {} 654 IsNeedInitClickEventRecorder()655 virtual bool IsNeedInitClickEventRecorder() const 656 { 657 return false; 658 } 659 InitClickEventRecorder()660 void InitClickEventRecorder() 661 { 662 auto host = GetHost(); 663 CHECK_NULL_VOID(host); 664 auto gesture = host->GetOrCreateGestureEventHub(); 665 CHECK_NULL_VOID(gesture); 666 if (!gesture->IsUserClickable()) { 667 if (clickCallback_) { 668 gesture->RemoveClickEvent(clickCallback_); 669 clickCallback_ = nullptr; 670 } 671 return; 672 } 673 674 if (clickCallback_) { 675 return; 676 } 677 678 auto clickCallback = [weak = WeakClaim(this)](GestureEvent& info) { 679 if (!Recorder::EventRecorder::Get().IsComponentRecordEnable()) { 680 return; 681 } 682 auto pattern = weak.Upgrade(); 683 CHECK_NULL_VOID(pattern); 684 auto host = pattern->GetHost(); 685 CHECK_NULL_VOID(host); 686 auto inspectorId = host->GetInspectorId().value_or(""); 687 auto text = host->GetAccessibilityProperty<NG::AccessibilityProperty>()->GetGroupText(true); 688 auto desc = host->GetAutoEventParamValue(""); 689 if (inspectorId.empty() && text.empty() && desc.empty()) { 690 return; 691 } 692 693 Recorder::EventParamsBuilder builder; 694 builder.SetId(inspectorId).SetType(host->GetTag()).SetText(text).SetDescription(desc); 695 Recorder::EventRecorder::Get().OnClick(std::move(builder)); 696 }; 697 clickCallback_ = MakeRefPtr<ClickEvent>(std::move(clickCallback)); 698 gesture->AddClickEvent(clickCallback_); 699 } 700 701 WeakPtr<FrameNode> frameNode_; 702 RefPtr<ClickEvent> clickCallback_; 703 704 private: 705 ACE_DISALLOW_COPY_AND_MOVE(Pattern); 706 }; 707 } // namespace OHOS::Ace::NG 708 709 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_PATTERN_H 710