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