• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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_PIPELINE_PIPELINE_BASE_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_PIPELINE_PIPELINE_BASE_H
18 
19 #include <atomic>
20 #include <functional>
21 #include <memory>
22 #include <optional>
23 #include <shared_mutex>
24 #include <stack>
25 #include <string>
26 #include <unordered_map>
27 #include <utility>
28 
29 #include "base/geometry/dimension.h"
30 #include "base/resource/asset_manager.h"
31 #include "base/resource/data_provider_manager.h"
32 #include "base/resource/shared_image_manager.h"
33 #include "base/thread/task_executor.h"
34 #include "core/accessibility/accessibility_manager.h"
35 #include "core/animation/schedule_task.h"
36 #include "core/common/clipboard/clipboard_proxy.h"
37 #include "core/common/display_info.h"
38 #include "core/common/draw_delegate.h"
39 #include "core/common/event_manager.h"
40 #include "core/common/platform_bridge.h"
41 #include "core/common/platform_res_register.h"
42 #include "core/common/resource/resource_configuration.h"
43 #include "core/common/thp_extra_manager.h"
44 #include "core/common/thread_checker.h"
45 #include "core/common/window_animation_config.h"
46 #include "core/components/common/layout/constants.h"
47 #include "core/components/common/properties/animation_option.h"
48 #include "core/components/theme/theme_manager.h"
49 #include "core/components_ng/property/safe_area_insets.h"
50 #include "core/event/axis_event.h"
51 #include "core/event/key_event.h"
52 #include "core/event/mouse_event.h"
53 #include "core/event/rotation_event.h"
54 #include "core/event/touch_event.h"
55 #include "core/event/pointer_event.h"
56 #include "core/gestures/gesture_info.h"
57 #include "core/image/image_cache.h"
58 #include "core/pipeline/container_window_manager.h"
59 #include "core/components_ng/manager/display_sync/ui_display_sync_manager.h"
60 #include "interfaces/inner_api/ace/serialized_gesture.h"
61 
62 namespace OHOS::Rosen {
63 class RSTransaction;
64 class AvoidArea;
65 } // namespace OHOS::Rosen
66 
67 namespace OHOS::Ace {
68 namespace NG {
69 class FrameNode;
70 } // namespace NG
71 
72 struct KeyboardAnimationCurve {
73     std::string curveType_;
74     std::vector<float> curveParams_;
75     uint32_t duration_ = 0;
76 };
77 
78 struct KeyboardAnimationConfig {
79     KeyboardAnimationCurve curveIn_;
80     KeyboardAnimationCurve curveOut_;
81 };
82 
83 struct FontInfo;
84 struct FontConfigJsonInfo;
85 class Frontend;
86 class OffscreenCanvas;
87 class Window;
88 class FontManager;
89 class ManagerInterface;
90 class NavigationController;
91 enum class FrontendType;
92 enum class KeyboardAction {
93     NONE,
94     CLOSING,
95     OPENING,
96 };
97 using SharePanelCallback = std::function<void(const std::string& bundleName, const std::string& abilityName)>;
98 using AceVsyncCallback = std::function<void(uint64_t, uint32_t)>;
99 using EtsCardTouchEventCallback = std::function<void(const TouchEvent&,
100     SerializedGesture& serializedGesture)>;
101 
102 class ACE_FORCE_EXPORT PipelineBase : public AceType {
103     DECLARE_ACE_TYPE(PipelineBase, AceType);
104 
105 public:
106     PipelineBase() = default;
107     PipelineBase(std::shared_ptr<Window> window, RefPtr<TaskExecutor> taskExecutor, RefPtr<AssetManager> assetManager,
108         const RefPtr<Frontend>& frontend, int32_t instanceId);
109     PipelineBase(std::shared_ptr<Window> window, RefPtr<TaskExecutor> taskExecutor, RefPtr<AssetManager> assetManager,
110         const RefPtr<Frontend>& frontend, int32_t instanceId, RefPtr<PlatformResRegister> platformResRegister);
111     ~PipelineBase() override;
112 
113     static RefPtr<PipelineBase> GetCurrentContext();
114 
115     static RefPtr<PipelineBase> GetCurrentContextSafely();
116 
117     static RefPtr<PipelineBase> GetCurrentContextSafelyWithCheck();
118 
119     static RefPtr<PipelineBase> GetMainPipelineContext();
120 
121     static RefPtr<ThemeManager> CurrentThemeManager();
122 
123     static void SetCallBackNode(const WeakPtr<NG::FrameNode>& node);
124 
125     /*
126      * Change px to vp with density of current pipeline
127      */
128     static double Px2VpWithCurrentDensity(double px);
129 
130     /*
131      * Change vp to px with density of current pipeline
132      */
133     static double Vp2PxWithCurrentDensity(double vp);
134 
135     /*
136      * Get density of current pipeline if valid, or return density of default display
137      */
138     static double GetCurrentDensity();
139 
140     virtual void SetupRootElement() = 0;
141 
142     virtual uint64_t GetTimeFromExternalTimer();
143 
144     virtual bool NeedSoftKeyboard() = 0;
145 
146     virtual void SetOnWindowFocused(const std::function<void()>& callback) = 0;
147 
148     bool Animate(const AnimationOption& option, const RefPtr<Curve>& curve,
149         const std::function<void()>& propertyCallback, const std::function<void()>& finishCallBack = nullptr);
150 
151     virtual void AddKeyFrame(
152         float fraction, const RefPtr<Curve>& curve, const std::function<void()>& propertyCallback) = 0;
153 
154     virtual void AddKeyFrame(float fraction, const std::function<void()>& propertyCallback) = 0;
155 
156     void PrepareOpenImplicitAnimation();
157 
CatchInteractiveAnimations(const std::function<void ()> & animationCallback)158     virtual bool CatchInteractiveAnimations(const std::function<void()>& animationCallback)
159     {
160         return false;
161     }
162 
163     void OpenImplicitAnimation(const AnimationOption& option, const RefPtr<Curve>& curve,
164         const std::function<void()>& finishCallback = nullptr);
165 
166     void StartImplicitAnimation(const AnimationOption& operation, const RefPtr<Curve>& curve,
167         const std::function<void()>& finishCallback = nullptr);
168 
169     void PrepareCloseImplicitAnimation();
170 
171     bool CloseImplicitAnimation();
172 
173     void ForceLayoutForImplicitAnimation();
174 
175     void ForceRenderForImplicitAnimation();
176 
177     // add schedule task and return the unique mark id.
178     virtual uint32_t AddScheduleTask(const RefPtr<ScheduleTask>& task) = 0;
179 
180     // remove schedule task by id.
181     virtual void RemoveScheduleTask(uint32_t id) = 0;
182 
183     // Called by view when touch event received.
184     virtual void OnTouchEvent(const TouchEvent& point, bool isSubPipe = false) = 0;
185 
186     // Called by ohos AceContainer when touch event received.
187     virtual void OnTouchEvent(const TouchEvent& point, const RefPtr<NG::FrameNode>& node, bool isSubPipe = false) {}
188 
OnAccessibilityHoverEvent(const TouchEvent & point,const RefPtr<NG::FrameNode> & node)189     virtual void OnAccessibilityHoverEvent(const TouchEvent& point, const RefPtr<NG::FrameNode>& node) {}
190 
OnPenHoverEvent(const TouchEvent & point,const RefPtr<NG::FrameNode> & node)191     virtual void OnPenHoverEvent(const TouchEvent& point, const RefPtr<NG::FrameNode>& node) {}
192 
HandlePenHoverOut(const TouchEvent & point)193     virtual void HandlePenHoverOut(const TouchEvent& point) {}
194 
195     // Called by container when key event received.
196     // if return false, then this event needs platform to handle it.
197     virtual bool OnKeyEvent(const KeyEvent& event) = 0;
198 
199     // Called by view when mouse event received.
200     virtual void OnMouseEvent(const MouseEvent& event) = 0;
201 
202     // Called by ohos AceContainer when mouse event received.
OnMouseEvent(const MouseEvent & event,const RefPtr<NG::FrameNode> & node)203     virtual void OnMouseEvent(const MouseEvent& event, const RefPtr<NG::FrameNode>& node) {}
204 
205     // Called by view when axis event received.
206     virtual void OnAxisEvent(const AxisEvent& event) = 0;
207 
208     // Called by ohos AceContainer when axis event received.
OnAxisEvent(const AxisEvent & event,const RefPtr<NG::FrameNode> & node)209     virtual void OnAxisEvent(const AxisEvent& event, const RefPtr<NG::FrameNode>& node) {}
210 
211     // Called by container when rotation event received.
212     // if return false, then this event needs platform to handle it.
213     virtual bool OnRotationEvent(const RotationEvent& event) const = 0;
214 
215     // Called by window when received vsync signal.
216     virtual void OnVsyncEvent(uint64_t nanoTimestamp, uint32_t frameCount);
217 
218     // Called by viewr
219     virtual void OnDragEvent(const PointerEvent& pointerEvent, DragEventAction action,
220         const RefPtr<NG::FrameNode>& node = nullptr) = 0;
221 
222     // Called by view when idle event.
223     virtual void OnIdle(int64_t deadline) = 0;
224 
225     virtual void SetBuildAfterCallback(const std::function<void()>& callback) = 0;
226 
227     virtual void DispatchDisplaySync(uint64_t nanoTimestamp) = 0;
228 
229     virtual void FlushAnimation(uint64_t nanoTimestamp) = 0;
230 
231     virtual void SendEventToAccessibility(const AccessibilityEvent& accessibilityEvent);
232 
233     virtual void SaveExplicitAnimationOption(const AnimationOption& option) = 0;
234 
235     virtual void CreateExplicitAnimator(const std::function<void()>& onFinishEvent) = 0;
236 
237     virtual void ClearExplicitAnimationOption() = 0;
238 
239     virtual AnimationOption GetExplicitAnimationOption() const = 0;
240 
241     virtual void Destroy();
242 
243     virtual void OnShow() = 0;
244 
245     virtual void OnHide() = 0;
246 
247     virtual void WindowFocus(bool isFocus) = 0;
248 
249     virtual void ContainerModalUnFocus() = 0;
250 
251     virtual void ShowContainerTitle(bool isShow, bool hasDeco = true, bool needUpdate = false) = 0;
252 
253     virtual void OnSurfaceChanged(int32_t width, int32_t height,
254         WindowSizeChangeReason type = WindowSizeChangeReason::UNDEFINED,
255         const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr) = 0;
256 
257     virtual void OnSurfacePositionChanged(int32_t posX, int32_t posY) = 0;
258 
OnSurfaceDensityChanged(double density)259     virtual void OnSurfaceDensityChanged(double density)
260     {
261         // To avoid the race condition caused by the offscreen canvas get density from the pipeline in the worker
262         // thread.
263         std::lock_guard lock(densityChangeMutex_);
264         for (auto&& [id, callback] : densityChangedCallbacks_) {
265             if (callback) {
266                 callback(density);
267             }
268         }
269     }
270 
SendUpdateVirtualNodeFocusEvent()271     void SendUpdateVirtualNodeFocusEvent()
272     {
273         auto accessibilityManager = GetAccessibilityManager();
274         CHECK_NULL_VOID(accessibilityManager);
275         accessibilityManager->UpdateVirtualNodeFocus();
276     }
277 
RegisterWindowDensityCallback(std::function<double ()> && callback)278     void RegisterWindowDensityCallback(std::function<double()>&& callback)
279     {
280         windowDensityCallback_ = callback;
281     }
282 
GetWindowDensity()283     double GetWindowDensity() const
284     {
285         if (windowDensityCallback_) {
286             return windowDensityCallback_();
287         }
288         return 1.0;
289     }
290 
RegisterDensityChangedCallback(std::function<void (double)> && callback)291     int32_t RegisterDensityChangedCallback(std::function<void(double)>&& callback)
292     {
293         if (callback) {
294             // To avoid the race condition caused by the offscreen canvas get density from the pipeline in the worker
295             // thread.
296             std::lock_guard lock(densityChangeMutex_);
297             densityChangedCallbacks_.emplace(++densityChangeCallbackId_, std::move(callback));
298             return densityChangeCallbackId_;
299         }
300         return 0;
301     }
302 
UnregisterDensityChangedCallback(int32_t callbackId)303     void UnregisterDensityChangedCallback(int32_t callbackId)
304     {
305         // To avoid the race condition caused by the offscreen canvas get density from the pipeline in the worker
306         // thread.
307         std::lock_guard lock(densityChangeMutex_);
308         densityChangedCallbacks_.erase(callbackId);
309     }
310 
311     virtual void OnTransformHintChanged(uint32_t transform) = 0;
312 
313     virtual void OnSystemBarHeightChanged(double statusBar, double navigationBar) = 0;
314 
315     virtual void OnSurfaceDestroyed() = 0;
316 
317     virtual void NotifyOnPreDraw() = 0;
318 
319     virtual bool CallRouterBackToPopPage() = 0;
320 
PopPageStackOverlay()321     virtual bool PopPageStackOverlay()
322     {
323         return false;
324     }
325 
HideOverlays()326     virtual void HideOverlays() {}
327 
OnPageShow()328     virtual void OnPageShow() {}
329 
330     virtual void OnActionEvent(const std::string& action);
331 
332     virtual void Finish(bool autoFinish = true) const {}
333 
RequestFullWindow(int32_t duration)334     virtual void RequestFullWindow(int32_t duration) {}
335 
336     virtual bool RequestFocus(const std::string& targetNodeId, bool isSyncRequest = false)
337     {
338         return false;
339     }
340 
341     // Called by AceContainer.
342     bool Dump(const std::vector<std::string>& params) const;
343 
IsLastPage()344     virtual bool IsLastPage()
345     {
346         return false;
347     }
348 
GetIsDeclarative()349     virtual bool GetIsDeclarative() const
350     {
351         return true;
352     }
353 
SetAppBgColor(const Color & color)354     virtual void SetAppBgColor(const Color& color)
355     {
356         appBgColor_ = color;
357     }
358 
ChangeDarkModeBrightness()359     virtual void ChangeDarkModeBrightness() {}
360 
SetFormRenderingMode(int8_t renderMode)361     void SetFormRenderingMode(int8_t renderMode)
362     {
363         renderingMode_ = renderMode;
364     }
365 
GetAppBgColor()366     const Color& GetAppBgColor() const
367     {
368         return appBgColor_;
369     }
370 
GetAppLabelId()371     int32_t GetAppLabelId() const
372     {
373         return appLabelId_;
374     }
375 
SetAppLabelId(int32_t appLabelId)376     void SetAppLabelId(int32_t appLabelId)
377     {
378         appLabelId_ = appLabelId;
379     }
380 
381     virtual void SetAppTitle(const std::string& title) = 0;
382 
383     virtual void SetAppIcon(const RefPtr<PixelMap>& icon) = 0;
384 
SetContainerButtonHide(bool hideSplit,bool hideMaximize,bool hideMinimize)385     virtual void SetContainerButtonHide(bool hideSplit, bool hideMaximize, bool hideMinimize) {}
386 
RefreshRootBgColor()387     virtual void RefreshRootBgColor() const {}
388 
PostponePageTransition()389     virtual void PostponePageTransition() {}
LaunchPageTransition()390     virtual void LaunchPageTransition() {}
391 
GetBoundingRectData(int32_t nodeId,Rect & rect)392     virtual void GetBoundingRectData(int32_t nodeId, Rect& rect) {}
393 
CheckAndUpdateKeyboardInset(float keyboardHeight)394     virtual void CheckAndUpdateKeyboardInset(float keyboardHeight) {}
395 
396     virtual RefPtr<AccessibilityManager> GetAccessibilityManager() const;
397 
GetNavigationController(const std::string & id)398     virtual std::shared_ptr<NavigationController> GetNavigationController(const std::string& id)
399     {
400         return nullptr;
401     }
402 
403     void SetRootSize(double density, float width, float height);
404 
405     void UpdateFontWeightScale();
406 
SetFollowSystem(bool followSystem)407     void SetFollowSystem(bool followSystem)
408     {
409         followSystem_ = followSystem;
410     }
411 
SetMaxAppFontScale(float maxAppFontScale)412     void SetMaxAppFontScale(float maxAppFontScale)
413     {
414         maxAppFontScale_ = maxAppFontScale;
415     }
416 
GetMaxAppFontScale()417     float GetMaxAppFontScale()
418     {
419         return maxAppFontScale_;
420     }
421 
IsFollowSystem()422     bool IsFollowSystem()
423     {
424         return followSystem_;
425     }
426 
427     double NormalizeToPx(const Dimension& dimension) const;
428 
429     double ConvertPxToVp(const Dimension& dimension) const;
430 
431     using FinishEventHandler = std::function<void()>;
SetFinishEventHandler(FinishEventHandler && listener)432     void SetFinishEventHandler(FinishEventHandler&& listener)
433     {
434         finishEventHandler_ = std::move(listener);
435     }
436 
437     using StartAbilityHandler = std::function<void(const std::string& address)>;
SetStartAbilityHandler(StartAbilityHandler && listener)438     void SetStartAbilityHandler(StartAbilityHandler&& listener)
439     {
440         startAbilityHandler_ = std::move(listener);
441     }
442     void HyperlinkStartAbility(const std::string& address) const;
443 
444     using ActionEventHandler = std::function<void(const std::string& action)>;
SetActionEventHandler(ActionEventHandler && listener)445     void SetActionEventHandler(ActionEventHandler&& listener)
446     {
447         actionEventHandler_ = std::move(listener);
448     }
449 
450     using FormLinkInfoUpdateHandler = std::function<void(const std::vector<std::string>&)>;
SetFormLinkInfoUpdateHandler(FormLinkInfoUpdateHandler && listener)451     void SetFormLinkInfoUpdateHandler(FormLinkInfoUpdateHandler&& listener)
452     {
453         formLinkInfoUpdateHandler_ = std::move(listener);
454     }
455 
456     using StatusBarEventHandler = std::function<void(const Color& color)>;
SetStatusBarEventHandler(StatusBarEventHandler && listener)457     void SetStatusBarEventHandler(StatusBarEventHandler&& listener)
458     {
459         statusBarBgColorEventHandler_ = std::move(listener);
460     }
461     void NotifyStatusBarBgColor(const Color& color) const;
462 
463     using PopupEventHandler = std::function<void()>;
SetPopupEventHandler(PopupEventHandler && listener)464     void SetPopupEventHandler(PopupEventHandler&& listener)
465     {
466         popupEventHandler_ = std::move(listener);
467     }
468     void NotifyPopupDismiss() const;
469 
470     using MenuEventHandler = std::function<void()>;
SetMenuEventHandler(MenuEventHandler && listener)471     void SetMenuEventHandler(MenuEventHandler&& listener)
472     {
473         menuEventHandler_ = std::move(listener);
474     }
475     void NotifyMenuDismiss() const;
476 
477     using ContextMenuEventHandler = std::function<void()>;
SetContextMenuEventHandler(ContextMenuEventHandler && listener)478     void SetContextMenuEventHandler(ContextMenuEventHandler&& listener)
479     {
480         contextMenuEventHandler_ = std::move(listener);
481     }
482     void NotifyContextMenuDismiss() const;
483 
484     using RouterBackEventHandler = std::function<void()>;
SetRouterBackEventHandler(RouterBackEventHandler && listener)485     void SetRouterBackEventHandler(RouterBackEventHandler&& listener)
486     {
487         routerBackEventHandler_ = std::move(listener);
488     }
489     void NotifyRouterBackDismiss() const;
490 
491     using PopPageSuccessEventHandler = std::function<void(const std::string& pageUrl, const int32_t pageId)>;
SetPopPageSuccessEventHandler(PopPageSuccessEventHandler && listener)492     void SetPopPageSuccessEventHandler(PopPageSuccessEventHandler&& listener)
493     {
494         popPageSuccessEventHandler_.push_back(std::move(listener));
495     }
496     void NotifyPopPageSuccessDismiss(const std::string& pageUrl, int32_t pageId) const;
497 
498     using IsPagePathInvalidEventHandler = std::function<void(bool& isPageInvalid)>;
SetIsPagePathInvalidEventHandler(IsPagePathInvalidEventHandler && listener)499     void SetIsPagePathInvalidEventHandler(IsPagePathInvalidEventHandler&& listener)
500     {
501         isPagePathInvalidEventHandler_.push_back(std::move(listener));
502     }
503     void NotifyIsPagePathInvalidDismiss(bool isPageInvalid) const;
504 
505     using DestroyEventHandler = std::function<void()>;
SetDestroyHandler(DestroyEventHandler && listener)506     void SetDestroyHandler(DestroyEventHandler&& listener)
507     {
508         destroyEventHandler_.push_back(std::move(listener));
509     }
510     void NotifyDestroyEventDismiss() const;
511 
512     using DispatchTouchEventHandler = std::function<void(const TouchEvent& event)>;
SetDispatchTouchEventHandler(DispatchTouchEventHandler && listener)513     void SetDispatchTouchEventHandler(DispatchTouchEventHandler&& listener)
514     {
515         dispatchTouchEventHandler_.push_back(std::move(listener));
516     }
517     void NotifyDispatchTouchEventDismiss(const TouchEvent& event) const;
518 
519     using GetViewScaleCallback = std::function<bool(float&, float&)>;
SetGetViewScaleCallback(GetViewScaleCallback && callback)520     void SetGetViewScaleCallback(GetViewScaleCallback&& callback)
521     {
522         getViewScaleCallback_ = callback;
523     }
524 
525     using OnPageShowCallBack = std::function<void()>;
SetOnPageShow(OnPageShowCallBack && onPageShowCallBack)526     void SetOnPageShow(OnPageShowCallBack&& onPageShowCallBack)
527     {
528         onPageShowCallBack_ = std::move(onPageShowCallBack);
529     }
530 
531     using AnimationCallback = std::function<void()>;
SetAnimationCallback(AnimationCallback && callback)532     void SetAnimationCallback(AnimationCallback&& callback)
533     {
534         animationCallback_ = std::move(callback);
535     }
536 
537     using ProfilerCallback = std::function<void(const std::string&)>;
SetOnVsyncProfiler(const ProfilerCallback & callback)538     void SetOnVsyncProfiler(const ProfilerCallback& callback)
539     {
540         onVsyncProfiler_ = callback;
541     }
542 
543     using OnRouterChangeCallback = bool (*)(const std::string currentRouterPath);
AddRouterChangeCallback(const OnRouterChangeCallback & onRouterChangeCallback)544     void AddRouterChangeCallback(const OnRouterChangeCallback& onRouterChangeCallback)
545     {
546         onRouterChangeCallback_ = onRouterChangeCallback;
547     }
548 
549     void onRouterChange(const std::string& url);
550 
ResetOnVsyncProfiler()551     void ResetOnVsyncProfiler()
552     {
553         onVsyncProfiler_ = nullptr;
554     }
555 
GetViewScale(float & scaleX,float & scaleY)556     bool GetViewScale(float& scaleX, float& scaleY)
557     {
558         if (getViewScaleCallback_) {
559             return getViewScaleCallback_(scaleX, scaleY);
560         }
561         return false;
562     }
563 
GetTaskExecutor()564     RefPtr<TaskExecutor> GetTaskExecutor() const
565     {
566         return taskExecutor_;
567     }
568 
569     RefPtr<Frontend> GetFrontend() const;
570 
GetInstanceId()571     int32_t GetInstanceId() const
572     {
573         return instanceId_;
574     }
575 
576     void ClearImageCache();
577 
578     void SetImageCache(const RefPtr<ImageCache>& imageChache);
579 
580     RefPtr<ImageCache> GetImageCache() const;
581 
GetOrCreateSharedImageManager()582     const RefPtr<SharedImageManager>& GetOrCreateSharedImageManager()
583     {
584         std::scoped_lock<std::shared_mutex> lock(imageMtx_);
585         if (!sharedImageManager_) {
586             sharedImageManager_ = MakeRefPtr<SharedImageManager>(taskExecutor_);
587         }
588         return sharedImageManager_;
589     }
590 
GetOrCreateUIDisplaySyncManager()591     const RefPtr<UIDisplaySyncManager>& GetOrCreateUIDisplaySyncManager()
592     {
593         std::call_once(displaySyncFlag_, [this]() {
594             if (!uiDisplaySyncManager_) {
595                 uiDisplaySyncManager_ = MakeRefPtr<UIDisplaySyncManager>();
596             }
597         });
598         return uiDisplaySyncManager_;
599     }
600 
GetWindow()601     Window* GetWindow()
602     {
603         return window_.get();
604     }
605 
GetAssetManager()606     RefPtr<AssetManager> GetAssetManager() const
607     {
608         return assetManager_;
609     }
610 
GetMinPlatformVersion()611     int32_t GetMinPlatformVersion() const
612     {
613         // Since API10, the platform version data format has changed.
614         // Use the last three digits of data as platform version. For example (4000000010).
615         return minPlatformVersion_ % 1000;
616     }
617 
SetMinPlatformVersion(int32_t minPlatformVersion)618     void SetMinPlatformVersion(int32_t minPlatformVersion)
619     {
620         minPlatformVersion_ = minPlatformVersion;
621     }
622 
SetInstallationFree(int32_t installationFree)623     void SetInstallationFree(int32_t installationFree)
624     {
625         installationFree_ = installationFree;
626     }
627 
GetInstallationFree()628     bool GetInstallationFree() const
629     {
630         return installationFree_;
631     }
632 
SetSharePanelCallback(SharePanelCallback && callback)633     void SetSharePanelCallback(SharePanelCallback&& callback)
634     {
635         sharePanelCallback_ = std::move(callback);
636     }
637 
FireSharePanelCallback(const std::string & bundleName,const std::string & abilityName)638     void FireSharePanelCallback(const std::string& bundleName, const std::string& abilityName)
639     {
640         if (sharePanelCallback_) {
641             sharePanelCallback_(bundleName, abilityName);
642         }
643     }
644 
GetThemeManager()645     RefPtr<ThemeManager> GetThemeManager() const
646     {
647         std::shared_lock<std::shared_mutex> lock(themeMtx_);
648         return themeManager_;
649     }
650 
SetThemeManager(RefPtr<ThemeManager> theme)651     void SetThemeManager(RefPtr<ThemeManager> theme)
652     {
653         CHECK_RUN_ON(UI);
654         std::unique_lock<std::shared_mutex> lock(themeMtx_);
655         themeManager_ = std::move(theme);
656     }
657 
658     template<typename T>
GetTheme()659     RefPtr<T> GetTheme() const
660     {
661         std::shared_lock<std::shared_mutex> lock(themeMtx_);
662         if (themeManager_) {
663             return themeManager_->GetTheme<T>();
664         }
665         return {};
666     }
667 
668     template<typename T>
GetDraggable()669     bool GetDraggable()
670     {
671         if (isJsCard_ || isFormRender_) {
672             return false;
673         }
674         auto theme = GetTheme<T>();
675         CHECK_NULL_RETURN(theme, false);
676         return theme->GetDraggable();
677     }
678 
GetTextFieldManager()679     const RefPtr<ManagerInterface>& GetTextFieldManager()
680     {
681         return textFieldManager_;
682     }
683     void SetTextFieldManager(const RefPtr<ManagerInterface>& manager);
684 
GetFontManager()685     const RefPtr<FontManager>& GetFontManager() const
686     {
687         return fontManager_;
688     }
689 
GetDataProviderManager()690     const RefPtr<DataProviderManagerInterface>& GetDataProviderManager() const
691     {
692         return dataProviderManager_;
693     }
SetDataProviderManager(const RefPtr<DataProviderManagerInterface> & dataProviderManager)694     void SetDataProviderManager(const RefPtr<DataProviderManagerInterface>& dataProviderManager)
695     {
696         dataProviderManager_ = dataProviderManager;
697     }
698 
GetMessageBridge()699     const RefPtr<PlatformBridge>& GetMessageBridge() const
700     {
701         return messageBridge_;
702     }
SetMessageBridge(const RefPtr<PlatformBridge> & messageBridge)703     void SetMessageBridge(const RefPtr<PlatformBridge>& messageBridge)
704     {
705         messageBridge_ = messageBridge;
706     }
707 
SetIsJsCard(bool isJsCard)708     void SetIsJsCard(bool isJsCard)
709     {
710         isJsCard_ = isJsCard;
711     }
712 
SetIsJsPlugin(bool isJsPlugin)713     void SetIsJsPlugin(bool isJsPlugin)
714     {
715         isJsPlugin_ = isJsPlugin;
716     }
717 
SetDrawDelegate(std::unique_ptr<DrawDelegate> delegate)718     void SetDrawDelegate(std::unique_ptr<DrawDelegate> delegate)
719     {
720         drawDelegate_ = std::move(delegate);
721     }
722 
IsJsCard()723     bool IsJsCard() const
724     {
725         return isJsCard_;
726     }
727 
IsJsPlugin()728     bool IsJsPlugin() const
729     {
730         return isJsPlugin_;
731     }
732 
SetIsFormRender(bool isEtsCard)733     void SetIsFormRender(bool isEtsCard)
734     {
735         isFormRender_ = isEtsCard;
736     }
737 
IsFormRender()738     bool IsFormRender() const
739     {
740         return isFormRender_;
741     }
742 
SetIsDynamicRender(bool isDynamicRender)743     void SetIsDynamicRender(bool isDynamicRender)
744     {
745         isDynamicRender_ = isDynamicRender;
746     }
747 
IsDynamicRender()748     bool IsDynamicRender() const
749     {
750         return isDynamicRender_;
751     }
752 
753     // Get the dp scale which used to covert dp to logic px.
GetDipScale()754     double GetDipScale() const
755     {
756         return dipScale_;
757     }
758 
759     // Get the window design scale used to covert lpx to logic px.
GetLogicScale()760     double GetLogicScale() const
761     {
762         return designWidthScale_;
763     }
764 
GetFontScale()765     float GetFontScale() const
766     {
767         return fontScale_;
768     }
769     void SetFontScale(float fontScale);
770 
GetFontWeightScale()771     float GetFontWeightScale() const
772     {
773         return fontWeightScale_;
774     }
775     void SetFontWeightScale(float fontWeightScale);
776 
GetWindowId()777     uint32_t GetWindowId() const
778     {
779         return windowId_;
780     }
781 
SetWindowId(uint32_t windowId)782     void SetWindowId(uint32_t windowId)
783     {
784         windowId_ = windowId;
785     }
786 
SetFocusWindowId(uint32_t windowId)787     void SetFocusWindowId(uint32_t windowId)
788     {
789         focusWindowId_ = windowId;
790     }
791 
GetFocusWindowId()792     uint32_t GetFocusWindowId() const
793     {
794         return focusWindowId_.value_or(windowId_);
795     }
796 
IsFocusWindowIdSetted()797     bool IsFocusWindowIdSetted() const
798     {
799         return focusWindowId_.has_value();
800     }
801 
SetRealHostWindowId(uint32_t realHostWindowId)802     void SetRealHostWindowId(uint32_t realHostWindowId)
803     {
804         realHostWindowId_ = realHostWindowId;
805     }
806 
GetRealHostWindowId()807     uint32_t GetRealHostWindowId() const
808     {
809         return realHostWindowId_.value_or(GetFocusWindowId());
810     }
811 
IsRealHostWindowIdSetted()812     bool IsRealHostWindowIdSetted() const
813     {
814         return realHostWindowId_.has_value();
815     }
816 
GetViewScale()817     float GetViewScale() const
818     {
819         return viewScale_;
820     }
821 
GetRootWidth()822     double GetRootWidth() const
823     {
824         return rootWidth_;
825     }
826 
GetRootHeight()827     double GetRootHeight() const
828     {
829         return rootHeight_;
830     }
831 
SetWindowModal(WindowModal modal)832     void SetWindowModal(WindowModal modal)
833     {
834         windowModal_ = modal;
835     }
836 
GetWindowModal()837     WindowModal GetWindowModal() const
838     {
839         return windowModal_;
840     }
841 
IsFullScreenModal()842     bool IsFullScreenModal() const
843     {
844         return windowModal_ == WindowModal::NORMAL || windowModal_ == WindowModal::SEMI_MODAL_FULL_SCREEN ||
845                windowModal_ == WindowModal::CONTAINER_MODAL || isFullWindow_;
846     }
847 
SetIsRightToLeft(bool isRightToLeft)848     void SetIsRightToLeft(bool isRightToLeft)
849     {
850         isRightToLeft_ = isRightToLeft;
851     }
852 
IsRightToLeft()853     bool IsRightToLeft() const
854     {
855         return isRightToLeft_;
856     }
857 
SetEventManager(const RefPtr<EventManager> & eventManager)858     void SetEventManager(const RefPtr<EventManager>& eventManager)
859     {
860         eventManager_ = eventManager;
861     }
862 
GetEventManager()863     RefPtr<EventManager> GetEventManager() const
864     {
865         return eventManager_;
866     }
867 
GetWindowManager()868     const RefPtr<WindowManager>& GetWindowManager() const
869     {
870         return windowManager_;
871     }
872 
873     bool HasFloatTitle() const;
874 
IsRebuildFinished()875     bool IsRebuildFinished() const
876     {
877         return isRebuildFinished_;
878     }
879 
880     void RequestFrame();
881 
882     void RegisterFont(const std::string& familyName, const std::string& familySrc, const std::string& bundleName = "",
883         const std::string& moduleName = "");
884 
885     void GetSystemFontList(std::vector<std::string>& fontList);
886 
887     bool GetSystemFont(const std::string& fontName, FontInfo& fontInfo);
888 
889     void GetUIFontConfig(FontConfigJsonInfo& fontConfigJsonInfo);
890 
891     void TryLoadImageInfo(const std::string& src, std::function<void(bool, int32_t, int32_t)>&& loadCallback);
892 
893     RefPtr<OffscreenCanvas> CreateOffscreenCanvas(int32_t width, int32_t height);
894 
895     void PostAsyncEvent(TaskExecutor::Task&& task, const std::string& name,
896         TaskExecutor::TaskType type = TaskExecutor::TaskType::UI);
897 
898     void PostAsyncEvent(const TaskExecutor::Task& task, const std::string& name,
899         TaskExecutor::TaskType type = TaskExecutor::TaskType::UI);
900 
901     void PostSyncEvent(const TaskExecutor::Task& task, const std::string& name,
902         TaskExecutor::TaskType type = TaskExecutor::TaskType::UI);
903 
904     virtual void FlushReload(const ConfigurationChange& configurationChange, bool fullUpdate = true) {}
FlushBuild()905     virtual void FlushBuild() {}
906 
FlushReloadTransition()907     virtual void FlushReloadTransition() {}
RebuildFontNode()908     virtual void RebuildFontNode() {}
GetFrontendType()909     FrontendType GetFrontendType() const
910     {
911         return frontendType_;
912     }
913 
GetDensity()914     double GetDensity() const
915     {
916         return density_;
917     }
918 
GetPlatformResRegister()919     RefPtr<PlatformResRegister> GetPlatformResRegister() const
920     {
921         return platformResRegister_;
922     }
923 
924     void SetTouchPipeline(const WeakPtr<PipelineBase>& context);
925     void RemoveTouchPipeline(const WeakPtr<PipelineBase>& context);
926 
927     void OnVirtualKeyboardAreaChange(Rect keyboardArea,
928         const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr, const float safeHeight = 0.0f,
929         bool supportAvoidance = false, bool forceChange = false);
930     void OnVirtualKeyboardAreaChange(Rect keyboardArea, double positionY, double height,
931         const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr, bool forceChange = false);
932     void OnFoldStatusChanged(FoldStatus foldStatus);
933 
934     using foldStatusChangedCallback = std::function<bool(FoldStatus)>;
SetFoldStatusChangeCallback(foldStatusChangedCallback && listener)935     void SetFoldStatusChangeCallback(foldStatusChangedCallback&& listener)
936     {
937         foldStatusChangedCallback_.emplace_back(std::move(listener));
938     }
939 
940     void OnFoldDisplayModeChanged(FoldDisplayMode foldDisplayMode);
941 
942     using virtualKeyBoardCallback = std::function<bool(int32_t, int32_t, double)>;
SetVirtualKeyBoardCallback(virtualKeyBoardCallback && listener)943     void SetVirtualKeyBoardCallback(virtualKeyBoardCallback&& listener)
944     {
945         static std::atomic<int32_t> pseudoId(-1); // -1 will not be conflict with real node ids.
946         auto nodeId = pseudoId.fetch_sub(1, std::memory_order_relaxed);
947         virtualKeyBoardCallback_.emplace(std::make_pair(nodeId, std::move(listener)));
948     }
SetVirtualKeyBoardCallback(int32_t nodeId,virtualKeyBoardCallback && listener)949     void SetVirtualKeyBoardCallback(int32_t nodeId, virtualKeyBoardCallback&& listener)
950     {
951         virtualKeyBoardCallback_.emplace(std::make_pair(nodeId, std::move(listener)));
952     }
RemoveVirtualKeyBoardCallback(int32_t nodeId)953     void RemoveVirtualKeyBoardCallback(int32_t nodeId)
954     {
955         virtualKeyBoardCallback_.erase(nodeId);
956     }
NotifyVirtualKeyBoard(int32_t width,int32_t height,double keyboard)957     bool NotifyVirtualKeyBoard(int32_t width, int32_t height, double keyboard) const
958     {
959         bool isConsume = false;
960         for (const auto& [nodeId, iterVirtualKeyBoardCallback] : virtualKeyBoardCallback_) {
961             if (iterVirtualKeyBoardCallback && iterVirtualKeyBoardCallback(width, height, keyboard)) {
962                 isConsume = true;
963             }
964         }
965         return isConsume;
966     }
967 
968     using configChangedCallback = std::function<void()>;
SetConfigChangedCallback(int32_t nodeId,configChangedCallback && listener)969     void SetConfigChangedCallback(int32_t nodeId, configChangedCallback&& listener)
970     {
971         configChangedCallback_.emplace(make_pair(nodeId, std::move(listener)));
972     }
RemoveConfigChangedCallback(int32_t nodeId)973     void RemoveConfigChangedCallback(int32_t nodeId)
974     {
975         configChangedCallback_.erase(nodeId);
976     }
977 
NotifyConfigurationChange()978     void NotifyConfigurationChange()
979     {
980         for (const auto& [nodeId, callback] : configChangedCallback_) {
981             if (callback) {
982                 callback();
983             }
984         }
985     }
986 
987     using PostRTTaskCallback = std::function<void(std::function<void()>&&)>;
SetPostRTTaskCallBack(PostRTTaskCallback && callback)988     void SetPostRTTaskCallBack(PostRTTaskCallback&& callback)
989     {
990         postRTTaskCallback_ = std::move(callback);
991     }
992 
PostTaskToRT(std::function<void ()> && task)993     void PostTaskToRT(std::function<void()>&& task)
994     {
995         if (postRTTaskCallback_) {
996             postRTTaskCallback_(std::move(task));
997         }
998     }
999 
1000     void SetGetWindowRectImpl(std::function<Rect()>&& callback);
1001 
1002     Rect GetCurrentWindowRect() const;
1003 
1004     using SafeAreaInsets = NG::SafeAreaInsets;
UpdateSystemSafeArea(const SafeAreaInsets & systemSafeArea)1005     virtual void UpdateSystemSafeArea(const SafeAreaInsets& systemSafeArea) {}
1006 
UpdateCutoutSafeArea(const SafeAreaInsets & cutoutSafeArea)1007     virtual void UpdateCutoutSafeArea(const SafeAreaInsets& cutoutSafeArea) {}
1008 
UpdateNavSafeArea(const SafeAreaInsets & navSafeArea)1009     virtual void UpdateNavSafeArea(const SafeAreaInsets& navSafeArea) {}
1010 
UpdateOriginAvoidArea(const Rosen::AvoidArea & avoidArea,uint32_t type)1011     virtual void UpdateOriginAvoidArea(const Rosen::AvoidArea& avoidArea, uint32_t type) {}
1012 
SetEnableKeyBoardAvoidMode(bool value)1013     virtual void SetEnableKeyBoardAvoidMode(bool value) {}
1014 
IsEnableKeyBoardAvoidMode()1015     virtual bool IsEnableKeyBoardAvoidMode() {
1016         return false;
1017     }
1018 
RequireSummary()1019     virtual void RequireSummary() {}
1020 
SetPluginOffset(const Offset & offset)1021     void SetPluginOffset(const Offset& offset)
1022     {
1023         pluginOffset_ = offset;
1024     }
1025 
GetPluginOffset()1026     Offset GetPluginOffset() const
1027     {
1028         return pluginOffset_;
1029     }
1030 
SetPluginEventOffset(const Offset & offset)1031     void SetPluginEventOffset(const Offset& offset)
1032     {
1033         pluginEventOffset_ = offset;
1034     }
1035 
GetPluginEventOffset()1036     Offset GetPluginEventOffset() const
1037     {
1038         return pluginEventOffset_;
1039     }
NotifyMemoryLevel(int32_t level)1040     virtual void NotifyMemoryLevel(int32_t level) {}
1041 
SetDisplayWindowRectInfo(const Rect & displayWindowRectInfo)1042     void SetDisplayWindowRectInfo(const Rect& displayWindowRectInfo)
1043     {
1044         displayWindowRectInfo_ = displayWindowRectInfo;
1045     }
1046 
1047     virtual void SetContainerWindow(bool isShow) = 0;
1048 
1049     // This method can get the coordinates and size of the current window,
1050     // which can be added to the return value of the GetGlobalOffset method to get the window coordinates of the node.
GetDisplayWindowRectInfo()1051     const Rect& GetDisplayWindowRectInfo() const
1052     {
1053         return displayWindowRectInfo_;
1054     }
FlushModifier()1055     virtual void FlushModifier() {}
1056     virtual void FlushMessages() = 0;
SetGSVsyncCallback(std::function<void (void)> && callback)1057     void SetGSVsyncCallback(std::function<void(void)>&& callback)
1058     {
1059         gsVsyncCallback_ = std::move(callback);
1060     }
1061 
1062     virtual void FlushUITasks(bool triggeredByImplicitAnimation = false) = 0;
1063 
FlushAfterLayoutCallbackInImplicitAnimationTask()1064     virtual void FlushAfterLayoutCallbackInImplicitAnimationTask() {}
1065 
1066     virtual void FlushPipelineImmediately() = 0;
1067 
1068     virtual void FlushOnceVsyncTask() = 0;
1069 
1070     // get animateTo closure option
GetSyncAnimationOption()1071     AnimationOption GetSyncAnimationOption()
1072     {
1073         return animationOption_;
1074     }
1075 
SetSyncAnimationOption(const AnimationOption & option)1076     void SetSyncAnimationOption(const AnimationOption& option)
1077     {
1078         animationOption_ = option;
1079     }
1080 
SetKeyboardAnimationConfig(const KeyboardAnimationConfig & config)1081     void SetKeyboardAnimationConfig(const KeyboardAnimationConfig& config)
1082     {
1083         keyboardAnimationConfig_ = config;
1084     }
1085 
GetKeyboardAnimationConfig()1086     KeyboardAnimationConfig GetKeyboardAnimationConfig() const
1087     {
1088         return keyboardAnimationConfig_;
1089     }
1090 
SetNextFrameLayoutCallback(std::function<void ()> && callback)1091     void SetNextFrameLayoutCallback(std::function<void()>&& callback)
1092     {
1093         nextFrameLayoutCallback_ = std::move(callback);
1094     }
1095 
SetForegroundCalled(bool isForegroundCalled)1096     void SetForegroundCalled(bool isForegroundCalled)
1097     {
1098         isForegroundCalled_ = isForegroundCalled;
1099     }
1100 
SetIsSubPipeline(bool isSubPipeline)1101     void SetIsSubPipeline(bool isSubPipeline)
1102     {
1103         isSubPipeline_ = isSubPipeline;
1104     }
1105 
IsSubPipeline()1106     bool IsSubPipeline() const
1107     {
1108         return isSubPipeline_;
1109     }
1110 
SetParentPipeline(const WeakPtr<PipelineBase> & pipeline)1111     void SetParentPipeline(const WeakPtr<PipelineBase>& pipeline)
1112     {
1113         parentPipeline_ = pipeline;
1114     }
1115 
1116     void AddEtsCardTouchEventCallback(int32_t ponitId, EtsCardTouchEventCallback&& callback);
1117 
1118     void HandleEtsCardTouchEvent(const TouchEvent& point, SerializedGesture &serializedGesture);
1119 
1120     void RemoveEtsCardTouchEventCallback(int32_t ponitId);
1121 
1122     void SetSubWindowVsyncCallback(AceVsyncCallback&& callback, int32_t subWindowId);
1123 
1124     void SetJsFormVsyncCallback(AceVsyncCallback&& callback, int32_t subWindowId);
1125 
1126     void RemoveSubWindowVsyncCallback(int32_t subWindowId);
1127 
1128     void RemoveJsFormVsyncCallback(int32_t subWindowId);
1129 
SetIsLayoutFullScreen(bool isLayoutFullScreen)1130     virtual void SetIsLayoutFullScreen(bool isLayoutFullScreen) {}
SetIsNeedAvoidWindow(bool isLayoutFullScreen)1131     virtual void SetIsNeedAvoidWindow(bool isLayoutFullScreen) {}
SetIgnoreViewSafeArea(bool ignoreViewSafeArea)1132     virtual void SetIgnoreViewSafeArea(bool ignoreViewSafeArea) {}
OnFoldStatusChange(FoldStatus foldStatus)1133     virtual void OnFoldStatusChange(FoldStatus foldStatus) {}
OnFoldDisplayModeChange(FoldDisplayMode foldDisplayMode)1134     virtual void OnFoldDisplayModeChange(FoldDisplayMode foldDisplayMode) {}
1135 
SetIsAppWindow(bool isAppWindow)1136     void SetIsAppWindow(bool isAppWindow)
1137     {
1138         isAppWindow_ = isAppWindow;
1139     }
1140 
GetIsAppWindow()1141     bool GetIsAppWindow() const
1142     {
1143         return isAppWindow_;
1144     }
1145 
SetFormAnimationStartTime(int64_t time)1146     void SetFormAnimationStartTime(int64_t time)
1147     {
1148         formAnimationStartTime_ = time;
1149     }
1150 
GetFormAnimationStartTime()1151     int64_t GetFormAnimationStartTime() const
1152     {
1153         return formAnimationStartTime_;
1154     }
1155 
SetIsFormAnimation(bool isFormAnimation)1156     void SetIsFormAnimation(bool isFormAnimation)
1157     {
1158         isFormAnimation_ = isFormAnimation;
1159     }
1160 
IsFormAnimation()1161     bool IsFormAnimation() const
1162     {
1163         return isFormAnimation_;
1164     }
1165 
SetFormAnimationFinishCallback(bool isFormAnimationFinishCallback)1166     void SetFormAnimationFinishCallback(bool isFormAnimationFinishCallback)
1167     {
1168         isFormAnimationFinishCallback_ = isFormAnimationFinishCallback;
1169     }
1170 
IsFormAnimationFinishCallback()1171     bool IsFormAnimationFinishCallback() const
1172     {
1173         return isFormAnimationFinishCallback_;
1174     }
1175 
1176     // restore
RestoreNodeInfo(std::unique_ptr<JsonValue> nodeInfo)1177     virtual void RestoreNodeInfo(std::unique_ptr<JsonValue> nodeInfo) {}
1178 
GetStoredNodeInfo()1179     virtual std::unique_ptr<JsonValue> GetStoredNodeInfo()
1180     {
1181         return nullptr;
1182     }
1183 
GetLastTouchTime()1184     uint64_t GetLastTouchTime() const
1185     {
1186         return lastTouchTime_;
1187     }
1188 
AddFormLinkInfo(int32_t id,const std::string & info)1189     void AddFormLinkInfo(int32_t id, const std::string& info)
1190     {
1191         LOGI("AddFormLinkInfo is %{public}s, id is %{public}d", info.c_str(), id);
1192         formLinkInfoMap_[id] = info;
1193     }
1194 
IsLayouting()1195     virtual bool IsLayouting() const
1196     {
1197         return false;
1198     }
1199 
SetHalfLeading(bool halfLeading)1200     void SetHalfLeading(bool halfLeading)
1201     {
1202         halfLeading_ = halfLeading;
1203     }
1204 
GetHalfLeading()1205     bool GetHalfLeading() const
1206     {
1207         return halfLeading_;
1208     }
1209 
SetHasPreviewTextOption(bool hasOption)1210     void SetHasPreviewTextOption(bool hasOption)
1211     {
1212         hasPreviewTextOption_ = hasOption;
1213     }
1214 
GetHasPreviewTextOption()1215     bool GetHasPreviewTextOption() const
1216     {
1217         return hasPreviewTextOption_;
1218     }
1219 
SetSupportPreviewText(bool changeSupported)1220     void SetSupportPreviewText(bool changeSupported)
1221     {
1222         hasSupportedPreviewText_ = !changeSupported;
1223     }
1224 
GetSupportPreviewText()1225     bool GetSupportPreviewText() const
1226     {
1227         return hasSupportedPreviewText_;
1228     }
1229 
SetUseCutout(bool useCutout)1230     void SetUseCutout(bool useCutout)
1231     {
1232         useCutout_ = useCutout;
1233     }
1234 
GetUseCutout()1235     bool GetUseCutout() const
1236     {
1237         return useCutout_;
1238     }
1239 
GetOnFoucs()1240     bool GetOnFoucs() const
1241     {
1242         return onFocus_;
1243     }
1244 
GetVsyncTime()1245     uint64_t GetVsyncTime() const
1246     {
1247         return vsyncTime_;
1248     }
1249 
SetVsyncTime(uint64_t time)1250     void SetVsyncTime(uint64_t time)
1251     {
1252         vsyncTime_ = time;
1253     }
1254 
UpdateCurrentActiveNode(const WeakPtr<NG::FrameNode> & node)1255     virtual void UpdateCurrentActiveNode(const WeakPtr<NG::FrameNode>& node) {}
1256 
GetCurrentExtraInfo()1257     virtual std::string GetCurrentExtraInfo() { return ""; }
1258 
1259     virtual void UpdateTitleInTargetPos(bool isShow = true, int32_t height = 0) {}
1260 
SetCursor(int32_t cursorValue)1261     virtual void SetCursor(int32_t cursorValue) {}
1262 
1263     virtual void RestoreDefault(int32_t windowId = 0) {}
1264 
SetOnFormRecycleCallback(std::function<std::string ()> && onFormRecycle)1265     void SetOnFormRecycleCallback(std::function<std::string()>&& onFormRecycle)
1266     {
1267         onFormRecycle_ = std::move(onFormRecycle);
1268     }
1269 
1270     std::string OnFormRecycle();
1271 
SetOnFormRecoverCallback(std::function<void (std::string)> && onFormRecover)1272     void SetOnFormRecoverCallback(std::function<void(std::string)>&& onFormRecover)
1273     {
1274         onFormRecover_ = std::move(onFormRecover);
1275     }
1276 
1277     void OnFormRecover(const std::string& statusData);
1278 
IsDragging()1279     virtual bool IsDragging() const
1280     {
1281         return false;
1282     }
1283 
SetIsDragging(bool isDragging)1284     virtual void SetIsDragging(bool isDragging) {}
1285 
ResetDragging()1286     virtual void ResetDragging() {}
1287 
GetSerializedGesture()1288     virtual const SerializedGesture& GetSerializedGesture() const
1289     {
1290         return serializedGesture_;
1291     }
1292 
PrintVsyncInfoIfNeed()1293     virtual bool PrintVsyncInfoIfNeed() const
1294     {
1295         return false;
1296     }
1297 
1298 
StartWindowAnimation()1299     virtual void StartWindowAnimation() {}
1300 
StopWindowAnimation()1301     virtual void StopWindowAnimation() {}
1302 
AddSyncGeometryNodeTask(std::function<void ()> && task)1303     virtual void AddSyncGeometryNodeTask(std::function<void()>&& task) {}
1304 
FlushSyncGeometryNodeTasks()1305     virtual void FlushSyncGeometryNodeTasks() {}
1306 
ChangeSensitiveNodes(bool flag)1307     virtual void ChangeSensitiveNodes(bool flag) {}
1308 
IsContainerModalVisible()1309     virtual bool IsContainerModalVisible()
1310     {
1311         return false;
1312     }
1313 
GetFrameCount()1314     uint32_t GetFrameCount() const
1315     {
1316         return frameCount_;
1317     }
1318 
GetKeyboardAction()1319     KeyboardAction GetKeyboardAction()
1320     {
1321         return keyboardAction_;
1322     }
1323 
SetKeyboardAction(KeyboardAction action)1324     void SetKeyboardAction(KeyboardAction action)
1325     {
1326         keyboardAction_ = action;
1327     }
1328     void SetUiDvsyncSwitch(bool on);
1329 
CheckAndLogLastReceivedTouchEventInfo(int32_t eventId,TouchType type)1330     virtual void CheckAndLogLastReceivedTouchEventInfo(int32_t eventId, TouchType type) {}
1331 
CheckAndLogLastConsumedTouchEventInfo(int32_t eventId,TouchType type)1332     virtual void CheckAndLogLastConsumedTouchEventInfo(int32_t eventId, TouchType type) {}
1333 
CheckAndLogLastReceivedMouseEventInfo(int32_t eventId,MouseAction action)1334     virtual void CheckAndLogLastReceivedMouseEventInfo(int32_t eventId, MouseAction action) {}
1335 
CheckAndLogLastConsumedMouseEventInfo(int32_t eventId,MouseAction action)1336     virtual void CheckAndLogLastConsumedMouseEventInfo(int32_t eventId, MouseAction action) {}
1337 
CheckAndLogLastReceivedAxisEventInfo(int32_t eventId,AxisAction action)1338     virtual void CheckAndLogLastReceivedAxisEventInfo(int32_t eventId, AxisAction action) {}
1339 
CheckAndLogLastConsumedAxisEventInfo(int32_t eventId,AxisAction action)1340     virtual void CheckAndLogLastConsumedAxisEventInfo(int32_t eventId, AxisAction action) {}
1341 
GetPageAvoidOffset()1342     virtual float GetPageAvoidOffset()
1343     {
1344         return 0.0f;
1345     }
1346 
CheckNeedAvoidInSubWindow()1347     virtual bool CheckNeedAvoidInSubWindow()
1348     {
1349         return false;
1350     }
1351 
1352     virtual bool IsDensityChanged() const = 0;
1353 
GetResponseRegion(const RefPtr<NG::FrameNode> & rootNode)1354     virtual std::string GetResponseRegion(const RefPtr<NG::FrameNode>& rootNode)
1355     {
1356         return "";
1357     };
1358 
NotifyResponseRegionChanged(const RefPtr<NG::FrameNode> & rootNode)1359     virtual void NotifyResponseRegionChanged(const RefPtr<NG::FrameNode>& rootNode) {};
1360 
SetTHPExtraManager(const RefPtr<NG::THPExtraManager> & thpExtraMgr)1361     void SetTHPExtraManager(const RefPtr<NG::THPExtraManager>& thpExtraMgr)
1362     {
1363         thpExtraMgr_ = thpExtraMgr;
1364     }
1365 
GetTHPExtraManager()1366     const RefPtr<NG::THPExtraManager>& GetTHPExtraManager() const
1367     {
1368         return thpExtraMgr_;
1369     }
1370 
1371     virtual bool GetOnShow() const = 0;
1372     bool IsDestroyed();
1373 
1374     void SetDestroyed();
1375 
1376 #if defined(SUPPORT_TOUCH_TARGET_TEST)
1377     // Called by hittest to find touch node is equal target.
1378     virtual bool OnTouchTargetHitTest(const TouchEvent& point, bool isSubPipe = false,
1379         const std::string& target = "") = 0;
1380 #endif
IsWindowFocused()1381     virtual bool IsWindowFocused() const
1382     {
1383         return GetOnFoucs();
1384     }
1385 
SetDragNodeGrayscale(float dragNodeGrayscale)1386     void SetDragNodeGrayscale(float dragNodeGrayscale)
1387     {
1388         dragNodeGrayscale_ = dragNodeGrayscale;
1389     }
1390 
GetDragNodeGrayscale()1391     float GetDragNodeGrayscale() const
1392     {
1393         return dragNodeGrayscale_;
1394     }
1395 
IsDirtyNodesEmpty()1396     virtual bool IsDirtyNodesEmpty() const
1397     {
1398         return true;
1399     }
1400 
IsDirtyLayoutNodesEmpty()1401     virtual bool IsDirtyLayoutNodesEmpty() const
1402     {
1403         return true;
1404     }
1405 
SetOpenInvisibleFreeze(bool isOpenInvisibleFreeze)1406     void SetOpenInvisibleFreeze(bool isOpenInvisibleFreeze)
1407     {
1408         isOpenInvisibleFreeze_ = isOpenInvisibleFreeze;
1409     }
1410 
IsOpenInvisibleFreeze()1411     bool IsOpenInvisibleFreeze() const
1412     {
1413         return isOpenInvisibleFreeze_;
1414     }
1415 
SetVisibleAreaRealTime(bool visibleAreaRealTime)1416     void SetVisibleAreaRealTime(bool visibleAreaRealTime)
1417     {
1418         visibleAreaRealTime_ = visibleAreaRealTime;
1419     }
1420 
GetVisibleAreaRealTime()1421     bool GetVisibleAreaRealTime() const
1422     {
1423         return visibleAreaRealTime_;
1424     }
1425 
1426     void SetAccessibilityEventCallback(std::function<void(uint32_t, int64_t)>&& callback);
1427 
1428     void AddAccessibilityCallbackEvent(AccessibilityCallbackEventId event, int64_t parameter);
1429 
1430     void FireAccessibilityEvents();
1431 
1432 protected:
1433     virtual bool MaybeRelease() override;
TryCallNextFrameLayoutCallback()1434     void TryCallNextFrameLayoutCallback()
1435     {
1436         if (isForegroundCalled_ && nextFrameLayoutCallback_) {
1437             isForegroundCalled_ = false;
1438             nextFrameLayoutCallback_();
1439             LOGI("nextFrameLayoutCallback called");
1440         }
1441     }
1442 
OnDumpInfo(const std::vector<std::string> & params)1443     virtual bool OnDumpInfo(const std::vector<std::string>& params) const
1444     {
1445         return false;
1446     }
1447     virtual void FlushVsync(uint64_t nanoTimestamp, uint32_t frameCount) = 0;
1448     virtual void SetRootRect(double width, double height, double offset = 0.0) = 0;
1449     virtual void FlushPipelineWithoutAnimation() = 0;
1450 
1451     virtual void OnVirtualKeyboardHeightChange(float keyboardHeight,
1452         const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr, const float safeHeight = 0.0f,
1453         const bool supportAvoidance = false, bool forceChange = false)
1454     {}
1455     virtual void OnVirtualKeyboardHeightChange(float keyboardHeight, double positionY, double height,
1456         const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr, bool forceChange = false)
1457     {}
1458 
1459     void UpdateRootSizeAndScale(int32_t width, int32_t height);
1460 
SetIsReloading(bool isReloading)1461     void SetIsReloading(bool isReloading)
1462     {
1463         isReloading_ = isReloading;
1464     }
1465 
1466     std::function<void()> GetWrappedAnimationCallback(const std::function<void()>& finishCallback);
1467 
1468     std::map<int32_t, configChangedCallback> configChangedCallback_;
1469     std::map<int32_t, virtualKeyBoardCallback> virtualKeyBoardCallback_;
1470     std::list<foldStatusChangedCallback> foldStatusChangedCallback_;
1471 
1472     bool isRebuildFinished_ = false;
1473     bool isJsCard_ = false;
1474     bool isFormRender_ = false;
1475     bool isDynamicRender_ = false;
1476     bool isRightToLeft_ = false;
1477     bool isFullWindow_ = false;
1478     bool isAppWindow_ = true;
1479     bool installationFree_ = false;
1480     bool isSubPipeline_ = false;
1481     bool isReloading_ = false;
1482 
1483     bool isJsPlugin_ = false;
1484     bool isOpenInvisibleFreeze_ = false;
1485 
1486     std::unordered_map<int32_t, AceVsyncCallback> subWindowVsyncCallbacks_;
1487     std::unordered_map<int32_t, AceVsyncCallback> jsFormVsyncCallbacks_;
1488     int32_t minPlatformVersion_ = 0;
1489     uint32_t windowId_ = 0;
1490     // UIExtensionAbility need component windowID
1491     std::optional<uint32_t> focusWindowId_;
1492     std::optional<uint32_t> realHostWindowId_;
1493 
1494     int32_t appLabelId_ = 0;
1495     float fontScale_ = 1.0f;
1496     float fontWeightScale_ = 1.0f;
1497     float designWidthScale_ = 1.0f;
1498     float viewScale_ = 1.0f;
1499     double density_ = 1.0;
1500     double dipScale_ = 1.0;
1501     double rootHeight_ = 0.0;
1502     double rootWidth_ = 0.0;
1503     FrontendType frontendType_;
1504     WindowModal windowModal_ = WindowModal::NORMAL;
1505 
1506     Offset pluginOffset_ { 0, 0 };
1507     Offset pluginEventOffset_ { 0, 0 };
1508     Color appBgColor_ = Color::WHITE;
1509     int8_t renderingMode_ = 0;
1510 
1511     std::unique_ptr<DrawDelegate> drawDelegate_;
1512     std::stack<bool> pendingImplicitLayout_;
1513     std::stack<bool> pendingImplicitRender_;
1514     std::stack<bool> pendingFrontendAnimation_;
1515     std::shared_ptr<Window> window_;
1516     RefPtr<TaskExecutor> taskExecutor_;
1517     RefPtr<AssetManager> assetManager_;
1518     WeakPtr<Frontend> weakFrontend_;
1519     int32_t instanceId_ = 0;
1520     RefPtr<EventManager> eventManager_;
1521     RefPtr<ImageCache> imageCache_;
1522     RefPtr<SharedImageManager> sharedImageManager_;
1523     mutable std::shared_mutex imageMtx_;
1524     mutable std::shared_mutex themeMtx_;
1525     mutable std::mutex destructMutex_;
1526     RefPtr<ThemeManager> themeManager_;
1527     RefPtr<DataProviderManagerInterface> dataProviderManager_;
1528     RefPtr<FontManager> fontManager_;
1529     RefPtr<ManagerInterface> textFieldManager_;
1530     RefPtr<PlatformBridge> messageBridge_;
1531     RefPtr<WindowManager> windowManager_;
1532     OnPageShowCallBack onPageShowCallBack_;
1533     AnimationCallback animationCallback_;
1534     ProfilerCallback onVsyncProfiler_;
1535     FinishEventHandler finishEventHandler_;
1536     StartAbilityHandler startAbilityHandler_;
1537     ActionEventHandler actionEventHandler_;
1538     FormLinkInfoUpdateHandler formLinkInfoUpdateHandler_;
1539     RefPtr<PlatformResRegister> platformResRegister_;
1540 
1541     WeakPtr<PipelineBase> parentPipeline_;
1542 
1543     std::vector<WeakPtr<PipelineBase>> touchPluginPipelineContext_;
1544     std::unordered_map<int32_t, EtsCardTouchEventCallback> etsCardTouchEventCallback_;
1545 
1546     RefPtr<Clipboard> clipboard_;
1547     std::function<void(const std::string&)> clipboardCallback_ = nullptr;
1548     Rect displayWindowRectInfo_;
1549     AnimationOption animationOption_;
1550     KeyboardAnimationConfig keyboardAnimationConfig_;
1551 
1552     std::function<void()> nextFrameLayoutCallback_ = nullptr;
1553     SharePanelCallback sharePanelCallback_ = nullptr;
1554     std::atomic<bool> isForegroundCalled_ = false;
1555     std::atomic<bool> onFocus_ = false;
1556     uint64_t lastTouchTime_ = 0;
1557     std::map<int32_t, std::string> formLinkInfoMap_;
1558     struct FunctionHash {
operatorFunctionHash1559         std::size_t operator()(const std::shared_ptr<std::function<void()>>& functionPtr) const
1560         {
1561             return std::hash<std::function<void()>*>()(functionPtr.get());
1562         }
1563     };
1564     std::function<std::string()> onFormRecycle_;
1565     std::function<void(std::string)> onFormRecover_;
1566 
1567     uint64_t compensationValue_ = 0;
1568     int64_t recvTime_ = 0;
1569     std::once_flag displaySyncFlag_;
1570     RefPtr<UIDisplaySyncManager> uiDisplaySyncManager_;
1571 
1572     SerializedGesture serializedGesture_;
1573     RefPtr<NG::THPExtraManager> thpExtraMgr_;
1574 private:
1575     void DumpFrontend() const;
1576     double ModifyKeyboardHeight(double keyboardHeight) const;
1577     StatusBarEventHandler statusBarBgColorEventHandler_;
1578     PopupEventHandler popupEventHandler_;
1579     MenuEventHandler menuEventHandler_;
1580     ContextMenuEventHandler contextMenuEventHandler_;
1581     RouterBackEventHandler routerBackEventHandler_;
1582     std::list<PopPageSuccessEventHandler> popPageSuccessEventHandler_;
1583     std::list<IsPagePathInvalidEventHandler> isPagePathInvalidEventHandler_;
1584     std::list<DestroyEventHandler> destroyEventHandler_;
1585     std::list<DispatchTouchEventHandler> dispatchTouchEventHandler_;
1586     GetViewScaleCallback getViewScaleCallback_;
1587     // OnRouterChangeCallback is function point, need to be initialized.
1588     OnRouterChangeCallback onRouterChangeCallback_ = nullptr;
1589     PostRTTaskCallback postRTTaskCallback_;
1590     std::function<void(void)> gsVsyncCallback_;
1591     std::unordered_set<std::shared_ptr<std::function<void()>>, FunctionHash> finishFunctions_;
1592     bool followSystem_ = false;
1593     float maxAppFontScale_ = static_cast<float>(INT32_MAX);
1594     bool isFormAnimationFinishCallback_ = false;
1595     int64_t formAnimationStartTime_ = 0;
1596     bool isFormAnimation_ = false;
1597     bool halfLeading_ = false;
1598     bool hasSupportedPreviewText_ = true;
1599     bool hasPreviewTextOption_ = false;
1600     bool useCutout_ = false;
1601     // whether visible area need to be calculate at each vsync after approximate timeout.
1602     bool visibleAreaRealTime_ = false;
1603     uint64_t vsyncTime_ = 0;
1604     bool destroyed_ = false;
1605     uint32_t frameCount_ = 0;
1606     KeyboardAction keyboardAction_ = KeyboardAction::NONE;
1607     float dragNodeGrayscale_ = 0.0f;
1608 
1609     // To avoid the race condition caused by the offscreen canvas get density from the pipeline in the worker thread.
1610     std::mutex densityChangeMutex_;
1611     int32_t densityChangeCallbackId_ = 0;
1612     std::unordered_map<int32_t, std::function<void(double)>> densityChangedCallbacks_;
1613     std::function<double()> windowDensityCallback_;
1614     std::function<void(uint32_t, int64_t)> accessibilityCallback_;
1615     std::set<AccessibilityCallbackEvent> accessibilityEvents_;
1616 
1617     ACE_DISALLOW_COPY_AND_MOVE(PipelineBase);
1618 };
1619 
1620 } // namespace OHOS::Ace
1621 
1622 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_PIPELINE_PIPELINE_BASE_H
1623