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