• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
GetDragOriginDpi() const164 float DragDataManager::GetDragOriginDpi() const
165 {
166     return dragOriginDpi_;
167 }
168 
GetCoordinateCorrected()169 bool DragDataManager::GetCoordinateCorrected()
170 {
171     return dragData_.hasCoordinateCorrected;
172 }
173 
SetTextEditorAreaFlag(bool enable)174 void DragDataManager::SetTextEditorAreaFlag(bool enable)
175 {
176     textEditorAreaFlag_ = enable;
177 }
178 
GetTextEditorAreaFlag()179 bool DragDataManager::GetTextEditorAreaFlag()
180 {
181     return textEditorAreaFlag_;
182 }
183 
SetInitialPixelMapLocation(const std::pair<int32_t,int32_t> & location)184 void DragDataManager::SetInitialPixelMapLocation(const std::pair<int32_t, int32_t> &location)
185 {
186     initialPixelMapLocation_ = location;
187 }
188 
GetInitialPixelMapLocation()189 std::pair<int32_t, int32_t> DragDataManager::GetInitialPixelMapLocation()
190 {
191     return initialPixelMapLocation_;
192 }
193 
SetPreviewStyle(const PreviewStyle & previewStyle)194 void DragDataManager::SetPreviewStyle(const PreviewStyle &previewStyle)
195 {
196     previewStyle_ = previewStyle;
197 }
198 
GetPreviewStyle()199 PreviewStyle DragDataManager::GetPreviewStyle()
200 {
201     return previewStyle_;
202 }
203 } // namespace DeviceStatus
204 } // namespace Msdp
205 } // namespace OHOS