• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_DRAG_DROP_DRAG_DROP_GLOBAL_CONTROLLER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MANAGER_DRAG_DROP_DRAG_DROP_GLOBAL_CONTROLLER_H
18 
19 #include <atomic>
20 #include <cstdint>
21 #include <memory>
22 #include <mutex>
23 #include <shared_mutex>
24 #include <unordered_map>
25 
26 #include "base/memory/referenced.h"
27 #include "base/utils/macros.h"
28 #include "base/utils/noncopyable.h"
29 #include "core/gestures/drag_event.h"
30 
31 namespace OHOS::Ace::NG {
32 class FrameNode;
33 class ACE_FORCE_EXPORT DragDropGlobalController {
34 public:
35     ~DragDropGlobalController();
36 
37     static DragDropGlobalController& GetInstance();
38 
39     void PublishMenuStatusWithNode(bool isShowing, const RefPtr<FrameNode>& targetNode = nullptr);
40     void UpdateMenuShowingStatus(bool isShowing);
41     bool IsMenuShowing() const;
42     bool IsInMoving() const;
43     void ResetDragDropInitiatingStatus();
44     void UpdateDragDropInitiatingStatus(const RefPtr<FrameNode>& frameNode,
45         const DragDropInitiatingStatus& dragStatus);
46     void SetPrepareDragFrameNode(const WeakPtr<FrameNode>& prepareDragFrameNode);
47     const WeakPtr<FrameNode> GetPrepareDragFrameNode() const;
48     void SetPreDragStatus(PreDragStatus preDragStatus);
49     PreDragStatus GetPreDragStatus() const;
50     void SetEnableDropDisallowedBadge(bool enableDisallowStatusShowing);
51     bool GetEnableDropDisallowedBadge() const;
52     void UpdateDragFilterShowingStatus(bool isShowing);
53     bool IsDragFilterShowing() const;
54     bool IsOnOnDropPhase();
55     void SetIsOnOnDropPhase(bool isOnOnDropPhase);
56     bool RequestDragEndCallback(int32_t requestId, DragRet dragResult,
57         std::function<void(const DragRet&)> stopDragCallback);
58     int32_t NotifyDragResult(int32_t requestId, int32_t result);
59     int32_t NotifyDragEndPendingDone(int32_t requestId);
60 
61     // app global drag
62     void SetIsAppGlobalDragEnabled(bool isAppGlobalDragEnabled);
63     bool IsAppGlobalDragEnabled() const;
64     bool IsAlreadyGetAppGlobalDrag() const;
65 
66     void SetDragStartRequestStatus(DragStartRequestStatus dragStartRequestStatus);
67 
68     DragStartRequestStatus GetDragStartRequestStatus();
69 
70     void SetAsyncDragCallback(std::function<void()> asyncDragCallbac);
71 
72     std::function<void()> GetAsyncDragCallback();
73 
74     void SetCallAnsyncDragEnd(std::function<void(DragStartRequestStatus)> callSyncDragEnd);
75 
76     std::function<void(DragStartRequestStatus)> GetCallAnsyncEnd();
77 
78     bool IsCurrentDrag(int32_t requestId) const;
79 private:
80     DragDropGlobalController() = default;
81 
82 private:
83     mutable std::shared_mutex mutex_;
84     // this is the real time menu show status flag, need to change to pair with menu target node in future
85     bool isContextMenuShowing_ = false;
86     ACE_DISALLOW_COPY_AND_MOVE(DragDropGlobalController);
87     RefPtr<FrameNode> currentDragNode_ = nullptr;
88     WeakPtr<FrameNode> prepareDragFrameNode_;
89     WeakPtr<FrameNode> menuLiftingTargetNode_;
90     PreDragStatus preDragStatus_ = PreDragStatus::ACTION_DETECTING_STATUS;
91 
92     bool isDragFilterShowing_ = false;
93 
94     DragStartRequestStatus dragStartRequestStatus_{DragStartRequestStatus::READY};
95     std::function<void()> asyncDragCallback_;
96     std::function<void(DragStartRequestStatus)> callSyncDragEnd_;
97 
98     // use for async on drop
99     bool isOnOnDropPhase_ = false;
100     int32_t requestId_ = -1;
101     std::function<void(const DragRet&)> stopDragCallback_ = nullptr;
102     DragRet dragResult_ = DragRet::DRAG_FAIL;
103 
104     // app global drag
105     bool isAppGlobalDragEnabled_ = false;
106     bool isAlreadyGetAppGlobalDrag_ = false;
107     bool enableDropDisallowedBadge_ = false;
108 };
109 
110 } // namespace OHOS::Ace::NG
111 
112 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MANAGER_DRAG_DROP_DRAG_DROP_GLOBAL_CONTROLLER_H
113