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 #include "drag_data_manager.h"
17
18 #include "devicestatus_define.h"
19 #include "drag_data.h"
20 #include "fi_log.h"
21
22 #undef LOG_TAG
23 #define LOG_TAG "DragDataManager"
24
25 namespace OHOS {
26 namespace Msdp {
27 namespace DeviceStatus {
28 namespace {
29 constexpr int32_t DEFAULT_DISPLAY_ID { 0 };
30 } // namespace
31
32 DragDataManager::DragDataManager() = default;
33 DragDataManager::~DragDataManager() = default;
34
SetDragStyle(DragCursorStyle style)35 void DragDataManager::SetDragStyle(DragCursorStyle style)
36 {
37 dragStyle_ = style;
38 }
39
Init(const DragData & dragData,const std::string & appCaller)40 void DragDataManager::Init(const DragData &dragData, const std::string &appCaller)
41 {
42 dragData_ = dragData;
43 dragData_.appCaller = appCaller;
44 if (dragData.displayId < DEFAULT_DISPLAY_ID) {
45 dragData_.displayId = DEFAULT_DISPLAY_ID;
46 FI_HILOGW("Correct the value of displayId(%{public}d) to 0", dragData.displayId);
47 }
48 targetPid_ = -1;
49 targetTid_ = -1;
50 }
51
SetShadowInfos(const std::vector<ShadowInfo> & shadowInfos)52 void DragDataManager::SetShadowInfos(const std::vector<ShadowInfo> &shadowInfos)
53 {
54 dragData_.shadowInfos = shadowInfos;
55 }
56
UpdateShadowInfos(std::shared_ptr<OHOS::Media::PixelMap> pixelMap)57 void DragDataManager::UpdateShadowInfos(std::shared_ptr<OHOS::Media::PixelMap> pixelMap)
58 {
59 ShadowInfo shadowInfo;
60 shadowInfo.pixelMap = pixelMap;
61 dragData_.shadowInfos.push_back(shadowInfo);
62 dragData_.dragNum++;
63 }
64
GetDragStyle() const65 DragCursorStyle DragDataManager::GetDragStyle() const
66 {
67 return dragStyle_;
68 }
69
GetDragData() const70 DragData DragDataManager::GetDragData() const
71 {
72 return dragData_;
73 }
74
SetDragWindowVisible(bool visible)75 void DragDataManager::SetDragWindowVisible(bool visible)
76 {
77 visible_ = visible;
78 }
79
GetDragWindowVisible() const80 bool DragDataManager::GetDragWindowVisible() const
81 {
82 return visible_;
83 }
84
SetTargetTid(int32_t targetTid)85 void DragDataManager::SetTargetTid(int32_t targetTid)
86 {
87 targetTid_ = targetTid;
88 }
89
GetTargetTid() const90 int32_t DragDataManager::GetTargetTid() const
91 {
92 return targetTid_;
93 }
94
SetTargetPid(int32_t pid)95 void DragDataManager::SetTargetPid(int32_t pid)
96 {
97 targetPid_ = pid;
98 }
99
GetTargetPid() const100 int32_t DragDataManager::GetTargetPid() const
101 {
102 return targetPid_;
103 }
104
SetEventId(int32_t eventId)105 void DragDataManager::SetEventId(int32_t eventId)
106 {
107 eventId_ = eventId;
108 }
109
GetEventId() const110 int32_t DragDataManager::GetEventId() const
111 {
112 return eventId_;
113 }
114
GetShadowOffset(ShadowOffset & shadowOffset) const115 int32_t DragDataManager::GetShadowOffset(ShadowOffset &shadowOffset) const
116 {
117 if (dragData_.shadowInfos.empty()) {
118 FI_HILOGE("ShadowInfos is empty");
119 return RET_ERR;
120 }
121 auto pixelMap = dragData_.shadowInfos.front().pixelMap;
122 CHKPR(pixelMap, RET_ERR);
123 shadowOffset = {
124 .offsetX = dragData_.shadowInfos.front().x,
125 .offsetY = dragData_.shadowInfos.front().y,
126 .width = pixelMap->GetWidth(),
127 .height = pixelMap->GetHeight()
128 };
129 FI_HILOGD("offsetX:%{private}d, offsetY:%{private}d, width:%{public}d, height:%{public}d",
130 shadowOffset.offsetX, shadowOffset.offsetY, shadowOffset.width, shadowOffset.height);
131 return RET_OK;
132 }
133
ResetDragData()134 void DragDataManager::ResetDragData()
135 {
136 CALL_DEBUG_ENTER;
137 dragData_ = { };
138 previewStyle_ = { };
139 dragStyle_ = DragCursorStyle::DEFAULT;
140 visible_ = false;
141 targetTid_ = -1;
142 targetPid_ = -1;
143 eventId_ = -1;
144 textEditorAreaFlag_ = false;
145 dragOriginDpi_ = 0.0f;
146 }
147
SetPixelMapLocation(const std::pair<int32_t,int32_t> & location)148 void DragDataManager::SetPixelMapLocation(const std::pair<int32_t, int32_t> &location)
149 {
150 if (dragData_.shadowInfos.empty()) {
151 FI_HILOGE("ShadowInfos is empty");
152 return;
153 }
154 dragData_.shadowInfos[0].x = location.first;
155 dragData_.shadowInfos[0].y = location.second;
156 }
157
SetDragOriginDpi(float dragOriginDpi)158 void DragDataManager::SetDragOriginDpi(float dragOriginDpi)
159 {
160 dragOriginDpi_ = dragOriginDpi;
161 FI_HILOGD("dragOriginDpi_:%{public}f", dragOriginDpi_);
162 }
163
GetSummaryInfo(DragSummaryInfo & dragSummaryInfo)164 void DragDataManager::GetSummaryInfo(DragSummaryInfo &dragSummaryInfo)
165 {
166 dragSummaryInfo.summarys = dragData_.summarys;
167 dragSummaryInfo.detailedSummarys = dragData_.detailedSummarys;
168 dragSummaryInfo.summaryFormat = dragData_.summaryFormat;
169 dragSummaryInfo.version = dragData_.summaryVersion;
170 dragSummaryInfo.totalSize = dragData_.summaryTotalSize;
171 }
172
GetDragOriginDpi() const173 float DragDataManager::GetDragOriginDpi() const
174 {
175 return dragOriginDpi_;
176 }
177
GetCoordinateCorrected()178 bool DragDataManager::GetCoordinateCorrected()
179 {
180 return dragData_.hasCoordinateCorrected;
181 }
182
SetTextEditorAreaFlag(bool enable)183 void DragDataManager::SetTextEditorAreaFlag(bool enable)
184 {
185 textEditorAreaFlag_ = enable;
186 }
187
GetTextEditorAreaFlag()188 bool DragDataManager::GetTextEditorAreaFlag()
189 {
190 return textEditorAreaFlag_;
191 }
192
SetInitialPixelMapLocation(const std::pair<int32_t,int32_t> & location)193 void DragDataManager::SetInitialPixelMapLocation(const std::pair<int32_t, int32_t> &location)
194 {
195 initialPixelMapLocation_ = location;
196 }
197
GetInitialPixelMapLocation()198 std::pair<int32_t, int32_t> DragDataManager::GetInitialPixelMapLocation()
199 {
200 return initialPixelMapLocation_;
201 }
202
SetPreviewStyle(const PreviewStyle & previewStyle)203 void DragDataManager::SetPreviewStyle(const PreviewStyle &previewStyle)
204 {
205 previewStyle_ = previewStyle;
206 }
207
GetPreviewStyle()208 PreviewStyle DragDataManager::GetPreviewStyle()
209 {
210 return previewStyle_;
211 }
212 } // namespace DeviceStatus
213 } // namespace Msdp
214 } // namespace OHOS