1 /* 2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_PIPELINE_CONTEXT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_PIPELINE_CONTEXT_H 18 19 #include <list> 20 #include <map> 21 #include <memory> 22 #include <queue> 23 #include <set> 24 #include <unordered_map> 25 #include <utility> 26 #include <thread> 27 28 #include "base/geometry/dimension.h" 29 #include "base/geometry/offset.h" 30 #include "base/geometry/rect.h" 31 #include "base/image/pixel_map.h" 32 #include "base/memory/ace_type.h" 33 #include "base/resource/asset_manager.h" 34 #include "base/resource/data_provider_manager.h" 35 #include "base/thread/task_executor.h" 36 #include "base/utils/macros.h" 37 #include "base/utils/noncopyable.h" 38 #include "core/animation/flush_event.h" 39 #include "core/animation/page_transition_listener.h" 40 #include "core/animation/schedule_task.h" 41 #include "core/common/event_manager.h" 42 #include "core/common/focus_animation_manager.h" 43 #include "core/common/platform_res_register.h" 44 #include "core/components/box/drag_drop_event.h" 45 #include "core/components/common/properties/color.h" 46 #include "core/components/dialog/dialog_properties.h" 47 #include "core/components/page/page_component.h" 48 #include "core/components/text_overlay/text_overlay_manager.h" 49 #include "core/components/theme/theme_manager.h" 50 #include "core/event/event_trigger.h" 51 #include "core/gestures/gesture_info.h" 52 #include "core/image/image_cache.h" 53 #include "core/pipeline/base/composed_component.h" 54 #include "core/pipeline/base/factories/render_factory.h" 55 #include "core/pipeline/pipeline_base.h" 56 #ifndef WEARABLE_PRODUCT 57 #include "core/event/multimodal/multimodal_manager.h" 58 #include "core/event/multimodal/multimodal_subscriber.h" 59 #endif 60 #include "core/common/clipboard/clipboard_proxy.h" 61 62 namespace OHOS::Rosen { 63 class RSUIDirector; 64 } // namespace OHOS::Rosen 65 66 namespace OHOS::Ace { 67 68 class CardTransitionController; 69 class ComposedElement; 70 class FontManager; 71 class OverlayElement; 72 class RenderNode; 73 class RenderFocusAnimation; 74 class RootElement; 75 class SharedTransitionController; 76 class StageElement; 77 class StackElement; 78 class Window; 79 class Animator; 80 class ManagerInterface; 81 class AccessibilityManager; 82 class RenderContext; 83 struct PageTarget; 84 class DialogComponent; 85 class SelectPopupComponent; 86 class RenderElement; 87 88 struct WindowBlurInfo { 89 float progress_; 90 WindowBlurStyle style_; 91 RRect innerRect_; 92 std::vector<RRect> coords_; 93 }; 94 95 struct VisibleCallbackInfo { 96 VisibleRatioCallback callback; 97 double visibleRatio = 1.0; 98 bool isCurrentVisible = false; 99 }; 100 101 using OnRouterChangeCallback = bool (*)(const std::string currentRouterPath); 102 using SubscribeCtrlACallback = std::function<void()>; 103 104 class ACE_EXPORT PipelineContext : public PipelineBase { 105 DECLARE_ACE_TYPE(PipelineContext, PipelineBase); 106 107 public: 108 static constexpr int32_t DEFAULT_HOVER_ENTER_ANIMATION_ID = -1; 109 using TimeProvider = std::function<int64_t(void)>; 110 using SurfaceChangedCallbackMap = 111 std::unordered_map<int32_t, std::function<void(int32_t, int32_t, int32_t, int32_t, WindowSizeChangeReason)>>; 112 using SurfacePositionChangedCallbackMap = std::unordered_map<int32_t, std::function<void(int32_t, int32_t)>>; 113 114 PipelineContext(std::shared_ptr<Window> window, RefPtr<TaskExecutor> taskExecutor, 115 RefPtr<AssetManager> assetManager, RefPtr<PlatformResRegister> platformResRegister, 116 const RefPtr<Frontend>& frontend, int32_t instanceId); 117 PipelineContext(std::shared_ptr<Window> window, RefPtr<TaskExecutor>& taskExecutor, 118 RefPtr<AssetManager> assetManager, const RefPtr<Frontend>& frontend); 119 120 ~PipelineContext() override; 121 122 void SetupRootElement() override; 123 124 // This is used for subwindow, when the subwindow is created,a new subRootElement will be built 125 RefPtr<Element> SetupSubRootElement(); 126 RefPtr<DialogComponent> ShowDialog( 127 const DialogProperties& dialogProperties, bool isRightToLeft, const std::string& inspectorTag = ""); 128 void CloseContextMenu(); 129 void GetBoundingRectData(int32_t nodeId, Rect& rect) override; 130 131 void PushVisibleCallback(int32_t nodeId, double ratio, std::function<void(bool, double)>&& callback); 132 void RemoveVisibleChangeNode(int32_t nodeId); 133 134 void PushPage(const RefPtr<PageComponent>& pageComponent, const RefPtr<StageElement>& stage); 135 void PushPage(const RefPtr<PageComponent>& pageComponent); 136 void PostponePageTransition() override; 137 void LaunchPageTransition() override; 138 139 bool CanPushPage(); 140 141 bool IsTransitionStop() const; 142 143 void PopPage(); 144 145 void PopToPage(int32_t pageId); 146 147 void RestorePopPage(const RefPtr<PageComponent>& pageComponent); 148 149 bool CanPopPage(); 150 151 void ReplacePage(const RefPtr<PageComponent>& pageComponent, const RefPtr<StageElement>& stage, 152 const std::function<void()>& listener = nullptr); 153 void ReplacePage(const RefPtr<PageComponent>& pageComponent); 154 155 bool CanReplacePage(); 156 157 bool ClearInvisiblePages(const std::function<void()>& listener = nullptr); 158 159 bool CallRouterBackToPopPage() override; 160 161 void SetSinglePageId(int32_t pageId); 162 163 bool PopPageStackOverlay() override; 164 165 void HideOverlays() override; 166 167 void NotifyAppStorage(const std::string& key, const std::string& value); 168 169 RefPtr<StackElement> GetLastStack() const; 170 171 RefPtr<PageElement> GetLastPage() const; 172 173 RefPtr<RenderNode> GetLastPageRender() const; 174 175 void ScheduleUpdate(const RefPtr<ComposedComponent>& composed); 176 177 void AddComposedElement(const ComposeId& id, const RefPtr<ComposedElement>& element); 178 179 void RemoveComposedElement(const ComposeId& id, const RefPtr<ComposedElement>& element); 180 181 void AddDirtyElement(const RefPtr<Element>& dirtyElement); 182 183 void AddNeedRebuildFocusElement(const RefPtr<Element>& focusElement); 184 185 void AddDirtyRenderNode(const RefPtr<RenderNode>& renderNode, bool overlay = false); 186 187 void AddNeedRenderFinishNode(const RefPtr<RenderNode>& renderNode); 188 189 void AddDirtyLayoutNode(const RefPtr<RenderNode>& renderNode); 190 191 void AddPredictLayoutNode(const RefPtr<RenderNode>& renderNode); 192 193 void AddGeometryChangedNode(const RefPtr<RenderNode>& renderNode); 194 195 void AddPreFlushListener(const RefPtr<FlushEvent>& listener); 196 197 void AddPostAnimationFlushListener(const RefPtr<FlushEvent>& listener); 198 199 void AddPostFlushListener(const RefPtr<FlushEvent>& listener); 200 201 void AddPageUpdateTask(std::function<void()>&& task, bool directExecute = false); 202 203 void SetRequestedRotationNode(const WeakPtr<RenderNode>& renderNode); 204 205 void RemoveRequestedRotationNode(const WeakPtr<RenderNode>& renderNode); 206 207 // add schedule task and return the unique mark id. 208 uint32_t AddScheduleTask(const RefPtr<ScheduleTask>& task) override; 209 210 // remove schedule task by id. 211 void RemoveScheduleTask(uint32_t id) override; 212 213 // Called by view when touch event received. 214 void OnTouchEvent(const TouchEvent& point, bool isSubPipe = false) override; 215 216 // Called by container when key event received. 217 // if return false, then this event needs platform to handle it. 218 bool OnKeyEvent(const KeyEvent& event) override; 219 220 // Called by view when mouse event received. 221 void OnMouseEvent(const MouseEvent& event) override; 222 223 // Called by view when axis event received. 224 void OnAxisEvent(const AxisEvent& event) override; 225 226 // Called by container when rotation event received. 227 // if return false, then this event needs platform to handle it. 228 bool OnRotationEvent(const RotationEvent& event) const override; 229 230 // Called by view when idle event. 231 void OnIdle(int64_t deadline) override; 232 233 void OnVirtualKeyboardHeightChange( 234 float keyboardHeight, const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr) override; 235 236 // Set card position for barrierFree 237 void SetCardViewPosition(int id, float offsetX, float offsetY); 238 239 void SetCardViewAccessibilityParams(const std::string& key, bool focus); 240 241 void FlushPipelineImmediately() override; 242 RegisterEventHandler(const RefPtr<AceEventHandler> & handler)243 void RegisterEventHandler(const RefPtr<AceEventHandler>& handler) 244 { 245 eventTrigger_.RegisterEventHandler(handler); 246 } 247 248 template<class... Args> FireAsyncEvent(const EventMarker & marker,Args &&...args)249 void FireAsyncEvent(const EventMarker& marker, Args&&... args) 250 { 251 eventTrigger_.TriggerAsyncEvent(marker, std::forward<Args>(args)...); 252 } 253 254 template<class... Args> FireSyncEvent(const EventMarker & marker,Args &&...args)255 void FireSyncEvent(const EventMarker& marker, Args&&... args) 256 { 257 eventTrigger_.TriggerSyncEvent(marker, std::forward<Args>(args)...); 258 } 259 260 void OnSurfaceChanged( 261 int32_t width, int32_t height, WindowSizeChangeReason type = WindowSizeChangeReason::UNDEFINED, 262 const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr) override; 263 264 void OnSurfacePositionChanged(int32_t posX, int32_t posY) override; 265 266 void WindowSizeChangeAnimate(int32_t width, int32_t height, WindowSizeChangeReason type, 267 const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr); 268 269 void OnSurfaceDensityChanged(double density) override; 270 271 void OnSystemBarHeightChanged(double statusBar, double navigationBar) override; 272 273 void OnSurfaceDestroyed() override; 274 275 // SemiModal and DialogModal have their own enter/exit animation and will exit after animation done. 276 void Finish(bool autoFinish = true) const override; 277 278 void RequestFullWindow(int32_t duration) override; 279 280 // Get the font scale used to covert fp to logic px. GetFontUnitScale()281 double GetFontUnitScale() const 282 { 283 return dipScale_ * fontScale_; 284 } 285 286 RefPtr<RenderNode> DragTestAll(const TouchEvent& point); 287 RefPtr<RenderNode> DragTest(const TouchEvent& point, const RefPtr<RenderNode>& renderNode, int32_t deep); 288 SetRootHeight(double rootHeight)289 void SetRootHeight(double rootHeight) 290 { 291 if (rootHeight > 0.0) { 292 rootHeight_ = rootHeight; 293 } 294 } 295 296 Rect GetRootRect() const; 297 Rect GetStageRect() const; 298 Rect GetPageRect() const; 299 IsSurfaceReady()300 bool IsSurfaceReady() const 301 { 302 return isSurfaceReady_; 303 } 304 305 void ShowFocusAnimation( 306 const RRect& rrect, const Color& color, const Offset& offset, bool isIndented = false) const; 307 308 void ShowFocusAnimation(const RRect& rrect, const Color& color, const Offset& offset, const Rect& clipRect) const; 309 310 void ShowShadow(const RRect& rrect, const Offset& offset) const; 311 312 void ShowShadow(const RRect& rrect, const Offset& offset, const Rect& clipRect) const; 313 314 RefPtr<RenderFocusAnimation> GetRenderFocusAnimation() const; 315 316 void PushFocusAnimation(const RefPtr<Element>& element) const; 317 318 void PushShadow(const RefPtr<Element>& element) const; 319 320 void PopFocusAnimation() const; 321 322 void PopRootFocusAnimation() const; 323 324 void PopShadow() const; 325 326 void CancelFocusAnimation() const; 327 328 void CancelShadow() const; 329 330 void SetUseRootAnimation(bool useRoot); 331 332 void AddDirtyFocus(const RefPtr<FocusNode>& node); 333 334 void RefreshStageFocus(); 335 336 void ShowContainerTitle(bool isShow, bool hasDeco = true, bool needUpdate = false) override; 337 338 void SetContainerButtonHide(bool hideSplit, bool hideMaximize, bool hideMinimize) override; 339 340 RefPtr<StageElement> GetStageElement() const; 341 342 RefPtr<ComposedElement> GetComposedElementById(const ComposeId& id); 343 344 void SendCallbackMessageToFrontend(const std::string& callbackId, const std::string& data); 345 346 void SendEventToFrontend(const EventMarker& eventMarker); 347 348 void SendEventToFrontend(const EventMarker& eventMarker, const std::string& param); 349 350 bool AccessibilityRequestFocus(const ComposeId& id); 351 352 bool RequestFocus(const RefPtr<Element>& targetElement); 353 bool RequestFocus(const std::string& targetNodeId) override; 354 bool RequestDefaultFocus(); 355 NeedSoftKeyboard()356 bool NeedSoftKeyboard() override 357 { 358 return false; 359 } 360 SetOnWindowFocused(const std::function<void ()> & callback)361 void SetOnWindowFocused(const std::function<void()>& callback) override {}; 362 363 BaseId::IdType AddPageTransitionListener(const PageTransitionListenable::CallbackFuncType& funcObject); 364 365 const RefPtr<OverlayElement> GetOverlayElement() const; 366 367 void RemovePageTransitionListener(typename BaseId::IdType id); 368 369 void ClearPageTransitionListeners(); 370 371 void Destroy() override; 372 373 bool IsLastPage() override; 374 375 RefPtr<Element> GetDeactivateElement(int32_t componentId) const; 376 377 void ClearDeactivateElements(); 378 379 void AddDeactivateElement(int32_t id, const RefPtr<Element>& element); 380 GetRenderFactory()381 const RefPtr<RenderFactory>& GetRenderFactory() const 382 { 383 return renderFactory_; 384 } 385 386 #ifndef WEARABLE_PRODUCT 387 void SetMultimodalSubscriber(const RefPtr<MultimodalSubscriber>& multimodalSubscriber); 388 GetMultiModalManager()389 const RefPtr<MultiModalManager>& GetMultiModalManager() const 390 { 391 return multiModalManager_; 392 } 393 #endif 394 395 void SetWindowOnShow(); 396 397 void SetWindowOnHide(); 398 399 void OnShow() override; 400 401 void OnHide() override; 402 MarkForcedRefresh()403 void MarkForcedRefresh() 404 { 405 needForcedRefresh_ = true; 406 } 407 408 void SetTimeProvider(TimeProvider&& timeProvider); 409 410 uint64_t GetTimeFromExternalTimer() override; 411 412 void AddFontNode(const WeakPtr<RenderNode>& node); 413 414 void RemoveFontNode(const WeakPtr<RenderNode>& node); 415 416 void LoadSystemFont(const std::function<void()>& onFondsLoaded); 417 GetSharedTransitionController()418 const RefPtr<SharedTransitionController>& GetSharedTransitionController() const 419 { 420 return sharedTransitionController_; 421 } 422 GetCardTransitionController()423 const RefPtr<CardTransitionController>& GetCardTransitionController() const 424 { 425 return cardTransitionController_; 426 } 427 428 void SetClickPosition(const Offset& position) const; 429 430 void RootLostFocus(BlurReason reason = BlurReason::FOCUS_SWITCH) const; 431 432 void FlushFocus(); 433 434 void WindowFocus(bool isFocus) override; 435 436 void ContainerModalUnFocus() override; 437 438 void OnPageShow() override; 439 GetStatusBarHeight()440 double GetStatusBarHeight() const 441 { 442 return statusBarHeight_; 443 } 444 GetNavigationBarHeight()445 double GetNavigationBarHeight() const 446 { 447 return navigationBarHeight_; 448 } 449 SetAppearingDuration(int32_t duration)450 void SetAppearingDuration(int32_t duration) 451 { 452 cardAppearingDuration_ = duration; 453 } 454 GetAppearingDuration()455 int32_t GetAppearingDuration() const 456 { 457 return cardAppearingDuration_; 458 } 459 SetModalHeight(int32_t height)460 void SetModalHeight(int32_t height) 461 { 462 modalHeight_ = height; 463 } 464 SetModalColor(uint32_t color)465 void SetModalColor(uint32_t color) 466 { 467 modalColor_ = color; 468 } 469 470 void MovePage(const Offset& rootRect, double offsetHeight); 471 SetBuildAfterCallback(const std::function<void ()> & callback)472 void SetBuildAfterCallback(const std::function<void()>& callback) override 473 { 474 buildAfterCallback_.emplace_back(callback); 475 } 476 477 void SetIsKeyEvent(bool isKeyEvent); 478 IsKeyEvent()479 bool IsKeyEvent() const 480 { 481 return isKeyEvent_; 482 } 483 484 void RefreshRootBgColor() const override; 485 void AddToHoverList(const RefPtr<RenderNode>& node); 486 487 using UpdateWindowBlurRegionHandler = std::function<void(const std::vector<std::vector<float>>&)>; 488 SetUpdateWindowBlurRegionHandler(UpdateWindowBlurRegionHandler handler)489 void SetUpdateWindowBlurRegionHandler(UpdateWindowBlurRegionHandler handler) 490 { 491 updateWindowBlurRegionHandler_ = std::move(handler); 492 } 493 494 using DragEventHandler = std::function<void(const std::string&, const RefPtr<PixelMap>& pixmap)>; 495 SetDragEventHandler(DragEventHandler && callback)496 void SetDragEventHandler(DragEventHandler&& callback) 497 { 498 dragEventHandler_ = callback; 499 } 500 501 using InitDragEventListener = std::function<void()>; 502 SetInitDragListener(InitDragEventListener && callback)503 void SetInitDragListener(InitDragEventListener&& callback) 504 { 505 initDragEventListener_ = callback; 506 } 507 508 void UpdateWindowBlurRegion( 509 int32_t id, RRect rRect, float progress, WindowBlurStyle style, const std::vector<RRect>& coords); 510 511 void ClearWindowBlurRegion(int32_t id); 512 IsBuildingFirstPage()513 bool IsBuildingFirstPage() const 514 { 515 return buildingFirstPage_; 516 } 517 518 using UpdateWindowBlurDrawOpHandler = std::function<void(void)>; 519 SetUpdateWindowBlurDrawOpHandler(UpdateWindowBlurDrawOpHandler handler)520 void SetUpdateWindowBlurDrawOpHandler(UpdateWindowBlurDrawOpHandler handler) 521 { 522 updateWindowBlurDrawOpHandler_ = std::move(handler); 523 } 524 525 void NavigatePage(uint8_t type, const PageTarget& target, const std::string& params); 526 527 void AddKeyFrame( 528 float fraction, const RefPtr<Curve>& curve, const std::function<void()>& propertyCallback) override; 529 530 void AddKeyFrame(float fraction, const std::function<void()>& propertyCallback) override; 531 532 void SaveExplicitAnimationOption(const AnimationOption& option) override; 533 534 void CreateExplicitAnimator(const std::function<void()>& onFinishEvent) override; 535 536 void ClearExplicitAnimationOption() override; 537 538 AnimationOption GetExplicitAnimationOption() const override; 539 540 void FlushBuild() override; 541 SetUseLiteStyle(bool useLiteStyle)542 void SetUseLiteStyle(bool useLiteStyle) 543 { 544 useLiteStyle_ = useLiteStyle; 545 } 546 UseLiteStyle()547 bool UseLiteStyle() const 548 { 549 return useLiteStyle_; 550 } 551 GetDirtyRect()552 const Rect& GetDirtyRect() const 553 { 554 return dirtyRect_; 555 } 556 557 bool GetIsDeclarative() const override; 558 IsForbidPlatformQuit()559 bool IsForbidPlatformQuit() const 560 { 561 return forbidPlatformQuit_; 562 } 563 564 void SetForbidPlatformQuit(bool forbidPlatformQuit); 565 566 void SetAppBgColor(const Color& color) override; 567 SetPhotoCachePath(const std::string & photoCachePath)568 void SetPhotoCachePath(const std::string& photoCachePath) 569 { 570 photoCachePath_ = photoCachePath; 571 } 572 GetPhotoCachePath()573 const std::string& GetPhotoCachePath() 574 { 575 return photoCachePath_; 576 } 577 SetScreenOnCallback(std::function<void (std::function<void ()> && func)> && screenOnCallback)578 void SetScreenOnCallback(std::function<void(std::function<void()>&& func)>&& screenOnCallback) 579 { 580 screenOnCallback_ = std::move(screenOnCallback); 581 } 582 SetScreenOffCallback(std::function<void (std::function<void ()> && func)> && screenOffCallback)583 void SetScreenOffCallback(std::function<void(std::function<void()>&& func)>&& screenOffCallback) 584 { 585 screenOffCallback_ = std::move(screenOffCallback); 586 } 587 588 void AddScreenOnEvent(std::function<void()>&& func); 589 void AddScreenOffEvent(std::function<void()>&& func); 590 void AddAlignDeclarationNode(const RefPtr<RenderNode>& node); 591 void AddLayoutTransitionNode(const RefPtr<RenderNode>& node); 592 std::list<RefPtr<RenderNode>>& GetAlignDeclarationNodeList(); SetQueryIfWindowInScreenCallback(std::function<void ()> && func)593 void SetQueryIfWindowInScreenCallback(std::function<void()>&& func) 594 { 595 queryIfWindowInScreenCallback_ = std::move(func); 596 } SetIsWindowInScreen(bool isWindowInScreen)597 void SetIsWindowInScreen(bool isWindowInScreen) 598 { 599 isWindowInScreen_ = isWindowInScreen; 600 } 601 // This interface posts an async task to do async query and returns the result from previous query. 602 bool IsWindowInScreen(); 603 void NotifyOnPreDraw() override; 604 void AddNodesToNotifyOnPreDraw(const RefPtr<RenderNode>& renderNode); 605 606 void UpdateNodesNeedDrawOnPixelMap(); 607 void SearchNodesNeedDrawOnPixelMap(const RefPtr<RenderNode>& renderNode); 608 void NotifyDrawOnPixelMap(); 609 GetRootElement()610 const RefPtr<RootElement>& GetRootElement() const 611 { 612 return rootElement_; 613 } 614 SetAccessibilityEnabled(bool isEnabled)615 void SetAccessibilityEnabled(bool isEnabled) 616 { 617 isAccessibilityEnabled_ = isEnabled; 618 } IsAccessibilityEnabled()619 bool IsAccessibilityEnabled() const 620 { 621 return isAccessibilityEnabled_ || IsVisibleChangeNodeExists(-1); 622 } 623 624 bool IsVisibleChangeNodeExists(NodeId index) const; 625 RegisterSurfaceChangedCallback(std::function<void (int32_t,int32_t,int32_t,int32_t,WindowSizeChangeReason)> && callback)626 int32_t RegisterSurfaceChangedCallback( 627 std::function<void(int32_t, int32_t, int32_t, int32_t, WindowSizeChangeReason)>&& callback) 628 { 629 if (callback) { 630 surfaceChangedCallbackMap_.emplace(++callbackId_, std::move(callback)); 631 return callbackId_; 632 } 633 return 0; 634 } 635 UnregisterSurfaceChangedCallback(int32_t callbackId)636 void UnregisterSurfaceChangedCallback(int32_t callbackId) 637 { 638 surfaceChangedCallbackMap_.erase(callbackId); 639 } 640 RegisterSurfacePositionChangedCallback(std::function<void (int32_t,int32_t)> && callback)641 int32_t RegisterSurfacePositionChangedCallback(std::function<void(int32_t, int32_t)>&& callback) 642 { 643 if (callback) { 644 surfacePositionChangedCallbackMap_.emplace(++callbackId_, std::move(callback)); 645 return callbackId_; 646 } 647 return 0; 648 } 649 UnregisterSurfacePositionChangedCallback(int32_t callbackId)650 void UnregisterSurfacePositionChangedCallback(int32_t callbackId) 651 { 652 surfacePositionChangedCallbackMap_.erase(callbackId); 653 } 654 void StartSystemDrag(const std::string& str, const RefPtr<PixelMap>& pixmap); 655 void InitDragListener(); 656 void OnDragEvent(const PointerEvent& pointerEvent, DragEventAction action) override; 657 void SetPreTargetRenderNode(const RefPtr<DragDropEvent>& preDragDropNode); 658 const RefPtr<DragDropEvent>& GetPreTargetRenderNode() const; 659 void SetInitRenderNode(const RefPtr<RenderNode>& initRenderNode); 660 const RefPtr<RenderNode>& GetInitRenderNode() const; 661 SetContextMenu(const RefPtr<Component> & contextMenu)662 void SetContextMenu(const RefPtr<Component>& contextMenu) 663 { 664 contextMenu_ = contextMenu; 665 } 666 667 void SetClipHole(double left, double top, double width, double height); 668 GetTransparentHole()669 const Rect& GetTransparentHole() const 670 { 671 return transparentHole_; 672 } 673 GetHasMeetSubWindowNode()674 bool GetHasMeetSubWindowNode() const 675 { 676 return hasMeetSubWindowNode_; 677 } 678 SetHasMeetSubWindowNode(bool hasMeetSubWindowNode)679 void SetHasMeetSubWindowNode(bool hasMeetSubWindowNode) 680 { 681 hasMeetSubWindowNode_ = hasMeetSubWindowNode; 682 } 683 GetHasClipHole()684 bool GetHasClipHole() const 685 { 686 return hasClipHole_; 687 } 688 SetHasClipHole(bool hasClipHole)689 void SetHasClipHole(bool hasClipHole) 690 { 691 hasClipHole_ = hasClipHole; 692 } 693 GetIsHoleValid()694 bool GetIsHoleValid() const 695 { 696 return isHoleValid_; 697 } 698 699 void SetRSUIDirector(std::shared_ptr<OHOS::Rosen::RSUIDirector> rsUIDirector); 700 701 std::shared_ptr<OHOS::Rosen::RSUIDirector> GetRSUIDirector(); 702 IsShiftDown()703 bool IsShiftDown() const 704 { 705 return isShiftDown_; 706 } 707 MarkIsShiftDown(bool isShiftDown)708 void MarkIsShiftDown(bool isShiftDown) 709 { 710 isShiftDown_ = isShiftDown; 711 } 712 IsCtrlDown()713 bool IsCtrlDown() const 714 { 715 return isCtrlDown_; 716 } 717 MarkIsCtrlDown(bool isCtrlDown)718 void MarkIsCtrlDown(bool isCtrlDown) 719 { 720 isCtrlDown_ = isCtrlDown; 721 } 722 IsKeyboardA()723 bool IsKeyboardA() const 724 { 725 return isKeyboardA_; 726 } 727 MarkIsKeyboardA(bool isKeyboardA)728 void MarkIsKeyboardA(bool isKeyboardA) 729 { 730 isKeyboardA_ = isKeyboardA; 731 } 732 733 void SetShortcutKey(const KeyEvent& event); 734 SetTextOverlayManager(const RefPtr<TextOverlayManager> & textOverlayManager)735 void SetTextOverlayManager(const RefPtr<TextOverlayManager>& textOverlayManager) 736 { 737 textOverlayManager_ = textOverlayManager; 738 } 739 GetTextOverlayManager()740 RefPtr<TextOverlayManager> GetTextOverlayManager() const 741 { 742 return textOverlayManager_; 743 } 744 SubscribeCtrlA(SubscribeCtrlACallback callback)745 void SubscribeCtrlA(SubscribeCtrlACallback callback) 746 { 747 subscribeCtrlA_ = std::move(callback); 748 } 749 SetClipboardCallback(const std::function<void (const std::string &)> & callback)750 void SetClipboardCallback(const std::function<void(const std::string&)>& callback) 751 { 752 clipboardCallback_ = callback; 753 } 754 755 void ProcessDragEvent( 756 const RefPtr<RenderNode>& renderNode, const RefPtr<DragEvent>& event, const Point& globalPoint); 757 void ProcessDragEventEnd( 758 const RefPtr<RenderNode>& renderNode, const RefPtr<DragEvent>& event, const Point& globalPoint); 759 760 // restore 761 void RestoreNodeInfo(std::unique_ptr<JsonValue> nodeInfo) override; 762 std::unique_ptr<JsonValue> GetStoredNodeInfo() override; 763 void StoreNode(int32_t restoreId, const WeakPtr<RenderElement>& node); 764 std::string GetRestoreInfo(int32_t restoreId); 765 GetIsTabKeyPressed()766 bool GetIsTabKeyPressed() const 767 { 768 return isTabKeyPressed_; 769 } 770 GetIsFocusingByTab()771 bool GetIsFocusingByTab() const 772 { 773 return isFocusingByTab_; 774 } 775 SetIsFocusingByTab(bool isFocusingByTab)776 void SetIsFocusingByTab(bool isFocusingByTab) 777 { 778 isFocusingByTab_ = isFocusingByTab; 779 } 780 781 void AddVisibleAreaChangeNode(const ComposeId& nodeId, double ratio, const VisibleRatioCallback& callback); 782 GetOnShow()783 bool GetOnShow() const 784 { 785 return onShow_; 786 } 787 AddRectCallback(OutOfRectGetRectCallback & getRectCallback,OutOfRectTouchCallback & touchCallback,OutOfRectMouseCallback & mouseCallback)788 void AddRectCallback(OutOfRectGetRectCallback& getRectCallback, OutOfRectTouchCallback& touchCallback, 789 OutOfRectMouseCallback& mouseCallback) 790 { 791 rectCallbackList_.emplace_back(RectCallback(getRectCallback, touchCallback, mouseCallback)); 792 } 793 794 void SetRootRect(double width, double height, double offset = 0.0) override 795 { 796 SetRootSizeWithWidthHeight(width, height, offset); 797 } 798 799 void SetContainerWindow(bool isShow) override; 800 801 void SetAppTitle(const std::string& title) override; 802 void SetAppIcon(const RefPtr<PixelMap>& icon) override; 803 void FlushMessages() override; 804 805 protected: 806 bool OnDumpInfo(const std::vector<std::string>& params) const override; 807 void FlushVsync(uint64_t nanoTimestamp, uint32_t frameCount) override; 808 void FlushPipelineWithoutAnimation() override; 809 void DispatchDisplaySync(uint64_t nanoTimestamp) override; 810 void FlushAnimation(uint64_t nanoTimestamp) override; 811 void FlushReload(const ConfigurationChange& configurationChange) override; 812 void FlushReloadTransition() override; FlushUITasks()813 void FlushUITasks() override 814 { 815 FlushLayout(); 816 } 817 818 std::shared_ptr<OHOS::Rosen::RSUIDirector> rsUIDirector_; 819 bool hasIdleTasks_ = false; 820 821 private: 822 void FlushLayout(); 823 void FlushGeometryProperties(); 824 void FlushRender(); 825 void FlushRenderFinish(); 826 void FireVisibleChangeEvent(); 827 void FlushPredictLayout(int64_t deadline); 828 void FlushPostAnimation(); 829 void FlushPageUpdateTasks(); 830 void ProcessPreFlush(); 831 void ProcessPostFlush(); 832 void SetRootSizeWithWidthHeight(int32_t width, int32_t height, int32_t offset = 0); 833 void FlushBuildAndLayoutBeforeSurfaceReady(); 834 void FlushAnimationTasks(); 835 void DumpAccessibility(const std::vector<std::string>& params) const; 836 void FlushWindowBlur(); 837 void MakeThreadStuck(const std::vector<std::string>& params) const; 838 void ExitAnimation(); 839 void CreateGeometryTransition(); 840 void CorrectPosition(); 841 void CreateTouchEventOnZoom(const AxisEvent& event); 842 void HandleVisibleAreaChangeEvent(); 843 void FlushTouchEvents(); 844 845 template<typename T> 846 struct NodeCompare { operatorNodeCompare847 bool operator()(const T& nodeLeft, const T& nodeRight) const 848 { 849 if (nodeLeft->GetDepth() < nodeRight->GetDepth()) { 850 return true; 851 } 852 if (nodeLeft->GetDepth() == nodeRight->GetDepth()) { 853 return nodeLeft < nodeRight; 854 } 855 return false; 856 } 857 }; 858 859 template<typename T> 860 struct NodeCompareWeak { operatorNodeCompareWeak861 bool operator()(const T& nodeLeftWeak, const T& nodeRightWeak) const 862 { 863 auto nodeLeft = nodeLeftWeak.Upgrade(); 864 auto nodeRight = nodeRightWeak.Upgrade(); 865 if (!nodeLeft || !nodeRight) { 866 return true; 867 } 868 auto compare = NodeCompare<decltype(nodeLeft)>(); 869 return compare(nodeLeft, nodeRight); 870 } 871 }; 872 873 Rect dirtyRect_; 874 uint32_t nextScheduleTaskId_ = 0; 875 std::unordered_map<uint32_t, RefPtr<ScheduleTask>> scheduleTasks_; 876 std::unordered_map<ComposeId, std::list<RefPtr<ComposedElement>>> composedElementMap_; 877 std::set<WeakPtr<Element>, NodeCompareWeak<WeakPtr<Element>>> dirtyElements_; 878 std::set<WeakPtr<Element>, NodeCompareWeak<WeakPtr<Element>>> needRebuildFocusElement_; 879 std::set<RefPtr<RenderNode>, NodeCompare<RefPtr<RenderNode>>> dirtyRenderNodes_; 880 std::set<RefPtr<RenderNode>, NodeCompare<RefPtr<RenderNode>>> dirtyRenderNodesInOverlay_; 881 std::set<RefPtr<RenderNode>, NodeCompare<RefPtr<RenderNode>>> dirtyLayoutNodes_; 882 std::set<RefPtr<RenderNode>, NodeCompare<RefPtr<RenderNode>>> predictLayoutNodes_; 883 std::set<RefPtr<RenderNode>, NodeCompare<RefPtr<RenderNode>>> needPaintFinishNodes_; 884 std::set<RefPtr<RenderNode>, NodeCompare<RefPtr<RenderNode>>> geometryChangedNodes_; 885 std::set<RefPtr<RenderNode>> nodesToNotifyOnPreDraw_; 886 std::set<RefPtr<RenderNode>> nodesNeedDrawOnPixelMap_; 887 std::list<RefPtr<FlushEvent>> postFlushListeners_; 888 std::list<RefPtr<FlushEvent>> postAnimationFlushListeners_; 889 std::list<RefPtr<FlushEvent>> preFlushListeners_; 890 RefPtr<FocusAnimationManager> focusAnimationManager_; 891 892 RefPtr<RootElement> rootElement_; 893 WeakPtr<FocusNode> dirtyFocusNode_; 894 WeakPtr<FocusNode> dirtyFocusScope_; 895 std::list<std::function<void()>> buildAfterCallback_; 896 RefPtr<RenderFactory> renderFactory_; 897 UpdateWindowBlurRegionHandler updateWindowBlurRegionHandler_; 898 UpdateWindowBlurDrawOpHandler updateWindowBlurDrawOpHandler_; 899 DragEventHandler dragEventHandler_; 900 InitDragEventListener initDragEventListener_; 901 std::vector<KeyCode> pressedKeyCodes; 902 TouchEvent zoomEventA_; 903 TouchEvent zoomEventB_; 904 bool isOnScrollZoomEvent_ = false; 905 bool isKeyCtrlPressed_ = false; 906 907 Rect transparentHole_; 908 // use for traversing clipping hole 909 bool hasMeetSubWindowNode_ = false; 910 // use for judge clip hole status 911 bool hasClipHole_ = false; 912 // judge hole is valid 913 bool isHoleValid_ = false; 914 915 #ifndef WEARABLE_PRODUCT 916 RefPtr<MultiModalManager> multiModalManager_ = MakeRefPtr<MultiModalManager>(); 917 #endif 918 RefPtr<SharedTransitionController> sharedTransitionController_; 919 RefPtr<CardTransitionController> cardTransitionController_; 920 RefPtr<TextOverlayManager> textOverlayManager_; 921 EventTrigger eventTrigger_; 922 923 WeakPtr<RenderNode> requestedRenderNode_; 924 // Make page update tasks pending here to avoid block receiving vsync. 925 std::queue<std::function<void()>> pageUpdateTasks_; 926 // strong deactivate element and it's id. 927 std::map<int32_t, RefPtr<Element>> deactivateElements_; 928 929 RefPtr<Component> contextMenu_; 930 931 // window blur region 932 std::unordered_map<int32_t, WindowBlurInfo> windowBlurRegions_; 933 934 std::list<RefPtr<RenderNode>> alignDeclarationNodeList_; 935 std::set<RefPtr<RenderNode>> layoutTransitionNodeSet_; 936 937 std::function<void()> queryIfWindowInScreenCallback_; 938 std::atomic<bool> isWindowInScreen_ = true; 939 940 RefPtr<DragDropEvent> preTargetRenderNode_; 941 942 bool isSurfaceReady_ = false; 943 944 int32_t cardAppearingDuration_ = 0; 945 double statusBarHeight_ = 0.0; // dp 946 double navigationBarHeight_ = 0.0; // dp 947 bool needForcedRefresh_ = false; 948 bool isFlushingAnimation_ = false; 949 bool isMoving_ = false; 950 std::atomic<bool> onShow_ = true; 951 bool isKeyEvent_ = false; 952 bool needWindowBlurRegionRefresh_ = false; 953 bool useLiteStyle_ = false; 954 bool isFirstLoaded_ = true; 955 bool isDensityUpdate_ = false; 956 uint64_t flushAnimationTimestamp_ = 0; 957 TimeProvider timeProvider_; 958 int32_t modalHeight_ = 0; 959 int32_t hoverNodeId_ = DEFAULT_HOVER_ENTER_ANIMATION_ID; 960 uint32_t modalColor_ = 0x00000000; 961 std::list<RefPtr<RenderNode>> hoverNodes_; 962 std::function<void(std::function<void()>&&)> screenOffCallback_; 963 std::function<void(std::function<void()>&&)> screenOnCallback_; 964 #if defined(ENABLE_NATIVE_VIEW) 965 int32_t frameCount_ = 0; 966 #endif 967 968 int32_t width_ = 0; 969 int32_t height_ = 0; 970 bool isFirstPage_ = true; 971 bool buildingFirstPage_ = false; 972 bool forbidPlatformQuit_ = false; 973 std::string photoCachePath_; 974 AnimationOption explicitAnimationOption_; 975 std::map<int32_t, RefPtr<Animator>> explicitAnimators_; 976 bool isAccessibilityEnabled_ = false; 977 978 int32_t callbackId_ = 0; 979 SurfaceChangedCallbackMap surfaceChangedCallbackMap_; 980 SurfacePositionChangedCallbackMap surfacePositionChangedCallbackMap_; 981 982 bool isShiftDown_ = false; 983 bool isCtrlDown_ = false; 984 bool isKeyboardA_ = false; 985 bool isTabKeyPressed_ = false; 986 bool isFocusingByTab_ = false; 987 SubscribeCtrlACallback subscribeCtrlA_; 988 989 std::function<void()> nextFrameLayoutCallback_ = nullptr; 990 Size selectedItemSize_ { 0.0, 0.0 }; 991 size_t selectedIndex_ = -1; 992 size_t insertIndex_ = -1; 993 RefPtr<RenderNode> initRenderNode_; 994 std::string customDragInfo_; 995 std::string selectedText_; 996 std::string imageSrc_; 997 Offset pageOffset_; 998 Offset rootOffset_; 999 1000 std::unordered_map<int32_t, WeakPtr<RenderElement>> storeNode_; 1001 std::unordered_map<int32_t, std::string> restoreNodeInfo_; 1002 1003 std::unordered_map<ComposeId, std::list<VisibleCallbackInfo>> visibleAreaChangeNodes_; 1004 1005 std::vector<RectCallback> rectCallbackList_; 1006 std::list<TouchEvent> touchEvents_; 1007 1008 ACE_DISALLOW_COPY_AND_MOVE(PipelineContext); 1009 }; 1010 1011 } // namespace OHOS::Ace 1012 1013 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_PIPELINE_CONTEXT_H 1014