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     ADD_SELECTED_PIXELMAP,
56 };
57 
58 struct StartDragParam final : public ParamBase {
59     explicit StartDragParam(DragData &dragData);
60     explicit StartDragParam(const DragData &dragData);
61 
62     bool Marshalling(MessageParcel &parcel) const override;
63     bool Unmarshalling(MessageParcel &parcel) override;
64 
65     // For efficiency, we want to avoid copying 'DragData' whenever possible.
66     // Considering the 'Start drag' scenario, we use 'StartDragParam' simply
67     // as wrapper of 'DragData' and serialize 'DragData' in the right same
68     // call. We do not dereference 'DragData' or keep a reference to it for
69     // later use. In this case, we can safely keep a pointer to the input 'DragData'.
70     DragData *dragDataPtr_ { nullptr };
71     const DragData *cDragDataPtr_ { nullptr };
72 };
73 
74 struct StopDragParam final : public ParamBase {
75     StopDragParam() = default;
76     explicit StopDragParam(const DragDropResult &dropResult);
77 
78     bool Marshalling(MessageParcel &parcel) const override;
79     bool Unmarshalling(MessageParcel &parcel) override;
80 
81     DragDropResult dropResult_ {};
82 };
83 
84 struct SetDragWindowVisibleParam final : public ParamBase {
85     SetDragWindowVisibleParam() = default;
86     SetDragWindowVisibleParam(bool visible, bool isForce);
87 
88     bool Marshalling(MessageParcel &parcel) const override;
89     bool Unmarshalling(MessageParcel &parcel) override;
90 
91     bool visible_ { false };
92     bool isForce_ { false };
93 };
94 
95 struct UpdateDragStyleParam final : public ParamBase {
96     UpdateDragStyleParam() = default;
97     explicit UpdateDragStyleParam(DragCursorStyle style, int32_t eventId);
98 
99     bool Marshalling(MessageParcel &parcel) const override;
100     bool Unmarshalling(MessageParcel &parcel) override;
101 
102     DragCursorStyle cursorStyle_ { DragCursorStyle::DEFAULT };
103     int32_t eventId_ { -1 };
104 };
105 
106 struct UpdateShadowPicParam final : public ParamBase {
107     UpdateShadowPicParam() = default;
108     explicit UpdateShadowPicParam(const ShadowInfo &shadowInfo);
109 
110     bool Marshalling(MessageParcel &parcel) const override;
111     bool Unmarshalling(MessageParcel &parcel) override;
112 
113     ShadowInfo shadowInfo_ {};
114 };
115 
116 struct GetDragTargetPidReply : public ParamBase {
117     GetDragTargetPidReply() = default;
118     explicit GetDragTargetPidReply(int32_t pid);
119 
120     bool Marshalling(MessageParcel &parcel) const override;
121     bool Unmarshalling(MessageParcel &parcel) override;
122 
123     int32_t targetPid_ { -1 };
124 };
125 
126 struct GetUdKeyReply final : public ParamBase {
127     GetUdKeyReply() = default;
128     explicit GetUdKeyReply(std::string &&udKey);
129 
130     bool Marshalling(MessageParcel &parcel) const override;
131     bool Unmarshalling(MessageParcel &parcel) override;
132 
133     std::string udKey_;
134 };
135 
136 struct GetShadowOffsetReply final : public ParamBase {
137     GetShadowOffsetReply() = default;
138     explicit GetShadowOffsetReply(const ShadowOffset &shadowOffset);
139 
140     bool Marshalling(MessageParcel &parcel) const override;
141     bool Unmarshalling(MessageParcel &parcel) override;
142 
143     ShadowOffset shadowOffset_ {};
144 };
145 
146 using GetDragDataReply = StartDragParam;
147 
148 struct UpdatePreviewStyleParam final : public ParamBase {
149     UpdatePreviewStyleParam() = default;
150     explicit UpdatePreviewStyleParam(const PreviewStyle &previewStyle);
151 
152     bool Marshalling(MessageParcel &parcel) const override;
153     bool Unmarshalling(MessageParcel &parcel) override;
154 
155     PreviewStyle previewStyle_;
156 };
157 
158 struct UpdatePreviewAnimationParam final : public ParamBase {
159     UpdatePreviewAnimationParam() = default;
160     UpdatePreviewAnimationParam(const PreviewStyle &previewStyle, const PreviewAnimation &animation);
161 
162     bool Marshalling(MessageParcel &parcel) const override;
163     bool Unmarshalling(MessageParcel &parcel) override;
164 
165     PreviewStyle previewStyle_ {};
166     PreviewAnimation previewAnimation_ {};
167 };
168 
169 struct RotateDragWindowSyncParam final : public ParamBase {
170     RotateDragWindowSyncParam() = default;
171     explicit RotateDragWindowSyncParam(const std::shared_ptr<Rosen::RSTransaction>& rsTransaction);
172 
173     bool Marshalling(MessageParcel &parcel) const override;
174     bool Unmarshalling(MessageParcel &parcel) override;
175 
176     std::shared_ptr<Rosen::RSTransaction> rsTransaction_ { nullptr };
177 };
178 
179 struct SetDragWindowScreenIdParam final : public ParamBase {
180     SetDragWindowScreenIdParam() = default;
181     SetDragWindowScreenIdParam(uint64_t displayId, uint64_t screenId);
182 
183     bool Marshalling(MessageParcel &parcel) const override;
184     bool Unmarshalling(MessageParcel &parcel) override;
185 
186     uint64_t displayId_ { 0 };
187     uint64_t screenId_ { 0 };
188 };
189 
190 struct AddDraglistenerParam final : public ParamBase {
191     AddDraglistenerParam() = default;
192     AddDraglistenerParam(bool isJsCaller);
193 
194     bool Marshalling(MessageParcel &parcel) const override;
195     bool Unmarshalling(MessageParcel &parcel) override;
196 
197     bool isJsCaller_ { false };
198 };
199 
200 struct RemoveDraglistenerParam final : public ParamBase {
201     RemoveDraglistenerParam() = default;
202     RemoveDraglistenerParam(bool isJsCaller);
203 
204     bool Marshalling(MessageParcel &parcel) const override;
205     bool Unmarshalling(MessageParcel &parcel) override;
206 
207     bool isJsCaller_ { false };
208 };
209 
210 struct GetDragSummaryParam final : public ParamBase {
211     GetDragSummaryParam() = default;
212     GetDragSummaryParam(bool isJsCaller);
213 
214     bool Marshalling(MessageParcel &parcel) const override;
215     bool Unmarshalling(MessageParcel &parcel) override;
216 
217     bool isJsCaller_ { false };
218 };
219 
220 struct GetDragSummaryReply final : public ParamBase {
221     GetDragSummaryReply() = default;
222     explicit GetDragSummaryReply(std::map<std::string, int64_t> &&summary);
223 
224     bool Marshalling(MessageParcel &parcel) const override;
225     bool Unmarshalling(MessageParcel &parcel) override;
226 
227     std::map<std::string, int64_t> summary_;
228 };
229 
230 struct GetDragStateReply final : public ParamBase {
231     GetDragStateReply() = default;
232     explicit GetDragStateReply(DragState dragState);
233 
234     bool Marshalling(MessageParcel &parcel) const override;
235     bool Unmarshalling(MessageParcel &parcel) override;
236 
237     DragState dragState_ { DragState::ERROR };
238 };
239 
240 using EnterTextEditorAreaParam = BooleanReply;
241 using SetMouseDragMonitorStateParam = BooleanReply;
242 struct GetDragActionReply final : public ParamBase {
243     GetDragActionReply() = default;
244     explicit GetDragActionReply(DragAction dragAction);
245 
246     bool Marshalling(MessageParcel &parcel) const override;
247     bool Unmarshalling(MessageParcel &parcel) override;
248 
249     DragAction dragAction_ { DragAction::INVALID };
250 };
251 
252 struct GetExtraInfoReply final : public ParamBase {
253     GetExtraInfoReply() = default;
254     explicit GetExtraInfoReply(std::string &&extraInfo);
255 
256     bool Marshalling(MessageParcel &parcel) const override;
257     bool Unmarshalling(MessageParcel &parcel) override;
258 
259     std::string extraInfo_;
260 };
261 
262 struct AddSelectedPixelMapParam final : public ParamBase {
263     AddSelectedPixelMapParam() = default;
264     explicit AddSelectedPixelMapParam(std::shared_ptr<OHOS::Media::PixelMap> pixelMap);
265 
266     bool Marshalling(MessageParcel &parcel) const override;
267     bool Unmarshalling(MessageParcel &parcel) override;
268 
269     std::shared_ptr<OHOS::Media::PixelMap> pixelMap_ { nullptr };
270 };
271 } // namespace DeviceStatus
272 } // namespace Msdp
273 } // namespace OHOS
274 #endif // DRAG_PARAMS_H
275