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 enum class NodeType { 37 HANDLE, TOUCH_MENU, HANDLE_WITH_MENU, RIGHT_CLICK_MENU 38 }; 39 40 class ACE_EXPORT SelectContentOverlayManager : public virtual AceType { 41 DECLARE_ACE_TYPE(SelectContentOverlayManager, AceType); 42 43 public: SelectContentOverlayManager(const RefPtr<FrameNode> & rootNode)44 explicit SelectContentOverlayManager(const RefPtr<FrameNode>& rootNode) : rootNodeWeak_(rootNode) {} 45 ~SelectContentOverlayManager() override = default; 46 static const RefPtr<SelectContentOverlayManager> GetOverlayManager( 47 const RefPtr<SelectOverlayHolder>& holder = nullptr); 48 bool IsOpen(); 49 bool IsCreating(); 50 void Show(bool animation, int32_t requestCode); 51 void Close(int32_t id, bool animation, CloseReason reason); 52 bool CloseCurrent(bool animation, CloseReason reason); 53 void CloseWithOverlayId(int32_t overlayId, CloseReason reason, bool animation); 54 void ShowOptionMenu(); 55 void HideOptionMenu(bool noAnimation = false); 56 void ToggleOptionMenu(); 57 void DisableMenu(); 58 void EnableMenu(); 59 void HideHandle(); 60 void HandleGlobalEvent(const TouchEvent& touchPoint, const NG::OffsetF& rootOffset); 61 void SetHoldSelectionCallback(int32_t id, const HoldSelectionInfo& selectionInfo); 62 void RemoveHoldSelectionCallback(int32_t id); 63 void MarkInfoChange(SelectOverlayDirtyFlag dirtyFlag); 64 void MarkSelectOverlayDirty(PropertyChangeFlag changeFlag); 65 bool IsMenuShow(); 66 bool IsSingleHandle(); 67 bool IsHandlesShow(); 68 bool IsHandleReverse(); 69 void ResetSelectionRect(); 70 void RestartHiddenHandleTask(bool isDelay); 71 void CancelHiddenHandleTask(); 72 const RefPtr<FrameNode> GetSelectOverlayRoot(); 73 RefPtr<SelectOverlayNode> GetSelectOverlayNode(); 74 OptionMenuType GetShowMenuType(); 75 GetSelectOverlayInfo()76 std::optional<SelectOverlayInfo> GetSelectOverlayInfo() 77 { 78 return shareOverlayInfo_ ? *shareOverlayInfo_ : std::optional<SelectOverlayInfo>(); 79 } 80 SetLegacyManagerBridge(const LegacyManagerCallbacks & callbacks)81 void SetLegacyManagerBridge(const LegacyManagerCallbacks& callbacks) 82 { 83 legacyManagerCallbacks_ = callbacks; 84 } 85 86 RefPtr<Pattern> GetMenuPattern(); 87 RefPtr<Pattern> GetHandlePattern(); 88 RefPtr<FrameNode> GetHandleOverlayNode(); 89 void NotifyUpdateToolBar(bool itemChanged); 90 void SwitchToHandleMode(HandleLevelMode mode, bool forceChange = true); 91 float GetHandleDiameter(); 92 void ConvertPointRelativeToNode(const RefPtr<FrameNode>& node, PointF& point); 93 bool IsTouchAtHandle(const PointF& localPoint, const PointF& globalPoint); 94 void UpdateViewPort(); 95 void SetHandleCircleIsShow(bool isFirst, bool isShow); 96 void SetIsHandleLineShow(bool isShow); 97 void MarkHandleDirtyNode(PropertyChangeFlag flag); 98 void ConvertHandleRelativeToParent(SelectHandleInfo& info); 99 void ConvertRectRelativeToParent(RectF& rect); 100 void RevertRectRelativeToRoot(RectF& rect); 101 OffsetF GetContainerModalOffset(); 102 bool IsStopBackPress() const; 103 104 private: 105 void SetHolder(const RefPtr<SelectOverlayHolder>& holder); 106 bool HasHolder(int32_t holderId); 107 void SetHolderInternal(const RefPtr<SelectOverlayHolder>& holder); 108 void CreateSelectOverlay(SelectOverlayInfo& info, bool animation = false); 109 void CreateNormalSelectOverlay(SelectOverlayInfo& info, bool animation); 110 void CreateHandleLevelSelectOverlay(SelectOverlayInfo& info, bool animation, HandleLevelMode mode); 111 void UpdateExistOverlay(const SelectOverlayInfo& info, bool animation, int32_t requestCode); 112 bool IsSameMouseSelectOverlay(const SelectOverlayInfo& info); 113 bool CloseInternal(int32_t holderId, bool animation, CloseReason reason); 114 void DestroySelectOverlayNode(const RefPtr<FrameNode>& node); 115 void DestroySelectOverlayNodeWithAnimation(const RefPtr<FrameNode>& node); 116 void MountNodeToRoot(const RefPtr<FrameNode>& overlayNode, bool animation, NodeType nodeType); 117 void MountNodeToCaller(const RefPtr<FrameNode>& overlayNode, bool animation); 118 std::function<void()> MakeMenuCallback(OptionMenuActionId actionId, const SelectOverlayInfo& info); 119 SelectOverlayInfo BuildSelectOverlayInfo(int32_t requestCode); 120 void UpdateStatusInfos(SelectOverlayInfo& info); 121 void RegisterTouchCallback(SelectOverlayInfo& info); 122 void RegisterHandleCallback(SelectOverlayInfo& info); 123 void HandleSelectionEvent(const PointF& point, const TouchEvent& rawTouchEvent); 124 void UpdateHandleInfosWithFlag(int32_t updateFlag); 125 bool IsTouchInSelectOverlayArea(const PointF& point); 126 bool IsTouchInNormalSelectOverlayArea(const PointF& point); 127 bool IsTouchInHandleLevelOverlayArea(const PointF& point); 128 RefPtr<UINode> FindWindowScene(RefPtr<FrameNode> targetNode); 129 void ClearAllStatus(); 130 bool IsEnableHandleLevel(); 131 void NotifySelectOverlayShow(bool isCreated); 132 std::list<RefPtr<UINode>>::const_iterator FindSelectOverlaySlot( 133 const RefPtr<FrameNode>& root, const std::list<RefPtr<UINode>>& children); 134 RefPtr<FrameNode> GetContainerModalRoot(); 135 void UpdateSelectOverlayInfoInternal(SelectOverlayInfo& overlayInfo); 136 137 RefPtr<SelectOverlayHolder> selectOverlayHolder_; 138 WeakPtr<FrameNode> selectOverlayNode_; 139 WeakPtr<FrameNode> menuNode_; 140 WeakPtr<FrameNode> handleNode_; 141 std::shared_ptr<SelectOverlayInfo> shareOverlayInfo_; 142 WeakPtr<FrameNode> rootNodeWeak_; 143 int32_t selectionHoldId_ = -1; 144 std::optional<HoldSelectionInfo> holdSelectionInfo_; 145 LegacyManagerCallbacks legacyManagerCallbacks_; 146 bool isIntercept_ = false; 147 148 ACE_DISALLOW_COPY_AND_MOVE(SelectContentOverlayManager); 149 }; 150 } // namespace OHOS::Ace::NG 151 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MANAGER_SELECT_CONTENT_OVERLAY_SELECT_CONTENT_OVERLAY_MANAGER_H 152