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     GET_DRAG_ACTION,
51     GET_EXTRA_INFO,
52     ERASE_MOUSE_ICON,
53     SET_DRAG_WINDOW_SCREEN_ID,
54     ADD_SELECTED_PIXELMAP,
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);
97 
98     bool Marshalling(MessageParcel &parcel) const override;
99     bool Unmarshalling(MessageParcel &parcel) override;
100 
101     DragCursorStyle cursorStyle_ { DragCursorStyle::DEFAULT };
102 };
103 
104 struct UpdateShadowPicParam final : public ParamBase {
105     UpdateShadowPicParam() = default;
106     explicit UpdateShadowPicParam(const ShadowInfo &shadowInfo);
107 
108     bool Marshalling(MessageParcel &parcel) const override;
109     bool Unmarshalling(MessageParcel &parcel) override;
110 
111     ShadowInfo shadowInfo_ {};
112 };
113 
114 struct GetDragTargetPidReply : public ParamBase {
115     GetDragTargetPidReply() = default;
116     explicit GetDragTargetPidReply(int32_t pid);
117 
118     bool Marshalling(MessageParcel &parcel) const override;
119     bool Unmarshalling(MessageParcel &parcel) override;
120 
121     int32_t targetPid_ { -1 };
122 };
123 
124 struct GetUdKeyReply final : public ParamBase {
125     GetUdKeyReply() = default;
126     explicit GetUdKeyReply(std::string &&udKey);
127 
128     bool Marshalling(MessageParcel &parcel) const override;
129     bool Unmarshalling(MessageParcel &parcel) override;
130 
131     std::string udKey_;
132 };
133 
134 struct GetShadowOffsetReply final : public ParamBase {
135     GetShadowOffsetReply() = default;
136     explicit GetShadowOffsetReply(const ShadowOffset &shadowOffset);
137 
138     bool Marshalling(MessageParcel &parcel) const override;
139     bool Unmarshalling(MessageParcel &parcel) override;
140 
141     ShadowOffset shadowOffset_ {};
142 };
143 
144 using GetDragDataReply = StartDragParam;
145 
146 struct UpdatePreviewStyleParam final : public ParamBase {
147     UpdatePreviewStyleParam() = default;
148     explicit UpdatePreviewStyleParam(const PreviewStyle &previewStyle);
149 
150     bool Marshalling(MessageParcel &parcel) const override;
151     bool Unmarshalling(MessageParcel &parcel) override;
152 
153     PreviewStyle previewStyle_;
154 };
155 
156 struct UpdatePreviewAnimationParam final : public ParamBase {
157     UpdatePreviewAnimationParam() = default;
158     UpdatePreviewAnimationParam(const PreviewStyle &previewStyle, const PreviewAnimation &animation);
159 
160     bool Marshalling(MessageParcel &parcel) const override;
161     bool Unmarshalling(MessageParcel &parcel) override;
162 
163     PreviewStyle previewStyle_ {};
164     PreviewAnimation previewAnimation_ {};
165 };
166 
167 struct RotateDragWindowSyncParam final : public ParamBase {
168     RotateDragWindowSyncParam() = default;
169     explicit RotateDragWindowSyncParam(const std::shared_ptr<Rosen::RSTransaction>& rsTransaction);
170 
171     bool Marshalling(MessageParcel &parcel) const override;
172     bool Unmarshalling(MessageParcel &parcel) override;
173 
174     std::shared_ptr<Rosen::RSTransaction> rsTransaction_ { nullptr };
175 };
176 
177 struct SetDragWindowScreenIdParam final : public ParamBase {
178     SetDragWindowScreenIdParam() = default;
179     SetDragWindowScreenIdParam(uint64_t displayId, uint64_t screenId);
180 
181     bool Marshalling(MessageParcel &parcel) const override;
182     bool Unmarshalling(MessageParcel &parcel) override;
183 
184     uint64_t displayId_ { 0 };
185     uint64_t screenId_ { 0 };
186 };
187 
188 struct GetDragSummaryReply final : public ParamBase {
189     GetDragSummaryReply() = default;
190     explicit GetDragSummaryReply(std::map<std::string, int64_t> &&summary);
191 
192     bool Marshalling(MessageParcel &parcel) const override;
193     bool Unmarshalling(MessageParcel &parcel) override;
194 
195     std::map<std::string, int64_t> summary_;
196 };
197 
198 struct GetDragStateReply final : public ParamBase {
199     GetDragStateReply() = default;
200     explicit GetDragStateReply(DragState dragState);
201 
202     bool Marshalling(MessageParcel &parcel) const override;
203     bool Unmarshalling(MessageParcel &parcel) override;
204 
205     DragState dragState_ { DragState::ERROR };
206 };
207 
208 using EnterTextEditorAreaParam = BooleanReply;
209 
210 struct GetDragActionReply final : public ParamBase {
211     GetDragActionReply() = default;
212     explicit GetDragActionReply(DragAction dragAction);
213 
214     bool Marshalling(MessageParcel &parcel) const override;
215     bool Unmarshalling(MessageParcel &parcel) override;
216 
217     DragAction dragAction_ { DragAction::INVALID };
218 };
219 
220 struct GetExtraInfoReply final : public ParamBase {
221     GetExtraInfoReply() = default;
222     explicit GetExtraInfoReply(std::string &&extraInfo);
223 
224     bool Marshalling(MessageParcel &parcel) const override;
225     bool Unmarshalling(MessageParcel &parcel) override;
226 
227     std::string extraInfo_;
228 };
229 
230 struct AddSelectedPixelMapParam final : public ParamBase {
231     AddSelectedPixelMapParam() = default;
232     explicit AddSelectedPixelMapParam(std::shared_ptr<OHOS::Media::PixelMap> pixelMap);
233 
234     bool Marshalling(MessageParcel &parcel) const override;
235     bool Unmarshalling(MessageParcel &parcel) override;
236 
237     std::shared_ptr<OHOS::Media::PixelMap> pixelMap_ { nullptr };
238 };
239 } // namespace DeviceStatus
240 } // namespace Msdp
241 } // namespace OHOS
242 #endif // DRAG_PARAMS_H
243