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 OnKeyEvent(const KeyEvent& 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 PointerEvent& 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 SetFocusWindowId(uint32_t windowId)809 void SetFocusWindowId(uint32_t windowId) 810 { 811 focusWindowId_ = windowId; 812 } 813 GetFocusWindowId()814 uint32_t GetFocusWindowId() const 815 { 816 return focusWindowId_.value_or(windowId_); 817 } 818 IsFocusWindowIdSetted()819 bool IsFocusWindowIdSetted() const 820 { 821 return focusWindowId_.has_value(); 822 } 823 SetRealHostWindowId(uint32_t realHostWindowId)824 void SetRealHostWindowId(uint32_t realHostWindowId) 825 { 826 realHostWindowId_ = realHostWindowId; 827 } 828 GetRealHostWindowId()829 uint32_t GetRealHostWindowId() const 830 { 831 return realHostWindowId_.value_or(GetFocusWindowId()); 832 } 833 IsRealHostWindowIdSetted()834 bool IsRealHostWindowIdSetted() const 835 { 836 return realHostWindowId_.has_value(); 837 } 838 GetViewScale()839 float GetViewScale() const 840 { 841 return viewScale_; 842 } 843 GetRootWidth()844 double GetRootWidth() const 845 { 846 return rootWidth_; 847 } 848 GetRootHeight()849 double GetRootHeight() const 850 { 851 return rootHeight_; 852 } 853 SetWindowModal(WindowModal modal)854 void SetWindowModal(WindowModal modal) 855 { 856 windowModal_ = modal; 857 } 858 GetWindowModal()859 WindowModal GetWindowModal() const 860 { 861 return windowModal_; 862 } 863 IsFullScreenModal()864 bool IsFullScreenModal() const 865 { 866 return windowModal_ == WindowModal::NORMAL || windowModal_ == WindowModal::SEMI_MODAL_FULL_SCREEN || 867 windowModal_ == WindowModal::CONTAINER_MODAL || isFullWindow_; 868 } 869 SetIsRightToLeft(bool isRightToLeft)870 void SetIsRightToLeft(bool isRightToLeft) 871 { 872 isRightToLeft_ = isRightToLeft; 873 } 874 IsRightToLeft()875 bool IsRightToLeft() const 876 { 877 return isRightToLeft_; 878 } 879 SetEventManager(const RefPtr<EventManager> & eventManager)880 void SetEventManager(const RefPtr<EventManager>& eventManager) 881 { 882 eventManager_ = eventManager; 883 } 884 GetEventManager()885 RefPtr<EventManager> GetEventManager() const 886 { 887 return eventManager_; 888 } 889 GetWindowManager()890 const RefPtr<WindowManager>& GetWindowManager() const 891 { 892 return windowManager_; 893 } 894 895 bool HasFloatTitle() const; 896 IsRebuildFinished()897 bool IsRebuildFinished() const 898 { 899 return isRebuildFinished_; 900 } 901 902 void RequestFrame(); 903 904 void RegisterFont(const std::string& familyName, const std::string& familySrc, const std::string& bundleName = "", 905 const std::string& moduleName = ""); 906 907 void GetSystemFontList(std::vector<std::string>& fontList); 908 909 bool GetSystemFont(const std::string& fontName, FontInfo& fontInfo); 910 911 void GetUIFontConfig(FontConfigJsonInfo& fontConfigJsonInfo); 912 913 void TryLoadImageInfo(const std::string& src, std::function<void(bool, int32_t, int32_t)>&& loadCallback); 914 915 RefPtr<OffscreenCanvas> CreateOffscreenCanvas(int32_t width, int32_t height); 916 917 void PostAsyncEvent(TaskExecutor::Task&& task, const std::string& name, 918 TaskExecutor::TaskType type = TaskExecutor::TaskType::UI); 919 920 void PostAsyncEvent(const TaskExecutor::Task& task, const std::string& name, 921 TaskExecutor::TaskType type = TaskExecutor::TaskType::UI); 922 923 void PostSyncEvent(const TaskExecutor::Task& task, const std::string& name, 924 TaskExecutor::TaskType type = TaskExecutor::TaskType::UI); 925 926 virtual void FlushReload(const ConfigurationChange& configurationChange, bool fullUpdate = true) {} 927 FlushBuild()928 virtual void FlushBuild() {} 929 FlushReloadTransition()930 virtual void FlushReloadTransition() {} RebuildFontNode()931 virtual void RebuildFontNode() {} GetFrontendType()932 FrontendType GetFrontendType() const 933 { 934 return frontendType_; 935 } 936 GetDensity()937 double GetDensity() const 938 { 939 return density_; 940 } 941 GetPlatformResRegister()942 RefPtr<PlatformResRegister> GetPlatformResRegister() const 943 { 944 return platformResRegister_; 945 } 946 947 void SetTouchPipeline(const WeakPtr<PipelineBase>& context); 948 void RemoveTouchPipeline(const WeakPtr<PipelineBase>& context); 949 950 void OnVirtualKeyboardAreaChange(Rect keyboardArea, 951 const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr, const float safeHeight = 0.0f, 952 bool supportAvoidance = false, bool forceChange = false); 953 void OnVirtualKeyboardAreaChange(Rect keyboardArea, double positionY, double height, 954 const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr, bool forceChange = false); 955 void OnFoldStatusChanged(FoldStatus foldStatus); 956 957 using foldStatusChangedCallback = std::function<bool(FoldStatus)>; SetFoldStatusChangeCallback(foldStatusChangedCallback && listener)958 void SetFoldStatusChangeCallback(foldStatusChangedCallback&& listener) 959 { 960 foldStatusChangedCallback_.emplace_back(std::move(listener)); 961 } 962 963 void OnFoldDisplayModeChanged(FoldDisplayMode foldDisplayMode); 964 965 using virtualKeyBoardCallback = std::function<bool(int32_t, int32_t, double)>; SetVirtualKeyBoardCallback(virtualKeyBoardCallback && listener)966 void SetVirtualKeyBoardCallback(virtualKeyBoardCallback&& listener) 967 { 968 static std::atomic<int32_t> pseudoId(-1); // -1 will not be conflict with real node ids. 969 auto nodeId = pseudoId.fetch_sub(1, std::memory_order_relaxed); 970 virtualKeyBoardCallback_.emplace(std::make_pair(nodeId, std::move(listener))); 971 } SetVirtualKeyBoardCallback(int32_t nodeId,virtualKeyBoardCallback && listener)972 void SetVirtualKeyBoardCallback(int32_t nodeId, virtualKeyBoardCallback&& listener) 973 { 974 virtualKeyBoardCallback_.emplace(std::make_pair(nodeId, std::move(listener))); 975 } RemoveVirtualKeyBoardCallback(int32_t nodeId)976 void RemoveVirtualKeyBoardCallback(int32_t nodeId) 977 { 978 virtualKeyBoardCallback_.erase(nodeId); 979 } NotifyVirtualKeyBoard(int32_t width,int32_t height,double keyboard)980 bool NotifyVirtualKeyBoard(int32_t width, int32_t height, double keyboard) const 981 { 982 bool isConsume = false; 983 for (const auto& [nodeId, iterVirtualKeyBoardCallback] : virtualKeyBoardCallback_) { 984 if (iterVirtualKeyBoardCallback && iterVirtualKeyBoardCallback(width, height, keyboard)) { 985 isConsume = true; 986 } 987 } 988 return isConsume; 989 } 990 991 using configChangedCallback = std::function<void()>; SetConfigChangedCallback(int32_t nodeId,configChangedCallback && listener)992 void SetConfigChangedCallback(int32_t nodeId, configChangedCallback&& listener) 993 { 994 configChangedCallback_.emplace(make_pair(nodeId, std::move(listener))); 995 } RemoveConfigChangedCallback(int32_t nodeId)996 void RemoveConfigChangedCallback(int32_t nodeId) 997 { 998 configChangedCallback_.erase(nodeId); 999 } 1000 NotifyConfigurationChange()1001 void NotifyConfigurationChange() 1002 { 1003 for (const auto& [nodeId, callback] : configChangedCallback_) { 1004 if (callback) { 1005 callback(); 1006 } 1007 } 1008 } 1009 1010 using PostRTTaskCallback = std::function<void(std::function<void()>&&)>; SetPostRTTaskCallBack(PostRTTaskCallback && callback)1011 void SetPostRTTaskCallBack(PostRTTaskCallback&& callback) 1012 { 1013 postRTTaskCallback_ = std::move(callback); 1014 } 1015 PostTaskToRT(std::function<void ()> && task)1016 void PostTaskToRT(std::function<void()>&& task) 1017 { 1018 if (postRTTaskCallback_) { 1019 postRTTaskCallback_(std::move(task)); 1020 } 1021 } 1022 1023 void SetGetWindowRectImpl(std::function<Rect()>&& callback); 1024 1025 Rect GetCurrentWindowRect() const; 1026 1027 using SafeAreaInsets = NG::SafeAreaInsets; UpdateSystemSafeArea(const SafeAreaInsets & systemSafeArea)1028 virtual void UpdateSystemSafeArea(const SafeAreaInsets& systemSafeArea) {} 1029 UpdateCutoutSafeArea(const SafeAreaInsets & cutoutSafeArea)1030 virtual void UpdateCutoutSafeArea(const SafeAreaInsets& cutoutSafeArea) {} 1031 UpdateNavSafeArea(const SafeAreaInsets & navSafeArea)1032 virtual void UpdateNavSafeArea(const SafeAreaInsets& navSafeArea) {} 1033 UpdateOriginAvoidArea(const Rosen::AvoidArea & avoidArea,uint32_t type)1034 virtual void UpdateOriginAvoidArea(const Rosen::AvoidArea& avoidArea, uint32_t type) {} 1035 SetEnableKeyBoardAvoidMode(KeyBoardAvoidMode value)1036 virtual void SetEnableKeyBoardAvoidMode(KeyBoardAvoidMode value) {} 1037 GetEnableKeyBoardAvoidMode()1038 virtual KeyBoardAvoidMode GetEnableKeyBoardAvoidMode() { 1039 return KeyBoardAvoidMode::OFFSET; 1040 } 1041 IsEnableKeyBoardAvoidMode()1042 virtual bool IsEnableKeyBoardAvoidMode() { 1043 return false; 1044 } 1045 RequireSummary()1046 virtual void RequireSummary() {} 1047 SetPluginOffset(const Offset & offset)1048 void SetPluginOffset(const Offset& offset) 1049 { 1050 pluginOffset_ = offset; 1051 } 1052 GetPluginOffset()1053 Offset GetPluginOffset() const 1054 { 1055 return pluginOffset_; 1056 } 1057 SetPluginEventOffset(const Offset & offset)1058 void SetPluginEventOffset(const Offset& offset) 1059 { 1060 pluginEventOffset_ = offset; 1061 } 1062 GetPluginEventOffset()1063 Offset GetPluginEventOffset() const 1064 { 1065 return pluginEventOffset_; 1066 } NotifyMemoryLevel(int32_t level)1067 virtual void NotifyMemoryLevel(int32_t level) {} 1068 SetDisplayWindowRectInfo(const Rect & displayWindowRectInfo)1069 void SetDisplayWindowRectInfo(const Rect& displayWindowRectInfo) 1070 { 1071 displayWindowRectInfo_ = displayWindowRectInfo; 1072 } 1073 1074 virtual void SetContainerWindow(bool isShow) = 0; 1075 1076 // This method can get the coordinates and size of the current window, 1077 // which can be added to the return value of the GetGlobalOffset method to get the window coordinates of the node. GetDisplayWindowRectInfo()1078 const Rect& GetDisplayWindowRectInfo() const 1079 { 1080 return displayWindowRectInfo_; 1081 } FlushModifier()1082 virtual void FlushModifier() {} 1083 virtual void FlushMessages() = 0; SetGSVsyncCallback(std::function<void (void)> && callback)1084 void SetGSVsyncCallback(std::function<void(void)>&& callback) 1085 { 1086 gsVsyncCallback_ = std::move(callback); 1087 } 1088 1089 virtual void FlushUITasks(bool triggeredByImplicitAnimation = false) = 0; 1090 FlushAfterLayoutCallbackInImplicitAnimationTask()1091 virtual void FlushAfterLayoutCallbackInImplicitAnimationTask() {} 1092 1093 virtual void FlushPipelineImmediately() = 0; 1094 1095 virtual void FlushOnceVsyncTask() = 0; 1096 1097 // get animateTo closure option GetSyncAnimationOption()1098 AnimationOption GetSyncAnimationOption() 1099 { 1100 return animationOption_; 1101 } 1102 SetSyncAnimationOption(const AnimationOption & option)1103 void SetSyncAnimationOption(const AnimationOption& option) 1104 { 1105 animationOption_ = option; 1106 } 1107 SetKeyboardAnimationConfig(const KeyboardAnimationConfig & config)1108 void SetKeyboardAnimationConfig(const KeyboardAnimationConfig& config) 1109 { 1110 keyboardAnimationConfig_ = config; 1111 } 1112 GetKeyboardAnimationConfig()1113 KeyboardAnimationConfig GetKeyboardAnimationConfig() const 1114 { 1115 return keyboardAnimationConfig_; 1116 } 1117 SetNextFrameLayoutCallback(std::function<void ()> && callback)1118 void SetNextFrameLayoutCallback(std::function<void()>&& callback) 1119 { 1120 nextFrameLayoutCallback_ = std::move(callback); 1121 } 1122 SetForegroundCalled(bool isForegroundCalled)1123 void SetForegroundCalled(bool isForegroundCalled) 1124 { 1125 isForegroundCalled_ = isForegroundCalled; 1126 } 1127 SetIsSubPipeline(bool isSubPipeline)1128 void SetIsSubPipeline(bool isSubPipeline) 1129 { 1130 isSubPipeline_ = isSubPipeline; 1131 } 1132 IsSubPipeline()1133 bool IsSubPipeline() const 1134 { 1135 return isSubPipeline_; 1136 } 1137 SetParentPipeline(const WeakPtr<PipelineBase> & pipeline)1138 void SetParentPipeline(const WeakPtr<PipelineBase>& pipeline) 1139 { 1140 parentPipeline_ = pipeline; 1141 } 1142 1143 void AddEtsCardTouchEventCallback(int32_t ponitId, EtsCardTouchEventCallback&& callback); 1144 1145 void HandleEtsCardTouchEvent(const TouchEvent& point, SerializedGesture &serializedGesture); 1146 1147 void RemoveEtsCardTouchEventCallback(int32_t ponitId); 1148 1149 void SetSubWindowVsyncCallback(AceVsyncCallback&& callback, int32_t subWindowId); 1150 1151 void SetJsFormVsyncCallback(AceVsyncCallback&& callback, int32_t subWindowId); 1152 1153 void RemoveSubWindowVsyncCallback(int32_t subWindowId); 1154 1155 void RemoveJsFormVsyncCallback(int32_t subWindowId); 1156 SetIsLayoutFullScreen(bool isLayoutFullScreen)1157 virtual void SetIsLayoutFullScreen(bool isLayoutFullScreen) {} SetIsNeedAvoidWindow(bool isLayoutFullScreen)1158 virtual void SetIsNeedAvoidWindow(bool isLayoutFullScreen) {} SetIgnoreViewSafeArea(bool ignoreViewSafeArea)1159 virtual void SetIgnoreViewSafeArea(bool ignoreViewSafeArea) {} OnFoldStatusChange(FoldStatus foldStatus)1160 virtual void OnFoldStatusChange(FoldStatus foldStatus) {} OnFoldDisplayModeChange(FoldDisplayMode foldDisplayMode)1161 virtual void OnFoldDisplayModeChange(FoldDisplayMode foldDisplayMode) {} 1162 SetIsAppWindow(bool isAppWindow)1163 void SetIsAppWindow(bool isAppWindow) 1164 { 1165 isAppWindow_ = isAppWindow; 1166 } 1167 GetIsAppWindow()1168 bool GetIsAppWindow() const 1169 { 1170 return isAppWindow_; 1171 } 1172 SetFormAnimationStartTime(int64_t time)1173 void SetFormAnimationStartTime(int64_t time) 1174 { 1175 formAnimationStartTime_ = time; 1176 } 1177 GetFormAnimationStartTime()1178 int64_t GetFormAnimationStartTime() const 1179 { 1180 return formAnimationStartTime_; 1181 } 1182 SetIsFormAnimation(bool isFormAnimation)1183 void SetIsFormAnimation(bool isFormAnimation) 1184 { 1185 isFormAnimation_ = isFormAnimation; 1186 } 1187 IsFormAnimation()1188 bool IsFormAnimation() const 1189 { 1190 return isFormAnimation_; 1191 } 1192 SetFormAnimationFinishCallback(bool isFormAnimationFinishCallback)1193 void SetFormAnimationFinishCallback(bool isFormAnimationFinishCallback) 1194 { 1195 isFormAnimationFinishCallback_ = isFormAnimationFinishCallback; 1196 } 1197 IsFormAnimationFinishCallback()1198 bool IsFormAnimationFinishCallback() const 1199 { 1200 return isFormAnimationFinishCallback_; 1201 } 1202 1203 // restore RestoreNodeInfo(std::unique_ptr<JsonValue> nodeInfo)1204 virtual void RestoreNodeInfo(std::unique_ptr<JsonValue> nodeInfo) {} 1205 GetStoredNodeInfo()1206 virtual std::unique_ptr<JsonValue> GetStoredNodeInfo() 1207 { 1208 return nullptr; 1209 } 1210 GetLastTouchTime()1211 uint64_t GetLastTouchTime() const 1212 { 1213 return lastTouchTime_; 1214 } 1215 AddFormLinkInfo(int32_t id,const std::string & info)1216 void AddFormLinkInfo(int32_t id, const std::string& info) 1217 { 1218 LOGI("AddFormLinkInfo is %{public}s, id is %{public}d", info.c_str(), id); 1219 formLinkInfoMap_[id] = info; 1220 } 1221 IsLayouting()1222 virtual bool IsLayouting() const 1223 { 1224 return false; 1225 } 1226 SetHalfLeading(bool halfLeading)1227 void SetHalfLeading(bool halfLeading) 1228 { 1229 halfLeading_ = halfLeading; 1230 } 1231 GetHalfLeading()1232 bool GetHalfLeading() const 1233 { 1234 return halfLeading_; 1235 } 1236 SetHasPreviewTextOption(bool hasOption)1237 void SetHasPreviewTextOption(bool hasOption) 1238 { 1239 hasPreviewTextOption_ = hasOption; 1240 } 1241 GetHasPreviewTextOption()1242 bool GetHasPreviewTextOption() const 1243 { 1244 return hasPreviewTextOption_; 1245 } 1246 SetSupportPreviewText(bool changeSupported)1247 void SetSupportPreviewText(bool changeSupported) 1248 { 1249 hasSupportedPreviewText_ = !changeSupported; 1250 } 1251 GetSupportPreviewText()1252 bool GetSupportPreviewText() const 1253 { 1254 return hasSupportedPreviewText_; 1255 } 1256 SetUseCutout(bool useCutout)1257 void SetUseCutout(bool useCutout) 1258 { 1259 useCutout_ = useCutout; 1260 } 1261 GetUseCutout()1262 bool GetUseCutout() const 1263 { 1264 return useCutout_; 1265 } 1266 GetOnFoucs()1267 bool GetOnFoucs() const 1268 { 1269 return onFocus_; 1270 } 1271 GetVsyncTime()1272 uint64_t GetVsyncTime() const 1273 { 1274 return vsyncTime_; 1275 } 1276 SetVsyncTime(uint64_t time)1277 void SetVsyncTime(uint64_t time) 1278 { 1279 vsyncTime_ = time; 1280 } 1281 UpdateCurrentActiveNode(const WeakPtr<NG::FrameNode> & node)1282 virtual void UpdateCurrentActiveNode(const WeakPtr<NG::FrameNode>& node) {} 1283 GetCurrentExtraInfo()1284 virtual std::string GetCurrentExtraInfo() { return ""; } 1285 1286 virtual void UpdateTitleInTargetPos(bool isShow = true, int32_t height = 0) {} 1287 SetCursor(int32_t cursorValue)1288 virtual void SetCursor(int32_t cursorValue) {} 1289 1290 virtual void RestoreDefault(int32_t windowId = 0) {} 1291 SetOnFormRecycleCallback(std::function<std::string ()> && onFormRecycle)1292 void SetOnFormRecycleCallback(std::function<std::string()>&& onFormRecycle) 1293 { 1294 onFormRecycle_ = std::move(onFormRecycle); 1295 } 1296 1297 std::string OnFormRecycle(); 1298 SetOnFormRecoverCallback(std::function<void (std::string)> && onFormRecover)1299 void SetOnFormRecoverCallback(std::function<void(std::string)>&& onFormRecover) 1300 { 1301 onFormRecover_ = std::move(onFormRecover); 1302 } 1303 1304 void OnFormRecover(const std::string& statusData); 1305 IsDragging()1306 virtual bool IsDragging() const 1307 { 1308 return false; 1309 } 1310 SetIsDragging(bool isDragging)1311 virtual void SetIsDragging(bool isDragging) {} 1312 ResetDragging()1313 virtual void ResetDragging() {} 1314 GetSerializedGesture()1315 virtual const SerializedGesture& GetSerializedGesture() const 1316 { 1317 return serializedGesture_; 1318 } 1319 PrintVsyncInfoIfNeed()1320 virtual bool PrintVsyncInfoIfNeed() const 1321 { 1322 return false; 1323 } 1324 1325 StartWindowAnimation()1326 virtual void StartWindowAnimation() {} 1327 StopWindowAnimation()1328 virtual void StopWindowAnimation() {} 1329 AddSyncGeometryNodeTask(std::function<void ()> && task)1330 virtual void AddSyncGeometryNodeTask(std::function<void()>&& task) {} 1331 FlushSyncGeometryNodeTasks()1332 virtual void FlushSyncGeometryNodeTasks() {} 1333 ChangeSensitiveNodes(bool flag)1334 virtual void ChangeSensitiveNodes(bool flag) {} 1335 IsContainerModalVisible()1336 virtual bool IsContainerModalVisible() 1337 { 1338 return false; 1339 } 1340 GetFrameCount()1341 uint32_t GetFrameCount() const 1342 { 1343 return frameCount_; 1344 } 1345 GetKeyboardAction()1346 KeyboardAction GetKeyboardAction() 1347 { 1348 return keyboardAction_; 1349 } 1350 SetKeyboardAction(KeyboardAction action)1351 void SetKeyboardAction(KeyboardAction action) 1352 { 1353 keyboardAction_ = action; 1354 } 1355 void SetUiDvsyncSwitch(bool on); 1356 CheckAndLogLastReceivedTouchEventInfo(int32_t eventId,TouchType type)1357 virtual void CheckAndLogLastReceivedTouchEventInfo(int32_t eventId, TouchType type) {} 1358 CheckAndLogLastConsumedTouchEventInfo(int32_t eventId,TouchType type)1359 virtual void CheckAndLogLastConsumedTouchEventInfo(int32_t eventId, TouchType type) {} 1360 CheckAndLogLastReceivedMouseEventInfo(int32_t eventId,MouseAction action)1361 virtual void CheckAndLogLastReceivedMouseEventInfo(int32_t eventId, MouseAction action) {} 1362 CheckAndLogLastConsumedMouseEventInfo(int32_t eventId,MouseAction action)1363 virtual void CheckAndLogLastConsumedMouseEventInfo(int32_t eventId, MouseAction action) {} 1364 CheckAndLogLastReceivedAxisEventInfo(int32_t eventId,AxisAction action)1365 virtual void CheckAndLogLastReceivedAxisEventInfo(int32_t eventId, AxisAction action) {} 1366 CheckAndLogLastConsumedAxisEventInfo(int32_t eventId,AxisAction action)1367 virtual void CheckAndLogLastConsumedAxisEventInfo(int32_t eventId, AxisAction action) {} 1368 GetPageAvoidOffset()1369 virtual float GetPageAvoidOffset() 1370 { 1371 return 0.0f; 1372 } 1373 CheckNeedAvoidInSubWindow()1374 virtual bool CheckNeedAvoidInSubWindow() 1375 { 1376 return false; 1377 } 1378 1379 virtual bool IsDensityChanged() const = 0; 1380 GetResponseRegion(const RefPtr<NG::FrameNode> & rootNode)1381 virtual std::string GetResponseRegion(const RefPtr<NG::FrameNode>& rootNode) 1382 { 1383 return ""; 1384 }; 1385 NotifyResponseRegionChanged(const RefPtr<NG::FrameNode> & rootNode)1386 virtual void NotifyResponseRegionChanged(const RefPtr<NG::FrameNode>& rootNode) {}; 1387 SetTHPExtraManager(const RefPtr<NG::THPExtraManager> & thpExtraMgr)1388 void SetTHPExtraManager(const RefPtr<NG::THPExtraManager>& thpExtraMgr) 1389 { 1390 thpExtraMgr_ = thpExtraMgr; 1391 } 1392 GetTHPExtraManager()1393 const RefPtr<NG::THPExtraManager>& GetTHPExtraManager() const 1394 { 1395 return thpExtraMgr_; 1396 } 1397 1398 virtual bool GetOnShow() const = 0; 1399 bool IsDestroyed(); 1400 1401 void SetDestroyed(); 1402 1403 #if defined(SUPPORT_TOUCH_TARGET_TEST) 1404 // Called by hittest to find touch node is equal target. 1405 virtual bool OnTouchTargetHitTest(const TouchEvent& point, bool isSubPipe = false, 1406 const std::string& target = "") = 0; 1407 #endif IsWindowFocused()1408 virtual bool IsWindowFocused() const 1409 { 1410 return GetOnFoucs(); 1411 } 1412 SetDragNodeGrayscale(float dragNodeGrayscale)1413 void SetDragNodeGrayscale(float dragNodeGrayscale) 1414 { 1415 dragNodeGrayscale_ = dragNodeGrayscale; 1416 } 1417 GetDragNodeGrayscale()1418 float GetDragNodeGrayscale() const 1419 { 1420 return dragNodeGrayscale_; 1421 } 1422 IsDirtyNodesEmpty()1423 virtual bool IsDirtyNodesEmpty() const 1424 { 1425 return true; 1426 } 1427 IsDirtyLayoutNodesEmpty()1428 virtual bool IsDirtyLayoutNodesEmpty() const 1429 { 1430 return true; 1431 } 1432 SetOpenInvisibleFreeze(bool isOpenInvisibleFreeze)1433 void SetOpenInvisibleFreeze(bool isOpenInvisibleFreeze) 1434 { 1435 isOpenInvisibleFreeze_ = isOpenInvisibleFreeze; 1436 } 1437 IsOpenInvisibleFreeze()1438 bool IsOpenInvisibleFreeze() const 1439 { 1440 return isOpenInvisibleFreeze_; 1441 } 1442 SetVisibleAreaRealTime(bool visibleAreaRealTime)1443 void SetVisibleAreaRealTime(bool visibleAreaRealTime) 1444 { 1445 visibleAreaRealTime_ = visibleAreaRealTime; 1446 } 1447 GetVisibleAreaRealTime()1448 bool GetVisibleAreaRealTime() const 1449 { 1450 return visibleAreaRealTime_; 1451 } 1452 1453 void SetAccessibilityEventCallback(std::function<void(uint32_t, int64_t)>&& callback); 1454 1455 void AddAccessibilityCallbackEvent(AccessibilityCallbackEventId event, int64_t parameter); 1456 1457 void FireAccessibilityEvents(); 1458 1459 void SetUIExtensionEventCallback(std::function<void(uint32_t)>&& callback); 1460 void AddUIExtensionCallbackEvent(NG::UIExtCallbackEventId eventId); 1461 void FireAllUIExtensionEvents(); 1462 void FireUIExtensionEventOnceImmediately(NG::UIExtCallbackEventId eventId); 1463 1464 protected: 1465 virtual bool MaybeRelease() override; TryCallNextFrameLayoutCallback()1466 void TryCallNextFrameLayoutCallback() 1467 { 1468 if (isForegroundCalled_ && nextFrameLayoutCallback_) { 1469 isForegroundCalled_ = false; 1470 nextFrameLayoutCallback_(); 1471 LOGI("nextFrameLayoutCallback called"); 1472 } 1473 } 1474 OnDumpInfo(const std::vector<std::string> & params)1475 virtual bool OnDumpInfo(const std::vector<std::string>& params) const 1476 { 1477 return false; 1478 } 1479 virtual void FlushVsync(uint64_t nanoTimestamp, uint32_t frameCount) = 0; 1480 virtual void SetRootRect(double width, double height, double offset = 0.0) = 0; 1481 virtual void FlushPipelineWithoutAnimation() = 0; 1482 1483 virtual void OnVirtualKeyboardHeightChange(float keyboardHeight, 1484 const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr, const float safeHeight = 0.0f, 1485 const bool supportAvoidance = false, bool forceChange = false) 1486 {} 1487 virtual void OnVirtualKeyboardHeightChange(float keyboardHeight, double positionY, double height, 1488 const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr, bool forceChange = false) 1489 {} 1490 1491 void UpdateRootSizeAndScale(int32_t width, int32_t height); 1492 SetIsReloading(bool isReloading)1493 void SetIsReloading(bool isReloading) 1494 { 1495 isReloading_ = isReloading; 1496 } 1497 bool FireUIExtensionEventValid(); 1498 1499 std::function<void()> GetWrappedAnimationCallback(const std::function<void()>& finishCallback); 1500 1501 std::map<int32_t, configChangedCallback> configChangedCallback_; 1502 std::map<int32_t, virtualKeyBoardCallback> virtualKeyBoardCallback_; 1503 std::list<foldStatusChangedCallback> foldStatusChangedCallback_; 1504 1505 bool isRebuildFinished_ = false; 1506 bool isJsCard_ = false; 1507 bool isFormRender_ = false; 1508 bool isDynamicRender_ = false; 1509 bool isRightToLeft_ = false; 1510 bool isFullWindow_ = false; 1511 bool isAppWindow_ = true; 1512 bool installationFree_ = false; 1513 bool isSubPipeline_ = false; 1514 bool isReloading_ = false; 1515 1516 bool isJsPlugin_ = false; 1517 bool isOpenInvisibleFreeze_ = false; 1518 1519 std::unordered_map<int32_t, AceVsyncCallback> subWindowVsyncCallbacks_; 1520 std::unordered_map<int32_t, AceVsyncCallback> jsFormVsyncCallbacks_; 1521 int32_t minPlatformVersion_ = 0; 1522 uint32_t windowId_ = 0; 1523 // UIExtensionAbility need component windowID 1524 std::optional<uint32_t> focusWindowId_; 1525 std::optional<uint32_t> realHostWindowId_; 1526 1527 int32_t appLabelId_ = 0; 1528 float fontScale_ = 1.0f; 1529 float fontWeightScale_ = 1.0f; 1530 float designWidthScale_ = 1.0f; 1531 float viewScale_ = 1.0f; 1532 double density_ = 1.0; 1533 double dipScale_ = 1.0; 1534 double rootHeight_ = 0.0; 1535 double rootWidth_ = 0.0; 1536 int32_t width_ = 0; 1537 int32_t height_ = 0; 1538 FrontendType frontendType_; 1539 WindowModal windowModal_ = WindowModal::NORMAL; 1540 1541 Offset pluginOffset_ { 0, 0 }; 1542 Offset pluginEventOffset_ { 0, 0 }; 1543 Color appBgColor_ = Color::WHITE; 1544 int8_t renderingMode_ = 0; 1545 1546 std::unique_ptr<DrawDelegate> drawDelegate_; 1547 std::stack<bool> pendingImplicitLayout_; 1548 std::stack<bool> pendingImplicitRender_; 1549 std::stack<bool> pendingFrontendAnimation_; 1550 std::shared_ptr<Window> window_; 1551 RefPtr<TaskExecutor> taskExecutor_; 1552 RefPtr<AssetManager> assetManager_; 1553 WeakPtr<Frontend> weakFrontend_; 1554 int32_t instanceId_ = 0; 1555 RefPtr<EventManager> eventManager_; 1556 RefPtr<ImageCache> imageCache_; 1557 RefPtr<SharedImageManager> sharedImageManager_; 1558 mutable std::shared_mutex imageMtx_; 1559 mutable std::shared_mutex themeMtx_; 1560 mutable std::mutex destructMutex_; 1561 RefPtr<ThemeManager> themeManager_; 1562 RefPtr<DataProviderManagerInterface> dataProviderManager_; 1563 RefPtr<FontManager> fontManager_; 1564 RefPtr<ManagerInterface> textFieldManager_; 1565 RefPtr<PlatformBridge> messageBridge_; 1566 RefPtr<WindowManager> windowManager_; 1567 OnPageShowCallBack onPageShowCallBack_; 1568 AnimationCallback animationCallback_; 1569 ProfilerCallback onVsyncProfiler_; 1570 FinishEventHandler finishEventHandler_; 1571 StartAbilityHandler startAbilityHandler_; 1572 ActionEventHandler actionEventHandler_; 1573 FormLinkInfoUpdateHandler formLinkInfoUpdateHandler_; 1574 RefPtr<PlatformResRegister> platformResRegister_; 1575 1576 WeakPtr<PipelineBase> parentPipeline_; 1577 1578 std::vector<WeakPtr<PipelineBase>> touchPluginPipelineContext_; 1579 std::unordered_map<int32_t, EtsCardTouchEventCallback> etsCardTouchEventCallback_; 1580 1581 RefPtr<Clipboard> clipboard_; 1582 std::function<void(const std::string&)> clipboardCallback_ = nullptr; 1583 Rect displayWindowRectInfo_; 1584 AnimationOption animationOption_; 1585 KeyboardAnimationConfig keyboardAnimationConfig_; 1586 1587 std::function<void()> nextFrameLayoutCallback_ = nullptr; 1588 SharePanelCallback sharePanelCallback_ = nullptr; 1589 std::atomic<bool> isForegroundCalled_ = false; 1590 std::atomic<bool> onFocus_ = false; 1591 uint64_t lastTouchTime_ = 0; 1592 std::map<int32_t, std::string> formLinkInfoMap_; 1593 struct FunctionHash { operatorFunctionHash1594 std::size_t operator()(const std::shared_ptr<std::function<void()>>& functionPtr) const 1595 { 1596 return std::hash<std::function<void()>*>()(functionPtr.get()); 1597 } 1598 }; 1599 std::function<std::string()> onFormRecycle_; 1600 std::function<void(std::string)> onFormRecover_; 1601 1602 uint64_t compensationValue_ = 0; 1603 int64_t recvTime_ = 0; 1604 std::once_flag displaySyncFlag_; 1605 RefPtr<UIDisplaySyncManager> uiDisplaySyncManager_; 1606 1607 SerializedGesture serializedGesture_; 1608 RefPtr<NG::THPExtraManager> thpExtraMgr_; 1609 private: 1610 void DumpFrontend() const; 1611 double ModifyKeyboardHeight(double keyboardHeight) const; 1612 void FireUIExtensionEventInner(uint32_t eventId); 1613 StatusBarEventHandler statusBarBgColorEventHandler_; 1614 PopupEventHandler popupEventHandler_; 1615 MenuEventHandler menuEventHandler_; 1616 ContextMenuEventHandler contextMenuEventHandler_; 1617 RouterBackEventHandler routerBackEventHandler_; 1618 std::list<PopPageSuccessEventHandler> popPageSuccessEventHandler_; 1619 std::list<IsPagePathInvalidEventHandler> isPagePathInvalidEventHandler_; 1620 std::list<DestroyEventHandler> destroyEventHandler_; 1621 std::list<DispatchTouchEventHandler> dispatchTouchEventHandler_; 1622 GetViewScaleCallback getViewScaleCallback_; 1623 // OnRouterChangeCallback is function point, need to be initialized. 1624 OnRouterChangeCallback onRouterChangeCallback_ = nullptr; 1625 PostRTTaskCallback postRTTaskCallback_; 1626 std::function<void(void)> gsVsyncCallback_; 1627 std::unordered_set<std::shared_ptr<std::function<void()>>, FunctionHash> finishFunctions_; 1628 bool followSystem_ = false; 1629 float maxAppFontScale_ = static_cast<float>(INT32_MAX); 1630 bool isFormAnimationFinishCallback_ = false; 1631 int64_t formAnimationStartTime_ = 0; 1632 bool isFormAnimation_ = false; 1633 bool halfLeading_ = false; 1634 bool hasSupportedPreviewText_ = true; 1635 bool hasPreviewTextOption_ = false; 1636 bool useCutout_ = false; 1637 // whether visible area need to be calculate at each vsync after approximate timeout. 1638 bool visibleAreaRealTime_ = false; 1639 uint64_t vsyncTime_ = 0; 1640 bool destroyed_ = false; 1641 uint32_t frameCount_ = 0; 1642 KeyboardAction keyboardAction_ = KeyboardAction::NONE; 1643 float dragNodeGrayscale_ = 0.0f; 1644 1645 // To avoid the race condition caused by the offscreen canvas get density from the pipeline in the worker thread. 1646 std::mutex densityChangeMutex_; 1647 int32_t densityChangeCallbackId_ = 0; 1648 std::unordered_map<int32_t, std::function<void(double)>> densityChangedCallbacks_; 1649 std::function<double()> windowDensityCallback_; 1650 std::function<void(uint32_t)> uiExtensionEventCallback_; 1651 std::set<NG::UIExtCallbackEvent> uiExtensionEvents_; 1652 std::function<void(uint32_t, int64_t)> accessibilityCallback_; 1653 std::set<AccessibilityCallbackEvent> accessibilityEvents_; 1654 1655 ACE_DISALLOW_COPY_AND_MOVE(PipelineBase); 1656 }; 1657 1658 } // namespace OHOS::Ace 1659 1660 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_PIPELINE_PIPELINE_BASE_H 1661