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 #undef LOG_TAG
25 #define LOG_TAG "DragDataManager"
26
27 namespace OHOS {
28 namespace Msdp {
29 namespace DeviceStatus {
30 namespace {
31 constexpr int32_t DEFAULT_DISPLAY_ID { 0 };
32 } // namespace
33
34 DragDataManager::DragDataManager() = default;
35 DragDataManager::~DragDataManager() = default;
36
SetDragStyle(DragCursorStyle style)37 void DragDataManager::SetDragStyle(DragCursorStyle style)
38 {
39 dragStyle_ = style;
40 }
41
Init(const DragData & dragData)42 void DragDataManager::Init(const DragData &dragData)
43 {
44 dragData_ = dragData;
45 if (dragData.displayId < DEFAULT_DISPLAY_ID) {
46 dragData_.displayId = DEFAULT_DISPLAY_ID;
47 FI_HILOGW("Correct the value of displayId(%{public}d) to 0", dragData.displayId);
48 }
49 targetPid_ = -1;
50 targetTid_ = -1;
51 }
52
SetShadowInfos(const std::vector<ShadowInfo> & shadowInfos)53 void DragDataManager::SetShadowInfos(const std::vector<ShadowInfo> &shadowInfos)
54 {
55 dragData_.shadowInfos = shadowInfos;
56 }
57
GetDragStyle() const58 DragCursorStyle DragDataManager::GetDragStyle() const
59 {
60 return dragStyle_;
61 }
62
GetDragData() const63 DragData DragDataManager::GetDragData() const
64 {
65 return dragData_;
66 }
67
SetDragWindowVisible(bool visible)68 void DragDataManager::SetDragWindowVisible(bool visible)
69 {
70 visible_ = visible;
71 }
72
GetDragWindowVisible() const73 bool DragDataManager::GetDragWindowVisible() const
74 {
75 return visible_;
76 }
77
SetTargetTid(int32_t targetTid)78 void DragDataManager::SetTargetTid(int32_t targetTid)
79 {
80 targetTid_ = targetTid;
81 }
82
GetTargetTid() const83 int32_t DragDataManager::GetTargetTid() const
84 {
85 return targetTid_;
86 }
87
SetTargetPid(int32_t pid)88 void DragDataManager::SetTargetPid(int32_t pid)
89 {
90 targetPid_ = pid;
91 }
92
GetTargetPid() const93 int32_t DragDataManager::GetTargetPid() const
94 {
95 return targetPid_;
96 }
97
GetShadowOffset(ShadowOffset & shadowOffset) const98 int32_t DragDataManager::GetShadowOffset(ShadowOffset &shadowOffset) const
99 {
100 if (dragData_.shadowInfos.empty()) {
101 FI_HILOGE("ShadowInfos is empty");
102 return RET_ERR;
103 }
104 auto pixelMap = dragData_.shadowInfos.front().pixelMap;
105 CHKPR(pixelMap, RET_ERR);
106 shadowOffset = {
107 .offsetX = dragData_.shadowInfos.front().x,
108 .offsetY = dragData_.shadowInfos.front().y,
109 .width = pixelMap->GetWidth(),
110 .height = pixelMap->GetHeight()
111 };
112 FI_HILOGD("offsetX:%{private}d, offsetY:%{private}d, width:%{public}d, height:%{public}d",
113 shadowOffset.offsetX, shadowOffset.offsetY, shadowOffset.width, shadowOffset.height);
114 return RET_OK;
115 }
116
ResetDragData()117 void DragDataManager::ResetDragData()
118 {
119 CALL_DEBUG_ENTER;
120 dragData_ = { };
121 previewStyle_ = { };
122 dragStyle_ = DragCursorStyle::DEFAULT;
123 visible_ = false;
124 targetTid_ = -1;
125 targetPid_ = -1;
126 textEditorAreaFlag_ = false;
127 dragOriginDpi_ = 0.0f;
128 }
129
SetPixelMapLocation(const std::pair<int32_t,int32_t> & location)130 void DragDataManager::SetPixelMapLocation(const std::pair<int32_t, int32_t> &location)
131 {
132 if (dragData_.shadowInfos.empty()) {
133 FI_HILOGE("ShadowInfos is empty");
134 return;
135 }
136 dragData_.shadowInfos[0].x = location.first;
137 dragData_.shadowInfos[0].y = location.second;
138 }
139
SetDragOriginDpi(float dragOriginDpi)140 void DragDataManager::SetDragOriginDpi(float dragOriginDpi)
141 {
142 dragOriginDpi_ = dragOriginDpi;
143 FI_HILOGD("dragOriginDpi_:%{public}f", dragOriginDpi_);
144 }
145
GetDragOriginDpi() const146 float DragDataManager::GetDragOriginDpi() const
147 {
148 return dragOriginDpi_;
149 }
150
GetCoordinateCorrected()151 bool DragDataManager::GetCoordinateCorrected()
152 {
153 return dragData_.hasCoordinateCorrected;
154 }
155
SetTextEditorAreaFlag(bool enable)156 void DragDataManager::SetTextEditorAreaFlag(bool enable)
157 {
158 textEditorAreaFlag_ = enable;
159 }
160
GetTextEditorAreaFlag()161 bool DragDataManager::GetTextEditorAreaFlag()
162 {
163 return textEditorAreaFlag_;
164 }
165
SetInitialPixelMapLocation(const std::pair<int32_t,int32_t> & location)166 void DragDataManager::SetInitialPixelMapLocation(const std::pair<int32_t, int32_t> &location)
167 {
168 initialPixelMapLocation_ = location;
169 }
170
GetInitialPixelMapLocation()171 std::pair<int32_t, int32_t> DragDataManager::GetInitialPixelMapLocation()
172 {
173 return initialPixelMapLocation_;
174 }
175
SetPreviewStyle(const PreviewStyle & previewStyle)176 void DragDataManager::SetPreviewStyle(const PreviewStyle &previewStyle)
177 {
178 previewStyle_ = previewStyle;
179 }
180
GetPreviewStyle()181 PreviewStyle DragDataManager::GetPreviewStyle()
182 {
183 return previewStyle_;
184 }
185 } // namespace DeviceStatus
186 } // namespace Msdp
187 } // namespace OHOS