1 /* 2 * Copyright (c) 2022-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_PIPELINE_NG_CONTEXT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_PIPELINE_NG_CONTEXT_H 18 19 #include <cstdint> 20 #include <functional> 21 #include <list> 22 #include <unordered_map> 23 #include <utility> 24 25 #include "base/geometry/ng/rect_t.h" 26 #include "base/log/frame_info.h" 27 #include "base/log/frame_report.h" 28 #include "base/memory/referenced.h" 29 #include "base/view_data/view_data_wrap.h" 30 #include "core/common/frontend.h" 31 #include "core/components/common/layout/constants.h" 32 #include "core/components_ng/base/frame_node.h" 33 #include "core/components_ng/gestures/recognizers/gesture_recognizer.h" 34 #include "core/components_ng/manager/drag_drop/drag_drop_manager.h" 35 #include "core/components_ng/manager/frame_rate/frame_rate_manager.h" 36 #include "core/components_ng/manager/full_screen/full_screen_manager.h" 37 #include "core/components_ng/manager/post_event/post_event_manager.h" 38 #include "core/components_ng/manager/safe_area/safe_area_manager.h" 39 #include "core/components_ng/manager/select_overlay/select_overlay_manager.h" 40 #include "core/components_ng/manager/shared_overlay/shared_overlay_manager.h" 41 #include "core/components_ng/pattern/custom/custom_node.h" 42 #ifdef WINDOW_SCENE_SUPPORTED 43 #include "core/components_ng/pattern/ui_extension/ui_extension_manager.h" 44 #endif 45 #include "core/components_ng/pattern/overlay/overlay_manager.h" 46 #include "core/components_ng/pattern/stage/stage_manager.h" 47 #include "core/components_ng/property/safe_area_insets.h" 48 #include "core/event/touch_event.h" 49 #include "core/pipeline/pipeline_base.h" 50 51 namespace OHOS::Ace::NG { 52 class ACE_EXPORT PipelineContext : public PipelineBase { 53 DECLARE_ACE_TYPE(NG::PipelineContext, PipelineBase); 54 55 public: 56 using SurfaceChangedCallbackMap = 57 std::unordered_map<int32_t, std::function<void(int32_t, int32_t, int32_t, int32_t, WindowSizeChangeReason)>>; 58 using SurfacePositionChangedCallbackMap = std::unordered_map<int32_t, std::function<void(int32_t, int32_t)>>; 59 using FoldStatusChangedCallbackMap = std::unordered_map<int32_t, std::function<void(FoldStatus)>>; 60 using FoldDisplayModeChangedCallbackMap = std::unordered_map<int32_t, std::function<void(FoldDisplayMode)>>; 61 using PredictTask = std::function<void(int64_t, bool)>; 62 PipelineContext(std::shared_ptr<Window> window, RefPtr<TaskExecutor> taskExecutor, 63 RefPtr<AssetManager> assetManager, RefPtr<PlatformResRegister> platformResRegister, 64 const RefPtr<Frontend>& frontend, int32_t instanceId); 65 PipelineContext(std::shared_ptr<Window> window, RefPtr<TaskExecutor> taskExecutor, 66 RefPtr<AssetManager> assetManager, const RefPtr<Frontend>& frontend, int32_t instanceId); 67 PipelineContext() = default; 68 69 ~PipelineContext() override = default; 70 71 static RefPtr<PipelineContext> GetCurrentContext(); 72 73 static RefPtr<PipelineContext> GetCurrentContextSafely(); 74 75 static RefPtr<PipelineContext> GetMainPipelineContext(); 76 77 static RefPtr<PipelineContext> GetContextByContainerId(int32_t containerId); 78 79 static float GetCurrentRootWidth(); 80 81 static float GetCurrentRootHeight(); 82 83 // handle close keyboard 84 RefPtr<FrameNode> HandleFocusNode(); 85 void IsCloseSCBKeyboard(); 86 void IsSCBWindowKeyboard(RefPtr<FrameNode> curFrameNode); 87 void IsNotSCBWindowKeyboard(RefPtr<FrameNode> curFrameNode); SetNeedSoftKeyboard(std::optional<bool> flag)88 void SetNeedSoftKeyboard(std::optional<bool> flag) 89 { 90 needSoftKeyboard_ = flag; 91 } 92 93 void SetupRootElement() override; 94 95 void SetupSubRootElement(); 96 97 bool NeedSoftKeyboard() override; 98 SetFocusNode(RefPtr<FrameNode> node)99 void SetFocusNode(RefPtr<FrameNode> node) 100 { 101 focusNode_ = node; 102 } 103 GetFocusNode()104 RefPtr<FrameNode> GetFocusNode() 105 { 106 return focusNode_; 107 } 108 SetOnWindowFocused(const std::function<void ()> & callback)109 void SetOnWindowFocused(const std::function<void()>& callback) override 110 { 111 focusOnNodeCallback_ = callback; 112 } 113 GetRootElement()114 const RefPtr<FrameNode>& GetRootElement() const 115 { 116 return rootNode_; 117 } 118 AddKeyFrame(float fraction,const RefPtr<Curve> & curve,const std::function<void ()> & propertyCallback)119 void AddKeyFrame(float fraction, const RefPtr<Curve>& curve, const std::function<void()>& propertyCallback) override 120 {} 121 AddKeyFrame(float fraction,const std::function<void ()> & propertyCallback)122 void AddKeyFrame(float fraction, const std::function<void()>& propertyCallback) override {} 123 124 // add schedule task and return the unique mark id. 125 uint32_t AddScheduleTask(const RefPtr<ScheduleTask>& task) override; 126 127 // remove schedule task by id. 128 void RemoveScheduleTask(uint32_t id) override; 129 130 void OnTouchEvent(const TouchEvent& point, const RefPtr<NG::FrameNode>& node, bool isSubPipe = false) override; 131 132 void OnMouseEvent(const MouseEvent& event, const RefPtr<NG::FrameNode>& node) override; 133 134 void OnAxisEvent(const AxisEvent& event, const RefPtr<NG::FrameNode>& node) override; 135 136 // Called by view when touch event received. 137 void OnTouchEvent(const TouchEvent& point, bool isSubPipe = false) override; 138 139 // Called by container when key event received. 140 // if return false, then this event needs platform to handle it. 141 bool OnKeyEvent(const KeyEvent& event) override; 142 143 // Called by view when mouse event received. 144 void OnMouseEvent(const MouseEvent& event) override; 145 146 // Do mouse event actively. 147 void FlushMouseEvent(); 148 149 // Called by view when axis event received. 150 void OnAxisEvent(const AxisEvent& event) override; 151 152 // Called by container when rotation event received. 153 // if return false, then this event needs platform to handle it. OnRotationEvent(const RotationEvent & event)154 bool OnRotationEvent(const RotationEvent& event) const override 155 { 156 return false; 157 } 158 159 void OnDragEvent(const PointerEvent& pointerEvent, DragEventAction action) override; 160 161 // Called by view when idle event. 162 void OnIdle(int64_t deadline) override; 163 SetBuildAfterCallback(const std::function<void ()> & callback)164 void SetBuildAfterCallback(const std::function<void()>& callback) override 165 { 166 buildFinishCallbacks_.emplace_back(callback); 167 } 168 SaveExplicitAnimationOption(const AnimationOption & option)169 void SaveExplicitAnimationOption(const AnimationOption& option) override {} 170 CreateExplicitAnimator(const std::function<void ()> & onFinishEvent)171 void CreateExplicitAnimator(const std::function<void()>& onFinishEvent) override {} 172 ClearExplicitAnimationOption()173 void ClearExplicitAnimationOption() override {} 174 GetExplicitAnimationOption()175 AnimationOption GetExplicitAnimationOption() const override 176 { 177 return {}; 178 } 179 180 void AddOnAreaChangeNode(int32_t nodeId); 181 182 void RemoveOnAreaChangeNode(int32_t nodeId); 183 184 void HandleOnAreaChangeEvent(uint64_t nanoTimestamp); 185 186 void AddVisibleAreaChangeNode( 187 const RefPtr<FrameNode>& node, double ratio, const VisibleRatioCallback& callback, bool isUserCallback = true); 188 void RemoveVisibleAreaChangeNode(int32_t nodeId); 189 190 void AddFormVisibleChangeNode(const RefPtr<FrameNode>& node, const std::function<void(bool)>& callback); 191 void RemoveFormVisibleChangeNode(int32_t nodeId); 192 193 void HandleVisibleAreaChangeEvent(); 194 void HandleFormVisibleChangeEvent(bool isVisible); 195 196 void HandleSubwindow(bool isShow); 197 198 void Destroy() override; 199 200 void OnShow() override; 201 202 void OnHide() override; 203 204 void WindowFocus(bool isFocus) override; 205 206 void ContainerModalUnFocus() override; 207 208 void ShowContainerTitle(bool isShow, bool hasDeco = true, bool needUpdate = false) override; 209 210 void SetAppBgColor(const Color& color) override; 211 212 void SetAppTitle(const std::string& title) override; 213 214 void SetAppIcon(const RefPtr<PixelMap>& icon) override; 215 216 void OnSurfaceChanged(int32_t width, int32_t height, 217 WindowSizeChangeReason type = WindowSizeChangeReason::UNDEFINED, 218 const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr) override; 219 220 void OnLayoutCompleted(const std::string& componentId); 221 void OnDrawCompleted(const std::string& componentId); 222 223 void OnSurfacePositionChanged(int32_t posX, int32_t posY) override; 224 225 void OnSurfaceDensityChanged(double density) override; 226 OnSystemBarHeightChanged(double statusBar,double navigationBar)227 void OnSystemBarHeightChanged(double statusBar, double navigationBar) override {} 228 OnSurfaceDestroyed()229 void OnSurfaceDestroyed() override {} 230 NotifyOnPreDraw()231 void NotifyOnPreDraw() override {} 232 CallRouterBackToPopPage()233 bool CallRouterBackToPopPage() override 234 { 235 return OnBackPressed(); 236 } 237 238 bool OnBackPressed(); 239 240 RefPtr<FrameNode> FindNavigationNodeToHandleBack(const RefPtr<UINode>& node); 241 242 void AddDirtyPropertyNode(const RefPtr<FrameNode>& dirty); 243 244 void AddDirtyCustomNode(const RefPtr<UINode>& dirtyNode); 245 246 void AddDirtyLayoutNode(const RefPtr<FrameNode>& dirty); 247 248 void AddDirtyRenderNode(const RefPtr<FrameNode>& dirty); 249 250 void AddPredictTask(PredictTask&& task); 251 252 void AddAfterLayoutTask(std::function<void()>&& task); 253 254 void AddPersistAfterLayoutTask(std::function<void()>&& task); 255 256 void AddAfterRenderTask(std::function<void()>&& task); 257 AddDragWindowVisibleTask(std::function<void ()> && task)258 void AddDragWindowVisibleTask(std::function<void()>&& task) 259 { 260 dragWindowVisibleCallback_ = std::move(task); 261 } 262 263 void FlushDirtyNodeUpdate(); 264 265 void SetRootRect(double width, double height, double offset) override; 266 267 void SetWindowSceneConsumed(bool isConsumed); 268 269 bool IsWindowSceneConsumed(); 270 271 void UpdateSystemSafeArea(const SafeAreaInsets& systemSafeArea) override; 272 void UpdateCutoutSafeArea(const SafeAreaInsets& cutoutSafeArea) override; 273 void UpdateNavSafeArea(const SafeAreaInsets& navSafeArea) override; 274 void UpdateOriginAvoidArea(const Rosen::AvoidArea& avoidArea, uint32_t type) override; 275 UpdateDisplayAvailableRect(const Rect & displayAvailableRect)276 void UpdateDisplayAvailableRect(const Rect& displayAvailableRect) 277 { 278 displayAvailableRect_ = displayAvailableRect; 279 } GetDisplayAvailableRect()280 Rect GetDisplayAvailableRect() const 281 { 282 return displayAvailableRect_; 283 } 284 void SetEnableKeyBoardAvoidMode(bool value) override; 285 bool IsEnableKeyBoardAvoidMode() override; GetSafeAreaManager()286 const RefPtr<SafeAreaManager>& GetSafeAreaManager() const 287 { 288 return safeAreaManager_; 289 } 290 virtual SafeAreaInsets GetSafeArea() const; 291 292 const RefPtr<FullScreenManager>& GetFullScreenManager(); 293 294 const RefPtr<StageManager>& GetStageManager(); 295 296 const RefPtr<OverlayManager>& GetOverlayManager(); 297 298 const RefPtr<SelectOverlayManager>& GetSelectOverlayManager(); 299 GetSharedOverlayManager()300 const RefPtr<SharedOverlayManager>& GetSharedOverlayManager() 301 { 302 return sharedTransitionManager_; 303 } 304 305 #ifdef WINDOW_SCENE_SUPPORTED GetUIExtensionManager()306 const RefPtr<UIExtensionManager>& GetUIExtensionManager() 307 { 308 return uiExtensionManager_; 309 } 310 #endif 311 312 const RefPtr<DragDropManager>& GetDragDropManager(); 313 GetFrameRateManager()314 const RefPtr<FrameRateManager>& GetFrameRateManager() 315 { 316 return frameRateManager_; 317 } 318 319 void FlushBuild() override; 320 321 void FlushPipelineImmediately() override; 322 323 void AddBuildFinishCallBack(std::function<void()>&& callback); 324 325 void AddWindowStateChangedCallback(int32_t nodeId); 326 327 void RemoveWindowStateChangedCallback(int32_t nodeId); 328 329 void AddWindowFocusChangedCallback(int32_t nodeId); 330 331 void RemoveWindowFocusChangedCallback(int32_t nodeId); 332 333 void AddWindowSizeChangeCallback(int32_t nodeId); 334 335 void RemoveWindowSizeChangeCallback(int32_t nodeId); 336 337 void AddNavigationStateCallback( 338 int32_t pageId, int32_t nodeId, const std::function<void()>& callback, bool isOnShow); 339 340 void RemoveNavigationStateCallback(int32_t pageId, int32_t nodeId); 341 342 void FirePageChanged(int32_t pageId, bool isOnShow); 343 344 bool HasDifferentDirectionGesture() const; 345 IsKeyInPressed(KeyCode tarCode)346 bool IsKeyInPressed(KeyCode tarCode) const 347 { 348 CHECK_NULL_RETURN(eventManager_, false); 349 return eventManager_->IsKeyInPressed(tarCode); 350 } 351 GetIsFocusingByTab()352 bool GetIsFocusingByTab() const 353 { 354 return isFocusingByTab_; 355 } 356 SetIsFocusingByTab(bool isFocusingByTab)357 void SetIsFocusingByTab(bool isFocusingByTab) 358 { 359 isFocusingByTab_ = isFocusingByTab; 360 } 361 GetIsFocusActive()362 bool GetIsFocusActive() const 363 { 364 return isFocusActive_; 365 } 366 367 bool SetIsFocusActive(bool isFocusActive); 368 369 void AddIsFocusActiveUpdateEvent(const RefPtr<FrameNode>& node, const std::function<void(bool)>& eventCallback); 370 void RemoveIsFocusActiveUpdateEvent(const RefPtr<FrameNode>& node); 371 IsTabJustTriggerOnKeyEvent()372 bool IsTabJustTriggerOnKeyEvent() const 373 { 374 return isTabJustTriggerOnKeyEvent_; 375 } 376 GetOnShow()377 bool GetOnShow() const 378 { 379 return onShow_; 380 } 381 382 bool ChangeMouseStyle(int32_t nodeId, MouseFormat format); 383 384 bool RequestDefaultFocus(const RefPtr<FocusHub>& mainView); 385 bool RequestFocus(const std::string& targetNodeId) override; 386 void AddDirtyFocus(const RefPtr<FrameNode>& node); 387 void AddDirtyDefaultFocus(const RefPtr<FrameNode>& node); 388 void AddDirtyRequestFocus(const RefPtr<FrameNode>& node); 389 void RootLostFocus(BlurReason reason = BlurReason::FOCUS_SWITCH) const; 390 391 void SetContainerWindow(bool isShow) override; 392 void SetContainerButtonHide(bool hideSplit, bool hideMaximize, bool hideMinimize) override; 393 void SetCloseButtonStatus(bool isEnabled); 394 395 void AddNodesToNotifyMemoryLevel(int32_t nodeId); 396 void RemoveNodesToNotifyMemoryLevel(int32_t nodeId); 397 void NotifyMemoryLevel(int32_t level) override; 398 void FlushMessages() override; 399 400 void FlushUITasks() override; 401 IsLayouting()402 bool IsLayouting() const override 403 { 404 return taskScheduler_->IsLayouting(); 405 } 406 // end pipeline, exit app 407 void Finish(bool autoFinish) const override; GetRootRect()408 RectF GetRootRect() 409 { 410 CHECK_NULL_RETURN(rootNode_, RectF()); 411 auto geometryNode = rootNode_->GetGeometryNode(); 412 CHECK_NULL_RETURN(geometryNode, RectF()); 413 return geometryNode->GetFrameRect(); 414 } 415 416 void FlushReload(const ConfigurationChange& configurationChange) override; 417 RegisterSurfaceChangedCallback(std::function<void (int32_t,int32_t,int32_t,int32_t,WindowSizeChangeReason)> && callback)418 int32_t RegisterSurfaceChangedCallback( 419 std::function<void(int32_t, int32_t, int32_t, int32_t, WindowSizeChangeReason)>&& callback) 420 { 421 if (callback) { 422 surfaceChangedCallbackMap_.emplace(++callbackId_, std::move(callback)); 423 return callbackId_; 424 } 425 return 0; 426 } 427 UnregisterSurfaceChangedCallback(int32_t callbackId)428 void UnregisterSurfaceChangedCallback(int32_t callbackId) 429 { 430 surfaceChangedCallbackMap_.erase(callbackId); 431 } 432 RegisterFoldStatusChangedCallback(std::function<void (FoldStatus)> && callback)433 int32_t RegisterFoldStatusChangedCallback(std::function<void(FoldStatus)>&& callback) 434 { 435 if (callback) { 436 foldStatusChangedCallbackMap_.emplace(callbackId_, std::move(callback)); 437 return callbackId_; 438 } 439 return 0; 440 } 441 UnRegisterFoldStatusChangedCallback(int32_t callbackId)442 void UnRegisterFoldStatusChangedCallback(int32_t callbackId) 443 { 444 foldStatusChangedCallbackMap_.erase(callbackId); 445 } 446 RegisterFoldDisplayModeChangedCallback(std::function<void (FoldDisplayMode)> && callback)447 int32_t RegisterFoldDisplayModeChangedCallback(std::function<void(FoldDisplayMode)>&& callback) 448 { 449 if (callback) { 450 foldDisplayModeChangedCallbackMap_.emplace(++callbackId_, std::move(callback)); 451 return callbackId_; 452 } 453 return 0; 454 } 455 UnRegisterFoldDisplayModeChangedCallback(int32_t callbackId)456 void UnRegisterFoldDisplayModeChangedCallback(int32_t callbackId) 457 { 458 foldDisplayModeChangedCallbackMap_.erase(callbackId); 459 } 460 RegisterSurfacePositionChangedCallback(std::function<void (int32_t,int32_t)> && callback)461 int32_t RegisterSurfacePositionChangedCallback(std::function<void(int32_t, int32_t)>&& callback) 462 { 463 if (callback) { 464 surfacePositionChangedCallbackMap_.emplace(++callbackId_, std::move(callback)); 465 return callbackId_; 466 } 467 return 0; 468 } 469 UnregisterSurfacePositionChangedCallback(int32_t callbackId)470 void UnregisterSurfacePositionChangedCallback(int32_t callbackId) 471 { 472 surfacePositionChangedCallbackMap_.erase(callbackId); 473 } 474 SetMouseStyleHoldNode(int32_t id)475 void SetMouseStyleHoldNode(int32_t id) 476 { 477 if (mouseStyleNodeId_ == -1) { 478 mouseStyleNodeId_ = id; 479 } 480 } FreeMouseStyleHoldNode(int32_t id)481 void FreeMouseStyleHoldNode(int32_t id) 482 { 483 if (mouseStyleNodeId_ == id) { 484 mouseStyleNodeId_ = -1; 485 } 486 } 487 MarkNeedFlushMouseEvent()488 void MarkNeedFlushMouseEvent() 489 { 490 isNeedFlushMouseEvent_ = true; 491 } 492 MarkNeedFlushAnimationStartTime()493 void MarkNeedFlushAnimationStartTime() 494 { 495 isNeedFlushAnimationStartTime_ = true; 496 } 497 498 // font 499 void AddFontNodeNG(const WeakPtr<UINode>& node); 500 void RemoveFontNodeNG(const WeakPtr<UINode>& node); 501 502 // restore 503 void RestoreNodeInfo(std::unique_ptr<JsonValue> nodeInfo) override; 504 std::unique_ptr<JsonValue> GetStoredNodeInfo() override; 505 void StoreNode(int32_t restoreId, const WeakPtr<FrameNode>& node); 506 bool GetRestoreInfo(int32_t restoreId, std::string& restoreInfo); RemoveStoredNode(int32_t restoreId)507 void RemoveStoredNode(int32_t restoreId) 508 { 509 storeNode_.erase(restoreId); 510 } 511 void SetNeedRenderNode(const RefPtr<FrameNode>& node); 512 513 void SetIgnoreViewSafeArea(bool value) override; 514 void SetIsLayoutFullScreen(bool value) override; 515 void SetIsNeedAvoidWindow(bool value) override; 516 517 void AddAnimationClosure(std::function<void()>&& animation); 518 void FlushAnimationClosure(); 519 void RegisterDumpInfoListener(const std::function<void(const std::vector<std::string>&)>& callback); 520 void DumpJsInfo(const std::vector<std::string>& params) const; 521 522 bool DumpPageViewData(const RefPtr<FrameNode>& node, RefPtr<ViewDataWrap> viewDataWrap); 523 bool CheckNeedAutoSave(); 524 bool CheckPageFocus(); 525 void NotifyFillRequestSuccess(AceAutoFillType autoFillType, RefPtr<ViewDataWrap> viewDataWrap); 526 void NotifyFillRequestFailed(RefPtr<FrameNode> node, int32_t errCode); 527 528 std::shared_ptr<NavigationController> GetNavigationController(const std::string& id) override; 529 void AddOrReplaceNavigationNode(const std::string& id, const WeakPtr<FrameNode>& node); 530 void DeleteNavigationNode(const std::string& id); 531 AddGestureTask(const DelayedTask & task)532 void AddGestureTask(const DelayedTask& task) 533 { 534 delayedTasks_.emplace_back(task); 535 } 536 RemoveGestureTask(const DelayedTask & task)537 void RemoveGestureTask(const DelayedTask& task) 538 { 539 for (auto iter = delayedTasks_.begin(); iter != delayedTasks_.end();) { 540 if (iter->recognizer == task.recognizer) { 541 delayedTasks_.erase(iter++); 542 } else { 543 ++iter; 544 } 545 } 546 } 547 SetScreenNode(const RefPtr<FrameNode> & node)548 void SetScreenNode(const RefPtr<FrameNode>& node) 549 { 550 CHECK_NULL_VOID(node); 551 screenNode_ = AceType::WeakClaim(AceType::RawPtr(node)); 552 } GetScreenNode()553 RefPtr<FrameNode> GetScreenNode() const 554 { 555 return screenNode_.Upgrade(); 556 } 557 558 void SetJSViewActive(bool active, WeakPtr<CustomNode> custom); 559 UpdateCurrentActiveNode(const WeakPtr<FrameNode> & node)560 void UpdateCurrentActiveNode(const WeakPtr<FrameNode>& node) override 561 { 562 activeNode_ = std::move(node); 563 } 564 GetCurrentActiveNode()565 const WeakPtr<FrameNode>& GetCurrentActiveNode() const 566 { 567 return activeNode_; 568 } 569 570 std::string GetCurrentExtraInfo() override; 571 void UpdateTitleInTargetPos(bool isShow, int32_t height) override; 572 573 void SetCursor(int32_t cursorValue) override; 574 575 void RestoreDefault() override; 576 577 void OnFoldStatusChange(FoldStatus foldStatus) override; 578 void OnFoldDisplayModeChange(FoldDisplayMode foldDisplayMode) override; 579 580 // for frontend animation interface. 581 void OpenFrontendAnimation( 582 const AnimationOption& option, const RefPtr<Curve>& curve, const std::function<void()>& finishCallback); 583 void CloseFrontendAnimation(); 584 585 bool IsDragging() const override; 586 void SetIsDragging(bool isDragging) override; 587 588 void ResetDragging() override; 589 const RefPtr<PostEventManager>& GetPostEventManager(); 590 591 void SetContainerModalTitleVisible(bool customTitleSettedShow, bool floatingTitleSettedShow); 592 void SetContainerModalTitleHeight(int32_t height); 593 int32_t GetContainerModalTitleHeight(); 594 bool GetContainerModalButtonsRect(RectF& containerModal, RectF& buttons); 595 void SubscribeContainerModalButtonsRectChange( 596 std::function<void(RectF& containerModal, RectF& buttons)>&& callback); 597 598 const SerializedGesture& GetSerializedGesture() const override; 599 // return value means whether it has printed info 600 bool PrintVsyncInfoIfNeed() const override; 601 void SetUIExtensionImeShow(bool imeShow); 602 StartWindowAnimation()603 void StartWindowAnimation() override 604 { 605 isWindowAnimation_ = true; 606 } 607 StopWindowAnimation()608 void StopWindowAnimation() override 609 { 610 isWindowAnimation_ = false; 611 } 612 613 void AddSyncGeometryNodeTask(std::function<void()>&& task) override; 614 void FlushSyncGeometryNodeTasks() override; 615 616 protected: 617 void StartWindowSizeChangeAnimate(int32_t width, int32_t height, WindowSizeChangeReason type, 618 const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr); 619 void StartWindowMaximizeAnimation( 620 int32_t width, int32_t height, const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr); 621 void StartFullToMultWindowAnimation(int32_t width, int32_t height, WindowSizeChangeReason type, 622 const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr); 623 624 void FlushVsync(uint64_t nanoTimestamp, uint32_t frameCount) override; 625 void FlushPipelineWithoutAnimation() override; 626 void FlushFocus(); 627 void FlushFrameTrace(); 628 void DispatchDisplaySync(uint64_t nanoTimestamp) override; 629 void FlushAnimation(uint64_t nanoTimestamp) override; 630 bool OnDumpInfo(const std::vector<std::string>& params) const override; 631 632 void OnVirtualKeyboardHeightChange( 633 float keyboardHeight, const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr) override; 634 void OnVirtualKeyboardHeightChange(float keyboardHeight, double positionY, double height, 635 const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr) override; 636 637 private: 638 void ExecuteSurfaceChangedCallbacks(int32_t newWidth, int32_t newHeight, WindowSizeChangeReason type); 639 640 void FlushWindowStateChangedCallback(bool isShow); 641 642 void FlushWindowFocusChangedCallback(bool isFocus); 643 644 void FlushWindowSizeChangeCallback(int32_t width, int32_t height, WindowSizeChangeReason type); 645 646 void FlushTouchEvents(); 647 648 void ProcessDelayTasks(); 649 650 void InspectDrew(); 651 652 void FlushBuildFinishCallbacks(); 653 654 void DumpPipelineInfo() const; 655 656 void RegisterRootEvent(); 657 658 void ResetDraggingStatus(const TouchEvent& touchPoint); 659 660 FrameInfo* GetCurrentFrameInfo(uint64_t recvTime, uint64_t timeStamp); 661 662 void AnimateOnSafeAreaUpdate(); 663 void SyncSafeArea(bool onKeyboard = false); 664 665 // only used for static form. 666 void UpdateFormLinkInfos(); 667 668 void FlushFrameRate(); 669 670 template<typename T> 671 struct NodeCompare { operatorNodeCompare672 bool operator()(const T& nodeLeft, const T& nodeRight) const 673 { 674 if (!nodeLeft || !nodeRight) { 675 return false; 676 } 677 if (nodeLeft->GetDepth() < nodeRight->GetDepth()) { 678 return true; 679 } 680 if (nodeLeft->GetDepth() == nodeRight->GetDepth()) { 681 return nodeLeft < nodeRight; 682 } 683 return false; 684 } 685 }; 686 687 std::pair<float, float> LinearInterpolation(const std::tuple<float, float, uint64_t>& history, 688 const std::tuple<float, float, uint64_t>& current, const uint64_t nanoTimeStamp); 689 690 std::pair<float, float> GetResampleCoord(const std::vector<TouchEvent>& history, 691 const std::vector<TouchEvent>& current, const uint64_t nanoTimeStamp, const bool isScreen); 692 693 std::tuple<float, float, uint64_t> GetAvgPoint(const std::vector<TouchEvent>& events, const bool isScreen); 694 695 TouchEvent GetResampleTouchEvent( 696 const std::vector<TouchEvent>& history, const std::vector<TouchEvent>& current, const uint64_t nanoTimeStamp); 697 698 TouchEvent GetLatestPoint(const std::vector<TouchEvent>& current, const uint64_t nanoTimeStamp); 699 700 std::unique_ptr<UITaskScheduler> taskScheduler_ = std::make_unique<UITaskScheduler>(); 701 702 std::unordered_map<uint32_t, WeakPtr<ScheduleTask>> scheduleTasks_; 703 704 std::set<RefPtr<FrameNode>, NodeCompare<RefPtr<FrameNode>>> dirtyPropertyNodes_; // used in node api. 705 std::set<RefPtr<UINode>, NodeCompare<RefPtr<UINode>>> dirtyNodes_; 706 std::list<std::function<void()>> buildFinishCallbacks_; 707 708 // window on show or on hide 709 std::set<int32_t> onWindowStateChangedCallbacks_; 710 // window on focused or on unfocused 711 std::list<int32_t> onWindowFocusChangedCallbacks_; 712 // window on drag 713 std::list<int32_t> onWindowSizeChangeCallbacks_; 714 715 std::list<int32_t> nodesToNotifyMemoryLevel_; 716 717 std::list<TouchEvent> touchEvents_; 718 719 std::vector<std::function<void(const std::vector<std::string>&)>> dumpListeners_; 720 721 RefPtr<FrameNode> rootNode_; 722 723 int32_t curFocusNodeId_ = -1; 724 725 std::set<RefPtr<FrameNode>> needRenderNode_; 726 727 int32_t callbackId_ = 0; 728 SurfaceChangedCallbackMap surfaceChangedCallbackMap_; 729 SurfacePositionChangedCallbackMap surfacePositionChangedCallbackMap_; 730 FoldStatusChangedCallbackMap foldStatusChangedCallbackMap_; 731 FoldDisplayModeChangedCallbackMap foldDisplayModeChangedCallbackMap_; 732 733 std::unordered_set<int32_t> onAreaChangeNodeIds_; 734 std::unordered_set<int32_t> onVisibleAreaChangeNodeIds_; 735 std::unordered_set<int32_t> onFormVisibleChangeNodeIds_; 736 std::unordered_map<int32_t, std::list<std::pair<int32_t, std::function<void()>>>> pageIdOnShowMap_; 737 std::unordered_map<int32_t, std::list<std::pair<int32_t, std::function<void()>>>> pageIdOnHideMap_; 738 739 RefPtr<StageManager> stageManager_; 740 RefPtr<OverlayManager> overlayManager_; 741 RefPtr<FullScreenManager> fullScreenManager_; 742 RefPtr<SelectOverlayManager> selectOverlayManager_; 743 RefPtr<DragDropManager> dragDropManager_; 744 RefPtr<SharedOverlayManager> sharedTransitionManager_; 745 #ifdef WINDOW_SCENE_SUPPORTED 746 RefPtr<UIExtensionManager> uiExtensionManager_; 747 #endif 748 RefPtr<SafeAreaManager> safeAreaManager_ = MakeRefPtr<SafeAreaManager>(); 749 RefPtr<FrameRateManager> frameRateManager_ = MakeRefPtr<FrameRateManager>(); 750 Rect displayAvailableRect_; 751 std::unordered_map<size_t, TouchTestResult> touchTestResults_; 752 WeakPtr<FrameNode> dirtyFocusNode_; 753 WeakPtr<FrameNode> dirtyFocusScope_; 754 WeakPtr<FrameNode> dirtyDefaultFocusNode_; 755 WeakPtr<FrameNode> dirtyRequestFocusNode_; 756 WeakPtr<FrameNode> screenNode_; 757 uint32_t nextScheduleTaskId_ = 0; 758 int32_t mouseStyleNodeId_ = -1; 759 uint64_t resampleTimeStamp_ = 0; 760 bool hasIdleTasks_ = false; 761 bool isFocusingByTab_ = false; 762 bool isFocusActive_ = false; 763 bool isTabJustTriggerOnKeyEvent_ = false; 764 bool onShow_ = false; 765 bool isNeedFlushMouseEvent_ = false; 766 bool isNeedFlushAnimationStartTime_ = false; 767 bool canUseLongPredictTask_ = false; 768 bool isWindowSceneConsumed_ = false; 769 bool isDensityChanged_ = false; 770 bool isBeforeDragHandleAxis_ = false; 771 WeakPtr<FrameNode> activeNode_; 772 bool isWindowAnimation_ = false; 773 bool prevKeyboardAvoidMode_ = false; 774 775 RefPtr<FrameNode> focusNode_; 776 std::function<void()> focusOnNodeCallback_; 777 std::function<void()> dragWindowVisibleCallback_; 778 779 std::optional<bool> needSoftKeyboard_; 780 std::optional<bool> windowFocus_; 781 std::optional<bool> windowShow_; 782 783 std::unique_ptr<MouseEvent> lastMouseEvent_; 784 785 std::unordered_map<int32_t, WeakPtr<FrameNode>> storeNode_; 786 std::unordered_map<int32_t, std::string> restoreNodeInfo_; 787 788 std::unordered_map<int32_t, std::vector<TouchEvent>> historyPointsById_; 789 790 std::list<FrameInfo> dumpFrameInfos_; 791 std::list<std::function<void()>> animationClosuresList_; 792 793 std::map<int32_t, std::function<void(bool)>> isFocusActiveUpdateEvents_; 794 std::map<int32_t, std::function<void(bool)>> onFormVisibleChangeEvents_; 795 mutable std::mutex navigationMutex_; 796 std::map<std::string, WeakPtr<FrameNode>> navigationNodes_; 797 std::list<DelayedTask> delayedTasks_; 798 RefPtr<PostEventManager> postEventManager_; 799 800 ACE_DISALLOW_COPY_AND_MOVE(PipelineContext); 801 802 int32_t preNodeId_ = -1; 803 }; 804 } // namespace OHOS::Ace::NG 805 806 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_PIPELINE_NG_CONTEXT_H 807