1 /* 2 * Copyright (c) 2022-2024 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 "interfaces/inner_api/ace/arkui_rect.h" 26 27 #include "base/geometry/ng/rect_t.h" 28 #include "base/log/frame_info.h" 29 #include "base/log/frame_report.h" 30 #include "base/memory/referenced.h" 31 #include "base/utils/device_config.h" 32 #include "base/view_data/view_data_wrap.h" 33 #include "core/accessibility/accessibility_manager_ng.h" 34 #include "core/common/frontend.h" 35 #include "core/common/thp_extra_manager.h" 36 #include "core/components/common/layout/constants.h" 37 #include "core/components_ng/base/frame_node.h" 38 #include "core/components_ng/gestures/recognizers/gesture_recognizer.h" 39 #include "core/components_ng/manager/avoid_info/avoid_info_manager.h" 40 #include "core/components_ng/manager/drag_drop/drag_drop_manager.h" 41 #include "core/components_ng/manager/form_event/form_event_manager.h" 42 #include "core/components_ng/manager/form_gesture/form_gesture_manager.h" 43 #include "core/components_ng/manager/form_visible/form_visible_manager.h" 44 #include "core/components_ng/manager/frame_rate/frame_rate_manager.h" 45 #include "core/components_ng/manager/full_screen/full_screen_manager.h" 46 #include "core/components_ng/manager/memory/memory_manager.h" 47 #include "core/components_ng/manager/navigation/navigation_manager.h" 48 #include "core/components_ng/manager/post_event/post_event_manager.h" 49 #include "core/components_ng/manager/privacy_sensitive/privacy_sensitive_manager.h" 50 #include "core/components_ng/manager/safe_area/safe_area_manager.h" 51 #include "core/components_ng/manager/select_overlay/select_overlay_manager.h" 52 #include "core/components_ng/manager/shared_overlay/shared_overlay_manager.h" 53 #include "core/components_ng/pattern/custom/custom_node.h" 54 #ifdef WINDOW_SCENE_SUPPORTED 55 #include "core/components_ng/pattern/ui_extension/ui_extension_manager.h" 56 #endif 57 #include "core/common/ace_translate_manager.h" 58 #include "core/components_ng/manager/focus/focus_manager.h" 59 #include "core/components_ng/pattern/overlay/overlay_manager.h" 60 #include "core/components_ng/pattern/recycle_view/recycle_manager.h" 61 #include "core/components_ng/pattern/stage/stage_manager.h" 62 #include "core/components_ng/pattern/web/itouch_event_callback.h" 63 #include "core/components_ng/property/safe_area_insets.h" 64 #include "core/pipeline/pipeline_base.h" 65 namespace OHOS::Ace::Kit { 66 class UIContext; 67 class UIContextImpl; 68 } 69 70 namespace OHOS::Ace::NG { 71 72 using VsyncCallbackFun = std::function<void()>; 73 using FrameCallbackFunc = std::function<void(uint64_t nanoTimestamp)>; 74 using FrameCallbackFuncFromCAPI = std::function<void(uint64_t nanoTimestamp, uint32_t frameCount)>; 75 76 enum class MockFlushEventType : int32_t { 77 REJECT = -1, 78 NONE = 0, 79 EXECUTE = 1, 80 }; 81 class ACE_FORCE_EXPORT PipelineContext : public PipelineBase { 82 DECLARE_ACE_TYPE(NG::PipelineContext, PipelineBase); 83 84 public: 85 using SurfaceChangedCallbackMap = 86 std::unordered_map<int32_t, std::function<void(int32_t, int32_t, int32_t, int32_t, WindowSizeChangeReason)>>; 87 using SurfacePositionChangedCallbackMap = std::unordered_map<int32_t, std::function<void(int32_t, int32_t)>>; 88 using FoldStatusChangedCallbackMap = std::unordered_map<int32_t, std::function<void(FoldStatus)>>; 89 using HalfFoldHoverChangedCallbackMap = std::unordered_map<int32_t, std::function<void(bool)>>; 90 using FoldDisplayModeChangedCallbackMap = std::unordered_map<int32_t, std::function<void(FoldDisplayMode)>>; 91 using TransformHintChangedCallbackMap = std::unordered_map<int32_t, std::function<void(uint32_t)>>; 92 using PredictTask = std::function<void(int64_t, bool)>; 93 PipelineContext(std::shared_ptr<Window> window, RefPtr<TaskExecutor> taskExecutor, 94 RefPtr<AssetManager> assetManager, RefPtr<PlatformResRegister> platformResRegister, 95 const RefPtr<Frontend>& frontend, int32_t instanceId); 96 PipelineContext(std::shared_ptr<Window> window, RefPtr<TaskExecutor> taskExecutor, 97 RefPtr<AssetManager> assetManager, const RefPtr<Frontend>& frontend, int32_t instanceId); 98 PipelineContext(); 99 100 ~PipelineContext() override = default; 101 102 static RefPtr<PipelineContext> GetCurrentContext(); 103 104 static RefPtr<PipelineContext> GetCurrentContextSafely(); 105 106 static RefPtr<PipelineContext> GetCurrentContextSafelyWithCheck(); 107 108 static PipelineContext* GetCurrentContextPtrSafely(); 109 110 static PipelineContext* GetCurrentContextPtrSafelyWithCheck(); 111 112 113 static RefPtr<PipelineContext> GetMainPipelineContext(); 114 115 static RefPtr<PipelineContext> GetContextByContainerId(int32_t containerId); 116 117 static float GetCurrentRootWidth(); 118 119 static float GetCurrentRootHeight(); 120 121 void MarkDirtyOverlay(); 122 123 void SetupRootElement() override; 124 125 void SetupSubRootElement(); 126 127 bool NeedSoftKeyboard() override; 128 129 void SetOnWindowFocused(const std::function<void()>& callback) override; 130 GetWindowFocusCallback()131 const std::function<void()>& GetWindowFocusCallback() const 132 { 133 return focusOnNodeCallback_; 134 } 135 SetSizeChangeByRotateCallback(const std::function<void (bool isRotate,const std::shared_ptr<Rosen::RSTransaction> & rsTransaction)> & callback)136 void SetSizeChangeByRotateCallback(const std::function<void(bool isRotate, 137 const std::shared_ptr<Rosen::RSTransaction>& rsTransaction)>& callback) 138 { 139 sizeChangeByRotateCallback_ = callback; 140 } 141 SetLinkJumpCallback(const std::function<void (const std::string & link)> & callback)142 void SetLinkJumpCallback(const std::function<void(const std::string& link)>& callback) 143 { 144 linkJumpCallback_ = callback; 145 } 146 ExecuteLinkJumpCallback(const std::string & link)147 void ExecuteLinkJumpCallback(const std::string& link) 148 { 149 linkJumpCallback_(link); 150 } 151 GetIsLinkJumpOpen()152 bool GetIsLinkJumpOpen() 153 { 154 return linkJumpCallback_ != nullptr; 155 } 156 FireSizeChangeByRotateCallback(bool isRotate,const std::shared_ptr<Rosen::RSTransaction> & rsTransaction)157 void FireSizeChangeByRotateCallback(bool isRotate, 158 const std::shared_ptr<Rosen::RSTransaction>& rsTransaction) 159 { 160 if (sizeChangeByRotateCallback_) { 161 sizeChangeByRotateCallback_(isRotate, rsTransaction); 162 } 163 } 164 GetRootElement()165 const RefPtr<FrameNode>& GetRootElement() const 166 { 167 return rootNode_; 168 } 169 AddKeyFrame(float fraction,const RefPtr<Curve> & curve,const std::function<void ()> & propertyCallback)170 void AddKeyFrame(float fraction, const RefPtr<Curve>& curve, const std::function<void()>& propertyCallback) override 171 {} 172 AddKeyFrame(float fraction,const std::function<void ()> & propertyCallback)173 void AddKeyFrame(float fraction, const std::function<void()>& propertyCallback) override {} 174 175 // add schedule task and return the unique mark id. 176 uint32_t AddScheduleTask(const RefPtr<ScheduleTask>& task) override; 177 178 // remove schedule task by id. 179 void RemoveScheduleTask(uint32_t id) override; 180 181 std::string GetCurrentPageNameCallback(); 182 183 void OnTouchEvent(const TouchEvent& point, const RefPtr<NG::FrameNode>& node, bool isSubPipe = false) override; 184 185 void OnAccessibilityHoverEvent(const TouchEvent& point, const RefPtr<NG::FrameNode>& node) override; 186 187 void OnPenHoverEvent(const TouchEvent& point, const RefPtr<NG::FrameNode>& node) override; 188 189 void HandlePenHoverOut(const TouchEvent& point) override; 190 191 void OnMouseMoveEventForAxisEvent(const MouseEvent& event, const RefPtr<NG::FrameNode>& node) override; 192 193 void OnMouseEvent(const MouseEvent& event, const RefPtr<NG::FrameNode>& node) override; 194 void DispatchMouseEvent(const MouseEvent& event, const RefPtr<FrameNode>& node); 195 196 void OnAxisEvent(const AxisEvent& event, const RefPtr<NG::FrameNode>& node) override; 197 198 // Called by view when touch event received. 199 void OnTouchEvent(const TouchEvent& point, bool isSubPipe = false) override; 200 201 #if defined(SUPPORT_TOUCH_TARGET_TEST) 202 // Used to determine whether the touched frameNode is the target 203 bool OnTouchTargetHitTest(const TouchEvent& point, bool isSubPipe = false, const std::string& target = "") override; 204 #endif 205 // Called by container when key event received. 206 // if return false, then this event needs platform to handle it. 207 bool OnNonPointerEvent(const NonPointerEvent& event) override; 208 209 // ReDispatch KeyEvent from Web process. 210 void ReDispatch(KeyEvent& keyEvent); 211 212 // Called by view when mouse event received. 213 void OnMouseEvent(const MouseEvent& event) override; 214 215 // Do mouse event actively. 216 void FlushMouseEvent(); 217 218 void HandleTouchHoverOut(const TouchEvent& point); 219 220 void FlushMouseEventVoluntarily(); 221 222 void FlushMouseEventForHover(); 223 224 void FlushMouseEventInVsync(); 225 226 void SetDisplayWindowRectInfo(const Rect& displayWindowRectInfo) override; 227 228 void SetWindowSizeChangeReason(WindowSizeChangeReason reason) override; 229 230 void SetIsTransFlag(bool result); 231 232 void OnFlushMouseEvent(TouchRestrict& touchRestrict); 233 void OnFlushMouseEvent(const RefPtr<FrameNode> &node, 234 const std::list<MouseEvent>& moseEvents, TouchRestrict& touchRestric); 235 void DispatchMouseEvent( 236 std::unordered_map<int, MouseEvent>& idToMousePoints, 237 std::unordered_map<int32_t, MouseEvent> &newIdMousePoints, 238 const std::list<MouseEvent> &mouseEvents, 239 TouchRestrict& touchRestrict, 240 const RefPtr<FrameNode> &node); 241 void FlushDragEvents(); 242 void FlushDragEvents(const RefPtr<DragDropManager>& manager, 243 std::string extraInfo, 244 const RefPtr<FrameNode>& node, 245 const std::list<DragPointerEvent>& pointEvent); 246 void FlushDragEvents(const RefPtr<DragDropManager>& manager, 247 std::unordered_map<int32_t, DragPointerEvent> newIdPoints, 248 std::string& extraInfo, 249 std::unordered_map<int, DragPointerEvent> &idToPoints, 250 const RefPtr<FrameNode>& node); 251 252 // Called by view when axis event received. 253 void OnAxisEvent(const AxisEvent& event) override; 254 255 // Called by container when rotation event received. 256 // if return false, then this event needs platform to handle it. OnRotationEvent(const RotationEvent & event)257 bool OnRotationEvent(const RotationEvent& event) const override 258 { 259 return false; 260 } 261 262 void OnDragEvent(const DragPointerEvent& pointerEvent, DragEventAction action, 263 const RefPtr<NG::FrameNode>& node = nullptr) override; 264 265 void HandleOnDragEventMove(const DragPointerEvent& pointerEvent, DragEventAction action, 266 const RefPtr<NG::FrameNode>& node = nullptr); 267 268 // Called by view when idle event. 269 void OnIdle(int64_t deadline) override; 270 SetBuildAfterCallback(const std::function<void ()> & callback)271 void SetBuildAfterCallback(const std::function<void()>& callback) override 272 { 273 buildFinishCallbacks_.emplace_back(callback); 274 } 275 SaveExplicitAnimationOption(const AnimationOption & option)276 void SaveExplicitAnimationOption(const AnimationOption& option) override {} 277 CreateExplicitAnimator(const std::function<void ()> & onFinishEvent)278 void CreateExplicitAnimator(const std::function<void()>& onFinishEvent) override {} 279 ClearExplicitAnimationOption()280 void ClearExplicitAnimationOption() override {} 281 GetExplicitAnimationOption()282 AnimationOption GetExplicitAnimationOption() const override 283 { 284 return {}; 285 } 286 287 bool HasOnAreaChangeNode(int32_t nodeId); 288 289 void AddOnAreaChangeNode(int32_t nodeId); 290 291 void RemoveOnAreaChangeNode(int32_t nodeId); 292 293 void HandleOnAreaChangeEvent(uint64_t nanoTimestamp); 294 295 // Just register notification, no need to update callback. 296 void AddVisibleAreaChangeNode(const int32_t nodeId); 297 298 void AddVisibleAreaChangeNode(const RefPtr<FrameNode>& node, 299 const std::vector<double>& ratio, const VisibleRatioCallback& callback, bool isUserCallback = true, 300 bool isCalculateInnerClip = false); 301 void RemoveVisibleAreaChangeNode(int32_t nodeId); 302 303 void HandleVisibleAreaChangeEvent(uint64_t nanoTimestamp); 304 305 void HandleSubwindow(bool isShow); 306 307 void Destroy() override; 308 309 void OnShow() override; 310 311 void OnHide() override; 312 313 void WindowFocus(bool isFocus) override; 314 315 void WindowActivate(bool isActive) override; 316 317 void ContainerModalUnFocus() override; 318 319 void ShowContainerTitle(bool isShow, bool hasDeco = true, bool needUpdate = false) override; 320 321 void SetAppBgColor(const Color& color) override; 322 323 void SetWindowContainerColor(const Color& activeColor, const Color& inactiveColor) override; 324 325 void SetAppTitle(const std::string& title) override; 326 327 void SetAppIcon(const RefPtr<PixelMap>& icon) override; 328 329 void OnSurfaceChanged(int32_t width, int32_t height, 330 WindowSizeChangeReason type = WindowSizeChangeReason::UNDEFINED, 331 const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr) override; 332 333 void OnLayoutCompleted(const std::string& componentId); 334 void OnDrawCompleted(const std::string& componentId); 335 336 void OnSurfacePositionChanged(int32_t posX, int32_t posY) override; 337 338 void OnSurfaceDensityChanged(double density) override; 339 OnSystemBarHeightChanged(double statusBar,double navigationBar)340 void OnSystemBarHeightChanged(double statusBar, double navigationBar) override {} 341 OnSurfaceDestroyed()342 void OnSurfaceDestroyed() override {} 343 NotifyOnPreDraw()344 void NotifyOnPreDraw() override {} 345 CallRouterBackToPopPage()346 bool CallRouterBackToPopPage() override 347 { 348 return OnBackPressed(); 349 } 350 351 bool OnBackPressed(); 352 353 RefPtr<FrameNode> FindNavigationNodeToHandleBack(const RefPtr<UINode>& node, bool& isEntry); 354 355 void AddDirtyPropertyNode(const RefPtr<FrameNode>& dirty); 356 357 void AddDirtyCustomNode(const RefPtr<UINode>& dirtyNode); 358 359 void AddDirtyLayoutNode(const RefPtr<FrameNode>& dirty); 360 361 void AddLayoutNode(const RefPtr<FrameNode>& layoutNode); 362 363 void AddDirtyRenderNode(const RefPtr<FrameNode>& dirty); 364 365 void AddDirtyFreezeNode(FrameNode* node); 366 367 void AddPredictTask(PredictTask&& task); 368 369 void AddAfterLayoutTask(std::function<void()>&& task, bool isFlushInImplicitAnimationTask = false); 370 371 void AddPersistAfterLayoutTask(std::function<void()>&& task); 372 373 void AddAfterRenderTask(std::function<void()>&& task); 374 375 void AddSafeAreaPaddingProcessTask(FrameNode* node); 376 void RemoveSafeAreaPaddingProcessTask(FrameNode* node); 377 AddDragWindowVisibleTask(std::function<void ()> && task)378 void AddDragWindowVisibleTask(std::function<void()>&& task) 379 { 380 dragWindowVisibleCallback_ = std::move(task); 381 } 382 383 void FlushOnceVsyncTask() override; 384 385 void FlushFreezeNode(); 386 void FlushDirtyPropertyNodes(); 387 void FlushDirtyNodeUpdate(); 388 void FlushSafeAreaPaddingProcess(); 389 390 void SetRootRect(double width, double height, double offset) override; 391 392 void SetWindowSceneConsumed(bool isConsumed); 393 394 bool IsWindowSceneConsumed(); 395 396 void UpdateSystemSafeArea(const SafeAreaInsets& systemSafeArea, bool checkSystemWindow = false) override; 397 void UpdateCutoutSafeArea(const SafeAreaInsets& cutoutSafeArea, bool checkSystemWindow = false) override; 398 void UpdateNavSafeArea(const SafeAreaInsets& navSafeArea, bool checkSystemWindow = false) override; 399 400 void UpdateOriginAvoidArea(const Rosen::AvoidArea& avoidArea, uint32_t type) override; 401 402 float GetPageAvoidOffset() override; 403 404 bool CheckNeedAvoidInSubWindow() override; 405 406 void CheckAndUpdateKeyboardInset(float keyboardHeight) override; 407 408 void UpdateSizeChangeReason( 409 WindowSizeChangeReason type, const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr); 410 UpdateDisplayAvailableRect(const Rect & displayAvailableRect)411 void UpdateDisplayAvailableRect(const Rect& displayAvailableRect) 412 { 413 displayAvailableRect_ = displayAvailableRect; 414 } GetDisplayAvailableRect()415 Rect GetDisplayAvailableRect() const 416 { 417 return displayAvailableRect_; 418 } 419 420 void SetEnableKeyBoardAvoidMode(KeyBoardAvoidMode value) override; 421 422 KeyBoardAvoidMode GetEnableKeyBoardAvoidMode() override; 423 424 bool UsingCaretAvoidMode(); 425 426 void OnCaretPositionChangeOrKeyboardHeightChange(float keyboardHeight, double positionY, double height, 427 const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr, bool forceChange = false); 428 void DoKeyboardAvoidFunc(float keyboardHeight, double positionY, double height, 429 bool keyboardHeightChanged); 430 float CalcNewKeyboardOffset(float keyboardHeight, float positionYWithOffset, 431 float height, SizeF& rootSize, bool isInline = false); 432 float CalcAvoidOffset(float keyboardHeight, float positionYWithOffset, 433 float height, SizeF rootSize); 434 435 bool IsEnableKeyBoardAvoidMode() override; 436 437 void RequireSummary() override; 438 GetSafeAreaManager()439 const RefPtr<SafeAreaManager>& GetSafeAreaManager() const 440 { 441 return safeAreaManager_; 442 } 443 virtual SafeAreaInsets GetSafeArea() const; 444 445 virtual SafeAreaInsets GetSafeAreaWithoutProcess() const; 446 447 const RefPtr<FullScreenManager>& GetFullScreenManager(); 448 449 RefPtr<AccessibilityManagerNG> GetAccessibilityManagerNG(); 450 451 void SendEventToAccessibilityWithNode( 452 const AccessibilityEvent& accessibilityEvent, const RefPtr<FrameNode>& node); 453 454 const RefPtr<StageManager>& GetStageManager(); 455 456 const RefPtr<OverlayManager>& GetOverlayManager(); 457 458 const RefPtr<SelectOverlayManager>& GetSelectOverlayManager(); 459 GetSharedOverlayManager()460 const RefPtr<SharedOverlayManager>& GetSharedOverlayManager() 461 { 462 return sharedTransitionManager_; 463 } 464 465 #ifdef WINDOW_SCENE_SUPPORTED GetUIExtensionManager()466 const RefPtr<UIExtensionManager>& GetUIExtensionManager() 467 { 468 return uiExtensionManager_; 469 } 470 #endif 471 472 const RefPtr<DragDropManager>& GetDragDropManager(); 473 474 const RefPtr<FocusManager>& GetFocusManager() const; 475 476 const RefPtr<FocusManager>& GetOrCreateFocusManager(); 477 GetFrameRateManager()478 const RefPtr<FrameRateManager>& GetFrameRateManager() 479 { 480 return frameRateManager_; 481 } 482 483 void FlushBuild() override; 484 485 void FlushPipelineImmediately() override; 486 void RebuildFontNode() override; 487 488 void AddBuildFinishCallBack(std::function<void()>&& callback); 489 490 void AddWindowStateChangedCallback(int32_t nodeId); 491 492 void RemoveWindowStateChangedCallback(int32_t nodeId); 493 494 void AddWindowFocusChangedCallback(int32_t nodeId); 495 496 void RemoveWindowFocusChangedCallback(int32_t nodeId); 497 498 void AddWindowActivateChangedCallback(int32_t nodeId); 499 500 void RemoveWindowActivateChangedCallback(int32_t nodeId); 501 502 void AddWindowSizeChangeCallback(int32_t nodeId); 503 504 void RemoveWindowSizeChangeCallback(int32_t nodeId); 505 506 void AddWindowSizeDragEndCallback(std::function<void()>&& callback); 507 508 void AddNavigationNode(int32_t pageId, WeakPtr<UINode> navigationNode); 509 510 void RemoveNavigationNode(int32_t pageId, int32_t nodeId); 511 512 void FirePageChanged(int32_t pageId, bool isOnShow); 513 514 bool HasDifferentDirectionGesture() const; 515 IsKeyInPressed(KeyCode tarCode)516 bool IsKeyInPressed(KeyCode tarCode) const 517 { 518 CHECK_NULL_RETURN(eventManager_, false); 519 return eventManager_->IsKeyInPressed(tarCode); 520 } 521 GetIsFocusingByTab()522 bool GetIsFocusingByTab() const 523 { 524 return isFocusingByTab_; 525 } 526 SetIsFocusingByTab(bool isFocusingByTab)527 void SetIsFocusingByTab(bool isFocusingByTab) 528 { 529 isFocusingByTab_ = isFocusingByTab; 530 } 531 GetIsFocusActive()532 bool GetIsFocusActive() const 533 { 534 return isFocusActive_; 535 } 536 537 bool SetIsFocusActive(bool isFocusActive, 538 FocusActiveReason reason = FocusActiveReason::KEYBOARD_EVENT, bool autoFocusInactive = true); 539 540 void AddIsFocusActiveUpdateEvent(const RefPtr<FrameNode>& node, const std::function<void(bool)>& eventCallback); 541 void RemoveIsFocusActiveUpdateEvent(const RefPtr<FrameNode>& node); 542 IsTabJustTriggerOnKeyEvent()543 bool IsTabJustTriggerOnKeyEvent() const 544 { 545 return eventManager_->IsTabJustTriggerOnKeyEvent(); 546 } 547 GetOnShow()548 bool GetOnShow() const override 549 { 550 return onShow_; 551 } 552 553 bool ChangeMouseStyle(int32_t nodeId, MouseFormat format, int32_t windowId = 0, bool isByPass = false, 554 MouseStyleChangeReason reason = MouseStyleChangeReason::INNER_SET_MOUSESTYLE); 555 556 bool RequestFocus(const std::string& targetNodeId, bool isSyncRequest = false) override; 557 void AddDirtyFocus(const RefPtr<FrameNode>& node); 558 void AddDirtyRequestFocus(const RefPtr<FrameNode>& node); 559 void RootLostFocus(BlurReason reason = BlurReason::FOCUS_SWITCH) const; 560 561 void SetContainerWindow(bool isShow, RRect& rRect); 562 void SetContainerButtonHide(bool hideSplit, bool hideMaximize, bool hideMinimize, bool hideClose) override; 563 void EnableContainerModalGesture(bool isEnable) override; 564 void SetCloseButtonStatus(bool isEnabled); 565 566 void AddNodesToNotifyMemoryLevel(int32_t nodeId); 567 void RemoveNodesToNotifyMemoryLevel(int32_t nodeId); 568 void NotifyMemoryLevel(int32_t level) override; 569 void FlushModifier() override; 570 void FlushMessages() override; 571 572 void FlushUITasks(bool triggeredByImplicitAnimation = false) override; 573 void FlushUITaskWithSingleDirtyNode(const RefPtr<FrameNode>& node); 574 575 void FlushAfterLayoutCallbackInImplicitAnimationTask() override; 576 GetIsRequestVsync()577 bool GetIsRequestVsync() 578 { 579 return window_->GetIsRequestVsync(); 580 } 581 IsLayouting()582 bool IsLayouting() const override 583 { 584 return taskScheduler_->IsLayouting(); 585 } 586 // end pipeline, exit app 587 void Finish(bool autoFinish) const override; GetRootRect()588 RectF GetRootRect() 589 { 590 CHECK_NULL_RETURN(rootNode_, RectF()); 591 auto geometryNode = rootNode_->GetGeometryNode(); 592 CHECK_NULL_RETURN(geometryNode, RectF()); 593 return geometryNode->GetFrameRect(); 594 } 595 596 void FlushReload(const ConfigurationChange& configurationChange, bool fullUpdate = true) override; OnFlushReloadFinish()597 void OnFlushReloadFinish() 598 { 599 auto tasks = std::move(afterReloadAnimationTasks_); 600 for (const auto& task : tasks) { 601 if (task) { 602 task(); 603 } 604 } 605 } AddAfterReloadAnimationTask(std::function<void ()> && task)606 void AddAfterReloadAnimationTask(std::function<void()>&& task) 607 { 608 afterReloadAnimationTasks_.emplace_back(std::move(task)); 609 } 610 RegisterSurfaceChangedCallback(std::function<void (int32_t,int32_t,int32_t,int32_t,WindowSizeChangeReason)> && callback)611 int32_t RegisterSurfaceChangedCallback( 612 std::function<void(int32_t, int32_t, int32_t, int32_t, WindowSizeChangeReason)>&& callback) 613 { 614 if (callback) { 615 surfaceChangedCallbackMap_.emplace(++callbackId_, std::move(callback)); 616 return callbackId_; 617 } 618 return 0; 619 } 620 UnregisterSurfaceChangedCallback(int32_t callbackId)621 void UnregisterSurfaceChangedCallback(int32_t callbackId) 622 { 623 surfaceChangedCallbackMap_.erase(callbackId); 624 } 625 RegisterFoldStatusChangedCallback(std::function<void (FoldStatus)> && callback)626 int32_t RegisterFoldStatusChangedCallback(std::function<void(FoldStatus)>&& callback) 627 { 628 if (callback) { 629 foldStatusChangedCallbackMap_.emplace(callbackId_, std::move(callback)); 630 return callbackId_; 631 } 632 return 0; 633 } 634 UnRegisterFoldStatusChangedCallback(int32_t callbackId)635 void UnRegisterFoldStatusChangedCallback(int32_t callbackId) 636 { 637 foldStatusChangedCallbackMap_.erase(callbackId); 638 } 639 RegisterHalfFoldHoverChangedCallback(std::function<void (bool)> && callback)640 int32_t RegisterHalfFoldHoverChangedCallback(std::function<void(bool)>&& callback) 641 { 642 if (callback) { 643 halfFoldHoverChangedCallbackMap_.emplace(++callbackId_, std::move(callback)); 644 return callbackId_; 645 } 646 return 0; 647 } 648 UnRegisterHalfFoldHoverChangedCallback(int32_t callbackId)649 void UnRegisterHalfFoldHoverChangedCallback(int32_t callbackId) 650 { 651 halfFoldHoverChangedCallbackMap_.erase(callbackId); 652 } 653 654 void UpdateHalfFoldHoverStatus(int32_t windowWidth, int32_t windowHeight); 655 IsHalfFoldHoverStatus()656 bool IsHalfFoldHoverStatus() 657 { 658 return isHalfFoldHoverStatus_; 659 } 660 661 void OnHalfFoldHoverChangedCallback(); 662 RegisterFoldDisplayModeChangedCallback(std::function<void (FoldDisplayMode)> && callback)663 int32_t RegisterFoldDisplayModeChangedCallback(std::function<void(FoldDisplayMode)>&& callback) 664 { 665 if (callback) { 666 foldDisplayModeChangedCallbackMap_.emplace(++callbackId_, std::move(callback)); 667 return callbackId_; 668 } 669 return 0; 670 } 671 UnRegisterFoldDisplayModeChangedCallback(int32_t callbackId)672 void UnRegisterFoldDisplayModeChangedCallback(int32_t callbackId) 673 { 674 foldDisplayModeChangedCallbackMap_.erase(callbackId); 675 } 676 RegisterSurfacePositionChangedCallback(std::function<void (int32_t,int32_t)> && callback)677 int32_t RegisterSurfacePositionChangedCallback(std::function<void(int32_t, int32_t)>&& callback) 678 { 679 if (callback) { 680 surfacePositionChangedCallbackMap_.emplace(++callbackId_, std::move(callback)); 681 return callbackId_; 682 } 683 return 0; 684 } 685 UnregisterSurfacePositionChangedCallback(int32_t callbackId)686 void UnregisterSurfacePositionChangedCallback(int32_t callbackId) 687 { 688 surfacePositionChangedCallbackMap_.erase(callbackId); 689 } 690 RegisterTransformHintChangeCallback(std::function<void (uint32_t)> && callback)691 int32_t RegisterTransformHintChangeCallback(std::function<void(uint32_t)>&& callback) 692 { 693 if (callback) { 694 transformHintChangedCallbackMap_.emplace(++callbackId_, std::move(callback)); 695 return callbackId_; 696 } 697 return 0; 698 } 699 UnregisterTransformHintChangedCallback(int32_t callbackId)700 void UnregisterTransformHintChangedCallback(int32_t callbackId) 701 { 702 transformHintChangedCallbackMap_.erase(callbackId); 703 } 704 SetMouseStyleHoldNode(int32_t id)705 bool SetMouseStyleHoldNode(int32_t id) 706 { 707 CHECK_NULL_RETURN(eventManager_, false); 708 auto mouseStyleManager = eventManager_->GetMouseStyleManager(); 709 if (mouseStyleManager) { 710 return mouseStyleManager->SetMouseStyleHoldNode(id); 711 } 712 return false; 713 } 714 FreeMouseStyleHoldNode(int32_t id)715 bool FreeMouseStyleHoldNode(int32_t id) 716 { 717 CHECK_NULL_RETURN(eventManager_, false); 718 auto mouseStyleManager = eventManager_->GetMouseStyleManager(); 719 if (mouseStyleManager) { 720 return mouseStyleManager->FreeMouseStyleHoldNode(id); 721 } 722 return false; 723 } 724 FreeMouseStyleHoldNode()725 bool FreeMouseStyleHoldNode() 726 { 727 CHECK_NULL_RETURN(eventManager_, false); 728 auto mouseStyleManager = eventManager_->GetMouseStyleManager(); 729 if (mouseStyleManager) { 730 return mouseStyleManager->FreeMouseStyleHoldNode(); 731 } 732 return false; 733 } 734 735 void MarkNeedFlushMouseEvent(MockFlushEventType type = MockFlushEventType::EXECUTE) 736 { 737 isNeedFlushMouseEvent_ = type; 738 } 739 MarkNeedFlushAnimationStartTime()740 void MarkNeedFlushAnimationStartTime() 741 { 742 isNeedFlushAnimationStartTime_ = true; 743 } 744 745 // font 746 void AddFontNodeNG(const WeakPtr<UINode>& node); 747 void RemoveFontNodeNG(const WeakPtr<UINode>& node); 748 749 // restore 750 void RestoreNodeInfo(std::unique_ptr<JsonValue> nodeInfo) override; 751 std::unique_ptr<JsonValue> GetStoredNodeInfo() override; 752 void StoreNode(int32_t restoreId, const WeakPtr<FrameNode>& node); 753 bool GetRestoreInfo(int32_t restoreId, std::string& restoreInfo); RemoveStoredNode(int32_t restoreId)754 void RemoveStoredNode(int32_t restoreId) 755 { 756 storeNode_.erase(restoreId); 757 } 758 void SetNeedRenderNode(const WeakPtr<FrameNode>& node); 759 760 void SetIgnoreViewSafeArea(bool value) override; 761 void SetIsLayoutFullScreen(bool value) override; 762 void SetIsNeedAvoidWindow(bool value) override; 763 764 void AddAnimationClosure(std::function<void()>&& animation); 765 void FlushAnimationClosure(); 766 void DumpJsInfo(const std::vector<std::string>& params) const; 767 void DumpUIExt() const override; 768 769 bool DumpPageViewData(const RefPtr<FrameNode>& node, RefPtr<ViewDataWrap> viewDataWrap, 770 bool skipSubAutoFillContainer = false, bool needsRecordData = false); 771 bool CheckNeedAutoSave(); 772 bool CheckOverlayFocus(); 773 void NotifyFillRequestSuccess(AceAutoFillType autoFillType, RefPtr<ViewDataWrap> viewDataWrap); 774 void NotifyFillRequestFailed(RefPtr<FrameNode> node, int32_t errCode, 775 const std::string& fillContent = "", bool isPopup = false); 776 777 std::shared_ptr<NavigationController> GetNavigationController(const std::string& id) override; 778 void AddOrReplaceNavigationNode(const std::string& id, const WeakPtr<FrameNode>& node); 779 void DeleteNavigationNode(const std::string& id); 780 AddGestureTask(const DelayedTask & task)781 void AddGestureTask(const DelayedTask& task) 782 { 783 delayedTasks_.emplace_back(task); 784 } 785 RemoveGestureTask(const DelayedTask & task)786 void RemoveGestureTask(const DelayedTask& task) 787 { 788 for (auto iter = delayedTasks_.begin(); iter != delayedTasks_.end();) { 789 if (iter->recognizer == task.recognizer) { 790 iter = delayedTasks_.erase(iter); 791 } else { 792 ++iter; 793 } 794 } 795 } 796 SetScreenNode(const RefPtr<FrameNode> & node)797 void SetScreenNode(const RefPtr<FrameNode>& node) 798 { 799 CHECK_NULL_VOID(node); 800 screenNode_ = AceType::WeakClaim(AceType::RawPtr(node)); 801 } GetScreenNode()802 RefPtr<FrameNode> GetScreenNode() const 803 { 804 return screenNode_.Upgrade(); 805 } 806 SetFocusedWindowSceneNode(const WeakPtr<FrameNode> & node)807 void SetFocusedWindowSceneNode(const WeakPtr<FrameNode>& node) 808 { 809 windowSceneNode_ = node; 810 } GetFocusedWindowSceneNode()811 RefPtr<FrameNode> GetFocusedWindowSceneNode() const 812 { 813 return windowSceneNode_.Upgrade(); 814 } 815 816 void SetJSViewActive(bool active, WeakPtr<CustomNode> custom); 817 UpdateCurrentActiveNode(const WeakPtr<FrameNode> & node)818 void UpdateCurrentActiveNode(const WeakPtr<FrameNode>& node) override 819 { 820 activeNode_ = std::move(node); 821 } 822 GetCurrentActiveNode()823 const WeakPtr<FrameNode>& GetCurrentActiveNode() const 824 { 825 return activeNode_; 826 } 827 828 std::string GetCurrentExtraInfo() override; 829 void UpdateTitleInTargetPos(bool isShow, int32_t height) override; 830 831 void SetCursor(int32_t cursorValue) override; 832 833 void RestoreDefault(int32_t windowId = 0) override; 834 835 void OnFoldStatusChange(FoldStatus foldStatus) override; 836 void OnFoldDisplayModeChange(FoldDisplayMode foldDisplayMode) override; 837 838 void OnTransformHintChanged(uint32_t transform) override; 839 GetTransformHint()840 uint32_t GetTransformHint() const 841 { 842 return transform_; 843 } 844 845 // for frontend animation interface. 846 void OpenFrontendAnimation( 847 const AnimationOption& option, const RefPtr<Curve>& curve, const std::function<void()>& finishCallback); 848 void CloseFrontendAnimation(); 849 850 bool IsDragging() const override; 851 void SetIsDragging(bool isDragging) override; 852 853 void ResetDragging() override; 854 const RefPtr<PostEventManager>& GetPostEventManager(); 855 856 void SetContainerModalTitleVisible(bool customTitleSettedShow, bool floatingTitleSettedShow); 857 void SetContainerModalTitleHeight(int32_t height); 858 int32_t GetContainerModalTitleHeight(); 859 bool GetContainerModalButtonsRect(RectF& containerModal, RectF& buttons); 860 void SubscribeContainerModalButtonsRectChange( 861 std::function<void(RectF& containerModal, RectF& buttons)>&& callback); 862 void GetWindowPaintRectWithoutMeasureAndLayout(RectInt& rect); 863 864 const SerializedGesture& GetSerializedGesture() const override; 865 // return value means whether it has printed info 866 bool PrintVsyncInfoIfNeed() const override; 867 void SetUIExtensionImeShow(bool imeShow); 868 StartWindowAnimation()869 void StartWindowAnimation() override 870 { 871 isWindowAnimation_ = true; 872 } 873 874 void StopWindowAnimation() override; 875 876 void AddSyncGeometryNodeTask(std::function<void()>&& task) override; 877 void FlushSyncGeometryNodeTasks() override; SetVsyncListener(VsyncCallbackFun vsync)878 void SetVsyncListener(VsyncCallbackFun vsync) 879 { 880 vsyncListener_ = std::move(vsync); 881 } 882 SetOnceVsyncListener(VsyncCallbackFun vsync)883 void SetOnceVsyncListener(VsyncCallbackFun vsync) 884 { 885 onceVsyncListener_ = std::move(vsync); 886 } 887 HasOnceVsyncListener()888 bool HasOnceVsyncListener() { 889 return onceVsyncListener_ != nullptr; 890 } 891 GetMemoryManager()892 const RefPtr<MemoryManager>& GetMemoryManager() const 893 { 894 return memoryMgr_; 895 } 896 GetNavigationManager()897 const RefPtr<NavigationManager>& GetNavigationManager() const 898 { 899 return navigationMgr_; 900 } 901 GetFormVisibleManager()902 const RefPtr<FormVisibleManager>& GetFormVisibleManager() const 903 { 904 return formVisibleMgr_; 905 } 906 GetFormEventManager()907 const RefPtr<FormEventManager>& GetFormEventManager() const 908 { 909 return formEventMgr_; 910 } 911 GetFormGestureManager()912 const RefPtr<FormGestureManager>& GetFormGestureManager() const 913 { 914 return formGestureMgr_; 915 } 916 GetAvoidInfoManager()917 const RefPtr<AvoidInfoManager>& GetAvoidInfoManager() const 918 { 919 return avoidInfoMgr_; 920 } 921 GetRecycleManager()922 const std::unique_ptr<RecycleManager>& GetRecycleManager() const 923 { 924 return recycleManager_; 925 } 926 GetPrivacySensitiveManager()927 RefPtr<PrivacySensitiveManager> GetPrivacySensitiveManager() const 928 { 929 return privacySensitiveManager_; 930 } 931 ChangeSensitiveNodes(bool flag)932 void ChangeSensitiveNodes(bool flag) override 933 { 934 privacySensitiveManager_->TriggerFrameNodesSensitive(flag); 935 } 936 937 void FlushRequestFocus(); 938 939 Dimension GetCustomTitleHeight(); 940 941 void SetOverlayNodePositions(std::vector<Ace::RectF> rects); 942 943 static void SetCallBackNode(const WeakPtr<NG::FrameNode>& node); 944 945 std::vector<Ace::RectF> GetOverlayNodePositions(); 946 947 void RegisterOverlayNodePositionsUpdateCallback( 948 const std::function<void(std::vector<Ace::RectF>)>&& callback); 949 950 void TriggerOverlayNodePositionsUpdateCallback(std::vector<Ace::RectF> rects); 951 952 void DetachNode(RefPtr<UINode> uiNode); 953 954 void CheckNeedUpdateBackgroundColor(Color& color); 955 956 bool CheckNeedDisableUpdateBackgroundImage(); 957 958 void ChangeDarkModeBrightness() override; 959 960 std::string GetResponseRegion(const RefPtr<NG::FrameNode>& rootNode) override; 961 962 void NotifyResponseRegionChanged(const RefPtr<NG::FrameNode>& rootNode) override; 963 SetLocalColorMode(ColorMode colorMode)964 void SetLocalColorMode(ColorMode colorMode) 965 { 966 auto localColorModeValue = static_cast<int32_t>(colorMode); 967 localColorMode_ = localColorModeValue; 968 } 969 GetLocalColorMode()970 ColorMode GetLocalColorMode() const // ColorMode for WithTheme 971 { 972 ColorMode colorMode = static_cast<ColorMode>(localColorMode_.load()); 973 return colorMode; 974 } 975 976 ColorMode GetColorMode() const; 977 SetIsFreezeFlushMessage(bool isFreezeFlushMessage)978 void SetIsFreezeFlushMessage(bool isFreezeFlushMessage) 979 { 980 isFreezeFlushMessage_ = isFreezeFlushMessage; 981 } 982 IsFreezeFlushMessage()983 bool IsFreezeFlushMessage() const 984 { 985 return isFreezeFlushMessage_; 986 } 987 bool IsContainerModalVisible() override; SetDoKeyboardAvoidAnimate(bool isDoKeyboardAvoidAnimate)988 void SetDoKeyboardAvoidAnimate(bool isDoKeyboardAvoidAnimate) 989 { 990 isDoKeyboardAvoidAnimate_ = isDoKeyboardAvoidAnimate; 991 } 992 993 void CheckAndLogLastReceivedTouchEventInfo(int32_t eventId, TouchType type) override; 994 995 void CheckAndLogLastConsumedTouchEventInfo(int32_t eventId, TouchType type) override; 996 997 void CheckAndLogLastReceivedMouseEventInfo(int32_t eventId, MouseAction action) override; 998 999 void CheckAndLogLastConsumedMouseEventInfo(int32_t eventId, MouseAction action) override; 1000 1001 void CheckAndLogLastReceivedAxisEventInfo(int32_t eventId, AxisAction action) override; 1002 1003 void CheckAndLogLastConsumedAxisEventInfo(int32_t eventId, AxisAction action) override; 1004 1005 void AddFrameCallback(FrameCallbackFunc&& frameCallbackFunc, FrameCallbackFunc&& idleCallbackFunc, 1006 int64_t delayMillis); 1007 1008 void FlushFrameCallback(uint64_t nanoTimestamp); 1009 void TriggerIdleCallback(int64_t deadline); 1010 1011 void AddCAPIFrameCallback(FrameCallbackFuncFromCAPI&& frameCallbackFuncFromCAPI); 1012 void FlushFrameCallbackFromCAPI(uint64_t nanoTimestamp, uint32_t frameCount); 1013 1014 void RegisterTouchEventListener(const std::shared_ptr<ITouchEventCallback>& listener); 1015 void UnregisterTouchEventListener(const WeakPtr<NG::Pattern>& pattern); 1016 SetPredictNode(const RefPtr<FrameNode> & node)1017 void SetPredictNode(const RefPtr<FrameNode>& node) 1018 { 1019 predictNode_ = node; 1020 } 1021 ResetPredictNode()1022 void ResetPredictNode() 1023 { 1024 predictNode_.Reset(); 1025 } 1026 1027 void PreLayout(uint64_t nanoTimestamp, uint32_t frameCount); 1028 IsDensityChanged()1029 bool IsDensityChanged() const override 1030 { 1031 return isDensityChanged_; 1032 } 1033 IsNeedReloadDensity()1034 bool IsNeedReloadDensity() const override 1035 { 1036 return isNeedReloadDensity_; 1037 } 1038 SetIsNeedReloadDensity(bool isNeedReloadDensity)1039 void SetIsNeedReloadDensity(bool isNeedReloadDensity) override 1040 { 1041 isNeedReloadDensity_ = isNeedReloadDensity; 1042 } 1043 1044 void GetInspectorTree(bool onlyNeedVisible); 1045 void NotifyAllWebPattern(bool isRegister); 1046 void AddFrameNodeChangeListener(const WeakPtr<FrameNode>& node); 1047 void RemoveFrameNodeChangeListener(int32_t nodeId); 1048 bool AddChangedFrameNode(const WeakPtr<FrameNode>& node); 1049 void RemoveChangedFrameNode(int32_t nodeId); SetForceSplitEnable(bool isForceSplit,const std::string & homePage)1050 void SetForceSplitEnable(bool isForceSplit, const std::string& homePage) 1051 { 1052 TAG_LOGI(AceLogTag::ACE_ROUTER, "set force split %{public}s", isForceSplit ? "enable" : "disable"); 1053 isForceSplit_ = isForceSplit; 1054 homePageConfig_ = homePage; 1055 } 1056 GetForceSplitEnable()1057 bool GetForceSplitEnable() const 1058 { 1059 return isForceSplit_; 1060 } 1061 GetHomePageConfig()1062 std::string GetHomePageConfig() const 1063 { 1064 return homePageConfig_; 1065 } 1066 1067 bool CatchInteractiveAnimations(const std::function<void()>& animationCallback) override; 1068 IsWindowFocused()1069 bool IsWindowFocused() const override 1070 { 1071 return isWindowHasFocused_ && GetOnFoucs(); 1072 } 1073 1074 void CollectTouchEventsBeforeVsync(std::list<TouchEvent>& touchEvents); 1075 IsDirtyNodesEmpty()1076 bool IsDirtyNodesEmpty() const override 1077 { 1078 return dirtyNodes_.empty(); 1079 } 1080 IsDirtyLayoutNodesEmpty()1081 bool IsDirtyLayoutNodesEmpty() const override 1082 { 1083 return taskScheduler_->IsDirtyLayoutNodesEmpty(); 1084 } 1085 IsDirtyPropertyNodesEmpty()1086 bool IsDirtyPropertyNodesEmpty() const override 1087 { 1088 return dirtyPropertyNodes_.empty(); 1089 } 1090 1091 void SyncSafeArea(SafeAreaSyncType syncType = SafeAreaSyncType::SYNC_TYPE_NONE); 1092 bool CheckThreadSafe(); 1093 IsHoverModeChange()1094 bool IsHoverModeChange() const 1095 { 1096 return isHoverModeChanged_; 1097 } 1098 1099 void UpdateHalfFoldHoverProperty(int32_t windowWidth, int32_t windowHeight); 1100 1101 void AnimateOnSafeAreaUpdate(); 1102 void RegisterAttachedNode(UINode* uiNode); 1103 void RemoveAttachedNode(UINode* uiNode); 1104 1105 bool GetContainerFloatingTitleVisible() override; 1106 1107 bool GetContainerCustomTitleVisible() override; 1108 1109 bool GetContainerControlButtonVisible() override; 1110 1111 std::string GetBundleName(); 1112 std::string GetModuleName(); 1113 SaveTranslateManager(std::shared_ptr<UiTranslateManagerImpl> uiTranslateManager)1114 void SaveTranslateManager(std::shared_ptr<UiTranslateManagerImpl> uiTranslateManager) 1115 { 1116 uiTranslateManager_ = uiTranslateManager; 1117 } 1118 RegisterListenerForTranslate(const WeakPtr<NG::FrameNode> node)1119 void RegisterListenerForTranslate(const WeakPtr<NG::FrameNode> node) 1120 { 1121 uiTranslateManager_->AddTranslateListener(node); 1122 } 1123 UnRegisterListenerForTranslate(int32_t nodeId)1124 void UnRegisterListenerForTranslate(int32_t nodeId) 1125 { 1126 uiTranslateManager_->RemoveTranslateListener(nodeId); 1127 } 1128 1129 void SetEnableSwipeBack(bool isEnable) override; 1130 GetHostParentOffsetToWindow()1131 Offset GetHostParentOffsetToWindow() const 1132 { 1133 return lastHostParentOffsetToWindow_; 1134 } 1135 1136 void SetHostParentOffsetToWindow(const Offset& offset); 1137 1138 RefPtr<Kit::UIContext> GetUIContext(); 1139 void AddPendingDeleteCustomNode(const RefPtr<CustomNode>& node); 1140 void FlushPendingDeleteCustomNode(); 1141 1142 void HandleSpecialContainerNode(); 1143 AddPositionZNode(int32_t nodeId)1144 void AddPositionZNode(int32_t nodeId) 1145 { 1146 positionZNodes_.insert(nodeId); 1147 } 1148 DeletePositionZNode(int32_t nodeId)1149 void DeletePositionZNode(int32_t nodeId) 1150 { 1151 auto it = positionZNodes_.find(nodeId); 1152 if (it != positionZNodes_.end()) { 1153 positionZNodes_.erase(it); 1154 } 1155 } 1156 GetPositionZNodes()1157 std::set<int32_t> GetPositionZNodes() 1158 { 1159 return positionZNodes_; 1160 } 1161 ClearPositionZNodes()1162 void ClearPositionZNodes() 1163 { 1164 positionZNodes_.clear(); 1165 } IsWindowSizeDragging()1166 bool IsWindowSizeDragging() const 1167 { 1168 return isWindowSizeDragging_; 1169 } 1170 1171 void SetIsWindowSizeDragging(bool isDragging); 1172 void GetAllPixelMap(); AddPixelMap(int32_t nodeId,RefPtr<PixelMap> pixelMap)1173 void AddPixelMap(int32_t nodeId, RefPtr<PixelMap> pixelMap) 1174 { 1175 uiTranslateManager_->AddPixelMap(nodeId, pixelMap); 1176 } 1177 1178 protected: 1179 void StartWindowSizeChangeAnimate(int32_t width, int32_t height, WindowSizeChangeReason type, 1180 const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr); 1181 void StartWindowMaximizeAnimation( 1182 int32_t width, int32_t height, const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr); 1183 void StartFullToMultWindowAnimation(int32_t width, int32_t height, WindowSizeChangeReason type, 1184 const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr); 1185 void StartSplitWindowAnimation(int32_t width, int32_t height, WindowSizeChangeReason type, 1186 const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr); 1187 1188 void FlushVsync(uint64_t nanoTimestamp, uint32_t frameCount) override; 1189 void FlushPipelineWithoutAnimation() override; 1190 void FlushFocus(); 1191 void FlushFocusWithNode(RefPtr<FrameNode> focusNode, bool isScope); 1192 void DispatchDisplaySync(uint64_t nanoTimestamp) override; 1193 void FlushAnimation(uint64_t nanoTimestamp) override; 1194 bool OnDumpInfo(const std::vector<std::string>& params) const override; 1195 void OnDumpRecorderStart(const std::vector<std::string>& params) const; 1196 void TriggerFrameDumpFuncIfExist() const; 1197 1198 void OnVirtualKeyboardHeightChange(float keyboardHeight, 1199 const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr, const float safeHeight = 0.0f, 1200 const bool supportAvoidance = false, bool forceChange = false) override; 1201 void OnVirtualKeyboardHeightChange(float keyboardHeight, double positionY, double height, 1202 const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr, bool forceChange = false) override; 1203 void FlushDirtyPropertyNodesWhenExist(); 1204 SetIsLayouting(bool layouting)1205 void SetIsLayouting(bool layouting) 1206 { 1207 taskScheduler_->SetIsLayouting(layouting); 1208 } 1209 1210 void AvoidanceLogic(float keyboardHeight, const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr, 1211 const float safeHeight = 0.0f, const bool supportAvoidance = false); 1212 void OriginalAvoidanceLogic( 1213 float keyboardHeight, const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr); 1214 RefPtr<FrameNode> GetContainerModalNode(); 1215 void DoKeyboardAvoidAnimate(const KeyboardAnimationConfig& keyboardAnimationConfig, float keyboardHeight, 1216 const std::function<void()>& func); 1217 void StartFoldStatusDelayTask(FoldStatus foldStatus); 1218 void PostKeyboardAvoidTask(); 1219 1220 private: 1221 void ExecuteSurfaceChangedCallbacks(int32_t newWidth, int32_t newHeight, WindowSizeChangeReason type); 1222 1223 void FlushWindowStateChangedCallback(bool isShow); 1224 1225 void FlushWindowFocusChangedCallback(bool isFocus); 1226 1227 void FlushWindowActivateChangedCallback(bool isActivate); 1228 1229 void FlushWindowSizeChangeCallback(int32_t width, int32_t height, WindowSizeChangeReason type); 1230 1231 1232 uint64_t GetResampleStamp() const; 1233 void ConsumeTouchEvents(std::list<TouchEvent>& touchEvents, std::unordered_map<int, TouchEvent>& idToTouchPoints); 1234 void AccelerateConsumeTouchEvents( 1235 std::list<TouchEvent>& touchEvents, std::unordered_map<int, TouchEvent>& idToTouchPoints); SetTouchAccelarate(bool isEnable)1236 void SetTouchAccelarate(bool isEnable) override 1237 { 1238 touchAccelarate_ = isEnable; 1239 } SetTouchPassThrough(bool isEnable)1240 void SetTouchPassThrough(bool isEnable) override 1241 { 1242 isEventsPassThrough_ = isEnable; 1243 } 1244 1245 void FlushTouchEvents(); 1246 void FlushWindowPatternInfo(); 1247 void FlushFocusView(); 1248 void FlushFocusScroll(); 1249 1250 void ProcessDelayTasks(); 1251 1252 void InspectDrew(); 1253 1254 void FlushBuildFinishCallbacks(); 1255 1256 void DumpPipelineInfo() const; 1257 1258 void RegisterRootEvent(); 1259 1260 void ResetDraggingStatus(const TouchEvent& touchPoint, const RefPtr<FrameNode>& node = nullptr); 1261 1262 void CancelDragIfRightBtnPressed(const MouseEvent& event); 1263 1264 void UpdateLastMoveEvent(const MouseEvent& event); 1265 1266 void CompensateTouchMoveEvent(const TouchEvent& event); 1267 1268 bool CompensateTouchMoveEventFromUnhandledEvents(const TouchEvent& event); 1269 1270 void DispatchMouseToTouchEvent(const MouseEvent& event, const RefPtr<FrameNode>& node); 1271 1272 void CompensateMouseMoveEvent(const MouseEvent& event, const RefPtr<FrameNode>& node); 1273 1274 bool CompensateMouseMoveEventFromUnhandledEvents(const MouseEvent& event, const RefPtr<FrameNode>& node); 1275 1276 void CompensatePointerMoveEvent(const DragPointerEvent& event, const RefPtr<FrameNode>& node); 1277 1278 bool CompensatePointerMoveEventFromUnhandledEvents(const DragPointerEvent& event, const RefPtr<FrameNode>& node); 1279 1280 FrameInfo* GetCurrentFrameInfo(uint64_t recvTime, uint64_t timeStamp); 1281 1282 void DispatchAxisEventToDragDropManager(const AxisEvent& event, const RefPtr<FrameNode>& node, 1283 SerializedGesture& etsSerializedGesture); 1284 1285 // only used for static form. 1286 void UpdateFormLinkInfos(); 1287 1288 void FlushFrameRate(); 1289 1290 void RegisterFocusCallback(); 1291 void DumpFocus(bool hasJson) const; 1292 void DumpResLoadError() const; 1293 void DumpInspector(const std::vector<std::string>& params, bool hasJson) const; 1294 void DumpElement(const std::vector<std::string>& params, bool hasJson) const; 1295 void DumpData(const RefPtr<FrameNode>& node, const std::vector<std::string>& params, bool hasJson) const; 1296 template<typename T> 1297 struct NodeCompare { operatorNodeCompare1298 bool operator()(const T& nodeLeft, const T& nodeRight) const 1299 { 1300 if (!nodeLeft || !nodeRight) { 1301 return false; 1302 } 1303 if (nodeLeft->GetDepth() < nodeRight->GetDepth()) { 1304 return true; 1305 } 1306 if (nodeLeft->GetDepth() == nodeRight->GetDepth()) { 1307 return nodeLeft < nodeRight; 1308 } 1309 return false; 1310 } 1311 }; 1312 1313 void FlushNodeChangeFlag(); 1314 void CleanNodeChangeFlag(); 1315 1316 uint64_t AdjustVsyncTimeStamp(uint64_t nanoTimestamp); 1317 bool FlushModifierAnimation(uint64_t nanoTimestamp); 1318 1319 void FlushAnimationDirtysWhenExist(const AnimationOption& option); 1320 1321 std::unique_ptr<UITaskScheduler> taskScheduler_ = std::make_unique<UITaskScheduler>(); 1322 1323 std::unordered_map<uint32_t, WeakPtr<ScheduleTask>> scheduleTasks_; 1324 1325 std::list<WeakPtr<FrameNode>> dirtyFreezeNode_; // used in freeze feature. 1326 std::stack<RefPtr<CustomNode>> pendingDeleteCustomNode_; 1327 std::set<RefPtr<FrameNode>, NodeCompare<RefPtr<FrameNode>>> dirtyPropertyNodes_; // used in node api. 1328 std::set<RefPtr<UINode>, NodeCompare<RefPtr<UINode>>> dirtyNodes_; 1329 std::list<std::function<void()>> buildFinishCallbacks_; 1330 1331 // window on show or on hide 1332 std::set<int32_t> onWindowStateChangedCallbacks_; 1333 // window on focused or on unfocused 1334 std::set<int32_t> onWindowFocusChangedCallbacks_; 1335 // window on activate or on unactivate 1336 std::set<int32_t> onWindowActivateChangedCallbacks_; 1337 // window on drag 1338 std::list<int32_t> onWindowSizeChangeCallbacks_; 1339 // window size drag end 1340 std::list<std::function<void()>> onWindowSizeDragEndCallbacks_; 1341 1342 std::list<int32_t> nodesToNotifyMemoryLevel_; 1343 1344 std::list<TouchEvent> touchEvents_; 1345 1346 std::map<RefPtr<FrameNode>, std::list<DragPointerEvent>> dragEvents_; 1347 std::map<RefPtr<FrameNode>, std::list<MouseEvent>> mouseEvents_; 1348 std::vector<std::function<void(const std::vector<std::string>&)>> dumpListeners_; 1349 1350 RefPtr<FrameNode> rootNode_; 1351 1352 int32_t curFocusNodeId_ = -1; 1353 1354 bool isTransFlag_ = false; 1355 OHOS::Ace::WindowSizeChangeReason windowSizeChangeReason_ = WindowSizeChangeReason::UNDEFINED; 1356 SourceType lastSourceType_ = SourceType::NONE; 1357 bool preIsHalfFoldHoverStatus_ = false; 1358 bool isHoverModeChanged_ = false; 1359 1360 std::set<WeakPtr<FrameNode>> needRenderNode_; 1361 1362 int32_t callbackId_ = 0; 1363 SurfaceChangedCallbackMap surfaceChangedCallbackMap_; 1364 SurfacePositionChangedCallbackMap surfacePositionChangedCallbackMap_; 1365 FoldStatusChangedCallbackMap foldStatusChangedCallbackMap_; 1366 HalfFoldHoverChangedCallbackMap halfFoldHoverChangedCallbackMap_; 1367 FoldDisplayModeChangedCallbackMap foldDisplayModeChangedCallbackMap_; 1368 TransformHintChangedCallbackMap transformHintChangedCallbackMap_; 1369 1370 bool isOnAreaChangeNodesCacheVaild_ = false; 1371 std::vector<FrameNode*> onAreaChangeNodesCache_; 1372 std::unordered_set<int32_t> onAreaChangeNodeIds_; 1373 std::unordered_set<int32_t> onVisibleAreaChangeNodeIds_; 1374 std::unordered_map<int32_t, std::vector<MouseEvent>> historyMousePointsById_; 1375 std::unordered_map<int32_t, std::vector<DragPointerEvent>> historyPointsEventById_; 1376 RefPtr<AccessibilityManagerNG> accessibilityManagerNG_; 1377 RefPtr<StageManager> stageManager_; 1378 RefPtr<OverlayManager> overlayManager_; 1379 RefPtr<FullScreenManager> fullScreenManager_; 1380 RefPtr<SelectOverlayManager> selectOverlayManager_; 1381 RefPtr<DragDropManager> dragDropManager_; 1382 RefPtr<FocusManager> focusManager_; 1383 RefPtr<SharedOverlayManager> sharedTransitionManager_; 1384 #ifdef WINDOW_SCENE_SUPPORTED 1385 RefPtr<UIExtensionManager> uiExtensionManager_ = MakeRefPtr<UIExtensionManager>(); 1386 #endif 1387 RefPtr<SafeAreaManager> safeAreaManager_ = MakeRefPtr<SafeAreaManager>(); 1388 RefPtr<FrameRateManager> frameRateManager_ = MakeRefPtr<FrameRateManager>(); 1389 RefPtr<PrivacySensitiveManager> privacySensitiveManager_ = MakeRefPtr<PrivacySensitiveManager>(); 1390 Rect displayAvailableRect_; 1391 WeakPtr<FrameNode> dirtyFocusNode_; 1392 WeakPtr<FrameNode> dirtyFocusScope_; 1393 WeakPtr<FrameNode> dirtyRequestFocusNode_; 1394 WeakPtr<FrameNode> screenNode_; 1395 WeakPtr<FrameNode> windowSceneNode_; 1396 uint32_t nextScheduleTaskId_ = 0; 1397 uint64_t resampleTimeStamp_ = 0; 1398 bool touchAccelarate_ = false; 1399 bool isEventsPassThrough_ = false; 1400 uint64_t animationTimeStamp_ = 0; 1401 bool hasIdleTasks_ = false; 1402 bool isFocusingByTab_ = false; 1403 bool isFocusActive_ = false; 1404 bool isWindowHasFocused_ = false; 1405 bool onShow_ = false; 1406 MockFlushEventType isNeedFlushMouseEvent_ = MockFlushEventType::NONE; 1407 bool isNeedFlushAnimationStartTime_ = false; 1408 bool canUseLongPredictTask_ = false; 1409 bool isWindowSceneConsumed_ = false; 1410 bool isDensityChanged_ = false; 1411 bool isNeedReloadDensity_ = false; 1412 bool isBeforeDragHandleAxis_ = false; 1413 WeakPtr<FrameNode> activeNode_; 1414 bool isWindowAnimation_ = false; 1415 bool isWindowSizeDragging_ = false; 1416 KeyBoardAvoidMode prevKeyboardAvoidMode_ = KeyBoardAvoidMode::OFFSET; 1417 bool isFreezeFlushMessage_ = false; 1418 1419 RefPtr<FrameNode> focusNode_; 1420 std::function<void()> focusOnNodeCallback_; 1421 std::function<void(bool isRotate, 1422 const std::shared_ptr<Rosen::RSTransaction>& rsTransaction)> sizeChangeByRotateCallback_; 1423 std::function<void(const std::string&)> linkJumpCallback_ = nullptr; 1424 std::function<void()> dragWindowVisibleCallback_; 1425 1426 std::optional<bool> needSoftKeyboard_; 1427 std::optional<bool> windowFocus_; 1428 std::optional<bool> windowShow_; 1429 1430 std::unique_ptr<MouseEvent> lastMouseEvent_; 1431 1432 std::unordered_map<int32_t, WeakPtr<FrameNode>> storeNode_; 1433 std::unordered_map<int32_t, std::string> restoreNodeInfo_; 1434 std::unordered_map<int32_t, std::vector<WeakPtr<UINode>>> pageToNavigationNodes_; 1435 std::unordered_map<int32_t, std::vector<TouchEvent>> historyPointsById_; 1436 1437 std::set<int32_t> positionZNodes_; 1438 1439 std::list<FrameInfo> dumpFrameInfos_; 1440 std::list<std::function<void()>> animationClosuresList_; 1441 1442 std::map<int32_t, std::function<void(bool)>> isFocusActiveUpdateEvents_; 1443 mutable std::mutex navigationMutex_; 1444 std::map<std::string, WeakPtr<FrameNode>> navigationNodes_; 1445 std::list<DelayedTask> delayedTasks_; 1446 RefPtr<PostEventManager> postEventManager_; 1447 1448 std::map<RefPtr<FrameNode>, std::vector<MouseEvent>> nodeToMousePoints_; 1449 std::map<RefPtr<FrameNode>, std::vector<DragPointerEvent>> nodeToPointEvent_; 1450 std::vector<Ace::RectF> overlayNodePositions_; 1451 std::function<void(std::vector<Ace::RectF>)> overlayNodePositionUpdateCallback_; 1452 1453 RefPtr<FrameNode> predictNode_; 1454 1455 VsyncCallbackFun vsyncListener_; 1456 VsyncCallbackFun onceVsyncListener_; 1457 ACE_DISALLOW_COPY_AND_MOVE(PipelineContext); 1458 1459 int32_t preNodeId_ = -1; 1460 1461 RefPtr<AvoidInfoManager> avoidInfoMgr_ = MakeRefPtr<AvoidInfoManager>(); 1462 RefPtr<MemoryManager> memoryMgr_ = MakeRefPtr<MemoryManager>(); 1463 RefPtr<NavigationManager> navigationMgr_ = MakeRefPtr<NavigationManager>(); 1464 RefPtr<FormVisibleManager> formVisibleMgr_ = MakeRefPtr<FormVisibleManager>(); 1465 RefPtr<FormEventManager> formEventMgr_ = MakeRefPtr<FormEventManager>(); 1466 RefPtr<FormGestureManager> formGestureMgr_ = MakeRefPtr<FormGestureManager>(); 1467 std::unique_ptr<RecycleManager> recycleManager_ = std::make_unique<RecycleManager>(); 1468 ColorMode colorMode_ = ColorMode::LIGHT; 1469 std::atomic<int32_t> localColorMode_ = static_cast<int32_t>(ColorMode::COLOR_MODE_UNDEFINED); 1470 std::vector<std::shared_ptr<ITouchEventCallback>> listenerVector_; 1471 bool customTitleSettedShow_ = true; 1472 bool isShowTitle_ = false; 1473 int32_t lastAnimatorExpectedFrameRate_ = -1; 1474 bool isDoKeyboardAvoidAnimate_ = true; 1475 bool isForceSplit_ = false; 1476 std::string homePageConfig_; 1477 1478 std::list<FrameCallbackFuncFromCAPI> frameCallbackFuncsFromCAPI_; 1479 std::list<FrameCallbackFunc> frameCallbackFuncs_; 1480 std::list<FrameCallbackFunc> idleCallbackFuncs_; 1481 uint32_t transform_ = 0; 1482 std::list<WeakPtr<FrameNode>> changeInfoListeners_; 1483 std::list<WeakPtr<FrameNode>> changedNodes_; 1484 bool isHalfFoldHoverStatus_ = false; 1485 CancelableCallback<void()> foldStatusDelayTask_; 1486 bool isFirstRootLayout_ = true; 1487 bool isFirstFlushMessages_ = true; 1488 bool autoFocusInactive_ = true; 1489 AxisEventChecker axisEventChecker_; 1490 std::unordered_set<UINode*> attachedNodeSet_; 1491 std::list<std::function<void()>> afterReloadAnimationTasks_; 1492 Offset lastHostParentOffsetToWindow_ { 0, 0 }; 1493 1494 RefPtr<Kit::UIContextImpl> uiContextImpl_; 1495 std::shared_ptr<UiTranslateManagerImpl> uiTranslateManager_; 1496 friend class ScopedLayout; 1497 friend class FormGestureManager; 1498 }; 1499 1500 /** 1501 * @description: only protect isLayouting_ flag in pipeline and 1502 * the user needs to guarantee that current layout is not nested 1503 */ 1504 class ACE_FORCE_EXPORT ScopedLayout final { 1505 public: 1506 ScopedLayout(PipelineContext* pipeline); 1507 ~ScopedLayout(); 1508 1509 private: 1510 PipelineContext* pipeline_ = nullptr; 1511 bool isLayouting_ = false; 1512 }; 1513 } // namespace OHOS::Ace::NG 1514 1515 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_PIPELINE_NG_CONTEXT_H 1516