1 /* 2 * Copyright (c) 2022 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 <shared_mutex> 23 #include <stack> 24 #include <string> 25 #include <utility> 26 27 #include "base/geometry/dimension.h" 28 #include "base/resource/asset_manager.h" 29 #include "base/resource/data_provider_manager.h" 30 #include "base/resource/shared_image_manager.h" 31 #include "base/thread/task_executor.h" 32 #include "core/accessibility/accessibility_manager.h" 33 #include "core/animation/schedule_task.h" 34 #include "core/common/clipboard/clipboard_proxy.h" 35 #include "core/common/draw_delegate.h" 36 #include "core/common/event_manager.h" 37 #include "core/common/platform_bridge.h" 38 #include "core/common/platform_res_register.h" 39 #include "core/common/window_animation_config.h" 40 #include "core/components/common/properties/animation_option.h" 41 #include "core/components/theme/theme_manager.h" 42 #include "core/event/axis_event.h" 43 #include "core/event/key_event.h" 44 #include "core/event/mouse_event.h" 45 #include "core/event/rotation_event.h" 46 #include "core/event/touch_event.h" 47 #include "core/gestures/gesture_info.h" 48 #include "core/image/image_cache.h" 49 #include "core/pipeline/container_window_manager.h" 50 51 namespace OHOS::Ace { 52 53 class Frontend; 54 class OffscreenCanvas; 55 class Window; 56 class FontManager; 57 class ManagerInterface; 58 enum class FrontendType; 59 using SharePanelCallback = std::function<void(const std::string& bundleName, const std::string& abilityName)>; 60 using EtsCardTouchEventCallback = std::function<void(const TouchEvent&)>; 61 62 class ACE_EXPORT PipelineBase : public AceType { 63 DECLARE_ACE_TYPE(PipelineBase, AceType); 64 65 public: 66 PipelineBase() = default; 67 PipelineBase(std::unique_ptr<Window> window, RefPtr<TaskExecutor> taskExecutor, RefPtr<AssetManager> assetManager, 68 const RefPtr<Frontend>& frontend, int32_t instanceId); 69 PipelineBase(std::unique_ptr<Window> window, RefPtr<TaskExecutor> taskExecutor, RefPtr<AssetManager> assetManager, 70 const RefPtr<Frontend>& frontend, int32_t instanceId, RefPtr<PlatformResRegister> platformResRegister); 71 ~PipelineBase() override; 72 73 static RefPtr<PipelineBase> GetCurrentContext(); 74 75 virtual void SetupRootElement() = 0; 76 77 virtual uint64_t GetTimeFromExternalTimer(); 78 79 bool Animate(const AnimationOption& option, const RefPtr<Curve>& curve, 80 const std::function<void()>& propertyCallback, const std::function<void()>& finishCallBack = nullptr); 81 82 virtual void AddKeyFrame( 83 float fraction, const RefPtr<Curve>& curve, const std::function<void()>& propertyCallback) = 0; 84 85 virtual void AddKeyFrame(float fraction, const std::function<void()>& propertyCallback) = 0; 86 87 void PrepareOpenImplicitAnimation(); 88 89 void OpenImplicitAnimation(const AnimationOption& option, const RefPtr<Curve>& curve, 90 const std::function<void()>& finishCallBack = nullptr); 91 92 void PrepareCloseImplicitAnimation(); 93 94 bool CloseImplicitAnimation(); 95 96 void ForceLayoutForImplicitAnimation(); 97 98 // add schedule task and return the unique mark id. 99 virtual uint32_t AddScheduleTask(const RefPtr<ScheduleTask>& task) = 0; 100 101 // remove schedule task by id. 102 virtual void RemoveScheduleTask(uint32_t id) = 0; 103 104 // Called by view when touch event received. 105 virtual void OnTouchEvent(const TouchEvent& point, bool isSubPipe = false) = 0; 106 107 // Called by container when key event received. 108 // if return false, then this event needs platform to handle it. 109 virtual bool OnKeyEvent(const KeyEvent& event) = 0; 110 111 // Called by view when mouse event received. 112 virtual void OnMouseEvent(const MouseEvent& event) = 0; 113 114 // Called by view when axis event received. 115 virtual void OnAxisEvent(const AxisEvent& event) = 0; 116 117 // Called by container when rotation event received. 118 // if return false, then this event needs platform to handle it. 119 virtual bool OnRotationEvent(const RotationEvent& event) const = 0; 120 121 // Called by window when received vsync signal. 122 virtual void OnVsyncEvent(uint64_t nanoTimestamp, uint32_t frameCount); 123 124 // Called by view 125 virtual void OnDragEvent(int32_t x, int32_t y, DragEventAction action) = 0; 126 127 // Called by view when idle event. 128 virtual void OnIdle(int64_t deadline) = 0; 129 130 virtual void SetBuildAfterCallback(const std::function<void()>& callback) = 0; 131 132 virtual void FlushAnimation(uint64_t nanoTimestamp) = 0; 133 134 virtual void SendEventToAccessibility(const AccessibilityEvent& accessibilityEvent); 135 136 virtual void SaveExplicitAnimationOption(const AnimationOption& option) = 0; 137 138 virtual void CreateExplicitAnimator(const std::function<void()>& onFinishEvent) = 0; 139 140 virtual void ClearExplicitAnimationOption() = 0; 141 142 virtual AnimationOption GetExplicitAnimationOption() const = 0; 143 144 virtual void Destroy(); 145 146 virtual void OnShow() = 0; 147 148 virtual void OnHide() = 0; 149 150 virtual void WindowFocus(bool isFocus) = 0; 151 152 virtual void ShowContainerTitle(bool isShow) = 0; 153 154 virtual void OnSurfaceChanged( 155 int32_t width, int32_t height, WindowSizeChangeReason type = WindowSizeChangeReason::UNDEFINED) = 0; 156 157 virtual void OnSurfacePositionChanged(int32_t posX, int32_t posY) = 0; 158 159 virtual void OnSurfaceDensityChanged(double density) = 0; 160 161 virtual void OnSystemBarHeightChanged(double statusBar, double navigationBar) = 0; 162 163 virtual void OnSurfaceDestroyed() = 0; 164 165 virtual void NotifyOnPreDraw() = 0; 166 167 virtual bool CallRouterBackToPopPage() = 0; 168 OnPageShow()169 virtual void OnPageShow() {} 170 171 virtual void OnActionEvent(const std::string& action); 172 173 virtual void Finish(bool autoFinish = true) const {} 174 RequestFullWindow(int32_t duration)175 virtual void RequestFullWindow(int32_t duration) {} 176 RequestFocus(const std::string & targetNodeId)177 virtual bool RequestFocus(const std::string& targetNodeId) 178 { 179 return false; 180 } 181 182 // Called by AceAbility and UiContent. 183 void DumpInfo(const std::vector<std::string>& params, std::vector<std::string>& info); 184 185 // Called by AceEngine. 186 bool Dump(const std::vector<std::string>& params) const; 187 IsLastPage()188 virtual bool IsLastPage() 189 { 190 return false; 191 } 192 GetIsDeclarative()193 virtual bool GetIsDeclarative() const 194 { 195 return true; 196 } 197 SetAppBgColor(const Color & color)198 virtual void SetAppBgColor(const Color& color) 199 { 200 appBgColor_ = color; 201 } 202 GetAppBgColor()203 const Color& GetAppBgColor() const 204 { 205 return appBgColor_; 206 } 207 GetAppLabelId()208 int32_t GetAppLabelId() const 209 { 210 return appLabelId_; 211 } 212 SetAppLabelId(int32_t appLabelId)213 void SetAppLabelId(int32_t appLabelId) 214 { 215 appLabelId_ = appLabelId; 216 } 217 218 virtual void SetAppTitle(const std::string& title) = 0; 219 220 virtual void SetAppIcon(const RefPtr<PixelMap>& icon) = 0; 221 RefreshRootBgColor()222 virtual void RefreshRootBgColor() const {} 223 PostponePageTransition()224 virtual void PostponePageTransition() {} LaunchPageTransition()225 virtual void LaunchPageTransition() {} 226 GetBoundingRectData(int32_t nodeId,Rect & rect)227 virtual void GetBoundingRectData(int32_t nodeId, Rect& rect) {} 228 229 virtual RefPtr<AccessibilityManager> GetAccessibilityManager() const; 230 231 void SetRootSize(double density, int32_t width, int32_t height); 232 233 void UpdateFontWeightScale(); 234 235 double NormalizeToPx(const Dimension& dimension) const; 236 237 double ConvertPxToVp(const Dimension& dimension) const; 238 239 using FinishEventHandler = std::function<void()>; SetFinishEventHandler(FinishEventHandler && listener)240 void SetFinishEventHandler(FinishEventHandler&& listener) 241 { 242 finishEventHandler_ = std::move(listener); 243 } 244 245 using StartAbilityHandler = std::function<void(const std::string& address)>; SetStartAbilityHandler(StartAbilityHandler && listener)246 void SetStartAbilityHandler(StartAbilityHandler&& listener) 247 { 248 startAbilityHandler_ = std::move(listener); 249 } 250 void HyperlinkStartAbility(const std::string& address) const; 251 252 using ActionEventHandler = std::function<void(const std::string& action)>; SetActionEventHandler(ActionEventHandler && listener)253 void SetActionEventHandler(ActionEventHandler&& listener) 254 { 255 actionEventHandler_ = std::move(listener); 256 } 257 258 using StatusBarEventHandler = std::function<void(const Color& color)>; SetStatusBarEventHandler(StatusBarEventHandler && listener)259 void SetStatusBarEventHandler(StatusBarEventHandler&& listener) 260 { 261 statusBarBgColorEventHandler_ = std::move(listener); 262 } 263 void NotifyStatusBarBgColor(const Color& color) const; 264 using PopupEventHandler = std::function<void()>; 265 SetPopupEventHandler(PopupEventHandler && listener)266 void SetPopupEventHandler(PopupEventHandler&& listener) 267 { 268 popupEventHandler_ = std::move(listener); 269 } 270 void NotifyPopupDismiss() const; 271 272 using RouterBackEventHandler = std::function<void()>; SetRouterBackEventHandler(RouterBackEventHandler && listener)273 void SetRouterBackEventHandler(RouterBackEventHandler&& listener) 274 { 275 routerBackEventHandler_ = std::move(listener); 276 } 277 void NotifyRouterBackDismiss() const; 278 279 using PopPageSuccessEventHandler = std::function<void(const std::string& pageUrl, const int32_t pageId)>; SetPopPageSuccessEventHandler(PopPageSuccessEventHandler && listener)280 void SetPopPageSuccessEventHandler(PopPageSuccessEventHandler&& listener) 281 { 282 popPageSuccessEventHandler_.push_back(std::move(listener)); 283 } 284 void NotifyPopPageSuccessDismiss(const std::string& pageUrl, int32_t pageId) const; 285 286 using IsPagePathInvalidEventHandler = std::function<void(bool& isPageInvalid)>; SetIsPagePathInvalidEventHandler(IsPagePathInvalidEventHandler && listener)287 void SetIsPagePathInvalidEventHandler(IsPagePathInvalidEventHandler&& listener) 288 { 289 isPagePathInvalidEventHandler_.push_back(std::move(listener)); 290 } 291 void NotifyIsPagePathInvalidDismiss(bool isPageInvalid) const; 292 293 using DestroyEventHandler = std::function<void()>; SetDestroyHandler(DestroyEventHandler && listener)294 void SetDestroyHandler(DestroyEventHandler&& listener) 295 { 296 destroyEventHandler_.push_back(std::move(listener)); 297 } 298 void NotifyDestroyEventDismiss() const; 299 300 using DispatchTouchEventHandler = std::function<void(const TouchEvent& event)>; SetDispatchTouchEventHandler(DispatchTouchEventHandler && listener)301 void SetDispatchTouchEventHandler(DispatchTouchEventHandler&& listener) 302 { 303 dispatchTouchEventHandler_.push_back(std::move(listener)); 304 } 305 void NotifyDispatchTouchEventDismiss(const TouchEvent& event) const; 306 307 using GetViewScaleCallback = std::function<bool(float&, float&)>; SetGetViewScaleCallback(GetViewScaleCallback && callback)308 void SetGetViewScaleCallback(GetViewScaleCallback&& callback) 309 { 310 getViewScaleCallback_ = callback; 311 } 312 313 using OnPageShowCallBack = std::function<void()>; SetOnPageShow(OnPageShowCallBack && onPageShowCallBack)314 void SetOnPageShow(OnPageShowCallBack&& onPageShowCallBack) 315 { 316 onPageShowCallBack_ = std::move(onPageShowCallBack); 317 } 318 319 using AnimationCallback = std::function<void()>; SetAnimationCallback(AnimationCallback && callback)320 void SetAnimationCallback(AnimationCallback&& callback) 321 { 322 animationCallback_ = std::move(callback); 323 } 324 325 using ProfilerCallback = std::function<void(const std::string&)>; SetOnVsyncProfiler(const ProfilerCallback & callback)326 void SetOnVsyncProfiler(const ProfilerCallback& callback) 327 { 328 onVsyncProfiler_ = callback; 329 } 330 331 using OnRouterChangeCallback = bool (*)(const std::string currentRouterPath); AddRouterChangeCallback(const OnRouterChangeCallback & onRouterChangeCallback)332 void AddRouterChangeCallback(const OnRouterChangeCallback& onRouterChangeCallback) 333 { 334 onRouterChangeCallback_ = onRouterChangeCallback; 335 } 336 337 void onRouterChange(const std::string& url); 338 ResetOnVsyncProfiler()339 void ResetOnVsyncProfiler() 340 { 341 onVsyncProfiler_ = nullptr; 342 } 343 GetViewScale(float & scaleX,float & scaleY)344 bool GetViewScale(float& scaleX, float& scaleY) 345 { 346 if (getViewScaleCallback_) { 347 return getViewScaleCallback_(scaleX, scaleY); 348 } 349 return false; 350 } 351 GetTaskExecutor()352 RefPtr<TaskExecutor> GetTaskExecutor() const 353 { 354 return taskExecutor_; 355 } 356 357 RefPtr<Frontend> GetFrontend() const; 358 GetInstanceId()359 int32_t GetInstanceId() const 360 { 361 return instanceId_; 362 } 363 364 void ClearImageCache(); 365 366 void SetImageCache(const RefPtr<ImageCache>& imageChache); 367 368 RefPtr<ImageCache> GetImageCache() const; 369 GetSharedImageManager()370 const RefPtr<SharedImageManager>& GetSharedImageManager() const 371 { 372 return sharedImageManager_; 373 } 374 SetSharedImageManager(const RefPtr<SharedImageManager> & sharedImageManager)375 void SetSharedImageManager(const RefPtr<SharedImageManager>& sharedImageManager) 376 { 377 sharedImageManager_ = sharedImageManager; 378 } 379 GetWindow()380 Window* GetWindow() 381 { 382 return window_.get(); 383 } 384 GetAssetManager()385 RefPtr<AssetManager> GetAssetManager() const 386 { 387 return assetManager_; 388 } 389 GetMinPlatformVersion()390 int32_t GetMinPlatformVersion() const 391 { 392 return minPlatformVersion_; 393 } 394 SetMinPlatformVersion(int32_t minPlatformVersion)395 void SetMinPlatformVersion(int32_t minPlatformVersion) 396 { 397 minPlatformVersion_ = minPlatformVersion; 398 } 399 SetInstallationFree(int32_t installationFree)400 void SetInstallationFree(int32_t installationFree) 401 { 402 installationFree_ = installationFree; 403 } 404 SetSharePanelCallback(SharePanelCallback && callback)405 void SetSharePanelCallback(SharePanelCallback&& callback) 406 { 407 sharePanelCallback_ = std::move(callback); 408 } 409 FireSharePanelCallback(const std::string & bundleName,const std::string & abilityName)410 void FireSharePanelCallback(const std::string& bundleName, const std::string& abilityName) 411 { 412 if (sharePanelCallback_) { 413 sharePanelCallback_(bundleName, abilityName); 414 } 415 } 416 GetThemeManager()417 RefPtr<ThemeManager> GetThemeManager() const 418 { 419 return themeManager_; 420 } SetThemeManager(RefPtr<ThemeManager> theme)421 void SetThemeManager(RefPtr<ThemeManager> theme) 422 { 423 themeManager_ = std::move(theme); 424 } 425 426 template<typename T> GetTheme()427 RefPtr<T> GetTheme() const 428 { 429 if (themeManager_) { 430 return themeManager_->GetTheme<T>(); 431 } 432 return {}; 433 } 434 GetTextFieldManager()435 const RefPtr<ManagerInterface>& GetTextFieldManager() 436 { 437 return textFieldManager_; 438 } 439 void SetTextFieldManager(const RefPtr<ManagerInterface>& manager); 440 GetFontManager()441 const RefPtr<FontManager>& GetFontManager() const 442 { 443 return fontManager_; 444 } 445 GetDataProviderManager()446 const RefPtr<DataProviderManagerInterface>& GetDataProviderManager() const 447 { 448 return dataProviderManager_; 449 } SetDataProviderManager(const RefPtr<DataProviderManagerInterface> & dataProviderManager)450 void SetDataProviderManager(const RefPtr<DataProviderManagerInterface>& dataProviderManager) 451 { 452 dataProviderManager_ = dataProviderManager; 453 } 454 GetMessageBridge()455 const RefPtr<PlatformBridge>& GetMessageBridge() const 456 { 457 return messageBridge_; 458 } SetMessageBridge(const RefPtr<PlatformBridge> & messageBridge)459 void SetMessageBridge(const RefPtr<PlatformBridge>& messageBridge) 460 { 461 messageBridge_ = messageBridge; 462 } 463 SetIsJsCard(bool isJsCard)464 void SetIsJsCard(bool isJsCard) 465 { 466 isJsCard_ = isJsCard; 467 } 468 SetIsJsPlugin(bool isJsPlugin)469 void SetIsJsPlugin(bool isJsPlugin) 470 { 471 isJsPlugin_ = isJsPlugin; 472 } 473 SetDrawDelegate(std::unique_ptr<DrawDelegate> delegate)474 void SetDrawDelegate(std::unique_ptr<DrawDelegate> delegate) 475 { 476 drawDelegate_ = std::move(delegate); 477 } 478 IsJsCard()479 bool IsJsCard() const 480 { 481 return isJsCard_; 482 } 483 SetIsFormRender(bool isEtsCard)484 void SetIsFormRender(bool isEtsCard) 485 { 486 isFormRender_ = isEtsCard; 487 } 488 IsFormRender()489 bool IsFormRender() const 490 { 491 return isFormRender_; 492 } 493 494 // Get the dp scale which used to covert dp to logic px. GetDipScale()495 double GetDipScale() const 496 { 497 return dipScale_; 498 } 499 500 // Get the widnow design scale used to covert lpx to logic px. GetLogicScale()501 double GetLogicScale() const 502 { 503 return designWidthScale_; 504 } 505 GetFontScale()506 float GetFontScale() const 507 { 508 return fontScale_; 509 } 510 void SetFontScale(float fontScale); 511 GetWindowId()512 int32_t GetWindowId() const 513 { 514 return windowId_; 515 } 516 SetWindowId(int32_t windowId)517 void SetWindowId(int32_t windowId) 518 { 519 windowId_ = windowId; 520 } 521 GetViewScale()522 float GetViewScale() const 523 { 524 return viewScale_; 525 } 526 GetRootWidth()527 double GetRootWidth() const 528 { 529 return rootWidth_; 530 } 531 GetRootHeight()532 double GetRootHeight() const 533 { 534 return rootHeight_; 535 } 536 SetWindowModal(WindowModal modal)537 void SetWindowModal(WindowModal modal) 538 { 539 windowModal_ = modal; 540 } 541 GetWindowModal()542 WindowModal GetWindowModal() const 543 { 544 return windowModal_; 545 } 546 IsFullScreenModal()547 bool IsFullScreenModal() const 548 { 549 return windowModal_ == WindowModal::NORMAL || windowModal_ == WindowModal::SEMI_MODAL_FULL_SCREEN || 550 windowModal_ == WindowModal::CONTAINER_MODAL || isFullWindow_; 551 } 552 SetIsRightToLeft(bool isRightToLeft)553 void SetIsRightToLeft(bool isRightToLeft) 554 { 555 isRightToLeft_ = isRightToLeft; 556 } 557 IsRightToLeft()558 bool IsRightToLeft() const 559 { 560 return isRightToLeft_; 561 } 562 SetEventManager(const RefPtr<EventManager> & eventManager)563 void SetEventManager(const RefPtr<EventManager>& eventManager) 564 { 565 eventManager_ = eventManager; 566 } 567 GetEventManager()568 RefPtr<EventManager> GetEventManager() const 569 { 570 return eventManager_; 571 } 572 GetWindowManager()573 const RefPtr<WindowManager>& GetWindowManager() const 574 { 575 return windowManager_; 576 } 577 IsRebuildFinished()578 bool IsRebuildFinished() const 579 { 580 return isRebuildFinished_; 581 } 582 583 void RequestFrame(); 584 585 void RegisterFont(const std::string& familyName, const std::string& familySrc); 586 587 void TryLoadImageInfo(const std::string& src, std::function<void(bool, int32_t, int32_t)>&& loadCallback); 588 589 RefPtr<OffscreenCanvas> CreateOffscreenCanvas(int32_t width, int32_t height); 590 591 void PostAsyncEvent(TaskExecutor::Task&& task, TaskExecutor::TaskType type = TaskExecutor::TaskType::UI); 592 593 void PostAsyncEvent(const TaskExecutor::Task& task, TaskExecutor::TaskType type = TaskExecutor::TaskType::UI); 594 595 void PostSyncEvent(const TaskExecutor::Task& task, TaskExecutor::TaskType type = TaskExecutor::TaskType::UI); 596 FlushReload()597 virtual void FlushReload() {} FlushBuild()598 virtual void FlushBuild() {} 599 FlushReloadTransition()600 virtual void FlushReloadTransition() {} GetFrontendType()601 FrontendType GetFrontendType() const 602 { 603 return frontendType_; 604 } 605 GetDensity()606 double GetDensity() const 607 { 608 return density_; 609 } 610 GetPlatformResRegister()611 RefPtr<PlatformResRegister> GetPlatformResRegister() const 612 { 613 return platformResRegister_; 614 } 615 616 void SetTouchPipeline(const WeakPtr<PipelineBase>& context); 617 void RemoveTouchPipeline(const WeakPtr<PipelineBase>& context); 618 619 void OnVirtualKeyboardAreaChange(Rect keyboardArea); 620 621 using virtualKeyBoardCallback = std::function<bool(int32_t, int32_t, double)>; SetVirtualKeyBoardCallback(virtualKeyBoardCallback && listener)622 void SetVirtualKeyBoardCallback(virtualKeyBoardCallback&& listener) 623 { 624 virtualKeyBoardCallback_.push_back(std::move(listener)); 625 } NotifyVirtualKeyBoard(int32_t width,int32_t height,double keyboard)626 bool NotifyVirtualKeyBoard(int32_t width, int32_t height, double keyboard) const 627 { 628 bool isConsume = false; 629 for (const auto& iterVirtualKeyBoardCallback : virtualKeyBoardCallback_) { 630 if (iterVirtualKeyBoardCallback && iterVirtualKeyBoardCallback(width, height, keyboard)) { 631 isConsume = true; 632 } 633 } 634 return isConsume; 635 } 636 637 using configChangedCallback = std::function<void()>; SetConfigChangedCallback(configChangedCallback && listener)638 void SetConfigChangedCallback(configChangedCallback&& listener) 639 { 640 configChangedCallback_.push_back(std::move(listener)); 641 } 642 NotifyConfigurationChange()643 void NotifyConfigurationChange() 644 { 645 for (const auto& callback : configChangedCallback_) { 646 if (callback) { 647 callback(); 648 } 649 } 650 } 651 652 using PostRTTaskCallback = std::function<void(std::function<void()>&&)>; SetPostRTTaskCallBack(PostRTTaskCallback && callback)653 void SetPostRTTaskCallBack(PostRTTaskCallback&& callback) 654 { 655 postRTTaskCallback_ = std::move(callback); 656 } 657 PostTaskToRT(std::function<void ()> && task)658 void PostTaskToRT(std::function<void()>&& task) 659 { 660 if (postRTTaskCallback_) { 661 postRTTaskCallback_(std::move(task)); 662 } 663 } 664 665 void SetGetWindowRectImpl(std::function<Rect()>&& callback); 666 667 Rect GetCurrentWindowRect() const; 668 SetPluginOffset(const Offset & offset)669 void SetPluginOffset(const Offset& offset) 670 { 671 pluginOffset_ = offset; 672 } 673 GetPluginOffset()674 Offset GetPluginOffset() const 675 { 676 return pluginOffset_; 677 } 678 SetPluginEventOffset(const Offset & offset)679 void SetPluginEventOffset(const Offset& offset) 680 { 681 pluginEventOffset_ = offset; 682 } 683 GetPluginEventOffset()684 Offset GetPluginEventOffset() const 685 { 686 return pluginEventOffset_; 687 } NotifyMemoryLevel(int32_t level)688 virtual void NotifyMemoryLevel(int32_t level) {} 689 SetDisplayWindowRectInfo(const Rect & displayWindowRectInfo)690 void SetDisplayWindowRectInfo(const Rect& displayWindowRectInfo) 691 { 692 displayWindowRectInfo_ = displayWindowRectInfo; 693 } 694 695 virtual void SetContainerWindow(bool isShow) = 0; 696 697 // This method can get the coordinates and size of the current window, 698 // which can be added to the return value of the GetGlobalOffset method to get the window coordinates of the node. GetDisplayWindowRectInfo()699 const Rect& GetDisplayWindowRectInfo() const 700 { 701 return displayWindowRectInfo_; 702 } 703 virtual void FlushMessages() = 0; 704 705 virtual void FlushUITasks() = 0; 706 707 virtual void FlushPipelineImmediately() = 0; 708 709 // for sync animation only GetSyncAnimationOption()710 AnimationOption GetSyncAnimationOption() 711 { 712 return animationOption_; 713 } 714 SetSyncAnimationOption(const AnimationOption & option)715 void SetSyncAnimationOption(const AnimationOption& option) 716 { 717 animationOption_ = option; 718 } 719 SetNextFrameLayoutCallback(std::function<void ()> && callback)720 void SetNextFrameLayoutCallback(std::function<void()>&& callback) 721 { 722 nextFrameLayoutCallback_ = std::move(callback); 723 } 724 SetForegroundCalled(bool isForegroundCalled)725 void SetForegroundCalled(bool isForegroundCalled) 726 { 727 isForegroundCalled_ = isForegroundCalled; 728 } 729 SetIsSubPipeline(bool isSubPipeline)730 void SetIsSubPipeline(bool isSubPipeline) 731 { 732 isSubPipeline_ = isSubPipeline; 733 } 734 IsSubPipeline()735 bool IsSubPipeline() const 736 { 737 return isSubPipeline_; 738 } 739 SetParentPipeline(const WeakPtr<PipelineBase> & pipeline)740 void SetParentPipeline(const WeakPtr<PipelineBase>& pipeline) 741 { 742 parentPipeline_ = pipeline; 743 } 744 745 void AddEtsCardTouchEventCallback(int32_t ponitId, EtsCardTouchEventCallback&& callback); 746 747 void HandleEtsCardTouchEvent(const TouchEvent& point); 748 749 void RemoveEtsCardTouchEventCallback(int32_t ponitId); 750 751 protected: TryCallNextFrameLayoutCallback()752 void TryCallNextFrameLayoutCallback() 753 { 754 if (isForegroundCalled_ && nextFrameLayoutCallback_) { 755 isForegroundCalled_ = false; 756 nextFrameLayoutCallback_(); 757 LOGI("nextFrameLayoutCallback called"); 758 } 759 } 760 OnDumpInfo(const std::vector<std::string> & params)761 virtual bool OnDumpInfo(const std::vector<std::string>& params) const 762 { 763 return false; 764 } 765 virtual void FlushVsync(uint64_t nanoTimestamp, uint32_t frameCount) = 0; 766 virtual void SetRootRect(double width, double height, double offset = 0.0) = 0; 767 virtual void FlushPipelineWithoutAnimation() = 0; 768 OnVirtualKeyboardHeightChange(float keyboardHeight)769 virtual void OnVirtualKeyboardHeightChange(float keyboardHeight) {} 770 771 void UpdateRootSizeAndScale(int32_t width, int32_t height); 772 773 std::list<configChangedCallback> configChangedCallback_; 774 std::list<virtualKeyBoardCallback> virtualKeyBoardCallback_; 775 776 bool isRebuildFinished_ = false; 777 bool isJsCard_ = false; 778 bool isFormRender_ = false; 779 bool isRightToLeft_ = false; 780 bool isFullWindow_ = false; 781 bool installationFree_ = false; 782 bool isSubPipeline_ = false; 783 784 bool isJsPlugin_ = false; 785 int32_t minPlatformVersion_ = 0; 786 int32_t windowId_ = 0; 787 int32_t appLabelId_ = 0; 788 float fontScale_ = 1.0f; 789 float designWidthScale_ = 1.0f; 790 float viewScale_ = 1.0f; 791 double density_ = 1.0; 792 double dipScale_ = 1.0; 793 double rootHeight_ = 0.0; 794 double rootWidth_ = 0.0; 795 FrontendType frontendType_; 796 WindowModal windowModal_ = WindowModal::NORMAL; 797 798 Offset pluginOffset_ { 0, 0 }; 799 Offset pluginEventOffset_ { 0, 0 }; 800 Color appBgColor_ = Color::WHITE; 801 802 std::unique_ptr<DrawDelegate> drawDelegate_; 803 std::stack<bool> pendingImplicitLayout_; 804 std::unique_ptr<Window> window_; 805 RefPtr<TaskExecutor> taskExecutor_; 806 RefPtr<AssetManager> assetManager_; 807 WeakPtr<Frontend> weakFrontend_; 808 int32_t instanceId_ = 0; 809 RefPtr<EventManager> eventManager_; 810 RefPtr<ImageCache> imageCache_; 811 RefPtr<SharedImageManager> sharedImageManager_; 812 mutable std::shared_mutex imageCacheMutex_; 813 RefPtr<ThemeManager> themeManager_; 814 RefPtr<DataProviderManagerInterface> dataProviderManager_; 815 RefPtr<FontManager> fontManager_; 816 RefPtr<ManagerInterface> textFieldManager_; 817 RefPtr<PlatformBridge> messageBridge_; 818 RefPtr<WindowManager> windowManager_; 819 OnPageShowCallBack onPageShowCallBack_; 820 AnimationCallback animationCallback_; 821 ProfilerCallback onVsyncProfiler_; 822 FinishEventHandler finishEventHandler_; 823 StartAbilityHandler startAbilityHandler_; 824 ActionEventHandler actionEventHandler_; 825 RefPtr<PlatformResRegister> platformResRegister_; 826 827 WeakPtr<PipelineBase> parentPipeline_; 828 829 std::vector<WeakPtr<PipelineBase>> touchPluginPipelineContext_; 830 std::unordered_map<int32_t, EtsCardTouchEventCallback> etsCardTouchEventCallback_; 831 832 RefPtr<Clipboard> clipboard_; 833 std::function<void(const std::string&)> clipboardCallback_ = nullptr; 834 Rect displayWindowRectInfo_; 835 AnimationOption animationOption_; 836 837 std::function<void()> nextFrameLayoutCallback_ = nullptr; 838 SharePanelCallback sharePanelCallback_ = nullptr; 839 std::atomic<bool> isForegroundCalled_ = false; 840 841 private: 842 void DumpFrontend() const; 843 StatusBarEventHandler statusBarBgColorEventHandler_; 844 PopupEventHandler popupEventHandler_; 845 RouterBackEventHandler routerBackEventHandler_; 846 std::list<PopPageSuccessEventHandler> popPageSuccessEventHandler_; 847 std::list<IsPagePathInvalidEventHandler> isPagePathInvalidEventHandler_; 848 std::list<DestroyEventHandler> destroyEventHandler_; 849 std::list<DispatchTouchEventHandler> dispatchTouchEventHandler_; 850 GetViewScaleCallback getViewScaleCallback_; 851 // OnRouterChangeCallback is function point, need to be initialized. 852 OnRouterChangeCallback onRouterChangeCallback_ = nullptr; 853 PostRTTaskCallback postRTTaskCallback_; 854 std::atomic_flag isDumping_ = ATOMIC_FLAG_INIT; 855 ACE_DISALLOW_COPY_AND_MOVE(PipelineBase); 856 }; 857 858 } // namespace OHOS::Ace 859 860 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_PIPELINE_PIPELINE_BASE_H 861