1 /*
2  * Copyright (c) 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 DRAG_PARAMS_H
17 #define DRAG_PARAMS_H
18 
19 #include <memory>
20 
21 #include "transaction/rs_transaction.h"
22 
23 #include "default_params.h"
24 #include "drag_data.h"
25 #include "intention_identity.h"
26 
27 namespace OHOS {
28 namespace Msdp {
29 namespace DeviceStatus {
30 enum DragRequestID : uint32_t {
31     UNKNOWN_DRAG_ACTION,
32     ADD_DRAG_LISTENER,
33     REMOVE_DRAG_LISTENER,
34     ADD_SUBSCRIPT_LISTENER,
35     REMOVE_SUBSCRIPT_LISTENER,
36     SET_DRAG_WINDOW_VISIBLE,
37     UPDATE_DRAG_STYLE,
38     UPDATE_SHADOW_PIC,
39     GET_DRAG_TARGET_PID,
40     GET_UDKEY,
41     GET_SHADOW_OFFSET,
42     GET_DRAG_DATA,
43     UPDATE_PREVIEW_STYLE,
44     UPDATE_PREVIEW_STYLE_WITH_ANIMATION,
45     ROTATE_DRAG_WINDOW_SYNC,
46     GET_DRAG_SUMMARY,
47     GET_DRAG_STATE,
48     ADD_PRIVILEGE,
49     ENTER_TEXT_EDITOR_AREA,
50     SET_MOUSE_DRAG_MONITOR_STATE,
51     GET_DRAG_ACTION,
52     GET_EXTRA_INFO,
53     ERASE_MOUSE_ICON,
54     SET_DRAG_WINDOW_SCREEN_ID,
55 };
56 
57 struct StartDragParam final : public ParamBase {
58     explicit StartDragParam(DragData &dragData);
59     explicit StartDragParam(const DragData &dragData);
60 
61     bool Marshalling(MessageParcel &parcel) const override;
62     bool Unmarshalling(MessageParcel &parcel) override;
63 
64     // For efficiency, we want to avoid copying 'DragData' whenever possible.
65     // Considering the 'Start drag' scenario, we use 'StartDragParam' simply
66     // as wrapper of 'DragData' and serialize 'DragData' in the right same
67     // call. We do not dereference 'DragData' or keep a reference to it for
68     // later use. In this case, we can safely keep a pointer to the input 'DragData'.
69     DragData *dragDataPtr_ { nullptr };
70     const DragData *cDragDataPtr_ { nullptr };
71 };
72 
73 struct StopDragParam final : public ParamBase {
74     StopDragParam() = default;
75     explicit StopDragParam(const DragDropResult &dropResult);
76 
77     bool Marshalling(MessageParcel &parcel) const override;
78     bool Unmarshalling(MessageParcel &parcel) override;
79 
80     DragDropResult dropResult_ {};
81 };
82 
83 struct SetDragWindowVisibleParam final : public ParamBase {
84     SetDragWindowVisibleParam() = default;
85     SetDragWindowVisibleParam(bool visible, bool isForce);
86 
87     bool Marshalling(MessageParcel &parcel) const override;
88     bool Unmarshalling(MessageParcel &parcel) override;
89 
90     bool visible_ { false };
91     bool isForce_ { false };
92 };
93 
94 struct UpdateDragStyleParam final : public ParamBase {
95     UpdateDragStyleParam() = default;
96     explicit UpdateDragStyleParam(DragCursorStyle style, int32_t eventId);
97 
98     bool Marshalling(MessageParcel &parcel) const override;
99     bool Unmarshalling(MessageParcel &parcel) override;
100 
101     DragCursorStyle cursorStyle_ { DragCursorStyle::DEFAULT };
102     int32_t eventId_ { -1 };
103 };
104 
105 struct UpdateShadowPicParam final : public ParamBase {
106     UpdateShadowPicParam() = default;
107     explicit UpdateShadowPicParam(const ShadowInfo &shadowInfo);
108 
109     bool Marshalling(MessageParcel &parcel) const override;
110     bool Unmarshalling(MessageParcel &parcel) override;
111 
112     ShadowInfo shadowInfo_ {};
113 };
114 
115 struct GetDragTargetPidReply : public ParamBase {
116     GetDragTargetPidReply() = default;
117     explicit GetDragTargetPidReply(int32_t pid);
118 
119     bool Marshalling(MessageParcel &parcel) const override;
120     bool Unmarshalling(MessageParcel &parcel) override;
121 
122     int32_t targetPid_ { -1 };
123 };
124 
125 struct GetUdKeyReply final : public ParamBase {
126     GetUdKeyReply() = default;
127     explicit GetUdKeyReply(std::string &&udKey);
128 
129     bool Marshalling(MessageParcel &parcel) const override;
130     bool Unmarshalling(MessageParcel &parcel) override;
131 
132     std::string udKey_;
133 };
134 
135 struct GetShadowOffsetReply final : public ParamBase {
136     GetShadowOffsetReply() = default;
137     explicit GetShadowOffsetReply(const ShadowOffset &shadowOffset);
138 
139     bool Marshalling(MessageParcel &parcel) const override;
140     bool Unmarshalling(MessageParcel &parcel) override;
141 
142     ShadowOffset shadowOffset_ {};
143 };
144 
145 using GetDragDataReply = StartDragParam;
146 
147 struct UpdatePreviewStyleParam final : public ParamBase {
148     UpdatePreviewStyleParam() = default;
149     explicit UpdatePreviewStyleParam(const PreviewStyle &previewStyle);
150 
151     bool Marshalling(MessageParcel &parcel) const override;
152     bool Unmarshalling(MessageParcel &parcel) override;
153 
154     PreviewStyle previewStyle_;
155 };
156 
157 struct UpdatePreviewAnimationParam final : public ParamBase {
158     UpdatePreviewAnimationParam() = default;
159     UpdatePreviewAnimationParam(const PreviewStyle &previewStyle, const PreviewAnimation &animation);
160 
161     bool Marshalling(MessageParcel &parcel) const override;
162     bool Unmarshalling(MessageParcel &parcel) override;
163 
164     PreviewStyle previewStyle_ {};
165     PreviewAnimation previewAnimation_ {};
166 };
167 
168 struct RotateDragWindowSyncParam final : public ParamBase {
169     RotateDragWindowSyncParam() = default;
170     explicit RotateDragWindowSyncParam(const std::shared_ptr<Rosen::RSTransaction>& rsTransaction);
171 
172     bool Marshalling(MessageParcel &parcel) const override;
173     bool Unmarshalling(MessageParcel &parcel) override;
174 
175     std::shared_ptr<Rosen::RSTransaction> rsTransaction_ { nullptr };
176 };
177 
178 struct SetDragWindowScreenIdParam final : public ParamBase {
179     SetDragWindowScreenIdParam() = default;
180     SetDragWindowScreenIdParam(uint64_t displayId, uint64_t screenId);
181 
182     bool Marshalling(MessageParcel &parcel) const override;
183     bool Unmarshalling(MessageParcel &parcel) override;
184 
185     uint64_t displayId_ { 0 };
186     uint64_t screenId_ { 0 };
187 };
188 
189 struct AddDraglistenerParam final : public ParamBase {
190     AddDraglistenerParam() = default;
191     AddDraglistenerParam(bool isJsCaller);
192 
193     bool Marshalling(MessageParcel &parcel) const override;
194     bool Unmarshalling(MessageParcel &parcel) override;
195 
196     bool isJsCaller_ { false };
197 };
198 
199 struct RemoveDraglistenerParam final : public ParamBase {
200     RemoveDraglistenerParam() = default;
201     RemoveDraglistenerParam(bool isJsCaller);
202 
203     bool Marshalling(MessageParcel &parcel) const override;
204     bool Unmarshalling(MessageParcel &parcel) override;
205 
206     bool isJsCaller_ { false };
207 };
208 
209 struct GetDragSummaryParam final : public ParamBase {
210     GetDragSummaryParam() = default;
211     GetDragSummaryParam(bool isJsCaller);
212 
213     bool Marshalling(MessageParcel &parcel) const override;
214     bool Unmarshalling(MessageParcel &parcel) override;
215 
216     bool isJsCaller_ { false };
217 };
218 
219 struct GetDragSummaryReply final : public ParamBase {
220     GetDragSummaryReply() = default;
221     explicit GetDragSummaryReply(std::map<std::string, int64_t> &&summary);
222 
223     bool Marshalling(MessageParcel &parcel) const override;
224     bool Unmarshalling(MessageParcel &parcel) override;
225 
226     std::map<std::string, int64_t> summary_;
227 };
228 
229 struct GetDragStateReply final : public ParamBase {
230     GetDragStateReply() = default;
231     explicit GetDragStateReply(DragState dragState);
232 
233     bool Marshalling(MessageParcel &parcel) const override;
234     bool Unmarshalling(MessageParcel &parcel) override;
235 
236     DragState dragState_ { DragState::ERROR };
237 };
238 
239 using EnterTextEditorAreaParam = BooleanReply;
240 using SetMouseDragMonitorStateParam = BooleanReply;
241 struct GetDragActionReply final : public ParamBase {
242     GetDragActionReply() = default;
243     explicit GetDragActionReply(DragAction dragAction);
244 
245     bool Marshalling(MessageParcel &parcel) const override;
246     bool Unmarshalling(MessageParcel &parcel) override;
247 
248     DragAction dragAction_ { DragAction::INVALID };
249 };
250 
251 struct GetExtraInfoReply final : public ParamBase {
252     GetExtraInfoReply() = default;
253     explicit GetExtraInfoReply(std::string &&extraInfo);
254 
255     bool Marshalling(MessageParcel &parcel) const override;
256     bool Unmarshalling(MessageParcel &parcel) override;
257 
258     std::string extraInfo_;
259 };
260 } // namespace DeviceStatus
261 } // namespace Msdp
262 } // namespace OHOS
263 #endif // DRAG_PARAMS_H
264