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 "hitrace_meter.h"
19
20 #include "devicestatus_define.h"
21 #include "drag_data.h"
22 #include "fi_log.h"
23
24 namespace OHOS {
25 namespace Msdp {
26 namespace DeviceStatus {
27 namespace {
28 constexpr OHOS::HiviewDFX::HiLogLabel LABEL { LOG_CORE, MSDP_DOMAIN_ID, "DragDataManager" };
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
GetDragStyle() const56 DragCursorStyle DragDataManager::GetDragStyle() const
57 {
58 return dragStyle_;
59 }
60
GetDragData() const61 DragData DragDataManager::GetDragData() const
62 {
63 return dragData_;
64 }
65
SetDragWindowVisible(bool visible)66 void DragDataManager::SetDragWindowVisible(bool visible)
67 {
68 visible_ = visible;
69 }
70
GetDragWindowVisible() const71 bool DragDataManager::GetDragWindowVisible() const
72 {
73 return visible_;
74 }
75
SetTargetTid(int32_t targetTid)76 void DragDataManager::SetTargetTid(int32_t targetTid)
77 {
78 targetTid_ = targetTid;
79 }
80
GetTargetTid() const81 int32_t DragDataManager::GetTargetTid() const
82 {
83 return targetTid_;
84 }
85
SetTargetPid(int32_t pid)86 void DragDataManager::SetTargetPid(int32_t pid)
87 {
88 targetPid_ = pid;
89 }
90
GetTargetPid() const91 int32_t DragDataManager::GetTargetPid() const
92 {
93 return targetPid_;
94 }
95
GetShadowOffset(int32_t & offsetX,int32_t & offsetY,int32_t & width,int32_t & height) const96 int32_t DragDataManager::GetShadowOffset(int32_t &offsetX, int32_t &offsetY, int32_t &width, int32_t &height) const
97 {
98 if (dragData_.shadowInfos.empty()) {
99 FI_HILOGE("ShadowInfos is empty");
100 return RET_ERR;
101 }
102 offsetX = dragData_.shadowInfos.front().x;
103 offsetY = dragData_.shadowInfos.front().y;
104 auto pixelMap = dragData_.shadowInfos.front().pixelMap;
105 CHKPR(pixelMap, RET_ERR);
106 width = pixelMap->GetWidth();
107 height = pixelMap->GetHeight();
108 FI_HILOGD("offsetX:%{public}d, offsetY:%{public}d, width:%{public}d, height:%{public}d",
109 offsetX, offsetY, width, height);
110 return RET_OK;
111 }
112
ResetDragData()113 void DragDataManager::ResetDragData()
114 {
115 CALL_DEBUG_ENTER;
116 dragData_ = { };
117 previewStyle_ = { };
118 dragStyle_ = DragCursorStyle::DEFAULT;
119 visible_ = false;
120 targetTid_ = -1;
121 targetPid_ = -1;
122 isMotionDrag_ = false;
123 textEditorAreaFlag_ = false;
124 }
125
SetPixelMapLocation(const std::pair<int32_t,int32_t> & location)126 void DragDataManager::SetPixelMapLocation(const std::pair<int32_t, int32_t> &location)
127 {
128 if (dragData_.shadowInfos.empty()) {
129 FI_HILOGE("ShadowInfos is empty");
130 return;
131 }
132 dragData_.shadowInfos[0].x = location.first;
133 dragData_.shadowInfos[0].y = location.second;
134 }
135
GetCoordinateCorrected()136 bool DragDataManager::GetCoordinateCorrected()
137 {
138 return dragData_.hasCoordinateCorrected;
139 }
140
SetTextEditorAreaFlag(bool enable)141 void DragDataManager::SetTextEditorAreaFlag(bool enable)
142 {
143 textEditorAreaFlag_ = enable;
144 }
145
GetTextEditorAreaFlag()146 bool DragDataManager::GetTextEditorAreaFlag()
147 {
148 return textEditorAreaFlag_;
149 }
150
SetInitialPixelMapLocation(const std::pair<int32_t,int32_t> & location)151 void DragDataManager::SetInitialPixelMapLocation(const std::pair<int32_t, int32_t> &location)
152 {
153 initialPixelMapLocation_ = location;
154 }
155
GetInitialPixelMapLocation()156 std::pair<int32_t, int32_t> DragDataManager::GetInitialPixelMapLocation()
157 {
158 return initialPixelMapLocation_;
159 }
160
SetMotionDrag(bool isMotionDrag)161 void DragDataManager::SetMotionDrag(bool isMotionDrag)
162 {
163 isMotionDrag_ = isMotionDrag;
164 FI_HILOGD("isMotionDrag_:%{public}d", isMotionDrag_);
165 }
166
IsMotionDrag() const167 bool DragDataManager::IsMotionDrag() const
168 {
169 FI_HILOGD("isMotionDrag_:%{public}d", isMotionDrag_);
170 return isMotionDrag_;
171 }
172
SetPreviewStyle(const PreviewStyle & previewStyle)173 void DragDataManager::SetPreviewStyle(const PreviewStyle &previewStyle)
174 {
175 previewStyle_ = previewStyle;
176 }
177
GetPreviewStyle()178 PreviewStyle DragDataManager::GetPreviewStyle()
179 {
180 return previewStyle_;
181 }
182 } // namespace DeviceStatus
183 } // namespace Msdp
184 } // namespace OHOS