• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 INTERACTION_MANAGER_H
17 #define INTERACTION_MANAGER_H
18 
19 #include <functional>
20 #include <memory>
21 
22 #include "nocopyable.h"
23 
24 #include "coordination_message.h"
25 #include "drag_data.h"
26 #include "i_coordination_listener.h"
27 #include "i_drag_listener.h"
28 #include "i_start_drag_listener.h"
29 #include "i_hotarea_listener.h"
30 #include "i_subscript_listener.h"
31 
32 namespace OHOS {
33 namespace Msdp {
34 namespace DeviceStatus {
35 class InteractionManager {
36 public:
37 
38     static InteractionManager *GetInstance();
39     virtual ~InteractionManager() = default;
40 
41     /**
42      * @brief Registers a listener for screen hopping events of the mouse pointer.
43      * @param listener Indicates the listener for screen hopping events of the mouse pointer.
44      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
45      * @since 9
46      */
47     int32_t RegisterCoordinationListener(std::shared_ptr<ICoordinationListener> listener,
48         bool isCompatible = false);
49 
50     /**
51      * @brief Unregisters a listener for screen hopping events of the mouse pointer.
52      * @param listener Indicates the listener for screen hopping events of the mouse pointer.
53      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
54      * @since 9
55      */
56     int32_t UnregisterCoordinationListener(std::shared_ptr<ICoordinationListener> listener,
57         bool isCompatible = false);
58 
59     /**
60      * @brief Prepares for screen hopping.
61      * @param callback Indicates the callback used to receive the result of enabling or disabling screen hopping.
62      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
63      * @since 9
64      */
65     int32_t PrepareCoordination(std::function<void(const std::string&, CoordinationMessage)> callback,
66         bool isCompatible = false);
67 
68     /**
69      * @brief Cancels the preparation for screen hopping.
70      * @param callback Indicates the callback used to receive the result of enabling or disabling screen hopping.
71      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
72      * @since 9
73      */
74     int32_t UnprepareCoordination(std::function<void(const std::string&, CoordinationMessage)> callback,
75         bool isCompatible = false);
76 
77     /**
78      * @brief Starts screen hopping for the mouse pointer.
79      * @param s remoteNetworkId Indicates the descriptor of the target input device (network ID) for screen hopping.
80      * @param startDeviceId Indicates the ID of the source input device (device ID handle) for screen hopping.
81      * @param callback Indicates the callback used to receive the result of starting screen hopping.
82      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
83      * @since 9
84      */
85     int32_t ActivateCoordination(const std::string &remoteNetworkId, int32_t startDeviceId,
86         std::function<void(const std::string&, CoordinationMessage)> callback, bool isCompatible = false);
87 
88     /**
89      * @brief Stops screen hopping for the mouse pointer.
90      * @param isUnchained Specifies Whether to disable the cross-device link.
91      * The value <b>true</b> means to disable the cross-device link, and <b>false</b> means the opposite.
92      * @param callback Indicates the callback used to receive the result of stopping screen hopping.
93      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
94      * @since 9
95      */
96     int32_t DeactivateCoordination(bool isUnchained,
97         std::function<void(const std::string&, CoordinationMessage)> callback, bool isCompatible = false);
98 
99     /**
100      * @brief Obtains the screen hopping status of a mouse pointer.
101      * @param networkId Indicates the descriptor of the input device.
102      * @param callback Indicates the callback used to receive the screen hopping status.
103      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
104      * @since 9
105      */
106     int32_t GetCoordinationState(const std::string &networkId, std::function<void(bool)> callback,
107         bool isCompatible = false);
108 
109     /**
110      * @brief Starts dragging.
111      * @param dragData Indicates additional data used for dragging.
112      * @param listener Indicates the listener used to notify dragging result etc.
113      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
114      * @since 10
115      */
116     int32_t StartDrag(const DragData &dragData, std::shared_ptr<IStartDragListener> listener);
117 
118     /**
119      * @brief Stops dragging.
120      * @param result Indicates the dragging result. The value <b>0</b> means that the dragging operation is successful;
121      * <b>1</b> means that the dragging operation is failed; <b>2</b> means that the dragging operation is canceled.
122      * @param hasCustomAnimation Specifies whether a custom animation is played when the dragging is successful.
123      * The value <b>true</b> means that a custom animation is played,
124      * and <b>false</b> means that the default animation is played.
125      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
126      * @since 10
127      */
128     int32_t StopDrag(const DragDropResult &dropResult);
129 
130     /**
131      * @brief Updates the mouse pointer style used for dragging.
132      * @param style Indicates the new mouse pointer style.
133      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
134      * @since 10
135      */
136     int32_t UpdateDragStyle(DragCursorStyle style);
137 
138     /**
139      * @brief Obtains the PID of the target window.
140      * @return Returns a value greater than or equal to 0 in normal cases; returns <b>-1</b> if the PID is invalid.
141      * @since 10
142      */
143     int32_t GetDragTargetPid();
144 
145     /**
146      * @brief Obtains the unified data key of the target window.
147      * @param UdKey Indicates the unified data key of the target window.
148      * @return Returns a value greater than or equal to 0 in normal cases; returns <b>-1</b> if the PID is invalid.
149      * @since 10
150      */
151     int32_t GetUdKey(std::string &udKey);
152 
153     /**
154      * @brief Registers a listener for dragging status changes.
155      * @param listener Indicates the listener for dragging status changes.
156      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
157      * @since 10
158      */
159     int32_t AddDraglistener(std::shared_ptr<IDragListener> listener);
160 
161     /**
162      * @brief Unregisters a listener for dragging status changes.
163      * @param listener Indicates the listener for dragging status changes.
164      * If no value is passed, all listeners are canceled.
165      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
166      * @since 10
167      */
168     int32_t RemoveDraglistener(std::shared_ptr<IDragListener> listener = nullptr);
169 
170     /**
171      * @brief Register a listener for dragging corner style changes.
172      * @param listener Indicates the listener for dragging corner style changes.
173      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
174      * @since 10
175      */
176     int32_t AddSubscriptListener(std::shared_ptr<ISubscriptListener> listener);
177 
178     /**
179      * @brief Unregisters a listener for dragging corner style changes.
180      * @param listener Indicates the listener for dragging corner style changes.
181      * If no value is passed, all listeners are canceled.
182      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
183      * @since 10
184      */
185     int32_t RemoveSubscriptListener(std::shared_ptr<ISubscriptListener> listener);
186 
187     /**
188      * @brief Displays or hides the dragging window.
189      * @param visible Specifies whether to display the dragging window.
190      * The value <b>true</b> means to display the dragging window, and <b>false</b> means to hide the window.
191      * @param isForce Specifies Enforce the visibility of the drag window, which is applied to this drag.
192      * For example, if you set the drag window to Hidden and isForce to true during a drag, the setting does not
193      * take effect when the drag window is displayed and isForce is false, and the setting becomes invalid at the
194      * end of the current drag.
195      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
196      * @since 10
197      */
198     int32_t SetDragWindowVisible(bool visible, bool isForce = false);
199 
200     /**
201      * @brief Obtains the position of the touch point or mouse pointer relative to
202      * the upper left corner of the shadow thumbnail.
203      * @param offsetX Indicates the x coordinate.
204      * @param offsetY Indicates the y coordinate.
205      * @param width Indicates the width of the shadow thumbnail.
206      * @param height Indicates the height of the shadow thumbnail.
207      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
208      * @since 10
209      */
210     int32_t GetShadowOffset(int32_t &offsetX, int32_t &offsetY, int32_t &width, int32_t &height);
211 
212     /**
213      * @brief Updates the shadow thumbnail information used for dragging.
214      * @param shadowInfo Indicates the new shadow thumbnail information.
215      * @return Returns <b>0</b> if the operation is successful; returns other values if the operation fails.
216      * @since 10
217      */
218     int32_t UpdateShadowPic(const ShadowInfo &shadowInfo);
219 
220     /**
221      * @brief Obtains the dragging data.
222      * @param dragData Indicates the dragging data.
223      * @return Returns <b>0</b> if the operation is successful; returns other values if the operation fails.
224      * @since 10
225      */
226     int32_t GetDragData(DragData &dragData);
227 
228     /**
229      * @brief Obtains the current droping type.
230      * @param dragAction dropping type while user pressed ctrl or not.
231      * @return Returns <b>0</b> if the operation is successful; returns other values if the operation fails.
232      * @since 10
233      */
234     int32_t GetDragAction(DragAction &dragAction);
235 
236     /**
237      * @brief Obtains the 'extraInfo' field in the drag data.
238      * @param extraInfo Indicates the 'extraInfo' field in the drag data, mainly to save whether to allow drag across
239      * the device "drag_allow_distributed" field.
240      * @return Returns <b>0</b> if the operation is successful; returns other values if the operation fails.
241      * @since 10
242      */
243     int32_t GetExtraInfo(std::string &extraInfo);
244 
245     /**
246      * @brief Registers a listener for screen hot area of the mouse pointer.
247      * @param listener Indicates the listener for screen hot area of the mouse pointer.
248      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
249      * @since 11
250      */
251     int32_t AddHotAreaListener(std::shared_ptr<IHotAreaListener> listener);
252 
253     /**
254      * @brief Obtains the dragging state.
255      * @param dragState Dragging state.
256      * @return Returns <b>0</b> if the operation is successful; returns other values if the operation fails.
257      * @since 10
258      */
259     int32_t GetDragState(DragState &dragState);
260 
261     /**
262      * @brief Unregisters a listener for screen hot area of the mouse pointer.
263      * @param listener Indicates the listener for screen hot area of the mouse pointer.
264      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
265      * @since 9
266      */
267     int32_t RemoveHotAreaListener(std::shared_ptr<IHotAreaListener> listener = nullptr);
268 
269     /**
270      * @brief Update preview style when dragging.
271      * @param previewStyle Indicates the preview style param for dragged item.
272      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
273      * @since 11
274      */
275     int32_t UpdatePreviewStyle(const PreviewStyle &previewStyle);
276 
277     /**
278      * @brief Update preview style with animation when dragging.
279      * @param previewStyle Indicates the preview style param for dragged item.
280      * @param animation Indicates the animation param for dragged item.
281      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
282      * @since 11
283      */
284     int32_t UpdatePreviewStyleWithAnimation(const PreviewStyle &previewStyle, const PreviewAnimation &animation);
285 
286     /**
287      * @brief Obtains data summary of the drag object.
288      * @param summarys Indicates data summary of the drag object.
289      * @return Returns <b>0</b> if the operation is successful; returns other values if the operation fails.
290      * @since 11
291      */
292     int32_t GetDragSummary(std::map<std::string, int64_t> &summarys);
293 
294     /**
295      * @brief Specifies whether to implement 8dp movement in the text editor area.
296      * @param enable Indicates whether to enable 8dp movement.
297      * The value <b>true</b> means to enable 8dp movement, and the value <b>false</b> means the opposite.
298      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
299      * @since 11
300      */
301     int32_t EnterTextEditorArea(bool enable);
302 
303     int32_t AddPrivilege();
304 
305 private:
306     InteractionManager() = default;
307     DISALLOW_COPY_AND_MOVE(InteractionManager);
308     static InteractionManager *instance_;
309 };
310 } // namespace DeviceStatus
311 } // namespace Msdp
312 } // namespace OHOS
313 
314 #define INTERACTION_MGR OHOS::Msdp::DeviceStatus::InteractionManager::GetInstance()
315 
316 #endif // INTERACTION_MANAGER_H
317