1 /* 2 * Copyright (c) 2024 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_COMPONENTS_NG_MANAGER_SELECT_CONTENT_OVERLAY_SELECT_CONTENT_OVERLAY_MANAGER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MANAGER_SELECT_CONTENT_OVERLAY_SELECT_CONTENT_OVERLAY_MANAGER_H 18 19 #include <functional> 20 #include <optional> 21 22 #include "base/memory/ace_type.h" 23 #include "base/memory/referenced.h" 24 #include "core/components_ng/manager/select_content_overlay/select_overlay_holder.h" 25 #include "core/components_ng/pattern/select_overlay/select_overlay_node.h" 26 #include "core/components_ng/pattern/select_overlay/select_overlay_property.h" 27 #include "core/event/touch_event.h" 28 29 namespace OHOS::Ace::NG { 30 31 struct LegacyManagerCallbacks { 32 std::function<void(bool, bool)> closeCallback; 33 std::function<void()> selectionResetCallback; 34 }; 35 36 class ACE_EXPORT SelectContentOverlayManager : public virtual AceType { 37 DECLARE_ACE_TYPE(SelectContentOverlayManager, AceType); 38 39 public: SelectContentOverlayManager(const RefPtr<FrameNode> & rootNode)40 explicit SelectContentOverlayManager(const RefPtr<FrameNode>& rootNode) : rootNodeWeak_(rootNode) {} 41 ~SelectContentOverlayManager() override = default; 42 static const RefPtr<SelectContentOverlayManager> GetOverlayManager( 43 const RefPtr<SelectOverlayHolder>& holder = nullptr); 44 bool IsOpen(); 45 bool IsCreating(); 46 void Show(bool animation, int32_t requestCode); 47 void Close(int32_t id, bool animation, CloseReason reason); 48 bool CloseCurrent(bool animation, CloseReason reason); 49 void CloseWithOverlayId(int32_t overlayId, CloseReason reason, bool animation); 50 void ShowOptionMenu(); 51 void HideOptionMenu(bool noAnimation = false); 52 void ToggleOptionMenu(); 53 void DisableMenu(); 54 void EnableMenu(); 55 void HideHandle(); 56 void HandleGlobalEvent(const TouchEvent& touchPoint, const NG::OffsetF& rootOffset); 57 void SetHoldSelectionCallback(int32_t id, const HoldSelectionInfo& selectionInfo); 58 void RemoveHoldSelectionCallback(int32_t id); 59 void MarkInfoChange(SelectOverlayDirtyFlag dirtyFlag); 60 void MarkSelectOverlayDirty(PropertyChangeFlag changeFlag); 61 bool IsMenuShow(); 62 bool IsSingleHandle(); 63 bool IsHandlesShow(); 64 bool IsHandleReverse(); 65 void ResetSelectionRect(); 66 void RestartHiddenHandleTask(bool isDelay); 67 void CancelHiddenHandleTask(); 68 const RefPtr<FrameNode> GetSelectOverlayRoot(); 69 RefPtr<SelectOverlayNode> GetSelectOverlayNode(); 70 OptionMenuType GetShowMenuType(); 71 GetSelectOverlayInfo()72 std::optional<SelectOverlayInfo> GetSelectOverlayInfo() 73 { 74 return shareOverlayInfo_ ? *shareOverlayInfo_ : std::optional<SelectOverlayInfo>(); 75 } 76 SetLegacyManagerBridge(const LegacyManagerCallbacks & callbacks)77 void SetLegacyManagerBridge(const LegacyManagerCallbacks& callbacks) 78 { 79 legacyManagerCallbacks_ = callbacks; 80 } 81 82 RefPtr<Pattern> GetMenuPattern(); 83 RefPtr<Pattern> GetHandlePattern(); 84 RefPtr<FrameNode> GetHandleOverlayNode(); 85 void NotifyUpdateToolBar(bool itemChanged); 86 void SwitchToHandleMode(HandleLevelMode mode, bool forceChange = true); 87 float GetHandleDiameter(); 88 void ConvertPointRelativeToNode(const RefPtr<FrameNode>& node, PointF& point); 89 bool IsTouchAtHandle(const PointF& localPoint, const PointF& globalPoint); 90 void UpdateViewPort(); 91 void SetHandleCircleIsShow(bool isFirst, bool isShow); 92 void SetIsHandleLineShow(bool isShow); 93 void MarkHandleDirtyNode(PropertyChangeFlag flag); 94 95 private: 96 void SetHolder(const RefPtr<SelectOverlayHolder>& holder); 97 bool HasHolder(int32_t holderId); 98 void SetHolderInternal(const RefPtr<SelectOverlayHolder>& holder); 99 void CreateSelectOverlay(SelectOverlayInfo& info, bool animation = false); 100 void CreateNormalSelectOverlay(SelectOverlayInfo& info, bool animation); 101 void CreateHandleLevelSelectOverlay(SelectOverlayInfo& info, bool animation, HandleLevelMode mode); 102 void UpdateExistOverlay(const SelectOverlayInfo& info, bool animation, int32_t requestCode); 103 bool IsSameMouseSelectOverlay(const SelectOverlayInfo& info); 104 bool CloseInternal(int32_t holderId, bool animation, CloseReason reason); 105 void DestroySelectOverlayNode(const RefPtr<FrameNode>& node); 106 void DestroySelectOverlayNodeWithAnimation(const RefPtr<FrameNode>& node); 107 void MountNodeToRoot(const RefPtr<FrameNode>& overlayNode, bool animation); 108 void MountNodeToCaller(const RefPtr<FrameNode>& overlayNode, bool animation); 109 std::function<void()> MakeMenuCallback(OptionMenuActionId actionId, const SelectOverlayInfo& info); 110 SelectOverlayInfo BuildSelectOverlayInfo(int32_t requestCode); 111 void UpdateStatusInfos(SelectOverlayInfo& info); 112 void RegisterTouchCallback(SelectOverlayInfo& info); 113 void RegisterHandleCallback(SelectOverlayInfo& info); 114 void HandleSelectionEvent(const PointF& point, const TouchEvent& rawTouchEvent); 115 void UpdateHandleInfosWithFlag(int32_t updateFlag); 116 bool IsTouchInSelectOverlayArea(const PointF& point); 117 bool IsTouchInNormalSelectOverlayArea(const PointF& point); 118 bool IsTouchInHandleLevelOverlayArea(const PointF& point); 119 RefPtr<UINode> FindWindowScene(RefPtr<FrameNode> targetNode); 120 void ClearAllStatus(); 121 bool IsEnableHandleLevel(); 122 void NotifySelectOverlayShow(bool isCreated); 123 std::list<RefPtr<UINode>>::const_iterator FindSelectOverlaySlot( 124 const RefPtr<FrameNode>& root, const std::list<RefPtr<UINode>>& children); 125 126 RefPtr<SelectOverlayHolder> selectOverlayHolder_; 127 WeakPtr<FrameNode> selectOverlayNode_; 128 WeakPtr<FrameNode> menuNode_; 129 WeakPtr<FrameNode> handleNode_; 130 std::shared_ptr<SelectOverlayInfo> shareOverlayInfo_; 131 WeakPtr<FrameNode> rootNodeWeak_; 132 int32_t selectionHoldId_ = -1; 133 std::optional<HoldSelectionInfo> holdSelectionInfo_; 134 LegacyManagerCallbacks legacyManagerCallbacks_; 135 bool isIntercept_ = false; 136 137 ACE_DISALLOW_COPY_AND_MOVE(SelectContentOverlayManager); 138 }; 139 } // namespace OHOS::Ace::NG 140 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MANAGER_SELECT_CONTENT_OVERLAY_SELECT_CONTENT_OVERLAY_MANAGER_H 141