• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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_COMMON_PIPELINE_CONTEXT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_PIPELINE_CONTEXT_H
18 
19 #include <list>
20 #include <map>
21 #include <memory>
22 #include <queue>
23 #include <set>
24 #include <unordered_map>
25 #include <utility>
26 
27 #include "base/geometry/dimension.h"
28 #include "base/geometry/offset.h"
29 #include "base/geometry/rect.h"
30 #include "base/image/pixel_map.h"
31 #include "base/memory/ace_type.h"
32 #include "base/resource/asset_manager.h"
33 #include "base/resource/data_provider_manager.h"
34 #include "base/thread/task_executor.h"
35 #include "base/utils/macros.h"
36 #include "base/utils/noncopyable.h"
37 #include "core/animation/flush_event.h"
38 #include "core/animation/page_transition_listener.h"
39 #include "core/animation/schedule_task.h"
40 #include "core/common/event_manager.h"
41 #include "core/common/focus_animation_manager.h"
42 #include "core/common/platform_res_register.h"
43 #include "core/components/box/drag_drop_event.h"
44 #include "core/components/common/properties/color.h"
45 #include "core/components/dialog/dialog_properties.h"
46 #include "core/components/page/page_component.h"
47 #include "core/components/text_overlay/text_overlay_manager.h"
48 #include "core/components/theme/theme_manager.h"
49 #include "core/event/event_trigger.h"
50 #include "core/gestures/gesture_info.h"
51 #include "core/image/image_cache.h"
52 #include "core/pipeline/base/composed_component.h"
53 #include "core/pipeline/base/factories/render_factory.h"
54 #include "core/pipeline/pipeline_base.h"
55 #ifndef WEARABLE_PRODUCT
56 #include "core/event/multimodal/multimodal_manager.h"
57 #include "core/event/multimodal/multimodal_subscriber.h"
58 #endif
59 #include "core/common/clipboard/clipboard_proxy.h"
60 
61 namespace OHOS::Rosen {
62 class RSUIDirector;
63 } // namespace OHOS::Rosen
64 
65 namespace OHOS::Ace {
66 
67 class CardTransitionController;
68 class ComposedElement;
69 class FontManager;
70 class OverlayElement;
71 class RenderNode;
72 class RenderFocusAnimation;
73 class RootElement;
74 class SharedTransitionController;
75 class StageElement;
76 class StackElement;
77 class Window;
78 class Animator;
79 class ManagerInterface;
80 class AccessibilityManager;
81 class RenderContext;
82 struct PageTarget;
83 class DialogComponent;
84 class SelectPopupComponent;
85 class RenderElement;
86 
87 struct WindowBlurInfo {
88     float progress_;
89     WindowBlurStyle style_;
90     RRect innerRect_;
91     std::vector<RRect> coords_;
92 };
93 
94 struct VisibleCallbackInfo {
95     VisibleRatioCallback callback;
96     double visibleRatio = 1.0;
97     bool isCurrentVisible = false;
98 };
99 
100 using OnRouterChangeCallback = bool (*)(const std::string currentRouterPath);
101 using SubscribeCtrlACallback = std::function<void()>;
102 
103 class ACE_EXPORT PipelineContext : public PipelineBase {
104     DECLARE_ACE_TYPE(PipelineContext, PipelineBase);
105 
106 public:
107     static constexpr int32_t DEFAULT_HOVER_ENTER_ANIMATION_ID = -1;
108     using TimeProvider = std::function<int64_t(void)>;
109     using SurfaceChangedCallbackMap =
110         std::unordered_map<int32_t, std::function<void(int32_t, int32_t, int32_t, int32_t)>>;
111     using SurfacePositionChangedCallbackMap = std::unordered_map<int32_t, std::function<void(int32_t, int32_t)>>;
112 
113     PipelineContext(std::unique_ptr<Window> window, RefPtr<TaskExecutor> taskExecutor,
114         RefPtr<AssetManager> assetManager, RefPtr<PlatformResRegister> platformResRegister,
115         const RefPtr<Frontend>& frontend, int32_t instanceId);
116     PipelineContext(std::unique_ptr<Window> window, RefPtr<TaskExecutor>& taskExecutor,
117         RefPtr<AssetManager> assetManager, const RefPtr<Frontend>& frontend);
118 
119     ~PipelineContext() override;
120 
121     void SetupRootElement() override;
122 
123     // This is used for subwindow, when the subwindow is created,a new subRootElement will be built
124     RefPtr<Element> SetupSubRootElement();
125     RefPtr<DialogComponent> ShowDialog(
126         const DialogProperties& dialogProperties, bool isRightToLeft, const std::string& inspectorTag = "");
127     void CloseContextMenu();
128     void GetBoundingRectData(int32_t nodeId, Rect& rect) override;
129 
130     void PushVisibleCallback(int32_t nodeId, double ratio, std::function<void(bool, double)>&& callback);
131     void RemoveVisibleChangeNode(int32_t nodeId);
132 
133     void PushPage(const RefPtr<PageComponent>& pageComponent, const RefPtr<StageElement>& stage);
134     void PushPage(const RefPtr<PageComponent>& pageComponent);
135     void PostponePageTransition() override;
136     void LaunchPageTransition() override;
137 
138     bool CanPushPage();
139 
140     bool IsTransitionStop() const;
141 
142     void PopPage();
143 
144     void PopToPage(int32_t pageId);
145 
146     void RestorePopPage(const RefPtr<PageComponent>& pageComponent);
147 
148     bool CanPopPage();
149 
150     void ReplacePage(const RefPtr<PageComponent>& pageComponent, const RefPtr<StageElement>& stage,
151         const std::function<void()>& listener = nullptr);
152     void ReplacePage(const RefPtr<PageComponent>& pageComponent);
153 
154     bool CanReplacePage();
155 
156     bool ClearInvisiblePages(const std::function<void()>& listener = nullptr);
157 
158     bool CallRouterBackToPopPage() override;
159 
160     void SetSinglePageId(int32_t pageId);
161 
162     bool PopPageStackOverlay();
163 
164     void NotifyAppStorage(const std::string& key, const std::string& value);
165 
166     RefPtr<StackElement> GetLastStack() const;
167 
168     RefPtr<PageElement> GetLastPage() const;
169 
170     RefPtr<RenderNode> GetLastPageRender() const;
171 
172     void ScheduleUpdate(const RefPtr<ComposedComponent>& composed);
173 
174     void AddComposedElement(const ComposeId& id, const RefPtr<ComposedElement>& element);
175 
176     void RemoveComposedElement(const ComposeId& id, const RefPtr<ComposedElement>& element);
177 
178     void AddDirtyElement(const RefPtr<Element>& dirtyElement);
179 
180     void AddNeedRebuildFocusElement(const RefPtr<Element>& focusElement);
181 
182     void AddDirtyRenderNode(const RefPtr<RenderNode>& renderNode, bool overlay = false);
183 
184     void AddNeedRenderFinishNode(const RefPtr<RenderNode>& renderNode);
185 
186     void AddDirtyLayoutNode(const RefPtr<RenderNode>& renderNode);
187 
188     void AddPredictLayoutNode(const RefPtr<RenderNode>& renderNode);
189 
190     void AddGeometryChangedNode(const RefPtr<RenderNode>& renderNode);
191 
192     void AddPreFlushListener(const RefPtr<FlushEvent>& listener);
193 
194     void AddPostAnimationFlushListener(const RefPtr<FlushEvent>& listener);
195 
196     void AddPostFlushListener(const RefPtr<FlushEvent>& listener);
197 
198     void AddPageUpdateTask(std::function<void()>&& task, bool directExecute = false);
199 
200     void SetRequestedRotationNode(const WeakPtr<RenderNode>& renderNode);
201 
202     void RemoveRequestedRotationNode(const WeakPtr<RenderNode>& renderNode);
203 
204     // add schedule task and return the unique mark id.
205     uint32_t AddScheduleTask(const RefPtr<ScheduleTask>& task) override;
206 
207     // remove schedule task by id.
208     void RemoveScheduleTask(uint32_t id) override;
209 
210     // Called by view when touch event received.
211     void OnTouchEvent(const TouchEvent& point, bool isSubPipe = false) override;
212 
213     // Called by container when key event received.
214     // if return false, then this event needs platform to handle it.
215     bool OnKeyEvent(const KeyEvent& event) override;
216 
217     // Called by view when mouse event received.
218     void OnMouseEvent(const MouseEvent& event) override;
219 
220     // Called by view when axis event received.
221     void OnAxisEvent(const AxisEvent& event) override;
222 
223     // Called by container when rotation event received.
224     // if return false, then this event needs platform to handle it.
225     bool OnRotationEvent(const RotationEvent& event) const override;
226 
227     // Called by view when idle event.
228     void OnIdle(int64_t deadline) override;
229 
230     void OnVirtualKeyboardHeightChange(float keyboardHeight) override;
231 
232     // Set card position for barrierFree
233     void SetCardViewPosition(int id, float offsetX, float offsetY);
234 
235     void SetCardViewAccessibilityParams(const std::string& key, bool focus);
236 
237     void FlushPipelineImmediately() override;
238 
RegisterEventHandler(const RefPtr<AceEventHandler> & handler)239     void RegisterEventHandler(const RefPtr<AceEventHandler>& handler)
240     {
241         eventTrigger_.RegisterEventHandler(handler);
242     }
243 
244     template<class... Args>
FireAsyncEvent(const EventMarker & marker,Args &&...args)245     void FireAsyncEvent(const EventMarker& marker, Args&&... args)
246     {
247         eventTrigger_.TriggerAsyncEvent(marker, std::forward<Args>(args)...);
248     }
249 
250     template<class... Args>
FireSyncEvent(const EventMarker & marker,Args &&...args)251     void FireSyncEvent(const EventMarker& marker, Args&&... args)
252     {
253         eventTrigger_.TriggerSyncEvent(marker, std::forward<Args>(args)...);
254     }
255 
256     void OnSurfaceChanged(
257         int32_t width, int32_t height, WindowSizeChangeReason type = WindowSizeChangeReason::UNDEFINED) override;
258 
259     void OnSurfacePositionChanged(int32_t posX, int32_t posY) override;
260 
261     void WindowSizeChangeAnimate(int32_t width, int32_t height, WindowSizeChangeReason type);
262 
263     void OnSurfaceDensityChanged(double density) override;
264 
265     void OnSystemBarHeightChanged(double statusBar, double navigationBar) override;
266 
267     void OnSurfaceDestroyed() override;
268 
269     // SemiModal and DialogModal have their own enter/exit animation and will exit after animation done.
270     void Finish(bool autoFinish = true) const override;
271 
272     void RequestFullWindow(int32_t duration) override;
273 
274     // Get the font scale used to covert fp to logic px.
GetFontUnitScale()275     double GetFontUnitScale() const
276     {
277         return dipScale_ * fontScale_;
278     }
279 
280     RefPtr<RenderNode> DragTestAll(const TouchEvent& point);
281     RefPtr<RenderNode> DragTest(const TouchEvent& point, const RefPtr<RenderNode>& renderNode, int32_t deep);
282 
SetRootHeight(double rootHeight)283     void SetRootHeight(double rootHeight)
284     {
285         if (rootHeight > 0.0) {
286             rootHeight_ = rootHeight;
287         }
288     }
289 
290     Rect GetRootRect() const;
291     Rect GetStageRect() const;
292     Rect GetPageRect() const;
293 
IsSurfaceReady()294     bool IsSurfaceReady() const
295     {
296         return isSurfaceReady_;
297     }
298 
299     void ShowFocusAnimation(
300         const RRect& rrect, const Color& color, const Offset& offset, bool isIndented = false) const;
301 
302     void ShowFocusAnimation(const RRect& rrect, const Color& color, const Offset& offset, const Rect& clipRect) const;
303 
304     void ShowShadow(const RRect& rrect, const Offset& offset) const;
305 
306     void ShowShadow(const RRect& rrect, const Offset& offset, const Rect& clipRect) const;
307 
308     RefPtr<RenderFocusAnimation> GetRenderFocusAnimation() const;
309 
310     void PushFocusAnimation(const RefPtr<Element>& element) const;
311 
312     void PushShadow(const RefPtr<Element>& element) const;
313 
314     void PopFocusAnimation() const;
315 
316     void PopRootFocusAnimation() const;
317 
318     void PopShadow() const;
319 
320     void CancelFocusAnimation() const;
321 
322     void CancelShadow() const;
323 
324     void SetUseRootAnimation(bool useRoot);
325 
326     void AddDirtyFocus(const RefPtr<FocusNode>& node);
327 
328     void RefreshStageFocus();
329 
330     void ShowContainerTitle(bool isShow) override;
331 
332     void SetContainerButtonHide(bool hideSplit, bool hideMaximize, bool hideMinimize);
333 
334     RefPtr<StageElement> GetStageElement() const;
335 
336     RefPtr<ComposedElement> GetComposedElementById(const ComposeId& id);
337 
338     void SendCallbackMessageToFrontend(const std::string& callbackId, const std::string& data);
339 
340     void SendEventToFrontend(const EventMarker& eventMarker);
341 
342     void SendEventToFrontend(const EventMarker& eventMarker, const std::string& param);
343 
344     bool AccessibilityRequestFocus(const ComposeId& id);
345 
346     bool RequestFocus(const RefPtr<Element>& targetElement);
347     bool RequestFocus(const std::string& targetNodeId) override;
348     bool RequestDefaultFocus();
349 
350     BaseId::IdType AddPageTransitionListener(const PageTransitionListenable::CallbackFuncType& funcObject);
351 
352     const RefPtr<OverlayElement> GetOverlayElement() const;
353 
354     void RemovePageTransitionListener(typename BaseId::IdType id);
355 
356     void ClearPageTransitionListeners();
357 
358     void Destroy() override;
359 
360     bool IsLastPage() override;
361 
362     RefPtr<Element> GetDeactivateElement(int32_t componentId) const;
363 
364     void ClearDeactivateElements();
365 
366     void AddDeactivateElement(int32_t id, const RefPtr<Element>& element);
367 
GetRenderFactory()368     const RefPtr<RenderFactory>& GetRenderFactory() const
369     {
370         return renderFactory_;
371     }
372 
373 #ifndef WEARABLE_PRODUCT
374     void SetMultimodalSubscriber(const RefPtr<MultimodalSubscriber>& multimodalSubscriber);
375 
GetMultiModalManager()376     const RefPtr<MultiModalManager>& GetMultiModalManager() const
377     {
378         return multiModalManager_;
379     }
380 #endif
381 
382     void SetWindowOnShow();
383 
384     void SetWindowOnHide();
385 
386     void OnShow() override;
387 
388     void OnHide() override;
389 
MarkForcedRefresh()390     void MarkForcedRefresh()
391     {
392         needForcedRefresh_ = true;
393     }
394 
395     void SetTimeProvider(TimeProvider&& timeProvider);
396 
397     uint64_t GetTimeFromExternalTimer() override;
398 
399     void AddFontNode(const WeakPtr<RenderNode>& node);
400 
401     void RemoveFontNode(const WeakPtr<RenderNode>& node);
402 
403     void LoadSystemFont(const std::function<void()>& onFondsLoaded);
404 
GetSharedTransitionController()405     const RefPtr<SharedTransitionController>& GetSharedTransitionController() const
406     {
407         return sharedTransitionController_;
408     }
409 
GetCardTransitionController()410     const RefPtr<CardTransitionController>& GetCardTransitionController() const
411     {
412         return cardTransitionController_;
413     }
414 
415     void SetClickPosition(const Offset& position) const;
416 
417     void RootLostFocus(BlurReason reason = BlurReason::FOCUS_SWITCH) const;
418 
419     void FlushFocus();
420 
421     void WindowFocus(bool isFocus) override;
422 
423     void OnPageShow() override;
424 
GetStatusBarHeight()425     double GetStatusBarHeight() const
426     {
427         return statusBarHeight_;
428     }
429 
GetNavigationBarHeight()430     double GetNavigationBarHeight() const
431     {
432         return navigationBarHeight_;
433     }
434 
SetAppearingDuration(int32_t duration)435     void SetAppearingDuration(int32_t duration)
436     {
437         cardAppearingDuration_ = duration;
438     }
439 
GetAppearingDuration()440     int32_t GetAppearingDuration() const
441     {
442         return cardAppearingDuration_;
443     }
444 
SetModalHeight(int32_t height)445     void SetModalHeight(int32_t height)
446     {
447         modalHeight_ = height;
448     }
449 
SetModalColor(uint32_t color)450     void SetModalColor(uint32_t color)
451     {
452         modalColor_ = color;
453     }
454 
455     void MovePage(const Offset& rootRect, double offsetHeight);
456 
SetBuildAfterCallback(const std::function<void ()> & callback)457     void SetBuildAfterCallback(const std::function<void()>& callback) override
458     {
459         buildAfterCallback_.emplace_back(callback);
460     }
461 
462     void SetIsKeyEvent(bool isKeyEvent);
463 
IsKeyEvent()464     bool IsKeyEvent() const
465     {
466         return isKeyEvent_;
467     }
468 
IsJsPlugin()469     bool IsJsPlugin() const
470     {
471         return isJsPlugin_;
472     }
473 
474     void RefreshRootBgColor() const override;
475     void AddToHoverList(const RefPtr<RenderNode>& node);
476 
477     using UpdateWindowBlurRegionHandler = std::function<void(const std::vector<std::vector<float>>&)>;
478 
SetUpdateWindowBlurRegionHandler(UpdateWindowBlurRegionHandler handler)479     void SetUpdateWindowBlurRegionHandler(UpdateWindowBlurRegionHandler handler)
480     {
481         updateWindowBlurRegionHandler_ = std::move(handler);
482     }
483 
484     using DragEventHandler = std::function<void(const std::string&, const RefPtr<PixelMap>& pixmap)>;
485 
SetDragEventHandler(DragEventHandler && callback)486     void SetDragEventHandler(DragEventHandler&& callback)
487     {
488         dragEventHandler_ = callback;
489     }
490 
491     using InitDragEventListener = std::function<void()>;
492 
SetInitDragListener(InitDragEventListener && callback)493     void SetInitDragListener(InitDragEventListener&& callback)
494     {
495         initDragEventListener_ = callback;
496     }
497 
498     void UpdateWindowBlurRegion(
499         int32_t id, RRect rRect, float progress, WindowBlurStyle style, const std::vector<RRect>& coords);
500 
501     void ClearWindowBlurRegion(int32_t id);
502 
IsBuildingFirstPage()503     bool IsBuildingFirstPage() const
504     {
505         return buildingFirstPage_;
506     }
507 
508     using UpdateWindowBlurDrawOpHandler = std::function<void(void)>;
509 
SetUpdateWindowBlurDrawOpHandler(UpdateWindowBlurDrawOpHandler handler)510     void SetUpdateWindowBlurDrawOpHandler(UpdateWindowBlurDrawOpHandler handler)
511     {
512         updateWindowBlurDrawOpHandler_ = std::move(handler);
513     }
514 
515     void NavigatePage(uint8_t type, const PageTarget& target, const std::string& params);
516 
517     void AddKeyFrame(
518         float fraction, const RefPtr<Curve>& curve, const std::function<void()>& propertyCallback) override;
519 
520     void AddKeyFrame(float fraction, const std::function<void()>& propertyCallback) override;
521 
522     void SaveExplicitAnimationOption(const AnimationOption& option) override;
523 
524     void CreateExplicitAnimator(const std::function<void()>& onFinishEvent) override;
525 
526     void ClearExplicitAnimationOption() override;
527 
528     AnimationOption GetExplicitAnimationOption() const override;
529 
530     void FlushBuild() override;
531 
SetUseLiteStyle(bool useLiteStyle)532     void SetUseLiteStyle(bool useLiteStyle)
533     {
534         useLiteStyle_ = useLiteStyle;
535     }
536 
UseLiteStyle()537     bool UseLiteStyle() const
538     {
539         return useLiteStyle_;
540     }
541 
GetDirtyRect()542     const Rect& GetDirtyRect() const
543     {
544         return dirtyRect_;
545     }
546 
547     bool GetIsDeclarative() const override;
548 
IsForbidPlatformQuit()549     bool IsForbidPlatformQuit() const
550     {
551         return forbidPlatformQuit_;
552     }
553 
554     void SetForbidPlatformQuit(bool forbidPlatformQuit);
555 
556     void SetAppBgColor(const Color& color) override;
557 
SetPhotoCachePath(const std::string & photoCachePath)558     void SetPhotoCachePath(const std::string& photoCachePath)
559     {
560         photoCachePath_ = photoCachePath;
561     }
562 
GetPhotoCachePath()563     const std::string& GetPhotoCachePath()
564     {
565         return photoCachePath_;
566     }
567 
SetScreenOnCallback(std::function<void (std::function<void ()> && func)> && screenOnCallback)568     void SetScreenOnCallback(std::function<void(std::function<void()>&& func)>&& screenOnCallback)
569     {
570         screenOnCallback_ = std::move(screenOnCallback);
571     }
572 
SetScreenOffCallback(std::function<void (std::function<void ()> && func)> && screenOffCallback)573     void SetScreenOffCallback(std::function<void(std::function<void()>&& func)>&& screenOffCallback)
574     {
575         screenOffCallback_ = std::move(screenOffCallback);
576     }
577 
578     void AddScreenOnEvent(std::function<void()>&& func);
579     void AddScreenOffEvent(std::function<void()>&& func);
580     void AddAlignDeclarationNode(const RefPtr<RenderNode>& node);
581     void AddLayoutTransitionNode(const RefPtr<RenderNode>& node);
582     std::list<RefPtr<RenderNode>>& GetAlignDeclarationNodeList();
SetQueryIfWindowInScreenCallback(std::function<void ()> && func)583     void SetQueryIfWindowInScreenCallback(std::function<void()>&& func)
584     {
585         queryIfWindowInScreenCallback_ = std::move(func);
586     }
SetIsWindowInScreen(bool isWindowInScreen)587     void SetIsWindowInScreen(bool isWindowInScreen)
588     {
589         isWindowInScreen_ = isWindowInScreen;
590     }
591     // This interface posts an async task to do async query and returns the result from previous query.
592     bool IsWindowInScreen();
593     void NotifyOnPreDraw() override;
594     void AddNodesToNotifyOnPreDraw(const RefPtr<RenderNode>& renderNode);
595 
596     void UpdateNodesNeedDrawOnPixelMap();
597     void SearchNodesNeedDrawOnPixelMap(const RefPtr<RenderNode>& renderNode);
598     void NotifyDrawOnPixelMap();
599 
GetRootElement()600     const RefPtr<RootElement>& GetRootElement() const
601     {
602         return rootElement_;
603     }
604 
SetAccessibilityEnabled(bool isEnabled)605     void SetAccessibilityEnabled(bool isEnabled)
606     {
607         isAccessibilityEnabled_ = isEnabled;
608     }
IsAccessibilityEnabled()609     bool IsAccessibilityEnabled() const
610     {
611         return isAccessibilityEnabled_ || IsVisibleChangeNodeExists(-1);
612     }
613 
614     bool IsVisibleChangeNodeExists(NodeId index) const;
615 
RegisterSurfaceChangedCallback(std::function<void (int32_t,int32_t,int32_t,int32_t)> && callback)616     int32_t RegisterSurfaceChangedCallback(std::function<void(int32_t, int32_t, int32_t, int32_t)>&& callback)
617     {
618         if (callback) {
619             surfaceChangedCallbackMap_.emplace(++callbackId_, std::move(callback));
620             return callbackId_;
621         }
622         return 0;
623     }
624 
UnregisterSurfaceChangedCallback(int32_t callbackId)625     void UnregisterSurfaceChangedCallback(int32_t callbackId)
626     {
627         surfaceChangedCallbackMap_.erase(callbackId);
628     }
629 
RegisterSurfacePositionChangedCallback(std::function<void (int32_t,int32_t)> && callback)630     int32_t RegisterSurfacePositionChangedCallback(std::function<void(int32_t, int32_t)>&& callback)
631     {
632         if (callback) {
633             surfacePositionChangedCallbackMap_.emplace(++callbackId_, std::move(callback));
634             return callbackId_;
635         }
636         return 0;
637     }
638 
UnregisterSurfacePositionChangedCallback(int32_t callbackId)639     void UnregisterSurfacePositionChangedCallback(int32_t callbackId)
640     {
641         surfacePositionChangedCallbackMap_.erase(callbackId);
642     }
643     void StartSystemDrag(const std::string& str, const RefPtr<PixelMap>& pixmap);
644     void InitDragListener();
645     void OnDragEvent(int32_t x, int32_t y, DragEventAction action) override;
646     void SetPreTargetRenderNode(const RefPtr<DragDropEvent>& preDragDropNode);
647     const RefPtr<DragDropEvent>& GetPreTargetRenderNode() const;
648     void SetInitRenderNode(const RefPtr<RenderNode>& initRenderNode);
649     const RefPtr<RenderNode>& GetInitRenderNode() const;
650 
SetContextMenu(const RefPtr<Component> & contextMenu)651     void SetContextMenu(const RefPtr<Component>& contextMenu)
652     {
653         contextMenu_ = contextMenu;
654     }
655 
656     void SetClipHole(double left, double top, double width, double height);
657 
GetTransparentHole()658     const Rect& GetTransparentHole() const
659     {
660         return transparentHole_;
661     }
662 
GetHasMeetSubWindowNode()663     bool GetHasMeetSubWindowNode() const
664     {
665         return hasMeetSubWindowNode_;
666     }
667 
SetHasMeetSubWindowNode(bool hasMeetSubWindowNode)668     void SetHasMeetSubWindowNode(bool hasMeetSubWindowNode)
669     {
670         hasMeetSubWindowNode_ = hasMeetSubWindowNode;
671     }
672 
GetHasClipHole()673     bool GetHasClipHole() const
674     {
675         return hasClipHole_;
676     }
677 
SetHasClipHole(bool hasClipHole)678     void SetHasClipHole(bool hasClipHole)
679     {
680         hasClipHole_ = hasClipHole;
681     }
682 
GetIsHoleValid()683     bool GetIsHoleValid() const
684     {
685         return isHoleValid_;
686     }
687 
688     void SetRSUIDirector(std::shared_ptr<OHOS::Rosen::RSUIDirector> rsUIDirector);
689 
690     std::shared_ptr<OHOS::Rosen::RSUIDirector> GetRSUIDirector();
691 
IsShiftDown()692     bool IsShiftDown() const
693     {
694         return isShiftDown_;
695     }
696 
MarkIsShiftDown(bool isShiftDown)697     void MarkIsShiftDown(bool isShiftDown)
698     {
699         isShiftDown_ = isShiftDown;
700     }
701 
IsCtrlDown()702     bool IsCtrlDown() const
703     {
704         return isCtrlDown_;
705     }
706 
MarkIsCtrlDown(bool isCtrlDown)707     void MarkIsCtrlDown(bool isCtrlDown)
708     {
709         isCtrlDown_ = isCtrlDown;
710     }
711 
IsKeyboardA()712     bool IsKeyboardA() const
713     {
714         return isKeyboardA_;
715     }
716 
MarkIsKeyboardA(bool isKeyboardA)717     void MarkIsKeyboardA(bool isKeyboardA)
718     {
719         isKeyboardA_ = isKeyboardA;
720     }
721 
722     void SetShortcutKey(const KeyEvent& event);
723 
SetTextOverlayManager(const RefPtr<TextOverlayManager> & textOverlayManager)724     void SetTextOverlayManager(const RefPtr<TextOverlayManager>& textOverlayManager)
725     {
726         textOverlayManager_ = textOverlayManager;
727     }
728 
GetTextOverlayManager()729     RefPtr<TextOverlayManager> GetTextOverlayManager() const
730     {
731         return textOverlayManager_;
732     }
733 
SubscribeCtrlA(SubscribeCtrlACallback callback)734     void SubscribeCtrlA(SubscribeCtrlACallback callback)
735     {
736         subscribeCtrlA_ = std::move(callback);
737     }
738 
SetClipboardCallback(const std::function<void (const std::string &)> & callback)739     void SetClipboardCallback(const std::function<void(const std::string&)>& callback)
740     {
741         clipboardCallback_ = callback;
742     }
743 
744     void ProcessDragEvent(
745         const RefPtr<RenderNode>& renderNode, const RefPtr<DragEvent>& event, const Point& globalPoint);
746     void ProcessDragEventEnd(
747         const RefPtr<RenderNode>& renderNode, const RefPtr<DragEvent>& event, const Point& globalPoint);
748 
749     void StoreNode(int32_t restoreId, const WeakPtr<RenderElement>& node);
750 
751     std::unique_ptr<JsonValue> GetStoredNodeInfo();
752 
753     void RestoreNodeInfo(std::unique_ptr<JsonValue> nodeInfo);
754 
755     std::string GetRestoreInfo(int32_t restoreId);
756 
GetIsTabKeyPressed()757     bool GetIsTabKeyPressed() const
758     {
759         return isTabKeyPressed_;
760     }
761 
GetIsFocusingByTab()762     bool GetIsFocusingByTab() const
763     {
764         return isFocusingByTab_;
765     }
766 
SetIsFocusingByTab(bool isFocusingByTab)767     void SetIsFocusingByTab(bool isFocusingByTab)
768     {
769         isFocusingByTab_ = isFocusingByTab;
770     }
771 
772     void AddVisibleAreaChangeNode(const ComposeId& nodeId, double ratio, const VisibleRatioCallback& callback);
773 
GetOnShow()774     bool GetOnShow() const
775     {
776         return onShow_;
777     }
778 
AddRectCallback(OutOfRectGetRectCallback & getRectCallback,OutOfRectTouchCallback & touchCallback,OutOfRectMouseCallback & mouseCallback)779     void AddRectCallback(OutOfRectGetRectCallback& getRectCallback, OutOfRectTouchCallback& touchCallback,
780         OutOfRectMouseCallback& mouseCallback)
781     {
782         rectCallbackList_.emplace_back(RectCallback(getRectCallback, touchCallback, mouseCallback));
783     }
784 
785     void SetRootRect(double width, double height, double offset = 0.0) override
786     {
787         SetRootSizeWithWidthHeight(width, height, offset);
788     }
789 
790     void SetContainerWindow(bool isShow) override;
791 
792     void SetAppTitle(const std::string& title) override;
793     void SetAppIcon(const RefPtr<PixelMap>& icon) override;
794     void FlushMessages() override;
795 
796 protected:
797     bool OnDumpInfo(const std::vector<std::string>& params) const override;
798     void FlushVsync(uint64_t nanoTimestamp, uint32_t frameCount) override;
799     void FlushPipelineWithoutAnimation() override;
800     void FlushAnimation(uint64_t nanoTimestamp) override;
801     void FlushReload() override;
802     void FlushReloadTransition() override;
FlushUITasks()803     void FlushUITasks() override
804     {
805         FlushLayout();
806     }
807 
808     std::shared_ptr<OHOS::Rosen::RSUIDirector> rsUIDirector_;
809     bool hasIdleTasks_ = false;
810 
811 private:
812     void FlushLayout();
813     void FlushGeometryProperties();
814     void FlushRender();
815     void FlushRenderFinish();
816     void FireVisibleChangeEvent();
817     void FlushPredictLayout(int64_t deadline);
818     void FlushPostAnimation();
819     void FlushPageUpdateTasks();
820     void ProcessPreFlush();
821     void ProcessPostFlush();
822     void SetRootSizeWithWidthHeight(int32_t width, int32_t height, int32_t offset = 0);
823     void FlushBuildAndLayoutBeforeSurfaceReady();
824     void FlushAnimationTasks();
825     void DumpAccessibility(const std::vector<std::string>& params) const;
826     void FlushWindowBlur();
827     void MakeThreadStuck(const std::vector<std::string>& params) const;
828     void ExitAnimation();
829     void CreateGeometryTransition();
830     void CorrectPosition();
831     void CreateTouchEventOnZoom(const AxisEvent& event);
832     void HandleVisibleAreaChangeEvent();
833     void FlushTouchEvents();
834 
835     template<typename T>
836     struct NodeCompare {
operatorNodeCompare837         bool operator()(const T& nodeLeft, const T& nodeRight) const
838         {
839             if (nodeLeft->GetDepth() < nodeRight->GetDepth()) {
840                 return true;
841             }
842             if (nodeLeft->GetDepth() == nodeRight->GetDepth()) {
843                 return nodeLeft < nodeRight;
844             }
845             return false;
846         }
847     };
848 
849     template<typename T>
850     struct NodeCompareWeak {
operatorNodeCompareWeak851         bool operator()(const T& nodeLeftWeak, const T& nodeRightWeak) const
852         {
853             auto nodeLeft = nodeLeftWeak.Upgrade();
854             auto nodeRight = nodeRightWeak.Upgrade();
855             if (!nodeLeft || !nodeRight) {
856                 return true;
857             }
858             auto compare = NodeCompare<decltype(nodeLeft)>();
859             return compare(nodeLeft, nodeRight);
860         }
861     };
862 
863     Rect dirtyRect_;
864     uint32_t nextScheduleTaskId_ = 0;
865     std::mutex scheduleTasksMutex_;
866     std::unordered_map<uint32_t, RefPtr<ScheduleTask>> scheduleTasks_;
867     std::unordered_map<ComposeId, std::list<RefPtr<ComposedElement>>> composedElementMap_;
868     std::set<WeakPtr<Element>, NodeCompareWeak<WeakPtr<Element>>> dirtyElements_;
869     std::set<WeakPtr<Element>, NodeCompareWeak<WeakPtr<Element>>> needRebuildFocusElement_;
870     std::set<RefPtr<RenderNode>, NodeCompare<RefPtr<RenderNode>>> dirtyRenderNodes_;
871     std::set<RefPtr<RenderNode>, NodeCompare<RefPtr<RenderNode>>> dirtyRenderNodesInOverlay_;
872     std::set<RefPtr<RenderNode>, NodeCompare<RefPtr<RenderNode>>> dirtyLayoutNodes_;
873     std::set<RefPtr<RenderNode>, NodeCompare<RefPtr<RenderNode>>> predictLayoutNodes_;
874     std::set<RefPtr<RenderNode>, NodeCompare<RefPtr<RenderNode>>> needPaintFinishNodes_;
875     std::set<RefPtr<RenderNode>, NodeCompare<RefPtr<RenderNode>>> geometryChangedNodes_;
876     std::set<RefPtr<RenderNode>> nodesToNotifyOnPreDraw_;
877     std::set<RefPtr<RenderNode>> nodesNeedDrawOnPixelMap_;
878     std::list<RefPtr<FlushEvent>> postFlushListeners_;
879     std::list<RefPtr<FlushEvent>> postAnimationFlushListeners_;
880     std::list<RefPtr<FlushEvent>> preFlushListeners_;
881     RefPtr<FocusAnimationManager> focusAnimationManager_;
882 
883     RefPtr<RootElement> rootElement_;
884     WeakPtr<FocusNode> dirtyFocusNode_;
885     WeakPtr<FocusNode> dirtyFocusScope_;
886     std::list<std::function<void()>> buildAfterCallback_;
887     RefPtr<RenderFactory> renderFactory_;
888     UpdateWindowBlurRegionHandler updateWindowBlurRegionHandler_;
889     UpdateWindowBlurDrawOpHandler updateWindowBlurDrawOpHandler_;
890     DragEventHandler dragEventHandler_;
891     InitDragEventListener initDragEventListener_;
892     std::vector<KeyCode> pressedKeyCodes;
893     TouchEvent zoomEventA_;
894     TouchEvent zoomEventB_;
895     bool isOnScrollZoomEvent_ = false;
896     bool isKeyCtrlPressed_ = false;
897 
898     Rect transparentHole_;
899     // use for traversing clipping hole
900     bool hasMeetSubWindowNode_ = false;
901     // use for judge clip hole status
902     bool hasClipHole_ = false;
903     // judge hole is valid
904     bool isHoleValid_ = false;
905 
906 #ifndef WEARABLE_PRODUCT
907     RefPtr<MultiModalManager> multiModalManager_ = MakeRefPtr<MultiModalManager>();
908 #endif
909     RefPtr<SharedTransitionController> sharedTransitionController_;
910     RefPtr<CardTransitionController> cardTransitionController_;
911     RefPtr<TextOverlayManager> textOverlayManager_;
912     EventTrigger eventTrigger_;
913 
914     WeakPtr<RenderNode> requestedRenderNode_;
915     // Make page update tasks pending here to avoid block receiving vsync.
916     std::queue<std::function<void()>> pageUpdateTasks_;
917     // strong deactivate element and it's id.
918     std::map<int32_t, RefPtr<Element>> deactivateElements_;
919 
920     RefPtr<Component> contextMenu_;
921 
922     // window blur region
923     std::unordered_map<int32_t, WindowBlurInfo> windowBlurRegions_;
924 
925     std::list<RefPtr<RenderNode>> alignDeclarationNodeList_;
926     std::set<RefPtr<RenderNode>> layoutTransitionNodeSet_;
927 
928     std::function<void()> queryIfWindowInScreenCallback_;
929     std::atomic<bool> isWindowInScreen_ = true;
930 
931     RefPtr<DragDropEvent> preTargetRenderNode_;
932 
933     bool isSurfaceReady_ = false;
934 
935     int32_t cardAppearingDuration_ = 0;
936     double statusBarHeight_ = 0.0;     // dp
937     double navigationBarHeight_ = 0.0; // dp
938     bool needForcedRefresh_ = false;
939     bool isFlushingAnimation_ = false;
940     bool isMoving_ = false;
941     std::atomic<bool> onShow_ = true;
942     std::atomic<bool> onFocus_ = true;
943     bool isKeyEvent_ = false;
944     bool needWindowBlurRegionRefresh_ = false;
945     bool useLiteStyle_ = false;
946     bool isFirstLoaded_ = true;
947     bool isDensityUpdate_ = false;
948     uint64_t flushAnimationTimestamp_ = 0;
949     TimeProvider timeProvider_;
950     int32_t modalHeight_ = 0;
951     int32_t hoverNodeId_ = DEFAULT_HOVER_ENTER_ANIMATION_ID;
952     uint32_t modalColor_ = 0x00000000;
953     std::list<RefPtr<RenderNode>> hoverNodes_;
954     std::function<void(std::function<void()>&&)> screenOffCallback_;
955     std::function<void(std::function<void()>&&)> screenOnCallback_;
956 #if defined(ENABLE_NATIVE_VIEW)
957     int32_t frameCount_ = 0;
958 #endif
959 
960     int32_t width_ = 0;
961     int32_t height_ = 0;
962     bool isFirstPage_ = true;
963     bool buildingFirstPage_ = false;
964     bool forbidPlatformQuit_ = false;
965     std::string photoCachePath_;
966     AnimationOption explicitAnimationOption_;
967     std::map<int32_t, RefPtr<Animator>> explicitAnimators_;
968     bool isAccessibilityEnabled_ = false;
969 
970     int32_t callbackId_ = 0;
971     SurfaceChangedCallbackMap surfaceChangedCallbackMap_;
972     SurfacePositionChangedCallbackMap surfacePositionChangedCallbackMap_;
973 
974     bool isShiftDown_ = false;
975     bool isCtrlDown_ = false;
976     bool isKeyboardA_ = false;
977     bool isTabKeyPressed_ = false;
978     bool isFocusingByTab_ = false;
979     SubscribeCtrlACallback subscribeCtrlA_;
980 
981     std::function<void()> nextFrameLayoutCallback_ = nullptr;
982     Size selectedItemSize_ { 0.0, 0.0 };
983     size_t selectedIndex_ = -1;
984     size_t insertIndex_ = -1;
985     RefPtr<RenderNode> initRenderNode_;
986     std::string customDragInfo_;
987     std::string selectedText_;
988     std::string imageSrc_;
989     Offset pageOffset_;
990     Offset rootOffset_;
991 
992     std::unordered_map<int32_t, WeakPtr<RenderElement>> storeNode_;
993     std::unordered_map<int32_t, std::string> restoreNodeInfo_;
994 
995     std::unordered_map<ComposeId, std::list<VisibleCallbackInfo>> visibleAreaChangeNodes_;
996 
997     std::vector<RectCallback> rectCallbackList_;
998     std::list<TouchEvent> touchEvents_;
999 
1000     int32_t rotationAnimationCount_ = 0;
1001 
1002     ACE_DISALLOW_COPY_AND_MOVE(PipelineContext);
1003 };
1004 
1005 } // namespace OHOS::Ace
1006 
1007 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_PIPELINE_CONTEXT_H
1008