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)40 void DragDataManager::Init(const DragData &dragData)
41 {
42 dragData_ = dragData;
43 if (dragData.displayId < DEFAULT_DISPLAY_ID) {
44 dragData_.displayId = DEFAULT_DISPLAY_ID;
45 FI_HILOGW("Correct the value of displayId(%{public}d) to 0", dragData.displayId);
46 }
47 targetPid_ = -1;
48 targetTid_ = -1;
49 }
50
SetShadowInfos(const std::vector<ShadowInfo> &shadowInfos)51 void DragDataManager::SetShadowInfos(const std::vector<ShadowInfo> &shadowInfos)
52 {
53 dragData_.shadowInfos = shadowInfos;
54 }
55
UpdateShadowInfos(std::shared_ptr<OHOS::Media::PixelMap> pixelMap)56 void DragDataManager::UpdateShadowInfos(std::shared_ptr<OHOS::Media::PixelMap> pixelMap)
57 {
58 ShadowInfo shadowInfo;
59 shadowInfo.pixelMap = pixelMap;
60 dragData_.shadowInfos.push_back(shadowInfo);
61 dragData_.dragNum++;
62 }
63
GetDragStyle() const64 DragCursorStyle DragDataManager::GetDragStyle() const
65 {
66 return dragStyle_;
67 }
68
GetDragData() const69 DragData DragDataManager::GetDragData() const
70 {
71 return dragData_;
72 }
73
SetDragWindowVisible(bool visible)74 void DragDataManager::SetDragWindowVisible(bool visible)
75 {
76 visible_ = visible;
77 }
78
GetDragWindowVisible() const79 bool DragDataManager::GetDragWindowVisible() const
80 {
81 return visible_;
82 }
83
SetTargetTid(int32_t targetTid)84 void DragDataManager::SetTargetTid(int32_t targetTid)
85 {
86 targetTid_ = targetTid;
87 }
88
GetTargetTid() const89 int32_t DragDataManager::GetTargetTid() const
90 {
91 return targetTid_;
92 }
93
SetTargetPid(int32_t pid)94 void DragDataManager::SetTargetPid(int32_t pid)
95 {
96 targetPid_ = pid;
97 }
98
GetTargetPid() const99 int32_t DragDataManager::GetTargetPid() const
100 {
101 return targetPid_;
102 }
103
GetShadowOffset(ShadowOffset &shadowOffset) const104 int32_t DragDataManager::GetShadowOffset(ShadowOffset &shadowOffset) const
105 {
106 if (dragData_.shadowInfos.empty()) {
107 FI_HILOGE("ShadowInfos is empty");
108 return RET_ERR;
109 }
110 auto pixelMap = dragData_.shadowInfos.front().pixelMap;
111 CHKPR(pixelMap, RET_ERR);
112 shadowOffset = {
113 .offsetX = dragData_.shadowInfos.front().x,
114 .offsetY = dragData_.shadowInfos.front().y,
115 .width = pixelMap->GetWidth(),
116 .height = pixelMap->GetHeight()
117 };
118 FI_HILOGD("offsetX:%{private}d, offsetY:%{private}d, width:%{public}d, height:%{public}d",
119 shadowOffset.offsetX, shadowOffset.offsetY, shadowOffset.width, shadowOffset.height);
120 return RET_OK;
121 }
122
ResetDragData()123 void DragDataManager::ResetDragData()
124 {
125 CALL_DEBUG_ENTER;
126 dragData_ = { };
127 previewStyle_ = { };
128 dragStyle_ = DragCursorStyle::DEFAULT;
129 visible_ = false;
130 targetTid_ = -1;
131 targetPid_ = -1;
132 textEditorAreaFlag_ = false;
133 dragOriginDpi_ = 0.0f;
134 }
135
SetPixelMapLocation(const std::pair<int32_t, int32_t> &location)136 void DragDataManager::SetPixelMapLocation(const std::pair<int32_t, int32_t> &location)
137 {
138 if (dragData_.shadowInfos.empty()) {
139 FI_HILOGE("ShadowInfos is empty");
140 return;
141 }
142 dragData_.shadowInfos[0].x = location.first;
143 dragData_.shadowInfos[0].y = location.second;
144 }
145
SetDragOriginDpi(float dragOriginDpi)146 void DragDataManager::SetDragOriginDpi(float dragOriginDpi)
147 {
148 dragOriginDpi_ = dragOriginDpi;
149 FI_HILOGD("dragOriginDpi_:%{public}f", dragOriginDpi_);
150 }
151
GetDragOriginDpi() const152 float DragDataManager::GetDragOriginDpi() const
153 {
154 return dragOriginDpi_;
155 }
156
GetCoordinateCorrected()157 bool DragDataManager::GetCoordinateCorrected()
158 {
159 return dragData_.hasCoordinateCorrected;
160 }
161
SetTextEditorAreaFlag(bool enable)162 void DragDataManager::SetTextEditorAreaFlag(bool enable)
163 {
164 textEditorAreaFlag_ = enable;
165 }
166
GetTextEditorAreaFlag()167 bool DragDataManager::GetTextEditorAreaFlag()
168 {
169 return textEditorAreaFlag_;
170 }
171
SetInitialPixelMapLocation(const std::pair<int32_t, int32_t> &location)172 void DragDataManager::SetInitialPixelMapLocation(const std::pair<int32_t, int32_t> &location)
173 {
174 initialPixelMapLocation_ = location;
175 }
176
GetInitialPixelMapLocation()177 std::pair<int32_t, int32_t> DragDataManager::GetInitialPixelMapLocation()
178 {
179 return initialPixelMapLocation_;
180 }
181
SetPreviewStyle(const PreviewStyle &previewStyle)182 void DragDataManager::SetPreviewStyle(const PreviewStyle &previewStyle)
183 {
184 previewStyle_ = previewStyle;
185 }
186
GetPreviewStyle()187 PreviewStyle DragDataManager::GetPreviewStyle()
188 {
189 return previewStyle_;
190 }
191 } // namespace DeviceStatus
192 } // namespace Msdp
193 } // namespace OHOS