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