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