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) 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 356 BaseId::IdType AddPageTransitionListener(const PageTransitionListenable::CallbackFuncType& funcObject); 357 358 const RefPtr<OverlayElement> GetOverlayElement() const; 359 360 void RemovePageTransitionListener(typename BaseId::IdType id); 361 362 void ClearPageTransitionListeners(); 363 364 void Destroy() override; 365 366 bool IsLastPage() override; 367 368 RefPtr<Element> GetDeactivateElement(int32_t componentId) const; 369 370 void ClearDeactivateElements(); 371 372 void AddDeactivateElement(int32_t id, const RefPtr<Element>& element); 373 GetRenderFactory()374 const RefPtr<RenderFactory>& GetRenderFactory() const 375 { 376 return renderFactory_; 377 } 378 379 #ifndef WEARABLE_PRODUCT 380 void SetMultimodalSubscriber(const RefPtr<MultimodalSubscriber>& multimodalSubscriber); 381 GetMultiModalManager()382 const RefPtr<MultiModalManager>& GetMultiModalManager() const 383 { 384 return multiModalManager_; 385 } 386 #endif 387 388 void SetWindowOnShow(); 389 390 void SetWindowOnHide(); 391 392 void OnShow() override; 393 394 void OnHide() override; 395 MarkForcedRefresh()396 void MarkForcedRefresh() 397 { 398 needForcedRefresh_ = true; 399 } 400 401 void SetTimeProvider(TimeProvider&& timeProvider); 402 403 uint64_t GetTimeFromExternalTimer() override; 404 405 void AddFontNode(const WeakPtr<RenderNode>& node); 406 407 void RemoveFontNode(const WeakPtr<RenderNode>& node); 408 409 void LoadSystemFont(const std::function<void()>& onFondsLoaded); 410 GetSharedTransitionController()411 const RefPtr<SharedTransitionController>& GetSharedTransitionController() const 412 { 413 return sharedTransitionController_; 414 } 415 GetCardTransitionController()416 const RefPtr<CardTransitionController>& GetCardTransitionController() const 417 { 418 return cardTransitionController_; 419 } 420 421 void SetClickPosition(const Offset& position) const; 422 423 void RootLostFocus(BlurReason reason = BlurReason::FOCUS_SWITCH) const; 424 425 void FlushFocus(); 426 427 void WindowFocus(bool isFocus) override; 428 429 void OnPageShow() override; 430 GetStatusBarHeight()431 double GetStatusBarHeight() const 432 { 433 return statusBarHeight_; 434 } 435 GetNavigationBarHeight()436 double GetNavigationBarHeight() const 437 { 438 return navigationBarHeight_; 439 } 440 SetAppearingDuration(int32_t duration)441 void SetAppearingDuration(int32_t duration) 442 { 443 cardAppearingDuration_ = duration; 444 } 445 GetAppearingDuration()446 int32_t GetAppearingDuration() const 447 { 448 return cardAppearingDuration_; 449 } 450 SetModalHeight(int32_t height)451 void SetModalHeight(int32_t height) 452 { 453 modalHeight_ = height; 454 } 455 SetModalColor(uint32_t color)456 void SetModalColor(uint32_t color) 457 { 458 modalColor_ = color; 459 } 460 461 void MovePage(const Offset& rootRect, double offsetHeight); 462 SetBuildAfterCallback(const std::function<void ()> & callback)463 void SetBuildAfterCallback(const std::function<void()>& callback) override 464 { 465 buildAfterCallback_.emplace_back(callback); 466 } 467 468 void SetIsKeyEvent(bool isKeyEvent); 469 IsKeyEvent()470 bool IsKeyEvent() const 471 { 472 return isKeyEvent_; 473 } 474 IsJsPlugin()475 bool IsJsPlugin() const 476 { 477 return isJsPlugin_; 478 } 479 480 void RefreshRootBgColor() const override; 481 void AddToHoverList(const RefPtr<RenderNode>& node); 482 483 using UpdateWindowBlurRegionHandler = std::function<void(const std::vector<std::vector<float>>&)>; 484 SetUpdateWindowBlurRegionHandler(UpdateWindowBlurRegionHandler handler)485 void SetUpdateWindowBlurRegionHandler(UpdateWindowBlurRegionHandler handler) 486 { 487 updateWindowBlurRegionHandler_ = std::move(handler); 488 } 489 490 using DragEventHandler = std::function<void(const std::string&, const RefPtr<PixelMap>& pixmap)>; 491 SetDragEventHandler(DragEventHandler && callback)492 void SetDragEventHandler(DragEventHandler&& callback) 493 { 494 dragEventHandler_ = callback; 495 } 496 497 using InitDragEventListener = std::function<void()>; 498 SetInitDragListener(InitDragEventListener && callback)499 void SetInitDragListener(InitDragEventListener&& callback) 500 { 501 initDragEventListener_ = callback; 502 } 503 504 void UpdateWindowBlurRegion( 505 int32_t id, RRect rRect, float progress, WindowBlurStyle style, const std::vector<RRect>& coords); 506 507 void ClearWindowBlurRegion(int32_t id); 508 IsBuildingFirstPage()509 bool IsBuildingFirstPage() const 510 { 511 return buildingFirstPage_; 512 } 513 514 using UpdateWindowBlurDrawOpHandler = std::function<void(void)>; 515 SetUpdateWindowBlurDrawOpHandler(UpdateWindowBlurDrawOpHandler handler)516 void SetUpdateWindowBlurDrawOpHandler(UpdateWindowBlurDrawOpHandler handler) 517 { 518 updateWindowBlurDrawOpHandler_ = std::move(handler); 519 } 520 521 void NavigatePage(uint8_t type, const PageTarget& target, const std::string& params); 522 523 void AddKeyFrame( 524 float fraction, const RefPtr<Curve>& curve, const std::function<void()>& propertyCallback) override; 525 526 void AddKeyFrame(float fraction, const std::function<void()>& propertyCallback) override; 527 528 void SaveExplicitAnimationOption(const AnimationOption& option) override; 529 530 void CreateExplicitAnimator(const std::function<void()>& onFinishEvent) override; 531 532 void ClearExplicitAnimationOption() override; 533 534 AnimationOption GetExplicitAnimationOption() const override; 535 536 void FlushBuild() override; 537 SetUseLiteStyle(bool useLiteStyle)538 void SetUseLiteStyle(bool useLiteStyle) 539 { 540 useLiteStyle_ = useLiteStyle; 541 } 542 UseLiteStyle()543 bool UseLiteStyle() const 544 { 545 return useLiteStyle_; 546 } 547 GetDirtyRect()548 const Rect& GetDirtyRect() const 549 { 550 return dirtyRect_; 551 } 552 553 bool GetIsDeclarative() const override; 554 IsForbidPlatformQuit()555 bool IsForbidPlatformQuit() const 556 { 557 return forbidPlatformQuit_; 558 } 559 560 void SetForbidPlatformQuit(bool forbidPlatformQuit); 561 562 void SetAppBgColor(const Color& color) override; 563 SetPhotoCachePath(const std::string & photoCachePath)564 void SetPhotoCachePath(const std::string& photoCachePath) 565 { 566 photoCachePath_ = photoCachePath; 567 } 568 GetPhotoCachePath()569 const std::string& GetPhotoCachePath() 570 { 571 return photoCachePath_; 572 } 573 SetScreenOnCallback(std::function<void (std::function<void ()> && func)> && screenOnCallback)574 void SetScreenOnCallback(std::function<void(std::function<void()>&& func)>&& screenOnCallback) 575 { 576 screenOnCallback_ = std::move(screenOnCallback); 577 } 578 SetScreenOffCallback(std::function<void (std::function<void ()> && func)> && screenOffCallback)579 void SetScreenOffCallback(std::function<void(std::function<void()>&& func)>&& screenOffCallback) 580 { 581 screenOffCallback_ = std::move(screenOffCallback); 582 } 583 584 void AddScreenOnEvent(std::function<void()>&& func); 585 void AddScreenOffEvent(std::function<void()>&& func); 586 void AddAlignDeclarationNode(const RefPtr<RenderNode>& node); 587 void AddLayoutTransitionNode(const RefPtr<RenderNode>& node); 588 std::list<RefPtr<RenderNode>>& GetAlignDeclarationNodeList(); SetQueryIfWindowInScreenCallback(std::function<void ()> && func)589 void SetQueryIfWindowInScreenCallback(std::function<void()>&& func) 590 { 591 queryIfWindowInScreenCallback_ = std::move(func); 592 } SetIsWindowInScreen(bool isWindowInScreen)593 void SetIsWindowInScreen(bool isWindowInScreen) 594 { 595 isWindowInScreen_ = isWindowInScreen; 596 } 597 // This interface posts an async task to do async query and returns the result from previous query. 598 bool IsWindowInScreen(); 599 void NotifyOnPreDraw() override; 600 void AddNodesToNotifyOnPreDraw(const RefPtr<RenderNode>& renderNode); 601 602 void UpdateNodesNeedDrawOnPixelMap(); 603 void SearchNodesNeedDrawOnPixelMap(const RefPtr<RenderNode>& renderNode); 604 void NotifyDrawOnPixelMap(); 605 GetRootElement()606 const RefPtr<RootElement>& GetRootElement() const 607 { 608 return rootElement_; 609 } 610 SetAccessibilityEnabled(bool isEnabled)611 void SetAccessibilityEnabled(bool isEnabled) 612 { 613 isAccessibilityEnabled_ = isEnabled; 614 } IsAccessibilityEnabled()615 bool IsAccessibilityEnabled() const 616 { 617 return isAccessibilityEnabled_ || IsVisibleChangeNodeExists(-1); 618 } 619 620 bool IsVisibleChangeNodeExists(NodeId index) const; 621 RegisterSurfaceChangedCallback(std::function<void (int32_t,int32_t,int32_t,int32_t,WindowSizeChangeReason)> && callback)622 int32_t RegisterSurfaceChangedCallback( 623 std::function<void(int32_t, int32_t, int32_t, int32_t, WindowSizeChangeReason)>&& callback) 624 { 625 if (callback) { 626 surfaceChangedCallbackMap_.emplace(++callbackId_, std::move(callback)); 627 return callbackId_; 628 } 629 return 0; 630 } 631 UnregisterSurfaceChangedCallback(int32_t callbackId)632 void UnregisterSurfaceChangedCallback(int32_t callbackId) 633 { 634 surfaceChangedCallbackMap_.erase(callbackId); 635 } 636 RegisterSurfacePositionChangedCallback(std::function<void (int32_t,int32_t)> && callback)637 int32_t RegisterSurfacePositionChangedCallback(std::function<void(int32_t, int32_t)>&& callback) 638 { 639 if (callback) { 640 surfacePositionChangedCallbackMap_.emplace(++callbackId_, std::move(callback)); 641 return callbackId_; 642 } 643 return 0; 644 } 645 UnregisterSurfacePositionChangedCallback(int32_t callbackId)646 void UnregisterSurfacePositionChangedCallback(int32_t callbackId) 647 { 648 surfacePositionChangedCallbackMap_.erase(callbackId); 649 } 650 void StartSystemDrag(const std::string& str, const RefPtr<PixelMap>& pixmap); 651 void InitDragListener(); 652 void OnDragEvent(int32_t x, int32_t y, DragEventAction action) override; 653 void SetPreTargetRenderNode(const RefPtr<DragDropEvent>& preDragDropNode); 654 const RefPtr<DragDropEvent>& GetPreTargetRenderNode() const; 655 void SetInitRenderNode(const RefPtr<RenderNode>& initRenderNode); 656 const RefPtr<RenderNode>& GetInitRenderNode() const; 657 SetContextMenu(const RefPtr<Component> & contextMenu)658 void SetContextMenu(const RefPtr<Component>& contextMenu) 659 { 660 contextMenu_ = contextMenu; 661 } 662 663 void SetClipHole(double left, double top, double width, double height); 664 GetTransparentHole()665 const Rect& GetTransparentHole() const 666 { 667 return transparentHole_; 668 } 669 GetHasMeetSubWindowNode()670 bool GetHasMeetSubWindowNode() const 671 { 672 return hasMeetSubWindowNode_; 673 } 674 SetHasMeetSubWindowNode(bool hasMeetSubWindowNode)675 void SetHasMeetSubWindowNode(bool hasMeetSubWindowNode) 676 { 677 hasMeetSubWindowNode_ = hasMeetSubWindowNode; 678 } 679 GetHasClipHole()680 bool GetHasClipHole() const 681 { 682 return hasClipHole_; 683 } 684 SetHasClipHole(bool hasClipHole)685 void SetHasClipHole(bool hasClipHole) 686 { 687 hasClipHole_ = hasClipHole; 688 } 689 GetIsHoleValid()690 bool GetIsHoleValid() const 691 { 692 return isHoleValid_; 693 } 694 695 void SetRSUIDirector(std::shared_ptr<OHOS::Rosen::RSUIDirector> rsUIDirector); 696 697 std::shared_ptr<OHOS::Rosen::RSUIDirector> GetRSUIDirector(); 698 IsShiftDown()699 bool IsShiftDown() const 700 { 701 return isShiftDown_; 702 } 703 MarkIsShiftDown(bool isShiftDown)704 void MarkIsShiftDown(bool isShiftDown) 705 { 706 isShiftDown_ = isShiftDown; 707 } 708 IsCtrlDown()709 bool IsCtrlDown() const 710 { 711 return isCtrlDown_; 712 } 713 MarkIsCtrlDown(bool isCtrlDown)714 void MarkIsCtrlDown(bool isCtrlDown) 715 { 716 isCtrlDown_ = isCtrlDown; 717 } 718 IsKeyboardA()719 bool IsKeyboardA() const 720 { 721 return isKeyboardA_; 722 } 723 MarkIsKeyboardA(bool isKeyboardA)724 void MarkIsKeyboardA(bool isKeyboardA) 725 { 726 isKeyboardA_ = isKeyboardA; 727 } 728 729 void SetShortcutKey(const KeyEvent& event); 730 SetTextOverlayManager(const RefPtr<TextOverlayManager> & textOverlayManager)731 void SetTextOverlayManager(const RefPtr<TextOverlayManager>& textOverlayManager) 732 { 733 textOverlayManager_ = textOverlayManager; 734 } 735 GetTextOverlayManager()736 RefPtr<TextOverlayManager> GetTextOverlayManager() const 737 { 738 return textOverlayManager_; 739 } 740 SubscribeCtrlA(SubscribeCtrlACallback callback)741 void SubscribeCtrlA(SubscribeCtrlACallback callback) 742 { 743 subscribeCtrlA_ = std::move(callback); 744 } 745 SetClipboardCallback(const std::function<void (const std::string &)> & callback)746 void SetClipboardCallback(const std::function<void(const std::string&)>& callback) 747 { 748 clipboardCallback_ = callback; 749 } 750 751 void ProcessDragEvent( 752 const RefPtr<RenderNode>& renderNode, const RefPtr<DragEvent>& event, const Point& globalPoint); 753 void ProcessDragEventEnd( 754 const RefPtr<RenderNode>& renderNode, const RefPtr<DragEvent>& event, const Point& globalPoint); 755 756 // restore 757 void RestoreNodeInfo(std::unique_ptr<JsonValue> nodeInfo) override; 758 std::unique_ptr<JsonValue> GetStoredNodeInfo() override; 759 void StoreNode(int32_t restoreId, const WeakPtr<RenderElement>& node); 760 std::string GetRestoreInfo(int32_t restoreId); 761 GetIsTabKeyPressed()762 bool GetIsTabKeyPressed() const 763 { 764 return isTabKeyPressed_; 765 } 766 GetIsFocusingByTab()767 bool GetIsFocusingByTab() const 768 { 769 return isFocusingByTab_; 770 } 771 SetIsFocusingByTab(bool isFocusingByTab)772 void SetIsFocusingByTab(bool isFocusingByTab) 773 { 774 isFocusingByTab_ = isFocusingByTab; 775 } 776 777 void AddVisibleAreaChangeNode(const ComposeId& nodeId, double ratio, const VisibleRatioCallback& callback); 778 GetOnShow()779 bool GetOnShow() const 780 { 781 return onShow_; 782 } 783 AddRectCallback(OutOfRectGetRectCallback & getRectCallback,OutOfRectTouchCallback & touchCallback,OutOfRectMouseCallback & mouseCallback)784 void AddRectCallback(OutOfRectGetRectCallback& getRectCallback, OutOfRectTouchCallback& touchCallback, 785 OutOfRectMouseCallback& mouseCallback) 786 { 787 rectCallbackList_.emplace_back(RectCallback(getRectCallback, touchCallback, mouseCallback)); 788 } 789 790 void SetRootRect(double width, double height, double offset = 0.0) override 791 { 792 SetRootSizeWithWidthHeight(width, height, offset); 793 } 794 795 void SetContainerWindow(bool isShow) override; 796 797 void SetAppTitle(const std::string& title) override; 798 void SetAppIcon(const RefPtr<PixelMap>& icon) override; 799 void FlushMessages() override; 800 801 protected: 802 bool OnDumpInfo(const std::vector<std::string>& params) const override; 803 void FlushVsync(uint64_t nanoTimestamp, uint32_t frameCount) override; 804 void FlushPipelineWithoutAnimation() override; 805 void FlushAnimation(uint64_t nanoTimestamp) override; 806 void FlushReload() override; 807 void FlushReloadTransition() override; FlushUITasks()808 void FlushUITasks() override 809 { 810 FlushLayout(); 811 } 812 813 std::shared_ptr<OHOS::Rosen::RSUIDirector> rsUIDirector_; 814 bool hasIdleTasks_ = false; 815 816 private: 817 void FlushLayout(); 818 void FlushGeometryProperties(); 819 void FlushRender(); 820 void FlushRenderFinish(); 821 void FireVisibleChangeEvent(); 822 void FlushPredictLayout(int64_t deadline); 823 void FlushPostAnimation(); 824 void FlushPageUpdateTasks(); 825 void ProcessPreFlush(); 826 void ProcessPostFlush(); 827 void SetRootSizeWithWidthHeight(int32_t width, int32_t height, int32_t offset = 0); 828 void FlushBuildAndLayoutBeforeSurfaceReady(); 829 void FlushAnimationTasks(); 830 void DumpAccessibility(const std::vector<std::string>& params) const; 831 void FlushWindowBlur(); 832 void MakeThreadStuck(const std::vector<std::string>& params) const; 833 void ExitAnimation(); 834 void CreateGeometryTransition(); 835 void CorrectPosition(); 836 void CreateTouchEventOnZoom(const AxisEvent& event); 837 void HandleVisibleAreaChangeEvent(); 838 void FlushTouchEvents(); 839 840 template<typename T> 841 struct NodeCompare { operatorNodeCompare842 bool operator()(const T& nodeLeft, const T& nodeRight) const 843 { 844 if (nodeLeft->GetDepth() < nodeRight->GetDepth()) { 845 return true; 846 } 847 if (nodeLeft->GetDepth() == nodeRight->GetDepth()) { 848 return nodeLeft < nodeRight; 849 } 850 return false; 851 } 852 }; 853 854 template<typename T> 855 struct NodeCompareWeak { operatorNodeCompareWeak856 bool operator()(const T& nodeLeftWeak, const T& nodeRightWeak) const 857 { 858 auto nodeLeft = nodeLeftWeak.Upgrade(); 859 auto nodeRight = nodeRightWeak.Upgrade(); 860 if (!nodeLeft || !nodeRight) { 861 return true; 862 } 863 auto compare = NodeCompare<decltype(nodeLeft)>(); 864 return compare(nodeLeft, nodeRight); 865 } 866 }; 867 868 Rect dirtyRect_; 869 uint32_t nextScheduleTaskId_ = 0; 870 std::unordered_map<uint32_t, RefPtr<ScheduleTask>> scheduleTasks_; 871 std::unordered_map<ComposeId, std::list<RefPtr<ComposedElement>>> composedElementMap_; 872 std::set<WeakPtr<Element>, NodeCompareWeak<WeakPtr<Element>>> dirtyElements_; 873 std::set<WeakPtr<Element>, NodeCompareWeak<WeakPtr<Element>>> needRebuildFocusElement_; 874 std::set<RefPtr<RenderNode>, NodeCompare<RefPtr<RenderNode>>> dirtyRenderNodes_; 875 std::set<RefPtr<RenderNode>, NodeCompare<RefPtr<RenderNode>>> dirtyRenderNodesInOverlay_; 876 std::set<RefPtr<RenderNode>, NodeCompare<RefPtr<RenderNode>>> dirtyLayoutNodes_; 877 std::set<RefPtr<RenderNode>, NodeCompare<RefPtr<RenderNode>>> predictLayoutNodes_; 878 std::set<RefPtr<RenderNode>, NodeCompare<RefPtr<RenderNode>>> needPaintFinishNodes_; 879 std::set<RefPtr<RenderNode>, NodeCompare<RefPtr<RenderNode>>> geometryChangedNodes_; 880 std::set<RefPtr<RenderNode>> nodesToNotifyOnPreDraw_; 881 std::set<RefPtr<RenderNode>> nodesNeedDrawOnPixelMap_; 882 std::list<RefPtr<FlushEvent>> postFlushListeners_; 883 std::list<RefPtr<FlushEvent>> postAnimationFlushListeners_; 884 std::list<RefPtr<FlushEvent>> preFlushListeners_; 885 RefPtr<FocusAnimationManager> focusAnimationManager_; 886 887 RefPtr<RootElement> rootElement_; 888 WeakPtr<FocusNode> dirtyFocusNode_; 889 WeakPtr<FocusNode> dirtyFocusScope_; 890 std::list<std::function<void()>> buildAfterCallback_; 891 RefPtr<RenderFactory> renderFactory_; 892 UpdateWindowBlurRegionHandler updateWindowBlurRegionHandler_; 893 UpdateWindowBlurDrawOpHandler updateWindowBlurDrawOpHandler_; 894 DragEventHandler dragEventHandler_; 895 InitDragEventListener initDragEventListener_; 896 std::vector<KeyCode> pressedKeyCodes; 897 TouchEvent zoomEventA_; 898 TouchEvent zoomEventB_; 899 bool isOnScrollZoomEvent_ = false; 900 bool isKeyCtrlPressed_ = false; 901 902 Rect transparentHole_; 903 // use for traversing clipping hole 904 bool hasMeetSubWindowNode_ = false; 905 // use for judge clip hole status 906 bool hasClipHole_ = false; 907 // judge hole is valid 908 bool isHoleValid_ = false; 909 910 #ifndef WEARABLE_PRODUCT 911 RefPtr<MultiModalManager> multiModalManager_ = MakeRefPtr<MultiModalManager>(); 912 #endif 913 RefPtr<SharedTransitionController> sharedTransitionController_; 914 RefPtr<CardTransitionController> cardTransitionController_; 915 RefPtr<TextOverlayManager> textOverlayManager_; 916 EventTrigger eventTrigger_; 917 918 WeakPtr<RenderNode> requestedRenderNode_; 919 // Make page update tasks pending here to avoid block receiving vsync. 920 std::queue<std::function<void()>> pageUpdateTasks_; 921 // strong deactivate element and it's id. 922 std::map<int32_t, RefPtr<Element>> deactivateElements_; 923 924 RefPtr<Component> contextMenu_; 925 926 // window blur region 927 std::unordered_map<int32_t, WindowBlurInfo> windowBlurRegions_; 928 929 std::list<RefPtr<RenderNode>> alignDeclarationNodeList_; 930 std::set<RefPtr<RenderNode>> layoutTransitionNodeSet_; 931 932 std::function<void()> queryIfWindowInScreenCallback_; 933 std::atomic<bool> isWindowInScreen_ = true; 934 935 RefPtr<DragDropEvent> preTargetRenderNode_; 936 937 bool isSurfaceReady_ = false; 938 939 int32_t cardAppearingDuration_ = 0; 940 double statusBarHeight_ = 0.0; // dp 941 double navigationBarHeight_ = 0.0; // dp 942 bool needForcedRefresh_ = false; 943 bool isFlushingAnimation_ = false; 944 bool isMoving_ = false; 945 std::atomic<bool> onShow_ = true; 946 std::atomic<bool> onFocus_ = true; 947 bool isKeyEvent_ = false; 948 bool needWindowBlurRegionRefresh_ = false; 949 bool useLiteStyle_ = false; 950 bool isFirstLoaded_ = true; 951 bool isDensityUpdate_ = false; 952 uint64_t flushAnimationTimestamp_ = 0; 953 TimeProvider timeProvider_; 954 int32_t modalHeight_ = 0; 955 int32_t hoverNodeId_ = DEFAULT_HOVER_ENTER_ANIMATION_ID; 956 uint32_t modalColor_ = 0x00000000; 957 std::list<RefPtr<RenderNode>> hoverNodes_; 958 std::function<void(std::function<void()>&&)> screenOffCallback_; 959 std::function<void(std::function<void()>&&)> screenOnCallback_; 960 #if defined(ENABLE_NATIVE_VIEW) 961 int32_t frameCount_ = 0; 962 #endif 963 964 int32_t width_ = 0; 965 int32_t height_ = 0; 966 bool isFirstPage_ = true; 967 bool buildingFirstPage_ = false; 968 bool forbidPlatformQuit_ = false; 969 std::string photoCachePath_; 970 AnimationOption explicitAnimationOption_; 971 std::map<int32_t, RefPtr<Animator>> explicitAnimators_; 972 bool isAccessibilityEnabled_ = false; 973 974 int32_t callbackId_ = 0; 975 SurfaceChangedCallbackMap surfaceChangedCallbackMap_; 976 SurfacePositionChangedCallbackMap surfacePositionChangedCallbackMap_; 977 978 bool isShiftDown_ = false; 979 bool isCtrlDown_ = false; 980 bool isKeyboardA_ = false; 981 bool isTabKeyPressed_ = false; 982 bool isFocusingByTab_ = false; 983 SubscribeCtrlACallback subscribeCtrlA_; 984 985 std::function<void()> nextFrameLayoutCallback_ = nullptr; 986 Size selectedItemSize_ { 0.0, 0.0 }; 987 size_t selectedIndex_ = -1; 988 size_t insertIndex_ = -1; 989 RefPtr<RenderNode> initRenderNode_; 990 std::string customDragInfo_; 991 std::string selectedText_; 992 std::string imageSrc_; 993 Offset pageOffset_; 994 Offset rootOffset_; 995 996 std::unordered_map<int32_t, WeakPtr<RenderElement>> storeNode_; 997 std::unordered_map<int32_t, std::string> restoreNodeInfo_; 998 999 std::unordered_map<ComposeId, std::list<VisibleCallbackInfo>> visibleAreaChangeNodes_; 1000 1001 std::vector<RectCallback> rectCallbackList_; 1002 std::list<TouchEvent> touchEvents_; 1003 1004 ACE_DISALLOW_COPY_AND_MOVE(PipelineContext); 1005 }; 1006 1007 } // namespace OHOS::Ace 1008 1009 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_PIPELINE_CONTEXT_H 1010