• 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/draw_delegate.h"
38 #include "core/common/event_manager.h"
39 #include "core/common/platform_bridge.h"
40 #include "core/common/platform_res_register.h"
41 #include "core/common/thread_checker.h"
42 #include "core/common/window_animation_config.h"
43 #include "core/components/common/properties/animation_option.h"
44 #include "core/components/theme/theme_manager.h"
45 #include "core/components_ng/property/safe_area_insets.h"
46 #include "core/event/axis_event.h"
47 #include "core/event/key_event.h"
48 #include "core/event/mouse_event.h"
49 #include "core/event/rotation_event.h"
50 #include "core/event/touch_event.h"
51 #include "core/gestures/gesture_info.h"
52 #include "core/image/image_cache.h"
53 #include "core/pipeline/container_window_manager.h"
54 
55 namespace OHOS::Rosen {
56 class RSTransaction;
57 }
58 
59 namespace OHOS::Ace {
60 
61 struct KeyboardAnimationConfig {
62     std::string curveType_;
63     std::vector<float> curveParams_;
64     uint32_t durationIn_ = 0;
65     uint32_t durationOut_ = 0;
66 };
67 
68 struct FontInfo {
69     std::string path;
70     std::string postScriptName;
71     std::string fullName;
72     std::string family;
73     std::string subfamily;
74     uint32_t weight = 0;
75     uint32_t width = 0;
76     bool italic = false;
77     bool monoSpace = false;
78     bool symbolic = false;
79 };
80 
81 class Frontend;
82 class OffscreenCanvas;
83 class Window;
84 class FontManager;
85 class ManagerInterface;
86 enum class FrontendType;
87 using SharePanelCallback = std::function<void(const std::string& bundleName, const std::string& abilityName)>;
88 using AceVsyncCallback = std::function<void(uint64_t, uint32_t)>;
89 using EtsCardTouchEventCallback = std::function<void(const TouchEvent&)>;
90 
91 class ACE_FORCE_EXPORT PipelineBase : public AceType {
92     DECLARE_ACE_TYPE(PipelineBase, AceType);
93 
94 public:
95     PipelineBase() = default;
96     PipelineBase(std::shared_ptr<Window> window, RefPtr<TaskExecutor> taskExecutor, RefPtr<AssetManager> assetManager,
97         const RefPtr<Frontend>& frontend, int32_t instanceId);
98     PipelineBase(std::shared_ptr<Window> window, RefPtr<TaskExecutor> taskExecutor, RefPtr<AssetManager> assetManager,
99         const RefPtr<Frontend>& frontend, int32_t instanceId, RefPtr<PlatformResRegister> platformResRegister);
100     ~PipelineBase() override;
101 
102     static RefPtr<PipelineBase> GetCurrentContext();
103 
104     static RefPtr<ThemeManager> CurrentThemeManager();
105 
106     virtual void SetupRootElement() = 0;
107 
108     virtual uint64_t GetTimeFromExternalTimer();
109 
110     bool Animate(const AnimationOption& option, const RefPtr<Curve>& curve,
111         const std::function<void()>& propertyCallback, const std::function<void()>& finishCallBack = nullptr);
112 
113     virtual void AddKeyFrame(
114         float fraction, const RefPtr<Curve>& curve, const std::function<void()>& propertyCallback) = 0;
115 
116     virtual void AddKeyFrame(float fraction, const std::function<void()>& propertyCallback) = 0;
117 
118     void PrepareOpenImplicitAnimation();
119 
120     void OpenImplicitAnimation(const AnimationOption& option, const RefPtr<Curve>& curve,
121         const std::function<void()>& finishCallBack = nullptr);
122 
123     void PrepareCloseImplicitAnimation();
124 
125     bool CloseImplicitAnimation();
126 
127     void ForceLayoutForImplicitAnimation();
128 
129     void ForceRenderForImplicitAnimation();
130 
131     // add schedule task and return the unique mark id.
132     virtual uint32_t AddScheduleTask(const RefPtr<ScheduleTask>& task) = 0;
133 
134     // remove schedule task by id.
135     virtual void RemoveScheduleTask(uint32_t id) = 0;
136 
137     // Called by view when touch event received.
138     virtual void OnTouchEvent(const TouchEvent& point, bool isSubPipe = false) = 0;
139 
140     // Called by container when key event received.
141     // if return false, then this event needs platform to handle it.
142     virtual bool OnKeyEvent(const KeyEvent& event) = 0;
143 
144     // Called by view when mouse event received.
145     virtual void OnMouseEvent(const MouseEvent& event) = 0;
146 
147     // Called by view when axis event received.
148     virtual void OnAxisEvent(const AxisEvent& event) = 0;
149 
150     // Called by container when rotation event received.
151     // if return false, then this event needs platform to handle it.
152     virtual bool OnRotationEvent(const RotationEvent& event) const = 0;
153 
154     // Called by window when received vsync signal.
155     virtual void OnVsyncEvent(uint64_t nanoTimestamp, uint32_t frameCount);
156 
157     // Called by view
158     virtual void OnDragEvent(int32_t x, int32_t y, DragEventAction action) = 0;
159 
160     // Called by view when idle event.
161     virtual void OnIdle(int64_t deadline) = 0;
162 
163     virtual void SetBuildAfterCallback(const std::function<void()>& callback) = 0;
164 
165     virtual void FlushAnimation(uint64_t nanoTimestamp) = 0;
166 
167     virtual void SendEventToAccessibility(const AccessibilityEvent& accessibilityEvent);
168 
169     virtual void SaveExplicitAnimationOption(const AnimationOption& option) = 0;
170 
171     virtual void CreateExplicitAnimator(const std::function<void()>& onFinishEvent) = 0;
172 
173     virtual void ClearExplicitAnimationOption() = 0;
174 
175     virtual AnimationOption GetExplicitAnimationOption() const = 0;
176 
177     virtual void Destroy();
178 
179     virtual void OnShow() = 0;
180 
181     virtual void OnHide() = 0;
182 
183     virtual void WindowFocus(bool isFocus) = 0;
184 
185     virtual void ShowContainerTitle(bool isShow, bool hasDeco = true) = 0;
186 
187     virtual void OnSurfaceChanged(int32_t width, int32_t height,
188         WindowSizeChangeReason type = WindowSizeChangeReason::UNDEFINED,
189         const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr) = 0;
190 
191     virtual void OnSurfacePositionChanged(int32_t posX, int32_t posY) = 0;
192 
193     virtual void OnSurfaceDensityChanged(double density) = 0;
194 
195     virtual void OnSystemBarHeightChanged(double statusBar, double navigationBar) = 0;
196 
197     virtual void OnSurfaceDestroyed() = 0;
198 
199     virtual void NotifyOnPreDraw() = 0;
200 
201     virtual bool CallRouterBackToPopPage() = 0;
202 
PopPageStackOverlay()203     virtual bool PopPageStackOverlay()
204     {
205         return false;
206     }
207 
HideOverlays()208     virtual void HideOverlays() {}
209 
OnPageShow()210     virtual void OnPageShow() {}
211 
212     virtual void OnActionEvent(const std::string& action);
213 
214     virtual void Finish(bool autoFinish = true) const {}
215 
RequestFullWindow(int32_t duration)216     virtual void RequestFullWindow(int32_t duration) {}
217 
RequestFocus(const std::string & targetNodeId)218     virtual bool RequestFocus(const std::string& targetNodeId)
219     {
220         return false;
221     }
222 
223     // Called by AceContainer.
224     bool Dump(const std::vector<std::string>& params) const;
225 
IsLastPage()226     virtual bool IsLastPage()
227     {
228         return false;
229     }
230 
GetIsDeclarative()231     virtual bool GetIsDeclarative() const
232     {
233         return true;
234     }
235 
SetAppBgColor(const Color & color)236     virtual void SetAppBgColor(const Color& color)
237     {
238         appBgColor_ = color;
239     }
240 
GetAppBgColor()241     const Color& GetAppBgColor() const
242     {
243         return appBgColor_;
244     }
245 
GetAppLabelId()246     int32_t GetAppLabelId() const
247     {
248         return appLabelId_;
249     }
250 
SetAppLabelId(int32_t appLabelId)251     void SetAppLabelId(int32_t appLabelId)
252     {
253         appLabelId_ = appLabelId;
254     }
255 
256     virtual void SetAppTitle(const std::string& title) = 0;
257 
258     virtual void SetAppIcon(const RefPtr<PixelMap>& icon) = 0;
259 
SetContainerButtonHide(bool hideSplit,bool hideMaximize,bool hideMinimize)260     virtual void SetContainerButtonHide(bool hideSplit, bool hideMaximize, bool hideMinimize) {}
261 
RefreshRootBgColor()262     virtual void RefreshRootBgColor() const {}
263 
PostponePageTransition()264     virtual void PostponePageTransition() {}
LaunchPageTransition()265     virtual void LaunchPageTransition() {}
266 
GetBoundingRectData(int32_t nodeId,Rect & rect)267     virtual void GetBoundingRectData(int32_t nodeId, Rect& rect) {}
268 
269     virtual RefPtr<AccessibilityManager> GetAccessibilityManager() const;
270 
271     void SetRootSize(double density, int32_t width, int32_t height);
272 
273     void UpdateFontWeightScale();
274 
275     double NormalizeToPx(const Dimension& dimension) const;
276 
277     double ConvertPxToVp(const Dimension& dimension) const;
278 
279     using FinishEventHandler = std::function<void()>;
SetFinishEventHandler(FinishEventHandler && listener)280     void SetFinishEventHandler(FinishEventHandler&& listener)
281     {
282         finishEventHandler_ = std::move(listener);
283     }
284 
285     using StartAbilityHandler = std::function<void(const std::string& address)>;
SetStartAbilityHandler(StartAbilityHandler && listener)286     void SetStartAbilityHandler(StartAbilityHandler&& listener)
287     {
288         startAbilityHandler_ = std::move(listener);
289     }
290     void HyperlinkStartAbility(const std::string& address) const;
291 
292     using ActionEventHandler = std::function<void(const std::string& action)>;
SetActionEventHandler(ActionEventHandler && listener)293     void SetActionEventHandler(ActionEventHandler&& listener)
294     {
295         actionEventHandler_ = std::move(listener);
296     }
297 
298     using FormLinkInfoUpdateHandler = std::function<void(const std::vector<std::string>&)>;
SetFormLinkInfoUpdateHandler(FormLinkInfoUpdateHandler && listener)299     void SetFormLinkInfoUpdateHandler(FormLinkInfoUpdateHandler&& listener)
300     {
301         formLinkInfoUpdateHandler_ = std::move(listener);
302     }
303 
304     using StatusBarEventHandler = std::function<void(const Color& color)>;
SetStatusBarEventHandler(StatusBarEventHandler && listener)305     void SetStatusBarEventHandler(StatusBarEventHandler&& listener)
306     {
307         statusBarBgColorEventHandler_ = std::move(listener);
308     }
309     void NotifyStatusBarBgColor(const Color& color) const;
310 
311     using PopupEventHandler = std::function<void()>;
SetPopupEventHandler(PopupEventHandler && listener)312     void SetPopupEventHandler(PopupEventHandler&& listener)
313     {
314         popupEventHandler_ = std::move(listener);
315     }
316     void NotifyPopupDismiss() const;
317 
318     using MenuEventHandler = std::function<void()>;
SetMenuEventHandler(MenuEventHandler && listener)319     void SetMenuEventHandler(MenuEventHandler&& listener)
320     {
321         menuEventHandler_ = std::move(listener);
322     }
323     void NotifyMenuDismiss() const;
324 
325     using ContextMenuEventHandler = std::function<void()>;
SetContextMenuEventHandler(ContextMenuEventHandler && listener)326     void SetContextMenuEventHandler(ContextMenuEventHandler&& listener)
327     {
328         contextMenuEventHandler_ = std::move(listener);
329     }
330     void NotifyContextMenuDismiss() const;
331 
332     using RouterBackEventHandler = std::function<void()>;
SetRouterBackEventHandler(RouterBackEventHandler && listener)333     void SetRouterBackEventHandler(RouterBackEventHandler&& listener)
334     {
335         routerBackEventHandler_ = std::move(listener);
336     }
337     void NotifyRouterBackDismiss() const;
338 
339     using PopPageSuccessEventHandler = std::function<void(const std::string& pageUrl, const int32_t pageId)>;
SetPopPageSuccessEventHandler(PopPageSuccessEventHandler && listener)340     void SetPopPageSuccessEventHandler(PopPageSuccessEventHandler&& listener)
341     {
342         popPageSuccessEventHandler_.push_back(std::move(listener));
343     }
344     void NotifyPopPageSuccessDismiss(const std::string& pageUrl, int32_t pageId) const;
345 
346     using IsPagePathInvalidEventHandler = std::function<void(bool& isPageInvalid)>;
SetIsPagePathInvalidEventHandler(IsPagePathInvalidEventHandler && listener)347     void SetIsPagePathInvalidEventHandler(IsPagePathInvalidEventHandler&& listener)
348     {
349         isPagePathInvalidEventHandler_.push_back(std::move(listener));
350     }
351     void NotifyIsPagePathInvalidDismiss(bool isPageInvalid) const;
352 
353     using DestroyEventHandler = std::function<void()>;
SetDestroyHandler(DestroyEventHandler && listener)354     void SetDestroyHandler(DestroyEventHandler&& listener)
355     {
356         destroyEventHandler_.push_back(std::move(listener));
357     }
358     void NotifyDestroyEventDismiss() const;
359 
360     using DispatchTouchEventHandler = std::function<void(const TouchEvent& event)>;
SetDispatchTouchEventHandler(DispatchTouchEventHandler && listener)361     void SetDispatchTouchEventHandler(DispatchTouchEventHandler&& listener)
362     {
363         dispatchTouchEventHandler_.push_back(std::move(listener));
364     }
365     void NotifyDispatchTouchEventDismiss(const TouchEvent& event) const;
366 
367     using GetViewScaleCallback = std::function<bool(float&, float&)>;
SetGetViewScaleCallback(GetViewScaleCallback && callback)368     void SetGetViewScaleCallback(GetViewScaleCallback&& callback)
369     {
370         getViewScaleCallback_ = callback;
371     }
372 
373     using OnPageShowCallBack = std::function<void()>;
SetOnPageShow(OnPageShowCallBack && onPageShowCallBack)374     void SetOnPageShow(OnPageShowCallBack&& onPageShowCallBack)
375     {
376         onPageShowCallBack_ = std::move(onPageShowCallBack);
377     }
378 
379     using AnimationCallback = std::function<void()>;
SetAnimationCallback(AnimationCallback && callback)380     void SetAnimationCallback(AnimationCallback&& callback)
381     {
382         animationCallback_ = std::move(callback);
383     }
384 
385     using ProfilerCallback = std::function<void(const std::string&)>;
SetOnVsyncProfiler(const ProfilerCallback & callback)386     void SetOnVsyncProfiler(const ProfilerCallback& callback)
387     {
388         onVsyncProfiler_ = callback;
389     }
390 
391     using OnRouterChangeCallback = bool (*)(const std::string currentRouterPath);
AddRouterChangeCallback(const OnRouterChangeCallback & onRouterChangeCallback)392     void AddRouterChangeCallback(const OnRouterChangeCallback& onRouterChangeCallback)
393     {
394         onRouterChangeCallback_ = onRouterChangeCallback;
395     }
396 
397     void onRouterChange(const std::string& url);
398 
ResetOnVsyncProfiler()399     void ResetOnVsyncProfiler()
400     {
401         onVsyncProfiler_ = nullptr;
402     }
403 
GetViewScale(float & scaleX,float & scaleY)404     bool GetViewScale(float& scaleX, float& scaleY)
405     {
406         if (getViewScaleCallback_) {
407             return getViewScaleCallback_(scaleX, scaleY);
408         }
409         return false;
410     }
411 
GetTaskExecutor()412     RefPtr<TaskExecutor> GetTaskExecutor() const
413     {
414         return taskExecutor_;
415     }
416 
417     RefPtr<Frontend> GetFrontend() const;
418 
GetInstanceId()419     int32_t GetInstanceId() const
420     {
421         return instanceId_;
422     }
423 
424     void ClearImageCache();
425 
426     void SetImageCache(const RefPtr<ImageCache>& imageChache);
427 
428     RefPtr<ImageCache> GetImageCache() const;
429 
GetOrCreateSharedImageManager()430     const RefPtr<SharedImageManager>& GetOrCreateSharedImageManager()
431     {
432         std::scoped_lock<std::shared_mutex> lock(imageMtx_);
433         if (!sharedImageManager_) {
434             sharedImageManager_ = MakeRefPtr<SharedImageManager>(taskExecutor_);
435         }
436         return sharedImageManager_;
437     }
438 
GetWindow()439     Window* GetWindow()
440     {
441         return window_.get();
442     }
443 
GetAssetManager()444     RefPtr<AssetManager> GetAssetManager() const
445     {
446         return assetManager_;
447     }
448 
GetMinPlatformVersion()449     int32_t GetMinPlatformVersion() const
450     {
451         return minPlatformVersion_;
452     }
453 
SetMinPlatformVersion(int32_t minPlatformVersion)454     void SetMinPlatformVersion(int32_t minPlatformVersion)
455     {
456         minPlatformVersion_ = minPlatformVersion;
457     }
458 
SetInstallationFree(int32_t installationFree)459     void SetInstallationFree(int32_t installationFree)
460     {
461         installationFree_ = installationFree;
462     }
463 
GetInstallationFree()464     bool GetInstallationFree() const
465     {
466         return installationFree_;
467     }
468 
SetSharePanelCallback(SharePanelCallback && callback)469     void SetSharePanelCallback(SharePanelCallback&& callback)
470     {
471         sharePanelCallback_ = std::move(callback);
472     }
473 
FireSharePanelCallback(const std::string & bundleName,const std::string & abilityName)474     void FireSharePanelCallback(const std::string& bundleName, const std::string& abilityName)
475     {
476         if (sharePanelCallback_) {
477             sharePanelCallback_(bundleName, abilityName);
478         }
479     }
480 
GetThemeManager()481     RefPtr<ThemeManager> GetThemeManager() const
482     {
483         std::shared_lock<std::shared_mutex> lock(themeMtx_);
484         return themeManager_;
485     }
486 
SetThemeManager(RefPtr<ThemeManager> theme)487     void SetThemeManager(RefPtr<ThemeManager> theme)
488     {
489         CHECK_RUN_ON(UI);
490         std::unique_lock<std::shared_mutex> lock(themeMtx_);
491         themeManager_ = std::move(theme);
492     }
493 
494     template<typename T>
GetTheme()495     RefPtr<T> GetTheme() const
496     {
497         std::shared_lock<std::shared_mutex> lock(themeMtx_);
498         if (themeManager_) {
499             return themeManager_->GetTheme<T>();
500         }
501         return {};
502     }
503 
GetTextFieldManager()504     const RefPtr<ManagerInterface>& GetTextFieldManager()
505     {
506         return textFieldManager_;
507     }
508     void SetTextFieldManager(const RefPtr<ManagerInterface>& manager);
509 
GetFontManager()510     const RefPtr<FontManager>& GetFontManager() const
511     {
512         return fontManager_;
513     }
514 
GetDataProviderManager()515     const RefPtr<DataProviderManagerInterface>& GetDataProviderManager() const
516     {
517         return dataProviderManager_;
518     }
SetDataProviderManager(const RefPtr<DataProviderManagerInterface> & dataProviderManager)519     void SetDataProviderManager(const RefPtr<DataProviderManagerInterface>& dataProviderManager)
520     {
521         dataProviderManager_ = dataProviderManager;
522     }
523 
GetMessageBridge()524     const RefPtr<PlatformBridge>& GetMessageBridge() const
525     {
526         return messageBridge_;
527     }
SetMessageBridge(const RefPtr<PlatformBridge> & messageBridge)528     void SetMessageBridge(const RefPtr<PlatformBridge>& messageBridge)
529     {
530         messageBridge_ = messageBridge;
531     }
532 
SetIsJsCard(bool isJsCard)533     void SetIsJsCard(bool isJsCard)
534     {
535         isJsCard_ = isJsCard;
536     }
537 
SetIsJsPlugin(bool isJsPlugin)538     void SetIsJsPlugin(bool isJsPlugin)
539     {
540         isJsPlugin_ = isJsPlugin;
541     }
542 
SetDrawDelegate(std::unique_ptr<DrawDelegate> delegate)543     void SetDrawDelegate(std::unique_ptr<DrawDelegate> delegate)
544     {
545         drawDelegate_ = std::move(delegate);
546     }
547 
IsJsCard()548     bool IsJsCard() const
549     {
550         return isJsCard_;
551     }
552 
SetIsFormRender(bool isEtsCard)553     void SetIsFormRender(bool isEtsCard)
554     {
555         isFormRender_ = isEtsCard;
556     }
557 
IsFormRender()558     bool IsFormRender() const
559     {
560         return isFormRender_;
561     }
562 
563     // Get the dp scale which used to covert dp to logic px.
GetDipScale()564     double GetDipScale() const
565     {
566         return dipScale_;
567     }
568 
569     // Get the window design scale used to covert lpx to logic px.
GetLogicScale()570     double GetLogicScale() const
571     {
572         return designWidthScale_;
573     }
574 
GetFontScale()575     float GetFontScale() const
576     {
577         return fontScale_;
578     }
579     void SetFontScale(float fontScale);
580 
GetWindowId()581     uint32_t GetWindowId() const
582     {
583         return windowId_;
584     }
585 
SetWindowId(uint32_t windowId)586     void SetWindowId(uint32_t windowId)
587     {
588         windowId_ = windowId;
589     }
590 
SetFocusWindowId(uint32_t windowId)591     void SetFocusWindowId(uint32_t windowId)
592     {
593         focusWindowId_ = windowId;
594     }
595 
GetFocusWindowId()596     uint32_t GetFocusWindowId() const
597     {
598         return focusWindowId_.value_or(windowId_);
599     }
600 
IsFocusWindowIdSetted()601     bool IsFocusWindowIdSetted() const
602     {
603         return focusWindowId_.has_value();
604     }
605 
GetViewScale()606     float GetViewScale() const
607     {
608         return viewScale_;
609     }
610 
GetRootWidth()611     double GetRootWidth() const
612     {
613         return rootWidth_;
614     }
615 
GetRootHeight()616     double GetRootHeight() const
617     {
618         return rootHeight_;
619     }
620 
SetWindowModal(WindowModal modal)621     void SetWindowModal(WindowModal modal)
622     {
623         windowModal_ = modal;
624     }
625 
GetWindowModal()626     WindowModal GetWindowModal() const
627     {
628         return windowModal_;
629     }
630 
IsFullScreenModal()631     bool IsFullScreenModal() const
632     {
633         return windowModal_ == WindowModal::NORMAL || windowModal_ == WindowModal::SEMI_MODAL_FULL_SCREEN ||
634                windowModal_ == WindowModal::CONTAINER_MODAL || isFullWindow_;
635     }
636 
SetIsRightToLeft(bool isRightToLeft)637     void SetIsRightToLeft(bool isRightToLeft)
638     {
639         isRightToLeft_ = isRightToLeft;
640     }
641 
IsRightToLeft()642     bool IsRightToLeft() const
643     {
644         return isRightToLeft_;
645     }
646 
SetEventManager(const RefPtr<EventManager> & eventManager)647     void SetEventManager(const RefPtr<EventManager>& eventManager)
648     {
649         eventManager_ = eventManager;
650     }
651 
GetEventManager()652     RefPtr<EventManager> GetEventManager() const
653     {
654         return eventManager_;
655     }
656 
GetWindowManager()657     const RefPtr<WindowManager>& GetWindowManager() const
658     {
659         return windowManager_;
660     }
661 
662     bool HasFloatTitle() const;
663 
IsRebuildFinished()664     bool IsRebuildFinished() const
665     {
666         return isRebuildFinished_;
667     }
668 
669     void RequestFrame();
670 
671     void RegisterFont(const std::string& familyName, const std::string& familySrc);
672 
673     void GetSystemFontList(std::vector<std::string>& fontList);
674 
675     bool GetSystemFont(const std::string& fontName, FontInfo& fontInfo);
676 
677     void TryLoadImageInfo(const std::string& src, std::function<void(bool, int32_t, int32_t)>&& loadCallback);
678 
679     RefPtr<OffscreenCanvas> CreateOffscreenCanvas(int32_t width, int32_t height);
680 
681     void PostAsyncEvent(TaskExecutor::Task&& task, TaskExecutor::TaskType type = TaskExecutor::TaskType::UI);
682 
683     void PostAsyncEvent(const TaskExecutor::Task& task, TaskExecutor::TaskType type = TaskExecutor::TaskType::UI);
684 
685     void PostSyncEvent(const TaskExecutor::Task& task, TaskExecutor::TaskType type = TaskExecutor::TaskType::UI);
686 
FlushReload()687     virtual void FlushReload() {}
FlushBuild()688     virtual void FlushBuild() {}
689 
FlushReloadTransition()690     virtual void FlushReloadTransition() {}
GetFrontendType()691     FrontendType GetFrontendType() const
692     {
693         return frontendType_;
694     }
695 
GetDensity()696     double GetDensity() const
697     {
698         return density_;
699     }
700 
GetPlatformResRegister()701     RefPtr<PlatformResRegister> GetPlatformResRegister() const
702     {
703         return platformResRegister_;
704     }
705 
706     void SetTouchPipeline(const WeakPtr<PipelineBase>& context);
707     void RemoveTouchPipeline(const WeakPtr<PipelineBase>& context);
708 
709     void OnVirtualKeyboardAreaChange(
710         Rect keyboardArea, const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr);
711 
712     using virtualKeyBoardCallback = std::function<bool(int32_t, int32_t, double)>;
SetVirtualKeyBoardCallback(virtualKeyBoardCallback && listener)713     void SetVirtualKeyBoardCallback(virtualKeyBoardCallback&& listener)
714     {
715         virtualKeyBoardCallback_.push_back(std::move(listener));
716     }
NotifyVirtualKeyBoard(int32_t width,int32_t height,double keyboard)717     bool NotifyVirtualKeyBoard(int32_t width, int32_t height, double keyboard) const
718     {
719         bool isConsume = false;
720         for (const auto& iterVirtualKeyBoardCallback : virtualKeyBoardCallback_) {
721             if (iterVirtualKeyBoardCallback && iterVirtualKeyBoardCallback(width, height, keyboard)) {
722                 isConsume = true;
723             }
724         }
725         return isConsume;
726     }
727 
728     using configChangedCallback = std::function<void()>;
SetConfigChangedCallback(configChangedCallback && listener)729     void SetConfigChangedCallback(configChangedCallback&& listener)
730     {
731         configChangedCallback_.push_back(std::move(listener));
732     }
733 
NotifyConfigurationChange(const OnConfigurationChange & configurationChange)734     virtual void NotifyConfigurationChange(const OnConfigurationChange& configurationChange)
735     {
736         for (const auto& callback : configChangedCallback_) {
737             if (callback) {
738                 callback();
739             }
740         }
741     }
742 
743     using PostRTTaskCallback = std::function<void(std::function<void()>&&)>;
SetPostRTTaskCallBack(PostRTTaskCallback && callback)744     void SetPostRTTaskCallBack(PostRTTaskCallback&& callback)
745     {
746         postRTTaskCallback_ = std::move(callback);
747     }
748 
PostTaskToRT(std::function<void ()> && task)749     void PostTaskToRT(std::function<void()>&& task)
750     {
751         if (postRTTaskCallback_) {
752             postRTTaskCallback_(std::move(task));
753         }
754     }
755 
756     void SetGetWindowRectImpl(std::function<Rect()>&& callback);
757 
758     Rect GetCurrentWindowRect() const;
759 
760     using SafeAreaInsets = NG::SafeAreaInsets;
UpdateSystemSafeArea(const SafeAreaInsets & systemSafeArea)761     virtual void UpdateSystemSafeArea(const SafeAreaInsets& systemSafeArea) {}
762 
UpdateCutoutSafeArea(const SafeAreaInsets & cutoutSafeArea)763     virtual void UpdateCutoutSafeArea(const SafeAreaInsets& cutoutSafeArea) {}
764 
SetPluginOffset(const Offset & offset)765     void SetPluginOffset(const Offset& offset)
766     {
767         pluginOffset_ = offset;
768     }
769 
GetPluginOffset()770     Offset GetPluginOffset() const
771     {
772         return pluginOffset_;
773     }
774 
SetPluginEventOffset(const Offset & offset)775     void SetPluginEventOffset(const Offset& offset)
776     {
777         pluginEventOffset_ = offset;
778     }
779 
GetPluginEventOffset()780     Offset GetPluginEventOffset() const
781     {
782         return pluginEventOffset_;
783     }
NotifyMemoryLevel(int32_t level)784     virtual void NotifyMemoryLevel(int32_t level) {}
785 
SetDisplayWindowRectInfo(const Rect & displayWindowRectInfo)786     void SetDisplayWindowRectInfo(const Rect& displayWindowRectInfo)
787     {
788         displayWindowRectInfo_ = displayWindowRectInfo;
789     }
790 
791     virtual void SetContainerWindow(bool isShow) = 0;
792 
793     // This method can get the coordinates and size of the current window,
794     // which can be added to the return value of the GetGlobalOffset method to get the window coordinates of the node.
GetDisplayWindowRectInfo()795     const Rect& GetDisplayWindowRectInfo() const
796     {
797         return displayWindowRectInfo_;
798     }
799     virtual void FlushMessages() = 0;
SetGSVsyncCallback(std::function<void (void)> && callback)800     void SetGSVsyncCallback(std::function<void(void)>&& callback)
801     {
802         gsVsyncCallback_ = std::move(callback);
803     }
804 
805     virtual void FlushUITasks() = 0;
806 
807     virtual void FlushPipelineImmediately() = 0;
808 
809     // get animateTo closure option
GetSyncAnimationOption()810     AnimationOption GetSyncAnimationOption()
811     {
812         return animationOption_;
813     }
814 
SetSyncAnimationOption(const AnimationOption & option)815     void SetSyncAnimationOption(const AnimationOption& option)
816     {
817         animationOption_ = option;
818     }
819 
SetKeyboardAnimationConfig(const KeyboardAnimationConfig & config)820     void SetKeyboardAnimationConfig(const KeyboardAnimationConfig& config)
821     {
822         keyboardAnimationConfig_ = config;
823     }
824 
SetNextFrameLayoutCallback(std::function<void ()> && callback)825     void SetNextFrameLayoutCallback(std::function<void()>&& callback)
826     {
827         nextFrameLayoutCallback_ = std::move(callback);
828     }
829 
SetForegroundCalled(bool isForegroundCalled)830     void SetForegroundCalled(bool isForegroundCalled)
831     {
832         isForegroundCalled_ = isForegroundCalled;
833     }
834 
SetIsSubPipeline(bool isSubPipeline)835     void SetIsSubPipeline(bool isSubPipeline)
836     {
837         isSubPipeline_ = isSubPipeline;
838     }
839 
IsSubPipeline()840     bool IsSubPipeline() const
841     {
842         return isSubPipeline_;
843     }
844 
SetParentPipeline(const WeakPtr<PipelineBase> & pipeline)845     void SetParentPipeline(const WeakPtr<PipelineBase>& pipeline)
846     {
847         parentPipeline_ = pipeline;
848     }
849 
850     void AddEtsCardTouchEventCallback(int32_t ponitId, EtsCardTouchEventCallback&& callback);
851 
852     void HandleEtsCardTouchEvent(const TouchEvent& point);
853 
854     void RemoveEtsCardTouchEventCallback(int32_t ponitId);
855 
856     void SetSubWindowVsyncCallback(AceVsyncCallback&& callback, int32_t subWindowId);
857 
858     void RemoveSubWindowVsyncCallback(int32_t subWindowId);
859 
SetIsLayoutFullScreen(bool isLayoutFullScreen)860     virtual void SetIsLayoutFullScreen(bool isLayoutFullScreen) {}
SetIgnoreViewSafeArea(bool ignoreViewSafeArea)861     virtual void SetIgnoreViewSafeArea(bool ignoreViewSafeArea) {}
862 
SetIsAppWindow(bool isAppWindow)863     void SetIsAppWindow(bool isAppWindow)
864     {
865         isAppWindow_ = isAppWindow;
866     }
867 
GetIsAppWindow()868     bool GetIsAppWindow() const
869     {
870         return isAppWindow_;
871     }
872 
SetEnableImplicitAnimation(bool enableImplicitAnimation)873     void SetEnableImplicitAnimation(bool enableImplicitAnimation)
874     {
875         enableImplicitAnimation_ = enableImplicitAnimation;
876     }
877 
GetEnableImplicitAnimation()878     bool GetEnableImplicitAnimation() const
879     {
880         return enableImplicitAnimation_;
881     }
882 
883     // restore
RestoreNodeInfo(std::unique_ptr<JsonValue> nodeInfo)884     virtual void RestoreNodeInfo(std::unique_ptr<JsonValue> nodeInfo) {}
885 
GetStoredNodeInfo()886     virtual std::unique_ptr<JsonValue> GetStoredNodeInfo()
887     {
888         return nullptr;
889     }
890 
GetLastTouchTime()891     uint64_t GetLastTouchTime() const
892     {
893         return lastTouchTime_;
894     }
895 
AddFormLinkInfo(int32_t id,const std::string & info)896     void AddFormLinkInfo(int32_t id, const std::string& info)
897     {
898         LOGI("AddFormLinkInfo is %{public}s, id is %{public}d", info.c_str(), id);
899         formLinkInfoMap_[id] = info;
900     }
901 
IsLayouting()902     virtual bool IsLayouting() const
903     {
904         return false;
905     }
906 
907 protected:
908     virtual bool MaybeRelease() override;
TryCallNextFrameLayoutCallback()909     void TryCallNextFrameLayoutCallback()
910     {
911         if (isForegroundCalled_ && nextFrameLayoutCallback_) {
912             isForegroundCalled_ = false;
913             nextFrameLayoutCallback_();
914             LOGI("nextFrameLayoutCallback called");
915         }
916     }
917 
OnDumpInfo(const std::vector<std::string> & params)918     virtual bool OnDumpInfo(const std::vector<std::string>& params) const
919     {
920         return false;
921     }
922     virtual void FlushVsync(uint64_t nanoTimestamp, uint32_t frameCount) = 0;
923     virtual void SetRootRect(double width, double height, double offset = 0.0) = 0;
924     virtual void FlushPipelineWithoutAnimation() = 0;
925 
926     virtual void OnVirtualKeyboardHeightChange(
927         float keyboardHeight, const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr)
928     {}
929 
930     void UpdateRootSizeAndScale(int32_t width, int32_t height);
931 
SetIsReloading(bool isReloading)932     void SetIsReloading(bool isReloading)
933     {
934         isReloading_ = isReloading;
935     }
936 
937     std::list<configChangedCallback> configChangedCallback_;
938     std::list<virtualKeyBoardCallback> virtualKeyBoardCallback_;
939 
940     bool isRebuildFinished_ = false;
941     bool isJsCard_ = false;
942     bool isFormRender_ = false;
943     bool isRightToLeft_ = false;
944     bool isFullWindow_ = false;
945     bool isAppWindow_ = true;
946     bool installationFree_ = false;
947     bool isSubPipeline_ = false;
948 
949     bool isJsPlugin_ = false;
950 
951     std::unordered_map<int32_t, AceVsyncCallback> subWindowVsyncCallbacks_;
952     int32_t minPlatformVersion_ = 0;
953     uint32_t windowId_ = 0;
954     // UIExtensionAbility need component windowID
955     std::optional<uint32_t> focusWindowId_;
956 
957     int32_t appLabelId_ = 0;
958     float fontScale_ = 1.0f;
959     float designWidthScale_ = 1.0f;
960     float viewScale_ = 1.0f;
961     double density_ = 1.0;
962     double dipScale_ = 1.0;
963     double rootHeight_ = 0.0;
964     double rootWidth_ = 0.0;
965     FrontendType frontendType_;
966     WindowModal windowModal_ = WindowModal::NORMAL;
967 
968     Offset pluginOffset_ { 0, 0 };
969     Offset pluginEventOffset_ { 0, 0 };
970     Color appBgColor_ = Color::WHITE;
971 
972     std::unique_ptr<DrawDelegate> drawDelegate_;
973     std::stack<bool> pendingImplicitLayout_;
974     std::stack<bool> pendingImplicitRender_;
975     std::shared_ptr<Window> window_;
976     RefPtr<TaskExecutor> taskExecutor_;
977     RefPtr<AssetManager> assetManager_;
978     WeakPtr<Frontend> weakFrontend_;
979     int32_t instanceId_ = 0;
980     RefPtr<EventManager> eventManager_;
981     RefPtr<ImageCache> imageCache_;
982     RefPtr<SharedImageManager> sharedImageManager_;
983     mutable std::shared_mutex imageMtx_;
984     mutable std::shared_mutex themeMtx_;
985     RefPtr<ThemeManager> themeManager_;
986     RefPtr<DataProviderManagerInterface> dataProviderManager_;
987     RefPtr<FontManager> fontManager_;
988     RefPtr<ManagerInterface> textFieldManager_;
989     RefPtr<PlatformBridge> messageBridge_;
990     RefPtr<WindowManager> windowManager_;
991     OnPageShowCallBack onPageShowCallBack_;
992     AnimationCallback animationCallback_;
993     ProfilerCallback onVsyncProfiler_;
994     FinishEventHandler finishEventHandler_;
995     StartAbilityHandler startAbilityHandler_;
996     ActionEventHandler actionEventHandler_;
997     FormLinkInfoUpdateHandler formLinkInfoUpdateHandler_;
998     RefPtr<PlatformResRegister> platformResRegister_;
999 
1000     WeakPtr<PipelineBase> parentPipeline_;
1001 
1002     std::vector<WeakPtr<PipelineBase>> touchPluginPipelineContext_;
1003     std::unordered_map<int32_t, EtsCardTouchEventCallback> etsCardTouchEventCallback_;
1004 
1005     RefPtr<Clipboard> clipboard_;
1006     std::function<void(const std::string&)> clipboardCallback_ = nullptr;
1007     Rect displayWindowRectInfo_;
1008     AnimationOption animationOption_;
1009     KeyboardAnimationConfig keyboardAnimationConfig_;
1010 
1011     std::function<void()> nextFrameLayoutCallback_ = nullptr;
1012     SharePanelCallback sharePanelCallback_ = nullptr;
1013     std::atomic<bool> isForegroundCalled_ = false;
1014     uint64_t lastTouchTime_ = 0;
1015     std::map<int32_t, std::string> formLinkInfoMap_;
1016 
1017 private:
1018     void DumpFrontend() const;
1019     double ModifyKeyboardHeight(double keyboardHeight) const;
1020     StatusBarEventHandler statusBarBgColorEventHandler_;
1021     PopupEventHandler popupEventHandler_;
1022     MenuEventHandler menuEventHandler_;
1023     ContextMenuEventHandler contextMenuEventHandler_;
1024     RouterBackEventHandler routerBackEventHandler_;
1025     std::list<PopPageSuccessEventHandler> popPageSuccessEventHandler_;
1026     std::list<IsPagePathInvalidEventHandler> isPagePathInvalidEventHandler_;
1027     std::list<DestroyEventHandler> destroyEventHandler_;
1028     std::list<DispatchTouchEventHandler> dispatchTouchEventHandler_;
1029     GetViewScaleCallback getViewScaleCallback_;
1030     // OnRouterChangeCallback is function point, need to be initialized.
1031     OnRouterChangeCallback onRouterChangeCallback_ = nullptr;
1032     PostRTTaskCallback postRTTaskCallback_;
1033     std::function<void(void)> gsVsyncCallback_;
1034     bool enableImplicitAnimation_ = true;
1035     bool isReloading_ = false;
1036 
1037     ACE_DISALLOW_COPY_AND_MOVE(PipelineBase);
1038 };
1039 
1040 } // namespace OHOS::Ace
1041 
1042 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_PIPELINE_PIPELINE_BASE_H
1043