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_PIPELINE_PIPELINE_BASE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_PIPELINE_PIPELINE_BASE_H 18 19 #include <atomic> 20 #include <functional> 21 #include <memory> 22 #include <optional> 23 #include <shared_mutex> 24 #include <stack> 25 #include <string> 26 #include <unordered_map> 27 #include <utility> 28 29 #include "base/geometry/dimension.h" 30 #include "base/resource/asset_manager.h" 31 #include "base/resource/data_provider_manager.h" 32 #include "base/resource/shared_image_manager.h" 33 #include "base/thread/task_executor.h" 34 #include "core/accessibility/accessibility_manager.h" 35 #include "core/animation/schedule_task.h" 36 #include "core/common/clipboard/clipboard_proxy.h" 37 #include "core/common/display_info.h" 38 #include "core/common/draw_delegate.h" 39 #include "core/common/event_manager.h" 40 #include "core/common/platform_bridge.h" 41 #include "core/common/platform_res_register.h" 42 #include "core/common/resource/resource_configuration.h" 43 #include "core/common/thp_extra_manager.h" 44 #include "core/common/thread_checker.h" 45 #include "core/common/window_animation_config.h" 46 #include "core/components/common/layout/constants.h" 47 #include "core/components/common/properties/animation_option.h" 48 #include "core/components/theme/theme_manager.h" 49 #include "core/components_ng/pattern/ui_extension/ui_extension_config.h" 50 #include "core/components_ng/property/safe_area_insets.h" 51 #include "core/event/axis_event.h" 52 #include "core/event/key_event.h" 53 #include "core/event/mouse_event.h" 54 #include "core/event/rotation_event.h" 55 #include "core/event/touch_event.h" 56 #include "core/event/pointer_event.h" 57 #include "core/gestures/gesture_info.h" 58 #include "core/image/image_cache.h" 59 #include "core/pipeline/container_window_manager.h" 60 #include "core/components_ng/manager/display_sync/ui_display_sync_manager.h" 61 #include "interfaces/inner_api/ace/serialized_gesture.h" 62 63 namespace OHOS::Rosen { 64 class RSTransaction; 65 class AvoidArea; 66 } // namespace OHOS::Rosen 67 68 namespace OHOS::Ace { 69 namespace NG { 70 class FrameNode; 71 } // namespace NG 72 73 struct KeyboardAnimationCurve { 74 std::string curveType_; 75 std::vector<float> curveParams_; 76 uint32_t duration_ = 0; 77 }; 78 79 struct KeyboardAnimationConfig { 80 KeyboardAnimationCurve curveIn_; 81 KeyboardAnimationCurve curveOut_; 82 }; 83 84 struct FontInfo; 85 struct FontConfigJsonInfo; 86 class Frontend; 87 class OffscreenCanvas; 88 class Window; 89 class FontManager; 90 class ManagerInterface; 91 class NavigationController; 92 enum class FrontendType; 93 enum class KeyboardAction { 94 NONE, 95 CLOSING, 96 OPENING, 97 }; 98 using SharePanelCallback = std::function<void(const std::string& bundleName, const std::string& abilityName)>; 99 using AceVsyncCallback = std::function<void(uint64_t, uint32_t)>; 100 using EtsCardTouchEventCallback = std::function<void(const TouchEvent&, 101 SerializedGesture& serializedGesture)>; 102 103 class ACE_FORCE_EXPORT PipelineBase : public AceType { 104 DECLARE_ACE_TYPE(PipelineBase, AceType); 105 106 public: 107 PipelineBase() = default; 108 PipelineBase(std::shared_ptr<Window> window, RefPtr<TaskExecutor> taskExecutor, RefPtr<AssetManager> assetManager, 109 const RefPtr<Frontend>& frontend, int32_t instanceId); 110 PipelineBase(std::shared_ptr<Window> window, RefPtr<TaskExecutor> taskExecutor, RefPtr<AssetManager> assetManager, 111 const RefPtr<Frontend>& frontend, int32_t instanceId, RefPtr<PlatformResRegister> platformResRegister); 112 ~PipelineBase() override; 113 114 static RefPtr<PipelineBase> GetCurrentContext(); 115 116 static RefPtr<PipelineBase> GetCurrentContextSafely(); 117 118 static RefPtr<PipelineBase> GetCurrentContextSafelyWithCheck(); 119 120 static RefPtr<PipelineBase> GetMainPipelineContext(); 121 122 static RefPtr<ThemeManager> CurrentThemeManager(); 123 124 static void SetCallBackNode(const WeakPtr<NG::FrameNode>& node); 125 126 /* 127 * Change px to vp with density of current pipeline 128 */ 129 static double Px2VpWithCurrentDensity(double px); 130 131 /* 132 * Change vp to px with density of current pipeline 133 */ 134 static double Vp2PxWithCurrentDensity(double vp); 135 136 /* 137 * Get density of current pipeline if valid, or return density of default display 138 */ 139 static double GetCurrentDensity(); 140 141 virtual void SetupRootElement() = 0; 142 143 virtual uint64_t GetTimeFromExternalTimer(); 144 145 virtual bool NeedSoftKeyboard() = 0; 146 147 virtual void SetOnWindowFocused(const std::function<void()>& callback) = 0; 148 149 bool Animate(const AnimationOption& option, const RefPtr<Curve>& curve, 150 const std::function<void()>& propertyCallback, const std::function<void()>& finishCallBack = nullptr); 151 152 virtual void AddKeyFrame( 153 float fraction, const RefPtr<Curve>& curve, const std::function<void()>& propertyCallback) = 0; 154 155 virtual void AddKeyFrame(float fraction, const std::function<void()>& propertyCallback) = 0; 156 157 void PrepareOpenImplicitAnimation(); 158 CatchInteractiveAnimations(const std::function<void ()> & animationCallback)159 virtual bool CatchInteractiveAnimations(const std::function<void()>& animationCallback) 160 { 161 return false; 162 } 163 164 void OpenImplicitAnimation(const AnimationOption& option, const RefPtr<Curve>& curve, 165 const std::function<void()>& finishCallback = nullptr); 166 167 void StartImplicitAnimation(const AnimationOption& operation, const RefPtr<Curve>& curve, 168 const std::function<void()>& finishCallback = nullptr); 169 170 void PrepareCloseImplicitAnimation(); 171 172 bool CloseImplicitAnimation(); 173 174 void ForceLayoutForImplicitAnimation(); 175 176 void ForceRenderForImplicitAnimation(); 177 178 // add schedule task and return the unique mark id. 179 virtual uint32_t AddScheduleTask(const RefPtr<ScheduleTask>& task) = 0; 180 181 // remove schedule task by id. 182 virtual void RemoveScheduleTask(uint32_t id) = 0; 183 184 // Called by view when touch event received. 185 virtual void OnTouchEvent(const TouchEvent& point, bool isSubPipe = false, bool isEventsPassThrough = false) = 0; 186 187 // Called by ohos AceContainer when touch event received. 188 virtual void OnTouchEvent(const TouchEvent& point, const RefPtr<NG::FrameNode>& node, bool isSubPipe = false, 189 bool isEventsPassThrough = false) 190 {} 191 OnAccessibilityHoverEvent(const TouchEvent & point,const RefPtr<NG::FrameNode> & node)192 virtual void OnAccessibilityHoverEvent(const TouchEvent& point, const RefPtr<NG::FrameNode>& node) {} 193 OnPenHoverEvent(const TouchEvent & point,const RefPtr<NG::FrameNode> & node)194 virtual void OnPenHoverEvent(const TouchEvent& point, const RefPtr<NG::FrameNode>& node) {} 195 HandlePenHoverOut(const TouchEvent & point)196 virtual void HandlePenHoverOut(const TouchEvent& point) {} 197 198 // Called by container when key event received. 199 // if return false, then this event needs platform to handle it. 200 virtual bool OnNonPointerEvent(const NonPointerEvent& event) = 0; 201 202 // Called by view when mouse event received. 203 virtual void OnMouseEvent(const MouseEvent& event) = 0; 204 205 // Called by ohos AceContainer when mouse event received. OnMouseEvent(const MouseEvent & event,const RefPtr<NG::FrameNode> & node)206 virtual void OnMouseEvent(const MouseEvent& event, const RefPtr<NG::FrameNode>& node) {} 207 208 // Called by view when axis event received. 209 virtual void OnAxisEvent(const AxisEvent& event) = 0; 210 211 // Called by ohos AceContainer when axis event received. OnAxisEvent(const AxisEvent & event,const RefPtr<NG::FrameNode> & node)212 virtual void OnAxisEvent(const AxisEvent& event, const RefPtr<NG::FrameNode>& node) {} 213 214 // Called by container when rotation event received. 215 // if return false, then this event needs platform to handle it. 216 virtual bool OnRotationEvent(const RotationEvent& event) const = 0; 217 218 // Called by window when received vsync signal. 219 virtual void OnVsyncEvent(uint64_t nanoTimestamp, uint32_t frameCount); 220 221 // Called by viewr 222 virtual void OnDragEvent(const DragPointerEvent& pointerEvent, DragEventAction action, 223 const RefPtr<NG::FrameNode>& node = nullptr) = 0; 224 225 // Called by view when idle event. 226 virtual void OnIdle(int64_t deadline) = 0; 227 228 virtual void SetBuildAfterCallback(const std::function<void()>& callback) = 0; 229 230 virtual void DispatchDisplaySync(uint64_t nanoTimestamp) = 0; 231 232 virtual void FlushAnimation(uint64_t nanoTimestamp) = 0; 233 234 virtual void SendEventToAccessibility(const AccessibilityEvent& accessibilityEvent); 235 236 virtual void SaveExplicitAnimationOption(const AnimationOption& option) = 0; 237 238 virtual void CreateExplicitAnimator(const std::function<void()>& onFinishEvent) = 0; 239 240 virtual void ClearExplicitAnimationOption() = 0; 241 242 virtual AnimationOption GetExplicitAnimationOption() const = 0; 243 244 virtual void Destroy(); 245 246 virtual void OnShow() = 0; 247 248 virtual void OnHide() = 0; 249 250 virtual void WindowFocus(bool isFocus) = 0; 251 252 virtual void ContainerModalUnFocus() = 0; 253 254 virtual void ShowContainerTitle(bool isShow, bool hasDeco = true, bool needUpdate = false) = 0; 255 256 virtual void OnSurfaceChanged(int32_t width, int32_t height, 257 WindowSizeChangeReason type = WindowSizeChangeReason::UNDEFINED, 258 const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr) = 0; 259 260 virtual void OnSurfacePositionChanged(int32_t posX, int32_t posY) = 0; 261 OnSurfaceDensityChanged(double density)262 virtual void OnSurfaceDensityChanged(double density) 263 { 264 // To avoid the race condition caused by the offscreen canvas get density from the pipeline in the worker 265 // thread. 266 std::lock_guard lock(densityChangeMutex_); 267 for (auto&& [id, callback] : densityChangedCallbacks_) { 268 if (callback) { 269 callback(density); 270 } 271 } 272 } 273 SendUpdateVirtualNodeFocusEvent()274 void SendUpdateVirtualNodeFocusEvent() 275 { 276 auto accessibilityManager = GetAccessibilityManager(); 277 CHECK_NULL_VOID(accessibilityManager); 278 accessibilityManager->UpdateVirtualNodeFocus(); 279 } 280 RegisterWindowDensityCallback(std::function<double ()> && callback)281 void RegisterWindowDensityCallback(std::function<double()>&& callback) 282 { 283 windowDensityCallback_ = callback; 284 } 285 GetWindowDensity()286 double GetWindowDensity() const 287 { 288 if (windowDensityCallback_) { 289 return windowDensityCallback_(); 290 } 291 return 1.0; 292 } 293 RegisterDensityChangedCallback(std::function<void (double)> && callback)294 int32_t RegisterDensityChangedCallback(std::function<void(double)>&& callback) 295 { 296 if (callback) { 297 // To avoid the race condition caused by the offscreen canvas get density from the pipeline in the worker 298 // thread. 299 std::lock_guard lock(densityChangeMutex_); 300 densityChangedCallbacks_.emplace(++densityChangeCallbackId_, std::move(callback)); 301 return densityChangeCallbackId_; 302 } 303 return 0; 304 } 305 UnregisterDensityChangedCallback(int32_t callbackId)306 void UnregisterDensityChangedCallback(int32_t callbackId) 307 { 308 // To avoid the race condition caused by the offscreen canvas get density from the pipeline in the worker 309 // thread. 310 std::lock_guard lock(densityChangeMutex_); 311 densityChangedCallbacks_.erase(callbackId); 312 } 313 314 virtual void OnTransformHintChanged(uint32_t transform) = 0; 315 316 virtual void OnSystemBarHeightChanged(double statusBar, double navigationBar) = 0; 317 318 virtual void OnSurfaceDestroyed() = 0; 319 320 virtual void NotifyOnPreDraw() = 0; 321 322 virtual bool CallRouterBackToPopPage() = 0; 323 PopPageStackOverlay()324 virtual bool PopPageStackOverlay() 325 { 326 return false; 327 } 328 HideOverlays()329 virtual void HideOverlays() {} 330 OnPageShow()331 virtual void OnPageShow() {} 332 333 virtual void OnActionEvent(const std::string& action); 334 335 virtual void Finish(bool autoFinish = true) const {} 336 RequestFullWindow(int32_t duration)337 virtual void RequestFullWindow(int32_t duration) {} 338 339 virtual bool RequestFocus(const std::string& targetNodeId, bool isSyncRequest = false) 340 { 341 return false; 342 } 343 344 // Called by AceContainer. 345 bool Dump(const std::vector<std::string>& params) const; 346 DumpUIExt()347 virtual void DumpUIExt() const {} 348 IsLastPage()349 virtual bool IsLastPage() 350 { 351 return false; 352 } 353 GetIsDeclarative()354 virtual bool GetIsDeclarative() const 355 { 356 return true; 357 } 358 SetAppBgColor(const Color & color)359 virtual void SetAppBgColor(const Color& color) 360 { 361 appBgColor_ = color; 362 } 363 ChangeDarkModeBrightness()364 virtual void ChangeDarkModeBrightness() {} 365 SetFormRenderingMode(int8_t renderMode)366 void SetFormRenderingMode(int8_t renderMode) 367 { 368 renderingMode_ = renderMode; 369 } 370 GetAppBgColor()371 const Color& GetAppBgColor() const 372 { 373 return appBgColor_; 374 } 375 GetAppLabelId()376 int32_t GetAppLabelId() const 377 { 378 return appLabelId_; 379 } 380 SetAppLabelId(int32_t appLabelId)381 void SetAppLabelId(int32_t appLabelId) 382 { 383 appLabelId_ = appLabelId; 384 } 385 386 virtual void SetAppTitle(const std::string& title) = 0; 387 388 virtual void SetAppIcon(const RefPtr<PixelMap>& icon) = 0; 389 SetContainerButtonHide(bool hideSplit,bool hideMaximize,bool hideMinimize,bool hideClose)390 virtual void SetContainerButtonHide(bool hideSplit, bool hideMaximize, bool hideMinimize, bool hideClose) {} 391 EnableContainerModalGesture(bool isEnable)392 virtual void EnableContainerModalGesture(bool isEnable) {} 393 GetContainerFloatingTitleVisible()394 virtual bool GetContainerFloatingTitleVisible() 395 { 396 return false; 397 } 398 GetContainerCustomTitleVisible()399 virtual bool GetContainerCustomTitleVisible() 400 { 401 return false; 402 } 403 GetContainerControlButtonVisible()404 virtual bool GetContainerControlButtonVisible() 405 { 406 return false; 407 } 408 RefreshRootBgColor()409 virtual void RefreshRootBgColor() const {} 410 PostponePageTransition()411 virtual void PostponePageTransition() {} LaunchPageTransition()412 virtual void LaunchPageTransition() {} 413 GetBoundingRectData(int32_t nodeId,Rect & rect)414 virtual void GetBoundingRectData(int32_t nodeId, Rect& rect) {} 415 CheckAndUpdateKeyboardInset(float keyboardHeight)416 virtual void CheckAndUpdateKeyboardInset(float keyboardHeight) {} 417 418 virtual RefPtr<AccessibilityManager> GetAccessibilityManager() const; 419 GetNavigationController(const std::string & id)420 virtual std::shared_ptr<NavigationController> GetNavigationController(const std::string& id) 421 { 422 return nullptr; 423 } 424 425 void SetRootSize(double density, float width, float height); 426 427 void UpdateFontWeightScale(); 428 SetFollowSystem(bool followSystem)429 void SetFollowSystem(bool followSystem) 430 { 431 followSystem_ = followSystem; 432 } 433 SetMaxAppFontScale(float maxAppFontScale)434 void SetMaxAppFontScale(float maxAppFontScale) 435 { 436 maxAppFontScale_ = maxAppFontScale; 437 } 438 GetMaxAppFontScale()439 float GetMaxAppFontScale() 440 { 441 return maxAppFontScale_; 442 } 443 IsFollowSystem()444 bool IsFollowSystem() 445 { 446 return followSystem_; 447 } 448 449 double NormalizeToPx(const Dimension& dimension) const; 450 451 double ConvertPxToVp(const Dimension& dimension) const; 452 453 using FinishEventHandler = std::function<void()>; SetFinishEventHandler(FinishEventHandler && listener)454 void SetFinishEventHandler(FinishEventHandler&& listener) 455 { 456 finishEventHandler_ = std::move(listener); 457 } 458 459 using StartAbilityHandler = std::function<void(const std::string& address)>; SetStartAbilityHandler(StartAbilityHandler && listener)460 void SetStartAbilityHandler(StartAbilityHandler&& listener) 461 { 462 startAbilityHandler_ = std::move(listener); 463 } 464 void HyperlinkStartAbility(const std::string& address) const; 465 466 using ActionEventHandler = std::function<void(const std::string& action)>; SetActionEventHandler(ActionEventHandler && listener)467 void SetActionEventHandler(ActionEventHandler&& listener) 468 { 469 actionEventHandler_ = std::move(listener); 470 } 471 472 using FormLinkInfoUpdateHandler = std::function<void(const std::vector<std::string>&)>; SetFormLinkInfoUpdateHandler(FormLinkInfoUpdateHandler && listener)473 void SetFormLinkInfoUpdateHandler(FormLinkInfoUpdateHandler&& listener) 474 { 475 formLinkInfoUpdateHandler_ = std::move(listener); 476 } 477 478 using StatusBarEventHandler = std::function<void(const Color& color)>; SetStatusBarEventHandler(StatusBarEventHandler && listener)479 void SetStatusBarEventHandler(StatusBarEventHandler&& listener) 480 { 481 statusBarBgColorEventHandler_ = std::move(listener); 482 } 483 void NotifyStatusBarBgColor(const Color& color) const; 484 485 using PopupEventHandler = std::function<void()>; SetPopupEventHandler(PopupEventHandler && listener)486 void SetPopupEventHandler(PopupEventHandler&& listener) 487 { 488 popupEventHandler_ = std::move(listener); 489 } 490 void NotifyPopupDismiss() const; 491 492 using MenuEventHandler = std::function<void()>; SetMenuEventHandler(MenuEventHandler && listener)493 void SetMenuEventHandler(MenuEventHandler&& listener) 494 { 495 menuEventHandler_ = std::move(listener); 496 } 497 void NotifyMenuDismiss() const; 498 499 using ContextMenuEventHandler = std::function<void()>; SetContextMenuEventHandler(ContextMenuEventHandler && listener)500 void SetContextMenuEventHandler(ContextMenuEventHandler&& listener) 501 { 502 contextMenuEventHandler_ = std::move(listener); 503 } 504 void NotifyContextMenuDismiss() const; 505 506 using RouterBackEventHandler = std::function<void()>; SetRouterBackEventHandler(RouterBackEventHandler && listener)507 void SetRouterBackEventHandler(RouterBackEventHandler&& listener) 508 { 509 routerBackEventHandler_ = std::move(listener); 510 } 511 void NotifyRouterBackDismiss() const; 512 513 using PopPageSuccessEventHandler = std::function<void(const std::string& pageUrl, const int32_t pageId)>; SetPopPageSuccessEventHandler(PopPageSuccessEventHandler && listener)514 void SetPopPageSuccessEventHandler(PopPageSuccessEventHandler&& listener) 515 { 516 popPageSuccessEventHandler_.push_back(std::move(listener)); 517 } 518 void NotifyPopPageSuccessDismiss(const std::string& pageUrl, int32_t pageId) const; 519 520 using IsPagePathInvalidEventHandler = std::function<void(bool& isPageInvalid)>; SetIsPagePathInvalidEventHandler(IsPagePathInvalidEventHandler && listener)521 void SetIsPagePathInvalidEventHandler(IsPagePathInvalidEventHandler&& listener) 522 { 523 isPagePathInvalidEventHandler_.push_back(std::move(listener)); 524 } 525 void NotifyIsPagePathInvalidDismiss(bool isPageInvalid) const; 526 527 using DestroyEventHandler = std::function<void()>; SetDestroyHandler(DestroyEventHandler && listener)528 void SetDestroyHandler(DestroyEventHandler&& listener) 529 { 530 destroyEventHandler_.push_back(std::move(listener)); 531 } 532 void NotifyDestroyEventDismiss() const; 533 534 using DispatchTouchEventHandler = std::function<void(const TouchEvent& event)>; SetDispatchTouchEventHandler(DispatchTouchEventHandler && listener)535 void SetDispatchTouchEventHandler(DispatchTouchEventHandler&& listener) 536 { 537 dispatchTouchEventHandler_.push_back(std::move(listener)); 538 } 539 void NotifyDispatchTouchEventDismiss(const TouchEvent& event) const; 540 541 using GetViewScaleCallback = std::function<bool(float&, float&)>; SetGetViewScaleCallback(GetViewScaleCallback && callback)542 void SetGetViewScaleCallback(GetViewScaleCallback&& callback) 543 { 544 getViewScaleCallback_ = callback; 545 } 546 547 using OnPageShowCallBack = std::function<void()>; SetOnPageShow(OnPageShowCallBack && onPageShowCallBack)548 void SetOnPageShow(OnPageShowCallBack&& onPageShowCallBack) 549 { 550 onPageShowCallBack_ = std::move(onPageShowCallBack); 551 } 552 553 using AnimationCallback = std::function<void()>; SetAnimationCallback(AnimationCallback && callback)554 void SetAnimationCallback(AnimationCallback&& callback) 555 { 556 animationCallback_ = std::move(callback); 557 } 558 559 using ProfilerCallback = std::function<void(const std::string&)>; SetOnVsyncProfiler(const ProfilerCallback & callback)560 void SetOnVsyncProfiler(const ProfilerCallback& callback) 561 { 562 onVsyncProfiler_ = callback; 563 } 564 565 using OnRouterChangeCallback = bool (*)(const std::string currentRouterPath); AddRouterChangeCallback(const OnRouterChangeCallback & onRouterChangeCallback)566 void AddRouterChangeCallback(const OnRouterChangeCallback& onRouterChangeCallback) 567 { 568 onRouterChangeCallback_ = onRouterChangeCallback; 569 } 570 571 void onRouterChange(const std::string& url); 572 ResetOnVsyncProfiler()573 void ResetOnVsyncProfiler() 574 { 575 onVsyncProfiler_ = nullptr; 576 } 577 GetViewScale(float & scaleX,float & scaleY)578 bool GetViewScale(float& scaleX, float& scaleY) 579 { 580 if (getViewScaleCallback_) { 581 return getViewScaleCallback_(scaleX, scaleY); 582 } 583 return false; 584 } 585 GetTaskExecutor()586 RefPtr<TaskExecutor> GetTaskExecutor() const 587 { 588 return taskExecutor_; 589 } 590 591 RefPtr<Frontend> GetFrontend() const; 592 GetInstanceId()593 int32_t GetInstanceId() const 594 { 595 return instanceId_; 596 } 597 598 void ClearImageCache(); 599 600 void SetImageCache(const RefPtr<ImageCache>& imageChache); 601 602 RefPtr<ImageCache> GetImageCache() const; 603 GetOrCreateSharedImageManager()604 const RefPtr<SharedImageManager>& GetOrCreateSharedImageManager() 605 { 606 std::scoped_lock<std::shared_mutex> lock(imageMtx_); 607 if (!sharedImageManager_) { 608 sharedImageManager_ = MakeRefPtr<SharedImageManager>(taskExecutor_); 609 } 610 return sharedImageManager_; 611 } 612 GetOrCreateUIDisplaySyncManager()613 const RefPtr<UIDisplaySyncManager>& GetOrCreateUIDisplaySyncManager() 614 { 615 std::call_once(displaySyncFlag_, [this]() { 616 if (!uiDisplaySyncManager_) { 617 uiDisplaySyncManager_ = MakeRefPtr<UIDisplaySyncManager>(); 618 } 619 }); 620 return uiDisplaySyncManager_; 621 } 622 GetWindow()623 Window* GetWindow() 624 { 625 return window_.get(); 626 } 627 GetAssetManager()628 RefPtr<AssetManager> GetAssetManager() const 629 { 630 return assetManager_; 631 } 632 GetMinPlatformVersion()633 int32_t GetMinPlatformVersion() const 634 { 635 // Since API10, the platform version data format has changed. 636 // Use the last three digits of data as platform version. For example (4000000010). 637 return minPlatformVersion_ % 1000; 638 } 639 SetMinPlatformVersion(int32_t minPlatformVersion)640 void SetMinPlatformVersion(int32_t minPlatformVersion) 641 { 642 minPlatformVersion_ = minPlatformVersion; 643 } 644 SetInstallationFree(int32_t installationFree)645 void SetInstallationFree(int32_t installationFree) 646 { 647 installationFree_ = installationFree; 648 } 649 GetInstallationFree()650 bool GetInstallationFree() const 651 { 652 return installationFree_; 653 } 654 SetSharePanelCallback(SharePanelCallback && callback)655 void SetSharePanelCallback(SharePanelCallback&& callback) 656 { 657 sharePanelCallback_ = std::move(callback); 658 } 659 FireSharePanelCallback(const std::string & bundleName,const std::string & abilityName)660 void FireSharePanelCallback(const std::string& bundleName, const std::string& abilityName) 661 { 662 if (sharePanelCallback_) { 663 sharePanelCallback_(bundleName, abilityName); 664 } 665 } 666 GetThemeManager()667 RefPtr<ThemeManager> GetThemeManager() const 668 { 669 std::shared_lock<std::shared_mutex> lock(themeMtx_); 670 return themeManager_; 671 } 672 SetThemeManager(RefPtr<ThemeManager> theme)673 void SetThemeManager(RefPtr<ThemeManager> theme) 674 { 675 CHECK_RUN_ON(UI); 676 std::unique_lock<std::shared_mutex> lock(themeMtx_); 677 themeManager_ = std::move(theme); 678 } 679 680 template<typename T> GetTheme()681 RefPtr<T> GetTheme() const 682 { 683 std::shared_lock<std::shared_mutex> lock(themeMtx_); 684 if (themeManager_) { 685 return themeManager_->GetTheme<T>(); 686 } 687 return {}; 688 } 689 690 template<typename T> GetDraggable()691 bool GetDraggable() 692 { 693 if (isJsCard_ || isFormRender_) { 694 return false; 695 } 696 auto theme = GetTheme<T>(); 697 CHECK_NULL_RETURN(theme, false); 698 return theme->GetDraggable(); 699 } 700 GetTextFieldManager()701 const RefPtr<ManagerInterface>& GetTextFieldManager() 702 { 703 return textFieldManager_; 704 } 705 void SetTextFieldManager(const RefPtr<ManagerInterface>& manager); 706 GetFontManager()707 const RefPtr<FontManager>& GetFontManager() const 708 { 709 return fontManager_; 710 } 711 GetDataProviderManager()712 const RefPtr<DataProviderManagerInterface>& GetDataProviderManager() const 713 { 714 return dataProviderManager_; 715 } SetDataProviderManager(const RefPtr<DataProviderManagerInterface> & dataProviderManager)716 void SetDataProviderManager(const RefPtr<DataProviderManagerInterface>& dataProviderManager) 717 { 718 dataProviderManager_ = dataProviderManager; 719 } 720 GetMessageBridge()721 const RefPtr<PlatformBridge>& GetMessageBridge() const 722 { 723 return messageBridge_; 724 } SetMessageBridge(const RefPtr<PlatformBridge> & messageBridge)725 void SetMessageBridge(const RefPtr<PlatformBridge>& messageBridge) 726 { 727 messageBridge_ = messageBridge; 728 } 729 SetIsJsCard(bool isJsCard)730 void SetIsJsCard(bool isJsCard) 731 { 732 isJsCard_ = isJsCard; 733 } 734 SetIsJsPlugin(bool isJsPlugin)735 void SetIsJsPlugin(bool isJsPlugin) 736 { 737 isJsPlugin_ = isJsPlugin; 738 } 739 SetDrawDelegate(std::unique_ptr<DrawDelegate> delegate)740 void SetDrawDelegate(std::unique_ptr<DrawDelegate> delegate) 741 { 742 drawDelegate_ = std::move(delegate); 743 } 744 IsJsCard()745 bool IsJsCard() const 746 { 747 return isJsCard_; 748 } 749 IsJsPlugin()750 bool IsJsPlugin() const 751 { 752 return isJsPlugin_; 753 } 754 SetIsFormRender(bool isEtsCard)755 void SetIsFormRender(bool isEtsCard) 756 { 757 isFormRender_ = isEtsCard; 758 } 759 IsFormRender()760 bool IsFormRender() const 761 { 762 return isFormRender_; 763 } 764 SetIsDynamicRender(bool isDynamicRender)765 void SetIsDynamicRender(bool isDynamicRender) 766 { 767 isDynamicRender_ = isDynamicRender; 768 } 769 IsDynamicRender()770 bool IsDynamicRender() const 771 { 772 return isDynamicRender_; 773 } 774 775 // Get the dp scale which used to covert dp to logic px. GetDipScale()776 double GetDipScale() const 777 { 778 return dipScale_; 779 } 780 781 // Get the window design scale used to covert lpx to logic px. GetLogicScale()782 double GetLogicScale() const 783 { 784 return designWidthScale_; 785 } 786 GetFontScale()787 float GetFontScale() const 788 { 789 return fontScale_; 790 } 791 void SetFontScale(float fontScale); 792 GetFontWeightScale()793 float GetFontWeightScale() const 794 { 795 return fontWeightScale_; 796 } 797 void SetFontWeightScale(float fontWeightScale); 798 GetWindowId()799 uint32_t GetWindowId() const 800 { 801 return windowId_; 802 } 803 SetWindowId(uint32_t windowId)804 void SetWindowId(uint32_t windowId) 805 { 806 windowId_ = windowId; 807 } 808 809 bool NeedTouchInterpolation(); 810 SetFocusWindowId(uint32_t windowId)811 void SetFocusWindowId(uint32_t windowId) 812 { 813 focusWindowId_ = windowId; 814 } 815 GetFocusWindowId()816 uint32_t GetFocusWindowId() const 817 { 818 return focusWindowId_.value_or(windowId_); 819 } 820 IsFocusWindowIdSetted()821 bool IsFocusWindowIdSetted() const 822 { 823 return focusWindowId_.has_value(); 824 } 825 SetRealHostWindowId(uint32_t realHostWindowId)826 void SetRealHostWindowId(uint32_t realHostWindowId) 827 { 828 realHostWindowId_ = realHostWindowId; 829 } 830 GetRealHostWindowId()831 uint32_t GetRealHostWindowId() const 832 { 833 return realHostWindowId_.value_or(GetFocusWindowId()); 834 } 835 IsRealHostWindowIdSetted()836 bool IsRealHostWindowIdSetted() const 837 { 838 return realHostWindowId_.has_value(); 839 } 840 GetViewScale()841 float GetViewScale() const 842 { 843 return viewScale_; 844 } 845 GetRootWidth()846 double GetRootWidth() const 847 { 848 return rootWidth_; 849 } 850 GetRootHeight()851 double GetRootHeight() const 852 { 853 return rootHeight_; 854 } 855 SetWindowModal(WindowModal modal)856 void SetWindowModal(WindowModal modal) 857 { 858 windowModal_ = modal; 859 } 860 GetWindowModal()861 WindowModal GetWindowModal() const 862 { 863 return windowModal_; 864 } 865 IsFullScreenModal()866 bool IsFullScreenModal() const 867 { 868 return windowModal_ == WindowModal::NORMAL || windowModal_ == WindowModal::SEMI_MODAL_FULL_SCREEN || 869 windowModal_ == WindowModal::CONTAINER_MODAL || isFullWindow_; 870 } 871 SetIsRightToLeft(bool isRightToLeft)872 void SetIsRightToLeft(bool isRightToLeft) 873 { 874 isRightToLeft_ = isRightToLeft; 875 } 876 IsRightToLeft()877 bool IsRightToLeft() const 878 { 879 return isRightToLeft_; 880 } 881 SetEventManager(const RefPtr<EventManager> & eventManager)882 void SetEventManager(const RefPtr<EventManager>& eventManager) 883 { 884 eventManager_ = eventManager; 885 } 886 GetEventManager()887 RefPtr<EventManager> GetEventManager() const 888 { 889 return eventManager_; 890 } 891 GetWindowManager()892 const RefPtr<WindowManager>& GetWindowManager() const 893 { 894 return windowManager_; 895 } 896 897 bool HasFloatTitle() const; 898 IsRebuildFinished()899 bool IsRebuildFinished() const 900 { 901 return isRebuildFinished_; 902 } 903 904 void RequestFrame(); 905 906 void RegisterFont(const std::string& familyName, const std::string& familySrc, const std::string& bundleName = "", 907 const std::string& moduleName = ""); 908 909 void GetSystemFontList(std::vector<std::string>& fontList); 910 911 bool GetSystemFont(const std::string& fontName, FontInfo& fontInfo); 912 913 void GetUIFontConfig(FontConfigJsonInfo& fontConfigJsonInfo); 914 915 void TryLoadImageInfo(const std::string& src, std::function<void(bool, int32_t, int32_t)>&& loadCallback); 916 917 RefPtr<OffscreenCanvas> CreateOffscreenCanvas(int32_t width, int32_t height); 918 919 void PostAsyncEvent(TaskExecutor::Task&& task, const std::string& name, 920 TaskExecutor::TaskType type = TaskExecutor::TaskType::UI); 921 922 void PostAsyncEvent(const TaskExecutor::Task& task, const std::string& name, 923 TaskExecutor::TaskType type = TaskExecutor::TaskType::UI); 924 925 void PostSyncEvent(const TaskExecutor::Task& task, const std::string& name, 926 TaskExecutor::TaskType type = TaskExecutor::TaskType::UI); 927 928 virtual void FlushReload(const ConfigurationChange& configurationChange, bool fullUpdate = true) {} 929 FlushBuild()930 virtual void FlushBuild() {} 931 FlushReloadTransition()932 virtual void FlushReloadTransition() {} RebuildFontNode()933 virtual void RebuildFontNode() {} GetFrontendType()934 FrontendType GetFrontendType() const 935 { 936 return frontendType_; 937 } 938 GetDensity()939 double GetDensity() const 940 { 941 return density_; 942 } 943 GetPlatformResRegister()944 RefPtr<PlatformResRegister> GetPlatformResRegister() const 945 { 946 return platformResRegister_; 947 } 948 949 void SetTouchPipeline(const WeakPtr<PipelineBase>& context); 950 void RemoveTouchPipeline(const WeakPtr<PipelineBase>& context); 951 952 void OnVirtualKeyboardAreaChange(Rect keyboardArea, 953 const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr, const float safeHeight = 0.0f, 954 bool supportAvoidance = false, bool forceChange = false); 955 void OnVirtualKeyboardAreaChange(Rect keyboardArea, double positionY, double height, 956 const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr, bool forceChange = false); 957 void OnFoldStatusChanged(FoldStatus foldStatus); 958 959 using foldStatusChangedCallback = std::function<bool(FoldStatus)>; SetFoldStatusChangeCallback(foldStatusChangedCallback && listener)960 void SetFoldStatusChangeCallback(foldStatusChangedCallback&& listener) 961 { 962 foldStatusChangedCallback_.emplace_back(std::move(listener)); 963 } 964 965 void OnFoldDisplayModeChanged(FoldDisplayMode foldDisplayMode); 966 967 using virtualKeyBoardCallback = std::function<bool(int32_t, int32_t, double)>; SetVirtualKeyBoardCallback(virtualKeyBoardCallback && listener)968 void SetVirtualKeyBoardCallback(virtualKeyBoardCallback&& listener) 969 { 970 static std::atomic<int32_t> pseudoId(-1); // -1 will not be conflict with real node ids. 971 auto nodeId = pseudoId.fetch_sub(1, std::memory_order_relaxed); 972 virtualKeyBoardCallback_.emplace(std::make_pair(nodeId, std::move(listener))); 973 } SetVirtualKeyBoardCallback(int32_t nodeId,virtualKeyBoardCallback && listener)974 void SetVirtualKeyBoardCallback(int32_t nodeId, virtualKeyBoardCallback&& listener) 975 { 976 virtualKeyBoardCallback_.emplace(std::make_pair(nodeId, std::move(listener))); 977 } RemoveVirtualKeyBoardCallback(int32_t nodeId)978 void RemoveVirtualKeyBoardCallback(int32_t nodeId) 979 { 980 virtualKeyBoardCallback_.erase(nodeId); 981 } NotifyVirtualKeyBoard(int32_t width,int32_t height,double keyboard)982 bool NotifyVirtualKeyBoard(int32_t width, int32_t height, double keyboard) const 983 { 984 bool isConsume = false; 985 for (const auto& [nodeId, iterVirtualKeyBoardCallback] : virtualKeyBoardCallback_) { 986 if (iterVirtualKeyBoardCallback && iterVirtualKeyBoardCallback(width, height, keyboard)) { 987 isConsume = true; 988 } 989 } 990 return isConsume; 991 } 992 993 using configChangedCallback = std::function<void()>; SetConfigChangedCallback(int32_t nodeId,configChangedCallback && listener)994 void SetConfigChangedCallback(int32_t nodeId, configChangedCallback&& listener) 995 { 996 configChangedCallback_.emplace(make_pair(nodeId, std::move(listener))); 997 } RemoveConfigChangedCallback(int32_t nodeId)998 void RemoveConfigChangedCallback(int32_t nodeId) 999 { 1000 configChangedCallback_.erase(nodeId); 1001 } 1002 NotifyConfigurationChange()1003 void NotifyConfigurationChange() 1004 { 1005 for (const auto& [nodeId, callback] : configChangedCallback_) { 1006 if (callback) { 1007 callback(); 1008 } 1009 } 1010 } 1011 1012 using PostRTTaskCallback = std::function<void(std::function<void()>&&)>; SetPostRTTaskCallBack(PostRTTaskCallback && callback)1013 void SetPostRTTaskCallBack(PostRTTaskCallback&& callback) 1014 { 1015 postRTTaskCallback_ = std::move(callback); 1016 } 1017 PostTaskToRT(std::function<void ()> && task)1018 void PostTaskToRT(std::function<void()>&& task) 1019 { 1020 if (postRTTaskCallback_) { 1021 postRTTaskCallback_(std::move(task)); 1022 } 1023 } 1024 1025 void SetGetWindowRectImpl(std::function<Rect()>&& callback); 1026 1027 Rect GetCurrentWindowRect() const; 1028 1029 using SafeAreaInsets = NG::SafeAreaInsets; UpdateSystemSafeArea(const SafeAreaInsets & systemSafeArea)1030 virtual void UpdateSystemSafeArea(const SafeAreaInsets& systemSafeArea) {} 1031 UpdateCutoutSafeArea(const SafeAreaInsets & cutoutSafeArea)1032 virtual void UpdateCutoutSafeArea(const SafeAreaInsets& cutoutSafeArea) {} 1033 UpdateNavSafeArea(const SafeAreaInsets & navSafeArea)1034 virtual void UpdateNavSafeArea(const SafeAreaInsets& navSafeArea) {} 1035 UpdateOriginAvoidArea(const Rosen::AvoidArea & avoidArea,uint32_t type)1036 virtual void UpdateOriginAvoidArea(const Rosen::AvoidArea& avoidArea, uint32_t type) {} 1037 SetEnableKeyBoardAvoidMode(KeyBoardAvoidMode value)1038 virtual void SetEnableKeyBoardAvoidMode(KeyBoardAvoidMode value) {} 1039 GetEnableKeyBoardAvoidMode()1040 virtual KeyBoardAvoidMode GetEnableKeyBoardAvoidMode() { 1041 return KeyBoardAvoidMode::OFFSET; 1042 } 1043 IsEnableKeyBoardAvoidMode()1044 virtual bool IsEnableKeyBoardAvoidMode() { 1045 return false; 1046 } 1047 RequireSummary()1048 virtual void RequireSummary() {} 1049 SetPluginOffset(const Offset & offset)1050 void SetPluginOffset(const Offset& offset) 1051 { 1052 pluginOffset_ = offset; 1053 } 1054 GetPluginOffset()1055 Offset GetPluginOffset() const 1056 { 1057 return pluginOffset_; 1058 } 1059 SetPluginEventOffset(const Offset & offset)1060 void SetPluginEventOffset(const Offset& offset) 1061 { 1062 pluginEventOffset_ = offset; 1063 } 1064 GetPluginEventOffset()1065 Offset GetPluginEventOffset() const 1066 { 1067 return pluginEventOffset_; 1068 } NotifyMemoryLevel(int32_t level)1069 virtual void NotifyMemoryLevel(int32_t level) {} 1070 SetDisplayWindowRectInfo(const Rect & displayWindowRectInfo)1071 void SetDisplayWindowRectInfo(const Rect& displayWindowRectInfo) 1072 { 1073 displayWindowRectInfo_ = displayWindowRectInfo; 1074 } 1075 1076 virtual void SetContainerWindow(bool isShow) = 0; 1077 1078 // This method can get the coordinates and size of the current window, 1079 // which can be added to the return value of the GetGlobalOffset method to get the window coordinates of the node. GetDisplayWindowRectInfo()1080 const Rect& GetDisplayWindowRectInfo() const 1081 { 1082 return displayWindowRectInfo_; 1083 } FlushModifier()1084 virtual void FlushModifier() {} 1085 virtual void FlushMessages() = 0; SetGSVsyncCallback(std::function<void (void)> && callback)1086 void SetGSVsyncCallback(std::function<void(void)>&& callback) 1087 { 1088 gsVsyncCallback_ = std::move(callback); 1089 } 1090 1091 virtual void FlushUITasks(bool triggeredByImplicitAnimation = false) = 0; 1092 FlushAfterLayoutCallbackInImplicitAnimationTask()1093 virtual void FlushAfterLayoutCallbackInImplicitAnimationTask() {} 1094 1095 virtual void FlushPipelineImmediately() = 0; 1096 1097 virtual void FlushOnceVsyncTask() = 0; 1098 1099 // get animateTo closure option GetSyncAnimationOption()1100 AnimationOption GetSyncAnimationOption() 1101 { 1102 return animationOption_; 1103 } 1104 SetSyncAnimationOption(const AnimationOption & option)1105 void SetSyncAnimationOption(const AnimationOption& option) 1106 { 1107 animationOption_ = option; 1108 } 1109 SetKeyboardAnimationConfig(const KeyboardAnimationConfig & config)1110 void SetKeyboardAnimationConfig(const KeyboardAnimationConfig& config) 1111 { 1112 keyboardAnimationConfig_ = config; 1113 } 1114 GetKeyboardAnimationConfig()1115 KeyboardAnimationConfig GetKeyboardAnimationConfig() const 1116 { 1117 return keyboardAnimationConfig_; 1118 } 1119 SetNextFrameLayoutCallback(std::function<void ()> && callback)1120 void SetNextFrameLayoutCallback(std::function<void()>&& callback) 1121 { 1122 nextFrameLayoutCallback_ = std::move(callback); 1123 } 1124 SetForegroundCalled(bool isForegroundCalled)1125 void SetForegroundCalled(bool isForegroundCalled) 1126 { 1127 isForegroundCalled_ = isForegroundCalled; 1128 } 1129 SetIsSubPipeline(bool isSubPipeline)1130 void SetIsSubPipeline(bool isSubPipeline) 1131 { 1132 isSubPipeline_ = isSubPipeline; 1133 } 1134 IsSubPipeline()1135 bool IsSubPipeline() const 1136 { 1137 return isSubPipeline_; 1138 } 1139 SetParentPipeline(const WeakPtr<PipelineBase> & pipeline)1140 void SetParentPipeline(const WeakPtr<PipelineBase>& pipeline) 1141 { 1142 parentPipeline_ = pipeline; 1143 } 1144 1145 void AddEtsCardTouchEventCallback(int32_t ponitId, EtsCardTouchEventCallback&& callback); 1146 1147 void HandleEtsCardTouchEvent(const TouchEvent& point, SerializedGesture &serializedGesture); 1148 1149 void RemoveEtsCardTouchEventCallback(int32_t ponitId); 1150 1151 void SetSubWindowVsyncCallback(AceVsyncCallback&& callback, int32_t subWindowId); 1152 1153 void SetJsFormVsyncCallback(AceVsyncCallback&& callback, int32_t subWindowId); 1154 1155 void RemoveSubWindowVsyncCallback(int32_t subWindowId); 1156 1157 void RemoveJsFormVsyncCallback(int32_t subWindowId); 1158 SetIsLayoutFullScreen(bool isLayoutFullScreen)1159 virtual void SetIsLayoutFullScreen(bool isLayoutFullScreen) {} SetIsNeedAvoidWindow(bool isLayoutFullScreen)1160 virtual void SetIsNeedAvoidWindow(bool isLayoutFullScreen) {} SetIgnoreViewSafeArea(bool ignoreViewSafeArea)1161 virtual void SetIgnoreViewSafeArea(bool ignoreViewSafeArea) {} OnFoldStatusChange(FoldStatus foldStatus)1162 virtual void OnFoldStatusChange(FoldStatus foldStatus) {} OnFoldDisplayModeChange(FoldDisplayMode foldDisplayMode)1163 virtual void OnFoldDisplayModeChange(FoldDisplayMode foldDisplayMode) {} 1164 SetIsAppWindow(bool isAppWindow)1165 void SetIsAppWindow(bool isAppWindow) 1166 { 1167 isAppWindow_ = isAppWindow; 1168 } 1169 GetIsAppWindow()1170 bool GetIsAppWindow() const 1171 { 1172 return isAppWindow_; 1173 } 1174 SetFormAnimationStartTime(int64_t time)1175 void SetFormAnimationStartTime(int64_t time) 1176 { 1177 formAnimationStartTime_ = time; 1178 } 1179 GetFormAnimationStartTime()1180 int64_t GetFormAnimationStartTime() const 1181 { 1182 return formAnimationStartTime_; 1183 } 1184 SetIsFormAnimation(bool isFormAnimation)1185 void SetIsFormAnimation(bool isFormAnimation) 1186 { 1187 isFormAnimation_ = isFormAnimation; 1188 } 1189 IsFormAnimation()1190 bool IsFormAnimation() const 1191 { 1192 return isFormAnimation_; 1193 } 1194 SetFormAnimationFinishCallback(bool isFormAnimationFinishCallback)1195 void SetFormAnimationFinishCallback(bool isFormAnimationFinishCallback) 1196 { 1197 isFormAnimationFinishCallback_ = isFormAnimationFinishCallback; 1198 } 1199 IsFormAnimationFinishCallback()1200 bool IsFormAnimationFinishCallback() const 1201 { 1202 return isFormAnimationFinishCallback_; 1203 } 1204 1205 // restore RestoreNodeInfo(std::unique_ptr<JsonValue> nodeInfo)1206 virtual void RestoreNodeInfo(std::unique_ptr<JsonValue> nodeInfo) {} 1207 GetStoredNodeInfo()1208 virtual std::unique_ptr<JsonValue> GetStoredNodeInfo() 1209 { 1210 return nullptr; 1211 } 1212 GetLastTouchTime()1213 uint64_t GetLastTouchTime() const 1214 { 1215 return lastTouchTime_; 1216 } 1217 AddFormLinkInfo(int32_t id,const std::string & info)1218 void AddFormLinkInfo(int32_t id, const std::string& info) 1219 { 1220 LOGI("AddFormLinkInfo is %{public}s, id is %{public}d", info.c_str(), id); 1221 formLinkInfoMap_[id] = info; 1222 } 1223 IsLayouting()1224 virtual bool IsLayouting() const 1225 { 1226 return false; 1227 } 1228 SetHalfLeading(bool halfLeading)1229 void SetHalfLeading(bool halfLeading) 1230 { 1231 halfLeading_ = halfLeading; 1232 } 1233 GetHalfLeading()1234 bool GetHalfLeading() const 1235 { 1236 return halfLeading_; 1237 } 1238 SetHasPreviewTextOption(bool hasOption)1239 void SetHasPreviewTextOption(bool hasOption) 1240 { 1241 hasPreviewTextOption_ = hasOption; 1242 } 1243 GetHasPreviewTextOption()1244 bool GetHasPreviewTextOption() const 1245 { 1246 return hasPreviewTextOption_; 1247 } 1248 SetSupportPreviewText(bool changeSupported)1249 void SetSupportPreviewText(bool changeSupported) 1250 { 1251 hasSupportedPreviewText_ = !changeSupported; 1252 } 1253 GetSupportPreviewText()1254 bool GetSupportPreviewText() const 1255 { 1256 return hasSupportedPreviewText_; 1257 } 1258 SetUseCutout(bool useCutout)1259 void SetUseCutout(bool useCutout) 1260 { 1261 useCutout_ = useCutout; 1262 } 1263 GetUseCutout()1264 bool GetUseCutout() const 1265 { 1266 return useCutout_; 1267 } 1268 GetOnFoucs()1269 bool GetOnFoucs() const 1270 { 1271 return onFocus_; 1272 } 1273 GetVsyncTime()1274 uint64_t GetVsyncTime() const 1275 { 1276 return vsyncTime_; 1277 } 1278 SetVsyncTime(uint64_t time)1279 void SetVsyncTime(uint64_t time) 1280 { 1281 vsyncTime_ = time; 1282 } 1283 UpdateCurrentActiveNode(const WeakPtr<NG::FrameNode> & node)1284 virtual void UpdateCurrentActiveNode(const WeakPtr<NG::FrameNode>& node) {} 1285 GetCurrentExtraInfo()1286 virtual std::string GetCurrentExtraInfo() { return ""; } 1287 1288 virtual void UpdateTitleInTargetPos(bool isShow = true, int32_t height = 0) {} 1289 SetCursor(int32_t cursorValue)1290 virtual void SetCursor(int32_t cursorValue) {} 1291 1292 virtual void RestoreDefault(int32_t windowId = 0) {} 1293 SetOnFormRecycleCallback(std::function<std::string ()> && onFormRecycle)1294 void SetOnFormRecycleCallback(std::function<std::string()>&& onFormRecycle) 1295 { 1296 onFormRecycle_ = std::move(onFormRecycle); 1297 } 1298 1299 std::string OnFormRecycle(); 1300 SetOnFormRecoverCallback(std::function<void (std::string)> && onFormRecover)1301 void SetOnFormRecoverCallback(std::function<void(std::string)>&& onFormRecover) 1302 { 1303 onFormRecover_ = std::move(onFormRecover); 1304 } 1305 1306 void OnFormRecover(const std::string& statusData); 1307 IsDragging()1308 virtual bool IsDragging() const 1309 { 1310 return false; 1311 } 1312 SetIsDragging(bool isDragging)1313 virtual void SetIsDragging(bool isDragging) {} 1314 ResetDragging()1315 virtual void ResetDragging() {} 1316 GetSerializedGesture()1317 virtual const SerializedGesture& GetSerializedGesture() const 1318 { 1319 return serializedGesture_; 1320 } 1321 PrintVsyncInfoIfNeed()1322 virtual bool PrintVsyncInfoIfNeed() const 1323 { 1324 return false; 1325 } 1326 1327 StartWindowAnimation()1328 virtual void StartWindowAnimation() {} 1329 StopWindowAnimation()1330 virtual void StopWindowAnimation() {} 1331 AddSyncGeometryNodeTask(std::function<void ()> && task)1332 virtual void AddSyncGeometryNodeTask(std::function<void()>&& task) {} 1333 FlushSyncGeometryNodeTasks()1334 virtual void FlushSyncGeometryNodeTasks() {} 1335 ChangeSensitiveNodes(bool flag)1336 virtual void ChangeSensitiveNodes(bool flag) {} 1337 IsContainerModalVisible()1338 virtual bool IsContainerModalVisible() 1339 { 1340 return false; 1341 } 1342 GetFrameCount()1343 uint32_t GetFrameCount() const 1344 { 1345 return frameCount_; 1346 } 1347 GetKeyboardAction()1348 KeyboardAction GetKeyboardAction() 1349 { 1350 return keyboardAction_; 1351 } 1352 SetKeyboardAction(KeyboardAction action)1353 void SetKeyboardAction(KeyboardAction action) 1354 { 1355 keyboardAction_ = action; 1356 } 1357 void SetUiDvsyncSwitch(bool on); 1358 CheckAndLogLastReceivedTouchEventInfo(int32_t eventId,TouchType type)1359 virtual void CheckAndLogLastReceivedTouchEventInfo(int32_t eventId, TouchType type) {} 1360 CheckAndLogLastConsumedTouchEventInfo(int32_t eventId,TouchType type)1361 virtual void CheckAndLogLastConsumedTouchEventInfo(int32_t eventId, TouchType type) {} 1362 CheckAndLogLastReceivedMouseEventInfo(int32_t eventId,MouseAction action)1363 virtual void CheckAndLogLastReceivedMouseEventInfo(int32_t eventId, MouseAction action) {} 1364 CheckAndLogLastConsumedMouseEventInfo(int32_t eventId,MouseAction action)1365 virtual void CheckAndLogLastConsumedMouseEventInfo(int32_t eventId, MouseAction action) {} 1366 CheckAndLogLastReceivedAxisEventInfo(int32_t eventId,AxisAction action)1367 virtual void CheckAndLogLastReceivedAxisEventInfo(int32_t eventId, AxisAction action) {} 1368 CheckAndLogLastConsumedAxisEventInfo(int32_t eventId,AxisAction action)1369 virtual void CheckAndLogLastConsumedAxisEventInfo(int32_t eventId, AxisAction action) {} 1370 GetPageAvoidOffset()1371 virtual float GetPageAvoidOffset() 1372 { 1373 return 0.0f; 1374 } 1375 CheckNeedAvoidInSubWindow()1376 virtual bool CheckNeedAvoidInSubWindow() 1377 { 1378 return false; 1379 } 1380 1381 virtual bool IsDensityChanged() const = 0; 1382 GetResponseRegion(const RefPtr<NG::FrameNode> & rootNode)1383 virtual std::string GetResponseRegion(const RefPtr<NG::FrameNode>& rootNode) 1384 { 1385 return ""; 1386 }; 1387 NotifyResponseRegionChanged(const RefPtr<NG::FrameNode> & rootNode)1388 virtual void NotifyResponseRegionChanged(const RefPtr<NG::FrameNode>& rootNode) {}; 1389 SetTHPExtraManager(const RefPtr<NG::THPExtraManager> & thpExtraMgr)1390 void SetTHPExtraManager(const RefPtr<NG::THPExtraManager>& thpExtraMgr) 1391 { 1392 thpExtraMgr_ = thpExtraMgr; 1393 } 1394 GetTHPExtraManager()1395 const RefPtr<NG::THPExtraManager>& GetTHPExtraManager() const 1396 { 1397 return thpExtraMgr_; 1398 } 1399 1400 virtual bool GetOnShow() const = 0; 1401 bool IsDestroyed(); 1402 1403 void SetDestroyed(); 1404 1405 #if defined(SUPPORT_TOUCH_TARGET_TEST) 1406 // Called by hittest to find touch node is equal target. 1407 virtual bool OnTouchTargetHitTest(const TouchEvent& point, bool isSubPipe = false, 1408 const std::string& target = "") = 0; 1409 #endif IsWindowFocused()1410 virtual bool IsWindowFocused() const 1411 { 1412 return GetOnFoucs(); 1413 } 1414 SetDragNodeGrayscale(float dragNodeGrayscale)1415 void SetDragNodeGrayscale(float dragNodeGrayscale) 1416 { 1417 dragNodeGrayscale_ = dragNodeGrayscale; 1418 } 1419 GetDragNodeGrayscale()1420 float GetDragNodeGrayscale() const 1421 { 1422 return dragNodeGrayscale_; 1423 } 1424 IsDirtyNodesEmpty()1425 virtual bool IsDirtyNodesEmpty() const 1426 { 1427 return true; 1428 } 1429 IsDirtyLayoutNodesEmpty()1430 virtual bool IsDirtyLayoutNodesEmpty() const 1431 { 1432 return true; 1433 } 1434 SetOpenInvisibleFreeze(bool isOpenInvisibleFreeze)1435 void SetOpenInvisibleFreeze(bool isOpenInvisibleFreeze) 1436 { 1437 isOpenInvisibleFreeze_ = isOpenInvisibleFreeze; 1438 } 1439 IsOpenInvisibleFreeze()1440 bool IsOpenInvisibleFreeze() const 1441 { 1442 return isOpenInvisibleFreeze_; 1443 } 1444 SetVisibleAreaRealTime(bool visibleAreaRealTime)1445 void SetVisibleAreaRealTime(bool visibleAreaRealTime) 1446 { 1447 visibleAreaRealTime_ = visibleAreaRealTime; 1448 } 1449 GetVisibleAreaRealTime()1450 bool GetVisibleAreaRealTime() const 1451 { 1452 return visibleAreaRealTime_; 1453 } 1454 1455 void SetAccessibilityEventCallback(std::function<void(uint32_t, int64_t)>&& callback); 1456 1457 void AddAccessibilityCallbackEvent(AccessibilityCallbackEventId event, int64_t parameter); 1458 1459 void FireAccessibilityEvents(); 1460 1461 void SetUIExtensionEventCallback(std::function<void(uint32_t)>&& callback); 1462 void AddUIExtensionCallbackEvent(NG::UIExtCallbackEventId eventId); 1463 void FireAllUIExtensionEvents(); 1464 void FireUIExtensionEventOnceImmediately(NG::UIExtCallbackEventId eventId); 1465 1466 protected: 1467 virtual bool MaybeRelease() override; TryCallNextFrameLayoutCallback()1468 void TryCallNextFrameLayoutCallback() 1469 { 1470 if (isForegroundCalled_ && nextFrameLayoutCallback_) { 1471 isForegroundCalled_ = false; 1472 nextFrameLayoutCallback_(); 1473 LOGI("nextFrameLayoutCallback called"); 1474 } 1475 } 1476 OnDumpInfo(const std::vector<std::string> & params)1477 virtual bool OnDumpInfo(const std::vector<std::string>& params) const 1478 { 1479 return false; 1480 } 1481 virtual void FlushVsync(uint64_t nanoTimestamp, uint32_t frameCount) = 0; 1482 virtual void SetRootRect(double width, double height, double offset = 0.0) = 0; 1483 virtual void FlushPipelineWithoutAnimation() = 0; 1484 1485 virtual void OnVirtualKeyboardHeightChange(float keyboardHeight, 1486 const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr, const float safeHeight = 0.0f, 1487 const bool supportAvoidance = false, bool forceChange = false) 1488 {} 1489 virtual void OnVirtualKeyboardHeightChange(float keyboardHeight, double positionY, double height, 1490 const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr, bool forceChange = false) 1491 {} 1492 1493 void UpdateRootSizeAndScale(int32_t width, int32_t height); 1494 SetIsReloading(bool isReloading)1495 void SetIsReloading(bool isReloading) 1496 { 1497 isReloading_ = isReloading; 1498 } 1499 bool FireUIExtensionEventValid(); 1500 1501 std::function<void()> GetWrappedAnimationCallback(const std::function<void()>& finishCallback); 1502 1503 std::map<int32_t, configChangedCallback> configChangedCallback_; 1504 std::map<int32_t, virtualKeyBoardCallback> virtualKeyBoardCallback_; 1505 std::list<foldStatusChangedCallback> foldStatusChangedCallback_; 1506 1507 bool isRebuildFinished_ = false; 1508 bool isJsCard_ = false; 1509 bool isFormRender_ = false; 1510 bool isDynamicRender_ = false; 1511 bool isRightToLeft_ = false; 1512 bool isFullWindow_ = false; 1513 bool isAppWindow_ = true; 1514 bool installationFree_ = false; 1515 bool isSubPipeline_ = false; 1516 bool isReloading_ = false; 1517 1518 bool isJsPlugin_ = false; 1519 bool isOpenInvisibleFreeze_ = false; 1520 1521 std::unordered_map<int32_t, AceVsyncCallback> subWindowVsyncCallbacks_; 1522 std::unordered_map<int32_t, AceVsyncCallback> jsFormVsyncCallbacks_; 1523 int32_t minPlatformVersion_ = 0; 1524 uint32_t windowId_ = 0; 1525 // UIExtensionAbility need component windowID 1526 std::optional<uint32_t> focusWindowId_; 1527 std::optional<uint32_t> realHostWindowId_; 1528 1529 int32_t appLabelId_ = 0; 1530 float fontScale_ = 1.0f; 1531 float fontWeightScale_ = 1.0f; 1532 float designWidthScale_ = 1.0f; 1533 float viewScale_ = 1.0f; 1534 double density_ = 1.0; 1535 double dipScale_ = 1.0; 1536 double rootHeight_ = 0.0; 1537 double rootWidth_ = 0.0; 1538 int32_t width_ = 0; 1539 int32_t height_ = 0; 1540 FrontendType frontendType_; 1541 WindowModal windowModal_ = WindowModal::NORMAL; 1542 1543 Offset pluginOffset_ { 0, 0 }; 1544 Offset pluginEventOffset_ { 0, 0 }; 1545 Color appBgColor_ = Color::WHITE; 1546 int8_t renderingMode_ = 0; 1547 1548 std::unique_ptr<DrawDelegate> drawDelegate_; 1549 std::stack<bool> pendingImplicitLayout_; 1550 std::stack<bool> pendingImplicitRender_; 1551 std::stack<bool> pendingFrontendAnimation_; 1552 std::shared_ptr<Window> window_; 1553 RefPtr<TaskExecutor> taskExecutor_; 1554 RefPtr<AssetManager> assetManager_; 1555 WeakPtr<Frontend> weakFrontend_; 1556 int32_t instanceId_ = 0; 1557 RefPtr<EventManager> eventManager_; 1558 RefPtr<ImageCache> imageCache_; 1559 RefPtr<SharedImageManager> sharedImageManager_; 1560 mutable std::shared_mutex imageMtx_; 1561 mutable std::shared_mutex themeMtx_; 1562 mutable std::mutex destructMutex_; 1563 RefPtr<ThemeManager> themeManager_; 1564 RefPtr<DataProviderManagerInterface> dataProviderManager_; 1565 RefPtr<FontManager> fontManager_; 1566 RefPtr<ManagerInterface> textFieldManager_; 1567 RefPtr<PlatformBridge> messageBridge_; 1568 RefPtr<WindowManager> windowManager_; 1569 OnPageShowCallBack onPageShowCallBack_; 1570 AnimationCallback animationCallback_; 1571 ProfilerCallback onVsyncProfiler_; 1572 FinishEventHandler finishEventHandler_; 1573 StartAbilityHandler startAbilityHandler_; 1574 ActionEventHandler actionEventHandler_; 1575 FormLinkInfoUpdateHandler formLinkInfoUpdateHandler_; 1576 RefPtr<PlatformResRegister> platformResRegister_; 1577 1578 WeakPtr<PipelineBase> parentPipeline_; 1579 1580 std::vector<WeakPtr<PipelineBase>> touchPluginPipelineContext_; 1581 std::unordered_map<int32_t, EtsCardTouchEventCallback> etsCardTouchEventCallback_; 1582 1583 RefPtr<Clipboard> clipboard_; 1584 std::function<void(const std::string&)> clipboardCallback_ = nullptr; 1585 Rect displayWindowRectInfo_; 1586 AnimationOption animationOption_; 1587 KeyboardAnimationConfig keyboardAnimationConfig_; 1588 1589 std::function<void()> nextFrameLayoutCallback_ = nullptr; 1590 SharePanelCallback sharePanelCallback_ = nullptr; 1591 std::atomic<bool> isForegroundCalled_ = false; 1592 std::atomic<bool> onFocus_ = false; 1593 uint64_t lastTouchTime_ = 0; 1594 std::map<int32_t, std::string> formLinkInfoMap_; 1595 struct FunctionHash { operatorFunctionHash1596 std::size_t operator()(const std::shared_ptr<std::function<void()>>& functionPtr) const 1597 { 1598 return std::hash<std::function<void()>*>()(functionPtr.get()); 1599 } 1600 }; 1601 std::function<std::string()> onFormRecycle_; 1602 std::function<void(std::string)> onFormRecover_; 1603 1604 uint64_t compensationValue_ = 0; 1605 int64_t recvTime_ = 0; 1606 std::once_flag displaySyncFlag_; 1607 RefPtr<UIDisplaySyncManager> uiDisplaySyncManager_; 1608 1609 SerializedGesture serializedGesture_; 1610 RefPtr<NG::THPExtraManager> thpExtraMgr_; 1611 private: 1612 void DumpFrontend() const; 1613 double ModifyKeyboardHeight(double keyboardHeight) const; 1614 void FireUIExtensionEventInner(uint32_t eventId); 1615 StatusBarEventHandler statusBarBgColorEventHandler_; 1616 PopupEventHandler popupEventHandler_; 1617 MenuEventHandler menuEventHandler_; 1618 ContextMenuEventHandler contextMenuEventHandler_; 1619 RouterBackEventHandler routerBackEventHandler_; 1620 std::list<PopPageSuccessEventHandler> popPageSuccessEventHandler_; 1621 std::list<IsPagePathInvalidEventHandler> isPagePathInvalidEventHandler_; 1622 std::list<DestroyEventHandler> destroyEventHandler_; 1623 std::list<DispatchTouchEventHandler> dispatchTouchEventHandler_; 1624 GetViewScaleCallback getViewScaleCallback_; 1625 // OnRouterChangeCallback is function point, need to be initialized. 1626 OnRouterChangeCallback onRouterChangeCallback_ = nullptr; 1627 PostRTTaskCallback postRTTaskCallback_; 1628 std::function<void(void)> gsVsyncCallback_; 1629 std::unordered_set<std::shared_ptr<std::function<void()>>, FunctionHash> finishFunctions_; 1630 bool followSystem_ = false; 1631 float maxAppFontScale_ = static_cast<float>(INT32_MAX); 1632 bool isFormAnimationFinishCallback_ = false; 1633 int64_t formAnimationStartTime_ = 0; 1634 bool isFormAnimation_ = false; 1635 bool halfLeading_ = false; 1636 bool hasSupportedPreviewText_ = true; 1637 bool hasPreviewTextOption_ = false; 1638 bool useCutout_ = false; 1639 // whether visible area need to be calculate at each vsync after approximate timeout. 1640 bool visibleAreaRealTime_ = false; 1641 uint64_t vsyncTime_ = 0; 1642 bool destroyed_ = false; 1643 uint32_t frameCount_ = 0; 1644 KeyboardAction keyboardAction_ = KeyboardAction::NONE; 1645 float dragNodeGrayscale_ = 0.0f; 1646 1647 // To avoid the race condition caused by the offscreen canvas get density from the pipeline in the worker thread. 1648 std::mutex densityChangeMutex_; 1649 int32_t densityChangeCallbackId_ = 0; 1650 std::unordered_map<int32_t, std::function<void(double)>> densityChangedCallbacks_; 1651 std::function<double()> windowDensityCallback_; 1652 std::function<void(uint32_t)> uiExtensionEventCallback_; 1653 std::set<NG::UIExtCallbackEvent> uiExtensionEvents_; 1654 std::function<void(uint32_t, int64_t)> accessibilityCallback_; 1655 std::set<AccessibilityCallbackEvent> accessibilityEvents_; 1656 1657 ACE_DISALLOW_COPY_AND_MOVE(PipelineBase); 1658 }; 1659 1660 } // namespace OHOS::Ace 1661 1662 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_PIPELINE_PIPELINE_BASE_H 1663