• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/common/resource/pattern_resource_manager.h"
31 #include "core/components_ng/base/frame_node.h"
32 #include "core/components_ng/event/event_hub.h"
33 #include "core/components_ng/layout/layout_property.h"
34 #include "core/components_ng/property/property.h"
35 #include "core/components_ng/render/node_paint_method.h"
36 #include "core/components_ng/render/paint_property.h"
37 #include "core/event/pointer_event.h"
38 #include "core/common/container_consts.h"
39 
40 struct _ArkUINodeAdapter;
41 typedef _ArkUINodeAdapter* ArkUINodeAdapterHandle;
42 
43 namespace OHOS::Accessibility {
44 class AccessibilityElementInfo;
45 class AccessibilityEventInfo;
46 }
47 
48 namespace OHOS::Ace::NG {
49 class AccessibilitySessionAdapter;
50 class InspectorFilter;
51 
52 class ScrollingListener : public AceType {
53     DECLARE_ACE_TYPE(ScrollingListener, AceType);
54 
55 public:
ScrollingListener(std::function<void ()> && callback)56     explicit ScrollingListener(std::function<void()>&& callback) : callback_(std::move(callback)) {}
57 
58     ~ScrollingListener() override = default;
59 
NotifyScrollingEvent()60     void NotifyScrollingEvent()
61     {
62         if (callback_) {
63             callback_();
64         }
65     }
66 
67 private:
68     std::function<void()> callback_;
69 };
70 
71 // Pattern is the base class for different measure, layout and paint behavior.
72 class ACE_FORCE_EXPORT Pattern : public virtual AceType {
73     DECLARE_ACE_TYPE(Pattern, AceType);
74 
75 public:
76     Pattern() = default;
77     ~Pattern() override = default;
78 
79     // atomic node is like button, image, custom node and so on.
80     // In ets UI compiler, the atomic node does not Add Pop function, only have Create function.
IsAtomicNode()81     virtual bool IsAtomicNode() const
82     {
83         return true;
84     }
85 
ConsumeChildrenAdjustment(const OffsetF &)86     virtual bool ConsumeChildrenAdjustment(const OffsetF& /* offset */)
87     {
88         return false;
89     }
90 
OnForegroundColorUpdate()91     virtual void OnForegroundColorUpdate() {}
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 
IsEnableMatchParent()126     virtual bool IsEnableMatchParent()
127     {
128         return false;
129     }
130 
IsEnableChildrenMatchParent()131     virtual bool IsEnableChildrenMatchParent()
132     {
133         return false;
134     }
135 
IsEnableFix()136     virtual bool IsEnableFix()
137     {
138         return false;
139     }
140 
GetContextParam()141     virtual std::optional<RenderContext::ContextParam> GetContextParam() const
142     {
143         return std::nullopt;
144     }
145 
DetachFromFrameNode(FrameNode * frameNode)146     void DetachFromFrameNode(FrameNode* frameNode)
147     {
148         onDetach_ = true;
149         OnDetachFromFrameNode(frameNode);
150         onDetach_ = false;
151         frameNode_.Reset();
152     }
153 
AttachToFrameNode(const WeakPtr<FrameNode> & frameNode)154     void AttachToFrameNode(const WeakPtr<FrameNode>& frameNode)
155     {
156         if (frameNode_ == frameNode) {
157             return;
158         }
159         frameNode_ = frameNode;
160         OnAttachToFrameNode();
161     }
162 
CustomizeExpandSafeArea()163     virtual bool CustomizeExpandSafeArea()
164     {
165         return false;
166     }
167 
CreateAccessibilityProperty()168     virtual RefPtr<AccessibilityProperty> CreateAccessibilityProperty()
169     {
170         return MakeRefPtr<AccessibilityProperty>();
171     }
172 
CreatePaintProperty()173     virtual RefPtr<PaintProperty> CreatePaintProperty()
174     {
175         return MakeRefPtr<PaintProperty>();
176     }
177 
CreateLayoutProperty()178     virtual RefPtr<LayoutProperty> CreateLayoutProperty()
179     {
180         return MakeRefPtr<LayoutProperty>();
181     }
182 
CreateLayoutAlgorithm()183     virtual RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm()
184     {
185         return MakeRefPtr<BoxLayoutAlgorithm>();
186     }
187 
CreateNodePaintMethod()188     virtual RefPtr<NodePaintMethod> CreateNodePaintMethod()
189     {
190         return nullptr;
191     }
192 
CreateDefaultNodePaintMethod()193     virtual RefPtr<NodePaintMethod> CreateDefaultNodePaintMethod()
194     {
195         return MakeRefPtr<NodePaintMethod>();
196     }
197 
GetOverridePaintRect()198     virtual std::optional<RectF> GetOverridePaintRect() const
199     {
200         return std::nullopt;
201     }
202 
CreateEventHub()203     virtual RefPtr<EventHub> CreateEventHub()
204     {
205         return MakeRefPtr<EventHub>();
206     }
207 
OnContextAttached()208     virtual void OnContextAttached() {}
209 
OpIncType()210     virtual OPINC_TYPE_E OpIncType()
211     {
212         return OPINC_NODE_POSSIBLE;
213     }
214 
OnModifyDone()215     virtual void OnModifyDone()
216     {
217         CheckLocalized();
218         auto frameNode = GetHost();
219         const auto& children = frameNode->GetChildren();
220         if (children.empty()) {
221             return;
222         }
223         const auto& renderContext = frameNode->GetRenderContext();
224         if (!renderContext->HasForegroundColor() && !renderContext->HasForegroundColorStrategy()) {
225             return;
226         }
227         std::list<RefPtr<FrameNode>> childrenList {};
228         std::queue<RefPtr<FrameNode>> queue {};
229         queue.emplace(frameNode);
230         RefPtr<FrameNode> parentNode;
231         while (!queue.empty()) {
232             parentNode = queue.front();
233             queue.pop();
234             auto childs = parentNode->GetChildren();
235             if (childs.empty()) {
236                 continue;
237             }
238             for (auto child : childs) {
239                 if (!AceType::InstanceOf<NG::FrameNode>(child)) {
240                     continue;
241                 }
242                 auto childFrameNode = AceType::DynamicCast<FrameNode>(child);
243                 auto childRenderContext = childFrameNode->GetRenderContext();
244                 if (childRenderContext->HasForegroundColorFlag() && childRenderContext->GetForegroundColorFlagValue()) {
245                     continue;
246                 }
247                 queue.emplace(childFrameNode);
248                 childrenList.emplace_back(childFrameNode);
249             }
250         }
251         UpdateChildRenderContext(renderContext, childrenList);
252     }
253 
UpdateChildRenderContext(const RefPtr<RenderContext> & renderContext,std::list<RefPtr<FrameNode>> & childrenList)254     void UpdateChildRenderContext(
255         const RefPtr<RenderContext>& renderContext, std::list<RefPtr<FrameNode>>& childrenList)
256     {
257         bool isForegroundColor = renderContext->HasForegroundColor();
258         for (auto child : childrenList) {
259             auto childRenderContext = child->GetRenderContext();
260             if (!childRenderContext->HasForegroundColor() && !childRenderContext->HasForegroundColorStrategy()) {
261                 if (isForegroundColor) {
262                     childRenderContext->UpdateForegroundColor(renderContext->GetForegroundColorValue());
263                     childRenderContext->ResetForegroundColorStrategy();
264                     childRenderContext->UpdateForegroundColorFlag(false);
265                 } else {
266                     childRenderContext->UpdateForegroundColorStrategy(renderContext->GetForegroundColorStrategyValue());
267                     childRenderContext->ResetForegroundColor();
268                     childRenderContext->UpdateForegroundColorFlag(false);
269                 }
270             } else {
271                 if (!childRenderContext->HasForegroundColorFlag()) {
272                     continue;
273                 }
274                 if (childRenderContext->GetForegroundColorFlagValue()) {
275                     continue;
276                 }
277                 if (isForegroundColor) {
278                     childRenderContext->UpdateForegroundColor(renderContext->GetForegroundColorValue());
279                     childRenderContext->ResetForegroundColorStrategy();
280                     childRenderContext->UpdateForegroundColorFlag(false);
281                 } else {
282                     childRenderContext->UpdateForegroundColorStrategy(renderContext->GetForegroundColorStrategyValue());
283                     childRenderContext->ResetForegroundColor();
284                     childRenderContext->UpdateForegroundColorFlag(false);
285                 }
286             }
287         }
288     }
289 
OnAfterModifyDone()290     virtual void OnAfterModifyDone() {}
291 
OnMountToParentDone()292     virtual void OnMountToParentDone() {}
293 
AfterMountToParent()294     virtual void AfterMountToParent() {}
295 
OnSensitiveStyleChange(bool isSensitive)296     virtual void OnSensitiveStyleChange(bool isSensitive) {}
297 
AllowVisibleAreaCheck()298     virtual bool AllowVisibleAreaCheck() const
299     {
300         return false;
301     }
302 
IsRootPattern()303     virtual bool IsRootPattern() const
304     {
305         return false;
306     }
307 
IsMeasureBoundary()308     virtual bool IsMeasureBoundary() const
309     {
310         return false;
311     }
312 
IsRenderBoundary()313     virtual bool IsRenderBoundary() const
314     {
315         return true;
316     }
317 
NotifyForNextTouchEvent()318     virtual void NotifyForNextTouchEvent() {}
319 
OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper> &,bool,bool)320     virtual bool OnDirtyLayoutWrapperSwap(
321         const RefPtr<LayoutWrapper>& /*dirty*/, bool /*skipMeasure*/, bool /*skipLayout*/)
322     {
323         return false;
324     }
325 
BeforeSyncGeometryProperties(const DirtySwapConfig & config)326     virtual void BeforeSyncGeometryProperties(const DirtySwapConfig& config) {}
OnSyncGeometryNode(const DirtySwapConfig & config)327     virtual void OnSyncGeometryNode(const DirtySwapConfig& config) {}
328 
329     // Called on main thread to check if need rerender of the content.
OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper> &,const DirtySwapConfig &)330     virtual bool OnDirtyLayoutWrapperSwap(
331         const RefPtr<LayoutWrapper>& /*dirty*/, const DirtySwapConfig& /*changeConfig*/)
332     {
333         return false;
334     }
335 
UsResRegion()336     virtual bool UsResRegion()
337     {
338         return true;
339     }
340 
GetHostFrameSize()341     std::optional<SizeF> GetHostFrameSize() const
342     {
343         auto frameNode = frameNode_.Upgrade();
344         if (!frameNode) {
345             return std::nullopt;
346         }
347         return frameNode->GetGeometryNode()->GetMarginFrameSize();
348     }
349 
GetHostFrameOffset()350     std::optional<OffsetF> GetHostFrameOffset() const
351     {
352         auto frameNode = frameNode_.Upgrade();
353         if (!frameNode) {
354             return std::nullopt;
355         }
356         return frameNode->GetGeometryNode()->GetFrameOffset();
357     }
358 
GetHostFrameGlobalOffset()359     std::optional<OffsetF> GetHostFrameGlobalOffset() const
360     {
361         auto frameNode = frameNode_.Upgrade();
362         if (!frameNode) {
363             return std::nullopt;
364         }
365         return frameNode->GetGeometryNode()->GetFrameOffset() + frameNode->GetGeometryNode()->GetParentGlobalOffset();
366     }
367 
GetHostContentSize()368     std::optional<SizeF> GetHostContentSize() const
369     {
370         auto frameNode = frameNode_.Upgrade();
371         if (!frameNode) {
372             return std::nullopt;
373         }
374         const auto& content = frameNode->GetGeometryNode()->GetContent();
375         if (!content) {
376             return std::nullopt;
377         }
378         return content->GetRect().GetSize();
379     }
380 
GetHost()381     RefPtr<FrameNode> GetHost() const
382     {
383         if (onDetach_ && SystemProperties::DetectGetHostOnDetach()) {
384             LOGF_ABORT("fatal: can't GetHost at detaching period");
385         }
386         return frameNode_.Upgrade();
387     }
388 
GetHostInstanceId()389     int32_t GetHostInstanceId() const
390     {
391         auto host = GetHost();
392         CHECK_NULL_RETURN(host, INSTANCE_ID_UNDEFINED);
393         return host->GetInstanceId();
394     }
395 
GetContext()396     PipelineContext* GetContext() const
397     {
398         auto frameNode = GetHost();
399         CHECK_NULL_RETURN(frameNode, nullptr);
400         return frameNode->GetContext();
401     }
402 
GetRenderContext()403     RenderContext* GetRenderContext() const
404     {
405         auto frameNode = GetHost();
406         CHECK_NULL_RETURN(frameNode, nullptr);
407         return frameNode->GetRenderContext().GetRawPtr();
408     }
409 
DumpInfo()410     virtual void DumpInfo() {}
DumpInfo(std::unique_ptr<JsonValue> & json)411     virtual void DumpInfo(std::unique_ptr<JsonValue>& json) {}
DumpSimplifyInfo(std::unique_ptr<JsonValue> & json)412     virtual void DumpSimplifyInfo(std::unique_ptr<JsonValue>& json) {}
DumpAdvanceInfo()413     virtual void DumpAdvanceInfo() {}
DumpAdvanceInfo(std::unique_ptr<JsonValue> & json)414     virtual void DumpAdvanceInfo(std::unique_ptr<JsonValue>& json) {}
415     virtual void DumpViewDataPageNode(RefPtr<ViewDataWrap> viewDataWrap, bool needsRecordData = false) {}
DumpSimplifyInfo(std::shared_ptr<JsonValue> & json)416     virtual void DumpSimplifyInfo(std::shared_ptr<JsonValue>& json) {}
NotifyFillRequestSuccess(RefPtr<ViewDataWrap> viewDataWrap,RefPtr<PageNodeInfoWrap> nodeWrap,AceAutoFillType autoFillType)417     virtual void NotifyFillRequestSuccess(RefPtr<ViewDataWrap> viewDataWrap,
418         RefPtr<PageNodeInfoWrap> nodeWrap, AceAutoFillType autoFillType) {}
419     virtual void NotifyFillRequestFailed(int32_t errCode, const std::string& fillContent = "", bool isPopup = false) {}
CheckAutoSave()420     virtual bool CheckAutoSave()
421     {
422         return false;
423     }
424 
425     template<typename T>
GetLayoutProperty()426     RefPtr<T> GetLayoutProperty() const
427     {
428         auto host = GetHost();
429         CHECK_NULL_RETURN(host, nullptr);
430         return DynamicCast<T>(host->GetLayoutProperty<T>());
431     }
432 
433     template<typename T>
GetPaintProperty()434     RefPtr<T> GetPaintProperty() const
435     {
436         auto host = GetHost();
437         CHECK_NULL_RETURN(host, nullptr);
438         return DynamicCast<T>(host->GetPaintProperty<T>());
439     }
440 
441     template<typename T>
GetOrCreateEventHub()442     RefPtr<T> GetOrCreateEventHub() const
443     {
444         auto host = GetHost();
445         CHECK_NULL_RETURN(host, nullptr);
446         return DynamicCast<T>(host->GetOrCreateEventHub<T>());
447     }
448 
449     void MarkDirty(PropertyChangeFlag flag = PROPERTY_UPDATE_MEASURE_SELF)
450     {
451         auto host = GetHost();
452         CHECK_NULL_VOID(host);
453         host->MarkDirtyNode(flag);
454     }
455 
456     // Called after frameNode RebuildRenderContextTree.
OnRebuildFrame()457     virtual void OnRebuildFrame() {}
458     // Called before frameNode CreateLayoutWrapper.
BeforeCreateLayoutWrapper()459     virtual void BeforeCreateLayoutWrapper() {}
460     // Called before frameNode CreatePaintWrapper.
BeforeCreatePaintWrapper()461     virtual void BeforeCreatePaintWrapper() {}
462 
GetFocusPattern()463     virtual FocusPattern GetFocusPattern() const
464     {
465         return { FocusType::DISABLE, false, FocusStyleType::NONE };
466     }
467 
GetScopeFocusAlgorithm()468     virtual ScopeFocusAlgorithm GetScopeFocusAlgorithm()
469     {
470         return ScopeFocusAlgorithm();
471     }
472 
ScrollToNode(const RefPtr<FrameNode> & focusFrameNode)473     virtual bool ScrollToNode(const RefPtr<FrameNode>& focusFrameNode)
474     {
475         return false;
476     }
477 
GetFocusNodeIndex(const RefPtr<FocusHub> & focusNode)478     virtual int32_t GetFocusNodeIndex(const RefPtr<FocusHub>& focusNode)
479     {
480         return -1;
481     }
482 
ScrollToFocusNodeIndex(int32_t index)483     virtual void ScrollToFocusNodeIndex(int32_t index) {}
484 
485     // out of viewport or visible is none or gone.
OnInActive()486     virtual void OnInActive() {}
OnActive()487     virtual void OnActive() {}
488 
489     // called by window life cycle.
OnWindowShow()490     virtual void OnWindowShow() {}
OnWindowHide()491     virtual void OnWindowHide() {}
OnWindowFocused()492     virtual void OnWindowFocused() {}
OnWindowUnfocused()493     virtual void OnWindowUnfocused() {}
OnWindowActivated()494     virtual void OnWindowActivated() {}
OnWindowDeactivated()495     virtual void OnWindowDeactivated() {}
OnPixelRoundFinish(const SizeF & pixelGridRoundSize)496     virtual void OnPixelRoundFinish(const SizeF& pixelGridRoundSize) {}
OnWindowSizeChanged(int32_t width,int32_t height,WindowSizeChangeReason type)497     virtual void OnWindowSizeChanged(int32_t width, int32_t height, WindowSizeChangeReason type) {}
OnNotifyMemoryLevel(int32_t level)498     virtual void OnNotifyMemoryLevel(int32_t level) {}
499 
500     // get XTS inspector value
ToJsonValue(std::unique_ptr<JsonValue> & json,const InspectorFilter & filter)501     virtual void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const {}
502 
ToTreeJson(std::unique_ptr<JsonValue> & json,const InspectorConfig & config)503     virtual void ToTreeJson(std::unique_ptr<JsonValue>& json, const InspectorConfig& config) const {}
504 
505     // call by recycle framework.
OnRecycle()506     virtual void OnRecycle() {}
OnReuse()507     virtual void OnReuse() {}
508 
OnAttachToMainTree()509     virtual void OnAttachToMainTree() {}
OnAttachToBuilderNode(NodeStatus nodeStatus)510     virtual void OnAttachToBuilderNode(NodeStatus nodeStatus) {}
511 
OnDetachFromMainTree()512     virtual void OnDetachFromMainTree() {}
513 
FromJson(const std::unique_ptr<JsonValue> & json)514     virtual void FromJson(const std::unique_ptr<JsonValue>& json) {}
515 
OnAreaChangedInner()516     virtual void OnAreaChangedInner() {}
OnVisibleChange(bool isVisible)517     virtual void OnVisibleChange(bool isVisible) {}
ProvideRestoreInfo()518     virtual std::string ProvideRestoreInfo()
519     {
520         return "";
521     }
522 
OnRestoreInfo(const std::string & restoreInfo)523     virtual void OnRestoreInfo(const std::string& restoreInfo) {}
524 
IsNeedAdjustByAspectRatio()525     virtual bool IsNeedAdjustByAspectRatio()
526     {
527         auto host = GetHost();
528         CHECK_NULL_RETURN(host, false);
529         auto layoutProperty = host->GetLayoutProperty();
530         CHECK_NULL_RETURN(host, false);
531         return layoutProperty->HasAspectRatio();
532     }
533 
OnTouchTestHit(SourceType hitTestType)534     virtual void OnTouchTestHit(SourceType hitTestType) {}
535 
GetDragRecordSize()536     virtual int32_t GetDragRecordSize()
537     {
538         return -1;
539     }
540 
OnBackPressedCallback()541     virtual bool OnBackPressedCallback()
542     {
543         return false;
544     }
545 
HandleOnDragStatusCallback(const DragEventType & dragEventType,const RefPtr<NotifyDragEvent> & notifyDragEvent)546     virtual void HandleOnDragStatusCallback(
547         const DragEventType& dragEventType, const RefPtr<NotifyDragEvent>& notifyDragEvent) {};
548 
HandleDragEvent(const DragPointerEvent & info)549     virtual void HandleDragEvent(const DragPointerEvent& info) {};
OnLanguageConfigurationUpdate()550     virtual void OnLanguageConfigurationUpdate() {}
OnColorConfigurationUpdate()551     virtual void OnColorConfigurationUpdate() {}
552     virtual void OnColorModeChange(uint32_t colorMode);
OnDirectionConfigurationUpdate()553     virtual void OnDirectionConfigurationUpdate() {}
OnDpiConfigurationUpdate()554     virtual void OnDpiConfigurationUpdate() {}
OnIconConfigurationUpdate()555     virtual void OnIconConfigurationUpdate() {}
OnFontConfigurationUpdate()556     virtual void OnFontConfigurationUpdate() {}
OnFontScaleConfigurationUpdate()557     virtual void OnFontScaleConfigurationUpdate() {}
OnForegroundColorUpdate(const Color & value)558     virtual void OnForegroundColorUpdate(const Color& value) {}
559 
ShouldDelayChildPressedState()560     virtual bool ShouldDelayChildPressedState() const
561     {
562         return false;
563     }
564 
ShouldPreventChildPressedState()565     virtual bool ShouldPreventChildPressedState() const
566     {
567         return false;
568     }
569 
RegisterScrollingListener(const RefPtr<ScrollingListener> listener)570     virtual void RegisterScrollingListener(const RefPtr<ScrollingListener> listener) {}
FireAndCleanScrollingListener()571     virtual void FireAndCleanScrollingListener() {}
CleanScrollingListener()572     virtual void CleanScrollingListener() {}
ResetDragOption()573     virtual void ResetDragOption() {}
574 
WrapExtensionAbilityId(int64_t extensionOffset,int64_t abilityId)575     virtual int64_t WrapExtensionAbilityId(int64_t extensionOffset, int64_t abilityId)
576     {
577         return -1;
578     }
579 
SearchExtensionElementInfoByAccessibilityId(int64_t elementId,int32_t mode,int64_t baseParent,std::list<Accessibility::AccessibilityElementInfo> & output)580     virtual void SearchExtensionElementInfoByAccessibilityId(int64_t elementId, int32_t mode,
581         int64_t baseParent, std::list<Accessibility::AccessibilityElementInfo>& output) {}
SearchElementInfosByText(int64_t elementId,const std::string & text,int64_t baseParent,std::list<Accessibility::AccessibilityElementInfo> & output)582     virtual void SearchElementInfosByText(int64_t elementId, const std::string& text,
583         int64_t baseParent, std::list<Accessibility::AccessibilityElementInfo>& output) {}
FindFocusedElementInfo(int64_t elementId,int32_t focusType,int64_t baseParent,Accessibility::AccessibilityElementInfo & output)584     virtual void FindFocusedElementInfo(int64_t elementId, int32_t focusType,
585         int64_t baseParent, Accessibility::AccessibilityElementInfo& output) {}
FocusMoveSearch(int64_t elementId,int32_t direction,int64_t baseParent,Accessibility::AccessibilityElementInfo & output)586     virtual void FocusMoveSearch(int64_t elementId, int32_t direction,
587         int64_t baseParent, Accessibility::AccessibilityElementInfo& output) {}
TransferExecuteAction(int64_t elementId,const std::map<std::string,std::string> & actionArguments,int32_t action,int64_t offset)588     virtual bool TransferExecuteAction(
589         int64_t elementId, const std::map<std::string, std::string>& actionArguments, int32_t action, int64_t offset)
590     {
591         return false;
592     }
593 
GetAccessibilitySessionAdapter()594     virtual RefPtr<AccessibilitySessionAdapter> GetAccessibilitySessionAdapter()
595     {
596         return nullptr;
597     }
598 
GetUiExtensionId()599     virtual int32_t GetUiExtensionId()
600     {
601         return -1;
602     }
603 
GetLongPressEventRecorder()604     GestureEventFunc GetLongPressEventRecorder()
605     {
606         auto longPressCallback = [weak = WeakClaim(this)](GestureEvent& info) {
607             if (!Recorder::EventRecorder::Get().IsComponentRecordEnable()) {
608                 return;
609             }
610             auto pattern = weak.Upgrade();
611             CHECK_NULL_VOID(pattern);
612             auto host = pattern->GetHost();
613             CHECK_NULL_VOID(host);
614             auto inspectorId = host->GetInspectorId().value_or("");
615             auto text = host->GetAccessibilityProperty<NG::AccessibilityProperty>()->GetGroupText(true);
616             auto desc = host->GetAutoEventParamValue("");
617 
618             Recorder::EventParamsBuilder builder;
619             builder.SetId(inspectorId)
620                 .SetType(host->GetTag())
621                 .SetEventType(Recorder::LONG_PRESS)
622                 .SetText(text)
623                 .SetHost(host)
624                 .SetDescription(desc);
625             if (Recorder::EventRecorder::Get().IsRecordEnable(Recorder::EventCategory::CATEGORY_RECT)) {
626                 auto rect = host->GetTransformRectRelativeToWindow().ToBounds();
627                 builder.SetExtra(Recorder::KEY_NODE_RECT, std::move(rect));
628             }
629             Recorder::EventRecorder::Get().OnEvent(std::move(builder));
630         };
631         return longPressCallback;
632     }
633 
OnAttachContext(PipelineContext * context)634     virtual void OnAttachContext(PipelineContext *context) {}
OnDetachContext(PipelineContext * context)635     virtual void OnDetachContext(PipelineContext *context) {}
SetFrameRateRange(const RefPtr<FrameRateRange> & rateRange,SwiperDynamicSyncSceneType type)636     virtual void SetFrameRateRange(const RefPtr<FrameRateRange>& rateRange, SwiperDynamicSyncSceneType type) {}
637 
CheckLocalized()638     void CheckLocalized()
639     {
640         auto host = GetHost();
641         CHECK_NULL_VOID(host);
642         auto layoutProperty = host->GetLayoutProperty();
643         CHECK_NULL_VOID(layoutProperty);
644         auto layoutDirection = layoutProperty->GetNonAutoLayoutDirection();
645         if (layoutProperty->IsPositionLocalizedEdges()) {
646             layoutProperty->CheckPositionLocalizedEdges(layoutDirection);
647         }
648         layoutProperty->CheckMarkAnchorPosition(layoutDirection);
649         if (layoutProperty->IsOffsetLocalizedEdges()) {
650             layoutProperty->CheckOffsetLocalizedEdges(layoutDirection);
651         }
652         layoutProperty->CheckLocalizedPadding(layoutProperty, layoutDirection);
653         layoutProperty->CheckLocalizedMargin(layoutProperty, layoutDirection);
654         layoutProperty->CheckLocalizedEdgeWidths(layoutProperty, layoutDirection);
655         layoutProperty->CheckLocalizedEdgeColors(layoutDirection);
656         layoutProperty->CheckLocalizedBorderRadiuses(layoutDirection);
657         layoutProperty->CheckLocalizedOuterBorderColor(layoutDirection);
658         layoutProperty->CheckLocalizedBorderImageSlice(layoutDirection);
659         layoutProperty->CheckLocalizedBorderImageWidth(layoutDirection);
660         layoutProperty->CheckLocalizedBorderImageOutset(layoutDirection);
661         layoutProperty->CheckLocalizedAlignment(layoutDirection);
662         // Reset for safeAreaExpand's Cache in GeometryNode
663         host->ResetSafeAreaPadding();
664         layoutProperty->CheckLocalizedSafeAreaPadding(layoutDirection);
665         layoutProperty->CheckIgnoreLayoutSafeArea(layoutDirection);
666         layoutProperty->CheckBackgroundLayoutSafeAreaEdges(layoutDirection);
667     }
668 
OnFrameNodeChanged(FrameNodeChangeInfoFlag flag)669     virtual void OnFrameNodeChanged(FrameNodeChangeInfoFlag flag) {}
670 
GetWindowPatternType()671     virtual uint32_t GetWindowPatternType() const
672     {
673         return 0;
674     }
675 
IsResponseRegionExpandingNeededForStylus(const TouchEvent & touchEvent)676     virtual bool IsResponseRegionExpandingNeededForStylus(const TouchEvent& touchEvent) const
677     {
678         return false;
679     }
680 
ExpandDefaultResponseRegion(RectF & rect)681     virtual RectF ExpandDefaultResponseRegion(RectF& rect)
682     {
683         return RectF();
684     }
685 
NotifyDataChange(int32_t index,int32_t count)686     virtual void NotifyDataChange(int32_t index, int32_t count) {};
687 
RenderCustomChild(int64_t deadline)688     virtual bool RenderCustomChild(int64_t deadline)
689     {
690         return true;
691     }
692 
TriggerAutoSaveWhenInvisible()693     virtual bool TriggerAutoSaveWhenInvisible()
694     {
695         return false;
696     }
697 
AddInnerOnGestureRecognizerJudgeBegin(GestureRecognizerJudgeFunc && gestureRecognizerJudgeFunc)698     virtual void AddInnerOnGestureRecognizerJudgeBegin(
699         GestureRecognizerJudgeFunc&& gestureRecognizerJudgeFunc) {};
700 
RecoverInnerOnGestureRecognizerJudgeBegin()701     virtual void RecoverInnerOnGestureRecognizerJudgeBegin() {};
702 
OnThemeScopeUpdate(int32_t themeScopeId)703     virtual bool OnThemeScopeUpdate(int32_t themeScopeId)
704     {
705         return false;
706     }
707 
708     void AddResObj(
709         const std::string& key,
710         const RefPtr<ResourceObject>& resObj,
711         std::function<void(const RefPtr<ResourceObject>&)>&& updateFunc);
712 
713     void RemoveResObj(const std::string& key);
714 
715     void AddResCache(const std::string& key, const std::string& value);
716 
717     std::string GetResCacheMapByKey(const std::string& key);
718 
GetThemeScopeId()719     int32_t GetThemeScopeId() const
720     {
721         auto host = GetHost();
722         CHECK_NULL_RETURN(host, 0);
723         return host->GetThemeScopeId();
724     }
725 
ReusedNodeSkipMeasure()726     virtual bool ReusedNodeSkipMeasure()
727     {
728         return false;
729     }
730 
OnFocusNodeChange(FocusReason focusReason)731     virtual void OnFocusNodeChange(FocusReason focusReason) {}
OnCollectRemoved()732     virtual void OnCollectRemoved() {}
GetCurrentLanguage()733     virtual std::string GetCurrentLanguage()
734     {
735         return nullptr;
736     };
GetTranslateText(std::string extraData,std::function<void (std::string)> callback,bool isContinued)737     virtual void GetTranslateText(
738         std::string extraData, std::function<void(std::string)> callback, bool isContinued) {};
SendTranslateResult(std::vector<std::string> results,std::vector<int32_t> ids)739     virtual void SendTranslateResult(std::vector<std::string> results, std::vector<int32_t> ids) {};
EndTranslate()740     virtual void EndTranslate() {};
SendTranslateResult(std::string results)741     virtual void SendTranslateResult(std::string results) {};
742     int32_t OnRecvCommand(const std::string& command);
OnInjectionEvent(const std::string & command)743     virtual int32_t OnInjectionEvent(const std::string& command)
744     {
745         return RET_SUCCESS;
746     };
747 
BorderUnoccupied()748     virtual bool BorderUnoccupied() const
749     {
750         return false;
751     }
752 
753     virtual void UnRegisterResource(const std::string& key);
754 
755     template<typename T>
RegisterResource(const std::string & key,const RefPtr<ResourceObject> & resObj,T value)756     void RegisterResource(const std::string& key, const RefPtr<ResourceObject>& resObj, T value)
757     {
758         if (resourceMgr_ == nullptr) {
759             resourceMgr_ = MakeRefPtr<PatternResourceManager>();
760         }
761         auto&& propUpdateFunc = [weakptr = AceType::WeakClaim(this)](
762                                     const std::string& key, const RefPtr<PropertyValueBase>& valueBase) {
763             auto pattern = weakptr.Upgrade();
764             CHECK_NULL_VOID(pattern);
765             pattern->UpdatePropertyImpl(key, valueBase);
766         };
767         resourceMgr_->RegisterResource<T>(std::move(propUpdateFunc), key, resObj, value);
768     }
769 
UpdatePropertyImpl(const std::string & key,RefPtr<PropertyValueBase> valueBase)770     virtual void UpdatePropertyImpl(const std::string& key, RefPtr<PropertyValueBase> valueBase) {};
771 
OnAttachAdapter(const RefPtr<FrameNode> & node,const RefPtr<UINode> & child)772     virtual bool OnAttachAdapter(const RefPtr<FrameNode>& node, const RefPtr<UINode>& child)
773     {
774         return false;
775     }
776 
UpdateBorderResource()777     virtual void UpdateBorderResource() {};
UpdateMarginResource()778     virtual void UpdateMarginResource() {};
DetachHostNodeAdapter(const RefPtr<FrameNode> & node)779     virtual bool DetachHostNodeAdapter(const RefPtr<FrameNode>& node)
780     {
781         return false;
782     }
GetNodeAdapterComponent(ArkUINodeAdapterHandle handle,const RefPtr<FrameNode> & node)783     virtual bool GetNodeAdapterComponent(ArkUINodeAdapterHandle handle, const RefPtr<FrameNode>& node)
784     {
785         return false;
786     }
ChildPreMeasureHelperEnabled()787     virtual bool ChildPreMeasureHelperEnabled()
788     {
789         return false;
790     }
ChildPreMeasureHelperCustomized()791     virtual bool ChildPreMeasureHelperCustomized()
792     {
793         return false;
794     }
ChildPreMeasureHelper(LayoutWrapper * layoutWrapper,const std::optional<LayoutConstraintF> & parentConstraint)795     virtual bool ChildPreMeasureHelper(
796         LayoutWrapper* layoutWrapper, const std::optional<LayoutConstraintF>& parentConstraint)
797     {
798         return false;
799     }
800     virtual bool AccumulatingTerminateHelper(RectF& adjustingRect, ExpandEdges& totalExpand, bool fromSelf = false,
801         LayoutSafeAreaType ignoreType = NG::LAYOUT_SAFE_AREA_TYPE_SYSTEM)
802     {
803         return false;
804     }
PostponedTaskForIgnoreEnabled()805     virtual bool PostponedTaskForIgnoreEnabled()
806     {
807         return false;
808     }
PostponedTaskForIgnoreCustomized()809     virtual bool PostponedTaskForIgnoreCustomized()
810     {
811         return false;
812     }
PostponedTaskForIgnore()813     virtual void PostponedTaskForIgnore() {}
NeedCustomizeSafeAreaPadding()814     virtual bool NeedCustomizeSafeAreaPadding()
815     {
816         return false;
817     }
CustomizeSafeAreaPadding(PaddingPropertyF safeAreaPadding,bool needRotate)818     virtual PaddingPropertyF CustomizeSafeAreaPadding(PaddingPropertyF safeAreaPadding, bool needRotate)
819     {
820         return safeAreaPadding;
821     }
ChildTentativelyLayouted()822     virtual bool ChildTentativelyLayouted()
823     {
824         return false;
825     }
826 
827 protected:
OnAttachToFrameNode()828     virtual void OnAttachToFrameNode() {}
OnDetachFromFrameNode(FrameNode * frameNode)829     virtual void OnDetachFromFrameNode(FrameNode* frameNode) {}
830 
831     WeakPtr<FrameNode> frameNode_;
832     RefPtr<PatternResourceManager> resourceMgr_;
833 
834 private:
835     bool onDetach_ = false;
836     ACE_DISALLOW_COPY_AND_MOVE(Pattern);
837 };
838 } // namespace OHOS::Ace::NG
839 
840 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_PATTERN_H
841